@@ -4,7 +4,6 @@ use huffman::{HuffmanDecoder, HuffmanTable};
4
4
use marker:: Marker ;
5
5
use parser:: { AdobeColorTransform , AppData , CodingProcess , Component , Dimensions , EntropyCoding , FrameInfo ,
6
6
parse_app, parse_com, parse_dht, parse_dqt, parse_dri, parse_sof, parse_sos, ScanInfo } ;
7
- use rayon:: par_iter:: * ;
8
7
use upsampler:: Upsampler ;
9
8
use std:: cmp;
10
9
use std:: io:: Read ;
@@ -755,25 +754,58 @@ fn compute_image(components: &[Component],
755
754
Ok ( buffer)
756
755
}
757
756
else {
758
- let color_convert_func = try!( choose_color_convert_func ( components. len ( ) , is_jfif, color_transform) ) ;
759
- let upsampler = try!( Upsampler :: new ( components, output_size. width , output_size. height ) ) ;
760
- let line_size = output_size. width as usize * components. len ( ) ;
761
- let mut image = vec ! [ 0u8 ; line_size * output_size. height as usize ] ;
762
-
763
- image. chunks_mut ( line_size)
764
- . collect :: < Vec < & mut [ u8 ] > > ( )
765
- . par_iter_mut ( )
766
- . weight_max ( )
767
- . enumerate ( )
768
- . for_each ( |( row, line) | {
769
- upsampler. upsample_and_interleave_row ( data, row, output_size. width as usize , * line) ;
770
- color_convert_func ( * line, output_size. width as usize ) ;
771
- } ) ;
772
-
773
- Ok ( image)
757
+ compute_image_parallel ( components, data, output_size, is_jfif, color_transform)
774
758
}
775
759
}
776
760
761
+ #[ cfg( feature="rayon" ) ]
762
+ fn compute_image_parallel ( components : & [ Component ] ,
763
+ data : & [ Vec < u8 > ] ,
764
+ output_size : Dimensions ,
765
+ is_jfif : bool ,
766
+ color_transform : Option < AdobeColorTransform > ) -> Result < Vec < u8 > > {
767
+ use rayon:: par_iter:: * ;
768
+
769
+ let color_convert_func = try!( choose_color_convert_func ( components. len ( ) , is_jfif, color_transform) ) ;
770
+ let upsampler = try!( Upsampler :: new ( components, output_size. width , output_size. height ) ) ;
771
+ let line_size = output_size. width as usize * components. len ( ) ;
772
+ let mut image = vec ! [ 0u8 ; line_size * output_size. height as usize ] ;
773
+
774
+ image. chunks_mut ( line_size)
775
+ . collect :: < Vec < & mut [ u8 ] > > ( )
776
+ . par_iter_mut ( )
777
+ . weight_max ( )
778
+ . enumerate ( )
779
+ . for_each ( |( row, line) | {
780
+ upsampler. upsample_and_interleave_row ( data, row, output_size. width as usize , * line) ;
781
+ color_convert_func ( * line, output_size. width as usize ) ;
782
+ } ) ;
783
+
784
+ Ok ( image)
785
+ }
786
+
787
+ #[ cfg( not( feature="rayon" ) ) ]
788
+ fn compute_image_parallel ( components : & [ Component ] ,
789
+ data : & [ Vec < u8 > ] ,
790
+ output_size : Dimensions ,
791
+ is_jfif : bool ,
792
+ color_transform : Option < AdobeColorTransform > ) -> Result < Vec < u8 > > {
793
+ let color_convert_func = try!( choose_color_convert_func ( components. len ( ) , is_jfif, color_transform) ) ;
794
+ let upsampler = try!( Upsampler :: new ( components, output_size. width , output_size. height ) ) ;
795
+ let line_size = output_size. width as usize * components. len ( ) ;
796
+ let mut image = vec ! [ 0u8 ; line_size * output_size. height as usize ] ;
797
+
798
+ for ( row, line) in image. chunks_mut ( line_size)
799
+ . collect :: < Vec < & mut [ u8 ] > > ( )
800
+ . iter_mut ( )
801
+ . enumerate ( ) {
802
+ upsampler. upsample_and_interleave_row ( data, row, output_size. width as usize , * line) ;
803
+ color_convert_func ( * line, output_size. width as usize ) ;
804
+ }
805
+
806
+ Ok ( image)
807
+ }
808
+
777
809
fn choose_color_convert_func ( component_count : usize ,
778
810
_is_jfif : bool ,
779
811
color_transform : Option < AdobeColorTransform > )
0 commit comments