feat(editor): step controls for orientation, crop, look and output size
Owner review 1 asked for the Camera step to frame the picture the way the mockup does, so the step now offers Aspect, Rotation (icon buttons), Mirror and Flip switches, Straighten, Crop size, Crop X and Crop Y, and Reset framing. Cropping by margins is gone: the crop box is now held to the chosen aspect. - EditorSession gains Orient and ResetFraming. Edit and Optimise refit a box that was already held to the aspect whenever the aspect or the export box changes, and do it in the same undo step. A crop from an older project that was placed by offsets is left for the render to fit. - Straighten drives the preview's grid through the new SliderActivity attached behaviour, which a NumberRow switches on with ShowsGrid. - Exposure gains a Look group with Filter and Strength. A newer project's extra look data is kept as it is. - Export: Width and Height now edit the preset's own box, and a new Output size row shows the size after the chosen proportions are applied, marked Capped when the encoder shrinks it. ExportPlan carries OutputSize and EncodedSize. - New SwitchRow, IconActionsRow and GroupRow rows with their panel templates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aaf9c0bba7
commit
7413b72ecc
14 files changed
+1030
-100
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,160 @@ 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 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 ResetFramingClearsTheCropAndTheOrientationAndKeepsTheKeyframes()
|
||||
{
|
||||
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 });
|
||||
Assert.SequenceEqual([key], camera.Keyframes, "keyframes stay");
|
||||
Assert.Equal("9:16", camera.Aspect.Manual, "the aspect is not framing");
|
||||
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 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