Bug 389366 - "Canvas's .getImageData is returning premultiplied alpha pixels" [p=philip@zaynar.demon.co.uk (Philip Taylor) r=vlad a1.9=damons]

git-svn-id: svn://10.0.0.236/trunk@238060 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
reed%reedloden.com
2007-10-24 01:06:23 +00:00
parent f2d20b6068
commit 4211f4f51c

View File

@@ -2465,6 +2465,13 @@ nsCanvasRenderingContext2D::GetImageData()
PRUint8 g = *row++;
PRUint8 b = *row++;
#endif
// Convert to non-premultiplied color
if (a != 0) {
r = (r * 255) / a;
g = (g * 255) / a;
b = (b * 255) / a;
}
*dest++ = INT_TO_JSVAL(r);
*dest++ = INT_TO_JSVAL(g);
*dest++ = INT_TO_JSVAL(b);
@@ -2588,6 +2595,11 @@ nsCanvasRenderingContext2D::PutImageData()
else if (JSVAL_IS_DOUBLE(va)) ia = (PRUint8) (*JSVAL_TO_DOUBLE(va));
else return NS_ERROR_DOM_SYNTAX_ERR;
// Convert to premultiplied color (losslessly if the input came from getImageData)
ir = (ir*ia + 254) / 255;
ig = (ig*ia + 254) / 255;
ib = (ib*ia + 254) / 255;
#ifdef IS_LITTLE_ENDIAN
*imgPtr++ = ib;
*imgPtr++ = ig;