//! fills the surface with given color void CImage::fill(const SColor &color) { u32 c; switch (Format) { case ECF_A1R5G5B5: { c = color.toA1R5G5B5(); c |= c << 16; break; } case ECF_R5G6B5: { c = SharedColorConverter::getInstance().A8R8G8B8toR5G6B5( color.color); c |= c << 16; break; } case ECF_A8R8G8B8: { c = color.color; break; } case ECF_R8G8B8: { u8 rgb[3]; SharedColorConverter::getInstance().convert_A8R8G8B8toR8G8B8( &color, 1, rgb); const u32 size = getImageDataSizeInBytes(); for (u32 i = 0; i < size; i += 3) { memcpy(Data + i, rgb, 3); } return; break; } case ECF_R16F: case ECF_G16R16F: case ECF_A16B16G16R16F: case ECF_R32F: case ECF_G32R32F: case ECF_A32B32G32R32F: case ECF_UNKNOWN: default: { break; } } if (Format != ECF_A1R5G5B5 && Format != ECF_R5G6B5 && Format != ECF_A8R8G8B8) { return; } StaticVideoUtils::memset32(Data, c, getImageDataSizeInBytes()); }
//! fills the surface with given color void CImage::fill(const SColor &color) { u32 c; switch ( Format ) { case ECF_A1R5G5B5: c = color.toA1R5G5B5(); c |= c << 16; break; case ECF_R5G6B5: c = video::A8R8G8B8toR5G6B5( color.color ); c |= c << 16; break; case ECF_A8R8G8B8: c = color.color; break; case ECF_R8G8B8: { u8 rgb[3]; CColorConverter::convert_A8R8G8B8toR8G8B8(&color, 1, rgb); const u32 size = getImageDataSizeInBytes(); for (u32 i=0; i<size; i+=3) { memcpy(Data+i, rgb, 3); } return; } break; default: // TODO: Handle other formats return; } memset32( Data, c, getImageDataSizeInBytes() ); }
//! Creates a boolean alpha channel of the texture based of an color key. void CNullDriver::makeColorKeyTexture(ITexture* texture, SColor color, bool zeroTexels) const { if (!texture) return; if (texture->getColorFormat() != ECF_A1R5G5B5 && texture->getColorFormat() != ECF_A8R8G8B8 ) { Printer::log("Error: Unsupported texture color format for making color key channel.", ELL_ERROR); return; } if (texture->getColorFormat() == ECF_A1R5G5B5) { u16 *p = (u16*)texture->lock(); if (!p) { Printer::log("Could not lock texture for making color key channel.", ELL_ERROR); return; } const dimension2d<u32> dim = texture->getSize(); const u32 pitch = texture->getPitch() / 2; // color with alpha disabled (i.e. fully transparent) const u16 refZeroAlpha = (0x7fff & color.toA1R5G5B5()); const u32 pixels = pitch * dim.Height; for (u32 pixel = 0; pixel < pixels; ++ pixel) { // If the color matches the reference color, ignoring alphas, // set the alpha to zero. if(((*p) & 0x7fff) == refZeroAlpha) { if(zeroTexels) (*p) = 0; else (*p) = refZeroAlpha; } ++p; } texture->unlock(); } else { u32 *p = (u32*)texture->lock(); if (!p) { Printer::log("Could not lock texture for making color key channel.", ELL_ERROR); return; } dimension2d<u32> dim = texture->getSize(); u32 pitch = texture->getPitch() / 4; // color with alpha disabled (fully transparent) const u32 refZeroAlpha = 0x00ffffff & color.color; const u32 pixels = pitch * dim.Height; for (u32 pixel = 0; pixel < pixels; ++ pixel) { // If the color matches the reference color, ignoring alphas, // set the alpha to zero. if(((*p) & 0x00ffffff) == refZeroAlpha) { if(zeroTexels) (*p) = 0; else (*p) = refZeroAlpha; } ++p; } texture->unlock(); } texture->regenerateMipMapLevels(); }