Debian Codegraph @

src/mcu.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 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#;
10 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!, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/};
11 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/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().;
12
13 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#;
14 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#;
15 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#::Lumarust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Luma#;
16 use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::logrust-analyzer cargo log 0.4.29 crate/::{errorrust-analyzer cargo log 0.4.29 macros/error!, tracerust-analyzer cargo log 0.4.29 macros/trace!, warnrust-analyzer cargo log 0.4.29 macros/warn!};
17
18 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::bitstreamrust-analyzer cargo zune-jpeg 0.5.15 bitstream/::BitStreamrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#;
19 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::componentsrust-analyzer cargo zune-jpeg 0.5.15 components/::SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#;
20 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::decoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/::MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.;
21 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#;
22 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::markerrust-analyzer cargo zune-jpeg 0.5.15 marker/::Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#;
23 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::mcu_progrust-analyzer cargo zune-jpeg 0.5.15 mcu_prog/::get_markerrust-analyzer cargo zune-jpeg 0.5.15 mcu_prog/get_marker().;
24 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::miscrust-analyzer cargo zune-jpeg 0.5.15 misc/::{calculate_padded_widthrust-analyzer cargo zune-jpeg 0.5.15 misc/calculate_padded_width()., setup_component_paramsrust-analyzer cargo zune-jpeg 0.5.15 misc/setup_component_params().};
25 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::workerrust-analyzer cargo zune-jpeg 0.5.15 worker/::{color_convertrust-analyzer cargo zune-jpeg 0.5.15 worker/color_convert()., upsamplerust-analyzer cargo zune-jpeg 0.5.15 worker/upsample().};
26 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#;
27
28 /// The size of a DC block for a MCU.
29
30 pub const DCT_BLOCKrust-analyzer cargo zune-jpeg 0.5.15 mcu/DCT_BLOCK.: usize = 64;
31
32 impl<T: ZByteReaderTraitrust-analyzer cargo zune-core 0.5.1 bytestream/traits/ZByteReaderTrait#> JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#<T> {
33 /// Check for existence of DC and AC Huffman Tables
34 pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn check_tablesrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]check_tables().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
35 // check that dc and AC tables exist outside the hot path
36 for component in &self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components. {
37 let _ = &self
38 .dc_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#dc_huffman_tables.
39 .getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(component.dc_huff_tablerust-analyzer cargo zune-jpeg 0.5.15 components/Components#dc_huff_table.)
40 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
41 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
42 DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::HuffmanDecoderust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#HuffmanDecode#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
43 "No Huffman DC table for component {:?} ",
44 component.component_idrust-analyzer cargo zune-jpeg 0.5.15 components/Components#component_id.
45 ))
46 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
47 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
48 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
49 DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::HuffmanDecoderust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#HuffmanDecode#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
50 "No DC table for component {:?}",
51 component.component_idrust-analyzer cargo zune-jpeg 0.5.15 components/Components#component_id.
52 ))
53 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
54
55 let _ = &self
56 .ac_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#ac_huffman_tables.
57 .getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(component.ac_huff_tablerust-analyzer cargo zune-jpeg 0.5.15 components/Components#ac_huff_table.)
58 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
59 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
60 DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::HuffmanDecoderust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#HuffmanDecode#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
61 "No Huffman AC table for component {:?} ",
62 component.component_idrust-analyzer cargo zune-jpeg 0.5.15 components/Components#component_id.
63 ))
64 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
65 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
66 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
67 DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::HuffmanDecoderust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#HuffmanDecode#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
68 "No AC table for component {:?}",
69 component.component_idrust-analyzer cargo zune-jpeg 0.5.15 components/Components#component_id.
70 ))
71 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
72 }
73 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
74 }
75
76 /// Decode MCUs and carry out post processing.
77 ///
78 /// This is the main decoder loop for the library, the hot path.
79 ///
80 /// Because of this, we pull in some very crazy optimization tricks hence readability is a pinch
81 /// here.
82 #[allow(
83 clippy::similar_names,
84 clippy::too_many_lines,
85 clippy::cast_possible_truncation
86 )]
87 #[inline(never)]
88 pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn decode_mcu_ycbcr_baselinerust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]decode_mcu_ycbcr_baseline().(
89 &mut self, pixels: &mut [u8]
90 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
91 setup_component_paramsrust-analyzer cargo zune-jpeg 0.5.15 misc/setup_component_params().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
92
93 // check dc and AC tables
94 self.check_tablesrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]check_tables().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
95
96 let (mut mcu_width, mut mcu_height);
97
98 if self.is_interleavedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_interleaved. {
99 // set upsampling functions
100 self.set_upsamplingrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]set_upsampling().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
101
102 mcu_width = self.mcu_xrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_x.;
103 mcu_height = self.mcu_yrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_y.;
104 } else {
105 // For non-interleaved images( (1*1) subsampling)
106 // number of MCU's are the widths (+7 to account for paddings) divided bu 8.
107 mcu_width = (self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width. as usize 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;
108 mcu_height = (self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#height. as usize 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;
109 }
110 if self.is_interleavedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_interleaved.
111 && self.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().1
112 && self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_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][`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().1
113 && (self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#sample_ratio. rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Vrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#V#
114 || self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#sample_ratio. rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::HVrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#HV#)
115 {
116 // For a specific set of images, e.g interleaved,
117 // when converting from YcbCr to grayscale, we need to
118 // take into account mcu height since the MCU decoding needs to take
119 // it into account for padding purposes and the post processor
120 // parses two rows per mcu width.
121 //
122 // set coeff to be 2 to ensure that we increment two rows
123 // for every mcu processed also
124 mcu_height 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().self.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max.;
125 mcu_height rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`DivAssign<Self>`]div_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`DivAssign<Self>`]div_assign().self.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max.;
126 self.coeffrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#coeff. = 2;
127 }
128
129 if self.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#::Lumarust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Luma# && self.is_interleavedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_interleaved. {
130 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Grayscale image with down-sampled component, resetting component details");
131
132 self.reset_paramsrust-analyzer cargo zune-jpeg 0.5.15 mcu_prog/impl#[`JpegDecoder<T>`]reset_params().();
133
134 mcu_width = ((self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().7) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div().8) as usize;
135 mcu_height = ((self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#height. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().7) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div().8) as usize;
136 }
137 let width = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width.);
138
139 let padded_width = calculate_padded_widthrust-analyzer cargo zune-jpeg 0.5.15 misc/calculate_padded_width().(width, self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#sample_ratio.);
140
141 let mut stream = BitStreamrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#::newrust-analyzer cargo zune-jpeg 0.5.15 bitstream/impl#[BitStream]new().();
142 let mut tmp = [0_i32; DCT_BLOCKrust-analyzer cargo zune-jpeg 0.5.15 mcu/DCT_BLOCK.];
143
144 let comp_len = self.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().();
145
146 for (pos, comp) in self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
147 // Allocate only needed components.
148 //
149 // For special colorspaces i.e YCCK and CMYK, just allocate all of the needed
150 // components.
151 if minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(
152 self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_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 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,
153 pos
154 ) 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().pos
155 || comp_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().4
156 // Special colorspace
157 {
158 // allocate enough space to hold a whole MCU width
159 // this means we should take into account sampling ratios
160 // `*8` is because each MCU spans 8 widths.
161 let len = comp.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][`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().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 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;
162
163 comp.neededrust-analyzer cargo zune-jpeg 0.5.15 components/Components#needed. = true;
164 comp.raw_coeffrust-analyzer cargo zune-jpeg 0.5.15 components/Components#raw_coeff. = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; len];
165 } else {
166 comp.neededrust-analyzer cargo zune-jpeg 0.5.15 components/Components#needed. = false;
167 }
168 }
169
170 // If all components are contained in the first scan of MCUs, then we can process into
171 // (upsampled) pixels immediately after each MCU, for convenience we use each row of MCUS.
172 // Otherwise, we must first wait until following SOS provide the remaining components.
173 let all_components_in_first_scan = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(self.num_scansrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#num_scans.) 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().self.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().();
174 let mut progressive_mcus: [Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16>; 4] = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::arrayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/from_fn().(|_| vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
175
176 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().all_components_in_first_scan {
177 for (component, mcu) in self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(&mut progressive_mcus) {
178 let len = mcu_width
179 *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.vertical_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#vertical_sample.
180 *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.
181 *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().mcu_height
182 *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().64;
183 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().mcu = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; len];
184 }
185 }
186
187 let mut pixels_written = 0;
188
189 let is_hv = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<bool>`]from().(self.is_interleavedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_interleaved.);
190 let upsampler_scratch_size = is_hv rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.width_striderust-analyzer cargo zune-jpeg 0.5.15 components/Components#width_stride.).maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#max().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0) 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;
191 let mut upsampler_scratch_space = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; upsampler_scratch_size];
192
193 'sos: loop {
194 tracerust-analyzer cargo log 0.4.29 macros/trace!!(
195 "Baseline decoding of components: {:?}",
196 &self.z_orderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#z_order.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(self.num_scansrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#num_scans.)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().
197 );
198
199 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Decoding MCU width: {mcu_width}, height: {mcu_height}");
200
201 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#mcu_height {
202 if stream.overread_byrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#overread_by. 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 {
203 pixels.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(pixels_written..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| v.fillrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]fill().(128));
204 if self.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().() {
205 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#::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#("Premature end of buffer"));
206 };
207
208 errorrust-analyzer cargo log 0.4.29 macros/error!!("Premature end of buffer");
209 break;
210 }
211
212 // decode a whole MCU width,
213 // this takes into account interleaved components.
214 let terminate = if all_components_in_first_scan {
215 self.decode_mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]decode_mcu_width().::<false>(
216 mcu_width,
217 i,
218 &mut tmp,
219 &mut stream,
220 &mut progressive_mcus
221 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
222 } else {
223 /* NB: (cae). This code was added due to the issue at https://github.com/etemesi254/zune-image/issues/277
224 *
225 * There is a particular set of images that interleave the start of scan (SOS) with the MCU,
226 * E.g if it's a three component image, we have SOS->MCU ->SOS->MCU ->SOS->MCU
227 * which presents a problem on decoding, we need to buffer the whole image before continuing since
228 * we won't have a row containing all the component data which will be needed e.g for color conversion.
229 *
230 * The mechanisms is that we decode the whole image upfront, which goes against the normal
231 * routine of decoding MCU width , so this requires more memory upfront than initial routines
232 * but it is a single image out of the many corpuses that exist, so its fine.
233 * (image in test-images/jpeg/sos_news.jpeg)
234
235 * Code contributed by Aurelia Molzer (https://github.com/197g)
236
237 *
238 */
239
240 self.decode_mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]decode_mcu_width().::<true>(
241 mcu_width,
242 i,
243 &mut tmp,
244 &mut stream,
245 &mut progressive_mcus
246 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
247 };
248
249 // process that width up until it's impossible. This is faster than allocation the
250 // full components, which we skipped earlier.
251 if all_components_in_first_scan {
252 self.post_processrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]post_process().(
253 pixels,
254 i,
255 mcu_height,
256 width,
257 padded_width,
258 &mut pixels_written,
259 &mut upsampler_scratch_space
260 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
261 }
262
263 match terminate {
264 McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::Okrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#Ok# => {}
265 McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::AnotherSosrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#AnotherSos# if all_components_in_first_scan => {
266 warnrust-analyzer cargo log 0.4.29 macros/warn!!("More than one SOS despite already having all components");
267 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
268 }
269 McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::AnotherSosrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#AnotherSos# => continue 'sos,
270 McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::InterScanMarkerrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#InterScanMarker#(marker) => {
271 // Handle inter-scan markers (DHT/DQT/etc) uniformly here.
272 // This keeps all marker handling in the outer loop.
273 if self.advance_to_next_sosrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]advance_to_next_sos().(marker, &mut stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
274 continue 'sos;
275 } else {
276 // Hit EOI
277 break;
278 }
279 }
280 McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::Terminaterust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#Terminate# => {
281 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Got terminate signal, will not process further");
282 pixels.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(pixels_written..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| v.fillrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]fill().(128));
283 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
284 }
285 }
286 }
287
288 // Breaks if we get here, looping only if we have restarted, i.e. found another SOS and
289 // continued at `'sos'.
290 break;
291 }
292
293 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().all_components_in_first_scan {
294 self.finish_baseline_decodingrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]finish_baseline_decoding().(&progressive_mcus, mcu_width, pixels)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
295 }
296
297 // it may happen that some images don't have the whole buffer
298 // so we can't panic in case of that
299 // assert_eq!(pixels_written, pixels.len());
300
301 // For UHD usecases that tie two images separating them with EOI and
302 // SOI markers, it may happen that we do not reach this image end of image
303 // So this ensures we reach it
304 // Ensure we read EOI
305 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().stream.seen_eoirust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#seen_eoi. {
306 let marker = get_markerrust-analyzer cargo zune-jpeg 0.5.15 mcu_prog/get_marker().(&mut self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream., &mut stream);
307 match marker {
308 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_m) => {
309 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Found marker {:?}", _m);
310 }
311 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => {
312 // ignore error
313 }
314 }
315 }
316
317 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Finished decoding image");
318
319 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
320 }
321
322 /// Process all MCUs when baseline decoding has been processing them component-after-component.
323 /// For simplicity this assembles the dequantized blocks in the order that the post processing
324 /// of an interleaved baseline decoding would use.
325 #[allow(clippy::too_many_lines)]
326 #[allow(clippy::cast_sign_loss)]
327 pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn finish_baseline_decodingrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]finish_baseline_decoding().(
328 &mut self, block: &[Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16>; MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.], _mcu_width: usize, pixels: &mut [u8]
329 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
330 let mcu_height = self.mcu_yrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_y.;
331
332 // Size of our output image(width*height)
333 let is_hv = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<bool>`]from().(self.is_interleavedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_interleaved.);
334 let upsampler_scratch_size = is_hv rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..width_striderust-analyzer cargo zune-jpeg 0.5.15 components/Components#width_stride.;
335 let width = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width.);
336 let padded_width = calculate_padded_widthrust-analyzer cargo zune-jpeg 0.5.15 misc/calculate_padded_width().(width, self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#sample_ratio.);
337
338 let mut upsampler_scratch_space = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; upsampler_scratch_size];
339
340 for (pos, comp) in self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
341 // Mark only needed components for computing output colors.
342 if minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(
343 self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_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 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,
344 pos
345 ) 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().pos
346 || self.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#
347 || self.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#
348 {
349 comp.neededrust-analyzer cargo zune-jpeg 0.5.15 components/Components#needed. = true;
350 } else {
351 comp.neededrust-analyzer cargo zune-jpeg 0.5.15 components/Components#needed. = false;
352 }
353 }
354
355 let mut pixels_written = 0;
356
357 // dequantize and idct have been performed, only color convert.
358 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#mcu_height {
359 // All the data is already in the right order, we just need to be able to pass it to
360 // the post_process & upsample method. That expects all the data to be stored as one
361 // row of MCUs in each component's `raw_coeff`.
362 'component: for (position, component) in &mut self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
363 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().component.neededrust-analyzer cargo zune-jpeg 0.5.15 components/Components#needed. {
364 continue 'component;
365 }
366
367 // step is the number of pixels this iteration wil be handling
368 // Given by the number of mcu's height and the length of the component block
369 // Since the component block contains the whole channel as raw pixels
370 // we this evenly divides the pixels into MCU blocks
371 //
372 // For interleaved images, this gives us the exact pixels comprising a whole MCU
373 // block
374 let step = block[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().position]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`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().mcu_height;
375
376 // where we will be reading our pixels from.
377 let slice = &block[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().position]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i 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().step..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#step]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index().;
378 let temp_channel = &mut component.raw_coeffrust-analyzer cargo zune-jpeg 0.5.15 components/Components#raw_coeff.;
379 temp_channel[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#step]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(slice);
380 }
381
382 // process that whole stripe of MCUs
383 self.post_processrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]post_process().(
384 pixels,
385 i,
386 mcu_height,
387 width,
388 padded_width,
389 &mut pixels_written,
390 &mut upsampler_scratch_space
391 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
392 }
393
394 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
395 }
396
397 fn decode_mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]decode_mcu_width().<const PROGRESSIVE: bool>(
398 &mut self, mcu_width: usize, mcu_height: usize, tmp: &mut [i32; 64],
399 stream: &mut BitStreamrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#, progressive: &mut [Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16>; 4]
400 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#, DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
401 let is_one_by_one = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.scan_subsampledrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#scan_subsampled.;
402
403 // The definition of MCU depends on the sampling factor of involved scans. When components
404 // have different factors then each Minimal-Coding-Unit is the least common multiple such
405 // that we have an integer number of blocks from each component. But the decoding of these
406 // components differs from it otherwise, we need an inner loop with a dynamic amount of
407 // coefficients per component, whereas otherwise we have exactly one block of coefficients
408 // encoded for each component in the bitstream order.
409 //
410 // We statically specialize on this to improve code generation of the common case a little
411 // bit. We could also special case common sub-sampling cases but be mindful of code bloat.
412 if is_one_by_one {
413 self.inner_decode_mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]inner_decode_mcu_width().::<PROGRESSIVE, false>(
414 mcu_width,
415 mcu_height,
416 tmp,
417 stream,
418 progressive
419 )
420 } else {
421 self.inner_decode_mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]inner_decode_mcu_width().::<PROGRESSIVE, true>(
422 mcu_width,
423 mcu_height,
424 tmp,
425 stream,
426 progressive
427 )
428 }
429 }
430
431 // Inline-never ensures we do get this function optimize on its own, into two different
432 // versions, without the optimizer tripping up over the complexity that comes with the
433 // constant folding. And constant folding is quite important for performance here as
434 // when `not SAMPLED` then the inner loop has exactly one iteration per component in
435 // the scan. The difference was ~1% or a bit more.
436 fn inner_decode_mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]inner_decode_mcu_width().<const PROGRESSIVE: bool, const SAMPLED: bool>(
437 &mut self, mcu_width: usize, mcu_height: usize, tmp: &mut [i32; 64],
438 stream: &mut BitStreamrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#, progressive: &mut [Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16>; 4]
439 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#, DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
440 let z_order = self.z_orderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#z_order.;
441 let z_scans = &z_order[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(self.num_scansrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#num_scans.)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().;
442
443 // How much of the head of `tmp` was written by the last MCU decoding? We only check for
444 // two different cases and not all possible outcomes as this is only used to optimize the
445 // bytes written in `fill`. Since the clobber happens in UNZIGZAG order we'd be straddling
446 // most cache lines anyways even if we did a partial write with the exact length of the
447 // coefficient data which was written into `tmp`.
448 let mut clobber_more_than_4x4 = true;
449
450 // For non-interleaved scans (PROGRESSIVE=true), each scan contains a single component
451 // and we iterate over that component's actual data unit count, not the interleaved MCU
452 // width multiplied by sampling factor.
453 let mut scan_du_width = if PROGRESSIVE {
454 let k = z_scans[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().;
455 let comp = &self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
456 // Calculate actual data units for this component: ceil(width / (8 * subsampling_ratio))
457 (self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width. as usize 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().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 ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().self.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 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)
458 /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().(self.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)
459 } else {
460 mcu_width
461 };
462 // In malformed scans that list multiple components, clamp to the smallest row capacity
463 // to avoid writing past the row buffer.
464 if PROGRESSIVE && z_scans.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>`]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().1 {
465 let min_du = z_scans
466 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
467 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|&k| self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..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][`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)
468 .minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#min().()
469 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0);
470 scan_du_width = scan_du_width.minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(min_du);
471 }
472
473 for j in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#scan_du_width {
474 // iterate over components
475 for &k in z_scans {
476 // we made this loop body massive due to several different paths that depend on
477 // static conditions. Note we (potentially) call into other functions so the
478 // compiler will not unroll anything here anyways. The gains from separating
479 // differently optimized loop bodies are much greater than a single additional jump
480 // here.
481 let component = &mut self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().k]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().;
482
483 let dc_table = self.dc_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#dc_huffman_tables.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().component.dc_huff_tablerust-analyzer cargo zune-jpeg 0.5.15 components/Components#dc_huff_table. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().
484 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
485 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#("DC table not found"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
486
487 let ac_table = self.ac_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#ac_huffman_tables.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().component.ac_huff_tablerust-analyzer cargo zune-jpeg 0.5.15 components/Components#ac_huff_table. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().
488 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
489 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#("AC table not found"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
490
491 let qt_table = &component.quantization_tablerust-analyzer cargo zune-jpeg 0.5.15 components/Components#quantization_table.;
492 let channel = if PROGRESSIVE {
493 let offset =
494 mcu_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.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][`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().component.vertical_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#vertical_sample.;
495 // Small stopgap for https://github.com/etemesi254/zune-image/issues/362
496 if offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().progressive[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().k]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(){
497 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#::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#("Would panic on slice iteration"))
498 }
499 &mut progressive[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().k]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().
500 } else {
501 &mut component.raw_coeffrust-analyzer cargo zune-jpeg 0.5.15 components/Components#raw_coeff.
502 };
503
504 let component_samples_needed = component.neededrust-analyzer cargo zune-jpeg 0.5.15 components/Components#needed.;
505
506 // If image is interleaved iterate over scan components,
507 // otherwise if it-s non-interleaved, these routines iterate in
508 // trivial scanline order(Y,Cb,Cr)
509 //
510 // Turn the bounds into a compile time constant for a common special case. This
511 // allows the compiler to unroll the loop and then do a bunch of interleaving.
512 //
513 // For PROGRESSIVE (non-interleaved), we iterate data units directly so
514 // h_samp/v_samp loops run exactly once.
515 let v_step =
516 if SAMPLED && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().PROGRESSIVE { 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#component.vertical_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#vertical_sample. } else { 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#1 };
517
518 for v_samp in v_step {
519 let h_step =
520 if SAMPLED && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().PROGRESSIVE { 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#component.horizontal_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#horizontal_sample. } else { 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#1 };
521
522 for h_samp in h_step {
523 let result = if component_samples_needed {
524 // Fill the array with zeroes, decode_mcu_block expects
525 // a zero based array. Clobber is in zig-zag order though.
526 // Writing consecutive entries is basically free in terms
527 // of memory throughput so we opt for a larger power of
528 // two which lets the compiler turn this into a repeated
529 // write of a zeroed vector register, which does not have
530 // any branches, instead of a more difficult pattern where
531 // we attempt to overwrite exactly one coefficient.
532 let clobber_len = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().clobber_more_than_4x4 { 32 } else { 64 };
533
534 tmp[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#clobber_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..fillrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]fill().(0);
535
536 stream.decode_mcu_blockrust-analyzer cargo zune-jpeg 0.5.15 bitstream/impl#[BitStream]decode_mcu_block().(
537 &mut self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream.,
538 dc_table,
539 ac_table,
540 qt_table,
541 tmp,
542 &mut component.dc_predrust-analyzer cargo zune-jpeg 0.5.15 components/Components#dc_pred.
543 )
544 } else {
545 // We do not touch tmp so there is no need to reset it.
546 stream.discard_mcu_blockrust-analyzer cargo zune-jpeg 0.5.15 bitstream/impl#[BitStream]discard_mcu_block().(&mut self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream., dc_table, ac_table)
547 };
548
549 // If an error occurs we can either propagate it
550 // as an error or print it and call terminate.
551 //
552 // This allows even corrupt images to render something,
553 // even if its bad, matching browsers.
554 //
555 // See example in https://github.com/etemesi254/zune-image/issues/293
556 let len = if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(len) = result {
557 len
558 } else {
559 // result.is_err()
560 return if self.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().() {
561 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(result.errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]err().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
562 } else {
563 errorrust-analyzer cargo log 0.4.29 macros/error!!("{}", result.errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]err().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
564 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::Terminaterust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#Terminate#)
565 };
566 };
567
568 if component_samples_needed {
569 // tmp was only written partially, note that len is in ZigZag order.
570 clobber_more_than_4x4 = len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().10;
571
572 let idct_position = if PROGRESSIVE {
573 // For non-interleaved, j indexes data units directly
574 j 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
575 } else {
576 // derived from stb and rewritten for my tastes
577 let c2 = v_samp 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;
578 let c3 = ((j 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().h_samp) 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;
579
580 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][`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().c2 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().c3
581 };
582
583 let idct_pos = channel.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(idct_position..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
584
585 if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]le().1 {
586 (self.idct_1x1_funcrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#idct_1x1_func.)(tmp, idct_pos, component.width_striderust-analyzer cargo zune-jpeg 0.5.15 components/Components#width_stride.);
587 } else if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]le().10 {
588 (self.idct_4x4_funcrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#idct_4x4_func.)(tmp, idct_pos, component.width_striderust-analyzer cargo zune-jpeg 0.5.15 components/Components#width_stride.);
589 } else {
590 // call idct.
591 (self.idct_funcrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#idct_func.)(tmp, idct_pos, component.width_striderust-analyzer cargo zune-jpeg 0.5.15 components/Components#width_stride.);
592 }
593 }
594 }
595 }
596 }
597
598 self.todorust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#todo. = self.todorust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#todo..wrapping_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]wrapping_sub().(1);
599
600 if self.todorust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#todo. 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().0 {
601 self.handle_rst_mainrust-analyzer cargo zune-jpeg 0.5.15 mcu_prog/impl#[`JpegDecoder<T>`]handle_rst_main().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
602 continue;
603 }
604
605 if stream.markerrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#marker..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && stream.bits_leftrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#bits_left. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 {
606 break;
607 }
608 }
609
610 self.check_stream_marker_after_mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]check_stream_marker_after_mcu_width().(stream)
611 }
612
613 fn check_stream_marker_after_mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]check_stream_marker_after_mcu_width().(
614 &mut self, stream: &mut BitStreamrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#
615 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#, DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
616 // After all interleaved components, that's an MCU
617 // handle stream markers
618 //
619 // In some corrupt images, it may occur that header markers occur in the stream.
620 // The spec EXPLICITLY FORBIDS this, specifically, in
621 // routine F.2.2.5 it says
622 // `The only valid marker which may occur within the Huffman coded data is the RSTm marker.`
623 //
624 // But libjpeg-turbo allows it because of some weird reason. so I'll also
625 // allow it because of some weird reason.
626 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(m) = stream.markerrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#marker. {
627 if m rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq().Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::EOIrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#EOI# {
628 // acknowledge and ignore EOI marker.
629 stream.markerrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#marker..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().();
630 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Found EOI marker");
631 // Google Introduced the Ultra-HD image format which is basically
632 // stitching two images into one container.
633 // They basically separate two images via a EOI and SOI marker
634 // so let's just ensure if we ever see EOI, we never read past that
635 // ever.
636 // https://github.com/google/libultrahdr
637 stream.seen_eoirust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#seen_eoi. = true;
638 } else if let Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::RSTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#RST#(_) = m {
639 //debug_assert_eq!(self.todo, 0);
640 if self.todorust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#todo. 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().0 {
641 self.handle_rstrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]handle_rst().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
642 }
643 } else if let Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOSrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOS# = m {
644 self.parse_marker_innerrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]parse_marker_inner().(m)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
645 stream.markerrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#marker..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().();
646 stream.resetrust-analyzer cargo zune-jpeg 0.5.15 bitstream/impl#[BitStream]reset().();
647 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Found SOS marker");
648 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::AnotherSosrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#AnotherSos#);
649 } else if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(m, Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DHTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DHT# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DQTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DQT# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DRIrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DRI# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::COMrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#COM#)
650 || matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(m, Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::APPrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#APP#(_))
651 {
652 // For non-interleaved images, setup markers can appear between scans.
653 // Signal the caller to handle this marker and find the next SOS.
654 // This keeps all marker parsing in the caller's loop.
655 stream.markerrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#marker..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().();
656 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Found inter-scan marker {:?}", m);
657 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::InterScanMarkerrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#InterScanMarker#(m));
658 } else {
659 if self.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().() {
660 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#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
661 "Marker {m:?} found where not expected"
662 )));
663 }
664 errorrust-analyzer cargo log 0.4.29 macros/error!!(
665 "Marker `{:?}` Found within Huffman Stream, possibly corrupt jpeg",
666 m
667 );
668
669 self.parse_marker_innerrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]parse_marker_inner().(m)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
670 stream.markerrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#marker..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().();
671 stream.resetrust-analyzer cargo zune-jpeg 0.5.15 bitstream/impl#[BitStream]reset().();
672 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::Terminaterust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#Terminate#);
673 }
674 }
675
676 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#::Okrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#Ok#)
677 }
678
679 /// Scan for the next SOS marker, parsing setup markers along the way.
680 ///
681 /// This is the unified marker scanning function used after encountering an
682 /// inter-scan marker. It handles DHT, DQT, DRI, COM, and APP markers that
683 /// can appear between scans in non-interleaved images.
684 ///
685 /// # Arguments
686 /// * `first_marker` - The first marker that was already detected (not yet parsed)
687 /// * `stream` - The bitstream state
688 ///
689 /// # Returns
690 /// * `Ok(true)` - Found SOS, ready to continue decoding
691 /// * `Ok(false)` - Found EOI, decoding complete
692 /// * `Err(_)` - Error (too many markers, unexpected marker in strict mode, etc.)
693 fn advance_to_next_sosrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]advance_to_next_sos().(
694 &mut self,
695 first_marker: Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#,
696 stream: &mut BitStreamrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#
697 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
698 // Limit iterations to prevent DoS from malicious files.
699 const MAX_INTER_SCAN_MARKERSrust-analyzer cargo zune-jpeg 0.5.15 mcu/MAX_INTER_SCAN_MARKERS.: usize = 64;
700
701 // Parse the first marker that triggered this call
702 self.parse_marker_innerrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]parse_marker_inner().(first_marker)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
703 stream.resetrust-analyzer cargo zune-jpeg 0.5.15 bitstream/impl#[BitStream]reset().();
704
705 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MAX_INTER_SCAN_MARKERSrust-analyzer cargo zune-jpeg 0.5.15 mcu/MAX_INTER_SCAN_MARKERS. {
706 let marker = get_markerrust-analyzer cargo zune-jpeg 0.5.15 mcu_prog/get_marker().(&mut self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream., stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
707
708 match marker {
709 Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOSrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOS# => {
710 self.parse_marker_innerrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]parse_marker_inner().(Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOSrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOS#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
711 stream.resetrust-analyzer cargo zune-jpeg 0.5.15 bitstream/impl#[BitStream]reset().();
712 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Found SOS marker, continuing decode");
713 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true);
714 }
715 Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::EOIrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#EOI# => {
716 stream.seen_eoirust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#seen_eoi. = true;
717 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Found EOI marker");
718 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false);
719 }
720 Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DHTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DHT# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DQTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DQT# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DRIrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DRI# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::COMrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#COM# => {
721 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Parsing inter-scan marker {:?}", marker);
722 self.parse_marker_innerrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]parse_marker_inner().(marker)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
723 }
724 Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::APPrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#APP#(_) => {
725 tracerust-analyzer cargo log 0.4.29 macros/trace!!("Parsing inter-scan APP marker {:?}", marker);
726 self.parse_marker_innerrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]parse_marker_inner().(marker)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
727 }
728 other => {
729 if self.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().() {
730 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#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
731 "Unexpected marker {:?} while scanning for SOS between scans",
732 other
733 )));
734 }
735 // Non-strict: skip unknown marker
736 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Skipping unexpected marker {:?} between scans", other);
737 let length = self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..get_u16_be_errrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]get_u16_be_err().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
738 if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]ge().2 {
739 self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..skiprust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]skip().((length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().2) as usize)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
740 }
741 }
742 }
743 }
744
745 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#::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#(
746 "Too many markers between scans (exceeded limit of 64)"
747 ))
748 }
749
750 // handle RST markers.
751 // No-op if not using restarts
752 // this routine is shared with mcu_prog
753 #[cold]
754 pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn handle_rstrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]handle_rst().(&mut self, stream: &mut BitStreamrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
755 self.todorust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#todo. = self.restart_intervalrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#restart_interval.;
756
757 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(marker) = stream.markerrust-analyzer cargo zune-jpeg 0.5.15 bitstream/BitStream#marker. {
758 // Found a marker
759 // Read stream and see what marker is stored there
760 match marker {
761 Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::RSTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#RST#(_) => {
762 // reset stream
763 stream.resetrust-analyzer cargo zune-jpeg 0.5.15 bitstream/impl#[BitStream]reset().();
764 // Initialize dc predictions to zero for all components
765 self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]for_each().(|x| x.dc_predrust-analyzer cargo zune-jpeg 0.5.15 components/Components#dc_pred. = 0);
766 // Start iterating again. from position.
767 }
768 Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::EOIrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#EOI# => {
769 // silent pass
770 }
771 // Valid markers that can appear between scans at a restart boundary
772 // (restart interval aligns with end of scan). Leave for caller.
773 Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOSrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOS# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DHTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DHT# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DQTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DQT# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DRIrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DRI# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::COMrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#COM#
774 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::APPrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#APP#(_) => {}
775 _ => {
776 if self.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().() {
777 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#::MCUErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#MCUError#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
778 "Unexpected marker {marker:?} at restart boundary"
779 )));
780 }
781 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Unexpected marker {:?} at restart boundary", marker);
782 }
783 }
784 }
785 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
786 }
787 #[allow(clippy::too_many_lines, clippy::too_many_arguments)]
788 pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn post_processrust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]post_process().(
789 &mut self, pixels: &mut [u8], i: usize, mcu_height: usize, width: usize,
790 padded_width: usize, pixels_written: &mut usize, upsampler_scratch_space: &mut [i16]
791 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
792 let out_colorspace_components = self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_colorspace().().num_componentsrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]num_components().();
793
794 let mut px = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().pixels_written;
795 // indicates whether image is vertically up-sampled
796 let is_vertically_sampled = self
797 .componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.
798 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
799 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|c| c.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio. rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::HVrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#HV# || c.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio. rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Vrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#V#);
800
801 let mut comp_len = self.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().();
802
803 // If we are moving from YCbCr -> Luma, we do not allocate storage for other components, so we
804 // will panic when we are trying to read samples, so for that case,
805 // hardcode it so that we don't panic when doing
806 // *samp = &samples[j][pos * padded_width..(pos + 1) * padded_width]
807 if out_colorspace_components 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().comp_len && self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_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().Lumarust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Luma# {
808 comp_len = out_colorspace_components;
809 }
810 let mut color_conv_function =
811 |num_iters: usize, samples: [&[i16]; 4]| -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> {
812 for (pos, output) in pixels[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().px..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().
813 .chunks_exact_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact_mut().(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().out_colorspace_components)
814 .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(num_iters)
815 .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().()
816 {
817 let mut raw_samples: [&[i16]; 4] = [&[], &[], &[], &[]];
818
819 // iterate over each line, since color-convert needs only
820 // one line
821 for (j, samp) in raw_samples.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(comp_len) {
822 let temp = &samples[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().j]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(pos 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().padded_width..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().1) 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().padded_width);
823 if temp.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
824 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#::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#("Missing samples"));
825 }
826 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().samp = temp.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
827 }
828 color_convertrust-analyzer cargo zune-jpeg 0.5.15 worker/color_convert().(
829 &raw_samples,
830 self.color_convert_16rust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#color_convert_16.,
831 self.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace.,
832 self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_colorspace().(),
833 output,
834 width,
835 padded_width
836 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
837 px 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().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().out_colorspace_components;
838 }
839 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
840 };
841
842 let comps = &mut self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().;
843
844 if self.is_interleavedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_interleaved. && self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_colorspace().() 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().ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::Lumarust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Luma# {
845 for comp in comps.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() {
846 upsamplerust-analyzer cargo zune-jpeg 0.5.15 worker/upsample().(
847 comp,
848 mcu_height,
849 i,
850 upsampler_scratch_space,
851 is_vertically_sampled
852 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
853 }
854
855 if is_vertically_sampled {
856 if i 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 {
857 // write the last line, it wasn't up-sampled as we didn't have row_down
858 // yet
859 let mut samples: [&[i16]; 4] = [&[], &[], &[], &[]];
860
861 for (samp, component) in samples.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(comps.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) {
862 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().samp = &component.first_row_upsample_destrust-analyzer cargo zune-jpeg 0.5.15 components/Components#first_row_upsample_dest.;
863 }
864
865 // ensure length matches for all samples
866 let _first_len = samples[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
867
868 // This was a good check, but can be caused to panic, esp on invalid/corrupt images.
869 // See one in issue https://github.com/etemesi254/zune-image/issues/262, so for now
870 // we just ignore and generate invalid images at the end.
871
872 //
873 //
874 // for samp in samples.iter().take(comp_len) {
875 // assert_eq!(first_len, samp.len());
876 // }
877 let num_iters = self.coeffrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#coeff. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max.;
878
879 color_conv_function(num_iters, samples)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
880 }
881
882 // After up-sampling the last row, save any row that can be used for
883 // a later up-sampling,
884 //
885 // E.g the Y sample is not sampled but we haven't finished upsampling the last row of
886 // the previous mcu, since we don't have the down row, so save it
887 for component in comps.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() {
888 if component.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio. 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().SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Hrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#H# {
889 // We don't care about H sampling factors, since it's copied in the workers function
890
891 // copy last row to be used for the next color conversion
892 let size = component.vertical_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#vertical_sample.
893 *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.width_striderust-analyzer cargo zune-jpeg 0.5.15 components/Components#width_stride.
894 *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.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio..samplerust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios]sample().();
895
896 let last_bytes =
897 component.raw_coeffrust-analyzer cargo zune-jpeg 0.5.15 components/Components#raw_coeff..rchunks_exact_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]rchunks_exact_mut().(size).nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`RChunksExactMut<'a, T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
898
899 component
900 .first_row_upsample_destrust-analyzer cargo zune-jpeg 0.5.15 components/Components#first_row_upsample_dest.
901 .copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(last_bytes);
902 }
903 }
904 }
905
906 let mut samples: [&[i16]; 4] = [&[], &[], &[], &[]];
907
908 for (samp, component) in samples.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(comps.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) {
909 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().samp = if component.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio. rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 components/impl#[SampleRatios][`PartialEq<Self>`]eq().SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Nonerust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#None# {
910 &component.raw_coeffrust-analyzer cargo zune-jpeg 0.5.15 components/Components#raw_coeff.
911 } else {
912 &component.upsample_destrust-analyzer cargo zune-jpeg 0.5.15 components/Components#upsample_dest.
913 };
914 }
915
916 // we either do 7 or 8 MCU's depending on the state, this only applies to
917 // vertically sampled images
918 //
919 // for rows up until the last MCU, we do not upsample the last stride of the MCU
920 // which means that the number of iterations should take that into account is one less the
921 // up-sampled size
922 //
923 // For the last MCU, we upsample the last stride, meaning that if we hit the last MCU, we
924 // should sample full raw coeffs
925 let is_last_considered = is_vertically_sampled && (i 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().mcu_height.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1));
926
927 let num_iters = (8 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().usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<bool>`]from().(is_last_considered)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.coeffrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#coeff. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max.;
928
929 color_conv_function(num_iters, samples)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
930 } else {
931 let mut channels_ref: [&[i16]; MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.] = [&[]; MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.];
932
933 self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.
934 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
935 .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().()
936 .for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(|(pos, x)| channels_ref[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut(). = &x.raw_coeffrust-analyzer cargo zune-jpeg 0.5.15 components/Components#raw_coeff.);
937
938 if let SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Genericrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#Generic#(_, v) = self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#sample_ratio. {
939 color_conv_function(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().v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.coeffrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#coeff., channels_ref)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
940 } else {
941 color_conv_function(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().self.coeffrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#coeff., channels_ref)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
942 }
943 }
944
945 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().pixels_written = px;
946 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
947 }
948 }
949
950 enum McuContinuationrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation# {
951 Okrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#Ok#,
952 AnotherSosrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#AnotherSos#,
953 /// Found an inter-scan marker (DHT/DQT/DRI/COM/APP) that needs handling.
954 /// The caller should parse it and scan for the next SOS.
955 InterScanMarkerrust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#InterScanMarker#(Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#),
956 Terminaterust-analyzer cargo zune-jpeg 0.5.15 mcu/McuContinuation#Terminate#
957 }