From ca101f9fa6afec6f8cd80e1365faca42a8cfec79 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Mon, 15 Nov 2010 13:30:06 -0800 Subject: [PATCH] Misc refactoring --- src/PixelArray.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/PixelArray.cc b/src/PixelArray.cc index 1f9ad7a..1200431 100644 --- a/src/PixelArray.cc +++ b/src/PixelArray.cc @@ -94,12 +94,17 @@ PixelArray::PixelArray(Canvas *canvas, int sx, int sy, int width, int height): int bx = x * 4; uint32_t *pixel = row + x; - // premultiplied + // ARGB uint8_t a = *pixel >> 24; + uint8_t r = *pixel >> 16; + uint8_t g = *pixel >> 8; + uint8_t b = *pixel; + + // undo premultiplication dst[bx + 3] = a; - dst[bx + 0] = (*pixel >> 16) * 255 / a; - dst[bx + 1] = (*pixel >> 8) * 255 / a; - dst[bx + 2] = *pixel * 255 / a; + dst[bx + 0] = r * 255 / a; + dst[bx + 1] = g * 255 / a; + dst[bx + 2] = b * 255 / a; } dst += s; }