mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
32-bit documents: Exposure works on the stored linear values (#400)
* 32-bit documents: Exposure works on the stored linear values Their samples are linear already, so going through the 2.2 curve applied the gamma twice. rgb32 and gray32 exposure.psd now match Photoshop within 0.5/255 (was 69/255 and 44/255). * Raise the Photoshop oracle floor to 130
This commit is contained in:
1 parent
a312c3d0c7
commit
8a5e89faa6
7 files changed
+32
-9
No files matched your search
@@ -13,7 +13,7 @@ use crate::Buffer;
|
||||
/// work in linear light (Exposure). Until ICC profiles are wired in (M8) this
|
||||
/// approximates the Photoshop defaults: sRGB for colour documents and the
|
||||
/// "Dot Gain 20%" grey profile (≈ gamma 1.73, fitted on the corpus) for
|
||||
/// grayscale documents.
|
||||
/// grayscale documents. 32-bit documents store linear light already.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum Transfer {
|
||||
/// sRGB piecewise curve.
|
||||
@@ -23,8 +23,13 @@ pub enum Transfer {
|
||||
}
|
||||
|
||||
impl Transfer {
|
||||
/// Default transfer for a document colour mode.
|
||||
pub fn for_mode(mode: photocraft_color::ColorMode) -> Self {
|
||||
/// Default transfer for a document's colour mode and depth. 32-bit samples are linear, and
|
||||
/// Photoshop's Exposure works on them as stored (photoshop corpus rgb32 and gray32
|
||||
/// exposure.psd: within 0.5/255, against 69/255 through the 2.2 curve).
|
||||
pub fn for_document(mode: photocraft_color::ColorMode, depth: photocraft_color::SampleType) -> Self {
|
||||
if depth == photocraft_color::SampleType::F32 {
|
||||
return Transfer::Gamma(1.0);
|
||||
}
|
||||
match mode {
|
||||
photocraft_color::ColorMode::Grayscale | photocraft_color::ColorMode::Duotone | photocraft_color::ColorMode::Bitmap => Transfer::Gamma(1.732),
|
||||
_ => Transfer::Srgb,
|
||||
|
||||
@@ -445,7 +445,7 @@ impl<'a> Ctx<'a> {
|
||||
fn for_doc(doc: &Document, patterns: &'a pattern::PreparedPatterns<'a>) -> Self {
|
||||
Self {
|
||||
canvas: doc.bounds(),
|
||||
transfer: adjust::Transfer::for_mode(doc.mode),
|
||||
transfer: adjust::Transfer::for_document(doc.mode, doc.depth),
|
||||
light: doc.global_light,
|
||||
patterns,
|
||||
mode: doc.mode,
|
||||
|
||||
@@ -1162,6 +1162,24 @@ fn exposure_offset_uses_gamma_2_2_in_rgb() {
|
||||
assert_eq!(adjust::Transfer::Gamma(1.732).for_exposure(), adjust::Transfer::Gamma(1.732));
|
||||
}
|
||||
|
||||
// 32-bit samples are linear light: +1 stop doubles them as stored, where an 8-bit document goes
|
||||
// through its tone curve first (photoshop corpus rgb32 and gray32 exposure.psd).
|
||||
#[test]
|
||||
fn exposure_scales_32_bit_samples_as_stored() {
|
||||
let plus_one_stop = Adjustment::Exposure { exposure: 1.0, offset: 0.0, gamma: 1.0 };
|
||||
for (depth, fmt, want) in [(SampleType::F32, PixelFormat::RGBA32F, 0.4), (SampleType::U8, PixelFormat::RGBA8, 0.2744)] {
|
||||
let mut d = Document::new("e", Size::new(1, 1), ColorMode::Rgb, depth);
|
||||
let mut l = Layer::raster("px", fmt);
|
||||
l.surface_mut().unwrap().fill_rect(Rect::new(0, 0, 1, 1), &[0.2, 0.2, 0.2, 1.0]);
|
||||
d.layers = vec![l, Layer::new("exp", LayerContent::Adjustment(plus_one_stop.clone()))];
|
||||
let got = px(&d, 0, 0)[0];
|
||||
assert!((got - want).abs() < 2e-3, "{depth:?}: {got}");
|
||||
}
|
||||
for mode in [ColorMode::Rgb, ColorMode::Grayscale] {
|
||||
assert_eq!(adjust::Transfer::for_document(mode, SampleType::F32), adjust::Transfer::Gamma(1.0));
|
||||
}
|
||||
}
|
||||
|
||||
// A 30° Reflected gradient fill on a 4 × 4 canvas renders as Photoshop's (its end point snaps to
|
||||
// the corner: t = |x − y| / 4) at every depth.
|
||||
#[test]
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn adjust_surface(s: &mut Surface, adj: &Adjustment, selection: Option<&Surf
|
||||
let raw = s.read_region(r);
|
||||
let mut buf = Buffer { rect: r, px: raw.chunks_exact(n).map(|p| to_rgba(&fmt, p)).collect() };
|
||||
let orig = buf.clone();
|
||||
adjust::apply_with(adj, &mut buf, adjust::Transfer::for_mode(mode));
|
||||
adjust::apply_with(adj, &mut buf, adjust::Transfer::for_document(mode, fmt.sample));
|
||||
let w = r.width() as usize;
|
||||
let mut out = Vec::with_capacity(raw.len());
|
||||
for (i, (a, o)) in buf.px.iter().zip(&orig.px).enumerate() {
|
||||
|
||||
@@ -298,7 +298,7 @@ impl<'a> DocCtx<'a> {
|
||||
pub fn of(doc: &'a Document) -> Self {
|
||||
DocCtx {
|
||||
canvas: doc.bounds(),
|
||||
transfer: Transfer::for_mode(doc.mode),
|
||||
transfer: Transfer::for_document(doc.mode, doc.depth),
|
||||
light: doc.global_light,
|
||||
patterns: &doc.patterns,
|
||||
mode: doc.mode,
|
||||
|
||||
@@ -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: 128, roundtrip_floor: 258 };
|
||||
const PHOTOSHOP: Source = Source { label: "photoshop oracles", dir: "corpus/photoshop", group_depth: 2, pass_floor: 130, roundtrip_floor: 258 };
|
||||
|
||||
/// The corpus directory; a missing corpus fails the test.
|
||||
fn locate(src: &Source) -> PathBuf {
|
||||
|
||||
+2
-2
@@ -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 | 12 | 46 scenarios: 3 within budget, 22 over budget or failing, 13 tracked only, 4 not run, 8 not measurable yet (baseline 2026-10-05) |
|
||||
| [File compatibility](#file-compatibility) | 1 | 8 | 18 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 229/309, round trip ≥ 307/309; photoshop oracles: oracle ≥ 128/256, round trip ≥ 258/256 |
|
||||
| [File compatibility](#file-compatibility) | 1 | 8 | 18 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 229/309, round trip ≥ 307/309; photoshop oracles: oracle ≥ 130/256, round trip ≥ 258/256 |
|
||||
| [Tools](#tools) | 3 | 14 | 13 | |
|
||||
| [Workspace and UI](#workspace-and-ui) | 0 | 3 | 20 | settings that do nothing: 60 of 133 (target 0) |
|
||||
| [Type](#type) | 0 | 3 | 6 | |
|
||||
@@ -84,7 +84,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 | 229 | 307 |
|
||||
| photoshop oracles | `corpus/photoshop` | 256 | 128 | 258 |
|
||||
| photoshop oracles | `corpus/photoshop` | 256 | 130 | 258 |
|
||||
|
||||
| Id | Target | Status | Issue | Note |
|
||||
|---|---|---|---|---|
|
||||
|
||||
Reference in new issue
Block a user