Skip to content

nativeImage.toBitmap() doesn't preserve color matrix / color space information. #46949

@reitowo

Description

@reitowo

Preflight Checklist

Electron Version

37.0.0

What operating system(s) are you using?

macOS

Operating System Version

macOS 15.4.1

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Expected Behavior

The pixel value should have no difference.

Actual Behavior

The pixel value have significant difference.

Testcase Gist URL

https://gist.github.com/dd7a08a4652da5af679add73d4a92c02

Additional Information

When I'm writing test spec for shared texture, I find out that two visually identical nativeImages, which pixel may have difference in 1-2 per color (#20B14B vs #22B14C)

Image
Image

When called toBitmap, the buffer contains pixel difference way more larger than it should be.

Pixel (127, 120): img1: [88, 175, 85], img2: [76, 177, 34]
Pixel (127, 121): img1: [88, 175, 85], img2: [76, 177, 34]
Pixel (127, 122): img1: [88, 175, 85], img2: [76, 177, 34]
Pixel (127, 123): img1: [88, 175, 85], img2: [76, 177, 34]
Pixel (127, 124): img1: [88, 175, 85], img2: [76, 177, 34]
Pixel (127, 125): img1: [88, 175, 85], img2: [76, 177, 34]
Pixel (127, 126): img1: [88, 175, 85], img2: [76, 177, 34]
Pixel (127, 127): img1: [88, 175, 85], img2: [76, 177, 34]

You can reproduce it by nativeImage.createFromBuffer of these two pictures, and toBitmap, then compare the pixel values.

I think toBitmap or some new method should convert to a unified color space / color matrix to allow pixel compare, otherwise we have no way to compare pixel data.

It is also fun that when Qt rendering this image, it also reads the wrong color. So I suspect it also drops some color space info. However these two images are visually identical when rendered on web browsers.

Note that Windows doesn't have such error.

Metadata

Metadata

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions