@@ -57,7 +57,7 @@ impl<W: Write> BitWriter<W> {
5757 if self . nbits >= 64 {
5858 self . writer . write_all ( & self . buffer . to_le_bytes ( ) ) ?;
5959 self . nbits -= 64 ;
60- self . buffer = bits. checked_shr ( ( nbits - self . nbits ) as u32 ) . unwrap_or ( 0 ) ;
60+ self . buffer = bits. checked_shr ( u32 :: from ( nbits - self . nbits ) ) . unwrap_or ( 0 ) ;
6161 }
6262 debug_assert ! ( self . nbits < 64 ) ;
6363 Ok ( ( ) )
@@ -82,10 +82,10 @@ fn write_single_entry_huffman_tree<W: Write>(w: &mut BitWriter<W>, symbol: u8) -
8282 w. write_bits ( 1 , 2 ) ?;
8383 if symbol <= 1 {
8484 w. write_bits ( 0 , 1 ) ?;
85- w. write_bits ( symbol as u64 , 1 ) ?;
85+ w. write_bits ( u64:: from ( symbol ) , 1 ) ?;
8686 } else {
8787 w. write_bits ( 1 , 1 ) ?;
88- w. write_bits ( symbol as u64 , 8 ) ?;
88+ w. write_bits ( u64:: from ( symbol ) , 8 ) ?;
8989 }
9090 Ok ( ( ) )
9191}
@@ -188,7 +188,7 @@ fn build_huffman_tree(
188188 let mut len = length_limit;
189189 let mut indexes = frequencies. iter ( ) . copied ( ) . enumerate ( ) . collect :: < Vec < _ > > ( ) ;
190190 indexes. sort_unstable_by_key ( |& ( _, frequency) | frequency) ;
191- for & ( i, frequency) in indexes. iter ( ) {
191+ for & ( i, frequency) in & indexes {
192192 if frequency > 0 {
193193 while counts[ len as usize ] == 0 {
194194 len -= 1 ;
@@ -251,13 +251,13 @@ fn write_huffman_tree<W: Write>(
251251 w. write_bits ( 0 , 1 ) ?; // normal huffman tree
252252 w. write_bits ( 19 - 4 , 4 ) ?; // num_code_lengths - 4
253253
254- for & i in CODE_LENGTH_ORDER . iter ( ) {
254+ for i in CODE_LENGTH_ORDER {
255255 if i > 15 || code_length_frequencies[ i] == 0 {
256256 w. write_bits ( 0 , 3 ) ?;
257257 } else if single_code_length_length {
258258 w. write_bits ( 1 , 3 ) ?;
259259 } else {
260- w. write_bits ( code_length_lengths[ i] as u64 , 3 ) ?;
260+ w. write_bits ( u64 :: from ( code_length_lengths[ i] ) , 3 ) ?;
261261 }
262262 }
263263
@@ -275,7 +275,7 @@ fn write_huffman_tree<W: Write>(
275275 if !single_code_length_length {
276276 for & len in lengths. iter ( ) {
277277 w. write_bits (
278- code_length_codes[ len as usize ] as u64 ,
278+ u64 :: from ( code_length_codes[ len as usize ] ) ,
279279 code_length_lengths[ len as usize ] ,
280280 ) ?;
281281 }
@@ -284,7 +284,7 @@ fn write_huffman_tree<W: Write>(
284284 Ok ( ( ) )
285285}
286286
287- fn length_to_symbol ( len : u16 ) -> ( u16 , u8 ) {
287+ const fn length_to_symbol ( len : u16 ) -> ( u16 , u8 ) {
288288 let len = len - 1 ;
289289 let highest_bit = 15 - len. leading_zeros ( ) as u16 ; // TODO: use ilog2 once MSRV >= 1.67
290290 let second_highest_bit = ( len >> ( highest_bit - 1 ) ) & 1 ;
@@ -331,11 +331,11 @@ fn write_run<W: Write>(
331331 if run_length > 0 {
332332 if run_length <= 4 {
333333 let symbol = 256 + run_length - 1 ;
334- w. write_bits ( codes1[ symbol] as u64 , lengths1[ symbol] ) ?;
334+ w. write_bits ( u64 :: from ( codes1[ symbol] ) , lengths1[ symbol] ) ?;
335335 } else {
336336 let ( symbol, extra_bits) = length_to_symbol ( run_length as u16 ) ;
337337 w. write_bits (
338- codes1[ 256 + symbol as usize ] as u64 ,
338+ u64 :: from ( codes1[ 256 + symbol as usize ] ) ,
339339 lengths1[ 256 + symbol as usize ] ,
340340 ) ?;
341341 w. write_bits (
@@ -392,7 +392,7 @@ fn encode_frame<W: Write>(
392392 } ;
393393
394394 assert_eq ! (
395- ( width as u64 * height as u64 ) . saturating_mul( bytes_per_pixel) ,
395+ ( u64 :: from ( width) * u64 :: from ( height ) ) . saturating_mul( bytes_per_pixel) ,
396396 data. len( ) as u64
397397 ) ;
398398
@@ -401,10 +401,10 @@ fn encode_frame<W: Write>(
401401 }
402402
403403 w. write_bits ( 0x2f , 8 ) ?; // signature
404- w. write_bits ( width as u64 - 1 , 14 ) ?;
405- w. write_bits ( height as u64 - 1 , 14 ) ?;
404+ w. write_bits ( u64:: from ( width ) - 1 , 14 ) ?;
405+ w. write_bits ( u64:: from ( height ) - 1 , 14 ) ?;
406406
407- w. write_bits ( is_alpha as u64 , 1 ) ?; // alpha used
407+ w. write_bits ( u64:: from ( is_alpha ) , 1 ) ?; // alpha used
408408 w. write_bits ( 0x0 , 3 ) ?; // version
409409
410410 // subtract green transform
@@ -542,7 +542,7 @@ fn encode_frame<W: Write>(
542542 ColorType :: L8 => {
543543 while let Some ( pixel) = it. next ( ) {
544544 w. write_bits (
545- codes1[ pixel[ 1 ] as usize ] as u64 ,
545+ u64 :: from ( codes1[ pixel[ 1 ] as usize ] ) ,
546546 lengths1[ pixel[ 1 ] as usize ] ,
547547 ) ?;
548548 write_run ( w, pixel, & mut it, & codes1, & lengths1) ?;
@@ -553,8 +553,8 @@ fn encode_frame<W: Write>(
553553 let len1 = lengths1[ pixel[ 1 ] as usize ] ;
554554 let len3 = lengths3[ pixel[ 3 ] as usize ] ;
555555
556- let code =
557- codes1 [ pixel [ 1 ] as usize ] as u64 | ( codes3[ pixel[ 3 ] as usize ] as u64 ) << len1;
556+ let code = u64 :: from ( codes1 [ pixel [ 1 ] as usize ] )
557+ | ( u64 :: from ( codes3[ pixel[ 3 ] as usize ] ) << len1) ;
558558
559559 w. write_bits ( code, len1 + len3) ?;
560560 write_run ( w, pixel, & mut it, & codes1, & lengths1) ?;
@@ -566,9 +566,9 @@ fn encode_frame<W: Write>(
566566 let len0 = lengths0[ pixel[ 0 ] as usize ] ;
567567 let len2 = lengths2[ pixel[ 2 ] as usize ] ;
568568
569- let code = codes1[ pixel[ 1 ] as usize ] as u64
570- | ( codes0[ pixel[ 0 ] as usize ] as u64 ) << len1
571- | ( codes2[ pixel[ 2 ] as usize ] as u64 ) << ( len1 + len0) ;
569+ let code = u64 :: from ( codes1[ pixel[ 1 ] as usize ] )
570+ | ( u64 :: from ( codes0[ pixel[ 0 ] as usize ] ) << len1)
571+ | ( u64 :: from ( codes2[ pixel[ 2 ] as usize ] ) << ( len1 + len0) ) ;
572572
573573 w. write_bits ( code, len1 + len0 + len2) ?;
574574 write_run ( w, pixel, & mut it, & codes1, & lengths1) ?;
@@ -581,10 +581,10 @@ fn encode_frame<W: Write>(
581581 let len2 = lengths2[ pixel[ 2 ] as usize ] ;
582582 let len3 = lengths3[ pixel[ 3 ] as usize ] ;
583583
584- let code = codes1[ pixel[ 1 ] as usize ] as u64
585- | ( codes0[ pixel[ 0 ] as usize ] as u64 ) << len1
586- | ( codes2[ pixel[ 2 ] as usize ] as u64 ) << ( len1 + len0)
587- | ( codes3[ pixel[ 3 ] as usize ] as u64 ) << ( len1 + len0 + len2) ;
584+ let code = u64 :: from ( codes1[ pixel[ 1 ] as usize ] )
585+ | ( u64 :: from ( codes0[ pixel[ 0 ] as usize ] ) << len1)
586+ | ( u64 :: from ( codes2[ pixel[ 2 ] as usize ] ) << ( len1 + len0) )
587+ | ( u64 :: from ( codes3[ pixel[ 3 ] as usize ] ) << ( len1 + len0 + len2) ) ;
588588
589589 w. write_bits ( code, len1 + len0 + len2 + len3) ?;
590590 write_run ( w, pixel, & mut it, & codes1, & lengths1) ?;
@@ -596,7 +596,7 @@ fn encode_frame<W: Write>(
596596 Ok ( ( ) )
597597}
598598
599- fn chunk_size ( inner_bytes : usize ) -> u32 {
599+ const fn chunk_size ( inner_bytes : usize ) -> u32 {
600600 if inner_bytes % 2 == 1 {
601601 ( inner_bytes + 1 ) as u32 + 8
602602 } else {
@@ -809,7 +809,7 @@ mod tests {
809809 . encode ( & img[ ..256 * 256 * 3 ] , 256 , 256 , crate :: ColorType :: Rgb8 )
810810 . unwrap ( ) ;
811811 let decoded = webp:: Decoder :: new ( & output) . decode ( ) . unwrap ( ) ;
812- assert ! ( & img[ ..256 * 256 * 3 ] == & * decoded) ;
812+ assert_eq ! ( img[ ..256 * 256 * 3 ] , * decoded) ;
813813
814814 let mut output = Vec :: new ( ) ;
815815 let mut encoder = WebPEncoder :: new ( & mut output) ;
@@ -818,7 +818,7 @@ mod tests {
818818 . encode ( & img, 256 , 256 , crate :: ColorType :: Rgba8 )
819819 . unwrap ( ) ;
820820 let decoded = webp:: Decoder :: new ( & output) . decode ( ) . unwrap ( ) ;
821- assert ! ( & img == & * decoded) ;
821+ assert_eq ! ( img, * decoded) ;
822822
823823 let mut output = Vec :: new ( ) ;
824824 let mut encoder = WebPEncoder :: new ( & mut output) ;
@@ -828,7 +828,7 @@ mod tests {
828828 . encode ( & img, 256 , 256 , crate :: ColorType :: Rgba8 )
829829 . unwrap ( ) ;
830830 let decoded = webp:: Decoder :: new ( & output) . decode ( ) . unwrap ( ) ;
831- assert ! ( & img == & * decoded) ;
831+ assert_eq ! ( img, * decoded) ;
832832
833833 let mut output = Vec :: new ( ) ;
834834 let mut encoder = WebPEncoder :: new ( & mut output) ;
@@ -838,18 +838,18 @@ mod tests {
838838 . encode ( & img, 256 , 256 , crate :: ColorType :: Rgba8 )
839839 . unwrap ( ) ;
840840 let decoded = webp:: Decoder :: new ( & output) . decode ( ) . unwrap ( ) ;
841- assert ! ( & img == & * decoded) ;
841+ assert_eq ! ( img, * decoded) ;
842842
843843 let mut output = Vec :: new ( ) ;
844844 let mut encoder = WebPEncoder :: new ( & mut output) ;
845- encoder. set_params ( params. clone ( ) ) ;
845+ encoder. set_params ( params) ;
846846 encoder. set_xmp_metadata ( vec ! [ 0 ; 7 ] ) ;
847847 encoder. set_icc_profile ( vec ! [ 0 ; 8 ] ) ;
848848 encoder. set_icc_profile ( vec ! [ 0 ; 9 ] ) ;
849849 encoder
850850 . encode ( & img, 256 , 256 , crate :: ColorType :: Rgba8 )
851851 . unwrap ( ) ;
852852 let decoded = webp:: Decoder :: new ( & output) . decode ( ) . unwrap ( ) ;
853- assert ! ( & img == & * decoded) ;
853+ assert_eq ! ( img, * decoded) ;
854854 }
855855}
0 commit comments