Image palettes

Functions

OSL_PALETTEoslCreatePaletteEx (int size, int location, short pixelFormat)
 
OSL_PALETTEoslCreatePalette (int size, short pixelFormat)
 
OSL_PALETTEoslCreatePaletteFrom (void *data, int size, short pixelFormat)
 
void oslDeletePalette (OSL_PALETTE *p)
 
int oslGetPaletteColor (OSL_PALETTE *p, int index)
 
void oslUncachePalette (OSL_PALETTE *pal)
 

Detailed Description

Palette for 4 and 8-bit images.

Function Documentation

OSL_PALETTE* oslCreatePaletteEx ( int  size,
int  location,
short  pixelFormat 
)

Creates a new (empty) palette with the specified pixelFormat.

Parameters
sizeNumber of colors of the palette.
locationLocation where to put the palette. Always put it in RAM for now (OSL_IN_RAM).
pixelFormatPixel format of each palette entry. It should always be OSL_PF_8888 as palettes are rather small in size.

Remember that raw access to palette is cached, so you must uncache it after having filled it. Look at oslGetImageLine and oslGetImagePixelAdr for more information.

//We can get the palette size with this (in our case it's 16, as 4 bits means 16 colors).
int palSize = 1 << osl_paletteSizes[img->pixelFormat];
//Loop index variable.
int i;
//Palettes are not automatically created with images, we need to do it by yourself
//Get a pointer to palette data
u32 *paletteData = (u32*)img->palette->data;
//Set all entries to bright opaque red.
for (i=0;i<img->palette->nElements;i++)
paletteData[i] = RGBA(255, 0, 0, 255);
//Don't forget to uncache the palette after finished with it
//An alternate possibility is: oslUncacheImage(img); (uncaches the palette as well)
OSL_PALETTE* oslCreatePalette ( int  size,
short  pixelFormat 
)
inline

Creates a palette. Simpler function without the location argument.

OSL_PALETTE* oslCreatePaletteFrom ( void *  data,
int  size,
short  pixelFormat 
)

Creates a palette from existing data. Please note that data is not copied to a new location but used as is! You just have to specify the palette size and pixelFormat.

void oslDeletePalette ( OSL_PALETTE p)

Deletes an existing palette. If the palette was created with oslCreatePaletteFrom, the data is not freed or anything, it's left as it was before, only the OSL_PALETTE structure is freed.

int oslGetPaletteColor ( OSL_PALETTE p,
int  index 
)

Returns a color entry from a palette. The color will be in the same pixelformat as the palette (16 or 32 bits).

void oslUncachePalette ( OSL_PALETTE pal)

Uncaches a palette. As with oslUncacheData, always uncache a palette after you've accessed it in a cached way (pal->data). Look at oslCreatePalette for more info.