Skip to content

Add explicit color management.#2323

Closed
lpy wants to merge 2 commits into
facebook:masterfrom
lpy:colorSpace
Closed

Add explicit color management.#2323
lpy wants to merge 2 commits into
facebook:masterfrom
lpy:colorSpace

Conversation

@lpy

@lpy lpy commented Apr 17, 2019

Copy link
Copy Markdown
Contributor

Color management was introduced in Android O. Currently Fresco allows
applications to specify whether a decoded bitmap should be transformed to SRGB
color space or not at load time, and legacy APIs pass in false, meaning if
applications don't use newer APIs, the decoded bitmap will have the encoded
color space as the final color space if they have one. This doesn't not align
with the world before Android O because before Android O, everything is
essentially treated as SRGB inside the rendering pipeline no matter whether the
images come with a color space.

This patch, 1) Modifies the newer APIs to accept ColorSpace instead of a
boolean, a more future-proof solution as mobile display technology evolves; 2)
Updates legacy APIs to pass in null, meaning on newer devices (API level >=
26), applications that haven't managed color will always get the decoded bitmap
in SRGB color space.

Issue: #2318

Color management was introduced in Android O. Currently Fresco allows
applications to specify whether a decoded bitmap should be transformed to SRGB
color space or not at load time, and legacy APIs pass in false, meaning if
applications don't use newer APIs, the decoded bitmap will have the encoded
color space as the final color space if they have one. This doesn't not align
with the world before Android O because before Android O, everything is
essentially treated as SRGB inside the rendering pipeline no matter whether the
images come with a color space.

This patch, 1) Modifies the newer APIs to accept ColorSpace instead of a
boolean, a more future-proof solution as mobile display technology evolves; 2)
Updates legacy APIs to pass in null, meaning on newer devices (API level >=
26), applications that haven't managed color will always get the decoded bitmap
in SRGB color space.

Issue: facebook#2318
@facebook-github-bot

Copy link
Copy Markdown
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@oprisnik oprisnik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request. Overall, this looks great. I've added some comments & a question but the change is almost good to go.

Please also sign the CLA :)

bitmapConfig);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
options.inPreferredColorSpace = colorSpace == null
? ColorSpace.get(ColorSpace.Named.SRGB) : colorSpace;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you've mentioned, this changes the default behavior for all images >= 26 to force SRGB instead of leaving inPreferredColorSpace at the default null value. However, this change also means that with this API it would not be possible to set inPreferredColorSpace=null.
I'm not sure if somebody would ever want to have this behavior but if we think that somebody might want this, it would be possible to just set the default ColorSpace in ImageDecodeOptions to SRGB and developers can then override it to null, which would enable the inPreferredColorSpace=null mode.
Existing calls that currently pass in null / false since they don't support color spaces could be changed to also pass in SRGB to be consistent.

I can't really think of a good example where this might be needed though, so this version here should be fine as well. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no benefit I can think of to get such behaviour in my humble opinion. One must be very sure about the encoded color space of the contents in order to be confident to skip this bit while also maintain color management in the pipeline. But in that case, the color space is already known in advance, and passing a ColorSpace would make the code more readable as well.

* @param transformToSRGB whether to allow the color space to be transformed to sRGB
* @return this builder
*/
public ImageDecodeOptionsBuilder setTransformToSRGB(boolean transformToSRGB) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to not break the API, we could deprecate this method and just set the color space accordingly (if we decide to support the null variant. Otherwise, this will be a no-op I suppose and we can just remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure this library provides benefit of helping manage color, I would suggest removing this, and don't support the null variant.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@lpy

lpy commented Apr 19, 2019

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, I resolved the last comment and replied the first two comments.

May I ask how to run the tests locally? Android Studio doesn't seem to allow me to run the tests. :) Also, the showcase keep returning error: cannot find symbol class AnimatedDrawable2 in the latest Android Studio, ci/circleci also seems to fail on master :(

@oprisnik

Copy link
Copy Markdown
Contributor

Yeah, the build was broken (I fixed it with 28de385) and our CI is also still acting up. Using Gradle / Android Studio usually works for test.

I'll import your pull request and do some internal testing. Thanks again!

@facebook-github-bot facebook-github-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oprisnik has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@lpy

lpy commented Apr 24, 2019

Copy link
Copy Markdown
Contributor Author

Should I wait for your feedback? May I ask help for CI rerun? I am going to squash into one commit to avoid commit pollution as well.

@lambdapioneer

lambdapioneer commented Apr 24, 2019

Copy link
Copy Markdown
Contributor

Ipy, don't worry about merging the commits. It will automatically be merged under the PR request including the summary when we land this internally.

When landing we'll also be auto-formatting the change to reflect our code style. This includes flipping some annotations as our tools assume @Nonnull be default. After passing our internal tests, this should land soon. (edit: was tomorrow, but it will take a bit more time)

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@oprisnik merged this pull request in 51efaa7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment