From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- vendor/exr/examples/5d_write_legacy_layers.rs | 73 +++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 vendor/exr/examples/5d_write_legacy_layers.rs (limited to 'vendor/exr/examples/5d_write_legacy_layers.rs') diff --git a/vendor/exr/examples/5d_write_legacy_layers.rs b/vendor/exr/examples/5d_write_legacy_layers.rs new file mode 100644 index 0000000..7276c7f --- /dev/null +++ b/vendor/exr/examples/5d_write_legacy_layers.rs @@ -0,0 +1,73 @@ + +#[macro_use] +extern crate smallvec; +extern crate rand; +extern crate half; + + +// exr imports +extern crate exr; + +// TODO create a dedicated reader and writer for this scenario + +/// Generate an image with channel groups and write it to a file. +/// Some legacy software may group layers that contain a `.` in the layer name. +/// +/// Note: This is an OpenEXR legacy strategy. OpenEXR supports layers natively since 2013. +/// Use the natively supported exrs `Layer` types instead, if possible. +/// +fn main() { + use exr::prelude::*; + // TODO simplify handling these types of layers using read() and write() + + let size = Vec2(512, 512); + + let create_channel = |name: &str| -> AnyChannel { + let color: f16 = f16::from_bits(rand::random::()); + + AnyChannel::new( + name, + FlatSamples::F16(vec![color; size.area() ]) + ) + }; + + + // The channels have the following structure: + // + // - Object + // - Red + // - Green + // - Blue + // - Alpha + + // - Background + // - Red + // - Green + // - Blue + + let foreground_r = create_channel("Object.R"); + let foreground_g = create_channel("Object.G"); + let foreground_b = create_channel("Object.B"); + let foreground_a = create_channel("Object.A"); + + let background_r = create_channel("Background.R"); + let background_g = create_channel("Background.G"); + let background_b = create_channel("Background.B"); + + let layer = Layer::new( + size, + LayerAttributes::named("test-image"), + Encoding::FAST_LOSSLESS, + AnyChannels::sort(smallvec![ // the order does not actually matter + foreground_r, foreground_g, foreground_b, foreground_a, + background_r, background_g, background_b + ]), + ); + + let image = Image::from_layer(layer); + + println!("writing image {:#?}", image); + image.write().to_file("groups.exr").unwrap(); + + println!("created file groups.exr"); +} \ No newline at end of file -- cgit v1.2.3