From 9bb7b55e0d36024f1c61c4e852eed84f9923faac Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 17:11:03 +0000 Subject: [PATCH 1/3] refactor(exr): decode channels with shared craft exr --- Cargo.lock | 94 +++++--- Cargo.toml | 42 ++-- crates/media/Cargo.toml | 2 +- crates/media/src/exr_channels.rs | 367 ++++++++++++------------------- xtask/src/pdf_deps.rs | 2 +- 5 files changed, 232 insertions(+), 275 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6450c078..64214d619 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,26 +1092,26 @@ dependencies = [ [[package]] name = "craft-aep" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-audio" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9)", "thiserror 2.0.21", ] [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-dpx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "thiserror 2.0.21", ] @@ -1119,7 +1119,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "serde", "serde_json", @@ -1129,30 +1129,34 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-exr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ + "exr", + "flate2", + "half", "serde_json", + "thiserror 2.0.21", ] [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "fixed_decimal", "icu_decimal", @@ -1175,8 +1179,9 @@ dependencies = [ [[package]] name = "craft-lottie" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ + "craft-zip", "serde_json", "thiserror 2.0.21", ] @@ -1184,7 +1189,7 @@ dependencies = [ [[package]] name = "craft-media" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "thiserror 2.0.21", ] @@ -1200,7 +1205,7 @@ dependencies = [ [[package]] name = "craft-mesh" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "miniz_oxide 0.9.1", "serde_json", @@ -1209,7 +1214,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "hayro-syntax", "thiserror 2.0.21", @@ -1218,7 +1223,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "encoding_rs", "flate2", @@ -1229,7 +1234,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "dispatch2", "egui", @@ -1240,19 +1245,21 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "craft-xml", "flate2", "kurbo", "roxmltree", "thiserror 2.0.21", + "vectorcraft-geom", + "vectorcraft-pathops", ] [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "craft-fonts-build", "craft-i18n", @@ -1273,7 +1280,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "chrono", "dunce", @@ -1300,9 +1307,9 @@ dependencies = [ [[package]] name = "craft-video" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9)", "rayon", "thiserror 2.0.21", ] @@ -1310,7 +1317,7 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "thiserror 2.0.21", ] @@ -1318,12 +1325,22 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.3", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -1683,7 +1700,7 @@ name = "effectcraft-export" version = "0.24.1" dependencies = [ "craft-audio", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9)", "craft-video", "effectcraft-color", "effectcraft-effects", @@ -1852,7 +1869,7 @@ dependencies = [ "craft-dpx", "craft-exr", "craft-gif", - "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9)", + "craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9)", "craft-webp", "effectcraft-color", "effectcraft-effects", @@ -3422,7 +3439,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "hayro-ccitt", ] @@ -3436,7 +3453,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=bc3e521bd37e53f2b5b4c55278111b55fd9a40f9#bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", @@ -6683,6 +6700,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "vectorcraft-geom" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "vectorcraft-pathops" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "linesweeper", + "thiserror 2.0.21", + "vectorcraft-geom", +] + [[package]] name = "vello_common" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 1b80048f2..83af23a17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,22 +11,22 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } -craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", features = ["decode"] } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } +craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } +craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9" } # 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 = "47107f660191de2f0b425569506f4daa4faadac9", features = ["egui"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -90,9 +90,9 @@ same-file = "1.0" tempfile = "3.27" # codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev. -craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["isobmff", "matroska"] } -craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } -craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } +craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", default-features = false, features = ["isobmff", "matroska"] } +craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] } +craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] } # footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001). # Only `crates/media`, `crates/export` and `crates/interchange` may depend on these. @@ -122,7 +122,7 @@ half = "2.7" # ui # Shared frontend components; keep this dependency above the engine boundary. # Shared UI and the complete egui family select reviewed immutable commits below. -craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", features = ["serde"] } # `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()` # and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate. egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] } @@ -231,8 +231,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9", version = "=0.3.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } diff --git a/crates/media/Cargo.toml b/crates/media/Cargo.toml index f744c684c..05e05b09c 100644 --- a/crates/media/Cargo.toml +++ b/crates/media/Cargo.toml @@ -32,7 +32,6 @@ filmcraft-mpegts = { workspace = true } filmcraft-frame = { workspace = true } filmcraft-color = { workspace = true } filmcraft-time = { workspace = true } -exr = { workspace = true } image = { workspace = true, features = ["gif", "webp", "tiff", "bmp", "exr", "tga", "hdr"] } rayon = { workspace = true } serde_json = { workspace = true } @@ -40,6 +39,7 @@ thiserror = { workspace = true } log = { workspace = true } [dev-dependencies] +exr = { workspace = true } # Writes the animated GIFs of the tests. gif = { workspace = true } tempfile = { workspace = true } diff --git a/crates/media/src/exr_channels.rs b/crates/media/src/exr_channels.rs index 96b0173cd..ee3cc3ed3 100644 --- a/crates/media/src/exr_channels.rs +++ b/crates/media/src/exr_channels.rs @@ -1,5 +1,5 @@ //! Auxiliary channels from multi-layer OpenEXR files (depth, object / material IDs, normals, -//! Cryptomatte, …) for the 3D Channel effects, read with the pure-Rust `exr` crate. +//! Cryptomatte, …) for the 3D Channel effects, read through the shared `craft-exr` decoder. //! //! Every channel of every layer becomes a plane named `layer.channel` (or just `channel` for //! the unnamed layer), placed in the display window (pixels outside a layer's data window are @@ -18,12 +18,6 @@ use std::sync::{Arc, Mutex, OnceLock, PoisonError}; use effectcraft_raster::channels3d::{BACKGROUND_DEPTH, split_channel}; use effectcraft_raster::{AuxChannels, Image}; use effectcraft_render::reads::{ReadFile, ReadFiles}; -use exr::block::UncompressedBlock; -use exr::block::chunk::TileCoordinates; -use exr::image::read::image::ReadImage; -use exr::image::read::layers::{ChannelsReader, ReadAllLayers, ReadChannels}; -use exr::meta::attribute::SampleType; -use exr::meta::header::Header; use crate::convert::{AlphaOp, float_to_image}; @@ -35,179 +29,20 @@ const MAX_DISPLAY_PIXELS: usize = 1 << 28; use craft_exr::channels::{is_depth, part_channel_name as channel_name}; pub use craft_exr::cryptomatte::parse_manifest; -/// The part name channels are prefixed with (`None`: unnamed). -fn part_name(header: &Header) -> Option { - header.own_attributes.layer_name.as_ref().map(|t| t.to_string()).filter(|s| !s.is_empty()) -} - /// Why an OpenEXR file's pixels can't be decoded when its headers name a compression this build /// can't decompress (HTJ2K, OpenEXR 3.4's High-Throughput JPEG 2000): the decoders only said /// "no non-deep rgb channels" or showed a transparent frame (#482). `None` for other files. pub fn unsupported_compression(bytes: &[u8]) -> Option<&'static str> { - use exr::compression::Compression; - let meta = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(bytes), false).ok()?; - meta.headers + let mut limits = craft_exr::decode::Limits::default(); + limits.max_pixels = u64::MAX; + limits.max_bytes = u64::MAX; + craft_exr::decode::parts(bytes, &limits) + .ok()? .iter() - .any(|h| matches!(h.compression, Compression::HTJ2K32 | Compression::HTJ2K256)) + .any(|part| matches!(part.compression.as_str(), "HTJ2K32" | "HTJ2K256")) .then_some("OpenEXR HTJ2K compression isn't supported yet: re-save the file with ZIP, PIZ or DWAA compression") } -/// Which channels a decode keeps, by plane name, and the display window they are placed in -/// (the first part's, as the `exr` crate reports the image's). -struct Planes<'k> { - keep: &'k dyn Fn(&str) -> bool, - display: exr::meta::attribute::IntegerBounds, -} - -/// One part's kept channels while it is decoded: each line of samples goes straight into its -/// channel's display-window plane (no copy of the part's samples in their own type first). -struct PlanesReader { - /// Per channel of the part: its plane name, sample type and plane (`None`: not kept). - planes: Vec)>>, - /// The data window's position in the display window, and the data window's and display - /// window's sizes. - offset: (i64, i64), - layer: (usize, usize), - display: (usize, usize), - f16s: Vec, - u32s: Vec, - f32s: Vec, - /// The part's channel indices of exact `R`, `G`, `B` and `A`, when it has R, G and B. - rgb: Option<([usize; 3], Option)>, - /// The part's display window differs from the first part's. - own_display: bool, -} - -/// A decoded part: its kept planes (in channel order) and what [`PlanesReader`] found. -struct PartPlanes { - planes: Vec<(String, Vec)>, - /// Positions in `planes` of the part's R, G, B (and A) channels, when it has them and keeps - /// them all. - rgb: Option<([usize; 3], Option)>, - has_rgb: bool, - exact: bool, -} - -impl<'s> ReadChannels<'s> for Planes<'_> { - type Reader = PlanesReader; - - fn create_channels_reader(&'s self, header: &Header) -> exr::error::Result { - if header.deep { - return Err(exr::error::Error::NotSupported("deep data".into())); - } - let dw = self.display; - let display = (dw.size.0, dw.size.1); - // Each channel is a display-window plane: a 60000² window over a 1×1 data window was a - // multi-gigabyte allocation per channel (#2141). - let n = display.0.checked_mul(display.1).filter(|n| *n > 0 && *n <= MAX_DISPLAY_PIXELS).ok_or(exr::error::Error::Invalid("display window".into()))?; - let prefix = part_name(header); - let pos = header.own_attributes.layer_position; - let offset = (i64::from(pos.0) - i64::from(dw.position.0), i64::from(pos.1) - i64::from(dw.position.1)); - let planes = header - .channels - .list - .iter() - .map(|ch| { - let name = channel_name(prefix.as_deref(), &ch.name.to_string()); - let fill = if is_depth(&name) { BACKGROUND_DEPTH } else { 0.0 }; - (self.keep)(&name).then(|| (name, ch.sample_type, vec![fill; n])) - }) - .collect(); - let find = |c: &str| header.channels.find_index_of_channel(&exr::meta::attribute::Text::from(c)); - let rgb = match (find("R"), find("G"), find("B")) { - (Some(r), Some(g), Some(b)) => Some(([r, g, b], find("A"))), - _ => None, - }; - Ok(PlanesReader { - planes, - offset, - layer: (header.layer_size.0, header.layer_size.1), - display, - f16s: vec![], - u32s: vec![], - f32s: vec![], - rgb, - own_display: header.shared_attributes.display_window != dw, - }) - } -} - -impl ChannelsReader for PlanesReader { - type Channels = PartPlanes; - - fn filter_block(&self, tile: TileCoordinates) -> bool { - tile.is_largest_resolution_level() && self.planes.iter().any(Option::is_some) - } - - fn read_block(&mut self, header: &Header, block: UncompressedBlock) -> exr::error::UnitResult { - let ((lw, lh), (w, h)) = (self.layer, self.display); - for line in block.lines(&header.channels) { - let Some(Some((_, kind, plane))) = self.planes.get_mut(line.location.channel) else { continue }; - let (x0, y, count) = (line.location.position.0, line.location.position.1, line.location.sample_count); - // The samples of data-window row `y`, columns `x0..x0 + count`, at display row `ty` - // from display column `tx0`; clipped to the display window. - if y >= lh || x0.checked_add(count).is_none_or(|end| end > lw) { - continue; - } - let Some(ty) = usize::try_from(y as i64 + self.offset.1).ok().filter(|ty| *ty < h) else { continue }; - let tx0 = x0 as i64 + self.offset.0; - let skip = usize::try_from(-tx0).unwrap_or(0).min(count); - let tx = usize::try_from(tx0.max(0)).unwrap_or(usize::MAX); - let take = (count - skip).min(w.saturating_sub(tx)); - let start = ty.checked_mul(w).and_then(|row| row.checked_add(tx)); - let Some(dst) = start.filter(|_| take > 0).and_then(|s| plane.get_mut(s..s.checked_add(take)?)) else { continue }; - match kind { - SampleType::F16 => { - self.f16s.resize(count, exr::prelude::f16::ZERO); - line.read_samples_into_slice(&mut self.f16s)?; - for (d, s) in dst.iter_mut().zip(self.f16s.iter().skip(skip)) { - *d = s.to_f32(); - } - } - SampleType::F32 => { - self.f32s.resize(count, 0.0); - line.read_samples_into_slice(&mut self.f32s)?; - for (d, s) in dst.iter_mut().zip(self.f32s.iter().skip(skip)) { - *d = *s; - } - } - SampleType::U32 => { - self.u32s.resize(count, 0); - line.read_samples_into_slice(&mut self.u32s)?; - for (d, s) in dst.iter_mut().zip(self.u32s.iter().skip(skip)) { - *d = *s as f32; - } - } - } - } - Ok(()) - } - - fn into_channels(self) -> PartPlanes { - // Positions of the kept channels among the kept planes. - let mut at = vec![None; self.planes.len()]; - let mut planes = Vec::with_capacity(self.planes.len()); - for (i, p) in self.planes.into_iter().enumerate() { - if let Some((name, _, data)) = p { - if let Some(slot) = at.get_mut(i) { - *slot = Some(planes.len()); - } - planes.push((name, data)); - } - } - let kept = |i: usize| at.get(i).copied().flatten(); - let has_rgb = self.rgb.is_some(); - let rgb = self.rgb.and_then(|([r, g, b], a)| { - let a = match a { - Some(a) => Some(kept(a)?), - None => None, - }; - Some(([kept(r)?, kept(g)?, kept(b)?], a)) - }); - PartPlanes { planes, rgb, has_rgb, exact: !self.own_display } - } -} - /// How the `image` crate's OpenEXR decoder would show a file: the first part with exact `R`, `G` /// and `B` channels (alpha `A` when it has one, else opaque), placed in the display window with /// 0 outside the data window. @@ -253,73 +88,103 @@ enum Refused { TooLarge(String), } -/// Bytes the planes of the channels `keep` names would take (`None`: not a readable header). -fn planes_bytes(meta: &exr::meta::MetaData, keep: &dyn Fn(&str) -> bool) -> Option { - let dw = meta.headers.first()?.shared_attributes.display_window; - let n = dw.size.0.checked_mul(dw.size.1)?; - let mut kept = 0usize; - for header in meta.headers.iter() { - let prefix = part_name(header); - kept = kept.saturating_add(header.channels.list.iter().filter(|ch| keep(&channel_name(prefix.as_deref(), &ch.name.to_string()))).count()); - } - Some(n.saturating_mul(kept).saturating_mul(std::mem::size_of::())) +/// Bytes the selected channels occupy in the first part's display window. The channel cache +/// reserves this before decoding so concurrent imports cannot exceed its soft budget. +fn planes_bytes(infos: &[craft_exr::decode::PartInfo], keep: &dyn Fn(&str) -> bool) -> Option { + let display = infos.first()?.display_window; + let pixels = u64::from(display.width).checked_mul(u64::from(display.height))?; + let selected = infos.iter().try_fold(0u64, |total, part| { + let count = part.channels.iter().filter(|channel| keep(&channel_name(part.name.as_deref(), &channel.name))).count() as u64; + total.checked_add(count) + })?; + usize::try_from(pixels.checked_mul(selected)?.checked_mul(4)?).ok() } -/// Decode the channels of an EXR file's bytes that `keep` names (by plane name). +/// Decode selected EXR channels through craft-exr, which places each selected block directly +/// into its bounded display-window plane. fn decode(bytes: &[u8], keep: &dyn Fn(&str) -> bool) -> Result { - let meta = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(bytes), false).map_err(|_| Refused::Unreadable)?; - let display = meta.headers.first().ok_or(Refused::Unreadable)?.shared_attributes.display_window; - let need = planes_bytes(&meta, keep).ok_or(Refused::Unreadable)?; - if need > MAX_DECODE_BYTES { - let gb = |b: usize| b as f64 / f64::from(1u32 << 30); + use craft_exr::decode::{self, Error as ExrError, Limits}; + + let mut limits = Limits::default(); + limits.max_pixels = MAX_DISPLAY_PIXELS as u64; + limits.max_bytes = MAX_DECODE_BYTES as u64; + // Header-only checks must not charge channels this caller does not decode. The shared display + // decoder independently checks the exact selected display planes before allocating them. + let mut header_limits = limits; + header_limits.max_width = u32::MAX; + header_limits.max_height = u32::MAX; + header_limits.max_pixels = u64::MAX; + header_limits.max_bytes = u64::MAX; + let infos = decode::parts(bytes, &header_limits).map_err(|e| match e { + ExrError::LimitExceeded(message) => Refused::TooLarge(message), + _ => Refused::Unreadable, + })?; + let display = infos.first().ok_or(Refused::Unreadable)?.display_window; + let needed = planes_bytes(&infos, keep).filter(|bytes| *bytes > 0).ok_or(Refused::Unreadable)?; + if needed > MAX_DECODE_BYTES { + let gb = |b: u64| b as f64 / f64::from(1u32 << 30); return Err(Refused::TooLarge(format!( "its {}×{} OpenEXR channels need {:.1} GB of memory, more than the {:.1} GB one file may use", - display.size.0, - display.size.1, - gb(need), - gb(MAX_DECODE_BYTES) + display.width, + display.height, + gb(needed as u64), + gb(MAX_DECODE_BYTES as u64), ))); } - let read = ReadImage::new(ReadAllLayers { read_channels: Planes { keep, display } }, |_| {}); - let img = read.from_buffered(std::io::Cursor::new(bytes)).map_err(|_| Refused::Unreadable)?; - let dw = img.attributes.display_window; - let mut aux = AuxChannels::new(dw.size.0 as u32, dw.size.1 as u32, 1.0); + + let mut aux = AuxChannels::new(display.width, display.height, 1.0); let mut crypto: HashMap, Option)> = HashMap::new(); - let mut collect_meta = |other: &HashMap| { - for (k, v) in other { - let key = k.to_string(); + let mut rgb = Rgb::None; + for info in infos { + for (key, value) in &info.text_attributes { let Some(rest) = key.strip_prefix("cryptomatte/") else { continue }; let Some((id, field)) = rest.split_once('/') else { continue }; - let exr::meta::attribute::AttributeValue::Text(t) = v else { continue }; - let e = crypto.entry(id.to_string()).or_default(); + let entry = crypto.entry(id.to_string()).or_default(); match field { - "name" => e.0 = Some(t.to_string()), - "manifest" => e.1 = Some(t.to_string()), + "name" => entry.0 = Some(value.clone()), + "manifest" => entry.1 = Some(value.clone()), _ => {} } } - }; - collect_meta(&img.attributes.other); - let mut rgb = Rgb::None; - for layer in img.layer_data { - collect_meta(&layer.attributes.other); - let part = layer.channel_data; - if rgb == Rgb::None && part.has_rgb { + let prefix = info.name.as_deref(); + let exact = info.display_window == display; + let rgb_indices = ["R", "G", "B"].map(|wanted| info.channels.iter().position(|channel| channel.name == wanted)); + let has_rgb = rgb_indices.iter().all(Option::is_some); + let alpha_index = info.channels.iter().position(|channel| channel.name == "A"); + let mut part = decode::decode_display_part( + bytes, + info.index, + keep, + &|name| { + if is_depth(name) { BACKGROUND_DEPTH } else { 0.0 } + }, + &limits, + ) + .map_err(|error| match error { + ExrError::LimitExceeded(message) => Refused::TooLarge(message), + _ => Refused::Unreadable, + })?; + if rgb == Rgb::None && has_rgb { let base = aux.channels.len(); - rgb = match part.rgb { - Some(([r, g, b], a)) if part.exact => { - let picked = [Some(r), Some(g), Some(b), a]; - let depth = picked.iter().flatten().any(|i| part.planes.get(*i).is_some_and(|(n, _)| is_depth(n))); - if depth { Rgb::Unsupported } else { Rgb::Planes([base + r, base + g, base + b], a.map(|a| base + a)) } + let locate = |raw: usize| { + let name = channel_name(prefix, &info.channels.get(raw)?.name); + part.channels.iter().position(|channel| channel.name == name) + }; + rgb = match (rgb_indices[0].and_then(locate), rgb_indices[1].and_then(locate), rgb_indices[2].and_then(locate)) { + (Some(r), Some(g), Some(b)) if exact => { + let a = alpha_index.and_then(locate); + let depth = + [Some(r), Some(g), Some(b), a].into_iter().flatten().any(|i| part.channels.get(i).is_some_and(|channel| is_depth(&channel.name))); + if depth { Rgb::Unsupported } else { Rgb::Planes([base + r, base + g, base + b], a.map(|i| base + i)) } } _ => Rgb::Unsupported, }; } - aux.channels.extend(part.planes); + aux.channels.extend(part.channels.drain(..).map(|channel| (channel.name, channel.samples))); } for (_, (name, manifest)) in crypto { - if let (Some(n), Some(m)) = (name, manifest) { - aux.manifests.push((n, parse_manifest(&m))); + if let (Some(name), Some(manifest)) = (name, manifest) { + aux.manifests.push((name, parse_manifest(&manifest))); } } aux.manifests.sort(); @@ -389,11 +254,16 @@ fn picture_names(aux: &AuxChannels) -> Option<([String; 3], Option)> { /// headers, then only those channels decoded; in a multi-part file the other parts' pixels are /// not even decompressed), with the names of its planes. fn picture_only(bytes: &[u8]) -> Result<(Decoded, [String; 3], Option), Refused> { - let meta = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(bytes), false).map_err(|_| Refused::Unreadable)?; + let mut limits = craft_exr::decode::Limits::default(); + limits.max_width = u32::MAX; + limits.max_height = u32::MAX; + limits.max_pixels = u64::MAX; + limits.max_bytes = u64::MAX; + let meta = craft_exr::decode::parts(bytes, &limits).map_err(|_| Refused::Unreadable)?; let mut names = AuxChannels::new(0, 0, 1.0); - for header in meta.headers.iter() { - let prefix = part_name(header); - names.channels.extend(header.channels.list.iter().map(|ch| (channel_name(prefix.as_deref(), &ch.name.to_string()), vec![]))); + for part in meta { + let prefix = part.name.as_deref(); + names.channels.extend(part.channels.iter().map(|ch| (channel_name(prefix, &ch.name), vec![]))); } let (rgb, a) = picture_names(&names).ok_or(Refused::Unreadable)?; // Planes are looked up by name ignoring case, so every channel that could answer is kept. @@ -672,8 +542,13 @@ impl ChannelCache { /// Decode the file at `path` whose bytes are `bytes` for `slot` (see [`ChannelCache::get`]). fn decode_file(&self, path: &str, slot: &Slot, bytes: &[u8]) -> Option> { // The planes it will allocate count against the budget while it decodes. - if let Ok(meta) = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(bytes), false) - && let Some(need) = planes_bytes(&meta, &|_| true) + let mut limits = craft_exr::decode::Limits::default(); + limits.max_width = u32::MAX; + limits.max_height = u32::MAX; + limits.max_pixels = u64::MAX; + limits.max_bytes = u64::MAX; + if let Ok(infos) = craft_exr::decode::parts(bytes, &limits) + && let Some(need) = planes_bytes(&infos, &|_| true) { self.account(slot, need.min(MAX_DECODE_BYTES)); } @@ -1242,6 +1117,50 @@ mod tests { assert!(aux.get("ViewLayer.Combined.R").is_some()); } + #[test] + fn multipart_fallback_filters_channels_and_reserves_display_planes() { + use exr::prelude::*; + let part = |name: &str, pos: (i32, i32), size: (usize, usize), channels: Vec>| { + let attrs = LayerAttributes { layer_name: Some(Text::from(name)), layer_position: Vec2(pos.0, pos.1), ..Default::default() }; + Layer::new(size, attrs, Encoding::FAST_LOSSLESS, AnyChannels::sort(channels.into())) + }; + let (w, h) = (2usize, 1usize); + let bytes = file( + vec![ + part("Depth", (0, 0), (1, 1), vec![AnyChannel::new("Z", FlatSamples::F32(vec![7.0]))]), + part( + "Beauty", + (1, 1), + (w, h), + vec![ + AnyChannel::new("R", FlatSamples::F32(vec![0.1; w * h])), + AnyChannel::new("G", FlatSamples::F32(vec![0.2; w * h])), + AnyChannel::new("B", FlatSamples::F32(vec![0.3; w * h])), + ], + ), + ], + IntegerBounds::from_dimensions((3, 2)), + ); + let mut limits = craft_exr::decode::Limits::default(); + limits.max_width = u32::MAX; + limits.max_height = u32::MAX; + limits.max_pixels = u64::MAX; + limits.max_bytes = u64::MAX; + let parts = craft_exr::decode::parts(&bytes, &limits).unwrap(); + assert_eq!(planes_bytes(&parts, &|name| name == "Beauty.R"), Some(3 * 2 * 4)); + assert_eq!(planes_bytes(&parts, &|_| false), Some(0)); + + let selected = decode(&bytes, &|name| name == "Beauty.R").unwrap(); + assert_eq!(selected.aux.channels.iter().map(|(name, _)| name.as_str()).collect::>(), ["Beauty.R"]); + assert_eq!(selected.aux.get("Beauty.R").unwrap(), [0.0, 0.0, 0.0, 0.0, 0.1, 0.1]); + + // The old app decoder selected the named beauty part when the first part was depth-only, + // and placed its data into the shared display window; retain that layered-picture result. + let image = layered_image(&bytes).unwrap().to_rgba32f(); + assert_eq!(image.get_pixel(1, 1).0, [0.1, 0.2, 0.3, 1.0]); + assert_eq!(image.get_pixel(0, 0).0, [0.0, 0.0, 0.0, 1.0]); + } + /// Straight RGBA of [`layered_image`] at pixel 0 for a file of single-value channels. fn picture>(channels: &[(S, f32)]) -> Vec { use exr::prelude::*; diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index a4ed9d6dd..d16ba14ee 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -5,7 +5,7 @@ use std::process::Command; use serde_json::Value; -const REV: &str = "47107f660191de2f0b425569506f4daa4faadac9"; +const REV: &str = "bc3e521bd37e53f2b5b4c55278111b55fd9a40f9"; const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> { From 85903800ddbd9d1d4160b902e8b45f8060b39c4c Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 14:46:37 -0500 Subject: [PATCH 2/3] Account selected EXR planes per part and skip unused parts --- crates/media/src/exr_channels.rs | 42 +++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/crates/media/src/exr_channels.rs b/crates/media/src/exr_channels.rs index ebd77f855..13e3c9d93 100644 --- a/crates/media/src/exr_channels.rs +++ b/crates/media/src/exr_channels.rs @@ -88,16 +88,19 @@ enum Refused { TooLarge(String), } -/// Bytes the selected channels occupy in the first part's display window. The channel cache +/// Bytes the selected channels occupy in each part's own display window. The channel cache /// reserves this before decoding so concurrent imports cannot exceed its soft budget. fn planes_bytes(infos: &[craft_exr::decode::PartInfo], keep: &dyn Fn(&str) -> bool) -> Option { - let display = infos.first()?.display_window; - let pixels = u64::from(display.width).checked_mul(u64::from(display.height))?; - let selected = infos.iter().try_fold(0u64, |total, part| { + infos.first()?; + let total = infos.iter().try_fold(0u64, |total, part| { let count = part.channels.iter().filter(|channel| keep(&channel_name(part.name.as_deref(), &channel.name))).count() as u64; - total.checked_add(count) + if count == 0 { + return Some(total); + } + let pixels = u64::from(part.display_window.width).checked_mul(u64::from(part.display_window.height))?; + total.checked_add(pixels.checked_mul(count)?.checked_mul(4)?) })?; - usize::try_from(pixels.checked_mul(selected)?.checked_mul(4)?).ok() + usize::try_from(total).ok() } /// Decode selected EXR channels through craft-exr, which places each selected block directly @@ -151,6 +154,14 @@ fn decode(bytes: &[u8], keep: &dyn Fn(&str) -> bool) -> Result let rgb_indices = ["R", "G", "B"].map(|wanted| info.channels.iter().position(|channel| channel.name == wanted)); let has_rgb = rgb_indices.iter().all(Option::is_some); let alpha_index = info.channels.iter().position(|channel| channel.name == "A"); + // Metadata above still belongs to the file, but an ignored part must not allocate or + // impose its pixel/deep-data limits on the selected picture channels. + if !info.channels.iter().any(|channel| keep(&channel_name(prefix, &channel.name))) { + if rgb == Rgb::None && has_rgb { + rgb = Rgb::Unsupported; + } + continue; + } let mut part = decode::decode_display_part( bytes, info.index, @@ -1172,6 +1183,25 @@ mod tests { assert_eq!(planes_bytes(&parts, &|name| name == "Beauty.R"), Some(3 * 2 * 4)); assert_eq!(planes_bytes(&parts, &|_| false), Some(0)); + // Different display windows must not reserve every part at the first part's size. + let mut varied = parts.clone(); + varied[0].display_window.width = 1; + varied[0].display_window.height = 1; + varied[1].display_window.width = 10; + varied[1].display_window.height = 20; + assert_eq!(planes_bytes(&varied, &|_| true), Some(4 + 10 * 20 * 3 * 4)); + assert_eq!(planes_bytes(&varied, &|name| name == "Beauty.R"), Some(10 * 20 * 4)); + varied[1].display_window.width = u32::MAX; + varied[1].display_window.height = u32::MAX; + assert_eq!(planes_bytes(&varied, &|_| true), None); + assert_eq!(planes_bytes(&varied, &|name| name == "Depth.Z"), Some(4)); + + // Skipping the RGB part preserves the first-RGB fallback state and depth samples. + let depth = decode(&bytes, &|name| name == "Depth.Z").unwrap(); + assert_eq!(depth.rgb, Rgb::Unsupported); + assert_eq!(depth.aux.channels.len(), 1); + assert_eq!(depth.aux.get("Depth.Z").unwrap()[0], 7.0); + let selected = decode(&bytes, &|name| name == "Beauty.R").unwrap(); assert_eq!(selected.aux.channels.iter().map(|(name, _)| name.as_str()).collect::>(), ["Beauty.R"]); assert_eq!(selected.aux.get("Beauty.R").unwrap(), [0.0, 0.0, 0.0, 0.0, 0.1, 0.1]); From 234273d9b86cfd447b73732efd36698d092d2c0f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 07:44:53 +0100 Subject: [PATCH 3/3] docs(exr): note the shared decoder's all-channel data-window bound --- crates/media/src/exr_channels.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/media/src/exr_channels.rs b/crates/media/src/exr_channels.rs index 13e3c9d93..3463cf663 100644 --- a/crates/media/src/exr_channels.rs +++ b/crates/media/src/exr_channels.rs @@ -112,7 +112,10 @@ fn decode(bytes: &[u8], keep: &dyn Fn(&str) -> bool) -> Result limits.max_pixels = MAX_DISPLAY_PIXELS as u64; limits.max_bytes = MAX_DECODE_BYTES as u64; // Header-only checks must not charge channels this caller does not decode. The shared display - // decoder independently checks the exact selected display planes before allocating them. + // decoder independently checks the exact selected display planes before allocating them. It + // also bounds a selected part's data window across all of its channels (decoded blocks carry + // every channel before the unused ones are dropped), so a part whose full channel set exceeds + // `max_bytes` is refused even when the kept planes alone would fit. let mut header_limits = limits; header_limits.max_width = u32::MAX; header_limits.max_height = u32::MAX;