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
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:
1 parent
db389a54f2
commit
188b2c2e55
355 files changed
+10549
-1061
No files matched your search
@@ -3,6 +3,7 @@ using System.Text.Json;
|
||||
using Chronos.App.Editor;
|
||||
using Chronos.Core.Advice;
|
||||
using Chronos.Core.Analysis;
|
||||
using Chronos.Core.Imaging.Geometry;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Protocol;
|
||||
@@ -416,4 +417,196 @@ public sealed class EditorSessionTests
|
||||
Assert.Equal(2, session.Project.HeroFrame);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Orientation and framing (owner review 1, R5/R6) ----
|
||||
|
||||
/// <summary>A project with a manual aspect (the advice never decides it) and a crop.</summary>
|
||||
private static ProjectSettings WithAspect(string aspect, double[]? crop = null)
|
||||
{
|
||||
var project = new ProjectSettings();
|
||||
return project with { Camera = project.Camera with { Aspect = project.Camera.Aspect.WithManual(aspect), Crop = crop } };
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task EachOrientationPressIsOneUndoStepAndTurnsTheCropWithThePicture()
|
||||
{
|
||||
var (session, _) = Open(WithAspect("16:9", [0.1, 0.2, 0.4, 0.3]));
|
||||
await using (session)
|
||||
{
|
||||
Assert.True(session.Orient(OrientationOp.RotateRight));
|
||||
Assert.Equal(90, session.Project.Camera.Rotate);
|
||||
Assert.Equal("9:16", session.Project.Camera.Aspect.Manual, "the proportions turn with the picture");
|
||||
Assert.SequenceEqual([0.5, 0.1, 0.3, 0.4], session.Project.Camera.Crop!, "the crop keeps the content");
|
||||
Assert.True(session.Orient(OrientationOp.Mirror));
|
||||
Assert.True(session.Project.Camera.Mirror);
|
||||
Assert.SequenceEqual([0.2, 0.1, 0.3, 0.4], session.Project.Camera.Crop!, "mirror maps x to 1 − x − w");
|
||||
|
||||
Assert.True(session.Undo());
|
||||
Assert.False(session.Project.Camera.Mirror, "one press, one step");
|
||||
Assert.Equal(90, session.Project.Camera.Rotate);
|
||||
Assert.True(session.Undo());
|
||||
Assert.Equal(0, session.Project.Camera.Rotate);
|
||||
Assert.SequenceEqual([0.1, 0.2, 0.4, 0.3], session.Project.Camera.Crop!);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OptimiseAfterATurnAdvisesTheAspectOfTheTurnedView()
|
||||
{
|
||||
var (session, _) = Open();
|
||||
await using (session)
|
||||
{
|
||||
session.Edit(p => Advisor.Apply(p, session.Advice));
|
||||
var advised = EditorSettings.Aspect.Effective(session.Project, null);
|
||||
Assert.True(advised is "16:9" or "9:16", "the analysis advises a video aspect");
|
||||
Assert.True(session.Orient(OrientationOp.RotateRight));
|
||||
var turned = EditorSettings.Aspect.Effective(session.Project, null);
|
||||
Assert.NotEqual(advised, turned, "the turn transposes the advised aspect");
|
||||
|
||||
session.Optimise(AdvisorSection.Camera);
|
||||
Assert.Equal(turned, EditorSettings.Aspect.Effective(session.Project, null), "the advice is worked out on the turned view");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ATurnSeenThroughAMirrorTurnsThePictureTheWayTheUserPressed()
|
||||
{
|
||||
var (session, _) = Open(WithAspect("16:9"));
|
||||
await using (session)
|
||||
{
|
||||
session.Orient(OrientationOp.RotateRight);
|
||||
Assert.Equal(90, session.Project.Camera.Rotate, "clockwise as stored");
|
||||
session.Orient(OrientationOp.Mirror);
|
||||
session.Orient(OrientationOp.RotateRight);
|
||||
Assert.Equal(0, session.Project.Camera.Rotate, "through one mirror, a clockwise press is an anticlockwise stored turn");
|
||||
session.Orient(OrientationOp.Flip);
|
||||
session.Orient(OrientationOp.RotateRight);
|
||||
Assert.Equal(90, session.Project.Camera.Rotate, "mirror and flip together are a half turn: the sense is kept");
|
||||
Assert.True(session.Project.Camera is { Mirror: true, Flip: true });
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FourRightTurnsGiveBackTheSameCanonicalText()
|
||||
{
|
||||
var keyed = WithAspect("16:9", [0.1, 0.2, 0.4, 0.3]);
|
||||
keyed = keyed with { Camera = keyed.Camera with { Keyframes = [new CameraKey(4, 0.3, 0.6, 1.5, 2)], Straighten = 1.5 } };
|
||||
var (session, _) = Open(keyed);
|
||||
await using (session)
|
||||
{
|
||||
var before = session.Project.ToJson();
|
||||
for (var i = 0; i < 4; i++) Assert.True(session.Orient(OrientationOp.RotateRight));
|
||||
Assert.Equal(before, session.Project.ToJson());
|
||||
Assert.Equal(ProjectSettings.CurrentVersion, session.Project.RequiredFormat, "a straighten needs format 2");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnAspectChangeRefitsALockedCropAroundItsCentre()
|
||||
{
|
||||
var (session, _) = Open(WithAspect("16:9"));
|
||||
await using (session)
|
||||
{
|
||||
var ratio = session.CropLockRatio(session.Project);
|
||||
var box = CropFrame.Clamp(new RectD(0.2, 0.2, 0.5, 0.5 / ratio), ratio);
|
||||
Assert.True(session.Edit(p => p with { Camera = p.Camera with { Crop = CropFrame.ToCrop(box) } }));
|
||||
Assert.True(session.Edit(p => EditorSettings.Aspect.WithManual(p, "9:16")));
|
||||
var refitted = CropFrame.Of(session.Project.Camera.Crop);
|
||||
Assert.Approximately(session.CropLockRatio(session.Project), refitted.Width / refitted.Height, 1e-9, "locked to the new proportions");
|
||||
Assert.Approximately(box.CenterX, refitted.CenterX, 1e-9, "the same centre");
|
||||
Assert.Approximately(box.CenterY, refitted.CenterY, 1e-9);
|
||||
Assert.Approximately(box.Width * box.Height, refitted.Width * refitted.Height, 1e-9, "the same area");
|
||||
Assert.True(session.Undo());
|
||||
Assert.SequenceEqual(CropFrame.ToCrop(box)!, session.Project.Camera.Crop!, "the aspect and the refit are one step");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALegacyCropPlacedByOffsetsIsLeftForTheRenderToFit()
|
||||
{
|
||||
var legacy = WithAspect("16:9", [0, 0, 1, 0.8]);
|
||||
legacy = legacy with { Camera = legacy.Camera with { OffsetX = 0.5 } };
|
||||
var (session, _) = Open(legacy);
|
||||
await using (session)
|
||||
{
|
||||
Assert.True(session.Edit(p => EditorSettings.Aspect.WithManual(p, "1:1")));
|
||||
Assert.SequenceEqual([0.0, 0, 1, 0.8], session.Project.Camera.Crop!);
|
||||
Assert.Equal(0.5, session.Project.Camera.OffsetX);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ResetFramingClearsTheCropAndTheOrientationAndKeepsTheKeyframesOnTheirContent()
|
||||
{
|
||||
var framed = WithAspect("9:16", [0.2, 0, 0.3, 1]);
|
||||
var key = new CameraKey(3, 0.4, 0.5, 2, 0);
|
||||
framed = framed with
|
||||
{
|
||||
Camera = framed.Camera with { OffsetX = 0.2, OffsetY = -0.1, Rotate = 270, Mirror = true, Flip = true, Straighten = -3.5, Keyframes = [key] },
|
||||
Look = new LookSettings { Filter = "sepia" },
|
||||
};
|
||||
var (session, _) = Open(framed);
|
||||
await using (session)
|
||||
{
|
||||
Assert.True(EditorSession.HasFraming(session.Project.Camera));
|
||||
Assert.True(session.ResetFraming());
|
||||
var camera = session.Project.Camera;
|
||||
Assert.Null(camera.Crop);
|
||||
Assert.True(camera is { OffsetX: 0, OffsetY: 0, Rotate: 0, Mirror: false, Flip: false, Straighten: 0 });
|
||||
var back = OrientationEdit.Apply(OrientationEdit.Apply(OrientationEdit.Apply(OrientationEdit.Apply(OrientationEdit.Apply(framed,
|
||||
OrientationOp.Flip), OrientationOp.Mirror), OrientationOp.RotateLeft), OrientationOp.RotateLeft), OrientationOp.RotateLeft);
|
||||
Assert.SequenceEqual(back.Camera.Keyframes, camera.Keyframes, "keyframes stay on the content they framed");
|
||||
Assert.Equal(1, camera.Keyframes.Count);
|
||||
Assert.Equal("16:9", camera.Aspect.Manual, "the aspect turns back with the picture");
|
||||
Assert.Equal("sepia", session.Project.Look?.Filter, "nor the look");
|
||||
Assert.False(EditorSession.HasFraming(camera));
|
||||
Assert.False(session.ResetFraming(), "nothing left to clear");
|
||||
Assert.True(session.Undo());
|
||||
Assert.Equal(270, session.Project.Camera.Rotate, "one step");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResetFramingTurnsAKeyframeBackWithThePicture()
|
||||
{
|
||||
var turned = new ProjectSettings();
|
||||
turned = turned with { Camera = turned.Camera with { Rotate = 90, Aspect = turned.Camera.Aspect.WithManual("9:16"), Keyframes = [new CameraKey(2, 0.2, 0.3, 1.5, 0)] } };
|
||||
var reset = EditorSession.WithoutFraming(turned);
|
||||
var (x, y) = OrientationEdit.MapPoint(0.2, 0.3, OrientationOp.RotateLeft);
|
||||
Assert.True(reset.Camera.Keyframes[0] is { CenterX: var cx, CenterY: var cy } && cx == x && cy == y, "moved as the picture turns back");
|
||||
Assert.True((x, y) != (0.2, 0.3));
|
||||
Assert.Equal("16:9", reset.Camera.Aspect.Manual);
|
||||
var again = OrientationEdit.Apply(reset, OrientationOp.RotateRight);
|
||||
Assert.True(again.Camera is { Rotate: 90 } && again.Camera.Keyframes[0] is { CenterX: 0.2, CenterY: 0.3 }, "turning again puts it where it was");
|
||||
Assert.Equal("9:16", again.Camera.Aspect.Manual);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequencePresetKeepsTheOrientationAndTheLook()
|
||||
{
|
||||
var turned = new ProjectSettings() with { Look = new LookSettings { Filter = "mono", Strength = 0.5 } };
|
||||
turned = turned with { Camera = turned.Camera with { Rotate = 90, Mirror = true, Straighten = 2 } };
|
||||
var (session, _) = Open(turned);
|
||||
await using (session)
|
||||
{
|
||||
Assert.True(session.ApplyPreset(session.Presets.First(p => p.Id == "social-vertical")));
|
||||
Assert.True(session.Project.Camera is { Rotate: 90, Mirror: true, Straighten: 2 });
|
||||
Assert.Equal("mono", session.Project.Look?.Filter);
|
||||
Assert.Equal(0.5, session.Project.Look?.Strength);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AReadOnlyProjectIsNeitherTurnedNorReset()
|
||||
{
|
||||
var (session, source) = Open(WithAspect("16:9", [0.1, 0.2, 0.4, 0.3]));
|
||||
await using (session)
|
||||
{
|
||||
source.IsReadOnly = true;
|
||||
Assert.False(session.Orient(OrientationOp.RotateLeft));
|
||||
Assert.False(session.ResetFraming());
|
||||
Assert.Equal(0, session.Project.Camera.Rotate);
|
||||
Assert.NotNull(session.Project.Camera.Crop);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user