New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added wide-gamut color support for ui.Image.toByteData
and ui.Image.colorSpace
#40031
Conversation
c019ff1
to
15743a8
Compare
ui.Image.toByteData
and ui.Image.colorSpace
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. |
lib/ui/painting.dart
Outdated
/// The color space that an [Image] uses. | ||
enum ColorSpace { | ||
/// The sRGB color gamut. | ||
sRGB, | ||
/// A color space that is backwards compatible with sRGB but can represent | ||
/// colors outside of that gamut with values outside of [0..1]; | ||
extendedSRGB, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this enum and values probably deserve a lot more explanation. I think @Hixie would probably be interesting in taking a pass over this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I'm finishing up a breaking change notice too that I planned on sharing with him for his review.
lib/ui/painting.dart
Outdated
/// The sRGB color gamut. | ||
sRGB, | ||
/// A color space that is backwards compatible with sRGB but can represent | ||
/// colors outside of that gamut with values outside of [0..1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that for "regular" images we gave colors channel values in the range of 0-255. Does the extended srb use 0-1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you have to use toByteData(ImageByteFormat.rawExtendedRgba128)
to get normalized color components. I can add a note here linking that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(added a note about ImageByteFormat.rawExtendedRgba128)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an impeller-only feature? Does Skia support this? I vaguely recall that it did. If so, we should add a proper CanvasKit implementation for this.
@@ -351,6 +351,8 @@ abstract class Image { | |||
|
|||
List<StackTrace>? debugGetOpenHandleStackTraces() => null; | |||
|
|||
ColorSpace get colorSpace => ColorSpace.sRGB; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like all concrete subclasses are implementing this getter. I think this means that the getter in the base class can be abstract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason all of the other places had to implement it themselves is because they are using implements
instead of extends
. I don't know if there was anyone that was using extends
, but if they were, I wouldn't want them to have to implement this property.
Yep, it's on impeller + iOS currently (and behind a switch which I hope to remove). The skia backend could support it but there are no plans to invest in it. I'd love to have web support too. I don't know what that would entail but webkit can already render wide gamut images for what it's worth. |
ec622be
to
6f36975
Compare
lib/ui/painting.dart
Outdated
/// This value can help you decide which [ImageByteFormat] to use with | ||
/// [Image.toByteData] and is the result of [Image.colorSpace]. | ||
enum ColorSpace { | ||
/// The sRGB color space, the defined standard color space for the web. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the defined standard color space for the web.
This is kind of an odd statement, I'm not sure how that helps me to know what it means for flutter. Perhaps describe this in terms of the values the colors can take and/or what encoding to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this value has any effect on what encoding you should use. The only way I could describe the values would be to list the frequencies in the gamut. Did you have a different idea on how we could specify it? It is kind of weird to list the web standard but it's the only thing I could grasp onto where people would have an existing familiarity with sRGB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined by whom? linking to the relevant standard would be useful for people new to this topic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Citations are provided in the wiki (but it was standardized by the International Electrotechnical Commission (IEC) as IEC 61966-2-1). Linking the wikipedia page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The important part isn't whether or not this is the defined color space for the web. As a flutter developer, what does the web's color space have to do with my application? If we don't have a good answer, maybe just something like "this is the default color space for applications" or something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, reworded it and added note about it being the colorspace of non-wide-gamut apps.
@@ -1591,6 +1605,21 @@ enum ImageByteFormat { | |||
/// image may use a single 8-bit channel for each pixel. | |||
rawUnmodified, | |||
|
|||
/// Raw extended range RGBA format. | |||
/// | |||
/// Unencoded bytes, in RGBA row-primary form with straight alpha, 32 bit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is straight alpha premultiplied or un-premultiplied (post multiplied)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's un-premultiplied, "straight" is the nomenclature we use in the other fields.
@@ -1591,6 +1605,21 @@ enum ImageByteFormat { | |||
/// image may use a single 8-bit channel for each pixel. | |||
rawUnmodified, | |||
|
|||
/// Raw extended range RGBA format. | |||
/// | |||
/// Unencoded bytes, in RGBA row-primary form with straight alpha, 32 bit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this matches the encoding of the dart:ui Color class, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dart:ui Color class is using integer values for components, this is float32.
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
…d `ui.Image.colorSpace` (flutter/engine#40031)
fixes flutter/flutter#121729
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.