LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #1238
bflatasticfa3dfbbc4aab
diff --cc crates/ui-egui/src/panels/edit.rsindex d5e8f0159,ecd9662de..76a54171f--- a/crates/ui-egui/src/panels/edit.rs+++ b/crates/ui-egui/src/panels/edit.rs@@@ -539,21 -523,44 +541,52 @@@ fn section// ------------------------------------------------------------------------------ histogram+/// The current photo's existing preview histogram, shared by Histogram and Tone Curve.+fn preview_histogram(app: &LightcraftApp, id: PhotoId) -> Option<lightcraft_raster::Histogram> {+ app.renderer+ .textures+ .get(&Slot::Main)+ .filter(|t| t.photo == id)+ .and_then(|t| t.histogram.clone())+ .or_else(|| app.renderer.textures.get(&Slot::Thumb(id)).and_then(|t| t.histogram.clone()))+}++ /// An HDR edit's histogram stays an HDR histogram: some renders carry only their 8-bit image's+ /// (a drag's drafts, a cached thumbnail or stand-in), and showing those would swap the panel to+ /// the SDR layout and back while a slider moves. Every render with HDR bins replaces the one kept for the photo, so+ /// the histogram still follows the edit live; an SDR edit shows what it gets.+ fn steady_hdr_histogram(ctx: &egui::Context, id: PhotoId, hdr_edit: bool, hist: Option<Histogram>) -> Option<Histogram> {+ let key = egui::Id::new(("hdrHistogram", id));+ match hist {+ Some(h) if h.hdr.is_some() => {+ ctx.data_mut(|d| d.insert_temp(key, h.clone()));+ Some(h)+ }+ h if hdr_edit => ctx.data(|d| d.get_temp::<Histogram>(key)).or(h),+ h => h,+ }+ }+fn histogram(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) {let t = Tokens::get(ui.ctx());let w = ui.available_width();- // the loupe render of this photo, else its thumbnail- let hist = preview_histogram(app, id);+ let hdr_edit = app.session.develop_of(id).is_some_and(|d| d.hdr.enabled);+ // a drag of an HDR edit: its drafts have no HDR histogram, so a small render beside them+ // gives one (at its own pace: the drafts don't wait for it)+ let interacting = app.session.interaction.is_some();+ if interacting && hdr_edit {+ let edge = lightcraft_pipeline::HDR_HISTOGRAM_DRAG_EDGE;+ if let Some(job) = app.session.render_job(id, edge, edge, false, app.ui.right != RightPanel::Crop)+ && app.renderer.live_hdr_histogram.as_ref().is_none_or(|l| l.1 != job.key)+ {+ app.renderer.request(Slot::HdrHistogram, job, 95);+ }+ }+ let live = app.renderer.live_hdr_histogram.as_ref().filter(|l| interacting && l.0 == id).map(|l| l.2.clone());+ // else the loupe render of this photo, else its thumbnail (grid view before the loupe has+ // rendered it)- let hist = live- .or_else(|| app.renderer.textures.get(&Slot::Main).filter(|t| t.photo == id).and_then(|t| t.histogram.clone()))- .or_else(|| app.renderer.textures.get(&Slot::Thumb(id)).and_then(|t| t.histogram.clone()));++ let hist = live.or_else(|| preview_histogram(app, id));+ let hist = steady_hdr_histogram(ui.ctx(), id, hdr_edit, hist);// an HDR edit's histogram (`pipeline::hdr_histogram`) gets a colour bar and an SDR / HDR label// row under the plotlet hdr = hist.as_ref().and_then(|h| h.hdr);@@@ -1640,27 -1465,28 +1673,53 @@@ fn quick_develop(app: &mut LightcraftAp});}+#[cfg(test)]+mod curve_histogram_tests {+ use super::*;++ #[test]+ fn curve_backdrop_tracks_luma_and_selected_channel() {+ let img = lightcraft_raster::Rgba8::from_fn(64, 32, |x, _| if x < 32 { [32, 100, 32, 255] } else { [224, 100, 224, 255] });+ let h = lightcraft_raster::Histogram::of_srgb8(&img);+ let red = curve_histogram_profile(&h, "red");+ let green = curve_histogram_profile(&h, "green");+ let luma = curve_histogram_profile(&h, "master");+ assert!(red[32] > red[150] && red[224] > red[150]);+ assert!(green[100] > green[32] && green[100] > green[224]);+ assert!(luma.iter().any(|v| *v > 0.0));+ }++ #[test]+ fn hdr_backdrop_uses_only_the_sdr_bins_and_never_overflows() {+ let h = lightcraft_raster::Histogram::of_hdr(&[[0.1, 0.1, 0.1], [1.0, 1.0, 1.0], [8.0, 8.0, 8.0]], 4.0);+ let values = curve_histogram_profile(&h, "parametric");+ assert!(values.iter().all(|v| v.is_finite() && (0.0..=1.0).contains(v)));+ assert!(values.iter().any(|v| *v > 0.0));+ }+}+++ #[cfg(test)]+ mod tests {+ use super::*;++ #[test]+ fn an_hdr_edit_keeps_its_hdr_histogram_through_8_bit_renders() {+ let ctx = egui::Context::default();+ let id = PhotoId(7);+ let sdr = Histogram::of_hdr(&[], 5.0);+ let sdr = Histogram { hdr: None, ..sdr };+ let hdr = |v: f32| Histogram::of_hdr(&[[v, v, v]], 5.0);+ // nothing kept yet: what arrives+ assert_eq!(steady_hdr_histogram(&ctx, id, true, Some(sdr.clone())), Some(sdr.clone()));+ assert_eq!(steady_hdr_histogram(&ctx, id, true, Some(hdr(2.0))), Some(hdr(2.0)));+ // a cached thumbnail's 8-bit histogram (or none) doesn't swap the panel to SDR+ assert_eq!(steady_hdr_histogram(&ctx, id, true, Some(sdr.clone())), Some(hdr(2.0)));+ assert_eq!(steady_hdr_histogram(&ctx, id, true, None), Some(hdr(2.0)));+ // the next HDR render replaces it: the histogram follows the slider+ assert_eq!(steady_hdr_histogram(&ctx, id, true, Some(hdr(4.0))), Some(hdr(4.0)));+ assert_eq!(steady_hdr_histogram(&ctx, id, true, Some(sdr.clone())), Some(hdr(4.0)));+ // HDR turned off: the SDR histogram at once; other photos keep their own+ assert_eq!(steady_hdr_histogram(&ctx, id, false, Some(sdr.clone())), Some(sdr.clone()));+ assert_eq!(steady_hdr_histogram(&ctx, PhotoId(8), true, Some(sdr.clone())), Some(sdr));+ }+ }diff --cc docs/parity-checklist.mdindex fa57f06d0,5aa003041..0860d391c--- a/docs/parity-checklist.md+++ b/docs/parity-checklist.md@@@ -150,8 -138,8 +150,10 @@@ differences and missing bindings are i| LR-VIEW-SLIDESHOW | Slideshow | P2 | ✅ | `cmd:view.slideshow` | View ▸ Slideshow (⌥⌘↩): the photos in view full screen, every 4 s (`interval`), wrapping; Space pauses, ←/→ step, Esc ends || LR-VIEW-SECONDWINDOW | Second display window [Classic] | P2 | ✅ | `cmd:view.secondWindow`, `crates/ui-egui/src/panels/second.rs` | Window ▸ Second Window (⌘F11): the active photo fitted in its own native window with its own render (a floating panel where there are no native windows); loupe view only (no grid / compare / survey there) || LR-VIEW-CLIPPING | Clipping indicators | P0 | ✅ | `cmd:view.clipping` | |+| LR-VIEW-HISTOGRAM | Histogram | P0 | ✅ | `cmd:view.histogram`, `crates/ui-egui/src/panels/edit.rs`, `crates/pipeline/src/lib.rs` (`hdr_histogram`) | HDR edits: SDR on the left half, the HDR range (0 to 5 stops above SDR white, a fixed scale) on the right with the headroom limit marked; colour bar (white, or Visualize HDR range's colours when that is on) and SDR / HDR labels; no drag-to-adjust on the histogram |+| LR-VIEW-HDR-DISPLAY | HDR display output | P2 | ⬜ | `apps/lightcraft/src/hdr_display.rs` (`choose`, `preferred_hdr_format`) | SDR/HDR decision (platform, surface format, OS headroom, `LIGHTCRAFT_HDR_DISPLAY=0`) is unit-tested and logged at start; always SDR today because eframe configures an 8-bit surface; no OS headroom query yet |+ | LR-VIEW-HISTOGRAM | Histogram | P0 | ✅ | `cmd:view.histogram`, `crates/ui-egui/src/panels/edit.rs`, `crates/pipeline/src/lib.rs` (`hdr_histogram`) | HDR edits: SDR on the left half, the HDR range (0 to 5 stops above SDR white, a fixed scale) on the right with the headroom limit marked; colour bar (white, or Visualize HDR range's colours when that is on) and SDR / HDR labels; it follows slider drags live (a small render beside the drafts, `Slot::HdrHistogram`) and never drops to the SDR layout mid-drag; no drag-to-adjust on the histogram |+ | LR-VIEW-HDR-DISPLAY | HDR display output | P2 | ⬜ | | |## D. Search & filter (FILT)