PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(io): warn when the PSD channel limit drops Quick Mask (#115)
MikeeIe61bfa60eb39
diff --git a/crates/io/src/psd_export.rs b/crates/io/src/psd_export.rsindex 7cc4b7929..22c0b5318 100644--- a/crates/io/src/psd_export.rs+++ b/crates/io/src/psd_export.rs@@ -628,7 +628,11 @@ pub fn document_to_psd_with(doc: &Document, opts: &PsdExportOptions) -> (PsdFileextra.push(q);Some((cc + usize::from(has_alpha) + extra.len() - 1) as u16)}- _ => None,+ Some(_) => {+ ex.warnings.push("Quick Mask was dropped because the PSD channel limit was reached".into());+ None+ }+ None => None,};for a in &extra {let s = if a.surface.format() != ex.mask_fmt { a.surface.convert(ex.mask_fmt) } else { a.surface.clone() };diff --git a/crates/io/tests/channels.rs b/crates/io/tests/channels.rsindex 8214f90f8..9ee9c30d9 100644--- a/crates/io/tests/channels.rs+++ b/crates/io/tests/channels.rs@@ -41,4 +41,13 @@ fn channel_options_spot_and_quick_mask_roundtrip() {assert_eq!(f2.resources.iter().filter(|r| r.id == 1077).count(), 1);assert_eq!(f2.resources.iter().filter(|r| r.id == 1022).count(), 1);}++ let mut full = Document::with_background("full", Size::new(1, 1), ColorMode::Rgb, SampleType::U8, Color::WHITE);+ full.channels = (0..53).map(|i| AlphaChannel::new(format!("Alpha {i}"), Surface::new(PixelFormat::GRAY8))).collect();+ full.quick_mask = Some(AlphaChannel::new("Quick Mask", Surface::new(PixelFormat::GRAY8)));+ let out = photocraft_io::export(&full, "full.psd", &Default::default()).unwrap();+ assert!(out.warnings.iter().any(|warning| warning.contains("Quick Mask")), "{:?}", out.warnings);+ let file = photocraft_psd::PsdFile::from_bytes(&out.bytes).unwrap();+ assert_eq!(file.header.channels, 56);+ assert!(file.resources.iter().all(|resource| resource.id != 1022));}