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:
Alby96andClaude Opus 5.5 committed 2026-11-04 20:24:03 +01:00
1 parent aaf9c0bba7
commit 7413b72ecc
14 files changed
+1030 -100

No files matched your search

@@ -0,0 +1,293 @@
using System.Globalization;
using Chronos.App.Editor;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
/// <summary>
/// The Camera step's rows (owner review 1, R5/R6) and the Exposure step's Look group on an open session of the 96 × 64
/// synthetic sunset: the crop box locked to the aspect through Crop size, X and Y, the orientation controls, Straighten,
/// the look written only when it is not the identity, and every row's label and tooltip in English and Italian.
/// </summary>
[Serial]
public sealed class CameraTabTests
{
private static (EditorSession Session, FakeSequenceSource Source) Open(ProjectSettings? project = null)
{
var content = EditorFixture.Content(EditorFixture.Sunset, project);
var source = new FakeSequenceSource(EditorFixture.Sunset, content);
return (new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20)), source);
}
private static ProjectSettings WithAspect(string aspect, string? preset = null)
{
var project = new ProjectSettings();
project = project with { Camera = project.Camera with { Aspect = project.Camera.Aspect.WithManual(aspect) } };
return preset is null ? project : project with { Export = project.Export with { Preset = project.Export.Preset.WithManual(preset) } };
}
private static T Row<T>(IReadOnlyList<SettingRow> rows, string headerKey)
where T : SettingRow => (T)rows.Single(r => r.Header == Loc.L(headerKey));
private static void Refresh(IReadOnlyList<SettingRow> rows)
{
foreach (var row in rows) row.Refresh();
}
[Test]
public async Task CropSizeAndPlaceMoveTheBoxLockedToTheAspect()
{
var (session, _) = Open(WithAspect("9:16"));
await using (session)
{
var rows = CameraTab.FramingRows(session);
var size = Row<NumberRow>(rows, "Editor.Camera.CropSize");
var x = Row<NumberRow>(rows, "Editor.Camera.CropX");
var y = Row<NumberRow>(rows, "Editor.Camera.CropY");
Assert.Equal(1.0, size.Value, "no crop: the largest box");
Assert.Equal(0.0, x.Value);
Assert.True(x.IsApplicable, "a 9:16 box can move across a 3:2 frame");
Assert.False(y.IsApplicable, "but not up or down");
Assert.Equal(Loc.L("Tooltips.Editor.NotApplicable.NoSlack"), y.NotApplicableReason);
var ratio = session.CropLockRatio(session.Project);
x.Value = 1;
var box = CropFrame.Of(session.Project.Camera.Crop);
Assert.Approximately(1, box.Right, 1e-9, "Crop X +1 puts the box at the right edge");
Assert.Approximately(ratio, box.Width / box.Height, 1e-9, "locked to the aspect");
Refresh(rows);
size.Value = 0.5;
box = CropFrame.Of(session.Project.Camera.Crop);
Assert.Approximately(0.5, box.Height, 1e-9, "half the largest box");
Assert.Approximately(1, box.Right, 1e-9, "still at the right edge");
Assert.Approximately(ratio, box.Width / box.Height, 1e-9);
Refresh(rows);
Assert.True(y.IsApplicable, "a smaller box can move up and down");
Assert.Equal(1.0, x.Value);
Assert.Equal("+1.00", x.DisplayValue);
Assert.Equal("50 %", size.DisplayValue);
y.Value = -1;
Assert.Approximately(0, CropFrame.Of(session.Project.Camera.Crop).Y, 1e-9, "Crop Y −1 is the top");
Refresh(rows);
size.Value = 0.02;
Assert.Approximately(CropFrame.MinimumShare, CropFrame.Of(session.Project.Camera.Crop).Height, 1e-9, "never below a tenth of the largest box");
Assert.True(session.Project.Camera is { OffsetX: 0, OffsetY: 0 });
}
}
[Test]
public async Task TheWholeFrameAtItsOwnProportionsIsNoCrop()
{
var (session, _) = Open(WithAspect("source", "png-sequence"));
await using (session)
{
var rows = CameraTab.FramingRows(session);
var size = Row<NumberRow>(rows, "Editor.Camera.CropSize");
size.Value = 0.6;
Assert.NotNull(session.Project.Camera.Crop);
Refresh(rows);
size.Value = 1;
Assert.Null(session.Project.Camera.Crop, "the largest box is the whole view: nothing is stored");
Assert.Equal(ProjectSettings.BaseVersion, session.Project.RequiredFormat);
}
}
[Test]
public async Task ALegacyCropPlacedByOffsetsIsBakedInAtItsFirstEdit()
{
var legacy = WithAspect("1:1");
legacy = legacy with { Camera = legacy.Camera with { OffsetX = 1 } };
var (session, _) = Open(legacy);
await using (session)
{
var rows = CameraTab.FramingRows(session);
var before = CameraTab.LockedBox(session, session.Project);
Assert.Approximately(1, before.Right, 1e-9, "the render puts the square at the right");
Assert.Equal(1.0, Row<NumberRow>(rows, "Editor.Camera.CropX").Value, "the rows show it where it renders");
Row<NumberRow>(rows, "Editor.Camera.CropSize").Value = 0.8;
var after = CropFrame.Of(session.Project.Camera.Crop);
Assert.True(session.Project.Camera is { OffsetX: 0, OffsetY: 0 }, "the offsets are baked into the box");
Assert.Approximately(1, after.Right, 1e-9);
Assert.Approximately(0.8 * before.Height, after.Height, 1e-9);
}
}
[Test]
public async Task TheRotationButtonsTurnAndTheRowShowsTheStoredAngle()
{
var (session, _) = Open(WithAspect("16:9"));
await using (session)
{
var rows = CameraTab.FramingRows(session);
var rotation = Row<IconActionsRow>(rows, "Editor.Camera.Rotation");
Assert.Equal("0°", rotation.Value);
Assert.SequenceEqual([Loc.L("Editor.Camera.RotateLeft"), Loc.L("Editor.Camera.RotateRight")], rotation.Actions.Select(a => a.Name));
Assert.SequenceEqual(["Icon.RotateLeft", "Icon.RotateRight"], rotation.Actions.Select(a => a.GlyphKey));
rotation.Actions[1].Command.Execute(null);
Refresh(rows);
Assert.Equal("90°", rotation.Value);
rotation.Actions[0].Command.Execute(null);
rotation.Actions[0].Command.Execute(null);
Refresh(rows);
Assert.Equal("270°", rotation.Value);
Assert.Equal("9:16", session.Project.Camera.Aspect.Manual, "three quarter turns: portrait");
}
}
[Test]
public async Task MirrorAndFlipAreSwitchesThatMoveTheCropWithThePicture()
{
var project = WithAspect("16:9");
project = project with { Camera = project.Camera with { Crop = [0.1, 0.2, 0.3, 0.4] } };
var (session, _) = Open(project);
await using (session)
{
var rows = CameraTab.FramingRows(session);
var mirror = Row<SwitchRow>(rows, "Editor.Camera.Mirror");
var flip = Row<SwitchRow>(rows, "Editor.Camera.Flip");
Assert.False(mirror.IsOn);
mirror.IsOn = true;
Assert.True(session.Project.Camera.Mirror);
Assert.SequenceEqual([0.6, 0.2, 0.3, 0.4], session.Project.Camera.Crop!, "x becomes 1 − x − w");
flip.IsOn = true;
Assert.True(session.Project.Camera.Flip);
Assert.SequenceEqual([0.6, 0.4, 0.3, 0.4], session.Project.Camera.Crop!, "y becomes 1 − y − h");
Assert.True(session.Undo());
Refresh(rows);
Assert.False(flip.IsOn, "the switch follows undo");
Assert.True(mirror.IsOn);
}
}
[Test]
public async Task ASwitchTheProjectDoesNotTakeSpringsBack()
{
var (session, source) = Open();
await using (session)
{
var mirror = Row<SwitchRow>(CameraTab.FramingRows(session), "Editor.Camera.Mirror");
source.IsReadOnly = true;
mirror.IsOn = true;
Assert.False(mirror.IsOn);
Assert.False(session.Project.Camera.Mirror);
}
}
[Test]
public async Task StraightenStoresTenthsOfADegreeAndShowsTheGrid()
{
var (session, _) = Open();
await using (session)
{
var straighten = Row<NumberRow>(CameraTab.FramingRows(session), "Editor.Camera.Straighten");
Assert.True(straighten.ShowsGrid, "using it shows the preview's grid");
Assert.Equal((-15.0, 15.0), (straighten.Minimum, straighten.Maximum));
straighten.Value = -1.23;
Assert.Equal(-1.2, session.Project.Camera.Straighten);
Assert.Equal("−1.2°", straighten.DisplayValue);
Assert.Equal(ProjectSettings.CurrentVersion, session.Project.RequiredFormat, "a straighten needs format 2");
straighten.Value = 0.02;
Assert.Equal(0.0, session.Project.Camera.Straighten);
Assert.False(double.IsNegative(session.Project.Camera.Straighten), "never −0");
Assert.Equal(ProjectSettings.BaseVersion, session.Project.RequiredFormat, "level again: format 1");
Assert.True(CameraTab.FramingRows(session).OfType<NumberRow>().Count(r => r.ShowsGrid) == 1, "only Straighten");
}
}
[Test]
public async Task TheLookIsWrittenOnlyWhenAFilterIsChosen()
{
var (session, _) = Open();
await using (session)
{
var before = session.Project.ToJson();
var rows = ExposureTab.LookRows(session);
Assert.True(rows[0] is GroupRow, "the group starts with its name");
var filter = Row<ChoiceRow>(rows, "Editor.Look.Filter");
var strength = Row<NumberRow>(rows, "Editor.Look.Strength");
Assert.Equal("none", filter.Selected?.Value);
Assert.False(strength.IsApplicable, "no filter: Strength is n/a");
Assert.Equal(Loc.L("Tooltips.Editor.NotApplicable.NoLook"), strength.NotApplicableReason);
Assert.SequenceEqual(["None", "Mono", "Sepia", "Warm", "Cool", "Vivid", "Muted", "Fade"], filter.Options.Select(o => o.Label));
filter.Selected = filter.Options.Single(o => Equals(o.Value, "sepia"));
Assert.Equal(new LookSettings { Filter = "sepia" }.Filter, session.Project.Look?.Filter);
Assert.Null(session.Project.Look!.Strength, "100 % is the default");
Assert.Equal(ProjectSettings.CurrentVersion, session.Project.RequiredFormat);
Refresh(rows);
Assert.True(strength.IsApplicable);
Assert.Equal(1.0, strength.Value);
strength.Value = 0.6;
Assert.Equal(0.6, session.Project.Look!.Strength);
Assert.Equal("60 %", strength.DisplayValue);
strength.Value = 1;
Assert.Null(session.Project.Look!.Strength);
Refresh(rows);
filter.Selected = filter.Options.Single(o => Equals(o.Value, "none"));
Assert.Null(session.Project.Look, "the identity is no look");
Assert.Equal(ProjectSettings.BaseVersion, session.Project.RequiredFormat);
Assert.Equal(before, session.Project.ToJson(), "and the text is the one before the look");
}
}
[Test]
public void ALookOfANewerChronosKeepsWhatItDoesNotKnow()
{
var extra = ProjectSettings.FromJson("""{"look":{"filter":"warm","strength":0.4,"grain":0.2}}""");
var changed = ExposureTab.WithLook(extra, "cool", 0.4);
Assert.Equal("cool", changed.Look?.Filter);
Assert.Contains("\"grain\":0.2", changed.ToJson().Replace(" ", string.Empty, StringComparison.Ordinal));
}
[Test]
public async Task EveryRowHasATooltipAndALabelOfAtMostThreeWordsInEnglishAndItalian()
{
var (session, _) = Open(WithAspect("9:16"));
await using (session)
{
var missing = new List<string>();
void OnMissing(string key) => missing.Add(key);
Loc.MissingKey += OnMissing;
try
{
foreach (var culture in new[] { "en", "it" })
{
Loc.SetCulture(CultureInfo.GetCultureInfo(culture));
var rows = CameraTab.FramingRows(session).Concat(ExposureTab.LookRows(session)).ToList();
var labels = new List<string>();
foreach (var row in rows)
{
labels.Add(row.Header);
Assert.False(string.IsNullOrWhiteSpace(row.ToolTip), $"{culture}: {row.Header} has a tooltip");
Assert.NotEqual(row.Header, row.ToolTip, $"{culture}: the tooltip explains, it does not repeat the label");
if (row is IconActionsRow icons)
{
foreach (var action in icons.Actions)
{
labels.Add(action.Name);
Assert.False(string.IsNullOrWhiteSpace(action.ToolTip), $"{culture}: {action.Name} has a tooltip");
}
}
if (row is ChoiceRow choices) labels.AddRange(choices.Options.Select(o => o.Label));
}
labels.AddRange(new[] { "Editor.Camera.ResetFraming", "Editor.Export.OutputSize" }.Select(k => Loc.L(k)));
foreach (var key in new[] { "Tooltips.Editor.Camera.ResetFraming", "Tooltips.Editor.Camera.ResetFramingNone", "Tooltips.Editor.Export.OutputSize" })
Assert.False(string.IsNullOrWhiteSpace(Loc.L(key)), key);
foreach (var label in labels)
Assert.LessOrEqual(label.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length, 3, $"{culture}: \"{label}\" is at most three words");
}
}
finally
{
Loc.MissingKey -= OnMissing;
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
Assert.Empty(missing);
}
}
}
@@ -206,6 +206,22 @@ public sealed class EditPathTests
"a crop of the whole frame is no crop");
}
[Test]
public void TheOrientationAndTheLookReadEdited()
{
var content = EditorFixture.Content(EditorFixture.Sunset);
var project = new ProjectSettings();
foreach (var (camera, what) in new[]
{
(new CameraSettings { Rotate = 90 }, "a quarter turn"), (new CameraSettings { Mirror = true }, "a mirror"),
(new CameraSettings { Flip = true }, "a flip"), (new CameraSettings { Straighten = -1.2 }, "a straighten"),
})
Assert.Equal(Loc.L("Editor.Step.Edited"), State(EditPath.Camera, content, project: project with { Camera = camera }).Text, what);
Assert.Equal(Loc.L("Editor.Step.Edited"), State(EditPath.Exposure, content, project: project with { Look = new LookSettings { Filter = "sepia" } }).Text,
"a look");
Assert.Equal(Loc.L("Common.Auto"), State(EditPath.Exposure, content, project: project with { Look = null }).Text, "no look");
}
[Test]
public void AMissingValueOfASettingThatDoesNotApplyAsksNothing()
{
@@ -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);
}
}
}
@@ -8,7 +8,7 @@ using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
/// <summary>Composed texts of the editor (the conflict prompt among them), crop margins and the waveform monitor.</summary>
/// <summary>Composed texts of the editor (the conflict prompt among them, the Camera step's values) and the waveform monitor.</summary>
public sealed class EditorTextTests
{
static EditorTextTests() => _ = EditorFixture.Sunset;
@@ -38,22 +38,15 @@ public sealed class EditorTextTests
}
[Test]
public void CropMarginsKeepAtLeastATenthOfTheFrame()
public void TheCameraRowsShowAnglesAndPlacementsAsTheMockupDoes()
{
Assert.SequenceEqual([0.0, 0, 0, 0], CropMargins.Of(null));
var crop = CropMargins.With(null, CropSide.Left, 0.2);
Assert.SequenceEqual([0.2, 0, 0.8, 1], crop!);
crop = CropMargins.With(crop, CropSide.Top, 0.6);
Assert.Approximately(CropMargins.MaxMargin, crop![1], 1e-12, "no margin beyond the maximum");
crop = CropMargins.With(crop, CropSide.Left, 0.45);
crop = CropMargins.With(crop, CropSide.Right, 0.45);
Assert.Approximately(CropMargins.MinSize, crop![2], 1e-12, "opposite margins leave a tenth of the width");
var margins = CropMargins.Of(crop);
Assert.Approximately(0.45, margins[0], 1e-12);
Assert.Approximately(0.45, margins[1], 1e-12);
Assert.Null(CropMargins.With(CropMargins.With(CropMargins.With(crop, CropSide.Left, 0), CropSide.Right, 0), CropSide.Top, 0),
"no margin left is the whole frame");
Assert.SequenceEqual([0.0, 0, 0, 0], CropMargins.Of([double.NaN, 0, 1, 1]), "an invalid crop is ignored, as the render does");
Assert.Equal("−1.2°", CameraTab.Degrees(-1.2), "a minus sign, one decimal");
Assert.Equal("15.0°", CameraTab.Degrees(15));
Assert.Equal("0°", CameraTab.Degrees(0), "level reads as a whole number");
Assert.Equal("0°", CameraTab.Degrees(-0.0), "never a negative zero");
Assert.Equal("+0.40", EditorText.Placement(0.4));
Assert.Equal("−0.60", EditorText.Placement(-0.6));
Assert.Equal("Centred", EditorText.Placement(0));
}
[Test]
@@ -1,6 +1,7 @@
using Chronos.App.Editor;
using Chronos.Core.Advice;
using Chronos.Core.Export;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Core.Video;
using Chronos.Core.Video.Managed;
@@ -90,4 +91,57 @@ public sealed class ExportPlannerTests
Assert.Equal("Custom", plan.PresetName);
Assert.Equal(48, plan.Setup.Encoder.Settings.Width);
}
/// <summary>An H.264 encoder that takes at most <paramref name="maxWidth"/>×<paramref name="maxHeight"/> (either way round).</summary>
private sealed class H264Provider(int maxWidth, int maxHeight) : IVideoEncoderProvider
{
public string Name => "h264";
public IReadOnlyList<EncoderCapability> Capabilities { get; } = [new(VideoCodec.H264, "Test H.264", false, maxWidth, maxHeight, false)];
public bool CanEncode(EncodeSettings settings) => settings.Codec == VideoCodec.H264;
public IVideoEncoderSession Open(EncodeSettings settings) => throw new NotSupportedException("Planning never encodes.");
}
private static ProjectSettings FourKAt(string aspect)
{
var project = new ProjectSettings();
return project with
{
Camera = project.Camera with { Aspect = project.Camera.Aspect.WithManual(aspect) },
Export = project.Export with { Preset = project.Export.Preset.WithManual("4k-h264") },
};
}
[Test]
public void TheChosenProportionsWinAndThePresetKeepsItsName()
{
var planner = new ExportPlanner(Content, [new H264Provider(4096, 2304)], EncoderHost.Client);
var plan = planner.Plan(FourKAt("9:16"))!;
Assert.Equal((2160, 3840), plan.OutputSize, "4K at 9:16");
Assert.Equal((2160, 3840), plan.EncodedSize, "the encoder takes it turned");
Assert.False(plan.IsCapped);
Assert.Equal("2160 × 3840", ExportTab.OutputSizeOf(plan));
Assert.Equal(Loc.L("Tooltips.Editor.Export.OutputSize"), ExportTab.OutputSizeToolTipOf(plan));
Assert.Equal(Loc.L("Export.Preset.4kH264"), plan.PresetName, "the preset is not made Custom");
Assert.False(plan.Export.IsCustom);
Assert.Equal((3840, 2160), (plan.Export.Width, plan.Export.Height), "Width × Height stay the preset's box");
var workload = plan.Setup.Workload();
Assert.Equal((2160, 3840), (workload.Width, workload.Height), "the estimate is of the adapted size");
var source = planner.Plan(FourKAt("source"))!;
Assert.Equal((3840, 2160), source.OutputSize, "source keeps the preset's ratio");
}
[Test]
public void AnOutputTheEncoderShrinksIsMarkedCapped()
{
var plan = new ExportPlanner(Content, [new H264Provider(1920, 1080)], EncoderHost.Client).Plan(FourKAt("9:16"))!;
Assert.Equal((2160, 3840), plan.OutputSize);
Assert.Equal((1080, 1920), plan.EncodedSize);
Assert.True(plan.IsCapped);
Assert.Equal(Loc.L("Editor.Export.Capped", "1080 × 1920"), ExportTab.OutputSizeOf(plan));
Assert.Equal(Loc.L("Tooltips.Editor.Export.OutputCapped", "1080 × 1920"), ExportTab.OutputSizeToolTipOf(plan), "the largest size it takes, turned");
}
}