New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 713862 link

Starred by 7 users

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: May 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Support color space embedding in image encoders

Project Member Reported by zakerinasab@chromium.org, Apr 20 2017

Issue description


Chrome's image encoders do not embed color space information.  So if you encode a P3 image to PNG, it will forget the fact that it is P3.

Furthermore, Chrome's image encoders unpremultiply and premultiply in the gamma encoded space.  If a color managed canvas in a linear gamma space is used, this will break.  They encoders need to premultiply linearly.

Along with crbug.com/663569, this can be done by replacing Chrome's image encoders with Skia ones.
 
Blocking: 713867
Cc: scroggo@chromium.org esprehn@chromium.org fmalita@chromium.org
I've just completed very similar work on Skia's image encoders (for Android):
***Embedding ICC profiles
***Supporting both versions of unpremultiplication
***Supporting Float16 inputs
***SIMD optimizations for the above

I think it would be great to avoid duplicating the work and just maintain one set of encoders.  This seems like a good time to try to make the switch to Skia.

It looks like platform/image-encoders is unowned, so I guess I'm volunteering to take ownership.  I'm CCing a few of the platform/ OWNERS (not sure who else to add - there hasn't been much recent activity on the encoders).  Please feel free to add anyone that might be interested in this project.
Project Member

Comment 3 by bugdroid1@chromium.org, May 2 2017

The following revision refers to this bug:
  https://skia.googlesource.com/skia/+/c06f309cf52b885b1b1d98c6b045b120a09f5c54

commit c06f309cf52b885b1b1d98c6b045b120a09f5c54
Author: Leon Scroggins <scroggo@google.com>
Date: Tue May 02 17:08:35 2017

Revert "Add support for row-by-row jpeg encoding"

This reverts commit 9b848d5749c5e34b56f927a3a3374c8ebafbd9db.

Reason for revert: ASAN reports leaked memory [1]. Google3 reports a "delete size mismatch" [2], which I suspect is the same issue.

[1] https://chromium-swarm.appspot.com/task?id=35e2c9fa9eac6310&refresh=10&show_raw=1
[2] https://test.corp.google.com/ui#cl=154838904&flags=CAMQBQ==&id=OCL:154838904:BASE:154839043:1493741642370:9c96115f&t=//chrome/skia/dm_wrapper:dm_wrapper

Original change's description:
> Add support for row-by-row jpeg encoding
> 
> Bug:  713862 
> Change-Id: I787b7c49662a00b89ae0ef35845dfbd6be3e6fb1
> Reviewed-on: https://skia-review.googlesource.com/14641
> Commit-Queue: Matt Sarett <msarett@google.com>
> Reviewed-by: Leon Scroggins <scroggo@google.com>
> 

TBR=msarett@google.com,scroggo@google.com,reed@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: Ic5a8d67e0d4a7733662586055ceff086a2ab335d
Reviewed-on: https://skia-review.googlesource.com/15140
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>

[delete] https://crrev.com/9b848d5749c5e34b56f927a3a3374c8ebafbd9db/src/images/SkJpegEncoder.h
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/gn/tests.gni
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/gm/encode-srgb.cpp
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/src/images/SkImageEncoderPriv.h
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/src/images/SkImageEncoder.cpp
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/src/images/SkJPEGImageEncoder.cpp
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/tests/ReadPixelsTest.cpp
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/tests/CodecTest.cpp
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/src/gpu/SkGr.cpp
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/src/core/SkImageInfoPriv.h
[modify] https://crrev.com/c06f309cf52b885b1b1d98c6b045b120a09f5c54/gm/encode-platform.cpp
[delete] https://crrev.com/9b848d5749c5e34b56f927a3a3374c8ebafbd9db/tests/EncodeTest.cpp

Project Member

Comment 4 by bugdroid1@chromium.org, May 2 2017

The following revision refers to this bug:
  https://skia.googlesource.com/skia/+/26b44df2333d5e8cec8aef11ab598d63b4ee05c7

commit 26b44df2333d5e8cec8aef11ab598d63b4ee05c7
Author: Matt Sarett <msarett@google.com>
Date: Tue May 02 20:40:10 2017

Add support for row-by-row jpeg encoding

Reland of:
https://skia-review.googlesource.com/c/14641/

Bug:  713862 
Change-Id: I9dca5ede4ebf569c5f80edcfb23a506b6cfa935e
Reviewed-on: https://skia-review.googlesource.com/15144
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>

[add] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/src/images/SkJpegEncoder.h
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/gn/tests.gni
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/gm/encode-srgb.cpp
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/src/images/SkImageEncoderPriv.h
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/src/images/SkImageEncoder.cpp
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/src/images/SkJPEGImageEncoder.cpp
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/tests/ReadPixelsTest.cpp
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/tests/CodecTest.cpp
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/src/gpu/SkGr.cpp
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/src/core/SkImageInfoPriv.h
[modify] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/gm/encode-platform.cpp
[add] https://crrev.com/26b44df2333d5e8cec8aef11ab598d63b4ee05c7/tests/EncodeTest.cpp

Project Member

Comment 5 by bugdroid1@chromium.org, May 5 2017

The following revision refers to this bug:
  https://skia.googlesource.com/skia/+/c367d03fb04fccdc63b1379cf74ddc1cab842039

commit c367d03fb04fccdc63b1379cf74ddc1cab842039
Author: Matt Sarett <msarett@google.com>
Date: Fri May 05 16:34:13 2017

Add support for row-by-row png encodes

Also adds a SkEncoder base class.

Bug:  713862 
Change-Id: Ia3f009cd9f376514f6c19396245fab3a43ae6536
Reviewed-on: https://skia-review.googlesource.com/15152
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>

[add] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/src/images/SkPngEncoder.h
[add] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/src/images/SkEncoder.h
[modify] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/src/images/SkJpegEncoder.h
[modify] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/src/images/SkImageEncoderPriv.h
[modify] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/gm/encode-srgb.cpp
[modify] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/src/images/SkImageEncoder.cpp
[modify] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/src/images/SkJPEGImageEncoder.cpp
[modify] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/tests/CodecTest.cpp
[modify] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/tests/EncodeTest.cpp
[modify] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/gm/encode-platform.cpp
[modify] https://crrev.com/c367d03fb04fccdc63b1379cf74ddc1cab842039/src/images/SkPNGImageEncoder.cpp

Project Member

Comment 6 by bugdroid1@chromium.org, May 8 2017

The following revision refers to this bug:
  https://skia.googlesource.com/skia/+/be4c9b0a8b9a508cf0de66c0fa401fc1217a32db

commit be4c9b0a8b9a508cf0de66c0fa401fc1217a32db
Author: Matt Sarett <msarett@google.com>
Date: Mon May 08 16:43:44 2017

Add filtering and zlib-level options to SkPngEncoder

Bug:  skia:6409 
Bug:  713862 
Change-Id: If287e2bcad5af990fac11e9091305f45ec903dbf
Reviewed-on: https://skia-review.googlesource.com/15647
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>

[modify] https://crrev.com/be4c9b0a8b9a508cf0de66c0fa401fc1217a32db/src/images/SkPngEncoder.h
[modify] https://crrev.com/be4c9b0a8b9a508cf0de66c0fa401fc1217a32db/src/images/SkPngEncoder.cpp
[modify] https://crrev.com/be4c9b0a8b9a508cf0de66c0fa401fc1217a32db/tests/EncodeTest.cpp

Project Member

Comment 7 by bugdroid1@chromium.org, May 9 2017

The following revision refers to this bug:
  https://skia.googlesource.com/skia/+/94fd06f074016e3ca6a82b88dfdc0ec61d24e67e

commit 94fd06f074016e3ca6a82b88dfdc0ec61d24e67e
Author: Matt Sarett <msarett@google.com>
Date: Tue May 09 17:46:30 2017

Move SkPngEncoder into public API

Bug:  713862 
Change-Id: I45068ed39affe41ffe0f29bf42c5ea1d9b0247ba
Reviewed-on: https://skia-review.googlesource.com/15897
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>

[modify] https://crrev.com/94fd06f074016e3ca6a82b88dfdc0ec61d24e67e/BUILD.gn
[rename] https://crrev.com/94fd06f074016e3ca6a82b88dfdc0ec61d24e67e/include/encode/SkEncoder.h
[rename] https://crrev.com/94fd06f074016e3ca6a82b88dfdc0ec61d24e67e/include/encode/SkPngEncoder.h

Project Member

Comment 8 by bugdroid1@chromium.org, May 9 2017

The following revision refers to this bug:
  https://skia.googlesource.com/skia/+/fe3190846c9af2cf19a76d7ab9799d7fa69c2369

commit fe3190846c9af2cf19a76d7ab9799d7fa69c2369
Author: Matt Sarett <msarett@google.com>
Date: Tue May 09 18:37:10 2017

Add downsampling option to SkJpegEncoder

Bug:  713862 
Change-Id: Ibad6ecf836ccfd355499e1bace7bcd4ba772a97a
Reviewed-on: https://skia-review.googlesource.com/15891
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>

[modify] https://crrev.com/fe3190846c9af2cf19a76d7ab9799d7fa69c2369/src/images/SkJpegEncoder.cpp
[modify] https://crrev.com/fe3190846c9af2cf19a76d7ab9799d7fa69c2369/tests/EncodeTest.cpp
[modify] https://crrev.com/fe3190846c9af2cf19a76d7ab9799d7fa69c2369/src/images/SkJpegEncoder.h

Project Member

Comment 10 by bugdroid1@chromium.org, May 12 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8

commit b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8
Author: msarett <msarett@google.com>
Date: Fri May 12 18:42:47 2017

Compile Skia image encoders

BUG= 713862 

Review-Url: https://codereview.chromium.org/2865363002
Cr-Commit-Position: refs/heads/master@{#471382}

[modify] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/content/renderer/gpu/gpu_benchmarking_extension.cc
[modify] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/skia/BUILD.gn
[delete] https://crrev.com/460d2176609a29589b5428b447a8f6b7d0a1fef4/skia/ext/skia_encode_image.cc
[delete] https://crrev.com/460d2176609a29589b5428b447a8f6b7d0a1fef4/skia/ext/skia_encode_image.h
[modify] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/third_party/libwebp/BUILD.gn
[modify] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/third_party/libwebp/README.chromium
[add] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/third_party/libwebp/mux/anim_encode.c
[add] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/third_party/libwebp/mux/animi.h
[add] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/third_party/libwebp/mux/muxedit.c
[add] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/third_party/libwebp/mux/muxi.h
[add] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/third_party/libwebp/mux/muxinternal.c
[add] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/third_party/libwebp/mux/muxread.c
[modify] https://crrev.com/b06d81fdf9fc3a85fe95aa3ef9cd1d7de09758c8/ui/gfx/codec/BUILD.gn
[delete] https://crrev.com/460d2176609a29589b5428b447a8f6b7d0a1fef4/ui/gfx/codec/skia_image_encoder_adapter.cc
[delete] https://crrev.com/460d2176609a29589b5428b447a8f6b7d0a1fef4/ui/gfx/codec/skia_image_encoder_adapter.h

Project Member

Comment 12 by bugdroid1@chromium.org, May 18 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/86074971b9640dbf59869071b4a18bec51c61424

commit 86074971b9640dbf59869071b4a18bec51c61424
Author: msarett <msarett@google.com>
Date: Thu May 18 12:25:27 2017

Use SkJpegEncoder in WebKit platform

This also makes CanvasAsyncBlobCreator use SkPngEncoder, since it is
natural to land jpeg and png together here.

The motivations for using Skia encoders are:
***Support for embedding ICC profiles
***Support for linear unpremultiplication and blending
***Support for multiple color types (including F16)
***Support for multiple alpha types (possible follow-up optimization)

As a long term refactoring goal, we should be able to delete
the WebKit image encoders and the ui/gfx image encoders, thus
leaving one set of image encoders to maintain.

Incidentally, I think this CL is also a nice simplication for
CanvasAsyncBlobCreator.

BUG= 713862 

Review-Url: https://codereview.chromium.org/2878333004
Cr-Commit-Position: refs/heads/master@{#472781}

[modify] https://crrev.com/86074971b9640dbf59869071b4a18bec51c61424/third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreator.cpp
[modify] https://crrev.com/86074971b9640dbf59869071b4a18bec51c61424/third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreator.h
[modify] https://crrev.com/86074971b9640dbf59869071b4a18bec51c61424/third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreatorTest.cpp
[modify] https://crrev.com/86074971b9640dbf59869071b4a18bec51c61424/third_party/WebKit/Source/platform/BUILD.gn
[modify] https://crrev.com/86074971b9640dbf59869071b4a18bec51c61424/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
[add] https://crrev.com/86074971b9640dbf59869071b4a18bec51c61424/third_party/WebKit/Source/platform/image-encoders/ImageEncoder.cpp
[add] https://crrev.com/86074971b9640dbf59869071b4a18bec51c61424/third_party/WebKit/Source/platform/image-encoders/ImageEncoder.h
[delete] https://crrev.com/8b69ce5fc7a7e267f2f893df6954c3787d5f2d2f/third_party/WebKit/Source/platform/image-encoders/JPEGImageEncoder.cpp
[delete] https://crrev.com/8b69ce5fc7a7e267f2f893df6954c3787d5f2d2f/third_party/WebKit/Source/platform/image-encoders/JPEGImageEncoder.h
[delete] https://crrev.com/8b69ce5fc7a7e267f2f893df6954c3787d5f2d2f/third_party/WebKit/Source/platform/image-encoders/JPEGImageEncoderTest.cpp
[delete] https://crrev.com/8b69ce5fc7a7e267f2f893df6954c3787d5f2d2f/third_party/WebKit/Source/platform/image-encoders/RGBAtoRGB.h

Project Member

Comment 13 by bugdroid1@chromium.org, May 19 2017

The following revision refers to this bug:
  https://skia.googlesource.com/skia/+/2f687877835b60497a48537b940cd634088eedf4

commit 2f687877835b60497a48537b940cd634088eedf4
Author: Matt Sarett <msarett@google.com>
Date: Fri May 19 23:35:46 2017

SkWebpEncoder: use bgra for lossless and yuv for lossy

Previosuly, we would (accidentally) always use just yuv.

Bug:  713862 
Change-Id: I00acc6ca2841ba0636494119b7b4f46a9deee401
Reviewed-on: https://skia-review.googlesource.com/17406
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>

[modify] https://crrev.com/2f687877835b60497a48537b940cd634088eedf4/tests/EncodeTest.cpp
[modify] https://crrev.com/2f687877835b60497a48537b940cd634088eedf4/src/images/SkWebpEncoder.cpp

Project Member

Comment 14 by bugdroid1@chromium.org, May 23 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/217d81bc49377c2235b8325a2f03dfce9ef45f95

commit 217d81bc49377c2235b8325a2f03dfce9ef45f95
Author: msarett <msarett@google.com>
Date: Tue May 23 18:19:42 2017

Use SkPngEncoder and SkWebpEncoder in WebKit platform

The motivations for using Skia encoders are:
***Support for embedding ICC profiles
***Support for linear unpremultiplication and blending
***Support for multiple color types (including F16)
***Support for multiple alpha types

As a long term refactoring goal, we should be able to delete
the WebKit image encoders and the ui/gfx image encoders, thus
leaving one set of image encoders to maintain.

BUG= 713862 

Review-Url: https://codereview.chromium.org/2891373002
Cr-Commit-Position: refs/heads/master@{#473985}

[modify] https://crrev.com/217d81bc49377c2235b8325a2f03dfce9ef45f95/third_party/WebKit/Source/core/inspector/InspectorLayerTreeAgent.cpp
[modify] https://crrev.com/217d81bc49377c2235b8325a2f03dfce9ef45f95/third_party/WebKit/Source/platform/BUILD.gn
[modify] https://crrev.com/217d81bc49377c2235b8325a2f03dfce9ef45f95/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
[modify] https://crrev.com/217d81bc49377c2235b8325a2f03dfce9ef45f95/third_party/WebKit/Source/platform/graphics/LoggingCanvas.cpp
[modify] https://crrev.com/217d81bc49377c2235b8325a2f03dfce9ef45f95/third_party/WebKit/Source/platform/graphics/PictureSnapshot.cpp
[modify] https://crrev.com/217d81bc49377c2235b8325a2f03dfce9ef45f95/third_party/WebKit/Source/platform/image-encoders/ImageEncoder.cpp
[modify] https://crrev.com/217d81bc49377c2235b8325a2f03dfce9ef45f95/third_party/WebKit/Source/platform/image-encoders/ImageEncoder.h
[delete] https://crrev.com/e635c3e1ed9ed9a0838beba6893b996a63c3e6a1/third_party/WebKit/Source/platform/image-encoders/PNGImageEncoder.cpp
[delete] https://crrev.com/e635c3e1ed9ed9a0838beba6893b996a63c3e6a1/third_party/WebKit/Source/platform/image-encoders/PNGImageEncoder.h
[delete] https://crrev.com/e635c3e1ed9ed9a0838beba6893b996a63c3e6a1/third_party/WebKit/Source/platform/image-encoders/WEBPImageEncoder.cpp
[delete] https://crrev.com/e635c3e1ed9ed9a0838beba6893b996a63c3e6a1/third_party/WebKit/Source/platform/image-encoders/WEBPImageEncoder.h

Status: Fixed (was: Assigned)
This is fixed.  The skia encoding APIs are listed here for convenience.
https://cs.chromium.org/chromium/src/third_party/skia/include/encode/SkJpegEncoder.h
https://cs.chromium.org/chromium/src/third_party/skia/include/encode/SkPngEncoder.h
https://cs.chromium.org/chromium/src/third_party/skia/include/encode/SkWebpEncoder.h

When calling into the Skia encoders, a color space will be embedded as long as the SkColorSpace on the input SkPixmap is non-null.  It's worth mentioning that this is currently only supported for color spaces with "numerical" transfer functions.

The unpremultiplication/blending behavior can also be controlled using the SkTransferFunctionBehavior on the various Options structs.  Note that that color correct option (kRespect) is only supported for sRGB and linear transfer functions.

It's also cool to point out that the new encoders support all (valid and logical) SkImageInfos.  So F16, kPremul, kBGRA, etc. are all now supported.  This may particularly useful in the JPEG case, where it appears that we currently unpremultiply before calling the encoder... and then the jpeg encoder redoes the premultiply in order to implement the "kBlendOnToBlack" behavior.  This is not necessary anymore.

Reza, feel free to direct further questions about the API to myself and Leon.

Comment 16 by noel@chromium.org, Jun 2 2017

Cc: noel@chromium.org
"This may particularly useful in the JPEG case, where it appears that we currently unpremultiply before calling the encoder... 

Not quite following.  The web would break if we did what you suggest we are doing, no?  

Before the changes herein, we would send premultipled pixels to the JPEG image encoder, and encode those pixels.  Encoding premultipled pixels forms a composite-over-black as required by the <canvas> spec.

For the WebGL <canvas>, we receive unpremultiplied pixels on readback from the GPU.  And so we must premultiply those pixels before sending them to the JPEG image encoder, again to meet the composite-over-black spec requirement.

Was any of the above changed during the course of this work?
There was no behavior change.

IIUC, as it is currently written, the pixels sent to the ImageEncoders are unpremultiplied.  Blending unpremultiplied pixels onto black is equivalent to doing a premultiply.  Ex:

SrcOver: s*a + d*(1-a) = s*a + 0*(1-a) = s*a

What I was suggesting is that it is now possible the send premultiplied pixels to the encoder.  Which means that blending onto black is equivalent to doing nothing.  I'm suggesting this as a possible optimization because I imagine that we are doing work on readback in order to unpremultiply the pixels.

Comment 18 by noel@chromium.org, Jun 5 2017

> There was no behavior change.

Ah good (there are layout tests covering this).

>IIUC, as it is currently written, the pixels sent to the ImageEncoders are unpremultiplied.

My understanding was that we were always sending premultiplied pixels to the JPEG encoder (see webkit link below).

> What I was suggesting is that it is now possible the send premultiplied pixels to the encoder.  Which means that blending onto black is equivalent to doing nothing.

Good suggestion, but we have been doing the suggested do-nothing optimization to form a composite-over-black for quite some time [1]

[1] https://bugs.webkit.org/attachment.cgi?id=76977&action=prettypatch

> I'm suggesting this as a possible optimization because I imagine that we are doing work on readback in order to unpremultiply the pixels.

It depends on what type of canvas we are reading-back from.

Based on the above link, when we readback from canvas 2d, we receive premultiplied pixels, and we would do the do-nothing optimization: pass the premultiplied pixels directly to the JPEG encoder. Covered by [2] at least.

[2] LayoutTests/canvas/philip/tests/toDataURL.jpeg.alpha.html

However, when we readback from canvas 3d, we receive unpremultiplied pixels.  So we had to premutliply the pixels first, and send the result to the encoder due to the composite over black spec requirement.  Not sure if we have GL tests covering this case?

Comment 19 by xlai@chromium.org, Sep 11 2017

Cc: reed@google.com xlai@chromium.org msarett@chromium.org
 Issue 536926  has been merged into this issue.
Blocking: -713867

Sign in to add a comment