From c34b30147e111cb445ade4552d2d9fe53fc41eba Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 24 Apr 2022 00:55:52 +0000 Subject: Release 10.86.33 git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@4328 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/pnmtopalm/palmtopnm.c | 57 ++++++++++++++++++++++++++--------- doc/HISTORY | 14 +++++++++ editor/pamdice.c | 6 ++-- editor/pnmgamma.c | 6 ++-- version.mk | 2 +- 5 files changed, 64 insertions(+), 21 deletions(-) diff --git a/converter/other/pnmtopalm/palmtopnm.c b/converter/other/pnmtopalm/palmtopnm.c index f202ccfc..0666141d 100644 --- a/converter/other/pnmtopalm/palmtopnm.c +++ b/converter/other/pnmtopalm/palmtopnm.c @@ -819,28 +819,46 @@ readPackBitsRow16(FILE * const ifP, Although the [...] spec is byte-oriented, the 16-bit algorithm is identical [to the 8-bit algorithm]: just substitute "word" for "byte". + + A note about the 0x80 control byte value: There are some sources that + suggest that 1) no Palm file ever uses that value; and 2) a Palm + decoder should treat it as a no-op and other decoders do. We don't + treat it as a no-op because we believe it is far more likely that if + someone _does_ put that value in a file, he means "repeat the next + word 129 times" than "do nothing." Plus, it's just simpler and + cleaner. Because of the ambiguity, though, anyone creating a Palm + file should avoid 0x80. */ unsigned int j; for (j = 0; j < bytesPerRow; ) { - unsigned char incountByte; - pm_readcharu(ifP, &incountByte); - if (incountByte & 0x80) { - int const signedIncount = (signed char)incountByte; - /* How do we handle incount == -128 ? */ - unsigned int const runlength = (-signedIncount + 1) * 2; - unsigned int k; + unsigned char controlByte; + unsigned int controlNum; + + pm_readcharu(ifP, &controlByte); + controlNum = (unsigned int)controlByte; + + if (controlNum >= 128) { + /* It's a run - output multiple copies of the next input word */ + unsigned int const runlength = (257 - controlNum) * 2; + unsigned short inval; + pm_readlittleshortu(ifP, &inval); + if (j + runlength <= bytesPerRow) { + unsigned int k; for (k = 0; k < runlength; k += 2) memcpy(palmrow + j + k, &inval, 2); } j += runlength; } else { + /* It's a nonrun - output the next words literally */ /* We just read the stream of shorts as a stream of chars */ - unsigned int const nonrunlength = (incountByte + 1) * 2; + unsigned int const nonrunlength = (controlNum + 1) * 2; + unsigned int k; + for (k = 0; (k < nonrunlength) && (j + k <= bytesPerRow); ++k) { unsigned char inval; pm_readcharu(ifP, &inval); @@ -863,23 +881,32 @@ readPackBitsRow(FILE * const ifP, unsigned char * const palmrow, unsigned int const bytesPerRow) { + /* See comments in 'readPackbitsRow16. Everything here is the same + except with 1-byte words instead of 2-byte words. + */ unsigned int j; for (j = 0; j < bytesPerRow; ) { - unsigned char incountByte; - pm_readcharu(ifP, &incountByte); - if (incountByte & 0x80) { - /* How do we handle incount == -128 ? */ - int const signedIncount = (char)incountByte; - unsigned int const runlength = -signedIncount + 1; + unsigned char controlByte; + unsigned int controlNum; + + pm_readcharu(ifP, &controlByte); + controlNum = controlByte; + + if (controlNum >= 128) { + unsigned int const runlength = 257 - controlNum; + unsigned char inval; + pm_readcharu(ifP, &inval); if (j + runlength <= bytesPerRow) memset(palmrow + j, inval, runlength); j += runlength; } else { - unsigned int const nonrunlength = incountByte + 1; + unsigned int const nonrunlength = controlNum + 1; + unsigned int k; + for (k = 0; k < nonrunlength && j + k <= bytesPerRow; ++k) { unsigned char inval; pm_readcharu(ifP, &inval); diff --git a/doc/HISTORY b/doc/HISTORY index f775d24b..f6a2f6fe 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -4,6 +4,20 @@ Netpbm. CHANGE HISTORY -------------- +22.04.24 BJH Release 10.86.33 + + palmtopnm: Fix failure with bogus claim of invalid input on + architectures that do not use two's complement negative numbers. + Always broken. (Ability to convert PackBits input was new in + Netpbm 10.27 (March 2005). + + pnmgamma -srgbtobt709, -bt709tosrgb: fix bug; incorrect output. + Always broken (These options were new in Netpbm 10.32 (February + 2006)). Thanks Alexander Shpilkin . + + pamdice: Fix incorrect output file name with PAM input. Always + broken (pamdice was new in Netpbm 9.25 (March 2002). + 22.03.20 BJH Release 10.86.32 pamx: Fix bug: top-justifies image in all cases where it should diff --git a/editor/pamdice.c b/editor/pamdice.c index 32881129..b478a25a 100644 --- a/editor/pamdice.c +++ b/editor/pamdice.c @@ -219,12 +219,14 @@ computeOutputFilenameFormat(int const format, const char * filenameSuffix; - switch(PNM_FORMAT_TYPE(format)) { + switch(PAM_FORMAT_TYPE(format)) { case PPM_TYPE: filenameSuffix = "ppm"; break; case PGM_TYPE: filenameSuffix = "pgm"; break; case PBM_TYPE: filenameSuffix = "pbm"; break; case PAM_TYPE: filenameSuffix = "pam"; break; - default: filenameSuffix = ""; break; + default: + pm_error("INTERNAL ERROR: impossible value for libnetpbm image " + "fomat code: %d", format); } pm_asprintf(filenameFormatP, "%%s_%%0%uu_%%0%uu.%s", diff --git a/editor/pnmgamma.c b/editor/pnmgamma.c index b357b0d8..0ed217d1 100644 --- a/editor/pnmgamma.c +++ b/editor/pnmgamma.c @@ -516,7 +516,7 @@ buildBt709ToSrgbGamma(xelval table[], if (radiance < linearCutoffSrgb * normalizer) srgb = radiance * linearExpansionSrgb; else - srgb = 1.055 * pow(normalized, oneOverGammaSrgb) - 0.055; + srgb = 1.055 * pow(radiance, oneOverGammaSrgb) - 0.055; assert(srgb <= 1.0); @@ -567,14 +567,14 @@ buildSrgbToBt709Gamma(xelval table[], if (i < linearCutoffSrgb / linearCompressionSrgb) radiance = normalized * linearCompressionSrgb; else - radiance = pow((normalized + 0.099) / 1.099, gammaSrgb); + radiance = pow((normalized + 0.055) / 1.055, gammaSrgb); assert(radiance <= 1.0); if (radiance < linearCutoff709 * normalizer) bt709 = radiance * linearExpansion709; else - bt709 = 1.055 * pow(normalized, oneOverGamma709) - 0.055; + bt709 = 1.099 * pow(radiance, oneOverGamma709) - 0.099; assert(bt709 <= 1.0); diff --git a/version.mk b/version.mk index ad4cadaf..8253b4b5 100644 --- a/version.mk +++ b/version.mk @@ -1,3 +1,3 @@ NETPBM_MAJOR_RELEASE = 10 NETPBM_MINOR_RELEASE = 86 -NETPBM_POINT_RELEASE = 32 +NETPBM_POINT_RELEASE = 33 -- cgit 1.4.1