From e61bfa60eb393444c2c6614971b10c8d86af7806 Mon Sep 17 00:00:00 2001 From: MikeeI Date: Mon, 5 Oct 2026 07:24:30 +0200 Subject: [PATCH] fix(io): warn when the PSD channel limit drops Quick Mask (#115) --- crates/io/src/psd_export.rs | 6 +++++- crates/io/tests/channels.rs | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/io/src/psd_export.rs b/crates/io/src/psd_export.rs index 7cc4b79298e..22c0b5318a1 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) -> (PsdFile extra.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.rs index 8214f90f806..9ee9c30d9af 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)); }