about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2022-04-24 00:55:52 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2022-04-24 00:55:52 +0000
commitc34b30147e111cb445ade4552d2d9fe53fc41eba (patch)
tree504d3672d8910c21d885ce22326d5ed898ccd892
parent925336fe011635da550369b9db527f034fbc587d (diff)
downloadnetpbm-mirror-c34b30147e111cb445ade4552d2d9fe53fc41eba.tar.gz
netpbm-mirror-c34b30147e111cb445ade4552d2d9fe53fc41eba.tar.xz
netpbm-mirror-c34b30147e111cb445ade4552d2d9fe53fc41eba.zip
Release 10.86.33
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@4328 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/pnmtopalm/palmtopnm.c57
-rw-r--r--doc/HISTORY14
-rw-r--r--editor/pamdice.c6
-rw-r--r--editor/pnmgamma.c6
-rw-r--r--version.mk2
5 files changed, 64 insertions, 21 deletions
diff --git a/converter/other/pnmtopalm/palmtopnm.c b/converter/other/pnmtopalm/palmtopnm.c
index f202ccfc..0666141d 100644
--- a/converter/other/pnmtopalm/palmtopnm.c
+++ b/converter/other/pnmtopalm/palmtopnm.c
@@ -819,28 +819,46 @@ readPackBitsRow16(FILE *          const ifP,
 
         Although the [...] spec is byte-oriented, the 16-bit algorithm is
         identical [to the 8-bit algorithm]: just substitute "word" for "byte".
+
+        A note about the 0x80 control byte value: There are some sources that
+        suggest that 1) no Palm file ever uses that value; and 2) a Palm
+        decoder should treat it as a no-op and other decoders do.  We don't
+        treat it as a no-op because we believe it is far more likely that if
+        someone _does_ put that value in a file, he means "repeat the next
+        word 129 times" than "do nothing."  Plus, it's just simpler and
+        cleaner.  Because of the ambiguity, though, anyone creating a Palm
+        file should avoid 0x80.
     */
     unsigned int j;
 
     for (j = 0;  j < bytesPerRow; ) {
-        unsigned char incountByte;
-        pm_readcharu(ifP, &incountByte);
-        if (incountByte & 0x80) {
-            int const signedIncount = (signed char)incountByte;
-            /* How do we handle incount == -128 ? */
-            unsigned int const runlength = (-signedIncount + 1) * 2;
-            unsigned int k;
+        unsigned char controlByte;
+        unsigned int  controlNum;
+
+        pm_readcharu(ifP, &controlByte);
+        controlNum = (unsigned int)controlByte;
+
+        if (controlNum >= 128) {
+            /* It's a run - output multiple copies of the next input word */
+            unsigned int const runlength = (257 - controlNum) * 2;
+
             unsigned short inval;
+
             pm_readlittleshortu(ifP, &inval);
+
             if (j + runlength <= bytesPerRow) {
+                unsigned int k;
                 for (k = 0; k < runlength; k += 2)
                     memcpy(palmrow + j + k, &inval, 2);
             }
             j += runlength;
         } else {
+            /* It's a nonrun - output the next words literally */
             /* We just read the stream of shorts as a stream of chars */
-            unsigned int const nonrunlength = (incountByte + 1) * 2;
+            unsigned int const nonrunlength = (controlNum + 1) * 2;
+
             unsigned int k;
+
             for (k = 0; (k < nonrunlength) && (j + k <= bytesPerRow); ++k) {
                 unsigned char inval;
                 pm_readcharu(ifP, &inval);
@@ -863,23 +881,32 @@ readPackBitsRow(FILE *          const ifP,
                 unsigned char * const palmrow,
                 unsigned int    const bytesPerRow) {
 
+    /* See comments in 'readPackbitsRow16.  Everything here is the same
+       except with 1-byte words instead of 2-byte words.
+    */
     unsigned int j;
 
     for (j = 0;  j < bytesPerRow; ) {
-        unsigned char incountByte;
-        pm_readcharu(ifP, &incountByte);
-        if (incountByte & 0x80) {
-            /* How do we handle incount == -128 ? */
-            int const signedIncount = (char)incountByte;
-            unsigned int const runlength = -signedIncount + 1;
+        unsigned char controlByte;
+        unsigned int  controlNum;
+
+        pm_readcharu(ifP, &controlByte);
+        controlNum = controlByte;
+
+        if (controlNum >= 128) {
+            unsigned int const runlength = 257 - controlNum;
+
             unsigned char inval;
+
             pm_readcharu(ifP, &inval);
             if (j + runlength <= bytesPerRow)
                 memset(palmrow + j, inval, runlength);
             j += runlength;
         } else {
-            unsigned int const nonrunlength = incountByte + 1;
+            unsigned int const nonrunlength = controlNum + 1;
+
             unsigned int k;
+
             for (k = 0; k < nonrunlength && j + k <= bytesPerRow; ++k) {
                 unsigned char inval;
                 pm_readcharu(ifP, &inval);
diff --git a/doc/HISTORY b/doc/HISTORY
index f775d24b..f6a2f6fe 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,6 +4,20 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+22.04.24 BJH  Release 10.86.33
+
+              palmtopnm: Fix failure with bogus claim of invalid input on
+              architectures that do not use two's complement negative numbers.
+              Always broken.  (Ability to convert PackBits input was new in
+              Netpbm 10.27 (March 2005).
+
+              pnmgamma -srgbtobt709, -bt709tosrgb: fix bug; incorrect output.
+              Always broken (These options were new in Netpbm 10.32 (February
+              2006)).  Thanks Alexander Shpilkin <ashpilkin@gmail.com>.
+
+              pamdice: Fix incorrect output file name with PAM input.  Always
+              broken (pamdice was new in Netpbm 9.25 (March 2002).
+
 22.03.20 BJH  Release 10.86.32
 
               pamx: Fix bug: top-justifies image in all cases where it should
diff --git a/editor/pamdice.c b/editor/pamdice.c
index 32881129..b478a25a 100644
--- a/editor/pamdice.c
+++ b/editor/pamdice.c
@@ -219,12 +219,14 @@ computeOutputFilenameFormat(int           const format,
 
     const char * filenameSuffix;
 
-    switch(PNM_FORMAT_TYPE(format)) {
+    switch(PAM_FORMAT_TYPE(format)) {
     case PPM_TYPE: filenameSuffix = "ppm"; break;
     case PGM_TYPE: filenameSuffix = "pgm"; break;
     case PBM_TYPE: filenameSuffix = "pbm"; break;
     case PAM_TYPE: filenameSuffix = "pam"; break;
-    default:       filenameSuffix = "";    break;
+    default:
+        pm_error("INTERNAL ERROR: impossible value for libnetpbm image "
+                 "fomat code: %d", format);
     }
     
     pm_asprintf(filenameFormatP, "%%s_%%0%uu_%%0%uu.%s",
diff --git a/editor/pnmgamma.c b/editor/pnmgamma.c
index b357b0d8..0ed217d1 100644
--- a/editor/pnmgamma.c
+++ b/editor/pnmgamma.c
@@ -516,7 +516,7 @@ buildBt709ToSrgbGamma(xelval       table[],
         if (radiance < linearCutoffSrgb * normalizer)
             srgb = radiance * linearExpansionSrgb;
         else
-            srgb = 1.055 * pow(normalized, oneOverGammaSrgb) - 0.055;
+            srgb = 1.055 * pow(radiance, oneOverGammaSrgb) - 0.055;
 
         assert(srgb <= 1.0);
 
@@ -567,14 +567,14 @@ buildSrgbToBt709Gamma(xelval       table[],
         if (i < linearCutoffSrgb / linearCompressionSrgb)
             radiance = normalized * linearCompressionSrgb;
         else
-            radiance = pow((normalized + 0.099) / 1.099, gammaSrgb);
+            radiance = pow((normalized + 0.055) / 1.055, gammaSrgb);
 
         assert(radiance <= 1.0);
 
         if (radiance < linearCutoff709 * normalizer)
             bt709 = radiance * linearExpansion709;
         else
-            bt709 = 1.055 * pow(normalized, oneOverGamma709) - 0.055;
+            bt709 = 1.099 * pow(radiance, oneOverGamma709) - 0.099;
 
         assert(bt709 <= 1.0);
 
diff --git a/version.mk b/version.mk
index ad4cadaf..8253b4b5 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 10
 NETPBM_MINOR_RELEASE = 86
-NETPBM_POINT_RELEASE = 32
+NETPBM_POINT_RELEASE = 33