Conversation
…sub-byte formats Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes critical bugs in the PNG decoder that prevented correct decoding of 16-bit per-channel images, grayscale+alpha (colorType 4) images, and sub-byte grayscale formats (bitDepth 1/2/4).
Changes:
- Fixed pixel stride calculation for 16-bit images to use actual channel size instead of hardcoded 8-bit offsets
- Added support for PNG colorType 4 (grayscale+alpha) which was previously unsupported
- Corrected scanline length calculation and pixel unpacking for sub-byte grayscale formats (bitDepth 1, 2, 4)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/formats/png_base.ts | Core decoder fix: replaces hardcoded pixel strides with dynamic calculations based on bitDepth and colorType, adds grayscale+alpha handling, and implements proper sub-byte pixel unpacking |
| test/formats/png.test.ts | Adds three decode-only tests with minimal hand-crafted PNG binaries to verify each of the three bug fixes |
| CHANGELOG.md | Documents the three decoder fixes in the Unreleased section under Fixed |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
|
@copilot investigate bun test failures in ci 7 tests failed: |
…with node:zlib fallback Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com> Agent-Logs-Url: https://github.com/cross-org/image/sessions/b9d06be4-3ef7-4982-8355-5e85e31c2768
…ompressionStream hang Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com> Agent-Logs-Url: https://github.com/cross-org/image/sessions/b9d06be4-3ef7-4982-8355-5e85e31c2768
Investigated in e6f28a2. The 7 Bun timeouts are not caused by this PR — they're pre-existing and affect all branches (confirmed the same failures on a completely separate PR run today: Root cause: Bun's Added |
|
@copilot I can not reproduce the bug in the md, please verify that it pinpoints the exact problem Root cause: Bun's CompressionStream("deflate") / DecompressionStream("deflate") hangs indefinitely when piped through Response streams. This blocks PNG/APNG/ICO deflate and TIFF Deflate compression. The same code works in Deno and Node.js. |
Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com> Agent-Logs-Url: https://github.com/cross-org/image/sessions/1b1ba7f0-ce77-47af-888a-de5458bfd268
Removed the file in 4d69bd6. The simple |
|
@copilot fix the failing ci by disabling bun for now |
Fixes critical bugs in the PNG decoder's
unfilterAndConvertmethod.PNG Decoder Fixes (
src/formats/png_base.ts)x*4,x*3,x) — only correct for 8-bit. Now usesx * bytesPerPixelas stride andchannelSize = bitDepth >> 3to address each channel's high byte."Unsupported PNG color type: 4". Now decodes gray + alpha into RGBA correctly.scanlineLengthwaswidth * 1 = widthbytes, but the correct value is⌈width × bitsPerPixel / 8⌉. Now computes the correct byte count and unpacks pixel values via bit-extraction with proper 0–255 scaling. The condition is explicit:if (bitDepth < 8 && (colorType === 0 || colorType === 3))to prevent issues if indexed-color support is added later.Tests Added (
test/formats/png.test.ts)Three new decode-only tests covering each fixed case using minimal hand-crafted PNG binaries.
Bun CI Timeouts (not caused by this PR)
Bun CI shows 7 test timeouts (ICO encode, TIFF Deflate) that are pre-existing and affect all branches — confirmed on a completely separate PR. Root cause has not been determined; a simple
CompressionStream("deflate")reproduction did not hang.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.