From 7e51994ff76dd2f4efcf0eb599c7e35a132c9855 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 10 May 2008 23:38:23 +0000 Subject: Do alpha git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@625 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- editor/pamthreshold.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'editor/pamthreshold.c') 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); -- cgit 1.4.1