Repository navigation
Conversation
bardrop
force-pushed
the
fix-imagedata-pixel-size
branch
from
November 14, 2026 00:11
2440858 to
f401105
Compare
createImageData(), getImageData() and putImageData() took the bytes per pixel from the Cairo stride divided by the canvas width. The stride pads each row to 4 bytes, so on a narrow A8, A1 or RGB16_565 canvas the ratio was too big (a 1px wide A8 canvas has a 4 byte stride): createImageData returned too much data, getImageData used a padded row step and putImageData read the source rows at the wrong offsets. Use the pixel size of the format instead. A1 stays bit-packed in createImageData. Fixes Automattic#2623
bardrop
force-pushed
the
fix-imagedata-pixel-size
branch
from
November 14, 2026 00:26
f401105 to
921d2e5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for contributing!
Fixes #2623
createImageData(),getImageData()andputImageData()worked out the bytes per pixel ascanvas->stride() / width. Cairo pads every row to 4 bytes, so on a narrow canvas this ratio is not the pixel size. A 1px wide A8 canvas has a 4 byte stride, so:createImageData(1, 2)returned 8 bytes instead of 2 (same for A1 and RGB16_565),getImageData()returned padded rows (a 1x3 A8 read gave 12 bytes),putImageData()read the source rows at the wrong offsets.The fix adds a small
imageDataBytesPerPixel()helper (4 for ARGB32/RGB24/RGB30, 2 for RGB16_565, 1 for A8) and uses it in all three. A1 stays bit-packed increateImageData()(ceil(w * h / 8), which is what the existing A1 test expects). I didn't reuseCanvas::approxBytesPerPixel()because it returns 3 for RGB30, which would change the RGB30createImageData()size.It isn't only 1px canvases:
createImageData()kept the fraction, so a 21px wide A8 canvas (24 byte stride) gave 14 bytes forcreateImageData(2, 6)instead of 12. When the width is already aligned, nothing changes.Testing
test/canvas.test.js(create/get/put on 1px wide A8, A1 and RGB16_565 canvases). All three fail on master, pass with the fix.npm test: 310 passing.npx mocha test/wpt/generated/*.js): same 114 failures before and after, none new.Built locally on macOS arm64 with zig 0.16.0.