Browse Source

Merge pull request #549 from aparshin/speedup-getimage

Optimize getImageData()
v1.x
Juriy Zaytsev 10 years ago
parent
commit
70162e6bc2
  1. 17
      src/PixelArray.cc

17
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;
}

Loading…
Cancel
Save