fix: normalize color space for consistent pixel values in nativeImage#48178
Conversation
|
We might want to consider this a breaking change, just to make sure we don't break any apps relying on the old behavior. |
1445729 to
75f0685
Compare
|
I'll let @reitowo decide! I think breaking change seems reasonable |
codebytere
left a comment
There was a problem hiding this comment.
Conceptually LGTM - i'm leaving semver-major for this as well.
75f0685 to
cb2e462
Compare
|
It only took me forever but I have integrated all feedback and rebased! |
reitowo
left a comment
There was a problem hiding this comment.
API LGTM with a minor nit suggestion
samuelmaddock
left a comment
There was a problem hiding this comment.
API LGTM
Open to include nativeImage.getColorSpace in this PR or separate as per @reitowo's feedback.
Will approve once tests are passing.
|
I think this is ready for merge? |
983322a to
69a031e
Compare
|
@samuelmaddock @codebytere this is green now, anyone want to re-review? |
jkleinsc
left a comment
There was a problem hiding this comment.
We should update the breaking changes to either 42 or 43 depending upon whether or not we want this to land in 42 or 43. I'm fine with it going into 42.
toBitmap() now normalizes the color space to sRGB by default, ensuring that visually identical images produce consistent pixel values regardless of their original color profile (e.g., Display P3 on macOS). An optional colorSpace parameter is added to toBitmap() to control the target color space: 'srgb' (default), 'display-p3', or 'source' (no conversion). Closes electron#46949
Sort ui/gfx/ includes alphabetically: codec/jpeg_codec.h, codec/png_codec.h, then color_space.h.
- Add breaking-changes.md entry for toBitmap() color space normalization under Planned Breaking API Changes (41.0) - Update getBitmap() docs to include colorSpace option and breaking-changes-header since it delegates to toBitmap()
Regenerate the colorspace-srgb.png and colorspace-p3.png test fixtures so they represent the same visual color encoded in two different source color spaces. The updated sRGB fixture stores the color as sRGB pixel values, while the Display P3 fixture stores the corresponding Display P3 pixel values and retains its embedded P3 ICC profile. Even though the source bitmaps can contain different bytes, their outputs should be byte-identical after normalization to the sRGB color space.
da8835a to
a4bb37c
Compare
I think I'd be OK with 42 if anyone feels strongly about it, but -- since it's a month later now -- it feels a little late in the cycle? I've pushed two changes up to unblock this PR:
|
|
Release Notes Persisted
|
|
I have automatically backported this PR to "43-x-y", please check out #51565 |
…#51565) fix: normalize color space for consistent pixel values in nativeImage (#48178) * fix: normalize color space for consistent pixel values in nativeImage toBitmap() now normalizes the color space to sRGB by default, ensuring that visually identical images produce consistent pixel values regardless of their original color profile (e.g., Display P3 on macOS). An optional colorSpace parameter is added to toBitmap() to control the target color space: 'srgb' (default), 'display-p3', or 'source' (no conversion). Closes #46949 * fix: implement feedback * fix: correct include ordering in electron_api_native_image.cc Sort ui/gfx/ includes alphabetically: codec/jpeg_codec.h, codec/png_codec.h, then color_space.h. * docs: add breaking-changes entry and update getBitmap docs - Add breaking-changes.md entry for toBitmap() color space normalization under Planned Breaking API Changes (41.0) - Update getBitmap() docs to include colorSpace option and breaking-changes-header since it delegates to toBitmap() * docs: linter: remove semicolons from js code samples * docs: linter: make change description <= 120 chars * test: fix new colorSpace spec * test: regenerate nativeImage color-space PNG fixtures Regenerate the colorspace-srgb.png and colorspace-p3.png test fixtures so they represent the same visual color encoded in two different source color spaces. The updated sRGB fixture stores the color as sRGB pixel values, while the Display P3 fixture stores the corresponding Display P3 pixel values and retains its embedded P3 ICC profile. Even though the source bitmaps can contain different bytes, their outputs should be byte-identical after normalization to the sRGB color space. * docs: marked breaking change for 43.0 * chore: fix up for lint --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Felix Rieseberg <f@anthropic.com>
Description of Change
This PR normalizes color space so that pixel values in
nativeImagematch if they do match visually to the user. I am not entirely sure whether we actually want this - a priori, I think this feels correct but I'm happy to be corrected.Closes #46949
Checklist
npm testpassesRelease Notes
Notes: fix: If a
nativeImagewas passed an image with a color profile, its pixel values will now be normalized to SRGB. This ensures that two visually identical images after color space application will receive similar pixel values when converted to anativeImage.