doubt about load_bitmap(const char *filename, RGB *pal)
sj971059

I read from allegro manual, I found before a bitmap is loaded to the program,We'll
call set_color_depth(int depth) and set_gfx_mode();
If we set 8 bits as the color_depth, when we use load_bitmap(filename, pal), the pal can't been passed as NULL , it must been a pointer points to a PALETTE type variable, after load_bitmap, we'll call set_palette(pal), if we doesn't do so,the last display reust is NOT right;
on the other way ,if we set 15,16,24,or 32 bits as the color_detph, the parameter passed to load_bitmap can be NULL, and we don't need to call set_palette(pal), and the last display result is right.
who can tell me what's the difference between them ?

by the way : after display the image to screen, I tried to get the bitmap color_depth, if we set 8 bits as the color_depth , the bitmap's color_depth is 8;
if we set 32 bits as the color_depth, the bitmap's color_depth is 32, I think the color_depth of the bitmap file is a const value, why does it change along with color_depth value?

here is the code :

set_color_depth(8);
   if (set_gfx_mode(GFX_AUTODETECTED, w, h, 0, 0) != 0) {
      allegro_message("Unable to set mode %ix%i with 8bpp\n", w, h);
     }
    /* load the image */
   background = load_bitmap(filename, pal); <------ here
   if (background != NULL) {
      set_palette(pal); <------ here
   };

another :

set_color_depth(32);
   if (set_gfx_mode(GFX_AUTODETECTED, w, h, 0, 0) != 0) {
      allegro_message("Unable to set mode %ix%i with 32bpp\n", w, h);
     }
    /* load the image */
   background = load_bitmap(filename, NULL); <----- here

BAF

8 bit is only 255 colors so for it to be right you need a pallette to tell it what colors are which. On higher bit modes, you have "nearly unlimited" colors, so pallettes arne't used.

The color depth changes because when you load the bitmap, Allegro converts it to the current color depth automagically.

Evert
Quote:

If we set 8 bits as the color_depth, when we use load_bitmap(filename, pal), the pal can't been passed as NULL , it must been a pointer points to a PALETTE type variable, after load_bitmap, we'll call set_palette(pal), if we doesn't do so,the last display reust is NOT right;
on the other way ,if we set 15,16,24,or 32 bits as the color_detph, the parameter passed to load_bitmap can be NULL, and we don't need to call set_palette(pal), and the last display result is right.

You're over complicating. You can always pass NULL for the pal argument, in which case the palette of the bitmap will be ignored (if there is one). Only 8 bit bitmaps have palettes anyway, so if you're loading a high or true colour image, the pal argument will be ignored anyway.
If you load an 8 bit image, you have to specify the palette of colours to use with it, because 8 bit images actually store the index into a 255 colour palette rather than the RGB value of a particular colour.

Quote:

I tried to get the bitmap color_depth, if we set 8 bits as the color_depth , the bitmap's color_depth is 8;
if we set 32 bits as the color_depth, the bitmap's color_depth is 32, I think the color_depth of the bitmap file is a const value, why does it change along with color_depth value?

You're converting the colour depth to the current colourdepth when the file is loaded; see set_color_conversion().

Thread #587448. Printed from Allegro.cc