GLE

GLE is a simple monochrome graphics format used for storing the Energy Star logo in AMI BIOS images. Full splash screens are usually stored in the PCX format.

Structure
The layout of a GLE file is as follows.

Converter
The following C99 program converts a GLE image to XPM.


 * 1) include 
 * 2) include 
 * 3) include 

struct gle_header { char   magic[3]; uint8_t reserved; /* = 1 */ uint8_t width; uint8_t height; uint8_t fgcolor; uint8_t bgcolor; };

static const uint_least32_t cga_palette[16] = { 0x000000, 0x0000aa, 0x00aa00, 0x00aaaa, 0xaa0000, 0xaa00aa, 0xaa5500, 0xaaaaaa, 0x555555, 0x5555ff, 0x55ff55, 0x55ffff, 0xff5555, 0xff55ff, 0xffff55, 0xffffff, };

int main(int argc, char *argv[]) { if (!argv[1]) { fprintf(stderr, "usage: %s $filename\n", argv[0]); return 1; }	FILE *inf = fopen(argv[1], "rb");

struct gle_header header; char magic[3]; if (!fread(&header, sizeof(header), 1, inf)) { if (feof(inf)) fprintf(stderr, "%s: %s: cannot read header: premature end of file\n", argv[0], argv[1]); else fprintf(stderr, "%s: %s: cannot read header: %s [%d]\n", argv[0], argv[1], strerror(errno), errno); return 1; }	if (memcmp(header.magic, "GLE", 3)) { fprintf(stderr, "%s: %s: magic number mismatch\n", argv[0], argv[1]); return 1; }	if (header.reserved != 1) { fprintf(stderr, "%s: %s: reserved byte == %u (!= 1), conversion may fail\n", argv[0], argv[1], header.reserved); }	uint8_t bitmap[header.width * header.height * 14]; if (!fread(bitmap, sizeof(bitmap), 1, inf)) { if (feof(inf)) fprintf(stderr, "%s: %s: cannot read bitmap data: premature end of file\n", argv[0], argv[1]); else fprintf(stderr, "%s: %s: cannot read bitmap data: %s [%d]\n", argv[0], argv[1], strerror(errno), errno); return 1; }

printf("/* XPM */\n"); printf("static char *gle[] = {\n"); printf("\"%u %u 2 1 \",\n", header.width * 8, header.height * 14); printf("\" c #%06x\",\n", cga_palette[header.bgcolor]); printf("\"@ c #%06x\",\n", cga_palette[header.fgcolor]);

for (size_t y = 0; y < 14 * header.height; ++y) { printf("\"");		for (size_t x = 0; x < header.width; ++x) {			uint8_t b = bitmap[(y - y % 14) * header.width + 14 * x + (y % 14)];			printf("%c%c%c%c%c%c%c%c",				(b >> 7)    ? '@' : ' ',				(b >> 6) & 1 ? '@' : ' ',				(b >> 5) & 1 ? '@' : ' ',				(b >> 4) & 1 ? '@' : ' ',				(b >> 3) & 1 ? '@' : ' ',				(b >> 2) & 1 ? '@' : ' ',				(b >> 1) & 1 ? '@' : ' ',				(b     ) & 1 ? '@' : ' '			);		}		printf("\",\n"); }

printf("};\n");

return 0; }