diff options
-rw-r--r-- | converter/other/pnmtops.c | 53 | ||||
-rw-r--r-- | converter/pbm/pbmtoepsi.c | 22 | ||||
-rw-r--r-- | doc/HISTORY | 22 | ||||
-rw-r--r-- | editor/pnmshear.c | 7 | ||||
-rw-r--r-- | generator/ppmpat.c | 18 | ||||
-rw-r--r-- | version.mk | 2 |
6 files changed, 103 insertions, 21 deletions
diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c index e1f2d185..150331a1 100644 --- a/converter/other/pnmtops.c +++ b/converter/other/pnmtops.c @@ -439,6 +439,42 @@ typedef struct { +static unsigned int +bytesPerRow (unsigned int const cols, + unsigned int const bitsPerSample) { +/*---------------------------------------------------------------------------- + Size of row buffer, padded up to byte boundary, given that the image + has 'cols' samples per row, 'bitsPerSample' bits per sample. +-----------------------------------------------------------------------------*/ + unsigned int retval; + + assert(bitsPerSample==1 || bitsPerSample==2 || bitsPerSample==4 || + bitsPerSample==8 || bitsPerSample==12); + + switch (bitsPerSample) { + case 1: + case 2: + case 4: + retval = cols / (8/bitsPerSample) + + (cols % (8/bitsPerSample) > 0 ? 1 : 0); + /* A more straightforward calculation would be + (cols * bitsPerSample + 7) / 8 , + but this overflows when icols is large. + */ + break; + case 8: + retval = cols; + break; + case 12: + retval = cols + (cols+1)/2; + break; + } + + return retval; +} + + + static void initOutputEncoder(OutputEncoder * const oeP, unsigned int const icols, @@ -448,20 +484,12 @@ initOutputEncoder(OutputEncoder * const oeP, bool const ascii85, bool const psFilter) { - unsigned int const bytesPerRow = icols / (8/bitsPerSample) + - (icols % (8/bitsPerSample) > 0 ? 1 : 0); - /* Size of row buffer, padded up to byte boundary. - - A more straightforward calculation would be - (icols * bitsPerSample + 7) / 8 , - but this overflows when icols is large. - */ - oeP->outputType = ascii85 ? Ascii85 : AsciiHex; if (rle) { oeP->compressRle = true; - oeP->runlengthRefresh = psFilter ? INT_MAX : bytesPerRow; + oeP->runlengthRefresh = + psFilter ? INT_MAX : bytesPerRow(icols, bitsPerSample); } else oeP->compressRle = false; @@ -741,10 +769,9 @@ asciiHexFilter(FILE * const ifP, outbuff[i*2] = hexits[item >> 4]; outbuff[i*2+1] = hexits[item & 15]; } + outbuff[readCt * 2] = '\n'; + writeFile(outbuff, readCt * 2 + 1, "asciiHex filter", ofP); } - outbuff[readCt * 2] = '\n'; - - writeFile(outbuff, readCt * 2 + 1, "asciiHex filter", ofP); } fclose(ifP); diff --git a/converter/pbm/pbmtoepsi.c b/converter/pbm/pbmtoepsi.c index fce7b6ea..6d2065dc 100644 --- a/converter/pbm/pbmtoepsi.c +++ b/converter/pbm/pbmtoepsi.c @@ -151,6 +151,13 @@ findPrincipalImage(bit ** const bits, } } } + + if(bottom == -MAXINT) { /* No black pixels encountered */ + pm_message("Blank page"); + top = left = 0; + bottom = rows-1; right = cols-1; + } + *topP = top; *bottomP = bottom; *leftP = left; @@ -238,13 +245,20 @@ main(int argc, char * argv[]) { for (row = top; row <= bottom; row++) { int col; + int outChars = 2; + printf("%% "); - printf("%% "); + for (col = left; col <= right; col += 8) { + if (outChars == 72) { + printf("\n%% "); + outChars = 2; + } - for (col = left; col <= right; col += 8) printf("%02x", eightPixels(bits, row, col, cols)); - - printf("\n"); + outChars += 2; + } + if (outChars > 0) + printf("\n"); } printf("%%%%EndImage\n"); printf("%%%%EndPreview\n"); diff --git a/doc/HISTORY b/doc/HISTORY index 5e877d4a..a39126ee 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -4,6 +4,28 @@ Netpbm. CHANGE HISTORY -------------- +not yet BJH Release 10.65.05 + + pnmtops: Fix spurious blank line in asciihex encoding of the + image raster. Probably harmless. Introduced in 10.56 + (September 2011). + + pnmtops: Fix crash with 12 bits per sample. Introduced in 10.53 + (December 2010). Thanks Prophet of the Way <afu@wta.att.ne.jp>. + + pbmtoepsi: fix handling of all-white image. Always broken. + Thanks Prophet of the Way <afu@wta.att.ne.jp>. + + pbmtoepsi: fix excessively long raster line. Always broken. + Thanks Prophet of the Way <afu@wta.att.ne.jp>. + + pnmshear: fix incorrect determination of background color. + Always broken. + + ppmpat: fix crash with -squig with aspect ratio < 1:25 or + > 25:1. Thanks Prophet of the Way <afu@wta.att.ne.jp>. + Always broken. + 13.11.24 BJH Release 10.64.04 pnmtops: Fix bug: wrong output with -ascii85. Introduced in diff --git a/editor/pnmshear.c b/editor/pnmshear.c index 6318f8e4..657f265d 100644 --- a/editor/pnmshear.c +++ b/editor/pnmshear.c @@ -241,14 +241,15 @@ main(int argc, char * argv[]) { pnm_writepnminit(stdout, newcols, rows, newmaxval, newformat, 0); newxelrow = pnm_allocrow(newcols); - bgxel = backgroundColor(cmdline.background, xelrow, cols, newmaxval, - format); - for (row = 0; row < rows; ++row) { double shearCols; pnm_readpnmrow(ifP, xelrow, cols, newmaxval, format); + if (row == 0) + bgxel = backgroundColor(cmdline.background, + xelrow, cols, newmaxval, format); + if (cmdline.angle > 0.0) shearCols = row * shearfac; else diff --git a/generator/ppmpat.c b/generator/ppmpat.c index 2e8092b3..fe1a1d27 100644 --- a/generator/ppmpat.c +++ b/generator/ppmpat.c @@ -877,6 +877,19 @@ static ppmd_point sq_offs[SQ_MAXCIRCLE_POINTS]; +static void +validateSquigAspect(unsigned int const cols, + unsigned int const rows) { + + if (cols / rows >= 25 || rows / cols >= 25) + pm_error("Image too narrow. Aspect ratio: %u/%u=%f " + "is outside accepted range: 0.04 - 25.0", + cols, rows, (float)cols/rows ); + +} + + + static ppmd_point vectorSum(ppmd_point const a, ppmd_point const b) { @@ -1081,6 +1094,8 @@ squig(pixel ** const pixels, pixval const maxval) { int i; + + validateSquigAspect(cols, rows); clearImageToBlack(pixels, cols, rows, maxval); @@ -1106,6 +1121,9 @@ squig(pixel ** const pixels, unsigned int j; for (j = 1; j < SQ_POINTS - 1; ++j) { + /* validateSquigAspect() assures that + cols - 2 * radius, rows -2 * radius are positive + */ c[j].x = (rand() % (cols - 2 * radius)) + radius; c[j].y = (rand() % (rows - 2 * radius)) + radius; } diff --git a/version.mk b/version.mk index 142da613..25c7d120 100644 --- a/version.mk +++ b/version.mk @@ -1,4 +1,4 @@ NETPBM_MAJOR_RELEASE = 10 NETPBM_MINOR_RELEASE = 64 -NETPBM_POINT_RELEASE = 4 +NETPBM_POINT_RELEASE = 5 |