Changeset 116330 in webkit


Ignore:
Timestamp:
May 7, 2012 11:34:16 AM (12 years ago)
Author:
noel.gordon@gmail.com
Message:

[CG] ImageBuffer::ImageDataToDataURL: Remove alpha stuffing when encoding to JPEG
https://bugs.webkit.org/show_bug.cgi?id=85779

Reviewed by Eric Seidel.

No change in behavior. Covered by fast/canvas/webgl/premultiplyalpha-test.html

  • platform/graphics/cg/ImageBufferCG.cpp:

(WebCore::ImageDataToDataURL): Remove the need to stuff the alpha channel with 255.
Rename dataVector to premultipliedData and verify that its resize() worked. Rewrite
the premultiplication loop without the alpha channel = 255 part and ask the CG JPEG
encoder to ignore the alpha channel (kCGImageAlphaNoneSkipLast) instead.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r116328 r116330  
     12012-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
    1162012-05-07  Dominik Röttsches  <dominik.rottsches@linux.intel.com>
    217
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp

    r116196 r116330  
    481481    ASSERT(uti);
    482482
     483    CGImageAlphaInfo dataAlphaInfo = kCGImageAlphaLast;
    483484    unsigned char* data = source.data()->data();
    484     Vector<uint8_t> dataVector;
     485    Vector<uint8_t> premultipliedData;
    485486
    486487    if (CFEqual(uti.get(), jpegUTI())) {
    487488        // 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];
    494496            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;
    498500            } 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];
    502504            }
    503             out[4 * i + 3] = 255;
    504505        }
    505506
    506         data = out;
     507        dataAlphaInfo = kCGImageAlphaNoneSkipLast; // Ignore the alpha channel.
     508        data = premultipliedData.data();
    507509    }
    508510
     
    514516    RetainPtr<CGImageRef> image;
    515517    image.adoptCF(CGImageCreate(source.width(), source.height(), 8, 32, 4 * source.width(),
    516                                 deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaLast,
     518                                deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | dataAlphaInfo,
    517519                                dataProvider.get(), 0, false, kCGRenderingIntentDefault));
    518520
Note: See TracChangeset for help on using the changeset viewer.