Changeset 116196 in webkit


Ignore:
Timestamp:
May 4, 2012 5:49:42 PM (12 years ago)
Author:
noel.gordon@gmail.com
Message:

[CG] Minor refactor of ImageBuffer::CGImageToDataURL and its callers
https://bugs.webkit.org/show_bug.cgi?id=85280

Reviewed by Kenneth Russell.

This patch means to simplify the diff of an upcoming patch. Refactoring
here in preparation for that patch.

No new tests. No behavioral change. Covered by canvas 2d and 3d tests:

canvas/philip/tests/*toDataURL*.html
fast/canvas/webgl/premultiplyalpha-test.html

  • platform/graphics/cg/ImageBufferCG.cpp:

(WebCore::CGImageToDataURL): Move the invalid image (!image) test here.
The comments are about JPEG images; say that. Rename out to base64Data.
(WebCore::ImageBuffer::toDataURL): Remove the !image test.
(WebCore::ImageDataToDataURL): Move and define variables where used and
make the code flow read similarly to toDataURL. Remove the !image test.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r116195 r116196  
     12012-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
    1222012-05-04  Shawn Singh  <shawnsingh@chromium.org>
    223
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp

    r114992 r116196  
    402402static String CGImageToDataURL(CGImageRef image, const String& mimeType, const double* quality)
    403403{
     404    if (!image)
     405        return "data:,";
     406
    404407    RetainPtr<CFMutableDataRef> data(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0));
    405408    if (!data)
     
    415418    RetainPtr<CFDictionaryRef> imageProperties = 0;
    416419    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.
    418421        RetainPtr<CFNumberRef> compressionQuality(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, quality));
    419422        const void* key = kCGImageDestinationLossyCompressionQuality;
     
    422425    }
    423426
    424     // Setting kCGImageDestinationBackgroundColor to black in imageProperties would allow saving some math in the
    425     // 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.
    426429
    427430    CGImageDestinationAddImage(destination.get(), image, imageProperties.get());
    428431    CGImageDestinationFinalize(destination.get());
    429432
    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;
    434437}
    435438
     
    468471    }
    469472
    470     if (!image)
    471         return "data:,";
    472 
    473473    return CGImageToDataURL(image.get(), mimeType, quality);
    474474}
     
    477477{
    478478    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
    479        
    480     RetainPtr<CGImageRef> image;
    481     RetainPtr<CGDataProviderRef> dataProvider;
    482 
    483     unsigned char* data = source.data()->data();
     479
    484480    RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType);
    485481    ASSERT(uti);
     482
     483    unsigned char* data = source.data()->data();
    486484    Vector<uint8_t> dataVector;
     485
    487486    if (CFEqual(uti.get(), jpegUTI())) {
    488487        // JPEGs don't have an alpha channel, so we have to manually composite on top of black.
     
    507506        data = out;
    508507    }
    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));
    513511    if (!dataProvider)
    514512        return "data:,";
    515513
     514    RetainPtr<CGImageRef> image;
    516515    image.adoptCF(CGImageCreate(source.width(), source.height(), 8, 32, 4 * source.width(),
    517516                                deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaLast,
    518517                                dataProvider.get(), 0, false, kCGRenderingIntentDefault));
    519                                
    520        
    521     if (!image)
    522         return "data:,";
    523518
    524519    return CGImageToDataURL(image.get(), mimeType, quality);
    525520}
     521
    526522} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.