|
|
|
|
GA_pixelFormat
Declaration
typedef struct {
N_uint8 RedMask;
N_uint8 RedPosition;
N_uint8 RedAdjust;
N_uint8 GreenMask;
N_uint8 GreenPosition;
N_uint8 GreenAdjust;
N_uint8 BlueMask;
N_uint8 BluePosition;
N_uint8 BlueAdjust;
N_uint8 AlphaMask;
N_uint8 AlphaPosition;
N_uint8 AlphaAdjust;
} GA_pixelFormat
Prototype In
snap/graphics.h
Description
Structure representing the format of an RGB pixel. This structure is used to describe the RGB pixel format for SNAP graphics modes, as well as the pixel format for system memory buffers converted on the fly by SNAP Graphics to the destination pixel format. RGB pixel formats are required for 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 RGB 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. SNAP Graphics has the ability to perform pixel format translation on the fly using the ConvertBlt family of functions, but this can be time consuming so directly rendering in the native pixel format can be more efficient. The formula for packing the pixel data into the proper positions given three 8-bit RGB values is as follows:
color = ((GA_color)((R >> RedAdjust) & RedMask)
<< RedPosition)
| ((GA_color)((G >> GreenAdjust)
& GreenMask)
<< GreenPosition)
| ((GA_color)((B >> BlueAdjust)
& BlueMask)
<< BluePosition);
Alternatively you can unpack the color values from the framebuffer with the following code (note that you lose precision when unpacking values from the framebuffer since the bottom bits always get set to 0):
R = (((color) >> RedPosition) & RedMask)
<< RedAdjust;
G = (((color) >> GreenPosition) & GreenMask)
<< GreenAdjust;
B = (((color) >> BluePosition) & 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 SNAP Graphics 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
One special cased pixel format is used to represent and 8bpp color index bitmap with an alpha channel. This pixel format is a 16-bit wide pixel format, but the red channel is considered to contain the 8-bit color index values. The pixel format structure for this type of bitmap looks like the following:
{0xFF,0x00,0, 0x00,0x00,0, 0x00,0x00,0, 0xFF,0x08,0}, // A8CI 8bpp + Alpha
Members
RedMask |
Unshifted 8-bit mask for the red color channel |
RedPosition |
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 |
GreenPosition |
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 |
BluePosition |
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 |
AlphaPosition |
Bit position for bit 0 of the alpha channel information |
AlphaAdjust |
Number of bits to shift the 8-bit alpha value right |
Copyright © 2002 SciTech Software, Inc. Visit our web site at http://www.scitechsoft.com