about summary refs log tree commit diff
path: root/editor
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-01-23 22:16:50 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-01-23 22:16:50 +0000
commit651d68f5652c36fbb260334f1a46a2705d8a0de8 (patch)
tree38e2dc4e32f6083d70543f10bde17a3531ea8691 /editor
parentd87a19306b69fa7e537b265983b54071805a5eb5 (diff)
downloadnetpbm-mirror-651d68f5652c36fbb260334f1a46a2705d8a0de8.tar.gz
netpbm-mirror-651d68f5652c36fbb260334f1a46a2705d8a0de8.tar.xz
netpbm-mirror-651d68f5652c36fbb260334f1a46a2705d8a0de8.zip
Release 10.35.73
git-svn-id: http://svn.code.sf.net/p/netpbm/code/super_stable@1103 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor')
-rw-r--r--editor/pnmconvol.c86
1 files changed, 80 insertions, 6 deletions
diff --git a/editor/pnmconvol.c b/editor/pnmconvol.c
index 0bf44ce3..651b9049 100644
--- a/editor/pnmconvol.c
+++ b/editor/pnmconvol.c
@@ -17,6 +17,8 @@
 
 /* A change history is at the bottom */
 
+#include <assert.h>
+
 #include "pnm.h"
 #include "shhopt.h"
 #include "mallocvar.h"
@@ -1821,11 +1823,86 @@ convolveIt(int                 const format,
 
 
 
+static void
+readKernel(const char * const fileName,
+           int *        const colsP,
+           int *        const rowsP,
+           xelval *     const maxvalP,
+           int *        const formatP,
+           xel ***      const xelsP) {
+/*----------------------------------------------------------------------------
+   Read in the pseudo-PNM that is the convolution matrix.
+
+   This is essentially pnm_readpnm(), 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);
+
+    FILE * fileP;
+    xel ** xels;
+    int cols, rows;
+    xelval maxval;
+    int format;
+    unsigned int row;
+
+    fileP = pm_openr(fileName);
+
+    pnm_readpnminit(fileP, &cols, &rows, &maxval, &format);
+
+    xels = pnm_allocarray(cols, rows);
+
+    for (row = 0; row < rows; ++row) {
+        if (format == PGM_FORMAT || format == PPM_FORMAT) {
+            /* Plain format -- can't use pnm_readpnmrow() because it will
+               reject a sample > maxval
+            */
+            unsigned int col;
+            for (col = 0; col < cols; ++col) {
+                switch (format) {
+                case PGM_FORMAT: {
+                    gray const g = pm_getuint(fileP);
+                    PNM_ASSIGN1(xels[row][col], g);
+                    } break;
+                case PPM_FORMAT: {
+                    pixval const r = pm_getuint(fileP);
+                    pixval const g = pm_getuint(fileP);
+                    pixval const b = pm_getuint(fileP);
+
+                    PNM_ASSIGN(xels[row][col], r, g, b);
+                } break;
+                default:
+                    assert(false);
+                }
+            }
+        } else {
+            /* Raw or PBM format -- pnm_readpnmrow() won't do any maxval
+               checking
+            */
+            pnm_readpnmrow(fileP, xels[row], cols, maxval, format);
+        }
+    }
+    *colsP   = cols;
+    *rowsP   = rows;
+    *maxvalP = maxval;
+    *formatP = format;
+    *xelsP   = xels;
+
+    pm_close(fileP);
+}
+
+
+
 int
 main(int argc, char * argv[]) {
 
     struct cmdlineInfo cmdline;
-    FILE* cifp;
     xel** cxels;
     int cformat;
     xelval cmaxval;
@@ -1838,11 +1915,8 @@ main(int argc, char * argv[]) {
 
     parseCommandLine(argc, argv, &cmdline);
 
-    cifp = pm_openr(cmdline.kernelFilespec);
-
-    /* Read in the convolution matrix. */
-    cxels = pnm_readpnm(cifp, &ccols, &crows, &cmaxval, &cformat);
-    pm_close(cifp);
+    readKernel(cmdline.kernelFilespec,
+               &ccols, &crows, &cmaxval, &cformat, &cxels);
 
     if (ccols % 2 != 1 || crows % 2 != 1)
         pm_error("the convolution matrix must have an odd number of "