feat(color): implement the built-in colour looks and their self-test check
The seven looks (mono, sepia, warm, cool, vivid, muted, fade) are now real: a linear-light 3x3 matrix built from Rec.709 luminance (saturation mixed as (1 - k)L + kI, tint gains normalised to luminance 1), a contrast power about mid grey 0.18 and a lift, blended by strength, never clamped so the knee that follows compresses any overshoot. The kernel is vectorised with Vector<float> and runs the last pixels through the same kernel, padded, so a pixel's result does not depend on its position; large frames split across cores like the exposure processor. A double-precision scalar reference backs the tests. The self-test gains proc.look (mono renders grey at the picture's luminance; an unknown look is ignored with Export.Render.LookIgnored). New tests cover the closed form per look, mono luminance, the strength midpoint, identity byte-equality, look-then-knee order, the render capture against FrameFinish, a median stack with mono and PNG determinism. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e4364c4f25
commit
429dbcc3d8
4 files changed
+537
-6
No files matched your search
@@ -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]));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user