@@ -89,7 +89,9 @@ pub fn resize(
8989 }
9090 }
9191 let mut dst = images:: Image :: new ( width, height, PixelType :: U8x4 ) ;
92- let options = ResizeOptions :: new ( ) . resize_alg ( filter. alg ( ) ) . use_alpha ( false ) ;
92+ let options = ResizeOptions :: new ( )
93+ . resize_alg ( filter. alg ( ) )
94+ . use_alpha ( false ) ;
9395 let mut resizer = Resizer :: new ( ) ;
9496 resizer
9597 . resize ( & src, & mut dst, & options)
@@ -297,7 +299,9 @@ fn luma(r: u8, g: u8, b: u8) -> u8 {
297299/// adjusts brightness by adding `amount` to each color channel.
298300pub fn brightness ( image : & Image , amount : i16 , limits : Limits ) -> Result < Image , Error > {
299301 if !( -255 ..=255 ) . contains ( & amount) {
300- return Err ( Error :: InvalidArgument ( "brightness must be -255..255" . into ( ) ) ) ;
302+ return Err ( Error :: InvalidArgument (
303+ "brightness must be -255..255" . into ( ) ,
304+ ) ) ;
301305 }
302306 map_channels ( image, limits, |v, _| {
303307 clamp_i16 ( i32:: from ( v) + i32:: from ( amount) )
@@ -421,8 +425,8 @@ pub fn gaussian_blur(image: &Image, sigma: f64, limits: Limits) -> Result<Image,
421425 for x in 0 ..w as usize {
422426 let mut acc = [ 0.0 ; 4 ] ;
423427 for ( k, weight) in weights. iter ( ) . enumerate ( ) {
424- let sy = ( y as i64 + k as i64 - i64:: from ( radius) )
425- . clamp ( 0 , i64 :: from ( h ) - 1 ) as usize ;
428+ let sy = ( y as i64 + k as i64 - i64:: from ( radius) ) . clamp ( 0 , i64 :: from ( h ) - 1 )
429+ as usize ;
426430 let offset = sy * w as usize * 4 + x * 4 ;
427431 for c in 0 ..4 {
428432 acc[ c] += f64:: from ( horizontal[ offset + c] ) * weight;
@@ -478,8 +482,13 @@ pub fn composite(
478482 require_rgba ( overlay) ?;
479483 validate_dimensions ( base. width ( ) , base. height ( ) , PixelFormat :: Rgba8 , limits)
480484 . map_err ( Error :: Limit ) ?;
481- validate_dimensions ( overlay. width ( ) , overlay. height ( ) , PixelFormat :: Rgba8 , limits)
482- . map_err ( Error :: Limit ) ?;
485+ validate_dimensions (
486+ overlay. width ( ) ,
487+ overlay. height ( ) ,
488+ PixelFormat :: Rgba8 ,
489+ limits,
490+ )
491+ . map_err ( Error :: Limit ) ?;
483492 let mut out = base. try_clone ( limits) . map_err ( Error :: Limit ) ?;
484493 let bw = base. width ( ) as i64 ;
485494 let bh = base. height ( ) as i64 ;
@@ -537,16 +546,16 @@ pub fn append(base: &Image, other: &Image, axis: Axis, limits: Limits) -> Result
537546 require_rgba ( other) ?;
538547 let ( width, height) = match axis {
539548 Axis :: Horizontal => (
540- base. width ( ) . checked_add ( other . width ( ) ) . ok_or_else ( || {
541- Error :: InvalidArgument ( "appended width overflows" . into ( ) )
542- } ) ?,
549+ base. width ( )
550+ . checked_add ( other . width ( ) )
551+ . ok_or_else ( || Error :: InvalidArgument ( "appended width overflows" . into ( ) ) ) ?,
543552 base. height ( ) . max ( other. height ( ) ) ,
544553 ) ,
545554 Axis :: Vertical => (
546555 base. width ( ) . max ( other. width ( ) ) ,
547- base. height ( ) . checked_add ( other . height ( ) ) . ok_or_else ( || {
548- Error :: InvalidArgument ( "appended height overflows" . into ( ) )
549- } ) ?,
556+ base. height ( )
557+ . checked_add ( other . height ( ) )
558+ . ok_or_else ( || Error :: InvalidArgument ( "appended height overflows" . into ( ) ) ) ?,
550559 ) ,
551560 } ;
552561 let mut out = empty_like ( width, height, limits) ?;
@@ -751,7 +760,7 @@ mod tests {
751760 img. as_bytes_mut ( ) [ ..4 ] . copy_from_slice ( & [ 255 , 0 , 0 , 0 ] ) ;
752761 img. as_bytes_mut ( ) [ 4 ..8 ] . copy_from_slice ( & [ 0 , 0 , 255 , 255 ] ) ;
753762 let out = gaussian_blur ( & img, 1.0 , Limits :: default ( ) ) . unwrap ( ) ;
754- for pixel in out. as_bytes ( ) . chunks_exact ( 4 ) {
763+ for pixel in out. as_bytes ( ) . as_chunks :: < 4 > ( ) . 0 {
755764 if pixel[ 3 ] > 0 {
756765 assert_eq ! ( pixel[ 0 ] , 0 ) ;
757766 assert ! ( pixel[ 2 ] > 0 ) ;
@@ -765,7 +774,7 @@ mod tests {
765774 img. as_bytes_mut ( ) [ ..4 ] . copy_from_slice ( & [ 255 , 0 , 0 , 0 ] ) ;
766775 img. as_bytes_mut ( ) [ 4 ..8 ] . copy_from_slice ( & [ 0 , 0 , 255 , 255 ] ) ;
767776 let out = resize ( & img, 8 , 1 , Filter :: Bilinear , Limits :: default ( ) ) . unwrap ( ) ;
768- for pixel in out. as_bytes ( ) . chunks_exact ( 4 ) {
777+ for pixel in out. as_bytes ( ) . as_chunks :: < 4 > ( ) . 0 {
769778 if pixel[ 3 ] > 0 {
770779 assert_eq ! ( pixel[ 0 ] , 0 ) ;
771780 assert ! ( pixel[ 2 ] > 0 ) ;
@@ -799,7 +808,10 @@ mod tests {
799808 fn composite_enforces_limits_for_both_images ( ) {
800809 let base = solid ( 2 , 2 , [ 0 , 0 , 0 , 255 ] ) ;
801810 let overlay = solid ( 1 , 1 , [ 0 , 0 , 0 , 255 ] ) ;
802- let limits = Limits { max_dimension : 1 , max_pixels : 1 } ;
811+ let limits = Limits {
812+ max_dimension : 1 ,
813+ max_pixels : 1 ,
814+ } ;
803815 assert ! ( composite( & base, & overlay, 0 , 0 , limits) . is_err( ) ) ;
804816 assert ! ( composite( & overlay, & base, 0 , 0 , limits) . is_err( ) ) ;
805817 }
@@ -817,7 +829,10 @@ mod tests {
817829 let base = solid ( 1 , 1 , [ 10 , 20 , 30 , 255 ] ) ;
818830 let overlay = solid ( 1 , 1 , [ 200 , 100 , 50 , 255 ] ) ;
819831 assert ! ( composite( & base, & overlay, i64 :: MAX , i64 :: MAX , Limits :: default ( ) ) . is_ok( ) ) ;
820- assert_eq ! ( composite( & base, & overlay, i64 :: MAX , 0 , Limits :: default ( ) ) . unwrap( ) , base) ;
832+ assert_eq ! (
833+ composite( & base, & overlay, i64 :: MAX , 0 , Limits :: default ( ) ) . unwrap( ) ,
834+ base
835+ ) ;
821836 }
822837
823838 #[ test]
0 commit comments