Debian Codegraph @

examples/5c_write_mip_maps.rs

raw symbols SCIP
1
2 extern crate smallvecrust-analyzer cargo exr 1.74.0 smallvec/;
3 extern crate randrust-analyzer cargo exr 1.74.0 rand/;
4 extern crate halfrust-analyzer cargo exr 1.74.0 half/;
5
6
7 // exr imports
8 extern crate exrrust-analyzer cargo exr 1.74.0 exr/;
9
10
11
12 /// Writes two layers, each with multiple mip maps.
13 /// All mip maps have solid color for brevity.
14 fn mainrust-analyzer cargo exr 1.74.0 main().() {
15 use exrrust-analyzer cargo exr 1.74.0 crate/::preluderust-analyzer cargo exr 1.74.0 prelude/::*;
16 use exrrust-analyzer cargo exr 1.74.0 crate/::mathrust-analyzer cargo exr 1.74.0 math/::RoundingModerust-analyzer cargo exr 1.74.0 math/RoundingMode#;
17 use smallvecrust-analyzer cargo smallvec 1.15.1 crate/::smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!;
18
19 let full_size = Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#(512, 512);
20 let size_rounding = RoundingModerust-analyzer cargo exr 1.74.0 math/RoundingMode#::Uprust-analyzer cargo exr 1.74.0 math/RoundingMode#Up#;
21
22 let mip_levels_sizes = exrrust-analyzer cargo exr 1.74.0 crate/::metarust-analyzer cargo exr 1.74.0 meta/::mip_map_levelsrust-analyzer cargo exr 1.74.0 meta/mip_map_levels().(
23 size_rounding, full_size
24 ).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
25
26 let red_mip_levels = mip_levels_sizes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
27 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(_index, level_size)|{
28 FlatSamplesrust-analyzer cargo exr 1.74.0 image/FlatSamples#::F32rust-analyzer cargo exr 1.74.0 image/FlatSamples#F32#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0.1_f32; level_size.arearust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]area().() ])
29 })
30 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
31
32 let green_mip_levels = mip_levels_sizes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
33 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(_index, level_size)|{
34 FlatSamplesrust-analyzer cargo exr 1.74.0 image/FlatSamples#::F32rust-analyzer cargo exr 1.74.0 image/FlatSamples#F32#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0.6_f32; level_size.arearust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]area().() ])
35 })
36 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
37
38 let blue_mip_levels = mip_levels_sizes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
39 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(_index, level_size)|{
40 FlatSamplesrust-analyzer cargo exr 1.74.0 image/FlatSamples#::F32rust-analyzer cargo exr 1.74.0 image/FlatSamples#F32#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1.0_f32; level_size.arearust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]area().() ])
41 })
42 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
43
44 let rgb_mip_maps = AnyChannelsrust-analyzer cargo exr 1.74.0 image/AnyChannels#::sortrust-analyzer cargo exr 1.74.0 image/impl#[`AnyChannels<SampleData>`]sort().(smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!![
45 AnyChannelrust-analyzer cargo exr 1.74.0 image/AnyChannel#::newrust-analyzer cargo exr 1.74.0 image/impl#[`AnyChannel<SampleData>`]new().("R", Levelsrust-analyzer cargo exr 1.74.0 image/Levels#::Miprust-analyzer cargo exr 1.74.0 image/Levels#Mip# { level_datarust-analyzer cargo exr 1.74.0 image/Levels#Mip#level_data.: red_mip_levels, rounding_moderust-analyzer cargo exr 1.74.0 image/Levels#Mip#rounding_mode.: size_rounding }),
46 AnyChannelrust-analyzer cargo exr 1.74.0 image/AnyChannel#::newrust-analyzer cargo exr 1.74.0 image/impl#[`AnyChannel<SampleData>`]new().("G", Levelsrust-analyzer cargo exr 1.74.0 image/Levels#::Miprust-analyzer cargo exr 1.74.0 image/Levels#Mip# { level_datarust-analyzer cargo exr 1.74.0 image/Levels#Mip#level_data.: green_mip_levels, rounding_moderust-analyzer cargo exr 1.74.0 image/Levels#Mip#rounding_mode.: size_rounding }),
47 AnyChannelrust-analyzer cargo exr 1.74.0 image/AnyChannel#::newrust-analyzer cargo exr 1.74.0 image/impl#[`AnyChannel<SampleData>`]new().("B", Levelsrust-analyzer cargo exr 1.74.0 image/Levels#::Miprust-analyzer cargo exr 1.74.0 image/Levels#Mip# { level_datarust-analyzer cargo exr 1.74.0 image/Levels#Mip#level_data.: blue_mip_levels, rounding_moderust-analyzer cargo exr 1.74.0 image/Levels#Mip#rounding_mode.: size_rounding }),
48 ]);
49
50 let layer1 = Layerrust-analyzer cargo exr 1.74.0 image/Layer#::newrust-analyzer cargo exr 1.74.0 image/impl#[`Layer<ChannelData>`]new().(
51 full_size,
52 LayerAttributesrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#::namedrust-analyzer cargo exr 1.74.0 meta/header/impl#[LayerAttributes]named().("teal rgb"),
53 Encodingrust-analyzer cargo exr 1.74.0 image/Encoding#::FAST_LOSSLESSrust-analyzer cargo exr 1.74.0 image/impl#[Encoding]FAST_LOSSLESS.,
54 rgb_mip_maps
55 );
56
57 let mut layer2 = layer1.clonerust-analyzer cargo exr 1.74.0 image/impl#[`Layer<Channels>`][Clone]clone().();
58 layer2.attributesrust-analyzer cargo exr 1.74.0 image/Layer#attributes..layer_namerust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#layer_name. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Copied Layer".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
59 layer2.encodingrust-analyzer cargo exr 1.74.0 image/Layer#encoding. = Encodingrust-analyzer cargo exr 1.74.0 image/Encoding#::SMALL_FAST_LOSSLESSrust-analyzer cargo exr 1.74.0 image/impl#[Encoding]SMALL_FAST_LOSSLESS.;
60
61 // define the visible area of the canvas
62 let image_attributes = ImageAttributesrust-analyzer cargo exr 1.74.0 meta/header/ImageAttributes#::newrust-analyzer cargo exr 1.74.0 meta/header/impl#[ImageAttributes]new().(
63 IntegerBoundsrust-analyzer cargo exr 1.74.0 meta/attribute/IntegerBounds#::from_dimensionsrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[IntegerBounds]from_dimensions().(full_size)
64 );
65
66 let image = Imagerust-analyzer cargo exr 1.74.0 image/Image#::emptyrust-analyzer cargo exr 1.74.0 image/impl#[`Image<NoneMore>`]empty().(image_attributes)
67 .with_layerrust-analyzer cargo exr 1.74.0 image/impl#[`Image<InnerLayers>`]with_layer().(layer1).with_layerrust-analyzer cargo exr 1.74.0 image/impl#[`Image<InnerLayers>`]with_layer().(layer2);
68
69 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("writing image...");
70 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().("mip_maps.exr").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
71
72 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("created file mip_maps.exr");
73 }