about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--converter/other/pgmtopbm.c19
-rw-r--r--doc/HISTORY2
2 files changed, 18 insertions, 3 deletions
diff --git a/converter/other/pgmtopbm.c b/converter/other/pgmtopbm.c
index 845c9fb5..64dc814b 100644
--- a/converter/other/pgmtopbm.c
+++ b/converter/other/pgmtopbm.c
@@ -30,6 +30,9 @@ struct CmdlineInfo {
     unsigned int  clumpSize;
     unsigned int  clusterRadius;
         /* Defined only for halftone == QT_CLUSTER */
+    unsigned int  randomSeed;
+    unsigned int  randomSeedSpec;
+        /* Defined only for halftone == QT_FS */
     float         threshval;
 };
 
@@ -72,6 +75,8 @@ parseCommandLine(int argc, const char ** argv,
             &valueSpec, 0);
     OPTENT3(0, "clump",     OPT_UINT,  &cmdlineP->clumpSize,
             &clumpSpec, 0);
+    OPTENT3(0, "randomseed", OPT_UINT,  &cmdlineP->randomSeed,
+            &cmdlineP->randomSeedSpec, 0);
 
     opt.opt_table = option_def;
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
@@ -127,6 +132,10 @@ parseCommandLine(int argc, const char ** argv,
                      cmdlineP->clumpSize);
     }
 
+    if (cmdlineP->halftone != QT_FS && cmdlineP->randomSeedSpec)
+        pm_message ("Ignoring -randomseed value "
+                    "(meaningful only with Floyd-Steinberg)");
+
     if (argc-1 > 1)
         pm_error("Too many arguments (%d).  There is at most one "
                  "non-option argument:  the file name",
@@ -441,7 +450,9 @@ fsDestroy(struct converter * const converterP) {
 static struct converter
 createFsConverter(unsigned int const cols,
                   gray         const maxval,
-                  float        const threshFraction) {
+                  float        const threshFraction,
+                  unsigned int const randomSeedSpec,
+                  unsigned int const randomSeed) {
 
     struct fsState * stateP;
     struct converter converter;
@@ -451,7 +462,7 @@ createFsConverter(unsigned int const cols,
     /* Initialize Floyd-Steinberg error vectors. */
     MALLOCARRAY_NOFAIL(stateP->thiserr, cols + 2);
     MALLOCARRAY_NOFAIL(stateP->nexterr, cols + 2);
-    srand(pm_randseed());
+    srand(randomSeedSpec ? randomSeed : pm_randseed());
 
     {
         /* (random errors in [-fs_scale/8 .. fs_scale/8]) */
@@ -724,7 +735,9 @@ main(int argc, const char *argv[]) {
 
         switch (cmdline.halftone) {
         case QT_FS:
-            converter = createFsConverter(cols, maxval, cmdline.threshval);
+            converter = createFsConverter(cols, maxval, cmdline.threshval,
+                                          cmdline.randomSeedSpec,
+                                          cmdline.randomSeed);
             break;
         case QT_THRESH:
             converter = createThreshConverter(cols, maxval, cmdline.threshval);
diff --git a/doc/HISTORY b/doc/HISTORY
index 2235d0a4..20c9ed47 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -6,6 +6,8 @@ CHANGE HISTORY
 
 not yet  BJH  Release 10.92.00
 
+              pgmtopbm: add -randomseed.
+
               pcdovtoppm: Fix some garbage from the conversion from csh to sh
               in Netpbm 9.12 (March 2001) in conversion from csh arrays that
               should have stopped it from working at all, despite reports from