From ff4fbc294eff0232603f1b963f35df93f45b01c7 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 19 Nov 2026 18:55:31 +0100 Subject: [PATCH] Address CodeRabbit review: report Interlaced on palette PNG exports The palette PNG path wrote an Indexed Color document without interlacing and said nothing; the band-wise PNG path warns when it turns interlacing off. The palette path now adds the same kind of warning. Co-Authored-By: Claude Opus 5.5 --- crates/io/src/flat.rs | 3 +++ crates/io/tests/it/modes.rs | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/crates/io/src/flat.rs b/crates/io/src/flat.rs index c299a34908..b12104ab70 100644 --- a/crates/io/src/flat.rs +++ b/crates/io/src/flat.rs @@ -2396,6 +2396,9 @@ fn export_mode_specific(doc: &Document, format: Format, opts: &ExportOptions) -> let dpi = opts.encode.embed_metadata.then_some((doc.resolution_dpi, doc.resolution_dpi)); let bytes = codecs::encode_png_indexed(doc.size.width, doc.size.height, &idx, &table.colors, table.transparent, dpi, opts.encode.png_stereo)?; let mut warnings = vec![format!("written as an 8-bit palette PNG ({} colours)", table.colors.len())]; + if opts.encode.png_interlaced { + warnings.push("written without interlacing: the palette PNG exporter does not interlace".into()); + } if opts.encode.embed_metadata && opts.xmp == XmpEmbed::All && !doc.metadata.text.is_empty() { warnings.push("text metadata is not supported by the palette PNG exporter; it will be dropped".into()); } diff --git a/crates/io/tests/it/modes.rs b/crates/io/tests/it/modes.rs index b1bfff3d30..ad3ac65415 100644 --- a/crates/io/tests/it/modes.rs +++ b/crates/io/tests/it/modes.rs @@ -153,6 +153,20 @@ fn indexed_png_keeps_the_document_resolution() { assert!((back.resolution_dpi - 300.0).abs() < 0.01, "{}", back.resolution_dpi); } +#[test] +fn indexed_png_reports_that_it_is_not_interlaced() { + // Interlaced was dropped without a word for an Indexed Color document; the RGB path warns. + let mut d = doc(ColorMode::Indexed); + d.color_table = Some(ColorTable { colors: vec![[0, 0, 0], [255, 0, 0]], transparent: None }); + let mut opts = photocraft_io::ExportOptions::default(); + opts.encode.png_interlaced = true; + let r = photocraft_io::export(&d, "x.png", &opts).unwrap(); + assert_eq!((r.bytes[25], r.bytes[28]), (3, 0), "a palette PNG, not interlaced"); + assert!(r.warnings.iter().any(|w| w.contains("without interlacing")), "{:?}", r.warnings); + let plain = photocraft_io::export(&d, "x.png", &Default::default()).unwrap(); + assert!(!plain.warnings.iter().any(|w| w.contains("interlac")), "{:?}", plain.warnings); +} + #[test] fn indexed_bmp_is_palette_bmp() { // The BMP export wrote an Indexed Color document as 24-bit RGB, so reopening it lost the mode (#3869 follow-up).