1
1
use decoder:: { Decoder , MAX_COMPONENTS } ;
2
- use error:: { Error , Result , UnsupportedFeature } ;
3
- use huffman:: { fill_default_mjpeg_tables , HuffmanDecoder , HuffmanTable } ;
2
+ use error:: { Error , Result } ;
3
+ use huffman:: HuffmanDecoder ;
4
4
use marker:: Marker ;
5
5
use parser:: Predictor ;
6
6
use parser:: {
7
- parse_app, parse_com, parse_dht, parse_dqt, parse_dri, parse_sof, parse_sos,
8
- AdobeColorTransform , AppData , CodingProcess , Component , Dimensions , EntropyCoding , FrameInfo ,
9
- IccChunk , ScanInfo ,
7
+ Component , FrameInfo ,
8
+ ScanInfo ,
10
9
} ;
11
10
use std:: io:: Read ;
12
11
@@ -20,8 +19,8 @@ impl<R: Read> Decoder<R> {
20
19
let ncomp = scan. component_indices . len ( ) ;
21
20
let npixel = frame. image_size . height as usize * frame. image_size . width as usize ;
22
21
assert ! ( ncomp <= MAX_COMPONENTS ) ;
23
- let mut results = vec ! [ vec!( 0 ; npixel) ; ncomp] ;
24
-
22
+ let mut results = vec ! [ vec!( 0 , npixel) ; ncomp] ;
23
+
25
24
let components: Vec < Component > = scan
26
25
. component_indices
27
26
. iter ( )
@@ -49,10 +48,10 @@ impl<R: Read> Decoder<R> {
49
48
50
49
let width = frame. image_size . width as usize ;
51
50
let height = frame. image_size . height as usize ;
52
-
51
+
53
52
let mut differences = vec ! [ Vec :: with_capacity( npixel) ; ncomp] ;
54
- for mcu_y in 0 ..height {
55
- for mcu_x in 0 ..width {
53
+ for _mcu_y in 0 ..height {
54
+ for _mcu_x in 0 ..width {
56
55
if self . restart_interval > 0 {
57
56
if mcus_left_until_restart == 0 {
58
57
match huffman. take_marker ( reader) ? {
@@ -139,14 +138,13 @@ impl<R: Read> Decoder<R> {
139
138
results[ i] [ mcu_y * width + mcu_x] = result;
140
139
}
141
140
}
142
-
143
141
}
144
142
} else {
145
143
for mcu_y in 0 ..height {
146
144
for mcu_x in 0 ..width {
147
145
for ( i, _component) in components. iter ( ) . enumerate ( ) {
148
146
let diff = differences[ i] [ mcu_y * width + mcu_x] ;
149
-
147
+
150
148
// The following lines could be further optimized, e.g. moving the checks
151
149
// and updates of the previous values into the prediction function or
152
150
// iterating such that diagonals with mcu_x + mcu_y = const are computed at
@@ -155,7 +153,8 @@ impl<R: Read> Decoder<R> {
155
153
ra[ i] = results[ i] [ mcu_y * frame. image_size . width as usize + mcu_x - 1 ] ;
156
154
}
157
155
if mcu_y > 0 {
158
- rb[ i] = results[ i] [ ( mcu_y - 1 ) * frame. image_size . width as usize + mcu_x] ;
156
+ rb[ i] =
157
+ results[ i] [ ( mcu_y - 1 ) * frame. image_size . width as usize + mcu_x] ;
159
158
if mcu_x > 0 {
160
159
rc[ i] = results[ i]
161
160
[ ( mcu_y - 1 ) * frame. image_size . width as usize + ( mcu_x - 1 ) ] ;
@@ -179,7 +178,6 @@ impl<R: Read> Decoder<R> {
179
178
}
180
179
}
181
180
}
182
-
183
181
184
182
let mut marker = huffman. take_marker ( & mut self . reader ) ?;
185
183
while let Some ( Marker :: RST ( _) ) = marker {
@@ -226,10 +224,7 @@ fn predict(
226
224
result
227
225
}
228
226
229
- pub fn compute_image_lossless (
230
- frame : & FrameInfo ,
231
- mut data : Vec < Vec < u16 > >
232
- ) -> Result < Vec < u8 > > {
227
+ pub fn compute_image_lossless ( frame : & FrameInfo , mut data : Vec < Vec < u16 > > ) -> Result < Vec < u8 > > {
233
228
if data. is_empty ( ) || data. iter ( ) . any ( Vec :: is_empty) {
234
229
return Err ( Error :: Format ( "not all components have data" . to_owned ( ) ) ) ;
235
230
}
@@ -241,10 +236,8 @@ pub fn compute_image_lossless(
241
236
let decoded = convert_to_u8 ( frame, data. remove ( 0 ) ) ;
242
237
Ok ( decoded)
243
238
} else {
244
- let mut decoded: Vec < u16 > = vec ! [
245
- 0u16 ;
246
- ncomp * output_size. width as usize * output_size. height as usize
247
- ] ;
239
+ let mut decoded: Vec < u16 > =
240
+ vec ! [ 0u16 ; ncomp * output_size. width as usize * output_size. height as usize ] ;
248
241
for ( x, chunk) in decoded. chunks_mut ( ncomp) . enumerate ( ) {
249
242
for ( i, ( component_data, _) ) in data. iter ( ) . zip ( components. iter ( ) ) . enumerate ( ) {
250
243
chunk[ i] = component_data[ x] ;
0 commit comments