@@ -369,7 +369,7 @@ fn optimize_png(
369
369
}
370
370
371
371
postprocess_chunks ( png, & opts, & raw . ihdr) ;
372
- recompress_frames ( png, & opts, deadline) ;
372
+ recompress_frames ( png, & opts, deadline) ? ;
373
373
374
374
let output = png. output ( ) ;
375
375
@@ -721,31 +721,30 @@ fn postprocess_chunks(png: &mut PngData, opts: &Options, orig_ihdr: &IhdrData) {
721
721
}
722
722
723
723
/// Recompress the additional frames of an APNG
724
- fn recompress_frames ( png : & mut PngData , opts : & Options , deadline : Arc < Deadline > ) {
724
+ fn recompress_frames ( png : & mut PngData , opts : & Options , deadline : Arc < Deadline > ) -> PngResult < ( ) > {
725
725
if !opts. idat_recoding || png. frames . is_empty ( ) {
726
- return ;
726
+ return Ok ( ( ) ) ;
727
727
}
728
728
// Use the same filter chosen for the main image
729
729
// No filter means we failed to optimise the main image and we shouldn't bother trying here
730
730
let Some ( filter) = png. filter else {
731
- return ;
731
+ return Ok ( ( ) ) ;
732
732
} ;
733
733
png. frames
734
734
. par_iter_mut ( )
735
735
. with_max_len ( 1 )
736
736
. enumerate ( )
737
- . for_each ( |( i, frame) | {
737
+ . try_for_each ( |( i, frame) | {
738
738
if deadline. passed ( ) {
739
- return ;
739
+ return Ok ( ( ) ) ;
740
740
}
741
741
let mut ihdr = png. raw . ihdr . clone ( ) ;
742
742
ihdr. width = frame. width ;
743
743
ihdr. height = frame. height ;
744
- if let Ok ( data) = PngImage :: new ( ihdr, & frame. data ) . and_then ( |image| {
745
- let filtered = image. filter_image ( filter, opts. optimize_alpha ) ;
746
- let max_size = AtomicMin :: new ( Some ( frame. data . len ( ) - 1 ) ) ;
747
- opts. deflate . deflate ( & filtered, & max_size)
748
- } ) {
744
+ let image = PngImage :: new ( ihdr, & frame. data ) ?;
745
+ let filtered = image. filter_image ( filter, opts. optimize_alpha ) ;
746
+ let max_size = AtomicMin :: new ( Some ( frame. data . len ( ) - 1 ) ) ;
747
+ if let Ok ( data) = opts. deflate . deflate ( & filtered, & max_size) {
749
748
debug ! (
750
749
"Recompressed fdAT #{:<2}: {} ({} bytes decrease)" ,
751
750
i,
@@ -754,7 +753,8 @@ fn recompress_frames(png: &mut PngData, opts: &Options, deadline: Arc<Deadline>)
754
753
) ;
755
754
frame. data = data;
756
755
}
757
- } ) ;
756
+ Ok ( ( ) )
757
+ } )
758
758
}
759
759
760
760
/// Check if an image was already optimized prior to oxipng's operations
0 commit comments