Skip to content

Commit 2772ecb

Browse files
committed
add "seed" param to perlin, worley and gaussnoise
see #1884
1 parent a43e9d3 commit 2772ecb

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- have a lock just for pdfium [DarthSim]
99
- get pdfium load building again [Projkt-James]
1010
- add _source load support for pdfium
11+
- add "seed" param to perlin, worley and gaussnoise
1112

1213
18/10/20 started 8.10.3
1314
- relax heic is_a rules [hisham]

libvips/create/gaussnoise.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ typedef struct _VipsGaussnoise {
7575
double mean;
7676
double sigma;
7777

78-
/* Per-image seed.
78+
/* Per-image seed. Each pixel is seeded by this plus the (x,
79+
* y) coordinate.
7980
*/
8081
guint32 seed;
8182
} VipsGaussnoise;
@@ -138,11 +139,6 @@ vips_gaussnoise_build( VipsObject *object )
138139
vips_image_pipelinev( create->out,
139140
VIPS_DEMAND_STYLE_ANY, NULL );
140141

141-
/* The seed for this image. Each pixel is seeded by this plus the (x,
142-
* y) coordinate.
143-
*/
144-
gaussnoise->seed = UINT_MAX * g_random_double();
145-
146142
if( vips_image_generate( create->out,
147143
NULL, vips_gaussnoise_gen, NULL, gaussnoise, NULL ) )
148144
return( -1 );
@@ -196,13 +192,21 @@ vips_gaussnoise_class_init( VipsGaussnoiseClass *class )
196192
G_STRUCT_OFFSET( VipsGaussnoise, sigma ),
197193
0, 100000, 30 );
198194

195+
VIPS_ARG_INT( class, "seed", 7,
196+
_( "Seed" ),
197+
_( "Random number seed" ),
198+
VIPS_ARGUMENT_OPTIONAL_INPUT,
199+
G_STRUCT_OFFSET( VipsGaussnoise, seed ),
200+
INT_MIN, INT_MAX, 0 );
201+
199202
}
200203

201204
static void
202205
vips_gaussnoise_init( VipsGaussnoise *gaussnoise )
203206
{
204207
gaussnoise->mean = 128.0;
205208
gaussnoise->sigma = 30.0;
209+
gaussnoise->seed = UINT_MAX * g_random_double();
206210
}
207211

208212
/**

libvips/create/perlin.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,6 @@ vips_perlin_build( VipsObject *object )
244244
VIPS_ROUND_UP( perlin->height, perlin->cell_size ) /
245245
perlin->cell_size;
246246

247-
perlin->seed = g_random_double() * 0xffffffffu;
248-
249247
vips_image_init_fields( create->out,
250248
perlin->width, perlin->height, 1,
251249
perlin->uchar ? VIPS_FORMAT_UCHAR : VIPS_FORMAT_FLOAT,
@@ -321,12 +319,20 @@ vips_perlin_class_init( VipsPerlinClass *class )
321319
G_STRUCT_OFFSET( VipsPerlin, uchar ),
322320
FALSE );
323321

322+
VIPS_ARG_INT( class, "seed", 5,
323+
_( "Seed" ),
324+
_( "Random number seed" ),
325+
VIPS_ARGUMENT_OPTIONAL_INPUT,
326+
G_STRUCT_OFFSET( VipsPerlin, seed ),
327+
INT_MIN, INT_MAX, 0 );
328+
324329
}
325330

326331
static void
327332
vips_perlin_init( VipsPerlin *perlin )
328333
{
329334
perlin->cell_size = 256;
335+
perlin->seed = UINT_MAX * g_random_double();
330336
}
331337

332338
/**

libvips/create/worley.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ vips_worley_build( VipsObject *object )
277277
VIPS_ROUND_UP( worley->height, worley->cell_size ) /
278278
worley->cell_size;
279279

280-
worley->seed = g_random_double() * 0xffffffffu;
281-
282280
vips_image_init_fields( create->out,
283281
worley->width, worley->height, 1,
284282
VIPS_FORMAT_FLOAT, VIPS_CODING_NONE,
@@ -328,12 +326,20 @@ vips_worley_class_init( VipsWorleyClass *class )
328326
G_STRUCT_OFFSET( VipsWorley, cell_size ),
329327
1, VIPS_MAX_COORD, 256 );
330328

329+
VIPS_ARG_INT( class, "seed", 4,
330+
_( "Seed" ),
331+
_( "Random number seed" ),
332+
VIPS_ARGUMENT_OPTIONAL_INPUT,
333+
G_STRUCT_OFFSET( VipsWorley, seed ),
334+
INT_MIN, INT_MAX, 0 );
335+
331336
}
332337

333338
static void
334339
vips_worley_init( VipsWorley *worley )
335340
{
336341
worley->cell_size = 256;
342+
worley->seed = UINT_MAX * g_random_double();
337343
}
338344

339345
/**

0 commit comments

Comments
 (0)