Skip to content

fix: normalize color space for consistent pixel values in nativeImage#51565

Merged
ckerr merged 1 commit into43-x-yfrom
trop/43-x-y-bp-fix-normalize-color-space-for-consistent-pixel-values-in-nativeimage-1778266657839
May 8, 2026
Merged

fix: normalize color space for consistent pixel values in nativeImage#51565
ckerr merged 1 commit into43-x-yfrom
trop/43-x-y-bp-fix-normalize-color-space-for-consistent-pixel-values-in-nativeimage-1778266657839

Conversation

@trop
Copy link
Copy Markdown
Contributor

@trop trop Bot commented May 8, 2026

Backport of #48178

See that PR for details.

Notes: fix: If a nativeImage was 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 a 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: Charles Kerr <charles@charleskerr.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

Co-authored-by: Felix Rieseberg <f@anthropic.com>
@trop trop Bot requested a review from a team as a code owner May 8, 2026 18:57
@trop trop Bot added 43-x-y backport This is a backport PR semver/major incompatible API changes labels May 8, 2026
@ckerr ckerr merged commit c49917c into 43-x-y May 8, 2026
79 checks passed
@ckerr ckerr deleted the trop/43-x-y-bp-fix-normalize-color-space-for-consistent-pixel-values-in-nativeimage-1778266657839 branch May 8, 2026 23:18
@release-clerk
Copy link
Copy Markdown

release-clerk Bot commented May 8, 2026

Release Notes Persisted

fix: If a nativeImage was 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 a nativeImage.

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

Labels

43-x-y backport This is a backport PR semver/major incompatible API changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant