about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-09-26 21:30:18 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-09-26 21:30:18 +0000
commit13ddd6e6ae24808acf0815de4e99868ffb094ed4 (patch)
treebd6e7d07bc33ce6edb22a913c44eb12f0ddbcc45
parent5d96d3c0c22088d20528fb0f0b126d175ec8a09f (diff)
downloadnetpbm-mirror-13ddd6e6ae24808acf0815de4e99868ffb094ed4.tar.gz
netpbm-mirror-13ddd6e6ae24808acf0815de4e99868ffb094ed4.tar.xz
netpbm-mirror-13ddd6e6ae24808acf0815de4e99868ffb094ed4.zip
Release 10.73.33
git-svn-id: http://svn.code.sf.net/p/netpbm/code/super_stable@3968 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/jpeg2000/libjasper/base/jas_stream.c2
-rw-r--r--converter/other/jpeg2000/pamtojpeg2k.c12
-rwxr-xr-xconverter/ppm/hpcdtoppm/pcdovtoppm30
-rw-r--r--doc/HISTORY29
-rw-r--r--editor/pamfunc.c56
-rw-r--r--editor/pnmnorm.c2
-rw-r--r--other/pamarith.c34
-rw-r--r--version.mk2
8 files changed, 117 insertions, 50 deletions
diff --git a/converter/other/jpeg2000/libjasper/base/jas_stream.c b/converter/other/jpeg2000/libjasper/base/jas_stream.c
index 16c948eb..24f835ed 100644
--- a/converter/other/jpeg2000/libjasper/base/jas_stream.c
+++ b/converter/other/jpeg2000/libjasper/base/jas_stream.c
@@ -414,9 +414,11 @@ jas_stream_t *jas_stream_tmpfile()
         if (rc == 0) {
             pm_setjmpbuf(&jmpbuf);
             *obj = pm_tmpfile_fd();
+            pm_setjmpbuf(NULL);
         } else {
             /* pm_tmpfile_fd() threw an error */
             jas_stream_destroy(stream);
+            pm_setjmpbuf(NULL);
             return 0;
         }
     }
diff --git a/converter/other/jpeg2000/pamtojpeg2k.c b/converter/other/jpeg2000/pamtojpeg2k.c
index 142e452f..90bd8955 100644
--- a/converter/other/jpeg2000/pamtojpeg2k.c
+++ b/converter/other/jpeg2000/pamtojpeg2k.c
@@ -195,15 +195,15 @@ parseCommandLine(int argc, char ** argv,
     if (!ilyrratesSpec)
         cmdlineP->ilyrrates = (char*) "";
     if (progressionSpec) {
-        if (strcmp(progressionOpt, "lrcp") == 0)
+        if (streq(progressionOpt, "lrcp"))
             cmdlineP->progression = PROG_LRCP;
-        if (strcmp(progressionOpt, "rlcp") == 0)
+        else if (streq(progressionOpt, "rlcp"))
             cmdlineP->progression = PROG_RLCP;
-        if (strcmp(progressionOpt, "rpcl") == 0)
+        else if (streq(progressionOpt, "rpcl"))
             cmdlineP->progression = PROG_RPCL;
-        if (strcmp(progressionOpt, "pcrl") == 0)
+        else if (streq(progressionOpt, "pcrl"))
             cmdlineP->progression = PROG_PCRL;
-        if (strcmp(progressionOpt, "cprl") == 0)
+        else if (streq(progressionOpt, "cprl"))
             cmdlineP->progression = PROG_CPRL;
         else
             pm_error("Invalid value for -progression: '%s'.  "
@@ -431,7 +431,7 @@ writeJpc(jas_image_t *      const jasperP,
                 cmdline.imgareatlx,
                 cmdline.imgareatly,
                 cmdline.tilegrdtlx,
-                cmdline.tilegrdtlx,
+                cmdline.tilegrdtly,
                 cmdline.tilewidth,
                 cmdline.tileheight,
                 cmdline.prcwidth,
diff --git a/converter/ppm/hpcdtoppm/pcdovtoppm b/converter/ppm/hpcdtoppm/pcdovtoppm
index dbf6f53d..01a68313 100755
--- a/converter/ppm/hpcdtoppm/pcdovtoppm
+++ b/converter/ppm/hpcdtoppm/pcdovtoppm
@@ -114,12 +114,6 @@ fi
 
 tmpfile=`tempfile -p pi -m 600`
 
-rowfiles=()
-imagefiles=()
-row=1
-col=1
-width=$size
-
 # Convert the PCD overview file to many PPM images
 if [ -f $1 ] ; then
     hpcdtoppm -Overview $1 $tmpfile
@@ -129,14 +123,20 @@ else
     usage
 fi
 
+imagefiles=
+rowfiles=
+row=1
+col=1
+width=$size
+
 for i in "$tmpfile"* 
 do
     if [ -f $i ] ; then
-        description=`pnmfile $i`
-        if [ "${description[4]}" -le $size -a \
-             "${description[6]}" -le $size ] ; then
+        thiswidth=$(pamfile -machine $i | cut -f 4 -d ' ')
+        thisheight=$(pamfile -machine $i | cut -f 5 -d ' ')
+        if [ "$thiswidth" -le $size -a "$thisheight" -le $size ] ; then
             cat $i > $tmpfile
-                else
+        else
             if [ "$colors" = "n" ] ; then
                 pnmscale -quiet -xysize $size $size $i > $tmpfile
             else
@@ -158,8 +158,8 @@ do
     fi
 
     rm -f $tmpfile
-    description=`pnmfile $imagefile`
-    width=$(( $width + ${description[4]} ))
+    thisWidth=$(pamfile -machine $i | cut -f 4 -d ' ')
+    width=$(( $width + $thisWidth ))
     imagefiles="$imagefiles $imagefile"
 
     if [ $col -ge $across -o $width -gt $maxwidth ] ; then
@@ -172,7 +172,7 @@ do
         ppmquant -quiet $colors > $rowfile
     fi
     rm -f $imagefiles
-    imagefiles=()
+    imagefiles=
     rowfiles="$rowfiles $rowfile"
     col=1
     row=$(( $row + 1 ))
@@ -182,7 +182,7 @@ do
     fi
 done
 
-if [ ${#imagefiles[*]} -gt 0 ] ; then
+if [ -n $imagefiles ] ; then
     rowfile=pi.${row}.$$
     rm -f $rowfile
     if [ "$colors" = "n" ] ; then
@@ -195,7 +195,7 @@ if [ ${#imagefiles[*]} -gt 0 ] ; then
     rowfiles="$rowfiles $rowfile"
 fi
 
-if [ ${#rowfiles[*]} = 1 ]; then
+if [ $(echo $rowfiles|wc -w) -eq 1 ] ; then
     cat $rowfiles
 else
     if [ "$colors" = "n" ] ; then
diff --git a/doc/HISTORY b/doc/HISTORY
index a68a4a77..eca25102 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,6 +4,35 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+20.09.26 BJH  Release 10.73.33
+
+              pamfunc: Fix always wrong output with -not.  Always broken.
+              (-not was new in Netpbm 10.40 (September 2007)).
+
+              pnmnorm: Fix bug: output too dark when -bpercent and -wpercent
+              indicate overlapping values.  Broken since Netpbm 10.43 (June
+              2008).
+
+              jpeg2ktopam: Fix crash whenever the program fails.  Broken in
+              Netpbm 10.42 (March 2008).
+
+              pamtojpeg2k: Fix failure with most -progression values.  Always
+              broken (pamtojpeg2k was new in Netpbm 10.12 (November 2002)).
+
+              pamtojpeg2k: Fix wrong result with -tilegrdtly.  Always
+              broken (pamtojpeg2k was new in Netpbm 10.12 (November 2002)).
+
+              pamarith: Fix crash with -compare where inputs are PBM.  Broken
+              in Netpbm 10.14 (February 2003).
+
+              pamfunc: Fix crash with -changemaxval and PBM input.  Always
+              broken.  -changemaxval was new in Netpbm 10.65 (December 2013).
+
+              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
+              users that they were using it.
+
 20.06.27 BJH  Release 10.73.32
 
               winicontoppm: Fix undefined behavior for various invalid input.
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/pnmnorm.c b/editor/pnmnorm.c
index 131b39d0..a3341eed 100644
--- a/editor/pnmnorm.c
+++ b/editor/pnmnorm.c
@@ -485,7 +485,7 @@ disOverlap(xelval   const reqBvalue,
             }
         } else {
             /* Both ends are free; use the point halfway between them. */
-            xelval const midPoint = (reqWvalue + reqBvalue + maxval/2)/2;
+            xelval const midPoint = (reqWvalue + reqBvalue)/2;
             *nonOlapBvalueP = MIN(midPoint, maxval-1);
             *nonOlapWvalueP = *nonOlapBvalueP + 1;
         }
diff --git a/other/pamarith.c b/other/pamarith.c
index 54c18485..3fde1953 100644
--- a/other/pamarith.c
+++ b/other/pamarith.c
@@ -213,6 +213,30 @@ functionCategory(enum function const function) {
 
 
 
+static int
+outFmtForCompare(int const format1,
+                 int const format2) {
+/*----------------------------------------------------------------------------
+   The format for the output image, given that the function is Compare and
+   'format1' and 'format2' are the input image formats.
+
+   Note that Compare is special because its maxval is always 2, and that
+   won't work for PBM.
+-----------------------------------------------------------------------------*/
+    int const tentativeFormat = MAX(format1, format2);
+
+    int retval;
+
+    switch (tentativeFormat) {
+    case PBM_FORMAT:  retval = PGM_FORMAT;      break;
+    case RPBM_FORMAT: retval = RPGM_FORMAT;     break;
+    default:          retval = tentativeFormat; break;
+    }
+    return retval;
+}
+
+
+
 static void
 computeOutputType(struct pam *  const outpamP,
                   struct pam    const inpam1,
@@ -222,13 +246,17 @@ computeOutputType(struct pam *  const outpamP,
     outpamP->size        = sizeof(struct pam);
     outpamP->len         = PAM_STRUCT_SIZE(tuple_type);
     outpamP->file        = stdout;
-    outpamP->format      = MAX(inpam1.format, inpam2.format);
     outpamP->plainformat = FALSE;
     outpamP->height      = inpam1.height;
     outpamP->width       = inpam1.width;
     outpamP->depth       = MAX(inpam1.depth, inpam2.depth);
 
-    switch (functionCategory(function)) {    
+    if (function == FN_COMPARE)
+        outpamP->format = outFmtForCompare(inpam1.format, inpam2.format);
+    else
+        outpamP->format = MAX(inpam1.format, inpam2.format);
+
+    switch (functionCategory(function)) {
     case CATEGORY_FRACTIONAL_ARITH:
         if (function == FN_COMPARE)
             outpamP->maxval = 2;
@@ -835,7 +863,7 @@ main(int argc, const char *argv[]) {
 
     switch (functionCategory(cmdline.function)) {    
     case CATEGORY_FRACTIONAL_ARITH:
-        if (inpam1.maxval == inpam2.maxval)
+        if (inpam1.maxval == inpam2.maxval && inpam2.maxval == outpam.maxval)
             doUnNormalizedArith(&inpam1, &inpam2, &outpam, cmdline.function);
         else
             doNormalizedArith(&inpam1, &inpam2, &outpam, cmdline.function);
diff --git a/version.mk b/version.mk
index 4f89ef21..904a29cc 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 10
 NETPBM_MINOR_RELEASE = 73
-NETPBM_POINT_RELEASE = 32
+NETPBM_POINT_RELEASE = 33