| 1 | //! How to read arbitrary channels and rgb channels. |
| 2 | |
| 3 | use craterust-analyzer cargo exr 1.74.0 crate/::preluderust-analyzer cargo exr 1.74.0 prelude/::*; |
| 4 | use craterust-analyzer cargo exr 1.74.0 crate/::iorust-analyzer cargo exr 1.74.0 io/::*; |
| 5 | use craterust-analyzer cargo exr 1.74.0 crate/::mathrust-analyzer cargo exr 1.74.0 math/::*; |
| 6 | use craterust-analyzer cargo exr 1.74.0 crate/::metarust-analyzer cargo exr 1.74.0 meta/::{headerrust-analyzer cargo exr 1.74.0 meta/header/::*, attributerust-analyzer cargo exr 1.74.0 meta/attribute/::*}; |
| 7 | use craterust-analyzer cargo exr 1.74.0 crate/::blockrust-analyzer cargo exr 1.74.0 block/::*; |
| 8 | use craterust-analyzer cargo exr 1.74.0 crate/::imagerust-analyzer cargo exr 1.74.0 image/::recursiverust-analyzer cargo exr 1.74.0 image/recursive/::*; |
| 9 | use craterust-analyzer cargo exr 1.74.0 crate/::blockrust-analyzer cargo exr 1.74.0 block/::samplesrust-analyzer cargo exr 1.74.0 block/samples/::*; |
| 10 | use craterust-analyzer cargo exr 1.74.0 crate/::imagerust-analyzer cargo exr 1.74.0 image/::writerust-analyzer cargo exr 1.74.0 image/write/::samplesrust-analyzer cargo exr 1.74.0 image/write/samples/::*; |
| 11 | |
| 12 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#; |
| 13 | |
| 14 | |
| 15 | /// Enables an image containing this list of channels to be written to a file. |
| 16 | pub trait WritableChannelsrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#<'slf> { |
| 17 | |
| 18 | /// Generate the file meta data for this list of channel |
| 19 | fn infer_channel_listrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#infer_channel_list().(&self) -> ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#; |
| 20 | |
| 21 | /// Generate the file meta data of whether and how resolution levels should be stored in the file |
| 22 | fn infer_level_modesrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#infer_level_modes().(&self) -> (LevelModerust-analyzer cargo exr 1.74.0 meta/attribute/LevelMode#, RoundingModerust-analyzer cargo exr 1.74.0 math/RoundingMode#); |
| 23 | |
| 24 | /// The type of temporary writer |
| 25 | type Writerrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#Writer#: ChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/ChannelsWriter#; |
| 26 | |
| 27 | /// Create a temporary writer for this list of channels |
| 28 | fn create_writerrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#create_writer().(&'slf self, header: &Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#) -> Self::Writerrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#Writer#; |
| 29 | } |
| 30 | |
| 31 | /// A temporary writer for a list of channels |
| 32 | pub trait ChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/ChannelsWriter#: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# { |
| 33 | |
| 34 | /// Deliver a block of pixels, containing all channel data, to be stored in the file |
| 35 | fn extract_uncompressed_blockrust-analyzer cargo exr 1.74.0 image/write/channels/ChannelsWriter#extract_uncompressed_block().(&self, header: &Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#, block: BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>; // TODO return uncompressed block? |
| 36 | } |
| 37 | |
| 38 | |
| 39 | /// Define how to get a pixel from your custom pixel storage. |
| 40 | /// Can be a closure of type [`Sync + Fn(Vec2<usize>) -> YourPixel`]. |
| 41 | pub trait GetPixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# { |
| 42 | |
| 43 | /// The pixel tuple containing `f32`, `f16`, `u32` and `Sample` values. |
| 44 | /// The length of the tuple must match the number of channels in the image. |
| 45 | type Pixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#Pixel#; |
| 46 | |
| 47 | /// Inspect a single pixel at the requested position. |
| 48 | /// Will be called exactly once for each pixel in the image. |
| 49 | /// The position will not exceed the image dimensions. |
| 50 | /// Might be called from multiple threads at the same time. |
| 51 | fn get_pixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#get_pixel().(&self, position: Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#<usize>) -> Self::Pixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#Pixel#; |
| 52 | } |
| 53 | |
| 54 | impl<F, P> GetPixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel# for F where F: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#<usize>) -> P { |
| 55 | type Pixelrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[F][GetPixel]Pixel# = P; |
| 56 | fn get_pixelrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[F][GetPixel]get_pixel().(&self, position: Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#<usize>) -> P { self(position) } |
| 57 | } |
| 58 | |
| 59 | impl<'samples, Samples> WritableChannelsrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#<'samples> for AnyChannelsrust-analyzer cargo exr 1.74.0 image/AnyChannels#<Samples> |
| 60 | where Samples: 'samples + WritableSamplesrust-analyzer cargo exr 1.74.0 image/write/samples/WritableSamples#<'samples> |
| 61 | { |
| 62 | fn infer_channel_listrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`AnyChannels<Samples>`][`WritableChannels<'samples>`]infer_channel_list().(&self) -> ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList# { |
| 63 | ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#::newrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelList]new().(self.listrust-analyzer cargo exr 1.74.0 image/AnyChannels#list..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|channel| ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription# { |
| 64 | namerust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#name.: channel.namerust-analyzer cargo exr 1.74.0 image/AnyChannel#name..clonerust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][Clone]clone().(), |
| 65 | sample_typerust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#sample_type.: channel.sample_datarust-analyzer cargo exr 1.74.0 image/AnyChannel#sample_data..sample_typerust-analyzer cargo exr 1.74.0 image/write/samples/WritableSamples#sample_type().(), |
| 66 | quantize_linearlyrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#quantize_linearly.: channel.quantize_linearlyrust-analyzer cargo exr 1.74.0 image/AnyChannel#quantize_linearly., |
| 67 | samplingrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#sampling.: channel.samplingrust-analyzer cargo exr 1.74.0 image/AnyChannel#sampling. |
| 68 | }).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 69 | } |
| 70 | |
| 71 | fn infer_level_modesrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`AnyChannels<Samples>`][`WritableChannels<'samples>`]infer_level_modes().(&self) -> (LevelModerust-analyzer cargo exr 1.74.0 meta/attribute/LevelMode#, RoundingModerust-analyzer cargo exr 1.74.0 math/RoundingMode#) { |
| 72 | let mode = self.listrust-analyzer cargo exr 1.74.0 image/AnyChannels#list..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("zero channels in list").sample_datarust-analyzer cargo exr 1.74.0 image/AnyChannel#sample_data..infer_level_modesrust-analyzer cargo exr 1.74.0 image/write/samples/WritableSamples#infer_level_modes().(); |
| 73 | |
| 74 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!( |
| 75 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat/repeat().(mode).ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(self.listrust-analyzer cargo exr 1.74.0 image/AnyChannels#list..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1)) |
| 76 | .allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|(first, other)| other.sample_datarust-analyzer cargo exr 1.74.0 image/AnyChannel#sample_data..infer_level_modesrust-analyzer cargo exr 1.74.0 image/write/samples/WritableSamples#infer_level_modes().() == first), |
| 77 | |
| 78 | "level mode must be the same across all levels (do not nest resolution levels!)" |
| 79 | ); |
| 80 | |
| 81 | mode |
| 82 | } |
| 83 | |
| 84 | type Writerrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`AnyChannels<Samples>`][`WritableChannels<'samples>`]Writer# = AnyChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/AnyChannelsWriter#<Samples::Writerrust-analyzer cargo exr 1.74.0 image/write/samples/WritableSamples#Writer#>; |
| 85 | fn create_writerrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`AnyChannels<Samples>`][`WritableChannels<'samples>`]create_writer().(&'samples self, header: &Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#) -> Selfrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`AnyChannels<Samples>`][`WritableChannels<'samples>`]::Writerrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#Writer# { |
| 86 | let channels = self.listrust-analyzer cargo exr 1.74.0 image/AnyChannels#list..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 87 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|chan| chan.sample_datarust-analyzer cargo exr 1.74.0 image/AnyChannel#sample_data..create_samples_writerrust-analyzer cargo exr 1.74.0 image/write/samples/WritableSamples#create_samples_writer().(header)) |
| 88 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 89 | |
| 90 | AnyChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/AnyChannelsWriter# { channelsrust-analyzer cargo exr 1.74.0 image/write/channels/AnyChannelsWriter#channels. } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /// A temporary writer for an arbitrary list of channels |
| 95 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 96 | pub struct AnyChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/AnyChannelsWriter#<SamplesWriter> { |
| 97 | channelsrust-analyzer cargo exr 1.74.0 image/write/channels/AnyChannelsWriter#channels.: SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#<[SamplesWriter; 4]> |
| 98 | } |
| 99 | |
| 100 | impl<Samples> ChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/ChannelsWriter# for AnyChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/AnyChannelsWriter#<Samples> where Samples: SamplesWriterrust-analyzer cargo exr 1.74.0 image/write/samples/SamplesWriter# { |
| 101 | fn extract_uncompressed_blockrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`AnyChannelsWriter<Samples>`][ChannelsWriter]extract_uncompressed_block().(&self, header: &Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#, block_index: BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 102 | UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#::collect_block_data_from_linesrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]collect_block_data_from_lines().(&header.channelsrust-analyzer cargo exr 1.74.0 meta/header/Header#channels., block_index, |line_ref| { |
| 103 | self.channelsrust-analyzer cargo exr 1.74.0 image/write/channels/AnyChannelsWriter#channels.[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().line_ref.locationrust-analyzer cargo exr 1.74.0 block/lines/LineSlice#location..channelrust-analyzer cargo exr 1.74.0 block/lines/LineIndex#channel.]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index()..extract_linerust-analyzer cargo exr 1.74.0 image/write/samples/SamplesWriter#extract_line().(line_ref) |
| 104 | }) |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | impl<'c, Channels, Storage> |
| 114 | WritableChannelsrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#<'c> for SpecificChannelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#<Storage, Channels> |
| 115 | where |
| 116 | Storage: 'c + GetPixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#, |
| 117 | Storage::Pixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#Pixel#: IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#, |
| 118 | Channels: 'c + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#, |
| 119 | <Channels as IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#>::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive#: WritableChannelsDescriptionrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#<<Storage::Pixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#Pixel# as IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#>::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive#>, |
| 120 | { |
| 121 | fn infer_channel_listrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`SpecificChannels<Storage, Channels>`][`WritableChannels<'c>`]infer_channel_list().(&self) -> ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList# { |
| 122 | let mut vec = self.channelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#channels..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().into_recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#into_recursive().().channel_descriptions_listrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#channel_descriptions_list().(); |
| 123 | vec.sort_unstable_by_keyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]sort_unstable_by_key().(|channel:&ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#| channel.namerust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#name..clonerust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][Clone]clone().()); // TODO no clone? |
| 124 | |
| 125 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!( |
| 126 | // check for equal neighbors in sorted vec |
| 127 | vec.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(vec.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1)).allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|(prev, next)| prev.namerust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#name. != next.namerust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#name.), |
| 128 | "specific channels contain duplicate channel names" |
| 129 | ); |
| 130 | |
| 131 | ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#::newrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelList]new().(vec) |
| 132 | } |
| 133 | |
| 134 | fn infer_level_modesrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`SpecificChannels<Storage, Channels>`][`WritableChannels<'c>`]infer_level_modes().(&self) -> (LevelModerust-analyzer cargo exr 1.74.0 meta/attribute/LevelMode#, RoundingModerust-analyzer cargo exr 1.74.0 math/RoundingMode#) { |
| 135 | (LevelModerust-analyzer cargo exr 1.74.0 meta/attribute/LevelMode#::Singularrust-analyzer cargo exr 1.74.0 meta/attribute/LevelMode#Singular#, RoundingModerust-analyzer cargo exr 1.74.0 math/RoundingMode#::Downrust-analyzer cargo exr 1.74.0 math/RoundingMode#Down#) // TODO |
| 136 | } |
| 137 | |
| 138 | type Writerrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`SpecificChannels<Storage, Channels>`][`WritableChannels<'c>`]Writer# = SpecificChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter#< |
| 139 | 'c, |
| 140 | <<Channels as IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#>::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive# as WritableChannelsDescriptionrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#<<Storage::Pixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#Pixel# as IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#>::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive#>>::RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#RecursiveWriter#, |
| 141 | Storage, |
| 142 | Channels |
| 143 | >; |
| 144 | |
| 145 | fn create_writerrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`SpecificChannels<Storage, Channels>`][`WritableChannels<'c>`]create_writer().(&'c self, header: &Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#) -> Selfrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`SpecificChannels<Storage, Channels>`][`WritableChannels<'c>`]::Writerrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#Writer# { |
| 146 | SpecificChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter# { |
| 147 | channelsrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter#channels.: self, |
| 148 | recursive_channel_writerrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter#recursive_channel_writer.: self.channelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#channels..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().into_recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#into_recursive().().create_recursive_writerrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#create_recursive_writer().(&header.channelsrust-analyzer cargo exr 1.74.0 meta/header/Header#channels.), |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | |
| 154 | |
| 155 | /// A temporary writer for a layer of channels, alpha being optional |
| 156 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 157 | pub struct SpecificChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter#<'channels, PixelWriter, Storage, Channels> { |
| 158 | channelsrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter#channels.: &'channels SpecificChannelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#<Storage, Channels>, // TODO this need not be a reference?? impl writer for specific_channels directly? |
| 159 | recursive_channel_writerrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter#recursive_channel_writer.: PixelWriter, |
| 160 | } |
| 161 | |
| 162 | |
| 163 | impl<'channels, PxWriter, Storage, Channels> ChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/ChannelsWriter# |
| 164 | for SpecificChannelsWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter#<'channels, PxWriter, Storage, Channels> |
| 165 | where |
| 166 | Channels: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, |
| 167 | Storage: GetPixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#, |
| 168 | Storage::Pixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#Pixel#: IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#, |
| 169 | PxWriter: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + RecursivePixelWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#<<Storage::Pixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#Pixel# as IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#>::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive#>, |
| 170 | { |
| 171 | fn extract_uncompressed_blockrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`SpecificChannelsWriter<'channels, PxWriter, Storage, Channels>`][ChannelsWriter]extract_uncompressed_block().(&self, header: &Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#, block_index: BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 172 | let block_bytes = block_index.pixel_sizerust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_size..arearust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]area().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().header.channelsrust-analyzer cargo exr 1.74.0 meta/header/Header#channels..bytes_per_pixelrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#bytes_per_pixel.; |
| 173 | let mut block_bytes = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0_u8; block_bytes]; |
| 174 | |
| 175 | let width = block_index.pixel_sizerust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_size..0rust-analyzer cargo exr 1.74.0 math/Vec2#0.; |
| 176 | let line_bytes = width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().header.channelsrust-analyzer cargo exr 1.74.0 meta/header/Header#channels..bytes_per_pixelrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#bytes_per_pixel.; |
| 177 | let byte_lines = block_bytes.chunks_exact_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact_mut().(line_bytes); |
| 178 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(byte_lines.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().(), block_index.pixel_sizerust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_size..heightrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]height().(), "invalid block line splits"); |
| 179 | |
| 180 | //dbg!(width, line_bytes, header.channels.bytes_per_pixel, byte_lines.len()); |
| 181 | |
| 182 | let mut pixel_line = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(width); |
| 183 | |
| 184 | for (y, line_bytes) in byte_lines.enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 185 | pixel_line.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 186 | pixel_line.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().((0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range# rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#width).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| |
| 187 | self.channelsrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter#channels..pixelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#pixels..get_pixelrust-analyzer cargo exr 1.74.0 image/write/channels/GetPixel#get_pixel().(block_index.pixel_positionrust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_position. rust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`][`Add<Self>`]add().+rust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`][`Add<Self>`]add(). rust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`][`Add<Self>`]add().Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#(x, y)).into_recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#into_recursive().() |
| 188 | )); |
| 189 | |
| 190 | self.recursive_channel_writerrust-analyzer cargo exr 1.74.0 image/write/channels/SpecificChannelsWriter#recursive_channel_writer..write_pixelsrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#write_pixels().(line_bytes, pixel_line.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().(), |px| px); |
| 191 | } |
| 192 | |
| 193 | block_bytes |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /// A tuple containing either `ChannelsDescription` or `Option<ChannelsDescription>` entries. |
| 198 | /// Use an `Option` if you want to dynamically omit a single channel (probably only for roundtrip tests). |
| 199 | /// The number of entries must match the number of channels. |
| 200 | pub trait WritableChannelsDescriptionrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#<Pixel>: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# { |
| 201 | |
| 202 | /// A type that has a recursive entry for each channel in the image, |
| 203 | /// which must accept the desired pixel type. |
| 204 | type RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#RecursiveWriter#: RecursivePixelWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#<Pixel>; |
| 205 | |
| 206 | /// Create the temporary writer, accepting the sorted list of channels from `channel_descriptions_list`. |
| 207 | fn create_recursive_writerrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#create_recursive_writer().(&self, channels: &ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#) -> Self::RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#RecursiveWriter#; |
| 208 | |
| 209 | /// Return all the channels that should actually end up in the image, in any order. |
| 210 | fn channel_descriptions_listrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#channel_descriptions_list().(&self) -> SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#<[ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#; 5]>; |
| 211 | } |
| 212 | |
| 213 | impl WritableChannelsDescriptionrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#<NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore#> for NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore# { |
| 214 | type RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[NoneMore][`WritableChannelsDescription<Self>`]RecursiveWriter# = NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore#; |
| 215 | fn create_recursive_writerrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[NoneMore][`WritableChannelsDescription<Self>`]create_recursive_writer().(&self, _: &ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#) -> Selfrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[NoneMore][`WritableChannelsDescription<Self>`]::RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#RecursiveWriter# { NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore# } |
| 216 | fn channel_descriptions_listrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[NoneMore][`WritableChannelsDescription<Self>`]channel_descriptions_list().(&self) -> SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#<[ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#; 5]> { SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#::newrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]new().() } |
| 217 | } |
| 218 | |
| 219 | impl<InnerDescriptions, InnerPixel, Sample: IntoNativeSamplerust-analyzer cargo exr 1.74.0 block/samples/IntoNativeSample#> |
| 220 | WritableChannelsDescriptionrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#<Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<InnerPixel, Sample>> |
| 221 | for Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<InnerDescriptions, ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#> |
| 222 | where InnerDescriptions: WritableChannelsDescriptionrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#<InnerPixel> |
| 223 | { |
| 224 | type RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<InnerDescriptions, ChannelDescription>`][`WritableChannelsDescription<Recursive<InnerPixel, Sample>>`]RecursiveWriter# = RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursiveWriter#<InnerDescriptions::RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#RecursiveWriter#, Sample>; |
| 225 | |
| 226 | fn create_recursive_writerrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<InnerDescriptions, ChannelDescription>`][`WritableChannelsDescription<Recursive<InnerPixel, Sample>>`]create_recursive_writer().(&self, channels: &ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#) -> Selfrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<InnerDescriptions, ChannelDescription>`][`WritableChannelsDescription<Recursive<InnerPixel, Sample>>`]::RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#RecursiveWriter# { |
| 227 | // this linear lookup is required because the order of the channels changed, due to alphabetical sorting |
| 228 | let (start_byte_offset, target_sample_type) = channels.channels_with_byte_offsetrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelList]channels_with_byte_offset().() |
| 229 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|(_offset, channel)| channel.namerust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#name. rust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][`PartialEq<Self>`]eq().==rust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][`PartialEq<Self>`]eq(). rust-analyzer cargo exr 1.74.0 meta/attribute/impl#[Text][`PartialEq<Self>`]eq().self.valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value..namerust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#name.) |
| 230 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(offset, channel)| (offset, channel.sample_typerust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#sample_type.)) |
| 231 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("a channel has not been put into channel list"); |
| 232 | |
| 233 | Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#::newrust-analyzer cargo exr 1.74.0 image/recursive/impl#[`Recursive<Inner, Value>`]new().(self.innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner..create_recursive_writerrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#create_recursive_writer().(channels), SampleWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter# { |
| 234 | start_byte_offsetrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#start_byte_offset., target_sample_typerust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#target_sample_type., |
| 235 | pxrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#px.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/impl#[`PhantomData<T>`][Default]default().() |
| 236 | }) |
| 237 | } |
| 238 | |
| 239 | fn channel_descriptions_listrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<InnerDescriptions, ChannelDescription>`][`WritableChannelsDescription<Recursive<InnerPixel, Sample>>`]channel_descriptions_list().(&self) -> SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#<[ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#; 5]> { |
| 240 | let mut inner_list = self.innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner..channel_descriptions_listrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#channel_descriptions_list().(); |
| 241 | inner_list.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(self.valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value..clonerust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelDescription][Clone]clone().()); |
| 242 | inner_list |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | impl<InnerDescriptions, InnerPixel, Sample: IntoNativeSamplerust-analyzer cargo exr 1.74.0 block/samples/IntoNativeSample#> |
| 247 | WritableChannelsDescriptionrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#<Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<InnerPixel, Sample>> |
| 248 | for Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<InnerDescriptions, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#>> |
| 249 | where InnerDescriptions: WritableChannelsDescriptionrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#<InnerPixel> |
| 250 | { |
| 251 | type RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<InnerDescriptions, Option<ChannelDescription>>`][`WritableChannelsDescription<Recursive<InnerPixel, Sample>>`]RecursiveWriter# = OptionalRecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/OptionalRecursiveWriter#<InnerDescriptions::RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#RecursiveWriter#, Sample>; |
| 252 | |
| 253 | fn create_recursive_writerrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<InnerDescriptions, Option<ChannelDescription>>`][`WritableChannelsDescription<Recursive<InnerPixel, Sample>>`]create_recursive_writer().(&self, channels: &ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#) -> Selfrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<InnerDescriptions, Option<ChannelDescription>>`][`WritableChannelsDescription<Recursive<InnerPixel, Sample>>`]::RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#RecursiveWriter# { |
| 254 | // this linear lookup is required because the order of the channels changed, due to alphabetical sorting |
| 255 | |
| 256 | let channel = self.valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|required_channel| |
| 257 | channels.channels_with_byte_offsetrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelList]channels_with_byte_offset().() |
| 258 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|(_offset, channel)| channel rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().&required_channel) |
| 259 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(offset, channel)| (offset, channel.sample_typerust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#sample_type.)) |
| 260 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("a channel has not been put into channel list") |
| 261 | ); |
| 262 | |
| 263 | Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#::newrust-analyzer cargo exr 1.74.0 image/recursive/impl#[`Recursive<Inner, Value>`]new().( |
| 264 | self.innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner..create_recursive_writerrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#create_recursive_writer().(channels), |
| 265 | channel.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(start_byte_offset, target_sample_type)| SampleWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter# { |
| 266 | start_byte_offsetrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#start_byte_offset., target_sample_typerust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#target_sample_type., |
| 267 | pxrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#px.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/impl#[`PhantomData<T>`][Default]default().(), |
| 268 | }) |
| 269 | ) |
| 270 | } |
| 271 | |
| 272 | fn channel_descriptions_listrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<InnerDescriptions, Option<ChannelDescription>>`][`WritableChannelsDescription<Recursive<InnerPixel, Sample>>`]channel_descriptions_list().(&self) -> SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#<[ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#; 5]> { |
| 273 | let mut inner_list = self.innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner..channel_descriptions_listrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannelsDescription#channel_descriptions_list().(); |
| 274 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = &self.valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value. { inner_list.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().(value.clonerust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelDescription][Clone]clone().()); } |
| 275 | inner_list |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /// Write pixels to a slice of bytes. The top level writer contains all the other channels, |
| 280 | /// the most inner channel is `NoneMore`. |
| 281 | pub trait RecursivePixelWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#<Pixel>: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# { |
| 282 | |
| 283 | /// Write pixels to a slice of bytes. Recursively do this for all channels. |
| 284 | fn write_pixelsrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#write_pixels().<FullPixel>(&self, bytes: &mut [u8], pixels: &[FullPixel], get_pixel: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&FullPixel) -> &Pixel); |
| 285 | } |
| 286 | |
| 287 | type RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursiveWriter#<Inner, Sample> = Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<Inner, SampleWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#<Sample>>; |
| 288 | type OptionalRecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/OptionalRecursiveWriter#<Inner, Sample> = Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<Inner, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<SampleWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#<Sample>>>; |
| 289 | |
| 290 | /// Write the pixels of a single channel, unconditionally. Generic over the concrete sample type (f16, f32, u32). |
| 291 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 292 | pub struct SampleWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#<Sample> { |
| 293 | target_sample_typerust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#target_sample_type.: SampleTyperust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#, |
| 294 | start_byte_offsetrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#start_byte_offset.: usize, |
| 295 | pxrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#px.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<Sample>, |
| 296 | } |
| 297 | |
| 298 | impl<Sample> SampleWriterrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#<Sample> where Sample: IntoNativeSamplerust-analyzer cargo exr 1.74.0 block/samples/IntoNativeSample# { |
| 299 | fn write_own_samplesrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`SampleWriter<Sample>`]write_own_samples().(&self, bytes: &mut [u8], samples: impl ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#=Sample>) { |
| 300 | let byte_start_index = samples.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.start_byte_offsetrust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#start_byte_offset.; |
| 301 | let byte_count = samples.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.target_sample_typerust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#target_sample_type..bytes_per_samplerust-analyzer cargo exr 1.74.0 meta/attribute/impl#[SampleType]bytes_per_sample().(); |
| 302 | let ref mut byte_writer = &mut bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().byte_start_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#byte_start_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().byte_count]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().; |
| 303 | |
| 304 | let write_error_msg = "invalid memory buffer length when writing"; |
| 305 | |
| 306 | // match outside the loop to avoid matching on every single sample |
| 307 | match self.target_sample_typerust-analyzer cargo exr 1.74.0 image/write/channels/SampleWriter#target_sample_type. { |
| 308 | // TODO does this boil down to a `memcpy` where the sample type equals the type parameter? |
| 309 | SampleTyperust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#::F16rust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#F16# => for sample in samples { sample.to_f16rust-analyzer cargo exr 1.74.0 block/samples/IntoNativeSample#to_f16().().write_nerust-analyzer cargo exr 1.74.0 io/impl#[f16][Data]write_ne().(byte_writer).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().(write_error_msg); }, |
| 310 | SampleTyperust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#::F32rust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#F32# => for sample in samples { sample.to_f32rust-analyzer cargo exr 1.74.0 block/samples/IntoNativeSample#to_f32().().write_nerust-analyzer cargo exr 1.74.0 io/impl#[f32][Data]write_ne().(byte_writer).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().(write_error_msg); }, |
| 311 | SampleTyperust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#::U32rust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#U32# => for sample in samples { sample.to_u32rust-analyzer cargo exr 1.74.0 block/samples/IntoNativeSample#to_u32().().write_nerust-analyzer cargo exr 1.74.0 io/impl#[u32][Data]write_ne().(byte_writer).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().(write_error_msg); }, |
| 312 | }; |
| 313 | |
| 314 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(byte_writer.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().(), "all samples are written, but more were expected"); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | impl RecursivePixelWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#<NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore#> for NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore# { |
| 319 | fn write_pixelsrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[NoneMore][`RecursivePixelWriter<Self>`]write_pixels().<FullPixel>(&self, _: &mut [u8], _: &[FullPixel], _: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&FullPixel) -> &NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore#) {} |
| 320 | } |
| 321 | |
| 322 | impl<Inner, InnerPixel, Sample: IntoNativeSamplerust-analyzer cargo exr 1.74.0 block/samples/IntoNativeSample#> |
| 323 | RecursivePixelWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#<Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<InnerPixel, Sample>> |
| 324 | for RecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursiveWriter#<Inner, Sample> |
| 325 | where Inner: RecursivePixelWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#<InnerPixel> |
| 326 | { |
| 327 | // TODO impl exact size iterator <item = Self::Pixel> |
| 328 | fn write_pixelsrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<Inner, SampleWriter<Sample>>`][`RecursivePixelWriter<Recursive<InnerPixel, Sample>>`]write_pixels().<FullPixel>(&self, bytes: &mut [u8], pixels: &[FullPixel], get_pixel: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&FullPixel) -> &Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<InnerPixel, Sample>){ |
| 329 | self.valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value..write_own_samplesrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`SampleWriter<Sample>`]write_own_samples().(bytes, pixels.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|px| get_pixel(px).valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value.)); |
| 330 | self.innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner..write_pixelsrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#write_pixels().(bytes, pixels, |px| &get_pixel(px).innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner.); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | impl<Inner, InnerPixel, Sample> RecursivePixelWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#<Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<InnerPixel, Sample>> |
| 335 | for OptionalRecursiveWriterrust-analyzer cargo exr 1.74.0 image/write/channels/OptionalRecursiveWriter#<Inner, Sample> |
| 336 | where Inner: RecursivePixelWriterrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#<InnerPixel>, |
| 337 | Sample: IntoNativeSamplerust-analyzer cargo exr 1.74.0 block/samples/IntoNativeSample# |
| 338 | { |
| 339 | fn write_pixelsrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`Recursive<Inner, Option<SampleWriter<Sample>>>`][`RecursivePixelWriter<Recursive<InnerPixel, Sample>>`]write_pixels().<FullPixel>(&self, bytes: &mut [u8], pixels: &[FullPixel], get_pixel: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&FullPixel) -> &Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<InnerPixel, Sample>) { |
| 340 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(writer) = &self.valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value. { |
| 341 | writer.write_own_samplesrust-analyzer cargo exr 1.74.0 image/write/channels/impl#[`SampleWriter<Sample>`]write_own_samples().(bytes, pixels.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|px| get_pixel(px).valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value.)); |
| 342 | } |
| 343 | |
| 344 | self.innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner..write_pixelsrust-analyzer cargo exr 1.74.0 image/write/channels/RecursivePixelWriter#write_pixels().(bytes, pixels, |px| &get_pixel(px).innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner.); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | #[cfg(test)] |
| 355 | mod testrust-analyzer cargo exr 1.74.0 image/write/channels/test/ { |
| 356 | use craterust-analyzer cargo exr 1.74.0 crate/::imagerust-analyzer cargo exr 1.74.0 image/::writerust-analyzer cargo exr 1.74.0 image/write/::channelsrust-analyzer cargo exr 1.74.0 image/write/channels/::WritableChannelsrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#; |
| 357 | use craterust-analyzer cargo exr 1.74.0 crate/::imagerust-analyzer cargo exr 1.74.0 image/::SpecificChannelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#; |
| 358 | use craterust-analyzer cargo exr 1.74.0 crate/::preluderust-analyzer cargo exr 1.74.0 prelude/::{f16rust-analyzer cargo half 2.6.0 binary16/f16#}; |
| 359 | use craterust-analyzer cargo exr 1.74.0 crate/::metarust-analyzer cargo exr 1.74.0 meta/::attributerust-analyzer cargo exr 1.74.0 meta/attribute/::{ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#, SampleTyperust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#}; |
| 360 | use craterust-analyzer cargo exr 1.74.0 crate/::imagerust-analyzer cargo exr 1.74.0 image/::pixel_vecrust-analyzer cargo exr 1.74.0 image/pixel_vec/::PixelVecrust-analyzer cargo exr 1.74.0 image/pixel_vec/PixelVec#; |
| 361 | |
| 362 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 363 | fn compilesrust-analyzer cargo exr 1.74.0 image/write/channels/test/compiles().(){ |
| 364 | let x = 3_f32; |
| 365 | let y = f16rust-analyzer cargo half 2.6.0 binary16/f16#::from_f32rust-analyzer cargo half 2.6.0 binary16/impl#[f16]from_f32().(4.0); |
| 366 | let z = 2_u32; |
| 367 | let s = 1.3_f32; |
| 368 | let px = (x,y,z,s); |
| 369 | |
| 370 | assert_is_writable_channelsrust-analyzer cargo exr 1.74.0 image/write/channels/test/assert_is_writable_channels().( |
| 371 | 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().(|_pos| px) |
| 372 | ); |
| 373 | |
| 374 | assert_is_writable_channelsrust-analyzer cargo exr 1.74.0 image/write/channels/test/assert_is_writable_channels().(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().( |
| 375 | PixelVecrust-analyzer cargo exr 1.74.0 image/pixel_vec/PixelVec#::newrust-analyzer cargo exr 1.74.0 image/pixel_vec/impl#[`PixelVec<Pixel>`]new().((3, 2), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![px, px, px, px, px, px]) |
| 376 | )); |
| 377 | |
| 378 | let px = (2333_u32, 4_f32); |
| 379 | assert_is_writable_channelsrust-analyzer cargo exr 1.74.0 image/write/channels/test/assert_is_writable_channels().( |
| 380 | SpecificChannelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#::buildrust-analyzer cargo exr 1.74.0 image/impl#[`SpecificChannels<(), ()>`]build().() |
| 381 | .with_channelrust-analyzer cargo exr 1.74.0 image/impl#[`SpecificChannelsBuilder<RecursiveChannels, RecursivePixel>`]with_channel().("A") |
| 382 | .with_channelrust-analyzer cargo exr 1.74.0 image/impl#[`SpecificChannelsBuilder<RecursiveChannels, RecursivePixel>`]with_channel().("C") |
| 383 | .with_pixelsrust-analyzer cargo exr 1.74.0 image/impl#[`SpecificChannelsBuilder<RecursiveChannels, RecursivePixel>`]with_pixels().(PixelVecrust-analyzer cargo exr 1.74.0 image/pixel_vec/PixelVec#::newrust-analyzer cargo exr 1.74.0 image/pixel_vec/impl#[`PixelVec<Pixel>`]new().((3, 2), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![px, px, px, px, px, px])) |
| 384 | ); |
| 385 | |
| 386 | let px = (3_f32, f16rust-analyzer cargo half 2.6.0 binary16/f16#::ONErust-analyzer cargo half 2.6.0 binary16/impl#[f16]ONE., 2333_u32, 4_f32); |
| 387 | assert_is_writable_channelsrust-analyzer cargo exr 1.74.0 image/write/channels/test/assert_is_writable_channels().(SpecificChannelsrust-analyzer cargo exr 1.74.0 image/SpecificChannels#::newrust-analyzer cargo exr 1.74.0 image/impl#[`SpecificChannels<SampleStorage, Channels>`]new().( |
| 388 | ( |
| 389 | ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#::namedrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelDescription]named().("x", SampleTyperust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#::F32rust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#F32#), |
| 390 | ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#::namedrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelDescription]named().("y", SampleTyperust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#::F16rust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#F16#), |
| 391 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#::namedrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelDescription]named().("z", SampleTyperust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#::U32rust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#U32#)), |
| 392 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ChannelDescriptionrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelDescription#::namedrust-analyzer cargo exr 1.74.0 meta/attribute/impl#[ChannelDescription]named().("p", SampleTyperust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#::F32rust-analyzer cargo exr 1.74.0 meta/attribute/SampleType#F32#)), |
| 393 | ), |
| 394 | |
| 395 | PixelVecrust-analyzer cargo exr 1.74.0 image/pixel_vec/PixelVec#::newrust-analyzer cargo exr 1.74.0 image/pixel_vec/impl#[`PixelVec<Pixel>`]new().((3, 2), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![px, px, px, px, px, px]) |
| 396 | )); |
| 397 | |
| 398 | |
| 399 | |
| 400 | fn assert_is_writable_channelsrust-analyzer cargo exr 1.74.0 image/write/channels/test/assert_is_writable_channels().<'s>(_channels: impl WritableChannelsrust-analyzer cargo exr 1.74.0 image/write/channels/WritableChannels#<'s>){} |
| 401 | |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | |
| 406 | |
| 407 |