mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 01:44:25 +00:00
Adjustment editor stories: each editor's cases in one card (Black & White, Channel Mixer, Selective Color, Color Balance tones, Photo Filter, Levels with a grayscale document, Curves with an isolated mask and a bumpy pencil curve)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
//! Stories of Brightness/Contrast, Threshold, Color Balance and Photo Filter.
|
||||
|
||||
use super::{
|
||||
BrightnessContrast, BrightnessContrastEditor, ColorBalance, ColorBalanceEditor, PhotoFilter, PhotoFilterEditor, PhotoFilterPreset,
|
||||
ThresholdEditor,
|
||||
BrightnessContrast, BrightnessContrastEditor, ColorBalance, ColorBalanceEditor, ColorBalanceTone, PhotoFilter, PhotoFilterEditor,
|
||||
PhotoFilterPreset, ThresholdEditor,
|
||||
};
|
||||
use crate::ui::curve::stories::story_bins;
|
||||
use crate::ui::histogram::{ChannelColor, HistogramData};
|
||||
@@ -25,21 +25,41 @@ fn threshold(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ThresholdEditor::new("Threshold", Bind::bound(level)).histogram(&histogram).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorBalanceEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn color_balance(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("value", ColorBalance { midtones: [20.0, -10.0, 5.0], ..ColorBalance::default() });
|
||||
ColorBalanceEditor::new("Color Balance", Bind::bound(value)).show(ui).into()
|
||||
fn color_balance(ui: &mut Ui, data: &mut StoryData, start: ColorBalanceTone) -> StoryOutput {
|
||||
let value = data.value(
|
||||
"value",
|
||||
ColorBalance { shadows: [-20.0, 0.0, 30.0], midtones: [10.0, -15.0, 0.0], highlights: [25.0, 10.0, -20.0], ..ColorBalance::default() },
|
||||
);
|
||||
let tone = data.value("tone", start);
|
||||
let shown = ColorBalanceEditor::new("Color Balance", Bind::bound(value)).tone(*tone).show(ui);
|
||||
*tone = shown.tone;
|
||||
shown.into()
|
||||
}
|
||||
|
||||
#[story(ColorBalanceEditor<'static>, covers = [], drive = Drive::Never, group = "Tones", title = "Shadows")]
|
||||
fn color_balance_shadows(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
color_balance(ui, data, ColorBalanceTone::Shadows)
|
||||
}
|
||||
|
||||
#[story(ColorBalanceEditor<'static>, covers = [Default], drive = Drive::Never, group = "Tones", title = "Midtones")]
|
||||
fn color_balance_midtones(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
color_balance(ui, data, ColorBalanceTone::Midtones)
|
||||
}
|
||||
|
||||
#[story(ColorBalanceEditor<'static>, covers = [], drive = Drive::Never, group = "Tones", title = "Highlights")]
|
||||
fn color_balance_highlights(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
color_balance(ui, data, ColorBalanceTone::Highlights)
|
||||
}
|
||||
|
||||
/// A filter preset: the Filter row is on.
|
||||
#[story(PhotoFilterEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
#[story(PhotoFilterEditor<'static>, covers = [Default], drive = Drive::Never, group = "Sources", title = "A filter preset")]
|
||||
fn photo_filter_preset(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("preset", PhotoFilter { color: PhotoFilterPreset::Cooling80.color(), density: 25.0, preserve_luminosity: true });
|
||||
PhotoFilterEditor::new("Photo Filter", Bind::bound(value)).show(ui).into()
|
||||
}
|
||||
|
||||
/// A colour of no preset: the Color row is on, and the select offers Custom.
|
||||
#[story(PhotoFilterEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
#[story(PhotoFilterEditor<'static>, covers = [], drive = Drive::Never, group = "Sources", title = "A custom color")]
|
||||
fn photo_filter_color(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("color", PhotoFilter { color: Srgba::rgb(0.4, 0.2, 0.6), density: 60.0, preserve_luminosity: false });
|
||||
PhotoFilterEditor::new("Photo Filter", Bind::bound(value)).show(ui).into()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
//! Stories of the Curves panel: points mode with the other channels as overlays, and pencil mode.
|
||||
//! Stories of the Curves panel in one card: points mode with the other channels as overlays, pencil mode, and an
|
||||
//! isolated mask channel.
|
||||
|
||||
use super::{CurvesMode, CurvesPanel, ToneCurves};
|
||||
use crate::ui::adjust::{ToneChannels, TonePicker, ToneSpace};
|
||||
use crate::ui::adjust::{ToneChannel, ToneChannels, TonePicker, ToneSpace};
|
||||
use crate::ui::curve::Curve;
|
||||
use crate::ui::curve::stories::story_bins;
|
||||
use crate::ui::histogram::ChannelColor;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -23,7 +25,12 @@ fn counts(shift: f32) -> [u32; 256] {
|
||||
counts
|
||||
}
|
||||
|
||||
#[story(CurvesPanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
/// A drawn curve with bumps, so Smooth has something to smooth.
|
||||
fn bumpy_map() -> Vec<f32> {
|
||||
(0..=255).map(|level| (level as f32 + 14.0 * (level as f32 / 255.0 * std::f32::consts::TAU * 3.0).sin()).clamp(0.0, 255.0)).collect()
|
||||
}
|
||||
|
||||
#[story(CurvesPanel<'static>, covers = [Default], drive = Drive::Never, group = "Modes", title = "Points")]
|
||||
fn curves_panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let channels = ToneChannels::of(ToneSpace::Rgb, false);
|
||||
let mut curves = ToneCurves::identity(&channels);
|
||||
@@ -34,10 +41,17 @@ fn curves_panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
CurvesPanel::new("Curves", Bind::bound(&mut rig.curves), channels).histograms(&histograms).pickers(Bind::bound(&mut rig.armed)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(CurvesPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
#[story(CurvesPanel<'static>, covers = [], drive = Drive::Never, group = "Modes", title = "Pencil, with Smooth")]
|
||||
fn curves_panel_pencil(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let channels = ToneChannels::of(ToneSpace::Rgb, false);
|
||||
let drawn = ToneCurves { curves: vec![Curve::Map((0..=255).map(|level| level as f32).collect()); channels.len()], mode: CurvesMode::Pencil };
|
||||
let drawn = ToneCurves { curves: vec![Curve::Map(bumpy_map()); channels.len()], mode: CurvesMode::Pencil };
|
||||
let curves = data.value("drawn", drawn);
|
||||
CurvesPanel::new("Curves", Bind::bound(curves), channels).histograms(&[counts(0.0), counts(0.0), counts(0.0), counts(0.0)]).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(CurvesPanel<'static>, covers = [], drive = Drive::Never, group = "Modes", title = "One isolated mask channel")]
|
||||
fn curves_panel_isolated_mask(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let channels = ToneChannels::isolated(ToneChannel::Named { name: "Layer mask".to_owned(), color: ChannelColor::Neutral });
|
||||
let curves = data.value("mask", ToneCurves::identity(&channels));
|
||||
CurvesPanel::new("Curves", Bind::bound(curves), channels).histograms(&[counts(0.0)]).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Stories of the Levels panel: the composite with the point pickers, and an isolated mask channel.
|
||||
//! Stories of the Levels panel in one card: the composite with the point pickers, after Auto, a picker armed, a
|
||||
//! grayscale document, and an isolated mask channel.
|
||||
|
||||
use super::LevelsPanel;
|
||||
use crate::ui::adjust::{Levels, ToneChannel, ToneChannels, TonePicker, ToneSpace};
|
||||
use crate::ui::adjust::{AdjustContext, Levels, ToneChannel, ToneChannels, TonePicker, ToneSpace};
|
||||
use crate::ui::curve::stories::story_bins;
|
||||
use crate::ui::histogram::ChannelColor;
|
||||
use craft_ui::contract::Bind;
|
||||
@@ -23,34 +24,46 @@ fn counts(shift: f32) -> [u32; 256] {
|
||||
counts
|
||||
}
|
||||
|
||||
fn rgb_panel(ui: &mut Ui, data: &mut StoryData, key: &'static str, levels: Vec<Levels>, armed: Option<TonePicker>) -> StoryOutput {
|
||||
let rig = data.value(key, Rig { levels, armed });
|
||||
let histograms = [counts(0.0), counts(0.0), counts(12.0), counts(-12.0)];
|
||||
LevelsPanel::new("Levels", Bind::bound(&mut rig.levels), ToneChannels::of(ToneSpace::Rgb, false))
|
||||
.histograms(&histograms)
|
||||
/// The panel over `channels` with the point pickers, in `context`.
|
||||
fn panel(ui: &mut Ui, data: &mut StoryData, channels: ToneChannels, context: AdjustContext, histograms: &[[u32; 256]], start: Rig) -> StoryOutput {
|
||||
let rig = data.value("rig", start);
|
||||
LevelsPanel::new("Levels", Bind::bound(&mut rig.levels), channels)
|
||||
.histograms(histograms)
|
||||
.pickers(Bind::bound(&mut rig.armed))
|
||||
.context(context)
|
||||
.show(ui)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[story(LevelsPanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn levels_panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
rgb_panel(ui, data, "rig", vec![Levels::identity(0.0..=255.0); 4], None)
|
||||
fn rgb_panel(ui: &mut Ui, data: &mut StoryData, levels: Vec<Levels>, armed: Option<TonePicker>) -> StoryOutput {
|
||||
let histograms = [counts(0.0), counts(0.0), counts(12.0), counts(-12.0)];
|
||||
panel(ui, data, ToneChannels::of(ToneSpace::Rgb, false), AdjustContext::dialog(true), &histograms, Rig { levels, armed })
|
||||
}
|
||||
|
||||
#[story(LevelsPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
#[story(LevelsPanel<'static>, covers = [Default], drive = Drive::Never, group = "Channels", title = "RGB with a histogram")]
|
||||
fn levels_panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
rgb_panel(ui, data, vec![Levels::identity(0.0..=255.0); 4], None)
|
||||
}
|
||||
|
||||
#[story(LevelsPanel<'static>, covers = [], drive = Drive::Never, group = "Channels", title = "After Auto")]
|
||||
fn levels_panel_after_auto(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut levels = vec![Levels::identity(0.0..=255.0); 4];
|
||||
levels[0] = levels[0].auto(&counts(0.0));
|
||||
rgb_panel(ui, data, "auto", levels, None)
|
||||
rgb_panel(ui, data, levels, None)
|
||||
}
|
||||
|
||||
#[story(LevelsPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
#[story(LevelsPanel<'static>, covers = [], drive = Drive::Never, group = "Channels", title = "Black point picker armed")]
|
||||
fn levels_panel_picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
rgb_panel(ui, data, "picker", vec![Levels::identity(0.0..=255.0); 4], Some(TonePicker::Black))
|
||||
rgb_panel(ui, data, vec![Levels::identity(0.0..=255.0); 4], Some(TonePicker::Black))
|
||||
}
|
||||
|
||||
#[story(LevelsPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
#[story(LevelsPanel<'static>, covers = [], drive = Drive::Never, group = "Channels", title = "Grayscale document")]
|
||||
fn levels_panel_gray(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let start = Rig { levels: vec![Levels::identity(0.0..=255.0)], armed: None };
|
||||
panel(ui, data, ToneChannels::of(ToneSpace::Rgb, true), AdjustContext::dialog(true).gray(true), &[counts(0.0)], start)
|
||||
}
|
||||
|
||||
#[story(LevelsPanel<'static>, covers = [], drive = Drive::Never, group = "Channels", title = "One isolated mask channel")]
|
||||
fn levels_panel_isolated_mask(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let levels = data.value("mask", vec![Levels::identity(0.0..=255.0)]);
|
||||
let channels = ToneChannels::isolated(ToneChannel::Named { name: "Layer mask".to_owned(), color: ChannelColor::Neutral });
|
||||
|
||||
@@ -1,29 +1,63 @@
|
||||
//! Stories of Black & White, Channel Mixer and Selective Color.
|
||||
//! Stories of Black & White, Channel Mixer and Selective Color: each editor's cases in one card.
|
||||
|
||||
use super::{BlackWhite, BlackWhiteEditor, ChannelMixer, ChannelMixerEditor, SelectiveColor, SelectiveColorEditor};
|
||||
use craft_theme::Srgba;
|
||||
use super::{BlackWhite, BlackWhiteEditor, ChannelMixer, ChannelMixerEditor, SelectiveColor, SelectiveColorEditor, SelectiveMethod};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
/// Tint on, with its colour well.
|
||||
#[story(BlackWhiteEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn black_white_tinted(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("value", BlackWhite { tint: true, tint_color: Srgba::rgb(0.88, 0.83, 0.7), ..BlackWhite::default() });
|
||||
fn black_white(ui: &mut Ui, data: &mut StoryData, start: BlackWhite) -> StoryOutput {
|
||||
let value = data.value("value", start);
|
||||
BlackWhiteEditor::new("Black & White", Bind::bound(value)).show(ui).into()
|
||||
}
|
||||
|
||||
/// Monochrome on: the one Gray output, and a Total over 100 % that warns.
|
||||
#[story(ChannelMixerEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn channel_mixer_monochrome(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("value", ChannelMixer { gray: Some([60.0, 60.0, 20.0, 0.0]), ..ChannelMixer::default() });
|
||||
#[story(BlackWhiteEditor<'static>, covers = [Default], drive = Drive::Never, group = "Tint", title = "Default")]
|
||||
fn black_white_default(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
black_white(ui, data, BlackWhite::default())
|
||||
}
|
||||
|
||||
/// Tint on, with its colour well.
|
||||
#[story(BlackWhiteEditor<'static>, covers = [], drive = Drive::Never, group = "Tint", title = "Tinted")]
|
||||
fn black_white_tinted(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
black_white(ui, data, BlackWhite { weights: [60.0, 80.0, 30.0, 70.0, 10.0, 40.0], tint: true, ..BlackWhite::default() })
|
||||
}
|
||||
|
||||
fn channel_mixer(ui: &mut Ui, data: &mut StoryData, start: ChannelMixer) -> StoryOutput {
|
||||
let value = data.value("value", start);
|
||||
ChannelMixerEditor::new("Channel Mixer", Bind::bound(value)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(SelectiveColorEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn selective_color(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut start = SelectiveColor::default();
|
||||
start.ranges[0] = [10.0, -20.0, 30.0, 0.0];
|
||||
#[story(ChannelMixerEditor<'static>, covers = [Default], drive = Drive::Never, group = "Outputs", title = "Color")]
|
||||
fn channel_mixer_color(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
channel_mixer(ui, data, ChannelMixer { red: [80.0, 20.0, 0.0, 0.0], ..ChannelMixer::default() })
|
||||
}
|
||||
|
||||
/// Monochrome on: the one Gray output.
|
||||
#[story(ChannelMixerEditor<'static>, covers = [], drive = Drive::Never, group = "Outputs", title = "Monochrome")]
|
||||
fn channel_mixer_monochrome(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
channel_mixer(ui, data, ChannelMixer { gray: Some(ChannelMixer::MONOCHROME_START), ..ChannelMixer::default() })
|
||||
}
|
||||
|
||||
/// A Total over 100 % warns.
|
||||
#[story(ChannelMixerEditor<'static>, covers = [], drive = Drive::Never, group = "Outputs", title = "Total over 100 %")]
|
||||
fn channel_mixer_over(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
channel_mixer(ui, data, ChannelMixer { red: [70.0, 50.0, 0.0, 0.0], ..ChannelMixer::default() })
|
||||
}
|
||||
|
||||
fn selective_color(ui: &mut Ui, data: &mut StoryData, start: SelectiveColor) -> StoryOutput {
|
||||
let value = data.value("value", start);
|
||||
SelectiveColorEditor::new("Selective Color", Bind::bound(value)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(SelectiveColorEditor<'static>, covers = [Default], drive = Drive::Never, group = "Methods", title = "Relative")]
|
||||
fn selective_color_relative(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut start = SelectiveColor::default();
|
||||
start.ranges[0] = [30.0, -10.0, 20.0, 0.0];
|
||||
selective_color(ui, data, start)
|
||||
}
|
||||
|
||||
#[story(SelectiveColorEditor<'static>, covers = [], drive = Drive::Never, group = "Methods", title = "Absolute")]
|
||||
fn selective_color_absolute(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut start = SelectiveColor { method: SelectiveMethod::Absolute, ..SelectiveColor::default() };
|
||||
start.ranges[0] = [-20.0, 25.0, 0.0, 10.0];
|
||||
selective_color(ui, data, start)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user