[Scummvm-cvs-logs] scummvm master -> dd84867997b515e2e95b383b68ebc27b9cc45b42
zeldin
marcus at mc.pp.se
Fri Jan 10 20:15:11 CET 2014
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
4b81b1299d GRAPHICS: Fix dest alpha formula in blendPixelPtr
dd84867997 ANDROID: Set correct blending function
Commit: 4b81b1299da2d81bf457b245b1f8cb3d21c8172f
https://github.com/scummvm/scummvm/commit/4b81b1299da2d81bf457b245b1f8cb3d21c8172f
Author: Marcus Comstedt (marcus at mc.pp.se)
Date: 2014-01-10T11:04:10-08:00
Commit Message:
GRAPHICS: Fix dest alpha formula in blendPixelPtr
The original alpha computation formula had a problem: If something was
drawn on top of a pixel that was already fully opaque, there would be
an overflow in the computed alpha, and the destination alpha would be
truncated to 0 (fully transparent).
In commit 264ba4a9 this formula was replaced with another one, which
did not have overflows but also was not correct.
This commits introduces a new formula, where the rounding errors have
been turned in another direction; drawing a fully opaque pixel on top
of a transparent one would result in a pixel which is almost, but not
fully, opaque. However, this is no problem in practice, since drawing
fully opaque pixels can be achieved with much less code as a special
case, so add that (also improves rendering speed).
Changed paths:
graphics/VectorRendererSpec.cpp
diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp
index de249e8..a3ec66a 100644
--- a/graphics/VectorRendererSpec.cpp
+++ b/graphics/VectorRendererSpec.cpp
@@ -620,7 +620,10 @@ applyScreenShading(GUI::ThemeEngine::ShadingStyle shadingStyle) {
template<typename PixelType>
inline void VectorRendererSpec<PixelType>::
blendPixelPtr(PixelType *ptr, PixelType color, uint8 alpha) {
- if (sizeof(PixelType) == 4) {
+ if (alpha == 0xff) {
+ // fully opaque pixel, don't blend
+ *ptr = color | _alphaMask;
+ } else if (sizeof(PixelType) == 4) {
const byte sR = (color & _redMask) >> _format.rShift;
const byte sG = (color & _greenMask) >> _format.gShift;
const byte sB = (color & _blueMask) >> _format.bShift;
@@ -628,15 +631,17 @@ blendPixelPtr(PixelType *ptr, PixelType color, uint8 alpha) {
byte dR = (*ptr & _redMask) >> _format.rShift;
byte dG = (*ptr & _greenMask) >> _format.gShift;
byte dB = (*ptr & _blueMask) >> _format.bShift;
+ byte dA = (*ptr & _alphaMask) >> _format.aShift;
dR += ((sR - dR) * alpha) >> 8;
dG += ((sG - dG) * alpha) >> 8;
dB += ((sB - dB) * alpha) >> 8;
+ dA += ((0xff - dA) * alpha) >> 8;
*ptr = ((dR << _format.rShift) & _redMask)
| ((dG << _format.gShift) & _greenMask)
| ((dB << _format.bShift) & _blueMask)
- | (*ptr & _alphaMask);
+ | ((dA << _format.aShift) & _alphaMask);
} else if (sizeof(PixelType) == 2) {
int idst = *ptr;
int isrc = color;
@@ -651,7 +656,9 @@ blendPixelPtr(PixelType *ptr, PixelType color, uint8 alpha) {
(_blueMask & ((idst & _blueMask) +
((int)(((int)(isrc & _blueMask) -
(int)(idst & _blueMask)) * alpha) >> 8))) |
- (idst & _alphaMask));
+ (_alphaMask & ((idst & _alphaMask) +
+ ((int)(((int)(_alphaMask) -
+ (int)(idst & _alphaMask)) * alpha) >> 8))));
} else {
error("Unsupported BPP format: %u", (uint)sizeof(PixelType));
}
Commit: dd84867997b515e2e95b383b68ebc27b9cc45b42
https://github.com/scummvm/scummvm/commit/dd84867997b515e2e95b383b68ebc27b9cc45b42
Author: Marcus Comstedt (marcus at mc.pp.se)
Date: 2014-01-10T11:05:32-08:00
Commit Message:
ANDROID: Set correct blending function
Overlays with alpha channel in ScummVM use pre-multiplied alpha.
Thus, is it necessary to set the source blend function to ONE, not
SOURCE_ALPHA.
While there is no firm decision on the texture format to be used to
cursors, make sure to set the key color to R=G=B=A=0.0, so that it
can be used with either pre-multiplied or non-pre-multiplied blending.
Changed paths:
backends/platform/android/gfx.cpp
diff --git a/backends/platform/android/gfx.cpp b/backends/platform/android/gfx.cpp
index 882dcff..0ce95a3 100644
--- a/backends/platform/android/gfx.cpp
+++ b/backends/platform/android/gfx.cpp
@@ -233,7 +233,7 @@ void OSystem_Android::initViewport() {
GLCALL(glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST));
GLCALL(glEnable(GL_BLEND));
- GLCALL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
+ GLCALL(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
GLCALL(glEnableClientState(GL_VERTEX_ARRAY));
GLCALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
@@ -726,7 +726,7 @@ void OSystem_Android::setMouseCursor(const void *buf, uint w, uint h,
_mouse_keycolor = keycolor;
p = _mouse_texture_palette->palette() + _mouse_keycolor * 2;
- WRITE_UINT16(p, READ_UINT16(p) & ~1);
+ WRITE_UINT16(p, 0);
}
if (w == 0 || h == 0)
@@ -779,7 +779,7 @@ void OSystem_Android::setCursorPaletteInternal(const byte *colors,
WRITE_UINT16(p, pf.RGBToColor(colors[0], colors[1], colors[2]));
p = _mouse_texture_palette->palette() + _mouse_keycolor * 2;
- WRITE_UINT16(p, READ_UINT16(p) & ~1);
+ WRITE_UINT16(p, 0);
}
void OSystem_Android::setCursorPalette(const byte *colors,
@@ -821,7 +821,7 @@ void OSystem_Android::disableCursorPalette() {
}
byte *p = _mouse_texture_palette->palette() + _mouse_keycolor * 2;
- WRITE_UINT16(p, READ_UINT16(p) & ~1);
+ WRITE_UINT16(p, 0);
}
}
More information about the Scummvm-git-logs
mailing list