Repository navigation
fix(web): pasted 16-bit PNG photos upload at 8 bits per channel - #40949
emmanuelchucks wants to merge 4 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The automated pipeline stopped on this pull request and will not merge it: the fix is written and reviewed, but proving it needs something no worker has:
It stays open for a person to finish or close. |
Problem
On a Mac, copying a photo on an iPhone and pasting it into the composer (Universal Clipboard) gives the browser a 16-bit RGBA PNG with a Display P3 profile. Mine was 1042×1389 and 8,711,193 bytes, from a 4032×3024 HDR JPEG.
compressImageToByteLimitonly redraws an image whose longest edge is over 2000px, so this one uploads byte for byte.Over my upload link (Starlink, about 0.1–0.4 MB/s) the server's
AttachmentUploadstorespans for these pastes took 20.7 s and 76.6 s. I also gave up on a few pastes that looked stuck and pasted again; their traces haveissueUrlanddeletePendingbut nostore.Change
fitImageToMaxEdge(nowfitImageForAttachment) also redraws a PNG whose IHDR bit depth is 16, at its own size. It goes through the same canvas path as the over-2000px case, so it stays a PNG, now at 8 bits per channel, in its own colour space (Display P3 is kept byreadImageColorSpace).Scope
A small fix for an obvious bug, so no issue. #20106 hit the same gap (images under 2000px are never re-encoded) when large images broke mid-turn Claude requests. It closed when Claude Code fixed its side, which left the upload size as it was.
Left out on purpose:
fitComposerImagehas the same edge-only rule. I didn't check whether iOS hands the app a 16-bit PNG, so it's unchanged.Verification
New case in
imageCompression.browser.test.ts: a Display P3 PNG drawn on afloat16canvas (Chromium writes it as 16-bit) comes back as an 8-bit PNG of the same size with the same colours, raw and colour-managed. Onmainit fails withexpected undefined to deeply equal { width: 300, height: 400 }, because the file passes through untouched.New case in
imageCompression.test.ts: a 16-bit PNG whose redraw comes out larger is kept as is.I ran
prepareImageForAttachmentin the Chromium test runner on two real pastes:mainPreparing took about 180 ms. For the first one I compared every pixel with the original: none differ, both colour-managed in P3 and raw, and the output carries the P3 profile.
vp run check:changedpasses.Not checked: Safari and Firefox, and the mobile app.
Code written with Claude Code (Claude Opus 5.5).