Debian Codegraph @

src/block/mod.rs

raw symbols SCIP
1 //! This is the low-level interface for the raw blocks of an image.
2 //! See `exr::image` module for a high-level interface.
3 //!
4 //! Handle compressed and uncompressed pixel byte blocks. Includes compression and decompression,
5 //! and reading a complete image into blocks.
6 //!
7 //! Start with the `block::read(...)`
8 //! and `block::write(...)` functions.
9
10
11 pub mod writerrust-analyzer cargo exr 1.74.0 block/writer/;
12 pub mod readerrust-analyzer cargo exr 1.74.0 block/reader/;
13
14 pub mod linesrust-analyzer cargo exr 1.74.0 block/lines/;
15 pub mod samplesrust-analyzer cargo exr 1.74.0 block/samples/;
16 pub mod chunkrust-analyzer cargo exr 1.74.0 block/chunk/;
17
18
19 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#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#};
20 use craterust-analyzer cargo exr 1.74.0 crate/::errorrust-analyzer cargo exr 1.74.0 error/::{Resultrust-analyzer cargo exr 1.74.0 error/Result#, UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult#, Errorrust-analyzer cargo exr 1.74.0 error/Error#, usize_to_i32rust-analyzer cargo exr 1.74.0 error/usize_to_i32().};
21 use craterust-analyzer cargo exr 1.74.0 crate/::metarust-analyzer cargo exr 1.74.0 meta/::{Headersrust-analyzer cargo exr 1.74.0 meta/Headers#, MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#, BlockDescriptionrust-analyzer cargo exr 1.74.0 meta/BlockDescription#};
22 use craterust-analyzer cargo exr 1.74.0 crate/::mathrust-analyzer cargo exr 1.74.0 math/::Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#;
23 use craterust-analyzer cargo exr 1.74.0 crate/::compressionrust-analyzer cargo exr 1.74.0 compression/::ByteVecrust-analyzer cargo exr 1.74.0 compression/ByteVec#;
24 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/::{CompressedBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedBlock#, CompressedTileBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedTileBlock#, CompressedScanLineBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedScanLineBlock#, Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#, TileCoordinatesrust-analyzer cargo exr 1.74.0 block/chunk/TileCoordinates#};
25 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#;
26 use craterust-analyzer cargo exr 1.74.0 crate/::blockrust-analyzer cargo exr 1.74.0 block/::linesrust-analyzer cargo exr 1.74.0 block/lines/::{LineIndexrust-analyzer cargo exr 1.74.0 block/lines/LineIndex#, LineRefrust-analyzer cargo exr 1.74.0 block/lines/LineRef#, LineSlicerust-analyzer cargo exr 1.74.0 block/lines/LineSlice#, LineRefMutrust-analyzer cargo exr 1.74.0 block/lines/LineRefMut#};
27 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/::ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#;
28
29
30 /// Specifies where a block of pixel data should be placed in the actual image.
31 /// This is a globally unique identifier which
32 /// includes the layer, level index, and pixel location.
33 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
34 pub struct BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex# {
35
36 /// Index of the layer.
37 pub layerrust-analyzer cargo exr 1.74.0 block/BlockIndex#layer.: usize,
38
39 /// Index of the top left pixel from the block within the data window.
40 pub pixel_positionrust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_position.: Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#<usize>,
41
42 /// Number of pixels in this block, extending to the right and downwards.
43 /// Stays the same across all resolution levels.
44 pub pixel_sizerust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_size.: Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#<usize>,
45
46 /// Index of the mip or rip level in the image.
47 pub levelrust-analyzer cargo exr 1.74.0 block/BlockIndex#level.: Vec2rust-analyzer cargo exr 1.74.0 math/Vec2#<usize>,
48 }
49
50 /// Contains a block of pixel data and where that data should be placed in the actual image.
51 /// The bytes must be encoded in native-endian format.
52 /// The conversion to little-endian format happens when converting to chunks (potentially in parallel).
53 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
54 pub struct UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock# {
55
56 /// Location of the data inside the image.
57 pub indexrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#index.: BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex#,
58
59 /// Uncompressed pixel values of the whole block.
60 /// One or more scan lines may be stored together as a scan line block.
61 /// This byte vector contains all pixel rows, one after another.
62 /// For each line in the tile, for each channel, the row values are contiguous.
63 /// Stores all samples of the first channel, then all samples of the second channel, and so on.
64 /// This data is in native-endian format.
65 pub datarust-analyzer cargo exr 1.74.0 block/UncompressedBlock#data.: ByteVecrust-analyzer cargo exr 1.74.0 compression/ByteVec#,
66 }
67
68 /// Immediately reads the meta data from the file.
69 /// Then, returns a reader that can be used to read all pixel blocks.
70 /// From the reader, you can pull each compressed chunk from the file.
71 /// Alternatively, you can create a decompressor, and pull the uncompressed data from it.
72 /// The reader is assumed to be buffered.
73 pub fn readrust-analyzer cargo exr 1.74.0 block/read().<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#>(buffered_read: R, pedantic: bool) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<selfrust-analyzer cargo exr 1.74.0 block/::readerrust-analyzer cargo exr 1.74.0 block/reader/::Readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#<R>> {
74 selfrust-analyzer cargo exr 1.74.0 block/::readerrust-analyzer cargo exr 1.74.0 block/reader/::Readerrust-analyzer cargo exr 1.74.0 block/reader/Reader#::read_from_bufferedrust-analyzer cargo exr 1.74.0 block/reader/impl#[`Reader<R>`]read_from_buffered().(buffered_read, pedantic)
75 }
76
77 /// Immediately writes the meta data to the file.
78 /// Then, calls a closure with a writer that can be used to write all pixel blocks.
79 /// In the closure, you can push compressed chunks directly into the writer.
80 /// Alternatively, you can create a compressor, wrapping the writer, and push the uncompressed data to it.
81 /// The writer is assumed to be buffered.
82 pub fn writerust-analyzer cargo exr 1.74.0 block/write().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#>(
83 buffered_write: W, headers: Headersrust-analyzer cargo exr 1.74.0 meta/Headers#, compatibility_checks: bool,
84 write_chunks: impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#, &mut selfrust-analyzer cargo exr 1.74.0 block/::writerrust-analyzer cargo exr 1.74.0 block/writer/::ChunkWriterrust-analyzer cargo exr 1.74.0 block/writer/ChunkWriter#<W>) -> UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult#
85 ) -> UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult# {
86 selfrust-analyzer cargo exr 1.74.0 block/::writerrust-analyzer cargo exr 1.74.0 block/writer/::write_chunks_withrust-analyzer cargo exr 1.74.0 block/writer/write_chunks_with().(buffered_write, headers, compatibility_checks, write_chunks)
87 }
88
89
90
91
92 /// This iterator tells you the block indices of all blocks that must be in the image.
93 /// The order of the blocks depends on the `LineOrder` attribute
94 /// (unspecified line order is treated the same as increasing line order).
95 /// The blocks written to the file must be exactly in this order,
96 /// except for when the `LineOrder` is unspecified.
97 /// The index represents the block index, in increasing line order, within the header.
98 pub fn enumerate_ordered_header_block_indicesrust-analyzer cargo exr 1.74.0 block/enumerate_ordered_header_block_indices().(headers: &[Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#]) -> impl '_ + 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#=(usize, BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex#)> {
99 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().().flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|(layer_index, header)|{
100 header.enumerate_ordered_blocksrust-analyzer cargo exr 1.74.0 meta/header/impl#[Header]enumerate_ordered_blocks().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(move |(index_in_header, tile)|{
101 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.).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("tile coordinate bug");
102
103 let block = BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex# {
104 layerrust-analyzer cargo exr 1.74.0 block/BlockIndex#layer.: layer_index,
105 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.,
106 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").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("data index bug"),
107 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.,
108 };
109
110 (index_in_header, block)
111 })
112 })
113 }
114
115
116 impl UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock# {
117
118 /// Decompress the possibly compressed chunk and returns an `UncompressedBlock`.
119 // for uncompressed data, the ByteVec in the chunk is moved all the way
120 #[inline]
121 #[must_use]
122 pub fn decompress_chunkrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]decompress_chunk().(chunk: Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#, meta_data: &MetaDatarust-analyzer cargo exr 1.74.0 meta/MetaData#, pedantic: bool) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<Selfrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]> {
123 let header: &Headerrust-analyzer cargo exr 1.74.0 meta/header/Header# = meta_data.headersrust-analyzer cargo exr 1.74.0 meta/MetaData#headers..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(chunk.layer_indexrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#layer_index.)
124 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().("chunk layer index"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
125
126 let tile_data_indices = header.get_block_data_indicesrust-analyzer cargo exr 1.74.0 meta/header/impl#[Header]get_block_data_indices().(&chunk.compressed_blockrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#compressed_block.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
127 let absolute_indices = header.get_absolute_block_pixel_coordinatesrust-analyzer cargo exr 1.74.0 meta/header/impl#[Header]get_absolute_block_pixel_coordinates().(tile_data_indices)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
128
129 absolute_indices.validaterust-analyzer cargo exr 1.74.0 meta/attribute/impl#[IntegerBounds]validate().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(header.layer_sizerust-analyzer cargo exr 1.74.0 meta/header/Header#layer_size.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
130
131 match chunk.compressed_blockrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#compressed_block. {
132 CompressedBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedBlock#::Tilerust-analyzer cargo exr 1.74.0 block/chunk/CompressedBlock#Tile#(CompressedTileBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedTileBlock# { compressed_pixels_lerust-analyzer cargo exr 1.74.0 block/chunk/CompressedTileBlock#compressed_pixels_le., .. }) |
133 CompressedBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedBlock#::ScanLinerust-analyzer cargo exr 1.74.0 block/chunk/CompressedBlock#ScanLine#(CompressedScanLineBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedScanLineBlock# { compressed_pixels_lerust-analyzer cargo exr 1.74.0 block/chunk/CompressedScanLineBlock#compressed_pixels_le., .. }) => {
134 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock# {
135 datarust-analyzer cargo exr 1.74.0 block/UncompressedBlock#data.: header.compressionrust-analyzer cargo exr 1.74.0 meta/header/Header#compression..decompress_image_section_from_lerust-analyzer cargo exr 1.74.0 compression/impl#[Compression]decompress_image_section_from_le().(header, compressed_pixels_le, absolute_indices, pedantic)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
136 indexrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#index.: BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex# {
137 layerrust-analyzer cargo exr 1.74.0 block/BlockIndex#layer.: chunk.layer_indexrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#layer_index.,
138 pixel_positionrust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_position.: absolute_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().,
139 levelrust-analyzer cargo exr 1.74.0 block/BlockIndex#level.: tile_data_indices.level_indexrust-analyzer cargo exr 1.74.0 block/chunk/TileCoordinates#level_index.,
140 pixel_sizerust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_size.: absolute_indices.sizerust-analyzer cargo exr 1.74.0 meta/attribute/IntegerBounds#size.,
141 }
142 })
143 },
144
145 _ => 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#::unsupportedrust-analyzer cargo exr 1.74.0 error/impl#[Error]unsupported().("deep data not supported yet"))
146 }
147 }
148
149 /// Consume this block by compressing it, returning a `Chunk`.
150 // for uncompressed data, the ByteVec in the chunk is moved all the way
151 #[inline]
152 #[must_use]
153 pub fn compress_to_chunkrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]compress_to_chunk().(self, headers: &[Headerrust-analyzer cargo exr 1.74.0 meta/header/Header#]) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#> {
154 let UncompressedBlockrust-analyzer cargo exr 1.74.0 block/UncompressedBlock# { datarust-analyzer cargo exr 1.74.0 block/UncompressedBlock#data., indexrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#index. } = self;
155
156 let header: &Headerrust-analyzer cargo exr 1.74.0 meta/header/Header# = headers.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(index.layerrust-analyzer cargo exr 1.74.0 block/BlockIndex#layer.)
157 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("block layer index bug");
158
159 let expected_byte_size = 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. 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.indexrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#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().(); // TODO sampling??
160 if expected_byte_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
161 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("get_line byte size should be {} but was {}", expected_byte_size, data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
162 }
163
164 let tile_coordinates = TileCoordinatesrust-analyzer cargo exr 1.74.0 block/chunk/TileCoordinates# {
165 // FIXME this calculation should not be made here but elsewhere instead (in meta::header?)
166 tile_indexrust-analyzer cargo exr 1.74.0 block/chunk/TileCoordinates#tile_index.: index.pixel_positionrust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_position. rust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`][`Div<Self>`]div()./rust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`][`Div<Self>`]div(). rust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`][`Div<Self>`]div().header.max_block_pixel_sizerust-analyzer cargo exr 1.74.0 meta/header/impl#[Header]max_block_pixel_size().(), // TODO sampling??
167 level_indexrust-analyzer cargo exr 1.74.0 block/chunk/TileCoordinates#level_index.: index.levelrust-analyzer cargo exr 1.74.0 block/BlockIndex#level.,
168 };
169
170 let absolute_indices = header.get_absolute_block_pixel_coordinatesrust-analyzer cargo exr 1.74.0 meta/header/impl#[Header]get_absolute_block_pixel_coordinates().(tile_coordinates)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
171 absolute_indices.validaterust-analyzer cargo exr 1.74.0 meta/attribute/impl#[IntegerBounds]validate().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(header.layer_sizerust-analyzer cargo exr 1.74.0 meta/header/Header#layer_size.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
172
173 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().header.compressionrust-analyzer cargo exr 1.74.0 meta/header/Header#compression..may_loose_datarust-analyzer cargo exr 1.74.0 compression/impl#[Compression]may_loose_data().() { debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(
174 &header.compressionrust-analyzer cargo exr 1.74.0 meta/header/Header#compression..decompress_image_section_from_lerust-analyzer cargo exr 1.74.0 compression/impl#[Compression]decompress_image_section_from_le().(
175 header,
176 header.compressionrust-analyzer cargo exr 1.74.0 meta/header/Header#compression..compress_image_section_to_lerust-analyzer cargo exr 1.74.0 compression/impl#[Compression]compress_image_section_to_le().(header, data.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(), absolute_indices)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
177 absolute_indices,
178 true
179 ).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
180 &data,
181 "compression method not round trippin'"
182 ); }
183
184 let compressed_pixels_le = header.compressionrust-analyzer cargo exr 1.74.0 meta/header/Header#compression..compress_image_section_to_lerust-analyzer cargo exr 1.74.0 compression/impl#[Compression]compress_image_section_to_le().(header, data, absolute_indices)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
185
186 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Chunkrust-analyzer cargo exr 1.74.0 block/chunk/Chunk# {
187 layer_indexrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#layer_index.: index.layerrust-analyzer cargo exr 1.74.0 block/BlockIndex#layer.,
188 compressed_blockrust-analyzer cargo exr 1.74.0 block/chunk/Chunk#compressed_block. : match header.blocksrust-analyzer cargo exr 1.74.0 meta/header/Header#blocks. {
189 BlockDescriptionrust-analyzer cargo exr 1.74.0 meta/BlockDescription#::ScanLinesrust-analyzer cargo exr 1.74.0 meta/BlockDescription#ScanLines# => CompressedBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedBlock#::ScanLinerust-analyzer cargo exr 1.74.0 block/chunk/CompressedBlock#ScanLine#(CompressedScanLineBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedScanLineBlock# {
190 compressed_pixels_lerust-analyzer cargo exr 1.74.0 block/chunk/CompressedScanLineBlock#compressed_pixels_le.,
191
192 // FIXME this calculation should not be made here but elsewhere instead (in meta::header?)
193 y_coordinaterust-analyzer cargo exr 1.74.0 block/chunk/CompressedScanLineBlock#y_coordinate.: usize_to_i32rust-analyzer cargo exr 1.74.0 error/usize_to_i32().(index.pixel_positionrust-analyzer cargo exr 1.74.0 block/BlockIndex#pixel_position..yrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]y().(), "pixel index")?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 ops/arith/impl#[i32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().header.own_attributesrust-analyzer cargo exr 1.74.0 meta/header/Header#own_attributes..layer_positionrust-analyzer cargo exr 1.74.0 meta/header/LayerAttributes#layer_position..yrust-analyzer cargo exr 1.74.0 math/impl#[`Vec2<T>`]y().(), // TODO sampling??
194 }),
195
196 BlockDescriptionrust-analyzer cargo exr 1.74.0 meta/BlockDescription#::Tilesrust-analyzer cargo exr 1.74.0 meta/BlockDescription#Tiles#(_) => CompressedBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedBlock#::Tilerust-analyzer cargo exr 1.74.0 block/chunk/CompressedBlock#Tile#(CompressedTileBlockrust-analyzer cargo exr 1.74.0 block/chunk/CompressedTileBlock# {
197 compressed_pixels_lerust-analyzer cargo exr 1.74.0 block/chunk/CompressedTileBlock#compressed_pixels_le.,
198 coordinatesrust-analyzer cargo exr 1.74.0 block/chunk/CompressedTileBlock#coordinates.: tile_coordinates,
199 }),
200 }
201 })
202 }
203
204 /// Iterate all the lines in this block.
205 /// Each line contains the all samples for one of the channels.
206 pub fn linesrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]lines().(&self, channels: &ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#) -> impl 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#=LineRefrust-analyzer cargo exr 1.74.0 block/lines/LineRef#<'_>> {
207 LineIndexrust-analyzer cargo exr 1.74.0 block/lines/LineIndex#::lines_in_blockrust-analyzer cargo exr 1.74.0 block/lines/impl#[LineIndex]lines_in_block().(self.indexrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#index., channels)
208 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(move |(bytes, line)| LineSlicerust-analyzer cargo exr 1.74.0 block/lines/LineSlice# { locationrust-analyzer cargo exr 1.74.0 block/lines/LineSlice#location.: line, valuerust-analyzer cargo exr 1.74.0 block/lines/LineSlice#value.: &self.datarust-analyzer cargo exr 1.74.0 block/UncompressedBlock#data.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().bytes]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). })
209 }
210
211 /* TODO pub fn lines_mut<'s>(&'s mut self, header: &Header) -> impl 's + Iterator<Item=LineRefMut<'s>> {
212 LineIndex::lines_in_block(self.index, &header.channels)
213 .map(move |(bytes, line)| LineSlice { location: line, value: &mut self.data[bytes] })
214 }*/
215
216 /*// TODO make iterator
217 /// Call a closure for each line of samples in this uncompressed block.
218 pub fn for_lines(
219 &self, header: &Header,
220 mut accept_line: impl FnMut(LineRef<'_>) -> UnitResult
221 ) -> UnitResult {
222 for (bytes, line) in LineIndex::lines_in_block(self.index, &header.channels) {
223 let line_ref = LineSlice { location: line, value: &self.data[bytes] };
224 accept_line(line_ref)?;
225 }
226
227 Ok(())
228 }*/
229
230 // TODO from iterator??
231 /// Create an uncompressed block byte vector by requesting one line of samples after another.
232 pub fn collect_block_data_from_linesrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]collect_block_data_from_lines().(
233 channels: &ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#, block_index: BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex#,
234 mut extract_line: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(LineRefMutrust-analyzer cargo exr 1.74.0 block/lines/LineRefMut#<'_>)
235 ) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>
236 {
237 let byte_count = 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().channels.bytes_per_pixelrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#bytes_per_pixel.;
238 let mut block_bytes = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0_u8; byte_count];
239
240 for (byte_range, line_index) in LineIndexrust-analyzer cargo exr 1.74.0 block/lines/LineIndex#::lines_in_blockrust-analyzer cargo exr 1.74.0 block/lines/impl#[LineIndex]lines_in_block().(block_index, channels) {
241 extract_line(LineRefMutrust-analyzer cargo exr 1.74.0 block/lines/LineRefMut# { // TODO subsampling
242 valuerust-analyzer cargo exr 1.74.0 block/lines/LineSlice#value.: &mut block_bytes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().byte_range]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().,
243 locationrust-analyzer cargo exr 1.74.0 block/lines/LineSlice#location.: line_index,
244 });
245 }
246
247 block_bytes
248 }
249
250 /// Create an uncompressed block by requesting one line of samples after another.
251 pub fn from_linesrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]from_lines().(
252 channels: &ChannelListrust-analyzer cargo exr 1.74.0 meta/attribute/ChannelList#, block_index: BlockIndexrust-analyzer cargo exr 1.74.0 block/BlockIndex#,
253 extract_line: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(LineRefMutrust-analyzer cargo exr 1.74.0 block/lines/LineRefMut#<'_>)
254 ) -> Selfrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock] {
255 Selfrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock] {
256 indexrust-analyzer cargo exr 1.74.0 block/UncompressedBlock#index.: block_index,
257 datarust-analyzer cargo exr 1.74.0 block/UncompressedBlock#data.: Selfrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]::collect_block_data_from_linesrust-analyzer cargo exr 1.74.0 block/impl#[UncompressedBlock]collect_block_data_from_lines().(channels, block_index, extract_line)
258 }
259 }
260 }