Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6e93286
Decode AVIF through shared image codecs
dylanmtaylor Nov 15, 2026
fd903de
Include JPEG encoder distribution notices
dylanmtaylor Nov 15, 2026
daed3a3
Exercise AVIF HDR decoding through public API
dylanmtaylor Nov 15, 2026
a47ba5b
Preserve AVIF source bit depth
dylanmtaylor Nov 15, 2026
ad442f3
Test AVIF alpha through public entrypoints
dylanmtaylor Nov 15, 2026
7d6f6fa
Update AVIF round trip for supported decode
dylanmtaylor Nov 15, 2026
55e9889
Document native AVIF decode support
dylanmtaylor Nov 15, 2026
797b3ef
Clarify import feature gates
dylanmtaylor Nov 15, 2026
99c47f7
Keep RAW fixtures valid under shared container and strip bounds
dylanmtaylor Nov 15, 2026
4225ae3
Merge main without regressing AVIF shared dependency alignment
dylanmtaylor Nov 15, 2026
dea4c9d
Include sample-to-chunk mappings in CR3 fixtures
dylanmtaylor Nov 15, 2026
e4c89d7
Find Similar test: a photo read from memory isn't a missing read (#3823)
Bruno-Alumn Nov 5, 2026
3455e4f
Find Similar test: every photo is measured after the resumed search
Bruno-Alumn Nov 5, 2026
e44fab5
Integrate main JPEG cutover while retaining AVIF source-depth pin
dylanmtaylor Nov 15, 2026
dfe879a
Bound AVIF padded picture storage and preserve integer source flag
dylanmtaylor Nov 15, 2026
c6e5789
Merge main and pin shared crates to craft-libs#1679 merge
FredApps Nov 16, 2026
3ef50ea
Size the AVIF picture-store budget for the stored canvas, not the cla…
FredApps Nov 16, 2026
4d1001c
Attribute the AVIF lossless decode fixture
FredApps Nov 16, 2026
111f31f
Keep the AVIF clap test helpers free of unwrap for the codecs lint gate
FredApps Nov 16, 2026
d8cc1eb
Merge remote-tracking branch 'origin/main' into t4312
FredApps Nov 16, 2026
efc47ac
Merge remote-tracking branch 'origin/main' into t4312
FredApps Nov 16, 2026
1c86e96
Merge remote-tracking branch 'origin/main' into t4312
FredApps Nov 16, 2026
70d26b6
Merge remote-tracking branch 'origin/main' into HEAD
dylanmtaylor Nov 17, 2026
ac118ad
lightcraft: keep the newer craft-cms pin after merging main
dylanmtaylor Nov 17, 2026
1b6b4b4
Merge remote-tracking branch 'origin/main' into HEAD
dylanmtaylor Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 39 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ repository = "https://github.com/storytold/lightcraft"
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["serde"] }
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
# Canon CRW decoder shared with the other Craft apps
craft-crw = { git = "https://github.com/storytold/craft-libs", rev = "94777dcf7f8962476e96b049d08d22e25b9330c2" }
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "94777dcf7f8962476e96b049d08d22e25b9330c2" }
craft-crw = { git = "https://github.com/storytold/craft-libs", rev = "6325cd286bd87effa3020b01d6b9d289d4f7c055" }
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18", version = "0.1.0" }
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "6325cd286bd87effa3020b01d6b9d289d4f7c055" }
craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", features = ["frames"] }
craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", default-features = false, features = ["decode", "encode"] }
# Photo metadata: EXIF, IPTC-IIM, XMP packets and GPX track logs (craft-libs#949)
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "94777dcf7f8962476e96b049d08d22e25b9330c2" }
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "6325cd286bd87effa3020b01d6b9d289d4f7c055" }
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "478c50560d3c6fad3d613af2a30b35c3bc9f4c0f" }
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "478c50560d3c6fad3d613af2a30b35c3bc9f4c0f" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" }
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "6325cd286bd87effa3020b01d6b9d289d4f7c055" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "6325cd286bd87effa3020b01d6b9d289d4f7c055" }
# craft-update: app-specific pretend versions apply to startup and manual checks.
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] }
craft-window = { git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["egui"] }
Expand All @@ -41,10 +41,10 @@ lightcraft-wincolor = { path = "crates/wincolor" }
lightcraft-color = { path = "crates/color" }
lightcraft-raster = { path = "crates/raster" }
# TIFF/IFD: the shared reader and writer (moved from crates/tiff; craft-libs#783).
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "94777dcf7f8962476e96b049d08d22e25b9330c2" }
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "6325cd286bd87effa3020b01d6b9d289d4f7c055" }
# Camera raw files, the format layer: every maker but CR3, ARW, RAF, RW2 and ORF (craft-libs#862 and the maker PRs).
# On the same commit as craft-tiff: its errors and IFDs are shared.
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "94777dcf7f8962476e96b049d08d22e25b9330c2" }
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "6325cd286bd87effa3020b01d6b9d289d4f7c055" }
lightcraft-raw = { path = "crates/raw" }
lightcraft-codecs = { path = "crates/codecs" }
lightcraft-meta = { path = "crates/meta" }
Expand Down
2 changes: 1 addition & 1 deletion crates/codecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jxl = ["dep:craft-jxl"]
# PhotoCraft); `cargo xtask ci` clippies and tests it (`--features heif`), releases don't ship it yet.
heif = ["dep:craft-heif"]
## AVIF encoding via ravif/rav1e (pure Rust, BSD). Native targets only; a no-op on wasm32.
avif = ["dep:ravif", "dep:rav1e", "dep:avif-serialize"]
avif = ["dep:ravif", "dep:rav1e", "dep:avif-serialize", "craft-image-codecs/avif-decode"]

[dev-dependencies]
# tests record why they skip (`cargo xtask ci` lists the skips)
Expand Down
4 changes: 2 additions & 2 deletions crates/codecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ Run `cargo test --release -p lightcraft-codecs --test it bench:: -- --ignored --

## Gaps / limitations

- **AVIF decode**: no permissively licensed, pure-Rust AV1 decoder exists today (dav1d is C;
rav1d-safe is AGPL). Files are sniffed and rejected with `Error::Unsupported`.
- **AVIF decode** uses the shared pure-Rust AV1 decoder on native builds with the `avif` feature.
Animated AVIF, depth and gain-map auxiliary images, and progressive/layered images are unsupported.
- **HEIC** needs the `heif` feature (off by default: HEVC patents are the distributor's call);
without it, `Error::Unsupported` says the build has no HEIC support. 4:2:2 and 4:4:4 HEIF
(Canon/Sony HIF) is refused: heic-rs 0.1.1 loses sync on those bitstreams.
Expand Down
93 changes: 93 additions & 0 deletions crates/codecs/src/avif_decode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//! AVIF container and pixel decoding via shared image codecs.
use crate::{DecodeOptions, Decoded, Error, Format, Result};

const F: Format = Format::Avif;

#[cfg(not(all(feature = "avif", not(target_arch = "wasm32"))))]
pub(crate) fn header(_: &[u8]) -> Result<(u32, u32, u16)> {
Err(Error::Unsupported(F, "AVIF decoding is not included in this build"))
}
#[cfg(not(all(feature = "avif", not(target_arch = "wasm32"))))]
pub(crate) fn decode(_: &[u8], _: &DecodeOptions) -> Result<Decoded> {
Err(Error::Unsupported(F, "AVIF decoding is not included in this build"))
}

#[cfg(all(feature = "avif", not(target_arch = "wasm32")))]
fn err(e: craft_image_codecs::CodecError) -> Error {
match e {
craft_image_codecs::CodecError::LimitExceeded(_) => Error::TooLarge(0, 0),
craft_image_codecs::CodecError::Unsupported { .. } => Error::Unsupported(F, "unsupported AVIF"),
other => Error::Malformed(F, other.to_string()),
}
}
#[cfg(all(feature = "avif", not(target_arch = "wasm32")))]
pub(crate) fn header(bytes: &[u8]) -> Result<(u32, u32, u16)> {
let (w, h) = craft_image_codecs::probe_size(bytes).map_err(err)?;
Ok((w, h, 1))
}
#[cfg(all(feature = "avif", not(target_arch = "wasm32")))]
pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result<Decoded> {
use crate::convert::{Buf, Meta, Model, Raw, check_size, finish};
use crate::space::SourceSpace;
let (w, h, _) = header(bytes)?;
check_size(F, w as u64, h as u64, opts)?;
let options = craft_image_codecs::DecodeOptions {
limits: craft_image_codecs::Limits {
max_width: u32::MAX,
max_height: u32::MAX,
max_pixels: opts.max_pixels,
max_alloc: opts.max_pixels.saturating_mul(32),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
},
keep_orientation: false,
};
let (img, bit_depth) = craft_image_codecs::decode_avif_with_depth(bytes, &options).map_err(err)?;
let (w, h) = (img.width(), img.height());
check_size(F, w as u64, h as u64, opts)?;
let buf = match img.sample_type() {
craft_image_codecs::SampleType::U8 => Buf::U8(img.as_u8().ok_or_else(|| Error::Malformed(F, "expected 8-bit samples".into()))?.to_vec()),
craft_image_codecs::SampleType::U16 => Buf::U16(img.to_u16_samples().ok_or_else(|| Error::Malformed(F, "expected 16-bit samples".into()))?),
craft_image_codecs::SampleType::F32 => Buf::F32(img.to_f32_samples().ok_or_else(|| Error::Malformed(F, "expected float samples".into()))?),
_ => return Err(Error::Unsupported(F, "unsupported AVIF sample type")),
};
let hint = img.cicp.and_then(|c| SourceSpace::from_cicp(c.primaries, c.transfer));
let raw = Raw { width: w as usize, height: h as usize, model: Model::Rgb, alpha: img.layout().has_alpha(), premultiplied: false, buf, bit_depth };
let meta = Meta { icc: img.icc, exif: img.meta.exif, xmp: img.meta.xmp, orientation: Some(1), hint, ..Default::default() };
finish(F, raw, meta, (w, h), opts)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

#[cfg(all(test, feature = "avif", not(target_arch = "wasm32")))]
mod tests {
use super::*;
const FIXTURE: &[u8] = include_bytes!("../tests/fixtures/quad-444-gbr-lossless.avif");
#[test]
fn production_entrypoints_decode_avif_and_enforce_pixel_budget() {
assert!(F.can_decode());
assert_eq!(crate::sniff(FIXTURE), Some(F));
let header = crate::read_header(FIXTURE).unwrap();
assert_eq!((header.width, header.height, header.orientation), (33, 17, 1));
let decoded = crate::decode(FIXTURE, DecodeOptions::default()).unwrap();
assert_eq!((decoded.source_width, decoded.source_height), (33, 17));
assert_eq!(decoded.bit_depth, 8);
let opts = DecodeOptions { max_pixels: 100, ..DecodeOptions::default() };
assert!(matches!(crate::decode(FIXTURE, opts), Err(Error::TooLarge(..))));
}
#[test]
fn hdr_avif_round_trips_highlights_through_public_decoder() {
let pixels = vec![2.0f32; 16 * 16 * 3];
for transfer in [crate::encode::HdrTransfer::Pq, crate::encode::HdrTransfer::Hlg] {
let bytes = crate::encode::encode_avif_hdr(16, 16, &pixels, 95, 10, &crate::encode::EncodeMeta::default(), transfer).unwrap();
let decoded = crate::decode(&bytes, DecodeOptions::default()).unwrap();
assert_eq!(decoded.bit_depth, 10);
assert!(decoded.image.data.iter().any(|pixel| pixel[0] > 1.0), "HDR highlights were lost");
}
}
#[test]
fn avif_alpha_survives_public_round_trip() {
let pixels = [200u8, 100, 50, 96].repeat(16 * 16);
let image = crate::encode::EncodeImage::new(16, 16, 4, crate::encode::Samples::U8(&pixels));
let bytes = crate::encode::encode_avif(&image, 95, 10, &crate::encode::EncodeMeta::default()).unwrap();
let decoded = crate::decode(&bytes, DecodeOptions::default()).unwrap();
let alpha = decoded.alpha.expect("alpha plane");
assert!((alpha.data[0] - 96.0 / 255.0).abs() < 0.04);
}
}
5 changes: 4 additions & 1 deletion crates/codecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#![forbid(unsafe_code)]
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]

mod avif_decode;
mod convert;
pub mod display;
pub mod encode;
Expand Down Expand Up @@ -221,6 +222,7 @@ pub fn read_header_unguarded(bytes: &[u8], format: Format) -> Result<Header> {
Format::WebP => webp::header(bytes)?,
Format::Psd => psd::header(bytes)?,
Format::Heif => heif::header(bytes)?,
Format::Avif => avif_decode::header(bytes)?,
Format::Gif | Format::Bmp => other::header(bytes, format)?,
// rare here (or, for JPEG XL, without a header reader yet): a small decode, as before
_ => {
Expand Down Expand Up @@ -257,7 +259,8 @@ pub fn decode_unguarded(bytes: &[u8], format: Format, opts: &DecodeOptions) -> R
#[cfg(not(feature = "jxl"))]
Format::Jxl => unsupported(),
Format::Heif => heif::decode(bytes, &opts),
Format::Avif | Format::RawTiffLike | Format::RawOther => unsupported(),
Format::Avif => avif_decode::decode(bytes, &opts),
Format::RawTiffLike | Format::RawOther => unsupported(),
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/codecs/src/sniff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ impl Format {
Format::Jxl => Some("built without the `jxl` feature"),
#[cfg(not(feature = "heif"))]
Format::Heif => Some(crate::heif::NOT_IN_BUILD),
Format::Avif => Some("no pure-Rust, permissively licensed AV1 decoder yet"),
#[cfg(not(all(feature = "avif", not(target_arch = "wasm32"))))]
Format::Avif => Some("AVIF decoding is not included in this build"),
Format::RawTiffLike | Format::RawOther => Some("camera raw: decode with lightcraft-raw"),
_ => None,
}
Expand Down
12 changes: 12 additions & 0 deletions crates/codecs/tests/fixtures/avif-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# AVIF decode fixtures

Small AVIF files from an independent encoder (libaom through FFmpeg 7.1), for `src/codecs/avif_decode.rs`.

- `quad-source.rgb`: the 33×17 source, raw RGB24 four-colour quadrants (red, green, blue, near-white).
- `quad-420-bt709.avif`: 8-bit 4:2:0, limited range, BT.709 matrix, odd size (FFmpeg leaves the primaries and transfer unspecified):
`ffmpeg -f rawvideo -pix_fmt rgb24 -s 33x17 -i quad-source.rgb -c:v libaom-av1 -crf 12 -still-picture 1 -pix_fmt yuv420p -colorspace bt709 -color_primaries bt709 -color_trc iec61966-2-1 -color_range tv quad-420-bt709.avif`
- `quad-420-bt709.dav1d.yuv`: that file's AV1 picture as libdav1d decodes it, planar 8-bit 4:2:0 (Y, then Cb, then Cr):
`ffmpeg -c:v libdav1d -i quad-420-bt709.avif -f rawvideo -pix_fmt yuv420p quad-420-bt709.dav1d.yuv`
- `quad-444-gbr-lossless.avif`: lossless 8-bit 4:4:4 with the identity (GBR) matrix, full range:
`ffmpeg -f rawvideo -pix_fmt rgb24 -s 33x17 -i quad-source.rgb -c:v libaom-av1 -crf 0 -still-picture 1 -pix_fmt gbrp -colorspace rgb -color_range pc quad-444-gbr-lossless.avif`.
It decodes to `quad-source.rgb` exactly.
Binary file not shown.
3 changes: 2 additions & 1 deletion crates/codecs/tests/it/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ fn avif_encode_native() {
if cfg!(feature = "avif") {
let b = r.unwrap();
assert_eq!(sniff(&b), Some(Format::Avif));
assert!(matches!(decode(&b, DecodeOptions::default()), Err(Error::Unsupported(Format::Avif, _))));
let decoded = decode(&b, DecodeOptions::default()).unwrap();
assert_eq!((decoded.source_width, decoded.source_height), (64, 48));
} else {
assert!(r.is_err());
}
Expand Down
Loading
Loading