Bug 38282 - Passing premultiplyAlpha=false to tex{Sub}Image2D loses information (skia)
Summary: Passing premultiplyAlpha=false to tex{Sub}Image2D loses information (skia)
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Zhenyao Mo
URL:
Keywords:
Depends on:
Blocks: 44661
  Show dependency treegraph
 
Reported: 2010-04-28 14:08 PDT by Kenneth Russell
Modified: 2010-08-27 18:06 PDT (History)
9 users (show)

See Also:


Attachments
patch (51.91 KB, patch)
2010-08-24 17:45 PDT, Zhenyao Mo
zmo: commit-queue-
Details | Formatted Diff | Diff
revised patch: fixing style issues (51.91 KB, patch)
2010-08-24 17:56 PDT, Zhenyao Mo
zmo: commit-queue-
Details | Formatted Diff | Diff
revised patch: an attempt to fix the Qt port (54.58 KB, patch)
2010-08-25 10:20 PDT, Zhenyao Mo
kbr: review+
zmo: commit-queue-
Details | Formatted Diff | Diff
patch: dealing case of texImage2D using HTMLCanvasElement as input (6.67 KB, patch)
2010-08-26 19:14 PDT, Zhenyao Mo
zmo: commit-queue-
Details | Formatted Diff | Diff
revised patch: fix a tiny logic bug (6.71 KB, patch)
2010-08-26 19:16 PDT, Zhenyao Mo
kbr: review+
zmo: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kenneth Russell 2010-04-28 14:08:12 PDT
If an RGBA PNG image is uploaded via texImage2D or texSubImage2D and false is passed for the premultiplyAlpha argument, the result is currently lossy; the alpha channel is multiplied in to the color channels by the browser and then divided out later. The WebGL specification requires that this upload path be lossless so that images which do not contain color and alpha information (for example, using the RGBA channels as arbitrary data inputs to a shader) are not destroyed during the upload process.
Comment 1 Zhenyao Mo 2010-08-24 17:35:41 PDT
break the bug into two: skia and cg

cg is here: https://bugs.webkit.org/show_bug.cgi?id=44566
Comment 2 Zhenyao Mo 2010-08-24 17:45:41 PDT
Created attachment 65347 [details]
patch

Test is in sync with khronos (with certain parts commented out).
Comment 3 WebKit Review Bot 2010-08-24 17:52:16 PDT
Attachment 65347 [details] did not pass style-queue:

Failed to run "['WebKitTools/Scripts/check-webkit-style']" exit_code: 1
WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp:87:  Missing spaces around <  [whitespace/operators] [3]
WebCore/platform/image-decoders/ImageDecoder.h:158:  Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.  [readability/comparison_to_zero] [5]
Total errors found: 2 in 27 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Zhenyao Mo 2010-08-24 17:56:34 PDT
Created attachment 65349 [details]
revised patch: fixing style issues
Comment 5 Zhenyao Mo 2010-08-25 10:20:25 PDT
Created attachment 65433 [details]
revised patch: an attempt to fix the Qt port
Comment 6 Zhenyao Mo 2010-08-25 10:22:51 PDT
Eric, is there anyway we can get the output from Qt?  I see it's failing, but have no idea why.  If I can get the output, it will be much easier for me to fix the issue.
Comment 7 Eric Seidel (no email) 2010-08-25 11:34:48 PDT
I'm not sure why Qt failed to post results here.
Comment 8 Kenneth Russell 2010-08-25 11:58:53 PDT
Comment on attachment 65433 [details]
revised patch: an attempt to fix the Qt port

Generally looks good. A few comments; please address before committing.

WebCore/platform/graphics/cg/ImageSourceCG.cpp:68
 +      , m_premultiplyAlpha(premultiplyAlpha)
Should add a FIXME indicating this isn't obeyed yet.

WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp: 
 +      if (skiaConfig != SkBitmap::kARGB_8888_Config)
I think it would be a good idea to retain some sort of this test of the configuration rather than just the assertion about pixels->rowBytes() below.

WebCore/platform/image-decoders/ImageDecoder.h:158
 +              if (!a && m_premultiplyAlpha)
It may be clearer here and below if m_premultiplyAlpha is tested first; i.e., "if (m_premultiplyAlpha && !a)".

WebCore/platform/image-decoders/ImageDecoder.h:197
 +                                // Whether to premultiply alpha to R, G, B channels;
alpha to -> alpha into

LayoutTests/fast/canvas/webgl/gl-teximage-expected.txt:1
 +  CONSOLE MESSAGE: line 260: ReferenceError: Can't find variable: notifyFinishedToHarness
This looks bad. Please investigate why this is being reported and fix.


LayoutTests/platform/mac/Skipped:297
 +  fast/canvas/webgl/gl-teximage.html
We should consider either adding this to mac-snowleopard or moving the skipped entries from that directory to this one. Doesn't need to be fixed right now.
Comment 9 Zhenyao Mo 2010-08-25 13:29:20 PDT
Committed r66039: <http://trac.webkit.org/changeset/66039>
Comment 10 Zhenyao Mo 2010-08-25 13:31:59 PDT
The landed patch addressed all the comments here except the last one.

(In reply to comment #8)
> (From update of attachment 65433 [details])
> Generally looks good. A few comments; please address before committing.
> 
> WebCore/platform/graphics/cg/ImageSourceCG.cpp:68
>  +      , m_premultiplyAlpha(premultiplyAlpha)
> Should add a FIXME indicating this isn't obeyed yet.
> 
> WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp: 
>  +      if (skiaConfig != SkBitmap::kARGB_8888_Config)
> I think it would be a good idea to retain some sort of this test of the configuration rather than just the assertion about pixels->rowBytes() below.
> 
> WebCore/platform/image-decoders/ImageDecoder.h:158
>  +              if (!a && m_premultiplyAlpha)
> It may be clearer here and below if m_premultiplyAlpha is tested first; i.e., "if (m_premultiplyAlpha && !a)".
> 
> WebCore/platform/image-decoders/ImageDecoder.h:197
>  +                                // Whether to premultiply alpha to R, G, B channels;
> alpha to -> alpha into
> 
> LayoutTests/fast/canvas/webgl/gl-teximage-expected.txt:1
>  +  CONSOLE MESSAGE: line 260: ReferenceError: Can't find variable: notifyFinishedToHarness
> This looks bad. Please investigate why this is being reported and fix.
> 
> 
> LayoutTests/platform/mac/Skipped:297
>  +  fast/canvas/webgl/gl-teximage.html
> We should consider either adding this to mac-snowleopard or moving the skipped entries from that directory to this one. Doesn't need to be fixed right now.
Comment 11 Zhenyao Mo 2010-08-25 20:50:43 PDT
Need to deal with the case where image->data() == null (in texImage2D with HTMLCanvasElement input)
Comment 12 Kenneth Russell 2010-08-26 11:31:58 PDT
(In reply to comment #11)
> Need to deal with the case where image->data() == null (in texImage2D with HTMLCanvasElement input)

Is it possible to refer to the Canvas's ImageBuffer rather than an Image for this upload case?
Comment 13 Zhenyao Mo 2010-08-26 11:52:18 PDT
(In reply to comment #12)
> (In reply to comment #11)
> > Need to deal with the case where image->data() == null (in texImage2D with HTMLCanvasElement input)
> 
> Is it possible to refer to the Canvas's ImageBuffer rather than an Image for this upload case?

I'll have a look.
Comment 14 Zhenyao Mo 2010-08-26 19:14:25 PDT
Created attachment 65659 [details]
patch: dealing case of texImage2D using HTMLCanvasElement as input
Comment 15 Zhenyao Mo 2010-08-26 19:16:54 PDT
Created attachment 65660 [details]
revised patch: fix a tiny logic bug
Comment 16 Kenneth Russell 2010-08-27 18:00:20 PDT
Comment on attachment 65660 [details]
revised patch: fix a tiny logic bug

Looks good to me.
Comment 17 Zhenyao Mo 2010-08-27 18:06:18 PDT
Committed r66288: <http://trac.webkit.org/changeset/66288>