<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>237082</bug_id>
          
          <creation_ts>2022-02-23 06:00:15 -0800</creation_ts>
          <short_desc>createImageBitmap cannot premultiply alpha with ImageData</short_desc>
          <delta_ts>2023-10-27 04:37:26 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Canvas</component>
          <version>Safari 15</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>182424</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Ashley Gullen">ashley</reporter>
          <assigned_to name="Matt Woodrow">mattwoodrow</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>dino</cc>
    
    <cc>dpaddock</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1845106</commentid>
    <comment_count>0</comment_count>
    <who name="Ashley Gullen">ashley</who>
    <bug_when>2022-02-23 06:00:15 -0800</bug_when>
    <thetext>Summary: when calling createImageBitmap() with an ImageData and the option premultiplyAlpha: &quot;premultiply&quot;, the resulting ImageBitmap still does not have premultiplied alpha. It appears to work correctly with other overloads using Blob, Image and Canvas.

Repro URL: https://downloads.scirra.com/labs/bugs/imagebitmapalpha/

The demo uses createImageBitmap() premultiplying alpha on Blob, Image, Canvas and ImageData. It uses a WebGL context to read the ImageBitmap pixel data back, via texture upload and readback.

In the ImageData case, the texture pixel data still uses unpremultiplied alpha. Look in the console of the repro page and it will log pass/fail results. The ImageData case fails with pixel data [0, 0, 255, 44], with the expected result [0, 0, 44, 44].</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1845355</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-02-23 15:36:46 -0800</bug_when>
    <thetext>&lt;rdar://problem/89382358&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1948808</commentid>
    <comment_count>2</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2023-04-14 09:13:55 -0700</bug_when>
    <thetext>I initially though there might have been a mistake in the optimized code path for premultiplied alpha, but I tried the test case with the slow byte-wise math and the results are identical.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1948828</commentid>
    <comment_count>3</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2023-04-14 10:56:34 -0700</bug_when>
    <thetext>Source is unpremultiplied RGBA8, destination for createImageBitmap backing store is premultiplied BGRA8. Colorspace is unchanged.

Although the test case talks about [12, 12], the math actually gives you [12, 3].

Inputs to vImagePremultiplyData_RGBA8888 look correct, e.g. the pixel at location 12, 3 in the source buffer is: 

00 00 FF 2C

The result of premultiplying is:

00 00 2C 2C

Which is correct.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1948864</commentid>
    <comment_count>4</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2023-04-14 13:29:31 -0700</bug_when>
    <thetext>The RGBA8 is then permuted to BGRA to go into the IOSurface:

00 00 2C 2C

Becomes

2C 00 00 2C

So the image buffer is properly constructed.

I think the issue is when this buffer is used to populate the textImage (WebGLRenderingContextBase::texImageSource) doesn&apos;t have the context that the image data is premultiplied; it looks like it rolls the premultiplication out of the buffer before loading into the texture.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1949309</commentid>
    <comment_count>5</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2023-04-17 17:21:32 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/12834</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1949530</commentid>
    <comment_count>6</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2023-04-18 11:33:32 -0700</bug_when>
    <thetext>It doesn&apos;t look like WPT has any coverage for createImageBitmap with &apos;premultiply&apos; set.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1949601</commentid>
    <comment_count>7</comment_count>
    <who name="Matt Woodrow">mattwoodrow</who>
    <bug_when>2023-04-18 16:25:34 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/12891</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1949777</commentid>
    <comment_count>8</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-04-19 10:59:24 -0700</bug_when>
    <thetext>Committed 263137@main (aa1ea27b114e): &lt;https://commits.webkit.org/263137@main&gt;

Reviewed commits have been landed. Closing PR #12891 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>