Truecolor pixel formats

In a truecolor video mode the red, green, and blue components for each pixel are packed directly into the color value, rather than using a palette lookup table. In a 15-bit mode there are 5 bits for each color, in 16-bit modes there are 5 bits each of red and blue and six bits of green, and both 24 and 32-bit modes use 8 bits for each color (the 32-bit pixels simply have an extra padding byte to align the data nicely). The layout of these components can vary depending on your hardware, but will generally either be RGB or BGR. Since the layout is not known until you select the video mode you will be using, you must call set_gfx_mode() before using any of the following routines!


int makecol8(int r, int g, int b);

int makecol15(int r, int g, int b);

int makecol16(int r, int g, int b);

int makecol24(int r, int g, int b);

int makecol32(int r, int g, int b);

These functions convert colors from a hardware independent form (red, green, and blue values ranging 0-255) into various display dependent pixel formats. Converting to 15, 16, 24, or 32-bit formats only takes a few shifts, so it is fairly efficient. Converting to an 8-bit color involves searching the palette to find the closest match, which is quite slow unless you have set up an RGB mapping table (see below). Example:
      /* 16 bit color version of green. */
      int green_color = makecol16(0, 255, 0);

Return value: Returns the requested RGB triplet in the specified color depth.

See also: makeacol32, makecol, makecol_depth, makecol15_dither, rgb_map, bestfit_color, set_color_depth.
Examples using this: exrgbhsv.
int makeacol32(int r, int g, int b, int a);

Converts an RGBA color into a 32-bit display pixel format, which includes an alpha (transparency) value. There are no versions of this routine for other color depths, because only the 32-bit format has enough room to store a proper alpha channel. You should only use RGBA format colors as the input to draw_trans_sprite() or draw_trans_rle_sprite() after calling set_alpha_blender(), rather than drawing them directly to the screen.
See also: makeacol, set_alpha_blender, set_write_alpha_blender.
int makecol(int r, int g, int b);

Converts colors from a hardware independent format (red, green, and blue values ranging 0-255) to the pixel format required by the current video mode, calling the preceding 8, 15, 16, 24, or 32-bit makecol functions as appropriate. Example:
      /* Regardless of color depth, this will look green. */
      int green_color = makecol(0, 255, 0);

Return value: Returns the requested RGB triplet in the current color depth.

See also: makeacol, makecol8, makecol_depth, makecol15_dither, rgb_map, set_color_depth.
Examples using this: Available Allegro examples.
int makecol_depth(int color_depth, int r, int g, int b);

Converts colors from a hardware independent format (red, green, and blue values ranging 0-255) to the pixel format required by the specified color depth. Example:
      /* Compose the green color for 15 bit color depth. */
      int green_15bit = makecol_depth(15, 0, 255, 0);

Return value: Returns the requested RGB triplet in the specified color depth.

See also: makeacol, makecol, makecol8, makecol15_dither, rgb_map, set_color_depth.
int makeacol(int r, int g, int b, int a);

int makeacol_depth(int color_depth, int r, int g, int b, int a);

Convert RGBA colors into display dependent pixel formats. In anything less than a 32-bit mode, these are the same as calling makecol() or makecol_depth(), but by using these routines it is possible to create 32-bit color values that contain a true 8 bit alpha channel along with the red, green, and blue components. You should only use RGBA format colors as the input to draw_trans_sprite() or draw_trans_rle_sprite() after calling set_alpha_blender(), rather than drawing them directly to the screen.

Return value: Returns the requested RGBA quadruplet.

See also: makecol, makecol_depth, set_alpha_blender, set_write_alpha_blender.
Examples using this: exrotscl.
int makecol15_dither(int r, int g, int b, int x, int y);

int makecol16_dither(int r, int g, int b, int x, int y);

Given both a color value and a pixel coordinate, calculate a dithered 15 or 16-bit RGB value. This can produce better results when reducing images from truecolor to hicolor. In addition to calling these functions directly, hicolor dithering can be automatically enabled when loading graphics by calling the set_color_conversion() function, for example set_color_conversion(COLORCONV_REDUCE_TRUE_TO_HI | COLORCONV_DITHER).

Example:

      int pixel1, pixel2;

      /* The following two color values MAY be different. */
      pixel1 = makecol16_dither(255, 192, 64, 0, 0);
      pixel2 = makecol16_dither(255, 192, 64, 1, 0);

Return value: Returns the RGB value dithered for the specified coordinate.

See also: makecol, makecol8, set_color_conversion.
int getr8(int c);

int getg8(int c);

int getb8(int c);

int getr15(int c);

int getg15(int c);

int getb15(int c);

int getr16(int c);

int getg16(int c);

int getb16(int c);

int getr24(int c);

int getg24(int c);

int getb24(int c);

int getr32(int c);

int getg32(int c);

int getb32(int c);

Given a color in a display dependent format, these functions extract one of the red, green, or blue components (ranging 0-255). Example:
      int r, g, b, color_value;

      color_value = _getpixel15(screen, 100, 100);
      r = getr15(color_value);
      g = getg15(color_value);
      b = getb15(color_value);
See also: geta32, getr, getr_depth, makecol, set_color_depth.
int geta32(int c);

Given a color in a 32-bit pixel format, this function extracts the alpha component (ranging 0-255).
See also: getr8.
int getr(int c);

int getg(int c);

int getb(int c);

int geta(int c);

Given a color in the format being used by the current video mode, these functions extract one of the red, green, blue, or alpha components (ranging 0-255), calling the preceding 8, 15, 16, 24, or 32-bit get functions as appropriate. The alpha part is only meaningful for 32-bit pixels. Example:
      int r, g, b, color_value;

      color_value = getpixel(screen, 100, 100);
      r = getr(color_value);
      g = getg(color_value);
      b = getb(color_value);
See also: getr8, getr_depth, makecol, set_color_depth.
Examples using this: exalpha.
int getr_depth(int color_depth, int c);

int getg_depth(int color_depth, int c);

int getb_depth(int color_depth, int c);

int geta_depth(int color_depth, int c);

Given a color in the format being used by the specified color depth, these functions extract one of the red, green, blue, or alpha components (ranging 0-255). The alpha part is only meaningful for 32-bit pixels. Example:
      int r, g, b, color_value, bpp;

      bpp = bitmap_color_depth(bitmap);
      color_value = getpixel(bitmap, 100, 100);
      r = getr_depth(bpp, color_value);
      g = getg_depth(bpp, color_value);
      b = getb_depth(bpp, color_value);
See also: getr, getr8, geta32, makecol, set_color_depth.
Examples using this: exlights.
extern int palette_color[256];

Table mapping palette index colors (0-255) into whatever pixel format is being used by the current display mode. In a 256-color mode this just maps onto the array index. In truecolor modes it looks up the specified entry in the current palette, and converts that RGB value into the appropriate packed pixel format. Example:
      set_color_depth(32);
      ...
      set_palette(desktop_palette);
      /* Put a pixel with the color 2 (green) of the palette */
      putpixel(screen, 100, 100, palette_color[2]);
See also: set_palette, makecol, set_color_depth.
Examples using this: Available Allegro examples.
#define MASK_COLOR_8 0

#define MASK_COLOR_15 (5.5.5 pink)

#define MASK_COLOR_16 (5.6.5 pink)

#define MASK_COLOR_24 (8.8.8 pink)

#define MASK_COLOR_32 (8.8.8 pink)

Constants representing the colors used to mask transparent sprite pixels for each color depth. In 256-color resolutions this is zero, and in truecolor modes it is bright pink (maximum red and blue, zero green).
See also: bitmap_mask_color, makecol, draw_sprite, masked_blit.

Back to contents