Changeset 116196 in webkit
- Timestamp:
- May 4, 2012 5:49:42 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r116195 r116196 1 2012-05-04 Noel Gordon <noel.gordon@gmail.com> 2 3 [CG] Minor refactor of ImageBuffer::CGImageToDataURL and its callers 4 https://bugs.webkit.org/show_bug.cgi?id=85280 5 6 Reviewed by Kenneth Russell. 7 8 This patch means to simplify the diff of an upcoming patch. Refactoring 9 here in preparation for that patch. 10 11 No new tests. No behavioral change. Covered by canvas 2d and 3d tests: 12 canvas/philip/tests/*toDataURL*.html 13 fast/canvas/webgl/premultiplyalpha-test.html 14 15 * platform/graphics/cg/ImageBufferCG.cpp: 16 (WebCore::CGImageToDataURL): Move the invalid image (!image) test here. 17 The comments are about JPEG images; say that. Rename out to base64Data. 18 (WebCore::ImageBuffer::toDataURL): Remove the !image test. 19 (WebCore::ImageDataToDataURL): Move and define variables where used and 20 make the code flow read similarly to toDataURL. Remove the !image test. 21 1 22 2012-05-04 Shawn Singh <shawnsingh@chromium.org> 2 23 -
trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r114992 r116196 402 402 static String CGImageToDataURL(CGImageRef image, const String& mimeType, const double* quality) 403 403 { 404 if (!image) 405 return "data:,"; 406 404 407 RetainPtr<CFMutableDataRef> data(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0)); 405 408 if (!data) … … 415 418 RetainPtr<CFDictionaryRef> imageProperties = 0; 416 419 if (CFEqual(uti.get(), jpegUTI()) && quality && *quality >= 0.0 && *quality <= 1.0) { 417 // Apply the compression quality to the image destination.420 // Apply the compression quality to the JPEG image destination. 418 421 RetainPtr<CFNumberRef> compressionQuality(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, quality)); 419 422 const void* key = kCGImageDestinationLossyCompressionQuality; … … 422 425 } 423 426 424 // Setting kCGImageDestinationBackgroundColor to black in imageProperties would allow saving some math in the425 // calling functions, but it doesn't seem to work.427 // Setting kCGImageDestinationBackgroundColor to black for JPEG images in imageProperties would save some math 428 // in the calling functions, but it doesn't seem to work. 426 429 427 430 CGImageDestinationAddImage(destination.get(), image, imageProperties.get()); 428 431 CGImageDestinationFinalize(destination.get()); 429 432 430 Vector<char> out;431 base64Encode(reinterpret_cast<const char*>(CFDataGetBytePtr(data.get())), CFDataGetLength(data.get()), out);432 433 return "data:" + mimeType + ";base64," + out;433 Vector<char> base64Data; 434 base64Encode(reinterpret_cast<const char*>(CFDataGetBytePtr(data.get())), CFDataGetLength(data.get()), base64Data); 435 436 return "data:" + mimeType + ";base64," + base64Data; 434 437 } 435 438 … … 468 471 } 469 472 470 if (!image)471 return "data:,";472 473 473 return CGImageToDataURL(image.get(), mimeType, quality); 474 474 } … … 477 477 { 478 478 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 479 480 RetainPtr<CGImageRef> image; 481 RetainPtr<CGDataProviderRef> dataProvider; 482 483 unsigned char* data = source.data()->data(); 479 484 480 RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType); 485 481 ASSERT(uti); 482 483 unsigned char* data = source.data()->data(); 486 484 Vector<uint8_t> dataVector; 485 487 486 if (CFEqual(uti.get(), jpegUTI())) { 488 487 // JPEGs don't have an alpha channel, so we have to manually composite on top of black. … … 507 506 data = out; 508 507 } 509 510 dataProvider.adoptCF(CGDataProviderCreateWithData(0, data, 511 4 * source.width() * source.height(), 0)); 512 508 509 RetainPtr<CGDataProviderRef> dataProvider; 510 dataProvider.adoptCF(CGDataProviderCreateWithData(0, data, 4 * source.width() * source.height(), 0)); 513 511 if (!dataProvider) 514 512 return "data:,"; 515 513 514 RetainPtr<CGImageRef> image; 516 515 image.adoptCF(CGImageCreate(source.width(), source.height(), 8, 32, 4 * source.width(), 517 516 deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaLast, 518 517 dataProvider.get(), 0, false, kCGRenderingIntentDefault)); 519 520 521 if (!image)522 return "data:,";523 518 524 519 return CGImageToDataURL(image.get(), mimeType, quality); 525 520 } 521 526 522 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.