aboutsummaryrefslogtreecommitdiff
path: root/vendor/exr/examples/7_crop_alpha_rgba.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
committerValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
commita990de90fe41456a23e58bd087d2f107d321f3a1 (patch)
tree15afc392522a9e85dc3332235e311b7d39352ea9 /vendor/exr/examples/7_crop_alpha_rgba.rs
parent3d48cd3f81164bbfc1a755dc1d4a9a02f98c8ddd (diff)
downloadfparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.tar.xz
fparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.zip
Deleted vendor folder
Diffstat (limited to 'vendor/exr/examples/7_crop_alpha_rgba.rs')
-rw-r--r--vendor/exr/examples/7_crop_alpha_rgba.rs48
1 files changed, 0 insertions, 48 deletions
diff --git a/vendor/exr/examples/7_crop_alpha_rgba.rs b/vendor/exr/examples/7_crop_alpha_rgba.rs
deleted file mode 100644
index 18478d3..0000000
--- a/vendor/exr/examples/7_crop_alpha_rgba.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-
-extern crate image as png;
-
-extern crate exr;
-
-
-/// Read an rgba image, or fail if none can be found.
-/// Then crop away transparent pixels,
-/// and write the cropped result to another file.
-/// This retains only the rgb pixels, and no other layers.
-pub fn main() {
- use exr::prelude::*;
- use exr::image::pixel_vec::*; // import predefined pixel storage
-
- let path = "tests/images/valid/custom/oh crop.exr";
-
- type DynamicRgbaPixel = (Sample, Sample, Sample, Sample); // `Sample` is an enum containing the original data type (f16,f32, or u32)
-
- // load an rgba image
- // this specific example discards all but the first valid rgb layers and converts all pixels to f32 values
- // TODO optional alpha channel!
- let image: PixelImage<PixelVec<DynamicRgbaPixel>, RgbaChannels> = read_first_rgba_layer_from_file(
- path,
- PixelVec::<DynamicRgbaPixel>::constructor,
-
- // use this predefined rgba pixel container from the exr crate, requesting any type of pixels with 3 or 4 values
- PixelVec::set_pixel
- ).expect("this file exists in the exrs repository. download that?");
-
- // construct a ~simple~ cropped image
- let image: Image<Layer<CroppedChannels<SpecificChannels<PixelVec<DynamicRgbaPixel>, RgbaChannels>>>> = Image {
- attributes: image.attributes,
-
- // crop each layer
- layer_data: {
- println!("cropping layer {:#?}", image.layer_data);
-
- // if has alpha, crop it where alpha is zero
- image.layer_data
- .crop_where(|(_r, _g, _b, alpha)| alpha.is_zero())
- .or_crop_to_1x1_if_empty() // do not remove empty layers from image, because it could result in an image without content
- },
- };
-
- image.write().to_file("cropped_rgba.exr").unwrap();
- println!("cropped file to cropped_rgba.exr");
-}
-