From 74f2672c0d86da0ce526a454a8c818a4899eef10 Mon Sep 17 00:00:00 2001 From: MrCdK Date: Tue, 7 Oct 2014 23:46:01 +0200 Subject: [PATCH] Fix colorTransform also --- lime/graphics/utils/ImageDataUtil.hx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index 29495ca2e..3e8a2cc09 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -51,10 +51,12 @@ class ImageDataUtil { var stride = image.buffer.width * 4; var offset:Int; - var rowStart = Std.int (rect.y + image.offsetY); - var rowEnd = Std.int (rect.height + image.offsetY); - var columnStart = Std.int (rect.x + image.offsetX); - var columnEnd = Std.int (rect.width + image.offsetX); + var rowStart = Std.int (rect.top + image.offsetY); + var rowEnd = Std.int (rect.bottom + image.offsetY); + var columnStart = Std.int (rect.left + image.offsetX); + var columnEnd = Std.int (rect.right + image.offsetX); + + var r, g, b, a, ex = 0; for (row in rowStart...rowEnd) { @@ -62,10 +64,18 @@ class ImageDataUtil { offset = (row * stride) + (column * 4); - data[offset] = Std.int ((data[offset] * colorMatrix.redMultiplier) + colorMatrix.redOffset); - data[offset + 1] = Std.int ((data[offset + 1] * colorMatrix.greenMultiplier) + colorMatrix.greenOffset); - data[offset + 2] = Std.int ((data[offset + 2] * colorMatrix.blueMultiplier) + colorMatrix.blueOffset); - data[offset + 3] = Std.int ((data[offset + 3] * colorMatrix.alphaMultiplier) + colorMatrix.alphaOffset); + a = Std.int ((data[offset + 3] * colorMatrix.alphaMultiplier) + colorMatrix.alphaOffset); + ex = a > 0xFF ? a - 0xFF : 0; + b = Std.int ((data[offset + 2] * colorMatrix.blueMultiplier) + colorMatrix.blueOffset + ex); + ex = b > 0xFF ? b - 0xFF : 0; + g = Std.int ((data[offset + 1] * colorMatrix.greenMultiplier) + colorMatrix.greenOffset + ex); + ex = g > 0xFF ? g - 0xFF : 0; + r = Std.int ((data[offset] * colorMatrix.redMultiplier) + colorMatrix.redOffset + ex); + + data[offset] = r > 0xFF ? 0xFF : r; + data[offset + 1] = g > 0xFF ? 0xFF : g; + data[offset + 2] = b > 0xFF ? 0xFF : b; + data[offset + 3] = a > 0xFF ? 0xFF : a; }