diff --git a/src/PixelArray.cc b/src/PixelArray.cc index 0a773cc..f39b337 100644 --- a/src/PixelArray.cc +++ b/src/PixelArray.cc @@ -114,10 +114,19 @@ 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); + + // Performance optimization: fully transparent/opaque pixels + // can be processed more efficiently + 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; }