Debian Codegraph @

src/encoder.rs

raw symbols SCIP
1 //! # Minimal gif encoder
2
3 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#;
4 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/;
5 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#;
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/;
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/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#;
9
10 use weezlrust-analyzer cargo weezl 0.1.10 crate/::{encoderust-analyzer cargo weezl 0.1.10 encode/::Encoderrust-analyzer cargo weezl 0.1.10 encode/Encoder# as LzwEncoderrust-analyzer cargo weezl 0.1.10 encode/Encoder#, BitOrderrust-analyzer cargo weezl 0.1.10 BitOrder#};
11
12 use craterust-analyzer cargo gif 0.14.2 crate/::commonrust-analyzer cargo gif 0.14.2 common/::{AnyExtensionrust-analyzer cargo gif 0.14.2 common/AnyExtension#, Blockrust-analyzer cargo gif 0.14.2 common/Block#, DisposalMethodrust-analyzer cargo gif 0.14.2 common/DisposalMethod#, Extensionrust-analyzer cargo gif 0.14.2 common/Extension#, Framerust-analyzer cargo gif 0.14.2 common/Frame#};
13 use craterust-analyzer cargo gif 0.14.2 crate/::traitsrust-analyzer cargo gif 0.14.2 traits/::WriteBytesExtrust-analyzer cargo gif 0.14.2 traits/WriteBytesExt#;
14
15 /// The image has incorrect properties, making it impossible to encode as a gif.
16 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
17 #[non_exhaustive]
18 pub enum EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError# {
19 /// The image has too many colors.
20 TooManyColorsrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#TooManyColors#,
21 /// The image has no color palette which is required.
22 MissingColorPaletterust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#MissingColorPalette#,
23 /// LZW data is not valid for GIF. This may happen when wrong buffer is given to `write_lzw_pre_encoded_frame`
24 InvalidMinCodeSizerust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#InvalidMinCodeSize#,
25 }
26
27 impl errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError# {}
28 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError# {
29 #[cold]
30 fn fmtrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingFormatError][Display]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
31 match self {
32 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingFormatError][Display]::TooManyColorsrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#TooManyColors# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(fmt, "the image has too many colors"),
33 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingFormatError][Display]::MissingColorPaletterust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#MissingColorPalette# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
34 fmt,
35 "the GIF format requires a color palette but none was given"
36 ),
37 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingFormatError][Display]::InvalidMinCodeSizerust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#InvalidMinCodeSize# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(fmt, "LZW data is invalid"),
38 }
39 }
40 }
41
42 /// Encoding error.
43 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
44 #[non_exhaustive]
45 pub enum EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError# {
46 /// Frame buffer is too small for the declared dimensions.
47 FrameBufferTooSmallForDimensionsrust-analyzer cargo gif 0.14.2 encoder/EncodingError#FrameBufferTooSmallForDimensions#,
48 /// Failed to internally allocate a buffer of sufficient size.
49 OutOfMemoryrust-analyzer cargo gif 0.14.2 encoder/EncodingError#OutOfMemory#,
50 /// Expected a writer but none found.
51 WriterNotFoundrust-analyzer cargo gif 0.14.2 encoder/EncodingError#WriterNotFound#,
52 /// Returned if the to image is not encodable as a gif.
53 Formatrust-analyzer cargo gif 0.14.2 encoder/EncodingError#Format#(EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#),
54 /// Wraps `std::io::Error`.
55 Iorust-analyzer cargo gif 0.14.2 encoder/EncodingError#Io#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#),
56 }
57
58 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError# {
59 #[cold]
60 fn fmtrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Display]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
61 match self {
62 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Display]::FrameBufferTooSmallForDimensionsrust-analyzer cargo gif 0.14.2 encoder/EncodingError#FrameBufferTooSmallForDimensions# => {
63 fmt.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("Frame Buffer Too Small for Dimensions")
64 }
65 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Display]::OutOfMemoryrust-analyzer cargo gif 0.14.2 encoder/EncodingError#OutOfMemory# => fmt.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("Out of Memory"),
66 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Display]::WriterNotFoundrust-analyzer cargo gif 0.14.2 encoder/EncodingError#WriterNotFound# => fmt.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("Writer Not Found"),
67 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Display]::Iorust-analyzer cargo gif 0.14.2 encoder/EncodingError#Io#(err) => err.fmtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][Display]fmt().(fmt),
68 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Display]::Formatrust-analyzer cargo gif 0.14.2 encoder/EncodingError#Format#(err) => err.fmtrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingFormatError][Display]fmt().(fmt),
69 }
70 }
71 }
72
73 impl errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError# {
74 #[cold]
75 fn sourcerust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Error]source().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&(dyn errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + 'static)> {
76 match self {
77 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Error]::FrameBufferTooSmallForDimensionsrust-analyzer cargo gif 0.14.2 encoder/EncodingError#FrameBufferTooSmallForDimensions# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
78 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Error]::OutOfMemoryrust-analyzer cargo gif 0.14.2 encoder/EncodingError#OutOfMemory# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
79 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Error]::WriterNotFoundrust-analyzer cargo gif 0.14.2 encoder/EncodingError#WriterNotFound# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
80 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Error]::Iorust-analyzer cargo gif 0.14.2 encoder/EncodingError#Io#(err) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(err),
81 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][Error]::Formatrust-analyzer cargo gif 0.14.2 encoder/EncodingError#Format#(err) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(err),
82 }
83 }
84 }
85
86 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> for EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError# {
87 #[cold]
88 fn fromrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][`From<io::Error>`]from().(err: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#) -> Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][`From<io::Error>`] {
89 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][`From<io::Error>`]::Iorust-analyzer cargo gif 0.14.2 encoder/EncodingError#Io#(err)
90 }
91 }
92
93 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#> for EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError# {
94 #[cold]
95 fn fromrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][`From<EncodingFormatError>`]from().(err: EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#) -> Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][`From<EncodingFormatError>`] {
96 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][`From<EncodingFormatError>`]::Formatrust-analyzer cargo gif 0.14.2 encoder/EncodingError#Format#(err)
97 }
98 }
99
100 /// Number of repetitions
101 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, 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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
102 pub enum Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat# {
103 /// Finite number of repetitions
104 Finiterust-analyzer cargo gif 0.14.2 encoder/Repeat#Finite#(u16),
105 /// Infinite number of repetitions
106 Infiniterust-analyzer cargo gif 0.14.2 encoder/Repeat#Infinite#,
107 }
108
109 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat# {
110 fn defaultrust-analyzer cargo gif 0.14.2 encoder/impl#[Repeat][Default]default().() -> Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[Repeat][Default] {
111 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[Repeat][Default]::Finiterust-analyzer cargo gif 0.14.2 encoder/Repeat#Finite#(0)
112 }
113 }
114
115 /// Extension data.
116 #[non_exhaustive]
117 pub enum ExtensionDatarust-analyzer cargo gif 0.14.2 encoder/ExtensionData# {
118 /// Control extension. Use `ExtensionData::new_control_ext` to construct.
119 Controlrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control# {
120 /// Flags.
121 flagsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control#flags.: u8,
122 /// Frame delay.
123 delayrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control#delay.: u16,
124 /// Transparent index.
125 trnsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control#trns.: u8,
126 },
127 /// Sets the number of repetitions
128 Repetitionsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Repetitions#(Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#),
129 }
130
131 impl ExtensionDatarust-analyzer cargo gif 0.14.2 encoder/ExtensionData# {
132 /// Constructor for control extension data.
133 ///
134 /// `delay` is given in units of 10 ms.
135 #[must_use]
136 pub fn new_control_extrust-analyzer cargo gif 0.14.2 encoder/impl#[ExtensionData]new_control_ext().(
137 delay: u16,
138 dispose: DisposalMethodrust-analyzer cargo gif 0.14.2 common/DisposalMethod#,
139 needs_user_input: bool,
140 trns: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>,
141 ) -> Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[ExtensionData] {
142 let mut flags = 0;
143 let trns = match trns {
144 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(trns) => {
145 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().1;
146 trns
147 }
148 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => 0,
149 };
150 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().u8::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u8][`From<bool>`]from().(needs_user_input) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().1;
151 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().(dispose as u8) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().2;
152 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[ExtensionData]::Controlrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control# { flagsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control#flags., delayrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control#delay., trnsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control#trns. }
153 }
154 }
155
156 impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Encoderrust-analyzer cargo gif 0.14.2 encoder/Encoder#<W> {
157 /// Creates a new encoder.
158 ///
159 /// `global_palette` gives the global color palette in the format `[r, g, b, ...]`,
160 /// if no global palette shall be used an empty slice may be supplied.
161 pub fn newrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]new().(
162 w: W,
163 width: u16,
164 height: u16,
165 global_palette: &[u8],
166 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`], EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
167 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`] {
168 wrust-analyzer cargo gif 0.14.2 encoder/Encoder#w.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(w),
169 global_paletterust-analyzer cargo gif 0.14.2 encoder/Encoder#global_palette.: false,
170 widthrust-analyzer cargo gif 0.14.2 encoder/Encoder#width.,
171 heightrust-analyzer cargo gif 0.14.2 encoder/Encoder#height.,
172 bufferrust-analyzer cargo gif 0.14.2 encoder/Encoder#buffer.: 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().(),
173 }
174 .write_global_paletterust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_global_palette().(global_palette)
175 }
176
177 /// Write an extension block that signals a repeat behaviour.
178 pub fn set_repeatrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]set_repeat().(&mut self, repeat: Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
179 self.write_extensionrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_extension().(ExtensionDatarust-analyzer cargo gif 0.14.2 encoder/ExtensionData#::Repetitionsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Repetitions#(repeat))
180 }
181
182 /// Writes the global color palette.
183 fn write_global_paletterust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_global_palette().(mut self, palette: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`], EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
184 let mut flags = 0;
185 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().0b1000_0000;
186 let (palette, padding, table_size) = Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]::check_color_tablerust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]check_color_table().(palette)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
187 self.global_paletterust-analyzer cargo gif 0.14.2 encoder/Encoder#global_palette. = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().palette.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().();
188 // Size of global color table.
189 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().table_size;
190 // Color resolution .. FIXME. This is mostly ignored (by ImageMagick at least) but hey, we
191 // should use some sensible value here or even allow configuring it?
192 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().table_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().4; // wtf flag
193 self.write_screen_descrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_screen_desc().(flags)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
194 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]::write_color_tablerust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_color_table().(self.writerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]writer().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., palette, padding)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
195 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self)
196 }
197
198 /// Writes a frame to the image.
199 ///
200 /// Note: This function also writes a control extension if necessary.
201 pub fn write_framerust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_frame().(&mut self, frame: &Framerust-analyzer cargo gif 0.14.2 common/Frame#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
202 if usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(frame.widthrust-analyzer cargo gif 0.14.2 common/Frame#width.)
203 .checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(frame.heightrust-analyzer cargo gif 0.14.2 common/Frame#height.))
204 .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(true, |size| frame.bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer..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 cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().size)
205 {
206 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#::FrameBufferTooSmallForDimensionsrust-analyzer cargo gif 0.14.2 encoder/EncodingError#FrameBufferTooSmallForDimensions#);
207 }
208 debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(
209 (frame.widthrust-analyzer cargo gif 0.14.2 common/Frame#width. >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). 0 && frame.heightrust-analyzer cargo gif 0.14.2 common/Frame#height. >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). 0) || 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().(),
210 "the frame has 0 pixels, but non-empty buffer"
211 );
212 self.write_frame_headerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_frame_header().(frame)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
213 self.write_image_blockrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_image_block().(&frame.bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer.)
214 }
215
216 fn write_frame_headerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_frame_header().(&mut self, frame: &Framerust-analyzer cargo gif 0.14.2 common/Frame#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
217 self.write_extensionrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_extension().(ExtensionDatarust-analyzer cargo gif 0.14.2 encoder/ExtensionData#::new_control_extrust-analyzer cargo gif 0.14.2 encoder/impl#[ExtensionData]new_control_ext().(
218 frame.delayrust-analyzer cargo gif 0.14.2 common/Frame#delay.,
219 frame.disposerust-analyzer cargo gif 0.14.2 common/Frame#dispose.,
220 frame.needs_user_inputrust-analyzer cargo gif 0.14.2 common/Frame#needs_user_input.,
221 frame.transparentrust-analyzer cargo gif 0.14.2 common/Frame#transparent.,
222 ))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
223 let mut flags = 0;
224 if frame.interlacedrust-analyzer cargo gif 0.14.2 common/Frame#interlaced. {
225 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().0b0100_0000;
226 }
227 let palette = match frame.paletterust-analyzer cargo gif 0.14.2 common/Frame#palette. {
228 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref palette) => {
229 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().0b1000_0000;
230 let (palette, padding, table_size) = Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]::check_color_tablerust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]check_color_table().(palette)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
231 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().table_size;
232 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((palette, padding))
233 }
234 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# if self.global_paletterust-analyzer cargo gif 0.14.2 encoder/Encoder#global_palette. => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
235 _ => {
236 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#::fromrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][`From<EncodingFormatError>`]from().(
237 EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#::MissingColorPaletterust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#MissingColorPalette#,
238 ))
239 }
240 };
241 let mut tmp = tmp_bufrust-analyzer cargo gif 0.14.2 encoder/tmp_buf().::<10>();
242 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(Blockrust-analyzer cargo gif 0.14.2 common/Block#::Imagerust-analyzer cargo gif 0.14.2 common/Block#Image# as u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
243 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u16>`]write_le().(frame.leftrust-analyzer cargo gif 0.14.2 common/Frame#left.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
244 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u16>`]write_le().(frame.toprust-analyzer cargo gif 0.14.2 common/Frame#top.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
245 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u16>`]write_le().(frame.widthrust-analyzer cargo gif 0.14.2 common/Frame#width.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
246 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u16>`]write_le().(frame.heightrust-analyzer cargo gif 0.14.2 common/Frame#height.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
247 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(flags)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
248 let writer = self.writerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]writer().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
249 tmp.finishrust-analyzer cargo gif 0.14.2 encoder/impl#[`Buf<N>`]finish().(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().writer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
250 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((palette, padding)) = palette {
251 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]::write_color_tablerust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_color_table().(writer, palette, padding)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
252 }
253 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
254 }
255
256 fn write_image_blockrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_image_block().(&mut self, data: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
257 self.bufferrust-analyzer cargo gif 0.14.2 encoder/Encoder#buffer..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
258 self.bufferrust-analyzer cargo gif 0.14.2 encoder/Encoder#buffer.
259 .try_reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]try_reserve().(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 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().4)
260 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#::OutOfMemoryrust-analyzer cargo gif 0.14.2 encoder/EncodingError#OutOfMemory#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
261 lzw_encoderust-analyzer cargo gif 0.14.2 encoder/lzw_encode().(data, &mut self.bufferrust-analyzer cargo gif 0.14.2 encoder/Encoder#buffer.);
262
263 let writer = self.wrust-analyzer cargo gif 0.14.2 encoder/Encoder#w..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#::WriterNotFoundrust-analyzer cargo gif 0.14.2 encoder/EncodingError#WriterNotFound#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
264 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]::write_encoded_image_blockrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_encoded_image_block().(writer, &self.bufferrust-analyzer cargo gif 0.14.2 encoder/Encoder#buffer.)
265 }
266
267 fn write_encoded_image_blockrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_encoded_image_block().(
268 writer: &mut W,
269 data_with_min_code_size: &[u8],
270 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
271 let (&min_code_size, data) = data_with_min_code_size.split_firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_first().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().((&2, &[]));
272 writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(min_code_size)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
273
274 // Write blocks. `chunks_exact` seems to be slightly faster
275 // than `chunks` according to both Rust docs and benchmark results.
276 let mut iter = data.chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(0xFF);
277 for full_block in iter.by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().() {
278 writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(0xFFu8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
279 writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(full_block)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
280 }
281 let last_block = iter.remainderrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`ChunksExact<'a, T>`]remainder().();
282 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().last_block.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
283 writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(last_block.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
284 writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(last_block)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
285 }
286 writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(0u8).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().)
287 }
288
289 fn write_color_tablerust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_color_table().(
290 writer: &mut W,
291 table: &[u8],
292 padding: usize,
293 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
294 writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(table)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
295 // Waste some space as of gif spec
296 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#padding {
297 writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&[0, 0, 0])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
298 }
299 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
300 }
301
302 /// returns rounded palette size, number of missing colors, and table size flag
303 fn check_color_tablerust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]check_color_table().(table: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(&[u8], usize, u8), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
304 let num_colors = table.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().3;
305 if num_colors rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().256 {
306 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#::fromrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][`From<EncodingFormatError>`]from().(EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#::TooManyColorsrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#TooManyColors#));
307 }
308 let table_size = flag_sizerust-analyzer cargo gif 0.14.2 encoder/flag_size().(num_colors);
309 let padding = (2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<u8>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<u8>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<u8>`]shl().table_size) 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().num_colors;
310 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((&table[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#num_colors 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().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., padding, table_size))
311 }
312
313 /// Writes an extension to the image.
314 ///
315 /// It is normally not necessary to call this method manually.
316 pub fn write_extensionrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_extension().(&mut self, extension: ExtensionDatarust-analyzer cargo gif 0.14.2 encoder/ExtensionData#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
317 use selfrust-analyzer cargo gif 0.14.2 encoder/::ExtensionDatarust-analyzer cargo gif 0.14.2 encoder/ExtensionData#::*;
318 // 0 finite repetitions can only be achieved
319 // if the corresponting extension is not written
320 if let Repetitionsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Repetitions#(Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#::Finiterust-analyzer cargo gif 0.14.2 encoder/Repeat#Finite#(0)) = extension {
321 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
322 }
323 let writer = self.writerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]writer().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
324 writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(Blockrust-analyzer cargo gif 0.14.2 common/Block#::Extensionrust-analyzer cargo gif 0.14.2 common/Block#Extension# as u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
325 match extension {
326 Controlrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control# { flagsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control#flags., delayrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control#delay., trnsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Control#trns. } => {
327 let mut tmp = tmp_bufrust-analyzer cargo gif 0.14.2 encoder/tmp_buf().::<6>();
328 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(Extensionrust-analyzer cargo gif 0.14.2 common/Extension#::Controlrust-analyzer cargo gif 0.14.2 common/Extension#Control# as u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
329 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(4u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
330 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(flags)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
331 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u16>`]write_le().(delay)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
332 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(trns)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
333 tmp.finishrust-analyzer cargo gif 0.14.2 encoder/impl#[`Buf<N>`]finish().(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().writer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
334 }
335 Repetitionsrust-analyzer cargo gif 0.14.2 encoder/ExtensionData#Repetitions#(repeat) => {
336 let mut tmp = tmp_bufrust-analyzer cargo gif 0.14.2 encoder/tmp_buf().::<17>();
337 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(Extensionrust-analyzer cargo gif 0.14.2 common/Extension#::Applicationrust-analyzer cargo gif 0.14.2 common/Extension#Application# as u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
338 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(11u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
339 tmp.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"NETSCAPE2.0")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
340 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(3u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
341 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(1u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
342 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u16>`]write_le().(match repeat {
343 Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#::Finiterust-analyzer cargo gif 0.14.2 encoder/Repeat#Finite#(no) => no,
344 Repeatrust-analyzer cargo gif 0.14.2 encoder/Repeat#::Infiniterust-analyzer cargo gif 0.14.2 encoder/Repeat#Infinite# => 0u16,
345 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
346 tmp.finishrust-analyzer cargo gif 0.14.2 encoder/impl#[`Buf<N>`]finish().(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().writer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
347 }
348 }
349 writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(0u8).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().)
350 }
351
352 /// Writes a raw extension to the image.
353 ///
354 /// This method can be used to write an unsupported extension to the file. `func` is the extension
355 /// identifier (e.g. `Extension::Application as u8`). `data` are the extension payload blocks. If any
356 /// contained slice has a lenght > 255 it is automatically divided into sub-blocks.
357 pub fn write_raw_extensionrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_raw_extension().(
358 &mut self,
359 func: AnyExtensionrust-analyzer cargo gif 0.14.2 common/AnyExtension#,
360 data: &[&[u8]],
361 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
362 let writer = self.writerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]writer().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
363 writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(Blockrust-analyzer cargo gif 0.14.2 common/Block#::Extensionrust-analyzer cargo gif 0.14.2 common/Block#Extension# as u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
364 writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(func.0rust-analyzer cargo gif 0.14.2 common/AnyExtension#0.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
365 for block in data {
366 for chunk in block.chunksrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks().(0xFF) {
367 writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(chunk.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
368 writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(chunk)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
369 }
370 }
371 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(writer.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(0u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
372 }
373
374 /// Writes a frame to the image, but expects `Frame.buffer` to contain LZW-encoded data
375 /// from [`Frame::make_lzw_pre_encoded`].
376 ///
377 /// Note: This function also writes a control extension if necessary.
378 pub fn write_lzw_pre_encoded_framerust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_lzw_pre_encoded_frame().(&mut self, frame: &Framerust-analyzer cargo gif 0.14.2 common/Frame#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
379 // empty data is allowed
380 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&min_code_size) = frame.bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().() {
381 if min_code_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().11 || min_code_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().2 {
382 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#::Formatrust-analyzer cargo gif 0.14.2 encoder/EncodingError#Format#(
383 EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#::InvalidMinCodeSizerust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#InvalidMinCodeSize#,
384 ));
385 }
386 }
387
388 self.write_frame_headerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_frame_header().(frame)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
389 let writer = self.writerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]writer().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
390 Selfrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]::write_encoded_image_blockrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_encoded_image_block().(writer, &frame.bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer.)
391 }
392
393 /// Writes the logical screen desriptor
394 fn write_screen_descrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_screen_desc().(&mut self, flags: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
395 let mut tmp = tmp_bufrust-analyzer cargo gif 0.14.2 encoder/tmp_buf().::<13>();
396 tmp.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"GIF89a")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
397 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u16>`]write_le().(self.widthrust-analyzer cargo gif 0.14.2 encoder/Encoder#width.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
398 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u16>`]write_le().(self.heightrust-analyzer cargo gif 0.14.2 encoder/Encoder#height.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
399 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(flags)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; // packed field
400 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(0u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; // bg index
401 tmp.write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(0u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; // aspect ratio
402 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tmp.finishrust-analyzer cargo gif 0.14.2 encoder/impl#[`Buf<N>`]finish().(self.writerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]writer().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
403 }
404
405 /// Gets a reference to the writer instance used by this encoder.
406 pub fn get_refrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]get_ref().(&self) -> &W {
407 self.wrust-analyzer cargo gif 0.14.2 encoder/Encoder#w..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
408 }
409
410 /// Gets a mutable reference to the writer instance used by this encoder.
411 ///
412 /// It is inadvisable to directly write to the underlying writer.
413 pub fn get_mutrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]get_mut().(&mut self) -> &mut W {
414 self.wrust-analyzer cargo gif 0.14.2 encoder/Encoder#w..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
415 }
416
417 /// Finishes writing, and returns the `io::Write` instance used by this encoder
418 pub fn into_innerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]into_inner().(mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<W, EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
419 self.write_trailerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_trailer().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
420 self.wrust-analyzer cargo gif 0.14.2 encoder/Encoder#w..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#::WriterNotFoundrust-analyzer cargo gif 0.14.2 encoder/EncodingError#WriterNotFound#)
421 }
422
423 /// Write the final tailer.
424 fn write_trailerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_trailer().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
425 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.writerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]writer().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..write_lerust-analyzer cargo gif 0.14.2 traits/impl#[W][`WriteBytesExt<u8>`]write_le().(Blockrust-analyzer cargo gif 0.14.2 common/Block#::Trailerrust-analyzer cargo gif 0.14.2 common/Block#Trailer# as u8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
426 }
427
428 #[inline]
429 fn writerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]writer().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&mut W, EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#> {
430 self.wrust-analyzer cargo gif 0.14.2 encoder/Encoder#w..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#::WriterNotFoundrust-analyzer cargo gif 0.14.2 encoder/EncodingError#WriterNotFound#)
431 }
432 }
433
434 /// Encodes the data into the provided buffer.
435 ///
436 /// The first byte is the minimum code size, followed by LZW data.
437 fn lzw_encoderust-analyzer cargo gif 0.14.2 encoder/lzw_encode().(data: &[u8], buffer: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) {
438 let mut max_byte = 0;
439 for &byte in data {
440 if byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().max_byte {
441 max_byte = byte;
442 // code size is the same after that
443 if byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().127 {
444 break;
445 }
446 }
447 }
448 let palette_min_len = u32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`From<u8>`]from().(max_byte) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1;
449 // As per gif spec: The minimal code size has to be >= 2
450 let min_code_size = palette_min_len.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(4).next_power_of_tworust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]next_power_of_two().().trailing_zerosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]trailing_zeros().() as u8;
451 buffer.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(min_code_size);
452 let mut enc = LzwEncoderrust-analyzer cargo weezl 0.1.10 encode/Encoder#::newrust-analyzer cargo weezl 0.1.10 encode/impl#[Encoder]new().(BitOrderrust-analyzer cargo weezl 0.1.10 BitOrder#::Lsbrust-analyzer cargo weezl 0.1.10 BitOrder#Lsb#, min_code_size);
453 let len = enc.into_vecrust-analyzer cargo weezl 0.1.10 encode/impl#[Encoder]into_vec().(buffer).encode_allrust-analyzer cargo weezl 0.1.10 encode/impl#[`IntoVec<'_>`]encode_all().(data).consumed_outrust-analyzer cargo weezl 0.1.10 error/VectorResult#consumed_out.;
454 buffer.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1);
455 }
456
457 impl Framerust-analyzer cargo gif 0.14.2 common/Frame#<'_> {
458 /// Replace frame's buffer with a LZW-compressed one for use with [`Encoder::write_lzw_pre_encoded_frame`].
459 ///
460 /// Frames can be compressed in any order, separately from the `Encoder`, which can be used to compress frames in parallel.
461 pub fn make_lzw_pre_encodedrust-analyzer cargo gif 0.14.2 encoder/impl#[`Frame<'_>`]make_lzw_pre_encoded().(&mut self) {
462 let mut buffer = 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().();
463 buffer.try_reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]try_reserve().(self.bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer..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().2).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("OOM");
464 lzw_encoderust-analyzer cargo gif 0.14.2 encoder/lzw_encode().(&self.bufferrust-analyzer cargo gif 0.14.2 common/Frame#buffer., &mut buffer);
465 self.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#(buffer);
466 }
467 }
468
469 /// GIF encoder.
470 pub struct Encoderrust-analyzer cargo gif 0.14.2 encoder/Encoder#<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> {
471 wrust-analyzer cargo gif 0.14.2 encoder/Encoder#w.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<W>,
472 global_paletterust-analyzer cargo gif 0.14.2 encoder/Encoder#global_palette.: bool,
473 widthrust-analyzer cargo gif 0.14.2 encoder/Encoder#width.: u16,
474 heightrust-analyzer cargo gif 0.14.2 encoder/Encoder#height.: u16,
475 bufferrust-analyzer cargo gif 0.14.2 encoder/Encoder#buffer.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>,
476 }
477
478 impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Encoderrust-analyzer cargo gif 0.14.2 encoder/Encoder#<W> {
479 #[cfg(feature = "raii_no_panic")]
480 fn droprust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`][Drop]drop().(&mut self) {
481 if self.wrust-analyzer cargo gif 0.14.2 encoder/Encoder#w..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
482 let _ = self.write_trailerrust-analyzer cargo gif 0.14.2 encoder/impl#[`Encoder<W>`]write_trailer().();
483 }
484 }
485
486 #[cfg(not(feature = "raii_no_panic"))]
487 fn drop(&mut self) {
488 if selfrust-analyzer cargo gif 0.14.2 encoder/.w.is_some() {
489 selfrust-analyzer cargo gif 0.14.2 encoder/.write_trailer().unwrap();
490 }
491 }
492 }
493
494 // Color table size converted to flag bits
495 fn flag_sizerust-analyzer cargo gif 0.14.2 encoder/flag_size().(size: usize) -> u8 {
496 (size.clamprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][Ord]clamp().(2, 255).next_power_of_tworust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]next_power_of_two().().trailing_zerosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]trailing_zeros().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().1) as u8
497 }
498
499 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
500 fn test_flag_sizerust-analyzer cargo gif 0.14.2 encoder/test_flag_size().() {
501 #[rustfmt::skip]
502 fn expectedrust-analyzer cargo gif 0.14.2 encoder/expected().(size: usize) -> u8 {
503 match size {
504 0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#2 => 0,
505 3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#4 => 1,
506 5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#8 => 2,
507 9 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#16 => 3,
508 17 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#32 => 4,
509 33 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#64 => 5,
510 65 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#128 => 6,
511 129..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#256 => 7,
512 _ => 7
513 }
514 }
515
516 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#300 {
517 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(flag_sizerust-analyzer cargo gif 0.14.2 encoder/flag_size().(i), expectedrust-analyzer cargo gif 0.14.2 encoder/expected().(i));
518 }
519 for i in 4..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#255u8 {
520 let expected = match flag_sizerust-analyzer cargo gif 0.14.2 encoder/flag_size().(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().i as usize) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().1 {
521 1 => 2,
522 n => n,
523 };
524 let actual = (u32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`From<u8>`]from().(i) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1)
525 .maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(4)
526 .next_power_of_tworust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]next_power_of_two().()
527 .trailing_zerosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]trailing_zeros().() as u8;
528 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual, expected);
529 }
530 }
531
532 struct Bufrust-analyzer cargo gif 0.14.2 encoder/Buf#<const N: usize> {
533 bufrust-analyzer cargo gif 0.14.2 encoder/Buf#buf.: [u8; N],
534 posrust-analyzer cargo gif 0.14.2 encoder/Buf#pos.: usize,
535 }
536
537 impl<const N: usize> Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for Bufrust-analyzer cargo gif 0.14.2 encoder/Buf#<N> {
538 #[inline(always)]
539 fn writerust-analyzer cargo gif 0.14.2 encoder/impl#[`Buf<N>`][Write]write().(&mut self, buf: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> {
540 let len = buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
541 let pos = self.posrust-analyzer cargo gif 0.14.2 encoder/Buf#pos.;
542 self.bufrust-analyzer cargo gif 0.14.2 encoder/Buf#buf.
543 .get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pos 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().len)
544 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::WriteZerorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#WriteZero#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
545 .copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(buf);
546 self.posrust-analyzer cargo gif 0.14.2 encoder/Buf#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().len;
547 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(len)
548 }
549
550 fn flushrust-analyzer cargo gif 0.14.2 encoder/impl#[`Buf<N>`][Write]flush().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
551 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
552 }
553 }
554
555 fn tmp_bufrust-analyzer cargo gif 0.14.2 encoder/tmp_buf().<const N: usize>() -> Bufrust-analyzer cargo gif 0.14.2 encoder/Buf#<N> {
556 Bufrust-analyzer cargo gif 0.14.2 encoder/Buf# {
557 bufrust-analyzer cargo gif 0.14.2 encoder/Buf#buf.: [0; N],
558 posrust-analyzer cargo gif 0.14.2 encoder/Buf#pos.: 0,
559 }
560 }
561
562 impl<const N: usize> Bufrust-analyzer cargo gif 0.14.2 encoder/Buf#<N> {
563 #[inline(always)]
564 fn finishrust-analyzer cargo gif 0.14.2 encoder/impl#[`Buf<N>`]finish().(&self, mut w: impl Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
565 debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(self.posrust-analyzer cargo gif 0.14.2 encoder/Buf#pos., N);
566 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&self.bufrust-analyzer cargo gif 0.14.2 encoder/Buf#buf.)
567 }
568 }
569
570 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
571 fn error_castrust-analyzer cargo gif 0.14.2 encoder/error_cast().() {
572 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::boxedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/::Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#;
573 let _: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#> =
574 EncodingErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingError#::fromrust-analyzer cargo gif 0.14.2 encoder/impl#[EncodingError][`From<EncodingFormatError>`]from().(EncodingFormatErrorrust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#::MissingColorPaletterust-analyzer cargo gif 0.14.2 encoder/EncodingFormatError#MissingColorPalette#).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
575 }