diff --git a/.github/workflows/cache-prune.yml b/.github/workflows/cache-prune.yml index cc71a9c4f1..7607488502 100644 --- a/.github/workflows/cache-prune.yml +++ b/.github/workflows/cache-prune.yml @@ -21,7 +21,7 @@ jobs: # A fork's pull request from a branch named main also matches `branches`. if: github.event.workflow_run.event != 'pull_request' timeout-minutes: 10 - runs-on: ubuntu-24.04 + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-24.04' }} permissions: actions: write steps: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0baaa06b08..12d34acb61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,7 +93,7 @@ jobs: if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci') timeout-minutes: 10 name: select platforms - runs-on: ubuntu-latest + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-latest' }} outputs: windows: ${{ steps.pick.outputs.windows }} windows_gpu: ${{ steps.pick.outputs.windows_gpu }} @@ -167,6 +167,10 @@ jobs: # Tracks @main so suite-wide CI fixes reach every app without a PR in each repository. uses: storytold/craft-common-actions/.github/workflows/gate.yml@main with: + os: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && '["artcraft-k8s-trusted"]' || '["ubuntu-24.04"]' }} + # On the cluster runners sccache uses the shared cluster cache, which main runs fill for + # every app; PR runs on hosted runners can't reach it, so they leave it off. + sccache: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }} # egui/winit/rfd. packages: >- libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev @@ -264,7 +268,7 @@ jobs: # A cold Windows build takes about an hour, and the watch ends when it does; `watch-minutes` # ends it before this limit. timeout-minutes: 120 - runs-on: ubuntu-24.04 + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-24.04' }} permissions: actions: write steps: @@ -295,7 +299,7 @@ jobs: timeout-minutes: 60 name: test (without heif) # The gate's runner: its cache entry is keyed on the OS. - runs-on: ubuntu-24.04 + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-24.04' }} env: # The gate sets these; rust-cache hashes CARGO_* and RUST* variables into its key. CARGO_INCREMENTAL: 0 @@ -352,7 +356,7 @@ jobs: # restore and a download; a missing corpus fails the tests. The cache key changes only when a # pin or manifest does, so normally this restores in seconds (fork PRs read the base cache). name: corpus tests - runs-on: ubuntu-latest + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-latest' }} env: # test-corpus builds with --release, but here without the release profile's thin LTO and # single codegen unit: they ran LTO over the dependency graph for each of the ~95 corpus test @@ -393,7 +397,7 @@ jobs: # PRs run it only when web-relevant files change (see `platforms`); main always does. needs: platforms if: needs.platforms.outputs.web == 'true' - runs-on: ubuntu-latest + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-latest' }} env: # Match release.yml so PR results reflect what would actually ship. TRUNK_VERSION: 0.21.14 @@ -458,7 +462,7 @@ jobs: name: fuzz (${{ matrix.target.crate }}/${{ matrix.target.name }}) # Placeholder: manual trigger only until a nightly schedule is enabled. if: github.event_name == 'workflow_dispatch' && inputs.fuzz - runs-on: ubuntu-latest + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-latest' }} strategy: fail-fast: false matrix: @@ -512,7 +516,7 @@ jobs: color-range-performance: if: inputs.color_range == true - runs-on: ubuntu-latest + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-latest' }} timeout-minutes: 45 env: RAYON_NUM_THREADS: "4" @@ -545,7 +549,7 @@ jobs: selection-morphology: if: inputs.selection_morphology == true - runs-on: ubuntu-latest + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-latest' }} timeout-minutes: 45 env: RAYON_NUM_THREADS: "4" @@ -616,7 +620,7 @@ jobs: selection-combining: if: inputs.selection_combining == true - runs-on: ubuntu-latest + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-latest' }} timeout-minutes: 30 env: RAYON_NUM_THREADS: "4" @@ -643,7 +647,7 @@ jobs: brush-tip: if: inputs.brush_tip == true - runs-on: ubuntu-24.04 + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-24.04' }} timeout-minutes: 30 env: RAYON_NUM_THREADS: "4" @@ -687,7 +691,7 @@ jobs: path: brush-tip.txt dry-mixer: if: inputs.dry_mixer == true - runs-on: ubuntu-latest + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-latest' }} timeout-minutes: 90 env: RAYON_NUM_THREADS: "4" diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 2edb7a3931..d567f2c2c0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -31,6 +31,7 @@ jobs: # Tracks @main so suite-wide CI fixes reach every app without a PR in each repository. uses: storytold/craft-common-actions/.github/workflows/gate.yml@main with: + os: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && '["artcraft-k8s-trusted"]' || '["ubuntu-24.04"]' }} timeout-minutes: 15 # The book needs mdBook only: no craft-fonts, apt packages, wasm target or nextest. craft-fonts-ref: "" diff --git a/.github/workflows/packaging-lint.yml b/.github/workflows/packaging-lint.yml index 980c3a2445..a1a514af5a 100644 --- a/.github/workflows/packaging-lint.yml +++ b/.github/workflows/packaging-lint.yml @@ -27,7 +27,7 @@ jobs: verified-appimage-inputs: timeout-minutes: 10 name: Verified AppImage inputs - runs-on: ubuntu-latest + runs-on: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && 'artcraft-k8s-trusted' || 'ubuntu-latest' }} steps: - name: Harden runner uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 diff --git a/Cargo.lock b/Cargo.lock index 84b7b8e6fe..5a349ddc68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1370,7 +1370,7 @@ dependencies = [ "craft-automation", "craft-behavior", "craft-browse", - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "craft-color-ui", "craft-control", "craft-dialogs", @@ -1510,18 +1510,45 @@ dependencies = [ "rayon", ] +[[package]] +name = "craft-cms" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +dependencies = [ + "md-5", + "rayon", +] + [[package]] name = "craft-codepage" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540#77c7c62345c1f4213f59a07d9fdc156ecde0b540" +[[package]] +name = "craft-color" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +dependencies = [ + "serde", +] + +[[package]] +name = "craft-color-transform" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +dependencies = [ + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062)", + "craft-color", + "serde", +] + [[package]] name = "craft-color-ui" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540#77c7c62345c1f4213f59a07d9fdc156ecde0b540" dependencies = [ "craft-behavior", - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "craft-host", "craft-i18n", "craft-keymap", @@ -1555,7 +1582,7 @@ name = "craft-crs" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540#77c7c62345c1f4213f59a07d9fdc156ecde0b540" dependencies = [ - "craft-metadata", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "craft-xml", "thiserror 2.0.21", ] @@ -1576,6 +1603,29 @@ dependencies = [ "rayon", ] +[[package]] +name = "craft-develop" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +dependencies = [ + "craft-color-transform", + "craft-develop-model", + "rayon", + "serde", +] + +[[package]] +name = "craft-develop-model" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +dependencies = [ + "craft-geom", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062)", + "miniz_oxide 0.9.1", + "serde", + "serde_json", +] + [[package]] name = "craft-dialogs" version = "0.1.0" @@ -1721,6 +1771,14 @@ name = "craft-fonts-build" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540#77c7c62345c1f4213f59a07d9fdc156ecde0b540" +[[package]] +name = "craft-geom" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +dependencies = [ + "serde", +] + [[package]] name = "craft-heif" version = "0.1.0" @@ -1789,8 +1847,8 @@ dependencies = [ "craft-dds", "craft-heif", "craft-jpeg", - "craft-metadata", - "craft-tiff", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "crc32fast", "exr", "flate2", @@ -1904,7 +1962,19 @@ source = "git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a0 dependencies = [ "brotli-decompressor 6.3.2", "chrono", - "craft-tiff", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", + "quick-xml 0.41.0", + "serde", +] + +[[package]] +name = "craft-metadata" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +dependencies = [ + "brotli-decompressor 6.3.2", + "chrono", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062)", "quick-xml 0.41.0", "serde", ] @@ -2072,8 +2142,8 @@ source = "git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a0 dependencies = [ "chrono", "craft-crw", - "craft-metadata", - "craft-tiff", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "jxl-oxide", "miniz_oxide 0.9.1", "rayon", @@ -2224,6 +2294,15 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-tiff" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-time" version = "0.1.0" @@ -6336,7 +6415,7 @@ dependencies = [ "clap", "core-graphics2", "craft", - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "craft-image-codecs", "craft-svg", "craft-update", @@ -6384,7 +6463,9 @@ name = "photocraft-algo" version = "0.23.1" dependencies = [ "craft", - "craft-metadata", + "craft-develop", + "craft-develop-model", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "criterion", "photocraft-color", "photocraft-geom", @@ -6436,7 +6517,7 @@ dependencies = [ "clap_complete", "clap_mangen", "craft", - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "craft-image-codecs", "craft-psd", "photocraft-automation", @@ -6459,7 +6540,7 @@ dependencies = [ name = "photocraft-color" version = "0.23.1" dependencies = [ - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "craft-tracked", "craft-ui-macros", "serde", @@ -6469,7 +6550,7 @@ dependencies = [ name = "photocraft-compose" version = "0.23.1" dependencies = [ - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "criterion", "photocraft-color", "photocraft-doc", @@ -6503,7 +6584,8 @@ dependencies = [ "chrono", "craft", "craft-affinity", - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", + "craft-develop-model", "craft-file-formats", "craft-image-codecs", "craft-pcraft-format", @@ -6583,7 +6665,7 @@ name = "photocraft-gpu" version = "0.23.1" dependencies = [ "bytemuck", - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "half", "log", "photocraft-algo", @@ -6606,7 +6688,7 @@ dependencies = [ "blake3", "craft", "craft-affinity", - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "craft-crs", "craft-docpath", "craft-file-formats", @@ -6617,7 +6699,7 @@ dependencies = [ "craft-pdn", "craft-psd", "craft-svg", - "craft-tiff", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "craft-xcf", "craft-xml", "crc32fast", @@ -6675,7 +6757,7 @@ name = "photocraft-paint" version = "0.23.1" dependencies = [ "base64 0.23.1", - "craft-cms", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77c7c62345c1f4213f59a07d9fdc156ecde0b540)", "craft-tracked", "craft-ui-macros", "photocraft-color", diff --git a/Cargo.toml b/Cargo.toml index 0bbdcba3f8..0eecf9c47d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,8 @@ craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "77c7c6234 # Camera-field EXIF reader/writer, shared prerequisite craft-libs#1563. craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "77c7c62345c1f4213f59a07d9fdc156ecde0b540" } craft-crs = { git = "https://github.com/storytold/craft-libs", rev = "77c7c62345c1f4213f59a07d9fdc156ecde0b540" } +craft-develop = { git = "https://github.com/storytold/craft-libs", rev = "c42c34bfa127b095fb0a8d5ccaba0c168c254062" } +craft-develop-model = { git = "https://github.com/storytold/craft-libs", rev = "c42c34bfa127b095fb0a8d5ccaba0c168c254062" } # Interface translations: lookup, fallback, CLDR plurals and language names over the craft-i18n # catalogs that `crates/ui-egui/build.rs` embeds from `CRAFT_I18N_DIR` (storytold/craft-i18n, at # the commit in `craft-i18n.rev`). Already in the tree through craft. diff --git a/crates/algo/Cargo.toml b/crates/algo/Cargo.toml index 89ae1be3de..ae350d1ff2 100644 --- a/crates/algo/Cargo.toml +++ b/crates/algo/Cargo.toml @@ -10,11 +10,14 @@ rust-version.workspace = true workspace = true [dependencies] +craft-develop = { workspace = true } +craft-develop-model = { workspace = true } craft-metadata = { workspace = true } photocraft-geom = { workspace = true } photocraft-color = { workspace = true } photocraft-raster = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true } rustfft = "6.4.1" # `craft::imaging::fold_order`, `RawDevelopSettings` and `WideAngleSession`; the facade's `ui` stays off, so algo is egui-free. craft = { workspace = true, features = ["imaging"] } @@ -25,7 +28,6 @@ rayon = { workspace = true } [dev-dependencies] photocraft-testkit = { workspace = true } -serde_json = { workspace = true } criterion = { workspace = true } [[bench]] diff --git a/crates/algo/src/camera_raw.rs b/crates/algo/src/camera_raw.rs index 240c86cc76..f4fd95340a 100644 --- a/crates/algo/src/camera_raw.rs +++ b/crates/algo/src/camera_raw.rs @@ -312,52 +312,34 @@ fn guided(i: &[f32], p: &[f32], w: usize, h: usize, r: usize, eps: f32) -> Vec Vec { + // Keep the legacy f32 knot selection; normalizing in f64 can drop a saved knot. let mut p: Vec<[f32; 2]> = pts.iter().map(|q| [q[0] / 255.0, q[1] / 255.0]).collect(); p.sort_by(|a, b| a[0].total_cmp(&b[0])); p.dedup_by(|a, b| (a[0] - b[0]).abs() < 1e-6); - if p.len() < 2 { - return (0..n).map(|k| k as f32 / (n - 1) as f32).collect(); + if p.len() < 2 || n < 2 { + return (0..n).map(|k| if n <= 1 { 0.0 } else { k as f32 / (n - 1) as f32 }).collect(); } - let m = p.len(); - let d: Vec = (0..m - 1).map(|k| (p[k + 1][1] - p[k][1]) / (p[k + 1][0] - p[k][0]).max(1e-6)).collect(); - let mut t = vec![0.0f32; m]; - t[0] = d[0]; - t[m - 1] = d[m - 2]; - for k in 1..m - 1 { - t[k] = if d[k - 1] * d[k] <= 0.0 { 0.0 } else { (d[k - 1] + d[k]) / 2.0 }; - } - for k in 0..m - 1 { - if d[k] == 0.0 { - t[k] = 0.0; - t[k + 1] = 0.0; - continue; - } - let (a, b) = (t[k] / d[k], t[k + 1] / d[k]); - let s = a * a + b * b; - if s > 9.0 { - let tau = 3.0 / s.sqrt(); - t[k] = tau * a * d[k]; - t[k + 1] = tau * b * d[k]; - } - } - (0..n) - .map(|i| { - let x = i as f32 / (n - 1) as f32; - if x <= p[0][0] { - return p[0][1]; - } - if x >= p[m - 1][0] { - return p[m - 1][1]; - } - let k = p.windows(2).position(|wv| x <= wv[1][0]).unwrap_or(m - 2); - let hh = p[k + 1][0] - p[k][0]; - let s = (x - p[k][0]) / hh; - let (h00, h10, h01, h11) = (2.0 * s * s * s - 3.0 * s * s + 1.0, s * s * s - 2.0 * s * s + s, -2.0 * s * s * s + 3.0 * s * s, s * s * s - s * s); - (h00 * p[k][1] + h10 * hh * t[k] + h01 * p[k + 1][1] + h11 * hh * t[k + 1]).clamp(0.0, 1.0) - }) - .collect() + let p: Vec<_> = p.into_iter().map(|[x, y]| (f64::from(x), f64::from(y))).collect(); + craft_develop::color::spline::MonotoneCurve::new(&p).to_lut(n).v.into_iter().map(|v| v.clamp(0.0, 1.0)).collect() +} + +/// Migrate a PhotoCraft Camera Raw / `filter.cameraRaw` settings object to shared +/// [`craft_develop_model::DevelopSettings`], stripping PhotoCraft-only transport keys +/// (`layer`, `encodingGamma`, `__cameraRawPsd`) before delegating to +/// [`craft_develop_model::migration::migrate_camera_raw`]. +pub fn migrate_to_develop_settings( + base: &craft_develop_model::DevelopSettings, + fields: &serde_json::Value, +) -> Result { + let Some(obj) = fields.as_object() else { + return craft_develop_model::migration::migrate_camera_raw(base, fields); + }; + let cleaned: serde_json::Map = + obj.iter().filter(|(k, _)| !matches!(k.as_str(), "layer" | "encodingGamma" | "__cameraRawPsd")).map(|(k, v)| (k.clone(), v.clone())).collect(); + craft_develop_model::migration::migrate_camera_raw(base, &serde_json::Value::Object(cleaned)) } fn lut_eval(lut: &[f32], v: f32) -> f32 { @@ -1084,6 +1066,15 @@ mod tests { } } + #[test] + fn camera_raw_curve_keeps_legacy_close_knots() { + // The middle knots survive the original f32 normalization and make a sharp step. + let x = 127.5_f32; + let close = f32::from_bits(x.to_bits() + 33); + let lut = curve_lut(&[[0.0, 0.0], [x, 0.0], [close, 255.0], [255.0, 255.0]], 1024); + assert!(lut[256] < 0.01 && lut[767] > 0.99, "expected the legacy step, got {} and {}", lut[256], lut[767]); + } + #[test] fn curves_hsl_grading_detail_effects() { // Monotone cubic LUT through the points. diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 6cf1a53a76..0ce0aa8d6f 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -74,6 +74,7 @@ photocraft-ipp = { workspace = true } [dev-dependencies] craft-affinity = { workspace = true, features = ["synth"] } +craft-develop-model = { workspace = true } photocraft-io = { workspace = true, features = ["testgen"] } # Synthetic camera raw files for the open tests. photocraft-raw = { workspace = true, features = ["testgen"] } diff --git a/crates/engine/tests/it/camera_raw_baseline_pin.rs b/crates/engine/tests/it/camera_raw_baseline_pin.rs new file mode 100644 index 0000000000..e0e26cd252 --- /dev/null +++ b/crates/engine/tests/it/camera_raw_baseline_pin.rs @@ -0,0 +1,240 @@ +//! Pre-cutover baseline pins for `filter.cameraRaw` (pixel layer, smart filter, alpha, identity; #587 / #778). + +use photocraft_doc::LayerContent; +use photocraft_engine::Session; +use serde_json::json; + +fn active_pixel(s: &Session, x: i32, y: i32) -> [f32; 4] { + let st = s.active().unwrap(); + let layer = st.active_layer.and_then(|id| st.doc.layer(id)).unwrap(); + layer.surface().unwrap().rgba(x, y) +} + +#[test] +fn camera_raw_filter_preserves_identity_alpha_and_smart_filter_parity() { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 16, "height": 16, "depth": 16})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + s.execute("select.rect", json!({"x": 0, "y": 0, "width": 16, "height": 16})).unwrap(); + s.execute("edit.fill", json!({"contents": "color", "color": "#4080c0", "opacity": 50.0})).unwrap(); + s.execute("select.deselect", json!({})).unwrap(); + + let before = active_pixel(&s, 8, 8); + assert!((before[3] - 0.5).abs() < 0.02, "expected ~50% alpha: {before:?}"); + + // Identity filter leaves non-RAW pixels bit-identical. + s.execute("filter.cameraRaw", json!({})).unwrap(); + assert_eq!(active_pixel(&s, 8, 8), before); + + // Non-trivial filter preserves alpha and matches Smart Filter rendering. + let params = json!({ + "temperature": 15.0, + "tint": -10.0, + "exposure": 0.5, + "contrast": 20.0, + "highlights": -25.0, + "shadows": 30.0, + "vibrance": 15.0, + }); + + let mut smart_session = Session::new(); + smart_session.execute("file.new", json!({"width": 16, "height": 16, "depth": 16})).unwrap(); + smart_session.execute("layer.new.layer", json!({})).unwrap(); + smart_session.execute("select.rect", json!({"x": 0, "y": 0, "width": 16, "height": 16})).unwrap(); + smart_session.execute("edit.fill", json!({"contents": "color", "color": "#4080c0", "opacity": 50.0})).unwrap(); + smart_session.execute("select.deselect", json!({})).unwrap(); + smart_session.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + + s.execute("filter.cameraRaw", params.clone()).unwrap(); + smart_session.execute("filter.cameraRaw", params).unwrap(); + + let direct = active_pixel(&s, 8, 8); + assert!((direct[3] - before[3]).abs() < 1e-4, "alpha must be preserved: {before:?} -> {direct:?}"); + assert_ne!(direct[0..3], before[0..3], "RGB must change under non-default settings"); + + let smart_st = smart_session.active().unwrap(); + let smart_layer = smart_st.active_layer.and_then(|id| smart_st.doc.layer(id)).unwrap(); + let LayerContent::Smart(so) = &smart_layer.content else { + panic!("expected smart object"); + }; + assert_eq!(so.smart_filters.len(), 1); + assert_eq!(so.smart_filters[0].command, "filter.cameraRaw"); + let rendered = smart_layer.surface().unwrap().rgba(8, 8); + for c in 0..4 { + assert!((rendered[c] - direct[c]).abs() < 1e-3, "channel {c}: smart {rendered:?} vs direct {direct:?}"); + } +} + +#[test] +fn camera_raw_filter_legacy_baseline_pixels() { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 16, "height": 16, "depth": 16})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + s.execute("select.rect", json!({"x": 0, "y": 0, "width": 8, "height": 16})).unwrap(); + s.execute("edit.fill", json!({"contents": "color", "color": "#4080c0"})).unwrap(); + s.execute("select.rect", json!({"x": 8, "y": 0, "width": 8, "height": 16})).unwrap(); + s.execute("edit.fill", json!({"contents": "color", "color": "#c06020"})).unwrap(); + s.execute("select.deselect", json!({})).unwrap(); + + s.execute( + "filter.cameraRaw", + json!({ + "temperature": 15.0, + "tint": -10.0, + "exposure": 0.5, + "contrast": 20.0, + "highlights": -25.0, + "shadows": 30.0, + "whites": 10.0, + "blacks": -10.0, + "vibrance": 15.0, + "saturation": -5.0, + }), + ) + .unwrap(); + + let quantize = |px: [f32; 4]| px.map(|v| (v.clamp(0.0, 1.0) * 65535.0).round() as u16); + let got = [quantize(active_pixel(&s, 2, 2)), quantize(active_pixel(&s, 8, 8)), quantize(active_pixel(&s, 13, 13))]; + assert_eq!(got, [[19650, 39061, 56622, 65535], [57965, 29220, 10084, 65535], [57965, 29220, 10084, 65535]]); +} + +#[test] +fn camera_raw_smart_filter_migrates_to_shared_develop_settings() { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 8, "height": 8, "depth": 16})).unwrap(); + s.execute("edit.assignProfile", json!({"profile": "prophoto-compat"})).unwrap(); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + s.execute( + "filter.cameraRaw", + json!({ + "temperature": 18.0, + "tint": -12.0, + "exposure": 0.75, + "contrast": 22.0, + "highlights": -35.0, + "shadows": 40.0, + "whites": 15.0, + "blacks": -10.0, + "texture": 12.0, + "clarity": 16.0, + "dehaze": 8.0, + "vibrance": 20.0, + "saturation": -5.0, + "curveSplits": [25.0, 50.0, 75.0], + "pointCurve": [[0.0, 0.0], [64.0, 52.0], [255.0, 255.0]], + "hslHue": [5.0, -10.0, 0.0, 12.0, -4.0, 8.0, 0.0, -3.0], + "gradeShadows": {"hue": 210.0, "sat": 25.0, "lum": -5.0}, + "vignetteAmount": -20.0, + "vignetteStyle": "highlightPriority", + "shadowTint": -6.0, + "calibrationHue": [4.0, -3.0, 2.0] + }), + ) + .unwrap(); + + let st = s.active().unwrap(); + let layer = st.active_layer.and_then(|id| st.doc.layer(id)).unwrap(); + let LayerContent::Smart(so) = &layer.content else { + panic!("expected smart object"); + }; + assert_eq!(so.smart_filters[0].params["encodingGamma"], json!(1.8)); + let base = craft_develop_model::DevelopSettings::default(); + let migrated = photocraft_algo::camera_raw::migrate_to_develop_settings(&base, &so.smart_filters[0].params).unwrap(); + assert!(migrated.unmapped_fields.is_empty(), "unexpected unmapped fields: {:?}", migrated.unmapped_fields); + assert_eq!(migrated.settings.process, base.process); + assert_eq!(migrated.settings.light.exposure, 0.75); + assert_eq!(migrated.settings.light.contrast, 22.0); + assert_eq!(migrated.settings.wb.tint, -12.0); + assert_eq!(migrated.settings.vignette.style, craft_develop_model::VignetteStyle::HighlightPriority); +} + +#[test] +fn camera_raw_migration_preserves_exposure_presence_after_native_reopen() { + use std::sync::Arc; + + use craft_develop_model::{DevelopSettings, Process}; + use photocraft_color::{BlendMode, ColorMode, SampleType}; + use photocraft_doc::{Document, Layer, Size, SmartFilter, SmartObject, SmartSource}; + use photocraft_geom::Affine; + + // Original synthetic content. Exercise the native serializer, not the PSD importer. + let size = Size::new(2, 2); + let mut source = Session::new(); + source.execute("file.new", json!({"width": 2, "height": 2, "depth": 16})).unwrap(); + let embedded = Arc::new(photocraft_format::save_to_bytes(&source.active().unwrap().doc, &Default::default()).unwrap()); + let mut base = DevelopSettings { process: Process::V8.version(), ..Default::default() }; + base.light.exposure = -0.75; + base.light.contrast = 12.0; + for (params, expected) in [(json!({"encodingGamma": 1.8}), -0.75), (json!({"encodingGamma": 1.8, "exposure": 0.0}), 0.0)] { + let source = SmartSource::Embedded { file_name: "generated.pcraft".into(), bytes: embedded.clone() }; + let mut smart = SmartObject::new(source, Affine::IDENTITY, None); + smart.smart_filters.push(SmartFilter { + command: "filter.cameraRaw".into(), + params: params.clone(), + blend: BlendMode::Normal, + opacity: 1.0, + visible: true, + }); + let mut doc = Document::new("Saved Camera Raw exposure", size, ColorMode::Rgb, SampleType::U16); + doc.layers.push(Layer::new("Stored filter", LayerContent::Smart(smart))); + + let saved = photocraft_format::save_to_bytes(&doc, &Default::default()).unwrap(); + let reopened = photocraft_format::load_from_bytes(&saved).unwrap(); + let LayerContent::Smart(smart) = &reopened.layers[0].content else { panic!("expected reopened Smart Object") }; + let [filter] = smart.smart_filters.as_slice() else { panic!("expected one stored Camera Raw filter") }; + assert_eq!(filter.command, "filter.cameraRaw"); + assert_eq!(filter.params, params); + let migrated = photocraft_algo::camera_raw::migrate_to_develop_settings(&base, &filter.params).unwrap(); + assert!(migrated.unmapped_fields.is_empty(), "{:?}", migrated.unmapped_fields); + assert_eq!(migrated.settings.process, base.process); + assert_eq!(migrated.settings.light.exposure, expected); + assert_eq!(migrated.settings.light.contrast, base.light.contrast); + } +} + +#[test] +fn reopened_camera_raw_smart_filter_keeps_legacy_close_curve_knots() { + use std::sync::Arc; + + use photocraft_color::{BlendMode, ColorMode, SampleType}; + use photocraft_doc::{Document, Layer, Rect, Size, SmartFilter, SmartObject, SmartSource}; + use photocraft_geom::Affine; + use photocraft_raster::Surface; + + // Original synthetic neutral ramp, saved as real embedded PhotoCraft content. + let size = Size::new(5, 3); + let mut inner = Document::new("Gray ramp", size, ColorMode::Rgb, SampleType::U16); + let mut ramp = Surface::new(inner.pixel_format()); + for (x, gray) in (0..5).zip([0.125, 0.25, 0.75, 0.875, 1.0]) { + ramp.fill_rect(Rect::new(x, 0, x + 1, 3), &[gray, gray, gray, 1.0]); + } + inner.layers.push(Layer::new("Ramp", LayerContent::Raster(ramp))); + let original = photocraft_format::save_to_bytes(&inner, &Default::default()).unwrap(); + let mut smart = SmartObject::new(SmartSource::Embedded { file_name: "ramp.pcraft".into(), bytes: Arc::new(original) }, Affine::IDENTITY, None); + // The modern command rejects this small gap. Store the historical settings as a + // Smart Filter and drive production's lenient replay, not the new-edit validator. + let near = f32::from_bits(127.5_f32.to_bits() + 33); + let curve = [[0.0, 0.0], [127.5, 0.0], [near, 255.0], [255.0, 255.0]]; + let params = json!({"pointCurve": curve}); + smart.smart_filters.push(SmartFilter { command: "filter.cameraRaw".into(), params: params.clone(), blend: BlendMode::Normal, opacity: 1.0, visible: true }); + let mut document = Document::new("Stored Camera Raw curve", size, ColorMode::Rgb, SampleType::U16); + document.layers.push(Layer::new("Stored filter", LayerContent::Smart(smart))); + + let saved = photocraft_format::save_to_bytes(&document, &Default::default()).unwrap(); + let reopened = photocraft_format::load_from_bytes(&saved).unwrap(); + let LayerContent::Smart(smart) = &reopened.layers[0].content else { panic!("expected reopened Smart Object") }; + let [filter] = smart.smart_filters.as_slice() else { panic!("expected one stored Camera Raw filter") }; + assert_eq!(filter.params, params); + let SmartSource::Embedded { bytes, .. } = &smart.source else { panic!("expected embedded ramp") }; + let placed = photocraft_format::load_from_bytes(bytes).unwrap(); + let LayerContent::Raster(ramp) = &placed.layers[0].content else { panic!("expected decoded ramp pixels") }; + assert!((ramp.rgba(2, 1)[0] - 0.75).abs() < 0.01); + + // Identity placement: the embedded raster is already the placed input. This + // production entry point replays the stored stack without using layer cache pixels. + let rendered = photocraft_engine::smart_cmds::apply_smart_filters(ramp, smart, reopened.bounds()).unwrap(); + let bright = rendered.rgba(2, 1); + assert!(bright[..3].iter().all(|&v| v > 0.9), "legacy close-knot step must brighten the upper midtone: {bright:?}"); + let dark = rendered.rgba(1, 1); + assert!(dark[..3].iter().all(|&v| v < 0.1), "the lower midtone remains below the step: {dark:?}"); +} diff --git a/crates/engine/tests/it/main.rs b/crates/engine/tests/it/main.rs index 32c55b9ff4..7616c561e2 100644 --- a/crates/engine/tests/it/main.rs +++ b/crates/engine/tests/it/main.rs @@ -35,6 +35,7 @@ mod background_and_mask_depth; mod background_job_target; mod background_layer_consistency; mod brush_smoothing; +mod camera_raw_baseline_pin; mod camera_raw_exposure_clamp; mod camera_raw_noise_clamp; mod canvas_artboard_crop; diff --git a/crates/format/tests/it/camera_raw_roundtrip.rs b/crates/format/tests/it/camera_raw_roundtrip.rs new file mode 100644 index 0000000000..afb9c609d3 --- /dev/null +++ b/crates/format/tests/it/camera_raw_roundtrip.rs @@ -0,0 +1,98 @@ +//! Pins `.pcraft` serialization of `filter.cameraRaw` Smart Filters (pre-cutover baseline, #587 / #778). + +use photocraft_color::{BlendMode, ColorMode, SampleType}; +use photocraft_doc::{Document, Layer, LayerContent, Size, SmartContentsId, SmartFilter, SmartObject, SmartSource}; +use photocraft_geom::Affine; + +#[test] +fn pcraft_roundtrips_camera_raw_smart_filter_params() { + let mut doc = Document::new("CameraRawPin", Size::new(16, 16), ColorMode::Rgb, SampleType::U16); + let params: serde_json::Value = serde_json::from_str( + r#"{ + "temperature": 18.0, + "tint": -12.0, + "exposure": 0.75, + "contrast": 22.0, + "highlights": -35.0, + "shadows": 40.0, + "whites": 15.0, + "blacks": -10.0, + "texture": 12.0, + "clarity": 16.0, + "dehaze": 8.0, + "vibrance": 20.0, + "saturation": -5.0, + "curveShadows": 10.0, + "curveDarks": -8.0, + "curveLights": 12.0, + "curveHighlights": -6.0, + "curveSplits": [25.0, 50.0, 75.0], + "pointCurve": [[0.0, 0.0], [64.0, 52.0], [192.0, 204.0], [255.0, 255.0]], + "hslHue": [5.0, -10.0, 0.0, 12.0, -4.0, 8.0, 0.0, -3.0], + "hslSat": [10.0, 5.0, -8.0, 0.0, 6.0, -12.0, 4.0, 0.0], + "hslLum": [-4.0, 8.0, 2.0, -6.0, 0.0, 10.0, -2.0, 3.0], + "gradeShadows": {"hue": 210.0, "sat": 25.0, "lum": -5.0}, + "gradeMidtones": {"hue": 45.0, "sat": 10.0, "lum": 0.0}, + "gradeHighlights": {"hue": 35.0, "sat": 20.0, "lum": 4.0}, + "gradeGlobal": {"hue": 0.0, "sat": 0.0, "lum": 2.0}, + "gradeBlending": 60.0, + "gradeBalance": -15.0, + "sharpenAmount": 40.0, + "sharpenRadius": 1.2, + "sharpenDetail": 30.0, + "sharpenMasking": 20.0, + "noiseLuminance": 15.0, + "noiseLuminanceDetail": 50.0, + "noiseColor": 25.0, + "noiseColorDetail": 50.0, + "grainAmount": 12.0, + "grainSize": 25.0, + "grainRoughness": 50.0, + "vignetteAmount": -20.0, + "vignetteMidpoint": 45.0, + "vignetteFeather": 55.0, + "vignetteRoundness": 10.0, + "vignetteHighlights": 15.0, + "vignetteStyle": "highlightPriority", + "shadowTint": -6.0, + "calibrationHue": [4.0, -3.0, 2.0], + "calibrationSat": [8.0, -5.0, 6.0], + "encodingGamma": 1.8 + }"#, + ) + .unwrap(); + let smart = Layer::new( + "RawSmart", + LayerContent::Smart(SmartObject { + contents_id: SmartContentsId::fresh(), + vector_preview: None, + source: SmartSource::Embedded { file_name: "inner.png".into(), bytes: std::sync::Arc::new(vec![1, 2, 3, 4]) }, + transform: Affine::IDENTITY, + smart_filters: vec![SmartFilter { + command: "filter.cameraRaw".into(), + params: params.clone(), + blend: BlendMode::Normal, + opacity: 1.0, + visible: true, + }], + cache: None, + psd_raw: None, + filters_enabled: true, + filter_mask: None, + warp: None, + stack_mode: None, + perspective: None, + }), + ); + doc.layers.push(smart); + + let bytes = photocraft_format::save_to_bytes(&doc, &Default::default()).unwrap(); + let back = photocraft_format::load_from_bytes(&bytes).unwrap(); + assert_eq!(back, doc); + let LayerContent::Smart(so) = &back.layers[0].content else { + panic!("expected SmartObject after .pcraft roundtrip"); + }; + assert_eq!(so.smart_filters.len(), 1); + assert_eq!(so.smart_filters[0].command, "filter.cameraRaw"); + assert_eq!(so.smart_filters[0].params, params); +} diff --git a/crates/format/tests/it/main.rs b/crates/format/tests/it/main.rs index 057fc1e9bc..8da62a3e54 100644 --- a/crates/format/tests/it/main.rs +++ b/crates/format/tests/it/main.rs @@ -2,6 +2,7 @@ mod analysis; mod autosave; +mod camera_raw_roundtrip; mod common; mod corruption; mod directory_symlinks; diff --git a/crates/io/tests/it/raw.rs b/crates/io/tests/it/raw.rs index 89846774e6..34bcfe985d 100644 --- a/crates/io/tests/it/raw.rs +++ b/crates/io/tests/it/raw.rs @@ -686,3 +686,127 @@ fn a_kept_decode_gives_the_same_pixels_and_decodes_once() { assert_eq!(pixels(&got), pixels(&import_raw_tuned("a.nef", &nef, &RawTuning::default()).unwrap().0)); assert_eq!((got.document.size.width, got.document.size.height), (w as u32, h as u32)); } + +#[test] +fn raw_open_legacy_baseline_pixels() { + use photocraft_io::raw::{RawTuning, import_raw_tuned}; + + fn fnv1a_u16(bytes: &[u8]) -> u64 { + let mut h = 0xcbf2_9ce4_8422_2325u64; + for &b in bytes { + h ^= u64::from(b); + h = h.wrapping_mul(0x0100_0000_01b3); + } + h + } + + fn sample_rgb16(bytes: &[u8], w: usize, x: usize, y: usize) -> [u16; 3] { + let off = (y * w + x) * 6; + [ + u16::from_ne_bytes([bytes[off], bytes[off + 1]]), + u16::from_ne_bytes([bytes[off + 2], bytes[off + 3]]), + u16::from_ne_bytes([bytes[off + 4], bytes[off + 5]]), + ] + } + + let (w, h) = (16, 16); + let mut spec = DngSpec::cfa(w, h, mosaic(&scene(w, h), w, [0, 1, 1, 2], 0, 65535)); + spec.as_shot_neutral = Some([0.6, 1.0, 0.8]); + let bytes = spec.build(); + + let def = import("pin.dng", &bytes).unwrap(); + let def_img = photocraft_io::document_to_image(&def.document, &mut Vec::new()).unwrap(); + let def_px = [sample_rgb16(def_img.data(), w, 0, 0), sample_rgb16(def_img.data(), w, 7, 7), sample_rgb16(def_img.data(), w, 15, 15)]; + let def_hash = fnv1a_u16(def_img.data()); + + let tuning = RawTuning { + exposure: 0.75, + temperature: 15.0, + tint: -10.0, + shadows: 25.0, + highlights: -20.0, + clarity: 15.0, + texture: 10.0, + dehaze: 5.0, + ..Default::default() + }; + let (tuned, wb) = import_raw_tuned("pin.dng", &bytes, &tuning).unwrap(); + let tuned_img = photocraft_io::document_to_image(&tuned.document, &mut Vec::new()).unwrap(); + let tuned_px = [sample_rgb16(tuned_img.data(), w, 0, 0), sample_rgb16(tuned_img.data(), w, 7, 7), sample_rgb16(tuned_img.data(), w, 15, 15)]; + let tuned_hash = fnv1a_u16(tuned_img.data()); + + assert_eq!( + (def_px, def_hash, wb, tuned_px, tuned_hash), + ( + [[29624, 25113, 50386], [47838, 39368, 49721], [54364, 41011, 44877]], + 4_077_782_316_697_218_873, + false, + [[39218, 33230, 65535], [63447, 52123, 65535], [65535, 54111, 59021]], + 13_721_670_327_866_894_160, + ) + ); +} + +#[test] +fn raw_open_camera_wb_legacy_baseline_pixels() { + use photocraft_io::raw::{RawTuning, import_raw_tuned}; + + fn fnv1a_u16(bytes: &[u8]) -> u64 { + let mut h = 0xcbf2_9ce4_8422_2325u64; + for &b in bytes { + h ^= u64::from(b); + h = h.wrapping_mul(0x0100_0000_01b3); + } + h + } + + fn sample_rgb16(bytes: &[u8], w: usize, x: usize, y: usize) -> [u16; 3] { + let off = (y * w + x) * 6; + [ + u16::from_ne_bytes([bytes[off], bytes[off + 1]]), + u16::from_ne_bytes([bytes[off + 2], bytes[off + 3]]), + u16::from_ne_bytes([bytes[off + 4], bytes[off + 5]]), + ] + } + + let (w, h) = (16, 16); + let cam = scene(w, h); + let no_wb_bytes = nef_uncompressed(&cam, w, h, None); + let wb_bytes = nef_uncompressed_with_wb(&cam, w, h, None, Some([2048, 1536])); + + let no_wb_def = import("no_wb.nef", &no_wb_bytes).unwrap(); + let no_wb_img = photocraft_io::document_to_image(&no_wb_def.document, &mut Vec::new()).unwrap(); + + let def = import("wb.nef", &wb_bytes).unwrap(); + let def_img = photocraft_io::document_to_image(&def.document, &mut Vec::new()).unwrap(); + assert_ne!(def_img.data(), no_wb_img.data(), "camera WB must change developed pixels"); + let def_px = [sample_rgb16(def_img.data(), w, 0, 0), sample_rgb16(def_img.data(), w, 7, 7), sample_rgb16(def_img.data(), w, 15, 15)]; + let def_hash = fnv1a_u16(def_img.data()); + + let tuning = RawTuning { + exposure: 0.75, + temperature: 15.0, + tint: -10.0, + shadows: 25.0, + highlights: -20.0, + clarity: 15.0, + texture: 10.0, + dehaze: 5.0, + ..Default::default() + }; + let (tuned, wb) = import_raw_tuned("wb.nef", &wb_bytes, &tuning).unwrap(); + assert!(wb, "camera WB must be applied"); + let tuned_img = photocraft_io::document_to_image(&tuned.document, &mut Vec::new()).unwrap(); + let tuned_px = [sample_rgb16(tuned_img.data(), w, 0, 0), sample_rgb16(tuned_img.data(), w, 7, 7), sample_rgb16(tuned_img.data(), w, 15, 15)]; + let tuned_hash = fnv1a_u16(tuned_img.data()); + + assert_eq!( + (def_px, def_hash, tuned_px, tuned_hash), + ( + [[32172, 25684, 55879], [51905, 40291, 54669], [54973, 41164, 49114]], + 11_079_887_031_689_206_845, + [[41995, 33769, 65535], [65535, 53416, 65535], [65535, 54256, 62211]], + 14_795_269_389_460_323_633, + ) + ); +} diff --git a/crates/ui-egui/src/menu_floor_trials.rs b/crates/ui-egui/src/menu_floor_trials.rs index f61e567f98..fa053354c9 100644 --- a/crates/ui-egui/src/menu_floor_trials.rs +++ b/crates/ui-egui/src/menu_floor_trials.rs @@ -194,3 +194,32 @@ fn the_status_bar_sits_inside_the_window_when_its_views_run_and_replay() { ); } } + +/// The status message and the render-path note at the bar's far end are shown in memoized views, whose content the +/// bar's row does not lay out: each must still stand on the readout's line, in the middle of the bar (#16352). +#[test] +fn the_status_message_and_the_trailing_note_stand_on_the_readouts_line() { + let mut h = harness(1, 0, 0); + let message = "Scratch disk is low on free space"; + h.state_mut().ui.status = message.into(); + h.state_mut().ui.status_error = true; + let doc = h.state().session.active().map(|st| st.doc.id.0).expect("a document is open"); + h.state_mut().perf.gpu_layer_fit = Some(crate::canvas::gpu_canvas::LayerFit { doc, needed: 2 << 30, budget: 1 << 30 }); + h.run_steps(4); + let centre = |h: &H, label: &str| { + let Some(node) = h.query_all_by_label(label).max_by(|a, b| a.rect().bottom().total_cmp(&b.rect().bottom())) else { + panic!("the status bar shows {label:?}") + }; + node.rect().center().y + }; + let readout = centre(&h, "400 px x 300 px (72 ppi)"); + let Some(bar) = h.query_all_by_role(egui::accesskit::Role::Status).find(|n| n.accesskit_node().label().as_deref() == Some("Status")) else { + panic!("the window shows the status bar") + }; + let middle = bar.rect().center().y; + assert!((readout - middle).abs() <= 0.5, "the readout is centred at y {readout}, in the middle of the status bar at y {middle}"); + for label in [message, "GPU Memory Full"] { + let y = centre(&h, label); + assert!((y - readout).abs() <= 0.5, "{label:?} is centred at y {y}, on the readout's line at y {readout} (#16352)"); + } +} diff --git a/crates/ui-egui/src/panels/status_bar.rs b/crates/ui-egui/src/panels/status_bar.rs index 9ca8bd15da..342cf9175f 100644 --- a/crates/ui-egui/src/panels/status_bar.rs +++ b/crates/ui-egui/src/panels/status_bar.rs @@ -3,6 +3,7 @@ use craft::behavior::kurbo::Size; use craft::theme::variant::Tone; use craft::ui::bars::{Bar, BarKind, StatusItem, StatusMessage, StatusProgress, StatusReadout, StatusValues}; use craft::ui::contract::{Bind, MemoProps, MemoView, Outbox, ShowContainer as _}; +use craft::ui::layout_components::Row; use craft::ui::runtime::commands::CommandRef; use craft::ui::text::InvalidZoom; @@ -119,8 +120,16 @@ pub fn status_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { chrome_ui::zoom_alert(app, invalid_zoom); } -/// The status bar's trailing group. +/// The status bar's trailing group, in a row of its own centred down the bar's height, so its members stand on the +/// body's line: the bar's end region lays its children out from its top, and a memoized view's content is a layout +/// room the bar's row does not reach into (#16352). fn trailing_view(props: &mut TrailingProps<'_>, ui: &mut egui::Ui) { + let centred = ui.layout().with_cross_align(egui::Align::Center); + ui.with_layout(centred, |ui| Row::new().show(ui, |ui, _| trailing_members(props, ui))); +} + +/// The members of the status bar's trailing group: the render-path note, the background redraw and the job. +fn trailing_members(props: &mut TrailingProps<'_>, ui: &mut egui::Ui) { if let Some(shown) = &props.render_path { shown.show(ui); } @@ -134,8 +143,14 @@ fn trailing_view(props: &mut TrailingProps<'_>, ui: &mut egui::Ui) { } } -/// The status bar's body. +/// The status bar's body, in a row of its own: a memoized view's content is a layout room the bar's row does not reach +/// into, so without it the message would sit at the top of the bar instead of on the readout's line (#16352). fn body_view(props: &mut StatusProps<'_>, ui: &mut egui::Ui) { + Row::new().show(ui, |ui, _| body_members(props, ui)); +} + +/// The members of the status bar's body: the readout, or "No document", and the status message. +fn body_members(props: &mut StatusProps<'_>, ui: &mut egui::Ui) { match (props.document, props.view) { (Some(size), Some(view)) => { let out = StatusReadout::new(Bind::given(view), size, props.item, &props.values).show(ui);