When I've loaded an image I'm having difficulties to print the palette of it. Here's what I've done so far:
Code:
PAL_START_X = 510,
PAL_START_Y = 10,
PAL_SCALE = 8,
PAL_COLS = 16,
PAL_ROWS = 16,
...
/* Set the best color depth that we can find */
set_color_depth(16);
if(set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0) != 0)
{
set_color_depth(15);
if(set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0) != 0)
{
set_color_depth(32);
if(set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0) != 0)
{
set_color_depth(24);
if(set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0) != 0)
{
allegro_exit();
printf("Error setting graphics mode\n%s\n\n", allegro_error);
exit(1);
}
}
}
}
set_color_conversion(COLORCONV_TOTAL);
...
PALLETE pal;
BITMAP *bm = load_bitmap("foo.pcx", pal);
if(!bm)
exit(1);
get_palette(pal);
set_palette(pal);
print_palette(pal);
print_palette(pal);
...
void print_palette(const PALLETE pal)
{
int color = 0;
/* Those `-1's are because the outline of that rectangle would go over what
is needed */
for(int j = 0; j < PAL_ROWS; j++)
for(int i = 0; i < PAL_COLS; i++, color++)
{
rectfill(screen, PAL_START_X+i*PAL_SCALE, PAL_START_Y+j*PAL_SCALE,
PAL_START_X+i*PAL_SCALE+PAL_SCALE-1,
PAL_START_Y+j*PAL_SCALE+PAL_SCALE-1,
makecol(pal[color].r, pal[color].g, pal[color].b));
}
}
This supposed to print palette while one color takes 8*8 pixels and as 16*16 table. However, even when I only load 211 color picture my palette prints out all wrong.