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,6 +1,12 @@
|
||||
using System.IO;
|
||||
using Chronos.App.Editor;
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Core.Render.Diagnostics;
|
||||
using Chronos.Core.Video;
|
||||
using Chronos.Core.Video.Managed;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Editor;
|
||||
@@ -71,6 +77,11 @@ public sealed class PreviewRendererTests
|
||||
using var last = await renderer.RenderAsync(new PreviewRequest(EditorFixture.Sunset.Count - 1, new ProjectSettings(), 96, PreviewFraming.Source, true),
|
||||
null, CancellationToken.None);
|
||||
Assert.Empty(last!.Vectors);
|
||||
|
||||
// The flow sees the frames as the render's does, before the look (owner review 1, phase 4): the same vectors with Vivid.
|
||||
var vivid = new ProjectSettings { Look = new LookSettings { Filter = "vivid" } };
|
||||
using var looked = await renderer.RenderAsync(new PreviewRequest(10, vivid, 96, PreviewFraming.Source, Vectors: true), null, CancellationToken.None);
|
||||
Assert.SequenceEqual(frame.Vectors, looked!.Vectors);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -183,6 +194,133 @@ public sealed class PreviewRendererTests
|
||||
Assert.True(waveform.Density.Any(d => d > 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OutputFramingFollowsChosenPortraitProportions()
|
||||
{
|
||||
// The chosen proportions win (owner review 1, R5): the square preset's box takes a 9:16 picture.
|
||||
var (renderer, _) = Create();
|
||||
var project = new ProjectSettings();
|
||||
project = project with
|
||||
{
|
||||
Export = project.Export with { Preset = project.Export.Preset.WithManual("square-1440") },
|
||||
Camera = project.Camera with { Aspect = project.Camera.Aspect.WithManual("9:16") },
|
||||
};
|
||||
using var output = await renderer.RenderAsync(new PreviewRequest(0, project, 80, PreviewFraming.Output), null, CancellationToken.None);
|
||||
Assert.Equal(45, output!.Corrected.Width, "810 × 1440 at the preview's long edge");
|
||||
Assert.Equal(80, output.Corrected.Height);
|
||||
|
||||
using var source = await renderer.RenderAsync(new PreviewRequest(0, project, 96, PreviewFraming.Source), null, CancellationToken.None);
|
||||
Assert.Equal(96, source!.Corrected.Width, "the whole frame");
|
||||
Assert.Approximately(9.0 / 16 * 64 / 96, source.LockRatio, 1e-12, "the box's ratio in normalised units");
|
||||
Assert.Approximately(1, source.EditCrop.Height, 1e-9, "the largest 9:16 box of the 3:2 frame");
|
||||
Assert.Approximately(source.LockRatio, source.EditCrop.Width, 1e-9);
|
||||
Assert.Approximately(source.EditCrop.Width, source.Crop.Width, 0.02, "the output's footprint is the box");
|
||||
Assert.Approximately(source.EditCrop.X, source.Crop.X, 0.02);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SourceFramingShowsTheTurnedViewFrame()
|
||||
{
|
||||
var (renderer, _) = Create();
|
||||
var plain = new ProjectSettings();
|
||||
var turned = plain with { Camera = plain.Camera with { Rotate = 90 } };
|
||||
using var frame = await renderer.RenderAsync(new PreviewRequest(5, plain, 96, PreviewFraming.Source), null, CancellationToken.None);
|
||||
using var view = await renderer.RenderAsync(new PreviewRequest(5, turned, 96, PreviewFraming.Source), null, CancellationToken.None);
|
||||
Assert.Equal((96, 64), (frame!.Corrected.Width, frame.Corrected.Height));
|
||||
Assert.Equal((64, 96), (view!.Corrected.Width, view.Corrected.Height), "a quarter turn swaps the size");
|
||||
Assert.Equal((64, 96), (view.Original.Width, view.Original.Height));
|
||||
Assert.Equal((64, 96), view.ViewSize);
|
||||
Assert.Equal((96, 64), frame.ViewSize);
|
||||
|
||||
// Turned a quarter clockwise, exactly: the view's (x, y) is the frame's (y, H − 1 − x).
|
||||
for (var c = 0; c < 3; c++)
|
||||
{
|
||||
var a = frame.Original.Plane(c);
|
||||
var b = view.Original.Plane(c);
|
||||
for (var y = 0; y < 96; y += 7)
|
||||
{
|
||||
for (var x = 0; x < 64; x += 5) Assert.Approximately(a[(63 - x) * 96 + y], b[y * 64 + x], 1e-6, $"channel {c} at ({x}, {y})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheMaskIsTheEditableCropOfTheViewFrame()
|
||||
{
|
||||
var (renderer, _) = Create();
|
||||
var project = new ProjectSettings();
|
||||
project = project with
|
||||
{
|
||||
Camera = project.Camera with
|
||||
{
|
||||
Aspect = project.Camera.Aspect.WithManual("1:1"),
|
||||
Crop = [0.1, 0.05, 0.6, 0.8],
|
||||
OffsetX = 0.5,
|
||||
Rotate = 270,
|
||||
Straighten = 4,
|
||||
},
|
||||
};
|
||||
using var frame = await renderer.RenderAsync(new PreviewRequest(2, project, 96, PreviewFraming.Source), null, CancellationToken.None);
|
||||
var geometry = RenderGeometry.Create(project.Camera, ExportResolver.Resolve(project.Export), EditorFixture.Sunset.Options.Width, EditorFixture.Sunset.Options.Height);
|
||||
Assert.Equal(geometry.EditableCrop, frame!.EditCrop, "the box the render fits, the same on every frame");
|
||||
Assert.Equal(geometry.LockRatio, frame.LockRatio);
|
||||
Assert.Approximately(frame.EditCrop.Width / frame.EditCrop.Height * frame.Corrected.Width / frame.Corrected.Height, 1, 0.03, "square on the picture");
|
||||
Assert.Approximately(frame.EditCrop.X, frame.Crop.X, 0.02, "without stabilisation or pose, the output's footprint is the box");
|
||||
Assert.Approximately(frame.EditCrop.Width, frame.Crop.Width, 0.02);
|
||||
Assert.Approximately(frame.EditCrop.Height, frame.Crop.Height, 0.02);
|
||||
Assert.Equal((64, 96), (frame.Corrected.Width, frame.Corrected.Height));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALookChangesOnlyTheCorrectedPicture()
|
||||
{
|
||||
var (renderer, _) = Create();
|
||||
var plain = Deflickered() with { Exposure = new ProjectSettings().Exposure with { HighlightKnee = null } };
|
||||
var look = new LookSettings { Filter = "sepia", Strength = 0.6 };
|
||||
foreach (var framing in new[] { PreviewFraming.Output, PreviewFraming.Source })
|
||||
{
|
||||
using var before = await renderer.RenderAsync(new PreviewRequest(4, plain, 64, framing), null, CancellationToken.None);
|
||||
using var after = await renderer.RenderAsync(new PreviewRequest(4, plain with { Look = look }, 64, framing), null, CancellationToken.None);
|
||||
Assert.True(before!.Original.Data.SequenceEqual(after!.Original.Data), $"{framing}: the original side has no look");
|
||||
Assert.False(before.Corrected.Data.SequenceEqual(after.Corrected.Data), $"{framing}: the corrected side has it");
|
||||
FrameFinish.Apply(before.Corrected, look, null);
|
||||
Assert.True(before.Corrected.Data.SequenceEqual(after.Corrected.Data), $"{framing}: the render's finish");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OutputFramingMatchesTheRenderTurnedStraightenedAndWithALook()
|
||||
{
|
||||
var project = new ProjectSettings();
|
||||
project = project with
|
||||
{
|
||||
Exposure = project.Exposure with { HighlightKnee = null },
|
||||
Export = project.Export with { Preset = project.Export.Preset.WithManual("png-sequence") },
|
||||
Camera = project.Camera with { Rotate = 90, Straighten = 3 },
|
||||
Look = new LookSettings { Filter = "sepia", Strength = 0.6 },
|
||||
};
|
||||
var (renderer, _) = Create();
|
||||
using var preview = await renderer.RenderAsync(new PreviewRequest(0, project, 96, PreviewFraming.Output), null, CancellationToken.None);
|
||||
Assert.Equal((64, 96), (preview!.Corrected.Width, preview.Corrected.Height), "the turned frame at the source's size");
|
||||
|
||||
var capture = new CapturingEncoder();
|
||||
var pixels = new SyntheticFrameSource(EditorFixture.Sunset);
|
||||
var folder = Path.Combine(Path.GetTempPath(), "chronos-preview-" + Guid.NewGuid().ToString("N"));
|
||||
try
|
||||
{
|
||||
var input = new RenderInput { Source = pixels, Frames = pixels.Metadata(), Project = project };
|
||||
await new RenderPipeline([capture, new ManagedEncoderProvider()]).RenderAsync(input, new RenderTarget(ExportResolver.Resolve(project.Export), folder));
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(folder)) Directory.Delete(folder, recursive: true);
|
||||
}
|
||||
var rendered = capture.Frames[0];
|
||||
Assert.Equal((preview.Corrected.Width, preview.Corrected.Height), (rendered.Width, rendered.Height));
|
||||
Assert.Greater(Psnr(rendered, preview.Corrected), 40, "the preview is the render's frame");
|
||||
foreach (var frame in capture.Frames) frame.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>A sunset project as the advisor leaves it: deflicker, holy grail, white balance and stabilisation on.</summary>
|
||||
private static ProjectSettings Sunset()
|
||||
{
|
||||
@@ -207,6 +345,49 @@ public sealed class PreviewRendererTests
|
||||
return Math.Log2(sum / n);
|
||||
}
|
||||
|
||||
/// <summary>Peak signal-to-noise ratio of the 8-bit sRGB encodings.</summary>
|
||||
private static double Psnr(ImageBuffer expected, ImageBuffer actual)
|
||||
{
|
||||
var a = PixelConvert.ToInterleaved8(expected, 3);
|
||||
var b = PixelConvert.ToInterleaved8(actual, 3);
|
||||
double sum = 0;
|
||||
for (var i = 0; i < a.Length; i++) sum += (a[i] - b[i]) * (a[i] - b[i]);
|
||||
return sum == 0 ? double.PositiveInfinity : 10 * Math.Log10(255.0 * 255 / (sum / a.Length));
|
||||
}
|
||||
|
||||
/// <summary>A PNG-sequence encoder that keeps a copy of every frame instead of writing it.</summary>
|
||||
private sealed class CapturingEncoder : IVideoEncoderProvider
|
||||
{
|
||||
private static readonly EncoderCapability Capability = new(VideoCodec.PngSequence, "Capture", false, 8192, 8192, true);
|
||||
|
||||
public string Name => "capture";
|
||||
|
||||
public IReadOnlyList<EncoderCapability> Capabilities { get; } = [Capability];
|
||||
|
||||
public List<ImageBuffer> Frames { get; } = [];
|
||||
|
||||
public bool CanEncode(EncodeSettings settings) => settings.Codec == VideoCodec.PngSequence;
|
||||
|
||||
public IVideoEncoderSession Open(EncodeSettings settings) => new Session(this);
|
||||
|
||||
private sealed class Session(CapturingEncoder owner) : IVideoEncoderSession
|
||||
{
|
||||
public string EncoderName => Capability.Name;
|
||||
|
||||
public bool IsHardware => false;
|
||||
|
||||
public void WriteFrame(ImageBuffer frame, long duration90k) => owner.Frames.Add(frame.Clone());
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Standard deviation of the frame-to-frame differences (flicker, not the slow ramp).</summary>
|
||||
private static double Spread(List<double> values)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user