diff options
Diffstat (limited to 'converter/other/giftopnm.c')
-rw-r--r-- | converter/other/giftopnm.c | 330 |
1 files changed, 192 insertions, 138 deletions
diff --git a/converter/other/giftopnm.c b/converter/other/giftopnm.c index b0d479d5..f0946c9e 100644 --- a/converter/other/giftopnm.c +++ b/converter/other/giftopnm.c @@ -24,6 +24,7 @@ #define _BSD_SOURCE /* for strcaseeq */ #include <string.h> #include <assert.h> +#include <stdbool.h> #include "pm_config.h" #include "pm_c_util.h" @@ -42,13 +43,13 @@ #define MAX_LZW_BITS 12 #ifndef FASTPBMRENDER - #define FASTPBMRENDER TRUE + #define FASTPBMRENDER true #endif static const bool useFastPbmRender = FASTPBMRENDER; #ifndef REPORTLZWCODES - #define REPORTLZWCODES FALSE + #define REPORTLZWCODES false #endif static const bool wantLzwCodes = REPORTLZWCODES; @@ -61,7 +62,11 @@ readFile(FILE * const ifP, unsigned char * const buffer, size_t const len, const char ** const errorP) { +/*---------------------------------------------------------------------------- + Read the next 'len' bytes from *ifP into 'buffer'. + Fail if there aren't that many bytes to read. +-----------------------------------------------------------------------------*/ size_t bytesRead; bytesRead = fread(buffer, 1, len, ifP); @@ -92,7 +97,7 @@ struct CmdlineInfo { bool allImages; /* He wants all the images */ unsigned int imageNum; /* image number he wants from input, starting at 0. Undefined - if allImages is TRUE + if allImages is true */ const char * alphaFileName; unsigned int quitearly; @@ -102,7 +107,7 @@ struct CmdlineInfo { static void -parseCommandLine(int argc, char ** argv, +parseCommandLine(int argc, const char ** argv, struct CmdlineInfo * const cmdlineP) { /*---------------------------------------------------------------------------- Note that the file spec array we return is stored in the storage that @@ -136,20 +141,20 @@ parseCommandLine(int argc, char ** argv, &alphaSpec, 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, argv, opt, sizeof(opt), 0); + pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ free(option_def); if (!imageSpec) { cmdlineP->imageNum = 0; - cmdlineP->allImages = FALSE; + cmdlineP->allImages = false; } else { if (strcaseeq(image, "all")) { - cmdlineP->allImages = TRUE; + cmdlineP->allImages = true; } else { char * tailptr; @@ -165,7 +170,7 @@ parseCommandLine(int argc, char ** argv, pm_error("Invalid value for 'image' option. You specified " "zero. The first image is 1."); - cmdlineP->allImages = FALSE; + cmdlineP->allImages = false; cmdlineP->imageNum = (unsigned int) imageNum - 1; } } @@ -312,8 +317,8 @@ readColorMap(FILE * const ifP, assert(cmapSize <= MAXCOLORMAPSIZE); - *hasGrayP = FALSE; /* initial assumption */ - *hasColorP = FALSE; /* initial assumption */ + *hasGrayP = false; /* initial assumption */ + *hasColorP = false; /* initial assumption */ for (i = 0; i < cmapSize; ++i) { const char * error; @@ -327,16 +332,16 @@ readColorMap(FILE * const ifP, if (rgb[0] == rgb[1] && rgb[1] == rgb[2]) { if (rgb[0] != 0 && rgb[0] != GIFMAXVAL) - *hasGrayP = TRUE; + *hasGrayP = true; } else - *hasColorP = TRUE; + *hasColorP = true; } cmapP->size = cmapSize; } -static bool zeroDataBlock = FALSE; +static bool zeroDataBlock = false; /* the most recently read DataBlock was an EOD marker, i.e. had zero length */ @@ -355,10 +360,10 @@ getDataBlock(FILE * const ifP, of the datablock at 'buf', and its length as *lengthP. Except that if we hit EOF or have an I/O error reading the first - byte (size field) of the DataBlock, we return *eofP == TRUE and + byte (size field) of the DataBlock, we return *eofP == true and *lengthP == 0. - We return *eofP == FALSE if we don't hit EOF or have an I/O error. + We return *eofP == false if we don't hit EOF or have an I/O error. If we hit EOF or have an I/O error reading the data portion of the DataBlock, we exit the program with pm_error(). @@ -375,21 +380,21 @@ getDataBlock(FILE * const ifP, error); pm_strfree(error); *errorP = NULL; - *eofP = TRUE; + *eofP = true; *lengthP = 0; } else { if (verbose) pm_message("%d byte block at Position %ld", count, pos); - *eofP = FALSE; + *eofP = false; *lengthP = count; if (count == 0) { *errorP = NULL; - zeroDataBlock = TRUE; + zeroDataBlock = true; } else { const char * error; - zeroDataBlock = FALSE; + zeroDataBlock = false; readFile(ifP, buf, count, &error); if (error) { @@ -417,7 +422,7 @@ readThroughEod(FILE * const ifP) { unsigned char buf[256]; bool eod; - eod = FALSE; /* initial value */ + eod = false; /* initial value */ while (!eod) { bool eof; unsigned int count; @@ -430,7 +435,7 @@ readThroughEod(FILE * const ifP) { "anyway as if an EOD marker were at the end " "of the file."); if (error || eof || count == 0) - eod = TRUE; + eod = true; } } @@ -471,7 +476,7 @@ doCommentExtension(FILE * const ifP) { unsigned int blocklen; bool done; - done = FALSE; + done = false; while (!done) { bool eof; const char * error; @@ -480,7 +485,7 @@ doCommentExtension(FILE * const ifP) { pm_error("Error reading a data block in a comment extension. %s", error); if (blocklen == 0 || eof) - done = TRUE; + done = true; else { buf[blocklen] = '\0'; if (showComment) { @@ -622,7 +627,7 @@ getAnotherBlock(FILE * const ifP, /* Add the next block to the buffer */ getDataBlock(ifP, &gsP->buf[gsP->bufCount], &eof, &count, errorP); if (*errorP) - gsP->streamExhausted = TRUE; + gsP->streamExhausted = true; else { if (eof) { pm_message("EOF encountered in image " @@ -652,7 +657,7 @@ getCode_init(struct GetCodeState * const getCodeStateP) { getCodeStateP->buf[1] = 0; getCodeStateP->bufCount = 2; getCodeStateP->curbit = getCodeStateP->bufCount * 8; - getCodeStateP->streamExhausted = FALSE; + getCodeStateP->streamExhausted = false; } @@ -708,14 +713,14 @@ getCode_get(struct GetCodeState * const gsP, 'codeSize' is the number of bits in the code we are to get. - Return *eofP == TRUE iff we hit the end of the stream. That means a legal + Return *eofP == true iff we hit the end of the stream. That means a legal end of stream, marked by an EOD marker, not just end of file. An end of file in the middle of the GIF stream is an error. If there are bits left in the stream, but not 'codeSize' of them, we - call that a success with *eofP == TRUE. + call that a success with *eofP == true. - Return the code read (assuming *eofP == FALSE and *errorP == NULL) + Return the code read (assuming *eofP == false and *errorP == NULL) as *codeP. -----------------------------------------------------------------------------*/ @@ -737,7 +742,7 @@ getCode_get(struct GetCodeState * const gsP, /* The buffer still doesn't have enough bits in it; that means there were no data blocks left to read. */ - *eofP = TRUE; + *eofP = true; { int const bitsUnused = gsP->bufCount * 8 - gsP->curbit; @@ -754,7 +759,7 @@ getCode_get(struct GetCodeState * const gsP, pm_message("LZW code=0x%03x [%d]", *codeP, codeSize); gsP->curbit += codeSize; - *eofP = FALSE; + *eofP = false; } } } @@ -824,7 +829,7 @@ termStack(struct Stack * const stackP) { LZW is an extension of Limpel-Ziv. The two extensions are: - 1) in Limpel-Ziv, codes are all the same number of bits. In + 1) In Limpel-Ziv, codes are all the same number of bits. In LZW, they start out small and increase as the stream progresses. 2) LZW has a clear code that resets the string table and code @@ -860,7 +865,22 @@ termStack(struct Stack * const stackP) { static int const maxLzwCodeCt = (1<<MAX_LZW_BITS); -struct Decompressor { +typedef struct { +/*---------------------------------------------------------------------------- + An entry in the decompressor LZW code table. +-----------------------------------------------------------------------------*/ + unsigned int next; + /* The next code in the expansion after the one this entry specifies; + this is either another index into the LZW code table or a direct + code, which means it's the last data element in the expansion. + */ + unsigned int dataElement; + /* The data element (color map index or gray level) to add to the + expansion for this entry. + */ +} CodeTableEntry; + +typedef struct { struct Stack stack; bool fresh; /* The stream is right after a clear code or at the very beginning */ @@ -894,18 +914,24 @@ struct Decompressor { /* We are to tolerate bad input data as best we can, rather than just declaring an error and bailing out. */ - unsigned int table[(1 << MAX_LZW_BITS)][2]; /* LZW code table */ -}; + CodeTableEntry table[(1 << MAX_LZW_BITS)]; /* LZW code table */ + /* This contains the strings of expansions of LZW string codes, in + linked list form. table[N] gives the first data element for the + string with string code N and the LZW code for the rest of the + string. The latter is often a string code itself, which can also + be looked up in this table. + */ +} Decompressor; static void -resetDecompressor(struct Decompressor * const decompP) { +resetDecompressor(Decompressor * const decompP) { decompP->codeSize = decompP->initCodeSize+1; decompP->maxCodeCt = 1 << decompP->codeSize; decompP->nextTableSlot = decompP->maxDataVal + 3; - decompP->fresh = TRUE; + decompP->fresh = true; } @@ -919,7 +945,7 @@ validateTransparentIndex(unsigned int const transparentIndex, if (transparentIndex >= cmapSize) { if (tolerateBadInput) { if (transparentIndex > maxDataVal) - pm_error("Invalid transparent index value: %d", + pm_error("Invalid transparent index value: %u", transparentIndex); } else { pm_error("Invalid transparent index value %d in image with " @@ -936,13 +962,13 @@ validateTransparentIndex(unsigned int const transparentIndex, static void -lzwInit(struct Decompressor * const decompP, - FILE * const ifP, - int const initCodeSize, - unsigned int const cmapSize, - bool const haveTransColor, - unsigned int const transparentIndex, - bool const tolerateBadInput) { +lzwInit(Decompressor * const decompP, + FILE * const ifP, + int const initCodeSize, + unsigned int const cmapSize, + bool const haveTransColor, + unsigned int const transparentIndex, + bool const tolerateBadInput) { unsigned int const maxDataVal = (1 << initCodeSize) - 1; @@ -972,8 +998,8 @@ lzwInit(struct Decompressor * const decompP, { unsigned int i; for (i = 0; i <= maxDataVal; ++i) { - decompP->table[i][0] = 0; - decompP->table[i][1] = i < cmapSize ? i : 0; + decompP->table[i].next = 0; + decompP->table[i].dataElement = i < cmapSize ? i : 0; } } decompP->haveTransColor = haveTransColor; @@ -987,7 +1013,7 @@ lzwInit(struct Decompressor * const decompP, getCode_init(&getCodeState); - decompP->fresh = TRUE; + decompP->fresh = true; initStack(&decompP->stack, maxLzwCodeCt); @@ -997,8 +1023,8 @@ lzwInit(struct Decompressor * const decompP, static void -lzwAdjustForPBM(struct Decompressor * const decompP, - GifColorMap const cmap) { +lzwAdjustForPBM(Decompressor * const decompP, + GifColorMap const cmap) { /*---------------------------------------------------------------------------- In the PBM case we use the table index value directly instead of looking up the color map for each pixel. @@ -1009,13 +1035,14 @@ lzwAdjustForPBM(struct Decompressor * const decompP, ----------------------------------------------------------------------------*/ unsigned int i; for (i = 0; i < cmap.size; ++i) - decompP->table[i][1] = cmap.map[i][0] == 0 ? PBM_BLACK : PBM_WHITE; + decompP->table[i].dataElement = + cmap.map[i][0] == 0 ? PBM_BLACK : PBM_WHITE; } static void -lzwTerm(struct Decompressor * const decompP) { +lzwTerm(Decompressor * const decompP) { termStack(&decompP->stack); } @@ -1023,8 +1050,8 @@ lzwTerm(struct Decompressor * const decompP) { static void -pushWholeStringOnStack(struct Decompressor * const decompP, - unsigned int const code0) { +pushWholeStringOnStack(Decompressor * const decompP, + unsigned int const code0) { /*---------------------------------------------------------------------------- Get the whole string that compression code 'code0' represents and push it onto the code stack so the leftmost code is on top. Set @@ -1035,21 +1062,47 @@ pushWholeStringOnStack(struct Decompressor * const decompP, for (stringCount = 0, code = code0; code > decompP->maxDataVal; - ++stringCount, code = decompP->table[code][0] + ++stringCount, code = decompP->table[code].next ) { - pushStack(&decompP->stack, decompP->table[code][1]); + pushStack(&decompP->stack, decompP->table[code].dataElement); } - decompP->firstcode = decompP->table[code][1]; + decompP->firstcode = decompP->table[code].dataElement; pushStack(&decompP->stack, decompP->firstcode); } static void -expandCodeOntoStack(struct Decompressor * const decompP, - unsigned int const incode, - const char ** const errorP) { +addLzwStringCode(Decompressor * const decompP) { + + if (decompP->nextTableSlot < maxLzwCodeCt) { + decompP->table[decompP->nextTableSlot].next = + decompP->prevcode; + decompP->table[decompP->nextTableSlot].dataElement = + decompP->firstcode; + ++decompP->nextTableSlot; + if (decompP->nextTableSlot >= decompP->maxCodeCt) { + /* We've used up all the codes of the current code size. + Future codes in the stream will have codes one bit longer. + But there's an exception if we're already at the LZW + maximum, in which case the codes will simply continue + the same size. + */ + if (decompP->codeSize < MAX_LZW_BITS) { + ++decompP->codeSize; + decompP->maxCodeCt = 1 << decompP->codeSize; + } + } + } +} + + + +static void +expandCodeOntoStack(Decompressor * const decompP, + unsigned int const incode, + const char ** const errorP) { /*---------------------------------------------------------------------------- 'incode' is an LZW string code. It represents a string of true data elements, as defined by the string translation table in *decompP. @@ -1064,58 +1117,56 @@ expandCodeOntoStack(struct Decompressor * const decompP, as *errorP). -----------------------------------------------------------------------------*/ unsigned int code; + const char * gifError; - *errorP = NULL; /* Initial value */ + gifError = NULL; /* Initial value */ if (incode <= decompP->maxDataVal) { if (incode < decompP->cmapSize) code = incode; /* Direct index */ else if (decompP->tolerateBadInput && decompP->haveTransColor && - decompP->table[incode][1] == decompP->transparentIndex) + decompP->table[incode].dataElement == + decompP->transparentIndex) /* transparent code outside cmap exceptional case */ code = incode; else - pm_asprintf(errorP, "Error in GIF image: invalid color code %u. " + pm_asprintf(&gifError, "Invalid color code %u. " "Valid color values are 0 - %u", incode, decompP->cmapSize - 1); - } - else if (incode < decompP->nextTableSlot) + } else if (incode < decompP->nextTableSlot) /* LZW string, defined */ code = incode; - else if (incode == decompP->nextTableSlot && !decompP->fresh) { + else if (incode == decompP->nextTableSlot) { /* It's a code that isn't in our translation table yet. - This does not happen with the decoder in a fresh state. */ - if (wantLzwCodes && verbose) - pm_message ("LZW code valid, but not in decoder table"); - - pushStack(&decompP->stack, decompP->firstcode); - code = decompP->prevcode; + if (decompP->fresh) + pm_asprintf(&gifError, "LZW string code encountered with " + "decompressor in fresh state"); + else { + if (wantLzwCodes && verbose) + pm_message ("LZW code valid, but not in decoder table"); + + pushStack(&decompP->stack, decompP->firstcode); + code = decompP->prevcode; + } } else - pm_asprintf(errorP, "Error in GIF image: invalid LZW code"); - - if (!*errorP) { + pm_asprintf(&gifError, "LZW string code %u " + "is neither a previously defined one nor the " + "next in sequence to define (%u)", + incode, decompP->nextTableSlot); + + if (gifError) { + pm_asprintf(errorP, "INVALID GIF IMAGE: %s", gifError); + pm_strfree(gifError); + } else { pushWholeStringOnStack(decompP, code); - if (decompP->nextTableSlot < maxLzwCodeCt) { - decompP->table[decompP->nextTableSlot][0] = decompP->prevcode; - decompP->table[decompP->nextTableSlot][1] = decompP->firstcode; - ++decompP->nextTableSlot; - if (decompP->nextTableSlot >= decompP->maxCodeCt) { - /* We've used up all the codes of the current code size. - Future codes in the stream will have codes one bit longer. - But there's an exception if we're already at the LZW - maximum, in which case the codes will simply continue - the same size. - */ - if (decompP->codeSize < MAX_LZW_BITS) { - ++decompP->codeSize; - decompP->maxCodeCt = 1 << decompP->codeSize; - } - } - } + addLzwStringCode(decompP); + decompP->prevcode = incode; + + *errorP = NULL; } } @@ -1123,7 +1174,7 @@ expandCodeOntoStack(struct Decompressor * const decompP, static void lzwReadByteFresh(struct GetCodeState * const getCodeStateP, - struct Decompressor * const decompP, + Decompressor * const decompP, bool * const endOfImageP, unsigned char * const dataReadP, const char ** const errorP) { @@ -1143,7 +1194,7 @@ lzwReadByteFresh(struct GetCodeState * const getCodeStateP, assert(decompP->fresh); /* Entry requirement */ - decompP->fresh = FALSE; + decompP->fresh = false; do { getCode_get(getCodeStateP, decompP->ifP, decompP->codeSize, @@ -1152,11 +1203,11 @@ lzwReadByteFresh(struct GetCodeState * const getCodeStateP, if (!*errorP) { if (eof) - *endOfImageP = TRUE; + *endOfImageP = true; else if (code == decompP->endCode) { if (!zeroDataBlock) readThroughEod(decompP->ifP); - *endOfImageP = TRUE; + *endOfImageP = true; } else if (code >= decompP->cmapSize) { pm_asprintf(errorP, "Error in GIF image: invalid color code %u. " "Valid color values are: 0 - %u", @@ -1166,12 +1217,12 @@ lzwReadByteFresh(struct GetCodeState * const getCodeStateP, */ decompP->prevcode = decompP->firstcode = 0; - *endOfImageP = FALSE; + *endOfImageP = false; } else { /* valid code */ decompP->prevcode = code; - decompP->firstcode = decompP->table[code][1]; + decompP->firstcode = decompP->table[code].dataElement; *dataReadP = decompP->firstcode; - *endOfImageP = FALSE; + *endOfImageP = false; } } } @@ -1180,10 +1231,10 @@ lzwReadByteFresh(struct GetCodeState * const getCodeStateP, static void -lzwReadByte(struct Decompressor * const decompP, - unsigned char * const dataReadP, - bool * const endOfImageP, - const char ** const errorP) { +lzwReadByte(Decompressor * const decompP, + unsigned char * const dataReadP, + bool * const endOfImageP, + const char ** const errorP) { /*---------------------------------------------------------------------------- Return the next data element of the decompressed image. In the context of a GIF, a data element is the color table index of one pixel. @@ -1202,7 +1253,7 @@ lzwReadByte(struct Decompressor * const decompP, -----------------------------------------------------------------------------*/ if (!stackIsEmpty(&decompP->stack)) { *errorP = NULL; - *endOfImageP = FALSE; + *endOfImageP = false; *dataReadP = popStack(&decompP->stack); } else if (decompP->fresh) { lzwReadByteFresh(&getCodeState, decompP, endOfImageP, dataReadP, @@ -1225,10 +1276,10 @@ lzwReadByte(struct Decompressor * const decompP, if (code == decompP->endCode) { if (!zeroDataBlock) readThroughEod(decompP->ifP); - *endOfImageP = TRUE; + *endOfImageP = true; *errorP = NULL; } else { - *endOfImageP = FALSE; + *endOfImageP = false; expandCodeOntoStack(decompP, code, errorP); if (!*errorP) *dataReadP = popStack(&decompP->stack); @@ -1312,6 +1363,9 @@ renderRow(unsigned char * const cmapIndexRow, /*---------------------------------------------------------------------------- Convert one row of cmap indexes to PPM/PGM/PBM output. + The row is *xelrow, which is 'cols' columns wide and has pixels of format + 'format'. + Render the alpha row to *alphaFileP iff 'alphabits' is non-NULL. If 'haveTransColor' is false, render all white (i.e. the row is opaque). 'alphabits' is otherwise just a one-row buffer for us to use @@ -1407,12 +1461,12 @@ pnmFormat(bool const hasGray, static void -makePnmRow(struct Decompressor * const decompP, - unsigned int const cols, - unsigned int const rows, - bool const fillWithZero, - unsigned char * const cmapIndexRow, - const char ** const errorP) { +makePnmRow(Decompressor * const decompP, + unsigned int const cols, + unsigned int const rows, + bool const fillWithZero, + unsigned char *const cmapIndexRow, + const char ** const errorP) { bool fillingWithZero; unsigned int col; @@ -1456,15 +1510,15 @@ makePnmRow(struct Decompressor * const decompP, static void -convertRaster(struct Decompressor * const decompP, - unsigned int const cols, - unsigned int const rows, - GifColorMap const cmap, - bool const interlace, - FILE * const imageOutFileP, - FILE * const alphaFileP, - bool const hasGray, - bool const hasColor) { +convertRaster(Decompressor * const decompP, + unsigned int const cols, + unsigned int const rows, + GifColorMap const cmap, + bool const interlace, + FILE * const imageOutFileP, + FILE * const alphaFileP, + bool const hasGray, + bool const hasColor) { /*---------------------------------------------------------------------------- Read the raster from the GIF decompressor *decompP, and write it as a complete PNM stream (starting with the header) on *imageOutFileP and @@ -1493,9 +1547,9 @@ convertRaster(struct Decompressor * const decompP, MALLOCARRAY2(cmapIndexArray, interlace ? rows : 1 , cols); if (imageOutFileP) - pnm_writepnminit(imageOutFileP, cols, rows, GIFMAXVAL, format, FALSE); + pnm_writepnminit(imageOutFileP, cols, rows, GIFMAXVAL, format, false); if (alphaFileP) - pbm_writepbminit(alphaFileP, cols, rows, FALSE); + pbm_writepbminit(alphaFileP, cols, rows, false); xelrow = pnm_allocrow(cols); if (!xelrow) @@ -1559,13 +1613,13 @@ convertRaster(struct Decompressor * const decompP, static void -skipExtraneousData(struct Decompressor * const decompP) { +skipExtraneousData(Decompressor * const decompP) { unsigned char byteRead; bool endOfImage; const char * error; - endOfImage = FALSE; /* initial value */ + endOfImage = false; /* initial value */ lzwReadByte(decompP, &byteRead, &endOfImage, &error); @@ -1647,7 +1701,7 @@ readImageData(FILE * const ifP, bool const tolerateBadInput) { unsigned char lzwMinCodeSize; - struct Decompressor decomp; + Decompressor decomp; const char * error; readFile(ifP, &lzwMinCodeSize, sizeof(lzwMinCodeSize), &error); @@ -1788,7 +1842,7 @@ readExtensions(FILE* const ifP, next image or GIF stream terminator. If we encounter EOD (end of GIF stream) before we find an image - separator, we return *eodP == TRUE. Else *eodP == FALSE. + separator, we return *eodP == true. Else *eodP == false. If we hit end of file before an EOD marker, we fail. -----------------------------------------------------------------------------*/ @@ -1797,8 +1851,8 @@ readExtensions(FILE* const ifP, *errorP = NULL; /* initial value */ - eod = FALSE; - imageStart = FALSE; + eod = false; + imageStart = false; /* Read the image descriptor */ while (!imageStart && !eod && !*errorP) { @@ -1814,7 +1868,7 @@ readExtensions(FILE* const ifP, pm_strfree(error); } else { if (c == ';') { /* GIF terminator */ - eod = TRUE; + eod = true; } else if (c == '!') { /* Extension */ unsigned char functionCode; const char * error; @@ -1830,7 +1884,7 @@ readExtensions(FILE* const ifP, doExtension(ifP, functionCode, gif89P); } } else if (c == ',') - imageStart = TRUE; + imageStart = true; else pm_message("Encountered invalid character 0x%02x while " "seeking extension block, ignoring", (int)c); @@ -1961,7 +2015,7 @@ convertImage(FILE * const ifP, /*---------------------------------------------------------------------------- Read a single GIF image from the current position of file 'ifP'. - If 'skipIt' is TRUE, don't do anything else. Otherwise, write the + If 'skipIt' is true, don't do anything else. Otherwise, write the image to the current position of files *imageoutFileP and *alphafileP. If *alphafileP is NULL, though, don't write any alpha information. -----------------------------------------------------------------------------*/ @@ -2016,7 +2070,7 @@ disposeOfReadExtensionsError(const char * const error, pm_error("Error accessing Image %u of stream. %s", imageSeq, error); pm_strfree(error); - *eodP = TRUE; + *eodP = true; } } @@ -2037,7 +2091,7 @@ convertImages(FILE * const ifP, 'allImages' means Caller wants all the images in the stream. - 'requestedImageSeq' is meaningful only when 'allImages' is FALSE. It + 'requestedImageSeq' is meaningful only when 'allImages' is false. It is the sequence number of the one image Caller wants from the stream, with the first image being 0. @@ -2063,7 +2117,7 @@ convertImages(FILE * const ifP, readGifHeader(ifP, &gifScreen); - for (imageSeq = 0, eod = FALSE; + for (imageSeq = 0, eod = false; !eod && (allImages || imageSeq <= requestedImageSeq || drainStream); ++imageSeq) { @@ -2094,14 +2148,14 @@ convertImages(FILE * const ifP, int -main(int argc, char **argv) { +main(int argc, const char **argv) { struct CmdlineInfo cmdline; FILE * ifP; FILE * alphaFileP; FILE * imageOutFileP; - pnm_init(&argc, argv); + pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); verbose = cmdline.verbose; |