Image Formats

The data formats of the XImage are as follows :
         |MSB                           LSB|
         |Byte 3| |Byte 2| |Byte 1| |Byte 0|
24 bpp : 00000000 RRRRRRRR GGGGGGGG BBBBBBBB
16 bpp :                   RRRRRGGG GGGBBBBB
 8 bpp :                            CCCCCCCC

0 = always zero bits
R = the red bits
G = the green bits
B = the blue bits
C = the color index bits

The data format of the VortexGE render buffer is always as follows :
|MSB                           LSB|
|Byte 3| |Byte 2| |Byte 1| |Byte 0|
00000000 RRRRR000 GGGGG000 BBBBB000

A copy operation from the render buffer to the 24 bpp XImage data buffer can be done by using a single memcpy instruction like :
memcpy(pucXImageDataBuffer, pun8RenderBuffer, [Width] * [Height] * 4);
(assuming that the render buffer and the XImage have the same width and height)

A copy operation from the render buffer to the 16 bpp XImage must be done manually by first converting the RGB values of the render buffer to the RGB values of the XImage data buffer by using shift operation as follows :
RGB16 = (R << 8) | (G << 3) | (B >> 3) 
or in C++ instruction will be like this :
_vuint16 *pun16Tmp = (_vuint16 *) pucXImageDataBuffer;
_vuint8  *pun8Tmp  = pun8RenderBuffer;
 
*pun16Tmp++ = ((*pun8Tmp++) >> 3) | ((*pun8Tmp++) << 3) | ((*pun8Tmp++) << 8);

A copy operation from the render buffer to the 8 bpp XImage must be done manually by first converting the RGB values of the render buffer to the color index value of the XImage data buffer. To do this we use a color translation LUT that has 32x32x32 entries like this :
COLORINDEX = LUT[(R << 7) | (G << 2) | (B >> 3)]
or in C++ instruction will be like this :
_vuchar  *pucTmp  = pucXImageDataBuffer;
_vuint8  *pun8Tmp = pun8RenderBuffer;
 
*pucTmp++ = pucLUT[((*pun8Tmp++) >> 3) | ((*pun8Tmp++) << 2) | ((*pun8Tmp++) << 7)];

for the above operation to be valid we must fill the LUT with the color translation data as follows :
LUT[(R << 10) | (G << 5) + B] =  FIND_CLOSEST_COLOR(R, G, B)

the R, G and B are counters that run from 0 to 31 and the FIND_CLOSEST_COLOR is a function that searches the closest color value of the palette for each combination of R, G and B values.

Main Index