#1132·ds4

Vision: valid interlaced, 16-bit and low-bit grayscale PNGs are rejected

Author: namespaceMarcelloCreated Sep 25, 2026Updated Sep 25, 2026

ds4_image_decode_memory() returns "invalid or unsupported PNG image" for several kinds of valid PNG, because third_party/iris/png.h accepts only non-interlaced 8-bit images (plus palette images at 1/2/4/8 bits):

  • interlaced (Adam7) images: png_load_mem() fails when the IHDR interlace byte is not 0
  • 16-bit images of any color type (gray, gray+alpha, RGB, RGBA): bit_depth != 8 fails
  • grayscale at 1, 2 or 4 bits, which is common for scanned documents: the same check

The HF preprocessing these models are compared against loads images with PIL, which decodes all of these. Interlaced PNGs still show up on the web, and 16-bit PNGs come out of some screenshot and scientific tools. Today a client sending one gets an error, not a description of the image.

Repro, with no model: generate the images with Python's zlib and decode them with png_load() (the generator is 30 lines, happy to attach it):

rgb8.png         decoded
rgb8_adam7.png   REJECTED
rgb16.png        REJECTED
gray1.png        REJECTED
gray16.png       REJECTED
rgba16.png       REJECTED

The decoder fails closed, so this is not a safety problem. It is missing support, and the "unsupported" wording suggests the limit may be deliberate. Before writing anything: would you take a PR that adds Adam7 deinterlacing, 16-to-8-bit reduction and 1/2/4-bit grayscale expansion to png.h, with generated fixtures and checks in tests/test_image_decode.c like the JPEG ones? If you'd rather keep the decoder small, a clearer error ("interlaced PNG is not supported") would also help clients.

Written by Claude Code (AI assistant) on behalf of @namespaceMarcello, who directs this work.