feat(editor): visual crop, rotate/mirror/flip/straighten, colour looks (owner review 1 phase 4) (#26)
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>
This commit was merged in pull request #26.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-05 01:09:09 +01:00
1 parent db389a54f2
commit 188b2c2e55
355 files changed
+10549 -1061

No files matched your search

+163 -5
View File
@@ -13,6 +13,7 @@ using Chronos.Core.Advice;
using Chronos.Core.Analysis;
using Chronos.Core.Diagnostics;
using Chronos.Core.Export;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Core.Project;
@@ -64,9 +65,18 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private bool _showRegions;
private bool _showCropMask;
private bool _exportCropMask = true;
/// <summary>The Camera step's Crop mask, on by default: the crop box is edited there (owner review 1, R5).</summary>
private bool _cameraCropMask = true;
private CropMaskMode _cropMaskMode = CropMaskMode.ShowLoss;
private PreviewZoomMode _zoomMode = PreviewZoomMode.Fit;
private Rect _cropRect = new(0, 0, 1, 1);
private Rect _editCrop = new(0, 0, 1, 1);
private double _cropLockRatio = 1;
private bool _isStraightening;
/// <summary>The orientation of the camera the picture on screen was framed with (the crop box maps onto that view frame).</summary>
private (int Rotate, bool Mirror, bool Flip, double Straighten) _shownOrientation;
private IReadOnlyList<Point>? _regionBoundary;
private IReadOnlyList<MotionVector>? _motionVectors;
private int _previewEdge = DefaultPreviewEdge;
@@ -126,6 +136,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
if (StepFor(p) is { } step) SelectedTab = step;
});
CommitCropCommand = new RelayCommand(CommitCrop, _ => CropEditable);
Analysis = new AnalysisTab(this);
Frames = new FramesTab(this);
@@ -144,6 +155,8 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
// Until the link is read (AttachJobsAsync), a sequence of this PC cannot send its renders.
_syncGate = session.IsRemote ? ExportSyncGate.Remote : ExportSyncGate.SignedOut;
RenderChoices = [.. ExportPresets.BuiltIn.Select(p => new Choice(p.Id, p.NameKey))];
_shownOrientation = OrientationOf(session.Project.Camera);
UpdateCropBox();
session.ProjectChanged += OnProjectChanged;
session.ContentChanged += OnContentChanged;
@@ -277,6 +290,9 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
/// <summary>The Export step swaps the preview tools for compare, crop mask and a 10-second preview (Export.html).</summary>
public bool IsExportTab => SelectedTab is ExportTab;
/// <summary>The Camera step: its crop mask shows the crop box itself, edited on the picture (owner review 1, R5).</summary>
public bool IsCameraTab => SelectedTab is CameraTab;
/// <summary>The measuring area takes more of the height than the preview (the Analysis findings, the Export preset cards).</summary>
public bool IsTallMeasure => SelectedTab.PrefersTallMeasure;
@@ -364,21 +380,75 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
}
}
/// <summary>The Crop mask tool of the current tab: the Export tab has its own, on by default (Export.html).</summary>
/// <summary>
/// The Crop mask tool of the current tab: the Export tab has its own, on by default (Export.html), and so has the Camera
/// step, where the crop box is edited (owner review 1, R5).
/// </summary>
public bool ShowCropMask
{
get => IsExportTab ? _exportCropMask : _showCropMask;
get => IsExportTab ? _exportCropMask : IsCameraTab ? _cameraCropMask : _showCropMask;
set
{
if (value == ShowCropMask) return;
if (IsExportTab) _exportCropMask = value;
else if (IsCameraTab) _cameraCropMask = value;
else _showCropMask = value;
OnPropertyChanged();
OnPropertyChanged(nameof(CropModeToolTip));
OnCropEditableChanged();
RequestPreview(immediate: true);
}
}
/// <summary>
/// The crop box is moved and resized on the preview: the Camera step with its mask on, while the project can change
/// (not read-only, in a newer format, outdated or busy) and the picture on screen shows the project's view frame (after
/// a turn, a mirror, a flip or a straighten, the box waits for the picture it applies to: a drag before it would place
/// a box of the old frame in the new one).
/// </summary>
public bool CropEditable => IsCameraTab && ShowCropMask && IsEditable && !Session.Project.IsNewerFormat && FrameCount > 0
&& OrientationOf(Session.Project.Camera) == _shownOrientation;
/// <summary>
/// The crop box the Camera step shows and edits (<see cref="RenderGeometry.EditableCrop"/>), normalised in the view frame
/// the Source picture shows; the preview sets it to each finished edit before <see cref="CommitCropCommand"/> runs.
/// </summary>
public Rect EditCrop
{
get => _editCrop;
set
{
if (!Set(ref _editCrop, value)) return;
if (IsCameraTab) OnPropertyChanged(nameof(CropRect));
}
}
/// <summary>The crop box's width over its height in normalised units (<see cref="RenderGeometry.LockRatio"/>): the output proportions on the view frame.</summary>
public double CropLockRatio { get => _cropLockRatio; private set => Set(ref _cropLockRatio, value); }
/// <summary>
/// Writes a finished edit of the crop box (<see cref="CropEditEventArgs"/>, or a normalised <see cref="Rect"/>) as the
/// camera crop, locked and with the offsets at 0 (owner review 1, R5): one drag is one undo step, a run of key presses
/// merges into one ("Camera.Crop") that the key release ends.
/// </summary>
public ICommand CommitCropCommand { get; }
/// <summary>The Straighten slider is dragged or has the keyboard: the preview shows a fine grid to level the horizon against.</summary>
public bool IsStraightening
{
get => _isStraightening;
set
{
if (Set(ref _isStraightening, value)) OnPropertyChanged(nameof(ShowStraightenGrid));
}
}
/// <summary>The straighten grid over the preview (Camera step, while straightening).</summary>
public bool ShowStraightenGrid => IsStraightening && IsCameraTab;
/// <summary>What a drag on the preview does: the crop box's moves and keys while it is edited there, else compare, pan and zoom.</summary>
public string PreviewToolTip => Loc.L(CropEditable ? "Tooltips.Editor.Preview.CropEdit" : "Tooltips.Editor.Preview.View");
/// <summary>Overlays the viewport draws: only tools that have a button on the current tab.</summary>
public bool ViewVectors => ShowVectors && !IsExportTab;
@@ -422,7 +492,20 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
set => ZoomMode = value ? PreviewZoomMode.Actual : PreviewZoomMode.Fit;
}
public Rect CropRect { get => _cropRect; private set => Set(ref _cropRect, value); }
/// <summary>
/// The crop mask: on the Camera step the crop box (<see cref="EditCrop"/>), elsewhere the footprint of the frame's output
/// (stabilisation and camera pose included) on the Source picture.
/// </summary>
public Rect CropRect
{
get => IsCameraTab ? _editCrop : _cropRect;
private set
{
if (_cropRect == value) return;
_cropRect = value;
if (!IsCameraTab) OnPropertyChanged();
}
}
public IReadOnlyList<Point>? RegionBoundary { get => _regionBoundary; private set => Set(ref _regionBoundary, value); }
@@ -551,10 +634,19 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
public bool CanRender => RenderBlockedReason is null;
/// <summary>The settings format a render of <see cref="RenderExport"/> needs (<see cref="Chronos.Data.Processing.ProcessingJobs.RequiredFormat"/>).</summary>
private int RenderFormat =>
Chronos.Data.Processing.ProcessingJobs.RequiredFormat(Session.Project, RenderExport, Session.Content.SourceWidth, Session.Content.SourceHeight);
/// <summary>Why the project's export cannot be rendered now, localised; null when it can.</summary>
public string? RenderBlockedReason => Plan switch
{
_ when IsRemote && !Shell.Services.Sync.CanRender => Loc.L("Tooltips.Editor.Render.NoRight", ServerName),
// Settings or proportions the server would render otherwise (owner review 1, phase 4: an older server, Send and render too).
// A workspace project rendered on this PC from its originals (phase 5c) renders with this PC's engine: the server's
// format does not decide (sending its version home is held by the workspace's own gate).
_ when IsRemote && Session.Source is not IProjectRenders { RendersLocally: true }
&& ServerJobs.NeedsNewerServer(RenderFormat, Shell.Services.Sync.SettingsFormat) is { } newer => newer,
_ when IsOutdated => Loc.L("Tooltips.Editor.Outdated", ServerName),
null when _planned => Loc.L("Tooltips.Editor.Render.NoSource"),
null => Loc.L("Tooltips.Editor.Render.Planning"),
@@ -793,6 +885,13 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
PreviewImage = r.Corrected;
OriginalImage = r.Original;
CropRect = r.Crop;
// The crop box of the picture now on screen: its view frame, its proportions.
var shown = OrientationOf(request.Project.Camera);
var reframed = shown != _shownOrientation;
_shownOrientation = shown;
CropLockRatio = r.LockRatio;
EditCrop = r.EditCrop;
if (reframed) OnCropEditableChanged();
RegionBoundary = ViewRegions ? r.Horizon : null;
MotionVectors = ViewVectors ? r.Vectors : null;
WaveformImage = r.Waveform;
@@ -976,14 +1075,69 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private void OnToolsChanged()
{
OnPropertyChanged(nameof(IsCameraTab));
OnPropertyChanged(nameof(ShowCropMask));
OnPropertyChanged(nameof(CropModeToolTip));
OnPropertyChanged(nameof(ViewVectors));
OnPropertyChanged(nameof(ViewRegions));
OnPropertyChanged(nameof(CropRect));
OnPropertyChanged(nameof(ShowStraightenGrid));
OnCropEditableChanged();
}
/// <summary>Whether the crop box is edited on the preview, and what a drag there does.</summary>
private void OnCropEditableChanged()
{
OnPropertyChanged(nameof(CropEditable));
OnPropertyChanged(nameof(PreviewToolTip));
}
/// <summary>The rendered orientation members of <paramref name="camera"/>: the view frame the crop box is normalised in.</summary>
private static (int, bool, bool, double) OrientationOf(CameraSettings camera) =>
(FrameOrientation.TurnsOf(camera.Rotate), camera.Mirror, camera.Flip, FrameOrientation.StraightenOf(camera.Straighten));
/// <summary>
/// The crop box and its proportions for the project now, at once, while the picture on screen shows the same view frame
/// (a crop row, an aspect or preset change: no frame to wait for); a turn, mirror, flip or straighten waits for the
/// picture it applies to.
/// </summary>
private void UpdateCropBox()
{
var project = Session.Project;
if (OrientationOf(project.Camera) != _shownOrientation || Session.Content.SourceWidth <= 0 || Session.Content.SourceHeight <= 0) return;
try
{
var geometry = RenderGeometry.Create(project.Camera, ExportResolver.Resolve(project.Export), Session.Content.SourceWidth, Session.Content.SourceHeight);
CropLockRatio = geometry.LockRatio;
var box = geometry.EditableCrop;
EditCrop = new Rect(box.X, box.Y, box.Width, box.Height);
}
catch (Exception ex) when (ex is ArgumentException or InvalidOperationException or RenderException)
{
Log.Warning("editor", "The crop box could not be worked out", ex);
}
}
private void CommitCrop(object? parameter)
{
var (crop, nudge) = parameter switch
{
CropEditEventArgs edit => (edit.Crop, edit.IsNudge),
Rect rect => (rect, false),
_ => (Rect.Empty, false),
};
if (crop.IsEmpty || !CropEditable) return;
// The box itself, locked to the proportions on screen, with the offsets at 0: the render's FitCrop returns it unchanged.
var box = CropFrame.Clamp(new RectD(crop.X, crop.Y, crop.Width, crop.Height), CropLockRatio);
EditCrop = new Rect(box.X, box.Y, box.Width, box.Height);
Session.Edit(p => p with { Camera = p.Camera with { Crop = CropFrame.ToCrop(box), OffsetX = 0, OffsetY = 0 } }, "Camera.Crop");
if (!nudge) Session.EndEditRun();
}
private void OnProjectChanged()
{
UpdateCropBox();
OnCropEditableChanged();
foreach (var tab in Tabs) tab.Refresh();
UpdateMarkers();
RefreshSteps();
@@ -1002,6 +1156,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
Planner = new ExportPlanner(Session.Content, _encoders, _host);
if (Thumbnails.Count != FrameCount) Thumbnails = new EditorThumbnails(Session.Source, FrameCount);
Corrections = null;
UpdateCropBox();
_rendered = new RenderedSettings(Session.Content.Renders);
foreach (var tab in Tabs) tab.OnContentChanged();
OnPropertyChanged(nameof(Summary));
@@ -1340,6 +1495,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
OnPropertyChanged(nameof(IsAnalysing));
OnPropertyChanged(nameof(IsLocked));
OnPropertyChanged(nameof(IsEditable));
OnCropEditableChanged();
OnPropertyChanged(nameof(LockedToolTip));
OnPropertyChanged(nameof(AnalyseToolTip));
OnPropertyChanged(nameof(OptimiseAllToolTip));
@@ -1370,13 +1526,15 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
}
/// <summary>A rendered preview as frozen bitmaps and overlays in picture pixels (built off the UI thread).</summary>
private sealed record PreviewResult(ImageSource Corrected, ImageSource Original, Rect Crop, IReadOnlyList<Point> Horizon, IReadOnlyList<MotionVector> Vectors,
ImageSource? Waveform)
private sealed record PreviewResult(ImageSource Corrected, ImageSource Original, Rect Crop, Rect EditCrop, double LockRatio, IReadOnlyList<Point> Horizon,
IReadOnlyList<MotionVector> Vectors, ImageSource? Waveform)
{
public static PreviewResult From(PreviewFrame frame) => new(
EditorImages.ToBitmap(frame.Corrected),
EditorImages.ToBitmap(frame.Original),
new Rect(frame.Crop.X, frame.Crop.Y, frame.Crop.Width, frame.Crop.Height),
new Rect(frame.EditCrop.X, frame.EditCrop.Y, frame.EditCrop.Width, frame.EditCrop.Height),
frame.LockRatio,
[.. frame.Horizon.Select(p => new Point(p.X, p.Y))],
[.. frame.Vectors.Select(v => new MotionVector(v.X, v.Y, v.Dx, v.Dy))],
frame.Waveform is { } waveform ? EditorImages.ToMask(waveform) : null);