diff --git a/Cargo.lock b/Cargo.lock index 97e3ae5f2b..c85fe08a08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1504,7 +1504,7 @@ dependencies = [ [[package]] name = "craft-cms" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" dependencies = [ "md-5", "rayon", @@ -1527,7 +1527,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=e953d47a378776dea20789 [[package]] name = "craft-color" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" dependencies = [ "serde", ] @@ -1535,9 +1535,9 @@ dependencies = [ [[package]] name = "craft-color-transform" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" dependencies = [ - "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062)", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26)", "craft-color", "serde", ] @@ -1587,6 +1587,14 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-crw" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" +dependencies = [ + "thiserror 2.0.21", +] + [[package]] name = "craft-crw" version = "0.1.0" @@ -1606,10 +1614,13 @@ dependencies = [ [[package]] name = "craft-develop" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" dependencies = [ + "craft-color", "craft-color-transform", "craft-develop-model", + "craft-geom", + "craft-raw 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26)", "rayon", "serde", ] @@ -1617,10 +1628,10 @@ dependencies = [ [[package]] name = "craft-develop-model" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" dependencies = [ "craft-geom", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26)", "miniz_oxide 0.9.1", "serde", "serde_json", @@ -1694,7 +1705,7 @@ dependencies = [ "craft-kra", "craft-ora", "craft-pcraft-bundle", - "craft-raw", + "craft-raw 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e953d47a378776dea207899b10baf969fc8cbe53)", "craft-svg", "craft-zip", "serde", @@ -1774,7 +1785,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=e953d47a378776dea20789 [[package]] name = "craft-geom" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" dependencies = [ "serde", ] @@ -1958,11 +1969,11 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" dependencies = [ "brotli-decompressor 6.3.2", "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26)", "quick-xml 0.41.0", "serde", ] @@ -2135,13 +2146,31 @@ dependencies = [ "objc2-app-kit 0.3.2", ] +[[package]] +name = "craft-raw" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" +dependencies = [ + "chrono", + "craft-crw 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26)", + "jxl-oxide", + "miniz_oxide 0.9.1", + "rayon", + "serde", + "thiserror 2.0.21", + "zune-core", + "zune-jpeg", +] + [[package]] name = "craft-raw" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=e953d47a378776dea207899b10baf969fc8cbe53#e953d47a378776dea207899b10baf969fc8cbe53" dependencies = [ "chrono", - "craft-crw", + "craft-crw 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e953d47a378776dea207899b10baf969fc8cbe53)", "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e953d47a378776dea207899b10baf969fc8cbe53)", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e953d47a378776dea207899b10baf969fc8cbe53)", "jxl-oxide", @@ -2288,7 +2317,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c42c34bfa127b095fb0a8d5ccaba0c168c254062#c42c34bfa127b095fb0a8d5ccaba0c168c254062" +source = "git+https://github.com/storytold/craft-libs?rev=7631ed550ef6b1abcc90a095dd7338e1b2c67c26#7631ed550ef6b1abcc90a095dd7338e1b2c67c26" dependencies = [ "serde", "thiserror 2.0.21", @@ -6807,8 +6836,9 @@ dependencies = [ name = "photocraft-raw" version = "0.23.1" dependencies = [ + "craft-develop", "craft-image-codecs", - "craft-raw", + "craft-raw 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e953d47a378776dea207899b10baf969fc8cbe53)", "flate2", "image", "photocraft-raw", diff --git a/Cargo.toml b/Cargo.toml index 5c0066c3a3..06ecee7964 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,8 +67,8 @@ craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "e953d47a3 # Camera-field EXIF reader/writer, shared prerequisite craft-libs#1563. craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "e953d47a378776dea207899b10baf969fc8cbe53" } craft-crs = { git = "https://github.com/storytold/craft-libs", rev = "e953d47a378776dea207899b10baf969fc8cbe53" } -craft-develop = { git = "https://github.com/storytold/craft-libs", rev = "c42c34bfa127b095fb0a8d5ccaba0c168c254062" } -craft-develop-model = { git = "https://github.com/storytold/craft-libs", rev = "c42c34bfa127b095fb0a8d5ccaba0c168c254062" } +craft-develop = { git = "https://github.com/storytold/craft-libs", rev = "7631ed550ef6b1abcc90a095dd7338e1b2c67c26" } +craft-develop-model = { git = "https://github.com/storytold/craft-libs", rev = "7631ed550ef6b1abcc90a095dd7338e1b2c67c26" } # 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/engine/tests/it/camera_raw_baseline_pin.rs b/crates/engine/tests/it/camera_raw_baseline_pin.rs index e0e26cd252..b8977bb937 100644 --- a/crates/engine/tests/it/camera_raw_baseline_pin.rs +++ b/crates/engine/tests/it/camera_raw_baseline_pin.rs @@ -238,3 +238,83 @@ fn reopened_camera_raw_smart_filter_keeps_legacy_close_curve_knots() { let dark = rendered.rgba(1, 1); assert!(dark[..3].iter().all(|&v| v < 0.1), "the lower midtone remains below the step: {dark:?}"); } + +#[test] +fn camera_raw_filter_preserves_alpha_separately() { + use photocraft_algo::camera_raw::{self, CameraRaw, DevelopInputs}; + + let (w, h) = (32, 32); + let alphas = [0.0_f32, 0.25, 0.5, 0.75, 1.0]; + let mut px = Vec::with_capacity(w * h); + for y in 0..h { + for x in 0..w { + let a = alphas[(x + y) % alphas.len()]; + px.push([0.35 + (x as f32) * 0.005, 0.45, 0.55 - (y as f32) * 0.004, a]); + } + } + let original = px.clone(); + let mut p = CameraRaw::default(); + p.temperature = 20.0; + p.tint = -15.0; + p.exposure = 0.6; + p.contrast = 25.0; + p.highlights = -30.0; + p.shadows = 25.0; + p.clarity = 20.0; + p.texture = 25.0; + p.dehaze = 15.0; + p.sharpening = 30.0; + p.grain_amount = 20.0; + p.vignette = -25.0; + + camera_raw::develop(&mut px, w, h, &p, &DevelopInputs::default(), true); + + let mut rgb_changed = false; + for (i, (got, orig)) in px.iter().zip(original.iter()).enumerate() { + assert_eq!(got[3], orig[3], "alpha must be preserved separately at pixel {i}"); + if (0..3).any(|c| (got[c] - orig[c]).abs() > 1e-3) { + rgb_changed = true; + } + } + assert!(rgb_changed, "RGB channels should be modified by Camera Raw Filter"); +} + +#[test] +fn camera_raw_first_tiled_spatial_pass_matches_full_render_crop() { + use photocraft_algo::camera_raw::{self, CameraRaw, DevelopInputs}; + + let (full_w, full_h) = (128, 128); + let (tile_w, tile_h) = (96, 96); + let (crop_w, crop_h) = (64, 64); + + let make_buf = |w: usize, h: usize| -> Vec<[f32; 4]> { + let mut buf = Vec::with_capacity(w * h); + for y in 0..h { + for x in 0..w { + let wave = ((x as f32 * 0.35).sin() * (y as f32 * 0.25).cos()) * 0.15; + buf.push([(0.45 + wave).clamp(0.05, 0.95), (0.50 - wave * 0.5).clamp(0.05, 0.95), 0.42, 0.8]); + } + } + buf + }; + + let mut p = CameraRaw::default(); + p.texture = 40.0; + let inputs = DevelopInputs::default(); + + let mut full = make_buf(full_w, full_h); + camera_raw::develop(&mut full, full_w, full_h, &p, &inputs, true); + + let mut first_tile = make_buf(tile_w, tile_h); + camera_raw::develop(&mut first_tile, tile_w, tile_h, &p, &inputs, true); + + for y in 0..crop_h { + for x in 0..crop_w { + let f = full[y * full_w + x]; + let t = first_tile[y * tile_w + x]; + for c in 0..4 { + assert!((f[c] - t[c]).abs() < 1e-5, "first tiled spatial pass mismatch vs full render crop at ({x},{y}) ch {c}: full={} tile={}", f[c], t[c]); + } + } + } +} diff --git a/crates/raw/Cargo.toml b/crates/raw/Cargo.toml index 76410f1340..6d0b08d258 100644 --- a/crates/raw/Cargo.toml +++ b/crates/raw/Cargo.toml @@ -15,6 +15,7 @@ testgen = ["dep:image", "dep:flate2"] corpus = [] [dependencies] +craft-develop.workspace = true craft-raw.workspace = true # Synthetic fixture output used only by the retired format-parser tests. image = { workspace = true, features = ["jpeg"], optional = true } diff --git a/crates/raw/src/color.rs b/crates/raw/src/color.rs index 123754e90b..4d38808264 100644 --- a/crates/raw/src/color.rs +++ b/crates/raw/src/color.rs @@ -75,27 +75,7 @@ pub fn cct(xy: [f64; 2]) -> f64 { /// Approximate temperature of an EXIF `LightSource` code (the /// CalibrationIlluminant tags use the EXIF 2.3 table). `None` for unknown. pub fn illuminant_temperature(code: u32) -> Option { - Some(match code { - 17 => 2856.0, // Standard light A - 18 => 4874.0, // Standard light B - 19 => 6774.0, // Standard light C - 20 => 5503.0, // D55 - 21 => 6504.0, // D65 - 22 => 7504.0, // D75 - 23 => 5003.0, // D50 - 24 => 3200.0, // ISO studio tungsten - 3 => 2850.0, // Tungsten - 1 | 4 | 9 => 5500.0, // Daylight, flash, fine weather - 10 => 6500.0, // Cloudy - 11 => 7500.0, // Shade - 12 => 6430.0, // Daylight fluorescent - 13 => 5000.0, // Day white fluorescent - 14 => 4150.0, // Cool white fluorescent - 15 => 3525.0, // White fluorescent - 16 => 2925.0, // Warm white fluorescent - 2 => 4200.0, // Fluorescent - _ => return None, - }) + u16::try_from(code).ok().and_then(craft_develop::sensor::color::illuminant_temperature) } /// Bradford chromatic adaptation from white `src` to white `dst` (XYZ). diff --git a/crates/raw/tests/it/dng.rs b/crates/raw/tests/it/dng.rs index 1369ec643b..f6834576db 100644 --- a/crates/raw/tests/it/dng.rs +++ b/crates/raw/tests/it/dng.rs @@ -1280,3 +1280,67 @@ fn adjusted_crop_and_omitted_gain_table_notices_survive_development() { spec.default_crop_origin_double = None; check(&spec, Rect::new(3, 2, 11, 8), false, true); } + +/// Compare PhotoCraft's `develop_sensor` output converted from encoded ProPhoto RGB (D50, gamma 1.8) +/// into unclipped linear Rec.709/D65 against `craft_develop::sensor` at the same stage. +#[test] +fn raw_open_matches_craft_develop_in_unclipped_linear_rec709_d65() { + use craft_develop::sensor::{ + Cfa as SharedCfa, ColorData as SharedColorData, Method as SharedMethod, Normalized as SharedNormalized, color as shared_color, + demosaic as shared_demosaic, + }; + + let (w, h) = (32, 32); + // Mid-tone grey Bayer patch (RGGB) at ~25% of white = 65535. + let samples = vec![16384u16; w * h]; + let spec = DngSpec::cfa(w, h, samples.clone()); + let s = sensor(&spec.build()); + let dev = develop_sensor(&s, &DevelopOptions { orient: false, ..Default::default() }).unwrap(); + assert_eq!((dev.width as usize, dev.height as usize), (w, h)); + + // PhotoCraft `develop_sensor` outputs ProPhoto RGB (D50, gamma 1.8) u16; decode to linear + // ProPhoto, then convert D50 -> D65 -> linear Rec.709/D65. + let prophoto_to_xyz_d50 = shared_color::PROPHOTO.to_xyz(); + let d50_to_rec709_d65 = shared_color::SRGB.from_xyz().mul(&shared_color::bradford(shared_color::D50, shared_color::D65)); + let prophoto_to_rec709_d65 = d50_to_rec709_d65.mul(&prophoto_to_xyz_d50); + + // Shared `craft_develop::sensor` path in linear Rec.709/D65 on the same normalized sensor. + let norm = SharedNormalized { + width: w, + height: h, + cpp: 1, + data: samples.iter().map(|&v| f32::from(v) / 65535.0).collect(), + cfa: Some(SharedCfa { width: 2, height: 2, pattern: vec![0, 1, 1, 2], origin_x: 0, origin_y: 0 }), + }; + let mut color = SharedColorData::default(); + color.illuminant = [21, 0]; + color.color_matrix[0] = Some(shared_color::Mat3::IDENTITY); + let wb = shared_color::wb_multipliers(&color, shared_color::D65); + let cam_rgb = shared_demosaic(&norm, &wb, SharedMethod::Ahd); + let cam_to_rec709_d65 = d50_to_rec709_d65.mul(&shared_color::camera_to_xyz_d50(&color, shared_color::D65)); + + // Compare interior pixels (avoiding Bayer border effects) in linear Rec.709/D65. + for y in 4..(h - 4) { + for x in 4..(w - 4) { + let idx = (y * w + x) * 3; + let pp_lin = [ + (f64::from(dev.data[idx]) / 65535.0).powf(1.8), + (f64::from(dev.data[idx + 1]) / 65535.0).powf(1.8), + (f64::from(dev.data[idx + 2]) / 65535.0).powf(1.8), + ]; + let pc_rec709 = prophoto_to_rec709_d65.apply(pp_lin); + + let p = cam_rgb.pixel(x, y); + let shared_rec709 = cam_to_rec709_d65.apply([f64::from(p[0]), f64::from(p[1]), f64::from(p[2])]); + + for c in 0..3 { + assert!( + (pc_rec709[c] - shared_rec709[c]).abs() < 5e-3, + "linear Rec.709/D65 mismatch at ({x},{y}) ch {c}: photocraft={} shared={}", + pc_rec709[c], + shared_rec709[c] + ); + } + } + } +}