358 lines
16 KiB
C
358 lines
16 KiB
C
/*****************************************************************************
|
|
* "Gif-Lib" - Yet another gif library. *
|
|
* *
|
|
* Written by: Gershon Elber Ver 0.1, Jul. 1989 *
|
|
******************************************************************************
|
|
* Program to generate GIF image page from a given text by drawing the chars *
|
|
* using 8 by 8 fixed font. *
|
|
* Options: *
|
|
* -q : quite printing mode. *
|
|
* -s ColorMapSize : in bits, i.e. 6 bits for 64 colors. *
|
|
* -f ForeGroundIndex : by default foreground is 1. Must be in range 0..255. *
|
|
* -c R G B : set the foregound color values. By default it is white. *
|
|
* -t "Text" : Make one line given file (8 pixel high) from the given Text. *
|
|
* -h : on line help. *
|
|
******************************************************************************
|
|
* History: *
|
|
* 3 May 90 - Version 1.0 by Gershon Elber. *
|
|
*****************************************************************************/
|
|
|
|
#ifdef __MSDOS__
|
|
#include <stdlib.h>
|
|
#include <alloc.h>
|
|
#endif /* __MSDOS__ */
|
|
|
|
#include <stdio.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include "gif_lib.h"
|
|
#include "getarg.h"
|
|
|
|
#define PROGRAM_NAME "Text2Gif"
|
|
|
|
#define MAX_NUM_TEXT_LINES 100 /* Maximum number of lines in file. */
|
|
|
|
#define LINE_LEN 256 /* Maximum length of one text line. */
|
|
|
|
#define DEFAULT_FG_INDEX 1 /* Text foreground index. */
|
|
|
|
#define DEFAULT_COLOR_RED 255 /* Text foreground color. */
|
|
#define DEFAULT_COLOR_GREEN 255
|
|
#define DEFAULT_COLOR_BLUE 255
|
|
|
|
#ifdef __MSDOS__
|
|
extern unsigned int
|
|
_stklen = 16384; /* Increase default stack size. */
|
|
#endif /* __MSDOS__ */
|
|
|
|
#ifdef SYSV
|
|
static char *VersionStr =
|
|
"Gif library module \t\tGershon Elber\n\
|
|
(C) Copyright 1989 Gershon Elber, Non commercial use only.\n";
|
|
static char
|
|
*CtrlStr = "Text2Gif q%- s%-ClrMapSize!d f%-FGClr!d c%-R|G|B!d!d!d t%-\"Text\"!s h%-";
|
|
#else
|
|
static char
|
|
*VersionStr =
|
|
PROGRAM_NAME
|
|
GIF_LIB_VERSION
|
|
" Gershon Elber, "
|
|
__DATE__ ", " __TIME__ "\n"
|
|
"(C) Copyright 1989 Gershon Elber, Non commercial use only.\n";
|
|
static char
|
|
*CtrlStr =
|
|
PROGRAM_NAME
|
|
" q%- s%-ClrMapSize!d f%-FGClr!d c%-R|G|B!d!d!d t%-\"Text\"!s h%-";
|
|
#endif /* SYSV */
|
|
|
|
static unsigned int
|
|
RedColor = DEFAULT_COLOR_RED,
|
|
GreenColor = DEFAULT_COLOR_GREEN,
|
|
BlueColor = DEFAULT_COLOR_BLUE;
|
|
|
|
/*****************************************************************************
|
|
* Ascii 8 by 8 regular font - only first 128 characters are supported. *
|
|
*****************************************************************************/
|
|
static unsigned char AsciiTable[][8] = {
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* Ascii 0 */
|
|
{ 0x3c, 0x42, 0xa5, 0x81, 0xbd, 0x42, 0x3c, 0x00 }, /* Ascii 1 */
|
|
{ 0x3c, 0x7e, 0xdb, 0xff, 0xc3, 0x7e, 0x3c, 0x00 }, /* Ascii 2 */
|
|
{ 0x00, 0xee, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00 }, /* Ascii 3 */
|
|
{ 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00 }, /* Ascii 4 */
|
|
{ 0x00, 0x3c, 0x18, 0xff, 0xff, 0x08, 0x18, 0x00 }, /* Ascii 5 */
|
|
{ 0x10, 0x38, 0x7c, 0xfe, 0xfe, 0x10, 0x38, 0x00 }, /* Ascii 6 */
|
|
{ 0x00, 0x00, 0x18, 0x3c, 0x18, 0x00, 0x00, 0x00 }, /* Ascii 7 */
|
|
{ 0xff, 0xff, 0xe7, 0xc3, 0xe7, 0xff, 0xff, 0xff }, /* Ascii 8 */
|
|
{ 0x00, 0x3c, 0x42, 0x81, 0x81, 0x42, 0x3c, 0x00 }, /* Ascii 9 */
|
|
{ 0xff, 0xc3, 0xbd, 0x7e, 0x7e, 0xbd, 0xc3, 0xff }, /* Ascii 10 */
|
|
{ 0x1f, 0x07, 0x0d, 0x7c, 0xc6, 0xc6, 0x7c, 0x00 }, /* Ascii 11 */
|
|
{ 0x00, 0x7e, 0xc3, 0xc3, 0x7e, 0x18, 0x7e, 0x18 }, /* Ascii 12 */
|
|
{ 0x04, 0x06, 0x07, 0x04, 0x04, 0xfc, 0xf8, 0x00 }, /* Ascii 13 */
|
|
{ 0x0c, 0x0a, 0x0d, 0x0b, 0xf9, 0xf9, 0x1f, 0x1f }, /* Ascii 14 */
|
|
{ 0x00, 0x92, 0x7c, 0x44, 0xc6, 0x7c, 0x92, 0x00 }, /* Ascii 15 */
|
|
{ 0x00, 0x00, 0x60, 0x78, 0x7e, 0x78, 0x60, 0x00 }, /* Ascii 16 */
|
|
{ 0x00, 0x00, 0x06, 0x1e, 0x7e, 0x1e, 0x06, 0x00 }, /* Ascii 17 */
|
|
{ 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x18 }, /* Ascii 18 */
|
|
{ 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00 }, /* Ascii 19 */
|
|
{ 0xff, 0xb6, 0x76, 0x36, 0x36, 0x36, 0x36, 0x00 }, /* Ascii 20 */
|
|
{ 0x7e, 0xc1, 0xdc, 0x22, 0x22, 0x1f, 0x83, 0x7e }, /* Ascii 21 */
|
|
{ 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x00, 0x00, 0x00 }, /* Ascii 22 */
|
|
{ 0x18, 0x7e, 0x18, 0x18, 0x7e, 0x18, 0x00, 0xff }, /* Ascii 23 */
|
|
{ 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00 }, /* Ascii 24 */
|
|
{ 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x00 }, /* Ascii 25 */
|
|
{ 0x00, 0x04, 0x06, 0xff, 0x06, 0x04, 0x00, 0x00 }, /* Ascii 26 */
|
|
{ 0x00, 0x20, 0x60, 0xff, 0x60, 0x20, 0x00, 0x00 }, /* Ascii 27 */
|
|
{ 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xff, 0x00 }, /* Ascii 28 */
|
|
{ 0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00 }, /* Ascii 29 */
|
|
{ 0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x00, 0x00 }, /* Ascii 30 */
|
|
{ 0x00, 0x00, 0x00, 0xfe, 0x7c, 0x38, 0x10, 0x00 }, /* Ascii 31 */
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* */
|
|
{ 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x30, 0x00 }, /* ! */
|
|
{ 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* " */
|
|
{ 0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x00 }, /* # */
|
|
{ 0x10, 0x7c, 0xd2, 0x7c, 0x86, 0x7c, 0x10, 0x00 }, /* $ */
|
|
{ 0xf0, 0x96, 0xfc, 0x18, 0x3e, 0x72, 0xde, 0x00 }, /* % */
|
|
{ 0x30, 0x48, 0x30, 0x78, 0xce, 0xcc, 0x78, 0x00 }, /* & */
|
|
{ 0x0c, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* ' */
|
|
{ 0x10, 0x60, 0xc0, 0xc0, 0xc0, 0x60, 0x10, 0x00 }, /* ( */
|
|
{ 0x10, 0x0c, 0x06, 0x06, 0x06, 0x0c, 0x10, 0x00 }, /* ) */
|
|
{ 0x00, 0x54, 0x38, 0xfe, 0x38, 0x54, 0x00, 0x00 }, /* * */
|
|
{ 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00 }, /* + */
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x70 }, /* , */
|
|
{ 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00 }, /* - */
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00 }, /* . */
|
|
{ 0x02, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x00 }, /* / */
|
|
{ 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00 }, /* 0x */
|
|
{ 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x3c, 0x00 }, /* 1 */
|
|
{ 0x7c, 0xc6, 0x06, 0x0c, 0x30, 0x60, 0xfe, 0x00 }, /* 2 */
|
|
{ 0x7c, 0xc6, 0x06, 0x3c, 0x06, 0xc6, 0x7c, 0x00 }, /* 3 */
|
|
{ 0x0e, 0x1e, 0x36, 0x66, 0xfe, 0x06, 0x06, 0x00 }, /* 4 */
|
|
{ 0xfe, 0xc0, 0xc0, 0xfc, 0x06, 0x06, 0xfc, 0x00 }, /* 5 */
|
|
{ 0x7c, 0xc6, 0xc0, 0xfc, 0xc6, 0xc6, 0x7c, 0x00 }, /* 6 */
|
|
{ 0xfe, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x60, 0x00 }, /* 7 */
|
|
{ 0x7c, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0x7c, 0x00 }, /* 8 */
|
|
{ 0x7c, 0xc6, 0xc6, 0x7e, 0x06, 0xc6, 0x7c, 0x00 }, /* 9 */
|
|
{ 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 }, /* : */
|
|
{ 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x20, 0x00 }, /* }, */
|
|
{ 0x00, 0x1c, 0x30, 0x60, 0x30, 0x1c, 0x00, 0x00 }, /* < */
|
|
{ 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00 }, /* = */
|
|
{ 0x00, 0x70, 0x18, 0x0c, 0x18, 0x70, 0x00, 0x00 }, /* > */
|
|
{ 0x7c, 0xc6, 0x0c, 0x18, 0x30, 0x00, 0x30, 0x00 }, /* ? */
|
|
{ 0x7c, 0x82, 0x9a, 0xaa, 0xaa, 0x9e, 0x7c, 0x00 }, /* @ */
|
|
{ 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0x00 }, /* A */
|
|
{ 0xfc, 0xc6, 0xc6, 0xfc, 0xc6, 0xc6, 0xfc, 0x00 }, /* B */
|
|
{ 0x7c, 0xc6, 0xc6, 0xc0, 0xc0, 0xc6, 0x7c, 0x00 }, /* C */
|
|
{ 0xf8, 0xcc, 0xc6, 0xc6, 0xc6, 0xcc, 0xf8, 0x00 }, /* D */
|
|
{ 0xfe, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xfe, 0x00 }, /* E */
|
|
{ 0xfe, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0x00 }, /* F */
|
|
{ 0x7c, 0xc6, 0xc0, 0xce, 0xc6, 0xc6, 0x7e, 0x00 }, /* G */
|
|
{ 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00 }, /* H */
|
|
{ 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00 }, /* I */
|
|
{ 0x1e, 0x06, 0x06, 0x06, 0xc6, 0xc6, 0x7c, 0x00 }, /* J */
|
|
{ 0xc6, 0xcc, 0xd8, 0xf0, 0xd8, 0xcc, 0xc6, 0x00 }, /* K */
|
|
{ 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0x00 }, /* L */
|
|
{ 0xc6, 0xee, 0xfe, 0xd6, 0xc6, 0xc6, 0xc6, 0x00 }, /* M */
|
|
{ 0xc6, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0xc6, 0x00 }, /* N */
|
|
{ 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00 }, /* O */
|
|
{ 0xfc, 0xc6, 0xc6, 0xfc, 0xc0, 0xc0, 0xc0, 0x00 }, /* P */
|
|
{ 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x06 }, /* Q */
|
|
{ 0xfc, 0xc6, 0xc6, 0xfc, 0xc6, 0xc6, 0xc6, 0x00 }, /* R */
|
|
{ 0x78, 0xcc, 0x60, 0x30, 0x18, 0xcc, 0x78, 0x00 }, /* S */
|
|
{ 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00 }, /* T */
|
|
{ 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00 }, /* U */
|
|
{ 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00 }, /* V */
|
|
{ 0xc6, 0xc6, 0xc6, 0xd6, 0xfe, 0xee, 0xc6, 0x00 }, /* W */
|
|
{ 0xc6, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0xc6, 0x00 }, /* X */
|
|
{ 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x00 }, /* Y */
|
|
{ 0xfe, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xfe, 0x00 }, /* Z */
|
|
{ 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x00 }, /* [ */
|
|
{ 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x00 }, /* \ */
|
|
{ 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 0x00 }, /* ] */
|
|
{ 0x00, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00 }, /* ^ */
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff }, /* _ */
|
|
{ 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* ` */
|
|
{ 0x00, 0x00, 0x7c, 0x06, 0x7e, 0xc6, 0x7e, 0x00 }, /* a */
|
|
{ 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xe6, 0xdc, 0x00 }, /* b */
|
|
{ 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0x7e, 0x00 }, /* c */
|
|
{ 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xce, 0x76, 0x00 }, /* d */
|
|
{ 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0x7e, 0x00 }, /* e */
|
|
{ 0x1e, 0x30, 0x7c, 0x30, 0x30, 0x30, 0x30, 0x00 }, /* f */
|
|
{ 0x00, 0x00, 0x7e, 0xc6, 0xce, 0x76, 0x06, 0x7c }, /* g */
|
|
{ 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x00 }, /* */
|
|
{ 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00 }, /* i */
|
|
{ 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0xf0 }, /* j */
|
|
{ 0xc0, 0xc0, 0xcc, 0xd8, 0xf0, 0xd8, 0xcc, 0x00 }, /* k */
|
|
{ 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00 }, /* l */
|
|
{ 0x00, 0x00, 0xcc, 0xfe, 0xd6, 0xc6, 0xc6, 0x00 }, /* m */
|
|
{ 0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x00 }, /* n */
|
|
{ 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00 }, /* o */
|
|
{ 0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xe6, 0xdc, 0xc0 }, /* p */
|
|
{ 0x00, 0x00, 0x7e, 0xc6, 0xc6, 0xce, 0x76, 0x06 }, /* q */
|
|
{ 0x00, 0x00, 0x6e, 0x70, 0x60, 0x60, 0x60, 0x00 }, /* r */
|
|
{ 0x00, 0x00, 0x7c, 0xc0, 0x7c, 0x06, 0xfc, 0x00 }, /* s */
|
|
{ 0x30, 0x30, 0x7c, 0x30, 0x30, 0x30, 0x1c, 0x00 }, /* t */
|
|
{ 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x00 }, /* u */
|
|
{ 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00 }, /* v */
|
|
{ 0x00, 0x00, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x00 }, /* w */
|
|
{ 0x00, 0x00, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x00 }, /* x */
|
|
{ 0x00, 0x00, 0xc6, 0xc6, 0xce, 0x76, 0x06, 0x7c }, /* y */
|
|
{ 0x00, 0x00, 0xfc, 0x18, 0x30, 0x60, 0xfc, 0x00 }, /* z */
|
|
{ 0x0e, 0x18, 0x18, 0x70, 0x18, 0x18, 0x0e, 0x00 }, /* { */
|
|
{ 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00 }, /* | */
|
|
{ 0xe0, 0x30, 0x30, 0x1c, 0x30, 0x30, 0xe0, 0x00 }, /* } */
|
|
{ 0x00, 0x00, 0x70, 0x9a, 0x0e, 0x00, 0x00, 0x00 }, /* ~ */
|
|
{ 0x00, 0x00, 0x18, 0x3c, 0x66, 0xff, 0x00, 0x00 } /* Ascii 127 */
|
|
};
|
|
|
|
static void QuitGifError(GifFileType *GifFile);
|
|
static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
|
|
int BufferWidth, int ForeGroundIndex);
|
|
|
|
/******************************************************************************
|
|
* Interpret the command line and generate the given GIF file. *
|
|
******************************************************************************/
|
|
void main(int argc, char **argv)
|
|
{
|
|
int i, j, l, Error, ImageWidth, ImageHeight, NumOfLines, LogNumLevels,
|
|
NumLevels, ClrMapSizeFlag = FALSE, ColorMapSize = 1, ColorFlag = FALSE,
|
|
ForeGroundIndex = DEFAULT_FG_INDEX, ForeGroundFlag = FALSE,
|
|
TextLineFlag = FALSE, HelpFlag = FALSE;
|
|
char *TextLines[MAX_NUM_TEXT_LINES], Line[LINE_LEN];
|
|
GifRowType RasterBuffer[8];
|
|
GifColorType *ColorMap;
|
|
GifFileType *GifFile;
|
|
|
|
if ((Error = GAGetArgs(argc, argv, CtrlStr,
|
|
&GifQuitePrint, &ClrMapSizeFlag, &ColorMapSize,
|
|
&ForeGroundFlag, &ForeGroundIndex,
|
|
&ColorFlag, &RedColor, &GreenColor, &BlueColor,
|
|
&TextLineFlag, &TextLines[0],
|
|
&HelpFlag)) != FALSE) {
|
|
GAPrintErrMsg(Error);
|
|
GAPrintHowTo(CtrlStr);
|
|
exit(1);
|
|
}
|
|
|
|
if (HelpFlag) {
|
|
fprintf(stderr, VersionStr);
|
|
GAPrintHowTo(CtrlStr);
|
|
exit(0);
|
|
}
|
|
|
|
if (ForeGroundIndex > 255 || ForeGroundIndex < 1)
|
|
GIF_EXIT("Foregound (-f) should be in the range 1..255, aborted.");
|
|
|
|
if (ColorMapSize > 8 || ColorMapSize < 1)
|
|
GIF_EXIT("ColorMapSize (-s) should be in the range 1..8, aborted.");
|
|
|
|
if (TextLineFlag) {
|
|
NumOfLines = 1;
|
|
ImageHeight = 8;
|
|
ImageWidth = 8 * strlen(TextLines[0]);
|
|
}
|
|
else {
|
|
NumOfLines = l = 0;
|
|
while (fgets(Line, LINE_LEN - 1, stdin)) {
|
|
for (i = strlen(Line); i > 0 && Line[i-1] <= ' '; i--);
|
|
Line[i] = 0;
|
|
if (l < i) l = i;
|
|
TextLines[NumOfLines++] = strdup(Line);
|
|
if (NumOfLines == MAX_NUM_TEXT_LINES)
|
|
GIF_EXIT("Input file has too many lines, aborted.");
|
|
}
|
|
if (NumOfLines == 0)
|
|
GIF_EXIT("No input text, aborted.");
|
|
ImageHeight = 8 * NumOfLines;
|
|
ImageWidth = 8 * l;
|
|
}
|
|
|
|
/* Allocate the raster buffer for 8 scan lines (one text line). */
|
|
for (i = 0; i < 8; i++)
|
|
if ((RasterBuffer[i] = (GifRowType) malloc(sizeof(GifPixelType) *
|
|
ImageWidth)) == NULL)
|
|
GIF_EXIT("Failed to allocate memory required, aborted.");
|
|
|
|
/* Open stdout for the output file: */
|
|
if ((GifFile = EGifOpenFileHandle(1)) == NULL)
|
|
QuitGifError(GifFile);
|
|
|
|
/* Dump out screen description with given size and generated color map: */
|
|
for (LogNumLevels = 1, NumLevels = 2;
|
|
NumLevels < ForeGroundIndex;
|
|
LogNumLevels++, NumLevels <<= 1);
|
|
if (NumLevels < (1 << ColorMapSize)) {
|
|
NumLevels = (1 << ColorMapSize);
|
|
LogNumLevels = ColorMapSize;
|
|
}
|
|
|
|
if ((ColorMap = (GifColorType *) malloc(NumLevels * sizeof(GifColorType)))
|
|
== NULL) GIF_EXIT("Failed to allocate memory required, aborted.");
|
|
|
|
for (i = 0; i < NumLevels; i++)
|
|
ColorMap[i].Red = ColorMap[i].Green = ColorMap[i].Blue = 0;
|
|
ColorMap[ForeGroundIndex].Red = RedColor;
|
|
ColorMap[ForeGroundIndex].Green = GreenColor;
|
|
ColorMap[ForeGroundIndex].Blue = BlueColor;
|
|
|
|
if (EGifPutScreenDesc(GifFile,
|
|
ImageWidth, ImageHeight, LogNumLevels, 0, LogNumLevels, ColorMap)
|
|
== GIF_ERROR)
|
|
QuitGifError(GifFile);
|
|
|
|
/* Dump out the image descriptor: */
|
|
if (EGifPutImageDesc(GifFile,
|
|
0, 0, ImageWidth, ImageHeight, FALSE, LogNumLevels, NULL) == GIF_ERROR)
|
|
QuitGifError(GifFile);
|
|
|
|
GifQprintf("\n%s: Image 1 at (%d, %d) [%dx%d]: ",
|
|
PROGRAM_NAME, GifFile -> ILeft, GifFile -> ITop,
|
|
GifFile -> IWidth, GifFile -> IHeight);
|
|
|
|
for (i = l = 0; i < NumOfLines; i++) {
|
|
GenRasterTextLine(RasterBuffer, TextLines[i], ImageWidth,
|
|
ForeGroundIndex);
|
|
for (j = 0; j < 8; j++) {
|
|
if (EGifPutLine(GifFile, RasterBuffer[j], ImageWidth) == GIF_ERROR)
|
|
QuitGifError(GifFile);
|
|
GifQprintf("\b\b\b\b%-4d", l++);
|
|
}
|
|
}
|
|
|
|
if (EGifCloseFile(GifFile) == GIF_ERROR)
|
|
QuitGifError(GifFile);
|
|
}
|
|
|
|
/******************************************************************************
|
|
* Close output file (if open), and exit. *
|
|
******************************************************************************/
|
|
static void GenRasterTextLine(GifRowType *RasterBuffer, char *TextLine,
|
|
int BufferWidth, int ForeGroundIndex)
|
|
{
|
|
char c;
|
|
unsigned char Byte, Mask;
|
|
int i, j, k, CharPosX, Len = strlen(TextLine);
|
|
|
|
for (i = 0; i < BufferWidth; i++)
|
|
for (j = 0; j < 8; j++) RasterBuffer[j][i] = 0;
|
|
|
|
for (i = CharPosX = 0; i < Len; i++, CharPosX += 8) {
|
|
c = TextLine[i];
|
|
for (j = 0; j < 8; j++) {
|
|
Byte = AsciiTable[c][j];
|
|
for (k = 0, Mask = 128; k < 8; k++, Mask >>= 1)
|
|
if (Byte & Mask)
|
|
RasterBuffer[j][CharPosX + k] = ForeGroundIndex;
|
|
}
|
|
}
|
|
}
|
|
|
|
/******************************************************************************
|
|
* Close output file (if open), and exit. *
|
|
******************************************************************************/
|
|
static void QuitGifError(GifFileType *GifFile)
|
|
{
|
|
PrintGifError();
|
|
if (GifFile != NULL) EGifCloseFile(GifFile);
|
|
exit(1);
|
|
}
|