[go: up one dir, main page]

Menu

[efba94]: / util / gifovly.c  Maximize  Restore  History

Download this file

104 lines (86 with data), 2.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
/*****************************************************************************
* "Gif-Lib" - Yet another gif library.
*
* Written by: Gershon Elber Ver 0.1, Jul. 1989
******************************************************************************
* Takes a multi-image GIF and yields the overlay of all the images
******************************************************************************
* History:
* 6 May 94 - Version 1.0 by Eric Raymond.
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <stdbool.h>
#include "getarg.h"
#include "gif_lib.h"
#define PROGRAM_NAME "gifovly"
static char
*VersionStr =
PROGRAM_NAME
VERSION_COOKIE
" Eric Raymond, "
__DATE__ ", " __TIME__ "\n"
"(C) Copyright 1992 Eric Raymond.\n";
static char
*CtrlStr =
PROGRAM_NAME
" t%-TransparentColor!d h%-";
int main(int argc, char **argv)
{
int k;
GifFileType *GifFileIn, *GifFileOut = (GifFileType *)NULL;
SavedImage *bp;
int TransparentColor = 0;
bool Error, TransparentColorFlag = false, HelpFlag = false;
if ((Error = GAGetArgs(argc, argv, CtrlStr,
&TransparentColorFlag, &TransparentColor,
&HelpFlag)) != false) {
GAPrintErrMsg(Error);
GAPrintHowTo(CtrlStr);
exit(EXIT_FAILURE);
}
if (HelpFlag) {
(void)fprintf(stderr, VersionStr, GIFLIB_MAJOR, GIFLIB_MINOR);
GAPrintHowTo(CtrlStr);
exit(EXIT_SUCCESS);
}
if ((GifFileIn = DGifOpenFileHandle(0)) == NULL
|| DGifSlurp(GifFileIn) == GIF_ERROR
|| ((GifFileOut = EGifOpenFileHandle(1)) == (GifFileType *)NULL))
{
PrintGifError();
exit(EXIT_FAILURE);
}
GifFileOut->SWidth = GifFileIn->SWidth;
GifFileOut->SHeight = GifFileIn->SHeight;
GifFileOut->SColorResolution = GifFileIn->SColorResolution;
GifFileOut->SBackGroundColor = GifFileIn->SBackGroundColor;
GifFileOut->SColorMap = MakeMapObject(
GifFileIn->SColorMap->ColorCount,
GifFileIn->SColorMap->Colors);
/* The output file will have exactly one image */
MakeSavedImage(GifFileOut, &GifFileIn->SavedImages[0]);
bp = &GifFileOut->SavedImages[0];
for (k = 1; k < GifFileIn->ImageCount; k++)
{
register int i, j;
register unsigned char *sp, *tp;
SavedImage *ovp = &GifFileIn->SavedImages[k];
for (i = 0; i < ovp->ImageDesc.Height; i++)
{
tp = bp->RasterBits + (ovp->ImageDesc.Top + i) * bp->ImageDesc.Width + ovp->ImageDesc.Left;
sp = ovp->RasterBits + i * ovp->ImageDesc.Width;
for (j = 0; j < ovp->ImageDesc.Width; j++)
if (!TransparentColorFlag || sp[j] != TransparentColor)
tp[j] = sp[j];
}
}
if (EGifSpew(GifFileOut) == GIF_ERROR)
PrintGifError();
else if (DGifCloseFile(GifFileIn) == GIF_ERROR)
PrintGifError();
return 0;
}
/* gifovly.c ends here */