diff options
-rw-r--r-- | converter/other/ipdb.c | 2 | ||||
-rw-r--r-- | converter/other/pnmtopalm/pnmtopalm.c | 114 | ||||
-rw-r--r-- | doc/HISTORY | 9 | ||||
-rw-r--r-- | version.mk | 2 |
4 files changed, 37 insertions, 90 deletions
diff --git a/converter/other/ipdb.c b/converter/other/ipdb.c index 1d72cc31..882bf187 100644 --- a/converter/other/ipdb.c +++ b/converter/other/ipdb.c @@ -284,7 +284,7 @@ ipdb_image_alloc(const char * const name, MALLOCARRAY(imgP->data, w * h); if (imgP->data) { - MEMSZERO(imgP->data); + memset(imgP->data, 0, sizeof(*(imgP->data)) * w * h); } else failed = true; } diff --git a/converter/other/pnmtopalm/pnmtopalm.c b/converter/other/pnmtopalm/pnmtopalm.c index 6e290777..a7d1fd46 100644 --- a/converter/other/pnmtopalm/pnmtopalm.c +++ b/converter/other/pnmtopalm/pnmtopalm.c @@ -13,7 +13,13 @@ * * See LICENSE file for licensing information. * - * + * References for the Palm Bitmap format: + * + * https://web.archive.org/web/20030621112139/http://www.palmos.com:80/dev/support/docs/ + * https://web.archive.org/web/20030413080018/http://www.palmos.com:80/dev/support/docs/palmos/ReferenceTOC.html + * + * http://www.trantor.de/kawt/doc/palmimages.html + * (above retrieved August 2017) */ #include <string.h> @@ -26,6 +32,7 @@ #include "palm.h" #include "shhopt.h" #include "mallocvar.h" +#include "runlength.h" enum compressionType {COMP_NONE, COMP_SCANLINE, COMP_RLE, COMP_PACKBITS}; @@ -835,79 +842,6 @@ rleCompressAndBufferRow(const unsigned char * const rowdata, -/* FIXME Incorrect for images with pixelSize == 16 */ -static void -computeNextPackbitsRun(const unsigned char * const rowdata, - unsigned int const rowbytes, - unsigned int const startPos, - unsigned int * const nextPosP, - unsigned char * const output, - int * const countP) { - - unsigned int pos; - int count; - - pos = startPos; - count = 0; - - if (rowdata[pos] == rowdata[pos + 1]) { - ++pos; - --count; - while ((count > -127) && (pos < (rowbytes - 1)) && - (rowdata[pos] == rowdata[pos + 1])) { - ++pos; - --count; - } - ++pos; /* push pos past end of this run */ - } else { - output[count] = rowdata[pos]; - ++pos; - while ((count < 127) && (pos < (rowbytes - 1)) && - (rowdata[pos] != rowdata[pos + 1])) { - ++count; - output[count] = rowdata[pos]; - ++pos; - } - /* trailing literal */ - if ((count < 127) && (pos == (rowbytes - 1)) && - (rowdata[pos - 1] != rowdata[pos])) { - ++count; - output[count] = rowdata[pos]; - ++pos; - } - } - *nextPosP = pos; - *countP = count; -} - - - -static void -addPackbitsRunToBuffer(const unsigned char * const rowdata, - unsigned int const rowbytes, - unsigned int const pos, - unsigned char * const output, - int const count, - struct seqBuffer * const rasterBufferP) { - - addByteToBuffer(rasterBufferP, (unsigned char)(signed char)count); - if (count < 0) { - addByteToBuffer(rasterBufferP, rowdata[pos - 1]); - } else { - unsigned int j; - for (j = 0; j <= count; j++) - addByteToBuffer(rasterBufferP, output[j]); - } - - if (pos == (rowbytes - 1) && (rowdata[pos - 1] != rowdata[pos])) { - /* orphaned byte, treat as literal */ - addByteToBuffer(rasterBufferP, 0); - addByteToBuffer(rasterBufferP, rowdata[pos]); - } -} - - - static void packbitsCompressAndBufferRow(const unsigned char * const rowdata, unsigned int const rowbytes, @@ -917,21 +851,18 @@ packbitsCompressAndBufferRow(const unsigned char * const rowdata, add the packbits-compressed representation of it to the buffer with handle 'rasterBufferP'. -----------------------------------------------------------------------------*/ - unsigned int position; - /* byte position within the row */ - - position = 0; /* Start at beginning of row */ + unsigned char * compressedData; + size_t compressedDataCt; + unsigned int byteCt; - while (position < rowbytes - 1) { - unsigned char output[128]; - int count; + pm_rlenc_allocoutbuf(&compressedData, rowbytes, PM_RLE_PACKBITS); + pm_rlenc_compressbyte(rowdata, compressedData, PM_RLE_PACKBITS, + rowbytes, &compressedDataCt); - computeNextPackbitsRun(rowdata, rowbytes, position, - &position, output, &count); + for (byteCt = 0; byteCt < compressedDataCt; ++byteCt) + addByteToBuffer(rasterBufferP, compressedData[byteCt]); - addPackbitsRunToBuffer(rowdata, rowbytes, position, output, count, - rasterBufferP); - } + free(compressedData); } @@ -1028,7 +959,13 @@ bufferRaster(xel ** const xels, createBuffer(rasterBufferPP); MALLOCARRAY_NOFAIL(rowdata, rowbytes); - MALLOCARRAY_NOFAIL(lastrow, rowbytes); + if (compression == COMP_SCANLINE) + MALLOCARRAY_NOFAIL(lastrow, rowbytes); + else + lastrow = NULL; + + /* clear pad bytes to suppress valgrind error */ + rowdata[rowbytes - 1] = rowdata[rowbytes - 2] = 0x00; /* And write out the data. */ for (row = 0; row < rows; ++row) { @@ -1040,8 +977,9 @@ bufferRaster(xel ** const xels, if (compression == COMP_SCANLINE) memcpy(lastrow, rowdata, rowbytes); } - free(lastrow); free(rowdata); + if (compression == COMP_SCANLINE) + free(lastrow); } diff --git a/doc/HISTORY b/doc/HISTORY index 3ae601f1..c859fe42 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -4,6 +4,15 @@ Netpbm. CHANGE HISTORY -------------- +17.09.10 BJH Release 10.79.05 + + pnmtopalm: fix incorrect output with certain input files and + -packbits_compression. Always broken. -packbits_compression + was new in Netpbm 10.27 (March 2005). + + pamtopdbimg: Fix incorrect output. Always broken (pamtopdbimg + was new in Netpbm 10.52.00 (October 2010)). + 17.08.11 BJH Release 10.79.04 libnetpbm: font facilities: fix invalid memory reference with diff --git a/version.mk b/version.mk index 2dd1a5dd..71e25303 100644 --- a/version.mk +++ b/version.mk @@ -1,3 +1,3 @@ NETPBM_MAJOR_RELEASE = 10 NETPBM_MINOR_RELEASE = 79 -NETPBM_POINT_RELEASE = 4 +NETPBM_POINT_RELEASE = 5 |