mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-19 16:45:28 +00:00
psd: share recovering section-divider framing
This commit is contained in:
1 parent
7edb6b154a
commit
d0693d9dcb
5 files changed
+64
-8
No files matched your search
Generated
+1
-1
@@ -1463,7 +1463,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-psd"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=e1fc4b1376148197c2cfd2381eeb400e2731269a#e1fc4b1376148197c2cfd2381eeb400e2731269a"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=8df7c0268ac112fd285d33688eb6819365391a80#8df7c0268ac112fd285d33688eb6819365391a80"
|
||||
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 = "e1fc4b1376148197c2cfd2381eeb400e2731269a" }
|
||||
craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8df7c0268ac112fd285d33688eb6819365391a80" }
|
||||
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" }
|
||||
|
||||
@@ -158,14 +158,16 @@ impl Psd {
|
||||
b"lyid" => l.id = Some(r.u32()?),
|
||||
b"iOpa" => l.fill_opacity = r.u8()?,
|
||||
b"lsct" | b"lsdk" => {
|
||||
l.section = match r.u32()? {
|
||||
1 => Section::OpenFolder,
|
||||
2 => Section::ClosedFolder,
|
||||
3 => Section::Divider,
|
||||
use craft_psd::tagged::{SectionDivider, SectionType};
|
||||
let divider = SectionDivider::from_bytes_recovering_blend(b).map_err(|e| error(&e))?;
|
||||
l.section = match divider.kind {
|
||||
SectionType::OpenFolder => Section::OpenFolder,
|
||||
SectionType::ClosedFolder => Section::ClosedFolder,
|
||||
SectionType::BoundingDivider => Section::Divider,
|
||||
_ => Section::Layer,
|
||||
};
|
||||
if b.len() >= 12 && &b[4..8] == b"8BIM" {
|
||||
l.blend.copy_from_slice(&b[8..12]);
|
||||
if let Some(blend) = divider.blend_mode {
|
||||
l.blend = blend.key();
|
||||
}
|
||||
}
|
||||
b"TySh" => {
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::pixels::srgb_encode;
|
||||
mod fixed_adjustments;
|
||||
mod integration;
|
||||
mod opt;
|
||||
mod section_divider;
|
||||
mod shared_corpus;
|
||||
mod unicode_name;
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
use super::*;
|
||||
|
||||
fn parse_section_blocks(blocks: Vec<([u8; 4], Vec<u8>)>) -> (Section, [u8; 4]) {
|
||||
let mut doc = WDoc::new(1, 1);
|
||||
doc.layers = vec![WLayer::empty("Section", blocks).with_blend(b"mul ")];
|
||||
let layer = Psd::parse(write(&doc)).unwrap().layers.remove(0);
|
||||
(layer.section, layer.blend)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn section_prefixes_and_invalid_optional_signatures_preserve_prior_state() {
|
||||
let full = [0, 0, 0, 2, b'8', b'B', b'I', b'M', b'z', b'z', b'z', b'z', 0, 0, 0, 7, 255];
|
||||
for key in [*b"lsct", *b"lsdk"] {
|
||||
for len in 0..=17 {
|
||||
let data = full[..len].to_vec();
|
||||
assert_eq!(
|
||||
parse_section_blocks(vec![(key, data.clone())]),
|
||||
(if len < 4 { Section::Layer } else { Section::ClosedFolder }, if len < 12 { *b"mul " } else { *b"zzzz" }),
|
||||
"{key:?} length {len}"
|
||||
);
|
||||
let previous = vec![0, 0, 0, 1, b'8', b'B', b'I', b'M', b's', b'c', b'r', b'n'];
|
||||
let other = if key == *b"lsct" { *b"lsdk" } else { *b"lsct" };
|
||||
assert_eq!(
|
||||
parse_section_blocks(vec![(other, previous), (key, data.clone())]),
|
||||
(if len < 4 { Section::OpenFolder } else { Section::ClosedFolder }, if len < 12 { *b"scrn" } else { *b"zzzz" }),
|
||||
);
|
||||
if len >= 12 {
|
||||
let mut bad = data;
|
||||
bad[4..8].copy_from_slice(b"nope");
|
||||
assert_eq!(parse_section_blocks(vec![(key, bad)]), (Section::ClosedFolder, *b"mul "));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn section_unknown_kinds_and_sequential_keys_keep_blend_until_replaced() {
|
||||
for kind in [0u32, 1, 2, 3, 99, u32::MAX] {
|
||||
let expected = match kind {
|
||||
1 => Section::OpenFolder,
|
||||
2 => Section::ClosedFolder,
|
||||
3 => Section::Divider,
|
||||
_ => Section::Layer,
|
||||
};
|
||||
for keys in [[*b"lsct", *b"lsdk"], [*b"lsdk", *b"lsct"]] {
|
||||
let previous = vec![0, 0, 0, 1, b'8', b'B', b'I', b'M', b'z', b'z', b'z', b'z'];
|
||||
let mut bad = kind.to_be_bytes().to_vec();
|
||||
bad.extend_from_slice(b"nopepass");
|
||||
bad.extend_from_slice(&7u32.to_be_bytes());
|
||||
assert_eq!(parse_section_blocks(vec![(keys[0], previous), (keys[1], bad)]), (expected, *b"zzzz"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user