about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2024-10-23 19:39:55 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2024-10-23 19:39:55 +0000
commitf729c8566b4622350a1bad2c11eb38cae06c8bc0 (patch)
tree52ad9662f50071604a477094ac6630646c9f7bdb
parentea0ca6c83af94fed16a0778324fbb31bb498ae5e (diff)
downloadnetpbm-mirror-advanced.tar.gz
netpbm-mirror-advanced.tar.xz
netpbm-mirror-advanced.zip
Release 11.08.01 advanced
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@4966 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/pbm/pbmtoascii.c36
-rw-r--r--converter/ppm/pcxtoppm.c38
-rw-r--r--doc/HISTORY8
-rw-r--r--version.mk2
4 files changed, 62 insertions, 22 deletions
diff --git a/converter/pbm/pbmtoascii.c b/converter/pbm/pbmtoascii.c
index 634bea67..8a9710b6 100644
--- a/converter/pbm/pbmtoascii.c
+++ b/converter/pbm/pbmtoascii.c
@@ -13,6 +13,7 @@
 #include <assert.h>
 #include "mallocvar.h"
 #include "pbm.h"
+#include "pm_c_util.h"
 
 /*
   The algorithm is based on describing the 2 or 8 pixels in a cell with a
@@ -236,6 +237,8 @@ main(int argc, const char ** argv) {
     int argn, gridx, gridy;
     const char * carr;
     const char* usage = "[-1x2|-2x4] [pbmfile]";
+    bool carr1x2Spec = false; /* Initial value */
+    bool carr2x4Spec = false; /* Initial value */
 
     pm_proginit(&argc, argv);
 
@@ -243,25 +246,18 @@ main(int argc, const char ** argv) {
     argn = 1;
     gridx = 1;
     gridy = 2;
-    carr = carr1x2;
 
     /* Check for flags. */
-    while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
-    {
+    while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' ) {
         if ( pm_keymatch( argv[argn], "-1x2", 2 ) )
-        {
-            gridx = 1;
-            gridy = 2;
-            carr = carr1x2;
-        }
+            carr1x2Spec = true;
+
         else if ( pm_keymatch( argv[argn], "-2x4", 2 ) )
-        {
-            gridx = 2;
-            gridy = 4;
-            carr = carr2x4;
-        }
+            carr2x4Spec = true;
+
         else
             pm_usage( usage );
+
         ++argn;
     }
 
@@ -276,6 +272,20 @@ main(int argc, const char ** argv) {
     if ( argn != argc )
         pm_usage( usage );
 
+    if ( carr1x2Spec == true && carr2x4Spec == true) {
+            pm_error("You cannot specify both -1x2 and -2x4");
+    }
+    else if (carr2x4Spec == true) {
+            gridx = 2;
+            gridy = 4;
+            carr = carr2x4;
+    }
+    else {
+            gridx = 1;
+            gridy = 2;
+            carr = carr1x2;
+    }
+
     pbmtoascii(ifP, gridx, gridy, carr);
 
     pm_close(ifP);
diff --git a/converter/ppm/pcxtoppm.c b/converter/ppm/pcxtoppm.c
index f06dd4e8..8341cf18 100644
--- a/converter/ppm/pcxtoppm.c
+++ b/converter/ppm/pcxtoppm.c
@@ -363,9 +363,25 @@ pcxPlanesToPixels(unsigned char * const pixels,
                   unsigned int    const planes,
                   unsigned int    const bitsPerPixel) {
 /*----------------------------------------------------------------------------
-   Convert multi-plane format into 1 pixel per byte.
+   Unpack sub-byte sample values to yield one byte per pixel.
+
+   As input, 'bitPlanes' is a row of the image.  Each byte contains 8 samples,
+   one per bit.  They are arranged in plane major, column minor order, e.g.
+   in a 100-column image, the Plane 1 samples of the Columns 0-8 are in
+   bitPlanes[100].
+
+   As output, each byte of 'pixels' is one pixel, in major order by column and
+   minor order by plane, e.g. in a 4-plane image, pixels[5] is the Plane 1 of
+   Column 1.
+
+   'bitsPerPixel' is the number of bits per sample, and must be 1.  It's easy
+   to conceive how this subroutine should work with other numbers of bits per
+   sample, but it doesn't.
 -----------------------------------------------------------------------------*/
-    unsigned int const npixels = (bytesPerLine * 8) / bitsPerPixel;
+    unsigned int const pixelCt = bytesPerLine * 8;
+
+    unsigned int bitPlanesIdx;
+        /* Index into 'bitPlanes' of next byte to unpack */
 
     unsigned int  i;
 
@@ -375,23 +391,29 @@ pcxPlanesToPixels(unsigned char * const pixels,
         pm_error("can't handle more than 1 bit per pixel");
 
     /* Clear the pixel buffer - initial value */
-    for (i = 0; i < npixels; ++i)
+    for (i = 0; i < pixelCt; ++i)
         pixels[i] = 0;
 
+    bitPlanesIdx = 0;  /* initial value */
+
     for (i = 0; i < planes; ++i) {
         unsigned int const pixbit = (1 << i);
 
+        unsigned int pixelIdx;
+            /* Index into 'pixels' of next pixel to output */
+
         unsigned int j;
 
-        for (j = 0; j < bytesPerLine; ++j) {
-            unsigned int const bits = bitPlanes[j];
+        for (j = 0, pixelIdx = 0; j < bytesPerLine; ++j) {
+            unsigned int const bits = bitPlanes[bitPlanesIdx++];
 
             unsigned int mask;
-            unsigned int k;
 
-            for (mask = 0x80, k = 0; mask != 0; mask >>= 1, ++k)
+            for (mask = 0x80; mask != 0; mask >>= 1) {
                 if (bits & mask)
-                    pixels[k] |= pixbit;
+                    pixels[pixelIdx] |= pixbit;
+                ++pixelIdx;
+            }
         }
     }
 }
diff --git a/doc/HISTORY b/doc/HISTORY
index d19b571c..e4b0aa20 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,6 +4,14 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+24.10.23 BJH  Release 11.08.01
+
+              pcxtoppm: Fix wildly incorrect output for all multiplane
+              images.  Broken in Netpbm 11.04 (September 2023).
+
+              pbmtoascii: fix bug: allows both -1x2 and -2x4.  Always present
+              (pbmtoascii existed in primordial Netpbm).
+
 24.09.29 BJH  Release 11.08.00
 
               libnetpbm color name parsing: Fix handling of rgb: color names
diff --git a/version.mk b/version.mk
index 052a80e4..1573449f 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 11
 NETPBM_MINOR_RELEASE = 8
-NETPBM_POINT_RELEASE = 0
+NETPBM_POINT_RELEASE = 1