1
- use alloc:: borrow:: ToOwned ;
2
- use alloc:: sync:: Arc ;
3
- use alloc:: vec:: Vec ;
4
- use alloc:: { format, vec} ;
5
- use core:: cmp;
6
- use core:: mem;
7
- use core:: ops:: Range ;
8
- use std:: convert:: TryInto ;
9
- use std:: io:: Read ;
10
- use crate :: read_u8;
11
1
use crate :: error:: { Error , Result , UnsupportedFeature } ;
12
2
use crate :: huffman:: { fill_default_mjpeg_tables, HuffmanDecoder , HuffmanTable } ;
13
3
use crate :: marker:: Marker ;
@@ -16,8 +6,18 @@ use crate::parser::{
16
6
AdobeColorTransform , AppData , CodingProcess , Component , Dimensions , EntropyCoding , FrameInfo ,
17
7
IccChunk , ScanInfo ,
18
8
} ;
9
+ use crate :: read_u8;
19
10
use crate :: upsampler:: Upsampler ;
20
- use crate :: worker:: { PreferWorkerKind , RowData , Worker , with_worker} ;
11
+ use crate :: worker:: { with_worker, PreferWorkerKind , RowData , Worker } ;
12
+ use alloc:: borrow:: ToOwned ;
13
+ use alloc:: sync:: Arc ;
14
+ use alloc:: vec:: Vec ;
15
+ use alloc:: { format, vec} ;
16
+ use core:: cmp;
17
+ use core:: mem;
18
+ use core:: ops:: Range ;
19
+ use std:: convert:: TryInto ;
20
+ use std:: io:: Read ;
21
21
22
22
pub const MAX_COMPONENTS : usize = 4 ;
23
23
@@ -202,7 +202,8 @@ impl<R: Read> Decoder<R> {
202
202
pub fn read_info ( & mut self ) -> Result < ( ) > {
203
203
with_worker ( PreferWorkerKind :: Multithreaded , |worker| {
204
204
self . decode_internal ( true , worker)
205
- } ) . map ( |_| ( ) )
205
+ } )
206
+ . map ( |_| ( ) )
206
207
}
207
208
208
209
/// Configure the decoder to scale the image during decoding.
@@ -395,8 +396,7 @@ impl<R: Read> Decoder<R> {
395
396
}
396
397
}
397
398
398
- let ( marker, data) =
399
- self . decode_scan ( & frame, & scan, worker, & finished) ?;
399
+ let ( marker, data) = self . decode_scan ( & frame, & scan, worker, & finished) ?;
400
400
401
401
if let Some ( data) = data {
402
402
for ( i, plane) in data
@@ -542,12 +542,16 @@ impl<R: Read> Decoder<R> {
542
542
let frame = self . frame . as_ref ( ) . unwrap ( ) ;
543
543
544
544
if {
545
- let required_mem = frame. components . len ( )
545
+ let required_mem = frame
546
+ . components
547
+ . len ( )
546
548
. checked_mul ( frame. output_size . width . into ( ) )
547
549
. and_then ( |m| m. checked_mul ( frame. output_size . height . into ( ) ) ) ;
548
550
required_mem. map_or ( true , |m| self . decoding_buffer_size_limit < m)
549
551
} {
550
- return Err ( Error :: Format ( "size of decoded image exceeds maximum allowed size" . to_owned ( ) ) ) ;
552
+ return Err ( Error :: Format (
553
+ "size of decoded image exceeds maximum allowed size" . to_owned ( ) ,
554
+ ) ) ;
551
555
}
552
556
553
557
// If we're decoding a progressive jpeg and a component is unfinished, render what we've got
@@ -579,12 +583,12 @@ impl<R: Read> Decoder<R> {
579
583
* usize:: from ( component. vertical_sampling_factor )
580
584
* 64 ;
581
585
582
- let mut tasks = ( 0 ..frame. mcu_size . height )
583
- . map ( | mcu_y| {
584
- let offset = usize :: from ( mcu_y ) * coefficients_per_mcu_row ;
585
- let row_coefficients = self . coefficients [ i] [ offset..offset + coefficients_per_mcu_row] . to_vec ( ) ;
586
- ( i, row_coefficients)
587
- } ) ;
586
+ let mut tasks = ( 0 ..frame. mcu_size . height ) . map ( |mcu_y| {
587
+ let offset = usize :: from ( mcu_y) * coefficients_per_mcu_row ;
588
+ let row_coefficients =
589
+ self . coefficients [ i] [ offset..offset + coefficients_per_mcu_row] . to_vec ( ) ;
590
+ ( i, row_coefficients)
591
+ } ) ;
588
592
589
593
// FIXME: additional potential work stealing opportunities for rayon case if we
590
594
// also internally can parallelize over components.
@@ -825,7 +829,9 @@ impl<R: Read> Decoder<R> {
825
829
& mut mcu_row_coefficients[ i] [ block_offset..block_offset + 64 ]
826
830
} else {
827
831
& mut dummy_block[ ..64 ]
828
- } . try_into ( ) . unwrap ( ) ;
832
+ }
833
+ . try_into ( )
834
+ . unwrap ( ) ;
829
835
830
836
if scan. successive_approximation_high == 0 {
831
837
decode_block (
@@ -1174,7 +1180,10 @@ fn compute_image(
1174
1180
}
1175
1181
}
1176
1182
1177
- #[ cfg( feature = "rayon" ) ]
1183
+ #[ cfg( all(
1184
+ not( any( target_arch = "asmjs" , target_arch = "wasm32" ) ) ,
1185
+ feature = "rayon"
1186
+ ) ) ]
1178
1187
fn compute_image_parallel (
1179
1188
components : & [ Component ] ,
1180
1189
data : Vec < Vec < u8 > > ,
@@ -1206,7 +1215,10 @@ fn compute_image_parallel(
1206
1215
Ok ( image)
1207
1216
}
1208
1217
1209
- #[ cfg( not( feature = "rayon" ) ) ]
1218
+ #[ cfg( any(
1219
+ any( target_arch = "asmjs" , target_arch = "wasm32" ) ,
1220
+ not( feature = "rayon" )
1221
+ ) ) ]
1210
1222
fn compute_image_parallel (
1211
1223
components : & [ Component ] ,
1212
1224
data : Vec < Vec < u8 > > ,
@@ -1255,7 +1267,7 @@ fn choose_color_convert_func(
1255
1267
None => {
1256
1268
// Assume CMYK because no APP14 marker was found
1257
1269
Ok ( color_convert_line_cmyk)
1258
- } ,
1270
+ }
1259
1271
}
1260
1272
}
1261
1273
_ => panic ! ( ) ,
0 commit comments