@@ -128,12 +128,12 @@ impl<R: Read> Decoder<R> {
128
128
}
129
129
130
130
/// Configure the decoder to scale the image during decoding.
131
- ///
131
+ ///
132
132
/// This efficiently scales the image by the smallest supported scale
133
133
/// factor that produces an image larger than or equal to the requested
134
134
/// size in at least one axis. The currently implemented scale factors
135
135
/// are 1/8, 1/4, 1/2 and 1.
136
- ///
136
+ ///
137
137
/// To generate a thumbnail of an exact size, pass the desired size and
138
138
/// then scale to the final size using a traditional resampling algorithm.
139
139
pub fn scale ( & mut self , requested_width : u16 , requested_height : u16 ) -> Result < ( u16 , u16 ) > {
@@ -155,7 +155,7 @@ impl<R: Read> Decoder<R> {
155
155
return Ok ( Vec :: new ( ) ) ;
156
156
}
157
157
else if self . frame . is_none ( ) && ( self . reader . read_u8 ( ) ? != 0xFF || Marker :: from_u8 ( self . reader . read_u8 ( ) ?) != Some ( Marker :: SOI ) ) {
158
- return Err ( Error :: Format ( "first two bytes is not a SOI marker" . to_owned ( ) ) ) ;
158
+ return Err ( Error :: Format ( "first two bytes are not an SOI marker" . to_owned ( ) ) ) ;
159
159
}
160
160
161
161
let mut previous_marker = Marker :: SOI ;
@@ -399,7 +399,7 @@ impl<R: Read> Decoder<R> {
399
399
while byte == 0xFF {
400
400
byte = self . reader . read_u8 ( ) ?;
401
401
}
402
-
402
+
403
403
if byte != 0x00 && byte != 0xFF {
404
404
return Ok ( Marker :: from_u8 ( byte) . unwrap ( ) ) ;
405
405
}
@@ -613,14 +613,11 @@ fn decode_block<R: Read>(reader: &mut R,
613
613
let value = huffman. decode ( reader, dc_table. unwrap ( ) ) ?;
614
614
let diff = match value {
615
615
0 => 0 ,
616
+ 1 ..=11 => huffman. receive_extend ( reader, value) ?,
616
617
_ => {
617
618
// Section F.1.2.1.1
618
619
// Table F.1
619
- if value > 11 {
620
- return Err ( Error :: Format ( "invalid DC difference magnitude category" . to_owned ( ) ) ) ;
621
- }
622
-
623
- huffman. receive_extend ( reader, value) ?
620
+ return Err ( Error :: Format ( "invalid DC difference magnitude category" . to_owned ( ) ) ) ;
624
621
} ,
625
622
} ;
626
623
@@ -809,8 +806,8 @@ fn compute_image(components: &[Component],
809
806
output_size : Dimensions ,
810
807
is_jfif : bool ,
811
808
color_transform : Option < AdobeColorTransform > ) -> Result < Vec < u8 > > {
812
- if data. iter ( ) . any ( |data| data . is_empty ( ) ) {
813
- return Err ( Error :: Format ( "not all components has data" . to_owned ( ) ) ) ;
809
+ if data. iter ( ) . any ( Vec :: is_empty) {
810
+ return Err ( Error :: Format ( "not all components have data" . to_owned ( ) ) ) ;
814
811
}
815
812
816
813
if components. len ( ) == 1 {
@@ -908,7 +905,7 @@ fn choose_color_convert_func(component_count: usize,
908
905
match color_transform {
909
906
Some ( AdobeColorTransform :: Unknown ) => Ok ( color_convert_line_cmyk) ,
910
907
Some ( _) => Ok ( color_convert_line_ycck) ,
911
- None => Err ( Error :: Format ( "4 components without Adobe APP14 metadata to tell color space" . to_owned ( ) ) ) ,
908
+ None => Err ( Error :: Format ( "4 components without Adobe APP14 metadata to indicate color space" . to_owned ( ) ) ) ,
912
909
}
913
910
} ,
914
911
_ => panic ! ( ) ,
@@ -971,6 +968,5 @@ fn ycbcr_to_rgb(y: u8, cb: u8, cr: u8) -> (u8, u8, u8) {
971
968
972
969
fn clamp_to_u8 ( value : i32 ) -> i32 {
973
970
let value = std:: cmp:: max ( value, 0 ) ;
974
- let value = std:: cmp:: min ( value, 255 ) ;
975
- value
971
+ std:: cmp:: min ( value, 255 )
976
972
}
0 commit comments