Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Lab: adjustment layers composite on the stored L, a and b (seven Lab oracles pass) (#5171)

Timothy Daly4c450b3879eb
diff --git a/crates/compose/src/adjust.rs b/crates/compose/src/adjust.rs
index 673178c68..aff87ece0 100644
--- a/crates/compose/src/adjust.rs
+++ b/crates/compose/src/adjust.rs
@@ -396,6 +396,49 @@ fn lab_denorm(n: [f32; 3]) -> [f32; 3] {
lab_to_srgb([n[0] * 100.0, n[1] * 255.0 - 128.0, n[2] * 255.0 - 128.0])
}
+/// Neutral a or b as Lab surfaces store it ((0 + 128) / 255).
+pub const LAB_NEUTRAL: f32 = 128.0 / 255.0;
+
+/// An adjustment Photoshop evaluates on a Lab document's own channels, as an operation on one
+/// pixel's stored L, a, b (normalised as Lab surfaces store them: L / 100, (a + 128) / 255,
+/// (b + 128) / 255) in a document of `depth`: Invert and Posterize (each channel), Threshold
+/// (split on L, neutral result), Brightness/Contrast (L) and Levels or Curves with Lab records.
+/// `None` for any other adjustment. On the stored values colours outside the display gamut keep
+/// theirs, where [`apply_in`] can only round-trip them through clipped display RGB.
+pub fn lab_stored_op(adj: &Adjustment, depth: Option<SampleType>) -> Option<LabOp<'_>> {
+ let op: LabOp<'_> = match adj {
+ Adjustment::Invert | Adjustment::Posterize { .. } => Box::new(move |ch: &mut [f32; 3]| stored_channels(adj, ColorMode::Lab, depth, ch, 0.0)),
+ Adjustment::Threshold { level } => {
+ // Split on L on the 8-bit grid, like the display path (`apply_lab`).
+ let t = (level * 255.0).round();
+ Box::new(move |ch: &mut [f32; 3]| {
+ let white = (ch[0].clamp(0.0, 1.0) * 255.0).round() >= t;
+ *ch = [if white { 1.0 } else { 0.0 }, LAB_NEUTRAL, LAB_NEUTRAL];
+ })
+ }
+ Adjustment::BrightnessContrast { brightness, contrast, legacy } => {
+ let (b, c, legacy) = (*brightness, *contrast, *legacy);
+ let legacy_curve = legacy_brightness_contrast(b, c);
+ Box::new(move |ch: &mut [f32; 3]| {
+ ch[0] = if legacy { legacy_curve(ch[0]) } else { modern_contrast(modern_brightness(ch[0], b), c).clamp(0.0, 1.0) };
+ })
+ }
+ Adjustment::Levels { space: ToneSpace::Lab, .. } | Adjustment::Curves { space: ToneSpace::Lab, .. } => {
+ let luts = tone_luts_depth(adj, depth);
+ Box::new(move |ch: &mut [f32; 3]| {
+ for (v, t) in ch.iter_mut().zip(&luts) {
+ *v = lut(t, *v);
+ }
+ })
+ }
+ _ => return None,
+ };
+ Some(op)
+}
+
+/// One pixel's stored L, a, b through an adjustment ([`lab_stored_op`]).
+pub type LabOp<'a> = Box<dyn Fn(&mut [f32; 3]) + Send + Sync + 'a>;
+
/// The Lab evaluation of a [`lab_channel_adjustment`] in a document of `depth` (no-op for any
/// other adjustment).
fn apply_lab(adj: &Adjustment, buf: &mut Buffer, depth: Option<SampleType>) {
diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rs
index ad09375ed..f05520a58 100644
--- a/crates/compose/src/lib.rs
+++ b/crates/compose/src/lib.rs
@@ -25,6 +25,7 @@ pub mod gradient_fill;
pub mod masks;
pub mod multichannel;
pub mod native;
+pub mod native_lab;
pub mod pattern;
pub mod proxy;
pub mod psblend;
@@ -128,6 +129,10 @@ fn render_tiled_with(doc: &Document, rect: Rect, tile: i32, cx: &Ctx) -> Buffer
if u64::from(rect.width()) * u64::from(rect.height()) > MAX_RENDER_PIXELS {
return Buffer::transparent(Rect::EMPTY);
}
+ // A Lab stack with adjustment layers that work on L, a and b composites on its stored values.
+ if let Some(buf) = native_lab::render_lab(doc, rect, tile) {
+ return buf;
+ }
cx.set_fx_clip(rect);
if i64::from(rect.width()) <= i64::from(tile) && i64::from(rect.height()) <= i64::from(tile) {
return photocraft_color::convert::with_cmyk_space(cmyk, || {
@@ -260,7 +265,8 @@ pub fn band_rows_for(width: u32, requested: i32) -> i32 {
/// otherwise count as content: the result would span the whole canvas.
///
/// A CMYK document of plain Normal layers is composited in its ink values instead
-/// ([`native::flatten_cmyk`]), so flattening doesn't round-trip its pixels through RGB (#3778).
+/// ([`native::flatten_cmyk`]), so flattening doesn't round-trip its pixels through RGB (#3778),
+/// and a Lab one in its L, a and b ([`native_lab::flatten_lab`]).
pub fn flatten_to_surface(doc: &Document, fmt: photocraft_color::PixelFormat, background: Option<[f32; 3]>) -> Surface {
composite_to_surface(doc, doc.bounds(), fmt, background)
}
@@ -273,6 +279,11 @@ pub fn composite_to_surface(doc: &Document, rect: Rect, fmt: photocraft_color::P
{
return s;
}
+ if (background.is_none() || paper)
+ && let Some(s) = native_lab::flatten_lab(doc, rect, fmt, paper)
+ {
+ return s;
+ }
let mut s = Surface::new(fmt);
let n = fmt.channels();
let empty = s.default_pixel();
diff --git a/crates/compose/src/native_lab.rs b/crates/compose/src/native_lab.rs
new file mode 100644
index 000000000..0db59499d
--- /dev/null
+++ b/crates/compose/src/native_lab.rs
@@ -0,0 +1,253 @@
+//! Lab-native compositing of plain Lab layer stacks.
+//!
+//! The compositor works in display RGB, so a Lab document's layers are read through `lab_to_srgb`,
+//! which clips colours outside the display gamut, and adjustments Photoshop evaluates on L, a and
+//! b ([`adjust::lab_stored_op`]) can then only see those clipped colours: an inverted or levelled
+//! saturated colour comes out several levels off. When every visible layer is a plain Lab raster
+//! layer in Normal mode or such an adjustment layer, the stack is worked out on the stored values
+//! instead: Normal mixes L, a and b linearly, as Photoshop does in Lab, and an opaque layer keeps
+//! them exactly. A layer mask (unfeathered) scales the mix.
+//!
+//! Stacks with such adjustment layers render for display this way ([`render_lab`]); flattening
+//! ([`flatten_lab`]) keeps the stored values for any plain stack.
+
+use photocraft_color::blend::BlendMode;
+use photocraft_color::{ColorMode, PixelFormat, SampleType};
+use photocraft_doc::{Document, Layer, LayerContent, LayerMask};
+use photocraft_geom::Rect;
+use photocraft_raster::Surface;
+
+use crate::Buffer;
+use crate::adjust::{self, LabOp};
+
+/// Colour channels of a Lab pixel.
+const LAB: usize = 3;
+
+/// Whether the compositor would only blend `layer` Normally at its opacity through its layer mask:
+/// no clipping, vector mask, feathered mask, effects, excluded channels, Blend If or advanced
+/// blending.
+fn simple(layer: &Layer) -> bool {
+ layer.blend == BlendMode::Normal
+ && !layer.clipped
+ && !crate::masks::has_feather(layer)
+ && layer.vector_mask.as_ref().is_none_or(|v| !v.enabled)
+ && !crate::effects::has_effects(layer)
+ && layer.excluded_channels == 0
+ && layer.blend_if.is_default()
+ && layer.advanced.is_default()
+ && layer.video.is_none()
+}
+
+/// One step of a native stack, at the layer's opacity × fill, through its mask.
+enum Item<'a> {
+ Layer(&'a Surface, f32, Option<&'a LayerMask>),
+ Adjust(LabOp<'a>, f32, Option<&'a LayerMask>),
+}
+
+/// Groups nested deeper than this keep the RGB compositor.
+const MAX_DEPTH: usize = 64;
+
+/// `layers`' visible steps, appended to `items`; `None` when one needs the RGB compositor. A group
+/// at full opacity without a mask is inlined: pass-through groups composite their children straight
+/// onto the backdrop, and so do isolated (Normal) groups of raster layers alone, since Normal
+/// composites associatively; an adjustment inside an isolated group would only see the group's
+/// own content, so such a group keeps the RGB compositor (`adjustments` false).
+fn collect<'a>(layers: &'a [Layer], depth: SampleType, adjustments: bool, items: &mut Vec<Item<'a>>, level: usize) -> Option<()> {
+ if level > MAX_DEPTH {
+ return None;
+ }
+ for layer in layers.iter().filter(|l| l.visible) {
+ let alpha = (layer.opacity * layer.fill_opacity).clamp(0.0, 1.0);
+ let mask = layer.mask.as_ref().filter(|m| m.enabled);
+ let item = match &layer.content {
+ LayerContent::Group(g) => {
+ let open = g.artboard.is_none()
+ && alpha >= 1.0
+ && mask.is_none()
+ && !layer.clipped
+ && layer.vector_mask.as_ref().is_none_or(|v| !v.enabled)
+ && !crate::effects::has_effects(layer)
+ && layer.excluded_channels == 0
+ && layer.blend_if.is_default()
+ && layer.advanced.is_default();
+ match layer.blend {
+ BlendMode::PassThrough if open => collect(&g.children, depth, adjustments, items, level + 1)?,
+ BlendMode::Normal if open => collect(&g.children, depth, false, items, level + 1)?,
+ _ => return None,
+ }
+ continue;
+ }
+ LayerContent::Raster(s) if simple(layer) && s.format().mode == ColorMode::Lab => Item::Layer(s, alpha, mask),
+ LayerContent::Adjustment(adj) if adjustments && simple(layer) => Item::Adjust(adjust::lab_stored_op(adj, Some(depth))?, alpha, mask),
+ _ => return None,
+ };
+ items.push(item);
+ }
+ Some(())
+}
+
+/// A Lab document's visible layers, prepared for compositing on their stored L, a and b.
+pub struct LabStack<'a> {
+ items: Vec<Item<'a>>,
+}
+
+impl<'a> LabStack<'a> {
+ /// `None` unless `doc` is Lab and every visible layer is a plain Lab raster layer, an
+ /// adjustment layer [`adjust::lab_stored_op`] evaluates, or a group that can be inlined (see
+ /// the module docs and [`collect`]).
+ pub fn new(doc: &'a Document) -> Option<Self> {
+ if doc.mode != ColorMode::Lab {
+ return None;
+ }
+ let mut items = Vec::new();
+ collect(&doc.layers, doc.depth, true, &mut items, 0)?;
+ Some(LabStack { items })
+ }
+
+ /// Whether the stack has an adjustment layer (the RGB compositor can't match it exactly).
+ pub fn adjusts(&self) -> bool {
+ self.items.iter().any(|i| matches!(i, Item::Adjust(..)))
+ }
+
+ /// Straight L, a, b and alpha over `rect`, row-major, into `acc` (`src` and `mv` are scratch).
+ fn composite(&self, rect: Rect, acc: &mut Vec<[f32; LAB + 1]>, src: &mut Vec<f32>, mv: &mut Vec<f32>) {
+ let n = rect.width() as usize * rect.height() as usize;
+ acc.clear();
+ acc.resize(n, [0.0, adjust::LAB_NEUTRAL, adjust::LAB_NEUTRAL, 0.0]);
+ // The mask's value at each pixel (1 without one).
+ let masked = |mask: Option<&LayerMask>, mv: &mut Vec<f32>| match mask {
+ Some(m) => m.values_into(rect, mv),
+ None => {
+ mv.clear();
+ mv.resize(n, 1.0);
+ }
+ };
+ for item in &self.items {
+ match item {
+ Item::Layer(surf, opacity, mask) => {
+ let opacity = *opacity;
+ if opacity <= 0.0 || (surf.content_bounds().intersect(&rect).is_empty() && surf.default_pixel().get(LAB).is_none_or(|a| *a <= 0.0)) {
+ continue;
+ }
+ let sf = surf.format();
+ let sn = sf.channels();
+ surf.read_region_into(rect, src);
+ masked(*mask, mv);
+ for ((d, s), k) in acc.iter_mut().zip(src.chunks_exact(sn)).zip(mv.iter()) {
+ let sa = if sf.alpha { s.get(LAB).copied().unwrap_or(1.0) } else { 1.0 } * opacity * k.clamp(0.0, 1.0);
+ if sa <= 0.0 {
+ continue;
+ }
+ let oa = sa + d[LAB] * (1.0 - sa);
+ let keep = d[LAB] * (1.0 - sa);
+ for (c, v) in s.iter().take(LAB).enumerate() {
+ // An opaque pixel replaces what is below exactly (no rounding through the mix).
+ d[c] = if sa >= 1.0 { *v } else { (v * sa + d[c] * keep) / oa };
+ }
+ d[LAB] = oa;
+ }
+ }
+ Item::Adjust(op, opacity, mask) => {
+ if *opacity <= 0.0 {
+ continue;
+ }
+ masked(*mask, mv);
+ for (d, k) in acc.iter_mut().zip(mv.iter()) {
+ let mix = opacity * k.clamp(0.0, 1.0);
+ if d[LAB] <= 0.0 || mix <= 0.0 {
+ continue;
+ }
+ let mut lab = [d[0], d[1], d[2]];
+ op(&mut lab);
+ for (c, v) in lab.iter().enumerate() {
+ d[c] += (v - d[c]) * mix;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+/// The composite of `doc` over `rect` in `fmt`, worked out on stored L, a and b, or `None` when
+/// the document isn't Lab, `fmt` isn't, or a visible layer needs the full compositor (see the
+/// module docs). `white` flattens onto white (L 100, neutral a and b) and makes the result opaque.
+pub fn flatten_lab(doc: &Document, rect: Rect, fmt: PixelFormat, white: bool) -> Option<Surface> {
+ if fmt.mode != ColorMode::Lab {
+ return None;
+ }
+ let stack = LabStack::new(doc)?;
+ let mut out = Surface::new(fmt);
+ if rect.is_empty() {
+ return Some(out);
+ }
+ let n = fmt.channels();
+ let empty = out.default_pixel();
+ let rows = crate::band_rows_for(rect.width(), 0);
+ let (mut acc, mut src, mut mv, mut data) = (Vec::new(), Vec::new(), Vec::new(), Vec::new());
+ let mut y = rect.y0;
+ while y < rect.y1 {
+ let band = Rect::new(rect.x0, y, rect.x1, y.saturating_add(rows).min(rect.y1));
+ stack.composite(band, &mut acc, &mut src, &mut mv);
+ data.clear();
+ data.resize(acc.len() * n, 0.0);
+ for (p, o) in acc.iter().zip(data.chunks_exact_mut(n)) {
+ let a = p[LAB];
+ if white {
+ let paper = [1.0, adjust::LAB_NEUTRAL, adjust::LAB_NEUTRAL];
+ for c in 0..LAB {
+ o[c] = p[c] * a + paper[c] * (1.0 - a);
+ }
+ if fmt.alpha {
+ o[LAB] = 1.0;
+ }
+ } else if a <= 0.0 {
+ o.copy_from_slice(&empty[..n]);
+ } else {
+ o[..LAB].copy_from_slice(&p[..LAB]);
+ if fmt.alpha {
+ o[LAB] = a;
+ }
+ }
+ }
+ out.write_region(band, &data);
+ y = band.y1;
+ }
+ out.prune();
+ Some(out)
+}
+
+/// The display composite (straight RGBA) of a Lab document whose stack has adjustment layers that
+/// work on L, a and b, worked out on the stored values; `None` for any other document, which the
+/// RGB compositor renders. Rows of `tile` render in parallel.
+pub fn render_lab(doc: &Document, rect: Rect, tile: i32) -> Option<Buffer> {
+ let stack = LabStack::new(doc).filter(LabStack::adjusts)?;
+ let w = rect.width() as usize;
+ let mut out = Buffer::transparent(rect);
+ if w == 0 || rect.is_empty() {
+ return Some(out);
+ }
+ let rows = tile.max(1) as usize;
+ let band = |i: usize, px: &mut [[f32; 4]]| {
+ let y0 = rect.y0.saturating_add((i * rows) as i32);
+ let r = Rect::new(rect.x0, y0, rect.x1, y0.saturating_add((px.len() / w) as i32));
+ let (mut acc, mut src, mut mv) = (Vec::new(), Vec::new(), Vec::new());
+ stack.composite(r, &mut acc, &mut src, &mut mv);
+ for (o, p) in px.iter_mut().zip(&acc) {
+ if p[LAB] > 0.0 {
+ let [r, g, b] = photocraft_color::convert::lab_to_srgb([p[0] * 100.0, p[1] * 255.0 - 128.0, p[2] * 255.0 - 128.0]);
+ *o = [r, g, b, p[LAB]];
+ }
+ }
+ };
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ use rayon::prelude::*;
+ out.px.par_chunks_mut(w * rows).enumerate().for_each(|(i, px)| band(i, px));
+ }
+ #[cfg(target_arch = "wasm32")]
+ for (i, px) in out.px.chunks_mut(w * rows).enumerate() {
+ band(i, px);
+ }
+ Some(out)
+}
diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rs
index a2f1e617e..f9210a884 100644
--- a/crates/compose/src/tests.rs
+++ b/crates/compose/src/tests.rs
@@ -1,6 +1,6 @@
use super::*;
use photocraft_color::{Color, ColorMode, PixelFormat, SampleType};
-use photocraft_doc::adjust::{CurvePoint, LevelsChannel};
+use photocraft_doc::adjust::{CurvePoint, LevelsChannel, ToneSpace};
use photocraft_doc::{Adjustment, Document, Fill, Layer, LayerContent, LayerMask};
use photocraft_geom::Size;
@@ -2620,6 +2620,86 @@ fn lab_documents_invert_and_posterize_l_a_and_b() {
}
}
+/// A Lab document of one opaque layer holding stored L, a, b `lab` (normalised as Lab surfaces
+/// store them), with `adjustments` above it.
+fn lab_stack(lab: [f32; 3], depth: SampleType, adjustments: Vec<Adjustment>) -> Document {
+ let mut doc = Document::new("lab", Size::new(4, 4), ColorMode::Lab, depth);
+ let fmt = doc.pixel_format();
+ let mut layer = Layer::raster("bg", fmt);
+ if let Some(s) = layer.surface_mut() {
+ s.fill_rect(Rect::new(0, 0, 4, 4), &[lab[0], lab[1], lab[2], 1.0][..fmt.channels()]);
+ }
+ doc.layers.push(layer);
+ doc.layers.extend(adjustments.into_iter().map(|a| Layer::new("adj", LayerContent::Adjustment(a))));
+ doc
+}
+
+/// Display RGB of stored Lab `n`.
+fn lab_display(n: [f32; 3]) -> [f32; 3] {
+ photocraft_color::convert::lab_to_srgb([n[0] * 100.0, n[1] * 255.0 - 128.0, n[2] * 255.0 - 128.0])
+}
+
+// A saturated purple far outside sRGB (L 60, a +90, b -90). Read through display RGB it clips,
+// so Invert and Levels on L, a and b saw the clipped colour: the photoshop corpus's lab8 and
+// lab16 invert.psd were up to 11 levels off there. Worked out on the stored values, Invert gives
+// the bytes' complements (L 153 → 102, a 218 → 37, b 38 → 217), as Photoshop does.
+#[test]
+fn lab_adjustments_work_on_the_stored_values() {
+ let byte = |v: u8| f32::from(v) / 255.0;
+ let doc = lab_stack([byte(153), byte(218), byte(38)], SampleType::U8, vec![Adjustment::Invert]);
+ let p = px(&doc, 1, 1);
+ let want = lab_display([byte(102), byte(37), byte(217)]);
+ near3([p[0], p[1], p[2]], want, 1e-4, "inverted out-of-gamut purple");
+ // Through clipped display RGB the result is another colour.
+ let clipped = photocraft_color::convert::srgb_to_lab(lab_display([byte(153), byte(218), byte(38)]));
+ let via_rgb = lab_display([1.0 - clipped[0] / 100.0, (-clipped[1] - 1.0 + 128.0) / 255.0, (-clipped[2] - 1.0 + 128.0) / 255.0]);
+ assert!(via_rgb.iter().zip(want).any(|(a, b)| (a - b).abs() > 4.0 / 255.0), "the clipped path differs: {via_rgb:?} vs {want:?}");
+ // Levels on L only (a Lab record), half masked by opacity: L 0.6 → 0.6^(1/2) mixed halfway.
+ let ch = LevelsChannel { gamma: 2.0, ..Default::default() };
+ let levels = Adjustment::Levels {
+ master: LevelsChannel::default(),
+ per_channel: [ch.clone(), LevelsChannel::default(), LevelsChannel::default()],
+ space: ToneSpace::Lab,
+ black: LevelsChannel::default(),
+ };
+ let mut doc = lab_stack([0.6, byte(218), byte(38)], SampleType::U16, vec![levels]);
+ if let Some(l) = doc.layers.last_mut() {
+ l.opacity = 0.5;
+ }
+ let p = px(&doc, 1, 1);
+ let l = 0.6 + (adjust::levels_q(&ch, 0.6, Some(32768.0)) - 0.6) * 0.5;
+ near3([p[0], p[1], p[2]], lab_display([l, byte(218), byte(38)]), 1e-3, "levels on L at half opacity");
+}
+
+// Flattening a Lab document keeps its stored values, out-of-gamut colours included (the RGB
+// compositor clipped them on the way through display RGB).
+#[test]
+fn lab_flatten_keeps_the_stored_values() {
+ let lab = [0.6, 218.0 / 255.0, 38.0 / 255.0];
+ for depth in [SampleType::U8, SampleType::U16] {
+ let doc = lab_stack(lab, depth, vec![]);
+ let s = flatten_to_surface(&doc, doc.pixel_format(), None);
+ let got = s.pixel(2, 2);
+ assert!(got.iter().zip(lab).all(|(g, w)| (g - w).abs() < 1e-3), "{depth:?}: {got:?}");
+ }
+}
+
+// Anything the stored values can't carry exactly keeps the RGB compositor.
+#[test]
+fn lab_stacks_with_other_layers_keep_the_rgb_compositor() {
+ let lab = [0.6, 0.5, 0.5];
+ assert!(native_lab::LabStack::new(&lab_stack(lab, SampleType::U8, vec![Adjustment::Invert])).is_some_and(|s| s.adjusts()));
+ let hue = Adjustment::HueSaturation { hue: 30.0, saturation: 0.0, lightness: 0.0, colorize: false, ranges: photocraft_doc::adjust::HueRange::defaults() };
+ assert!(native_lab::LabStack::new(&lab_stack(lab, SampleType::U8, vec![hue])).is_none());
+ let mut multiply = lab_stack(lab, SampleType::U8, vec![Adjustment::Invert]);
+ if let Some(l) = multiply.layers.last_mut() {
+ l.blend = photocraft_color::blend::BlendMode::Multiply;
+ }
+ assert!(native_lab::LabStack::new(&multiply).is_none());
+ let rgb = Document::with_background("rgb", Size::new(4, 4), ColorMode::Rgb, SampleType::U8, Color::rgb(0.5, 0.5, 0.5));
+ assert!(native_lab::LabStack::new(&rgb).is_none());
+}
+
#[test]
fn lab_documents_brightness_contrast_moves_lightness_only() {
let lab = photocraft_color::convert::srgb_to_lab(MUTED);
diff --git a/crates/io/tests/corpus.rs b/crates/io/tests/corpus.rs
index babdc1e47..ffd80797c 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: 149, roundtrip_floor: 258 };
+const PHOTOSHOP: Source = Source { label: "photoshop oracles", dir: "corpus/photoshop", group_depth: 2, pass_floor: 152, 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.md
index 598eca008..a77e9ea38 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 (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 (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
@@ -142,6 +142,7 @@ remaining gaps in #1606 stay tracked with per-sample corpus ceilings.
| Date | Change | Summary |
|---|---|---|
+| 2026-10-13 | minor | Lab documents of plain layers with Invert, Posterize, Threshold, Brightness/Contrast or Lab Levels/Curves adjustment layers composite on the stored L, a, b instead of clipped display RGB, and flattening keeps them: lab16 invert, posterize-4, levels, curves and legacy Brightness/Contrast and lab8 invert and posterize-4 pass; Photoshop-oracle floor 145 → 152 of 258 |
| 2026-10-13 | minor | Levels round the gamma and output steps to whole levels too (8-bit), and the gamma above 1 starts along a toe of slope 2^gamma that joins the power curve: psd-tools levels_rgb and rgb8 stack-levels-curves-hue-posterize pass, rgb8/gray8 levels.psd exact; Photoshop-oracle floor 145 → 146 of 258, psd-tools 236 → 238 of 309 |
| 2026-10-13 | minor | 32-bit documents: legacy Brightness/Contrast, Channel Mixer, Photo Filter and the Black & White tint keep values above 1 and below 0 as Photoshop does (rgb32/gray32 brightness-contrast-legacy, rgb32 channel-mixer and black-white-tint pass); Photoshop-oracle floor 145 → 149 of 258 |
| 2026-10-13 | minor | Mask feathers blur with exactly the feather's variance (three extended boxes; whole-pixel boxes rounded 6 px to 6.48): psd-tools mask-parameters-no-real-channel passes, layer_mask_data 27 % → 4 % off; psd-tools floor → 240 of 309 (main 239) |
diff --git a/docs/gaps.md b/docs/gaps.md
index 6af065862..98fcd8cd2 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 (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: 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
Every known shortfall against Photoshop 2026 (27.11.0), one entry each, ranked by user impact
on the way to beta. This is the work list agents pick from: take the highest-ranked entry that
@@ -262,6 +262,7 @@ what an agent can't finish alone.
| Date | Change | Summary |
|---|---|---|
+| 2026-10-13 | minor | G1: Lab documents composite Invert, Posterize, Threshold, Brightness/Contrast and Lab Levels/Curves on their stored L, a, b (no clipped RGB round trip); seven Lab oracles pass; Photoshop-oracle floor 145 → 152 of 258 |
| 2026-10-13 | minor | G1: Levels round every step to whole levels and use Photoshop's shadow toe (slope 2^gamma); levels_rgb and stack-levels-curves-hue-posterize pass; Photoshop-oracle floor 145 → 146 of 258, psd-tools 236 → 238 of 309 |
| 2026-10-13 | minor | G1: 32-bit legacy Brightness/Contrast (pivot 127), Channel Mixer (1/1024 steps, constant ×255/512), Photo Filter and Black & White tint unclipped as Photoshop computes them, CPU and GPU; Photoshop-oracle floor 145 → 149 of 258 |
| 2026-10-13 | minor | G1: mask feathers blur with exactly the feather's variance; psd-tools mask-parameters-no-real-channel passes, layer_mask_data 27 % → 4 % off; psd-tools floor → 240 of 309 |
diff --git a/docs/scorecard.md b/docs/scorecard.md
index c64fecb5f..5d3a99304 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 ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 241/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 149/256, round trip ≥ 258/256 |
+| [File compatibility](#file-compatibility) | 7 | 13 | 7 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 241/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 152/256, round trip ≥ 258/256 |
| [Tools](#tools) | 32 | 11 | 0 | |
| [Workspace and UI](#workspace-and-ui) | 13 | 6 | 4 | settings that do nothing: 26 of 161 (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 | 146 | 169 |
| psd-tools corpus | `corpus/psd-tools` | 309 | 241 | 308 |
-| photoshop oracles | `corpus/photoshop` | 256 | 149 | 258 |
+| photoshop oracles | `corpus/photoshop` | 256 | 152 | 258 |
| Id | Target | Status | Issue | Note |
|---|---|---|---|---|