diff options
-rw-r--r-- | Makefile.common | 2 | ||||
-rw-r--r-- | Makefile.version | 2 | ||||
-rw-r--r-- | analyzer/pgmtexture.c | 7 | ||||
-rw-r--r-- | doc/HISTORY | 13 | ||||
-rw-r--r-- | editor/pamscale.c | 46 | ||||
-rw-r--r-- | lib/util/nstring.c | 1 |
6 files changed, 44 insertions, 27 deletions
diff --git a/Makefile.common b/Makefile.common index 29465892..5067e23f 100644 --- a/Makefile.common +++ b/Makefile.common @@ -68,7 +68,7 @@ include $(SRCDIR)/Makefile.version -INCLUDES2 := $(INCLUDES) -I$(SRCDIR)/$(SUBDIR) -I. -I importinc +INCLUDES2 := -I$(SRCDIR)/$(SUBDIR) -I. -I importinc $(INCLUDES) ifeq ($(NETPBMLIBTYPE),unixstatic) NETPBMLIBFNAME = libnetpbm.$(STATICLIBSUFFIX) diff --git a/Makefile.version b/Makefile.version index ae0fc7bc..516bd9df 100644 --- a/Makefile.version +++ b/Makefile.version @@ -1,3 +1,3 @@ NETPBM_MAJOR_RELEASE = 10 NETPBM_MINOR_RELEASE = 35 -NETPBM_POINT_RELEASE = 83 +NETPBM_POINT_RELEASE = 84 diff --git a/analyzer/pgmtexture.c b/analyzer/pgmtexture.c index 9fb80950..6a9f5a4f 100644 --- a/analyzer/pgmtexture.c +++ b/analyzer/pgmtexture.c @@ -542,7 +542,7 @@ f5_idm (float **P, int Ng) } static float -Pxpy[2 * PGM_MAXMAXVAL]; +Pxpy[2 * (PGM_MAXMAXVAL+1) + 1]; static float f6_savg (float **P, int Ng) @@ -627,8 +627,9 @@ f10_dvar (float **P, int Ng) /* Difference Variance */ { - int i, j, tmp; - float sum = 0, sum_sqr = 0, var = 0; + int i, j; + double tmp; + double sum = 0, sum_sqr = 0, var = 0; for (i = 0; i <= 2 * Ng; ++i) Pxpy[i] = 0; diff --git a/doc/HISTORY b/doc/HISTORY index 9c51e529..a4929f31 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -4,6 +4,19 @@ Netpbm. CHANGE HISTORY -------------- +12.02.14 BJH Release 10.35.84 + + pamscale: fix all black output with resampling. Always broken. + + pgmtexture: fix integer overflow in difference variance. + Always broken. + + pgmtexture: fix array bounds violations in various calculations. + Always broken. + + Build: always put Netpbm header files before external library + header files in search path. + 11.11.25 BJH Release 10.35.83 pngtopnm: fix crash with invalid tIME chunk. Always broken. diff --git a/editor/pamscale.c b/editor/pamscale.c index 5136c2cd..16bd8819 100644 --- a/editor/pamscale.c +++ b/editor/pamscale.c @@ -916,8 +916,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 @@ -928,7 +928,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)))); } @@ -1261,8 +1261,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. @@ -1270,18 +1271,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; } } @@ -1297,22 +1295,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); } } @@ -1336,7 +1335,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; @@ -1346,6 +1345,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]; @@ -1476,9 +1480,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/lib/util/nstring.c b/lib/util/nstring.c index 702a3c44..61acd061 100644 --- a/lib/util/nstring.c +++ b/lib/util/nstring.c @@ -769,7 +769,6 @@ asprintfN(const char ** const resultP, *resultP = strsol; else { size_t const allocSize = dryRunLen + 1; - char * result; result = malloc(allocSize); if (result == NULL) *resultP = strsol; |