1 /*****************************************************************************
2 * "Gif-Lib" - Yet another gif library. *
4 * Written by: Gershon Elber Ver 0.1, Jul. 1989 *
5 ******************************************************************************
6 * Program to generate a test pattern from a given color map *
7 ******************************************************************************
9 * -q : quiet printing mode. *
10 * -b : set background color.
11 * -h : on-line help. *
12 ******************************************************************************
14 * 21 Sep 92 - Version 1.0 by Eric S. Raymond. *
15 *****************************************************************************/
24 #endif /* __MSDOS__ */
35 #define PROGRAM_NAME "GifColor"
38 #define IMAGEWIDTH LINE_LEN*GIF_FONT_WIDTH
42 _stklen = 16384; /* Increase default stack size. */
43 #endif /* __MSDOS__ */
46 static char *VersionStr =
47 "Gif library module \t\tGershon Elber\n\
48 (C) Copyright 1989 Gershon Elber.\n";
50 *CtrlStr = "GifColor q%- b%-Background!d h%-";
57 __DATE__ ", " __TIME__ "\n"
58 "(C) Copyright 1989 Gershon Elber.\n";
60 *CtrlStr = PROGRAM_NAME " q%- b%-Background!d h%-";
63 static int BackGround = 0;
64 static void QuitGifError(GifFileType *GifFile);
65 static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
66 int BufferWidth, int ForeGroundIndex);
68 /******************************************************************************
69 * Interpret the command line and generate the given GIF file. *
70 ******************************************************************************/
71 int main(int argc, char **argv)
73 int i, j, l, Error, GifQuietPrint, ColorMapSize,
74 BackGroundFlag = FALSE, HelpFlag = FALSE;
76 GifRowType RasterBuffer[GIF_FONT_HEIGHT];
77 ColorMapObject *ColorMap;
79 GifColorType ScratchMap[256];
82 if ((Error = GAGetArgs(argc, argv, CtrlStr,
84 &BackGroundFlag, &BackGround,
85 &HelpFlag)) != FALSE) {
87 GAPrintHowTo(CtrlStr);
92 fprintf(stderr, VersionStr);
93 GAPrintHowTo(CtrlStr);
97 /* Allocate the raster buffer for GIF_FONT_HEIGHT scan lines. */
98 for (i = 0; i < GIF_FONT_HEIGHT; i++)
100 if ((RasterBuffer[i] = (GifRowType) malloc(sizeof(GifPixelType) *
101 IMAGEWIDTH)) == NULL)
102 GIF_EXIT("Failed to allocate memory required, aborted.");
105 /* Open stdout for the output file: */
106 if ((GifFile = EGifOpenFileHandle(1)) == NULL)
107 QuitGifError(GifFile);
109 /* Read the color map in ColorFile into this color map: */
112 "%*3d %3d %3d %3d\n",
113 &red, &green, &blue) == 3) {
114 ScratchMap[ColorMapSize].Red = red;
115 ScratchMap[ColorMapSize].Green = green;
116 ScratchMap[ColorMapSize].Blue = blue;
120 if ((ColorMap = MakeMapObject(1 << BitSize(ColorMapSize), ScratchMap)) == NULL)
121 GIF_EXIT("Failed to allocate memory required, aborted.");
123 if (EGifPutScreenDesc(GifFile,
124 IMAGEWIDTH, ColorMapSize * GIF_FONT_HEIGHT,
125 BitSize(ColorMapSize),
126 BackGround, ColorMap) == GIF_ERROR)
127 QuitGifError(GifFile);
129 /* Dump out the image descriptor: */
130 if (EGifPutImageDesc(GifFile,
131 0, 0, IMAGEWIDTH, ColorMapSize * GIF_FONT_HEIGHT, FALSE, NULL) == GIF_ERROR)
132 QuitGifError(GifFile);
134 GifQprintf("\n%s: Image 1 at (%d, %d) [%dx%d]: ",
135 PROGRAM_NAME, GifFile->Image.Left, GifFile->Image.Top,
136 GifFile->Image.Width, GifFile->Image.Height);
138 for (i = l = 0; i < ColorMap->ColorCount; i++) {
139 (void)sprintf(Line, "Color %-3d: [%-3d, %-3d, %-3d] ", i,
140 ColorMap->Colors[i].Red,
141 ColorMap->Colors[i].Green,
142 ColorMap->Colors[i].Blue);
143 GenRasterTextLine(RasterBuffer, Line, IMAGEWIDTH, i);
144 for (j = 0; j < GIF_FONT_HEIGHT; j++) {
145 if (EGifPutLine(GifFile, RasterBuffer[j], IMAGEWIDTH) == GIF_ERROR)
146 QuitGifError(GifFile);
147 GifQprintf("\b\b\b\b%-4d", l++);
151 if (EGifCloseFile(GifFile) == GIF_ERROR)
152 QuitGifError(GifFile);
157 /******************************************************************************
158 * Close output file (if open), and exit. *
159 ******************************************************************************/
160 static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
161 int BufferWidth, int ForeGroundIndex)
164 unsigned char Byte, Mask;
165 int i, j, k, CharPosX, Len = strlen(TextLine);
167 for (i = 0; i < BufferWidth; i++)
168 for (j = 0; j < GIF_FONT_HEIGHT; j++) RasterBuffer[j][i] = BackGround;
170 for (i = CharPosX = 0; i < Len; i++, CharPosX += GIF_FONT_WIDTH) {
172 for (j = 0; j < GIF_FONT_HEIGHT; j++) {
173 Byte = AsciiTable[(unsigned short)c][j];
174 for (k = 0, Mask = 128; k < GIF_FONT_WIDTH; k++, Mask >>= 1)
176 RasterBuffer[j][CharPosX + k] = ForeGroundIndex;
181 /******************************************************************************
182 * Close output file (if open), and exit. *
183 ******************************************************************************/
184 static void QuitGifError(GifFileType *GifFile)
187 if (GifFile != NULL) EGifCloseFile(GifFile);