Commit 3cb88e1a authored by hyatt@apple.com's avatar hyatt@apple.com

WebCore:

2008-05-05  David Hyatt  <hyatt@apple.com>

        Fix for https://bugs.webkit.org/show_bug.cgi?id=18821.  Fix some bugs in both get/PutImageData of <canvas>.

        Reviewed by Eric

        New tests added in fast/canvas/

        * platform/graphics/cg/ImageBufferCG.cpp:
        (WebCore::ImageBuffer::getImageData):
        (WebCore::ImageBuffer::putImageData):

LayoutTests:

2008-05-05  David Hyatt  <hyatt@apple.com>

        Fix for https://bugs.webkit.org/show_bug.cgi?id=18821, putImageData incorrect when data has alpha.

        Reviewed by Eric

        * fast/canvas/canvas-alphaImageData-behavior-expected.txt: Added.
        * fast/canvas/canvas-alphaImageData-behavior.html: Added.
        * fast/canvas/canvas-alphaImageData-behavior.js: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@32878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0fa4ee57
2008-05-05 David Hyatt <hyatt@apple.com>
Fix for https://bugs.webkit.org/show_bug.cgi?id=18821, putImageData incorrect when data has alpha.
Reviewed by Eric
* fast/canvas/canvas-alphaImageData-behavior-expected.txt: Added.
* fast/canvas/canvas-alphaImageData-behavior.html: Added.
* fast/canvas/canvas-alphaImageData-behavior.js: Added.
2008-05-05 Dan Bernstein <mitz@apple.com>
Rubber-stamped by Adam Roben.
Series of tests to ensure correct behaviour of getImageData and putImageData when alpha is involved
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS imgdata[4] is 0
PASS imgdata[5] is 255
PASS imgdata[6] is 0
PASS imgdata[7] is 253
PASS imgdata[4] is 0
PASS imgdata[5] is 255
PASS imgdata[6] is 0
PASS imgdata[7] is 253
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<canvas id="canvas" width="200" height="200"></canvas>
<script src="canvas-alphaImageData-behavior.js"></script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
description("Series of tests to ensure correct behaviour of getImageData and putImageData when alpha is involved");
var ctx = document.getElementById('canvas').getContext('2d');
ctx.fillStyle = 'rgba(255, 0, 0, 0.01)';
ctx.fillRect(0, 0, 1, 200);
ctx.fillStyle = 'rgba(0, 255, 0, 0.995)';
ctx.fillRect(1, 0, 199, 200);
var imageData = ctx.getImageData(0, 0, 200, 200);
var imgdata = imageData.data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "255");
shouldBe("imgdata[6]", "0");
shouldBe("imgdata[7]", "253");
ctx.putImageData(imageData, 0, 0);
imgdata = ctx.getImageData(0, 0, 200, 200).data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "255");
shouldBe("imgdata[6]", "0");
shouldBe("imgdata[7]", "253");
var successfullyParsed = true;
2008-05-05 David Hyatt <hyatt@apple.com>
Fix for https://bugs.webkit.org/show_bug.cgi?id=18821. Fix some bugs in both get/PutImageData of <canvas>.
Reviewed by Eric
New tests added in fast/canvas/
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::getImageData):
(WebCore::ImageBuffer::putImageData):
2008-05-05 Dan Bernstein <mitz@apple.com>
Reviewed by Dave Hyatt.
......@@ -149,16 +149,16 @@ PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const
for (int x = 0; x < numColumns; x++) {
int basex = x * 4;
if (unsigned char alpha = srcRows[basex + 3]) {
destRows[0] = (srcRows[basex] * 255) / alpha;
destRows[1] = (srcRows[basex + 1] * 255) / alpha;
destRows[2] = (srcRows[basex + 2] * 255) / alpha;
destRows[3] = alpha;
destRows[basex] = (srcRows[basex] * 255) / alpha;
destRows[basex + 1] = (srcRows[basex + 1] * 255) / alpha;
destRows[basex + 2] = (srcRows[basex + 2] * 255) / alpha;
destRows[basex + 3] = alpha;
} else {
reinterpret_cast<uint32_t*>(destRows)[0] = reinterpret_cast<uint32_t*>(srcRows)[0];
reinterpret_cast<uint32_t*>(destRows + basex)[0] = reinterpret_cast<uint32_t*>(srcRows + basex)[0];
}
destRows += 4;
}
srcRows += srcBytesPerRow;
destRows += destBytesPerRow;
}
return result;
}
......@@ -198,14 +198,15 @@ void ImageBuffer::putImageData(ImageData* source, const IntRect& sourceRect, con
unsigned char* destRows = reinterpret_cast<unsigned char*>(m_data) + desty * destBytesPerRow + destx * 4;
for (int y = 0; y < numRows; ++y) {
for (int x = 0; x < numColumns; x++) {
unsigned char alpha = srcRows[x * 4 + 3];
int basex = x * 4;
unsigned char alpha = srcRows[basex + 3];
if (alpha != 255) {
destRows[x * 4 + 0] = (srcRows[0] * alpha) / 255;
destRows[x * 4 + 1] = (srcRows[1] * alpha) / 255;
destRows[x * 4 + 2] = (srcRows[2] * alpha) / 255;
destRows[x * 4 + 3] = alpha;
destRows[basex] = (srcRows[basex] * alpha + 254) / 255;
destRows[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255;
destRows[basex + 2] = (srcRows[basex + 2] * alpha + 254) / 255;
destRows[basex + 3] = alpha;
} else {
reinterpret_cast<uint32_t*>(destRows + x * 4)[0] = reinterpret_cast<uint32_t*>(srcRows + x * 4)[0];
reinterpret_cast<uint32_t*>(destRows + basex)[0] = reinterpret_cast<uint32_t*>(srcRows + basex)[0];
}
}
destRows += destBytesPerRow;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment