Changeset 96000 in webkit
- Timestamp:
- Sep 26, 2011 3:07:33 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r95990 r96000 1 2011-09-26 John Bauman <jbauman@chromium.org> 2 3 Fix nonpremultiplied webgl toDataURL to jpeg 4 https://bugs.webkit.org/show_bug.cgi?id=68366 5 6 Update the premultiplyalpha-test from the WebGL conformance tests. 7 Also use the correct expected result for toDataURL.jpeg.alpha.html. 8 9 Reviewed by Kenneth Russell. 10 11 * fast/canvas/webgl/premultiplyalpha-test-expected.txt: 12 * fast/canvas/webgl/premultiplyalpha-test.html: 13 * platform/mac/canvas/philip/tests/toDataURL.jpeg.alpha-expected.txt: 14 1 15 2011-09-26 Ryosuke Niwa <rniwa@webkit.org> 2 16 -
trunk/LayoutTests/fast/canvas/webgl/premultiplyalpha-test-expected.txt
r95494 r96000 4 4 5 5 6 testing: premultipliedAlpha: true toDataURL: true6 testing: premultipliedAlpha: true imageFormat: image/png 7 7 PASS gl.getContextAttributes().premultipledAlpha is premultipledAlpha 8 PASS gl.getContextAttributes().preserveDrawingBuffer is true 8 9 PASS getError was expected value: NO_ERROR : Should be no errors from setup. 9 10 PASS getError was expected value: NO_ERROR : Should be no errors from drawing. … … 12 13 PASS should draw with 64,128,255,128 13 14 14 testing: premultipliedAlpha: true toDataURL: false15 testing: premultipliedAlpha: true imageFormat: undefined 15 16 PASS gl.getContextAttributes().premultipledAlpha is premultipledAlpha 17 PASS gl.getContextAttributes().preserveDrawingBuffer is true 16 18 PASS getError was expected value: NO_ERROR : Should be no errors from setup. 17 19 PASS getError was expected value: NO_ERROR : Should be no errors from drawing. … … 20 22 PASS should draw with 64,128,255,128 21 23 22 testing: premultipliedAlpha: false toDataURL: true24 testing: premultipliedAlpha: false imageFormat: image/png 23 25 PASS gl.getContextAttributes().premultipledAlpha is premultipledAlpha 26 PASS gl.getContextAttributes().preserveDrawingBuffer is true 24 27 PASS getError was expected value: NO_ERROR : Should be no errors from setup. 25 28 PASS getError was expected value: NO_ERROR : Should be no errors from drawing. … … 28 31 PASS should draw with 255,192,128,1 29 32 30 testing: premultipliedAlpha: false toDataURL: false33 testing: premultipliedAlpha: false imageFormat: undefined 31 34 PASS gl.getContextAttributes().premultipledAlpha is premultipledAlpha 35 PASS gl.getContextAttributes().preserveDrawingBuffer is true 32 36 PASS getError was expected value: NO_ERROR : Should be no errors from setup. 33 37 PASS getError was expected value: NO_ERROR : Should be no errors from drawing. … … 36 40 PASS should draw with 255,192,128,1 37 41 42 testing: premultipliedAlpha: false imageFormat: image/jpeg 43 PASS gl.getContextAttributes().premultipledAlpha is premultipledAlpha 44 PASS gl.getContextAttributes().preserveDrawingBuffer is true 45 PASS getError was expected value: NO_ERROR : Should be no errors from setup. 46 PASS getError was expected value: NO_ERROR : Should be no errors from drawing. 47 PASS getError was expected value: NO_ERROR : Should be no errors from creating copy. 48 PASS getError was expected value: NO_ERROR : Should be no errors from 2nd drawing. 49 PASS should draw with 128,128,128,255 50 51 testing: premultipliedAlpha: true imageFormat: image/jpeg 52 PASS gl.getContextAttributes().premultipledAlpha is premultipledAlpha 53 PASS gl.getContextAttributes().preserveDrawingBuffer is true 54 PASS getError was expected value: NO_ERROR : Should be no errors from setup. 55 PASS getError was expected value: NO_ERROR : Should be no errors from drawing. 56 PASS getError was expected value: NO_ERROR : Should be no errors from creating copy. 57 PASS getError was expected value: NO_ERROR : Should be no errors from 2nd drawing. 58 PASS should draw with 128,128,128,255 59 -
trunk/LayoutTests/fast/canvas/webgl/premultiplyalpha-test.html
r95494 r96000 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "http://www.w3.org/TR/html4/loose.dtd"> 1 <!DOCTYPE html> 3 2 <html> 4 3 <head> 4 <meta charset="utf-8"> 5 5 <title>Test the WebGL premultipledAlpha context creation flag.</title> 6 6 <link rel="stylesheet" href="../../js/resources/js-test-style.css"/> … … 22 22 expectedColor: [64, 128, 255, 128], 23 23 errorRange: 2, 24 useToDataURL: true,24 imageFormat: "image/png" 25 25 }, 26 26 // If premultipledAlpha is true then … … 31 31 expectedColor: [64, 128, 255, 128], 32 32 errorRange: 2, 33 useToDataURL: false,34 33 }, 35 34 // If premultipledAlpha is false then … … 40 39 expectedColor: [255, 192, 128, 1], 41 40 errorRange: 0, 42 useToDataURL: true,41 imageFormat: "image/png" 43 42 }, 44 43 // If premultipledAlpha is false then … … 49 48 expectedColor: [255, 192, 128, 1], 50 49 errorRange: 0, 51 useToDataURL: false, 50 }, 51 // If premultipledAlpha is false then 52 // [texture] [canvas] [dataURL] 53 // 255, 255, 255, 128 -> 255, 255, 255, 128 -> 128, 128, 128, 255 54 { creationAttributes: {premultipliedAlpha: false}, 55 sentColor: [255, 255, 255, 128], 56 expectedColor: [128, 128, 128, 255], 57 errorRange: 2, 58 imageFormat: "image/jpeg" 59 }, 60 // If premultipledAlpha is true then 61 // [texture] [canvas] [dataURL] 62 // 128, 128, 128, 128 -> 255, 255, 255, 128 -> 128, 128, 128, 255 63 { creationAttributes: {}, 64 sentColor: [128, 128, 128, 128], 65 expectedColor: [128, 128, 128, 255], 66 errorRange: 2, 67 imageFormat: "image/jpeg" 52 68 } 53 69 ]; … … 69 85 var test = tests[g_count++]; 70 86 canvas = document.createElement("canvas"); 87 // Need to preserve drawing buffer to load it in a callback 88 test.creationAttributes.preserveDrawingBuffer = true; 71 89 gl = wtu.create3DContext(canvas, test.creationAttributes); 72 90 var premultipliedAlpha = test.creationAttributes.premultipliedAlpha != false; 73 91 debug("") 74 debug("testing: premultipliedAlpha: " + premultipliedAlpha + " toDataURL: " + test.useToDataURL);92 debug("testing: premultipliedAlpha: " + premultipliedAlpha + " imageFormat: " + test.imageFormat); 75 93 76 94 shouldBe('gl.getContextAttributes().premultipledAlpha', 'premultipledAlpha'); 95 shouldBeTrue('gl.getContextAttributes().preserveDrawingBuffer'); 77 96 78 97 var program = wtu.setupTexturedQuad(gl); … … 97 116 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, false); 98 117 gl.bindTexture(gl.TEXTURE_2D, pngTex); 99 if (test. useToDataURL) {118 if (test.imageFormat) { 100 119 // create texture from image 101 120 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this); … … 118 137 } 119 138 120 if (test. useToDataURL) {139 if (test.imageFormat) { 121 140 // Load canvas into string using toDataURL 122 var png = canvas.toDataURL(); 123 // Load string into the texture 124 var input = document.createElement("img"); 125 input.onload = loadTexture; 126 input.src = png; 141 var imageUrl = canvas.toDataURL(test.imageFormat); 142 if (test.imageFormat != "image/png" && 143 (imageUrl.indexOf("data:image/png,") == 0 || 144 imageUrl.indexOf("data:image/png;") == 0)) { 145 debug("Image format " + test.imageFormat + " not supported; skipping"); 146 setTimeout(doNextTest, 0); 147 } else { 148 // Load string into the texture 149 var input = document.createElement("img"); 150 input.onload = loadTexture; 151 input.src = imageUrl; 152 } 127 153 } else { 128 154 // Load canvas into the texture asynchronously (to prevent unbounded stack consumption) … … 139 165 </script> 140 166 141 <script>142 </script>143 144 167 </body> 145 168 </html> -
trunk/LayoutTests/platform/mac/canvas/philip/tests/toDataURL.jpeg.alpha-expected.txt
r84509 r96000 1 Failed assertion: got pixel [193,255,192,255] at (50,25), expected [63,127,63,255] +/- 8 1 Passed -
trunk/Source/WebCore/ChangeLog
r95998 r96000 1 2011-09-26 John Bauman <jbauman@chromium.org> 2 3 Fix nonpremultiplied webgl toDataURL to jpeg 4 https://bugs.webkit.org/show_bug.cgi?id=68366 5 6 The canvas spec says that toDataURL to formats without an alpha must 7 be "composited onto a solid black background using the source-over 8 operator." Do that. 9 10 Reviewed by Kenneth Russell. 11 12 * platform/graphics/cg/ImageBufferCG.cpp: 13 (WebCore::CGImageToDataURL): 14 (WebCore::ImageBuffer::toDataURL): 15 (WebCore::ImageDataToDataURL): 16 * platform/image-encoders/skia/JPEGImageEncoder.cpp: 17 (WebCore::RGBAtoRGB): 18 1 19 2011-09-26 Raphael Kubo da Costa <kubo@profusion.mobi> 2 20 -
trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r95174 r96000 344 344 } 345 345 346 // Setting kCGImageDestinationBackgroundColor to black in imageProperties would allow saving some math in the 347 // calling functions, but it doesn't seem to work. 348 346 349 CGImageDestinationAddImage(destination.get(), image, imageProperties.get()); 347 350 CGImageDestinationFinalize(destination.get()); … … 356 359 { 357 360 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 358 359 RetainPtr<CGImageRef> image(AdoptCF, copyNativeImage(CopyBackingStore)); 361 RetainPtr<CGImageRef> image; 362 RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType); 363 ASSERT(uti); 364 365 if (CFEqual(uti.get(), jpegUTI())) { 366 // JPEGs don't have an alpha channel, so we have to manually composite on top of black. 367 RefPtr<ByteArray> arr = getPremultipliedImageData(IntRect(IntPoint(0, 0), m_size)); 368 369 unsigned char *data = arr->data(); 370 for (int i = 0; i < width() * height(); i++) 371 data[i * 4 + 3] = 255; // The image is already premultiplied, so we just need to make it opaque. 372 373 RetainPtr<CGDataProviderRef> dataProvider; 374 375 dataProvider.adoptCF(CGDataProviderCreateWithData(0, data, 376 4 * width() * height(), 0)); 377 378 if (!dataProvider) 379 return "data:,"; 380 381 image.adoptCF(CGImageCreate(width(), height(), 8, 32, 4 * width(), 382 CGColorSpaceCreateDeviceRGB(), kCGBitmapByteOrderDefault | kCGImageAlphaLast, 383 dataProvider.get(), 0, false, kCGRenderingIntentDefault)); 384 } else 385 image.adoptCF(copyNativeImage(CopyBackingStore)); 360 386 361 387 if (!image) … … 371 397 RetainPtr<CGImageRef> image; 372 398 RetainPtr<CGDataProviderRef> dataProvider; 399 400 unsigned char* data = source.data()->data()->data(); 401 RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType); 402 ASSERT(uti); 403 Vector<uint8_t> dataVector; 404 if (CFEqual(uti.get(), jpegUTI())) { 405 // JPEGs don't have an alpha channel, so we have to manually composite on top of black. 406 dataVector.resize(4 * source.width() * source.height()); 407 unsigned char *out = dataVector.data(); 408 409 for (int i = 0; i < source.width() * source.height(); i++) { 410 // Multiply color data by alpha, and set alpha to 255. 411 int alpha = data[4 * i + 3]; 412 if (alpha != 255) { 413 out[4 * i + 0] = data[4 * i + 0] * alpha / 255; 414 out[4 * i + 1] = data[4 * i + 1] * alpha / 255; 415 out[4 * i + 2] = data[4 * i + 2] * alpha / 255; 416 } else { 417 out[4 * i + 0] = data[4 * i + 0]; 418 out[4 * i + 1] = data[4 * i + 1]; 419 out[4 * i + 2] = data[4 * i + 2]; 420 } 421 out[4 * i + 3] = 255; 422 } 423 424 data = out; 425 } 373 426 374 dataProvider.adoptCF(CGDataProviderCreateWithData(0, source.data()->data()->data(),427 dataProvider.adoptCF(CGDataProviderCreateWithData(0, data, 375 428 4 * source.width() * source.height(), 0)); 376 429 -
trunk/Source/WebCore/platform/image-encoders/skia/JPEGImageEncoder.cpp
r95901 r96000 93 93 { 94 94 for (; pixelCount-- > 0; pixels += 4) { 95 *output++ = pixels[0]; 96 *output++ = pixels[1]; 97 *output++ = pixels[2]; 95 // Do source-over composition on black. 96 unsigned char alpha = pixels[3]; 97 if (alpha != 255) { 98 *output++ = SkMulDiv255Round(pixels[0], alpha); 99 *output++ = SkMulDiv255Round(pixels[1], alpha); 100 *output++ = SkMulDiv255Round(pixels[2], alpha); 101 } else { 102 *output++ = pixels[0]; 103 *output++ = pixels[1]; 104 *output++ = pixels[2]; 105 } 98 106 } 99 107 }
Note: See TracChangeset
for help on using the changeset viewer.