Skip to content

Accept 16-bit PNG input by stripping samples to 8 bits - #316

Open
malventano wants to merge 1 commit into
NVIDIA:mainfrom
malventano:fix/png-16bit
Open

malventano wants to merge 1 commit into
NVIDIA:mainfrom
malventano:fix/png-16bit

Conversation

@malventano

Copy link
Copy Markdown

Why: Image admission rejects every 16-bit PNG with HTTP 400 "PNG requires
non-animated, at most 8-bit samples". 16-bit samples occur in HDR screenshots
and in exports from image editors, with iPhone HDR screenshots as one source.
A client that attaches such a file loses the whole reply. Pillow-backed
serving accepts these files by retaining the high byte of each sample.

What changed: decode_png requests EXPAND and STRIP_16 and rejects only
animated PNG. The png strip transform keeps the high byte, so the existing
RGB8 loop and RgbImage need no depth branch. The decode test checks 16-bit
RGB, RGBA, and grayscale output against known high-byte values and still
checks truncated input rejection. helios/README.md records the conversion
and the remaining animated PNG rejection.

Benefit: 16-bit PNG input decodes to the same RGB8 bytes Pillow produces, so
these files are admitted instead of failing the request.

Evidence: cargo test --features images png_drops_alpha passed. A 1320x2868
16-bit iPhone HDR screenshot decoded by the patched code was byte identical
to Pillow 13.0.0 Image.open(...).convert("RGB"). The same file returned 200
from a local build of Flare v0.1.0 (0572fd1) with this patch, serving
DeepSeek V4.1 Flash, both directly and through Open WebUI 0.13.3. Animated
PNG remains rejected and was not exercised beyond the existing decode error
path.

Prepared by DSV4.1-Flash-1017 running on Flare v0.1.0 (0572fd1) with this
patch applied.

Image admission rejects every 16-bit PNG with HTTP 400 "PNG requires
non-animated, at most 8-bit samples". 16-bit samples occur in HDR
screenshots and in exports from image editors, with iPhone HDR
screenshots as one source. An OpenAI-compatible client that attaches
such a file loses the whole reply. Pillow-backed serving accepts these
files by retaining the high byte of each 16-bit sample.

decode_png now requests EXPAND and STRIP_16 and rejects only animated
PNG. The png crate strip transform keeps the high byte, so the existing
RGB8 loop and RgbImage need no depth branch. The decode test checks
16-bit RGB, RGBA, and grayscale output against known high-byte values
and still checks truncated input rejection. helios/README.md records the
conversion and the remaining animated PNG rejection.

16-bit PNG input now decodes to the same RGB8 bytes Pillow produces, so
these files are admitted instead of failing the request.

Validation: cargo test --features images png_drops_alpha passed. A
1320x2868 16-bit iPhone HDR screenshot decoded by the patched code was
byte identical to Pillow 13.0.0 Image.open(...).convert("RGB") for the
same file. The same file returned 200 from a local build serving
DeepSeek V4.1 Flash, both directly and through Open WebUI 0.13.3.
Animated PNG remains rejected and was not exercised beyond the existing
decode error path.

Signed-off-by: Allyn Malventano <malventano@users.noreply.github.com>
Design-Signed-Off-By: Allyn Malventano; design-review=ed22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant