mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
# Conflicts: # docs/file-format-parity.md
This commit is contained in:
commit
b1e408d28f
8 files changed
+2544
-17
No files matched your search
@@ -469,6 +469,67 @@ fn displace_psd_filter_renders_with_its_embedded_map() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A Perspective Warp smart filter as Photoshop writes it (`perspectiveWarpTransform`: vertices,
|
||||
/// warped vertices and quads of vertex indices, document pixels) opens as
|
||||
/// `layer.smartObjects.perspectiveWarp` and re-renders warped instead of flat (#6268), and keeps
|
||||
/// its planes through PSD export, `.pcraft` and a PSD re-import.
|
||||
#[test]
|
||||
fn perspective_warp_psd_filter_renders_warped() {
|
||||
use photocraft_psd::descriptor::{Descriptor, UnicodeString, Value};
|
||||
let pnts = |p: &[[f64; 2]]| {
|
||||
let px = |v: f64| Value::UnitFloat { unit: *b"#Pxl", value: v };
|
||||
Value::List(p.iter().map(|q| Value::Descriptor(Descriptor::new("Pnt ").with("Hrzn", px(q[0])).with("Vrtc", px(q[1])))).collect())
|
||||
};
|
||||
let quad = Descriptor::new("perspectiveWarpQuad").with("indices", Value::List((0..4).map(Value::Integer).collect()));
|
||||
let fltr = Descriptor::new("perspectiveWarpTransform")
|
||||
.with("vertices", pnts(&[[8.0, 6.0], [80.0, 6.0], [80.0, 58.0], [8.0, 58.0]]))
|
||||
// The right edge moves in and shrinks: the content no longer reaches x = 70.
|
||||
.with("warpedVertices", pnts(&[[8.0, 6.0], [50.0, 20.0], [50.0, 44.0], [8.0, 58.0]]))
|
||||
.with("quads", Value::List(vec![Value::Descriptor(quad)]));
|
||||
let item = Descriptor::new("filterFX")
|
||||
.with("Nm ", Value::Text(UnicodeString::new_nul("Perspective Warp...")))
|
||||
.with("enab", Value::Boolean(true))
|
||||
.with("hasoptions", Value::Boolean(true))
|
||||
.with("Fltr", Value::Descriptor(fltr))
|
||||
.with("filterID", Value::Integer(708));
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = session(depth);
|
||||
s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap();
|
||||
let id = photocraft_doc::LayerId(s.active().unwrap().active_layer.unwrap().0);
|
||||
let filter = photocraft_io::smart_map::filter_from_item(&item);
|
||||
assert_eq!(filter.command, "layer.smartObjects.perspectiveWarp");
|
||||
s.edit("perspective warp", |doc, _| {
|
||||
let mut l = doc.layer(id).unwrap().clone();
|
||||
let LayerContent::Smart(sm) = &mut l.content else { panic!("smart") };
|
||||
sm.smart_filters.push(filter.clone());
|
||||
assert!(refresh_layer(doc, &mut l).unwrap());
|
||||
*doc.layer_mut(id).unwrap() = l;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let doc = s.active().unwrap().doc.clone();
|
||||
let alpha = |doc: &Document, x: i32, y: i32| smart(doc).1.cache.unwrap().pixel(x, y)[3];
|
||||
assert!(alpha(&doc, 20, 30) > 0.99 && alpha(&doc, 70, 30) < 0.01 && alpha(&doc, 45, 10) < 0.01, "depth {depth}: warped");
|
||||
|
||||
let out = photocraft_io::export(&doc, "psd", &Default::default()).unwrap();
|
||||
assert!(out.warnings.is_empty(), "{:?}", out.warnings);
|
||||
assert_eq!(structure_errors(&out.bytes), Vec::<String>::new());
|
||||
keep(&format!("perspective-warp-{depth}.psd"), &out.bytes);
|
||||
let back = photocraft_io::import("perspective.psd", &out.bytes).unwrap().document;
|
||||
let native = photocraft_format::load_from_bytes(&photocraft_format::save_to_bytes(&back, &Default::default()).unwrap()).unwrap();
|
||||
for doc in [&back, &native] {
|
||||
let (bid, after) = smart(doc);
|
||||
assert_eq!(after.smart_filters, vec![filter.clone()], "depth {depth}");
|
||||
let mut l = doc.layer(photocraft_doc::LayerId(bid)).unwrap().clone();
|
||||
assert!(refresh_layer(doc, &mut l).unwrap());
|
||||
let LayerContent::Smart(sm) = &l.content else { panic!("smart") };
|
||||
let (a, b) = (sm.cache.as_ref().unwrap(), smart(&s.active().unwrap().doc).1.cache.unwrap());
|
||||
assert_eq!(a.pixel(20, 30), b.pixel(20, 30), "depth {depth}: re-render");
|
||||
assert_eq!(a.pixel(70, 30), b.pixel(70, 30), "depth {depth}: re-render");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A version-2 `liFD` item, as in Photoshop CS2's `lnkD` block: the fields every version has, and
|
||||
/// none of the version 5–7 fields after the file data.
|
||||
fn lifd_v2(f: &photocraft_io::linked::LinkedFile) -> Vec<u8> {
|
||||
@@ -670,3 +731,46 @@ fn a_soft_filter_mask_is_stored_the_way_photoshop_stores_it() {
|
||||
let d = max_diff(&photocraft_compose::flatten(&back).px, &photocraft_compose::flatten(&doc).px);
|
||||
assert!(d <= 2.0 / 255.0, "re-opened differs by {d}");
|
||||
}
|
||||
|
||||
/// Image › Adjustments › Hue/Saturation on a smart object is a smart filter that Photoshop saves
|
||||
/// as an `HStr` filter (#6267): it is written in that layout, opens as the same command and
|
||||
/// params, and re-renders adjusted instead of passing the source through.
|
||||
#[test]
|
||||
fn hue_saturation_smart_filter_survives_psd_and_re_renders() {
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = session(depth);
|
||||
s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap();
|
||||
let plain = smart(&s.active().unwrap().doc).1.cache.unwrap();
|
||||
let params = json!({"hue": 40, "saturation": -30, "lightness": 10, "colorize": false,
|
||||
"greens": {"hue": -20, "saturation": 15, "lightness": -5, "range": [75, 105, 135, 165]}});
|
||||
s.execute("image.adjustments.hueSaturation", params.clone()).unwrap();
|
||||
let doc = s.active().unwrap().doc.clone();
|
||||
let (_, before) = smart(&doc);
|
||||
assert_eq!(before.smart_filters.len(), 1);
|
||||
assert_eq!(before.smart_filters[0].command, "image.adjustments.hueSaturation");
|
||||
let adjusted = before.cache.clone().unwrap();
|
||||
assert!(plain.pixel(20, 20) != adjusted.pixel(20, 20), "depth {depth}: the filter changes pixels");
|
||||
|
||||
let out = photocraft_io::export(&doc, "psd", &Default::default()).unwrap();
|
||||
assert!(out.warnings.is_empty(), "{:?}", out.warnings);
|
||||
assert_eq!(structure_errors(&out.bytes), Vec::<String>::new());
|
||||
keep(&format!("hue-sat-{depth}.psd"), &out.bytes);
|
||||
let back = photocraft_io::import("hue-sat.psd", &out.bytes).unwrap().document;
|
||||
let (bid, after) = smart(&back);
|
||||
assert_eq!(after.smart_filters.len(), 1);
|
||||
let f = &after.smart_filters[0];
|
||||
assert_eq!(f.command, "image.adjustments.hueSaturation", "depth {depth}: {}", f.params);
|
||||
for (k, v) in params.as_object().unwrap() {
|
||||
assert_eq!(&f.params[k], v, "depth {depth}: {k}");
|
||||
}
|
||||
// Re-rendered from the source (as replaceContents / relink do), the filter still applies.
|
||||
let mut l = back.layer(photocraft_doc::LayerId(bid)).unwrap().clone();
|
||||
assert!(refresh_layer(&back, &mut l).unwrap());
|
||||
let LayerContent::Smart(sm) = &l.content else { panic!("smart") };
|
||||
let cache = sm.cache.as_ref().unwrap();
|
||||
for (x, y) in [(20, 20), (40, 30), (70, 50)] {
|
||||
let (a, b) = (cache.pixel(x, y), adjusted.pixel(x, y));
|
||||
assert!((0..4).all(|c| (a[c] - b[c]).abs() <= 1.0 / 255.0 + 1e-6), "depth {depth} at {x},{y}: {a:?} vs {b:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,8 +228,10 @@ fn parse_any(key: &[u8; 4], data: &[u8], cged: Option<&[u8]>) -> Adjustment {
|
||||
*r = HueRange { hue: h, saturation: s, lightness: l, bounds: HueRange::canonical_bounds([a, b, c, d]) };
|
||||
}
|
||||
}
|
||||
let hue = f32::from(bei16(data, base)?);
|
||||
Some(Adjustment::HueSaturation {
|
||||
hue: f32::from(bei16(data, base)?),
|
||||
// Photoshop stores the colorize hue signed (200 as -160); the model keeps 0..360.
|
||||
hue: if colorize { hue.rem_euclid(360.0) } else { hue },
|
||||
saturation: f32::from(bei16(data, base + 2)?),
|
||||
lightness: f32::from(bei16(data, base + 4)?),
|
||||
colorize,
|
||||
@@ -621,10 +623,16 @@ pub fn write(adj: &Adjustment) -> Vec<([u8; 4], Vec<u8>)> {
|
||||
put16(&mut v, 2);
|
||||
v.push(u8::from(*colorize));
|
||||
v.push(0);
|
||||
for _ in 0..2 {
|
||||
for x in [hue, saturation, lightness] {
|
||||
v.extend_from_slice(&clamp_i16(*x).to_be_bytes());
|
||||
}
|
||||
// The colorize triplet, then the master triplet. The inactive one gets Photoshop's
|
||||
// defaults; the colorize hue (0..360 in the model) is stored signed, -180..180.
|
||||
let (colorize_hsl, master) = if *colorize {
|
||||
let h = hue.rem_euclid(360.0);
|
||||
([if h > 180.0 { h - 360.0 } else { h }, *saturation, *lightness], [0.0; 3])
|
||||
} else {
|
||||
([30.0, 25.0, 0.0], [*hue, *saturation, *lightness])
|
||||
};
|
||||
for x in colorize_hsl.into_iter().chain(master) {
|
||||
v.extend_from_slice(&clamp_i16(x).to_be_bytes());
|
||||
}
|
||||
// Six hue ranges (reds, yellows, greens, cyans, blues, magentas): range values in
|
||||
// 0..360, then the range's hue, saturation and lightness.
|
||||
@@ -948,6 +956,21 @@ mod tests {
|
||||
assert_eq!(back, a);
|
||||
}
|
||||
|
||||
/// Photoshop keeps the colorize triplet at byte 4 and the master triplet at byte 10, and fills
|
||||
/// the inactive one with its defaults: colorize (30, 25, 0), master (0, 0, 0). The colorize hue
|
||||
/// is stored signed (200 -> -160).
|
||||
#[test]
|
||||
fn hue2_writes_each_triplet_in_its_own_slot() {
|
||||
let triplets = |a: &Adjustment| -> Vec<i16> {
|
||||
let blocks = write(a);
|
||||
(0..6).map(|i| bei16(&blocks[0].1, 4 + 2 * i).unwrap_or(i16::MIN)).collect()
|
||||
};
|
||||
let on = Adjustment::HueSaturation { hue: 200.0, saturation: 40.0, lightness: 10.0, colorize: true, ranges: HueRange::defaults() };
|
||||
assert_eq!(triplets(&on), [-160, 40, 10, 0, 0, 0]);
|
||||
let off = Adjustment::HueSaturation { hue: -30.0, saturation: 20.0, lightness: 5.0, colorize: false, ranges: HueRange::defaults() };
|
||||
assert_eq!(triplets(&off), [30, 25, 0, -30, 20, 5]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roundtrips() {
|
||||
rt(Adjustment::Invert);
|
||||
|
||||
@@ -0,0 +1,382 @@
|
||||
//! Hue/Saturation smart filters (`Fltr` class `HStr`, filterID `HStr` as a long), as Photoshop
|
||||
//! records Image › Adjustments › Hue/Saturation applied to a smart object:
|
||||
//!
|
||||
//! ```text
|
||||
//! Fltr = HStr { presetKind = presetKindType.presetKindCustom, Clrz = bool,
|
||||
//! Adjs = [ Hst2 { H , Strt, Lght } (master, first)
|
||||
//! Hst2 { LclR (1 reds … 6 magentas), BgnR, BgnS, EndS, EndR, (one per edited range)
|
||||
//! H , Strt, Lght } ] }
|
||||
//! ```
|
||||
//!
|
||||
//! Every number is a long: hue in degrees (a shift of -180..180, or 0..360 with Colorize), the
|
||||
//! rest in percent; the four range sliders are hue degrees (reds: 315, 345, 15, 45). The filter
|
||||
//! maps to `image.adjustments.hueSaturation` with the command's own params, so it re-renders
|
||||
//! when the smart object does. Anything else (an unknown key, a duplicated or unknown range, a
|
||||
//! value Photoshop's dialog can't hold) stays an opaque [`super::UNSUPPORTED_FILTER`].
|
||||
|
||||
use photocraft_doc::SmartFilter;
|
||||
use photocraft_doc::adjust::HueRange;
|
||||
use photocraft_psd::descriptor::{Descriptor, UnicodeString, Value};
|
||||
use serde_json::{Map, Value as J, json};
|
||||
|
||||
use super::{blend_options, enumv, is_meta, rgbc};
|
||||
use crate::blocks::num;
|
||||
|
||||
pub(super) const CLASS: &str = "HStr";
|
||||
pub(super) const COMMAND: &str = "image.adjustments.hueSaturation";
|
||||
const FILTER_ID: i32 = super::code(b"HStr");
|
||||
/// `Nm ` (Photoshop writes the localized menu item).
|
||||
const NAME: &str = "Hue/Saturation...";
|
||||
/// The `Fltr` descriptor's own name.
|
||||
const FLTR_NAME: &str = "Hue/Saturation";
|
||||
|
||||
/// The colour ranges in `LclR` order (1 = reds), as the command's param keys.
|
||||
const RANGES: [&str; 6] = ["reds", "yellows", "greens", "cyans", "blues", "magentas"];
|
||||
const BOUNDS: [&str; 4] = ["BgnR", "BgnS", "EndS", "EndR"];
|
||||
const SETTINGS: [(&str, &str); 3] = [("H ", "hue"), ("Strt", "saturation"), ("Lght", "lightness")];
|
||||
|
||||
/// A whole, finite number within `lo..=hi`, as JSON.
|
||||
fn whole(v: Option<&Value>, lo: f64, hi: f64) -> Option<J> {
|
||||
let v = num(v).filter(|v| v.is_finite() && v.fract() == 0.0 && (lo..=hi).contains(v))?;
|
||||
Some(json!(v as i64))
|
||||
}
|
||||
|
||||
/// `image.adjustments.hueSaturation` params for an `HStr` filter; `None` when any part of it is
|
||||
/// not the observed layout.
|
||||
pub(super) fn import_params(f: &Descriptor) -> Option<J> {
|
||||
if !f.class_id.is(CLASS) || f.items.iter().any(|(k, _)| !["presetKind", "Clrz", "Adjs"].iter().any(|n| k.is(n))) {
|
||||
return None;
|
||||
}
|
||||
let colorize = match f.get("Clrz") {
|
||||
Some(Value::Boolean(b)) => *b,
|
||||
None => false,
|
||||
Some(_) => return None,
|
||||
};
|
||||
let Some(Value::List(entries)) = f.get("Adjs") else { return None };
|
||||
// A master and six ranges at most.
|
||||
if entries.len() > 1 + RANGES.len() {
|
||||
return None;
|
||||
}
|
||||
let mut out = Map::new();
|
||||
out.insert("colorize".into(), J::Bool(colorize));
|
||||
let mut seen_master = false;
|
||||
for e in entries {
|
||||
let Value::Descriptor(e) = e else { return None };
|
||||
if e.items.iter().any(|(k, _)| !k.is("LclR") && !BOUNDS.iter().any(|n| k.is(n)) && !SETTINGS.iter().any(|(n, _)| k.is(n))) {
|
||||
return None;
|
||||
}
|
||||
let mut o = Map::new();
|
||||
match e.get("LclR") {
|
||||
None => {
|
||||
if std::mem::replace(&mut seen_master, true) {
|
||||
return None;
|
||||
}
|
||||
let (hue, sat) = if colorize { ((0.0, 360.0), (0.0, 100.0)) } else { ((-180.0, 180.0), (-100.0, 100.0)) };
|
||||
o.insert("hue".into(), whole(e.get("H "), hue.0, hue.1)?);
|
||||
o.insert("saturation".into(), whole(e.get("Strt"), sat.0, sat.1)?);
|
||||
o.insert("lightness".into(), whole(e.get("Lght"), -100.0, 100.0)?);
|
||||
out.extend(o);
|
||||
}
|
||||
r => {
|
||||
let i = whole(r, 1.0, RANGES.len() as f64)?.as_u64()?;
|
||||
let key = *RANGES.get(usize::try_from(i).ok()?.checked_sub(1)?)?;
|
||||
if out.contains_key(key) {
|
||||
return None;
|
||||
}
|
||||
o.insert("hue".into(), whole(e.get("H "), -180.0, 180.0)?);
|
||||
o.insert("saturation".into(), whole(e.get("Strt"), -100.0, 100.0)?);
|
||||
o.insert("lightness".into(), whole(e.get("Lght"), -100.0, 100.0)?);
|
||||
let bounds: Option<Vec<J>> = BOUNDS.iter().map(|k| whole(e.get(k), -720.0, 720.0)).collect();
|
||||
o.insert("range".into(), J::Array(bounds?));
|
||||
out.insert(key.into(), J::Object(o));
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(J::Object(out))
|
||||
}
|
||||
|
||||
/// A number param of `o` (`default` when absent), finite.
|
||||
fn number(o: &J, key: &str, default: f64) -> Result<f64, String> {
|
||||
match o.get(key) {
|
||||
None => Ok(default),
|
||||
Some(v) => v.as_f64().filter(|v| v.is_finite()).ok_or(format!("Hue/Saturation `{key}` must be a number")),
|
||||
}
|
||||
}
|
||||
|
||||
/// A number param rounded and clamped like the dialog's field, as a long.
|
||||
fn setting(o: &J, key: &str, default: f64, lo: f64, hi: f64) -> Result<Value, String> {
|
||||
Ok(long(number(o, key, default)?, lo, hi))
|
||||
}
|
||||
|
||||
fn long(v: f64, lo: f64, hi: f64) -> Value {
|
||||
Value::Integer(v.round().clamp(lo, hi) as i32)
|
||||
}
|
||||
|
||||
/// The `Adjs` entry of colour range `i` (0 = reds), or `None` when it is neutral with its default
|
||||
/// extent (Photoshop lists only the ranges that were edited).
|
||||
fn range_entry(i: usize, o: &J) -> Result<Option<Value>, String> {
|
||||
let obj = o.as_object().ok_or(format!("Hue/Saturation `{}` must be an object", RANGES.get(i).unwrap_or(&"")))?;
|
||||
if let Some(k) = obj.keys().find(|k| !["hue", "saturation", "lightness", "range"].contains(&k.as_str())) {
|
||||
return Err(format!("Hue/Saturation range setting `{k}` has no PSD equivalent"));
|
||||
}
|
||||
let neutral = HueRange::neutral(i);
|
||||
let bounds = match o.get("range") {
|
||||
None => neutral.bounds,
|
||||
Some(r) => {
|
||||
let a = r.as_array().filter(|a| a.len() == 4).ok_or("a Hue/Saturation range must be four hue degrees")?;
|
||||
let mut b = [0f32; 4];
|
||||
for (slot, v) in b.iter_mut().zip(a) {
|
||||
*slot = v.as_f64().filter(|v| v.is_finite()).ok_or("a Hue/Saturation range must be four hue degrees")? as f32;
|
||||
}
|
||||
HueRange::canonical_bounds(b)
|
||||
}
|
||||
};
|
||||
let hue = setting(o, "hue", 0.0, -180.0, 180.0)?;
|
||||
let sat = setting(o, "saturation", 0.0, -100.0, 100.0)?;
|
||||
let light = setting(o, "lightness", 0.0, -100.0, 100.0)?;
|
||||
let zero = Value::Integer(0);
|
||||
if [&hue, &sat, &light].iter().all(|v| **v == zero) && bounds == neutral.bounds {
|
||||
return Ok(None);
|
||||
}
|
||||
let lclr = i32::try_from(i + 1).map_err(|e| e.to_string())?;
|
||||
let mut d = Descriptor::new("Hst2").with("LclR", Value::Integer(lclr));
|
||||
for (k, v) in BOUNDS.iter().zip(bounds) {
|
||||
// Photoshop writes the sliders within one turn (reds: 315, 345, 15, 45).
|
||||
d = d.with(k, Value::Integer(f64::from(v).round().rem_euclid(360.0) as i32));
|
||||
}
|
||||
Ok(Some(Value::Descriptor(d.with("H ", hue).with("Strt", sat).with("Lght", light))))
|
||||
}
|
||||
|
||||
/// The `filterFXList` item for an `image.adjustments.hueSaturation` smart filter.
|
||||
pub(super) fn export_item(f: &SmartFilter) -> Result<Descriptor, String> {
|
||||
let p = &f.params;
|
||||
let obj = match p {
|
||||
J::Object(o) => o,
|
||||
J::Null => &Map::new(),
|
||||
_ => return Err("Hue/Saturation parameters must be an object".into()),
|
||||
};
|
||||
let known = |k: &str| ["hue", "saturation", "lightness", "colorize"].contains(&k) || RANGES.contains(&k);
|
||||
if let Some(k) = obj.keys().find(|k| !is_meta(k) && !known(k)) {
|
||||
return Err(format!("Hue/Saturation setting `{k}` has no PSD equivalent"));
|
||||
}
|
||||
let colorize = match p.get("colorize") {
|
||||
None => false,
|
||||
Some(v) => v.as_bool().ok_or("Hue/Saturation `colorize` must be true or false")?,
|
||||
};
|
||||
// As the command: Colorize hue is 0..360 and starts at 25 % saturation unless one is given.
|
||||
let master = if colorize {
|
||||
(long(number(p, "hue", 0.0)?.rem_euclid(360.0), 0.0, 360.0), setting(p, "saturation", 25.0, 0.0, 100.0)?)
|
||||
} else {
|
||||
(setting(p, "hue", 0.0, -180.0, 180.0)?, setting(p, "saturation", 0.0, -100.0, 100.0)?)
|
||||
};
|
||||
let mut adjs = vec![Value::Descriptor(
|
||||
Descriptor::new("Hst2").with("H ", master.0).with("Strt", master.1).with("Lght", setting(p, "lightness", 0.0, -100.0, 100.0)?),
|
||||
)];
|
||||
for (i, key) in RANGES.iter().enumerate() {
|
||||
if let Some(o) = p.get(*key) {
|
||||
adjs.extend(range_entry(i, o)?);
|
||||
}
|
||||
}
|
||||
let mut fltr = Descriptor::new(CLASS)
|
||||
.with("presetKind", enumv("presetKindType", "presetKindCustom"))
|
||||
.with("Clrz", Value::Boolean(colorize))
|
||||
.with("Adjs", Value::List(adjs));
|
||||
fltr.name = UnicodeString::new_nul(FLTR_NAME);
|
||||
Ok(Descriptor::new("filterFX")
|
||||
.with("Nm ", Value::Text(UnicodeString::new_nul(NAME)))
|
||||
.with("blendOptions", blend_options(f))
|
||||
.with("enab", Value::Boolean(f.visible))
|
||||
.with("hasoptions", Value::Boolean(true))
|
||||
.with("FrgC", rgbc(0.0))
|
||||
.with("BckC", rgbc(255.0))
|
||||
.with("Fltr", Value::Descriptor(fltr))
|
||||
.with("filterID", Value::Integer(FILTER_ID)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::smart_map::{UNSUPPORTED_FILTER, filter_from_item, item_for_filter};
|
||||
use photocraft_color::BlendMode;
|
||||
use photocraft_psd::descriptor::Id;
|
||||
|
||||
fn hst2(range: Option<(i32, [i32; 4])>, h: i32, s: i32, l: i32) -> Value {
|
||||
let mut d = Descriptor::new("Hst2");
|
||||
if let Some((r, b)) = range {
|
||||
d = d.with("LclR", Value::Integer(r));
|
||||
for (k, v) in BOUNDS.iter().zip(b) {
|
||||
d = d.with(k, Value::Integer(v));
|
||||
}
|
||||
}
|
||||
Value::Descriptor(d.with("H ", Value::Integer(h)).with("Strt", Value::Integer(s)).with("Lght", Value::Integer(l)))
|
||||
}
|
||||
|
||||
fn entry(items: &[(&str, Value)]) -> Value {
|
||||
Value::Descriptor(items.iter().fold(Descriptor::new("Hst2"), |d, (k, v)| d.with(k, v.clone())))
|
||||
}
|
||||
|
||||
fn fltr(colorize: bool, adjs: Vec<Value>) -> Descriptor {
|
||||
let mut f = Descriptor::new(CLASS)
|
||||
.with("presetKind", enumv("presetKindType", "presetKindCustom"))
|
||||
.with("Clrz", Value::Boolean(colorize))
|
||||
.with("Adjs", Value::List(adjs));
|
||||
f.name = UnicodeString::new_nul("Farbton/Sättigung");
|
||||
f
|
||||
}
|
||||
|
||||
/// A `filterFXList` item exactly as Photoshop saved it (German UI: localized names, the
|
||||
/// foreground colour of the moment in `FrgC`).
|
||||
fn item(f: Descriptor) -> Descriptor {
|
||||
let c = |r: f64, g: f64, b: f64| {
|
||||
Value::Descriptor(Descriptor::new("RGBC").with("Rd ", Value::Double(r)).with("Grn ", Value::Double(g)).with("Bl ", Value::Double(b)))
|
||||
};
|
||||
let neutral = SmartFilter { command: String::new(), params: J::Null, blend: BlendMode::Normal, opacity: 1.0, visible: true };
|
||||
Descriptor::new("filterFX")
|
||||
.with("Nm ", Value::Text(UnicodeString::new_nul("Farbton/Sättigung...")))
|
||||
.with("blendOptions", blend_options(&neutral))
|
||||
.with("enab", Value::Boolean(true))
|
||||
.with("hasoptions", Value::Boolean(true))
|
||||
.with("FrgC", c(167.0, 157.0, 147.0))
|
||||
.with("BckC", c(255.0, 255.0, 255.0))
|
||||
.with("Fltr", Value::Descriptor(f))
|
||||
.with("filterID", Value::Integer(FILTER_ID))
|
||||
}
|
||||
|
||||
/// Master 12 / -20 / 5 and Yellows -16 / 10 / -5 over 15, 45, 75, 105, Colorize off.
|
||||
fn observed() -> Descriptor {
|
||||
item(fltr(false, vec![hst2(None, 12, -20, 5), hst2(Some((2, [15, 45, 75, 105])), -16, 10, -5)]))
|
||||
}
|
||||
|
||||
fn fltr_of(d: &Descriptor) -> &Descriptor {
|
||||
match d.get("Fltr") {
|
||||
Some(Value::Descriptor(f)) => f,
|
||||
_ => panic!("no Fltr"),
|
||||
}
|
||||
}
|
||||
|
||||
fn filter(params: J) -> SmartFilter {
|
||||
SmartFilter { command: COMMAND.into(), params, blend: BlendMode::Normal, opacity: 1.0, visible: true }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_id_is_hstr() {
|
||||
assert_eq!(FILTER_ID, 1213428850);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn photoshop_items_map_to_the_command() {
|
||||
let f = filter_from_item(&observed());
|
||||
assert_eq!(f.command, COMMAND);
|
||||
assert_eq!(
|
||||
f.params,
|
||||
json!({"colorize": false, "hue": 12, "saturation": -20, "lightness": 5,
|
||||
"yellows": {"hue": -16, "saturation": 10, "lightness": -5, "range": [15, 45, 75, 105]}})
|
||||
);
|
||||
let c = filter_from_item(&item(fltr(true, vec![hst2(None, 200, 40, -10)])));
|
||||
assert_eq!(c.command, COMMAND);
|
||||
assert_eq!(c.params, json!({"colorize": true, "hue": 200, "saturation": 40, "lightness": -10}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_writes_photoshops_layout_and_round_trips() {
|
||||
let reds = item(fltr(false, vec![hst2(None, 0, 0, 0), hst2(Some((1, [315, 345, 15, 45])), 30, 0, 0)]));
|
||||
for src in [observed(), item(fltr(true, vec![hst2(None, 200, 40, -10)])), reds] {
|
||||
let f = filter_from_item(&src);
|
||||
let out = item_for_filter(&f).unwrap();
|
||||
let keys = |d: &Descriptor| d.items.iter().map(|(k, _)| k.clone()).collect::<Vec<Id>>();
|
||||
assert_eq!(keys(&out), keys(&src), "item key order");
|
||||
let (a, b) = (fltr_of(&out), fltr_of(&src));
|
||||
assert_eq!((&a.class_id, &a.items), (&b.class_id, &b.items), "Fltr as Photoshop writes it");
|
||||
assert_eq!(out.get("filterID"), Some(&Value::Integer(FILTER_ID)));
|
||||
assert_eq!(filter_from_item(&out), f);
|
||||
}
|
||||
// Blending and visibility are the model's own.
|
||||
let mut f = filter_from_item(&observed());
|
||||
(f.opacity, f.blend, f.visible) = (0.5, BlendMode::Screen, false);
|
||||
assert_eq!(filter_from_item(&item_for_filter(&f).unwrap()), f);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_params_are_written_like_the_dialog() {
|
||||
let export = |p: J| filter_from_item(&item_for_filter(&filter(p)).unwrap()).params;
|
||||
// Partial params: the command's defaults, numbers rounded and clamped.
|
||||
assert_eq!(export(json!({"hue": 12.4})), json!({"colorize": false, "hue": 12, "saturation": 0, "lightness": 0}));
|
||||
assert_eq!(export(json!({"hue": -400, "lightness": 101, "layer": 3})), json!({"colorize": false, "hue": -180, "saturation": 0, "lightness": 100}));
|
||||
assert_eq!(export(J::Null), json!({"colorize": false, "hue": 0, "saturation": 0, "lightness": 0}));
|
||||
// Colorize starts at 25 % saturation and wraps the hue into 0..360.
|
||||
assert_eq!(export(json!({"colorize": true, "hue": -30})), json!({"colorize": true, "hue": 330, "saturation": 25, "lightness": 0}));
|
||||
// The full set (`to_params`): neutral ranges at their default extent are left out, reds
|
||||
// are written within one turn.
|
||||
let mut full = json!({"hue": 0, "saturation": 0, "lightness": 0, "colorize": false});
|
||||
for (i, k) in RANGES.iter().enumerate() {
|
||||
let r = HueRange::neutral(i);
|
||||
full[*k] = json!({"hue": r.hue, "saturation": r.saturation, "lightness": r.lightness, "range": r.bounds});
|
||||
}
|
||||
full["reds"]["saturation"] = json!(-50.0);
|
||||
full["blues"]["range"] = json!([190, 220, 250, 280]);
|
||||
let back = export(full);
|
||||
assert_eq!(back["reds"], json!({"hue": 0, "saturation": -50, "lightness": 0, "range": [315, 345, 15, 45]}));
|
||||
assert_eq!(back["blues"], json!({"hue": 0, "saturation": 0, "lightness": 0, "range": [190, 220, 250, 280]}));
|
||||
assert_eq!(RANGES.iter().filter(|k| back.get(**k).is_some()).count(), 2, "{back}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unreadable_items_stay_opaque_and_are_written_back() {
|
||||
let zero = Value::Integer(0);
|
||||
let b4 = [0, 30, 60, 90];
|
||||
let cases = vec![
|
||||
fltr(false, vec![hst2(None, 1, 2, 3)]).with("Lab ", Value::Boolean(true)),
|
||||
fltr(false, vec![hst2(None, 1, 2, 3), hst2(None, 1, 2, 3)]),
|
||||
fltr(false, vec![hst2(None, 0, 0, 0), hst2(Some((2, b4)), 1, 0, 0), hst2(Some((2, b4)), 2, 0, 0)]),
|
||||
fltr(false, vec![hst2(Some((0, b4)), 1, 0, 0)]),
|
||||
fltr(false, vec![hst2(Some((7, b4)), 1, 0, 0)]),
|
||||
fltr(false, vec![hst2(Some((-1, b4)), 1, 0, 0)]),
|
||||
fltr(false, vec![hst2(None, 181, 0, 0)]),
|
||||
fltr(false, vec![hst2(None, 0, -101, 0)]),
|
||||
fltr(true, vec![hst2(None, -1, 0, 0)]),
|
||||
fltr(true, vec![hst2(None, 10, -5, 0)]),
|
||||
fltr(false, vec![hst2(Some((3, [0, 1, 2, 9999])), 1, 0, 0)]),
|
||||
fltr(false, vec![Value::Integer(4)]),
|
||||
fltr(false, vec![entry(&[("H ", zero.clone()), ("Strt", zero.clone()), ("Lght", zero.clone()), ("Clr ", zero.clone())])]),
|
||||
fltr(false, vec![entry(&[("H ", Value::Double(f64::NAN)), ("Strt", zero.clone()), ("Lght", zero.clone())])]),
|
||||
fltr(false, vec![entry(&[("H ", Value::Double(1.5)), ("Strt", zero.clone()), ("Lght", zero.clone())])]),
|
||||
fltr(false, vec![entry(&[("H ", Value::Boolean(true)), ("Strt", zero.clone()), ("Lght", zero.clone())])]),
|
||||
fltr(false, vec![entry(&[("Strt", zero.clone()), ("Lght", zero.clone())])]),
|
||||
fltr(false, vec![entry(&[("LclR", Value::Integer(1)), ("H ", zero.clone()), ("Strt", zero.clone()), ("Lght", zero.clone())])]),
|
||||
fltr(false, (0..8).map(|i| hst2(Some((i % 6 + 1, b4)), 0, 0, 0)).collect()),
|
||||
Descriptor::new(CLASS).with("Clrz", Value::Integer(1)).with("Adjs", Value::List(vec![hst2(None, 1, 2, 3)])),
|
||||
Descriptor::new(CLASS).with("Clrz", Value::Boolean(false)),
|
||||
Descriptor::new(CLASS).with("Adjs", Value::Integer(0)),
|
||||
];
|
||||
for (n, f) in cases.into_iter().enumerate() {
|
||||
let src = item(f);
|
||||
let sf = filter_from_item(&src);
|
||||
assert_eq!(sf.command, UNSUPPORTED_FILTER, "case {n}");
|
||||
assert_eq!(item_for_filter(&sf).unwrap().to_bytes(), src.to_bytes(), "case {n}");
|
||||
}
|
||||
// No `Fltr` at all.
|
||||
let mut bare = observed();
|
||||
bare.items.retain(|(k, _)| !k.is("Fltr"));
|
||||
assert_eq!(filter_from_item(&bare).command, UNSUPPORTED_FILTER);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_exports_report_errors() {
|
||||
for p in [
|
||||
json!(3),
|
||||
json!({"hue": "red"}),
|
||||
json!({"colorize": "yes"}),
|
||||
json!({"preset": "sepia"}),
|
||||
json!({"reds": 4}),
|
||||
json!({"reds": {"hue": "x"}}),
|
||||
json!({"reds": {"range": [1, 2, 3]}}),
|
||||
json!({"reds": {"range": [1, 2, 3, "x"]}}),
|
||||
json!({"reds": {"width": 2}}),
|
||||
] {
|
||||
assert!(item_for_filter(&filter(p.clone())).is_err(), "{p}");
|
||||
}
|
||||
// Huge numbers clamp rather than overflow.
|
||||
let out = filter_from_item(&item_for_filter(&filter(json!({"hue": f64::MAX, "colorize": true, "saturation": -1e300}))).unwrap());
|
||||
assert_eq!(out.command, COMMAND);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,446 @@
|
||||
//! Perspective Warp smart filters (`Fltr` class `perspectiveWarpTransform`).
|
||||
//!
|
||||
//! Layout as Photoshop writes it (checked by applying Edit › Perspective Warp to a smart object
|
||||
//! through the Action Manager and saving the PSD):
|
||||
//!
|
||||
//! ```text
|
||||
//! filterFX: Nm, blendOptions, enab, hasoptions (true), FrgC, BckC, filterID (1023 observed;
|
||||
//! other versions write other ids), Fltr = perspectiveWarpTransform {
|
||||
//! null = reference to the target layer,
|
||||
//! referenceRect = Rctn { Top, Left, Btom, Rght } (UntF #Pxl, the layer bounds),
|
||||
//! vertices = [ Pnt { Hrzn, Vrtc } (UntF #Pxl, document pixels) ], (Layout mode)
|
||||
//! warpedVertices = [ Pnt { Hrzn, Vrtc } ] (same count), (Warp mode)
|
||||
//! quads = [ perspectiveWarpQuad { indices = [4 × long] } ],
|
||||
//! PuX0..PuX3, PuY0..PuY3 (doubles: the placement corners when the filter was applied) }
|
||||
//! ```
|
||||
//!
|
||||
//! Each quad is one plane of `layer.smartObjects.perspectiveWarp`: `src` = the quad's
|
||||
//! `vertices`, `dst` = its `warpedVertices`, in the stored corner order. Quads that share a vertex
|
||||
//! share the corner, which the engine links. The item is kept as a template ([`TEMPLATE_KEY`]) so
|
||||
//! the keys PhotoCraft does not model go back unchanged, with only the vertices and quads
|
||||
//! rewritten from the edited planes. Anything inconsistent (an index out of range, mismatched
|
||||
//! vertex counts, a non-finite or degenerate quad) stays an opaque [`super::UNSUPPORTED_FILTER`].
|
||||
|
||||
use photocraft_algo::perspective::{PerspectiveMap, Plane, Straighten, straighten};
|
||||
use photocraft_doc::SmartFilter;
|
||||
use photocraft_psd::descriptor::{Class, Descriptor, Id, ReferenceItem, UnicodeString, Value};
|
||||
use serde_json::{Value as J, json};
|
||||
|
||||
use super::{blend_options, from_hex, get_desc, rgbc, set, to_hex, unit};
|
||||
|
||||
pub(super) const CLASS: &str = "perspectiveWarpTransform";
|
||||
/// The command this filter maps to (`photocraft_engine::distort_cmds::PERSPECTIVE_SMART`).
|
||||
pub(super) const COMMAND: &str = "layer.smartObjects.perspectiveWarp";
|
||||
/// Edit › Perspective Warp on a smart object stores its own id; it renders the same.
|
||||
const EDIT_COMMAND: &str = "edit.perspectiveWarp";
|
||||
/// The `filterID` Photoshop wrote for a new Perspective Warp smart filter.
|
||||
const FILTER_ID: i32 = 1023;
|
||||
const NAME: &str = "Perspective Warp...";
|
||||
pub(super) const TEMPLATE_KEY: &str = "__perspectiveWarpPsd";
|
||||
/// Far more planes than anyone lays out by hand; bounds the corner linking (quadratic).
|
||||
const MAX_QUADS: usize = 256;
|
||||
const MAX_VERTICES: usize = 4 * MAX_QUADS;
|
||||
const MAX_TEMPLATE_BYTES: usize = 1 << 20;
|
||||
|
||||
/// Whether `command` is a Perspective Warp smart filter this module writes.
|
||||
pub(super) fn handles(command: &str) -> bool {
|
||||
command == COMMAND || command == EDIT_COMMAND
|
||||
}
|
||||
|
||||
fn point(v: &Value) -> Option<[f64; 2]> {
|
||||
let Value::Descriptor(p) = v else { return None };
|
||||
let coord = |k: &str| match p.get(k)? {
|
||||
Value::Double(d) => Some(*d),
|
||||
Value::UnitFloat { unit: [b'#', b'P', b'x', b'l'], value } => Some(*value),
|
||||
_ => None,
|
||||
};
|
||||
Some([coord("Hrzn")?, coord("Vrtc")?]).filter(|q| q.iter().all(|v| v.is_finite()))
|
||||
}
|
||||
|
||||
fn points(f: &Descriptor, key: &str) -> Option<Vec<[f64; 2]>> {
|
||||
let Some(Value::List(list)) = f.get(key) else { return None };
|
||||
if list.is_empty() || list.len() > MAX_VERTICES {
|
||||
return None;
|
||||
}
|
||||
list.iter().map(point).collect()
|
||||
}
|
||||
|
||||
fn quads(f: &Descriptor) -> Option<Vec<[usize; 4]>> {
|
||||
let Some(Value::List(list)) = f.get("quads") else { return None };
|
||||
if list.is_empty() || list.len() > MAX_QUADS {
|
||||
return None;
|
||||
}
|
||||
list.iter()
|
||||
.map(|q| {
|
||||
let Value::Descriptor(q) = q else { return None };
|
||||
let Some(Value::List(ix)) = q.get("indices") else { return None };
|
||||
let ix: Vec<usize> = ix
|
||||
.iter()
|
||||
.map(|i| match i {
|
||||
Value::Integer(i) => usize::try_from(*i).ok(),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Option<_>>()?;
|
||||
ix.try_into().ok()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The planes a `perspectiveWarpTransform` descriptor describes; `None` when it is inconsistent.
|
||||
fn planes_of(f: &Descriptor) -> Option<Vec<Plane>> {
|
||||
let (src, dst) = (points(f, "vertices")?, points(f, "warpedVertices")?);
|
||||
if src.len() != dst.len() {
|
||||
return None;
|
||||
}
|
||||
let corners =
|
||||
|list: &[[f64; 2]], q: &[usize; 4]| -> Option<[[f64; 2]; 4]> { Some([*list.get(q[0])?, *list.get(q[1])?, *list.get(q[2])?, *list.get(q[3])?]) };
|
||||
let planes: Vec<Plane> = quads(f)?.iter().map(|q| Some(Plane { src: corners(&src, q)?, dst: corners(&dst, q)? })).collect::<Option<_>>()?;
|
||||
PerspectiveMap::new(&planes)?;
|
||||
Some(planes)
|
||||
}
|
||||
|
||||
/// `layer.smartObjects.perspectiveWarp` params for a Perspective Warp item.
|
||||
pub(super) fn import_params(item: &Descriptor) -> Option<J> {
|
||||
let f = get_desc(item, "Fltr")?;
|
||||
if !f.class_id.is(CLASS) {
|
||||
return None;
|
||||
}
|
||||
let planes = planes_of(f)?;
|
||||
// Neutral blending in the template: the model's own fields replace it on export.
|
||||
let mut template = item.clone();
|
||||
let neutral = SmartFilter { command: String::new(), params: J::Null, blend: photocraft_color::BlendMode::Normal, opacity: 1.0, visible: true };
|
||||
set(&mut template, "blendOptions", blend_options(&neutral));
|
||||
set(&mut template, "enab", Value::Boolean(true));
|
||||
Some(json!({"planes": planes, TEMPLATE_KEY: to_hex(&template.to_bytes())}))
|
||||
}
|
||||
|
||||
/// The template item of `params` (`None` when there is none), checked to be a Perspective Warp.
|
||||
fn template(params: &J) -> Result<Option<Descriptor>, String> {
|
||||
let Some(raw) = params.get(TEMPLATE_KEY) else { return Ok(None) };
|
||||
let raw = raw.as_str().ok_or("the Perspective Warp PSD data must be hex text")?;
|
||||
if raw.len() > MAX_TEMPLATE_BYTES * 2 {
|
||||
return Err("the Perspective Warp PSD data is too large".into());
|
||||
}
|
||||
let bytes = from_hex(raw).ok_or("the Perspective Warp PSD data is not valid hex")?;
|
||||
let item = Descriptor::from_bytes(&bytes).map_err(|e| format!("the Perspective Warp PSD data is unreadable ({e})"))?;
|
||||
if !item.class_id.is("filterFX") || !get_desc(&item, "Fltr").is_some_and(|f| f.class_id.is(CLASS)) {
|
||||
return Err("the Perspective Warp PSD data is not a Perspective Warp filter".into());
|
||||
}
|
||||
Ok(Some(item))
|
||||
}
|
||||
|
||||
/// The planes to write: as rendered, so a `straighten` is baked in.
|
||||
fn export_planes(params: &J) -> Result<Vec<Plane>, String> {
|
||||
let object = params.as_object().ok_or("Perspective Warp parameters must be an object")?;
|
||||
if let Some(k) = object.keys().find(|k| !super::is_meta(k) && !["planes", "straighten", "interpolation"].contains(&k.as_str())) {
|
||||
return Err(format!("Perspective Warp setting `{k}` has no PSD equivalent"));
|
||||
}
|
||||
let mut planes: Vec<Plane> =
|
||||
serde_json::from_value(params.get("planes").cloned().ok_or("it has no planes")?).map_err(|e| format!("its planes are unreadable ({e})"))?;
|
||||
if planes.is_empty() || planes.len() > MAX_QUADS {
|
||||
return Err(format!("it must have 1 to {MAX_QUADS} planes"));
|
||||
}
|
||||
if planes.iter().any(|q| q.src.iter().chain(&q.dst).flatten().any(|v| !v.is_finite())) {
|
||||
return Err("a plane corner is not finite".into());
|
||||
}
|
||||
if let Some(s) = params.get("straighten").and_then(J::as_str) {
|
||||
straighten(&mut planes, Straighten::parse(s).ok_or_else(|| format!("unknown straighten `{s}`"))?);
|
||||
}
|
||||
PerspectiveMap::new(&planes).ok_or("a plane is degenerate")?;
|
||||
Ok(planes)
|
||||
}
|
||||
|
||||
fn pnt(p: [f64; 2]) -> Value {
|
||||
Value::Descriptor(Descriptor::new("Pnt ").with("Hrzn", unit(b"#Pxl", p[0])).with("Vrtc", unit(b"#Pxl", p[1])))
|
||||
}
|
||||
|
||||
/// `vertices`, `warpedVertices` and `quads` for `planes`; a corner shared by several planes (same
|
||||
/// layout and warped position) is written once.
|
||||
fn geometry(planes: &[Plane]) -> (Value, Value, Value) {
|
||||
let mut corners: Vec<([f64; 2], [f64; 2])> = Vec::new();
|
||||
let mut quads = Vec::with_capacity(planes.len());
|
||||
for p in planes {
|
||||
let mut ix = Vec::with_capacity(4);
|
||||
for (s, d) in p.src.iter().zip(&p.dst) {
|
||||
let i = corners.iter().position(|c| c == &(*s, *d)).unwrap_or_else(|| {
|
||||
corners.push((*s, *d));
|
||||
corners.len() - 1
|
||||
});
|
||||
ix.push(Value::Integer(i32::try_from(i).unwrap_or(i32::MAX)));
|
||||
}
|
||||
quads.push(Value::Descriptor(Descriptor::new("perspectiveWarpQuad").with("indices", Value::List(ix))));
|
||||
}
|
||||
let src = corners.iter().map(|c| pnt(c.0)).collect();
|
||||
let dst = corners.iter().map(|c| pnt(c.1)).collect();
|
||||
(Value::List(src), Value::List(dst), Value::List(quads))
|
||||
}
|
||||
|
||||
/// A new `perspectiveWarpTransform` descriptor (no Photoshop template to start from).
|
||||
fn fresh_fltr(planes: &[Plane]) -> Descriptor {
|
||||
let (mut x0, mut y0, mut x1, mut y1) = (f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY);
|
||||
for c in planes.iter().flat_map(|p| p.src) {
|
||||
(x0, y0, x1, y1) = (x0.min(c[0]), y0.min(c[1]), x1.max(c[0]), y1.max(c[1]));
|
||||
}
|
||||
let target = Value::Reference(vec![ReferenceItem::Enumerated {
|
||||
class: Class { name: UnicodeString::new_nul(""), class_id: Id::new("Lyr ") },
|
||||
type_id: Id::new("Ordn"),
|
||||
value: Id::new("Trgt"),
|
||||
}]);
|
||||
let rect =
|
||||
Descriptor::new("Rctn").with("Top ", unit(b"#Pxl", y0)).with("Left", unit(b"#Pxl", x0)).with("Btom", unit(b"#Pxl", y1)).with("Rght", unit(b"#Pxl", x1));
|
||||
Descriptor::new(CLASS).with("null", target).with("referenceRect", Value::Descriptor(rect))
|
||||
}
|
||||
|
||||
/// The `filterFXList` item for a Perspective Warp smart filter.
|
||||
pub(super) fn export_item(sf: &SmartFilter) -> Result<Descriptor, String> {
|
||||
let params = &sf.params;
|
||||
let planes = export_planes(params)?;
|
||||
let template = template(params)?;
|
||||
let unchanged = template.as_ref().and_then(|item| get_desc(item, "Fltr")).and_then(planes_of).is_some_and(|p| p == planes);
|
||||
let mut item = match template {
|
||||
// Unchanged planes: the original item, vertex order and sharing included.
|
||||
Some(item) if unchanged => item,
|
||||
Some(mut item) => {
|
||||
let mut f = get_desc(&item, "Fltr").cloned().ok_or("the Perspective Warp PSD data has no filter")?;
|
||||
write_geometry(&mut f, &planes);
|
||||
set(&mut item, "Fltr", Value::Descriptor(f));
|
||||
item
|
||||
}
|
||||
None => {
|
||||
let mut f = fresh_fltr(&planes);
|
||||
write_geometry(&mut f, &planes);
|
||||
Descriptor::new("filterFX")
|
||||
.with("Nm ", Value::Text(UnicodeString::new_nul(NAME)))
|
||||
.with("blendOptions", blend_options(sf))
|
||||
.with("enab", Value::Boolean(sf.visible))
|
||||
.with("hasoptions", Value::Boolean(true))
|
||||
.with("FrgC", rgbc(0.0))
|
||||
.with("BckC", rgbc(255.0))
|
||||
.with("Fltr", Value::Descriptor(f))
|
||||
.with("filterID", Value::Integer(FILTER_ID))
|
||||
}
|
||||
};
|
||||
set(&mut item, "blendOptions", blend_options(sf));
|
||||
set(&mut item, "enab", Value::Boolean(sf.visible));
|
||||
Ok(item)
|
||||
}
|
||||
|
||||
fn write_geometry(f: &mut Descriptor, planes: &[Plane]) {
|
||||
let (src, dst, quads) = geometry(planes);
|
||||
set(f, "vertices", src);
|
||||
set(f, "warpedVertices", dst);
|
||||
set(f, "quads", quads);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::smart_map::{UNSUPPORTED_FILTER, filter_from_item, int, item_for_filter};
|
||||
|
||||
fn pts(list: &[[f64; 2]]) -> Value {
|
||||
Value::List(list.iter().map(|&p| pnt(p)).collect())
|
||||
}
|
||||
|
||||
fn quad_list<Q: AsRef<[i32]>>(q: &[Q]) -> Value {
|
||||
Value::List(
|
||||
q.iter()
|
||||
.map(|q| {
|
||||
Value::Descriptor(
|
||||
Descriptor::new("perspectiveWarpQuad").with("indices", Value::List(q.as_ref().iter().map(|&i| Value::Integer(i)).collect())),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
/// A `filterFXList` item as Photoshop wrote it for a one-plane Perspective Warp of a smart
|
||||
/// object placed at (40, 30)–(160, 120).
|
||||
fn item_with<Q: AsRef<[i32]>>(vertices: &[[f64; 2]], warped: &[[f64; 2]], q: &[Q], filter_id: i32) -> Descriptor {
|
||||
let mut f = fresh_fltr(&[Plane::identity([[40.0, 30.0], [160.0, 30.0], [160.0, 120.0], [40.0, 120.0]])])
|
||||
.with("vertices", pts(vertices))
|
||||
.with("warpedVertices", pts(warped))
|
||||
.with("quads", quad_list(q));
|
||||
for (i, (x, y)) in [(40.0, 30.0), (160.0, 30.0), (160.0, 120.0), (40.0, 120.0)].into_iter().enumerate() {
|
||||
f = f.with(&format!("PuX{i}"), Value::Double(x));
|
||||
f = f.with(&format!("PuY{i}"), Value::Double(y));
|
||||
}
|
||||
Descriptor::new("filterFX")
|
||||
.with("Nm ", Value::Text(UnicodeString::new_nul("Perspektivische Verformung...")))
|
||||
.with(
|
||||
"blendOptions",
|
||||
blend_options(&SmartFilter {
|
||||
command: String::new(),
|
||||
params: J::Null,
|
||||
blend: photocraft_color::BlendMode::Normal,
|
||||
opacity: 1.0,
|
||||
visible: true,
|
||||
}),
|
||||
)
|
||||
.with("enab", Value::Boolean(true))
|
||||
.with("hasoptions", Value::Boolean(true))
|
||||
.with("FrgC", rgbc(0.0))
|
||||
.with("BckC", rgbc(255.0))
|
||||
.with("Fltr", Value::Descriptor(f))
|
||||
.with("filterID", Value::Integer(filter_id))
|
||||
}
|
||||
|
||||
const V: [[f64; 2]; 4] = [[40.0, 30.0], [160.0, 30.0], [160.0, 120.0], [40.0, 120.0]];
|
||||
const W: [[f64; 2]; 4] = [[60.0, 50.0], [140.0, 40.0], [180.0, 130.0], [20.0, 110.0]];
|
||||
|
||||
fn one_plane() -> Descriptor {
|
||||
item_with(&V, &W, &[[0, 1, 2, 3]], FILTER_ID)
|
||||
}
|
||||
|
||||
/// Two planes sharing an edge (vertices 1 and 4).
|
||||
fn two_planes(filter_id: i32) -> Descriptor {
|
||||
let v = [[40.0, 30.0], [100.0, 30.0], [160.0, 30.0], [160.0, 120.0], [100.0, 120.0], [40.0, 120.0]];
|
||||
let w = [[40.0, 40.0], [100.0, 30.0], [170.0, 45.0], [150.0, 115.0], [100.0, 125.0], [30.0, 110.0]];
|
||||
item_with(&v, &w, &[[0, 1, 4, 5], [1, 2, 3, 4]], filter_id)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_perspective_warp_opens_as_the_command_with_its_planes() {
|
||||
let f = filter_from_item(&one_plane());
|
||||
assert_eq!(f.command, COMMAND);
|
||||
let planes: Vec<Plane> = serde_json::from_value(f.params["planes"].clone()).unwrap();
|
||||
assert_eq!(planes, vec![Plane { src: V, dst: W }]);
|
||||
|
||||
// Several quads become several planes; any filterID (708 in other versions) is read.
|
||||
let f = filter_from_item(&two_planes(708));
|
||||
assert_eq!(f.command, COMMAND);
|
||||
let planes: Vec<Plane> = serde_json::from_value(f.params["planes"].clone()).unwrap();
|
||||
assert_eq!(planes.len(), 2);
|
||||
assert_eq!(planes[0].src[1], planes[1].src[0], "the shared vertex is the same corner in both planes");
|
||||
assert_eq!(planes[1].dst, [[100.0, 30.0], [170.0, 45.0], [150.0, 115.0], [100.0, 125.0]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unchanged_filters_write_the_original_item_back() {
|
||||
for src in [one_plane(), two_planes(708)] {
|
||||
let f = filter_from_item(&src);
|
||||
assert_eq!(item_for_filter(&f).unwrap(), src);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edited_planes_round_trip_and_keep_the_rest_of_the_template() {
|
||||
let src = two_planes(708);
|
||||
let mut f = filter_from_item(&src);
|
||||
f.params["planes"][1]["dst"][2] = json!([155.5, 118.0]);
|
||||
f.opacity = 0.5;
|
||||
f.visible = false;
|
||||
let item = item_for_filter(&f).unwrap();
|
||||
assert_eq!(int(&item, "filterID"), Some(708), "the original filter id stays");
|
||||
let fltr = get_desc(&item, "Fltr").unwrap();
|
||||
assert_eq!(fltr.get("PuX1"), Some(&Value::Double(160.0)), "unmodelled keys stay");
|
||||
let Some(Value::List(v)) = fltr.get("vertices") else { panic!() };
|
||||
assert_eq!(v.len(), 6, "shared corners stay shared");
|
||||
let back = filter_from_item(&item);
|
||||
assert_eq!(back.command, COMMAND);
|
||||
assert_eq!(back.params["planes"], f.params["planes"]);
|
||||
assert_eq!((back.opacity, back.visible), (0.5, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_new_perspective_warp_writes_photoshops_layout() {
|
||||
let planes = vec![Plane { src: V, dst: W }];
|
||||
let f = SmartFilter {
|
||||
command: COMMAND.into(),
|
||||
params: json!({"planes": planes}),
|
||||
blend: photocraft_color::BlendMode::Multiply,
|
||||
opacity: 0.25,
|
||||
visible: true,
|
||||
};
|
||||
let item = item_for_filter(&f).unwrap();
|
||||
assert_eq!(int(&item, "filterID"), Some(FILTER_ID));
|
||||
assert_eq!(item.get("hasoptions"), Some(&Value::Boolean(true)));
|
||||
let fltr = get_desc(&item, "Fltr").unwrap();
|
||||
assert!(fltr.class_id.is(CLASS));
|
||||
assert_eq!(fltr.get("vertices"), Some(&pts(&V)));
|
||||
assert_eq!(fltr.get("warpedVertices"), Some(&pts(&W)));
|
||||
assert_eq!(fltr.get("quads"), Some(&quad_list(&[[0, 1, 2, 3]])));
|
||||
let rect = get_desc(fltr, "referenceRect").unwrap();
|
||||
assert_eq!(rect.get("Rght"), Some(&unit(b"#Pxl", 160.0)));
|
||||
let back = filter_from_item(&Descriptor::from_bytes(&item.to_bytes()).unwrap());
|
||||
assert_eq!((back.command.as_str(), &back.params["planes"]), (COMMAND, &json!(planes)));
|
||||
assert_eq!((back.blend, back.opacity), (photocraft_color::BlendMode::Multiply, 0.25));
|
||||
|
||||
// Edit › Perspective Warp on a smart object stores its own id; it is written too, with a
|
||||
// straighten baked in.
|
||||
let f = SmartFilter { command: EDIT_COMMAND.into(), params: json!({"planes": planes, "straighten": "auto", "interpolation": "bilinear"}), ..f };
|
||||
assert!(item_for_filter(&f).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inconsistent_perspective_warps_stay_opaque() {
|
||||
let nan = [[f64::NAN, 30.0], V[1], V[2], V[3]];
|
||||
let flat = [[0.0, 0.0]; 4];
|
||||
let without = |key: &str| {
|
||||
let mut i = one_plane();
|
||||
let mut f = get_desc(&i, "Fltr").unwrap().clone();
|
||||
f.items.retain(|(k, _)| !k.is(key));
|
||||
set(&mut i, "Fltr", Value::Descriptor(f));
|
||||
i
|
||||
};
|
||||
let mut bad_unit = one_plane();
|
||||
let mut f = get_desc(&bad_unit, "Fltr").unwrap().clone();
|
||||
let Some(Value::List(l)) = f.get("vertices").cloned() else { panic!() };
|
||||
let mut l = l;
|
||||
l[0] = Value::Descriptor(Descriptor::new("Pnt ").with("Hrzn", unit(b"#Prc", 40.0)).with("Vrtc", unit(b"#Prc", 30.0)));
|
||||
set(&mut f, "vertices", Value::List(l));
|
||||
set(&mut bad_unit, "Fltr", Value::Descriptor(f));
|
||||
let too_many: Vec<[i32; 4]> = vec![[0, 1, 2, 3]; MAX_QUADS + 1];
|
||||
for (i, src) in [
|
||||
item_with(&V, &W, &[[0, 1, 2, 4]], FILTER_ID),
|
||||
item_with(&V, &W, &[[0, 1, 2, -1]], FILTER_ID),
|
||||
item_with(&V, &W, &[[0, 1, 2]], FILTER_ID),
|
||||
item_with(&V, &W, &[[0, 1, 2, 3, 0]], FILTER_ID),
|
||||
item_with(&V, &W, &[] as &[[i32; 4]], FILTER_ID),
|
||||
item_with(&V, &W, &too_many, FILTER_ID),
|
||||
item_with(&V, &W[..3], &[[0, 1, 2, 3]], FILTER_ID),
|
||||
item_with(&nan, &W, &[[0, 1, 2, 3]], FILTER_ID),
|
||||
item_with(&flat, &W, &[[0, 1, 2, 3]], FILTER_ID),
|
||||
item_with(&[], &[], &[[0, 1, 2, 3]], FILTER_ID),
|
||||
without("vertices"),
|
||||
without("warpedVertices"),
|
||||
without("quads"),
|
||||
bad_unit,
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let f = filter_from_item(&src);
|
||||
assert_eq!(f.command, UNSUPPORTED_FILTER, "case {i}");
|
||||
// Bytes, as NaN is not equal to itself.
|
||||
assert_eq!(item_for_filter(&f).unwrap().to_bytes(), src.to_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_exports_report_errors() {
|
||||
let ok = filter_from_item(&one_plane()).params;
|
||||
let with = |k: &str, v: J| {
|
||||
let mut p = ok.clone();
|
||||
p[k] = v;
|
||||
p
|
||||
};
|
||||
let plane = json!([{"src": V, "dst": W}]);
|
||||
for p in [
|
||||
J::Null,
|
||||
json!({}),
|
||||
json!({"planes": []}),
|
||||
json!({"planes": "x"}),
|
||||
json!({"planes": [{"src": [[0, 0], [0, 0], [0, 0], [0, 0]], "dst": W}]}),
|
||||
json!({"planes": plane, "straighten": "sideways"}),
|
||||
json!({"planes": plane, "pins": []}),
|
||||
json!({"planes": vec![json!({"src": V, "dst": W}); MAX_QUADS + 1]}),
|
||||
with(TEMPLATE_KEY, json!("zz")),
|
||||
with(TEMPLATE_KEY, json!(7)),
|
||||
with(TEMPLATE_KEY, json!(to_hex(&Descriptor::new("filterFX").to_bytes()))),
|
||||
with(TEMPLATE_KEY, json!("0".repeat(MAX_TEMPLATE_BYTES * 2 + 2))),
|
||||
] {
|
||||
let f = SmartFilter { command: COMMAND.into(), params: p.clone(), blend: photocraft_color::BlendMode::Normal, opacity: 1.0, visible: true };
|
||||
assert!(export_item(&f).is_err(), "{p}");
|
||||
}
|
||||
}
|
||||
}
|
||||
+1571
-8
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
||||
# File-format parity
|
||||
|
||||
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-15 · **Change:** minor (DDS textures save: uncompressed or BC1–BC3, optional mip chain, DDS Options in Save As (#1327); large-file fixtures: a 20 MP layered PSD, a 150-layer layout, a 2 GB PSD and a 4.4 GB PSB generated at test time and round-tripped, FILE-216-2 done, #5107; earlier: PNG `sTER` stereo pairing kept on save, #6063; PDF write one flattened page via Save As / Save a Copy / CLI, #3401; CMYK Invert, Posterize and Threshold on the inks; smart filter masks on PSD open and save; Photoshop-oracle floor 188/258; lossy DNG, compression 34892, decodes with its levels and LinearizationTable applied to the stored 8-bit samples, FILE-215-11; CMYK Hue/Saturation and Color Balance keep the black ink; CMYK Posterize on the stored values, psd-tools oracle floor 242/309; CMYK adjustment layers composite on the document's inks; Photoshop-oracle floor 165/258; CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; modern Brightness/Contrast's brightness curve; Photoshop-oracle floor 151/258; Lab documents composite on their stored L, a, b; Photoshop-oracle floor 152/258; Levels on whole levels at every step with Photoshop's shadow toe; Photoshop-oracle floor 146/258, psd-tools 238/309; 32-bit adjustments unclipped; Photoshop-oracle floor 149/258; mask feathers blur with their exact variance; Threshold splits on Photoshop's luminosity; a pass-through clipping base with an adjustment renders isolated; psd-tools oracle floor 240/309; 16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; earlier: CMYK Invert, Posterize and Threshold on the inks; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding) · **Target:** Adobe Photoshop 2026
|
||||
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-15 · **Change:** minor (DDS textures save: uncompressed or BC1–BC3, optional mip chain, DDS Options in Save As (#1327); PSD smart filters: 41 filters (27 more: Blur, Surface Blur, Smart Sharpen, Diffuse, Wind, Offset, Mezzotint and others) plus Hue/Saturation and Perspective Warp mapped both ways, #6296, #6298, #6300, #6302, #6304, #6314, #6316, #6267, #6268, FILE-215-2; large-file fixtures: a 20 MP layered PSD, a 150-layer layout, a 2 GB PSD and a 4.4 GB PSB generated at test time and round-tripped, FILE-216-2 done, #5107; earlier: PNG `sTER` stereo pairing kept on save, #6063; PDF write one flattened page via Save As / Save a Copy / CLI, #3401; CMYK Invert, Posterize and Threshold on the inks; smart filter masks on PSD open and save; Photoshop-oracle floor 188/258; lossy DNG, compression 34892, decodes with its levels and LinearizationTable applied to the stored 8-bit samples, FILE-215-11; CMYK Hue/Saturation and Color Balance keep the black ink; CMYK Posterize on the stored values, psd-tools oracle floor 242/309; CMYK adjustment layers composite on the document's inks; Photoshop-oracle floor 165/258; CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; modern Brightness/Contrast's brightness curve; Photoshop-oracle floor 151/258; Lab documents composite on their stored L, a, b; Photoshop-oracle floor 152/258; Levels on whole levels at every step with Photoshop's shadow toe; Photoshop-oracle floor 146/258, psd-tools 238/309; 32-bit adjustments unclipped; Photoshop-oracle floor 149/258; mask feathers blur with their exact variance; Threshold splits on Photoshop's luminosity; a pass-through clipping base with an adjustment renders isolated; psd-tools oracle floor 240/309; 16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; earlier: CMYK Invert, Posterize and Threshold on the inks; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding) · **Target:** Adobe Photoshop 2026
|
||||
|
||||
Every format Photoshop 2026 (27.11.0) reads or writes, with PhotoCraft's support, fidelity and
|
||||
tests. Photoshop's list comes from its `Info.plist` `CFBundleDocumentTypes`, the PiPL read/write
|
||||
@@ -21,7 +21,7 @@ XL are missing (gap G10). Remaining: 300–500 h including PSD fidelity.
|
||||
|
||||
| Format | Photoshop | PhotoCraft read | PhotoCraft write | Fidelity and tests |
|
||||
|---|---|---|---|---|
|
||||
| PSD | R/W | yes | yes | 1/8/16/32-bit; Bitmap, Gray, Indexed, RGB, CMYK, Multichannel, Lab, Duotone; layers, groups, masks, vector masks, adjustment and fill layers, effects, text, shapes, smart objects (SoLd/lnk2; CS2 PlLd/lnkD read with their warp, kept as is or re-saved as SoLd once edited), smart filters (14 mapped plus Filter Gallery with Chrome, rest verbatim), slices, comps, Advanced Blending. Oracle floors: Photoshop-authored 188/258, io 148/170, psd-tools 249/309; round trip ≥ 169/170, 308/309, 258/256. Known failures: #1281, #2469 (#2374, text layers, closed 2026-10-10; #2465, CS2 `PlLd`-only smart objects, fixed 2026-10-12) |
|
||||
| PSD | R/W | yes | yes | 1/8/16/32-bit; Bitmap, Gray, Indexed, RGB, CMYK, Multichannel, Lab, Duotone; layers, groups, masks, vector masks, adjustment and fill layers, effects, text, shapes, smart objects (SoLd/lnk2; CS2 PlLd/lnkD read with their warp, kept as is or re-saved as SoLd once edited), smart filters (41 mapped plus Hue/Saturation, Perspective Warp, Filter Gallery with Chrome and a Camera Raw subset, rest verbatim), slices, comps, Advanced Blending. Oracle floors: Photoshop-authored 188/258, io 148/170, psd-tools 249/309; round trip ≥ 169/170, 308/309, 258/256. Known failures: #1281, #2469 (#2374, text layers, closed 2026-10-10; #2465, CS2 `PlLd`-only smart objects, fixed 2026-10-12) |
|
||||
| PSB | R/W | yes | yes | Auto-switches above 2 GB (REL-212-2); generated 20 MP, 150-layer, 2 GB PSD and 4.4 GB PSB fixtures opened, saved and re-opened by io tests/large_files.rs (FILE-216-2, 2026-10-13; the 4.4 GB PSB opens on Windows); > 4 GB from the app's File › Open on Windows: #375 |
|
||||
| Cloud PSD (.psdc) | R/W | no | no | Out of scope (Adobe cloud) |
|
||||
| TIFF | R/W | yes | yes | 8/16/32f, Gray/RGB/CMYK, BigTIFF, every IFD, banded parallel decode; layered TIFF both byte orders (FILE-215-7: extra alpha channels not written) |
|
||||
@@ -143,6 +143,15 @@ remaining gaps in #1606 stay tracked with per-sample corpus ceilings.
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-15 | minor | DDS textures save (#1327): uncompressed or BC1/BC2/BC3 (DXT1/3/5) from a clean-room block encoder, optional box-filtered mip chain, legacy header; DDS Options in Save As and Save a Copy, `ddsCompression`/`ddsMipmaps` for scripts, the CLI and MCP |
|
||||
| 2026-10-16 | minor | PSD smart filters: Perspective Warp (`perspectiveWarpTransform`: `vertices`, `warpedVertices`, `quads` of vertex indices, document pixels) opens as `layer.smartObjects.perspectiveWarp`, one plane per quad, and re-renders warped; save writes the original item with only the geometry rewritten, or a new one in Photoshop's layout; inconsistent descriptors stay verbatim (FILE-215-2, #6268) |
|
||||
| 2026-10-16 | minor | PSD smart filters: Hue/Saturation (`HStr`: `Clrz`, `Adjs` = master `Hst2` plus one per edited range with `LclR` and its four range sliders, all longs, measured on a Photoshop-saved file) opens as `image.adjustments.hueSaturation`, re-renders with the smart object and saves in Photoshop's layout; layouts outside it stay verbatim (FILE-215-2, #6267) |
|
||||
| 2026-10-15 | minor | PSD smart filters without options (Blur, Blur More, Average, Despeckle, Find Edges, Facet, Fragment, Sharpen, Sharpen More, Sharpen Edges, Solarize) map both ways as Photoshop stores them: `hasoptions` false, no `Fltr`, the four-char `filterID` (FILE-215-2) |
|
||||
| 2026-10-15 | minor | PSD smart filters: Surface Blur (filterID 1135, `surfaceBlur`), Smart Blur (`SmrB`) and Radial Blur (`RdlB`) open as editable filters and save with the keys, types and enums measured in Photoshop; out-of-range, unknown-enum or extra-key entries (an off-centre Radial Blur) stay verbatim (#6298, FILE-215-2) |
|
||||
| 2026-10-15 | minor | PSD smart filters: Smart Sharpen (filterID 1131, Gaussian removal; Lens/Motion Blur and legacy entries stay verbatim) and Dust & Scratches (`DstS`) open as editable filters and save in Photoshop's measured shape (#6300) |
|
||||
| 2026-10-15 | minor | PSD smart filters: Diffuse (`Dfs `, `DfsM` mode), Trace Contour (`TrcC`, level and `CntE` edge), Crystallize (`Crst`) and Pointillize (`Pntl`, background from `BckC`) open as editable smart filters and save in the shape measured in Photoshop (#6302, FILE-215-2) |
|
||||
| 2026-10-15 | minor | PSD smart filters: Wind (`Wnd `, `WndM` method, `Drct` direction), Extrude (`Extr`, `ExtT` type, size, depth, `ExtR` depth mode, solid front faces, mask incomplete blocks) and Tiles (`Tls `, count, offset, `FlCl` fill with the entry's `FrgC`/`BckC`) open as editable smart filters and save in the shape measured in Photoshop (#6314, FILE-215-2) |
|
||||
| 2026-10-15 | minor | PSD smart filters: Offset (`Ofst`: `Hrzn`/`Vrtc` long, `Fl ` `FlMd` Wrap/Background/Repeat) and Custom (`Cstm`: `Scl `, `Ofst` long, 25-long `Mtrx`) map both ways in `filterFX`, matching descriptors measured in Photoshop (FILE-215-2, #6304) |
|
||||
| 2026-10-15 | minor | PSD smart filters: Mezzotint (`Mztn`, `MztT` enum, all 10 types) and Color Halftone (`ClrH`, `Rds `/`Ang1`–`Ang4` longs) open as editable filters and save in Photoshop's shape, measured in Photoshop (FILE-215-2); Mezzotint's PhotoCraft-only seed is not saved |
|
||||
| 2026-10-15 | minor | PNG: a stereo PNG's `sTER` pairing (PNG Extensions 1.4.0 §3.6) is read on open and written back on save, so the file still says it is a stereo pair (#6063) |
|
||||
| 2026-10-15 | minor | PSD guides: image resource 1092 (guides v2) gives guides their own colours on import; 1092 and 1097 (guide GUIDs) are written back only while they still describe the document's guides, so an edit no longer leaves Photoshop a stale second guide list (#5966) |
|
||||
| 2026-10-14 | minor | PSD smart filter masks: Photoshop stores a smart object's filtered pixels without its filter mask and mixes the unfiltered ones (`FEid`) back in; import now mixes them and export writes them that way, so sf-filter-mask-hard, -gradient and sf-stack-blend-and-mask pass; Photoshop-oracle floor 185 → 188 of 258 |
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
|
||||
| Id | Target | Status | Issue | Note |
|
||||
|---|---|---|---|---|
|
||||
| FILE-215-1 | Smart Objects export as embedded Smart Objects (SoLd + lnk2), not flat pixels | done | [#215](https://github.com/storytold/photocraft/issues/215) | psd_export.rs smart_blocks: PlLd + SoLd, source in lnk2 (.pcraft -> PSB); engine tests/smart_psd.rs; Photoshop 2026 opens 8/16-bit exports as live smart objects. Linked files are embedded |
|
||||
| FILE-215-2 | Smart Filters survive PSD save and re-open (filterFX descriptor read and written) | partial | [#215](https://github.com/storytold/photocraft/issues/215) | smart_map.rs: 14 filters plus a verified Camera Raw subset mapped both ways, others kept verbatim, mask in FEid; io tests/smart_corpus.rs. PhotoCraft-only filters (Twirl, Liquify…) and unmapped Camera Raw settings are left out of filterFX with a warning |
|
||||
| FILE-215-2 | Smart Filters survive PSD save and re-open (filterFX descriptor read and written) | partial | [#215](https://github.com/storytold/photocraft/issues/215) | smart_map.rs: 41 filters plus Hue/Saturation, Perspective Warp, Filter Gallery (Chrome) and a verified Camera Raw subset mapped both ways, others kept verbatim, mask in FEid; io tests/smart_corpus.rs. PhotoCraft-only filters (Twirl, Liquify…) and unmapped Camera Raw settings are left out of filterFX with a warning |
|
||||
| FILE-215-3 | Filter mask can be painted directly, with undo | missing | [#215](https://github.com/storytold/photocraft/issues/215) | smart_cmds.rs:382 mask only from the selection |
|
||||
| FILE-215-4 | Adjustments (Hue/Sat + Colorize, Curves, Levels, Shadows/Highlights) apply as Smart Filters | done | [#215](https://github.com/storytold/photocraft/issues/215) | Image › Adjustments on a smart object records image.adjustments.<kind> as a smart filter (adjust_cmds.rs adjust_as_smart_filter; the selection becomes the filter mask), re-rendered from the source by adjust_as_filter and re-editable with layer.smartFilter.setParams; PSD maps Levels/Curves/Shadows-Highlights both ways (smart_map.rs). Opening the editor from the smart-filter row is FILE-215-5's row work |
|
||||
| FILE-215-5 | Smart Filter rows: collapse, mask thumb, blend icon, drag reorder, context menu, live preview | partial | [#215](https://github.com/storytold/photocraft/issues/215) | smart_ui.rs:31 rows + visibility + editor; no collapse, drag or context menu |
|
||||
|
||||
@@ -17,7 +17,7 @@ id = "FILE-215-2"
|
||||
target = "Smart Filters survive PSD save and re-open (filterFX descriptor read and written)"
|
||||
status = "partial"
|
||||
issue = 215
|
||||
note = "smart_map.rs: 14 filters plus a verified Camera Raw subset mapped both ways, others kept verbatim, mask in FEid; io tests/smart_corpus.rs. PhotoCraft-only filters (Twirl, Liquify…) and unmapped Camera Raw settings are left out of filterFX with a warning"
|
||||
note = "smart_map.rs: 41 filters plus Hue/Saturation, Perspective Warp, Filter Gallery (Chrome) and a verified Camera Raw subset mapped both ways, others kept verbatim, mask in FEid; io tests/smart_corpus.rs. PhotoCraft-only filters (Twirl, Liquify…) and unmapped Camera Raw settings are left out of filterFX with a warning"
|
||||
|
||||
[[item]]
|
||||
id = "FILE-215-3"
|
||||
|
||||
Reference in new issue
Block a user