Skip to content

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

Closed

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.

Activity

  1. added theissue type on May 6, 2025
  2. moved this to 👀 Unsorted Items in 37-x-yon May 6, 2025
  3. changed the title [-]nativeImage.toBitmap() doesn't preserve color matrix / color space information.[/-] [+]1nativeImage.toBitmap()1 doesn't preserve color matrix / color space information.[/+] on May 6, 2025
  4. changed the title [-]1nativeImage.toBitmap()1 doesn't preserve color matrix / color space information.[/-] [+]`nativeImage.toBitmap()` doesn't preserve color matrix / color space information.[/+] on May 6, 2025
  5. reitowo commented on May 6, 2025

    @reitowo
    MemberAuthor

    However, as the doc says it is the "native buffer" so I think it might be "technically correct" because color space info doesn't belongs to this buffer 😄 . But then this API is useless if color space is different, and there's no way to compare pixels, we don't even know two nativeImage have different color space.

  6. added
    blocked/need-repro
    on May 6, 2025
  7. electron-issue-triage commented on May 6, 2025

    @electron-issue-triage

    Hello @reitowo. Thanks for reporting this and helping to make Electron better!

    Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

    Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

    Now adding the blocked/need-repro Needs a test case to reproduce the bug label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

  8. reitowo commented on May 7, 2025

    @reitowo
    MemberAuthor
  9. removed
    blocked/need-repro
    on May 7, 2025
  10. added
    has-repro-gist
    on May 7, 2025
  11. 5 remaining items

  12. electron-issue-triage commented on Nov 26, 2025

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  13. reitowo commented on Nov 26, 2025

    @reitowo
    MemberAuthor

    bump

  14. added a commit that references this issue on Jan 24, 2026
    cb2e462
  15. electron-issue-triage commented on Feb 25, 2026

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  16. reitowo commented on Feb 25, 2026

    @reitowo
    MemberAuthor

    Bump

  17. added a commit that references this issue on Mar 23, 2026
    0348df5
  18. added a commit that references this issue on Apr 28, 2026
    b74fd7f
  19. added a commit that references this issue on May 8, 2026
    0e354e8
  20. added a commit that references this issue on May 8, 2026
    c49917c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

37-x-ybug 🪲component/native-imagehas-repro-gistplatform/macOS

Type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions