I'm working on a project that needs to operate without the use of extern data. Therefore I thought it might be useful to use the function in the GIMP (GNU Image Manipulation Program) to save an image as a C header file.
However, I can't get my function to work. It is supposed to convert the data in the header (in the example it's a font) to an allegro BITMAP struct.
Here are parts of the code produced by the GIMP (I've modified the variable names a little):
<code>
static unsigned int tahoma22Width = 513;
static unsigned int tahoma22Height = 289;
/* Call this macro repeatedly. After each use, the pixel data can be extracted */
#define HEADER_PIXEL(data,pixel) {\
pixel[0] = header_data_cmap[(unsigned char)data[0]][0]; \
pixel[1] = header_data_cmap[(unsigned char)data[0]][1]; \
pixel[2] = header_data_cmap[(unsigned char)data[0]][2]; \
data ++; }
static char header_data_cmap[256][3] = {
{255, 0,255},
{255,255,255},
{ 0,255,255},
{ 0,255,255},
{ 0,255,255},
{ 0,255,255},
{ 0,255,255},
{ 0,255,255},
//.....
static char header_data[] = {
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
//....
<code>
Here's my code
1 | void memoryPutpixel(BITMAP *bmp, int x, int y, int color) |
2 | { |
3 | bmp->line[y][x] = color; |
4 | } |
5 | |
6 | //Convert the data in the header to a BITMAP * |
7 | BITMAP *extractBmp(char *data, int width, int height) |
8 | { |
9 | char pixel[3]; |
10 | int x = 0, y = 0; |
11 | BITMAP *temp = create_bitmap(width, height); |
12 | for (int i = 0; i < width*height; i++) |
13 | { |
14 | HEADER_PIXEL(data, pixel); |
15 | memoryPutpixel(temp, x, y, makecol(pixel[0], pixel[1], pixel[2])); |
16 | x++; |
17 | if (x > width) |
18 | { |
19 | y++; |
20 | x = 0; |
21 | } |
22 | } |
23 | return temp; |
24 | } |
25 | |
26 | //... |
27 | |
28 | //Here's the code that calls the function |
29 | BITMAP *bmp = extractBmp(header_data, tahoma22Width, tahoma22Height); |
30 | |
31 | //... |
This doesn't work of course. The variable called data in the GIMP macro is supposed to point to a two-dimensional array. But the only two-dimensional array is header_data_cmap, and it can't point to that?
I'm a bit lost here, could someone please help me?
Just point it to header_data. the macro is already using header_data_cmap,
header_data_cmap[(unsigned char) data[0] ][0]
I think it wants a one dimentional array.
What's wrong with dat2c?
Yes, you're right. I missed one of the square brackets there, it should be a one-dimensional array. But then I can't understand why it isn't working. It is pointing to header_data, but I just get weird colors.
Actually I haven't tried dat2c, but maybe I should give it a try. Can't understand why this isn't working though.
[edit]
I found out what was wrong. I just had to change the arrays to unsigned char.
But now that I have the BITMAP *, how can I convert it to a FONT *? The grabber can do this, so it must be possible. I have tried searching the allegro source code for hints, but I can't even find where FONT * is declared. How would I go about writing a function that converts a BITMAP * to FONT *?
[/edit]