aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/surface.cpp
diff options
context:
space:
mode:
authorSven Hesse2011-01-16 22:29:49 +0000
committerSven Hesse2011-01-16 22:29:49 +0000
commite6d04b8ad61200716e376533bb075f8891739c20 (patch)
tree686fc4cf0b7b94d211201b928d89ab9fdbe58fd7 /engines/gob/surface.cpp
parent58228919fcf0cb669684a69d42fffedf20a0a074 (diff)
downloadscummvm-rg350-e6d04b8ad61200716e376533bb075f8891739c20.tar.gz
scummvm-rg350-e6d04b8ad61200716e376533bb075f8891739c20.tar.bz2
scummvm-rg350-e6d04b8ad61200716e376533bb075f8891739c20.zip
GOB: Adding a proper shade method
svn-id: r55273
Diffstat (limited to 'engines/gob/surface.cpp')
-rw-r--r--engines/gob/surface.cpp55
1 files changed, 55 insertions, 0 deletions
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<int32>(right - left + 1, 0, _width - left);
+ uint16 height = CLIP<int32>(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<int>((shadeR + strength * r) >> 4, 0, 255);
+ g = CLIP<int>((shadeG + strength * g) >> 4, 0, 255);
+ b = CLIP<int>((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;