Files
craft-libs/crates/image-codecs/src
Martin BallandClaude Sonnet 5.5 93dac78c93 craft-image-codecs: wrap a clipboard DIB as a BMP (dib_to_bmp, dib_layout) (#2062)
* image-codecs: wrap a clipboard DIB as a BMP (#778)

Add bmp_probe::dib_to_bmp (prepend the 14-byte file header, pixel offset
from the header with saturating arithmetic, try_reserve for the output)
and bmp_probe::dib_layout (V4/V5 alpha-mask BI_RGB becomes BI_BITFIELDS,
mask copy after the header). Both are ported from WordCraft's
crates/geom/src/picture.rs so it can drop its local copies. Tests compare
byte-for-byte with the originals over crafted DIBs and every prefix, and
decode wrapped results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* image-codecs: fix DIB offsets for V2/V3 bitfields and ambiguous mask copies (#778)

- dib_to_bmp no longer adds 12 appended-mask bytes to the pixel offset for 52- and
  56-byte BI_BITFIELDS headers, which carry their masks inside the header; the
  decoder reads the pixels at bfOffBits, so the offset was 12 bytes too far.
- dib_layout treats 12 bytes after the header that equal the masks as an existing
  copy only when more bytes follow than the pixels need, so an exact-length DIB
  whose pixels equal the masks gets its copy inserted.
- dib_layout reserves the 12 bytes before changing compression or masks, so a
  failed reservation returns the DIB unchanged; the mask bytes are a [u8; 12]
  array, not a heap copy.

The differential tests against the WordCraft originals now exclude exactly the
52/56-byte bitfields offset and the exact-length payload cases, and assert the new
behaviour for them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 14:45:56 -05:00
..
…
…
…
…
…
…