Debian Codegraph @

src/block/reader.rs

raw symbols SCIP
1 //! Composable structures to handle reading an image.
2
3
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#;
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#};
7 use craterust-analyzer cargo exr 1.74.0 crate/::blockrust-analyzer cargo exr 1.74.0 block/::{BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex#, UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#};
8 use craterust-analyzer cargo exr 1.74.0 crate/::blockrust-analyzer cargo exr 1.74.0 block/::chunkrust-analyzer cargo exr 1.74.0 block/chunk/::{Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#, TileCoordinatesrust-analyzer cargo exr 1.74.0 block/chunk/TileCoordinates#};
9 use craterust-analyzer cargo exr 1.74.0 crate/::errorrust-analyzer cargo exr 1.74.0 error/::{Errorrust-analyzer cargo exr 1.74.0 error/Error#, Resultrust-analyzer cargo exr 1.74.0 error/Result#, u64_to_usizerust-analyzer cargo exr 1.74.0 error/u64_to_usize()., UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult#};
10 use craterust-analyzer cargo exr 1.74.0 crate/::iorust-analyzer cargo exr 1.74.0 io/::{PeekReadrust-analyzer cargo exr 1.74.0 io/PeekRead#, Trackingrust-analyzer cargo exr 1.74.0 io/Tracking#};
11 use craterust-analyzer cargo exr 1.74.0 crate/::metarust-analyzer cargo exr 1.74.0 meta/::{MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#, OffsetTablesrust-analyzer cargo exr 1.74.0 meta/OffsetTables#};
12 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/::Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#;
13
14 /// Decode the meta data from a byte source, keeping the source ready for further reading.
15 /// Continue decoding the remaining bytes by calling `filtered_chunks` or `all_chunks`.
16 #[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:)]
17 pub struct Readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#<R> {
18 meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data.: MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#,
19 remaining_readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#remaining_reader.: PeekReadrust-analyzer cargo exr 1.74.0 io/PeekRead#<Trackingrust-analyzer cargo exr 1.74.0 io/Tracking#<R>>, // TODO does R need to be Seek or is Tracking enough?
20 }
21
22 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> Readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#<R> {
23
24 /// Start the reading process.
25 /// Immediately decodes the meta data into an internal field.
26 /// Access it via`meta_data()`.
27 pub fn read_from_bufferedrust-analyzer cargo exr 1.74.0 block/reader/impl#[`Reader<R>`]read_from_buffered().(read: R, pedantic: bool) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`Reader<R>`]> {
28 let mut remaining_reader = PeekReadrust-analyzer cargo exr 1.74.0 io/PeekRead#::newrust-analyzer cargo exr 1.74.0 io/impl#[`PeekRead<T>`]new().(Trackingrust-analyzer cargo exr 1.74.0 io/Tracking#::newrust-analyzer cargo exr 1.74.0 io/impl#[`Tracking<T>`]new().(read));
29 let meta_data = MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#::read_validated_from_buffered_peekablerust-analyzer cargo exr 1.74.0 meta/impl#[MetaData]read_validated_from_buffered_peekable().(&mut remaining_reader, pedantic)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
30 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`Reader<R>`] { meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data., remaining_readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#remaining_reader. })
31 }
32
33 // must not be mutable, as reading the file later on relies on the meta data
34 /// The decoded exr meta data from the file.
35 pub fn meta_datarust-analyzer cargo exr 1.74.0 block/reader/impl#[`Reader<R>`]meta_data().(&self) -> &MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData# { &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data. }
36
37 /// The decoded exr meta data from the file.
38 pub fn headersrust-analyzer cargo exr 1.74.0 block/reader/impl#[`Reader<R>`]headers().(&self) -> &[Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#] { &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data..headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers. }
39
40 /// Obtain the meta data ownership.
41 pub fn into_meta_datarust-analyzer cargo exr 1.74.0 block/reader/impl#[`Reader<R>`]into_meta_data().(self) -> MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData# { self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data. }
42
43 /// Prepare to read all the chunks from the file.
44 /// Does not decode the chunks now, but returns a decoder.
45 /// Reading all chunks reduces seeking the file, but some chunks might be read without being used.
46 pub fn all_chunksrust-analyzer cargo exr 1.74.0 block/reader/impl#[`Reader<R>`]all_chunks().(mut self, pedantic: bool) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<AllChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#<R>> {
47 let total_chunk_count = {
48 if pedantic {
49 let offset_tables = MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#::read_offset_tablesrust-analyzer cargo exr 1.74.0 meta/impl#[MetaData]read_offset_tables().(&mut self.remaining_readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#remaining_reader., &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data..headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
50 validate_offset_tablesrust-analyzer cargo exr 1.74.0 block/reader/validate_offset_tables().(self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data..headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers..as_slicerust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]as_slice().(), &offset_tables, self.remaining_readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#remaining_reader..byte_positionrust-analyzer cargo exr 1.74.0 io/impl#[`PeekRead<Tracking<T>>`]byte_position().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
51 offset_tables.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().(|table| table.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().()
52 }
53 else {
54 MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#::skip_offset_tablesrust-analyzer cargo exr 1.74.0 meta/impl#[MetaData]skip_offset_tables().(&mut self.remaining_readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#remaining_reader., &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data..headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
55 }
56 };
57
58 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(AllChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader# {
59 meta_datarust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#meta_data.: self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data.,
60 remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_chunks.: 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#total_chunk_count,
61 remaining_bytesrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_bytes.: self.remaining_readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#remaining_reader.,
62 pedanticrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#pedantic.
63 })
64 }
65
66 /// Prepare to read some the chunks from the file.
67 /// Does not decode the chunks now, but returns a decoder.
68 /// Reading only some chunks may seeking the file, potentially skipping many bytes.
69 // TODO tile indices add no new information to block index??
70 pub fn filter_chunksrust-analyzer cargo exr 1.74.0 block/reader/impl#[`Reader<R>`]filter_chunks().(mut self, pedantic: bool, mut filter: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#, TileCoordinatesrust-analyzer cargo exr 1.74.0 block/chunk/TileCoordinates#, BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex#) -> bool) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<FilteredChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#<R>> {
71 let offset_tables = MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#::read_offset_tablesrust-analyzer cargo exr 1.74.0 meta/impl#[MetaData]read_offset_tables().(&mut self.remaining_readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#remaining_reader., &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data..headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
72
73 // TODO regardless of pedantic, if invalid, read all chunks instead, and filter after reading each chunk?
74 if pedantic {
75 validate_offset_tablesrust-analyzer cargo exr 1.74.0 block/reader/validate_offset_tables().(
76 self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data..headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers..as_slicerust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]as_slice().(), &offset_tables,
77 self.remaining_readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#remaining_reader..byte_positionrust-analyzer cargo exr 1.74.0 io/impl#[`PeekRead<Tracking<T>>`]byte_position().()
78 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
79 }
80
81 let mut filtered_offsets = 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().(
82 (self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data..headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers..lenrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]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().32).minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(2*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2048)
83 );
84
85 // TODO detect whether the filter actually would skip chunks, and aviod sorting etc when not filtering is applied
86
87 for (header_index, header) in self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data..headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { // offset tables are stored same order as headers
88 for (block_index, tile) in header.blocks_increasing_y_orderrust-analyzer cargo exr 1.74.0 meta/header/impl#[Header]blocks_increasing_y_order().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { // in increasing_y order
89 let data_indices = header.get_absolute_block_pixel_coordinatesrust-analyzer cargo exr 1.74.0 meta/header/impl#[Header]get_absolute_block_pixel_coordinates().(tile.locationrust-analyzer cargo exr 1.74.0 meta/TileIndices#location.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
90
91 let block = BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex# {
92 layerrust-analyzer cargo exr 1.74.0 block/BlockIndex#layer.: header_index,
93 levelrust-analyzer cargo exr 1.74.0 block/BlockIndex#level.: tile.locationrust-analyzer cargo exr 1.74.0 meta/TileIndices#location..level_indexrust-analyzer cargo exr 1.74.0 block/chunk/TileCoordinates#level_index.,
94 pixel_positionrust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_position.: data_indices.positionrust-analyzer cargo exr 1.74.0 meta/attribute/IntegerBounds#position..to_usizerust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<i32>`]to_usize().("data indices start")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
95 pixel_sizerust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_size.: data_indices.sizerust-analyzer cargo exr 1.74.0 meta/attribute/IntegerBounds#size.,
96 };
97
98 if filter(&self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data., tile.locationrust-analyzer cargo exr 1.74.0 meta/TileIndices#location., block) {
99 filtered_offsets.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(offset_tables[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().header_index]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().block_index]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().) // safe indexing from `enumerate()`
100 }
101 };
102 }
103
104 filtered_offsets.sort_unstablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]sort_unstable().(); // enables reading continuously if possible (already sorted where line order increasing)
105
106 if pedantic {
107 // table is sorted. if any two neighbours are equal, we have duplicates. this is invalid.
108 if filtered_offsets.windowsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]windows().(2).anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|pair| pair[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().pair[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) {
109 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().("chunk offset table"))
110 }
111 }
112
113 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(FilteredChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader# {
114 meta_datarust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#meta_data.: self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/Reader#meta_data.,
115 expected_filtered_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#expected_filtered_chunk_count.: filtered_offsets.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
116 remaining_filtered_chunk_indicesrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#remaining_filtered_chunk_indices.: filtered_offsets.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().(),
117 remaining_bytesrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#remaining_bytes.: self.remaining_readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#remaining_reader.
118 })
119 }
120 }
121
122
123 fn validate_offset_tablesrust-analyzer cargo exr 1.74.0 block/reader/validate_offset_tables().(headers: &[Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#], offset_tables: &OffsetTablesrust-analyzer cargo exr 1.74.0 meta/OffsetTables#, chunks_start_byte: usize) -> UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult# {
124 let max_pixel_bytes: usize = headers.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() // when compressed, chunks are smaller, but never larger than max
125 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|header| header.max_pixel_file_bytesrust-analyzer cargo exr 1.74.0 meta/header/impl#[Header]max_pixel_file_bytes().())
126 .sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().();
127
128 // check that each offset is within the bounds
129 let end_byte = chunks_start_byte 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().max_pixel_bytes;
130 let is_invalid = offset_tables.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|&u64| u64_to_usizerust-analyzer cargo exr 1.74.0 error/u64_to_usize().(u64, "chunk start"))
131 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|maybe_chunk_start| match maybe_chunk_start {
132 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(chunk_start) => chunk_start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().chunks_start_byte || chunk_start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().end_byte,
133 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => true
134 });
135
136 if is_invalid { Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().("offset table")) }
137 else { Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) }
138 }
139
140
141
142
143 /// Decode the desired chunks and skip the unimportant chunks in the file.
144 /// The decoded chunks can be decompressed by calling
145 /// `decompress_parallel`, `decompress_sequential`, or `sequential_decompressor` or `parallel_decompressor`.
146 /// Call `on_progress` to have a callback with each block.
147 /// Also contains the image meta data.
148 #[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:)]
149 pub struct FilteredChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#<R> {
150 meta_datarust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#meta_data.: MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#,
151 expected_filtered_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#expected_filtered_chunk_count.: usize,
152 remaining_filtered_chunk_indicesrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#remaining_filtered_chunk_indices.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::IntoIterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/IntoIter#<u64>,
153 remaining_bytesrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#remaining_bytes.: PeekReadrust-analyzer cargo exr 1.74.0 io/PeekRead#<Trackingrust-analyzer cargo exr 1.74.0 io/Tracking#<R>>,
154 }
155
156 /// Decode all chunks in the file without seeking.
157 /// The decoded chunks can be decompressed by calling
158 /// `decompress_parallel`, `decompress_sequential`, or `sequential_decompressor` or `parallel_decompressor`.
159 /// Call `on_progress` to have a callback with each block.
160 /// Also contains the image meta data.
161 #[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:)]
162 pub struct AllChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#<R> {
163 meta_datarust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#meta_data.: MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#,
164 remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_chunks.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>,
165 remaining_bytesrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_bytes.: PeekReadrust-analyzer cargo exr 1.74.0 io/PeekRead#<Trackingrust-analyzer cargo exr 1.74.0 io/Tracking#<R>>,
166 pedanticrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#pedantic.: bool,
167 }
168
169 /// Decode chunks in the file without seeking.
170 /// Calls the supplied closure for each chunk.
171 /// The decoded chunks can be decompressed by calling
172 /// `decompress_parallel`, `decompress_sequential`, or `sequential_decompressor`.
173 /// Also contains the image meta data.
174 #[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:)]
175 pub struct OnProgressChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#<R, F> {
176 chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#chunks_reader.: R,
177 decoded_chunksrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#decoded_chunks.: usize,
178 callbackrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#callback.: F,
179 }
180
181 /// Decode chunks in the file.
182 /// The decoded chunks can be decompressed by calling
183 /// `decompress_parallel`, `decompress_sequential`, or `sequential_decompressor`.
184 /// Call `on_progress` to have a callback with each block.
185 /// Also contains the image meta data.
186 pub trait ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#=Resultrust-analyzer cargo exr 1.74.0 error/Result#<Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#>> + ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# {
187
188 /// The decoded exr meta data from the file.
189 fn meta_datarust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#meta_data().(&self) -> &MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#;
190
191 /// The decoded exr headers from the file.
192 fn headersrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#headers().(&self) -> &[Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#] { &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#meta_data().().headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers. }
193
194 /// The number of chunks that this reader will return in total.
195 /// Can be less than the total number of chunks in the file, if some chunks are skipped.
196 fn expected_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#expected_chunk_count().(&self) -> usize;
197
198 /// Read the next compressed chunk from the file.
199 /// Equivalent to `.next()`, as this also is an iterator.
200 /// Returns `None` if all chunks have been read.
201 fn read_next_chunkrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#read_next_chunk().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Resultrust-analyzer cargo exr 1.74.0 error/Result#<Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#>> { self.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() }
202
203 /// Create a new reader that calls the provided progress
204 /// callback for each chunk that is read from the file.
205 /// If the file can be successfully decoded,
206 /// the progress will always at least once include 0.0 at the start and 1.0 at the end.
207 fn on_progressrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#on_progress().<F>(self, on_progress: F) -> OnProgressChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#<Self, F> where F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(f64) {
208 OnProgressChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader# { chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#chunks_reader.: self, callbackrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#callback.: on_progress, decoded_chunksrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#decoded_chunks.: 0 }
209 }
210
211 #[cfg(feature = "rayon")]
212 /// Decompress all blocks in the file, using multiple cpu cores, and call the supplied closure for each block.
213 /// The order of the blocks is not deterministic.
214 /// You can also use `parallel_decompressor` to obtain an iterator instead.
215 /// Will fallback to sequential processing where threads are not available, or where it would not speed up the process.
216 // FIXME try async + futures instead of rayon! Maybe even allows for external async decoding? (-> impl Stream<UncompressedBlock>)
217 fn decompress_parallelrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#decompress_parallel().(
218 self, pedantic: bool,
219 mut insert_block: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#, UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#) -> UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult#
220 ) -> UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult#
221 {
222 let mut decompressor = match self.parallel_decompressorrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#parallel_decompressor().(pedantic) {
223 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(old_self) => return old_self.decompress_sequentialrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#decompress_sequential().(pedantic, insert_block),
224 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decompressor) => decompressor,
225 };
226
227 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(block) = decompressor.nextrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`][Iterator]next().() {
228 insert_block(decompressor.meta_datarust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`]meta_data().(), block?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
229 }
230
231 debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(decompressor.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().(), 0, "compressed blocks left after decompressing all blocks");
232 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
233 }
234
235 #[cfg(feature = "rayon")]
236 /// Return an iterator that decompresses the chunks with multiple threads.
237 /// The order of the blocks is not deterministic.
238 /// Use `ParallelBlockDecompressor::new` if you want to use your own thread pool.
239 /// By default, this uses as many threads as there are CPUs.
240 /// Returns the `self` if there is no need for parallel decompression.
241 fn parallel_decompressorrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#parallel_decompressor().(self, pedantic: bool) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<ParallelBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#<Self>, Self> {
242 ParallelBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#::newrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`]new().(self, pedantic)
243 }
244
245 /// Return an iterator that decompresses the chunks in this thread.
246 /// You can alternatively use `sequential_decompressor` if you prefer an external iterator.
247 fn decompress_sequentialrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#decompress_sequential().(
248 self, pedantic: bool,
249 mut insert_block: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#, UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#) -> UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult#
250 ) -> UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult#
251 {
252 let mut decompressor = self.sequential_decompressorrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#sequential_decompressor().(pedantic);
253 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(block) = decompressor.nextrust-analyzer cargo exr 1.74.0 block/reader/impl#[`SequentialBlockDecompressor<R>`][Iterator]next().() {
254 insert_block(decompressor.meta_datarust-analyzer cargo exr 1.74.0 block/reader/impl#[`SequentialBlockDecompressor<R>`]meta_data().(), block?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
255 }
256
257 debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(decompressor.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().(), 0, "compressed blocks left after decompressing all blocks");
258 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
259 }
260
261 /// Prepare reading the chunks sequentially, only a single thread, but with less memory overhead.
262 fn sequential_decompressorrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#sequential_decompressor().(self, pedantic: bool) -> SequentialBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#<Self> {
263 SequentialBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor# { remaining_chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#remaining_chunks_reader.: self, pedanticrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#pedantic. }
264 }
265 }
266
267 impl<R, F> ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader# for OnProgressChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#<R, F> where R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(f64) {
268 fn meta_datarust-analyzer cargo exr 1.74.0 block/reader/impl#[`OnProgressChunksReader<R, F>`][ChunksReader]meta_data().(&self) -> &MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData# { self.chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#chunks_reader..meta_datarust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#meta_data().() }
269 fn expected_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/impl#[`OnProgressChunksReader<R, F>`][ChunksReader]expected_chunk_count().(&self) -> usize { self.chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#chunks_reader..expected_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#expected_chunk_count().() }
270 }
271
272 impl<R, F> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for OnProgressChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#<R, F> where R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(f64) {}
273 impl<R, F> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for OnProgressChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#<R, F> where R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(f64) {
274 type Itemrust-analyzer cargo exr 1.74.0 block/reader/impl#[`OnProgressChunksReader<R, F>`][Iterator]Item# = Resultrust-analyzer cargo exr 1.74.0 error/Result#<Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#>;
275
276 fn nextrust-analyzer cargo exr 1.74.0 block/reader/impl#[`OnProgressChunksReader<R, F>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`OnProgressChunksReader<R, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
277 self.chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#chunks_reader..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|item|{
278 {
279 let total_chunks = self.expected_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/impl#[`OnProgressChunksReader<R, F>`][ChunksReader]expected_chunk_count().() as f64;
280 let callback = &mut self.callbackrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#callback.;
281 callback(self.decoded_chunksrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#decoded_chunks. as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().total_chunks);
282 }
283
284 self.decoded_chunksrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#decoded_chunks. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
285 item
286 })
287 .or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(||{
288 debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(
289 self.decoded_chunksrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#decoded_chunks., self.expected_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/impl#[`OnProgressChunksReader<R, F>`][ChunksReader]expected_chunk_count().(),
290 "chunks reader finished but not all chunks are decompressed"
291 );
292
293 let callback = &mut self.callbackrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#callback.;
294 callback(1.0);
295 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
296 })
297 }
298
299 fn size_hintrust-analyzer cargo exr 1.74.0 block/reader/impl#[`OnProgressChunksReader<R, F>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
300 self.chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/OnProgressChunksReader#chunks_reader..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().()
301 }
302 }
303
304 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader# for AllChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#<R> {
305 fn meta_datarust-analyzer cargo exr 1.74.0 block/reader/impl#[`AllChunksReader<R>`][ChunksReader]meta_data().(&self) -> &MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData# { &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#meta_data. }
306 fn expected_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/impl#[`AllChunksReader<R>`][ChunksReader]expected_chunk_count().(&self) -> usize { self.remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_chunks..endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end. }
307 }
308
309 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for AllChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#<R> {}
310 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for AllChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#<R> {
311 type Itemrust-analyzer cargo exr 1.74.0 block/reader/impl#[`AllChunksReader<R>`][Iterator]Item# = Resultrust-analyzer cargo exr 1.74.0 error/Result#<Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#>;
312
313 fn nextrust-analyzer cargo exr 1.74.0 block/reader/impl#[`AllChunksReader<R>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`AllChunksReader<R>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
314 // read as many chunks as the file should contain (inferred from meta data)
315 let next_chunk = self.remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_chunks..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/range/impl#[`ops::Range<A>`][Iterator]next().()
316 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|_| Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#::readrust-analyzer cargo exr 1.74.0 block/chunk/impl#[Chunk]read().(&mut self.remaining_bytesrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_bytes., &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#meta_data.));
317
318 // if no chunks are left, but some bytes remain, return error
319 if self.pedanticrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#pedantic. && next_chunk.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() && self.remaining_bytesrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_bytes..peek_u8rust-analyzer cargo exr 1.74.0 io/impl#[`PeekRead<T>`]peek_u8().().is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() {
320 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().("end of file expected")));
321 }
322
323 next_chunk
324 }
325
326 fn size_hintrust-analyzer cargo exr 1.74.0 block/reader/impl#[`AllChunksReader<R>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
327 (self.remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_chunks..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/AllChunksReader#remaining_chunks..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().()))
328 }
329 }
330
331 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader# for FilteredChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#<R> {
332 fn meta_datarust-analyzer cargo exr 1.74.0 block/reader/impl#[`FilteredChunksReader<R>`][ChunksReader]meta_data().(&self) -> &MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData# { &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#meta_data. }
333 fn expected_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/impl#[`FilteredChunksReader<R>`][ChunksReader]expected_chunk_count().(&self) -> usize { self.expected_filtered_chunk_countrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#expected_filtered_chunk_count. }
334 }
335
336 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for FilteredChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#<R> {}
337 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for FilteredChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#<R> {
338 type Itemrust-analyzer cargo exr 1.74.0 block/reader/impl#[`FilteredChunksReader<R>`][Iterator]Item# = Resultrust-analyzer cargo exr 1.74.0 error/Result#<Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#>;
339
340 fn nextrust-analyzer cargo exr 1.74.0 block/reader/impl#[`FilteredChunksReader<R>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`FilteredChunksReader<R>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
341 // read as many chunks as we have desired chunk offsets
342 self.remaining_filtered_chunk_indicesrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#remaining_filtered_chunk_indices..nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|next_chunk_location|{
343 self.remaining_bytesrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#remaining_bytes..skip_torust-analyzer cargo exr 1.74.0 io/impl#[`PeekRead<Tracking<T>>`]skip_to().( // no-op for seek at current position, uses skip_bytes for small amounts
344 usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<u64>`]try_from().(next_chunk_location)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
345 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
346
347 let meta_data = &self.meta_datarust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#meta_data.;
348 Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#::readrust-analyzer cargo exr 1.74.0 block/chunk/impl#[Chunk]read().(&mut self.remaining_bytesrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#remaining_bytes., meta_data)
349 })
350
351 // TODO remember last chunk index and then seek to index+size and check whether bytes are left?
352 }
353
354 fn size_hintrust-analyzer cargo exr 1.74.0 block/reader/impl#[`FilteredChunksReader<R>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
355 (self.remaining_filtered_chunk_indicesrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#remaining_filtered_chunk_indices..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.remaining_filtered_chunk_indicesrust-analyzer cargo exr 1.74.0 block/reader/FilteredChunksReader#remaining_filtered_chunk_indices..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().()))
356 }
357 }
358
359 /// Read all chunks from the file, decompressing each chunk immediately.
360 /// Implements iterator.
361 #[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:)]
362 pub struct SequentialBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#<R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#> {
363 remaining_chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#remaining_chunks_reader.: R,
364 pedanticrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#pedantic.: bool,
365 }
366
367 impl<R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#> SequentialBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#<R> {
368
369 /// The extracted meta data from the image file.
370 pub fn meta_datarust-analyzer cargo exr 1.74.0 block/reader/impl#[`SequentialBlockDecompressor<R>`]meta_data().(&self) -> &MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData# { self.remaining_chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#remaining_chunks_reader..meta_datarust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#meta_data().() }
371
372 /// Read and then decompress a single block of pixels from the byte source.
373 pub fn decompress_next_blockrust-analyzer cargo exr 1.74.0 block/reader/impl#[`SequentialBlockDecompressor<R>`]decompress_next_block().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Resultrust-analyzer cargo exr 1.74.0 error/Result#<UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#>> {
374 self.remaining_chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#remaining_chunks_reader..read_next_chunkrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#read_next_chunk().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|compressed_chunk|{
375 UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#::decompress_chunkrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]decompress_chunk().(compressed_chunk?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., &self.remaining_chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#remaining_chunks_reader..meta_datarust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#meta_data().(), self.pedanticrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#pedantic.)
376 })
377 }
378 }
379
380 #[cfg(feature = "rayon")]
381 /// Decompress the chunks in a file in parallel.
382 /// The first call to `next` will fill the thread pool with jobs,
383 /// starting to decompress the next few blocks.
384 /// These jobs will finish, even if you stop reading more blocks.
385 /// Implements iterator.
386 #[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:)]
387 pub struct ParallelBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#<R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#> {
388 remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#remaining_chunks.: R,
389 senderrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#sender.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::mpscrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/::Senderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/Sender#<Resultrust-analyzer cargo exr 1.74.0 error/Result#<UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#>>,
390 receiverrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#receiver.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::mpscrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/::Receiverrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/Receiver#<Resultrust-analyzer cargo exr 1.74.0 error/Result#<UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#>>,
391 currently_decompressing_countrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#currently_decompressing_count.: usize,
392 max_threadsrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#max_threads.: usize,
393
394 shared_meta_data_refrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#shared_meta_data_ref.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#>,
395 pedanticrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#pedantic.: bool,
396
397 poolrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#pool.: rayon_corerust-analyzer cargo rayon-core 1.13.0 crate/::ThreadPoolrust-analyzer cargo rayon-core 1.13.0 thread_pool/ThreadPool#,
398 }
399
400 #[cfg(feature = "rayon")]
401 impl<R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#> ParallelBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#<R> {
402
403 /// Create a new decompressor. Does not immediately spawn any tasks.
404 /// Decompression starts after the first call to `next`.
405 /// Returns the chunks if parallel decompression should not be used.
406 /// Use `new_with_thread_pool` to customize the threadpool.
407 pub fn newrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`]new().(chunks: R, pedantic: bool) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`], R> {
408 Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`]::new_with_thread_poolrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`]new_with_thread_pool().(chunks, pedantic, ||{
409 rayon_corerust-analyzer cargo rayon-core 1.13.0 crate/::ThreadPoolBuilderrust-analyzer cargo rayon-core 1.13.0 ThreadPoolBuilder#::newrust-analyzer cargo rayon-core 1.13.0 impl#[ThreadPoolBuilder]new().()
410 .thread_namerust-analyzer cargo rayon-core 1.13.0 impl#[`ThreadPoolBuilder<S>`]thread_name().(|index| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("OpenEXR Block Decompressor Thread #{}", index))
411 .buildrust-analyzer cargo rayon-core 1.13.0 impl#[`ThreadPoolBuilder<S>`]build().()
412 })
413 }
414
415 /// Create a new decompressor. Does not immediately spawn any tasks.
416 /// Decompression starts after the first call to `next`.
417 /// Returns the chunks if parallel decompression should not be used.
418 pub fn new_with_thread_poolrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`]new_with_thread_pool().<CreatePool>(chunks: R, pedantic: bool, try_create_thread_pool: CreatePool)
419 -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`], R>
420 where CreatePool: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<rayon_corerust-analyzer cargo rayon-core 1.13.0 crate/::ThreadPoolrust-analyzer cargo rayon-core 1.13.0 thread_pool/ThreadPool#, rayon_corerust-analyzer cargo rayon-core 1.13.0 crate/::ThreadPoolBuildErrorrust-analyzer cargo rayon-core 1.13.0 ThreadPoolBuildError#>
421 {
422 use craterust-analyzer cargo exr 1.74.0 crate/::compressionrust-analyzer cargo exr 1.74.0 compression/::Compressionrust-analyzer cargo exr 1.74.0 compression/Compression#;
423
424 let is_entirely_uncompressed = chunks.meta_datarust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#meta_data().().headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
425 .allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]all().(|head|head.compressionrust-analyzer cargo exr 1.74.0 meta/header/Header#compression. rust-analyzer cargo exr 1.74.0 compression/impl#[Compression][`PartialEq<Self>`]eq().==rust-analyzer cargo exr 1.74.0 compression/impl#[Compression][`PartialEq<Self>`]eq(). rust-analyzer cargo exr 1.74.0 compression/impl#[Compression][`PartialEq<Self>`]eq().Compressionrust-analyzer cargo exr 1.74.0 compression/Compression#::Uncompressedrust-analyzer cargo exr 1.74.0 compression/Compression#Uncompressed#);
426
427 // if no compression is used in the file, don't use a threadpool
428 if is_entirely_uncompressed {
429 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(chunks);
430 }
431
432 // in case thread pool creation fails (for example on WASM currently),
433 // we revert to sequential decompression
434 let pool = match try_create_thread_pool() {
435 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(pool) => pool,
436
437 // TODO print warning?
438 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(chunks),
439 };
440
441 let max_threads = pool.current_num_threadsrust-analyzer cargo rayon-core 1.13.0 thread_pool/impl#[ThreadPool]current_num_threads().().maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(1).minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(chunks.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][`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().2; // ca one block for each thread at all times
442
443 let (send, recv) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::mpscrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/::channelrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/channel().(); // TODO bounded channel simplifies logic?
444
445 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`] {
446 shared_meta_data_refrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#shared_meta_data_ref.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(chunks.meta_datarust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#meta_data().().clonerust-analyzer cargo exr 1.74.0 meta/impl#[MetaData][Clone]clone().()),
447 currently_decompressing_countrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#currently_decompressing_count.: 0,
448 remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#remaining_chunks.: chunks,
449 senderrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#sender.: send,
450 receiverrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#receiver.: recv,
451 pedanticrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#pedantic.,
452 max_threadsrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#max_threads.,
453
454 poolrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#pool.,
455 })
456 }
457
458 /// Fill the pool with decompression jobs. Returns the first job that finishes.
459 pub fn decompress_next_blockrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`]decompress_next_block().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Resultrust-analyzer cargo exr 1.74.0 error/Result#<UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#>> {
460
461 while self.currently_decompressing_countrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#currently_decompressing_count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.max_threadsrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#max_threads. {
462 let block = self.remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#remaining_chunks..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().();
463 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(block) = block {
464 let block = match block {
465 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(block) => block,
466 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error))
467 };
468
469 let sender = self.senderrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#sender..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/impl#[`Sender<T>`][Clone]clone().();
470 let meta = self.shared_meta_data_refrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#shared_meta_data_ref..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().();
471 let pedantic = self.pedanticrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#pedantic.;
472
473 self.currently_decompressing_countrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#currently_decompressing_count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
474
475 self.poolrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#pool..spawnrust-analyzer cargo rayon-core 1.13.0 thread_pool/impl#[ThreadPool]spawn().(move || {
476 let decompressed_or_err = UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#::decompress_chunkrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]decompress_chunk().(
477 block, &meta, pedantic
478 );
479
480 // by now, decompressing could have failed in another thread.
481 // the error is then already handled, so we simply
482 // don't send the decompressed block and do nothing
483 let _ = sender.sendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/impl#[`Sender<T>`]send().(decompressed_or_err);
484 });
485 }
486 else {
487 // there are no chunks left to decompress
488 break;
489 }
490 }
491
492 if self.currently_decompressing_countrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#currently_decompressing_count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
493 let next = self.receiverrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#receiver..recvrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/impl#[`Receiver<T>`]recv().()
494 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("all decompressing senders hung up but more messages were expected");
495
496 self.currently_decompressing_countrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#currently_decompressing_count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
497 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next)
498 }
499 else {
500 debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(self.receiverrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#receiver..try_recvrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/impl#[`Receiver<T>`]try_recv().().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().(), "uncompressed chunks left in channel after decompressing all chunks"); // TODO not reliable
501 debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(self.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/impl#[`&mut I`][ExactSizeIterator]len().(), 0, "compressed chunks left after decompressing all chunks");
502 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
503 }
504 }
505
506 /// The extracted meta data of the image file.
507 pub fn meta_datarust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`]meta_data().(&self) -> &MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData# { self.remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#remaining_chunks..meta_datarust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#meta_data().() }
508 }
509
510 impl<R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for SequentialBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#<R> {}
511 impl<R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for SequentialBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#<R> {
512 type Itemrust-analyzer cargo exr 1.74.0 block/reader/impl#[`SequentialBlockDecompressor<R>`][Iterator]Item# = Resultrust-analyzer cargo exr 1.74.0 error/Result#<UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#>;
513 fn nextrust-analyzer cargo exr 1.74.0 block/reader/impl#[`SequentialBlockDecompressor<R>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`SequentialBlockDecompressor<R>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { self.decompress_next_blockrust-analyzer cargo exr 1.74.0 block/reader/impl#[`SequentialBlockDecompressor<R>`]decompress_next_block().() }
514 fn size_hintrust-analyzer cargo exr 1.74.0 block/reader/impl#[`SequentialBlockDecompressor<R>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { self.remaining_chunks_readerrust-analyzer cargo exr 1.74.0 block/reader/SequentialBlockDecompressor#remaining_chunks_reader..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().() }
515 }
516
517 #[cfg(feature = "rayon")]
518 impl<R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for ParallelBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#<R> {}
519 #[cfg(feature = "rayon")]
520 impl<R: ChunksReaderrust-analyzer cargo exr 1.74.0 block/reader/ChunksReader#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for ParallelBlockDecompressorrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#<R> {
521 type Itemrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`][Iterator]Item# = Resultrust-analyzer cargo exr 1.74.0 error/Result#<UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#>;
522 fn nextrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { self.decompress_next_blockrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`]decompress_next_block().() }
523 fn size_hintrust-analyzer cargo exr 1.74.0 block/reader/impl#[`ParallelBlockDecompressor<R>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
524 let remaining = self.remaining_chunksrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#remaining_chunks..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][`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().self.currently_decompressing_countrust-analyzer cargo exr 1.74.0 block/reader/ParallelBlockDecompressor#currently_decompressing_count.;
525 (remaining, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(remaining))
526 }
527 }
528
529
530
531
532