camera_raw_mode read a missing SubIFDs offset as 0, so it walked the TIFF
header as the pointer array and could classify a malformed TIFF as RAW.
Skip the entry instead, matching LightCraft's classifier.
A BMP stores its resolution in biXPelsPerMeter and biYPelsPerMeter
(BITMAPINFOHEADER and later). The image crate writes 0 there and nothing
read the fields, so a 300 ppi image saved as BMP reopened at 72 ppi and an
opened BMP's resolution was lost (storytold/photocraft#13630).
decode now reads the fields into Metadata::dpi, encode writes
Metadata::dpi into them whatever embed_metadata says, and
caps(Format::Bmp).dpi is true. encode_bmp_indexed_with_dpi is the palette
writer with a resolution; encode_bmp_indexed keeps its signature and output.
On panic = "abort" targets (wasm32) the catch_unwind fallback can't run, so
frames whose first component is sampled below the frame's largest factors
go to craft-jpeg before zune-jpeg is called.
zune-jpeg allocates its whole output before reading a scan, so
decode_jpeg_inks now applies decode's scan-data guard (one byte for every
2048 pixels, counted on scan data, not APP padding) first. The comparison
test's noise is computed in u64, so it doesn't overflow on 32-bit targets.
zune-jpeg 0.5 asserts in its upsampler on some subsampled four-component
frames whose first component isn't the largest. decode now catches that
panic and reads the file with craft-jpeg, as it reads arithmetic-coded and
12-bit files. Refs #778.
BC4 is one block of 16 single-channel values and BC5 two of them, the
block BC3 already stores its alpha in, so the alpha block encoder and
decoder now serve all three (BC3's output stays the same).
Reading: ATI1 and BC4U, and DXGI 79 (typeless) and 80, open as gray;
ATI2 and BC5U, and DXGI 82 (typeless, as Pillow writes it) and 83,
open as RGB with blue 0. ATI2 follows Microsoft's mapping, red in the
first block. Signed BC4S/BC5S and DXGI 81/84 are refused, naming SNORM.
Writing: DdsCompression::Bc4 (bc4, ati1) from gray and Bc5 (bc5, ati2)
from RGB, with the DX10 header (BC4_UNORM, BC5_UNORM, one 2D texture),
mip chains included. The encode plan converts other layouts to gray
and RGB, so the fidelity warnings report colour to gray and dropped
alpha; BC5's dropped blue is documented under LossyCompression.
DdsCompression is now #[non_exhaustive] and ALL has six entries.
craft-dds holds the header parsing, the uncompressed and BC1-BC3
readers and writers and the block encoder, with its own pixel layout
and error types and rayon behind a `parallel` feature. It parses the
header first (Texture::parse) so a caller can check the size against
its limits before anything is allocated.
craft-image-codecs reads and writes DDS through it, re-exports its
DdsCompression and DdsOptions and maps its errors onto CodecError with
the same messages, so its API and output stay the same. Apps that only
need DDS can depend on craft-dds without the other codecs and their
licences.
* image-codecs: decode AVIF pixels with craft-video's pure-Rust AV1 decoder
New optional `avif-decode` feature (native targets) reads still AVIF
files: the HEIF/ISOBMFF item graph, grids, clap/irot/imir, alpha
auxiliary images (including premultiplied), 8/10/12-bit 4:0:0, 4:2:0,
4:2:2 and 4:4:4, nclx/ICC colour, Exif and XMP, and PQ/HLG to linear
F32 through cicp::linearize as the HEIF path does.
The container walk follows LightCraft #3017 by @emmertex. Every size is
checked against the caller's Limits before the AV1 decoder runs, the
decoder's memory budget is capped by max_alloc, and the decode is
wrapped in catch_unwind so a decoder panic becomes an error.
Fixtures are tiny ffmpeg/libaom files; the 4:2:0 planes match libdav1d
bit for bit. Adds a decode_avif fuzz target.
Part of storytold/craft-libs#778.
* image-codecs, video: address review on the AVIF decoder
- clap: width and height are unsigned fractions, the offsets have signed
numerators, so 0x80000000/0x40000000 is a width of 2, not -2.
- An item with clap, irot or imir more than once (repeated ipma records)
is refused before any canvas work, instead of rotating 261120 times.
- Matrix coefficients 10 (BT.2020 constant luminance) is refused rather
than converted with the non-constant-luminance equations.
- An alpha plane whose own transforms differ from the colour's is refused
rather than composed in the wrong place; none, or the colour's, still
decode.
- craft-video: Decoder::set_shown_budget lowers the per-chunk byte cap on
shown pictures (never above 1 GiB), and the AVIF decoder sets it to
max_alloc, so a payload of many shown pictures is refused before they
are built.
probe_size returned Unsupported for PNG, JPEG and TIFF, so callers sized
those images with a full decode. Each now reads only its header with the
checks decode runs: PNG's IHDR/fcTL, limits and plausibility; JPEG's
first frame header and EXIF; TIFF's default page directory, camera-raw
refusal and Orientation tag. The size is turned upright for 5-8, as
decode returns it.
In a multipart file the chunks start after the offset tables of all
parts. The deep readers in craft-exr and craft-image-codecs took the end
of the deep part's own table as the start of the chunk area, so an
offset into a later part's table passed the chunk-area check and its
bytes were parsed as a chunk.
Both readers now compute where the deep part's table starts and where
the last table ends with checked arithmetic, and refuse a file whose
tables run past its end before reading any offsets. The earlier tables'
sizes are no longer capped or saturated.
Tests build a two-part file from scratch (a deep part and a 1x1 flat
part, in both orders): the deep part decodes as in a single-part file,
an offset into the second table or one byte before the end of the
tables is refused, and a file that ends inside the second table is
refused.
Addresses review findings: a 1-bit file with an RGB colour map reads as
colour; the unused first byte of standard 32-bit pixels is no longer read
as alpha; the writer's buffer is reserved with try_reserve_exact. README
lists the native layouts correctly.
Addresses review findings: the RLE size check no longer demands separate
payload space for every row, and a row offset inside the offset tables is
refused. A row without its trailing zero count still reads, as in ffmpeg.
New optional `avif-decode` feature (native targets) reads still AVIF
files: the HEIF/ISOBMFF item graph, grids, clap/irot/imir, alpha
auxiliary images (including premultiplied), 8/10/12-bit 4:0:0, 4:2:0,
4:2:2 and 4:4:4, nclx/ICC colour, Exif and XMP, and PQ/HLG to linear
F32 through cicp::linearize as the HEIF path does.
The container walk follows LightCraft #3017 by @emmertex. Every size is
checked against the caller's Limits before the AV1 decoder runs, the
decoder's memory budget is capped by max_alloc, and the decode is
wrapped in catch_unwind so a decoder panic becomes an error.
Fixtures are tiny ffmpeg/libaom files; the 4:2:0 planes match libdav1d
bit for bit. Adds a decode_avif fuzz target.
Part of storytold/craft-libs#778.
Adds Format::JpegLs: lossless and near-lossless gray and RGB, 2 to 16
bits. Reads scans that code one component each; writes lossless 8- and
16-bit gray and RGB. Line- and sample-interleaved scans, mapping tables
and colour transforms are reported as unsupported.
Closes#1558
Adds Format::SunRaster: 1-, 8- (gray or colour-mapped), 24- and 32-bit
files, uncompressed or byte-encoded (RLE) on read, uncompressed on write.
Closes#1560
Adds Format::Sgi: 8- and 16-bit gray, gray+alpha, RGB and RGBA, verbatim
and run-length encoded on read, run-length encoded on write.
Palette-mapped files are reported as unsupported.
Closes#1559