Bug 89937 - [Qt] Use premultiplied alpha when extracting image data in WebGL
Summary: [Qt] Use premultiplied alpha when extracting image data in WebGL
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Noam Rosenthal
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-25 19:27 PDT by Noam Rosenthal
Modified: 2012-06-26 15:51 PDT (History)
4 users (show)

See Also:


Attachments
Patch (3.29 KB, patch)
2012-06-26 06:10 PDT, Noam Rosenthal
no flags Details | Formatted Diff | Diff
Patch (4.12 KB, patch)
2012-06-26 09:12 PDT, Noam Rosenthal
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Noam Rosenthal 2012-06-25 19:27:25 PDT
In GraphicsContext3DQt, we convert the native QPixmap to QImage::Format_ARGB32, and then pass AlphaDoPremultiply as an argument to packPixels.
This means that if the image was originally premultiplied, the code path would convert it to unpremultiplied and then back to premultiplied.
Instead, we should use QImage::Format_ARGB32_Premultiplied when premultiplyAlpha is true.
Comment 1 Dongseong Hwang 2012-06-25 19:38:00 PDT
This bug may solve itself with Bug 89938.

GraphicsContext3D::extractImageData causes strange message with specific png files.
Comment 2 Noam Rosenthal 2012-06-25 19:40:08 PDT
(In reply to comment #1)
> This bug may solve itself with Bug 89938.
> 
> GraphicsContext3D::extractImageData causes strange message with specific png files.

hmm... not sure they're related.
Comment 3 Noam Rosenthal 2012-06-26 06:10:13 PDT
Created attachment 149519 [details]
Patch
Comment 4 Simon Hausmann 2012-06-26 06:38:08 PDT
Comment on attachment 149519 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=149519&action=review

> Source/WebCore/ChangeLog:14
> +        Covered by existing WebGL pixel tests.

Any chance of naming them, for reference in the ChangeLog? :)
Comment 5 Jocelyn Turcotte 2012-06-26 07:03:25 PDT
View in context: https://bugs.webkit.org/attachment.cgi?id=149519&action=review

> Source/WebCore/ChangeLog:9
> +        Format_ARB32_Premultiplied instead of converting it to ARGB32 and then letting

ARB32 -> ARGB32

> Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp:503
> +    qtImage = qtImage.convertToFormat(premultiplyAlpha ? QImage::Format_ARGB32_Premultiplied : QImage::Format_ARGB32);

Won't this cause an extra conversion if the source image is, on the opposite, already in Format_ARGB32?
The cost of AlphaDoPremultiply should be pretty low as packPixel already has to convert from BGRA to ARGB and the data is in the CPU cache at the moment of the pre-multiplication.
Comment 6 Noam Rosenthal 2012-06-26 09:12:25 PDT
Created attachment 149542 [details]
Patch
Comment 7 Jocelyn Turcotte 2012-06-26 09:52:17 PDT
Comment on attachment 149542 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=149542&action=review

> Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp:520
> +    switch (qtImage.format()) {
> +    case QImage::Format_ARGB32:
> +        if (premultiplyAlpha)
> +            alphaOp = AlphaDoPremultiply;
> +        break;
> +    case QImage::Format_ARGB32_Premultiplied:
> +        if (!premultiplyAlpha)
> +            alphaOp = AlphaDoUnmultiply;
> +        break;
> +    default:
> +        // The image has a format that is not supported in packPixels. We have to convert it here.
> +        qtImage = qtImage.convertToFormat(premultiplyAlpha ? QImage::Format_ARGB32_Premultiplied : QImage::Format_ARGB32);
> +        break;
> +    }

Wouldn't if/else look cleaner?

if (qtImage.format() == QImage::Format_ARGB32 && premultiplyAlpha)
    alphaOp = AlphaDoPremultiply;
else if (qtImage.format() == QImage::Format_ARGB32_Premultiplied && !premultiplyAlpha)
    alphaOp = AlphaDoUnmultiply;
else
    // The image has a format that is not supported in packPixels. We have to convert it here.
    qtImage = qtImage.convertToFormat(premultiplyAlpha ? QImage::Format_ARGB32_Premultiplied : QImage::Format_ARGB32);

r=me in any case.
Comment 8 Jocelyn Turcotte 2012-06-26 09:55:34 PDT
(In reply to comment #7)
> Wouldn't if/else look cleaner?
> 
> if (qtImage.format() == QImage::Format_ARGB32 && premultiplyAlpha)
>     alphaOp = AlphaDoPremultiply;
> else if (qtImage.format() == QImage::Format_ARGB32_Premultiplied && !premultiplyAlpha)
>     alphaOp = AlphaDoUnmultiply;
> else
>     // The image has a format that is not supported in packPixels. We have to convert it here.
>     qtImage = qtImage.convertToFormat(premultiplyAlpha ? QImage::Format_ARGB32_Premultiplied : QImage::Format_ARGB32);

Humm that would cause a call to convertToFormat(Format_ARGB32) if qtImage.format() == QImage::Format_ARGB32 && !premultiplyAlpha. Probably a no-op but not so clean in any case, feel free to ignore.
Comment 9 WebKit Review Bot 2012-06-26 15:51:52 PDT
Comment on attachment 149542 [details]
Patch

Clearing flags on attachment: 149542

Committed r121292: <http://trac.webkit.org/changeset/121292>
Comment 10 WebKit Review Bot 2012-06-26 15:51:57 PDT
All reviewed patches have been landed.  Closing bug.