Skip to content

fix: preserve NativeImage scale factor when serializing single representations - #277

Merged
MarshallOfSound merged 1 commit into
mainfrom
claude/issue-276-nativeimage-scale
Nov 2, 2026
Merged

MarshallOfSound merged 1 commit into
mainfrom
claude/issue-276-nativeimage-scale

Conversation

@claude

@claude claude Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Requested via Slack thread

A NativeImage with a single representation at a scale factor other than 1 came out of remote with the wrong size and scrambled pixels, because serialization sent the bitmap's physical pixels together with the image's DIP size, and the receiving side rebuilt the buffer using those mismatched dimensions. This change sends such images as PNG instead, so the dimensions travel inside the encoding; Electron's addRepresentation already tries PNG decoding first, so deserialization is unchanged, and scale-1 images keep the existing raw bitmap path. New specs round-trip 1.5x and 2x images both directly and over remote in each direction, and they fail without the fix. Credit to @andersk for the diagnosis and for validating this approach at scale factors 1, 1.25, 1.5 and 2 in the issue.

Fixes #276


Generated by Claude Code

…entations

For an image with a single representation, serializeNativeImage sent the
raw bitmap from toBitmap() (physical pixels) together with getSize()
(DIPs). deserializeNativeImage passed that DIP size to addRepresentation,
which reads a raw buffer as width x height pixels, so any image whose
scale factor was not 1 arrived with the wrong dimensions and scrambled
pixels, in both directions.

Keep the raw bitmap at scale factor 1 and send a PNG otherwise.
addRepresentation decodes PNG buffers first and takes the dimensions from
the PNG itself, so deserialization needs no change.

Fixes #276

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PiGRtBhKem5mLgG1cSay1b
@MarshallOfSound
MarshallOfSound marked this pull request as ready for review October 31, 2026 19:48
@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) October 31, 2026 19:49
@MarshallOfSound
MarshallOfSound requested review from a team as code owners October 31, 2026 19:49
@MarshallOfSound
MarshallOfSound merged commit b9cc69b into main Nov 2, 2026
40 checks passed
@MarshallOfSound
MarshallOfSound deleted the claude/issue-276-nativeimage-scale branch November 2, 2026 17:07
@electron-npm-package-publisher

Copy link
Copy Markdown

🎉 This PR is included in version 2.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NativeImage with scale factor is corrupted when passed through remote

3 participants