about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--analyzer/pamtilt.c40
-rw-r--r--doc/HISTORY4
2 files changed, 32 insertions, 12 deletions
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;
     }
diff --git a/doc/HISTORY b/doc/HISTORY
index 721da7ed..4fe3d939 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -12,6 +12,10 @@ not yet  BJH  Release 10.63.00
               Perl programs: make them shell programs that reinvoke themselves
               as perl so we can get the Perl interpreter from the PATH.
 
+              pamtilt: fix bug: incorrect output or invalid memory access
+              crash.  Always broken (program was new in Neptbm 10.30
+              (October 2005)).
+
               pnmpsnr: fix bug: says types aren't the same when they are.
               Introduced in 10.61 (December 2012).