0beae765b9e7f5bd4736c3afc8993b69b309f810 jcasper Fri Nov 4 14:40:53 2022 -0700 Fix for overflowing color combinations when working with partial alpha values, refs #30227 diff --git src/inc/memgfx.h src/inc/memgfx.h index 6dc76bd..cc08d04 100644 --- src/inc/memgfx.h +++ src/inc/memgfx.h @@ -426,28 +426,28 @@ return; Color *pt = _mgPixAdr(img,x,y); /* algorithm borrowed from https://en.wikipedia.org/wiki/Alpha_compositing */ int aA = frac * 255; int rA = COLOR_32_RED(col); int gA = COLOR_32_GREEN(col); int bA = COLOR_32_BLUE(col); int aB = COLOR_32_ALPHA(*pt); int rB = COLOR_32_RED(*pt); int gB = COLOR_32_GREEN(*pt); int bB = COLOR_32_BLUE(*pt); -int aOut = aA + (aB * (255 - aA) / 255); +double aOut = aA + (aB * (255.0 - aA) / 255); int rOut, gOut, bOut; if (aOut == 0) rOut = gOut = bOut = 0; else { rOut = (rA * aA + rB * aB * (255 - aA) / 255)/aOut ; gOut = (gA * aA + gB * aB * (255 - aA) / 255)/aOut ; bOut = (bA * aA + bB * aB * (255 - aA) / 255)/aOut ; } mgPutDot(img,x,y,MAKECOLOR_32_A(rOut,gOut,bOut,aOut)); } #endif /* MEMGFX_H */