Files
Chronos/tests/Chronos.Core.Tests/Render/RenderSizeTests.cs
T
Alby96andClaude Opus 5.5 e4364c4f25 feat(project): settle phase 4 contracts: conditional settings format, transforms, look, output size
Groundwork for owner review 1, phase 4, so the parallel packages build on
fixed contracts and strings.

- Settings: camera rotate/mirror/flip/straighten and a look, declared after
  the existing members and omitted at default. ToJson writes the lowest
  format that renders the same (2 only while a transform or look is used),
  so projects without them keep byte-identical text and hash; an old-build
  simulation test proves the order survives an older build's round trip.
- RenderSize and RenderRules: proportions win over a fixed preset box, and
  the routing format a job needs.
- FrameOrientation, CropFrame, OrientationEdit, LookFilter (identity) and
  FrameFinish (look, then knee) wired into the render pipeline and preview;
  RenderGeometry gains view-frame members equivalent to today.
- Protocol trailing members for node, job and server formats; SyncText keys;
  EditPath counts transforms and the look as hand values.
- New en/it strings and tooltips, five icons, test fixtures moved to v3 as
  the first unread format, and the 18 DECISIONS rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 19:10:12 +01:00

84 lines
4.3 KiB
C#

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() });
}