Changeset 116330 in webkit
- Timestamp:
- May 7, 2012 11:34:16 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r116328 r116330 1 2012-05-07 Noel Gordon <noel.gordon@gmail.com> 2 3 [CG] ImageBuffer::ImageDataToDataURL: Remove alpha stuffing when encoding to JPEG 4 https://bugs.webkit.org/show_bug.cgi?id=85779 5 6 Reviewed by Eric Seidel. 7 8 No change in behavior. Covered by fast/canvas/webgl/premultiplyalpha-test.html 9 10 * platform/graphics/cg/ImageBufferCG.cpp: 11 (WebCore::ImageDataToDataURL): Remove the need to stuff the alpha channel with 255. 12 Rename dataVector to premultipliedData and verify that its resize() worked. Rewrite 13 the premultiplication loop without the alpha channel = 255 part and ask the CG JPEG 14 encoder to ignore the alpha channel (kCGImageAlphaNoneSkipLast) instead. 15 1 16 2012-05-07 Dominik Röttsches <dominik.rottsches@linux.intel.com> 2 17 -
trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r116196 r116330 481 481 ASSERT(uti); 482 482 483 CGImageAlphaInfo dataAlphaInfo = kCGImageAlphaLast; 483 484 unsigned char* data = source.data()->data(); 484 Vector<uint8_t> dataVector;485 Vector<uint8_t> premultipliedData; 485 486 486 487 if (CFEqual(uti.get(), jpegUTI())) { 487 488 // JPEGs don't have an alpha channel, so we have to manually composite on top of black. 488 dataVector.resize(4 * source.width() * source.height()); 489 unsigned char *out = dataVector.data(); 490 491 for (int i = 0; i < source.width() * source.height(); i++) { 492 // Multiply color data by alpha, and set alpha to 255. 493 int alpha = data[4 * i + 3]; 489 size_t size = 4 * source.width() * source.height(); 490 if (!premultipliedData.tryReserveCapacity(size)) 491 return "data:,"; 492 493 unsigned char *buffer = premultipliedData.data(); 494 for (size_t i = 0; i < size; i += 4) { 495 unsigned alpha = data[i + 3]; 494 496 if (alpha != 255) { 495 out[4 * i + 0] = data[4 *i + 0] * alpha / 255;496 out[4 * i + 1] = data[4 *i + 1] * alpha / 255;497 out[4 * i + 2] = data[4 *i + 2] * alpha / 255;497 buffer[i + 0] = data[i + 0] * alpha / 255; 498 buffer[i + 1] = data[i + 1] * alpha / 255; 499 buffer[i + 2] = data[i + 2] * alpha / 255; 498 500 } else { 499 out[4 * i + 0] = data[4 *i + 0];500 out[4 * i + 1] = data[4 *i + 1];501 out[4 * i + 2] = data[4 *i + 2];501 buffer[i + 0] = data[i + 0]; 502 buffer[i + 1] = data[i + 1]; 503 buffer[i + 2] = data[i + 2]; 502 504 } 503 out[4 * i + 3] = 255;504 505 } 505 506 506 data = out; 507 dataAlphaInfo = kCGImageAlphaNoneSkipLast; // Ignore the alpha channel. 508 data = premultipliedData.data(); 507 509 } 508 510 … … 514 516 RetainPtr<CGImageRef> image; 515 517 image.adoptCF(CGImageCreate(source.width(), source.height(), 8, 32, 4 * source.width(), 516 deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaLast,518 deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | dataAlphaInfo, 517 519 dataProvider.get(), 0, false, kCGRenderingIntentDefault)); 518 520
Note: See TracChangeset
for help on using the changeset viewer.