pixel_format_t

Declaration

typedef struct {
uchar redMask;
uchar redPos;
uchar redAdjust;
uchar greenMask;
uchar greenPos;
uchar greenAdjust;
uchar blueMask;
uchar bluePos;
uchar blueAdjust;
uchar alphaMask;
uchar alphaPos;
uchar alphaAdjust;
} pixel_format_t

Prototype In

mgraph.h

Description

Structure representing the format of an RGB pixel. This structure is used to describe the current RGB pixel format used by all MGL device contexts with pixel depths greater than or equal to 15-bits per pixel. The pixel formats for 15 and 16-bit modes are constant and never change, however there are 2 possible pixel formats for 24 bit RGB modes and 4 possible formats for 32 bit RGB modes that are supported by the MGL. The possible modes for 24-bits per pixel are:

24-bit | Description
RGB | Values are packed with Red in byte 2, Green in byte 1 and Blue in byte 0. This is the standard format used by all 24 bit Windows BMP files, and the native display format for most graphics hardware on the PC.
BGR | Values are packed with Blue in byte 2, Green in byte 1 and Red in byte 0. This format is the native display format for some graphics hardware on the PC.

The possible modes for 32-bits per pixel are:

32-bit | Description
ARGB | Values are packed with Red in byte 2, Green in byte 1 and Blue in byte 0 and alpha in byte 3.
ABGR | Values are packed with Blue in byte 2, Green in byte 1 and Red in byte 0 and alpha in byte 3.
RGBA | Values are packed with Red in byte 3, Green in byte 2 and Blue in byte 1 and alpha in byte 0.
BGRA | Values are packed with Blue in byte 3, Green in byte 2 and Red in byte 1 and alpha in byte 0.

If you intend to write your own direct rendering code for 15-bits per pixel and higher graphics modes, you will need to write your code so that it will adapt to the underlying pixel format used by the hardware to display the correct colors on the screen. The MGL will perform pixel format translation on the fly for MGL_bitBlt operations, but this can be time consuming. The formula for packing the pixel data into the proper positions given three 8-bit RGB values is as follows:

color = ((color_t)((R >> redAdjust) & redMask)
<< redPos)
| ((color_t)((G >> greenAdjust) & greenMask)
<< greenPos)
| ((color_t)((B >> blueAdjust) & blueMask)
<< bluePos);

Alternatively you can unpack the color values with the following code:

R = (((color) >> redPos) & redMask)
<< redAdjust;
G = (((color) >> greenPos) & greenMask)
<< greenAdjust;
B = (((color) >> bluePos) & blueMask)
<< blueAdjust;

If you wish to create your own pixel formats (such as to create memory custom bitmaps), the following list defines all the pixel formats that the MGL knows how to deal with:

{0x1F,0x0A,3, 0x1F,0x05,3, 0x1F,0x00,3, 0x01,0x0F,7}, // 555 15bpp
{0x1F,0x0B,3, 0x3F,0x05,2, 0x1F,0x00,3, 0x00,0x00,0}, // 565 16bpp
{0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0, 0x00,0x00,0}, // RGB 24bpp
{0xFF,0x00,0, 0xFF,0x08,0, 0xFF,0x10,0, 0x00,0x00,0}, // BGR 24bpp
{0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0, 0xFF,0x18,0}, // ARGB 32bpp
{0xFF,0x00,0, 0xFF,0x08,0, 0xFF,0x10,0, 0xFF,0x18,0}, // ABGR 32bpp
{0xFF,0x18,0, 0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0}, // RGBA 32bpp
{0xFF,0x08,0, 0xFF,0x10,0, 0xFF,0x18,0, 0xFF,0x00,0}, // BGRA 32bpp

Note: For 32-bit modes, the alpha channel information is unused, but should always be set to zero. Some hardware devices interpret the alpha channel information so unless you use a value of zero, you will get some strange looking results on the screen.

Members

redMask | Unshifted 8-bit mask for the red color channel, and will be 5-bits wide for a 5-bit color channel or 8-bits wide for an 8-bit color channel.
redPos | Bit position for bit 0 of the red color channel information.
redAdjust | Number of bits to shift the 8 bit red value right
greenMask | Unshifted 8-bit mask for the green color channel.
greenPos | Bit position for bit 0 of the green color channel information.
greenAdjust | Number of bits to shift the 8 bit green value right
blueMask | Unshifted 8-bit mask for the blue color channel.
bluePos | Bit position for bit 0 of the blue color channel information.
blueAdjust | Number of bits to shift the 8 bit blue value right
alphaMask | Unshifted 8-bit mask for the alpha channel.
alphaPost | Bit position for bit 0 of the alpha channel information
alphaAdjust | Number of bits to shift the 32 bit alpha value right

Copyright © 2002 SciTech Software, Inc. Visit our web site at http://www.scitechsoft.com