Pretty sure libtcod is graphical. It's used to display ascii characters (or anything else you can think of) out side of the terminal.
typedef struct RGB {
uint8_t red;
uint8_t green;
uint8_t blue;
} RGB;
typedef struct canvas {
int width;
int height;
RGB *data;
} canvas;
size_t extract_data_to_canvas (FILE *in, canvas *out)
{
int width, height, bpp;
int padding, offset, i, seek;
size_t len;
fseek (in, 0xA, SEEK_SET);
len = fread (&offset, sizeof(uint32_t), 1, in);
fseek (in, 0x12, SEEK_SET);
len = fread (&width, sizeof(int32_t), 1, in);
fseek (in, 0x16, SEEK_SET);
len = fread (&height, sizeof(int32_t), 1, in);
fseek (in, 0x1C, SEEK_SET);
len = fread (&bpp, sizeof(uint16_t), 1, in);
out->width = width;
out->height = height;
RGB data[width*height];
if((width * bpp / % 4 == 0)
padding = 0;
else
padding = (4 - ((width * bpp / % 4));
/* BROKEN */
seek = 0;
fseek (in, offset, SEEK_SET);
for (i = 0; i < width * height; i++, seek += 3) {
len = fread(&data[i], sizeof(RGB), 1, in);
if (i > 0 && i % width == 0) {
seek = seek + padding;
}
fseek (in, offset + seek, SEEK_SET);
}
out->data = data;
return len;
}
This one's driving me crazy. Running through out->data's values like this:
for (i = 0; i < width * height; i++)
printf ("%X %X %X\n", out->data[i].red, out->data.green, out->data.blue);
produces right values. But when calling the function and printing the values again, all I get is random data.
...
extract_data_to_canvas (f, &c);
for (i = 0; i < c.width * c.height; i++)
printf ("%X %X %X\n", c.data[i].red, c.data[i].green, c.data[i].blue);
...
I have a feeling I'm not assigning something correctly.