From e6d04b8ad61200716e376533bb075f8891739c20 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Sun, 16 Jan 2011 22:29:49 +0000 Subject: GOB: Adding a proper shade method svn-id: r55273 --- engines/gob/surface.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'engines/gob/surface.cpp') diff --git a/engines/gob/surface.cpp b/engines/gob/surface.cpp index fa2d9cf9ab..673d8b3a19 100644 --- a/engines/gob/surface.cpp +++ b/engines/gob/surface.cpp @@ -489,6 +489,61 @@ void Surface::clear() { fill(0); } +void Surface::shadeRect(uint16 left, uint16 top, uint16 right, uint16 bottom, + uint32 color, uint8 strength) { + + if (_bpp == 1) { + // We can't properly shade in paletted mode, fill the rect instead + fillRect(left, top, right, bottom, color); + return; + } + + // Just in case those are swapped + if (left > right) + SWAP(left, right); + if (top > bottom) + SWAP(top, bottom); + + if ((left >= _width) || (top >= _height)) + // Nothing to do + return; + + // Area to actually shade + uint16 width = CLIP(right - left + 1, 0, _width - left); + uint16 height = CLIP(bottom - top + 1, 0, _height - top); + + if ((width == 0) || (height == 0)) + // Nothing to do + return; + + Graphics::PixelFormat pixelFormat = g_system->getScreenFormat(); + + uint8 cR, cG, cB; + pixelFormat.colorToRGB(color, cR, cG, cB); + + int shadeR = cR * (16 - strength); + int shadeG = cG * (16 - strength); + int shadeB = cB * (16 - strength); + + Pixel p = get(left, top); + while (height-- > 0) { + for (uint16 i = 0; i < width; i++, ++p) { + uint8 r, g, b; + + pixelFormat.colorToRGB(p.get(), r, g, b); + + r = CLIP((shadeR + strength * r) >> 4, 0, 255); + g = CLIP((shadeG + strength * g) >> 4, 0, 255); + b = CLIP((shadeB + strength * b) >> 4, 0, 255); + + p.set(pixelFormat.RGBToColor(r, g, b)); + } + + p += _width - width; + } + +} + void Surface::putPixel(uint16 x, uint16 y, uint32 color) { if ((x >= _width) || (y >= _height)) return; -- cgit v1.2.3