diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2022-04-24 00:55:52 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2022-04-24 00:55:52 +0000 |
commit | c34b30147e111cb445ade4552d2d9fe53fc41eba (patch) | |
tree | 504d3672d8910c21d885ce22326d5ed898ccd892 /converter | |
parent | 925336fe011635da550369b9db527f034fbc587d (diff) | |
download | netpbm-mirror-c34b30147e111cb445ade4552d2d9fe53fc41eba.tar.gz netpbm-mirror-c34b30147e111cb445ade4552d2d9fe53fc41eba.tar.xz netpbm-mirror-c34b30147e111cb445ade4552d2d9fe53fc41eba.zip |
Release 10.86.33
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@4328 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter')
-rw-r--r-- | converter/other/pnmtopalm/palmtopnm.c | 57 |
1 files changed, 42 insertions, 15 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); |