Debian Codegraph @

examples/1a_write_rgba_with_metadata.rs

raw symbols SCIP
1
2 // exr imports
3 extern crate exrrust-analyzer cargo exr 1.74.0 exr/;
4
5 /// Write an rgba exr file, generating the pixel values on the fly.
6 /// This streams the generated pixel directly to the file,
7 /// never allocating the actual total pixel memory of the image.
8 fn mainrust-analyzer cargo exr 1.74.0 main().() {
9 use exrrust-analyzer cargo exr 1.74.0 crate/::preluderust-analyzer cargo exr 1.74.0 prelude/::*;
10 use exrrust-analyzer cargo exr 1.74.0 crate/::metarust-analyzer cargo exr 1.74.0 meta/::attributerust-analyzer cargo exr 1.74.0 meta/attribute/::*;
11
12 // this function can generate a color for any pixel
13 let generate_pixels = |position: Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#<usize>| (
14 position.xrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]x().() as f32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div().2048.0, // red
15 position.yrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]y().() as f32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div().2048.0, // green
16 1.0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().(position.yrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]y().() as f32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div().2048.0), // blue
17 1.0 // alpha
18 );
19
20 let mut layer_attributes = LayerAttributesrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#::namedrust-analyzer cargo exr 1.74.0 meta/header/impl#[LayerAttributes]named().("generated rgba main layer");
21 layer_attributes.commentsrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#comments. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Textrust-analyzer cargo exr 1.74.0 meta/attribute/Text#::fromrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][`From<&'s str>`]from().("This image was generated as part of an example"));
22 layer_attributes.ownerrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#owner. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Textrust-analyzer cargo exr 1.74.0 meta/attribute/Text#::fromrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][`From<&'s str>`]from().("The holy lambda function"));
23 layer_attributes.software_namerust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#software_name. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Textrust-analyzer cargo exr 1.74.0 meta/attribute/Text#::fromrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][`From<&'s str>`]from().("EXRS Project"));
24 layer_attributes.exposurerust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#exposure. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1.0);
25 layer_attributes.focusrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#focus. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(12.4);
26 layer_attributes.frames_per_secondrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#frames_per_second. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((60, 1));
27 layer_attributes.otherrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#other..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(
28 Textrust-analyzer cargo exr 1.74.0 meta/attribute/Text#::fromrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][`From<&'s str>`]from().("Layer Purpose (Custom Layer Attribute)"),
29 AttributeValuerust-analyzer cargo exr 1.74.0 meta/attribute/AttributeValue#::Textrust-analyzer cargo exr 1.74.0 meta/attribute/AttributeValue#Text#(Textrust-analyzer cargo exr 1.74.0 meta/attribute/Text#::fromrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][`From<&'s str>`]from().("This layer contains the rgb pixel data"))
30 );
31
32 let layer = Layerrust-analyzer cargo exr 1.74.0 image/Layer#::newrust-analyzer cargo exr 1.74.0 image/impl#[`Layer<ChannelData>`]new().(
33 (2*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2048, 2*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2048),
34 layer_attributes,
35 Encodingrust-analyzer cargo exr 1.74.0 image/Encoding#::SMALL_FAST_LOSSLESSrust-analyzer cargo exr 1.74.0 image/impl#[Encoding]SMALL_FAST_LOSSLESS., // use fast but lossy compression
36
37 SpecificChannelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#::rgbarust-analyzer cargo exr 1.74.0 image/impl#[`SpecificChannels<SampleStorage, (ChannelDescription, ChannelDescription, ChannelDescription, ChannelDescription)>`]rgba().(generate_pixels)
38 );
39
40 // crop away black and transparent pixels from the border, if any
41 let layer = layer
42 .crop_where_eqrust-analyzer cargo exr 1.74.0 image/crop/impl#[T][`CropWhere<<T as InspectSample>::Sample>`]crop_where_eq().((0.0, 0.0, 0.0, 0.0))
43 .or_crop_to_1x1_if_emptyrust-analyzer cargo exr 1.74.0 image/crop/impl#[`CropResult<Cropped, Original>`]or_crop_to_1x1_if_empty().();
44
45 let mut image = Imagerust-analyzer cargo exr 1.74.0 image/Image#::from_layerrust-analyzer cargo exr 1.74.0 image/impl#[`Image<Layer<ChannelData>>`]from_layer().(layer);
46 image.attributesrust-analyzer cargo exr 1.74.0 image/Image#attributes..pixel_aspectrust-analyzer cargo exr 1.74.0 meta/header/ImageAttributes#pixel_aspect. = 1.0;
47
48 image.attributesrust-analyzer cargo exr 1.74.0 image/Image#attributes..time_coderust-analyzer cargo exr 1.74.0 meta/header/ImageAttributes#time_code. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TimeCoderust-analyzer cargo exr 1.74.0 meta/attribute/TimeCode# {
49 hoursrust-analyzer cargo exr 1.74.0 meta/attribute/TimeCode#hours.: 0,
50 minutesrust-analyzer cargo exr 1.74.0 meta/attribute/TimeCode#minutes.: 1,
51 secondsrust-analyzer cargo exr 1.74.0 meta/attribute/TimeCode#seconds.: 59,
52 framerust-analyzer cargo exr 1.74.0 meta/attribute/TimeCode#frame.: 29,
53 ..TimeCoderust-analyzer cargo exr 1.74.0 meta/attribute/TimeCode#::defaultrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[TimeCode][Default]default().()
54 });
55
56 image.attributesrust-analyzer cargo exr 1.74.0 image/Image#attributes..otherrust-analyzer cargo exr 1.74.0 meta/header/ImageAttributes#other..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(
57 Textrust-analyzer cargo exr 1.74.0 meta/attribute/Text#::fromrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][`From<&'s str>`]from().("Mice Count (Custom Image Attribute)"),
58 AttributeValuerust-analyzer cargo exr 1.74.0 meta/attribute/AttributeValue#::I32rust-analyzer cargo exr 1.74.0 meta/attribute/AttributeValue#I32#(23333)
59 );
60
61 // write it to a file with all cores in parallel
62 image.writerust-analyzer cargo exr 1.74.0 image/write/impl#[`&'img Image<WritableLayers>`][`WritableImage<'img, WritableLayers>`]write().().to_filerust-analyzer cargo exr 1.74.0 image/write/impl#[`WriteImageWithOptions<'img, L, F>`]to_file().("generated_rgba_with_meta.exr").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
63 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("created file generated_rgba_with_meta.exr");
64 }