about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-12-05 20:20:19 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-12-05 20:20:19 +0000
commitd21c9b3ce1847ee69ace9603aced3c35fbedfeee (patch)
tree79a3b5d9d34c66aefb27e7b4724e5f9270dd7a09
parent27ee1afa95561c5142d19cbee516fbc963743af4 (diff)
downloadnetpbm-mirror-d21c9b3ce1847ee69ace9603aced3c35fbedfeee.tar.gz
netpbm-mirror-d21c9b3ce1847ee69ace9603aced3c35fbedfeee.tar.xz
netpbm-mirror-d21c9b3ce1847ee69ace9603aced3c35fbedfeee.zip
Release 11.04.05
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@4800 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY8
-rw-r--r--editor/pnmconvol.c62
-rw-r--r--version.mk2
3 files changed, 70 insertions, 2 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index 4995ede5..afb58838 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,6 +4,14 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+23.12.05 BJH  Release 11.04.05
+
+              pnmconvol: Restore ability of convolution matrix to be a
+              pseudo-plain-PNM with samples that exceed the maxval.  Lost in
+              10.30 (October 2005) because maxval-checking code was added to
+              libnetpbm.  (Was fixed in 10.47.08 in November 2010, but only in
+              the 10.47 series).
+
 23.11.14 BJH  Release 11.04.04
 
               pnmpad: fix wrong results with old-style options (e.g. "-t50").
diff --git a/editor/pnmconvol.c b/editor/pnmconvol.c
index fcd52bea..981797c7 100644
--- a/editor/pnmconvol.c
+++ b/editor/pnmconvol.c
@@ -617,6 +617,64 @@ normalizeKernel(struct ConvKernel * const convKernelP) {
 
 
 static void
+readPseudoPnmKernel(FILE *       const fileP,
+                    struct pam * const pamP,
+                    tuple ***    const tuplesP) {
+/*----------------------------------------------------------------------------
+   Read in the pseudo-PNM that is the convolution matrix.
+
+   This is essentially pnm_readpam(), except that it can take sample values
+   that exceed the maxval, which is not legal in PNM.  That's why it's
+   psuedo-PNM and not true PNM.
+-----------------------------------------------------------------------------*/
+
+    /* pm_getuint() is supposed to be internal to libnetpbm, but since we're
+       doing this backward compatibility hack here, we use it anyway.
+    */
+
+    unsigned int
+    pm_getuint(FILE * const file);
+
+    tuple ** tuples;
+    unsigned int row;
+
+    pnm_readpaminit(fileP, pamP, PAM_STRUCT_SIZE(tuple_type));
+
+    tuples = pnm_allocpamarray(pamP);
+
+    for (row = 0; row < pamP->height; ++row) {
+        if (pamP->format == PGM_FORMAT || pamP->format == PPM_FORMAT) {
+            /* Plain format -- can't use pnm_readpnmrow() because it will
+               reject a sample > maxval
+            */
+            unsigned int col;
+            for (col = 0; col < pamP->width; ++col) {
+                switch (pamP->format) {
+                case PGM_FORMAT:
+                    tuples[row][col][0] = pm_getuint(fileP);
+                    break;
+                case PPM_FORMAT:
+                    tuples[row][col][PAM_RED_PLANE] = pm_getuint(fileP);
+                    tuples[row][col][PAM_GRN_PLANE] = pm_getuint(fileP);
+                    tuples[row][col][PAM_BLU_PLANE] = pm_getuint(fileP);
+                    break;
+                default:
+                    assert(false);
+                }
+            }
+        } else {
+            /* Raw or PBM format -- pnm_readpnmrow() won't do any maxval
+               checking
+            */
+            pnm_readpamrow(pamP, tuples[row]);
+        }
+    }
+    *tuplesP = tuples;
+}
+
+
+
+static void
 getKernelPnm(const char *         const fileName,
              unsigned int         const depth,
              bool                 const offset,
@@ -639,12 +697,14 @@ getKernelPnm(const char *         const fileName,
     cifP = pm_openr(fileName);
 
     /* Read in the convolution matrix. */
-    ctuples = pnm_readpam(cifP, &cpam, PAM_STRUCT_SIZE(tuple_type));
+    readPseudoPnmKernel(cifP, &cpam, &ctuples);
     pm_close(cifP);
 
     validateKernelDimensions(cpam.width, cpam.height);
 
     convKernelCreatePnm(&cpam, ctuples, depth, offset, convKernelPP);
+
+    pnm_freepamarray(ctuples, &cpam);
 }
 
 
diff --git a/version.mk b/version.mk
index ff707ef6..67b46cf7 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 11
 NETPBM_MINOR_RELEASE = 4
-NETPBM_POINT_RELEASE = 4
+NETPBM_POINT_RELEASE = 5