1 /*****************************************************************************
3 gifcolor - generate color test-pattern GIFs
5 *****************************************************************************/
16 #define PROGRAM_NAME "gifcolor"
19 #define IMAGEWIDTH LINE_LEN*GIF_FONT_WIDTH
21 __attribute__((__section__(".tizen.build-id")))
27 __DATE__ ", " __TIME__ "\n"
28 "(C) Copyright 1989 Gershon Elber.\n";
30 *CtrlStr = PROGRAM_NAME " v%- b%-Background!d h%-";
32 static int BackGround = 0;
33 static void QuitGifError(GifFileType *GifFile);
34 static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
35 int BufferWidth, int ForeGroundIndex);
37 /******************************************************************************
38 Interpret the command line and generate the given GIF file.
39 ******************************************************************************/
40 int main(int argc, char **argv)
42 int i, j, l, GifNoisyPrint, ColorMapSize, ErrorCode;
43 bool Error, BackGroundFlag = false, HelpFlag = false;
45 GifRowType RasterBuffer[GIF_FONT_HEIGHT];
46 ColorMapObject *ColorMap;
48 GifColorType ScratchMap[256];
51 if ((Error = GAGetArgs(argc, argv, CtrlStr,
53 &BackGroundFlag, &BackGround,
54 &HelpFlag)) != false) {
56 GAPrintHowTo(CtrlStr);
61 (void)fprintf(stderr, VersionStr, GIFLIB_MAJOR, GIFLIB_MINOR);
62 GAPrintHowTo(CtrlStr);
66 /* Allocate the raster buffer for GIF_FONT_HEIGHT scan lines. */
67 for (i = 0; i < GIF_FONT_HEIGHT; i++)
69 if ((RasterBuffer[i] = (GifRowType) malloc(sizeof(GifPixelType) *
71 GIF_EXIT("Failed to allocate memory required, aborted.");
74 /* Open stdout for the output file: */
75 if ((GifFile = EGifOpenFileHandle(1, &ErrorCode)) == NULL) {
76 PrintGifError(ErrorCode);
80 /* Read the color map in ColorFile into this color map: */
84 &red, &green, &blue) == 3) {
85 ScratchMap[ColorMapSize].Red = red;
86 ScratchMap[ColorMapSize].Green = green;
87 ScratchMap[ColorMapSize].Blue = blue;
91 if ((ColorMap = GifMakeMapObject(1 << GifBitSize(ColorMapSize), ScratchMap)) == NULL)
92 GIF_EXIT("Failed to allocate memory required, aborted.");
94 if (EGifPutScreenDesc(GifFile,
95 IMAGEWIDTH, ColorMapSize * GIF_FONT_HEIGHT,
96 GifBitSize(ColorMapSize),
97 BackGround, ColorMap) == GIF_ERROR)
98 QuitGifError(GifFile);
100 /* Dump out the image descriptor: */
101 if (EGifPutImageDesc(GifFile,
102 0, 0, IMAGEWIDTH, ColorMapSize * GIF_FONT_HEIGHT, false, NULL) == GIF_ERROR)
103 QuitGifError(GifFile);
105 GifQprintf("\n%s: Image 1 at (%d, %d) [%dx%d]: ",
106 PROGRAM_NAME, GifFile->Image.Left, GifFile->Image.Top,
107 GifFile->Image.Width, GifFile->Image.Height);
109 for (i = l = 0; i < ColorMap->ColorCount; i++) {
110 (void)snprintf(Line, sizeof(Line),
111 "Color %-3d: [%-3d, %-3d, %-3d] ", i,
112 ColorMap->Colors[i].Red,
113 ColorMap->Colors[i].Green,
114 ColorMap->Colors[i].Blue);
115 GenRasterTextLine(RasterBuffer, Line, IMAGEWIDTH, i);
116 for (j = 0; j < GIF_FONT_HEIGHT; j++) {
117 if (EGifPutLine(GifFile, RasterBuffer[j], IMAGEWIDTH) == GIF_ERROR)
118 QuitGifError(GifFile);
119 GifQprintf("\b\b\b\b%-4d", l++);
123 if (EGifCloseFile(GifFile, &ErrorCode) == GIF_ERROR)
125 PrintGifError(ErrorCode);
132 /******************************************************************************
133 Close output file (if open), and exit.
134 ******************************************************************************/
135 static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
136 int BufferWidth, int ForeGroundIndex)
138 unsigned char Byte, Mask;
139 int i, j, k, CharPosX, Len = strlen(TextLine);
141 for (i = 0; i < BufferWidth; i++)
142 for (j = 0; j < GIF_FONT_HEIGHT; j++) RasterBuffer[j][i] = BackGround;
144 for (i = CharPosX = 0; i < Len; i++, CharPosX += GIF_FONT_WIDTH) {
145 unsigned char c = TextLine[i];
146 for (j = 0; j < GIF_FONT_HEIGHT; j++) {
147 Byte = GifAsciiTable8x8[(unsigned short)c][j];
148 for (k = 0, Mask = 128; k < GIF_FONT_WIDTH; k++, Mask >>= 1)
150 RasterBuffer[j][CharPosX + k] = ForeGroundIndex;
155 /******************************************************************************
156 Close output file (if open), and exit.
157 ******************************************************************************/
158 static void QuitGifError(GifFileType *GifFile)
160 if (GifFile != NULL) {
161 PrintGifError(GifFile->Error);
162 EGifCloseFile(GifFile, NULL);