diff --git a/src/Chronos.App/Editor/CameraTab.cs b/src/Chronos.App/Editor/CameraTab.cs
index e04406cc..72655af4 100644
--- a/src/Chronos.App/Editor/CameraTab.cs
+++ b/src/Chronos.App/Editor/CameraTab.cs
@@ -4,6 +4,7 @@ using System.Windows.Input;
using Chronos.App.Infrastructure;
using Chronos.Core.Advice;
using Chronos.Core.Export;
+using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Localization;
using Chronos.Core.Mathematics;
using Chronos.Core.Project;
@@ -13,9 +14,10 @@ using Chronos.Ui.Visuals;
namespace Chronos.App.Editor;
///
-/// Camera (BRIEF §12.3): the free crop of the frame (margins), the output aspect and its placement inside the crop, and
+/// Camera (BRIEF §12.3, owner review 1 R5/R6): the output aspect, the orientation (quarter turns, mirror, flip,
+/// straighten), the crop box locked to the aspect (its size and its place in the frame; the preview edits it too), and
/// virtual-camera keyframes edited as a zoom curve over the sequence (X = frame, Y = zoom) with the selected keyframe's
-/// framing below.
+/// framing below. Reset framing clears the crop and the orientation, never the keyframes.
///
public sealed class CameraTab : EditorTab
{
@@ -27,30 +29,99 @@ public sealed class CameraTab : EditorTab
public CameraTab(EditorViewModel editor)
: base(editor, "Camera", AdvisorSection.Camera)
{
- var s = editor.Session;
- Rows =
+ Rows = FramingRows(editor.Session);
+ AddKeyCommand = new RelayCommand(AddKey, () => !Editor.IsLocked && Keys.All(k => k.Frame != Editor.CurrentIndex));
+ RemoveKeyCommand = new RelayCommand(RemoveKey, () => !Editor.IsLocked && SelectedKey >= 0);
+ ResetFramingCommand = new RelayCommand(() => Editor.Session.ResetFraming(), () => !Editor.IsLocked && HasFraming);
+ CommitCurveCommand = new RelayCommand(CommitCurve);
+ Refresh();
+ }
+
+ ///
+ /// The step's rows, top to bottom: Aspect (a change refits the crop, ),
+ /// Rotation (a quarter turn per press, as the user sees the picture), Mirror, Flip, Straighten (±15°, the preview's
+ /// grid while it is used), and the crop box as Crop size (a share of the largest box the aspect allows), Crop X and
+ /// Crop Y (its centre within the frame's slack). The crop rows write the locked box itself with the offsets at 0, so a
+ /// legacy crop placed by offsets is baked in at its first edit ().
+ ///
+ public static IReadOnlyList FramingRows(EditorSession session)
+ {
+ ArgumentNullException.ThrowIfNull(session);
+ var s = session;
+ string? NoSlack(ProjectSettings p, bool horizontal) =>
+ CropFrame.HasSlack(LockedBox(s, p), horizontal) ? null : Loc.L("Tooltips.Editor.NotApplicable.NoSlack");
+ return
[
- CropRow(s, CropSide.Left, "Editor.Camera.CropLeft"),
- CropRow(s, CropSide.Right, "Editor.Camera.CropRight"),
- CropRow(s, CropSide.Top, "Editor.Camera.CropTop"),
- CropRow(s, CropSide.Bottom, "Editor.Camera.CropBottom"),
new AutoChoiceRow(s, EditorSettings.Aspect, "Editor.Camera.Aspect", "Tooltips.Editor.Camera.Aspect",
[
new Choice("source", "Editor.Aspect.Source"), new Choice("16:9", "Editor.Aspect.Ratio", "16:9"), new Choice("21:9", "Editor.Aspect.Ratio", "21:9"),
new Choice("4:3", "Editor.Aspect.Ratio", "4:3"), new Choice("3:2", "Editor.Aspect.Ratio", "3:2"), new Choice("1:1", "Editor.Aspect.Ratio", "1:1"),
new Choice("9:16", "Editor.Aspect.Ratio", "9:16"), new Choice("4:5", "Editor.Aspect.Ratio", "4:5"),
]),
- new NumberRow(s, "Editor.Camera.OffsetX", "Tooltips.Editor.Camera.OffsetX", -1, 1, 0.05, p => p.Camera.OffsetX,
- (p, v) => p with { Camera = p.Camera with { OffsetX = v } }, EditorText.Placement),
- new NumberRow(s, "Editor.Camera.OffsetY", "Tooltips.Editor.Camera.OffsetY", -1, 1, 0.05, p => p.Camera.OffsetY,
- (p, v) => p with { Camera = p.Camera with { OffsetY = v } }, EditorText.Placement),
+ new IconActionsRow("Editor.Camera.Rotation", "Tooltips.Editor.Camera.Rotation",
+ () => Loc.L("Editor.Value.Degrees", (FrameOrientation.TurnsOf(s.Project.Camera.Rotate) * 90).ToString(Loc.Culture)),
+ [
+ new IconAction("Icon.RotateLeft", "Editor.Camera.RotateLeft", "Tooltips.Editor.Camera.RotateLeft", () => s.Orient(OrientationOp.RotateLeft)),
+ new IconAction("Icon.RotateRight", "Editor.Camera.RotateRight", "Tooltips.Editor.Camera.RotateRight", () => s.Orient(OrientationOp.RotateRight)),
+ ]),
+ new SwitchRow(s, "Editor.Camera.Mirror", "Tooltips.Editor.Camera.Mirror", p => p.Camera.Mirror, _ => s.Orient(OrientationOp.Mirror)),
+ new SwitchRow(s, "Editor.Camera.Flip", "Tooltips.Editor.Camera.Flip", p => p.Camera.Flip, _ => s.Orient(OrientationOp.Flip)),
+ new NumberRow(s, "Editor.Camera.Straighten", "Tooltips.Editor.Camera.Straighten", -FrameOrientation.MaxStraighten, FrameOrientation.MaxStraighten, 0.1,
+ p => FrameOrientation.StraightenOf(p.Camera.Straighten),
+ (p, v) => p with { Camera = p.Camera with { Straighten = double.Round(v, 1) + 0.0 } }, Degrees)
+ { ShowsGrid = true },
+ new NumberRow(s, "Editor.Camera.CropSize", "Tooltips.Editor.Camera.CropSize", CropFrame.MinimumShare, 1, 0.01, p => CropRows(s, p).Size,
+ (p, v) => WithCropRows(s, p, size: v), v => Formatting.Percent(v)),
+ new NumberRow(s, "Editor.Camera.CropX", "Tooltips.Editor.Camera.CropX", -1, 1, 0.01, p => CropRows(s, p).X,
+ (p, v) => WithCropRows(s, p, x: v), EditorText.Placement, p => NoSlack(p, horizontal: true)),
+ new NumberRow(s, "Editor.Camera.CropY", "Tooltips.Editor.Camera.CropY", -1, 1, 0.01, p => CropRows(s, p).Y,
+ (p, v) => WithCropRows(s, p, y: v), EditorText.Placement, p => NoSlack(p, horizontal: false)),
];
- AddKeyCommand = new RelayCommand(AddKey, () => !Editor.IsLocked && Keys.All(k => k.Frame != Editor.CurrentIndex));
- RemoveKeyCommand = new RelayCommand(RemoveKey, () => !Editor.IsLocked && SelectedKey >= 0);
- CommitCurveCommand = new RelayCommand(CommitCurve);
- Refresh();
}
+ /// The crop box the editor shows for : the stored crop locked to the output proportions ().
+ public static RectD LockedBox(EditorSession session, ProjectSettings project)
+ {
+ ArgumentNullException.ThrowIfNull(session);
+ ArgumentNullException.ThrowIfNull(project);
+ var camera = project.Camera;
+ return CropFrame.Locked(camera.Crop, session.CropLockRatio(project), camera.OffsetX, camera.OffsetY);
+ }
+
+ /// The Crop size, Crop X and Crop Y rows of ().
+ public static (double Size, double X, double Y) CropRows(EditorSession session, ProjectSettings project)
+ {
+ ArgumentNullException.ThrowIfNull(session);
+ return CropFrame.ToRows(LockedBox(session, project), session.CropLockRatio(project));
+ }
+
+ ///
+ /// with one of the crop rows changed: the locked box of the rows written as the crop (null
+ /// for the whole view), the offsets at 0.
+ ///
+ public static ProjectSettings WithCropRows(EditorSession session, ProjectSettings project, double? size = null, double? x = null, double? y = null)
+ {
+ ArgumentNullException.ThrowIfNull(session);
+ ArgumentNullException.ThrowIfNull(project);
+ var ratio = session.CropLockRatio(project);
+ var rows = CropFrame.ToRows(LockedBox(session, project), ratio);
+ var box = CropFrame.FromRows(size ?? rows.Size, x ?? rows.X, y ?? rows.Y, ratio);
+ return project with { Camera = project.Camera with { Crop = CropFrame.ToCrop(box), OffsetX = 0, OffsetY = 0 } };
+ }
+
+ /// Straighten as its row shows it: "−1.2°", "0°".
+ public static string Degrees(double value) => Loc.L("Editor.Value.Degrees", value.ToString("0.0;−0.0;0", Loc.Culture));
+
+ /// Something Reset framing clears is set: a crop, offsets, a rotation, mirror, flip or straighten.
+ public bool HasFraming => EditorSession.HasFraming(Editor.Session.Project.Camera);
+
+ /// Reset framing (next to Optimise section and Reset).
+ public ICommand ResetFramingCommand { get; }
+
+ /// What Reset framing clears, that there is nothing to clear, or why it waits.
+ public string ResetFramingToolTip => Editor.LockedToolTip
+ ?? Loc.L(HasFraming ? "Tooltips.Editor.Camera.ResetFraming" : "Tooltips.Editor.Camera.ResetFramingNone");
+
/// Keyframes as curve points: X = frame / (count − 1), Y = (zoom − 1) / ( − 1). Edited in place by the curve editor.
public ObservableCollection KeyPoints { get; } = [];
@@ -128,6 +199,8 @@ public sealed class CameraTab : EditorTab
}
if (SelectedKey >= Keys.Count) SelectedKey = Keys.Count - 1;
OnSelectedKeyChanged();
+ OnPropertyChanged(nameof(HasFraming));
+ OnPropertyChanged(nameof(ResetFramingToolTip));
}
/// The curve editor finished an edit (add, move, delete): the points become the keyframes, keeping each one's framing.
@@ -157,13 +230,9 @@ public sealed class CameraTab : EditorTab
OnPropertyChanged(nameof(AddKeyToolTip));
OnPropertyChanged(nameof(RemoveKeyToolTip));
OnPropertyChanged(nameof(CurveToolTip));
+ OnPropertyChanged(nameof(ResetFramingToolTip));
}
- /// A margin of the free crop (); all zero = the whole frame.
- private static NumberRow CropRow(EditorSession session, CropSide side, string headerKey) => new(session, headerKey, "Tooltips.Editor.Camera.Crop", 0,
- CropMargins.MaxMargin, 0.01, p => CropMargins.Of(p.Camera.Crop)[(int)side],
- (p, v) => p with { Camera = p.Camera with { Crop = CropMargins.With(p.Camera.Crop, side, v) } }, v => Formatting.Percent(v));
-
private Point ToPoint(CameraKey key) => new(Editor.FrameCount > 1 ? (double)key.Frame / (Editor.FrameCount - 1) : 0, (key.Zoom - 1) / (MaxZoom - 1));
private void AddKey()
diff --git a/src/Chronos.App/Editor/CropMargins.cs b/src/Chronos.App/Editor/CropMargins.cs
deleted file mode 100644
index 013bed30..00000000
--- a/src/Chronos.App/Editor/CropMargins.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace Chronos.App.Editor;
-
-/// Margins of the free crop, in the order of (opposites differ in the lowest bit).
-public enum CropSide
-{
- Left,
- Right,
- Top,
- Bottom,
-}
-
-///
-/// The Camera tab's crop margins over CameraSettings.Crop (a normalised x, y, width, height rectangle, null for the
-/// whole frame): each margin at most , opposite margins leaving at least .
-///
-public static class CropMargins
-{
- public const double MaxMargin = 0.45;
-
- public const double MinSize = 0.1;
-
- /// Left, right, top and bottom margins of (zeros for none or an invalid one, which the render ignores too).
- public static double[] Of(double[]? crop) => crop is [var x, var y, var w, var h] && double.IsFinite(x + y + w + h)
- ? [double.Clamp(x, 0, 1), double.Clamp(1 - x - w, 0, 1), double.Clamp(y, 0, 1), double.Clamp(1 - y - h, 0, 1)]
- : [0, 0, 0, 0];
-
- /// with one margin changed; null when no margin is left (the whole frame).
- public static double[]? With(double[]? crop, CropSide side, double value)
- {
- var margins = Of(crop);
- var opposite = (int)side ^ 1;
- margins[(int)side] = double.Clamp(value, 0, double.Min(MaxMargin, 1 - MinSize - margins[opposite]));
- if (margins.All(m => m == 0)) return null;
- var (left, right, top, bottom) = (margins[0], margins[1], margins[2], margins[3]);
- return [left, top, 1 - left - right, 1 - top - bottom];
- }
-}
diff --git a/src/Chronos.App/Editor/EditorPanels.xaml b/src/Chronos.App/Editor/EditorPanels.xaml
index 6bab5ad6..ed534cf6 100644
--- a/src/Chronos.App/Editor/EditorPanels.xaml
+++ b/src/Chronos.App/Editor/EditorPanels.xaml
@@ -101,9 +101,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -135,18 +188,28 @@
-
+
+
+
+
+
-
-
+
+
@@ -211,9 +274,13 @@
-
+
+
+
+
@@ -364,6 +431,7 @@
+
-
-
+
+
+
+
+
+
@@ -406,8 +479,8 @@
Visibility="{Binding IsFrameRateAuto, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
-
-
+
+
@@ -421,8 +494,8 @@
Visibility="{Binding IsQualityApplicable, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
-
-
+
+
@@ -443,18 +516,18 @@
-
-
+
-
-
+
-
+
-
@@ -464,7 +537,7 @@
-
diff --git a/src/Chronos.App/Editor/EditorSession.cs b/src/Chronos.App/Editor/EditorSession.cs
index 39eeb8c6..58559621 100644
--- a/src/Chronos.App/Editor/EditorSession.cs
+++ b/src/Chronos.App/Editor/EditorSession.cs
@@ -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,81 @@ public sealed class EditorSession : IAsyncDisposable
///
public ProjectConflictException? Conflict { get; private set; }
- /// Applies as an undoable step; false when it changes nothing.
+ ///
+ /// Applies as an undoable step; false when it changes nothing. A crop box locked to the
+ /// output proportions follows a change of them () in the same step.
+ ///
/// Consecutive edits with the same key are one undo step (a slider drag).
public bool Edit(Func 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);
+ }
+
+ ///
+ /// 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 (,
+ /// owner review 1, R6).
+ ///
+ public bool Orient(OrientationOp op) => Edit(p => OrientationEdit.Apply(p, op));
+
+ ///
+ /// "Reset framing": the crop, its offsets, the rotation, mirror, flip and straighten cleared as one undo step; the
+ /// keyframes stay ().
+ ///
+ public bool ResetFraming() => Edit(WithoutFraming);
+
+ /// The crop's width over its height in normalised view units for ().
+ public double CropLockRatio(ProjectSettings project) => LockRatioOf(project, Content.SourceWidth, Content.SourceHeight);
+
+ ///
+ /// The lock ratio of the Camera step's crop (): 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.
+ ///
+ 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;
+ }
+
+ /// The project without framing: no crop, no offsets, no rotation, mirror, flip or straighten; keyframes and the aspect stay.
+ public static ProjectSettings WithoutFraming(ProjectSettings project)
+ {
+ ArgumentNullException.ThrowIfNull(project);
+ return project with { Camera = project.Camera with { Crop = null, OffsetX = 0, OffsetY = 0, Rotate = 0, Mirror = false, Flip = false, Straighten = 0 } };
+ }
+
+ /// Something clears is set.
+ 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;
+ }
+
+ ///
+ /// 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 (). A legacy free crop, one placed by offsets, and a
+ /// box already at the new ratio stay as they are (the render fits them, ).
+ ///
+ 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;
}
/// The drag or key press behind a run of merged edits ended ().
@@ -148,7 +219,8 @@ public sealed class EditorSession : IAsyncDisposable
///
/// 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.
///
public bool ApplyPreset(SequencePreset preset)
{
@@ -444,7 +516,7 @@ public sealed class EditorSession : IAsyncDisposable
settings = result.Settings;
changes.AddRange(result.Changes);
}
- History.Apply(settings);
+ History.Apply(KeepCropLocked(Project, settings, Content.SourceWidth, Content.SourceHeight));
return changes;
}
diff --git a/src/Chronos.App/Editor/ExportPlanner.cs b/src/Chronos.App/Editor/ExportPlanner.cs
index cf643906..db2c56a1 100644
--- a/src/Chronos.App/Editor/ExportPlanner.cs
+++ b/src/Chronos.App/Editor/ExportPlanner.cs
@@ -22,6 +22,18 @@ public sealed record ExportChoice(string Id, string Name, string ExportPresetId,
public sealed record ExportPlan(ResolvedExport Export, RenderSetup Setup, ExportEstimate Estimate, string FileName, string? NameError)
{
public string PresetName => ProcessingJobs.PresetName(Export);
+
+ ///
+ /// The size the render asks for (, owner review 1 R5: the preset's box fitted to the chosen
+ /// proportions, 4K at 9:16 = 2160×3840), before the encoder caps it.
+ ///
+ public (int Width, int Height) OutputSize { get; init; }
+
+ /// The size the encoder makes ( or smaller, when the encoder takes no more).
+ public (int Width, int Height) EncodedSize => (Setup.Encoder.Settings.Width, Setup.Encoder.Settings.Height);
+
+ /// The encoder shrank the output (by more than the rounding to even sizes every encoder makes).
+ public bool IsCapped => EncodedSize.Width < OutputSize.Width - 1 || EncodedSize.Height < OutputSize.Height - 1;
}
///
@@ -74,7 +86,9 @@ public sealed class ExportPlanner(SequenceContent content, IReadOnlyListThe first problem of a name template, localised; null when it is valid.
diff --git a/src/Chronos.App/Editor/ExportTab.cs b/src/Chronos.App/Editor/ExportTab.cs
index ff8a457a..2e71a3de 100644
--- a/src/Chronos.App/Editor/ExportTab.cs
+++ b/src/Chronos.App/Editor/ExportTab.cs
@@ -280,6 +280,27 @@ public sealed class ExportTab : EditorTab
public EditableField Height { get; }
+ ///
+ /// "2160 × 3840": what the render makes of the box (Width × Height) and the chosen proportions (owner review 1, R5),
+ /// "(capped)" when the encoder takes no more; null before the plan.
+ ///
+ public string? OutputSizeText => Editor.Plan is { } plan ? OutputSizeOf(plan) : null;
+
+ /// Where the output size comes from, or the largest size the encoder takes when it capped it.
+ public string OutputSizeToolTip => OutputSizeToolTipOf(Editor.Plan);
+
+ /// The Output size row of : "2160 × 3840", or "1080 × 1920 (capped)".
+ public static string OutputSizeOf(ExportPlan plan)
+ {
+ ArgumentNullException.ThrowIfNull(plan);
+ return plan.IsCapped ? Loc.L("Editor.Export.Capped", SizeText(plan.EncodedSize)) : SizeText(plan.OutputSize);
+ }
+
+ /// The Output size row's tooltip for .
+ public static string OutputSizeToolTipOf(ExportPlan? plan) => plan is { IsCapped: true }
+ ? Loc.L("Tooltips.Editor.Export.OutputCapped", SizeText(LargestTaken(plan)))
+ : Loc.L("Tooltips.Editor.Export.OutputSize");
+
/// "16:9".
public string AspectText => Editor.Plan is { } plan ? Aspect(plan.Setup.Encoder.Settings.Width, plan.Setup.Encoder.Settings.Height) : string.Empty;
@@ -473,6 +494,7 @@ public sealed class ExportTab : EditorTab
try
{
UpdateLists();
+ LoadBox();
SaveChoices = !CanChooseFolder ? [new SaveChoice(null)]
: Export.Folder is { } folder ? [new SaveChoice(null), new SaveChoice(folder), new SaveChoice(null, Browse: true)]
: [new SaveChoice(null), new SaveChoice(null, Browse: true)];
@@ -493,9 +515,7 @@ public sealed class ExportTab : EditorTab
_refreshing = true;
try
{
- var settings = Editor.Plan?.Setup.Encoder.Settings;
- if (!Width.IsDirty) Width.Load(settings?.Width.ToString(CultureInfo.InvariantCulture) ?? string.Empty);
- if (!Height.IsDirty) Height.Load(settings?.Height.ToString(CultureInfo.InvariantCulture) ?? string.Empty);
+ LoadBox();
UpdateLists();
Notices = Editor.Plan is { } plan ? PlanNotices(plan) : [];
OnAllPropertiesChanged();
@@ -547,6 +567,35 @@ public sealed class ExportTab : EditorTab
base.Dispose();
}
+ ///
+ /// Width and Height edit the preset's box, which the chosen proportions are fitted in (owner review 1, R5): they show the
+ /// resolved box (empty for a side the preset leaves to the source), not the size rendered (Output size).
+ ///
+ private void LoadBox()
+ {
+ var resolved = Resolved;
+ if (!Width.IsDirty) Width.Load(resolved.Width > 0 ? resolved.Width.ToString(CultureInfo.InvariantCulture) : string.Empty);
+ if (!Height.IsDirty) Height.Load(resolved.Height > 0 ? resolved.Height.ToString(CultureInfo.InvariantCulture) : string.Empty);
+ }
+
+ /// "2160 × 3840".
+ private static string SizeText((int Width, int Height) size) =>
+ size.Width.ToString(Loc.Culture) + " × " + size.Height.ToString(Loc.Culture);
+
+ ///
+ /// The encoder's largest size turned as the output is (as fits it) when the output is
+ /// larger; otherwise the codec level capped it, and the size made is the largest it takes.
+ ///
+ private static (int Width, int Height) LargestTaken(ExportPlan plan)
+ {
+ var (width, height) = plan.OutputSize;
+ if (plan.Setup.Encoder.Capability is not { } capability) return plan.EncodedSize;
+ var (maxWidth, maxHeight) = (width >= height) == (capability.MaxWidth >= capability.MaxHeight)
+ ? (capability.MaxWidth, capability.MaxHeight)
+ : (capability.MaxHeight, capability.MaxWidth);
+ return width > maxWidth || height > maxHeight ? (maxWidth, maxHeight) : plan.EncodedSize;
+ }
+
/// The choices that depend on the resolved codec (new lists only when they change, so selections stay bound).
private void UpdateLists()
{
diff --git a/src/Chronos.App/Editor/ExposureTab.cs b/src/Chronos.App/Editor/ExposureTab.cs
index cc1bdaa5..00a5186f 100644
--- a/src/Chronos.App/Editor/ExposureTab.cs
+++ b/src/Chronos.App/Editor/ExposureTab.cs
@@ -1,4 +1,6 @@
+using Chronos.App.Infrastructure;
using Chronos.Core.Advice;
+using Chronos.Core.Imaging.Color;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Core.Render;
@@ -20,7 +22,7 @@ public enum ExposureChart
}
///
-/// Exposure (BRIEF §12.3): deflicker, regions, holy-grail transitions and white balance. The luminance chart shows the
+/// Exposure (BRIEF §12.3): deflicker, regions, holy-grail transitions, white balance and the look. The luminance chart shows the
/// measured luminance (Sun) against the target curve the corrections produce (Accent), the sky region (dashed) and the
/// exposure steps as received; the flicker chart the frame-to-frame change before and after correction; the waveform
/// the luma distribution of the corrected frame on screen.
@@ -58,11 +60,47 @@ public sealed class ExposureTab : EditorTab
new InfoRow("Editor.Exposure.Temperature", "Tooltips.Editor.Exposure.Temperature", Temperature),
new NumberRow(s, "Editor.Exposure.Offset", "Tooltips.Editor.Exposure.Offset", -3, 3, 0.1, p => p.Exposure.ExposureOffsetEv,
(p, v) => p with { Exposure = p.Exposure with { ExposureOffsetEv = v } }, v => Loc.L("Editor.Value.Ev", EditorText.Ev(v))),
+ .. LookRows(s),
];
Refresh();
BuildChart();
}
+ ///
+ /// The Look group at the end of the step (owner review 1, R6): the filter (None, Mono, Sepia, Warm, Cool, Vivid, Muted,
+ /// Fade) and its strength, "n/a" without a filter. The look is a project setting outside Exposure, so moving these never
+ /// measures again ().
+ ///
+ public static IReadOnlyList LookRows(EditorSession session)
+ {
+ ArgumentNullException.ThrowIfNull(session);
+ string? NoLook(ProjectSettings p) => HasFilter(p) ? null : Loc.L("Tooltips.Editor.NotApplicable.NoLook");
+ return
+ [
+ new GroupRow("Editor.Look.Group", "Tooltips.Editor.Look.Group"),
+ new ChoiceRow(session, "Editor.Look.Filter", "Tooltips.Editor.Look.Filter",
+ [.. LookFilter.Names.Select(n => new Choice(n, "Editor.Look." + char.ToUpperInvariant(n[0]) + n[1..]))],
+ p => p.Look?.Filter ?? LookFilter.None, (p, v) => WithLook(p, (string)v, p.Look?.Strength)),
+ new NumberRow(session, "Editor.Look.Strength", "Tooltips.Editor.Look.Strength", 0, 1, 0.01, p => HasFilter(p) ? p.Look!.Strength ?? 1 : 1,
+ (p, v) => WithLook(p, p.Look?.Filter, double.Round(v, 2)), v => Formatting.Percent(v), NoLook),
+ ];
+ }
+
+ ///
+ /// with the look at : none when the filter
+ /// is None (so a project without a look keeps settings format 1 and its text), the strength omitted at 100 %. Values of
+ /// a newer Chronos inside the look are kept.
+ ///
+ public static ProjectSettings WithLook(ProjectSettings project, string? filter, double? strength)
+ {
+ ArgumentNullException.ThrowIfNull(project);
+ if (filter is null || filter == LookFilter.None) return project with { Look = null };
+ var look = (project.Look ?? new LookSettings()) with { Filter = filter, Strength = strength is >= 1 ? null : strength };
+ return project with { Look = look };
+ }
+
+ private static bool HasFilter(ProjectSettings project) => project.Look?.Filter is { } filter && filter != LookFilter.None && LookFilter.IsKnown(filter);
+
/// Luminance, flicker or waveform (the switch beside the chart).
public ExposureChart ChartMode
{
diff --git a/src/Chronos.App/Editor/SettingRows.cs b/src/Chronos.App/Editor/SettingRows.cs
index c59dc923..4870ffbf 100644
--- a/src/Chronos.App/Editor/SettingRows.cs
+++ b/src/Chronos.App/Editor/SettingRows.cs
@@ -3,6 +3,7 @@ using System.Windows.Input;
using Chronos.Core.Advice;
using Chronos.Core.Localization;
using Chronos.Core.Project;
+using Chronos.Ui.Controls;
using Chronos.Ui.Mvvm;
namespace Chronos.App.Editor;
@@ -306,6 +307,12 @@ public sealed class NumberRow : SettingRow
public double Maximum { get; }
public double Step { get; }
+ ///
+ /// Using the slider (dragged or focused) shows the preview's straighten grid (Editor.IsStraightening, driven
+ /// by the view through ): the Camera step's Straighten.
+ ///
+ public bool ShowsGrid { get; init; }
+
public double Value
{
get => _value;
@@ -395,3 +402,85 @@ public sealed class InfoRow(string headerKey, string toolTipKey, Func<(string? V
protected override void Read() => (Value, NotApplicableReason) = read();
}
+
+///
+/// A plain switch (no advice): the Camera step's Mirror and Flip. Each toggle is one edit, made by
+/// with the new state (it may change more than one member, as does).
+///
+public sealed class SwitchRow : SettingRow
+{
+ private readonly EditorSession _session;
+ private readonly Func _get;
+ private readonly Action _toggle;
+ private bool _isOn;
+
+ public SwitchRow(EditorSession session, string headerKey, string toolTipKey, Func get, Action toggle)
+ : base(headerKey, toolTipKey)
+ {
+ (_session, _get, _toggle) = (session, get, toggle);
+ Refresh();
+ }
+
+ public bool IsOn
+ {
+ get => _isOn;
+ set
+ {
+ if (!Set(ref _isOn, value) || IsRefreshing) return;
+ _toggle(value);
+ // A toggle the project did not take (read-only) springs back.
+ if (_get(_session.Project) != value) Refresh();
+ }
+ }
+
+ protected override void Read() => IsOn = _get(_session.Project);
+}
+
+/// An icon-only button of an : its glyph (a resource key such as "Icon.RotateLeft"), name and tooltip.
+public sealed class IconAction(string glyphKey, string nameKey, string toolTipKey, Action execute) : LocalizedViewModel
+{
+ public string GlyphKey { get; } = glyphKey;
+
+ public IconData? Glyph => System.Windows.Application.Current?.TryFindResource(GlyphKey) as IconData;
+
+ /// The button's accessible name ("Rotate left").
+ public string Name => Loc.L(nameKey);
+
+ public string ToolTip => Loc.L(toolTipKey);
+
+ public ICommand Command { get; } = new RelayCommand(execute);
+}
+
+/// A label, a read-only value and icon-only buttons (the Camera step's Rotation: "90°", Rotate left, Rotate right).
+public sealed class IconActionsRow : SettingRow
+{
+ private readonly Func _read;
+ private string _value = string.Empty;
+
+ public IconActionsRow(string headerKey, string toolTipKey, Func value, IReadOnlyList actions)
+ : base(headerKey, toolTipKey)
+ {
+ (_read, Actions) = (value, actions);
+ Refresh();
+ }
+
+ public string Value { get => _value; private set => Set(ref _value, value); }
+
+ public IReadOnlyList Actions { get; }
+
+ protected override void Read() => Value = _read();
+
+ public override void Dispose()
+ {
+ foreach (var action in Actions) action.Dispose();
+ base.Dispose();
+ }
+}
+
+/// The start of a group of rows inside a step's column: a divider and the group's name (the Exposure step's Look).
+public sealed class GroupRow(string headerKey, string toolTipKey) : SettingRow(headerKey, toolTipKey)
+{
+ protected override void Read()
+ {
+ }
+}
diff --git a/src/Chronos.App/Editor/SliderActivity.cs b/src/Chronos.App/Editor/SliderActivity.cs
new file mode 100644
index 00000000..a9db6c26
--- /dev/null
+++ b/src/Chronos.App/Editor/SliderActivity.cs
@@ -0,0 +1,50 @@
+using System.Windows;
+
+namespace Chronos.App.Editor;
+
+///
+/// Whether the user is using a control (it holds the keyboard focus or the mouse capture: a slider dragged or focused),
+/// for a binding to say so (, bound one way to the source): the Camera step's Straighten
+/// shows the preview's grid while it is used (owner review 1, R6). starts the tracking.
+///
+public static class SliderActivity
+{
+ public static readonly DependencyProperty TracksProperty = DependencyProperty.RegisterAttached(
+ "Tracks", typeof(bool), typeof(SliderActivity), new PropertyMetadata(false, OnTracksChanged));
+
+ public static readonly DependencyProperty IsActiveProperty = DependencyProperty.RegisterAttached(
+ "IsActive", typeof(bool), typeof(SliderActivity), new FrameworkPropertyMetadata(false));
+
+ public static bool GetTracks(DependencyObject d) => (bool)d.GetValue(TracksProperty);
+
+ public static void SetTracks(DependencyObject d, bool value) => d.SetValue(TracksProperty, value);
+
+ public static bool GetIsActive(DependencyObject d) => (bool)d.GetValue(IsActiveProperty);
+
+ public static void SetIsActive(DependencyObject d, bool value) => d.SetValue(IsActiveProperty, value);
+
+ private static void OnTracksChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is not FrameworkElement element) return;
+ element.IsKeyboardFocusWithinChanged -= OnChanged;
+ element.IsMouseCaptureWithinChanged -= OnChanged;
+ element.Unloaded -= OnUnloaded;
+ if (e.NewValue is not true) return;
+ element.IsKeyboardFocusWithinChanged += OnChanged;
+ element.IsMouseCaptureWithinChanged += OnChanged;
+ element.Unloaded += OnUnloaded;
+ Update(element);
+ }
+
+ private static void OnChanged(object sender, DependencyPropertyChangedEventArgs e) => Update((FrameworkElement)sender);
+
+ /// A control taken off screen (another step) is no longer being used.
+ private static void OnUnloaded(object sender, RoutedEventArgs e) => ((FrameworkElement)sender).SetCurrentValue(IsActiveProperty, false);
+
+ /// Set through , so a binding on the property stays and receives it.
+ private static void Update(FrameworkElement element)
+ {
+ var active = element.IsKeyboardFocusWithin || element.IsMouseCaptureWithin;
+ if (GetIsActive(element) != active) element.SetCurrentValue(IsActiveProperty, active);
+ }
+}
diff --git a/tests/Chronos.App.Tests/Editor/CameraTabTests.cs b/tests/Chronos.App.Tests/Editor/CameraTabTests.cs
new file mode 100644
index 00000000..254b6e33
--- /dev/null
+++ b/tests/Chronos.App.Tests/Editor/CameraTabTests.cs
@@ -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;
+
+///
+/// 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.
+///
+[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(IReadOnlyList rows, string headerKey)
+ where T : SettingRow => (T)rows.Single(r => r.Header == Loc.L(headerKey));
+
+ private static void Refresh(IReadOnlyList 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(rows, "Editor.Camera.CropSize");
+ var x = Row(rows, "Editor.Camera.CropX");
+ var y = Row(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(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(rows, "Editor.Camera.CropX").Value, "the rows show it where it renders");
+ Row(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(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(rows, "Editor.Camera.Mirror");
+ var flip = Row(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(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(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().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(rows, "Editor.Look.Filter");
+ var strength = Row(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();
+ 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();
+ 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);
+ }
+ }
+}
diff --git a/tests/Chronos.App.Tests/Editor/EditPathTests.cs b/tests/Chronos.App.Tests/Editor/EditPathTests.cs
index 8cf70289..90a995d0 100644
--- a/tests/Chronos.App.Tests/Editor/EditPathTests.cs
+++ b/tests/Chronos.App.Tests/Editor/EditPathTests.cs
@@ -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()
{
diff --git a/tests/Chronos.App.Tests/Editor/EditorSessionTests.cs b/tests/Chronos.App.Tests/Editor/EditorSessionTests.cs
index 62768347..f22c5a66 100644
--- a/tests/Chronos.App.Tests/Editor/EditorSessionTests.cs
+++ b/tests/Chronos.App.Tests/Editor/EditorSessionTests.cs
@@ -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) ----
+
+ /// A project with a manual aspect (the advice never decides it) and a crop.
+ 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);
+ }
+ }
}
diff --git a/tests/Chronos.App.Tests/Editor/EditorTextTests.cs b/tests/Chronos.App.Tests/Editor/EditorTextTests.cs
index 1b291bbb..93bc6142 100644
--- a/tests/Chronos.App.Tests/Editor/EditorTextTests.cs
+++ b/tests/Chronos.App.Tests/Editor/EditorTextTests.cs
@@ -8,7 +8,7 @@ using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
-/// Composed texts of the editor (the conflict prompt among them), crop margins and the waveform monitor.
+/// Composed texts of the editor (the conflict prompt among them, the Camera step's values) and the waveform monitor.
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]
diff --git a/tests/Chronos.App.Tests/Editor/ExportPlannerTests.cs b/tests/Chronos.App.Tests/Editor/ExportPlannerTests.cs
index ed36ee5b..b85a0970 100644
--- a/tests/Chronos.App.Tests/Editor/ExportPlannerTests.cs
+++ b/tests/Chronos.App.Tests/Editor/ExportPlannerTests.cs
@@ -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);
}
+
+ /// An H.264 encoder that takes at most × (either way round).
+ private sealed class H264Provider(int maxWidth, int maxHeight) : IVideoEncoderProvider
+ {
+ public string Name => "h264";
+
+ public IReadOnlyList 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");
+ }
}