diff options
Diffstat (limited to 'editor/pamthreshold.c')
-rw-r--r-- | editor/pamthreshold.c | 37 |
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); |