feat(render): orient, straighten and let the chosen proportions win in the render geometry
Owner review 1, phase 4, package P1: the Core geometry behind the visual crop (R5) and the orientation controls (R6). - RenderGeometry: one warp stab⁻¹ · O⁻¹ · V with the crop and the keyframe centres in the view frame T (turned, mirrored, flipped, straightened); the output size comes from RenderSize, so a fixed preset adapts to the aspect (4K at 9:16 = 2160×3840) and AspectFromPreset is gone; the decode grows by the straighten cover zoom; ViewFor, ViewToFrame, EditableCrop and FootprintInView get their real bodies; a rotation that is not a quarter turn and an out-of-range straighten render as none or clamped, with their warnings. - FrameOrientation: the cover zoom is taken on the pixel-centre extents, so every output pixel samples inside the frame (full alpha coverage at ±15°, never a smeared border). - CropFrame: crops are written on the 12-decimal grid OrientationEdit remaps on, so four turns or two mirrors give back the same text; a stored crop is read value by value as the render reads it. - Advisor: the aspect (and the horizon framing) is advised on the view turned by the camera (SequenceContext.Rotate/Flip, ForCamera); the analyser passes the project's camera. - Self-test: proc.orient, proc.straighten, proc.portrait. - Tests: exact pixel permutations for turns, mirror and flip, the orientation algebra, straighten against an analytic ramp and its full coverage, Create sizes, a crop keeping its content through every press, CropFrame move/resize/refit/rows, OrientationEdit round trips and its agreement with FrameOrientation, the turned-view advice, determinism. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e4364c4f25
commit
bee66da63a
18 files changed
+1052
-67
No files matched your search
@@ -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.DoesNotContain("Export.Render.AspectFromPreset", result.Warnings.Select(w => w.Key));
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user