1 /****************************************************************************
3 gifsponge.c - skeleton file for generic GIF `sponge' program
5 Slurp a GIF into core, operate on it, spew it out again. Most of the
6 junk above `int main' isn't needed for the skeleton, but is likely to
7 be for what you'll do with it.
9 If you compile this, it will turn into an expensive GIF copying routine;
10 stdin to stdout with no changes and minimal validation. Well, it's a
11 decent test of DGifSlurp() and EGifSpew(), anyway.
13 Note: due to the vicissitudes of Lempel-Ziv compression, the output of this
14 copier may not be bitwise identical to its input. This can happen if you
15 copy an image from a much more (or much *less*) memory-limited system; your
16 compression may use more (or fewer) bits. The uncompressed rasters should,
17 however, be identical (you can check this with gifbuild -d).
19 SPDX-License-Identifier: MIT
21 ****************************************************************************/
31 #define PROGRAM_NAME "gifsponge"
33 int main(int argc, char **argv)
36 GifFileType *GifFileIn, *GifFileOut = (GifFileType *)NULL;
38 if ((GifFileIn = DGifOpenFileHandle(0, &ErrorCode)) == NULL) {
39 PrintGifError(ErrorCode);
42 if (DGifSlurp(GifFileIn) == GIF_ERROR) {
43 PrintGifError(GifFileIn->Error);
46 if ((GifFileOut = EGifOpenFileHandle(1, &ErrorCode)) == NULL) {
47 PrintGifError(ErrorCode);
52 * Your operations on in-core structures go here.
53 * This code just copies the header and each image from the incoming file.
55 GifFileOut->SWidth = GifFileIn->SWidth;
56 GifFileOut->SHeight = GifFileIn->SHeight;
57 GifFileOut->SColorResolution = GifFileIn->SColorResolution;
58 GifFileOut->SBackGroundColor = GifFileIn->SBackGroundColor;
59 if (GifFileIn->SColorMap) {
60 GifFileOut->SColorMap = GifMakeMapObject(
61 GifFileIn->SColorMap->ColorCount,
62 GifFileIn->SColorMap->Colors);
64 GifFileOut->SColorMap = NULL;
67 for (i = 0; i < GifFileIn->ImageCount; i++)
68 (void) GifMakeSavedImage(GifFileOut, &GifFileIn->SavedImages[i]);
71 * Note: don't do DGifCloseFile early, as this will
72 * deallocate all the memory containing the GIF data!
74 * Further note: EGifSpew() doesn't try to validity-check any of this
75 * data; it's *your* responsibility to keep your changes consistent.
78 if (EGifSpew(GifFileOut) == GIF_ERROR)
79 PrintGifError(GifFileOut->Error);
81 if (DGifCloseFile(GifFileIn, &ErrorCode) == GIF_ERROR)
82 PrintGifError(ErrorCode);