//! fills the surface with given color void CImage::fill(const ColourValue &color) { UINT32 c; switch (Format) { case ECF_A1R5G5B5: c = A8R8G8B8toA1R5G5B5(color.getAsARGB()); c |= c << 16; break; case ECF_R5G6B5: c = A8R8G8B8toR5G6B5(color.getAsARGB()); c |= c << 16; break; case ECF_A8R8G8B8: c = color.getAsARGB(); break; case ECF_R8G8B8: { UINT8 rgb[3]; CColorConverter::convert_A8R8G8B8toR8G8B8(&color, 1, rgb); const UINT32 size = getImageDataSizeInBytes(); for (UINT32 i = 0; i<size; i += 3) { memcpy(Data + i, rgb, 3); } return; } break; default: // TODO: Handle other formats return; } memset32(Data, c, getImageDataSizeInBytes()); }
void CColorConverter::convert_A8R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP) { u32* sB = (u32*)sP; u16* dB = (u16*)dP; for (s32 x = 0; x < sN; ++x) *dB++ = A8R8G8B8toA1R5G5B5(*sB++); }
//! sets a pixel void CImage::setPixel(UINT32 x, UINT32 y, const ColourValue &color, bool blend) { ColourValue c = color; if (x >= Size.Width || y >= Size.Height) return; switch (Format) { case ECF_A1R5G5B5: { UINT16 * dest = (UINT16*)(Data + (y * Pitch) + (x << 1)); *dest = A8R8G8B8toA1R5G5B5(color.getAsARGB()); } break; case ECF_R5G6B5: { UINT16 * dest = (UINT16*)(Data + (y * Pitch) + (x << 1)); *dest = A8R8G8B8toR5G6B5(color.getAsARGB()); } break; case ECF_R8G8B8: { UINT8* dest = Data + (y * Pitch) + (x * 3); dest[0] = (UINT8)c.getRed(); dest[1] = (UINT8)c.getGreen(); dest[2] = (UINT8)c.getBlue(); } break; case ECF_A8R8G8B8: { UINT32 * dest = (UINT32*)(Data + (y * Pitch) + (x << 2)); *dest = blend ? PixelBlend32(*dest, color.getAsARGB()) : color.getAsARGB(); } break; #ifndef _DEBUG default: break; #endif } }