Skip to content

Commit 8fed4c1

Browse files
committed
Error if fdAT invalid
1 parent 369ca2c commit 8fed4c1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/lib.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn optimize_png(
369369
}
370370

371371
postprocess_chunks(png, &opts, &raw.ihdr);
372-
recompress_frames(png, &opts, deadline);
372+
recompress_frames(png, &opts, deadline)?;
373373

374374
let output = png.output();
375375

@@ -721,31 +721,30 @@ fn postprocess_chunks(png: &mut PngData, opts: &Options, orig_ihdr: &IhdrData) {
721721
}
722722

723723
/// 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<()> {
725725
if !opts.idat_recoding || png.frames.is_empty() {
726-
return;
726+
return Ok(());
727727
}
728728
// Use the same filter chosen for the main image
729729
// No filter means we failed to optimise the main image and we shouldn't bother trying here
730730
let Some(filter) = png.filter else {
731-
return;
731+
return Ok(());
732732
};
733733
png.frames
734734
.par_iter_mut()
735735
.with_max_len(1)
736736
.enumerate()
737-
.for_each(|(i, frame)| {
737+
.map(|(i, frame)| {
738738
if deadline.passed() {
739-
return;
739+
return Ok(());
740740
}
741741
let mut ihdr = png.raw.ihdr.clone();
742742
ihdr.width = frame.width;
743743
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) {
749748
debug!(
750749
"Recompressed fdAT #{:<2}: {} ({} bytes decrease)",
751750
i,
@@ -754,7 +753,9 @@ fn recompress_frames(png: &mut PngData, opts: &Options, deadline: Arc<Deadline>)
754753
);
755754
frame.data = data;
756755
}
757-
});
756+
Ok(())
757+
})
758+
.collect()
758759
}
759760

760761
/// Check if an image was already optimized prior to oxipng's operations

0 commit comments

Comments
 (0)