[Scummvm-git-logs] scummvm master -> 286cccdafeaf1c863df04b6c3f07c32ac84cdcd8
criezy
criezy at scummvm.org
Sun Feb 21 15:30:34 UTC 2021
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:
85854120fa GRAPHICS: Improve TTF rendering on transparent surfaces.
286cccdafe GRAPHICS: Update TTF render color blending to work with any surface alpha level
Commit: 85854120fa5030ddb7a6bf4b505393e8f90cf659
https://github.com/scummvm/scummvm/commit/85854120fa5030ddb7a6bf4b505393e8f90cf659
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2021-02-21T15:30:30Z
Commit Message:
GRAPHICS: Improve TTF rendering on transparent surfaces.
Update color blending to match blending found in ManagedSurface. TTF rendering assumed the alpha channel of the surface was completely opaque. ULTIMA8 TTF rendering attempts to use a transparent surface and became near-illegible for text on scrolls. This change will affect TTF rendering on surfaces that are not already painted.
Changed paths:
graphics/fonts/ttf.cpp
diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp
index fd48aee03c..eb43414f43 100644
--- a/graphics/fonts/ttf.cpp
+++ b/graphics/fonts/ttf.cpp
@@ -583,7 +583,7 @@ namespace {
template<typename ColorType>
static void renderGlyph(uint8 *dstPos, const int dstPitch, const uint8 *srcPos, const int srcPitch, const int w, const int h, ColorType color, const PixelFormat &dstFormat) {
- uint8 sR, sG, sB;
+ uint8 sA, sR, sG, sB;
dstFormat.colorToRGB(color, sR, sG, sB);
for (int y = 0; y < h; ++y) {
@@ -594,16 +594,25 @@ static void renderGlyph(uint8 *dstPos, const int dstPitch, const uint8 *srcPos,
if (*src == 255) {
*rDst = color;
} else if (*src) {
- const uint8 a = *src;
+ sA = *src;
- uint8 dR, dG, dB;
- dstFormat.colorToRGB(*rDst, dR, dG, dB);
+ uint8 dA, dR, dG, dB;
+ dstFormat.colorToARGB(*rDst, dA, dR, dG, dB);
- dR = ((255 - a) * dR + a * sR) / 255;
- dG = ((255 - a) * dG + a * sG) / 255;
- dB = ((255 - a) * dB + a * sB) / 255;
+ if (dA == 0) {
+ *rDst = dstFormat.ARGBToColor(sA, sR, sG, sB);
+ } else {
+ double alpha = (double)sA / 255.0;
+ dR = static_cast<uint8>((sR * alpha) + (dR * (1.0 - alpha)));
+ dG = static_cast<uint8>((sG * alpha) + (dG * (1.0 - alpha)));
+ dB = static_cast<uint8>((sB * alpha) + (dB * (1.0 - alpha)));
- *rDst = dstFormat.RGBToColor(dR, dG, dB);
+ if (sA > dA) {
+ dA = static_cast<uint8>((sA * alpha) + (dA * (1.0 - alpha)));
+ }
+
+ *rDst = dstFormat.ARGBToColor(dA, dR, dG, dB);
+ }
}
++rDst;
Commit: 286cccdafeaf1c863df04b6c3f07c32ac84cdcd8
https://github.com/scummvm/scummvm/commit/286cccdafeaf1c863df04b6c3f07c32ac84cdcd8
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2021-02-21T15:30:30Z
Commit Message:
GRAPHICS: Update TTF render color blending to work with any surface alpha level
Changed paths:
graphics/fonts/ttf.cpp
diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp
index eb43414f43..bf7cd661b7 100644
--- a/graphics/fonts/ttf.cpp
+++ b/graphics/fonts/ttf.cpp
@@ -599,20 +599,16 @@ static void renderGlyph(uint8 *dstPos, const int dstPitch, const uint8 *srcPos,
uint8 dA, dR, dG, dB;
dstFormat.colorToARGB(*rDst, dA, dR, dG, dB);
- if (dA == 0) {
- *rDst = dstFormat.ARGBToColor(sA, sR, sG, sB);
- } else {
- double alpha = (double)sA / 255.0;
- dR = static_cast<uint8>((sR * alpha) + (dR * (1.0 - alpha)));
- dG = static_cast<uint8>((sG * alpha) + (dG * (1.0 - alpha)));
- dB = static_cast<uint8>((sB * alpha) + (dB * (1.0 - alpha)));
-
- if (sA > dA) {
- dA = static_cast<uint8>((sA * alpha) + (dA * (1.0 - alpha)));
- }
-
- *rDst = dstFormat.ARGBToColor(dA, dR, dG, dB);
- }
+ double sAn = (double)sA / 255.0;
+ double dAn = (double)dA / 255.0;
+ double oAn = sAn + dAn * (1.0 - sAn);
+
+ dR = static_cast<uint8>(sR * sAn + dR * dAn * (1.0 - sAn) / oAn);
+ dG = static_cast<uint8>(sG * sAn + dG * dAn * (1.0 - sAn) / oAn);
+ dB = static_cast<uint8>(sB * sAn + dB * dAn * (1.0 - sAn) / oAn);
+ dA = static_cast<uint8>(oAn * 255.0);
+
+ *rDst = dstFormat.ARGBToColor(dA, dR, dG, dB);
}
++rDst;
More information about the Scummvm-git-logs
mailing list