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] - add support for another quantiser [DarthSim]
- jpeg2000 load left-justifies bitdepth - jpeg2000 load left-justifies bitdepth
- add "password" option to pdfload - add "password" option to pdfload
- improve the pixel rng
26/11/21 started 8.12.3 26/11/21 started 8.12.3
- better arg checking for hist_find_ndim [travisbell] - better arg checking for hist_find_ndim [travisbell]

View File

@ -1919,17 +1919,27 @@ vips_realpath( const char *path )
* http://isthe.com/chongo/tech/comp/fnv/#FNV-source * http://isthe.com/chongo/tech/comp/fnv/#FNV-source
*/ */
guint32 guint32
vips__random( guint32 seed ) vips__random_add( guint32 hash, int value )
{ {
return( 1103515245u * seed + 12345 ); #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 guint32
vips__random_add( guint32 seed, int value ) vips__random( guint32 seed )
{ {
seed = ((2166136261u ^ seed) * 16777619u) ^ value; guint32 hash;
return( vips__random( seed ) ); hash = 2166136261u;
hash = vips__random_add( hash, seed );
return( hash );
} }
static void * static void *