Changeset 75488 in webkit


Ignore:
Timestamp:
Jan 11, 2011 4:46:06 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-01-11 Noel Gordon <noel.gordon@gmail.com>

Reviewed by James Robinson.

[chromium] canvas.toDataURL("image/jpeg") should composite onto black.
https://bugs.webkit.org/show_bug.cgi?id=51237

canvas/philip/tests/toDataURL.jpeg.alpha.html only fails on chromium-mac
now, tracked by bug http://webkit.org/b/40147.

  • platform/chromium/test_expectations.txt: win & linux pass.

2011-01-11 Noel Gordon <noel.gordon@gmail.com>

Reviewed by James Robinson.

[chromium] canvas.toDataURL("image/jpeg") should composite onto black.
https://bugs.webkit.org/show_bug.cgi?id=51237

The Canvas specification requires that the canvas image is composited using
the Porter-Duff operator source-over onto a black background; the resultant
image should be JPEG encoded and returned as a dataURL. To composite image
A and background B, for any Porter-Duff operator, produce pixels I with

I = c(A)F(A) + c(B)F(B)

where, F(X) is the fraction [0.0-1.0] contributed to the composite by image
X, and c(X) are the premultiplied RGB color components of image X. Note by
definition, c(B) = 0 since the background is black, so I = c(A)F(A). Since
F(A) = 1 in Porter-Duff operator source-over, the composited pixels satisfy
I = c(A). Hence, to conform to the Canvas spec, pass the premultiplied RGB
color components of the canvas image to the JPEG encoder.

Covered by canvas/philip/tests/toDataURL.jpeg.alpha.html

  • platform/image-encoders/skia/JPEGImageEncoder.cpp: (WebCore::preMultipliedBGRAtoRGB): Use Porter-Duff source-over black.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r75484 r75488  
     12011-01-11  Noel Gordon  <noel.gordon@gmail.com>
     2
     3        Reviewed by James Robinson.
     4
     5        [chromium] canvas.toDataURL("image/jpeg") should composite onto black.
     6        https://bugs.webkit.org/show_bug.cgi?id=51237
     7
     8        canvas/philip/tests/toDataURL.jpeg.alpha.html only fails on chromium-mac
     9        now, tracked by bug http://webkit.org/b/40147.
     10
     11        * platform/chromium/test_expectations.txt: win & linux pass.
     12
    1132011-01-11  Anton Muhin  <antonm@chromium.org>
    214
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r75482 r75488  
    20552055BUGWK48579 : canvas/philip/tests/type.prototype.html = TEXT
    20562056BUGWK50797 : canvas/philip/tests/2d.fillStyle.parse.invalid.rgba-6.html = TEXT
    2057 BUGWK40147 : canvas/philip/tests/toDataURL.jpeg.alpha.html = TEXT
     2057BUGWK40147 MAC : canvas/philip/tests/toDataURL.jpeg.alpha.html = TEXT
    20582058BUGCR61824 : canvas/philip/tests/2d.pattern.image.string.html = TEXT
    20592059
  • trunk/Source/WebCore/ChangeLog

    r75487 r75488  
     12011-01-11  Noel Gordon  <noel.gordon@gmail.com>
     2
     3         Reviewed by James Robinson.
     4
     5         [chromium] canvas.toDataURL("image/jpeg") should composite onto black.
     6         https://bugs.webkit.org/show_bug.cgi?id=51237
     7
     8         The Canvas specification requires that the canvas image is composited using
     9         the Porter-Duff operator source-over onto a black background; the resultant
     10         image should be JPEG encoded and returned as a dataURL.  To composite image
     11         A and background B, for any Porter-Duff operator, produce pixels I with
     12
     13            I = c(A)F(A) + c(B)F(B)
     14
     15         where, F(X) is the fraction [0.0-1.0] contributed to the composite by image
     16         X, and c(X) are the premultiplied RGB color components of image X.  Note by
     17         definition, c(B) = 0 since the background is black, so I = c(A)F(A).  Since
     18         F(A) = 1 in Porter-Duff operator source-over, the composited pixels satisfy
     19         I = c(A).  Hence, to conform to the Canvas spec, pass the premultiplied RGB
     20         color components of the canvas image to the JPEG encoder.
     21
     22         Covered by canvas/philip/tests/toDataURL.jpeg.alpha.html
     23
     24         * platform/image-encoders/skia/JPEGImageEncoder.cpp:
     25         (WebCore::preMultipliedBGRAtoRGB): Use Porter-Duff source-over black.
     26
    1272011-01-11  François Sausset  <sausset@gmail.com>
    228
  • trunk/Source/WebCore/platform/image-encoders/skia/JPEGImageEncoder.cpp

    r74631 r75488  
    8080}
    8181
    82 // FIXME: is alpha unpremultiplication correct, or should the alpha channel
    83 // be ignored? See bug http://webkit.org/b/40147.
    84 void preMultipliedBGRAtoRGB(const SkPMColor* input, unsigned int pixels, unsigned char* output)
     82static void preMultipliedBGRAtoRGB(const SkPMColor* input, unsigned int pixels, unsigned char* output)
    8583{
    86     static const SkUnPreMultiply::Scale* scale = SkUnPreMultiply::GetScaleTable();
    87 
    8884    for (; pixels-- > 0; ++input) {
    89         const unsigned alpha = SkGetPackedA32(*input);
    90         if ((alpha != 0) && (alpha != 255)) {
    91             *output++ = SkUnPreMultiply::ApplyScale(scale[alpha], SkGetPackedR32(*input));
    92             *output++ = SkUnPreMultiply::ApplyScale(scale[alpha], SkGetPackedG32(*input));
    93             *output++ = SkUnPreMultiply::ApplyScale(scale[alpha], SkGetPackedB32(*input));
    94         } else {
    95             *output++ = SkGetPackedR32(*input);
    96             *output++ = SkGetPackedG32(*input);
    97             *output++ = SkGetPackedB32(*input);
    98         }
     85        *output++ = SkGetPackedR32(*input);
     86        *output++ = SkGetPackedG32(*input);
     87        *output++ = SkGetPackedB32(*input);
    9988    }
    10089}
Note: See TracChangeset for help on using the changeset viewer.