summaryrefslogtreecommitdiff
path: root/src/graphics.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-04 16:40:17 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-04 16:40:17 +0300
commit3181bc7610b80c360dc59a88b0408099e8ae3bc9 (patch)
tree215b6601036a4fe477e1226e2886c4d0f439ead7 /src/graphics.cpp
parent1c66b29979f2a3a9740545b4dbecdb08ea002e92 (diff)
downloadplus-3181bc7610b80c360dc59a88b0408099e8ae3bc9.tar.gz
plus-3181bc7610b80c360dc59a88b0408099e8ae3bc9.tar.bz2
plus-3181bc7610b80c360dc59a88b0408099e8ae3bc9.tar.xz
plus-3181bc7610b80c360dc59a88b0408099e8ae3bc9.zip
Possible fix for incorrect colors in fillRectangle function.
Diffstat (limited to 'src/graphics.cpp')
-rw-r--r--src/graphics.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index ec1de72e4..6dc3cede8 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -1320,21 +1320,27 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle)
mOldAlpha = mColor.a;
}
+ const SDL_PixelFormat * const format = mTarget->format;
+ const unsigned rMask = format->Rmask;
+ const unsigned gMask = format->Gmask;
+ const unsigned bMask = format->Bmask;
+ const unsigned aMask = format->Amask;
if (pixel != mOldPixel || mColor.a != mOldAlpha)
{
- const unsigned pb = (pixel & 0xff) * mColor.a;
- const unsigned pg = (pixel & 0xff00) * mColor.a;
- const unsigned pr = (pixel & 0xff0000) * mColor.a;
- const unsigned a1 = (255 - mColor.a);
+ const unsigned pb = (pixel & bMask) * mColor.a;
+ const unsigned pg = (pixel & gMask) * mColor.a;
+ const unsigned pr = (pixel & rMask) * mColor.a;
+ const unsigned a0 = (255 - mColor.a);
- const unsigned int a2 = a1 * 0xff;
- const unsigned int a3 = a1 * 0xff00;
+ const unsigned int a1 = a0 * bMask / 0xff;
+ const unsigned int a2 = a0 * gMask / 0xff;
+ const unsigned int a3 = a0 * rMask / 0xff;
for (int f = 0; f <= 0xff; f ++)
{
- cB[f] = ((pb + f * a1) >> 8) & 0xff;
- cG[f] = ((pg + f * a2) >> 8) & 0xff00;
- cR[f] = ((pr + f * a3) >> 8) & 0xff0000;
+ cB[f] = ((pb + f * a1) >> 8) & bMask;
+ cG[f] = ((pg + f * a2) >> 8) & gMask;
+ cR[f] = ((pr + f * a3) >> 8) & rMask;
}
mOldPixel = pixel;
@@ -1350,7 +1356,7 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle)
{
uint32_t *const p = p0 + x;
const uint32_t dst = *p;
- *p = cB[dst & 0xff] | cG[(dst & 0xff00) >> 8]
+ *p = cB[dst & bMask] | cG[(dst & gMask) >> 8]
| cR[(dst & 0xff0000) >> 16];
}
}