Macros | |
#define | oslGetImageLine(img, y) ((char*)((img)->data) + (y)*(((img)->realSizeX * osl_pixelWidth[(img)->pixelFormat])>>3)) |
#define | oslGetImagePixelAddr(img, x, y) ((char*)((img)->data) + ((((y)*(img)->realSizeX + (x)) * osl_pixelWidth[(img)->pixelFormat])>>3)) |
Functions | |
void | oslUncacheImageData (OSL_IMAGE *img) |
void | oslUncacheImage (OSL_IMAGE *img) |
int | oslGetImagePixel (OSL_IMAGE *img, unsigned int x, unsigned int y) |
void | oslSetImagePixel (OSL_IMAGE *img, unsigned int x, unsigned int y, int pixelValue) |
void * | oslGetSwizzledPixelAddr (OSL_IMAGE *img, unsigned int x, unsigned int y) |
int | oslConvertColor (int pfDst, int pfSrc, int color) |
int | oslConvertColorEx (OSL_PALETTE *p, int pfDst, int pfSrc, int color) |
void | oslLockImage (OSL_IMAGE *img) |
void | oslUnlockImage (OSL_IMAGE *img) |
Variables | |
const int | osl_pixelWidth [] |
const u8 | osl_paletteSizes [] |
Low level access to images.
#define oslGetImageLine | ( | img, | |
y | |||
) | ((char*)((img)->data) + (y)*(((img)->realSizeX * osl_pixelWidth[(img)->pixelFormat])>>3)) |
Returns the address of the beginning (left border) of an image line. This address can be used to access image raw data. Please note that when doing this, you'll have to respect the pixelformat of the image! If the image is 16 bits (4444, 5551 or 5650) then use a u16 pointer and appropriate RGBxx macros.
Here is an example which fills one line:
#define oslGetImagePixelAddr | ( | img, | |
x, | |||
y | |||
) | ((char*)((img)->data) + ((((y)*(img)->realSizeX + (x)) * osl_pixelWidth[(img)->pixelFormat])>>3)) |
Gets the address of a single pixel of an image. Please note that this works only for 8 to 32 bits pixel types, but not for 4 bits, as the byte is the smallest unit you can work with, and in this case a byte contains 2 pixels. In case of 4 bits, a pointer to the corresponding pixel pair (byte) will be returned, and you'll have to use masks to handle this correctly.
Here is an (untested) example:
|
inline |
Flushes the image data from the cache. Never forget to call this after you've modified an image in a cached way (by default all the following routines do). See oslUncacheData for more information.
Note: this routine does not flush the associated image palette data! Call oslUncacheImage instead if you need it!
void oslUncacheImage | ( | OSL_IMAGE * | img | ) |
Uncache a whole image, including its associated palette (image->palette).
int oslGetImagePixel | ( | OSL_IMAGE * | img, |
unsigned int | x, | ||
unsigned int | y | ||
) |
High-level routine which reads a single pixel on an image. Beware, caching is enabled, so after finished reading and/or writing pixels to an image, please take care to uncache your image! The best and cleaner way to do it is to use oslLockImage and oslUnlockImage. See oslGetImagePixel for an example.
\return The value of the pixel at that position. The value depends on the pixelformat, it can be a palette entry number if the image is paletted, or a color in the format of the image (so you may have to convert it depending on what you'd like).
Note: This routine also works for swizzled images!
Note: this routine is rather slow, you should consider raw access if you need good performance.
void oslSetImagePixel | ( | OSL_IMAGE * | img, |
unsigned int | x, | ||
unsigned int | y, | ||
int | pixelValue | ||
) |
Sets a pixel on the image. Same remarks as for oslGetImagePixel apply. The value is in the destination format of the image (so, either a palette entry or a color in the good format). Use conversions if needed, as shown in the example above. Here is another example that does calculation on every pixel of an image.
void* oslGetSwizzledPixelAddr | ( | OSL_IMAGE * | img, |
unsigned int | x, | ||
unsigned int | y | ||
) |
Returns the address of a pixel, working even if the image is swizzled. This implementation is slower but works in every case.
int oslConvertColor | ( | int | pfDst, |
int | pfSrc, | ||
int | color | ||
) |
Converts a color.
pfDst | Destination pixel format. |
pfSrc | Source pixel format. |
color | Color (in the source pixel format). |
int oslConvertColorEx | ( | OSL_PALETTE * | p, |
int | pfDst, | ||
int | pfSrc, | ||
int | color | ||
) |
Converts a color but using a palette if either the source or destination pixel format are paletted. See oslGetImagePixel for an example of use.
void oslLockImage | ( | OSL_IMAGE * | img | ) |
Locks an image, so that you can access it. Althrough not necessary, this is a good thing to do because it will automatically handle drawing to the drawbuffer, uncaching the image when finished and flushing the texture cache to avoid render errors when an image is modified while it's being drawn.
void oslUnlockImage | ( | OSL_IMAGE * | img | ) |
Unlock the image after you've finished with it.
const int osl_pixelWidth[] |
List of pixel widths (in bits) for each pixel format.
const u8 osl_paletteSizes[] |
List of palette sizes (in powers of two). For non-paletted formats, it is zero. Else you can get the palette size by doing 1 << osl_paletteSizes[pixelFormat].