diff --git a/crates/exr/src/decode.rs b/crates/exr/src/decode.rs index 94efc864de..9bfdf541ad 100644 --- a/crates/exr/src/decode.rs +++ b/crates/exr/src/decode.rs @@ -1,7 +1,7 @@ //! Bounded OpenEXR reading and writing on top of the `exr` crate (feature `decode`). //! //! - [`parts`] lists every part from the headers alone (size, windows, channels, compression, -//! text attributes), after checking the declared sizes against [`Limits`] and the file's size. +//! views, text attributes), after checking the declared sizes against [`Limits`] and the file's size. //! - [`pick_part`] chooses the part a plain picture decode shows: the best colour channel group //! ([`crate::channels::color_channels`]), the earliest part on a tie. //! - [`decode_part`] decodes the channels of one flat part that a filter keeps, in their stored @@ -161,6 +161,11 @@ pub struct PartInfo { pub name: Option, /// The `view` attribute of a stereo part. pub view: Option, + /// The `multiView` attribute of a single-part stereo file: its view names, the default view + /// first. A channel without a period is the default view's; another view's channels carry + /// the view name before the channel's own (`right.R`, `diffuse.right.R`). Empty without the + /// attribute. + pub multi_view: Vec, pub data_window: Window, pub display_window: Window, pub deep: bool, @@ -317,6 +322,7 @@ pub(crate) fn part_info(index: usize, header: &Header) -> PartInfo { index, name: header.own_attributes.layer_name.as_ref().map(|n| n.to_string()), view: header.own_attributes.view_name.as_ref().map(|v| v.to_string()), + multi_view: header.own_attributes.multi_view_names.iter().flatten().map(|v| v.to_string()).collect(), data_window: Window { x: header.own_attributes.layer_position.0, y: header.own_attributes.layer_position.1, width: w, height: h }, display_window: Window { x: display.position.0, y: display.position.1, width: dw, height: dh }, deep: header.deep, diff --git a/crates/exr/src/decode_tests.rs b/crates/exr/src/decode_tests.rs index 59d2c08ff7..fd279580b6 100644 --- a/crates/exr/src/decode_tests.rs +++ b/crates/exr/src/decode_tests.rs @@ -86,6 +86,32 @@ fn multi_part_files_list_and_decode_one_part() { assert_eq!(pick_part(&[]), None); } +#[test] +fn a_multi_view_part_lists_its_views_default_first() { + let mut stereo = layer(None, 3, 2, &["B", "G", "R", "right.B", "right.G", "right.R"], false, exr::prelude::Compression::ZIP1); + stereo.attributes.multi_view_names = Some(vec![Text::from("left"), Text::from("right")]); + let bytes = file(vec![stereo], (3, 2)); + let listed = parts(&bytes, &Limits::default()).unwrap(); + assert_eq!(listed[0].multi_view, ["left", "right"]); + assert_eq!(listed[0].view, None); + // The decoded part carries the same header facts. + assert_eq!(decode_part(&bytes, 0, &all, &Limits::default()).unwrap().info.multi_view, ["left", "right"]); + // The declared order, not a sorted one: the right view may be the default. + let mut right_first = layer(None, 3, 2, &["B", "G", "R", "left.B", "left.G", "left.R"], false, exr::prelude::Compression::ZIP1); + right_first.attributes.multi_view_names = Some(vec![Text::from("right"), Text::from("left")]); + assert_eq!(parts(&file(vec![right_first], (3, 2)), &Limits::default()).unwrap()[0].multi_view, ["right", "left"]); + + // Parts that each name their own view, and a plain file, have no `multiView`. + let mut left = layer(Some("beauty.left"), 3, 2, &["R"], false, exr::prelude::Compression::ZIP1); + left.attributes.view_name = Some(Text::from("left")); + let mut right = layer(Some("beauty.right"), 3, 2, &["R"], false, exr::prelude::Compression::ZIP1); + right.attributes.view_name = Some(Text::from("right")); + let listed = parts(&file(vec![left, right], (3, 2)), &Limits::default()).unwrap(); + assert_eq!(listed.iter().map(|p| (p.view.as_deref(), p.multi_view.len())).collect::>(), [(Some("left"), 0), (Some("right"), 0)]); + let plain = file(vec![layer(None, 3, 2, &["R"], false, exr::prelude::Compression::ZIP1)], (3, 2)); + assert!(parts(&plain, &Limits::default()).unwrap()[0].multi_view.is_empty()); +} + #[test] fn written_files_read_back() { let h: Vec = (0..6).map(|i| f16::from_f32(i as f32 / 4.0)).collect();