Game Development Reference
In-Depth Information
In addition to XImage , you need a color palette to map the bytes on XImage to ARGB colors
used by Android. For this purpose, you use the struct XColor , which holds the red, green,
and blue values of a color. You also need a function to allocate memory for the XImage given
its width and height ( XCreateImage ). This function will allocate space for the image byte
buffer. You must modify the palette upload function ( I_UploadNewPalette ) in i_video.c to
use the new XColor structure, as shown in Listing 5-23.
Listing 5-23. Setting the Color Palette in i_video.c
// Color palette
static XColor * colours;
static void I_UploadNewPalette(int pal)
{
// This is used to replace the current 256 color cmap with a new one
// Used by 256 color PseudoColor modes
static int cachedgamma;
static size_t num_pals;
if (V_GetMode() == VID_MODEGL)
return;
if ((colours == NULL) || (cachedgamma != usegamma)) {
int pplump = W_GetNumForName("PLAYPAL");
int gtlump = (W_CheckNumForName)("GAMMATBL",ns_prboom);
register const byte * palette = W_CacheLumpNum(pplump);
register const byte * const gtable = (const byte *)W_CacheLumpNum(gtlump)
+ 256*(cachedgamma = usegamma);
register int i;
num_pals = W_LumpLength(pplump) / (3*256);
num_pals *= 256;
if (!colours) {
// First call - allocate and prepare color array
colours = malloc(sizeof(*colours)*num_pals);
}
// set the colormap entries
for (i=0 ; (size_t)i<num_pals ; i++) {
colours[i].red = gtable[palette[0]];
colours[i].green = gtable[palette[1]];
colours[i].blue = gtable[palette[2]];
palette += 3;
}
W_UnlockLumpNum(pplump);
W_UnlockLumpNum(gtlump);
num_pals/=256;
}
}
 
Search WWH ::




Custom Search