--- netpbm-svn-4903.old/editor/pnmremap.c +++ netpbm-svn-4903/editor/pnmremap.c @@ -400,13 +400,54 @@ Set a random error in the range [-1 .. 1] (normalized via FS_SCALE) in the error array err[][]. -----------------------------------------------------------------------------*/ + unsigned int col; + int c; + char *cp; + unsigned long x_seed; struct pm_randSt randSt; assert(random.init != RANDOM_NONE); + x_seed = random.seed; + +/* ------------------------------------------------------------ */ + +/* This version of "pnmremap.c" supports an environment vari- */ +/* able named PNMREMAPRAND. If the variable is defined, and its */ +/* value starts with "f" or "F" [short for FALSE] or "n" or "N" */ +/* [short for "NO"], "pnmremap.c" uses a fixed random-number */ +/* seed. */ + +/* The PNMREMAPRAND feature was added for the benefit of a new */ +/* program named "ppmquantnr". The new program is equivalent to */ +/* the existing "ppmquant" program, with one difference: "ppm- */ +/* quantnr" sets PNMREMAPRAND to NO. The change means that the */ +/* user will get consistent results if he or she executes the */ +/* same "ppmquantnr" command repeatedly for identical input */ +/* files at different times. This is a useful feature for some */ +/* applications. */ + +/* As of 2019, "pnmremap.c" seems to include a similar feature */ +/* of its own. The PNMREMAPRAND feature will be retained, re- */ +/* gardless, for the sake of backwards compatibility. */ + + c = 0; + + if ((cp = getenv ("PNMREMAPRAND")) != NULL) + { + c = *cp; + if ((c >= 'a') && (c <= 'z')) c += 'A' - 'a'; + } + /* Produce consistent results? */ + if ((c == 'F') || (c == 'N')) + { /* Yes */ + x_seed = 0x3DBA656FL; + } + +/* ------------------------------------------------------------ */ - pm_randinit(&randSt); - pm_srand2(&randSt, random.init == RANDOM_WITHSEED, random.seed); + pm_randinit (&randSt); + pm_srand2 (&randSt, random.init == RANDOM_WITHSEED, x_seed); for (col = 0; col < width; ++col) { unsigned int plane;