about summary refs log tree commit diff
path: root/editor/pamthreshold.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-05-10 23:38:23 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-05-10 23:38:23 +0000
commit7e51994ff76dd2f4efcf0eb599c7e35a132c9855 (patch)
tree7a121d38a18b1ce1407b8214c8d200f1a1379b96 /editor/pamthreshold.c
parent1a47b7a701d4e4cd61fb7fbdc87584f062df4de4 (diff)
downloadnetpbm-mirror-7e51994ff76dd2f4efcf0eb599c7e35a132c9855.tar.gz
netpbm-mirror-7e51994ff76dd2f4efcf0eb599c7e35a132c9855.tar.xz
netpbm-mirror-7e51994ff76dd2f4efcf0eb599c7e35a132c9855.zip
Do alpha
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@625 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor/pamthreshold.c')
-rw-r--r--editor/pamthreshold.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/editor/pamthreshold.c b/editor/pamthreshold.c
index e6eed864..428b819d 100644
--- a/editor/pamthreshold.c
+++ b/editor/pamthreshold.c
@@ -222,6 +222,21 @@ parseCommandLine(int                 argc,
 
 
 
+static void
+thresholdPixel(struct pam * const outpamP,
+               tuplen       const inTuplen,
+               tuple        const outTuple,
+               float        const threshold) {
+
+    outTuple[0] = inTuplen[0] >= threshold ? PAM_BW_WHITE : PAM_BLACK;
+    if (outpamP->depth > 1) {
+        /* Do alpha */
+        outTuple[1] = inTuplen[1] > 0.5 ? 1 : 0;
+    }
+}
+
+
+
 /* simple thresholding (the same as in pamditherbw) */
 
 static void
@@ -240,9 +255,9 @@ thresholdSimple(struct pam * const inpamP,
     for (row = 0; row < inpamP->height; ++row) {
         unsigned int col;
         pnm_readpamrown(inpamP, inrow);
-        for (col = 0; col < inpamP->width; ++col)
-            outrow[col][0] =
-                inrow[col][0] >= threshold ? PAM_BW_WHITE : PAM_BLACK;
+        for (col = 0; col < inpamP->width; ++col) {
+            thresholdPixel(outpamP, inrow[col], outrow[col], threshold);
+        }
         pnm_writepamrow(outpamP, outrow);
     }
 
@@ -489,6 +504,7 @@ thresholdLocalRow(struct pam *       const inpamP,
                   struct cmdlineInfo const cmdline,
                   struct range       const globalRange,
                   samplen            const globalThreshold,
+                  struct pam *       const outpamP,
                   tuple *            const outrow) {
 
     tuplen * const inrow = inrows[row % windowHeight];
@@ -508,7 +524,7 @@ thresholdLocalRow(struct pam *       const inpamP,
                           cmdline.threshold, minSpread, globalThreshold,
                           &threshold);
         
-        outrow[col][0] = inrow[col][0] >= threshold ? PAM_BW_WHITE : PAM_BLACK;
+        thresholdPixel(outpamP, inrow[col], outrow[col], threshold);
     }
 }
 
@@ -595,7 +611,8 @@ thresholdLocal(struct pam *       const inpamP,
 
     for (row = 0; row < inpamP->height; ++row) {
         thresholdLocalRow(inpamP, inrows, oddLocalWidth, windowHeight, row,
-                          cmdline, globalRange, globalThreshold, outrow);
+                          cmdline, globalRange, globalThreshold,
+                          outpamP, outrow);
 
         pnm_writepamrow(outpamP, outrow);
         
@@ -664,10 +681,16 @@ main(int argc, char **argv) {
         outpam.plainformat = 0;
         outpam.height      = inpam.height;
         outpam.width       = inpam.width;
-        outpam.depth       = 1;
         outpam.maxval      = 1;
         outpam.bytes_per_sample = 1;
-        strcpy(outpam.tuple_type, "BLACKANDWHITE");
+
+        if (inpam.depth > 1) {
+            strcpy(outpam.tuple_type, "BLACKANDWHITE_ALPHA");
+            outpam.depth = 2;
+        } else {
+            strcpy(outpam.tuple_type, "BLACKANDWHITE");
+            outpam.depth = 1;
+        }
 
         pnm_writepaminit(&outpam);