Commit Graph
47 Commits
Author SHA1 Message Date
FredApps 28e1b05e3c Merge pull request #1774 from vangel76/perf/dds-bc45-1766
DDS textures: normal maps and grayscale maps save compressed (BC5/BC4), and DDS saves and opens faster
2026-11-16 19:55:31 +01:00
FredApps a58989cae9 image-codecs: skip a SubIFDs array whose offset is cut off (#1889)
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.
2026-11-16 10:26:36 -05:00
Dylan M. Taylor 731c4f262a Merge pull request #1758 from dotCooCoo/fix/exr-deep-part-tables-end
craft-exr: deep chunk offsets start after every part's offset table
2026-11-16 05:46:49 -05:00
ljkx 7adcc9a6c2 image-codecs: BMP keeps its resolution in the header's pixels per metre
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.
2026-11-16 10:05:03 +01:00
FredApps a499742a93 Merge pull request #1779 from storytold/image-codecs/jpeg-stored-inks
feat(image-codecs): read four-component JPEGs as stored inks
2026-11-16 04:48:49 +01:00
FredApps 2f10c9389e Merge pull request #1782 from storytold/image-codecs/jpeg-zune-panic
fix(image-codecs): read the JPEGs zune-jpeg panics on with craft-jpeg
2026-11-16 04:08:51 +01:00
FredApps 1b00186ae0 Merge pull request #1687 from storytold/codex/shared-font-plan-cache
Share per-face shaping plan cache
2026-11-16 04:01:15 +01:00
FredApps 9baecfa4a1 Merge origin/main; route frames zune-jpeg may panic on to craft-jpeg where panics abort
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.
2026-11-16 02:54:50 +01:00
FredApps c28356d400 Merge pull request #1660 from storytold/codex/legacy-exif-orientation
Share legacy EXIF summary and preserve PNG orientation
2026-11-16 02:48:31 +01:00
FredApps 5b5f42961c Merge pull request #1672 from storytold/codex/sunraster-main-reconcile
craft-image-codecs: add opt-in Sun Raster reader and writer
2026-11-16 02:41:41 +01:00
FredApps 4a70763629 fix(image-codecs): refuse JPEG inks of frames too large for their scan data
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.
2026-11-16 02:39:34 +01:00
FredApps 832883b5b4 Merge pull request #1755 from storytold/image-codecs/probe-size-png-jpeg-tiff
image-codecs: probe PNG, JPEG and TIFF sizes from the header
2026-11-16 02:38:50 +01:00
FredApps 7d1d64fc46 Merge remote-tracking branch 'origin/main' into w1687
# Conflicts:
#	crates/font-catalog/src/tests.rs
2026-11-16 02:31:10 +01:00
vangel76 7c34335afb Merge remote-tracking branch 'upstream/main' into perf/dds-bc45-1766 2026-11-16 01:34:47 +01:00
vangel76 39e1d41af7 DDS: refuse premultiplied-alpha DX10 textures
The DX10 header's alpha mode (miscFlags2, low three bits) was never
read, so RGBA, BGRA, BC2 and BC3 files marked premultiplied were read
as straight alpha. They are refused as Unsupported, like the legacy
DXT2/DXT4 FourCCs. Alpha modes 0, 1, 3 and 4 and the formats without
alpha are unchanged.
2026-11-16 01:34:20 +01:00
FredApps fc1801a3aa Merge remote-tracking branch 'origin/main' into image-codecs/jpeg-zune-panic 2026-11-16 01:33:19 +01:00
FredApps 12fdc6571f Merge remote-tracking branch 'origin/main' into w1672 2026-11-16 01:27:27 +01:00
FredApps 1b71cd1c18 Merge pull request #1667 from storytold/codex/sgi-main-reconcile
Reconcile SGI codec with merged JPEG-LS support
2026-11-16 01:26:24 +01:00
FredApps 159d7134d0 fix(image-codecs): read the JPEGs zune-jpeg panics on with craft-jpeg
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.
2026-11-16 01:13:19 +01:00
FredApps a61b1ad53c fix(image-codecs): JPEG inks of frames zune-jpeg panics on are an error 2026-11-16 01:05:44 +01:00
FredApps 927eabc6e6 feat(image-codecs): a JPEG's declared size from its headers, as zune-jpeg reads them 2026-11-16 00:52:35 +01:00
FredApps a6c3feafd9 Merge remote-tracking branch 'origin/codex/legacy-exif-orientation' into w-1668 2026-11-16 00:50:40 +01:00
FredApps 2c2fcd1a28 image-codecs: cover the legacy Sony lossless YCbCr rule and skipped directories 2026-11-16 00:50:39 +01:00
FredApps 473753b58c feat(image-codecs): read four-component JPEGs as stored inks
A jpeg_inks module for apps that keep a CMYK JPEG's inks the way zune-jpeg
readers gave them: every four-component file taken as Adobe-inverted, YCCK
turned into CMYK as libjpeg does (truncating), only the 8-bit Huffman frames
zune-jpeg decodes (arithmetic-coded and 12-bit files are refused), within
Limits. Also the frame's component count and the assembled ICC profile from
the headers alone. Refs #778.
2026-11-16 00:44:58 +01:00
FredApps 010d1c1f00 Merge remote-tracking branch 'origin/main' into image-codecs/probe-size-png-jpeg-tiff
# Conflicts:
#	crates/image-codecs/src/lib.rs
2026-11-16 00:38:11 +01:00
vangel76 c27333683a DDS: time decoding a 30 MP texture too
An ignored test beside the encode timings: the best of five decodes of
the same texture written with each compression. It uses only the API
the reader had before, so it runs on the old code for comparison.
2026-11-16 00:00:28 +01:00
vangel76 f31c93cf59 DDS: read and write BC4 and BC5 (grayscale data and normal maps)
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.
2026-11-16 00:00:28 +01:00
vangel76 e70cceae33 DDS: pin the writer's and reader's output as SHA-256 digests
Digests of uncompressed, BC1, BC2 and BC3 textures, with and without
mip chains, from deterministic odd-sized pictures (ramps, noise, flat
tiles, alpha at 0, 255 and in between) in RGBA, RGB, gray with alpha
and gray, and of decoding those files and hand-built ones in the other
stored layouts. The table is filled from the unchanged code; on a
mismatch the test prints every digest it computed.
2026-11-16 00:00:28 +01:00
FredApps 59b4f1e8c2 image-codecs: decode AVIF pixels with the pure-Rust AV1 decoder (#778) (#1601)
* 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.
2026-11-15 23:25:25 +01:00
FredApps 048c93634a image-codecs: probe PNG, JPEG and TIFF sizes from the header
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.
2026-11-15 22:15:55 +01:00
dotCooCoo 90b6cbef8a craft-exr: deep chunk offsets must follow every part's offset table
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.
2026-11-15 13:13:48 -08:00
Dylan M. Taylor 741323cbc3 Merge remote-tracking branch 'origin/codex/sgi-main-reconcile' into codex/sunraster-main-reconcile
# Conflicts:
#	crates/image-codecs/README.md
#	crates/image-codecs/src/codecs.rs
#	crates/image-codecs/src/format.rs
#	crates/image-codecs/src/lib.rs
#	crates/image-codecs/tests/it/detect_caps.rs
2026-11-15 17:32:32 +00:00
Dylan M. Taylor 90df9a4d99 Gate SGI codec support behind explicit feature 2026-11-15 17:28:29 +00:00
Dylan M. Taylor 9f18482853 Merge remote-tracking branch 'origin/main' into codex/sgi-main-reconcile
# Conflicts:
#	crates/image-codecs/README.md
#	crates/image-codecs/src/format.rs
#	crates/image-codecs/src/lib.rs
#	crates/image-codecs/tests/it/detect_caps.rs
2026-11-15 17:26:03 +00:00
Dylan M. Taylor 1fb21f0487 Share legacy TIFF RAW classification policy 2026-11-15 17:25:28 +00:00
Dylan M. Taylor f5a22a008c Merge pull request #1576 from el-j/feat/image-codecs-jpegls
craft-image-codecs: JPEG-LS reader and writer
2026-11-15 12:22:57 -05:00
Dylan M. Taylor c393428049 Merge pull request #1461 from storytold/fix/png-bounded-row-stream
image-codecs: bound PNG row streaming without a full-frame allocation
2026-11-15 11:01:29 -05:00
el-j 3ce92b332d craft-image-codecs: JPEG-LS (ITU-T T.87) reader and writer
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
2026-11-15 12:53:20 +01:00
el-j 5628ad359d craft-image-codecs: Sun Raster image reader and writer
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
2026-11-15 11:49:53 +01:00
el-j 2e3ff2162b craft-image-codecs: SGI image reader and writer
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
2026-11-15 11:44:48 +01:00
.CooCoo b63198042b craft-image-codecs: check the deep EXR corpus against pinned SHA-256 values (#1487)
The deep EXR corpus test read the five OpenEXR files in corpus/exr/
without a size bound or digest check, and a missing file failed with
advice to run `cargo xtask corpus --exr`, which craft-libs does not have.

- REAL_FILE_SHA256 pins the five files (OpenEXR commit 69b2604f). The
  test reads only those names, refuses a file that is missing, is not
  a regular file, is larger than 4 MiB or does not match its digest,
  and names the file and both digests.
- The failure points at the crate README, which says where the files
  come from and how to fill corpus/exr/, either from OpenEXR or with
  PhotoCraft's fetcher at the commit CI uses.
- Three tests that run without the corpus feature cover the pins, a
  changed byte, and missing, oversize and folder inputs.
2026-11-15 04:11:00 -05:00
Dylan M. Taylor c0ce055384 image-codecs: bound PNG row streaming independently of full output 2026-11-14 20:04:36 -05:00
Dylan M. Taylor c2a69bbdc6 Preserve unmarked CMYK JPEG samples 2026-11-14 13:23:47 +00:00
aiongg ea1c84290d image-codecs: list InkSet and ExtraSamples on TiffPage (#1307)
* image-codecs: list InkSet and ExtraSamples on TiffPage

* image-codecs: TiffPage InkSet and ExtraSamples as enums

* image-codecs: InkSet::InkNames, and Invalid for undefined tag values
2026-11-14 07:18:01 -05:00
Dylan M. Taylor 1532c43674 Align EXIF thumbnail test with shared metadata 2026-11-13 07:33:07 -05:00
Dylan M. Taylor 3bdf0eaadd Format shared image codec crate 2026-11-13 00:17:35 -05:00
Dylan M. Taylor 9430f2807e Add shared image codec facade 2026-11-13 00:17:04 -05:00