improve the pixel rng

see https://github.com/libvips/libvips/issues/2642
This commit is contained in:
John Cupitt 2022-02-02 18:15:26 +00:00
parent d9c00eb5ca
commit 8c668303f8
2 changed files with 18 additions and 7 deletions

View File

@ -3,6 +3,7 @@
- add support for another quantiser [DarthSim]
- jpeg2000 load left-justifies bitdepth
- add "password" option to pdfload
- improve the pixel rng
26/11/21 started 8.12.3
- better arg checking for hist_find_ndim [travisbell]

View File

@ -1918,18 +1918,28 @@ vips_realpath( const char *path )
/* A very simple random number generator. See:
* http://isthe.com/chongo/tech/comp/fnv/#FNV-source
*/
guint32
vips__random_add( guint32 hash, int value )
{
#define FNV_ADD( HASH, VALUE8 ) (((HASH) ^ (VALUE8)) * 16777619u)
hash = FNV_ADD( hash, value & 0xff );
hash = FNV_ADD( hash, (value >> 8) & 0xff );
hash = FNV_ADD( hash, (value >> 16) & 0xff );
hash = FNV_ADD( hash, (value >> 24) & 0xff );
return( hash );
}
guint32
vips__random( guint32 seed )
{
return( 1103515245u * seed + 12345 );
}
guint32 hash;
guint32
vips__random_add( guint32 seed, int value )
{
seed = ((2166136261u ^ seed) * 16777619u) ^ value;
hash = 2166136261u;
hash = vips__random_add( hash, seed );
return( vips__random( seed ) );
return( hash );
}
static void *