Files
Chronos/src/Chronos.Core/Render/Diagnostics/SelfTestGeometryChecks.cs
T
Alby96andClaude Opus 5.5 188b2c2e55
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
feat(editor): visual crop, rotate/mirror/flip/straighten, colour looks (owner review 1 phase 4) (#26)
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>
2026-11-05 01:09:09 +01:00

68 lines
4.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Chronos.Core.Imaging;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Project;
namespace Chronos.Core.Render.Diagnostics;
/// <summary>Orientation, straighten and output-proportion checks (owner review 1, R5/R6).</summary>
public static partial class SelfTest
{
private static IEnumerable<SelfTestCheck> GeometryChecks()
{
yield return Check("proc.orient", "A quarter turn with a mirror transposes the frame pixel for pixel", async context =>
{
var source = Synthetic(3);
var project = Plain with { Camera = new CameraSettings { Rotate = 90, Mirror = true } };
var frames = await RenderDecodedAsync(context, Input(source, project), Preset("png-sequence", 0, 0)).ConfigureAwait(false);
using var reference = source.Sequence.Render(1);
// A turn right then a mirror is the transpose: view (u, v) shows frame (v, u).
using var expected = new ImageBuffer(reference.Height, reference.Width, reference.Channels, clear: false);
for (var c = 0; c < reference.Channels; c++)
{
for (var v = 0; v < expected.Height; v++)
{
for (var u = 0; u < expected.Width; u++) expected[c, u, v] = reference[c, v, u];
}
}
var size = (frames[1].Width, frames[1].Height);
var psnr = size == (expected.Width, expected.Height) ? Psnr(expected, frames[1]) : 0;
DisposeAll(frames);
Require(size == (64, 96) && psnr > 60, Invariant($"{size}, PSNR {psnr:0.#} dB"));
return "transposed 64×96";
});
yield return Check("proc.straighten", "Straighten turns the view with no border and decodes larger by its cover zoom", async context =>
{
var source = Synthetic(3, o => o with { Width = 480, Height = 320 });
var project = Plain with { Camera = new CameraSettings { Straighten = 10 } };
var frames = await RenderDecodedAsync(context, Input(source, project), Preset("png-sequence", 96, 64)).ConfigureAwait(false);
var orientation = FrameOrientation.Of(project.Camera, 480, 320);
using var full = source.Sequence.Render(1);
var view = new GeometrySettings { OutputWidth = 96, OutputHeight = 64, Warp = orientation.ViewToFrame };
using var expected = GeometryStage.Apply(full, view);
// At full size (no minifying kernel), every pixel of the view is covered by the frame.
using var coverage = GeometryStage.Apply(full, view with { OutputWidth = 480, OutputHeight = 320, Border = BorderMode.Transparent });
var alpha = coverage.Plane(3).ToArray().Min();
var psnr = Psnr(expected, frames[1]);
DisposeAll(frames);
var edge = (int)double.Ceiling(96 * orientation.CoverZoom);
Require(psnr > 28 && alpha >= 1 - 1e-6 && source.LargestRenderRequest == edge,
Invariant($"PSNR {psnr:0.#} dB, coverage {alpha:0.######}, decoded at {source.LargestRenderRequest} px (expected {edge})"));
return Invariant($"PSNR {psnr:0.#} dB, zoom {orientation.CoverZoom:0.###}, decode {edge} px");
});
yield return Check("proc.portrait", "A 9:16 aspect turns a fixed-size preset to portrait (proportions win)", async context =>
{
var source = Synthetic(3);
var project = Plain with { Camera = new CameraSettings { Aspect = Manual("9:16") } };
var frames = await RenderDecodedAsync(context, Input(source, project), Preset("png-sequence", 96, 64)).ConfigureAwait(false);
using var reference = source.Sequence.Render(1);
var crop = AspectRatio.FitCrop(RectD.FromSize(96, 64), 9.0 / 16);
using var expected = GeometryStage.Apply(reference, new GeometrySettings { Crop = crop, OutputWidth = 54, OutputHeight = 96 });
var size = (frames[1].Width, frames[1].Height);
var psnr = size == (54, 96) ? Psnr(expected, frames[1]) : 0;
DisposeAll(frames);
Require(size == (54, 96) && psnr > 60, Invariant($"{size}, PSNR {psnr:0.#} dB"));
return "96×64 box → 54×96";
});
}
}