diff options
Diffstat (limited to 'converter/ppm/ppmtowinicon.c')
-rw-r--r-- | converter/ppm/ppmtowinicon.c | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c index bd478b1e..2d8ddaf7 100644 --- a/converter/ppm/ppmtowinicon.c +++ b/converter/ppm/ppmtowinicon.c @@ -10,6 +10,7 @@ ** implied warranty. */ +#include <stdbool.h> #include <assert.h> #include <math.h> #include <string.h> @@ -57,9 +58,7 @@ parseCommandLine(int argc, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; optStruct3 opt; unsigned int option_def_index; @@ -79,10 +78,10 @@ parseCommandLine(int argc, &cmdlineP->verbose, 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 */ + 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); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (!outputSpec) @@ -272,14 +271,14 @@ fillInRaster1(u1 ** const rowData, for (row = 0; row <rows; ++row) { u1 * thisRow; /* malloc'ed */ - unsigned int byteOn; - unsigned int bitOn; + unsigned int byteSeq; + unsigned int bitOnMask; MALLOCARRAY_NOFAIL(thisRow, xByteCt); - memset (thisRow, 0, xByteCt); + memset(thisRow, 0, xByteCt); /* initial value */ rowData[rows - row - 1] = thisRow; - byteOn = 0; /* initial value */ - bitOn = 128; /* initial value */ + byteSeq = 0; /* initial value */ + bitOnMask = 0x80; /* initial value */ if (pa) { unsigned int col; @@ -291,16 +290,19 @@ fillInRaster1(u1 ** const rowData, Unless the hashing function changes, 0's black. */ int const value = ppm_lookupcolor(cht, &pa[row][col]); + + assert(byteSeq < xByteCt); + if (!value) { /* leave black. */ } else { - thisRow[byteOn] |= bitOn; + thisRow[byteSeq] |= bitOnMask; } - if (bitOn == 1) { - ++byteOn; - bitOn = 128; + if (bitOnMask == 0x1) { + ++byteSeq; + bitOnMask = 0x80; } else { - bitOn >>= 1; + bitOnMask >>= 1; } } } else { @@ -323,15 +325,15 @@ fillInRaster4(u1 ** const rowData, for (row = 0; row < rows; ++row) { u1 * thisRow; - unsigned int byteOn; - unsigned int nibble; /* high nibble = 1, low nibble = 0; */ + unsigned int byteSeq; + unsigned int nibbleSig; /* high nibble = 1, low nibble = 0; */ MALLOCARRAY_NOFAIL(thisRow, xByteCt); memset(thisRow, 0, xByteCt); rowData[rows - row - 1] = thisRow; - byteOn = 0; /* initial value */ - nibble = 1; /* initial value */ + byteSeq = 0; /* initial value */ + nibbleSig = 1; /* initial value */ if (pa) { unsigned int col; @@ -339,16 +341,18 @@ fillInRaster4(u1 ** const rowData, for (col = 0; col < cols; ++col) { int value; + assert(byteSeq < xByteCt); + value = ppm_lookupcolor(cht, &pa[row][col]); /* init value */ /* Shift it, if we're putting it in the high nibble. */ - if (nibble) + if (nibbleSig == 1) value <<= 4; - thisRow[byteOn] |= value; - if (nibble == 1) - nibble = 0; + thisRow[byteSeq] |= value; + if (nibbleSig == 1) + nibbleSig = 0; else { - nibble = 1; - ++byteOn; + nibbleSig = 1; + ++byteSeq; } } } else { @@ -372,8 +376,10 @@ fillInRaster8(u1 ** const rowData, for (row = 0; row < rows; ++row) { u1 * thisRow; /* malloc'ed */ + assert(cols <= xByteCt); + MALLOCARRAY_NOFAIL(thisRow, xByteCt); - memset (thisRow, 0, xByteCt); + memset(thisRow, 0, xByteCt); rowData[rows - row - 1] = thisRow; if (pa) { unsigned int col; |