feat(editor): visual crop, rotate/mirror/flip/straighten, colour looks (owner review 1 phase 4) (#26)
CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s
CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s
Owner review 1 R5 + R6. Camera rotation, mirror, flip, straighten and crop handles locked to the output; an Exposure Look group; Export output size ("proportions win"); settings format 2 with older-node gates. Also fixes project text and hashes differing between Windows and Linux.
Closes #19
Closes #20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #26.
This commit is contained in:
1 parent
db389a54f2
commit
188b2c2e55
355 files changed
+10549
-1061
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Video;
|
||||
|
||||
@@ -26,7 +27,7 @@ internal sealed class CapturingEncoderProvider(string name, params EncoderCapabi
|
||||
public (int Frame, Exception Error)? FailAt { get; set; }
|
||||
|
||||
public bool CanEncode(EncodeSettings settings) => capabilities.Any(c =>
|
||||
c.Codec == settings.Codec && settings.Width <= c.MaxWidth && settings.Height <= c.MaxHeight && (settings.BitDepth == 8 || c.SupportsTenBit));
|
||||
c.Codec == settings.Codec && EncoderSelector.Takes(c, settings.Width, settings.Height) && (settings.BitDepth == 8 || c.SupportsTenBit));
|
||||
|
||||
public IVideoEncoderSession Open(EncodeSettings settings)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Imaging.Color;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Testing;
|
||||
using static Chronos.Core.Tests.Render.RenderFixture;
|
||||
|
||||
namespace Chronos.Core.Tests.Render;
|
||||
|
||||
/// <summary>The colour look in renders (owner review 1, R6): once per output frame, after stacking, before the knee.</summary>
|
||||
public sealed class LookRenderTests(TestContext context)
|
||||
{
|
||||
private static ProjectSettings With(LookSettings? look, double? knee = null, StackSettings? stack = null) =>
|
||||
Plain with { Look = look, Exposure = new ExposureSettings { HighlightKnee = knee }, Stack = stack ?? new StackSettings() };
|
||||
|
||||
private static void SameFrames(IReadOnlyList<ImageBuffer> expected, IReadOnlyList<ImageBuffer> actual)
|
||||
{
|
||||
Assert.Equal(expected.Count, actual.Count);
|
||||
for (var i = 0; i < expected.Count; i++) Assert.True(expected[i].Data.SequenceEqual(actual[i].Data), $"frame {i}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheIdentityLooksRenderTheSameBytesAsNoLook()
|
||||
{
|
||||
var (plain, _) = await CaptureAsync(Input(Source(4), With(null)), cancellationToken: context.Cancellation);
|
||||
foreach (var look in new[] { new LookSettings { Filter = LookFilter.None }, new LookSettings { Filter = "vivid", Strength = 0 } })
|
||||
{
|
||||
var (encode, result) = await CaptureAsync(Input(Source(4), With(look)), cancellationToken: context.Cancellation);
|
||||
SameFrames(plain.Frames, encode.Frames);
|
||||
Assert.Empty(result.Warnings);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUnknownLookRendersAsNoneWithAWarning()
|
||||
{
|
||||
var (plain, _) = await CaptureAsync(Input(Source(4), With(null)), cancellationToken: context.Cancellation);
|
||||
var (encode, result) = await CaptureAsync(Input(Source(4), With(new LookSettings { Filter = "technicolor" })), cancellationToken: context.Cancellation);
|
||||
SameFrames(plain.Frames, encode.Frames);
|
||||
Assert.Contains(result.Warnings, w => w.Key == "Export.Render.LookIgnored" && w.Args.SequenceEqual(["technicolor"]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ACaptureWithALookIsTheFinishOfThePlainCapture()
|
||||
{
|
||||
// The look comes before the knee: the plain render has no knee, so the finish adds both in its own order.
|
||||
var look = new LookSettings { Filter = "sepia", Strength = 0.7 };
|
||||
var source = Source(6, configure: o => o with { StartEv = 1, EndEv = 2 });
|
||||
var (plain, _) = await CaptureAsync(Input(source, With(null)), cancellationToken: context.Cancellation);
|
||||
var (encode, result) = await CaptureAsync(Input(source, With(look, knee: 0.85)), cancellationToken: context.Cancellation);
|
||||
Assert.Empty(result.Warnings);
|
||||
foreach (var frame in plain.Frames) FrameFinish.Apply(frame, look, 0.85);
|
||||
SameFrames(plain.Frames, encode.Frames);
|
||||
Assert.Less(encode.Frames.Max(f => f.Data.ToArray().Max()), 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AMedianStackWithMonoIsMonoOfTheMedian()
|
||||
{
|
||||
var stack = new StackSettings { Mode = StackSetting.Median, Length = 5 };
|
||||
var source = Source(9, motion: i => (0.5 * i, 0));
|
||||
var (median, _) = await CaptureAsync(Input(source, With(null, stack: stack)), cancellationToken: context.Cancellation);
|
||||
var (mono, _) = await CaptureAsync(Input(source, With(new LookSettings { Filter = "mono" }, stack: stack)), cancellationToken: context.Cancellation);
|
||||
foreach (var frame in median.Frames) LookFilter.Apply(frame, "mono", 1);
|
||||
SameFrames(median.Frames, mono.Frames);
|
||||
Assert.True(mono.Frames.All(f => f.Plane(0).SequenceEqual(f.Plane(1)) && f.Plane(1).SequenceEqual(f.Plane(2))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PngOutputWithALookIsByteIdenticalAcrossRuns()
|
||||
{
|
||||
var dir = context.CreateTempDirectory();
|
||||
var project = With(new LookSettings { Filter = "fade", Strength = 0.8 }, knee: 0.9);
|
||||
var first = await Pipeline().RenderAsync(Input(Source(5), project), Target(dir, Preset("png-sequence") with { BitDepth = 16 }, "a"), cancellationToken: context.Cancellation);
|
||||
var second = await Pipeline().RenderAsync(Input(Source(5), project), Target(dir, Preset("png-sequence") with { BitDepth = 16 }, "b"), cancellationToken: context.Cancellation);
|
||||
var a = Directory.GetFiles(first.OutputPath).Order(StringComparer.Ordinal).ToArray();
|
||||
var b = Directory.GetFiles(second.OutputPath).Order(StringComparer.Ordinal).ToArray();
|
||||
Assert.Equal(5, a.Length);
|
||||
Assert.Equal(a.Length, b.Length);
|
||||
for (var i = 0; i < a.Length; i++) Assert.BytesEqual(File.ReadAllBytes(a[i]), File.ReadAllBytes(b[i]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Imaging.Geometry;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Core.Tests.Geometry;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Core.Tests.Render;
|
||||
|
||||
public sealed class RenderGeometryTests
|
||||
{
|
||||
[Test]
|
||||
public void TheChosenProportionsWinOverAFixedPreset()
|
||||
{
|
||||
var portrait = RenderGeometry.Create(Camera("9:16"), Export("4k-h264"), 6000, 4000);
|
||||
Assert.Equal((2160, 3840), (portrait.OutputWidth, portrait.OutputHeight));
|
||||
Assert.Approximately(9 / 16.0, portrait.OutputRatio, 1e-12);
|
||||
Assert.Empty(portrait.Warnings);
|
||||
|
||||
var source = RenderGeometry.Create(new CameraSettings(), Export("4k-h264"), 6000, 4000);
|
||||
Assert.Equal((3840, 2160), (source.OutputWidth, source.OutputHeight));
|
||||
Assert.Approximately(16 / 9.0, source.OutputRatio, 1e-12);
|
||||
|
||||
// Every case agrees with RenderSize, which the server routes jobs with.
|
||||
foreach (var aspect in new[] { "source", "9:16", "1:1", "4:5", "21:9" })
|
||||
{
|
||||
foreach (var camera in new[] { Camera(aspect), Camera(aspect) with { Rotate = 90 } })
|
||||
{
|
||||
foreach (var preset in new[] { "4k-h264", "1080p-h264", "vertical-1080x1920", "png-sequence" })
|
||||
{
|
||||
var geometry = RenderGeometry.Create(camera, Export(preset), 6000, 4000);
|
||||
Assert.Equal(RenderSize.Of(camera, Export(preset), 6000, 4000), (geometry.OutputWidth, geometry.OutputHeight), $"{aspect} {preset} {camera.Rotate}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AQuarterTurnSwapsTheViewAndLocksTheCropInIt()
|
||||
{
|
||||
var turned = RenderGeometry.Create(new CameraSettings { Rotate = 90 }, Export("png-sequence"), 6000, 4000);
|
||||
Assert.Equal((4000, 6000), (turned.ViewWidth, turned.ViewHeight));
|
||||
Assert.Equal((4000, 6000), (turned.OutputWidth, turned.OutputHeight));
|
||||
Assert.Equal((6000, 4000), (turned.SourceWidth, turned.SourceHeight));
|
||||
|
||||
// 1:1 on the turned view: the box is as wide as the view and 4000/6000 of its height, in normalised units.
|
||||
var square = RenderGeometry.Create(Camera("1:1") with { Rotate = 90 }, Export("png-sequence"), 6000, 4000);
|
||||
Assert.Approximately(1.5, square.LockRatio, 1e-12);
|
||||
var crop = square.EditableCrop;
|
||||
Assert.Approximately(1, crop.Width, 1e-12);
|
||||
Assert.Approximately(2 / 3.0, crop.Height, 1e-12);
|
||||
Assert.Approximately(1 / 6.0, crop.Y, 1e-12);
|
||||
Assert.Equal((4000, 4000), (square.OutputWidth, square.OutputHeight));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheEditableCropIsTheRenderedCrop()
|
||||
{
|
||||
var camera = Camera("4:5") with { Crop = [0.1, 0.2, 0.5, 0.6], OffsetX = 1, OffsetY = -1, Rotate = 270, Mirror = true };
|
||||
var geometry = RenderGeometry.Create(camera, Export("png-sequence"), 96, 64);
|
||||
// The Export step's footprint of a frame without pose or stabilisation is the Camera step's box.
|
||||
foreach (var (w, h) in new[] { (96, 64), (48, 32) })
|
||||
{
|
||||
var plan = GeometryStage.Plan(w, h, geometry.For(w, h, 0, Affine2D.Identity));
|
||||
var footprint = geometry.FootprintInView(plan, w, h);
|
||||
var box = geometry.EditableCrop;
|
||||
Assert.Approximately(box.X, footprint.X, 1e-9);
|
||||
Assert.Approximately(box.Y, footprint.Y, 1e-9);
|
||||
Assert.Approximately(box.Width, footprint.Width, 1e-9);
|
||||
Assert.Approximately(box.Height, footprint.Height, 1e-9);
|
||||
}
|
||||
Assert.Equal(new RectD(0, 0, 1, 1), geometry.FootprintInView(null, 96, 64));
|
||||
// The box the editor would write for it renders the same.
|
||||
var written = Camera("4:5") with { Crop = CropFrame.ToCrop(geometry.EditableCrop), Rotate = 270, Mirror = true };
|
||||
var again = RenderGeometry.Create(written, Export("png-sequence"), 96, 64);
|
||||
Assert.Equal((geometry.OutputWidth, geometry.OutputHeight), (again.OutputWidth, again.OutputHeight));
|
||||
Assert.Approximately(geometry.EditableCrop.X, again.EditableCrop.X, 1e-12);
|
||||
Assert.Approximately(geometry.EditableCrop.Y, again.EditableCrop.Y, 1e-12);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ViewToFrameMapsTheViewOntoTheDecodedFrame()
|
||||
{
|
||||
var geometry = RenderGeometry.Create(new CameraSettings { Rotate = 180, Flip = true, Straighten = -4 }, Export("png-sequence"), 6000, 4000);
|
||||
var small = geometry.ViewToFrame(600, 400);
|
||||
Assert.Equal(FrameOrientation.Of(180, false, true, -4, 600, 400).ViewToFrame, small);
|
||||
Assert.Equal(geometry.Orientation.ViewToFrame, geometry.ViewToFrame(6000, 4000));
|
||||
Assert.Equal(Affine2D.Identity, RenderGeometry.Create(new CameraSettings(), Export("png-sequence"), 60, 40).ViewToFrame(60, 40));
|
||||
|
||||
// The Source framing shows the whole view at the size asked, and only an identity camera skips the warp.
|
||||
var view = geometry.ViewFor(600, 400, 300, 200);
|
||||
var plan = GeometryStage.Plan(600, 400, view);
|
||||
Assert.Equal((300, 200), (plan.OutputWidth, plan.OutputHeight));
|
||||
Assert.Equal(new RectD(0, 0, 600, 400), plan.Crop);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheDecodeGrowsWithTheCoverZoom()
|
||||
{
|
||||
var plain = RenderGeometry.Create(new CameraSettings(), Export("png-sequence", 96, 64), 480, 320);
|
||||
Assert.Equal(96, plain.WorkingLongEdge);
|
||||
foreach (var degrees in new[] { 2.0, 10.0, -15.0 })
|
||||
{
|
||||
var straightened = RenderGeometry.Create(new CameraSettings { Straighten = degrees }, Export("png-sequence", 96, 64), 480, 320);
|
||||
var zoom = straightened.Orientation.CoverZoom;
|
||||
Assert.Greater(zoom, 1);
|
||||
Assert.Equal((int)double.Ceiling(96 * zoom), straightened.WorkingLongEdge);
|
||||
}
|
||||
// Quarter turns do not change the long edge.
|
||||
Assert.Equal(96, RenderGeometry.Create(new CameraSettings { Rotate = 90 }, Export("png-sequence", 64, 96), 480, 320).WorkingLongEdge);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StabilisationComposesInRawFrameSpace()
|
||||
{
|
||||
// stab⁻¹ · O⁻¹ · V: the correction is undone in the decoded frame, after the view is mapped back into it.
|
||||
var geometry = RenderGeometry.Create(new CameraSettings { Rotate = 90 }, Export("png-sequence"), 96, 64);
|
||||
var shift = Affine2D.Translation(3, -2);
|
||||
var settings = geometry.For(96, 64, 0, shift);
|
||||
var plain = geometry.For(96, 64, 0, Affine2D.Identity);
|
||||
var (x, y) = settings.Warp.Apply(10, 20);
|
||||
var (px, py) = plain.Warp.Apply(10, 20);
|
||||
Assert.Within(px - 3, py + 2, x, y, 1e-12);
|
||||
|
||||
using var frame = FrameOrientationTests.Texture(96, 64, seed: 11);
|
||||
using var view = GeometryStage.Apply(frame, plain);
|
||||
Assert.Equal((64, 96), (view.Width, view.Height));
|
||||
}
|
||||
|
||||
private static CameraSettings Camera(string aspect) => new() { Aspect = new Auto<string>().WithManual(aspect) };
|
||||
|
||||
private static ResolvedExport Export(string preset, int width = -1, int height = -1)
|
||||
{
|
||||
var export = ExportResolver.Resolve(new ExportSettings { Preset = new Auto<string>().WithManual(preset) });
|
||||
return width < 0 ? export : export with { Width = width, Height = height };
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,33 @@ public sealed class RenderPipelineTests
|
||||
Assert.BytesEqual(File.ReadAllBytes(apngA.OutputPath), File.ReadAllBytes(apngB.OutputPath));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TransformedOutputsAreByteIdenticalAcrossRuns()
|
||||
{
|
||||
var dir = _context.CreateTempDirectory();
|
||||
var project = Plain with
|
||||
{
|
||||
Camera = new CameraSettings
|
||||
{
|
||||
Rotate = 90,
|
||||
Mirror = true,
|
||||
Straighten = 3.5,
|
||||
Aspect = new Auto<string>().WithManual("4:5"),
|
||||
Crop = [0.1, 0.05, 0.8, 0.8],
|
||||
Keyframes = [new CameraKey(0, 0.45, 0.5, 1.2, 2), new CameraKey(11, 0.55, 0.5, 1.4, -2)],
|
||||
},
|
||||
};
|
||||
var export = Preset("png-sequence", 64, 64);
|
||||
var first = await Pipeline().RenderAsync(Input(Source(), project), Target(dir, export, "a"), cancellationToken: _context.Cancellation);
|
||||
var second = await Pipeline().RenderAsync(Input(Source(), project), Target(dir, export, "b"), cancellationToken: _context.Cancellation);
|
||||
Assert.Equal((51, 64), (first.Width, first.Height));
|
||||
var a = Directory.GetFiles(first.OutputPath).Order(StringComparer.Ordinal).ToArray();
|
||||
var b = Directory.GetFiles(second.OutputPath).Order(StringComparer.Ordinal).ToArray();
|
||||
Assert.Equal(12, a.Length);
|
||||
Assert.Equal(a.Length, b.Length);
|
||||
for (var i = 0; i < a.Length; i++) Assert.BytesEqual(File.ReadAllBytes(a[i]), File.ReadAllBytes(b[i]));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Case("mjpeg-avi")]
|
||||
[Case("png-sequence")]
|
||||
|
||||
@@ -142,6 +142,61 @@ public sealed class RenderProcessingTests
|
||||
Assert.Greater(Psnr(expected, corner.Frames[2]), 60);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A crop in the view frame keeps its content through every orientation press: the capture after the press is the
|
||||
/// plain capture turned, mirrored or flipped the same way.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[Case(OrientationOp.RotateRight, 1, false, false)]
|
||||
[Case(OrientationOp.RotateLeft, 3, false, false)]
|
||||
[Case(OrientationOp.Mirror, 0, true, false)]
|
||||
[Case(OrientationOp.Flip, 0, false, true)]
|
||||
public async Task OrientationPressesKeepTheCroppedContent(OrientationOp op, int turns, bool mirror, bool flip)
|
||||
{
|
||||
var source = Source(4);
|
||||
var framed = With(camera: new CameraSettings { Crop = [0.5, 0.25, 0.5, 0.5], Aspect = On("3:2") });
|
||||
var (plain, before) = await CaptureAsync(Input(source, framed), Preset("png-sequence", 0, 0), cancellationToken: _context.Cancellation);
|
||||
Assert.Equal((48, 32), (before.Width, before.Height));
|
||||
var pressed = OrientationEdit.Apply(framed, op);
|
||||
var (moved, after) = await CaptureAsync(Input(source, pressed), Preset("png-sequence", 0, 0), cancellationToken: _context.Cancellation);
|
||||
Assert.Empty(after.Warnings);
|
||||
using var expected = Geometry.FrameOrientationTests.Permuted(plain.Frames[2], turns, mirror, flip);
|
||||
Assert.Equal((expected.Width, expected.Height), (after.Width, after.Height));
|
||||
var psnr = Psnr(expected, moved.Frames[2]);
|
||||
_context.Log($"{op}: {psnr:F1} dB");
|
||||
Assert.Greater(psnr, 60);
|
||||
Assert.True(expected.Data.SequenceEqual(moved.Frames[2].Data), "a quarter turn, a mirror and a flip move whole pixels");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APortraitAspectTurnsAFixedPresetToPortrait()
|
||||
{
|
||||
var source = Source(4);
|
||||
using var reference = source.Sequence.Render(2);
|
||||
var project = With(camera: new CameraSettings { Aspect = On("9:16") });
|
||||
var (encode, result) = await CaptureAsync(Input(source, project), Preset("png-sequence", 96, 64), cancellationToken: _context.Cancellation);
|
||||
Assert.Equal((54, 96), (result.Width, result.Height));
|
||||
Assert.Empty(result.Warnings);
|
||||
using var expected = GeometryStage.Apply(reference, new GeometrySettings { Crop = new RectD(30, 0, 36, 64), OutputWidth = 54, OutputHeight = 96 });
|
||||
Assert.Greater(Psnr(expected, encode.Frames[2]), 60);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task StraightenLevelsTheViewAndDecodesLarger()
|
||||
{
|
||||
var source = Source(4, width: 480, height: 320);
|
||||
var project = With(camera: new CameraSettings { Straighten = -6 });
|
||||
var (encode, result) = await CaptureAsync(Input(source, project), Preset("png-sequence", 96, 64), cancellationToken: _context.Cancellation);
|
||||
var orientation = FrameOrientation.Of(project.Camera, 480, 320);
|
||||
Assert.Equal((int)double.Ceiling(96 * orientation.CoverZoom), source.LargestRenderRequest);
|
||||
Assert.Empty(result.Warnings);
|
||||
using var full = source.Sequence.Render(1);
|
||||
using var expected = GeometryStage.Apply(full, new GeometrySettings { OutputWidth = 96, OutputHeight = 64, Warp = orientation.ViewToFrame });
|
||||
var psnr = Psnr(expected, encode.Frames[1]);
|
||||
_context.Log($"straighten −6° vs a direct warp: {psnr:F1} dB, cover zoom {orientation.CoverZoom:F4}");
|
||||
Assert.Greater(psnr, 28);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task VirtualCameraZoomsAndTheDecodeSizeFollowsTheNeed()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Core.Tests.Render;
|
||||
|
||||
public sealed class RenderRulesTests
|
||||
{
|
||||
[Test]
|
||||
public void AMismatchedFixedPresetNeedsFormatTwo()
|
||||
{
|
||||
var project = new ProjectSettings { Camera = Camera("9:16") };
|
||||
Assert.Equal(2, RenderRules.RequiredFormat(project, Export("4k-h264"), 6000, 4000));
|
||||
// The same proportions as the preset, "source" or a free-size preset change nothing an older build would render.
|
||||
Assert.Equal(1, RenderRules.RequiredFormat(project with { Camera = Camera("16:9") }, Export("4k-h264"), 6000, 4000));
|
||||
Assert.Equal(1, RenderRules.RequiredFormat(new ProjectSettings(), Export("4k-h264"), 6000, 4000));
|
||||
Assert.Equal(1, RenderRules.RequiredFormat(project, Export("png-sequence"), 6000, 4000));
|
||||
// The settings' own format counts too.
|
||||
var turned = new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } };
|
||||
Assert.Equal(2, RenderRules.RequiredFormat(turned, Export("png-sequence"), 6000, 4000));
|
||||
var newer = ProjectSettings.FromJson("""{ "version": 3 }""", allowNewer: true);
|
||||
Assert.Equal(3, RenderRules.RequiredFormat(newer, Export("4k-h264"), 6000, 4000));
|
||||
}
|
||||
|
||||
private static CameraSettings Camera(string aspect) => new() { Aspect = new Auto<string>().WithManual(aspect) };
|
||||
|
||||
private static ResolvedExport Export(string preset, ExportOverrides? overrides = null) =>
|
||||
ExportResolver.Resolve(new ExportSettings { Preset = new Auto<string>().WithManual(preset), Overrides = overrides ?? new ExportOverrides() });
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Core.Tests.Render;
|
||||
|
||||
public sealed class RenderSizeTests
|
||||
{
|
||||
[Theory]
|
||||
[Case("4k-h264", "9:16", 2160, 3840)]
|
||||
[Case("4k-h264", "1:1", 2160, 2160)]
|
||||
[Case("4k-h264", "4:5", 2160, 2700)]
|
||||
[Case("4k-h264", "21:9", 3840, 1646)]
|
||||
[Case("4k-h264", "16:9", 3840, 2160)]
|
||||
[Case("1080p-h264", "9:16", 1080, 1920)]
|
||||
[Case("vertical-1080x1920", "16:9", 1920, 1080)]
|
||||
[Case("vertical-1080x1920", "9:16", 1080, 1920)]
|
||||
public void TheChosenProportionsWinOverAFixedPreset(string preset, string aspect, int width, int height) =>
|
||||
Assert.Equal((width, height), RenderSize.Of(Camera(aspect), Export(preset), 6000, 4000));
|
||||
|
||||
[Test]
|
||||
public void SourceKeepsThePresetsSize()
|
||||
{
|
||||
Assert.Equal((3840, 2160), RenderSize.Of(new CameraSettings(), Export("4k-h264"), 3000, 4000));
|
||||
Assert.Equal((1080, 1920), RenderSize.Of(Camera("source"), Export("vertical-1080x1920"), 6000, 4000));
|
||||
// An aspect that cannot be read renders as source.
|
||||
Assert.Equal((3840, 2160), RenderSize.Of(Camera("wide"), Export("4k-h264"), 6000, 4000));
|
||||
// The Auto's advised value counts like a manual one.
|
||||
var advised = new CameraSettings { Aspect = new Auto<string>().WithAdvice("9:16", null) };
|
||||
Assert.Equal((2160, 3840), RenderSize.Of(advised, Export("4k-h264"), 6000, 4000));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SizesAreEvenOnlyForCodecsThatNeedIt()
|
||||
{
|
||||
var png = Export("png-sequence", new ExportOverrides { Width = 1001, Height = 1001 });
|
||||
Assert.Equal((563, 1001), RenderSize.Of(Camera("9:16"), png, 6000, 4000));
|
||||
var h264 = Export("1080p-h264", new ExportOverrides { Width = 1001, Height = 1001 });
|
||||
Assert.Equal((562, 1000), RenderSize.Of(Camera("9:16"), h264, 6000, 4000));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FreeSizePresetsAreUnchanged()
|
||||
{
|
||||
// No side given: the aspect-fitted crop of the view, capped by the decode size.
|
||||
var png = Export("png-sequence");
|
||||
Assert.Equal((6000, 4000), RenderSize.Of(new CameraSettings(), png, 6000, 4000));
|
||||
Assert.Equal((2250, 4000), RenderSize.Of(Camera("9:16"), png, 6000, 4000));
|
||||
Assert.Equal((1500, 1000), RenderSize.Of(new CameraSettings(), png, 6000, 4000, maxWorkingLongEdge: 1500));
|
||||
Assert.Equal((3000, 2000), RenderSize.Of(new CameraSettings { Crop = [0.25, 0.25, 0.5, 0.5] }, png, 6000, 4000));
|
||||
// One side given: the other from the ratio.
|
||||
Assert.Equal((1200, 800), RenderSize.Of(new CameraSettings(), Export("png-sequence", new ExportOverrides { Width = 1200 }), 6000, 4000));
|
||||
Assert.Equal((450, 800), RenderSize.Of(Camera("9:16"), Export("png-sequence", new ExportOverrides { Height = 800 }), 6000, 4000));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AQuarterTurnTurnsTheSourceRatio()
|
||||
{
|
||||
var turned = new CameraSettings { Rotate = 90 };
|
||||
Assert.Equal((4000, 6000), RenderSize.Of(turned, Export("png-sequence"), 6000, 4000));
|
||||
Assert.Equal((4000, 6000), RenderSize.ViewSize(turned, 6000, 4000));
|
||||
Assert.Equal((6000, 4000), RenderSize.ViewSize(turned with { Rotate = 180 }, 6000, 4000));
|
||||
// A fixed preset with "source" keeps its own size whatever the turn.
|
||||
Assert.Equal((3840, 2160), RenderSize.Of(turned, Export("4k-h264"), 6000, 4000));
|
||||
Assert.Approximately(2 / 3.0, RenderSize.Ratio(turned, Export("png-sequence"), 6000, 4000), 1e-12);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AdaptTurnsTheBoxToTheRatiosOrientation()
|
||||
{
|
||||
Assert.Equal((2160, 3840), RenderSize.Adapt(3840, 2160, 9 / 16.0));
|
||||
Assert.Equal((2160, 3840), RenderSize.Adapt(2160, 3840, 9 / 16.0));
|
||||
Assert.Equal((1920, 1080), RenderSize.Adapt(1080, 1920, 16 / 9.0));
|
||||
Assert.Equal((1080, 1080), RenderSize.Adapt(1080, 1920, 1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => RenderSize.Adapt(1920, 1080, 0));
|
||||
}
|
||||
|
||||
private static CameraSettings Camera(string aspect) => new() { Aspect = new Auto<string>().WithManual(aspect) };
|
||||
|
||||
private static ResolvedExport Export(string preset, ExportOverrides? overrides = null) =>
|
||||
ExportResolver.Resolve(new ExportSettings { Preset = new Auto<string>().WithManual(preset), Overrides = overrides ?? new ExportOverrides() });
|
||||
}
|
||||
@@ -44,6 +44,16 @@ public sealed class SelfTestTests
|
||||
Assert.True(results.Where(r => r.Id != "render.mp4").All(r => r.Outcome == SelfTestOutcome.Passed));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GeometryChecksPass()
|
||||
{
|
||||
string[] ids = ["proc.orient", "proc.straighten", "proc.portrait", "proc.aspect", "proc.crop", "proc.look"];
|
||||
var results = await SelfTest.RunAsync(new SelfTestOptions { WorkDirectory = _context.CreateTempDirectory(), Filters = ids }, cancellationToken: _context.Cancellation);
|
||||
foreach (var r in results) _context.Log($"{r.Id}: {r.Outcome} {r.Detail}");
|
||||
Assert.SequenceEqual(ids.Order(StringComparer.Ordinal), results.Select(r => r.Id).Order(StringComparer.Ordinal));
|
||||
Assert.True(results.All(r => r.Outcome == SelfTestOutcome.Passed));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FailuresAreReportedNotThrown()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user