aboutsummaryrefslogtreecommitdiff
path: root/vendor/exr/examples/5c_write_mip_maps.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/exr/examples/5c_write_mip_maps.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/exr/examples/5c_write_mip_maps.rs')
-rw-r--r--vendor/exr/examples/5c_write_mip_maps.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/vendor/exr/examples/5c_write_mip_maps.rs b/vendor/exr/examples/5c_write_mip_maps.rs
new file mode 100644
index 0000000..1096c4e
--- /dev/null
+++ b/vendor/exr/examples/5c_write_mip_maps.rs
@@ -0,0 +1,73 @@
+
+extern crate smallvec;
+extern crate rand;
+extern crate half;
+
+
+// exr imports
+extern crate exr;
+
+
+
+/// Writes two layers, each with multiple mip maps.
+/// All mip maps have solid color for brevity.
+fn main() {
+ use exr::prelude::*;
+ use exr::math::RoundingMode;
+ use smallvec::smallvec;
+
+ let full_size = Vec2(512, 512);
+ let size_rounding = RoundingMode::Up;
+
+ let mip_levels_sizes = exr::meta::mip_map_levels(
+ size_rounding, full_size
+ ).collect::<Vec<_>>();
+
+ let red_mip_levels = mip_levels_sizes.iter()
+ .map(|(_index, level_size)|{
+ FlatSamples::F32(vec![0.1_f32; level_size.area() ])
+ })
+ .collect();
+
+ let green_mip_levels = mip_levels_sizes.iter()
+ .map(|(_index, level_size)|{
+ FlatSamples::F32(vec![0.6_f32; level_size.area() ])
+ })
+ .collect();
+
+ let blue_mip_levels = mip_levels_sizes.iter()
+ .map(|(_index, level_size)|{
+ FlatSamples::F32(vec![1.0_f32; level_size.area() ])
+ })
+ .collect();
+
+ let rgb_mip_maps = AnyChannels::sort(smallvec![
+ AnyChannel::new("R", Levels::Mip { level_data: red_mip_levels, rounding_mode: size_rounding }),
+ AnyChannel::new("G", Levels::Mip { level_data: green_mip_levels, rounding_mode: size_rounding }),
+ AnyChannel::new("B", Levels::Mip { level_data: blue_mip_levels, rounding_mode: size_rounding }),
+ ]);
+
+ let layer1 = Layer::new(
+ full_size,
+ LayerAttributes::named("teal rgb"),
+ Encoding::FAST_LOSSLESS,
+ rgb_mip_maps
+ );
+
+ let mut layer2 = layer1.clone();
+ layer2.attributes.layer_name = Some("Copied Layer".into());
+ layer2.encoding = Encoding::SMALL_FAST_LOSSLESS;
+
+ // define the visible area of the canvas
+ let image_attributes = ImageAttributes::new(
+ IntegerBounds::from_dimensions(full_size)
+ );
+
+ let image = Image::empty(image_attributes)
+ .with_layer(layer1).with_layer(layer2);
+
+ println!("writing image...");
+ image.write().to_file("mip_maps.exr").unwrap();
+
+ println!("created file mip_maps.exr");
+} \ No newline at end of file