Game Development Reference
In-Depth Information
{
int red;
int green;
int blue;
};
// The Image
XImage * image;
/**
* XImage Constructor
*/
XImage * XCreateImage(int width, int height)
{
XImage * this = (XImage*) malloc(sizeof(XImage));
// set width, height
this->width = width;
this->height = height;
// allocate image buffer
this->data = (byte *)malloc (width * height);
return this;
}
/**********************************************************
* Class XImage
**********************************************************/
In addition to
XImage
, you need a color palette used 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 7-23.
Listing 7-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 colour cmap with a new one
// Used by 256 colour PseudoColor modes
static int cachedgamma;
static size_t num_pals;
if (V_GetMode() == VID_MODEGL)
return;