mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-19 16:45:28 +00:00
fix(psd): surface unsupported modern placements at import boundary
This commit is contained in:
1 parent
cb3f66e06c
commit
49170cdf18
4 files changed
+60
-7
No files matched your search
Generated
+1
-1
@@ -1449,7 +1449,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-psd"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e9ec4813311264ee1857079c2edd10a70e2389a6#e9ec4813311264ee1857079c2edd10a70e2389a6"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c9862964df7f73ad37706539a06e346fc4865ca3#c9862964df7f73ad37706539a06e346fc4865ca3"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs"
|
||||
craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", default-features = false, features = ["read"] }
|
||||
craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e9ec4813311264ee1857079c2edd10a70e2389a6" }
|
||||
craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c9862964df7f73ad37706539a06e346fc4865ca3" }
|
||||
craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "77686f24fe8665c21369f1b593f4d65a973e2a45" }
|
||||
craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
|
||||
+10
-5
@@ -68,7 +68,7 @@ impl Psd {
|
||||
}
|
||||
if let Some(info) = &file.layer_info {
|
||||
psd.merged_alpha = info.merged_alpha;
|
||||
psd.layers = info.layers.iter().enumerate().map(|(i, rec)| psd.layer(rec, i, splice)).collect();
|
||||
psd.layers = info.layers.iter().enumerate().map(|(i, rec)| psd.layer(rec, i, splice)).collect::<Result<Vec<_>>>()?;
|
||||
}
|
||||
for b in &file.global_blocks {
|
||||
if let Some(stored) = b.stored.as_ref().filter(|_| linked(&b.key, 0)) {
|
||||
@@ -81,7 +81,7 @@ impl Psd {
|
||||
|
||||
/// One layer record of the model, its additional information read into [`Layer`].
|
||||
/// `splice` maps craft-psd's offsets back into `self.data` (see [`read_file`]).
|
||||
fn layer(&self, rec: &craft_psd::LayerRecord, index: usize, splice: Splice) -> Layer {
|
||||
fn layer(&self, rec: &craft_psd::LayerRecord, index: usize, splice: Splice) -> Result<Layer> {
|
||||
let channels = rec
|
||||
.channels
|
||||
.iter()
|
||||
@@ -111,10 +111,15 @@ impl Psd {
|
||||
}
|
||||
for b in &rec.blocks {
|
||||
l.keys.push(b.key);
|
||||
// A malformed block only loses that block's information.
|
||||
let _ = self.layer_block(&mut l, &b.key, &b.data);
|
||||
// A malformed optional block only loses that block's information.
|
||||
// Unsupported modern placement geometry must not silently become an
|
||||
// unwarped layer or fall back to a less expressive PlLd in either order.
|
||||
match self.layer_block(&mut l, &b.key, &b.data) {
|
||||
Err(e @ Error::Unsupported(_)) if matches!(&b.key, b"SoLd" | b"SoLE") => return Err(e),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
l
|
||||
Ok(l)
|
||||
}
|
||||
|
||||
/// The embedded bytes of linked file `uuid`.
|
||||
|
||||
@@ -92,3 +92,51 @@ fn a_tiny_file_claiming_a_huge_image_is_refused_within_the_budget() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_modern_placement_does_not_fall_back_to_legacy_in_either_order() {
|
||||
use craft_psd::descriptor::{Descriptor, Id, ObjectArray, UnicodeString, Value, VersionedDescriptor};
|
||||
let quad = [[0.0, 0.0], [20.0, 0.0], [20.0, 10.0], [0.0, 10.0]];
|
||||
let legacy = craft_psd::smart::SmartObject { uuid: "legacy".into(), quad, size: Some([20.0, 10.0]), warp: None }.to_placed_layer();
|
||||
let modern = |middle| {
|
||||
let floats = |values| Value::UnitFloats { unit: *b"#Pxl", values };
|
||||
let points = Descriptor::new("rationalPoint")
|
||||
.with("Hrzn", floats((0..4).flat_map(|_| (0..7).map(|i| i as f64 * 20.0 / 6.0)).collect()))
|
||||
.with("Vrtc", floats((0..4).flat_map(|j| [j as f64 * 10.0 / 3.0; 7]).collect()));
|
||||
let envelope = Descriptor::new("customEnvelopeWarp")
|
||||
.with("quiltSliceX", floats(vec![0.0, middle, 20.0]))
|
||||
.with("quiltSliceY", floats(vec![0.0, 10.0]))
|
||||
.with("meshPoints", Value::ObjectArray(ObjectArray { prefix: 28, body: points }));
|
||||
let warp = Descriptor::new("quiltWarp")
|
||||
.with("warpStyle", Value::Enumerated { type_id: Id::new("warpStyle"), value: Id::new("warpCustom") })
|
||||
.with("customEnvelopeWarp", Value::Descriptor(envelope));
|
||||
let descriptor = Descriptor::new("null")
|
||||
.with("Idnt", Value::Text(UnicodeString::new("modern")))
|
||||
.with("Trnf", Value::List(quad.iter().flatten().map(|v| Value::Double(*v)).collect()))
|
||||
.with("quiltWarp", Value::Descriptor(warp));
|
||||
let mut bytes = b"soLD".to_vec();
|
||||
bytes.extend_from_slice(&4u32.to_be_bytes());
|
||||
bytes.extend_from_slice(&VersionedDescriptor::new(descriptor).to_bytes());
|
||||
bytes
|
||||
};
|
||||
for key in [*b"SoLd", *b"SoLE"] {
|
||||
for legacy_first in [false, true] {
|
||||
for (bytes, expected) in [(modern(5.0), None), (modern(10.0), Some("modern")), (b"soLD".to_vec(), Some("legacy"))] {
|
||||
let mut blocks = vec![(key, bytes), (*b"PlLd", legacy.clone()), (*b"luni", vec![0])];
|
||||
if legacy_first {
|
||||
blocks.swap(0, 1);
|
||||
}
|
||||
let mut doc = WDoc::new(2, 2);
|
||||
doc.layers = vec![WLayer::empty("placement", blocks)];
|
||||
let result = Psd::parse(write(&doc));
|
||||
if let Some(uuid) = expected {
|
||||
let parsed = result.unwrap();
|
||||
assert_eq!(parsed.layers[0].smart_object.as_ref().unwrap().uuid, uuid);
|
||||
assert_eq!(parsed.layers[0].name, "placement", "malformed optional metadata still recovers");
|
||||
} else {
|
||||
assert!(matches!(result, Err(Error::Unsupported(_))), "unsupported modern placement must be reported");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user