about summary refs log tree commit diff
path: root/editor
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-09-26 21:28:10 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-09-26 21:28:10 +0000
commit6eb04c5ebd4cd3cae0ce4de2921ce7a4b709d473 (patch)
treeec8aab03fe0ce392583b171556f3bd4706031df5 /editor
parent54191112065200f118588896c756ed48d99a515e (diff)
downloadnetpbm-mirror-6eb04c5ebd4cd3cae0ce4de2921ce7a4b709d473.tar.gz
netpbm-mirror-6eb04c5ebd4cd3cae0ce4de2921ce7a4b709d473.tar.xz
netpbm-mirror-6eb04c5ebd4cd3cae0ce4de2921ce7a4b709d473.zip
Release 10.86.17
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@3967 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor')
-rw-r--r--editor/pamfunc.c56
-rw-r--r--editor/pammixmulti.c2
2 files changed, 33 insertions, 25 deletions
diff --git a/editor/pamfunc.c b/editor/pamfunc.c
index 5945b82d..454e6d63 100644
--- a/editor/pamfunc.c
+++ b/editor/pamfunc.c
@@ -266,11 +266,12 @@ validateFunction(struct CmdlineInfo const cmdline,
 static void
 planTransform(struct CmdlineInfo const cmdline,
               sample             const inputMaxval,
+              int                const outputFormat,
               sample *           const outputMaxvalP,
               bool *             const mustChangeRasterP) {
 /*----------------------------------------------------------------------------
    Plan the transform described by 'cmdline', given the maxval of the input
-   image is 'inputMaxval.
+   image is 'inputMaxval and the output format will be 'outputFormat'.
 
    The plan just consists of whether to change the maxval or the raster.
    Some multiplications and divisions can be achieved just by changing the
@@ -278,30 +279,36 @@ planTransform(struct CmdlineInfo const cmdline,
 -----------------------------------------------------------------------------*/
     if (cmdline.changemaxval) {
         /* User allows us to change the maxval, if that makes it easier */
-        if (cmdline.function == FN_MULTIPLY || cmdline.function == FN_DIVIDE) {
-            float const multiplier =
-                cmdline.function == FN_MULTIPLY ? cmdline.u.multiplier :
-                (1/cmdline.u.divisor);
-
-            float const neededMaxval = inputMaxval / multiplier;
-
-            if (neededMaxval + 0.5 < inputMaxval) {
-                /* Lowering the maxval might make some of the sample values
-                   higher than the maxval, so we'd have to modify the raster
-                   to clip them.
-                */
-                *outputMaxvalP     = inputMaxval;
-                *mustChangeRasterP = true;
-            } else if (neededMaxval > PAM_OVERALL_MAXVAL) {
+        if (PNM_FORMAT_TYPE(outputFormat) == PBM_TYPE) {
+            *outputMaxvalP     = inputMaxval;
+            *mustChangeRasterP = true;
+        } else {
+            if (cmdline.function == FN_MULTIPLY ||
+                cmdline.function == FN_DIVIDE) {
+                float const multiplier =
+                    cmdline.function == FN_MULTIPLY ? cmdline.u.multiplier :
+                    (1/cmdline.u.divisor);
+
+                float const neededMaxval = inputMaxval / multiplier;
+
+                if (neededMaxval + 0.5 < inputMaxval) {
+                    /* Lowering the maxval might make some of the sample
+                       values higher than the maxval, so we'd have to modify
+                       the raster to clip them.
+                    */
+                    *outputMaxvalP     = inputMaxval;
+                    *mustChangeRasterP = true;
+                } else if (neededMaxval > PAM_OVERALL_MAXVAL) {
+                    *outputMaxvalP     = inputMaxval;
+                    *mustChangeRasterP = true;
+                } else {
+                    *outputMaxvalP     = ROUNDU(neededMaxval);
+                    *mustChangeRasterP = false;
+                }
+            } else {
                 *outputMaxvalP     = inputMaxval;
                 *mustChangeRasterP = true;
-            } else {
-                *outputMaxvalP     = ROUNDU(neededMaxval);
-                *mustChangeRasterP = false;
             }
-        } else {
-            *outputMaxvalP     = inputMaxval;
-            *mustChangeRasterP = true;
         }
     } else {
         *outputMaxvalP     = inputMaxval;
@@ -368,7 +375,7 @@ applyFunction(struct CmdlineInfo const cmdline,
                 outSample = inSample ^ cmdline.u.mask;
                 break;
             case FN_NOT:
-                outSample = ~inSample;
+                outSample = ~inSample & outpam.maxval;
                 break;
             case FN_SHIFTLEFT:
                 outSample =
@@ -412,7 +419,8 @@ main(int argc, const char *argv[]) {
     outpam = inpam;    /* Initial value -- most fields should be same */
     outpam.file = stdout;
 
-    planTransform(cmdline, inpam.maxval, &outpam.maxval, &mustChangeRaster);
+    planTransform(cmdline, inpam.maxval, outpam.format,
+                  &outpam.maxval, &mustChangeRaster);
 
     pnm_writepaminit(&outpam);
 
diff --git a/editor/pammixmulti.c b/editor/pammixmulti.c
index d063d96c..f5012d7a 100644
--- a/editor/pammixmulti.c
+++ b/editor/pammixmulti.c
@@ -243,7 +243,7 @@ blendTuplesRandom(struct ProgramState * const stateP,
   from a random input image.
 -----------------------------------------------------------------------------*/
     unsigned int const depth = stateP->inPam[0].depth;
-    unsigned int const img = (unsigned int) (random() % stateP->inFileCt);
+    unsigned int const img = (unsigned int) (rand() % stateP->inFileCt);
 
     unsigned int samp;