CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s
Owner review 1 R5 + R6. Camera rotation, mirror, flip, straighten and crop handles locked to the output; an Exposure Look group; Export output size ("proportions win"); settings format 2 with older-node gates. Also fixes project text and hashes differing between Windows and Linux.
Closes #19
Closes #20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
241 lines
13 KiB
C#
241 lines
13 KiB
C#
using Chronos.App.Infrastructure;
|
||
using Chronos.Core.Advice;
|
||
using Chronos.Core.Imaging.Color;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Core.Project;
|
||
using Chronos.Core.Render;
|
||
using Chronos.Ui.Visuals;
|
||
|
||
namespace Chronos.App.Editor;
|
||
|
||
/// <summary>The measuring tools of the Exposure tab (BRIEF §12.3 "luminance/waveform charts").</summary>
|
||
public enum ExposureChart
|
||
{
|
||
/// <summary>Measured luminance against the target curve, sky region and exposure steps.</summary>
|
||
Luminance,
|
||
|
||
/// <summary>Frame-to-frame luminance change before and after the correction.</summary>
|
||
Flicker,
|
||
|
||
/// <summary>Luma waveform of the corrected frame on screen.</summary>
|
||
Waveform,
|
||
}
|
||
|
||
/// <summary>
|
||
/// Exposure (BRIEF §12.3): deflicker, regions, holy-grail transitions, white balance and the look. The luminance chart shows the
|
||
/// measured luminance (Sun) against the target curve the corrections produce (Accent), the sky region (dashed) and the
|
||
/// exposure steps as received; the flicker chart the frame-to-frame change before and after correction; the waveform
|
||
/// the luma distribution of the corrected frame on screen.
|
||
/// </summary>
|
||
public sealed class ExposureTab : EditorTab
|
||
{
|
||
private IReadOnlyList<ChartSeries> _series = [];
|
||
private IReadOnlyList<ChartLegendItem> _legend = [];
|
||
private IReadOnlyList<TimelineMarker> _markers = [];
|
||
private string? _summary;
|
||
private ExposureChart _chartMode;
|
||
|
||
public ExposureTab(EditorViewModel editor)
|
||
: base(editor, "Exposure", AdvisorSection.Exposure)
|
||
{
|
||
var s = editor.Session;
|
||
// The same rule as the Edit path's (EditorSettings.Applies): a row shown n/a is never asked for.
|
||
string? NoDeflicker(ProjectSettings p) =>
|
||
EditorSettings.Applies(EditorSettings.DeflickerWindow, p, s.Content.Deep) ? null : Loc.L("Tooltips.Editor.NotApplicable.DeflickerOff");
|
||
string? NoHolyGrail(ProjectSettings p) =>
|
||
EditorSettings.Applies(EditorSettings.TransitionLength, p, s.Content.Deep) ? null : Loc.L("Tooltips.Editor.NotApplicable.HolyGrailOff");
|
||
Rows =
|
||
[
|
||
new AutoSwitchRow(s, EditorSettings.Deflicker, "Editor.Exposure.Deflicker", "Tooltips.Editor.Exposure.Deflicker"),
|
||
new AutoNumberRow<int>(s, EditorSettings.DeflickerWindow, "Editor.Exposure.Window", "Tooltips.Editor.Exposure.Window", 5, 151, 2, "0", NoDeflicker),
|
||
new AutoNumberRow<double>(s, EditorSettings.DeflickerStrength, "Editor.Exposure.Strength", "Tooltips.Editor.Exposure.Strength", 0, 1, 0.05, "0.00", NoDeflicker),
|
||
new AutoChoiceRow<RegionMode>(s, EditorSettings.Regions, "Editor.Exposure.Regions", "Tooltips.Editor.Exposure.Regions",
|
||
[
|
||
new Choice(RegionMode.Off, "Editor.Value.Off"), new Choice(RegionMode.Auto, "Editor.Regions.Auto"),
|
||
new Choice(RegionMode.Horizon, "Editor.Regions.Horizon"), new Choice(RegionMode.Luminance, "Editor.Regions.Luminance"),
|
||
], NoDeflicker),
|
||
new AutoSwitchRow(s, EditorSettings.HolyGrail, "Editor.Exposure.HolyGrail", "Tooltips.Editor.Exposure.HolyGrail"),
|
||
new AutoNumberRow<int>(s, EditorSettings.TransitionLength, "Editor.Exposure.Transitions", "Tooltips.Editor.Exposure.Transitions", 0, 120, 1, "0", NoHolyGrail),
|
||
new AutoSwitchRow(s, EditorSettings.WhiteBalance, "Editor.Exposure.WhiteBalance", "Tooltips.Editor.Exposure.WhiteBalance"),
|
||
new InfoRow("Editor.Exposure.Temperature", "Tooltips.Editor.Exposure.Temperature", Temperature),
|
||
new NumberRow(s, "Editor.Exposure.Offset", "Tooltips.Editor.Exposure.Offset", -3, 3, 0.1, p => p.Exposure.ExposureOffsetEv,
|
||
(p, v) => p with { Exposure = p.Exposure with { ExposureOffsetEv = v } }, v => Loc.L("Editor.Value.Ev", EditorText.Ev(v))),
|
||
.. LookRows(s),
|
||
];
|
||
Refresh();
|
||
BuildChart();
|
||
}
|
||
|
||
/// <summary>
|
||
/// The Look group at the end of the step (owner review 1, R6): the filter (None, Mono, Sepia, Warm, Cool, Vivid, Muted,
|
||
/// Fade) and its strength, "n/a" without a filter. The look is a project setting outside Exposure, so moving these never
|
||
/// measures again (<see cref="WithLook"/>).
|
||
/// </summary>
|
||
public static IReadOnlyList<SettingRow> LookRows(EditorSession session)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(session);
|
||
string? NoLook(ProjectSettings p) => HasFilter(p) ? null : Loc.L("Tooltips.Editor.NotApplicable.NoLook");
|
||
return
|
||
[
|
||
new GroupRow("Editor.Look.Group", "Tooltips.Editor.Look.Group"),
|
||
new ChoiceRow(session, "Editor.Look.Filter", "Tooltips.Editor.Look.Filter",
|
||
[.. LookFilter.Names.Select(n => new Choice(n, "Editor.Look." + char.ToUpperInvariant(n[0]) + n[1..]))],
|
||
p => p.Look?.Filter ?? LookFilter.None, (p, v) => WithLook(p, (string)v, p.Look?.Strength)),
|
||
new NumberRow(session, "Editor.Look.Strength", "Tooltips.Editor.Look.Strength", MinimumStrength, 1, 0.01, p => HasFilter(p) ? p.Look!.Strength ?? 1 : 1,
|
||
(p, v) => WithLook(p, p.Look?.Filter, double.Round(v, 2)), v => Formatting.Percent(v), NoLook),
|
||
];
|
||
}
|
||
|
||
/// <summary>
|
||
/// The Strength row's lowest value: None is the one way to a look that changes nothing, so the editor never stores a
|
||
/// filter at 0 % (an identity look that would still change the project's text and hash).
|
||
/// </summary>
|
||
public const double MinimumStrength = 0.01;
|
||
|
||
/// <summary>
|
||
/// <paramref name="project"/> with the look <paramref name="filter"/> at <paramref name="strength"/>: none when the filter
|
||
/// is None or the strength 0 (so a project without a look keeps settings format 1 and its text: the editor writes
|
||
/// <c>Look = null</c> whenever the look is the identity), the strength omitted at 100 %. Values of a newer Chronos
|
||
/// inside the look are kept.
|
||
/// </summary>
|
||
public static ProjectSettings WithLook(ProjectSettings project, string? filter, double? strength)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(project);
|
||
if (filter is null || filter == LookFilter.None || strength is <= 0) return project with { Look = null };
|
||
var look = (project.Look ?? new LookSettings()) with { Filter = filter, Strength = strength is >= 1 ? null : strength };
|
||
return project with { Look = look };
|
||
}
|
||
|
||
private static bool HasFilter(ProjectSettings project) => project.Look?.Filter is { } filter && filter != LookFilter.None && LookFilter.IsKnown(filter);
|
||
|
||
/// <summary>Luminance, flicker or waveform (the switch beside the chart).</summary>
|
||
public ExposureChart ChartMode
|
||
{
|
||
get => _chartMode;
|
||
set
|
||
{
|
||
if (!Set(ref _chartMode, value)) return;
|
||
OnPropertyChanged(nameof(IsLuminance));
|
||
OnPropertyChanged(nameof(IsFlicker));
|
||
OnPropertyChanged(nameof(IsWaveform));
|
||
BuildChart();
|
||
Editor.OnWaveformNeeded();
|
||
}
|
||
}
|
||
|
||
// The switch's radio buttons: checking one chooses its chart; the group's unchecking of the others is ignored.
|
||
public bool IsLuminance { get => _chartMode == ExposureChart.Luminance; set => Choose(value, ExposureChart.Luminance); }
|
||
|
||
public bool IsFlicker { get => _chartMode == ExposureChart.Flicker; set => Choose(value, ExposureChart.Flicker); }
|
||
|
||
public bool IsWaveform { get => _chartMode == ExposureChart.Waveform; set => Choose(value, ExposureChart.Waveform); }
|
||
|
||
/// <summary>"luma of frame 0413".</summary>
|
||
public string WaveformTitle => Loc.L("Editor.Chart.WaveformOf", (Editor.CurrentIndex + 1).ToString("D4", Loc.Culture));
|
||
|
||
public IReadOnlyList<ChartSeries> Series { get => _series; private set => Set(ref _series, value); }
|
||
|
||
public IReadOnlyList<ChartLegendItem> Legend { get => _legend; private set => Set(ref _legend, value); }
|
||
|
||
public IReadOnlyList<TimelineMarker> Markers { get => _markers; private set => Set(ref _markers, value); }
|
||
|
||
/// <summary>"flicker −67 % · max step 0.21 EV".</summary>
|
||
public string? Summary { get => _summary; private set => Set(ref _summary, value); }
|
||
|
||
public Func<double, string> YFormatter => _chartMode == ExposureChart.Flicker ? v => Loc.L("Editor.Value.Ev", EditorText.Ev(v)) : v => v.ToString("0.0", Loc.Culture);
|
||
|
||
public override void OnContentChanged()
|
||
{
|
||
base.OnContentChanged();
|
||
BuildChart();
|
||
}
|
||
|
||
public override void OnCorrectionsChanged() => BuildChart();
|
||
|
||
public override void OnCurrentFrameChanged() => OnPropertyChanged(nameof(WaveformTitle));
|
||
|
||
private void Choose(bool chosen, ExposureChart chart)
|
||
{
|
||
if (chosen) ChartMode = chart;
|
||
}
|
||
|
||
private (string?, string?) Temperature()
|
||
{
|
||
if (Editor.Session.Content.Deep is not { } deep) return (null, Loc.L("Tooltips.Editor.NotApplicable.NeedsAnalysis"));
|
||
if (deep.WhiteBalance is { KelvinLow: { } low, KelvinHigh: { } high })
|
||
return (Loc.L("Editor.Value.Kelvin", RoundToTens(low).ToString("N0", Loc.Culture), RoundToTens(high).ToString("N0", Loc.Culture)), null);
|
||
return (null, Loc.L("Tooltips.Editor.NotApplicable.Kelvin"));
|
||
}
|
||
|
||
/// <summary>Kelvin shown to the nearest ten (Math.Round takes no negative digit count).</summary>
|
||
internal static double RoundToTens(double kelvin) => double.Round(kelvin / 10) * 10;
|
||
|
||
private void BuildChart()
|
||
{
|
||
var content = Editor.Session.Content;
|
||
var n = content.Count;
|
||
var corrections = Editor.Corrections is { } c && c.FrameCount == n ? c : null;
|
||
double[] measured = corrections?.MeasuredLogLuminance is { } m && m.Any(double.IsFinite)
|
||
? m
|
||
: content.Deep is { } deep ? [.. deep.Frames.LogLuminance.Select(v => v ?? double.NaN)] : [.. content.Frames.Select(f => f.MeanLogLuminance ?? double.NaN)];
|
||
var markers = EditorViewModel.StepMarkers(content);
|
||
var series = new List<ChartSeries>();
|
||
var legend = new List<ChartLegendItem>();
|
||
if (_chartMode == ExposureChart.Flicker)
|
||
{
|
||
series.Add(new ChartSeries(Loc.L("Editor.Chart.FlickerBefore"), Steps(measured), "Brush.Sun"));
|
||
legend.Add(new ChartLegendItem(Loc.L("Editor.Chart.FlickerBefore"), "Brush.Sun"));
|
||
if (corrections is not null && measured.Any(double.IsFinite))
|
||
{
|
||
series.Add(new ChartSeries(Loc.L("Editor.Chart.FlickerAfter"), Steps(corrections.TargetLogLuminance()), "Brush.Accent") { Thickness = 2 });
|
||
legend.Add(new ChartLegendItem(Loc.L("Editor.Chart.FlickerAfter"), "Brush.Accent"));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
series.Add(new ChartSeries(Loc.L("Editor.Chart.Measured"), measured, "Brush.Sun"));
|
||
legend.Add(new ChartLegendItem(Loc.L("Editor.Chart.Measured"), "Brush.Sun"));
|
||
if (corrections is not null && measured.Any(double.IsFinite))
|
||
{
|
||
series.Add(new ChartSeries(Loc.L("Editor.Chart.Target"), corrections.TargetLogLuminance(), "Brush.Accent") { Thickness = 2 });
|
||
legend.Add(new ChartLegendItem(Loc.L("Editor.Chart.Target"), "Brush.Accent"));
|
||
}
|
||
if (content.Deep is { Regions: not null } withSky && withSky.Frames.SkyLogLuminance.Any(v => v is not null))
|
||
{
|
||
series.Add(new ChartSeries(Loc.L("Editor.Chart.Sky"), withSky.Frames.SkyLogLuminance.Select(v => v ?? double.NaN).ToArray(), "Brush.Region")
|
||
{ Dash = LineDash.Dashed });
|
||
legend.Add(new ChartLegendItem(Loc.L("Editor.Chart.Sky"), "Brush.Region", LegendSwatch.DashedLine));
|
||
}
|
||
}
|
||
if (markers.Count > 0) legend.Add(new ChartLegendItem(Loc.L("Editor.Chart.Steps"), "Brush.Sun", LegendSwatch.Triangle));
|
||
Series = series;
|
||
Legend = legend;
|
||
Markers = markers;
|
||
Summary = SummaryOf(corrections);
|
||
OnPropertyChanged(nameof(YFormatter));
|
||
}
|
||
|
||
/// <summary>Change from the previous usable frame, in EV (NaN where either is unusable).</summary>
|
||
private static double[] Steps(double[] logLuminance)
|
||
{
|
||
var steps = new double[logLuminance.Length];
|
||
var previous = double.NaN;
|
||
for (var i = 0; i < steps.Length; i++)
|
||
{
|
||
steps[i] = logLuminance[i] - previous;
|
||
if (double.IsFinite(logLuminance[i])) previous = logLuminance[i];
|
||
}
|
||
return steps;
|
||
}
|
||
|
||
private static string? SummaryOf(RenderCorrections? corrections)
|
||
{
|
||
if (corrections is null) return null;
|
||
var parts = new List<string>();
|
||
if (corrections.Report.Deflicker is { FlickerBefore: > 0 } d)
|
||
parts.Add(Loc.L("Editor.Exposure.FlickerChange", double.Round((d.FlickerAfter / d.FlickerBefore - 1) * 100).ToString("+0;−0;0", Loc.Culture)));
|
||
if (corrections.Report.MaxTargetStepEv is { } step) parts.Add(Loc.L("Editor.Exposure.MaxStep", step.ToString("0.00", Loc.Culture)));
|
||
return parts.Count == 0 ? null : string.Join(Loc.Separator, parts);
|
||
}
|
||
}
|