about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2011-12-12 00:33:59 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2011-12-12 00:33:59 +0000
commit07907eea94e6d1c66e2128127f6e90cc5204719b (patch)
treecce71e35958e9dd05b5953922caa79c8f0117ba1
parent6f30676c346820f3741b3fbe9691ac3e65bb10dd (diff)
downloadnetpbm-mirror-07907eea94e6d1c66e2128127f6e90cc5204719b.tar.gz
netpbm-mirror-07907eea94e6d1c66e2128127f6e90cc5204719b.tar.xz
netpbm-mirror-07907eea94e6d1c66e2128127f6e90cc5204719b.zip
Release 10.56.05
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@1607 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY6
-rw-r--r--editor/pamscale.c46
-rw-r--r--editor/specialty/pampaintspill.c1
-rw-r--r--version.mk2
4 files changed, 32 insertions, 23 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index 288a37db..96591cb7 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,6 +4,12 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+11.11.12 BJH  Release 10.56.05
+
+              pamscale: fix all black output with resampling.  Always broken.
+
+              Build: don't use <alloca.h>.
+
 11.11.22 BJH  Release 10.56.04
 
               pngtopam: fix crash with invalid tIME chunk.  Always broken.
diff --git a/editor/pamscale.c b/editor/pamscale.c
index 5b4fe9ff..9e613fc5 100644
--- a/editor/pamscale.c
+++ b/editor/pamscale.c
@@ -968,8 +968,8 @@ appendWeight(WLIST * const WList,
 
 
 static sample
-floatToSample(double const value,
-              sample const maxval) {
+unnormalize(double const normalized,
+            sample const maxval) {
 
     /* Take care here, the conversion of any floating point value <=
        -1.0 to an unsigned type is _undefined_.  See ISO 9899:1999
@@ -980,7 +980,7 @@ floatToSample(double const value,
        weights.  
     */
 
-    return MIN(maxval, (sample)(MAX(0.0, (value + 0.5))));
+    return MIN(maxval, (sample)(MAX(0.0, (normalized*maxval + 0.5))));
 }
 
 
@@ -1313,8 +1313,9 @@ addInPixel(const struct pam * const pamP,
            unsigned int       const opacityPlane,
            double *           const accum) {
 /*----------------------------------------------------------------------------
-  Add into *accum the values from the tuple 'tuple', weighted by
-  'weight'.
+  Add into accum[] the values from the tuple 'tuple', weighted by 'weight'.
+
+  accum[P] is the accumulated normalized sample value for Plane P.
 
   Iff 'haveOpacity', Plane 'opacityPlane' of the tuple is an opacity
   (alpha, transparency) plane.
@@ -1322,18 +1323,15 @@ addInPixel(const struct pam * const pamP,
     unsigned int plane;
 
     for (plane = 0; plane < pamP->depth; ++plane) {
-        sample adjustedForOpacity;
+        double const normalizedSample = (double)tuple[plane]/pamP->maxval;
+        double opacityAdjustment;
         
-        if (haveOpacity && plane != opacityPlane) {
-            float const opacity = (float)tuple[opacityPlane]/pamP->maxval;
-            float const unadjusted = (float)tuple[plane]/pamP->maxval;
-
-            adjustedForOpacity = 
-                floatToSample(unadjusted * opacity, pamP->maxval);
-        } else
-            adjustedForOpacity = tuple[plane];
+        if (haveOpacity && plane != opacityPlane)
+            opacityAdjustment = (double)tuple[opacityPlane]/pamP->maxval;
+        else
+            opacityAdjustment = 1;
         
-        accum[plane] += (double)adjustedForOpacity * weight;
+        accum[plane] += opacityAdjustment * normalizedSample * weight;
     }
 }
 
@@ -1349,22 +1347,23 @@ generateOutputTuple(const struct pam * const pamP,
   Convert the values accum[] accumulated for a pixel by
   outputOneResampledRow() to a bona fide PAM tuple as *tupleP,
   as described by *pamP.
+
+  accum[P] is the pixel's plane P value normalized (i.e. in range 0..1).
 -----------------------------------------------------------------------------*/
     unsigned int plane;
 
     for (plane = 0; plane < pamP->depth; ++plane) {
-        float opacityAdjustedSample;
+        float opacityAdjustedSample;  /* normalized sample value */
 
         if (haveOpacity && plane != opacityPlane) {
             if (accum[opacityPlane] < EPSILON) {
-                assert(accum[plane] < EPSILON);
                 opacityAdjustedSample = 0.0;
             } else 
                 opacityAdjustedSample = accum[plane] / accum[opacityPlane];
         } else
             opacityAdjustedSample = accum[plane];
 
-        (*tupleP)[plane] = floatToSample(opacityAdjustedSample, pamP->maxval);
+        (*tupleP)[plane] = unnormalize(opacityAdjustedSample, pamP->maxval);
     }
 }
 
@@ -1388,7 +1387,7 @@ outputOneResampledRow(const struct pam * const outpamP,
 
    'line' and 'accum' are just working space that Caller provides us
    with to save us the time of allocating it.  'line' is at least big
-   enough to hold an output row; 'weight' is at least outpamP->depth
+   enough to hold an output row; 'accum' is at least outpamP->depth
    big.
 -----------------------------------------------------------------------------*/
     unsigned int col;
@@ -1398,6 +1397,11 @@ outputOneResampledRow(const struct pam * const outpamP,
 
     pnm_getopacity(outpamP, &haveOpacity, &opacityPlane);
 
+    /* We accumulate intensity in accum[], where accum[P] is the intensity
+       for Plane P.  These are normalized values (i.e. in the range
+       0..1
+    */
+
     for (col = 0; col < outpamP->width; ++col) {
         WLIST const XW = XWeight[col];
 
@@ -1528,9 +1532,9 @@ resample(struct pam *     const inpamP,
     unsigned int maxRowWeights;
 
     tuple * line;
-        /* This is just work space for outputOneSampleRow() */
+        /* This is just work space for outputOneResampledRow() */
     double * weight;
-        /* This is just work space for outputOneSampleRow() */
+        /* This is just work space for outputOneResampledRow() */
 
     if (linear)
         pm_error("You cannot use the resampling scaling method on "
diff --git a/editor/specialty/pampaintspill.c b/editor/specialty/pampaintspill.c
index 449401ed..f9fe53c4 100644
--- a/editor/specialty/pampaintspill.c
+++ b/editor/specialty/pampaintspill.c
@@ -42,7 +42,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
-#include <alloca.h>
 #include <time.h>
 
 #include "mallocvar.h"
diff --git a/version.mk b/version.mk
index 01dd228e..c48a3a20 100644
--- a/version.mk
+++ b/version.mk
@@ -1,4 +1,4 @@
 NETPBM_MAJOR_RELEASE = 10
 NETPBM_MINOR_RELEASE = 56
-NETPBM_POINT_RELEASE = 4
+NETPBM_POINT_RELEASE = 5