From 3e0b20be316b04aef51202ff7e4d12057e3d2efc Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 13:20:43 -0500 Subject: [PATCH 1/2] Use shared PSD guides resource decoder Retain PhotoCraft guide colour and resource retention policy. Shared implementation extracted from Bram Heerink original f49564d281bf8892db58ed154767717223aff4f6. --- Cargo.lock | 28 ++++++++++++++++------- crates/io/Cargo.toml | 1 + crates/io/src/guides_map.rs | 45 ++++--------------------------------- 3 files changed, 25 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3935c94a4..f7885c1078 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1628,6 +1628,17 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-psd" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=6d590ce432d9ae725590df72428aeb47256a01fd#6d590ce432d9ae725590df72428aeb47256a01fd" +dependencies = [ + "encoding_rs", + "flate2", + "rayon", + "thiserror 2.0.21", +] + [[package]] name = "craft-raw" version = "0.1.0" @@ -5527,7 +5538,7 @@ dependencies = [ "craft-ai-agents", "craft-flags", "craft-image-codecs", - "craft-psd", + "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=09188c3bbfa443b089a3e022fad6abd7b464efda)", "getrandom 0.3.4", "hmac", "photocraft-color", @@ -5561,7 +5572,7 @@ dependencies = [ "clap_mangen", "craft-cms", "craft-image-codecs", - "craft-psd", + "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=09188c3bbfa443b089a3e022fad6abd7b464efda)", "photocraft-automation", "photocraft-doc", "photocraft-engine", @@ -5626,7 +5637,7 @@ dependencies = [ "craft-image-codecs", "craft-pcraft-format 0.1.0 (git+https://github.com/storytold/craft-libs?rev=3e970577b9bb446967c2003ec8ecaf4f28b0768c)", "craft-print", - "craft-psd", + "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=09188c3bbfa443b089a3e022fad6abd7b464efda)", "craft-xml", "exr", "flate2", @@ -5729,7 +5740,8 @@ dependencies = [ "craft-ora", "craft-pdf", "craft-pdn", - "craft-psd", + "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=09188c3bbfa443b089a3e022fad6abd7b464efda)", + "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=6d590ce432d9ae725590df72428aeb47256a01fd)", "craft-svg", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ad8faa1c136ce289e9f132c9137d0cd913bd4ef6)", "craft-xcf", @@ -5859,9 +5871,9 @@ dependencies = [ name = "photocraft-text" version = "0.23.1" dependencies = [ - "craft-plist", "base64 0.23.1", - "craft-psd", + "craft-plist", + "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=09188c3bbfa443b089a3e022fad6abd7b464efda)", "flate2", "parley", "photocraft-color", @@ -5883,7 +5895,7 @@ dependencies = [ "craft-i18n", "craft-image-codecs", "craft-print", - "craft-psd", + "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=09188c3bbfa443b089a3e022fad6abd7b464efda)", "craft-ui", "craft-update", "eframe", @@ -5938,7 +5950,7 @@ name = "photocraft-web" version = "0.23.1" dependencies = [ "craft-image-codecs", - "craft-psd", + "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=09188c3bbfa443b089a3e022fad6abd7b464efda)", "eframe", "egui", "js-sys", diff --git a/crates/io/Cargo.toml b/crates/io/Cargo.toml index 7280fa576e..ddbe19abdd 100644 --- a/crates/io/Cargo.toml +++ b/crates/io/Cargo.toml @@ -29,6 +29,7 @@ photocraft-doc = { workspace = true } photocraft-compose = { workspace = true } photocraft-algo = { workspace = true } craft-psd = { workspace = true } +craft-psd-guides = { package = "craft-psd", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6d590ce432d9ae725590df72428aeb47256a01fd" } photocraft-codecs = { workspace = true } photocraft-formats = { workspace = true } photocraft-raw = { workspace = true } diff --git a/crates/io/src/guides_map.rs b/crates/io/src/guides_map.rs index 6137011e2c..78038da666 100644 --- a/crates/io/src/guides_map.rs +++ b/crates/io/src/guides_map.rs @@ -18,50 +18,13 @@ use photocraft_doc::{Document, Guides}; -/// Grid and Guides, version 2 (positions, directions and colours). -pub const GUIDES_V2: u16 = 1092; -/// One GUID per guide, in 1092's order. -pub const GUIDE_IDS: u16 = 1097; -/// Photoshop's default guide colour (Cyan, `#4affff`), which 1092 also stores for guides -/// that use the preference colour. +pub use craft_psd_guides::guides::{GUIDE_IDS, GUIDES_V2, GuideV2, ids_count}; +/// Photoshop's default colour continues to follow the app preference. pub const DEFAULT_GUIDE_RGB: [u8; 3] = [0x4a, 0xff, 0xff]; -/// One guide of a 1092 resource. -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub struct GuideV2 { - /// Position in 1/32 px. - pub location: i32, - pub vertical: bool, - pub rgb: [u8; 3], -} - -fn be_u32(data: &[u8], at: usize) -> Option { - let b = data.get(at..at.checked_add(4)?)?; - Some(u32::from_be_bytes([b[0], b[1], b[2], b[3]])) -} - -/// The guides of a 1092 resource, or `None` when it is not version 2 or is cut short. +/// Decode the shared wire representation; document matching remains app policy. pub fn parse_v2(data: &[u8]) -> Option> { - if be_u32(data, 0)? != 2 { - return None; - } - let count = usize::try_from(be_u32(data, 12)?).ok()?; - // Each guide takes 9 bytes: a count the data can't hold is not a 1092 we understand. - if count > data.len().saturating_sub(16) / 9 { - return None; - } - (0..count) - .map(|i| { - let at = 16 + i * 9; - let g = data.get(at..at + 9)?; - Some(GuideV2 { location: i32::from_be_bytes([g[0], g[1], g[2], g[3]]), vertical: g[4] != 1, rgb: [g[6], g[7], g[8]] }) - }) - .collect() -} - -/// The number of entries a 1097 resource declares. -pub fn ids_count(data: &[u8]) -> Option { - be_u32(data, 0) + craft_psd_guides::guides::parse_v2(data).map(Iterator::collect) } /// The document's guides as 1092 would store them, sorted. From c1fa809f74adc4f0b646289c2f048cfcf32f47a0 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 16:51:07 -0500 Subject: [PATCH 2/2] Pin shared PSD guides to its merged prerequisite --- Cargo.lock | 4 ++-- crates/io/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b99f7398b9..da2c948e15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1631,7 +1631,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6d590ce432d9ae725590df72428aeb47256a01fd#6d590ce432d9ae725590df72428aeb47256a01fd" +source = "git+https://github.com/storytold/craft-libs?rev=589842f0da5c5a11e71f39b70092dcb918b92f39#589842f0da5c5a11e71f39b70092dcb918b92f39" dependencies = [ "encoding_rs", "flate2", @@ -5741,7 +5741,7 @@ dependencies = [ "craft-pdf", "craft-pdn", "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=09188c3bbfa443b089a3e022fad6abd7b464efda)", - "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=6d590ce432d9ae725590df72428aeb47256a01fd)", + "craft-psd 0.1.0 (git+https://github.com/storytold/craft-libs?rev=589842f0da5c5a11e71f39b70092dcb918b92f39)", "craft-svg", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ad8faa1c136ce289e9f132c9137d0cd913bd4ef6)", "craft-xcf", diff --git a/crates/io/Cargo.toml b/crates/io/Cargo.toml index ddbe19abdd..1ed14763db 100644 --- a/crates/io/Cargo.toml +++ b/crates/io/Cargo.toml @@ -29,7 +29,7 @@ photocraft-doc = { workspace = true } photocraft-compose = { workspace = true } photocraft-algo = { workspace = true } craft-psd = { workspace = true } -craft-psd-guides = { package = "craft-psd", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6d590ce432d9ae725590df72428aeb47256a01fd" } +craft-psd-guides = { package = "craft-psd", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "589842f0da5c5a11e71f39b70092dcb918b92f39" } photocraft-codecs = { workspace = true } photocraft-formats = { workspace = true } photocraft-raw = { workspace = true }