diff options
Diffstat (limited to 'converter/pbm')
-rw-r--r-- | converter/pbm/atktopbm.c | 34 | ||||
-rw-r--r-- | converter/pbm/escp2topbm.c | 18 | ||||
-rw-r--r-- | converter/pbm/g3topbm.c | 11 | ||||
-rw-r--r-- | converter/pbm/mdatopbm.c | 2 | ||||
-rw-r--r-- | converter/pbm/mgrtopbm.c | 30 | ||||
-rw-r--r-- | converter/pbm/pbmtoatk.c | 31 | ||||
-rw-r--r-- | converter/pbm/pbmtoescp2.c | 23 | ||||
-rw-r--r-- | converter/pbm/pbmtogem.c | 2 | ||||
-rw-r--r-- | converter/pbm/pbmtogo.c | 72 | ||||
-rw-r--r-- | converter/pbm/pbmtoibm23xx.c | 6 | ||||
-rw-r--r-- | converter/pbm/pbmtolps.c | 378 | ||||
-rw-r--r-- | converter/pbm/pbmtomacp.c | 2 | ||||
-rw-r--r-- | converter/pbm/pbmtomgr.c | 14 | ||||
-rw-r--r-- | converter/pbm/pbmtonokia.c | 87 | ||||
-rw-r--r-- | converter/pbm/pbmtopk.c | 120 | ||||
-rw-r--r-- | converter/pbm/pbmtoppa/README.REDHAT | 2 | ||||
-rw-r--r-- | converter/pbm/pbmtoppa/ppa.c | 10 | ||||
-rw-r--r-- | converter/pbm/pbmtoptx.c | 11 | ||||
-rw-r--r-- | converter/pbm/pbmtox10bm | 15 | ||||
-rw-r--r-- | converter/pbm/xbmtopbm.c | 36 | ||||
-rw-r--r-- | converter/pbm/ybmtopbm.c | 6 |
21 files changed, 519 insertions, 391 deletions
diff --git a/converter/pbm/atktopbm.c b/converter/pbm/atktopbm.c index 807e4f4a..57782d91 100644 --- a/converter/pbm/atktopbm.c +++ b/converter/pbm/atktopbm.c @@ -44,7 +44,7 @@ #define dataobject_OBJECTCREATIONFAILED 4 #define dataobject_BADFORMAT 5 -/* ReadRow(file, row, length) +/* ReadRow(file, row, length) ** Reads from 'file' the encoding of bytes to fill in 'row'. Row will be ** truncated or padded (with WHITE) to exactly 'length' bytes. ** @@ -52,7 +52,7 @@ ** '|' correct end of line ** '\0' if the length was satisfied (before a terminator) ** EOF if the file ended -** '\' '{' other recognized ends. +** '\' '{' other recognized ends. ** The '|' is the expected end and pads the row with WHITE. ** The '\' and '{' are error conditions and may indicate the ** beginning of some other portion of the data stream. @@ -76,11 +76,11 @@ ReadRow(FILE * const file, 'file' is where to get them from. 'row' is where to put bytes. 'length' is how many bytes in row must be filled. - + Return the delimiter that marks the end of the row, or EOF if EOF marks the end of the row, or NUL in some cases. -----------------------------------------------------------------------------*/ - /* Each input character is processed by the central loop. There are + /* Each input character is processed by the central loop. There are ** some input codes which require two or three characters for ** completion; these are handled by advancing the state machine. ** Errors are not processed; instead the state machine is reset @@ -98,7 +98,7 @@ ReadRow(FILE * const file, RepeatAndDigit /* have seen repeat code and its first following digit */ }; - + enum StateCode InputState; /* current state */ int c; /* the current input character */ long repeatcount; /* current repeat value */ @@ -106,8 +106,8 @@ ReadRow(FILE * const file, long pendinghex; /* the first of a pair of hex characters */ int lengthRemaining; unsigned char * cursor; - - /* We cannot exit when length becomes zero because we need to check + + /* We cannot exit when length becomes zero because we need to check ** to see if a row ending character follows. Thus length is checked ** only when we get a data generating byte. If length then is ** zero, we ungetc the byte. @@ -148,7 +148,7 @@ ReadRow(FILE * const file, while (lengthRemaining-- > 0) *cursor++ = WHITEBYTE; return c; - + CASE1(0x21): CASE6(0x22): CASE8(0x28): @@ -227,9 +227,9 @@ ReadRow(FILE * const file, break; store: - /* generate byte(s) into the output row + /* generate byte(s) into the output row Use repeatcount, depending on state. */ - if (lengthRemaining < repeatcount) + if (lengthRemaining < repeatcount) /* reduce repeat count if it would exceed available space */ repeatcount = lengthRemaining; @@ -269,7 +269,7 @@ ReadATKRaster(FILE * const ifP) { pm_error ("input file not Andrew raster object"); fscanf(ifP, " %d ", &version); - if (version < 2) + if (version < 2) pm_error ("version too old to parse"); { @@ -277,8 +277,8 @@ ReadATKRaster(FILE * const ifP) { long xscale, yscale; long xoffset, yoffset, subwidth, subheight; /* ignore all these features: */ - fscanf(ifP, " %u %ld %ld %ld %ld %ld %ld", - &options, &xscale, &yscale, &xoffset, + fscanf(ifP, " %u %ld %ld %ld %ld %ld %ld", + &options, &xscale, &yscale, &xoffset, &yoffset, &subwidth, &subheight); } /* scan to end of line in case this is actually something beyond V2 */ @@ -291,8 +291,12 @@ ReadATKRaster(FILE * const ifP) { fscanf(ifP, " %d %d %d ", &objectid, &width, &height); - if (width < 1 || height < 1 || width > 1000000 || height > 1000000) + if (width < 1 || height < 1 || width > 1000000 || height > 1000000) pm_error("bad width or height"); + /* Note: Whether these values are upper limits set by the author of + the original version of this program, or come from the official + file format specification is unknown. + */ pbm_writepbminit(stdout, width, height, 0); bitrow = pbm_allocrow_packed(width); @@ -302,7 +306,7 @@ ReadATKRaster(FILE * const ifP) { long const nextChar = ReadRow(ifP, bitrow, rowlen); switch (nextChar) { - case '|': + case '|': pbm_writepbmrow_packed(stdout, bitrow, width, 0); break; case EOF: diff --git a/converter/pbm/escp2topbm.c b/converter/pbm/escp2topbm.c index 8acd13d6..de3ea931 100644 --- a/converter/pbm/escp2topbm.c +++ b/converter/pbm/escp2topbm.c @@ -104,7 +104,7 @@ readChar(FILE * const ifP) { -static void +static void readStripeHeader(unsigned int * const widthThisStripeP, unsigned int * const rowsThisStripeP, unsigned int * const compressionP, @@ -120,7 +120,7 @@ readStripeHeader(unsigned int * const widthThisStripeP, compression = stripeHeader[0]; /* verticalResolution = stripeHeader[1]; */ /* horizontalResolution = stripeHeader[2]; */ - rowsThisStripe = stripeHeader[3]; + rowsThisStripe = stripeHeader[3]; widthThisStripe = stripeHeader[5] * 256 + stripeHeader[4]; if (widthThisStripe == 0 || rowsThisStripe == 0) @@ -143,7 +143,7 @@ readStripeHeader(unsigned int * const widthThisStripeP, /* RLE decoder */ static void -decEpsonRLE(unsigned int const blockSize, +decEpsonRLE(unsigned int const blockSize, unsigned char * const outBuffer, FILE * const ifP) { @@ -174,7 +174,7 @@ decEpsonRLE(unsigned int const blockSize, unsigned int i; for (i = 0; i < runLength; ++i) - outBuffer[dpos + i] = repeatChar; + outBuffer[dpos + i] = repeatChar; dpos += runLength; } } @@ -191,7 +191,7 @@ processStripeRaster(unsigned char ** const bitarray, unsigned int const compression, FILE * const ifP, unsigned int * const rowIdxP) { - + unsigned int const initialRowIdx = *rowIdxP; unsigned int const widthInBytes = pbm_packed_bytes(width); unsigned int const blockSize = rowsThisStripe * widthInBytes; @@ -237,7 +237,7 @@ expandBitarray(unsigned char *** const bitarrayP, if (*bitarraySizeP > heightMax) pm_error("Error: Image too tall"); else - REALLOCARRAY_NOFAIL(*bitarrayP, *bitarraySizeP); + REALLOCARRAY_NOFAIL(*bitarrayP, *bitarraySizeP); } @@ -253,7 +253,7 @@ writePbmImage(unsigned char ** const bitarray, pm_error("No image"); pbm_writepbminit(stdout, width, height, 0); - + for (row = 0; row < height; ++row) { pbm_cleanrowend_packed(bitarray[row], width); pbm_writepbmrow_packed(stdout, bitarray[row], width, 0); @@ -309,7 +309,7 @@ main(int argc, unsigned int compression; unsigned int rowsThisStripe; unsigned int widthThisStripe; - + readStripeHeader(&widthThisStripe, &rowsThisStripe, &compression, ifP); @@ -320,7 +320,7 @@ main(int argc, /* The official Epson manual says valid values are 1, 8, 24 but we just print a warning message and continue if other values are detected. - */ + */ pm_message("Abnormal data block height value: %u " "(ignoring)", rowsThisStripe); diff --git a/converter/pbm/g3topbm.c b/converter/pbm/g3topbm.c index 5d98fcb2..5db507a3 100644 --- a/converter/pbm/g3topbm.c +++ b/converter/pbm/g3topbm.c @@ -552,12 +552,11 @@ readFaxRow(struct BitStream * const bitStreamP, curcode = (curcode << 1) | bit; ++curlen; - if (curlen > 11 && curcode == 0x00) { - if (++fillbits > MAXFILLBITS) - pm_error("Encountered %u consecutive fill bits. " - "Aborting", fillbits); - } - else if (curlen - fillbits > 13) { + if (curlen > 11 && curcode == 0x00) { + if (++fillbits > MAXFILLBITS) + pm_error("Encountered %u consecutive fill bits. " + "Aborting", fillbits); + } else if (curlen - fillbits > 13) { formatBadCodeException(exceptionP, col, curlen, curcode); done = TRUE; } else if (curcode != 0) { diff --git a/converter/pbm/mdatopbm.c b/converter/pbm/mdatopbm.c index d8e06572..461b3f80 100644 --- a/converter/pbm/mdatopbm.c +++ b/converter/pbm/mdatopbm.c @@ -36,7 +36,7 @@ static bit **data; /* PBM image */ static mdbyte *mdrow; /* MDA row after decompression (MD3 only) */ static int bInvert = 0; /* Invert image? */ static int bScale = 0; /* Scale image? */ -static int bAscii = 0; /* Ouput ASCII PBM? */ +static int bAscii = 0; /* Output ASCII PBM? */ static int nInRows, nInCols; /* Height, width of input (rows x bytes) */ static int nOutCols, nOutRows; /* Height, width of output (rows x bytes) */ diff --git a/converter/pbm/mgrtopbm.c b/converter/pbm/mgrtopbm.c index 712e3be9..e0a88883 100644 --- a/converter/pbm/mgrtopbm.c +++ b/converter/pbm/mgrtopbm.c @@ -58,12 +58,12 @@ interpHdrHeight(struct b_header const head, static void -readMgrHeader(FILE * const ifP, - unsigned int * const colsP, - unsigned int * const rowsP, - unsigned int * const depthP, +readMgrHeader(FILE * const ifP, + unsigned int * const colsP, + unsigned int * const rowsP, + unsigned int * const depthP, unsigned int * const padrightP ) { - + struct b_header head; unsigned int pad; size_t bytesRead; @@ -73,10 +73,10 @@ readMgrHeader(FILE * const ifP, pm_error("Unable to read 1st byte of file. " "fread() returns errno %d (%s)", errno, strerror(errno)); - if (head.magic[0] == 'y' && head.magic[1] == 'z') { + if (head.magic[0] == 'y' && head.magic[1] == 'z') { /* new style bitmap */ size_t bytesRead; - bytesRead = fread(&head.depth, + bytesRead = fread(&head.depth, sizeof(head) - sizeof(struct old_b_header), 1, ifP); if (bytesRead != 1 ) pm_error("Unable to read header after 1st byte. " @@ -84,11 +84,11 @@ readMgrHeader(FILE * const ifP, errno, strerror(errno)); *depthP = (int) head.depth - ' '; pad = 8; - } else if (head.magic[0] == 'x' && head.magic[1] == 'z') { + } else if (head.magic[0] == 'x' && head.magic[1] == 'z') { /* old style bitmap with 32-bit padding */ *depthP = 1; pad = 32; - } else if (head.magic[0] == 'z' && head.magic[1] == 'z') { + } else if (head.magic[0] == 'z' && head.magic[1] == 'z') { /* old style bitmap with 16-bit padding */ *depthP = 1; pad = 16; @@ -104,8 +104,8 @@ readMgrHeader(FILE * const ifP, interpHdrWidth (head, colsP); interpHdrHeight(head, rowsP); - - *padrightP = ( ( *colsP + pad - 1 ) / pad ) * pad - *colsP; + + *padrightP = ((*colsP + pad - 1) / pad) * pad - *colsP; } @@ -131,7 +131,7 @@ main(int argc, inputFileName = argv[1]; else inputFileName = "-"; - + ifP = pm_openr(inputFileName); readMgrHeader(ifP, &cols, &rows, &depth, &padright); @@ -141,7 +141,7 @@ main(int argc, pbm_writepbminit(stdout, cols, rows, 0); bitrow = pbm_allocrow_packed(cols + padright); - + itemCount = (cols + padright ) / 8; for (row = 0; row < rows; ++row) { @@ -166,9 +166,9 @@ main(int argc, Changed bitrow from plain to raw, read function from getc() to fread(), write function from pbm_writepbmrow() to pbm_writepbmrow_packed(). Retired bitwise transformation functions. - + NOT tested for old-style format files. Only one zz file in mgrsrc-0.69 . - + */ diff --git a/converter/pbm/pbmtoatk.c b/converter/pbm/pbmtoatk.c index ea5b7abe..5f2b625c 100644 --- a/converter/pbm/pbmtoatk.c +++ b/converter/pbm/pbmtoatk.c @@ -22,8 +22,8 @@ static void -write_atk_bytes(FILE * const file, - unsigned char const curbyte, +write_atk_bytes(FILE * const file, + unsigned char const curbyte, unsigned int const startcount) { /* codes for data stream */ @@ -37,7 +37,7 @@ write_atk_bytes(FILE * const file, #define BLACKBYTE 0xFF /* WriteRow table for conversion of a byte value to two character - hex representation + hex representation */ static unsigned char hex[16] = { @@ -82,10 +82,10 @@ write_atk_bytes(FILE * const file, static void -process_atk_byte(int * const pcurcount, - unsigned char * const pcurbyte, - FILE * const file, - unsigned char const newbyte, +process_atk_byte(int * const pcurcount, + unsigned char * const pcurbyte, + FILE * const file, + unsigned char const newbyte, int const eolflag) { int curcount; @@ -93,7 +93,7 @@ process_atk_byte(int * const pcurcount, curcount = *pcurcount; /* initial value */ curbyte = *pcurbyte; /* initial value */ - + if (curcount < 1) { *pcurbyte = curbyte = newbyte; *pcurcount = curcount = 1; @@ -139,6 +139,17 @@ main(int argc, const char ** argv) { } pbm_readpbminit(ifP, &cols, &rows, &format); + /* Note: atktopbm imposes limits: cols <= 1000000 rows <= 1000000 + Whether these values are defined in the official file format + specification is unknown. We issue warning messages when large + values are encountered. + */ + + if (cols > 1000000) + pm_message("Proceeding with extremely large width value: %u", cols); + if (rows > 1000000) + pm_message("Proceeding with extremely large height value: %u", rows); + bitrow = pbm_allocrow_packed(cols); printf("\\begindata{raster,%d}\n", 1); @@ -152,7 +163,7 @@ main(int argc, const char ** argv) { pbm_readpbmrow_packed(ifP, bitrow, cols, format); pbm_cleanrowend_packed(bitrow, cols); - + for (i = 0, curbyte = 0, curcount = 0; i < byteCt; ++i) { process_atk_byte(&curcount, &curbyte, stdout, bitrow[i], @@ -162,7 +173,7 @@ main(int argc, const char ** argv) { pbm_freerow_packed(bitrow); pm_close(ifP); - + printf("\\enddata{raster, %d}\n", 1); return 0; diff --git a/converter/pbm/pbmtoescp2.c b/converter/pbm/pbmtoescp2.c index 6f284f3c..942ecec9 100644 --- a/converter/pbm/pbmtoescp2.c +++ b/converter/pbm/pbmtoescp2.c @@ -18,6 +18,7 @@ * * ESC/P Reference Manual (1997) * ftp://download.epson-europe.com/pub/download/182/epson18162eu.zip +* See Part 1 "ESC ." Print Raster Graphics */ #include <string.h> @@ -28,7 +29,7 @@ #include "runlength.h" #include "pbm.h" - +#define MAXCOLS (127 * 256 + 255) /* Limit in official Epson manual */ static char const esc = 033; @@ -57,19 +58,19 @@ parseCommandLine(int argc, const char ** argv, opt.opt_table = option_def; opt.short_allowed = FALSE; opt.allowNegNum = FALSE; - OPTENT3(0, "compress", OPT_UINT, &cmdlineP->compress, + OPTENT3(0, "compress", OPT_UINT, &cmdlineP->compress, &compressSpec, 0); - OPTENT3(0, "resolution", OPT_UINT, &cmdlineP->resolution, + OPTENT3(0, "resolution", OPT_UINT, &cmdlineP->resolution, &resolutionSpec, 0); - OPTENT3(0, "stripeheight", OPT_UINT, &cmdlineP->stripeHeight, + OPTENT3(0, "stripeheight", OPT_UINT, &cmdlineP->stripeHeight, &stripeHeightSpec, 0); - OPTENT3(0, "raw", OPT_FLAG, NULL, + OPTENT3(0, "raw", OPT_FLAG, NULL, &rawSpec, 0); - OPTENT3(0, "formfeed", OPT_FLAG, NULL, + OPTENT3(0, "formfeed", OPT_FLAG, NULL, &formfeedSpec, 0); - + pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); - + if (argc-1 > 1) pm_error("Too many arguments: %d. " "Only argument is the filename", argc-1); @@ -155,7 +156,7 @@ main(int argc, const char * argv[]) { unsigned char * bitrow[256]; unsigned char * compressedData; struct CmdlineInfo cmdline; - + pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); @@ -164,7 +165,7 @@ main(int argc, const char * argv[]) { pbm_readpbminit(ifP, &cols, &rows, &format); - if (cols / 256 > 127) /* Limit in official Epson manual */ + if (cols > MAXCOLS) pm_error("Image width is too large"); outColByteCt = pbm_packed_bytes(cols); @@ -229,7 +230,7 @@ main(int argc, const char * argv[]) { } } - free(inBuff); + free(inBuff); free(compressedData); pm_close(ifP); diff --git a/converter/pbm/pbmtogem.c b/converter/pbm/pbmtogem.c index 9eab0416..4fd30e92 100644 --- a/converter/pbm/pbmtogem.c +++ b/converter/pbm/pbmtogem.c @@ -26,7 +26,7 @@ * changed header length to count words to conform with Atari ST documentation * removed rounding of the imagewidth to the next word boundary * removed arbitrary limit to imagewidth -* changed pattern length to 1 to simplify locating of compressable parts +* changed pattern length to 1 to simplify locating of compressible parts * in real world images * add solid run and pattern run compression * diff --git a/converter/pbm/pbmtogo.c b/converter/pbm/pbmtogo.c index 23b2ee9a..4f84f391 100644 --- a/converter/pbm/pbmtogo.c +++ b/converter/pbm/pbmtogo.c @@ -1,29 +1,29 @@ /* pbmtogo.c - read a PBM image and produce a GraphOn terminal raster file -** +** ** Rev 1.1 was based on pbmtolj.c ** ** Bo Thide', Swedish Institute of Space Physics, bt@irfu.se -** +** ** ** $Log: pbmtogo.c,v $ * Revision 1.5 89/11/25 00:24:12 00:24:12 root (Bo Thide) * Bug found: The byte after 64 repeated bytes sometimes lost. Fixed. - * + * * Revision 1.4 89/11/24 14:56:04 14:56:04 root (Bo Thide) * Fixed the command line parsing since pbmtogo now always uses 2D * compression. Added a few comments to the source. - * + * * Revision 1.3 89/11/24 13:43:43 13:43:43 root (Bo Thide) * Added capability for > 63 repeated bytes and > 62 repeated lines in * the 2D compression scheme. - * + * * Revision 1.2 89/11/15 01:04:47 01:04:47 root (Bo Thide) * First version that works reasonably well with GraphOn 2D runlength * encoding/compression. - * + * * Revision 1.1 89/11/02 23:25:25 23:25:25 root (Bo Thide) * Initial revision - * + * ** ** Copyright (C) 1988, 1989 by Jef Poskanzer, Michael Haberler, and Bo Thide'. ** @@ -44,10 +44,10 @@ #define GRAPHON_WIDTH 1056 /* GraphOn has 1056 bit wide raster lines */ #define GRAPHON_WIDTH_BYTES (GRAPHON_WIDTH / 8) -#define REPEAT_CURRENT_LINE_MASK 0x00 -#define SKIP_AND_PLOT_MASK 0x40 -#define REPEAT_PLOT_MASK 0x80 -#define PLOT_ARBITRARY_DATA_MASK 0xc0 +#define REPEAT_CURRENT_LINE_MASK 0x00 +#define SKIP_AND_PLOT_MASK 0x40 +#define REPEAT_PLOT_MASK 0x80 +#define PLOT_ARBITRARY_DATA_MASK 0xc0 #define MAX_REPEAT 64 static unsigned char * scanlineptr; @@ -167,7 +167,7 @@ main(int argc, buffer[i] = oldscanline[i] = 0; putinit(); - /* Start donwloading screen raster */ + /* Start downloading screen raster */ printf("\033P0;1;0;4;1;%d;%d;1!R1/", rows, rucols); linerepeat = 63; /* 63 means "Start new picture" */ @@ -183,32 +183,32 @@ main(int argc, putbit(0); assert(bytesperrow <= GRAPHON_WIDTH_BYTES); - + /* XOR data from the new scan line with data from old scan line */ for (i = 0; i < bytesperrow; i++) diff[i] = oldscanline[i]^newscanline[i]; - + /* ** If the difference map is different from current internal buffer, - ** encode the difference and put it in the output buffer. + ** encode the difference and put it in the output buffer. ** Else, increase the counter for the current buffer by one. */ - + if ((memcmp(buffer, diff, bytesperrow) != 0) || (row == 0)) { - /* + /* **Since the data in the buffer has changed, send the **scan line repeat count to cause the old line(s) to **be plotted on the screen, copy the new data into - **the internal buffer, and reset the counters. + **the internal buffer, and reset the counters. */ - + putchar(linerepeat); for (i = 0; i < bytesperrow; ++i) buffer[i] = diff[i]; nbyte = 0; /* Internal buffer byte counter */ nout = 0; /* Output buffer byte counter */ - - /* Run length encode the new internal buffr (= difference map) */ + + /* Run length encode the new internal buffer (= difference map) */ while (TRUE) { ucount = 0; /* Unique items counter */ do /* Find unique patterns */ @@ -217,16 +217,16 @@ main(int argc, ucount++; } while (nbyte < bytesperrow && (olditem != buffer[nbyte]) && (ucount < MIN(bytesperrow, MAX_REPEAT))); - + if ((ucount != MAX_REPEAT) && (nbyte != bytesperrow)) { /* Back up to the last truly unique pattern */ ucount--; nbyte--; } - if (ucount > 0) { + if (ucount > 0) { /* Output the unique patterns */ - outbuffer[nout++] = + outbuffer[nout++] = (ucount-1) | PLOT_ARBITRARY_DATA_MASK; for (i = nbyte-ucount; i < nbyte; i++) outbuffer[nout++] = buffer[i]; @@ -235,12 +235,12 @@ main(int argc, /* ** If we already are at the end of the current scan ** line, skip the rest of the encoding and start - ** with a new scan line. + ** with a new scan line. */ if (nbyte >= bytesperrow) goto nextrow; - + ecount = 0; /* Equal items counter */ do /* Find equal patterns */ { @@ -248,25 +248,25 @@ main(int argc, ecount++; } while (nbyte < bytesperrow && (olditem == buffer[nbyte]) && (ecount < MIN(bytesperrow, MAX_REPEAT))); - + if (ecount > 1) { /* More than 1 equal pattern */ if (olditem == '\0') { /* White patterns */ if (nbyte >= bytesperrow-1) { /* No more valid data ahead */ - outbuffer[nout++] = + outbuffer[nout++] = (ecount-2) | SKIP_AND_PLOT_MASK; outbuffer[nout++] = buffer[nbyte-1]; - } - else { + } + else { /* More valid data ahead */ - outbuffer[nout++] = + outbuffer[nout++] = (ecount-1) | SKIP_AND_PLOT_MASK; outbuffer[nout++] = buffer[nbyte++]; - } + } } - else { + else { /* Non-white patterns */ outbuffer[nout++] = (ecount-1) | REPEAT_PLOT_MASK; outbuffer[nout++] = olditem; @@ -274,11 +274,11 @@ main(int argc, } /* if (ecount > 1) */ else nbyte--; /* No equal items found */ - + if (nbyte >= bytesperrow) goto nextrow; } /* while (TRUE) */ - + nextrow: printf("%d/", nout+1); /* Total bytes to xfer = nout+1 */ fflush(stdout); @@ -298,7 +298,7 @@ main(int argc, linerepeat = 0; } } - + /* Now we are ready for a new scan line */ for (i = 0; i < bytesperrow; ++i) oldscanline[i] = newscanline[i]; diff --git a/converter/pbm/pbmtoibm23xx.c b/converter/pbm/pbmtoibm23xx.c index 183d5419..3f1f9679 100644 --- a/converter/pbm/pbmtoibm23xx.c +++ b/converter/pbm/pbmtoibm23xx.c @@ -18,7 +18,7 @@ */ /* - * This prgram is primarily based on the description of Brothers PPDS + * This program is primarily based on the description of Brothers PPDS * emulation (see * http://www.brother.de/download/send_file.cfm?file_name=guide_ibmpro.pdf). * However, there are some differences. Their document states that @@ -39,7 +39,7 @@ * normally achieve in y. But the printer is able to do line feeds in * terms of 1/240", so the trick to print in higher resolutions is to * print in several interleaved passes, and do a line feed of 1/240" - * or 1/120" inbetween. + * or 1/120" in between. */ #include <stdio.h> @@ -131,7 +131,7 @@ process_handle(FILE * const fh, int cols, rows, format; /* iteration variables */ unsigned int x, y; - unsigned int bitline; /* pixel line within a sigle printing line */ + unsigned int bitline; /* pixel line within a single printing line */ unsigned int pass; /* here we build the to-be-printed data */ unsigned char *output; /* for reading one row from the file */ diff --git a/converter/pbm/pbmtolps.c b/converter/pbm/pbmtolps.c index 5adef4c8..d974fcb2 100644 --- a/converter/pbm/pbmtolps.c +++ b/converter/pbm/pbmtolps.c @@ -1,181 +1,253 @@ -/* - * pbmtolps -- convert a Portable BitMap into Postscript. The - * output Postscript uses lines instead of the image operator to - * generate a (device dependent) picture which will be imaged - * much faster. - * - * The Postscript path length is constrained to be less that 1000 - * points so that no limits are overrun on the Apple Laserwriter - * and (presumably) no other printers. - * - * To do: - * make sure encapsulated format is correct - * repitition of black-white strips - * make it more device independent (is this possible?) - * - * Author: - * George Phillips <phillips@cs.ubc.ca> - * Department of Computer Science - * University of British Columbia - */ - -#include <string.h> -#include <stdio.h> - +/*============================================================================= + pbmtolps +=============================================================================== + + Convert a PBM image to Postscript. The output Postscript uses lines instead + of the image operator to generate a (device dependent) picture which will be + imaged much faster. + + The Postscript path length is constrained to be at most 1000 vertices so that + no limits are overrun on the Apple Laserwriter and (presumably) no other + printers. The typical limit is 1500. See "4.4 Path Construction" and + "Appendix B: Implementation Limits" in: PostScript Language Reference Manual + https://www.adobe.com/content/dam/acom/en/devnet/actionscript/ + articles/psrefman.pdf + + To do: + make sure encapsulated format is correct + repetition of black-white strips + make it more device independent (is this possible?) + + Author: + George Phillips <phillips@cs.ubc.ca> + Department of Computer Science + University of British Columbia +=============================================================================*/ +#include <stdbool.h> + +#include "pm_c_util.h" +#include "mallocvar.h" #include "nstring.h" +#include "shhopt.h" #include "pbm.h" -static int prev_white = -1; -static int prev_black = -1; -static char cmd = '\0'; -static int pointcount = 2; +static float const MAX_DPI = 5000; +static float const MIN_DPI = 10; +static unsigned int const MAX_PATH_VERTICES = 1000; -#ifdef RUN -static int run = 1; -#endif -static char -morepoints(char cmd, int howmany_pbmtolps) { - pointcount += 2; - if (pointcount > 1000) { - pointcount = 2; - cmd += 'm' - 'a'; - } - return(cmd); +struct CmdlineInfo { + /* All the information the user supplied in the command line, in a form + easy for the program to use. + */ + const char * inputFileName; /* File name of input file */ + unsigned int inputFileSpec; /* Input file name specified */ + float lineWidth; /* Line width, if specified */ + unsigned int lineWidthSpec; /* Line width specified */ + float dpi; /* Resolution in DPI, if specified */ + unsigned int dpiSpec; /* Resolution specified */ +}; + + + +static void +validateDpi(float const dpi) { + + if (dpi > MAX_DPI || dpi < MIN_DPI) + pm_error("Specified DPI value out of range (%f)", dpi); } -static void -addstrip(int const white, - int const black) { - - if (cmd) { -#ifdef RUN - if (white == prev_white && black == prev_black) - run++; - else { - if (run == 1) -#endif - printf("%d %d %c ", - prev_black, prev_white, morepoints(cmd, 2)); -#ifdef RUN - else - /* of course, we need to give a new command */ - printf("%d %d %d %c ", - prev_white, prev_black, run, - morepoints(cmd + 'f' - 'a', 2 * run)); - run = 1; - } -#endif +static void +parseCommandLine(int argc, + const char ** const argv, + struct CmdlineInfo * const cmdlineP) { +/*---------------------------------------------------------------------------- + Parse program command line described in Unix standard form by argc + and argv. Return the information in the options as *cmdlineP. +-----------------------------------------------------------------------------*/ + optEntry * option_def; /* malloc'ed */ + /* Instructions to OptParseOptions3 on how to parse our options. */ + optStruct3 opt; + + unsigned int option_def_index; + + MALLOCARRAY_NOFAIL(option_def, 100); + + option_def_index = 0; /* incremented by OPTENTRY */ + OPTENT3(0, "linewidth", OPT_FLOAT, &cmdlineP->lineWidth, + &cmdlineP->lineWidthSpec, 0); + OPTENT3(0, "dpi", OPT_FLOAT, &cmdlineP->dpi, + &cmdlineP->dpiSpec, 0); + + opt.opt_table = option_def; + opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ + opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + + pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + /* Uses and sets argc, argv, and some of *cmdlineP and others. */ + + if (cmdlineP->dpiSpec) + validateDpi(cmdlineP->dpi); + else + cmdlineP->dpi = 300; + + if (argc-1 < 1) + cmdlineP->inputFileName = "-"; + else { + if (argc-1 > 1) + pm_error("Program takes zero or one argument (filename). You " + "specified %u", argc-1); + else + cmdlineP->inputFileName = argv[1]; } - prev_white = white; - prev_black = black; - cmd = 'a'; + if (cmdlineP->inputFileName[0] == '-' && + cmdlineP->inputFileName[1] == '\0') + cmdlineP->inputFileSpec = false; + else + cmdlineP->inputFileSpec = true; + + free(option_def); } -static void -nextline(void) { - /* need to check run, should have an outcommand */ - if (cmd) - printf("%d %d %c\n", prev_black, prev_white, morepoints('c', 3)); - else - printf("%c\n", morepoints('b', 1)); - cmd = '\0'; +static void +validateLineWidth(float const scCols, + float const scRows, + float const lineWidth) { + + if (lineWidth >= scCols || lineWidth >= scRows) + pm_error("Absurdly large -linewidth value (%f)", lineWidth); } -int -main(int argc, char ** argv) { - FILE* fp; - bit* bits; - int row; - int col; - int rows; - int cols; - int format; - int white; - int black; - const char* name; - float dpi = 300.0; - float sc_rows; - float sc_cols; - int i; - const char* const usage = "[ -dpi n ] [ pbmfile ]"; - - - pbm_init(&argc, argv); - - i = 1; - if (i < argc && streq(argv[i], "-dpi")) { - if (i == argc - 1) - pm_usage(usage); - sscanf(argv[i + 1], "%f", &dpi); - i += 2; - } +static void +doRaster(FILE * const ifP, + unsigned int const cols, + unsigned int const rows, + int const format, + FILE * const ofP) { - if (i < argc - 1) - pm_usage(usage); + bit * bitrow; + unsigned int row; + unsigned int vertexCt; + /* Number of vertices drawn since last stroke command */ - if (i == argc) { - name = "noname"; - fp = stdin; - } else { - name = argv[i]; - fp = pm_openr(name); - } - pbm_readpbminit(fp, &cols, &rows, &format); - bits = pbm_allocrow(cols); - - sc_rows = (float)rows / dpi * 72.0; - sc_cols = (float)cols / dpi * 72.0; - - puts("%!PS-Adobe-2.0 EPSF-2.0"); - puts("%%Creator: pbmtolps"); - printf("%%%%Title: %s\n", name); - printf("%%%%BoundingBox: %d %d %d %d\n", - (int)(305.5 - sc_cols / 2.0), - (int)(395.5 - sc_rows / 2.0), - (int)(306.5 + sc_cols / 2.0), - (int)(396.5 + sc_rows / 2.0)); - puts("%%EndComments"); - puts("%%EndProlog"); - puts("gsave"); - - printf("%f %f translate\n", 306.0 - sc_cols / 2.0, 396.0 + sc_rows / 2.0); - printf("72 %f div dup neg scale\n", dpi); - puts("/a { 0 rmoveto 0 rlineto } def"); - puts("/b { 0 row 1 add dup /row exch def moveto } def"); - puts("/c { a b } def"); - puts("/m { currentpoint stroke newpath moveto a } def"); - puts("/n { currentpoint stroke newpath moveto b } def"); - puts("/o { currentpoint stroke newpath moveto c } def"); - puts("/row 0 def"); - puts("newpath 0 0 moveto"); - - for (row = 0; row < rows; row++) { - pbm_readpbmrow(fp, bits, cols, format); - /* output white-strip+black-strip sequences */ - for (col = 0; col < cols; ) { - for (white = 0; col < cols && bits[col] == PBM_WHITE; col++) - white++; - for (black = 0; col < cols && bits[col] == PBM_BLACK; col++) - black++; + bitrow = pbm_allocrow(cols); + + for (row = 0, vertexCt = 0; row < rows; ++row) { + unsigned int col; + bool firstRun; + + firstRun = true; /* initial value */ + + pbm_readpbmrow(ifP, bitrow, cols, format); + + /* output white-strip + black-strip sequences */ - if (black != 0) - addstrip(white, black); + for (col = 0; col < cols; ) { + unsigned int whiteCt; + unsigned int blackCt; + + for (whiteCt = 0; col < cols && bitrow[col] == PBM_WHITE; ++col) + ++whiteCt; + for (blackCt = 0; col < cols && bitrow[col] == PBM_BLACK; ++col) + ++blackCt; + + if (blackCt > 0) { + if (vertexCt > MAX_PATH_VERTICES) { + printf("m "); + vertexCt = 0; + } + + if (firstRun) { + printf("%u %u moveto %u 0 rlineto\n", + whiteCt, row, blackCt); + firstRun = false; + } else + printf("%u %u a\n", blackCt, whiteCt); + + vertexCt += 2; + } } - nextline(); } - puts("stroke grestore showpage"); - puts("%%Trailer"); + pbm_freerow(bitrow); +} + + + +static void +pbmtolps(FILE * const ifP, + FILE * const ofP, + struct CmdlineInfo const cmdline) { + + const char * const psName = + cmdline.inputFileSpec ? cmdline.inputFileName : "noname"; + + int rows; + int cols; + int format; + float scRows, scCols; + /* Dimensions of the printed image in points */ + + pbm_readpbminit(ifP, &cols, &rows, &format); + + scRows = (float) rows / (cmdline.dpi / 72.0); + scCols = (float) cols / (cmdline.dpi / 72.0); + + if (cmdline.lineWidthSpec) + validateLineWidth(scCols, scRows, cmdline.lineWidth); + + fputs("%!PS-Adobe-2.0 EPSF-2.0\n", ofP); + fputs("%%Creator: pbmtolps\n", ofP); + fprintf(ofP, "%%%%Title: %s\n", psName); + fprintf(ofP, "%%%%BoundingBox: %d %d %d %d\n", + (int)(305.5 - scCols / 2.0), + (int)(395.5 - scRows / 2.0), + (int)(306.5 + scCols / 2.0), + (int)(396.5 + scRows / 2.0)); + fputs("%%EndComments\n", ofP); + fputs("%%EndProlog\n", ofP); + fputs("gsave\n", ofP); + + fprintf(ofP, "%f %f translate\n", + 306.0 - scCols / 2.0, 396.0 + scRows / 2.0); + fprintf(ofP, "72 %f div dup neg scale\n", cmdline.dpi); + + if (cmdline.lineWidthSpec) + fprintf(ofP, "%f setlinewidth\n", cmdline.lineWidth); + + fputs("/a { 0 rmoveto 0 rlineto } def\n", ofP); + fputs("/m { currentpoint stroke newpath moveto } def\n", ofP); + fputs("newpath 0 0 moveto\n", ofP); + + doRaster(ifP, cols, rows, format, ofP); + + fputs("stroke grestore showpage\n", ofP); + fputs("%%Trailer\n", ofP); +} + + + +int +main(int argc, const char *argv[]) { + FILE * ifP; + struct CmdlineInfo cmdline; + + pm_proginit(&argc, argv); + + parseCommandLine(argc, argv, &cmdline); + + ifP = pm_openr(cmdline.inputFileName); + + pbmtolps(ifP, stdout, cmdline); - pm_close(fp); + pm_close(ifP); - exit(0); + return 0; } diff --git a/converter/pbm/pbmtomacp.c b/converter/pbm/pbmtomacp.c index e02f5559..4897e6d0 100644 --- a/converter/pbm/pbmtomacp.c +++ b/converter/pbm/pbmtomacp.c @@ -18,7 +18,7 @@ /* - Implemention notes + Implementation notes Header size is 512 bytes. There is no MacBinary header. diff --git a/converter/pbm/pbmtomgr.c b/converter/pbm/pbmtomgr.c index 0e529740..faa56d8f 100644 --- a/converter/pbm/pbmtomgr.c +++ b/converter/pbm/pbmtomgr.c @@ -33,7 +33,7 @@ putinit(unsigned int const rows, head._reserved = ' '; writtenCount = fwrite(&head, sizeof(head), 1, stdout); if (writtenCount != 1) - pm_error("fwrite() failed to write the MGR header."); + pm_error("fwrite() failed to write the MGR header."); } @@ -63,7 +63,7 @@ main(int argc, inputFileName = argv[1]; else inputFileName = "-"; - + ifP = pm_openr(inputFileName); pbm_readpbminit(ifP, &cols, &rows, &format); @@ -71,14 +71,14 @@ main(int argc, pm_error("Image width too large: %u (max: %u)", cols, maxDimension); if (rows > maxDimension) pm_error("Image height too large: %u (max: %u)", rows, maxDimension); - + bitrow = pbm_allocrow_packed(cols); bytesPerRow = pbm_packed_bytes(cols); putinit(rows, cols); - + for (row = 0; row < rows; ++row) { - /* The raster formats are identical. + /* The raster formats are identical. The row end pad bits are set to 0 in mgr. */ size_t bytesWritten; @@ -89,7 +89,7 @@ main(int argc, bytesWritten = fwrite(bitrow, 1, bytesPerRow, stdout); if (bytesWritten != bytesPerRow ) pm_error("fwrite() failed to write MGR bitmap " - "to Standard Output."); + "to Standard Output."); } pm_close(ifP); return 0; @@ -102,7 +102,7 @@ main(int argc, pbm_readpbmrow_packed(), write function from putc() to fwrite(). Retired bitwise transformation functions. - + Produces only new style bitmap (8 bit padding.) See mgrtopbm.c . */ diff --git a/converter/pbm/pbmtonokia.c b/converter/pbm/pbmtonokia.c index 80b0bd59..4604064a 100644 --- a/converter/pbm/pbmtonokia.c +++ b/converter/pbm/pbmtonokia.c @@ -83,7 +83,7 @@ parseCommandLine(int argc, char ** argv, MALLOCARRAY_NOFAIL(option_def, 100); option_def_index = 0; /* incremented by OPTENT3 */ - OPTENT3(0, "fmt", OPT_STRING, &fmtOpt, + OPTENT3(0, "fmt", OPT_STRING, &fmtOpt, &fmtSpec, 0); OPTENT3(0, "net", OPT_STRING, &netOpt, &netSpec, 0); @@ -135,7 +135,7 @@ parseCommandLine(int argc, char ** argv, "the 120 characters allowed by the format.", (unsigned)strlen(cmdlineP->txt)); - if (argc-1 == 0) + if (argc-1 == 0) cmdlineP->inputFileName = "-"; else if (argc-1 != 1) pm_error("Program takes zero or one argument (filename). You " @@ -180,7 +180,7 @@ convertToHexNol(bit ** const image, /* header */ fprintf(ofP, "06050415820000%s00%02X%02X01", networkCode, cols, rows); - + /* image */ for (row = 0; row < rows; ++row) { unsigned int col; @@ -245,7 +245,7 @@ convertToHexNpm(bit ** const image, FILE * const ofP) { unsigned int row; - + /* header */ fprintf(ofP, "060504158A0000"); @@ -293,7 +293,7 @@ convertToNol(bit ** const image, unsigned int row; char header[32]; unsigned int it; - + /* header - this is a hack */ header[ 0] = 'N'; @@ -318,7 +318,7 @@ convertToNol(bit ** const image, header[19] = 0; fwrite(header, 20, 1, ofP); - + /* image */ for (row = 0; row < rows; ++row) { unsigned int col; @@ -368,7 +368,7 @@ convertToNgg(bit ** const image, header[15] = 0; fwrite(header, 16, 1, ofP); - + /* image */ for (row = 0; row < rows; ++row) { @@ -395,35 +395,56 @@ convertToNpm(bit ** const image, const char * const text, FILE * const ofP) { + size_t const textLen = text ? strlen(text) : 0; + unsigned int row; char header[132]; - size_t len; - - if (text) - len = strlen(text); - else - len = 0; /* header and optional text */ - header[ 0] = 'N'; - header[ 1] = 'P'; - header[ 2] = 'M'; - header[ 3] = 0; - header[ 4] = len; - header[ 5] = 0; - if (text) - memcpy(&header[6], text, len); - header[ 6 + len] = cols; - header[ 7 + len] = rows; - header[ 8 + len] = 1; - header[ 9 + len] = 1; - header[10 + len] = 0; /* unknown */ - - assert(10 + len < sizeof(header)); - - fwrite(header, 11 + len, 1, ofP); - + /* Our entry condition is that 'text' be a legal text field, which means + no more than 120 characters: + */ + assert(textLen <= 120); + + /* We don't have any specification of this format, but in May 2020, we + found what looks like a bug: the memcpy of the text field started at + &header[5] (overwriting the previous setting of header[5] and leaving + header[6+len-1] not set to anything). Nobody ever complained about + this, so maybe somehow it worked better than the sensible code we have + now, where the text field starts in the 7th byte. + */ + + /* The code below that deliberately avoids using 'text' as an argument to + memcpy when 'text' is null looks like it should have no practical + effect, because with a zero length memcpy, it shouldn't matter what the + from and to arguments are. But it's logically correct - a null pointer + just doesn't point anywhere. And believe it or not, it has a practical + effect - a truly bizarre one. This code used to be simpler and just + pass that null pointer to memcpy, with length 0, and as reported in May + 2020, a new optimizing compiler caused header[3] to contain random + values. That's right: 3. Skipping that presumed no-op memcpy stopped + the behavior. + */ + + header[ 0] = 'N'; + header[ 1] = 'P'; + header[ 2] = 'M'; + header[ 3] = 0; + header[ 4] = textLen; + header[ 5] = 0; + if (text) /* see above */ + memcpy(&header[6], text, textLen); + header[ 6 + textLen] = cols; + header[ 7 + textLen] = rows; + header[ 8 + textLen] = 1; + header[ 9 + textLen] = 1; + header[10 + textLen] = 0; /* unknown */ + + assert(10 + textLen < sizeof(header)); + + fwrite(header, 11 + textLen, 1, ofP); + /* image: stream of bits, each row padded to a byte boundary inspired by gnokii/common/gsm-filesystems.c */ @@ -453,7 +474,7 @@ convertToNpm(bit ** const image, -int +int main(int argc, char * argv[]) { @@ -521,6 +542,6 @@ Testing: The data was send with EMI/UCP protocol over TCP/IP. - 7.6.2001: tested with Nokia 3210: 72x14 Operator Logo - - 7.6.2001: tested with Nokia 6210: 72x14 Operator Logo and + - 7.6.2001: tested with Nokia 6210: 72x14 Operator Logo and 72x14 Group Graphic */ diff --git a/converter/pbm/pbmtopk.c b/converter/pbm/pbmtopk.c index 2f05d449..3f54254c 100644 --- a/converter/pbm/pbmtopk.c +++ b/converter/pbm/pbmtopk.c @@ -1,8 +1,8 @@ /* pbmtopk, adapted from "pxtopk.c by tomas rokicki" by AJCD 1/8/90 - + References (retrieved May 31 2015): - Packed (PK) Font File Format + Packed (PK) Font File Format https://www.tug.org/TUGboat/tb06-3/tb13pk.pdf Tex Font Metric Files (TFM) @@ -148,7 +148,7 @@ compute_checksum() temp_width:=memory[char_wd[c]]; if design_units<>unity then temp_width:=round((temp_width/design_units)*1048576.0); - temp_width:=temp_width + (c+4)*@'20000000; + temp_width:=temp_width + (c+4)*@'20000000; {this should be positive} c0:=(c0+c0+temp_width) mod 255; c1:=(c1+c1+temp_width) mod 253; @@ -173,12 +173,12 @@ compute_checksum() static byte -add_tfmtable(int * const table, - int * const count, - int const value, - int const max_count, +add_tfmtable(int * const table, + int * const count, + int const value, + int const max_count, const char * const name) { - + integer i; for (i = 0; i < *count; i++) /* search for value in tfm table */ if (table[i] == value) return (byte)i; @@ -194,8 +194,8 @@ add_tfmtable(int * const table, /* add a suffix to a filename in an allocated space */ -static void -pbmtopk_add_suffix(char * const name, +static void +pbmtopk_add_suffix(char * const name, const char * const suffix) { char *slash = strrchr(name, '/'); @@ -208,7 +208,7 @@ pbmtopk_add_suffix(char * const name, /* initialize the PK parameters */ -static void +static void initialize_pk(void) { integer i ; pm_message("This is PBMtoPK, version 2.4") ; @@ -225,13 +225,13 @@ initialize_pk(void) { /* write a single byte to the PK file */ -static void +static void pbmtopk_pkbyte(integer const b_in) { integer b; b = b_in; /* initial value */ - if (b < 0) + if (b < 0) b += 256 ; putc(b, pkfile) ; pbmtopk_pkloc++ ; @@ -240,13 +240,13 @@ pbmtopk_pkbyte(integer const b_in) { /* write two bytes to the PK file */ -static void +static void pkhalfword(integer const a_in) { integer a; a = a_in; - if (a < 0) + if (a < 0) a += 65536 ; pbmtopk_pkbyte(a >> 8) ; pbmtopk_pkbyte(a & 255) ; @@ -255,7 +255,7 @@ pkhalfword(integer const a_in) { /* write three bytes to the PK file */ -static void +static void pkthreebytes(integer const a) { pbmtopk_pkbyte((a>>16) & 255) ; @@ -266,7 +266,7 @@ pkthreebytes(integer const a) { /* write four bytes to the PK file */ -static void +static void pkword(integer const a) { pbmtopk_pkbyte((a>>24) & 255) ; pbmtopk_pkbyte((a>>16) & 255) ; @@ -277,7 +277,7 @@ pkword(integer const a) { /* write a nibble to the PK file */ -static void +static void pknyb(integer const a) { if (bitweight == 16) { @@ -292,15 +292,15 @@ pknyb(integer const a) { /* write preamble to PK file */ -static void +static void writepreamble(void) { integer i ; const char * const comment = "PBMtoPK 2.4 output" ; - + pbmtopk_pkbyte(247) ; /* PRE command */ pbmtopk_pkbyte(89) ; /* PK file type */ pbmtopk_pkbyte(strlen(comment)) ; /* output comment */ - for (i = 0 ; i < strlen(comment); i++) + for (i = 0 ; i < strlen(comment); i++) pbmtopk_pkbyte(xord[(int)comment[i]]) ; pkword(designsize) ; /* write designsize */ pkword(checksum) ; /* write checksum; calculate if possible */ @@ -311,7 +311,7 @@ writepreamble(void) { /* write postamble to PK file, padded to word length */ -static void +static void writepostamble(void) { pbmtopk_pkbyte(245) ; /* POST command */ while (pbmtopk_pkloc % 4) @@ -322,7 +322,7 @@ writepostamble(void) { /* write a byte to the TFM file */ -static void +static void tfmbyte(integer const b_in) { integer b; @@ -335,9 +335,9 @@ tfmbyte(integer const b_in) { /* write a half word to the TFM file */ -static void +static void tfmhalfword(integer const a_in) { - + integer a; a = a_in; @@ -350,7 +350,7 @@ tfmhalfword(integer const a_in) { /* write a word to the TFM file */ -static void +static void tfmword(integer const a) { tfmbyte((a>>24) & 255) ; tfmbyte((a>>16) & 255) ; @@ -361,12 +361,12 @@ tfmword(integer const a) { /* write the whole TFM file for the font */ -static void +static void writetfmfile(void) { integer totallength ; integer headersize = 17; integer i ; - + if (largestch - smallestch < 0) { largestch = 0; smallestch = 1; @@ -406,23 +406,23 @@ writetfmfile(void) { /* header */ tfmword(checksum) ; /* write checksum */ tfmword(designsize) ; /* write designsize */ - if (strlen(codingscheme) > 39) + if (strlen(codingscheme) > 39) tfmbyte(39) ; /* write coding scheme len */ - else + else tfmbyte(strlen(codingscheme)) ; for (i = 0; i < 39; i++) /* write coding scheme */ - if + if (*codingscheme) tfmbyte(xord[(int)(*codingscheme++)]) ; else tfmbyte(0) ; - if (strlen(familyname) > 19) + if (strlen(familyname) > 19) tfmbyte(19) ; /* write family length */ - else + else tfmbyte(strlen(familyname)) ; for (i = 0; i < 19; i++) /* write family */ - if (*familyname) + if (*familyname) tfmbyte(xord[(int)(*familyname++)]) ; - else + else tfmbyte(0) ; /* char_info */ for (car = smallestch; car <= largestch; car++) @@ -441,7 +441,7 @@ writetfmfile(void) { for (i = 0; i < numdepth; i++) tfmword(depthtab[i]) ; /* italic correction table */ for (i = 0; i < numitalic; i++) tfmword(italictab[i]) ; - /* no lig_kern, kern, or exten tables */ + /* no lig_kern, kern, or extent tables */ /* fontdimen table */ for (i = 0; i < numparam; i++) if (i && !fixrange(parameters[i])) @@ -456,11 +456,11 @@ writetfmfile(void) { /* read a character from a PBM file */ static void readcharacter(void) { FILE *fp; - + fp = pm_openr(filename[car]); bitmap = pbm_readpbm(fp, &width, &height) ; pm_close(fp) ; - + if ((charflags[car] & HORZESC) == 0) horzesc[car] = width ; if ((charflags[car] & VERTESC) == 0) vertesc[car] = 0; if ((charflags[car] & XOFFSET) == 0) xoffset[car] = 0; @@ -470,10 +470,10 @@ static void readcharacter(void) { if ((charflags[car] & TFMHEIGHT) == 0) hgtindex[car] = add_tfmheight(fixword(designunits(yoffset[car]+1))); if ((charflags[car] & TFMDEPTH) == 0) - depindex[car] = + depindex[car] = add_tfmdepth(fixword(designunits(height-1-yoffset[car]))); if ((charflags[car] & TFMITALIC) == 0) italindex[car] = 0; - + if (car < smallestch) smallestch = car; if (car > largestch) largestch = car; if (width > emwidth) emwidth = width ; @@ -482,14 +482,14 @@ static void readcharacter(void) { /* test if two rows of the PBM are the same */ -static int -equal(const bit * const row1, +static int +equal(const bit * const row1, const bit * const row2) { integer i ; - + for (i = 0; i < width; i++) - if (row1[i] != row2[i]) + if (row1[i] != row2[i]) return (0) ; return(1) ; @@ -497,7 +497,7 @@ equal(const bit * const row1, -static void +static void shipcharacter(void) { integer compsize ; @@ -526,13 +526,13 @@ shipcharacter(void) { integer max2 ; integer predpkloc ; integer buff ; - + integer tfwid = widthtab[tfmindex[car]] ; integer hesc = horzesc[car] ; integer vesc = vertesc[car] ; integer xoff = xoffset[car] ; integer yoff = yoffset[car] ; - + MALLOCARRAY(repeatptr, height + 1); MALLOCARRAY(bitcounts, height * width); if (repeatptr == NULL || bitcounts == NULL) @@ -781,8 +781,8 @@ shipcharacter(void) { } if (predpkloc != pbmtopk_pkloc) pm_error("bad predicted character length: character %d", car); - pbm_freerow(zerorow); - pbm_freerow(onesrow); + pbm_freerow(zerorow); + pbm_freerow(onesrow); free((char *)repeatptr); free((char *)bitcounts); } @@ -790,7 +790,7 @@ shipcharacter(void) { /* check that character is in valid range */ -static void +static void checkchar(void) { if (car < 0 || car >= MAXPKCHAR) pm_error("character must be in range 0 to %d", MAXPKCHAR-1) ; @@ -799,16 +799,16 @@ checkchar(void) { /* read character information from an option file */ -static void +static void optionfile(const char * const name) { FILE *fp ; char buffer[MAXOPTLINE] ; - + fp = pm_openr(name); while (!feof(fp)) { char *here = buffer; - + if (fgets(buffer, MAXOPTLINE, fp) == NULL) break ; while (ISSPACE(*here)) here++ ; if (*here && *here == '=') { @@ -817,7 +817,7 @@ optionfile(const char * const name) { } else if (*here && *here != '%' && *here != '#') { char str[NAMELENGTH] ; integer i, n; - + checkchar() ; if (sscanf(here, "%s%n", str, &n) != 1) pm_error("bad option file line %s", buffer) ; @@ -881,26 +881,26 @@ main(int argc, char *argv[]) { pbm_init(&argc, argv); initialize_pk() ; - + if (--argc < 1) pm_usage(usage) ; ++argv; if(strlen(*argv) + 4 > NAMELENGTH) pm_error("pkname is too long"); strcpy(pkname, *argv) ; pbmtopk_add_suffix(pkname, ".pk") ; - + if (--argc < 1) pm_usage(usage); ++argv; if(strlen(*argv) + 4 > NAMELENGTH) pm_error("tfmname is too long"); strcpy(tfmname, *argv) ; pbmtopk_add_suffix(tfmname, ".tfm") ; - + if (--argc < 1) pm_usage(usage) ; resolution = atoi(*++argv) ; if (resolution < 1 || resolution > 32767) pm_error("unlikely resolution %d dpi", resolution); - + car = flags = hesc = vesc = xoff = yoff = tfwid = 0; while (++argv, --argc) { if (argv[0][0] == '-' && argv[0][1]) { @@ -922,7 +922,7 @@ main(int argc, char *argv[]) { case 's': designsize = fixword(atof(p)); if (designsize < 1048576) - pm_error("design size %f out of range", + pm_error("design size %f out of range", unfixword(designsize)); case 'h': hesc = atoi(p) ; @@ -1009,3 +1009,5 @@ main(int argc, char *argv[]) { return 0; } + + diff --git a/converter/pbm/pbmtoppa/README.REDHAT b/converter/pbm/pbmtoppa/README.REDHAT index 3586aea2..e7b30490 100644 --- a/converter/pbm/pbmtoppa/README.REDHAT +++ b/converter/pbm/pbmtoppa/README.REDHAT @@ -17,7 +17,7 @@ StartEntry: DeskJet720C It does does not support color printing. \ IMPORTANT! Insert \ "- | pbm2ppa -" \ - in the "Extra GS Otions" field.\ + in the "Extra GS Options" field.\ } Resolution: {600} {600} {} EndEntry diff --git a/converter/pbm/pbmtoppa/ppa.c b/converter/pbm/pbmtoppa/ppa.c index aa30d684..69e7bb79 100644 --- a/converter/pbm/pbmtoppa/ppa.c +++ b/converter/pbm/pbmtoppa/ppa.c @@ -207,7 +207,7 @@ void ppa_init_job(ppa_stat* prn) scp3_put (prn->fptr, 0x018f, sizeof(init3), 7, 2, 4, init3); break; default: - fprintf(stderr,"ppa_init_job(): unknown printer verson\n"); + fprintf(stderr,"ppa_init_job(): unknown printer version\n"); } } @@ -238,7 +238,7 @@ void ppa_init_page(ppa_stat* prn) scp3_put (prn->fptr, 0x0183, sizeof(pageA), 5, 1, 0, pageA); break; default: - fprintf(stderr,"ppa_init_page(): unknown printer verson\n"); + fprintf(stderr,"ppa_init_page(): unknown printer version\n"); } } @@ -260,7 +260,7 @@ void ppa_load_page(ppa_stat* prn) scp3_put (prn->fptr, 0x0181, sizeof(loadC), 7, 1, 0, loadC); break; default: - fprintf(stderr,"ppa_load_page(): unknown printer verson\n"); + fprintf(stderr,"ppa_load_page(): unknown printer version\n"); } } @@ -282,7 +282,7 @@ void ppa_eject_page(ppa_stat* prn) scp3_put (prn->fptr, 0x0181, sizeof(loadC), 7, 1, 0, loadC); break; default: - fprintf(stderr,"ppa_eject_page(): unknown printer verson\n"); + fprintf(stderr,"ppa_eject_page(): unknown printer version\n"); } } @@ -440,7 +440,7 @@ void ppa_print_sweep(ppa_stat* prn,ppa_sweep_data* data) MF=1; break; default: - fprintf(stderr,"ppa_print_sweep(): unknown printer verson\n"); + fprintf(stderr,"ppa_print_sweep(): unknown printer version\n"); return; } diff --git a/converter/pbm/pbmtoptx.c b/converter/pbm/pbmtoptx.c index c0fb0f80..69f1707a 100644 --- a/converter/pbm/pbmtoptx.c +++ b/converter/pbm/pbmtoptx.c @@ -12,10 +12,10 @@ #include "pbm.h" -/* Follwing is obtained by reversing bit order (MFS-LFS) and adding 64. */ +/* Following is obtained by reversing bit order (MFS-LFS) and adding 64. */ /* Note the two escape sequences: \\ and \x7f . */ -static unsigned char const ptxchar[64] = +static unsigned char const ptxchar[64] = "@`PpHhXxDdTtLl\\|BbRrJjZzFfVvNn^~AaQqIiYyEeUuMm]}CcSsKk[{GgWwOo_\x7f"; @@ -32,7 +32,7 @@ putBitrow(const bit * const bitrow, unsigned int const byteCnt = (itemCnt * 6) / 8; bit const byteCur = bitrow[byteCnt]; bit const byteNext = bitrow[byteCnt + 1]; - + unsigned int item; switch (itemCnt % 4) { @@ -62,7 +62,7 @@ main(int argc, const char ** argv) { ifP = stdin; else { ifP = pm_openr(argv[1]); - + if (argc-1 > 1) pm_error("Too many arguments. The only possible argument is " "the input fil name"); @@ -82,9 +82,8 @@ main(int argc, const char ** argv) { pbm_freerow_packed(bitrow); pm_close(ifP); - + return 0; } - diff --git a/converter/pbm/pbmtox10bm b/converter/pbm/pbmtox10bm index deb3aeab..ca82fcd2 100644 --- a/converter/pbm/pbmtox10bm +++ b/converter/pbm/pbmtox10bm @@ -37,6 +37,16 @@ exec perl -w -x -S -- "$0" "$@" use strict; use File::Basename; use Cwd 'abs_path'; +use IO::Handle; + + + +sub pm_message($) { + STDERR->print("pbmtox10bm: $_[0]\n"); +} + + + sub doVersionHack($) { my ($argvR) = @_; @@ -56,13 +66,12 @@ my $infile; foreach (@ARGV) { if (/^-/) { # It's an option. But Pbmtox10bm didn't have any options. - print(STDERR "Invalid option '$_'\n"); + pm_message("Invalid option '$_'"); exit(10); } else { # It's a parameter if (defined($infile)) { - print(STDERR - "You may specify at most one non-option parameter.\n"); + pm_message("You may specify at most one non-option parameter."); exit(10); } else { $infile = $_; diff --git a/converter/pbm/xbmtopbm.c b/converter/pbm/xbmtopbm.c index bbf4e395..1f5384ed 100644 --- a/converter/pbm/xbmtopbm.c +++ b/converter/pbm/xbmtopbm.c @@ -109,25 +109,35 @@ parseDeclaration(const char * const line, -----------------------------------------------------------------------------*/ char nameAndType[MAX_LINE]; int rc; - + rc = sscanf(line, "static short %s = {", nameAndType); if (rc == 1) { *version10P = TRUE; *isDeclarationP = TRUE; } else { int rc; - rc = sscanf(line, "static char %s = {", nameAndType); + rc = sscanf(line, "static unsigned short %s = {", nameAndType); if (rc == 1) { - *version10P = FALSE; + /* This is apparently not legal X10 XBM; we recognize it as an + extension. Many non-Netpbm programs won't. + */ + *version10P = TRUE; *isDeclarationP = TRUE; } else { int rc; - rc = sscanf(line, "static unsigned char %s = {", nameAndType); + rc = sscanf(line, "static char %s = {", nameAndType); if (rc == 1) { *version10P = FALSE; *isDeclarationP = TRUE; - } else - *isDeclarationP = FALSE; + } else { + int rc; + rc = sscanf(line, "static unsigned char %s = {", nameAndType); + if (rc == 1) { + *version10P = FALSE; + *isDeclarationP = TRUE; + } else + *isDeclarationP = FALSE; + } } } } @@ -178,7 +188,7 @@ getXbmHeader(FILE * const ifP, } } - if (!foundDeclaration) + if (!foundDeclaration) pm_error("Unable to find a line in the file containing the start " "of C array declaration (\"static char\" or whatever)"); @@ -208,7 +218,7 @@ getHexByte(FILE * const ifP, assert(c1 >= 0); assert(c1 < 256); assert(c2 >= 0); assert(c2 < 256); - + value = (hexTable[c1] << 4) + hexTable[c2]; if (value >= 256) pm_error("Invalid XBM input. What should be a two digit " @@ -218,7 +228,7 @@ getHexByte(FILE * const ifP, } - + static void readX10Raster(FILE * const ifP, unsigned int const rasterLength, @@ -301,7 +311,7 @@ readBitmapFile(FILE * const ifP, mustPad = (width % 16 >= 1 && width % 16 <= 8 && version10); bytesPerLine = (width + 7) / 8 + (mustPad ? 1 : 0); - + rasterLength = bytesPerLine * height; MALLOCARRAY(data, rasterLength); @@ -331,7 +341,7 @@ main(int argc, const char * inputFileName; unsigned char * p; /* Cursor in raster data data[] */ - + initHexTable(); pbm_init(&argc, argv); @@ -339,7 +349,7 @@ main(int argc, if (argc-1 > 1) pm_error("The only possible argument is the input file name. " "You specified %u arguments", argc-1); - + if (argc-1 > 0) inputFileName = argv[1]; else @@ -359,7 +369,7 @@ main(int argc, for (row = 0; row < rows; ++row) { unsigned int const bytesPerRow = pbm_packed_bytes(cols); unsigned int i; - + for (i = 0; i < bytesPerRow; ++i) bitrow[i] = bitreverse[*p++]; diff --git a/converter/pbm/ybmtopbm.c b/converter/pbm/ybmtopbm.c index ea7e66a7..36f2dee7 100644 --- a/converter/pbm/ybmtopbm.c +++ b/converter/pbm/ybmtopbm.c @@ -19,7 +19,7 @@ static short const ybmMagic = ( ( '!' << 8 ) | '!' ); static void -getinit(FILE * const ifP, +getinit(FILE * const ifP, unsigned int * const colsP, unsigned int * const rowsP, int * const depthP) { @@ -80,7 +80,7 @@ main(int argc, const char * argv[]) { getinit(ifP, &cols, &rows, &depth); if (depth != 1) pm_error("YBM file has depth of %u, must be 1", (unsigned int) depth); - + pbm_writepbminit(stdout, cols, rows, 0); bitrow = pbm_allocrow_packed(cols + 8); @@ -95,7 +95,7 @@ main(int argc, const char * argv[]) { for (i = 0; i < itemCt; ++i) { short int item; pm_readbigshort(ifP, &item); - itemrow[i] = (uint16_t) item; + itemrow[i] = (uint16_t) item; } for (i = 0; i < pbm_packed_bytes(cols); ++i) |