Debian Codegraph @

src/reader/mod.rs

raw symbols SCIP
1 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
2 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#;
3 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core 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#, TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#};
4 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#;
5 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/;
6 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::numrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/::NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#;
7 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/;
8 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/::preluderust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/prelude/::*;
9
10 use craterust-analyzer cargo gif 0.14.2 crate/::commonrust-analyzer cargo gif 0.14.2 common/::{Blockrust-analyzer cargo gif 0.14.2 common/Block#, Framerust-analyzer cargo gif 0.14.2 common/Frame#};
11 use craterust-analyzer cargo gif 0.14.2 crate/::{AnyExtensionrust-analyzer cargo gif 0.14.2 common/AnyExtension#, Extensionrust-analyzer cargo gif 0.14.2 common/Extension#, Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#};
12
13 mod converterrust-analyzer cargo gif 0.14.2 reader/converter/;
14 mod decoderrust-analyzer cargo gif 0.14.2 reader/decoder/;
15
16 pub use selfrust-analyzer cargo gif 0.14.2 reader/::decoderrust-analyzer cargo gif 0.14.2 reader/decoder/::{
17 Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#, DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#, DecodingFormatErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingFormatError#, FrameDataTyperust-analyzer cargo gif 0.14.2 reader/decoder/FrameDataType#, FrameDecoderrust-analyzer cargo gif 0.14.2 reader/decoder/FrameDecoder#, OutputBufferrust-analyzer cargo gif 0.14.2 reader/decoder/OutputBuffer#,
18 StreamingDecoderrust-analyzer cargo gif 0.14.2 reader/decoder/StreamingDecoder#, Versionrust-analyzer cargo gif 0.14.2 reader/decoder/Version#, PLTE_CHANNELSrust-analyzer cargo gif 0.14.2 reader/decoder/PLTE_CHANNELS.,
19 };
20
21 pub use selfrust-analyzer cargo gif 0.14.2 reader/::converterrust-analyzer cargo gif 0.14.2 reader/converter/::ColorOutputrust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#;
22 use selfrust-analyzer cargo gif 0.14.2 reader/::converterrust-analyzer cargo gif 0.14.2 reader/converter/::PixelConverterrust-analyzer cargo gif 0.14.2 reader/converter/PixelConverter#;
23
24 #[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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
25 /// The maximum amount of memory the decoder is allowed to use for each frame
26 pub enum MemoryLimitrust-analyzer cargo gif 0.14.2 reader/MemoryLimit# {
27 /// Enforce no memory limit.
28 ///
29 /// If you intend to process images from unknown origins this is a potentially dangerous
30 /// constant to use, as your program could be vulnerable to decompression bombs. That is,
31 /// malicious images crafted specifically to require an enormous amount of memory to process
32 /// while having a disproportionately small file size.
33 ///
34 /// The risks for modern machines are a bit smaller as the size of each frame cannot
35 /// exceed 16GiB, but this is still a significant amount of memory.
36 Unlimitedrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#Unlimited#,
37 /// Limit the amount of memory that can be used for a single frame to this many bytes.
38 ///
39 /// It may not be enforced precisely due to allocator overhead
40 /// and the decoder potentially allocating small auxiliary buffers,
41 /// but it will precisely limit the size of the output buffer for each frame.
42 //
43 // The `NonZero` type is used to make FFI simpler.
44 // Due to the guaranteed niche optimization, `Unlimited` will be represented as `0`,
45 // and the whole enum as a simple `u64`.
46 Bytesrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#Bytes#(NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#),
47 }
48
49 impl MemoryLimitrust-analyzer cargo gif 0.14.2 reader/MemoryLimit# {
50 fn check_sizerust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]check_size().(&self, size: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
51 match self {
52 Selfrust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]::Unlimitedrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#Unlimited# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()),
53 Selfrust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]::Bytesrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#Bytes#(limit) => {
54 if size as u64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().limit.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() {
55 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
56 } else {
57 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::MemoryLimitrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#MemoryLimit#)
58 }
59 }
60 }
61 }
62
63 fn buffer_sizerust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]buffer_size().(&self, color: ColorOutputrust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#, width: u16, height: u16) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> {
64 let pixels = u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u16>`]from().(width) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u16>`]from().(height);
65
66 let bytes_per_pixel = match color {
67 ColorOutputrust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#::Indexedrust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#Indexed# => 1,
68 ColorOutputrust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#::RGBArust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#RGBA# => 4,
69 };
70
71 // This cannot overflow because the maximum possible value is 16GiB, well within u64 range
72 let total_bytes = pixels rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().bytes_per_pixel;
73
74 // On 32-bit platforms the size of the output buffer may not be representable
75 let usize_bytes = 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().(total_bytes).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
76
77 match self {
78 Selfrust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]::Unlimitedrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#Unlimited# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(usize_bytes),
79 Selfrust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]::Bytesrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#Bytes#(limit) => {
80 if total_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().limit.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() {
81 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
82 } else {
83 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(usize_bytes)
84 }
85 }
86 }
87 }
88
89 #[inline]
90 fn try_reserverust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]try_reserve().(&self, vec: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, additional: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
91 let len = vec
92 .lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
93 .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(additional)
94 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::MemoryLimitrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#MemoryLimit#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
95 self.check_sizerust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]check_size().(len)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
96 vec.try_reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]try_reserve().(additional)
97 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::OutOfMemoryrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#OutOfMemory#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
98 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
99 }
100 }
101
102 /// Options for opening a GIF decoder. [`DecodeOptions::read_info`] will start the decoder.
103 #[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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
104 pub struct DecodeOptionsrust-analyzer cargo gif 0.14.2 reader/DecodeOptions# {
105 memory_limitrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#memory_limit.: MemoryLimitrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#,
106 color_outputrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#color_output.: ColorOutputrust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#,
107 check_frame_consistencyrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#check_frame_consistency.: bool,
108 skip_frame_decodingrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#skip_frame_decoding.: bool,
109 check_for_end_coderust-analyzer cargo gif 0.14.2 reader/DecodeOptions#check_for_end_code.: bool,
110 allow_unknown_blocksrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#allow_unknown_blocks.: bool,
111 }
112
113 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for DecodeOptionsrust-analyzer cargo gif 0.14.2 reader/DecodeOptions# {
114 fn defaultrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions][Default]default().() -> Selfrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions][Default] {
115 Selfrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions][Default]::newrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]new().()
116 }
117 }
118
119 impl DecodeOptionsrust-analyzer cargo gif 0.14.2 reader/DecodeOptions# {
120 /// Creates a new decoder builder
121 #[must_use]
122 #[inline]
123 pub fn newrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]new().() -> Selfrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions] {
124 Selfrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions] {
125 memory_limitrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#memory_limit.: MemoryLimitrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#::Bytesrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#Bytes#(50_000_000.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()), // 50 MB
126 color_outputrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#color_output.: ColorOutputrust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#::Indexedrust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#Indexed#,
127 check_frame_consistencyrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#check_frame_consistency.: false,
128 skip_frame_decodingrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#skip_frame_decoding.: false,
129 check_for_end_coderust-analyzer cargo gif 0.14.2 reader/DecodeOptions#check_for_end_code.: false,
130 allow_unknown_blocksrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#allow_unknown_blocks.: false,
131 }
132 }
133
134 /// Configure how color data is decoded.
135 #[inline]
136 pub fn set_color_outputrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]set_color_output().(&mut self, color: ColorOutputrust-analyzer cargo gif 0.14.2 reader/converter/ColorOutput#) {
137 self.color_outputrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#color_output. = color;
138 }
139
140 /// Configure a memory limit for decoding.
141 pub fn set_memory_limitrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]set_memory_limit().(&mut self, limit: MemoryLimitrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#) {
142 self.memory_limitrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#memory_limit. = limit;
143 }
144
145 /// Configure if frames must be within the screen descriptor.
146 ///
147 /// The default is `false`.
148 ///
149 /// When turned on, all frame descriptors being read must fit within the screen descriptor or
150 /// otherwise an error is returned and the stream left in an unspecified state.
151 ///
152 /// When turned off, frames may be arbitrarily larger or offset in relation to the screen. Many
153 /// other decoder libraries handle this in highly divergent ways. This moves all checks to the
154 /// caller, for example to emulate a specific style.
155 pub fn check_frame_consistencyrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]check_frame_consistency().(&mut self, check: bool) {
156 self.check_frame_consistencyrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#check_frame_consistency. = check;
157 }
158
159 /// Configure whether to skip decoding frames.
160 ///
161 /// The default is false.
162 ///
163 /// When turned on, LZW decoding is skipped. [`Decoder::read_next_frame`] will return
164 /// compressed LZW bytes in frame's data.
165 /// [`Decoder::next_frame_info`] will return the metadata of the next frame as usual.
166 /// This is useful to count frames without incurring the overhead of decoding.
167 pub fn skip_frame_decodingrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]skip_frame_decoding().(&mut self, skip: bool) {
168 self.skip_frame_decodingrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#skip_frame_decoding. = skip;
169 }
170
171 /// Configure if LZW encoded blocks must end with a marker end code.
172 ///
173 /// The default is `false`.
174 ///
175 /// When turned on, all image data blocks—which are LZW encoded—must contain a special bit
176 /// sequence signalling the end of the data. LZW processing terminates when this code is
177 /// encountered. The specification states that it must be the last code output by the encoder
178 /// for an image.
179 ///
180 /// When turned off then image data blocks can simply end. Note that this might silently ignore
181 /// some bits of the last or second to last byte.
182 pub fn check_lzw_end_coderust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]check_lzw_end_code().(&mut self, check: bool) {
183 self.check_for_end_coderust-analyzer cargo gif 0.14.2 reader/DecodeOptions#check_for_end_code. = check;
184 }
185
186 /// Configure if unknown blocks are allowed to be decoded.
187 ///
188 /// The default is `false`.
189 ///
190 /// When turned on, the decoder will allow unknown blocks to be in the
191 /// `BlockStart` position.
192 ///
193 /// When turned off, decoded block starts must mark an `Image`, `Extension`,
194 /// or `Trailer` block. Otherwise, the decoded image will return an error.
195 /// If an unknown block error is returned from decoding, enabling this
196 /// setting may allow for a further state of decoding on the next attempt.
197 ///
198 /// This option also allows unknown extension blocks. The decoder assumes the follow the same
199 /// block layout, i.e. a sequence of zero-length terminated sub-blocks immediately follow the
200 /// extension introducer.
201 pub fn allow_unknown_blocksrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]allow_unknown_blocks().(&mut self, check: bool) {
202 self.allow_unknown_blocksrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#allow_unknown_blocks. = check;
203 }
204
205 /// Reads the logical screen descriptor including the global color palette
206 ///
207 /// Returns a [`Decoder`]. All decoder configuration has to be done beforehand.
208 pub fn read_inforust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]read_info().<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#>(self, r: R) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#<R>, DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
209 Decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#::with_no_initrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]with_no_init().(r, StreamingDecoderrust-analyzer cargo gif 0.14.2 reader/decoder/StreamingDecoder#::with_optionsrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[StreamingDecoder]with_options().(&self), self).initrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]init().()
210 }
211 }
212
213 struct ReadDecoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> {
214 readerrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#reader.: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#<R>,
215 decoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#decoder.: StreamingDecoderrust-analyzer cargo gif 0.14.2 reader/decoder/StreamingDecoder#,
216 at_eofrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#at_eof.: bool,
217 }
218
219 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> ReadDecoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#<R> {
220 #[inline(never)]
221 fn decode_nextrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]decode_next().(
222 &mut self,
223 write_into: &mut OutputBufferrust-analyzer cargo gif 0.14.2 reader/decoder/OutputBuffer#<'_>,
224 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#>, DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
225 while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.at_eofrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#at_eof. {
226 let (consumed, result) = {
227 let buf = self.readerrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#reader..fill_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`][BufRead]fill_buf().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
228 if buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
229 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::UnexpectedEofrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#UnexpectedEof#);
230 }
231
232 self.decoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#decoder..updaterust-analyzer cargo gif 0.14.2 reader/decoder/impl#[StreamingDecoder]update().(buf, write_into)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
233 };
234 self.readerrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#reader..consumerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`][BufRead]consume().(consumed);
235 match result {
236 Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::Nothingrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#Nothing# => (),
237 Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::BlockStartrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#BlockStart#(Blockrust-analyzer cargo gif 0.14.2 common/Block#::Trailerrust-analyzer cargo gif 0.14.2 common/Block#Trailer#) => {
238 self.at_eofrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#at_eof. = true;
239 }
240 result => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result)),
241 }
242 }
243 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
244 }
245
246 fn into_innerrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]into_inner().(self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#<R> {
247 self.readerrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#reader.
248 }
249
250 fn decode_next_bytesrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]decode_next_bytes().(&mut self, out: &mut OutputBufferrust-analyzer cargo gif 0.14.2 reader/decoder/OutputBuffer#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
251 match self.decode_nextrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]decode_next().(out)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
252 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::BytesDecodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#BytesDecoded#(len)) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(len.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().()),
253 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::DataEndrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#DataEnd#) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0),
254 _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::formatrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[DecodingError]format().("unexpected data")),
255 }
256 }
257 }
258 /// Headers for supported extensions.
259 const EXT_NAME_NETSCAPErust-analyzer cargo gif 0.14.2 reader/EXT_NAME_NETSCAPE.: &[u8] = b"NETSCAPE2.0";
260 const EXT_NAME_XMPrust-analyzer cargo gif 0.14.2 reader/EXT_NAME_XMP.: &[u8] = b"XMP DataXMP";
261 const EXT_NAME_ICCrust-analyzer cargo gif 0.14.2 reader/EXT_NAME_ICC.: &[u8] = b"ICCRGBG1012";
262
263 /// State when parsing application extension
264 enum AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState# {
265 /// Waiting for app name
266 Nonerust-analyzer cargo gif 0.14.2 reader/AppExtensionState#None#,
267 Netscaperust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Netscape#,
268 Xmprust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Xmp#,
269 Iccrust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Icc#,
270 Skiprust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Skip#,
271 }
272
273 #[allow(dead_code)]
274 /// GIF decoder. Create [`DecodeOptions`] to get started, and call [`DecodeOptions::read_info`].
275 pub struct Decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> {
276 decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder.: ReadDecoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#<R>,
277 pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter.: PixelConverterrust-analyzer cargo gif 0.14.2 reader/converter/PixelConverter#,
278 memory_limitrust-analyzer cargo gif 0.14.2 reader/Decoder#memory_limit.: MemoryLimitrust-analyzer cargo gif 0.14.2 reader/MemoryLimit#,
279 bg_colorrust-analyzer cargo gif 0.14.2 reader/Decoder#bg_color.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>,
280 repeatrust-analyzer cargo gif 0.14.2 reader/Decoder#repeat.: Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#,
281 current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame.: Framerust-analyzer cargo gif 0.14.2 common/Frame#<'static>,
282 current_frame_data_typerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame_data_type.: FrameDataTyperust-analyzer cargo gif 0.14.2 reader/decoder/FrameDataType#,
283 app_extension_staterust-analyzer cargo gif 0.14.2 reader/Decoder#app_extension_state.: AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#,
284 /// XMP metadata bytes.
285 xmp_metadatarust-analyzer cargo gif 0.14.2 reader/Decoder#xmp_metadata.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>,
286 /// ICC profile bytes.
287 icc_profilerust-analyzer cargo gif 0.14.2 reader/Decoder#icc_profile.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>,
288 }
289
290 impl<R> Decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#<R>
291 where
292 R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#,
293 {
294 /// Create a new decoder with default options.
295 #[inline]
296 pub fn newrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]new().(reader: R) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`], DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
297 DecodeOptionsrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#::newrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]new().().read_inforust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]read_info().(reader)
298 }
299
300 /// Return a builder that allows configuring limits etc.
301 #[must_use]
302 #[inline]
303 pub fn buildrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]build().() -> DecodeOptionsrust-analyzer cargo gif 0.14.2 reader/DecodeOptions# {
304 DecodeOptionsrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#::newrust-analyzer cargo gif 0.14.2 reader/impl#[DecodeOptions]new().()
305 }
306
307 fn with_no_initrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]with_no_init().(reader: R, decoder: StreamingDecoderrust-analyzer cargo gif 0.14.2 reader/decoder/StreamingDecoder#, options: DecodeOptionsrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#) -> Selfrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`] {
308 Selfrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`] {
309 decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder.: ReadDecoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder# {
310 readerrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#reader.: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(reader),
311 decoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#decoder.,
312 at_eofrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#at_eof.: false,
313 },
314 bg_colorrust-analyzer cargo gif 0.14.2 reader/Decoder#bg_color.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
315 pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter.: PixelConverterrust-analyzer cargo gif 0.14.2 reader/converter/PixelConverter#::newrust-analyzer cargo gif 0.14.2 reader/converter/impl#[PixelConverter]new().(options.color_outputrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#color_output.),
316 memory_limitrust-analyzer cargo gif 0.14.2 reader/Decoder#memory_limit.: options.memory_limitrust-analyzer cargo gif 0.14.2 reader/DecodeOptions#memory_limit..clonerust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit][Clone]clone().(),
317 repeatrust-analyzer cargo gif 0.14.2 reader/Decoder#repeat.: Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#::defaultrust-analyzer cargo gif 0.14.2 encoder/impl#[Repeat][Default]default().(),
318 current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame.: Framerust-analyzer cargo gif 0.14.2 common/Frame#::defaultrust-analyzer cargo gif 0.14.2 common/impl#[`Frame<'_>`][Default]default().(),
319 current_frame_data_typerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame_data_type.: FrameDataTyperust-analyzer cargo gif 0.14.2 reader/decoder/FrameDataType#::Pixelsrust-analyzer cargo gif 0.14.2 reader/decoder/FrameDataType#Pixels#,
320 app_extension_staterust-analyzer cargo gif 0.14.2 reader/Decoder#app_extension_state.: AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Nonerust-analyzer cargo gif 0.14.2 reader/AppExtensionState#None#,
321 xmp_metadatarust-analyzer cargo gif 0.14.2 reader/Decoder#xmp_metadata.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
322 icc_profilerust-analyzer cargo gif 0.14.2 reader/Decoder#icc_profile.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
323 }
324 }
325
326 fn initrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]init().(mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`], DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
327 const APP_EXTENSIONrust-analyzer cargo gif 0.14.2 reader/APP_EXTENSION.: AnyExtensionrust-analyzer cargo gif 0.14.2 common/AnyExtension# = AnyExtensionrust-analyzer cargo gif 0.14.2 common/AnyExtension#(Extensionrust-analyzer cargo gif 0.14.2 common/Extension#::Applicationrust-analyzer cargo gif 0.14.2 common/Extension#Application# as u8);
328 loop {
329 match self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decode_nextrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]decode_next().(&mut OutputBufferrust-analyzer cargo gif 0.14.2 reader/decoder/OutputBuffer#::Nonerust-analyzer cargo gif 0.14.2 reader/decoder/OutputBuffer#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
330 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::BackgroundColorrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#BackgroundColor#(bg_color)) => {
331 self.bg_colorrust-analyzer cargo gif 0.14.2 reader/Decoder#bg_color. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bg_color);
332 }
333 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::GlobalPaletterust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#GlobalPalette#(palette)) => {
334 self.pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter..set_global_paletterust-analyzer cargo gif 0.14.2 reader/converter/impl#[PixelConverter]set_global_palette().(palette.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
335 }
336 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::SubBlockrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#SubBlock# {
337 extrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#SubBlock#ext.: APP_EXTENSIONrust-analyzer cargo gif 0.14.2 reader/APP_EXTENSION.,
338 is_lastrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#SubBlock#is_last.,
339 }) => {
340 self.read_application_extensionrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]read_application_extension().(is_last)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
341 }
342 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::HeaderEndrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#HeaderEnd#) => break,
343 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => {
344 // There will be extra events when parsing application extension
345 continue;
346 }
347 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
348 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::formatrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[DecodingError]format().(
349 "file does not contain any image data",
350 ))
351 }
352 }
353 }
354 // If the background color is invalid, ignore it
355 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(palette) = self.pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter..global_paletterust-analyzer cargo gif 0.14.2 reader/converter/impl#[PixelConverter]global_palette().() {
356 if self.bg_colorrust-analyzer cargo gif 0.14.2 reader/Decoder#bg_color..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0) as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().(palette.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().PLTE_CHANNELSrust-analyzer cargo gif 0.14.2 reader/decoder/PLTE_CHANNELS.) {
357 self.bg_colorrust-analyzer cargo gif 0.14.2 reader/Decoder#bg_color. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
358 }
359 }
360 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self)
361 }
362
363 fn read_application_extensionrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]read_application_extension().(&mut self, is_last: bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
364 let data = self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#decoder..last_ext_sub_blockrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[StreamingDecoder]last_ext_sub_block().();
365 match self.app_extension_staterust-analyzer cargo gif 0.14.2 reader/Decoder#app_extension_state. {
366 AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Nonerust-analyzer cargo gif 0.14.2 reader/AppExtensionState#None# => {
367 // GIF spec requires len == 11
368 self.app_extension_staterust-analyzer cargo gif 0.14.2 reader/Decoder#app_extension_state. = match data {
369 EXT_NAME_NETSCAPErust-analyzer cargo gif 0.14.2 reader/EXT_NAME_NETSCAPE. => AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Netscaperust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Netscape#,
370 EXT_NAME_XMPrust-analyzer cargo gif 0.14.2 reader/EXT_NAME_XMP. => {
371 self.xmp_metadatarust-analyzer cargo gif 0.14.2 reader/Decoder#xmp_metadata. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
372 AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Xmprust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Xmp#
373 }
374 EXT_NAME_ICCrust-analyzer cargo gif 0.14.2 reader/EXT_NAME_ICC. => {
375 self.icc_profilerust-analyzer cargo gif 0.14.2 reader/Decoder#icc_profile. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
376 AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Iccrust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Icc#
377 }
378 _ => AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Skiprust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Skip#,
379 }
380 }
381 AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Netscaperust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Netscape# => {
382 if let [1, rest @ ..] = data {
383 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(repeat) = rest.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(u16::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]from_le_bytes().) {
384 self.repeatrust-analyzer cargo gif 0.14.2 reader/Decoder#repeat. = if repeat rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().0 {
385 Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#::Infiniterust-analyzer cargo gif 0.14.2 encoder/Repeat#Infinite#
386 } else {
387 Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#::Finiterust-analyzer cargo gif 0.14.2 encoder/Repeat#Finite#(repeat)
388 };
389 }
390 }
391 self.app_extension_staterust-analyzer cargo gif 0.14.2 reader/Decoder#app_extension_state. = AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Skiprust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Skip#;
392 }
393 AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Xmprust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Xmp# => {
394 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(xmp_metadata) = &mut self.xmp_metadatarust-analyzer cargo gif 0.14.2 reader/Decoder#xmp_metadata. {
395 // XMP is not written as a valid "pascal-string", so we need to stitch together
396 // the text from our collected sublock-lengths.
397 self.memory_limitrust-analyzer cargo gif 0.14.2 reader/Decoder#memory_limit.
398 .try_reserverust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]try_reserve().(xmp_metadata, 1 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().data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
399 xmp_metadata.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u8);
400 xmp_metadata.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(data);
401 if is_last {
402 // XMP adds a "ramp" of 257 bytes to the end of the metadata to let the "pascal-strings"
403 // parser converge to the null byte. The ramp looks like "0x01, 0xff, .., 0x01, 0x00".
404 // For convenience and to allow consumers to not be bothered with this implementation detail,
405 // we cut the ramp.
406 const RAMP_SIZErust-analyzer cargo gif 0.14.2 reader/RAMP_SIZE.: usize = 257;
407 if xmp_metadata.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().RAMP_SIZErust-analyzer cargo gif 0.14.2 reader/RAMP_SIZE.
408 && xmp_metadata.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]ends_with().(&[0x03, 0x02, 0x01, 0x00])
409 && xmp_metadata[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().xmp_metadata.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().RAMP_SIZErust-analyzer cargo gif 0.14.2 reader/RAMP_SIZE...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
410 .starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(&[0x01, 0x0ff])
411 {
412 xmp_metadata.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(xmp_metadata.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().RAMP_SIZErust-analyzer cargo gif 0.14.2 reader/RAMP_SIZE.);
413 }
414 }
415 }
416 }
417 AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Iccrust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Icc# => {
418 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(icc) = &mut self.icc_profilerust-analyzer cargo gif 0.14.2 reader/Decoder#icc_profile. {
419 self.memory_limitrust-analyzer cargo gif 0.14.2 reader/Decoder#memory_limit..try_reserverust-analyzer cargo gif 0.14.2 reader/impl#[MemoryLimit]try_reserve().(icc, data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
420 icc.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(data);
421 }
422 }
423 AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Skiprust-analyzer cargo gif 0.14.2 reader/AppExtensionState#Skip# => {}
424 };
425 if is_last {
426 self.app_extension_staterust-analyzer cargo gif 0.14.2 reader/Decoder#app_extension_state. = AppExtensionStaterust-analyzer cargo gif 0.14.2 reader/AppExtensionState#::Nonerust-analyzer cargo gif 0.14.2 reader/AppExtensionState#None#;
427 }
428 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
429 }
430
431 /// Returns the next frame info
432 pub fn next_frame_inforust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]next_frame_info().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Framerust-analyzer cargo gif 0.14.2 common/Frame#<'static>>, DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
433 loop {
434 match self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decode_nextrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]decode_next().(&mut OutputBufferrust-analyzer cargo gif 0.14.2 reader/decoder/OutputBuffer#::Nonerust-analyzer cargo gif 0.14.2 reader/decoder/OutputBuffer#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
435 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::FrameMetadatarust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#FrameMetadata#(frame_data_type)) => {
436 self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame. = self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#decoder..current_frame_mutrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[StreamingDecoder]current_frame_mut().().takerust-analyzer cargo gif 0.14.2 common/impl#[`Frame<'static>`]take().();
437 self.current_frame_data_typerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame_data_type. = frame_data_type;
438 if self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame..paletterust-analyzer cargo gif 0.14.2 common/Frame#palette..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() && self.global_paletterust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]global_palette().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
439 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::formatrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[DecodingError]format().(
440 "no color table available for current frame",
441 ));
442 }
443 break;
444 }
445 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => (),
446 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
447 }
448 }
449 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame.))
450 }
451
452 /// Query information about the frame previously advanced with [`Self::next_frame_info`].
453 ///
454 /// Returns `None` past the end of file.
455 pub fn current_frame_inforust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]current_frame_info().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Framerust-analyzer cargo gif 0.14.2 common/Frame#<'static>> {
456 if self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..at_eofrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#at_eof. {
457 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
458 } else {
459 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame.)
460 }
461 }
462
463 /// Reads the next frame from the image.
464 ///
465 /// Do not call `Self::next_frame_info` beforehand.
466 /// Deinterlaces the result.
467 ///
468 /// You can also call `.into_iter()` on the decoder to use it as a regular iterator.
469 pub fn read_next_framerust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]read_next_frame().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Framerust-analyzer cargo gif 0.14.2 common/Frame#<'static>>, DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
470 if self.next_frame_inforust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]next_frame_info().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
471 match self.current_frame_data_typerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame_data_type. {
472 FrameDataTyperust-analyzer cargo gif 0.14.2 reader/decoder/FrameDataType#::Pixelsrust-analyzer cargo gif 0.14.2 reader/decoder/FrameDataType#Pixels# => {
473 self.pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter..read_framerust-analyzer cargo gif 0.14.2 reader/converter/impl#[PixelConverter]read_frame().(
474 &mut self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame.,
475 &mut |out| self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decode_next_bytesrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]decode_next_bytes().(out),
476 &self.memory_limitrust-analyzer cargo gif 0.14.2 reader/Decoder#memory_limit.,
477 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
478 }
479 FrameDataTyperust-analyzer cargo gif 0.14.2 reader/decoder/FrameDataType#::Lzwrust-analyzer cargo gif 0.14.2 reader/decoder/FrameDataType#Lzw# { min_code_sizerust-analyzer cargo gif 0.14.2 reader/decoder/FrameDataType#Lzw#min_code_size. } => {
480 let mut vec = if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame..bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer., Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(_)) {
481 let mut vec =
482 memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame..bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer., Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&[]))
483 .into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().();
484 vec.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
485 vec
486 } else {
487 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()
488 };
489 // Guesstimate 2bpp
490 vec.try_reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]try_reserve().(
491 usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame..widthrust-analyzer cargo gif 0.14.2 common/Frame#width.)
492 *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().usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame..heightrust-analyzer cargo gif 0.14.2 common/Frame#height.)
493 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4,
494 )
495 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::OutOfMemoryrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#OutOfMemory#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
496 self.copy_lzw_into_bufferrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]copy_lzw_into_buffer().(min_code_size, &mut vec)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
497 self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame..bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer. = Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(vec);
498 }
499 }
500 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame.))
501 } else {
502 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
503 }
504 }
505
506 /// This is private for iterator's use
507 fn take_current_framerust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]take_current_frame().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Framerust-analyzer cargo gif 0.14.2 common/Frame#<'static>> {
508 if self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame..bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer..is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
509 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
510 }
511 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame..takerust-analyzer cargo gif 0.14.2 common/impl#[`Frame<'static>`]take().())
512 }
513
514 /// Reads the data of the current frame into a pre-allocated buffer.
515 ///
516 /// `Self::next_frame_info` needs to be called beforehand.
517 /// The length of `buf` must be at least `Self::buffer_size`.
518 /// Deinterlaces the result.
519 pub fn read_into_bufferrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]read_into_buffer().(&mut self, buf: &mut [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
520 self.pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter.
521 .read_into_bufferrust-analyzer cargo gif 0.14.2 reader/converter/impl#[PixelConverter]read_into_buffer().(&self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame., buf, &mut |out| {
522 self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decode_next_bytesrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]decode_next_bytes().(out)
523 })
524 }
525
526 fn copy_lzw_into_bufferrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]copy_lzw_into_buffer().(
527 &mut self,
528 min_code_size: u8,
529 buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>,
530 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
531 // `write_lzw_pre_encoded_frame` smuggles `min_code_size` in the first byte.
532 buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(min_code_size);
533 loop {
534 match self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decode_nextrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]decode_next().(&mut OutputBufferrust-analyzer cargo gif 0.14.2 reader/decoder/OutputBuffer#::Vecrust-analyzer cargo gif 0.14.2 reader/decoder/OutputBuffer#Vec#(buf))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
535 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::LzwDataCopiedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#LzwDataCopied#(_len)) => {}
536 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Decodedrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#::DataEndrust-analyzer cargo gif 0.14.2 reader/decoder/Decoded#DataEnd#) => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()),
537 _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::formatrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[DecodingError]format().("unexpected data")),
538 }
539 }
540 }
541
542 /// Reads data of the current frame into a pre-allocated buffer until the buffer has been
543 /// filled completely.
544 ///
545 /// The buffer length must be an even number of pixels (multiple of 4 if decoding RGBA).
546 ///
547 /// `Self::next_frame_info` needs to be called beforehand. Returns `true` if the supplied
548 /// buffer could be filled completely. Should not be called after `false` had been returned.
549 pub fn fill_bufferrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]fill_buffer().(&mut self, buf: &mut [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
550 self.pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter.
551 .fill_bufferrust-analyzer cargo gif 0.14.2 reader/converter/impl#[PixelConverter]fill_buffer().(&self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame., buf, &mut |out| {
552 self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decode_next_bytesrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]decode_next_bytes().(out)
553 })
554 }
555
556 /// Output buffer size
557 pub fn buffer_sizerust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]buffer_size().(&self) -> usize {
558 self.pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter.
559 .buffer_sizerust-analyzer cargo gif 0.14.2 reader/converter/impl#[PixelConverter]buffer_size().(&self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame.)
560 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
561 }
562
563 /// Line length of the current frame
564 pub fn line_lengthrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]line_length().(&self) -> usize {
565 self.pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter..line_lengthrust-analyzer cargo gif 0.14.2 reader/converter/impl#[PixelConverter]line_length().(&self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame.)
566 }
567
568 /// Returns the color palette relevant for the frame that has been decoded
569 #[inline]
570 pub fn paletterust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]palette().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#> {
571 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(match self.current_framerust-analyzer cargo gif 0.14.2 reader/Decoder#current_frame..paletterust-analyzer cargo gif 0.14.2 common/Frame#palette. {
572 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref table) => table,
573 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => self.global_paletterust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]global_palette().().ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
574 DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#::formatrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[DecodingError]format().("no color table available for current frame")
575 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
576 })
577 }
578
579 /// The global color palette
580 pub fn global_paletterust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]global_palette().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]> {
581 self.pixel_converterrust-analyzer cargo gif 0.14.2 reader/Decoder#pixel_converter..global_paletterust-analyzer cargo gif 0.14.2 reader/converter/impl#[PixelConverter]global_palette().()
582 }
583
584 /// Width of the image
585 #[inline]
586 pub fn widthrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]width().(&self) -> u16 {
587 self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#decoder..widthrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[StreamingDecoder]width().()
588 }
589
590 /// Height of the image
591 #[inline]
592 pub fn heightrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]height().(&self) -> u16 {
593 self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..decoderrust-analyzer cargo gif 0.14.2 reader/ReadDecoder#decoder..heightrust-analyzer cargo gif 0.14.2 reader/decoder/impl#[StreamingDecoder]height().()
594 }
595
596 /// XMP metadata stored in the image.
597 #[inline]
598 #[must_use]
599 pub fn xmp_metadatarust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]xmp_metadata().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]> {
600 self.xmp_metadatarust-analyzer cargo gif 0.14.2 reader/Decoder#xmp_metadata..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
601 }
602
603 /// ICC profile stored in the image.
604 #[inline]
605 #[must_use]
606 pub fn icc_profilerust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]icc_profile().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]> {
607 self.icc_profilerust-analyzer cargo gif 0.14.2 reader/Decoder#icc_profile..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
608 }
609
610 /// Abort decoding and recover the `io::Read` instance
611 pub fn into_innerrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]into_inner().(self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#<R> {
612 self.decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#decoder..into_innerrust-analyzer cargo gif 0.14.2 reader/impl#[`ReadDecoder<R>`]into_inner().()
613 }
614
615 /// Index of the background color in the global palette
616 ///
617 /// In practice this is not used, and the background is
618 /// always transparent
619 pub fn bg_colorrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]bg_color().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> {
620 self.bg_colorrust-analyzer cargo gif 0.14.2 reader/Decoder#bg_color..maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| v as usize)
621 }
622
623 /// Number of loop repetitions
624 #[inline]
625 pub fn repeatrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]repeat().(&self) -> Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat# {
626 self.repeatrust-analyzer cargo gif 0.14.2 reader/Decoder#repeat.
627 }
628 }
629
630 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for Decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#<R> {
631 type Itemrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`][IntoIterator]Item# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Framerust-analyzer cargo gif 0.14.2 common/Frame#<'static>, DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#>;
632 type IntoIterrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`][IntoIterator]IntoIter# = DecoderIterrust-analyzer cargo gif 0.14.2 reader/DecoderIter#<R>;
633
634 #[inline]
635 fn into_iterrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`][IntoIterator]into_iter().(self) -> Selfrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`][IntoIterator]::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter# {
636 DecoderIterrust-analyzer cargo gif 0.14.2 reader/DecoderIter# {
637 innerrust-analyzer cargo gif 0.14.2 reader/DecoderIter#inner.: self,
638 endedrust-analyzer cargo gif 0.14.2 reader/DecoderIter#ended.: false,
639 }
640 }
641 }
642
643 /// Use `decoder.into_iter()` to iterate over the frames
644 pub struct DecoderIterrust-analyzer cargo gif 0.14.2 reader/DecoderIter#<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> {
645 innerrust-analyzer cargo gif 0.14.2 reader/DecoderIter#inner.: Decoderrust-analyzer cargo gif 0.14.2 reader/Decoder#<R>,
646 endedrust-analyzer cargo gif 0.14.2 reader/DecoderIter#ended.: bool,
647 }
648
649 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> DecoderIterrust-analyzer cargo gif 0.14.2 reader/DecoderIter#<R> {
650 /// Abort decoding and recover the `io::Read` instance
651 ///
652 /// Use `for frame in iter.by_ref()` to be able to call this afterwards.
653 pub fn into_innerrust-analyzer cargo gif 0.14.2 reader/impl#[`DecoderIter<R>`]into_inner().(self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#<R> {
654 self.innerrust-analyzer cargo gif 0.14.2 reader/DecoderIter#inner..into_innerrust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]into_inner().()
655 }
656 }
657
658 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for DecoderIterrust-analyzer cargo gif 0.14.2 reader/DecoderIter#<R> {}
659
660 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for DecoderIterrust-analyzer cargo gif 0.14.2 reader/DecoderIter#<R> {
661 type Itemrust-analyzer cargo gif 0.14.2 reader/impl#[`DecoderIter<R>`][Iterator]Item# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Framerust-analyzer cargo gif 0.14.2 common/Frame#<'static>, DecodingErrorrust-analyzer cargo gif 0.14.2 reader/decoder/DecodingError#>;
662
663 fn nextrust-analyzer cargo gif 0.14.2 reader/impl#[`DecoderIter<R>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo gif 0.14.2 reader/impl#[`DecoderIter<R>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
664 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.endedrust-analyzer cargo gif 0.14.2 reader/DecoderIter#ended. {
665 match self.innerrust-analyzer cargo gif 0.14.2 reader/DecoderIter#inner..read_next_framerust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]read_next_frame().() {
666 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_)) => self.innerrust-analyzer cargo gif 0.14.2 reader/DecoderIter#inner..take_current_framerust-analyzer cargo gif 0.14.2 reader/impl#[`Decoder<R>`]take_current_frame().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#),
667 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {
668 self.endedrust-analyzer cargo gif 0.14.2 reader/DecoderIter#ended. = true;
669 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
670 }
671 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => {
672 self.endedrust-analyzer cargo gif 0.14.2 reader/DecoderIter#ended. = true;
673 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#(err))
674 }
675 }
676 } else {
677 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
678 }
679 }
680 }