PhotoCraft: An open-source, photo editor written by scratch in pure Rust
PSD: a smart object's filter mask shows when the file opens (#5005)
Timothy Daly4e1e325b1713
diff --git a/crates/compose/src/filter_mask.rs b/crates/compose/src/filter_mask.rsnew file mode 100644index 000000000..b84572045--- /dev/null+++ b/crates/compose/src/filter_mask.rs@@ -0,0 +1,191 @@+//! A smart object's filter mask (#215): how the filtered pixels and the unfiltered (placed) ones+//! combine.+//!+//! Photoshop stores a smart object's layer pixels with its filters applied but not its filter+//! mask, and mixes the unfiltered pixels back in through the mask when it composites (photoshop+//! corpus `sf-filter-mask-hard.psd` and `sf-filter-mask-gradient.psd`: the stored pixels are+//! filtered everywhere, the merged image only where the mask shows the filter). Our smart objects+//! keep the mixed result as their pixels, so PSD import mixes ([`mix`]) and export unmixes+//! ([`unmix`]).++use photocraft_doc::LayerMask;+use photocraft_raster::Surface;++/// `filtered` mixed over `base` (the unfiltered pixels) through `mask`: premultiplied, any+/// channel layout. Pixels the mask hides entirely are `base`'s.+pub fn mix(base: &Surface, filtered: &Surface, mask: &LayerMask) -> Surface {+ let fmt = base.format();+ let area = base.content_bounds().union(&filtered.content_bounds());+ let mut out = filtered.clone();+ if area.is_empty() || filtered.format() != fmt {+ return out;+ }+ let n = fmt.channels();+ let (b, f) = (base.read_region(area), filtered.read_region(area));+ let mut k = Vec::new();+ mask.values_into(area, &mut k);+ let mut o = vec![0.0f32; b.len()];+ for (i, ((bp, fp), op)) in b.chunks_exact(n).zip(f.chunks_exact(n)).zip(o.chunks_exact_mut(n)).enumerate() {+ let m = k.get(i).copied().unwrap_or(1.0).clamp(0.0, 1.0);+ if !fmt.alpha {+ for c in 0..n {+ op[c] = bp[c] + (fp[c] - bp[c]) * m;+ }+ continue;+ }+ let a = n - 1;+ let oa = bp[a] + (fp[a] - bp[a]) * m;+ op[a] = oa;+ for c in 0..a {+ let pm = bp[c] * bp[a] + (fp[c] * fp[a] - bp[c] * bp[a]) * m;+ op[c] = if oa > 0.0 { (pm / oa).clamp(0.0, 1.0) } else { 0.0 };+ }+ }+ out.write_region(area, &o);+ out.prune();+ out+}++/// The mask value below which a pixel's filtered value is taken to be unknown: [`unmix`] gives the+/// unfiltered value there, which the mask shows (almost) none of anyway.+const HIDDEN: f32 = 1.0 / 1024.0;++/// The inverse of [`mix`]: the filtered pixels that mix with `base` through `mask` to `mixed`+/// (clamped to 0..1). Where the mask hides the filter entirely they are `base`'s, which Photoshop+/// doesn't show there.+pub fn unmix(base: &Surface, mixed: &Surface, mask: &LayerMask) -> Surface {+ let fmt = base.format();+ let area = base.content_bounds().union(&mixed.content_bounds());+ let mut out = mixed.clone();+ if area.is_empty() || mixed.format() != fmt {+ return out;+ }+ let n = fmt.channels();+ let (b, x) = (base.read_region(area), mixed.read_region(area));+ let mut k = Vec::new();+ mask.values_into(area, &mut k);+ let mut o = vec![0.0f32; b.len()];+ for (i, ((bp, xp), op)) in b.chunks_exact(n).zip(x.chunks_exact(n)).zip(o.chunks_exact_mut(n)).enumerate() {+ let m = k.get(i).copied().unwrap_or(1.0).clamp(0.0, 1.0);+ if m < HIDDEN {+ // A transparent base pixel (Photoshop's cache keeps white there) stays empty, so the+ // stored pixels don't grow past the content.+ if !fmt.alpha || bp[n - 1] > 0.0 {+ op.copy_from_slice(bp);+ }+ continue;+ }+ if !fmt.alpha {+ for c in 0..n {+ op[c] = (bp[c] + (xp[c] - bp[c]) / m).clamp(0.0, 1.0);+ }+ continue;+ }+ let a = n - 1;+ let fa = (bp[a] + (xp[a] - bp[a]) / m).clamp(0.0, 1.0);+ if fa <= 0.0 {+ continue;+ }+ op[a] = fa;+ for c in 0..a {+ let pm = bp[c] * bp[a] + (xp[c] * xp[a] - bp[c] * bp[a]) / m;+ op[c] = (pm / fa).clamp(0.0, 1.0);+ }+ }+ out.write_region(area, &o);+ out.prune();+ out+}++#[cfg(test)]+mod tests {+ use photocraft_color::{ColorMode, PixelFormat, SampleType};+ use photocraft_doc::LayerMask;+ use photocraft_raster::Surface;++ use super::*;++ fn surface(fmt: PixelFormat, f: impl Fn(i32, i32) -> Vec<f32>) -> Surface {+ let mut s = Surface::new(fmt);+ for y in 0..4 {+ for x in 0..8 {+ s.write_pixel(x, y, &f(x, y));+ }+ }+ s+ }++ /// A mask ramping from hidden (left) to shown (right).+ fn ramp() -> LayerMask {+ let mut m = LayerMask::reveal_all();+ m.surface = surface(PixelFormat::new(ColorMode::Grayscale, SampleType::F32, false), |x, _| vec![x as f32 / 7.0]);+ m+ }++ #[test]+ fn unmix_inverts_mix_wherever_the_mask_shows_the_filter() {+ for fmt in [PixelFormat::new(ColorMode::Rgb, SampleType::F32, true), PixelFormat::new(ColorMode::Rgb, SampleType::F32, false)] {+ let base = surface(fmt, |x, y| {+ let mut p = vec![0.2 + 0.05 * x as f32, 0.6, 0.1 * y as f32];+ if fmt.alpha {+ p.push(0.5 + 0.06 * x as f32);+ }+ p+ });+ let filtered = surface(fmt, |_, y| {+ let mut p = vec![0.9 - 0.1 * y as f32, 0.3, 0.5];+ if fmt.alpha {+ p.push(0.8);+ }+ p+ });+ let m = ramp();+ let mixed = mix(&base, &filtered, &m);+ // Hidden column: the unfiltered pixels; shown column: the filtered ones.+ assert!(mixed.pixel(0, 2).iter().zip(base.pixel(0, 2)).all(|(a, b)| (a - b).abs() < 1e-6));+ assert!(mixed.pixel(7, 2).iter().zip(filtered.pixel(7, 2)).all(|(a, b)| (a - b).abs() < 1e-6));+ let back = unmix(&base, &mixed, &m);+ for y in 0..4 {+ for x in 1..8 {+ let (g, w) = (back.pixel(x, y), filtered.pixel(x, y));+ assert!(g.iter().zip(&w).all(|(a, b)| (a - b).abs() < 1e-4), "{fmt:?} ({x}, {y}): {g:?} vs {w:?}");+ }+ // Where the mask hides the filter entirely its value is unknown: the base stands in.+ assert_eq!(back.pixel(0, y), base.pixel(0, y));+ }+ // So mixing the unmixed pixels gives the mixed ones back everywhere.+ let again = mix(&base, &back, &m);+ for y in 0..4 {+ for x in 0..8 {+ assert!(again.pixel(x, y).iter().zip(mixed.pixel(x, y)).all(|(a, b)| (a - b).abs() < 1e-4));+ }+ }+ }+ }++ #[test]+ fn transparent_base_pixels_stay_empty() {+ // Photoshop's unfiltered cache carries white in transparent pixels; where the mask hides+ // the filter those must not become content of the stored pixels.+ let fmt = PixelFormat::new(ColorMode::Rgb, SampleType::U8, true);+ let base = surface(fmt, |x, _| if x < 4 { vec![1.0, 1.0, 1.0, 0.0] } else { vec![0.3, 0.4, 0.5, 1.0] });+ let mut hidden = LayerMask::reveal_all();+ hidden.surface = Surface::with_default(PixelFormat::GRAY8, &[0.0]);+ let mixed = mix(&base, &base, &hidden);+ let back = unmix(&base, &mixed, &hidden);+ assert_eq!(back.pixel(1, 1), vec![0.0; 4]);+ assert_eq!(back.content_bounds().x0, 4);+ }++ #[test]+ fn mismatched_or_empty_surfaces_are_left_alone() {+ let rgba = PixelFormat::new(ColorMode::Rgb, SampleType::U8, true);+ let gray = PixelFormat::new(ColorMode::Grayscale, SampleType::U8, true);+ let a = surface(rgba, |_, _| vec![0.5, 0.5, 0.5, 1.0]);+ let b = surface(gray, |_, _| vec![0.1, 1.0]);+ assert_eq!(mix(&a, &b, &ramp()), b);+ assert_eq!(unmix(&a, &b, &ramp()), b);+ let empty = Surface::new(rgba);+ assert_eq!(unmix(&empty, &empty, &ramp()), empty);+ }+}diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rsindex 31153867e..f688ffedb 100644--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@ -21,6 +21,7 @@ pub mod advanced;pub mod bounds;pub mod effects;pub mod fill_layout;+pub mod filter_mask;pub mod gradient_fill;pub mod masks;pub mod multichannel;diff --git a/crates/engine/src/smart_cmds.rs b/crates/engine/src/smart_cmds.rsindex 649a15441..e2c1cf2bf 100644--- a/crates/engine/src/smart_cmds.rs+++ b/crates/engine/src/smart_cmds.rs@@ -298,40 +298,6 @@ fn blend_surfaces(base: &Surface, top: &Surface, mode: BlendMode, opacity: f32)out}-/// Mixes `filtered` over `base` through the filter mask (premultiplied, any channel layout).-fn mask_mix(base: &Surface, filtered: &Surface, mask: &LayerMask) -> Surface {- let fmt = base.format();- let area = base.content_bounds().union(&filtered.content_bounds());- let mut out = filtered.clone();- if area.is_empty() {- return out;- }- let n = fmt.channels();- let (b, f) = (base.read_region(area), filtered.read_region(area));- let mut k = Vec::new();- mask.values_into(area, &mut k);- let mut o = vec![0.0f32; b.len()];- for (i, ((bp, fp), op)) in b.chunks_exact(n).zip(f.chunks_exact(n)).zip(o.chunks_exact_mut(n)).enumerate() {- let m = k.get(i).copied().unwrap_or(1.0).clamp(0.0, 1.0);- if !fmt.alpha {- for c in 0..n {- op[c] = bp[c] + (fp[c] - bp[c]) * m;- }- continue;- }- let a = n - 1;- let oa = bp[a] + (fp[a] - bp[a]) * m;- op[a] = oa;- for c in 0..a {- let pm = bp[c] * bp[a] + (fp[c] * fp[a] - bp[c] * bp[a]) * m;- op[c] = if oa > 0.0 { (pm / oa).clamp(0.0, 1.0) } else { 0.0 };- }- }- out.write_region(area, &o);- out.prune();- out-}-/// Runs the smart filter stack on the placed (unfiltered) content.pub fn apply_smart_filters(placed: &Surface, sm: &SmartObject, canvas: Rect) -> Surface {if !sm.filters_enabled || !sm.smart_filters.iter().any(|f| f.visible) {@@ -344,7 +310,7 @@ pub fn apply_smart_filters(placed: &Surface, sm: &SmartObject, canvas: Rect) ->cur = apply_smart_filter(f, &cur, canvas, extent);}match sm.filter_mask.as_ref().filter(|m| m.enabled) {- Some(m) => mask_mix(placed, &cur, m),+ Some(m) => photocraft_compose::filter_mask::mix(placed, &cur, m),None => cur,}}@@ -449,7 +415,7 @@ fn render_in(doc: &Document, sm: &SmartObject, ctx: &JobCtx) -> Result<Option<Su}ctx.progress(1.0, "");Ok(Some(match sm.filter_mask.as_ref().filter(|m| m.enabled) {- Some(m) => mask_mix(&placed()?.surface, &cur.surface, m),+ Some(m) => photocraft_compose::filter_mask::mix(&placed()?.surface, &cur.surface, m),None => cur.surface,}))}diff --git a/crates/engine/tests/smart_psd.rs b/crates/engine/tests/smart_psd.rsindex f7b86048b..2586f24cc 100644--- a/crates/engine/tests/smart_psd.rs+++ b/crates/engine/tests/smart_psd.rs@@ -615,3 +615,58 @@ fn cs2_plld_only_smart_object_saves_its_new_transform() {}assert!(photocraft_engine::smart_cmds::contents_of(&again, photocraft_doc::LayerId(aid)).is_ok(), "the contents are available");}++/// Photoshop stores a smart object's filtered pixels without its filter mask and mixes the+/// unfiltered ones back in through the mask (`compose::filter_mask`): the layer record we write+/// holds the filtered pixels wherever the mask shows any of the filter, and opening the file+/// mixes them back to what the document showed.+#[test]+fn a_soft_filter_mask_is_stored_the_way_photoshop_stores_it() {+ use photocraft_doc::LayerMask;+ use photocraft_raster::Surface;+ let mut s = session(8);+ s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap();+ s.execute("filter.blur.gaussianBlur", json!({"radius": 4})).unwrap();+ let id = s.active().unwrap().active_layer.unwrap();+ // A mask ramping from hiding the blur (left) to showing it (right).+ s.edit("mask", |doc, _| {+ let snapshot = doc.clone();+ let l = doc.layer_mut(id).unwrap();+ let LayerContent::Smart(sm) = &mut l.content else { panic!("smart") };+ let mut m = LayerMask::reveal_all();+ m.surface = Surface::new(photocraft_color::PixelFormat::GRAY8);+ let r = Rect::new(0, 0, W, H);+ m.surface.write_region(r, &(0..H).flat_map(|_| (0..W).map(|x| x as f32 / (W - 1) as f32)).collect::<Vec<_>>());+ sm.filter_mask = Some(m);+ refresh_layer(&snapshot, l).map(|_| ())+ })+ .unwrap();+ let doc = s.active().unwrap().doc.clone();+ let (_, sm) = smart(&doc);+ let mixed = sm.cache.clone().unwrap();+ // The same smart object with the mask switched off: filtered everywhere.+ let mut unmasked = sm.clone();+ unmasked.filter_mask.as_mut().unwrap().enabled = false;+ let filtered = photocraft_engine::smart_cmds::render(&doc, &unmasked).unwrap().unwrap();++ let out = photocraft_io::export(&doc, "psd", &Default::default()).unwrap();+ let file = photocraft_psd::PsdFile::from_bytes(&out.bytes).unwrap();+ let name = doc.layer(id).unwrap().name.clone();+ let record = (0..file.layers().len()).filter_map(|i| file.layer(i)).find(|l| l.name() == name).unwrap();+ let img = record.rgba8().unwrap();+ // A column where the mask shows about half the blur, over opaque content.+ let (x, y) = (W / 2, 20);+ let at = (((y - img.top) as u32 * img.width + (x - img.left) as u32) * 4) as usize;+ let stored = &img.data[at..at + 4];+ let want = filtered.pixel(x, y);+ let half = mixed.pixel(x, y);+ let gap = (0..3).map(|c| (want[c] - half[c]).abs()).fold(0.0f32, f32::max);+ assert!(gap > 3.0 / 255.0, "the mask's mix must show at ({x}, {y}) for this test to mean anything");+ for c in 0..3 {+ assert!((f32::from(stored[c]) / 255.0 - want[c]).abs() <= 1.5 / 255.0, "channel {c}: stored {stored:?}, filtered {want:?}, mixed {half:?}");+ }+ // Opening the file mixes the unfiltered pixels back in: it shows what the document showed.+ let back = photocraft_io::import("x.psd", &out.bytes).unwrap().document;+ 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}");+}diff --git a/crates/io/src/psd_export.rs b/crates/io/src/psd_export.rsindex 4fb952ba2..8ba30d83c 100644--- a/crates/io/src/psd_export.rs+++ b/crates/io/src/psd_export.rs@@ -164,6 +164,14 @@ struct SmartOut {keep_fx: std::collections::HashSet<String>,/// Regenerated `FEid` items.new_fx: Vec<photocraft_psd::filter_effects::FilterEffectsItem>,+ /// The unfiltered pixels of each smart object whose filter mask shows: its layer record holds+ /// the filtered pixels without the mask, as Photoshop's do (`compose::filter_mask`).+ unfiltered: std::collections::HashMap<photocraft_doc::LayerId, Surface>,+}++/// Whether a smart object's filter mask shows: enabled over at least one visible, enabled filter.+fn masked(sm: &photocraft_doc::SmartObject) -> bool {+ sm.filter_mask.as_ref().is_some_and(|m| m.enabled) && sm.filters_enabled && sm.smart_filters.iter().any(|f| f.visible)}/// `FEid` data padded to 4 bytes inside the block length: Photoshop counts the padding in the@@ -760,6 +768,12 @@ impl Ex {}if !stack.filters.is_empty() {self.smart.keep_fx.insert(t.placed.clone());+ if masked(sm) {+ let fmt = self.fmt;+ if let Some(u) = self.smart.old_fx.iter().find(|i| i.id == t.placed).and_then(|i| crate::smart_map::unfiltered_from_item(i, fmt)) {+ self.smart.unfiltered.insert(l.id, u);+ }+ }}return;}@@ -795,7 +809,14 @@ impl Ex {None => photocraft_algo::warp::place_source(&img, img_bounds, &sm.transform, sm.warp.as_ref()),};match unfiltered {- Ok(unfiltered) => crate::smart_map::feid_item(&placed, &unfiltered, sm.filter_mask.as_ref(), bounds, self.fmt),+ Ok(unfiltered) => {+ let item = crate::smart_map::feid_item(&placed, &unfiltered, sm.filter_mask.as_ref(), bounds, self.fmt);+ if item.is_some() && masked(sm) {+ let u = if unfiltered.format() == self.fmt { unfiltered } else { unfiltered.convert(self.fmt) };+ self.smart.unfiltered.insert(l.id, u);+ }+ item+ }Err(e) => {warnings.push(format!("smart filter mask was not re-rendered for PSD export ({e})"));None@@ -1072,7 +1093,12 @@ impl Ex {self.records.push(r);}LayerContent::Smart(sm) => {- let r = self.record(l, extra, sm.cache.as_ref());+ // Photoshop's record holds the filtered pixels without the filter mask.+ let unmixed = match (self.smart.unfiltered.get(&l.id), sm.cache.as_ref(), sm.filter_mask.as_ref()) {+ (Some(u), Some(c), Some(m)) if masked(sm) => Some(photocraft_compose::filter_mask::unmix(u, c, m)),+ _ => None,+ };+ let r = self.record(l, extra, unmixed.as_ref().or(sm.cache.as_ref()));self.records.push(r);}}diff --git a/crates/io/src/psd_import.rs b/crates/io/src/psd_import.rsindex c0144b66b..c20c1b7fe 100644--- a/crates/io/src/psd_import.rs+++ b/crates/io/src/psd_import.rs@@ -403,12 +403,26 @@ impl Ctx<'_> {Some(p) if !stack.filters.is_empty() => self.filter_mask(&p.placed, &stack, &name),_ => None,};+ // Photoshop stores the filtered pixels without the filter mask and mixes the unfiltered+ // ones (`FEid`) back in through it; our smart objects hold the mixed result.+ let stored = self.record_surface(rec, &name);+ let shown = stack.enabled && stack.filters.iter().any(|f| f.visible);+ let cache = match (&placed, filter_mask.as_ref().filter(|m| m.enabled && shown)) {+ (Some(p), Some(m)) => {+ let unfiltered = self.filter_effects.iter().find(|i| i.id == p.placed).and_then(|i| crate::smart_map::unfiltered_from_item(i, self.fmt));+ match unfiltered {+ Some(u) => photocraft_compose::filter_mask::mix(&u, &stored, m),+ None => stored,+ }+ }+ _ => stored,+ };LayerContent::Smart(SmartObject {contents_id,source: SmartSource::Linked { path: id },transform,smart_filters: stack.filters,- cache: Some(self.record_surface(rec, &name)),+ cache: Some(cache),psd_raw: principal(k),filters_enabled: stack.enabled,filter_mask,diff --git a/crates/io/src/smart_map.rs b/crates/io/src/smart_map.rsindex 6eeda61a1..3de336e16 100644--- a/crates/io/src/smart_map.rs+++ b/crates/io/src/smart_map.rs@@ -886,6 +886,45 @@ pub fn mask_from_item(item: &FilterEffectsItem, sample: SampleType, stack: &FiltOk(Some(LayerMask { surface, enabled: stack.mask_enabled, linked: stack.mask_linked, density: 1.0, feather: 0.0 }))}+/// The unfiltered placed pixels of an `FEid` item (the inverse of [`feid_item`]), in `fmt`: colour+/// channels from slot 0, transparency from the last slot (opaque without it). `None` when the+/// item has no colour planes, its depth isn't `fmt`'s, or a plane doesn't decode.+pub fn unfiltered_from_item(item: &FilterEffectsItem, fmt: PixelFormat) -> Option<Surface> {+ let depth = u16::try_from(item.depth).ok()?;+ if u32::from(crate::pixels::psd_depth(fmt.sample)) != item.depth || !fmt.alpha {+ return None;+ }+ let (w, h) = item.rect.size().ok()?;+ let n = w.checked_mul(h)?;+ let cc = fmt.mode.color_channels();+ let mut planes = Vec::with_capacity(cc + 1);+ for slot in (0..cc).chain(std::iter::once(item.slots.len().saturating_sub(1))) {+ planes.push(match item.slots.get(slot).and_then(Option::as_ref) {+ Some(p) => Some(p.decode(w, h, depth).ok()?),+ None if slot < cc => return None,+ None => None,+ });+ }+ let refs: Vec<Option<&[u8]>> = planes.iter().map(|p| p.as_deref()).collect();+ let mut fill = vec![crate::pixels::zero_sample(fmt.sample); cc];+ // Without a transparency plane the pixels are opaque (a native-endian full sample).+ fill.push(match fmt.sample {+ SampleType::U8 => vec![u8::MAX],+ SampleType::U16 => u16::MAX.to_ne_bytes().to_vec(),+ SampleType::F32 => 1.0f32.to_ne_bytes().to_vec(),+ });+ let mut invert = vec![fmt.mode == ColorMode::Cmyk; cc];+ invert.push(false);+ let mut bytes = crate::pixels::interleave(&refs, &fill, n, fmt.sample, &invert);+ if fmt.mode == ColorMode::Lab && fmt.sample == SampleType::U16 {+ crate::pixels::lab16_chroma(&mut bytes, cc + 1, true);+ }+ let mut surface = Surface::new(fmt);+ surface.write_interleaved(GeomRect::new(item.rect.left, item.rect.top, item.rect.right, item.rect.bottom), &bytes);+ surface.prune();+ Some(surface)+}+/// An `FEid` item for a smart object with filters: the unfiltered placed pixels Photoshop/// filters from (colour channels from slot 0, transparency in the last slot; in the document's/// pixel format, CMYK inverted as in layer channels) and the filter mask over `bounds` (whitediff --git a/crates/io/tests/corpus.rs b/crates/io/tests/corpus.rsindex a8d81a160..dd96d96c7 100644--- a/crates/io/tests/corpus.rs+++ b/crates/io/tests/corpus.rs@@ -156,7 +156,7 @@ const PSD_TOOLS: Source = Source { label: "psd-tools corpus", dir: "corpus/psd-t/// Our Photoshop-authored oracles (256 files; https://github.com/storytold/photocraft-corpus),/// grouped by feature (`smart-filters`, `effects`, `text`, `adjustments/<mode><bits>`).-const PHOTOSHOP: Source = Source { label: "photoshop oracles", dir: "corpus/photoshop", group_depth: 2, pass_floor: 185, roundtrip_floor: 258 };+const PHOTOSHOP: Source = Source { label: "photoshop oracles", dir: "corpus/photoshop", group_depth: 2, pass_floor: 188, roundtrip_floor: 258 };/// The corpus directory; a missing corpus fails the test.fn locate(src: &Source) -> PathBuf {diff --git a/docs/file-format-parity.md b/docs/file-format-parity.mdindex 6055bebae..b0771c4d6 100644--- a/docs/file-format-parity.md+++ b/docs/file-format-parity.md@@ -1,6 +1,6 @@# File-format parity-> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-13 · **Change:** minor (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-13 · **Change:** minor (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 2026Every format Photoshop 2026 (27.11.0) reads or writes, with PhotoCraft's support, fidelity andtests. 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 185/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 (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) || 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 (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-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 || 2026-10-13 | minor | Lossy DNG (compression 34892) decodes: 8-bit baseline JPEG tiles and strips, CFA and LinearRaw, partial edge tiles; the stored values take the normal levels and LinearizationTable (FILE-215-11, lossy DNG part) || 2026-10-14 | minor | Corpus floors raised to the measured results of the CMYK, Lab, 32-bit, Levels, Threshold, Posterize, feather and pass-through fixes landed together: Photoshop-authored 165 → 185 of 258, io 146 → 148 of 170, psd-tools 242 → 249 of 309 || 2026-10-13 | minor | CMYK Hue/Saturation (not Colorize) and Color Balance work on C, M and Y as inverted RGB with black kept, on the inks for display, export and destructive edits; cmyk8/16 hue-saturation 100% → 0.4–0.7% bad pixels, color-balance 74% → 25% |diff --git a/docs/gaps.md b/docs/gaps.mdindex d964b01eb..1520668ac 100644--- a/docs/gaps.md+++ b/docs/gaps.md@@ -1,6 +1,6 @@# Where PhotoCraft falls short of Photoshop-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (G10: DPX read and write, #1049, Cineon read; G1: CMYK Hue/Saturation and Color Balance keep the black ink; G1: CMYK Posterize on the stored values, psd-tools oracle floor 242/309; G1: CMYK adjustment layers composite on the document's inks, Photoshop-oracle floor 165/258; G1: CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; G1: modern Brightness/Contrast's brightness curve matches Photoshop, Photoshop-oracle floor 151/258; G1: Lab documents composite on their stored L, a, b, Photoshop-oracle floor 152/258; G1: Levels on whole levels at every step, Photoshop-oracle floor 146/258, psd-tools 238/309; G1: 32-bit Brightness/Contrast legacy, Channel Mixer, Photo Filter and Black & White tint unclipped as in Photoshop, Photoshop-oracle floor 149/258; G1: mask feathers blur with their exact variance, psd-tools oracle floor 240/309; G1: Threshold splits on Photoshop's luminosity, psd-tools oracle floor 241/309; G1: pass-through clipping base with an adjustment renders isolated, psd-tools oracle floor 240/309; G1: 16-bit Posterize as Photoshop bins it, psd-tools oracle floor 241/309; G1: Gradient Map driven by the W3C luminosity, Photoshop-oracle floor 147/258; G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (G1: smart filter masks show on PSD open, Photoshop-oracle floor 188/258; G10: DPX read and write, #1049, Cineon read; G1: CMYK Hue/Saturation and Color Balance keep the black ink; G1: CMYK Posterize on the stored values, psd-tools oracle floor 242/309; G1: CMYK adjustment layers composite on the document's inks, Photoshop-oracle floor 165/258; G1: CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; G1: modern Brightness/Contrast's brightness curve matches Photoshop, Photoshop-oracle floor 151/258; G1: Lab documents composite on their stored L, a, b, Photoshop-oracle floor 152/258; G1: Levels on whole levels at every step, Photoshop-oracle floor 146/258, psd-tools 238/309; G1: 32-bit Brightness/Contrast legacy, Channel Mixer, Photo Filter and Black & White tint unclipped as in Photoshop, Photoshop-oracle floor 149/258; G1: mask feathers blur with their exact variance, psd-tools oracle floor 240/309; G1: Threshold splits on Photoshop's luminosity, psd-tools oracle floor 241/309; G1: pass-through clipping base with an adjustment renders isolated, psd-tools oracle floor 240/309; G1: 16-bit Posterize as Photoshop bins it, psd-tools oracle floor 241/309; G1: Gradient Map driven by the W3C luminosity, Photoshop-oracle floor 147/258; G7: Field Blur's on-canvas pins, #3373; G4: Hue Jitter amount track, #3825 partial; G4: minimum field interaction, #3825 partial; G1: CMYK Invert, Posterize and Threshold on the inks, 16-bit Lab Invert; Photoshop-oracle floor 145/258; G11: `.atn` import maps 112 events: Select and Mask, Filter Gallery Spatter, Ripple, Crystallize, Pattern Fill layers, mask targeting, Step Backward, nudges in points, Bitmap mode; G5: Free Transform H/V skew fields; G9: toolbar tool shortcut editing; refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672; G1: #2465 fixed; stale missing-tool rows corrected: Color Replacement, Red Eye and Add/Delete Anchor Point are live tools, so only Art History Brush is missing; no estimate changed) · **Target:** Adobe Photoshop 2026Every known shortfall against Photoshop 2026 (27.11.0), one entry each, ranked by user impacton the way to beta. This is the work list agents pick from: take the highest-ranked entry that@@ -43,7 +43,7 @@ what an agent can't finish alone.- **Missing:** PSDs we write are not always accepted by Photoshop, and Photoshop-authored filesdon't always render as Photoshop renders them.- **Evidence:** corpus floors (`crates/io/tests/corpus.rs`, scorecard): Photoshop-authored- oracles 185/258 (72%; CMYK and Lab adjustment layers, 32-bit unclipped adjustments, Levels, Threshold, Posterize and mask feathers 2026-10-13; Gradient Map luminosity 2026-10-13; CMYK Invert, Posterize and Threshold on the inks 2026-10-12), io corpus 148/170 (87%), psd-tools 249/309 (81%); round trips ~100%+ oracles 188/258 (73%; smart filter masks 2026-10-14; CMYK and Lab adjustment layers, 32-bit unclipped adjustments, Levels, Threshold, Posterize and mask feathers 2026-10-13; Gradient Map luminosity 2026-10-13; CMYK Invert, Posterize and Threshold on the inks 2026-10-12), io corpus 148/170 (87%), psd-tools 249/309 (81%); round trips ~100%within the corpus. Smart-filter re-render matches 5/30. User reports: a PSD with text layersre-saved unmodified would not reopen (#2374, closed 2026-10-10), Photoshop 26.6 cannot reopen our files (#1281), "PSD notopening in Photoshop" (#2469), a CS2-era smart object unavailable (#2465, fixed 2026-10-12), PSB smart object@@ -269,6 +269,7 @@ what an agent can't finish alone.| Date | Change | Summary ||---|---|---|+| 2026-10-14 | minor | G1: a PSD smart object's filter mask shows when the file opens (Photoshop stores the filtered pixels unmasked); export stores them that way too; Photoshop-oracle floor 185 → 188 of 258 || 2026-10-13 | minor | G14: D90 image area measured (4288 × 2848 at (10, 10)); gap remains open || 2026-10-14 | minor | Corpus floors raised to the measured results of the CMYK, Lab, 32-bit, Levels, Threshold, Posterize, feather and pass-through fixes landed together: Photoshop-authored 165 → 185 of 258, io 146 → 148 of 170, psd-tools 242 → 249 of 309 || 2026-10-13 | minor | G1: CMYK Hue/Saturation and Color Balance work on C, M and Y as inverted RGB with black kept, as Photoshop does; cmyk hue-saturation 100% → 0.4–0.7% bad pixels, color-balance 74% → 25%; floor unchanged |diff --git a/docs/scorecard.md b/docs/scorecard.mdindex e856a1fdc..173f3b713 100644--- a/docs/scorecard.md+++ b/docs/scorecard.md@@ -7,7 +7,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js| Area | Done | Partial | Missing | Key numbers ||---|---:|---:|---:|---|| [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 17 not run, 5 not measurable yet (baseline 2026-10-05) |-| [File compatibility](#file-compatibility) | 7 | 13 | 7 | io corpus: oracle ≥ 148/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 249/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 185/256, round trip ≥ 258/256 |+| [File compatibility](#file-compatibility) | 7 | 13 | 7 | io corpus: oracle ≥ 148/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 249/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 188/256, round trip ≥ 258/256 || [Tools](#tools) | 33 | 11 | 0 | || [Workspace and UI](#workspace-and-ui) | 13 | 6 | 4 | settings that do nothing: 26 of 166 (target 0) || [Type](#type) | 4 | 3 | 2 | |@@ -94,7 +94,7 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t|---|---|---:|---:|---:|| io corpus | `corpus/psd` | 170 | 148 | 169 || psd-tools corpus | `corpus/psd-tools` | 309 | 249 | 308 |-| photoshop oracles | `corpus/photoshop` | 256 | 185 | 258 |+| photoshop oracles | `corpus/photoshop` | 256 | 188 | 258 || Id | Target | Status | Issue | Note ||---|---|---|---|---|