Commit Graph
202 Commits
Author SHA1 Message Date
BFlat ffdb249cbe Merge pull request #3322 from dotCooCoo/fix/png-borrow-icc-profile
image-codecs: borrow the ICC profile and EXIF in the PNG header
2026-11-26 10:27:00 +07:00
BFlat 4a078fdac1 Merge pull request #2723 from dotCooCoo/fix/jpegls-restart-marker-after-segment
image-codecs: reject a JPEG-LS restart marker that follows another segment
2026-11-26 10:11:33 +07:00
BFlat 273186cb47 Merge pull request #2709 from dotCooCoo/feat/image-codecs-display-srgb
image-codecs: convert an image's ICC or CICP colors for display
2026-11-26 10:11:11 +07:00
BFlat aa19b389ac Merge pull request #2616 from dotCooCoo/feat/image-codecs-into-rgba8
image-codecs: checked RGBA8 and RGBA16 conversions, and into_rgba8 without a copy
2026-11-26 10:05:47 +07:00
BFlat 4363011a8b Merge pull request #2607 from dotCooCoo/feat/image-codecs-encode-borrowed-rgba8
image-codecs: encode a PNG from borrowed RGBA8 pixels
2026-11-26 10:05:07 +07:00
BFlat 749f21db40 Merge pull request #2597 from dotCooCoo/feat/image-codecs-input-cap
image-codecs: read a file or stream into bytes with a size cap
2026-11-26 10:03:33 +07:00
dotCooCoo a409ba1f32 Merge main into fix/png-borrow-icc-profile 2026-11-25 14:17:24 -08:00
Elvis33LE 2b7d18f1fb deps: migrate craft-image-codecs to jpeg-encoder 0.7.1 2026-11-25 22:35:17 +01:00
aiongg d402a1d71b Gate-sized cases for slow non-UI tests; full sizes and every case nightly
Boundary tests set by a production constant check a small limit through a
private seam that takes it (b64 decode, drawingml table normalize, openpgp
verify), with the real constant nightly; captions and jbig2 check their
full-size boundaries nightly. Sweeps run every divisor-th case at the gate
(develop balanced highlights and thin line, jpeg low-memory tokens, png
streamed rows, mxf extreme fields, pdf crypt proptests), the fax bomb guard
page is wider and shorter, the resample bound pulls a shorter block, the nef
measured frames are read through probe_info, and local tone compares 64 and
256 pixels.
2026-11-25 01:32:48 +00:00
aiongg cbe6812a02 craft-image-codecs tests: smaller bomb-guard, PNG and DDS inputs, sampled fidelity sweep 2026-11-24 19:48:38 +00:00
dotCooCoo d28ad274b3 image-codecs: borrow the ICC profile and EXIF in the PNG header
The PNG writer copied the caller's ICC profile, and the exported EXIF,
into new buffers before writing the header. Each tagged save allocated a
second profile-sized buffer that could abort the process when memory ran
short. The header now borrows the profile, and borrows the EXIF whenever
export_exif returns it unchanged.
2026-11-23 23:58:58 -08:00
aiongg cf35f7dbae Merge remote-tracking branch 'upstream/main' into next-sync-1123
# Conflicts:
#	Cargo.toml
#	crates/audio/src/track.rs
2026-11-23 01:29:52 +00:00
Terra854 1c137fea60 image-codecs: share bounded PNG sRGB metadata writing (#2941)
* image-codecs: share bounded PNG sRGB metadata writing

* png: reject legacy color chunks that conflict with sRGB
2026-11-23 03:38:34 +07:00
Dylan M. Taylor 49f38d0e30 tiff: expose plain RGBA16 without the raster facade (#3082) 2026-11-22 15:16:58 -05:00
Dylan M. Taylor e683cb299f Merge pull request #3067 from storytold/feat/778-strict-jpeg-orientation
jpeg: share strict EXIF orientation framing
2026-11-22 13:17:05 -05:00
DylanMTaylor 7e88389c8e Document legacy JPEG zero-marker handling 2026-11-22 12:20:57 -05:00
Dylan M. Taylor 983a116784 tiff: share the plain RGBA16 writer 2026-11-22 11:06:35 -05:00
Dylan M. Taylor e084f8c1f6 jpeg: share strict EXIF orientation framing 2026-11-22 11:04:24 -05:00
Terra854andFredApps 52d2560c18 image-codecs: share ISO-BMFF brand prefix framing (#2638)
Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
2026-11-22 18:45:42 +07:00
Terra854 e1d62d7e19 image-codecs: share PNG physical resolution writing (#2879) 2026-11-21 12:56:40 -05:00
Dylan M. Taylor c60e7a2006 image-codecs: expose raw PNG pHYs pixels_per_meter reader (#785) (#2865) 2026-11-21 11:39:45 -05:00
dotCooCoo 5d55b9994a image-codecs: convert untagged 16-bit and float RGB without rounding to 8 bits
For an RGB image with no source profile and a display other than sRGB,
`to_display_rgba8` rounded the samples to RGBA8 and then converted them
from sRGB, which lost precision and clipped float values before the
transform. It now converts the samples through the sRGB profile directly,
so the result matches the same image tagged with sRGB. Gray, CMYK and Lab
images without a profile still go through their `to_rgba8` values.
2026-11-20 17:55:32 -08:00
dotCooCoo fcf08f47ef image-codecs: correct the prefix length that detect documents for FF D8
For a buffer of only `FF D8`, `detect_prefix` answers `NeedBytes(4)`,
a 4-byte prefix that includes the SOI, not 4 bytes after it.
2026-11-20 17:16:57 -08:00
dotCooCoo 8b2268a898 image-codecs: AVIF matrix 12 reads unspecified primaries as BT.709
Chromaticity-derived reconstruction (matrix 12) took Kr and Kb from the
raw primaries code, so primaries 2 got BT.2020 weights while the HLG gain
in `cicp::linearize` read them as BT.709. Reconstruction now reads
unspecified primaries as BT.709 too, so a file tagged 2 decodes the same
as one tagged 1. Explicit BT.2020 keeps its weights.
2026-11-20 17:13:37 -08:00
dotCooCoo 0af8630bfb image-codecs: HLG with unspecified primaries uses BT.709 luma weights
The display conversion reads CICP primaries 2 (unspecified) as BT.709,
but the HLG gain in `to_display_rgba8` and in `cicp::linearize` took
BT.2020 luma weights for it, so a chromatic HLG pixel with unspecified
primaries was shown differently from the same pixel tagged BT.709, and
differently again after the HEIF and AVIF readers decoded it to linear
light. Both paths now read unspecified primaries as BT.709 when they
pick the weights. Explicit BT.2020 primaries keep BT.2020 weights.
2026-11-20 15:50:46 -08:00
dotCooCoo 32bba41a91 image-codecs: reject a JPEG-LS restart marker that follows another segment
While a restart interval is in effect, the decoder now rejects a restart
marker anywhere outside a scan's data, including one that comes after a
comment or another segment. Before, only a marker directly after the scan
was rejected, and one after a comment was skipped and the image decoded.
With an interval of 0 a stray restart marker is still skipped.

`detect` documents that a buffer of only `FF D8` matches no format, and
the tests check the error kind of a malformed DRI segment and a DRI change
between the component scans of an RGB file.
2026-11-20 15:47:26 -08:00
dotCooCoo 89ae139a45 image-codecs: convert an image's ICC or CICP colors for display
Image::to_rgba8 changes only the layout and sample type, so an app that
shows the result as sRGB draws a Display P3, Adobe RGB or BT.2020 picture
with the wrong colors.

With the new `cms` feature, Image::source_profile returns the profile
that describes the samples (the embedded ICC profile, or for an RGB
image without one, the profile of its CICP description), and
Image::to_display_rgba8 converts the pixels through craft-cms into a
display profile the caller passes. An image with neither is treated as
sRGB. PQ and HLG samples are decoded to linear light first and clipped
at diffuse white. The output is checked against Limits and reserved
before conversion, and 16-bit and float images are converted in bands.
2026-11-20 14:48:33 -08:00
dotCooCoo c20769e3cc image-codecs: checked RGBA8 and RGBA16 conversions, and into_rgba8 without a copy
Image::try_to_rgba8 and Image::try_to_rgba16 check the output against
Limits and reserve it with try_reserve_exact before any pixel is
converted, as Image::to_rgba_f32 does. A gray image is a quarter of its
RGBA8 copy, so a decode that fits the budget could still allocate past
it when converted. Sources other than U8 and U16 are converted one pixel
at a time, without the whole-image f32 buffers.

Image::into_rgba8 consumes the image and returns the pixel buffer of an
RGBA8 image as it is. A caller that decodes and then needs RGBA8 no
longer holds the decoded image and a copy at once.

to_rgba8 and to_rgba16 convert the pixel data only, without cloning the
image's metadata first.
2026-11-20 10:42:06 -08:00
dotCooCoo a6997e9532 image-codecs: encode a PNG from borrowed RGBA8 pixels
encode_png_rgba8 writes interleaved 8-bit RGBA pixels as a PNG from a
borrowed slice. encode takes an Image, which owns its buffer, so a
caller holding pixels in a frame or a shared buffer had to copy the
whole image before saving it. The output is the same as encode of an
Image with the same pixels, no ICC profile and default metadata. A
buffer whose length is not width * height * 4 is rejected with
InvalidImage.
2026-11-20 10:40:20 -08:00
dotCooCoo 2d5b96929b image-codecs: read a file or stream into bytes with a size cap
The decoders take a byte slice, and Limits bound only the decoded image,
so a caller had to cap and read the input itself. read_bounded(reader,
max_bytes) reads at most one byte past max_bytes and fails with
ErrorKind::FileTooLarge for longer input, including a file that grows
after its size was checked and a stream with no end.
2026-11-20 10:34:27 -08:00
David MannandClaude Opus 5.5 1929e79ebb Merge storytold main into next (20 Nov, second sync)
Merges main at 8f92ed1334 (#2550 and the rest of main since the 20 Nov sync).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 16:38:55 +01:00
yoriswind 0596a975ae Reduce temporary memory when decoding DPX and Cineon
(cherry picked from commit f08789c7a6)
2026-11-20 07:00:55 +01:00
yoriswind 4f31e9c33a Avoid widened sample buffers in eight-bit DPX export
(cherry picked from commit 23393d1def)
2026-11-20 07:00:49 +01:00
FredApps 051ec4fd62 Merge pull request #2389 from yoriswind/codex/shared-dpx-export-u8-r1
Avoid widened sample buffers in eight-bit DPX export
2026-11-20 12:36:48 +07:00
FredApps 54cb4af7e1 Merge pull request #2396 from yoriswind/codex/shared-dpx-decode-widen-r1
Reduce temporary memory when decoding DPX and Cineon
2026-11-20 12:31:20 +07:00
Dylan M. Taylor a7c6c9d61c image-codecs: extract JPEG and JP2 embedding probes (#2498) 2026-11-19 23:32:11 -05:00
Elvis33LE 4b4d5f7a9d fix(exr): stage contained data windows in display canvas (#2033) 2026-11-19 21:30:51 -05:00
aiongg b05c1c27f9 Merge storytold main into next (20 Nov sync) 2026-11-20 01:48:18 +00:00
Dylan M. Taylor 512a1b8e8b mesh, image-codecs: add clearcoat/sheen GLB, obj_with_mtl, and EXR chromaticities (#778) (#2466)
* mesh, image-codecs: add clearcoat/sheen GLB, obj_with_mtl, and EXR chromaticities (#778)

* fix(mesh): import Image and TextureRef in obj tests

* fix(mesh): construct Mesh via struct literal in gltf test
2026-11-19 19:50:59 -05:00
Dylan M. Taylor bc186ca719 image-codecs: keep first JFIF APP0 density in scan_metadata (#2422) 2026-11-19 14:51:45 -05:00
Dylan M. Taylor 41a9edd001 image-codecs: keep resolution probe fallback and container-only WebP EXIF scan (#2409) 2026-11-19 13:11:14 -05:00
aiongg ca58dfe6c9 Merge storytold main into next (19 Nov sync)
Merges main at d7c9632bfb.

- Cargo.toml: both sides' new workspace crates (next's font-subset, harfbuzz-subset-sys and
  host; main's gpu, gpu-null, gpu-providers and gpu-wgpu).
- crates/jpeg: next split lib.rs into modules; main's reduced-size decoding goes to them: the
  scaled IDCT, reconstruction and render_scaled to idct.rs, MAX_SHRINK, reduced_estimate and
  decode_reduced stay public in lib.rs. Main's new test added; the frame test next removed
  stays removed.
- crates/audio, crates/media: next builds the integration tests into the library's test
  executable (autotests off, tests/main.rs); main's new DSD and MPEG-TS mux tests are modules
  there behind their features instead of [[test]] targets, and the mux tests reach their shared
  helper module through the integration module.
- crates/media/src/matroska/track.rs: main's new FFV1 codec-parameter test added; the test
  modules next removed stay removed.
- crates/file-formats: main's JXL capability test, which asks the codec whether JXL reads,
  replaces next's interim check.
2026-11-19 16:22:24 +00:00
Dylan M. Taylor d7c9632bfb image-codecs: add jpeg_with_icc and jpeg_without_icc to jpeg_inks (#2400) 2026-11-19 10:53:18 -05:00
FredAppsandFredApps 30a568b97f image-codecs: expose raw BMP density probe (#2354) [skip ci]
Co-authored-by: FredApps <FredApps@users.noreply.github.com>
2026-11-19 21:26:09 +07:00
yoriswind f08789c7a6 Reduce temporary memory when decoding DPX and Cineon 2026-11-19 01:50:21 -08:00
yoriswind 23393d1def Avoid widened sample buffers in eight-bit DPX export 2026-11-19 01:50:13 -08:00
Diego Chagas 401bf426a6 jxl: charge failed brob inflations, refuse large windows, walk boxes without a span list (#2275)
Follow-up to the brob budget:
- an over-cap or broken stream now charges the bytes it produced to the shared budget, so
  a file of many such streams cannot inflate the whole budget once per box;
- a Brotli header that declares a large window is refused before decoding (the decoder reserves
  its ring buffer up front, outside the output cap);
- boxes are walked one at a time instead of collected into a Vec of spans before the brob check.
image-codecs: document that JPEG XL ignores keep_orientation.
2026-11-19 00:11:50 -05:00
.CooCoo c39072d321 image-codecs: keep PrefixDetector tests within the prefix contract (#2277)
PrefixDetector::detect requires each call's bytes to start with the
previous call's bytes. Two integration tests passed a buffer that broke
that rule, so a detector that rechecks the SOI before resuming would
have failed them while still honoring the contract.

The tests now pass longer prefixes of one file and compare each answer
with detect_prefix on the same bytes. The check that a walk resumes at
the marker it stopped at stays in the jpegls unit tests, and a new unit
test checks that a walk that found a non-JPEG-LS frame header stays at
that marker.
2026-11-18 23:20:49 -05:00
aiongg e8e713ee26 Merge storytold main into next (18 Nov sync)
Merges main at 3b8e426a26.

- crates/ui: main's e-sign dialog (crates/ui/src/esign) moves to craft-cloud-ui beside the
  share dialog, behind craft-cloud-ui's esign feature; craft-ui forwards `esign` and
  re-exports the module.
- crates/proof: main's can_suggest_cased goes to affix/check.rs and its tests to
  affix/tests.rs (next split affix.rs); French wiring in lib.rs.
- crates/svg: main's validated resolver and raster validation stay under tree-render, which
  now also enables gif and image-webp; the shared image-codec helpers are gated on tree.
- craft-ai-agents: main's rev (craft-ai-integrations main), one entry.
- crates/craft: facade dependencies, features and re-exports for main's new crates.
2026-11-18 23:07:38 +00:00
.CooCoo b130ac1fa4 image-codecs: find the JPEG-LS frame header past 64 segments, and add detect_prefix (#2178)
* image-codecs: find the JPEG-LS frame header past 64 segments, and add detect_prefix

detect walked at most 64 marker segments looking for the SOF55 frame
header, so a JPEG-LS file with more segments before its frame header,
such as an ICC profile split over 255 APP2 segments, was reported as
JPEG. The walk now runs until it reaches a frame or scan header or the
end of the bytes. Each step moves forward at least one byte, so the walk
takes at most one step per byte.

detect also reported JPEG for a buffer that ended before the frame
header, which is what a caller that reads only the start of a file
passes. The new detect_prefix returns Detection::NeedBytes(n) in that
case, with the length the next step reads, and otherwise the answer
detect gives. The doc comment on detect now says that it needs the bytes
up to the frame header.

* image-codecs: walk each JPEG marker segment once when detecting in steps

detect_prefix walks the marker segments from the SOI on every call, so a
caller that reads exactly the length each Detection::NeedBytes asks for
walks the earlier segments again on each call. Over a file with many
small segments before its frame header, the total walk grows with the
square of the segment count.

The new PrefixDetector keeps the offset of the marker where its last
walk stopped and starts the next walk there. Its detect gives the same
answer and asks for the same lengths as detect_prefix, and
detect_prefix now runs a single step of a new PrefixDetector.

* image-codecs: read past a JPEG-LS restart interval segment and stop at FF 00

The JPEG-LS frame walk treated a DRI segment before the SOF55 frame header
as the end of the walk, so a file with one was detected and decoded as
JPEG. DRI now takes the length-prefixed path. The decoder accepts a 2-, 3-
or 4-byte interval of 0, reports a nonzero interval as unsupported, and
rejects other segment sizes as malformed.

`FF 00` after the SOI is a stuffed zero, not a marker, so the walk now ends
there instead of asking for a length field.

A PrefixDetector whose walk stopped at another frame header answers JPEG
for bytes that start with `FF D8 FF`, without walking from the SOI again.

* image-codecs: apply the JPEG-LS restart interval in effect at each scan

A later DRI with an interval of 0 turns restarts off again, and an
interval of at least the frame height puts a non-interleaved scan in
one interval with no restart marker. Both decode again. A nonzero
interval shorter than the frame height is still unsupported.

* image-codecs: reject a restart marker after a JPEG-LS scan of one interval

A restart marker comes only between two restart intervals. When the
interval in effect is at least the frame height, the scan is one
interval, so a restart marker after it, with or without fill bytes
before it, is now an error instead of being skipped.

Adds a test that a PrefixDetector starts each call at the marker where
its previous walk stopped.
2026-11-18 15:52:55 -05:00