From 3ef77e55c5d552a58555f3d5eb7b7079b537fff3 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sat, 24 Dec 2011 23:33:45 +0000 Subject: (svn r23670) -Feature: Add ability to adjust brightness of colour after remapping for 32bpp sprites --- src/blitter/32bpp_base.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/blitter/32bpp_base.hpp') diff --git a/src/blitter/32bpp_base.hpp b/src/blitter/32bpp_base.hpp index 1e7a22aad..686677caf 100644 --- a/src/blitter/32bpp_base.hpp +++ b/src/blitter/32bpp_base.hpp @@ -14,6 +14,7 @@ #include "base.hpp" #include "../core/bitmath_func.hpp" +#include "../core/math_func.hpp" #include "../gfx_func.h" /** Base for all 32bpp blitters. */ @@ -134,6 +135,33 @@ public: return ComposeColour(0xFF, colour, colour, colour); } + + static const int DEFAULT_BRIGHTNESS = 64; + + static inline uint32 AdjustBrightness(uint32 colour, uint8 brightness) + { + /* Shortcut for normal brightness */ + if (brightness == DEFAULT_BRIGHTNESS) return colour; + + uint16 ob = 0; + uint16 r = GB(colour, 16, 8) * brightness / DEFAULT_BRIGHTNESS; + uint16 g = GB(colour, 8, 8) * brightness / DEFAULT_BRIGHTNESS; + uint16 b = GB(colour, 0, 8) * brightness / DEFAULT_BRIGHTNESS; + + /* Sum overbright */ + if (r > 255) ob += r - 255; + if (g > 255) ob += g - 255; + if (b > 255) ob += b - 255; + + if (ob == 0) return ComposeColour(GB(colour, 24, 8), r, g, b); + + /* Reduce overbright strength */ + ob /= 2; + return ComposeColour(GB(colour, 24, 8), + r >= 255 ? 255 : min(r + ob * (255 - r) / 256, 255), + g >= 255 ? 255 : min(g + ob * (255 - g) / 256, 255), + b >= 255 ? 255 : min(b + ob * (255 - b) / 256, 255)); + } }; #endif /* BLITTER_32BPP_BASE_HPP */ -- cgit v1.2.3-54-g00ecf