add "seed" param to perlin, worley and gaussnoise

see https://github.com/libvips/libvips/issues/1884
This commit is contained in:
John Cupitt 2020-11-16 09:14:06 +00:00
parent a43e9d3982
commit 2772ecbb9e
4 changed files with 27 additions and 10 deletions

View File

@ -8,6 +8,7 @@
- have a lock just for pdfium [DarthSim]
- get pdfium load building again [Projkt-James]
- add _source load support for pdfium
- add "seed" param to perlin, worley and gaussnoise
18/10/20 started 8.10.3
- relax heic is_a rules [hisham]

View File

@ -75,7 +75,8 @@ typedef struct _VipsGaussnoise {
double mean;
double sigma;
/* Per-image seed.
/* Per-image seed. Each pixel is seeded by this plus the (x,
* y) coordinate.
*/
guint32 seed;
} VipsGaussnoise;
@ -138,11 +139,6 @@ vips_gaussnoise_build( VipsObject *object )
vips_image_pipelinev( create->out,
VIPS_DEMAND_STYLE_ANY, NULL );
/* The seed for this image. Each pixel is seeded by this plus the (x,
* y) coordinate.
*/
gaussnoise->seed = UINT_MAX * g_random_double();
if( vips_image_generate( create->out,
NULL, vips_gaussnoise_gen, NULL, gaussnoise, NULL ) )
return( -1 );
@ -196,6 +192,13 @@ vips_gaussnoise_class_init( VipsGaussnoiseClass *class )
G_STRUCT_OFFSET( VipsGaussnoise, sigma ),
0, 100000, 30 );
VIPS_ARG_INT( class, "seed", 7,
_( "Seed" ),
_( "Random number seed" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsGaussnoise, seed ),
INT_MIN, INT_MAX, 0 );
}
static void
@ -203,6 +206,7 @@ vips_gaussnoise_init( VipsGaussnoise *gaussnoise )
{
gaussnoise->mean = 128.0;
gaussnoise->sigma = 30.0;
gaussnoise->seed = UINT_MAX * g_random_double();
}
/**

View File

@ -244,8 +244,6 @@ vips_perlin_build( VipsObject *object )
VIPS_ROUND_UP( perlin->height, perlin->cell_size ) /
perlin->cell_size;
perlin->seed = g_random_double() * 0xffffffffu;
vips_image_init_fields( create->out,
perlin->width, perlin->height, 1,
perlin->uchar ? VIPS_FORMAT_UCHAR : VIPS_FORMAT_FLOAT,
@ -321,12 +319,20 @@ vips_perlin_class_init( VipsPerlinClass *class )
G_STRUCT_OFFSET( VipsPerlin, uchar ),
FALSE );
VIPS_ARG_INT( class, "seed", 5,
_( "Seed" ),
_( "Random number seed" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsPerlin, seed ),
INT_MIN, INT_MAX, 0 );
}
static void
vips_perlin_init( VipsPerlin *perlin )
{
perlin->cell_size = 256;
perlin->seed = UINT_MAX * g_random_double();
}
/**

View File

@ -277,8 +277,6 @@ vips_worley_build( VipsObject *object )
VIPS_ROUND_UP( worley->height, worley->cell_size ) /
worley->cell_size;
worley->seed = g_random_double() * 0xffffffffu;
vips_image_init_fields( create->out,
worley->width, worley->height, 1,
VIPS_FORMAT_FLOAT, VIPS_CODING_NONE,
@ -328,12 +326,20 @@ vips_worley_class_init( VipsWorleyClass *class )
G_STRUCT_OFFSET( VipsWorley, cell_size ),
1, VIPS_MAX_COORD, 256 );
VIPS_ARG_INT( class, "seed", 4,
_( "Seed" ),
_( "Random number seed" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsWorley, seed ),
INT_MIN, INT_MAX, 0 );
}
static void
vips_worley_init( VipsWorley *worley )
{
worley->cell_size = 256;
worley->seed = UINT_MAX * g_random_double();
}
/**