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

+96 -5
View File
@@ -1,7 +1,9 @@
using Chronos.Core.Advice;
using Chronos.Core.Diagnostics;
using Chronos.Core.Export;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Project;
using Chronos.Core.Render;
using Chronos.Core.Video;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Processing;
@@ -109,12 +111,89 @@ public sealed class EditorSession : IAsyncDisposable
/// </summary>
public ProjectConflictException? Conflict { get; private set; }
/// <summary>Applies <paramref name="change"/> as an undoable step; false when it changes nothing.</summary>
/// <summary>
/// Applies <paramref name="change"/> as an undoable step; false when it changes nothing. A crop box locked to the
/// output proportions follows a change of them (<see cref="KeepCropLocked"/>) in the same step.
/// </summary>
/// <param name="mergeKey">Consecutive edits with the same key are one undo step (a slider drag).</param>
public bool Edit(Func<ProjectSettings, ProjectSettings> change, string? mergeKey = null)
{
ArgumentNullException.ThrowIfNull(change);
return !IsReadOnly && History.Apply(change(Project), mergeKey);
if (IsReadOnly) return false;
var before = Project;
return History.Apply(KeepCropLocked(before, change(before), Content.SourceWidth, Content.SourceHeight), mergeKey);
}
/// <summary>
/// One press of the Camera step's orientation controls (Rotate left or right, Mirror, Flip) as one undo step: the
/// picture turns or mirrors as the user sees it, and the crop and the keyframes with it (<see cref="OrientationEdit"/>,
/// owner review 1, R6).
/// </summary>
public bool Orient(OrientationOp op) => Edit(p => OrientationEdit.Apply(p, op));
/// <summary>
/// "Reset framing": the crop, its offsets, the rotation, mirror, flip and straighten cleared as one undo step; the
/// keyframes stay (<see cref="WithoutFraming"/>).
/// </summary>
public bool ResetFraming() => Edit(WithoutFraming);
/// <summary>The crop's width over its height in normalised view units for <paramref name="project"/> (<see cref="LockRatioOf"/>).</summary>
public double CropLockRatio(ProjectSettings project) => LockRatioOf(project, Content.SourceWidth, Content.SourceHeight);
/// <summary>
/// The lock ratio of the Camera step's crop (<see cref="RenderGeometry.LockRatio"/>): the output ratio the render fits
/// the crop to, in units of the view frame of a source of the given size; a 1×1 view when the size is unknown.
/// </summary>
public static double LockRatioOf(ProjectSettings project, int sourceWidth, int sourceHeight)
{
ArgumentNullException.ThrowIfNull(project);
var (width, height) = sourceWidth > 0 && sourceHeight > 0 ? (sourceWidth, sourceHeight) : (1, 1);
return RenderGeometry.Create(project.Camera, ExportResolver.Resolve(project.Export), width, height).LockRatio;
}
/// <summary>
/// The project without framing: no crop, no offsets, no rotation, mirror, flip or straighten. The orientation is undone
/// press by press (<see cref="OrientationEdit"/>: the flip, the mirror, then quarter turns back), so the keyframes, the
/// parked ones and the aspect stay on the content they framed: a 9:16 set on a quarter-turned landscape is 16:9 again.
/// </summary>
public static ProjectSettings WithoutFraming(ProjectSettings project)
{
ArgumentNullException.ThrowIfNull(project);
var upright = project;
if (upright.Camera.Flip) upright = OrientationEdit.Apply(upright, OrientationOp.Flip);
if (upright.Camera.Mirror) upright = OrientationEdit.Apply(upright, OrientationOp.Mirror);
for (var turns = FrameOrientation.TurnsOf(upright.Camera.Rotate); turns > 0; turns--) upright = OrientationEdit.Apply(upright, OrientationOp.RotateLeft);
return upright with { Camera = upright.Camera with { Crop = null, OffsetX = 0, OffsetY = 0, Rotate = 0, Mirror = false, Flip = false, Straighten = 0 } };
}
/// <summary>Something <see cref="ResetFraming"/> clears is set.</summary>
public static bool HasFraming(CameraSettings camera)
{
ArgumentNullException.ThrowIfNull(camera);
return camera.Crop is not null || camera.OffsetX != 0 || camera.OffsetY != 0 || camera.Rotate != 0 || camera.Mirror || camera.Flip || camera.Straighten != 0;
}
/// <summary>
/// <paramref name="after"/> with its crop refitted to new output proportions (owner review 1, R5: an aspect change, a
/// turn of a "source" aspect, an export preset of another shape): a box that was locked to the proportions before keeps
/// its centre and area at the new ratio (<see cref="CropFrame.Refit"/>). A legacy free crop, one placed by offsets, and a
/// box already at the new ratio stay as they are (the render fits them, <see cref="AspectRatio.FitCrop"/>).
/// </summary>
public static ProjectSettings KeepCropLocked(ProjectSettings before, ProjectSettings after, int sourceWidth, int sourceHeight)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var camera = after.Camera;
if (CropFrame.IsWhole(camera.Crop) || camera.OffsetX != 0 || camera.OffsetY != 0) return after;
if (ReferenceEquals(before.Camera, camera) && ReferenceEquals(before.Export, after.Export)) return after;
var ratio = LockRatioOf(after, sourceWidth, sourceHeight);
var box = CropFrame.Of(camera.Crop);
if (IsLocked(box, ratio)) return after;
if (before.Camera.OffsetX != 0 || before.Camera.OffsetY != 0 || !IsLocked(CropFrame.Of(before.Camera.Crop), LockRatioOf(before, sourceWidth, sourceHeight)))
return after;
return after with { Camera = camera with { Crop = CropFrame.ToCrop(CropFrame.Refit(box, ratio)) } };
static bool IsLocked(RectD box, double lockRatio) => double.Abs(box.Width / box.Height / lockRatio - 1) < 1e-6;
}
/// <summary>The drag or key press behind a run of merged edits ended (<see cref="ProjectHistory.EndRun"/>).</summary>
@@ -148,7 +227,8 @@ public sealed class EditorSession : IAsyncDisposable
/// <summary>
/// Applies a sequence preset (BRIEF §10.3) as one undoable step: its timing, exposure, motion, aspect and export
/// preset; the user's frames (exclusions, hero), crop, keyframes, remap curve, exposure offset and output naming stay.
/// preset; the user's frames (exclusions, hero), crop (refitted to the preset's aspect), orientation, keyframes, remap
/// curve, exposure offset, look and output naming stay.
/// </summary>
public bool ApplyPreset(SequencePreset preset)
{
@@ -437,17 +517,28 @@ public sealed class EditorSession : IAsyncDisposable
{
if (IsReadOnly) return [];
var settings = Project;
var advice = AdviceFor(settings.Camera);
var changes = new List<SettingChange>();
foreach (var section in sections)
{
var result = Advisor.Optimise(section, settings, Advice);
var result = Advisor.Optimise(section, settings, advice);
settings = result.Settings;
changes.AddRange(result.Changes);
}
History.Apply(settings);
History.Apply(KeepCropLocked(Project, settings, Content.SourceWidth, Content.SourceHeight));
return changes;
}
/// <summary>
/// The advice for the view of <paramref name="camera"/>: <see cref="Advice"/> while the camera is not turned, flipped or straightened,
/// else worked out again on the turned view (<see cref="SequenceContext.ForCamera"/>), so that "Optimise" after a turn
/// keeps the transposed aspect <see cref="OrientationEdit"/> wrote instead of the unturned one.
/// </summary>
private AdvisorResult AdviceFor(CameraSettings camera) =>
camera.Rotate == Context.Rotate && camera.Flip == Context.Flip && camera.Straighten.Equals(Context.Straighten)
? Advice
: Advisor.Recommend(Content.Light, Content.Deep, Context.ForCamera(camera));
private void OnSaveFailed(Exception ex, int failures)
{
// A conflict is retried without the network until the user settles it: noted once, when it is found.