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 ****************************************************************************/
29 #define PROGRAM_NAME "gifsponge"
31 int main(int argc, char **argv)
34 GifFileType *GifFileIn, *GifFileOut = (GifFileType *)NULL;
36 if ((GifFileIn = DGifOpenFileHandle(0, &ErrorCode)) == NULL) {
37 PrintGifError(ErrorCode);
40 if (DGifSlurp(GifFileIn) == GIF_ERROR) {
41 PrintGifError(GifFileIn->Error);
44 if ((GifFileOut = EGifOpenFileHandle(1, &ErrorCode)) == NULL) {
45 PrintGifError(ErrorCode);
50 * Your operations on in-core structures go here.
51 * This code just copies the header and each image from the incoming file.
53 GifFileOut->SWidth = GifFileIn->SWidth;
54 GifFileOut->SHeight = GifFileIn->SHeight;
55 GifFileOut->SColorResolution = GifFileIn->SColorResolution;
56 GifFileOut->SBackGroundColor = GifFileIn->SBackGroundColor;
57 if (GifFileIn->SColorMap) {
58 GifFileOut->SColorMap = GifMakeMapObject(
59 GifFileIn->SColorMap->ColorCount,
60 GifFileIn->SColorMap->Colors);
62 GifFileOut->SColorMap = NULL;
65 for (i = 0; i < GifFileIn->ImageCount; i++)
66 (void) GifMakeSavedImage(GifFileOut, &GifFileIn->SavedImages[i]);
69 * Note: don't do DGifCloseFile early, as this will
70 * deallocate all the memory containing the GIF data!
72 * Further note: EGifSpew() doesn't try to validity-check any of this
73 * data; it's *your* responsibility to keep your changes consistent.
76 if (EGifSpew(GifFileOut) == GIF_ERROR)
77 PrintGifError(GifFileOut->Error);
79 if (DGifCloseFile(GifFileIn, &ErrorCode) == GIF_ERROR)
80 PrintGifError(ErrorCode);