Skip to main content

Module histogram

Module histogram 

Source
Expand description

A histogram drawn from bins the application computed (the scopes’ computation stays with the application): one filled curve per channel, linear or logarithmic, with clipping markers and a drag handed back to the application.

Experimental: may change in any release (docs/stability.md).
  • Channels: each Channel has its bins (any scale; they are normalised together) and its colour.
  • Clipping: Histogram::clipping lights a marker in a bottom corner when shadows or highlights are clipped (the fractions the application measured), in the histogram.clip-* colours.
  • Drag: Histogram::draggable makes the histogram a control, as in darktable where dragging the histogram drags the exposure. The widget owns no value: it hands the gesture back as Changes of a Drag (where the gesture began, and how far it moved, in widths of the histogram). Ctrl (Cmd) is ten times finer, Shift ten times coarser; Escape gives the gesture up. When focused, the left and right arrows move by a step.
  • Edit area: a draggable histogram registers as an edit area (egui_pop_core::areas): the framework draws its grip at rest on its right edge, and a hover card naming what the drag writes (Histogram::edits: “Exposure +0.30 EV”); a histogram that is not draggable registers as a display area, without a grip. Inside a panel whose state is not current the drag is inert: no grip, no drag, and a drag under way is given up.

The changes in HistogramOutput::changes say how far the gesture has moved so far, from from to to: applying to.delta - from.delta to the application’s value each time (HistogramOutput::moved) keeps it in step, including when a hook vetoes or redirects the gesture at its end, or when Escape gives it up (a change back to 0 comes then).

The on_change hook sees the drag’s frames (done: false), its end once more from 0 (done: true), and each key; egui-pop-imaging runs the finished ones as the histogram.drag step of an application.

use egui_pop_viewport::histogram::{Channel, Clipping, Histogram};

fn ui(ui: &mut egui::Ui, luma: &[f32], exposure: &mut f64) {
    let out = Histogram::new([Channel::new("Luminance", luma, egui::Color32::GRAY)])
        .log(true)
        .clipping(Clipping { shadows: 0.0, highlights: 0.004 })
        .draggable(true)
        .show(ui);
    // Four stops per width of the histogram.
    *exposure += f64::from(out.moved()) * 4.0;
}

Structs§

Channel
One channel: its bins (any scale; they are normalised) and colour.
Clipping
What is clipped, as the application measured it: the fraction of pixels (0 to 1) at or below black, and at or above white.
Drag
A drag on the histogram: where it began (a fraction of the width, 0 on the left; None for keys and assistive actions) and how far it has moved, in widths of the histogram (positive to the right).
Histogram
The histogram widget.
HistogramOutput
What the histogram did in a frame.
HistogramTokens
The histogram’s colours, from the theme (histogram.*).

Functions§

heights
The heights (0..1) of a channel’s bins, normalised by max.