Merge pull request #15189 from storytold/refactor/shared-psd-guides

Use shared PSD guides resource decoding
This commit is contained in:
Dylan M. Taylor authored and GitHub committed 2026-11-15 20:21:08 -05:00
commit e76ca374e8
3 files changed
+24 -48

No files matched your search

Generated
+19 -7
View File
@@ -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=589842f0da5c5a11e71f39b70092dcb918b92f39#589842f0da5c5a11e71f39b70092dcb918b92f39"
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=589842f0da5c5a11e71f39b70092dcb918b92f39)",
"craft-svg",
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ad8faa1c136ce289e9f132c9137d0cd913bd4ef6)",
"craft-xcf",
@@ -5861,7 +5873,7 @@ version = "0.23.1"
dependencies = [
"base64 0.23.1",
"craft-plist",
"craft-psd",
"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",
+1
View File
@@ -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 = "589842f0da5c5a11e71f39b70092dcb918b92f39" }
photocraft-codecs = { workspace = true }
photocraft-formats = { workspace = true }
photocraft-raw = { workspace = true }
+4 -41
View File
@@ -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<u32> {
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<Vec<GuideV2>> {
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<u32> {
be_u32(data, 0)
craft_psd_guides::guides::parse_v2(data).map(Iterator::collect)
}
/// The document's guides as 1092 would store them, sorted.