mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge PR #6160: feat(psd): editable Render smart filters (Clouds, Difference Clouds, Fibers, Lens Flare)
# Conflicts: # docs/file-format-parity.md
This commit is contained in:
commit
b68b64ccb5
9 files changed
+364
-67
No files matched your search
+19
-2
@@ -411,6 +411,14 @@ pub enum FilterParams {
|
||||
},
|
||||
|
||||
// ---- Render ----
|
||||
/// Clouds (or Difference Clouds, which subtracts them from the pixels) between two straight
|
||||
/// sRGB RGBA colours; the cloud size follows the bounds.
|
||||
Clouds {
|
||||
seed: u32,
|
||||
difference: bool,
|
||||
foreground: [f32; 4],
|
||||
background: [f32; 4],
|
||||
},
|
||||
/// Variance 1–64, strength 1–64; colours straight sRGB RGBA.
|
||||
Fibers {
|
||||
variance: f32,
|
||||
@@ -606,7 +614,13 @@ impl FilterParams {
|
||||
/// the reference bounds even where the layer is transparent, as Photoshop's does on an
|
||||
/// empty layer, while still reading no neighbourhood.
|
||||
pub fn renders_from_nothing(&self) -> bool {
|
||||
matches!(self, FilterParams::Fibers { .. })
|
||||
matches!(self, FilterParams::Fibers { .. } | FilterParams::Clouds { difference: false, .. })
|
||||
}
|
||||
|
||||
/// Whether the filter places and sizes its pattern by the canvas even with a selection
|
||||
/// (Clouds, Fibers): its bounds are then the canvas, and the selection only masks the result.
|
||||
pub fn sizes_by_canvas(&self) -> bool {
|
||||
matches!(self, FilterParams::Clouds { .. } | FilterParams::Fibers { .. })
|
||||
}
|
||||
|
||||
/// Human-readable name.
|
||||
@@ -653,6 +667,8 @@ impl FilterParams {
|
||||
FilterParams::Displace { .. } => "Displace",
|
||||
FilterParams::Shear { .. } => "Shear",
|
||||
FilterParams::ZigZag { .. } => "ZigZag",
|
||||
FilterParams::Clouds { difference: false, .. } => "Clouds",
|
||||
FilterParams::Clouds { difference: true, .. } => "Difference Clouds",
|
||||
FilterParams::Fibers { .. } => "Fibers",
|
||||
FilterParams::LensFlare { .. } => "Lens Flare",
|
||||
FilterParams::LightingEffects { .. } => "Lighting Effects",
|
||||
@@ -697,7 +713,7 @@ fn halo_ext(p: &FilterParams) -> Halo {
|
||||
FilterParams::Wind { method, .. } => r(stylize2::wind_reach(*method)),
|
||||
FilterParams::Displace { .. } | FilterParams::Shear { .. } | FilterParams::ZigZag { .. } | FilterParams::SpinBlur { .. } => Halo::Bounds,
|
||||
// Generators and per-pixel renders only need the bounds geometry (always in the context).
|
||||
FilterParams::Fibers { .. } | FilterParams::LensFlare { .. } => Halo::Radius(0),
|
||||
FilterParams::Fibers { .. } | FilterParams::LensFlare { .. } | FilterParams::Clouds { .. } => Halo::Radius(0),
|
||||
FilterParams::LightingEffects { .. } => r(1.0),
|
||||
FilterParams::Relight { intensity, .. } if *intensity == 0.0 => Halo::Radius(0),
|
||||
FilterParams::Relight { .. } => Halo::Radius(relight::halo_radius_max()),
|
||||
@@ -817,6 +833,7 @@ pub fn kernel(params: &FilterParams, src: &Image, out: Rect, ctx: &Ctx) -> Vec<f
|
||||
}
|
||||
FilterParams::Shear { points, undefined } => distort2::shear(src, out, ctx, points, *undefined),
|
||||
FilterParams::ZigZag { amount, ridges, style } => distort2::zigzag(src, out, ctx, *amount, *ridges, *style),
|
||||
FilterParams::Clouds { seed, difference, foreground, background } => render::clouds(src, out, ctx, *seed, *difference, (*foreground, *background)),
|
||||
FilterParams::Fibers { variance, strength, seed, foreground, background } => {
|
||||
render::fibers(src, out, ctx, *variance, *strength, *seed, (*foreground, *background))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Render: Fibers, Lens Flare, Lighting Effects.
|
||||
//! Render: Clouds, Difference Clouds, Fibers, Lens Flare, Lighting Effects.
|
||||
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
@@ -18,6 +18,57 @@ fn value_noise(x: f32, y: f32, seed: u32) -> f32 {
|
||||
top + (bot - top) * sy
|
||||
}
|
||||
|
||||
fn cloud_hash(x: i32, y: i32, seed: u32) -> f32 {
|
||||
let mut h = (x as u32).wrapping_mul(0x8da6_b343) ^ (y as u32).wrapping_mul(0xd816_3841) ^ seed.wrapping_mul(0xcb1a_b31f);
|
||||
h ^= h >> 13;
|
||||
h = h.wrapping_mul(0x5bd1_e995);
|
||||
h ^= h >> 15;
|
||||
(h & 0x00ff_ffff) as f32 / 0x00ff_ffff as f32
|
||||
}
|
||||
|
||||
/// Smooth value noise, summed over octaves (fBm), in 0..1.
|
||||
fn clouds_value(x: f32, y: f32, base: f32, seed: u32) -> f32 {
|
||||
let (mut sum, mut amp, mut freq, mut norm) = (0.0, 1.0, 1.0 / base, 0.0);
|
||||
for o in 0..8u32 {
|
||||
let (fx, fy) = (x * freq, y * freq);
|
||||
let (ix, iy) = (fx.floor() as i32, fy.floor() as i32);
|
||||
let (tx, ty) = (fx - ix as f32, fy - iy as f32);
|
||||
let (sx, sy) = (tx * tx * (3.0 - 2.0 * tx), ty * ty * (3.0 - 2.0 * ty));
|
||||
let s = seed.wrapping_add(o * 7919);
|
||||
let top = cloud_hash(ix, iy, s) + (cloud_hash(ix + 1, iy, s) - cloud_hash(ix, iy, s)) * sx;
|
||||
let bot = cloud_hash(ix, iy + 1, s) + (cloud_hash(ix + 1, iy + 1, s) - cloud_hash(ix, iy + 1, s)) * sx;
|
||||
sum += (top + (bot - top) * sy) * amp;
|
||||
norm += amp;
|
||||
amp *= 0.5;
|
||||
freq *= 2.0;
|
||||
}
|
||||
// Stretch the bell-shaped sum so the clouds use the full foreground→background range.
|
||||
((sum / norm - 0.5) * 2.2 + 0.5).clamp(0.0, 1.0)
|
||||
}
|
||||
|
||||
/// Clouds between the foreground and background colours; Difference Clouds subtracts them from
|
||||
/// the pixels (alpha kept). The cloud size is a quarter of the bounds' longer side, and the
|
||||
/// pattern is anchored at the bounds' corner (so it moves with a smart object).
|
||||
pub(crate) fn clouds(src: &Image, out: Rect, ctx: &Ctx, seed: u32, difference: bool, colours: ([f32; 4], [f32; 4])) -> Vec<f32> {
|
||||
let n = src.ch;
|
||||
let (fg, bg) = colours;
|
||||
let base = (ctx.bounds.width().max(ctx.bounds.height()) as f32 / 4.0).clamp(16.0, 512.0);
|
||||
let mut res = src.crop(out);
|
||||
for (i, px) in res.chunks_exact_mut(n).enumerate() {
|
||||
let (x, y) = xy(out, i);
|
||||
let (x, y) = (x - ctx.bounds.x0, y - ctx.bounds.y0);
|
||||
let t = clouds_value(x as f32, y as f32, base, seed);
|
||||
let c: [f32; 3] = std::array::from_fn(|k| fg[k] + (bg[k] - fg[k]) * t);
|
||||
if difference {
|
||||
let p = rgba(ctx, px);
|
||||
set_rgba(ctx, px, [(p[0] - c[0]).abs(), (p[1] - c[1]).abs(), (p[2] - c[2]).abs(), p[3]]);
|
||||
} else {
|
||||
set_rgba(ctx, px, [c[0], c[1], c[2], 1.0]);
|
||||
}
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
/// Fibers: vertical fibrous streaks between the foreground and background
|
||||
/// colours. Variance sets how quickly the colour varies across fibres (and
|
||||
/// how short they are); strength stretches each fibre vertically.
|
||||
@@ -32,8 +83,9 @@ pub(crate) fn fibers(src: &Image, out: Rect, ctx: &Ctx, variance: f32, strength:
|
||||
let fy = fx / (2.0 + st * 1.5) * (0.5 + var / 32.0);
|
||||
let mut res = src.crop(out);
|
||||
for (i, px) in res.chunks_exact_mut(n).enumerate() {
|
||||
// Anchored at the bounds' corner, so the fibres move with a smart object.
|
||||
let (x, y) = xy(out, i);
|
||||
let (xf, yf) = (x as f32, y as f32);
|
||||
let (xf, yf) = ((x - ctx.bounds.x0) as f32, (y - ctx.bounds.y0) as f32);
|
||||
let mut sum = 0.0;
|
||||
let mut amp = 1.0;
|
||||
let mut norm = 0.0;
|
||||
|
||||
@@ -278,57 +278,6 @@ fn average(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
})
|
||||
}
|
||||
|
||||
fn hash(x: i32, y: i32, seed: u32) -> f32 {
|
||||
let mut h = (x as u32).wrapping_mul(0x8da6_b343) ^ (y as u32).wrapping_mul(0xd816_3841) ^ seed.wrapping_mul(0xcb1a_b31f);
|
||||
h ^= h >> 13;
|
||||
h = h.wrapping_mul(0x5bd1_e995);
|
||||
h ^= h >> 15;
|
||||
(h & 0x00ff_ffff) as f32 / 0x00ff_ffff as f32
|
||||
}
|
||||
|
||||
/// Smooth value noise, summed over octaves (fBm), in 0..1.
|
||||
pub(crate) fn clouds_value(x: f32, y: f32, base: f32, seed: u32) -> f32 {
|
||||
let (mut sum, mut amp, mut freq, mut norm) = (0.0, 1.0, 1.0 / base, 0.0);
|
||||
for o in 0..8u32 {
|
||||
let (fx, fy) = (x * freq, y * freq);
|
||||
let (ix, iy) = (fx.floor() as i32, fy.floor() as i32);
|
||||
let (tx, ty) = (fx - ix as f32, fy - iy as f32);
|
||||
let (sx, sy) = (tx * tx * (3.0 - 2.0 * tx), ty * ty * (3.0 - 2.0 * ty));
|
||||
let s = seed.wrapping_add(o * 7919);
|
||||
let top = hash(ix, iy, s) + (hash(ix + 1, iy, s) - hash(ix, iy, s)) * sx;
|
||||
let bot = hash(ix, iy + 1, s) + (hash(ix + 1, iy + 1, s) - hash(ix, iy + 1, s)) * sx;
|
||||
sum += (top + (bot - top) * sy) * amp;
|
||||
norm += amp;
|
||||
amp *= 0.5;
|
||||
freq *= 2.0;
|
||||
}
|
||||
// Stretch the bell-shaped sum so the clouds use the full foreground→background range.
|
||||
((sum / norm - 0.5) * 2.2 + 0.5).clamp(0.0, 1.0)
|
||||
}
|
||||
|
||||
/// Filter › Render › Clouds / Difference Clouds, between the foreground and background colours.
|
||||
fn clouds(s: &mut Session, p: &Value, difference: bool) -> Result<Value> {
|
||||
let (fg, bg) = (s.tools.foreground, s.tools.background);
|
||||
let seed = p.get("seed").and_then(Value::as_u64).unwrap_or(0) as u32;
|
||||
let size = s.active().map_or(256.0, |d| d.doc.size.width.max(d.doc.size.height) as f32);
|
||||
let base = (size / 4.0).clamp(16.0, 512.0);
|
||||
map_pixels(s, if difference { "Difference Clouds" } else { "Clouds" }, p, |area, px, _| {
|
||||
let w = area.width() as usize;
|
||||
for (i, p) in px.iter_mut().enumerate() {
|
||||
let (x, y) = ((area.x0 + (i % w) as i32) as f32, (area.y0 + (i / w) as i32) as f32);
|
||||
let t = clouds_value(x, y, base, seed);
|
||||
let c: [f32; 3] = std::array::from_fn(|k| fg[k] + (bg[k] - fg[k]) * t);
|
||||
if difference {
|
||||
for k in 0..3 {
|
||||
p[k] = (p[k] - c[k]).abs();
|
||||
}
|
||||
} else {
|
||||
*p = [c[0], c[1], c[2], 1.0];
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// ---------- transform presets ----------
|
||||
|
||||
/// The presets' params: like Free Transform, they follow the Channels and Layers panel target.
|
||||
@@ -1057,8 +1006,6 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
show_only
|
||||
),
|
||||
spec!("filter.blur.average", "Average", &["Filter", "Blur"], None, "{}", has_pixels, average),
|
||||
spec!("filter.render.clouds", "Clouds", &["Filter", "Render"], None, r##"{"seed":u32=0}"##, has_pixels, |s, p| clouds(s, p, false)),
|
||||
spec!("filter.render.differenceClouds", "Difference Clouds", &["Filter", "Render"], None, r##"{"seed":u32=0}"##, has_pixels, |s, p| clouds(s, p, true)),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1541,6 +1488,31 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// A selection masks Clouds but doesn't change their size: inside it they are the canvas's
|
||||
/// clouds, as when Clouds sized itself by the document (before it became a filter).
|
||||
#[test]
|
||||
fn clouds_in_a_selection_are_the_canvas_clouds() {
|
||||
// Big enough that the canvas (cloud size 100 px) and the selection (16 px) size differently.
|
||||
let big = |depth: u32| {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 400, "height": 300, "depth": depth})).unwrap();
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
s
|
||||
};
|
||||
for depth in [8, 16, 32] {
|
||||
let mut whole = big(depth);
|
||||
whole.execute("filter.render.clouds", json!({"seed": 4})).unwrap();
|
||||
let mut s = big(depth);
|
||||
s.execute("select.rect", json!({"x": 50, "y": 40, "width": 60, "height": 50})).unwrap();
|
||||
s.execute("filter.render.clouds", json!({"seed": 4})).unwrap();
|
||||
for (x, y) in [(50, 40), (75, 60), (100, 85), (109, 89)] {
|
||||
let (a, b) = (pixel(&s, x, y), pixel(&whole, x, y));
|
||||
assert!((0..4).all(|c| (a[c] - b[c]).abs() < 1e-3), "depth {depth} at {x},{y}: {a:?} vs {b:?}");
|
||||
}
|
||||
assert_eq!(pixel(&s, 300, 200)[3], 0.0, "outside the selection the layer stays empty");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn average_and_clouds() {
|
||||
let mut s = session(8);
|
||||
|
||||
@@ -262,9 +262,10 @@ pub(crate) fn run_filter(s: &mut Session, id: &str, p: &Value) -> Result<Value>
|
||||
};
|
||||
let selection = doc.selection.clone();
|
||||
let sel_bounds = selection.as_ref().map(photocraft_raster::Surface::content_bounds);
|
||||
// Distortions centre on the selection when there is one, else the canvas.
|
||||
// Distortions centre on the selection when there is one, else the canvas. Clouds and
|
||||
// Fibers place and size their pattern by the canvas either way; the selection masks them.
|
||||
let doc_bounds = doc.bounds();
|
||||
let bounds = sel_bounds.filter(|b| !b.is_empty()).unwrap_or(doc_bounds);
|
||||
let bounds = if fp.sizes_by_canvas() { doc_bounds } else { sel_bounds.filter(|b| !b.is_empty()).unwrap_or(doc_bounds) };
|
||||
// Neighbourhood filters repeat edge pixels at the canvas edge (or past it, where the
|
||||
// layer has off-canvas pixels) instead of fading in transparency, as Photoshop does.
|
||||
if let Some(surf) = crate::channel_cmds::channel_surface_for_filter(doc, Some(layer), &p)? {
|
||||
|
||||
@@ -173,6 +173,12 @@ pub fn params_for(id: &str, p: &Value) -> Option<FilterParams> {
|
||||
},
|
||||
},
|
||||
// ---- Render ----
|
||||
"filter.render.clouds" | "filter.render.differenceClouds" => FilterParams::Clouds {
|
||||
seed: seed(p),
|
||||
difference: id == "filter.render.differenceClouds",
|
||||
foreground: colour(p, "foreground", BLACK),
|
||||
background: colour(p, "background", WHITE),
|
||||
},
|
||||
"filter.render.fibers" => FilterParams::Fibers {
|
||||
variance: f(p, "variance", 16.0).clamp(1.0, 64.0),
|
||||
strength: f(p, "strength", 4.0).clamp(1.0, 64.0),
|
||||
@@ -401,7 +407,8 @@ pub fn params_for(id: &str, p: &Value) -> Option<FilterParams> {
|
||||
|
||||
/// Ids whose rendering uses the foreground/background colours.
|
||||
fn uses_colours(id: &str) -> bool {
|
||||
matches!(id, "filter.render.fibers" | "filter.stylize.tiles" | "filter.pixelate.pointillize") || crate::gallery_cmds::uses_colours(id)
|
||||
matches!(id, "filter.render.clouds" | "filter.render.differenceClouds" | "filter.render.fibers" | "filter.stylize.tiles" | "filter.pixelate.pointillize")
|
||||
|| crate::gallery_cmds::uses_colours(id)
|
||||
}
|
||||
|
||||
/// Fills in session state a filter reads (the current colours) as explicit params, so the
|
||||
@@ -628,6 +635,8 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
r##"{"amount":-100..100=10,"ridges":0..20=5,"style":"pondRipples|outFromCenter|aroundCenter"}"##
|
||||
),
|
||||
// Render
|
||||
cmd!("filter.render.clouds", "Clouds", ["Filter", "Render"], r##"{"seed":u32=0,"foreground":json,"background":json}"##),
|
||||
cmd!("filter.render.differenceClouds", "Difference Clouds", ["Filter", "Render"], r##"{"seed":u32=0,"foreground":json,"background":json}"##),
|
||||
cmd!(
|
||||
"filter.render.fibers",
|
||||
"Fibers…",
|
||||
|
||||
@@ -314,7 +314,7 @@ pub fn apply_smart_filters(placed: &Surface, sm: &SmartObject, canvas: Rect) ->
|
||||
// Edge pixels repeat at the canvas ∪ placed-content edge, as for layer filters.
|
||||
let extent = canvas.union(&placed.content_bounds());
|
||||
for f in sm.smart_filters.iter().filter(|f| f.visible) {
|
||||
cur = apply_smart_filter(f, &cur, canvas, extent)?;
|
||||
cur = apply_smart_filter(f, &cur, filter_bounds(f, placed, canvas), extent)?;
|
||||
}
|
||||
Ok(match sm.filter_mask.as_ref().filter(|m| m.enabled) {
|
||||
Some(m) => photocraft_compose::filter_mask::mix(placed, &cur, m),
|
||||
@@ -322,6 +322,21 @@ pub fn apply_smart_filters(placed: &Surface, sm: &SmartObject, canvas: Rect) ->
|
||||
})
|
||||
}
|
||||
|
||||
/// The reference bounds of smart filter `f`. Render filters work within the smart object, as
|
||||
/// Photoshop's do: Lens Flare's centre is a fraction of the object, and Clouds and Fibers fill it
|
||||
/// and size their pattern by it. The object is its placed content's bounds (which leaves out
|
||||
/// fully transparent edges of the source); the other filters use the canvas, as on a layer.
|
||||
fn filter_bounds(f: &SmartFilter, placed: &Surface, canvas: Rect) -> Rect {
|
||||
match placed.content_bounds() {
|
||||
b if renders_in_object(f) && !b.is_empty() => b,
|
||||
_ => canvas,
|
||||
}
|
||||
}
|
||||
|
||||
fn renders_in_object(f: &SmartFilter) -> bool {
|
||||
matches!(f.command.as_str(), "filter.render.clouds" | "filter.render.differenceClouds" | "filter.render.fibers" | "filter.render.lensFlare")
|
||||
}
|
||||
|
||||
/// One visible smart filter over `cur`, blended with its blend mode and opacity. `Err` when the
|
||||
/// requesting session's authority denies the filter's params: callers surface the error instead of
|
||||
/// rendering (and caching) unfiltered pixels.
|
||||
@@ -424,10 +439,18 @@ fn render_in(doc: &Document, sm: &SmartObject, ctx: &JobCtx) -> Result<Option<Su
|
||||
None => (0, placed()?),
|
||||
};
|
||||
let n = filters.len() as f32;
|
||||
// The object's bounds, found once: the placed stage may have been evicted from the cache, and
|
||||
// placing it again for every render filter would decode the source each time.
|
||||
let mut object_bounds: Option<Rect> = None;
|
||||
for (i, (f, key)) in filters.iter().zip(&keys).enumerate().skip(done) {
|
||||
ctx.check()?;
|
||||
ctx.progress(i as f32 / n, "");
|
||||
cur = Stage { surface: apply_smart_filter(f, &cur.surface, canvas, cur.extent)?, extent: cur.extent };
|
||||
let bounds = match object_bounds {
|
||||
_ if !renders_in_object(f) => canvas,
|
||||
Some(b) => b,
|
||||
None => *object_bounds.insert(filter_bounds(f, &placed()?.surface, canvas)),
|
||||
};
|
||||
cur = Stage { surface: apply_smart_filter(f, &cur.surface, bounds, cur.extent)?, extent: cur.extent };
|
||||
stack_cache::put(*key, &cur);
|
||||
}
|
||||
ctx.progress(1.0, "");
|
||||
|
||||
@@ -1139,3 +1139,83 @@ fn displace_smart_filter_reads_its_map_path_on_re_render() {
|
||||
}
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
/// Clouds and Difference Clouds on a smart object are smart filters, as in Photoshop, and keep
|
||||
/// the colours they were drawn with: re-rendering after the colours change gives the same clouds.
|
||||
#[test]
|
||||
fn clouds_on_a_smart_object_are_smart_filters_with_their_colours() {
|
||||
for depth in DEPTHS {
|
||||
let mut s = session(depth);
|
||||
paint(&mut s);
|
||||
s.execute("filter.convertForSmartFilters", json!({})).unwrap();
|
||||
s.tools.foreground = [1.0, 0.0, 0.0, 1.0];
|
||||
s.tools.background = [0.0, 0.0, 1.0, 1.0];
|
||||
s.execute("filter.render.clouds", json!({"seed": 5})).unwrap();
|
||||
s.execute("filter.render.differenceClouds", json!({"seed": 9})).unwrap();
|
||||
let sm = active_smart(&s);
|
||||
let commands: Vec<&str> = sm.smart_filters.iter().map(|f| f.command.as_str()).collect();
|
||||
assert_eq!(commands, ["filter.render.clouds", "filter.render.differenceClouds"]);
|
||||
assert_eq!(sm.smart_filters[0].params["foreground"], json!([1.0, 0.0, 0.0, 1.0]));
|
||||
assert_eq!(sm.smart_filters[1].params["background"], json!([0.0, 0.0, 1.0, 1.0]));
|
||||
// Red-to-blue clouds, and their difference, have no green: they fill the object (painted
|
||||
// from (-6, 5) to (40, 38)) over the white background.
|
||||
let rendered = flat(&s);
|
||||
let object: Vec<[f32; 4]> = (5..38).flat_map(|y| (0..40).map(move |x| (y * W + x) as usize)).map(|i| rendered[i]).collect();
|
||||
assert!(object.iter().all(|p| p[1] < 0.02), "depth {depth}");
|
||||
assert!(max_diff(&object, &vec![object[0]; object.len()]) > 0.05, "the clouds vary");
|
||||
s.tools.foreground = [0.0, 1.0, 0.0, 1.0];
|
||||
s.execute("layer.smartFilter.setParams", json!({"index": 1, "params": {"seed": 9}})).unwrap();
|
||||
assert!(max_diff(&flat(&s), &rendered) < 1e-6, "depth {depth}: same params, same clouds");
|
||||
s.undo();
|
||||
s.undo();
|
||||
assert_eq!(active_smart(&s).smart_filters.len(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// Render filters on a smart object work within the object, as in Photoshop (and as PSD stores
|
||||
/// them): Lens Flare's centre is a fraction of the object's bounds, not of the canvas.
|
||||
#[test]
|
||||
fn lens_flare_centres_on_the_smart_object() {
|
||||
let mut s = session(8);
|
||||
let block = Rect::new(32, 24, W, H);
|
||||
s.edit("setup", |doc, active| {
|
||||
let surf = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap();
|
||||
let fmt = surf.format();
|
||||
let px = photocraft_raster::from_rgba(&fmt, [0.1, 0.1, 0.1, 1.0]);
|
||||
surf.write_region(block, &px.repeat((block.width() * block.height()) as usize));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
convert(&mut s);
|
||||
s.execute("filter.render.lensFlare", json!({"centerX": 0.5, "centerY": 0.5, "lens": "prime105"})).unwrap();
|
||||
// The centre of the brightest pixels inside the object (the canvas around it is white).
|
||||
let px = flat(&s);
|
||||
let inside: Vec<(i32, i32, f32)> =
|
||||
(block.y0..block.y1).flat_map(|y| (block.x0..block.x1).map(move |x| (x, y))).map(|(x, y)| (x, y, px[(y * W + x) as usize][1])).collect();
|
||||
let peak = inside.iter().map(|p| p.2).fold(0.0, f32::max);
|
||||
let core: Vec<_> = inside.iter().filter(|p| p.2 >= peak - 0.02).collect();
|
||||
let (x, y) = (core.iter().map(|p| p.0).sum::<i32>() / core.len() as i32, core.iter().map(|p| p.1).sum::<i32>() / core.len() as i32);
|
||||
assert!((x - 48).abs() <= 1 && (y - 36).abs() <= 1, "flare at {x},{y}, the object's centre is 48,36");
|
||||
}
|
||||
|
||||
/// Moving a smart object moves its Clouds and Fibers with it: the pattern is anchored at the
|
||||
/// object, not at the canvas, so re-rendering after the move doesn't change the texture.
|
||||
#[test]
|
||||
fn clouds_and_fibers_move_with_the_smart_object() {
|
||||
for (command, params) in [("filter.render.clouds", json!({"seed": 3})), ("filter.render.fibers", json!({"seed": 3}))] {
|
||||
let mut s = session(8);
|
||||
paint(&mut s);
|
||||
let id = convert(&mut s);
|
||||
s.execute(command, params).unwrap();
|
||||
let before = flat(&s);
|
||||
s.execute("edit.transform", json!({"layer": id, "matrix": [1, 0, 0, 1, 8, 6]})).unwrap();
|
||||
let after = flat(&s);
|
||||
// Inside the object (painted from (-6, 5) to (40, 38)) both before and after the move.
|
||||
for y in 8..30 {
|
||||
for x in 2..30 {
|
||||
let (a, b) = (before[(y * W + x) as usize], after[((y + 6) * W + x + 8) as usize]);
|
||||
assert!((0..4).all(|c| (a[c] - b[c]).abs() < 1e-3), "{command} at {x},{y}: {a:?} vs {b:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+145
-3
@@ -144,7 +144,7 @@ const fn code(c: &[u8; 4]) -> i32 {
|
||||
i32::from_be_bytes(*c)
|
||||
}
|
||||
|
||||
const KNOWN: [Known; 14] = [
|
||||
const KNOWN: [Known; 18] = [
|
||||
Known { class: "GsnB", filter_id: code(b"GsnB"), name: "Gaussian Blur...", command: "filter.blur.gaussianBlur" },
|
||||
Known { class: "boxblur", filter_id: 840, name: "Box Blur...", command: "filter.blur.boxBlur" },
|
||||
Known { class: "MtnB", filter_id: code(b"MtnB"), name: "Motion Blur...", command: "filter.blur.motionBlur" },
|
||||
@@ -160,8 +160,17 @@ const KNOWN: [Known; 14] = [
|
||||
Known { class: "Crvs", filter_id: code(b"Crvs"), name: "Curves...", command: "image.adjustments.curves" },
|
||||
// Shadows/Highlights at its defaults stores no `Fltr` (`hasoptions` false).
|
||||
Known { class: "adaptCorrect", filter_id: 781, name: "Shado&ws/Highlights...", command: "image.adjustments.shadowsHighlights" },
|
||||
Known { class: "LnsF", filter_id: code(b"LnsF"), name: "Lens Flare...", command: "filter.render.lensFlare" },
|
||||
// These three also read the item's foreground and background colours (`coloured_params`).
|
||||
Known { class: "Fbrs", filter_id: code(b"Fbrs"), name: "Fibers...", command: "filter.render.fibers" },
|
||||
Known { class: "Clds", filter_id: code(b"Clds"), name: "Clouds", command: "filter.render.clouds" },
|
||||
Known { class: "DfrC", filter_id: code(b"DfrC"), name: "Difference Clouds", command: "filter.render.differenceClouds" },
|
||||
];
|
||||
|
||||
/// Lens Flare's `Lns ` enum and our `lens` values. Photoshop's codes keep the old lens names:
|
||||
/// Nikon 35 mm and 105 mm primes, a Panavision movie prime.
|
||||
const LENSES: [(&[u8; 4], &str); 4] = [(b"Zm ", "zoom"), (b"Nkn ", "prime35"), (b"Nkn1", "prime105"), (b"PnVs", "moviePrime")];
|
||||
|
||||
fn known_by_command(command: &str) -> Option<&'static Known> {
|
||||
KNOWN.iter().find(|k| k.command == command)
|
||||
}
|
||||
@@ -282,6 +291,12 @@ fn known_params(class: &str, f: Option<&Descriptor>) -> Option<(&'static str, J)
|
||||
}
|
||||
("Msc ", Some(f)) => json!({"cellSize": px(f, "ClSz")?}),
|
||||
("Embs", Some(f)) => json!({"angle": int(f, "Angl")?, "height": int(f, "Hght")?, "amount": int(f, "Amnt")?}),
|
||||
("LnsF", Some(f)) => {
|
||||
let centre = get_desc(f, "FlrC")?;
|
||||
let lens = enum_of(f, "Lns ")?;
|
||||
let lens = LENSES.iter().find(|(c, _)| lens == &c[..])?.1;
|
||||
json!({"brightness": int(f, "Brgh")?, "centerX": px(centre, "Hrzn")?, "centerY": px(centre, "Vrtc")?, "lens": lens})
|
||||
}
|
||||
("Lvls", Some(f)) => levels_params(f)?,
|
||||
("Crvs", Some(f)) => curves_params(f)?,
|
||||
_ => return None,
|
||||
@@ -322,6 +337,26 @@ fn rgbc_colour(d: &Descriptor) -> Option<J> {
|
||||
Some(json!([c("Rd ")?, c("Grn ")?, c("Bl ")?, 1.0]))
|
||||
}
|
||||
|
||||
/// Fibers, Clouds and Difference Clouds draw with the item's foreground and background colours:
|
||||
/// their params are the `Fltr` settings plus those colours.
|
||||
fn coloured_params(class: &str, item: &Descriptor, f: &Descriptor) -> Option<(&'static str, J)> {
|
||||
let k = KNOWN.iter().find(|k| k.class == class)?;
|
||||
let colour = |key: &str| get_desc(item, key).and_then(rgbc_colour);
|
||||
// The seeds (`RndS`, `FlRs`) are signed longs; ours is their bit pattern.
|
||||
let mut p = match class {
|
||||
"Fbrs" => json!({"variance": int(f, "Vrnc")?, "strength": int(f, "Strg")?, "seed": int(f, "RndS")? as u32}),
|
||||
_ => json!({"seed": int(f, "FlRs")? as u32}),
|
||||
};
|
||||
let o = p.as_object_mut()?;
|
||||
o.insert("foreground".into(), colour("FrgC")?);
|
||||
o.insert("background".into(), colour("BckC")?);
|
||||
Some((k.command, p))
|
||||
}
|
||||
|
||||
fn seed_param(p: &J) -> Value {
|
||||
Value::Integer(p.get("seed").and_then(J::as_u64).and_then(|n| u32::try_from(n).ok()).unwrap_or(0) as i32)
|
||||
}
|
||||
|
||||
/// `filter.filterGallery` params for a `GEfc` filter item; `None` when an effect or setting is
|
||||
/// not modelled.
|
||||
fn gallery_params(item: &Descriptor, f: &Descriptor) -> Option<J> {
|
||||
@@ -470,6 +505,7 @@ pub fn filter_from_item(item: &Descriptor) -> SmartFilter {
|
||||
Some(camera_raw::CLASS) => camera_raw::import_params(item).map(|p| (camera_raw::COMMAND, p)),
|
||||
Some(displace::CLASS) => displace::import_params(item).map(|p| (displace::COMMAND, p)),
|
||||
Some(GALLERY_CLASS) => fltr.and_then(|f| gallery_params(item, f)).map(|p| (GALLERY_COMMAND, p)),
|
||||
Some(c @ ("Fbrs" | "Clds" | "DfrC")) => fltr.and_then(|f| coloured_params(c, item, f)),
|
||||
c => c.and_then(|c| known_params(c, fltr)),
|
||||
};
|
||||
let (command, params) = match known {
|
||||
@@ -595,6 +631,17 @@ fn fltr_for(k: &Known, p: &J) -> Result<Option<Descriptor>, String> {
|
||||
}
|
||||
"Msc " => d.with("ClSz", unit(b"#Pxl", pf(p, "cellSize", 10.0))),
|
||||
"Embs" => d.with("Angl", pi(p, "angle", 135.0)).with("Hght", pi(p, "height", 3.0)).with("Amnt", pi(p, "amount", 100.0)),
|
||||
"LnsF" => {
|
||||
let lens = p.get("lens").and_then(J::as_str).unwrap_or("zoom");
|
||||
let code = LENSES.iter().find(|(_, l)| *l == lens).ok_or_else(|| format!("lens `{lens}` has no PSD equivalent"))?.0;
|
||||
let mut centre = Descriptor::new("Pnt ").with("Hrzn", Value::Double(pf(p, "centerX", 0.5))).with("Vrtc", Value::Double(pf(p, "centerY", 0.5)));
|
||||
centre.name = UnicodeString::new_nul("");
|
||||
d.with("Brgh", pi(p, "brightness", 100.0))
|
||||
.with("FlrC", Value::Descriptor(centre))
|
||||
.with("Lns ", Value::Enumerated { type_id: Id::new("Lns "), value: Id::Code(*code) })
|
||||
}
|
||||
"Fbrs" => d.with("Vrnc", pi(p, "variance", 16.0)).with("Strg", pi(p, "strength", 4.0)).with("RndS", seed_param(p)),
|
||||
"Clds" | "DfrC" => d.with("FlRs", seed_param(p)),
|
||||
"Lvls" => d.with("Adjs", adjustments(p, false)?),
|
||||
"Crvs" => d.with("Adjs", adjustments(p, true)?),
|
||||
"adaptCorrect" => {
|
||||
@@ -633,19 +680,40 @@ pub fn item_for_filter(f: &SmartFilter) -> Result<Descriptor, String> {
|
||||
}
|
||||
let k = known_by_command(&f.command).ok_or("this filter has no PSD equivalent")?;
|
||||
let fltr = fltr_for(k, &f.params)?;
|
||||
// Fibers and the clouds draw with the colours stored on the item; the others store
|
||||
// Photoshop's defaults.
|
||||
let coloured = matches!(k.class, "Fbrs" | "Clds" | "DfrC");
|
||||
let (fg, bg) =
|
||||
if coloured { (colour_rgbc(f.params.get("foreground"), 0.0)?, colour_rgbc(f.params.get("background"), 255.0)?) } else { (rgbc(0.0), rgbc(255.0)) };
|
||||
// The render filters are written with the descriptor names Photoshop gives them: the filter's
|
||||
// own name on `Fltr` and empty ones on the colours.
|
||||
let render = coloured || k.class == "LnsF";
|
||||
let (fltr, fg, bg) = if render { (fltr.map(|f| named(f, k.name.trim_end_matches("..."))), named_value(fg), named_value(bg)) } else { (fltr, fg, bg) };
|
||||
let mut d = Descriptor::new("filterFX")
|
||||
.with("Nm ", Value::Text(UnicodeString::new_nul(k.name)))
|
||||
.with("blendOptions", blend_options(f))
|
||||
.with("enab", Value::Boolean(f.visible))
|
||||
.with("hasoptions", Value::Boolean(fltr.is_some()))
|
||||
.with("FrgC", rgbc(0.0))
|
||||
.with("BckC", rgbc(255.0));
|
||||
.with("FrgC", fg)
|
||||
.with("BckC", bg);
|
||||
if let Some(x) = fltr {
|
||||
d = d.with("Fltr", Value::Descriptor(x));
|
||||
}
|
||||
Ok(d.with("filterID", Value::Integer(k.filter_id)))
|
||||
}
|
||||
|
||||
fn named(mut d: Descriptor, name: &str) -> Descriptor {
|
||||
d.name = UnicodeString::new_nul(name);
|
||||
d
|
||||
}
|
||||
|
||||
fn named_value(v: Value) -> Value {
|
||||
match v {
|
||||
Value::Descriptor(d) => Value::Descriptor(named(d, "")),
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds a `filterFX` object; filters that can't be written are left out, with a message each.
|
||||
pub fn filter_fx(stack: &FilterStack, layer: &str, warnings: &mut Vec<String>) -> Descriptor {
|
||||
let mut list = Vec::new();
|
||||
@@ -1774,4 +1842,78 @@ mod tests {
|
||||
assert_eq!(u, uuid_from(b"x"));
|
||||
assert_ne!(u, uuid_from(b"y"));
|
||||
}
|
||||
|
||||
// Render filters as Photoshop 27 saves them on a smart object (`filterFXList` items, with
|
||||
// neutral blending): Clouds and Difference Clouds in white on black, Fibers in black on white,
|
||||
// Lens Flare with the 50-300mm Zoom at 159%.
|
||||
const PHOTOSHOP_CLOUDS: &str = "0000000100000000000866696c746572465800000008000000004e6d202054455854000000070043006c006f00750064007300000000000c626c656e644f7074696f6e734f626a63000000000000000c626c656e644f7074696f6e7300000002000000004f706374556e7446235072634059000000000000000000004d642020656e756d00000000426c6e4d000000066e6f726d616c00000000656e6162626f6f6c010000000a6861736f7074696f6e73626f6f6c0100000000467267434f626a630000000100000000000052474243000000030000000052642020646f7562406fe000000000000000000047726e20646f7562406fe0000000000000000000426c2020646f7562406fe000000000000000000042636b434f626a630000000100000000000052474243000000030000000052642020646f756200000000000000000000000047726e20646f7562000000000000000000000000426c2020646f7562000000000000000000000000466c74724f626a63000000070043006c006f007500640073000000000000436c64730000000100000000466c52736c6f6e67000049e40000000866696c74657249446c6f6e67436c6473";
|
||||
const PHOTOSHOP_DIFFERENCE_CLOUDS: &str = "0000000100000000000866696c746572465800000008000000004e6d202054455854000000120044006900660066006500720065006e0063006500200043006c006f00750064007300000000000c626c656e644f7074696f6e734f626a63000000000000000c626c656e644f7074696f6e7300000002000000004f706374556e7446235072634059000000000000000000004d642020656e756d00000000426c6e4d000000066e6f726d616c00000000656e6162626f6f6c010000000a6861736f7074696f6e73626f6f6c0100000000467267434f626a630000000100000000000052474243000000030000000052642020646f7562406fe000000000000000000047726e20646f7562406fe0000000000000000000426c2020646f7562406fe000000000000000000042636b434f626a630000000100000000000052474243000000030000000052642020646f756200000000000000000000000047726e20646f7562000000000000000000000000426c2020646f7562000000000000000000000000466c74724f626a63000000120044006900660066006500720065006e0063006500200043006c006f007500640073000000000000446672430000000100000000466c52736c6f6e67000057d20000000866696c74657249446c6f6e6744667243";
|
||||
const PHOTOSHOP_FIBERS: &str = "0000000100000000000866696c746572465800000008000000004e6d2020544558540000000a004600690062006500720073002e002e002e00000000000c626c656e644f7074696f6e734f626a63000000000000000c626c656e644f7074696f6e7300000002000000004f706374556e7446235072634059000000000000000000004d642020656e756d00000000426c6e4d000000066e6f726d616c00000000656e6162626f6f6c010000000a6861736f7074696f6e73626f6f6c0100000000467267434f626a630000000100000000000052474243000000030000000052642020646f756200000000000000000000000047726e20646f7562000000000000000000000000426c2020646f756200000000000000000000000042636b434f626a630000000100000000000052474243000000030000000052642020646f7562406fe000000000000000000047726e20646f7562406fe0000000000000000000426c2020646f7562406fe0000000000000000000466c74724f626a630000000700460069006200650072007300000000000046627273000000030000000056726e636c6f6e670000001000000000537472676c6f6e670000000400000000526e64536c6f6e67000062f10000000866696c74657249446c6f6e6746627273";
|
||||
const PHOTOSHOP_LENS_FLARE: &str = "0000000100000000000866696c746572465800000008000000004e6d2020544558540000000e004c0065006e007300200046006c006100720065002e002e002e00000000000c626c656e644f7074696f6e734f626a63000000000000000c626c656e644f7074696f6e7300000002000000004f706374556e7446235072634059000000000000000000004d642020656e756d00000000426c6e4d000000066e6f726d616c00000000656e6162626f6f6c010000000a6861736f7074696f6e73626f6f6c0100000000467267434f626a630000000100000000000052474243000000030000000052642020646f756200000000000000000000000047726e20646f7562000000000000000000000000426c2020646f756200000000000000000000000042636b434f626a630000000100000000000052474243000000030000000052642020646f7562406fe000000000000000000047726e20646f7562406fe0000000000000000000426c2020646f7562406fe0000000000000000000466c74724f626a630000000b004c0065006e007300200046006c0061007200650000000000004c6e73460000000300000000427267686c6f6e670000009f00000000466c72434f626a6300000001000000000000506e7420000000020000000048727a6e646f75623fe86666600000000000000056727463646f75623fe60b60c0000000000000004c6e7320656e756d000000004c6e7320000000005a6d20200000000866696c74657249446c6f6e674c6e7346";
|
||||
|
||||
fn photoshop(hex: &str) -> Descriptor {
|
||||
Descriptor::from_bytes(&from_hex(hex).unwrap()).unwrap()
|
||||
}
|
||||
|
||||
fn set_lens(item: &mut Descriptor, code: [u8; 4]) {
|
||||
let Some(Value::Descriptor(fltr)) = item.items.iter_mut().find(|(k, _)| k.is("Fltr")).map(|(_, v)| v) else { panic!("no Fltr") };
|
||||
set(fltr, "Lns ", Value::Enumerated { type_id: Id::new("Lns "), value: Id::Code(code) });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn photoshop_render_filters_read_and_write_like_photoshop() {
|
||||
let colours = |fg: f64, bg: f64| (json!([fg, fg, fg, 1.0]), json!([bg, bg, bg, 1.0]));
|
||||
let (white, black) = colours(1.0, 0.0);
|
||||
let cases = [
|
||||
(PHOTOSHOP_CLOUDS, "filter.render.clouds", json!({"seed": 18916, "foreground": white, "background": black})),
|
||||
(PHOTOSHOP_DIFFERENCE_CLOUDS, "filter.render.differenceClouds", json!({"seed": 22482, "foreground": white, "background": black})),
|
||||
(PHOTOSHOP_FIBERS, "filter.render.fibers", json!({"variance": 16, "strength": 4, "seed": 25329, "foreground": black, "background": white})),
|
||||
(
|
||||
PHOTOSHOP_LENS_FLARE,
|
||||
"filter.render.lensFlare",
|
||||
json!({"brightness": 159, "centerX": 0.762499988079071, "centerY": 0.6888889074325562, "lens": "zoom"}),
|
||||
),
|
||||
];
|
||||
for (hex, command, params) in cases {
|
||||
let item = photoshop(hex);
|
||||
let f = filter_from_item(&item);
|
||||
assert_eq!((f.command.as_str(), &f.params), (command, ¶ms));
|
||||
// Written back, it is Photoshop's item again: name, colours, settings and key order.
|
||||
assert_eq!(item_for_filter(&f).unwrap().items, item.items, "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_lens_flare_lens_round_trips_with_photoshops_code() {
|
||||
for (code, lens) in LENSES {
|
||||
let mut item = photoshop(PHOTOSHOP_LENS_FLARE);
|
||||
set_lens(&mut item, *code);
|
||||
let f = filter_from_item(&item);
|
||||
assert_eq!(f.params["lens"], lens);
|
||||
assert_eq!(item_for_filter(&f).unwrap().items, item.items, "{lens}");
|
||||
}
|
||||
// A lens we don't know keeps the filter verbatim.
|
||||
let mut item = photoshop(PHOTOSHOP_LENS_FLARE);
|
||||
set_lens(&mut item, *b"Xxxx");
|
||||
assert_eq!(filter_from_item(&item).command, UNSUPPORTED_FILTER);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_filters_made_in_photocraft_are_written() {
|
||||
// Without colours (an older document or a script), Photoshop's default black and white.
|
||||
let back = filter_from_item(&item_for_filter(&sf("filter.render.clouds", json!({"seed": 7}))).unwrap());
|
||||
assert_eq!(back.params, json!({"seed": 7, "foreground": [0.0, 0.0, 0.0, 1.0], "background": [1.0, 1.0, 1.0, 1.0]}));
|
||||
// A seed above i32::MAX keeps its bit pattern, and colours may be hex.
|
||||
let p = json!({"variance": 30, "strength": 10, "seed": 4_000_000_000u32, "foreground": "#ff0000", "background": [0.0, 0.0, 1.0, 1.0]});
|
||||
let back = filter_from_item(&item_for_filter(&sf("filter.render.fibers", p)).unwrap());
|
||||
assert_eq!(
|
||||
back.params,
|
||||
json!({"variance": 30, "strength": 10, "seed": 4_000_000_000u32, "foreground": [1.0, 0.0, 0.0, 1.0], "background": [0.0, 0.0, 1.0, 1.0]})
|
||||
);
|
||||
let flare = sf("filter.render.lensFlare", json!({"brightness": 120, "centerX": 0.25, "centerY": 0.75, "lens": "moviePrime"}));
|
||||
assert_eq!(filter_from_item(&item_for_filter(&flare).unwrap()).params, flare.params);
|
||||
// Lenses and colours we can't write are reported, not guessed.
|
||||
assert!(item_for_filter(&sf("filter.render.lensFlare", json!({"lens": "fisheye"}))).unwrap_err().contains("fisheye"));
|
||||
assert!(item_for_filter(&sf("filter.render.clouds", json!({"foreground": "red"}))).is_err());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# File-format parity
|
||||
|
||||
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-15 · **Change:** minor (Photoshop mixed-order TIFF type geometry, #4758; DDS textures save: uncompressed or BC1–BC3, optional mip chain, DDS Options in Save As (#1327); 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 (Photoshop mixed-order TIFF type geometry, #4758; PSD smart filters: Clouds, Difference Clouds, Fibers and Lens Flare open as editable filters; DDS textures save: uncompressed or BC1–BC3, optional mip chain, DDS Options in Save As (#1327); 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 (18 mapped, among them Clouds, Difference Clouds, Fibers and Lens Flare, 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) |
|
||||
| PSB | R/W | yes | yes | Auto-switches above 2 GB (REL-212-2); 4–5 GB fixtures generated (FILE-216-2); > 4 GB fails 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, including Photoshop mixed-order type blocks (#4758); undecodable type keeps saved pixels (FILE-215-7: extra alpha channels not written) |
|
||||
@@ -142,6 +142,7 @@ remaining gaps in #1606 stay tracked with per-sample corpus ceilings.
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-15 | minor | PSD smart filters: Clouds, Difference Clouds, Fibers and Lens Flare open as editable filters with their seeds, colours and lens, and save like Photoshop (checked against a Photoshop 27 file); render filters on a smart object work within the object, so a flare sits where Photoshop puts it |
|
||||
| 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-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) |
|
||||
|
||||
Reference in new issue
Block a user