From e347b7e20b3b65dc782f3ad50a2fa5c605ca7965 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Fri, 3 May 2013 17:05:44 +0000 Subject: Fix bug - row index incremented before use; should be after git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1895 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- analyzer/pamtilt.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'analyzer/pamtilt.c') diff --git a/analyzer/pamtilt.c b/analyzer/pamtilt.c index 5b571848..935ea98b 100644 --- a/analyzer/pamtilt.c +++ b/analyzer/pamtilt.c @@ -211,9 +211,32 @@ replacePixelValuesWithScaledDiffs( +static unsigned long +totalBrightness(sample ** const pixelWindow, + unsigned int const hsampleCt, + float const dy) { +/*---------------------------------------------------------------------------- + Total brightness of samples in the line that goes from the top left corner + of 'pixelWindow' down to the right at 'dy' rows per column. +-----------------------------------------------------------------------------*/ + unsigned long total; + unsigned int i; + float rowOffset; + + for (i = 0, rowOffset = 0.5, total = 0; + i < hsampleCt; + ++i, rowOffset += dy) { + + total += pixelWindow[(unsigned)rowOffset][i]; + } + return total; +} + + + static void scoreAngleRegion(sample ** const pixels, - unsigned int const hsamples, + unsigned int const hsampleCt, unsigned int const startRow, unsigned int const endRow, unsigned int const vstep, @@ -231,7 +254,7 @@ scoreAngleRegion(sample ** const pixels, Instead of a tilt angle, we have 'dy', the slope (downward) of the lines in our assumed tilt. -----------------------------------------------------------------------------*/ - double const tscale = 1.0 / hsamples; + double const tscale = 1.0 / hsampleCt; unsigned int row; double sum; @@ -242,17 +265,10 @@ scoreAngleRegion(sample ** const pixels, /* Number of lines that went into 'total' */ for (row = startRow, sum = 0.0, n = 0; row < endRow; row += vstep) { - float o; - long t; /* total brightness of the samples in the line */ - double dt; /* mean brightness of the samples in the line */ + double const dt = + tscale * totalBrightness(&pixels[row], hsampleCt, dy); + /* mean brightness of the samples in the line */ - unsigned int i; - - for (i = 0, t = 0, o = 0.5; - i < hsamples; - ++i, t += pixels[(int)(row + o)][i], o += dy) { - } - dt = tscale * t; sum += dt * dt; n += 1; } -- cgit 1.4.1