summaryrefslogtreecommitdiff
path: root/src/blitter/32bpp_base.hpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2011-12-24 23:33:45 +0000
committerpeter1138 <peter1138@openttd.org>2011-12-24 23:33:45 +0000
commit3ef77e55c5d552a58555f3d5eb7b7079b537fff3 (patch)
tree4a5d1131661b9fb4e94bf9409f089dae84f65f6e /src/blitter/32bpp_base.hpp
parentdc497258d68ebcd19f4e2512e7255aca344bfff0 (diff)
downloadopenttd-3ef77e55c5d552a58555f3d5eb7b7079b537fff3.tar.xz
(svn r23670) -Feature: Add ability to adjust brightness of colour after remapping for 32bpp sprites
Diffstat (limited to 'src/blitter/32bpp_base.hpp')
-rw-r--r--src/blitter/32bpp_base.hpp28
1 files changed, 28 insertions, 0 deletions
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 */