From e9cbda135bbc822009ff311cad6e420fb23cff82 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sun, 25 Aug 2013 23:20:14 +0200 Subject: WINTERMUTE: Fix alpha blending with colormod This fixes numerous transparency effects in J.U.L.I.A. --- .../wintermute/graphics/transparent_surface.cpp | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 249d30f7d9..00a3db83fd 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -299,14 +299,6 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p int cg = (color >> 8) & 0xff; int cb = (color >> 0) & 0xff; - // Compensate for transparency. Since we're coming - // down to 255 alpha, we just compensate for the colors here - if (ca != 255) { - cr = cr * ca >> 8; - cg = cg * ca >> 8; - cb = cb * ca >> 8; - } - // Create an encapsulating surface for the data TransparentSurface srcImage(*this, false); // TODO: Is the data really in the screen format? @@ -443,7 +435,6 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p if (ca != 255) { a = a * ca >> 8; } - switch (a) { case 0: // Full transparency out += 4; @@ -473,27 +464,27 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p default: // alpha blending outa = 255; - outb = (o_pix >> bShiftTarget) & 0xff; - outg = (o_pix >> gShiftTarget) & 0xff; - outr = (o_pix >> rShiftTarget) & 0xff; + outb = ((o_pix >> bShiftTarget) & 0xff) * (255 - a); + outg = ((o_pix >> gShiftTarget) & 0xff) * (255 - a); + outr = ((o_pix >> rShiftTarget) & 0xff) * (255 - a); if (cb == 0) outb = 0; else if (cb != 255) - outb += ((b - outb) * a * cb) >> 16; + outb = ((outb + b * a) * cb) >> 16; else - outb += ((b - outb) * a) >> 8; + outb = (outb + b * a) >> 8; if (cg == 0) outg = 0; else if (cg != 255) - outg += ((g - outg) * a * cg) >> 16; + outg = ((outg + g * a) * cg) >> 16; else - outg += ((g - outg) * a) >> 8; + outg = (outg + g * a) >> 8; if (cr == 0) outr = 0; else if (cr != 255) - outr += ((r - outr) * a * cr) >> 16; + outr = ((outr + r * a) * cr) >> 16; else - outr += ((r - outr) * a) >> 8; + outr = (outr + r * a) >> 8; out[aIndex] = outa; out[bIndex] = outb; out[gIndex] = outg; -- cgit v1.2.3