From 7bd77004a7a252e5e33309944e04e70dc7fd8c46 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Mon, 11 Sep 2006 02:38:48 +0000 Subject: Fast path for local thresholding: don't compute unneeded global stuff git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@53 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- editor/pamthreshold.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'editor/pamthreshold.c') diff --git a/editor/pamthreshold.c b/editor/pamthreshold.c index 40260e79..4caaed9b 100644 --- a/editor/pamthreshold.c +++ b/editor/pamthreshold.c @@ -508,9 +508,16 @@ thresholdLocal(struct pam * const inpamP, windowHeight = MIN(oddLocalHeight, inpamP->height); - analyzeDistribution(inpamP, &histogram, &globalRange); - - computeGlobalThreshold(inpamP, histogram, globalRange, &globalThreshold); + /* global information is needed for dual thresholding */ + if (cmdline.dual) { + analyzeDistribution(inpamP, &histogram, &globalRange); + computeGlobalThreshold(inpamP, histogram, globalRange, + &globalThreshold); + } else { + histogram = NULL; + initRange(&globalRange); + globalThreshold = 1.0; + } outrow = pnm_allocpamrow(outpamP); @@ -580,17 +587,17 @@ main(int argc, char **argv) { parseCommandLine(argc, argv, &cmdline); - if (cmdline.simple) + if (cmdline.simple || cmdline.local) ifP = pm_openr(cmdline.inputFileName); else ifP = pm_openr_seekable(cmdline.inputFileName); - /* threshold each image in the PAM file */ + /* Threshold each image in the PAM file */ eof = FALSE; while (!eof) { pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); - /* set output image parameters for a bilevel image */ + /* Set output image parameters for a bilevel image */ outpam.size = sizeof(outpam); outpam.len = PAM_STRUCT_SIZE(tuple_type); outpam.file = stdout; @@ -605,7 +612,7 @@ main(int argc, char **argv) { pnm_writepaminit(&outpam); - /* do the thresholding */ + /* Do the thresholding */ if (cmdline.simple) thresholdSimple(&inpam, &outpam, cmdline.threshold); -- cgit 1.4.1