Debian Codegraph @

src/misc.rs

raw symbols SCIP
1 /*
2 * Copyright (c) 2023.
3 *
4 * This software is free software;
5 *
6 * You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
7 */
8
9 //!Miscellaneous stuff
10 #![allow(dead_code)]
11
12 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!;
13 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().;
14 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/;
15 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/::NonZeroU32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU32#;
16
17 use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::bytestreamrust-analyzer cargo zune-core 0.5.1 bytestream/::ZByteReaderTraitrust-analyzer cargo zune-core 0.5.1 bytestream/traits/ZByteReaderTrait#;
18 use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::colorspacerust-analyzer cargo zune-core 0.5.1 colorspace/::ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#;
19 use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::logrust-analyzer cargo log 0.4.29 crate/::{tracerust-analyzer cargo log 0.4.29 macros/trace!, warnrust-analyzer cargo log 0.4.29 macros/warn!};
20
21 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::componentsrust-analyzer cargo zune-jpeg 0.5.15 components/::{ComponentIDrust-analyzer cargo zune-jpeg 0.5.15 components/ComponentID#, SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#};
22 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::errorsrust-analyzer cargo zune-jpeg 0.5.15 errors/::DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#;
23 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::huffmanrust-analyzer cargo zune-jpeg 0.5.15 huffman/::HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#;
24 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#;
25
26 /// Start of baseline DCT Huffman coding
27
28 pub const START_OF_FRAME_BASErust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_BASE.: u16 = 0xffc0;
29
30 /// Start of another frame
31
32 pub const START_OF_FRAME_EXT_SEQrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_EXT_SEQ.: u16 = 0xffc1;
33
34 /// Start of progressive DCT encoding
35
36 pub const START_OF_FRAME_PROG_DCTrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_PROG_DCT.: u16 = 0xffc2;
37
38 /// Start of Lossless sequential Huffman coding
39
40 pub const START_OF_FRAME_LOS_SEQrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_LOS_SEQ.: u16 = 0xffc3;
41
42 /// Start of extended sequential DCT arithmetic coding
43
44 pub const START_OF_FRAME_EXT_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_EXT_AR.: u16 = 0xffc9;
45
46 /// Start of Progressive DCT arithmetic coding
47
48 pub const START_OF_FRAME_PROG_DCT_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_PROG_DCT_AR.: u16 = 0xffca;
49
50 /// Start of Lossless sequential Arithmetic coding
51
52 pub const START_OF_FRAME_LOS_SEQ_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_LOS_SEQ_AR.: u16 = 0xffcb;
53
54 /// Undo run length encoding of coefficients by placing them in natural order
55 ///
56 /// This is an index from position-in-bitstream to position-in-row-major-order.
57 #[rustfmt::skip]
58 pub const UN_ZIGZAGrust-analyzer cargo zune-jpeg 0.5.15 misc/UN_ZIGZAG.: [usize; 64 + 16] = [
59 0, 1, 8, 16, 9, 2, 3, 10,
60 17, 24, 32, 25, 18, 11, 4, 5,
61 12, 19, 26, 33, 40, 48, 41, 34,
62 27, 20, 13, 6, 7, 14, 21, 28,
63 35, 42, 49, 56, 57, 50, 43, 36,
64 29, 22, 15, 23, 30, 37, 44, 51,
65 58, 59, 52, 45, 38, 31, 39, 46,
66 53, 60, 61, 54, 47, 55, 62, 63,
67 // Prevent overflowing
68 63, 63, 63, 63, 63, 63, 63, 63,
69 63, 63, 63, 63, 63, 63, 63, 63
70 ];
71
72 /// Align data to a 16 byte boundary
73 #[repr(align(16))]
74 #[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:)]
75
76 pub struct Aligned16rust-analyzer cargo zune-jpeg 0.5.15 misc/Aligned16#<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(pub T);
77
78 impl<T> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Aligned16rust-analyzer cargo zune-jpeg 0.5.15 misc/Aligned16#<T>
79 where
80 T: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#
81 {
82 fn defaultrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[`Aligned16<T>`][Default]default().() -> Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[`Aligned16<T>`][Default] {
83 Aligned16rust-analyzer cargo zune-jpeg 0.5.15 misc/Aligned16#(T::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().())
84 }
85 }
86
87 /// Align data to a 32 byte boundary
88 #[repr(align(32))]
89 #[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:)]
90 pub struct Aligned32rust-analyzer cargo zune-jpeg 0.5.15 misc/Aligned32#<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(pub T);
91
92 impl<T> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Aligned32rust-analyzer cargo zune-jpeg 0.5.15 misc/Aligned32#<T>
93 where
94 T: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#
95 {
96 fn defaultrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[`Aligned32<T>`][Default]default().() -> Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[`Aligned32<T>`][Default] {
97 Aligned32rust-analyzer cargo zune-jpeg 0.5.15 misc/Aligned32#(T::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().())
98 }
99 }
100
101 /// Markers that identify different Start of Image markers
102 /// They identify the type of encoding and whether the file use lossy(DCT) or
103 /// lossless compression and whether we use Huffman or arithmetic coding schemes
104 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, 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:)]
105 #[allow(clippy::upper_case_acronyms)]
106 pub enum SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers# {
107 /// Baseline DCT markers
108 BaselineDctrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#BaselineDct#,
109 /// SOF_1 Extended sequential DCT,Huffman coding
110 ExtendedSequentialHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ExtendedSequentialHuffman#,
111 /// Progressive DCT, Huffman coding
112 ProgressiveDctHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ProgressiveDctHuffman#,
113 /// Lossless (sequential), huffman coding,
114 LosslessHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#LosslessHuffman#,
115 /// Extended sequential DEC, arithmetic coding
116 ExtendedSequentialDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ExtendedSequentialDctArithmetic#,
117 /// Progressive DCT, arithmetic coding,
118 ProgressiveDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ProgressiveDctArithmetic#,
119 /// Lossless ( sequential), arithmetic coding
120 LosslessArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#LosslessArithmetic#
121 }
122
123 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers# {
124 fn defaultrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Default]default().() -> Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Default] {
125 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Default]::BaselineDctrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#BaselineDct#
126 }
127 }
128
129 impl SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers# {
130 /// Check if a certain marker is sequential DCT or not
131
132 pub fn is_sequential_dctrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]is_sequential_dct().(self) -> bool {
133 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
134 self,
135 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::BaselineDctrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#BaselineDct#
136 | Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::ExtendedSequentialHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ExtendedSequentialHuffman#
137 | Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::ExtendedSequentialDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ExtendedSequentialDctArithmetic#
138 )
139 }
140
141 /// Check if a marker is a Lossles type or not
142
143 pub fn is_losslessrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]is_lossless().(self) -> bool {
144 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::LosslessHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#LosslessHuffman# | Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::LosslessArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#LosslessArithmetic#)
145 }
146
147 /// Check whether a marker is a progressive marker or not
148
149 pub fn is_progressiverust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]is_progressive().(self) -> bool {
150 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
151 self,
152 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::ProgressiveDctHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ProgressiveDctHuffman# | Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::ProgressiveDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ProgressiveDctArithmetic#
153 )
154 }
155
156 /// Create a marker from an integer
157
158 pub fn from_intrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]from_int().(int: u16) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#> {
159 match int {
160 START_OF_FRAME_BASErust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_BASE. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::BaselineDctrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#BaselineDct#),
161 START_OF_FRAME_PROG_DCTrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_PROG_DCT. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::ProgressiveDctHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ProgressiveDctHuffman#),
162 START_OF_FRAME_PROG_DCT_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_PROG_DCT_AR. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::ProgressiveDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ProgressiveDctArithmetic#),
163 START_OF_FRAME_LOS_SEQrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_LOS_SEQ. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::LosslessHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#LosslessHuffman#),
164 START_OF_FRAME_LOS_SEQ_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_LOS_SEQ_AR. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::LosslessArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#LosslessArithmetic#),
165 START_OF_FRAME_EXT_SEQrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_EXT_SEQ. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::ExtendedSequentialHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ExtendedSequentialHuffman#),
166 START_OF_FRAME_EXT_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_EXT_AR. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers]::ExtendedSequentialDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ExtendedSequentialDctArithmetic#),
167 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
168 }
169 }
170 }
171
172 impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers# {
173 fn fmtrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
174 match &self {
175 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Debug]::BaselineDctrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#BaselineDct# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Baseline DCT"),
176 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Debug]::ExtendedSequentialHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ExtendedSequentialHuffman# => {
177 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Extended sequential DCT, Huffman Coding")
178 }
179 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Debug]::ProgressiveDctHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ProgressiveDctHuffman# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Progressive DCT,Huffman Encoding"),
180 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Debug]::LosslessHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#LosslessHuffman# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Lossless (sequential) Huffman encoding"),
181 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Debug]::ExtendedSequentialDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ExtendedSequentialDctArithmetic# => {
182 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Extended sequential DCT, arithmetic coding")
183 }
184 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Debug]::ProgressiveDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ProgressiveDctArithmetic# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Progressive DCT, arithmetic coding"),
185 Selfrust-analyzer cargo zune-jpeg 0.5.15 misc/impl#[SOFMarkers][Debug]::LosslessArithmeticrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#LosslessArithmetic# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Lossless (sequential) arithmetic coding")
186 }
187 }
188 }
189
190 /// Set up component parameters.
191 ///
192 /// This modifies the components in place setting up details needed by other
193 /// parts fo the decoder.
194 pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn setup_component_paramsrust-analyzer cargo zune-jpeg 0.5.15 misc/setup_component_params().<T: ZByteReaderTraitrust-analyzer cargo zune-core 0.5.1 bytestream/traits/ZByteReaderTrait#>(
195 img: &mut JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#<T>
196 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
197 let img_width = img.widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]width().();
198 let img_height = img.heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]height().();
199
200 // in case of adobe app14 being present, zero may indicate
201 // either CMYK if components are 4 or RGB if components are 3,
202 // see https://docs.oracle.com/javase/6/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html
203 // so since we may not know how many number of components
204 // we have when decoding app14, we have to defer that check
205 // until now.
206 //
207 // We know adobe app14 was present since it's the only one that can modify
208 // input colorspace to be CMYK
209 if img.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..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][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().3 && img.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace. rust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace][`PartialEq<Self>`]eq().ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::CMYKrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#CMYK# {
210 img.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace. = ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB#;
211 }
212
213 for component in &mut img.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components. {
214 // compute interleaved image info
215 // h_max contains the maximum horizontal component
216 img.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max. = maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(img.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max., component.horizontal_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#horizontal_sample.);
217 // v_max contains the maximum vertical component
218 img.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max. = maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(img.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max., component.vertical_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#vertical_sample.);
219 img.mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_width. = img.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max. 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().8;
220 img.mcu_heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_height. = img.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max. 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().8;
221 // Number of MCU's per width
222 img.mcu_xrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_x. = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(img.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width.).div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]div_ceil().(img.mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_width.);
223 // Number of MCU's per height
224 img.mcu_yrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_y. = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(img.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#height.).div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]div_ceil().(img.mcu_heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_height.);
225
226 if img.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 || img.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 {
227 // interleaved images have horizontal and vertical sampling factors
228 // not equal to 1.
229 img.is_interleavedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_interleaved. = true;
230 }
231 // Extract quantization tables from the arrays into components
232 let qt_table = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().img.qt_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#qt_tables.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().component.quantization_table_numberrust-analyzer cargo zune-jpeg 0.5.15 components/Components#quantization_table_number. as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().
233 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
234 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
235 DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::DqtErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#DqtError#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
236 "No quantization table for component {:?}",
237 component.component_idrust-analyzer cargo zune-jpeg 0.5.15 components/Components#component_id.
238 ))
239 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
240
241 let x = (usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(img_width) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().component.horizontal_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#horizontal_sample. 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().img.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max. 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().1) 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().img.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max.;
242 let y = (usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(img_height) 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().component.horizontal_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#horizontal_sample. 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().img.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max. 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().1) 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().img.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max.;
243 component.xrust-analyzer cargo zune-jpeg 0.5.15 components/Components#x. = x;
244 component.w2rust-analyzer cargo zune-jpeg 0.5.15 components/Components#w2. = img.mcu_xrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_x. 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().component.horizontal_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#horizontal_sample. 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().8;
245 // probably not needed. :)
246 component.yrust-analyzer cargo zune-jpeg 0.5.15 components/Components#y. = y;
247 component.quantization_tablerust-analyzer cargo zune-jpeg 0.5.15 components/Components#quantization_table. = qt_table;
248 // initially stride contains its horizontal sub-sampling
249 component.width_striderust-analyzer cargo zune-jpeg 0.5.15 components/Components#width_stride. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`MulAssign<Self>`]mul_assign().*=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`MulAssign<Self>`]mul_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`MulAssign<Self>`]mul_assign().img.mcu_xrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_x. 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().8;
250 }
251 {
252 // Sampling factors are one thing that suck
253 // this fixes a specific problem with images like
254 //
255 // (2 2) None
256 // (2 1) H
257 // (2 1) H
258 //
259 // The images exist in the wild, the images are not meant to exist
260 // but they do, it's just an annoying horizontal sub-sampling that
261 // I don't know why it exists.
262 // But it does
263 // So we try to cope with that.
264 // I am not sure of how to explain how to fix it, but it involved a debugger
265 // and to much coke(the legal one)
266 //
267 // If this wasn't present, self.upsample_dest would have the wrong length
268 let mut handle_that_annoying_bug = false;
269
270 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(y_component) = img
271 .componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.
272 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
273 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|c| c.component_idrust-analyzer cargo zune-jpeg 0.5.15 components/Components#component_id. rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[ComponentID][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[ComponentID][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[ComponentID][`PartialEq<Self>`]eq().ComponentIDrust-analyzer cargo zune-jpeg 0.5.15 components/ComponentID#::Yrust-analyzer cargo zune-jpeg 0.5.15 components/ComponentID#Y#)
274 {
275 if y_component.horizontal_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#horizontal_sample. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().2 || y_component.vertical_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#vertical_sample. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().2 {
276 handle_that_annoying_bug = true;
277 }
278 }
279 if handle_that_annoying_bug {
280 for comp in &mut img.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components. {
281 if (comp.component_idrust-analyzer cargo zune-jpeg 0.5.15 components/Components#component_id. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().ComponentIDrust-analyzer cargo zune-jpeg 0.5.15 components/ComponentID#::Yrust-analyzer cargo zune-jpeg 0.5.15 components/ComponentID#Y#)
282 && (comp.horizontal_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#horizontal_sample. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 || comp.vertical_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#vertical_sample. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1)
283 {
284 comp.fix_an_annoying_bugrust-analyzer cargo zune-jpeg 0.5.15 components/Components#fix_an_annoying_bug. = 2;
285 }
286 }
287 }
288 }
289
290 if img.is_mjpegrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_mjpeg. {
291 fill_default_mjpeg_tablesrust-analyzer cargo zune-jpeg 0.5.15 misc/fill_default_mjpeg_tables().(
292 img.is_progressiverust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_progressive.,
293 &mut img.dc_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#dc_huffman_tables.,
294 &mut img.ac_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#ac_huffman_tables.
295 );
296 }
297
298 // check colorspace matches
299 if img.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace..num_componentsrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]num_components().() 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().img.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
300 if img.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace. rust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace][`PartialEq<Self>`]eq().ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::YCCKrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#YCCK# {
301 // Some images may have YCCK format (from adobe app14 segment) which is supposed to be 4 components
302 // but only 3 components, see issue https://github.com/etemesi254/zune-image/issues/275
303 // So this is the behaviour of other decoders
304 // - stb_image: Treats it as YCbCr image
305 // - libjpeg_turbo: Does not know how to parse YCCK images (transform 2 app14) so treats
306 // it as YCbCr
307 // So I will match that to match existing ones
308 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Treating YCCK colorspace as YCbCr as component length does not match");
309 img.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace. = ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::YCbCrrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#YCbCr#
310 } else {
311 // Note, translated this to a warning to handle valid images of the sort
312 // See https://github.com/etemesi254/zune-image/issues/288 where there
313 // was a CMYK image with two components which would be decoded to 4 components
314 // by the decoder.
315 // So with a warning that becomes supported.
316 //
317 // djpeg fails to render an image from that also probably because it does not
318 // understand the expected format.
319 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().img.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..strict_moderust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]strict_mode().() {
320 warnrust-analyzer cargo log 0.4.29 macros/warn!!(
321 "Expected {} number of components but found {}",
322 img.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace..num_componentsrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]num_components().(),
323 img.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
324 );
325 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Defaulting to multisample to decode");
326
327 // N/B: We do not post process the color of such, treating it as multiband
328 // is the best option since I am not aware of grayscale+alpha which is the most common
329 // two band format in jpeg.
330 if img.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..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>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
331 img.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace. = ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::MultiBandrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#MultiBand#(
332 NonZeroU32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU32#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new().(img.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as u32).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
333 );
334 }
335 } else {
336 let msg = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
337 "Expected {} number of components but found {}",
338 img.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace..num_componentsrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]num_components().(),
339 img.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
340 );
341
342 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::Formatrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Format#(msg));
343 }
344 }
345 }
346 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
347 }
348
349 ///Calculate number of fill bytes added to the end of a JPEG image
350 /// to fill the image
351 ///
352 /// JPEG usually inserts padding bytes if the image width cannot be evenly divided into
353 /// 8 , 16 or 32 chunks depending on the sub sampling ratio. So given a sub-sampling ratio,
354 /// and the actual width, this calculates the padded bytes that were added to the image
355 ///
356 /// # Params
357 /// -actual_width: Actual width of the image
358 /// -sub_sample: Sub sampling factor of the image
359 ///
360 /// # Returns
361 /// The padded width, this is how long the width is for a particular image
362 pub fn calculate_padded_widthrust-analyzer cargo zune-jpeg 0.5.15 misc/calculate_padded_width().(actual_width: usize, sub_sample: SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#) -> usize {
363 match sub_sample {
364 SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Nonerust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#None# | SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Vrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#V# => {
365 // None+V sends one MCU row, so that's a simple calculation
366 ((actual_width 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().7) 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().8) 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().8
367 }
368 SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Hrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#H# | SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::HVrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#HV# => {
369 // sends two rows, width can be expanded by up to 15 more bytes
370 ((actual_width 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().15) 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().16) 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().16
371 }
372 SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Genericrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#Generic#(h, _) => {
373 ((actual_width 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().((h 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().8).saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1))) 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().(h 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().8)) 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().(h 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().8)
374 }
375 }
376 }
377
378 // https://www.loc.gov/preservation/digital/formats/fdd/fdd000063.shtml
379 // "Avery Lee, writing in the rec.video.desktop newsgroup in 2001, commented that "MJPEG, or at
380 // least the MJPEG in AVIs having the MJPG fourcc, is restricted JPEG with a fixed -- and
381 // *omitted* -- Huffman table. The JPEG must be YCbCr colorspace, it must be 4:2:2, and it must
382 // use basic Huffman encoding, not arithmetic or progressive.... You can indeed extract the
383 // MJPEG frames and decode them with a regular JPEG decoder, but you have to prepend the DHT
384 // segment to them, or else the decoder won't have any idea how to decompress the data.
385 // The exact table necessary is given in the OpenDML spec.""
386 pub fn fill_default_mjpeg_tablesrust-analyzer cargo zune-jpeg 0.5.15 misc/fill_default_mjpeg_tables().(
387 is_progressive: bool, dc_huffman_tables: &mut [Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#>],
388 ac_huffman_tables: &mut [Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#>]
389 ) {
390 // Section K.3.3
391 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Filling with default mjpeg tables");
392
393 if dc_huffman_tables[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
394 // Table K.3
395 dc_huffman_tables[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
396 HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#::new_unfilledrust-analyzer cargo zune-jpeg 0.5.15 huffman/impl#[HuffmanTable]new_unfilled().(
397 &[
398 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
399 0x00, 0x00, 0x00, 0x00
400 ],
401 &[
402 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B
403 ],
404 true,
405 is_progressive
406 )
407 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
408 );
409 }
410 if dc_huffman_tables[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
411 // Table K.4
412 dc_huffman_tables[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
413 HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#::new_unfilledrust-analyzer cargo zune-jpeg 0.5.15 huffman/impl#[HuffmanTable]new_unfilled().(
414 &[
415 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
416 0x00, 0x00, 0x00, 0x00
417 ],
418 &[
419 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B
420 ],
421 true,
422 is_progressive
423 )
424 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
425 );
426 }
427 if ac_huffman_tables[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
428 // Table K.5
429 ac_huffman_tables[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
430 HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#::new_unfilledrust-analyzer cargo zune-jpeg 0.5.15 huffman/impl#[HuffmanTable]new_unfilled().(
431 &[
432 0x00, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04,
433 0x00, 0x00, 0x01, 0x7D
434 ],
435 &[
436 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13,
437 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42,
438 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A,
439 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35,
440 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A,
441 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67,
442 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84,
443 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
444 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3,
445 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
446 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1,
447 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4,
448 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA
449 ],
450 false,
451 is_progressive
452 )
453 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
454 );
455 }
456 if ac_huffman_tables[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
457 // Table K.6
458 ac_huffman_tables[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
459 HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#::new_unfilledrust-analyzer cargo zune-jpeg 0.5.15 huffman/impl#[HuffmanTable]new_unfilled().(
460 &[
461 0x00, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04,
462 0x00, 0x01, 0x02, 0x77
463 ],
464 &[
465 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51,
466 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1,
467 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24,
468 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A,
469 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
470 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66,
471 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82,
472 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96,
473 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA,
474 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5,
475 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9,
476 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4,
477 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA
478 ],
479 false,
480 is_progressive
481 )
482 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
483 );
484 }
485 }