aboutsummaryrefslogtreecommitdiff
path: root/vendor/exr/examples/4a_write_custom_fixed_channels.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/4a_write_custom_fixed_channels.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/4a_write_custom_fixed_channels.rs')
-rw-r--r--vendor/exr/examples/4a_write_custom_fixed_channels.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/exr/examples/4a_write_custom_fixed_channels.rs b/vendor/exr/examples/4a_write_custom_fixed_channels.rs
new file mode 100644
index 0000000..4eb6f8d
--- /dev/null
+++ b/vendor/exr/examples/4a_write_custom_fixed_channels.rs
@@ -0,0 +1,41 @@
+
+// exr imports
+extern crate exr;
+
+/// Create an image with strange channels and write it to a file.
+fn main() {
+ use exr::prelude::*;
+
+ let pixels = SpecificChannels::build()
+ .with_channel("Kharthanasus Korthus")
+ .with_channel("Y")
+ .with_channel("11023")
+ .with_channel("*?!")
+ .with_channel("`--\"")
+ .with_channel("\r\r\r\n\n")
+ .with_pixel_fn(|position|{
+ if position.0 < 1000 {
+ (f16::from_f32(0.2), 0.666_f32, 4_u32, 1532434.0213_f32, 0.99999_f32, 3.142594_f32/4.0)
+ }
+ else {
+ (f16::from_f32(0.4), 0.777_f32, 8_u32, 102154.3_f32, 0.00001_f32, 3.142594_f32/4.0)
+ }
+ });
+
+ let image = Image::from_channels((2000, 1400), pixels);
+
+ // print progress only if it advances more than 1%
+ let mut current_progress_percentage = 0;
+
+ image.write()
+ .on_progress(|progress| {
+ let new_progress = (progress * 100.0) as usize;
+ if new_progress != current_progress_percentage {
+ current_progress_percentage = new_progress;
+ println!("progress: {}%", current_progress_percentage)
+ }
+ })
+ .to_file("custom_channels.exr").unwrap();
+
+ println!("created file custom_channels.exr");
+} \ No newline at end of file