Commit 350652b5 authored by oliver@apple.com's avatar oliver@apple.com

Bug 17620: getImageData lies

http://bugs.webkit.org/show_bug.cgi?id=17620

Reviewed by Mark Rowe

Correct logic to actually iterate over the source row


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30711 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7babd229
2008-03-03 Oliver Hunt <oliver@apple.com>
Reviewed by Mark Rowe.
Add check to make sure we return all the data in a row.
* fast/canvas/canvas-getImageData-expected.txt:
* fast/canvas/canvas-getImageData.html:
2008-03-03 Oliver Hunt <oliver@apple.com>
Reviewed by Mark Rowe.
......@@ -25,6 +25,7 @@ PASS: pixel at (88,0) was [0,234,0,255]
PASS: pixel at (92,0) was [0,244,0,255]
PASS: pixel at (96,0) was [0,255,0,255]
PASS: pixel at (5,5) was [64,128,191,255]
PASS: Correctly retrieved every pixel in a row
PASS: Correct data for content outside canvas bounds
PASS: pixel at (50,50) was [0,0,0,0]
PASS: pixel at (50,54) was [0,0,0,1]
......
......@@ -59,6 +59,25 @@ context.setFillColor(0.25, 0.5, 0.75, 1);
context.fillRect(5,5,1,1);
pixelShouldBe(context, 5, 5, [Math.round(0.25*255), Math.round(0.5*255), Math.round(0.75*255), 255]);
// Make sure we return correct values for the row
for (var i = 0; i < 100; i++) {
context.fillStyle = "rgba("+[0, i, 0, 1]+")";
context.fillRect(i, 10, 1, 1);
}
var rowImageData = context.getImageData(0, 10, 100, 1).data;
var rowCheck = true;
for (var i = 0; i < 100; i++) {
if (rowImageData[i * 4 + 1] != i) {
rowCheck = false;
break;
}
}
if (!rowCheck)
log("FAIL: Did not correctly retrieve every pixel in a row");
else
log("PASS: Correctly retrieved every pixel in a row");
// Check that we return transparent black for regions outside the canvas proper
context.fillStyle = "rgba(255,255,255,255)";
context.fillRect(198, 5, 4, 1); // final 2 pixels horizontally should be clipped
......
2008-03-03 Oliver Hunt <oliver@apple.com>
Reviewed by Mark Rowe.
Bug 17620: getImageData lies
http://bugs.webkit.org/show_bug.cgi?id=17620
Correct logic to actually iterate over the source row
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::getImageData):
2008-03-03 Oliver Hunt <oliver@apple.com>
Reviewed by Mark Rowe.
......@@ -142,10 +142,11 @@ PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const
unsigned char* destRows = data + desty * destBytesPerRow + destx * 4;
for (int y = 0; y < numRows; ++y) {
for (int x = 0; x < numColumns; x++) {
if (unsigned char alpha = srcRows[3]) {
destRows[0] = (srcRows[0] * 255) / alpha;
destRows[1] = (srcRows[1] * 255) / alpha;
destRows[2] = (srcRows[2] * 255) / alpha;
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;
} else {
reinterpret_cast<uint32_t*>(destRows)[0] = reinterpret_cast<uint32_t*>(srcRows)[0];
......
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