Files
Chronos/tests/Chronos.Core.Tests/Motion/FrameInterpolatorTests.cs
T
Alby96andClaude Opus 5.5 5f27a86406
CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
refactor!: rename Titano to Chronos and move CI and releases to Gitea
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout. The release cross-compiles the Windows programs, checks their
  icon, version and DPI manifest, packs installers and zips, publishes the
  Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only
  tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow) and
  pe-check.

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 11:34:48 +02:00

120 lines
5.7 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.Motion;
using Chronos.Testing;
namespace Chronos.Core.Tests.Motion;
public sealed class FrameInterpolatorTests
{
private const int Base = 256;
private const int Frame = 160;
private const int Margin = 16;
private readonly TestContext _context;
public FrameInterpolatorTests(TestContext context) => _context = context;
[Test]
public void EndpointsReproduceTheKeyFrames()
{
var texture = SyntheticImages.Natural(Base, seed: 13);
using var a = Shifted(texture, 0, 0);
using var b = Shifted(texture, 3, -1.5);
using var interpolator = new FrameInterpolator(FlowQuality.Balanced);
using var output = new ImageBuffer(Frame, Frame);
interpolator.Interpolate(a, b, 0, output);
Assert.True(a.Data.SequenceEqual(output.Data));
interpolator.Interpolate(a, b, 1, output);
Assert.True(b.Data.SequenceEqual(output.Data));
}
[Theory]
[Case(0.5)]
[Case(0.25)]
public void TranslationIsInterpolatedAlongTheMotion(double t)
{
const double dx = 4, dy = -2;
var texture = SyntheticImages.Natural(Base, seed: 13);
using var a = Shifted(texture, 0, 0);
using var b = Shifted(texture, dx, dy);
using var truth = Shifted(texture, t * dx, t * dy);
using var interpolator = new FrameInterpolator();
using var output = new ImageBuffer(Frame, Frame);
interpolator.Interpolate(a, b, t, output);
var psnr = SyntheticImages.Psnr(truth.Plane(1), output.Plane(1), Frame, Margin, Margin, Frame - Margin, Frame - Margin);
using var fade = new ImageBuffer(Frame, Frame);
for (var i = 0; i < fade.Data.Length; i++) fade.Data[i] = (float)((1 - t) * a.Data[i] + t * b.Data[i]);
var fadePsnr = SyntheticImages.Psnr(truth.Plane(1), fade.Plane(1), Frame, Margin, Margin, Frame - Margin, Frame - Margin);
_context.Log($"t = {t}: interpolated {psnr:F1} dB, cross-fade {fadePsnr:F1} dB");
Assert.GreaterOrEqual(psnr, 35);
Assert.Greater(psnr, fadePsnr + 10);
}
[Test]
public void OcclusionReasoningPicksTheVisibleFrame()
{
// Exact flows: the square moves 12 px right; at t = 0.5 a 6 px strip behind it is visible only in B
// and the strip ahead of it shows the square, which must be fetched along the square's motion.
var background = SyntheticImages.Natural(Base, seed: 3);
var foreground = SyntheticImages.Noise(Base, 1.2, seed: 4);
using var a = Composite(background, foreground, 50);
using var b = Composite(background, foreground, 62);
using var truth = Composite(background, foreground, 56);
using var forward = new MotionField(Frame, Frame, 1);
using var backward = new MotionField(Frame, Frame, 1);
for (var y = 50; y < 98; y++)
{
forward.U.Slice(y * Frame + 50, 48).Fill(12);
backward.U.Slice(y * Frame + 62, 48).Fill(-12);
}
using var handled = new ImageBuffer(Frame, Frame);
using var unweighted = new ImageBuffer(Frame, Frame);
FrameInterpolator.Synthesize(a, b, forward, backward, 0.5, handled);
FrameInterpolator.Synthesize(a, b, forward, backward, 0.5, unweighted, occlusionThreshold: 1e9);
// Rows through the object, columns around its trailing and leading edges.
var withWeights = SyntheticImages.Psnr(truth.Plane(1), handled.Plane(1), Frame, 36, 50, 124, 98);
var without = SyntheticImages.Psnr(truth.Plane(1), unweighted.Plane(1), Frame, 36, 50, 124, 98);
_context.Log($"exact flows, object region: occlusion-aware {withWeights:F1} dB, without sample weighting {without:F1} dB");
Assert.GreaterOrEqual(withWeights, 42);
Assert.Greater(withWeights, without + 10);
}
[Test]
public void MovingObjectIsInterpolatedWithEstimatedFlow()
{
var background = SyntheticImages.Natural(Base, seed: 3);
var foreground = SyntheticImages.Noise(Base, 1.2, seed: 4);
using var a = Composite(background, foreground, 50);
using var b = Composite(background, foreground, 62);
using var truth = Composite(background, foreground, 56);
using var interpolator = new FrameInterpolator();
using var output = new ImageBuffer(Frame, Frame);
interpolator.Interpolate(a, b, 0.5, output);
using var fade = new ImageBuffer(Frame, Frame);
for (var i = 0; i < fade.Data.Length; i++) fade.Data[i] = 0.5f * (a.Data[i] + b.Data[i]);
var psnr = SyntheticImages.Psnr(truth.Plane(1), output.Plane(1), Frame, 36, 50, 124, 98);
var fadePsnr = SyntheticImages.Psnr(truth.Plane(1), fade.Plane(1), Frame, 36, 50, 124, 98);
_context.Log($"estimated flows, object region: {psnr:F1} dB, cross-fade {fadePsnr:F1} dB");
Assert.GreaterOrEqual(psnr, 33);
Assert.Greater(psnr, fadePsnr + 5);
}
private static ImageBuffer Shifted(double[] texture, double dx, double dy)
{
var shifted = dx == 0 && dy == 0 ? texture : SyntheticImages.Shift(texture, Base, dx, dy);
return SyntheticImages.ToRgb(SyntheticImages.Crop(shifted, Base, 48, 48, Frame, Frame), Frame, Frame);
}
/// <summary>Static background with a 48×48 textured square whose left edge is at <paramref name="x0"/>; the square carries its texture along.</summary>
private static ImageBuffer Composite(double[] background, double[] foreground, int x0)
{
var plane = SyntheticImages.Crop(background, Base, 0, 0, Frame, Frame);
for (var y = 50; y < 98; y++)
{
for (var x = 0; x < 48; x++) plane[y * Frame + x0 + x] = (float)(0.3 + 0.8 * (foreground[y * Base + x] - 0.5));
}
return SyntheticImages.ToRgb(plane, Frame, Frame);
}
}