mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
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 <[email protected]>
This commit is contained in:
1 parent
2667bd6f15
commit
ff4fbc294e
2 files changed
+17
No files matched your search
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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).
|
||||
|
||||
Reference in new issue
Block a user