This source file includes following definitions.
- GifDrawText8x8
- GifDrawBox
- GifDrawRectangle
- GifDrawBoxedText8x8
#include <string.h>
#include <stdlib.h>
#include "gif_lib.h"
const unsigned char GifAsciiTable8x8[][GIF_FONT_WIDTH] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x3c, 0x42, 0xa5, 0x81, 0xbd, 0x42, 0x3c, 0x00},
{0x3c, 0x7e, 0xdb, 0xff, 0xc3, 0x7e, 0x3c, 0x00},
{0x00, 0xee, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00},
{0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00},
{0x00, 0x3c, 0x18, 0xff, 0xff, 0x08, 0x18, 0x00},
{0x10, 0x38, 0x7c, 0xfe, 0xfe, 0x10, 0x38, 0x00},
{0x00, 0x00, 0x18, 0x3c, 0x18, 0x00, 0x00, 0x00},
{0xff, 0xff, 0xe7, 0xc3, 0xe7, 0xff, 0xff, 0xff},
{0x00, 0x3c, 0x42, 0x81, 0x81, 0x42, 0x3c, 0x00},
{0xff, 0xc3, 0xbd, 0x7e, 0x7e, 0xbd, 0xc3, 0xff},
{0x1f, 0x07, 0x0d, 0x7c, 0xc6, 0xc6, 0x7c, 0x00},
{0x00, 0x7e, 0xc3, 0xc3, 0x7e, 0x18, 0x7e, 0x18},
{0x04, 0x06, 0x07, 0x04, 0x04, 0xfc, 0xf8, 0x00},
{0x0c, 0x0a, 0x0d, 0x0b, 0xf9, 0xf9, 0x1f, 0x1f},
{0x00, 0x92, 0x7c, 0x44, 0xc6, 0x7c, 0x92, 0x00},
{0x00, 0x00, 0x60, 0x78, 0x7e, 0x78, 0x60, 0x00},
{0x00, 0x00, 0x06, 0x1e, 0x7e, 0x1e, 0x06, 0x00},
{0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x18},
{0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00},
{0xff, 0xb6, 0x76, 0x36, 0x36, 0x36, 0x36, 0x00},
{0x7e, 0xc1, 0xdc, 0x22, 0x22, 0x1f, 0x83, 0x7e},
{0x00, 0x00, 0x00, 0x7e, 0x7e, 0x00, 0x00, 0x00},
{0x18, 0x7e, 0x18, 0x18, 0x7e, 0x18, 0x00, 0xff},
{0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00},
{0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x00},
{0x00, 0x04, 0x06, 0xff, 0x06, 0x04, 0x00, 0x00},
{0x00, 0x20, 0x60, 0xff, 0x60, 0x20, 0x00, 0x00},
{0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xff, 0x00},
{0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00},
{0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x00, 0x00},
{0x00, 0x00, 0x00, 0xfe, 0x7c, 0x38, 0x10, 0x00},
{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},
{0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x3c, 0x00},
{0x7c, 0xc6, 0x06, 0x0c, 0x30, 0x60, 0xfe, 0x00},
{0x7c, 0xc6, 0x06, 0x3c, 0x06, 0xc6, 0x7c, 0x00},
{0x0e, 0x1e, 0x36, 0x66, 0xfe, 0x06, 0x06, 0x00},
{0xfe, 0xc0, 0xc0, 0xfc, 0x06, 0x06, 0xfc, 0x00},
{0x7c, 0xc6, 0xc0, 0xfc, 0xc6, 0xc6, 0x7c, 0x00},
{0xfe, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x60, 0x00},
{0x7c, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0x7c, 0x00},
{0x7c, 0xc6, 0xc6, 0x7e, 0x06, 0xc6, 0x7c, 0x00},
{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},
{0xfc, 0xc6, 0xc6, 0xfc, 0xc6, 0xc6, 0xfc, 0x00},
{0x7c, 0xc6, 0xc6, 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66, 0x3c, 0x18, 0x18, 0x18, 0x00},
{0xfe, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xfe, 0x00},
{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},
{0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xe6, 0xdc, 0x00},
{0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0x7e, 0x00},
{0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xce, 0x76, 0x00},
{0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0x7e, 0x00},
{0x1e, 0x30, 0x7c, 0x30, 0x30, 0x30, 0x30, 0x00},
{0x00, 0x00, 0x7e, 0xc6, 0xce, 0x76, 0x06, 0x7c},
{0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x00},
{0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00},
{0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0xf0},
{0xc0, 0xc0, 0xcc, 0xd8, 0xf0, 0xd8, 0xcc, 0x00},
{0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00},
{0x00, 0x00, 0xcc, 0xfe, 0xd6, 0xc6, 0xc6, 0x00},
{0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x00},
{0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00},
{0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xe6, 0xdc, 0xc0},
{0x00, 0x00, 0x7e, 0xc6, 0xc6, 0xce, 0x76, 0x06},
{0x00, 0x00, 0x6e, 0x70, 0x60, 0x60, 0x60, 0x00},
{0x00, 0x00, 0x7c, 0xc0, 0x7c, 0x06, 0xfc, 0x00},
{0x30, 0x30, 0x7c, 0x30, 0x30, 0x30, 0x1c, 0x00},
{0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x00},
{0x00, 0x00, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00},
{0x00, 0x00, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x00},
{0x00, 0x00, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x00},
{0x00, 0x00, 0xc6, 0xc6, 0xce, 0x76, 0x06, 0x7c},
{0x00, 0x00, 0xfc, 0x18, 0x30, 0x60, 0xfc, 0x00},
{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}
};
void
GifDrawText8x8(SavedImage *Image,
const int x, const int y,
const char *legend,
const int color)
{
int i, j;
int base;
const char *cp;
for (i = 0; i < GIF_FONT_HEIGHT; i++) {
base = Image->ImageDesc.Width * (y + i) + x;
for (cp = legend; *cp; cp++)
for (j = 0; j < GIF_FONT_WIDTH; j++) {
if (GifAsciiTable8x8[(short)(*cp)][i] & (1 << (GIF_FONT_WIDTH - j)))
Image->RasterBits[base] = color;
base++;
}
}
}
void
GifDrawBox(SavedImage *Image,
const int x, const int y,
const int w, const int d,
const int color)
{
int j, base = Image->ImageDesc.Width * y + x;
for (j = 0; j < w; j++)
Image->RasterBits[base + j] =
Image->RasterBits[base + (d * Image->ImageDesc.Width) + j] = color;
for (j = 0; j < d; j++)
Image->RasterBits[base + j * Image->ImageDesc.Width] =
Image->RasterBits[base + j * Image->ImageDesc.Width + w] = color;
}
void
GifDrawRectangle(SavedImage *Image,
const int x, const int y,
const int w, const int d,
const int color)
{
unsigned char *bp = Image->RasterBits + Image->ImageDesc.Width * y + x;
int i;
for (i = 0; i < d; i++)
memset(bp + (i * Image->ImageDesc.Width), color, (size_t)w);
}
void
GifDrawBoxedText8x8(SavedImage *Image,
const int x, const int y,
const char *legend,
const int border,
const int bg, const int fg)
{
int j = 0, LineCount = 0, TextWidth = 0;
const char *cp;
char *dup;
for (cp = legend; *cp; cp++)
if (*cp == '\r') {
if (j > TextWidth)
TextWidth = j;
j = 0;
LineCount++;
} else if (*cp != '\t')
++j;
LineCount++;
if (j > TextWidth)
TextWidth = j;
dup = malloc(strlen(legend)+1);
if (dup != NULL) {
int i = 0;
GifDrawRectangle(Image, x + 1, y + 1,
border + TextWidth * GIF_FONT_WIDTH + border - 1,
border + LineCount * GIF_FONT_HEIGHT + border - 1, bg);
(void)strcpy(dup, (char *)legend);
cp = strtok((char *)dup, "\r\n");
do {
int leadspace = 0;
if (cp[0] == '\t')
leadspace = (TextWidth - strlen(++cp)) / 2;
GifDrawText8x8(Image, x + border + (leadspace * GIF_FONT_WIDTH),
y + border + (GIF_FONT_HEIGHT * i++), cp, fg);
cp = strtok((char *)NULL, "\r\n");
} while (cp);
(void)free((void *)dup);
GifDrawBox(Image, x, y, border + TextWidth * GIF_FONT_WIDTH + border,
border + LineCount * GIF_FONT_HEIGHT + border, fg);
}
}