From 6de09834cfa376d3ecd70fe55f729c0c52696b37 Mon Sep 17 00:00:00 2001 From: Alexander Parshin Date: Sat, 25 Apr 2015 10:02:44 +0300 Subject: [PATCH] Optimize getImageData() Mostly for fully transparent pixels --- src/PixelArray.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/PixelArray.cc b/src/PixelArray.cc index 0a773cc..4838eee 100644 --- a/src/PixelArray.cc +++ b/src/PixelArray.cc @@ -114,10 +114,16 @@ PixelArray::PixelArray(Canvas *canvas, int sx, int sy, int width, int height): uint8_t g = *pixel >> 8; uint8_t b = *pixel; dst[bx + 3] = a; - float alpha = (float) a / 255; - dst[bx + 0] = (int)((float) r / alpha); - dst[bx + 1] = (int)((float) g / alpha); - dst[bx + 2] = (int)((float) b / alpha); + if (a != 0 && a != 255) { + float alpha = (float) a / 255; + dst[bx + 0] = (int)((float) r / alpha); + dst[bx + 1] = (int)((float) g / alpha); + dst[bx + 2] = (int)((float) b / alpha); + } else { + dst[bx + 0] = r; + dst[bx + 1] = g; + dst[bx + 2] = b; + } } dst += dstStride; }