diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2024-01-01 19:20:09 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2024-01-01 19:20:09 +0000 |
commit | 7e2d734d4f8cf105c2a0e780277f8adda75200b3 (patch) | |
tree | 6c872ecdbd6de29ee89ec05fb2cf7331c295e0f7 | |
parent | 95e5fdd296e33da21711ba349c589aba81fbe799 (diff) | |
download | netpbm-mirror-7e2d734d4f8cf105c2a0e780277f8adda75200b3.tar.gz netpbm-mirror-7e2d734d4f8cf105c2a0e780277f8adda75200b3.tar.xz netpbm-mirror-7e2d734d4f8cf105c2a0e780277f8adda75200b3.zip |
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4834 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | converter/other/pamtogif.c | 130 |
1 files changed, 75 insertions, 55 deletions
diff --git a/converter/other/pamtogif.c b/converter/other/pamtogif.c index 4b609b5c..03e6d049 100644 --- a/converter/other/pamtogif.c +++ b/converter/other/pamtogif.c @@ -212,9 +212,9 @@ Putword(int const w, FILE * const fp) { static int -closestColor(tuple const color, - struct pam * const pamP, - struct Cmap * const cmapP) { +closestColor(tuple const color, + struct pam * const pamP, + const struct Cmap * const cmapP) { /*---------------------------------------------------------------------------- Return the colormap index of the color in the colormap *cmapP that is closest to the color 'color', whose format is specified by @@ -442,11 +442,11 @@ rowReader_read(RowReader * const rdrP, static unsigned int -gifPixel(struct pam * const pamP, - tuple const tuple, - unsigned int const alphaPlane, - sample const alphaThreshold, - struct Cmap * const cmapP) { +gifPixel(struct pam * const pamP, + tuple const tuple, + unsigned int const alphaPlane, + sample const alphaThreshold, + const struct Cmap * const cmapP) { /*---------------------------------------------------------------------------- Return the colormap index of the tuple 'tuple', whose format is described by *pamP, using colormap *cmapP. @@ -1429,15 +1429,15 @@ writeImageHeader(FILE * const ofP, static void -writeRaster(struct pam * const pamP, - RowReader * const rowReaderP, - unsigned int const alphaPlane, - unsigned int const alphaThreshold, - struct Cmap * const cmapP, - unsigned int const initBits, - FILE * const ofP, - bool const lzw, - bool const noclear) { +writeRaster(struct pam * const pamP, + RowReader * const rowReaderP, + unsigned int const alphaPlane, + unsigned int const alphaThreshold, + const struct Cmap * const cmapP, + unsigned int const initBits, + FILE * const ofP, + bool const lzw, + bool const noclear) { /*---------------------------------------------------------------------------- Write the raster to file 'ofP'. @@ -1522,6 +1522,48 @@ writeEndOfImage(FILE * const ofP) { static void +writeGifImage(FILE * const ofP, + unsigned int const leftOffset, + unsigned int const topOffset, + struct pam * const pamP, + pm_filepos const rasterPos, + bool const gInterlace, + unsigned int const bitsPerPixel, + bool const lzw, + bool const noclear, + bool const usingAlpha, + const struct Cmap * const cmapP) { + + unsigned int const initCodeSize = bitsPerPixel <= 1 ? 2 : bitsPerPixel; + /* The initial code size */ + + sample const alphaThreshold = (pamP->maxval + 1) / 2; + /* Levels below this in the alpha plane indicate transparent + pixels in the output image. + */ + + unsigned int const alphaPlane = usingAlpha ? pamAlphaPlane(pamP) : 0; + + RowReader * rowReaderP; + + writeImageSeparator(ofP); + + writeImageHeader(ofP, leftOffset, topOffset, pamP->width, pamP->height, + gInterlace, initCodeSize); + + rowReaderP = rowReader_create(pamP, rasterPos, gInterlace); + + writeRaster(pamP, rowReaderP, alphaPlane, alphaThreshold, + cmapP, initCodeSize + 1, ofP, lzw, noclear); + + rowReader_destroy(rowReaderP); + + writeEndOfImage(ofP); +} + + + +static void writeGifStreamTerminator(FILE * const ofP) { fputc(';', ofP); @@ -1530,18 +1572,18 @@ writeGifStreamTerminator(FILE * const ofP) { static void -writeGif(struct pam * const pamP, - FILE * const ofP, - pm_filepos const rasterPos, - bool const gInterlace, - int const background, - unsigned int const bitsPerPixel, - struct Cmap * const cmapP, - char const comment[], - float const aspect, - bool const lzw, - bool const noclear, - bool const usingAlpha) { +writeGif(struct pam * const pamP, + FILE * const ofP, + pm_filepos const rasterPos, + bool const gInterlace, + int const background, + unsigned int const bitsPerPixel, + const struct Cmap * const cmapP, + char const comment[], + float const aspect, + bool const lzw, + bool const noclear, + bool const usingAlpha) { /*---------------------------------------------------------------------------- 'usingAlpha' means use the alpha (transparency) plane, if there is one, to determine which GIF pixels are transparent. When this is true, the @@ -1550,18 +1592,6 @@ writeGif(struct pam * const pamP, unsigned int const leftOffset = 0; unsigned int const topOffset = 0; - unsigned int const initCodeSize = bitsPerPixel <= 1 ? 2 : bitsPerPixel; - /* The initial code size */ - - sample const alphaThreshold = (pamP->maxval + 1) / 2; - /* Levels below this in the alpha plane indicate transparent - pixels in the output image. - */ - - unsigned int const alphaPlane = usingAlpha ? pamAlphaPlane(pamP) : 0; - - RowReader * rowReaderP; - reportImageInfo(gInterlace, background, bitsPerPixel); if (pamP->width > 65535) @@ -1575,19 +1605,9 @@ writeGif(struct pam * const pamP, writeGifHeader(ofP, pamP->width, pamP->height, background, bitsPerPixel, cmapP, comment, aspect); - writeImageSeparator(ofP); - - writeImageHeader(ofP, leftOffset, topOffset, pamP->width, pamP->height, - gInterlace, initCodeSize); - - rowReaderP = rowReader_create(pamP, rasterPos, gInterlace); - - writeRaster(pamP, rowReaderP, alphaPlane, alphaThreshold, - cmapP, initCodeSize + 1, ofP, lzw, noclear); - - rowReader_destroy(rowReaderP); - - writeEndOfImage(ofP); + writeGifImage(ofP, leftOffset, topOffset, pamP, rasterPos, + gInterlace, bitsPerPixel, lzw, noclear, usingAlpha, + cmapP); writeGifStreamTerminator(ofP); } @@ -1596,7 +1616,7 @@ writeGif(struct pam * const pamP, static void reportTransparent(enum TransparencyType const transType, - struct Cmap * const cmapP) { + const struct Cmap * const cmapP) { if (verbose) { switch (transType) { |