Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(io): gate flat export shortcut on active compositing properties (#122)

MikeeIac22c5ae1e02
diff --git a/crates/io/src/flat.rs b/crates/io/src/flat.rs
index b75929c7c..9eecad5b1 100644
--- a/crates/io/src/flat.rs
+++ b/crates/io/src/flat.rs
@@ -88,9 +88,12 @@ fn single_layer(doc: &Document) -> Option<&Surface> {
&& l.opacity >= 1.0
&& l.fill_opacity >= 1.0
&& l.mask.is_none()
+ && l.vector_mask.as_ref().is_none_or(|mask| !mask.enabled)
&& l.effects.items.is_empty()
&& l.effects.psd_raw.is_none()
- && matches!(l.blend, BlendMode::Normal | BlendMode::PassThrough);
+ && matches!(l.blend, BlendMode::Normal | BlendMode::PassThrough)
+ && photocraft_compose::channel_weights(l, doc.mode).is_none()
+ && !photocraft_compose::blend_if_active(l, doc.mode);
match (&l.content, ok) {
(LayerContent::Raster(s), true) if s.format() == doc.pixel_format() => Some(s),
_ => None,
diff --git a/crates/io/tests/banded.rs b/crates/io/tests/banded.rs
index cf0919c74..eb8e97d6b 100644
--- a/crates/io/tests/banded.rs
+++ b/crates/io/tests/banded.rs
@@ -61,6 +61,17 @@ fn single_layer_native_export_strips_opaque_alpha() {
let img = photocraft_codecs::decode(&r.bytes).unwrap();
assert_eq!(img.layout().has_alpha(), alpha < 1.0);
}
+
+ let mut d = layered(8, 4, SampleType::U16, 1.0);
+ d.layers.truncate(1);
+ // A fractional edge exercises coverage rather than merely cropping raw samples.
+ d.layers[0].vector_mask = Some(photocraft_doc::VectorMask::new(photocraft_vector::shapes::rect(0.0, 0.0, 4.5, 4.0)));
+ let r = export(&d, "x.png", &ExportOptions::default()).unwrap();
+ let img = photocraft_codecs::decode(&r.bytes).unwrap();
+ assert_eq!(img.sample_type(), photocraft_codecs::SampleType::U16);
+ assert!(img.layout().has_alpha());
+ let got: Vec<f32> = img.to_rgba_f32().iter().map(|v| (v * 65535.0).round()).collect();
+ assert_eq!(got, composite_q(&d, 65535.0), "active vector mask: pixels differ");
}
#[test]