//! get a filtered pixel inline ColourValue CImage::getPixelBox(SINT32 x, SINT32 y, SINT32 fx, SINT32 fy, SINT32 bias) const { ColourValue c; SINT32 a = 0, r = 0, g = 0, b = 0; for (SINT32 dx = 0; dx != fx; ++dx) { for (SINT32 dy = 0; dy != fy; ++dy) { c = getPixel(SINT32_min(x + dx, Size.Width - 1), SINT32_min(y + dy, Size.Height - 1) ); a += c.getAlpha(); r += c.getRed(); g += c.getGreen(); b += c.getBlue(); } } SINT32 sdiv = s32_log2_f32(fx * fy); a = SINT32_clamp((a >> sdiv) + bias, 0, 255); r = SINT32_clamp((r >> sdiv) + bias, 0, 255); g = SINT32_clamp((g >> sdiv) + bias, 0, 255); b = SINT32_clamp((b >> sdiv) + bias, 0, 255); c.setAlpha(a); c.setRed(r); c.setBlue(b); c.setGreen(g); //c.set(a, r, g, b); return c; }
//! 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 } }