Files
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
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 and the system SQLite. 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; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

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>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

123 lines
4.9 KiB
C#
Raw Permalink 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;
namespace Chronos.Core.Tests.Motion;
/// <summary>Deterministic synthetic textures (periodic, band-limited) and exact sub-pixel shifts by Fourier phase ramp.</summary>
internal static class SyntheticImages
{
/// <summary>Gaussian-filtered white noise: spectral envelope exp(−2π²σ²|f|²), mean 0.5, standard deviation 0.15.</summary>
public static double[] Noise(int size, double sigma, int seed) =>
Synthesize(size, seed, f => double.Exp(-2 * double.Pi * double.Pi * sigma * sigma * f * f));
/// <summary>Natural-image-like texture: amplitude ∝ 1/f^1.4 with a soft high-frequency roll-off.</summary>
public static double[] Natural(int size, int seed) =>
Synthesize(size, seed, f => f == 0 ? 0 : double.Pow(f * size, -1.4) * double.Exp(-f * f / (2 * 0.2 * 0.2)));
/// <summary>Periodic shift with sub-pixel accuracy: result(x, y) = image(x − dx, y − dy).</summary>
public static double[] Shift(double[] image, int size, double dx, double dy)
{
var re = (double[])image.Clone();
var im = new double[re.Length];
Fourier.Forward2D(re, im, size, size);
for (var v = 0; v < size; v++)
{
for (var u = 0; u < size; u++)
{
var (s, c) = double.SinCos(-2 * double.Pi * (Signed(u, size) * dx + Signed(v, size) * dy) / size);
var i = v * size + u;
(re[i], im[i]) = (re[i] * c - im[i] * s, re[i] * s + im[i] * c);
}
}
Fourier.Inverse2D(re, im, size, size);
return re;
}
/// <summary>Copies a rectangle of a square periodic image into a float plane.</summary>
public static float[] Crop(double[] image, int size, int x0, int y0, int width, int height)
{
var plane = new float[width * height];
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++) plane[y * width + x] = (float)image[((y0 + y) % size) * size + (x0 + x) % size];
}
return plane;
}
/// <summary>Single-channel buffer from a plane.</summary>
public static ImageBuffer ToBuffer(float[] plane, int width, int height)
{
var buffer = new ImageBuffer(width, height, 1, clear: false);
plane.AsSpan().CopyTo(buffer.Plane(0));
return buffer;
}
/// <summary>RGB buffer whose channels are scaled copies of a plane (distinct but correlated colours).</summary>
public static ImageBuffer ToRgb(float[] plane, int width, int height)
{
var buffer = new ImageBuffer(width, height, 3, clear: false);
for (var c = 0; c < 3; c++)
{
var dst = buffer.Plane(c);
var gain = 0.6f + 0.2f * c;
for (var i = 0; i < plane.Length; i++) dst[i] = plane[i] * gain;
}
return buffer;
}
/// <summary>Peak signal-to-noise ratio in dB for unit peak over the window [x0, x1)×[y0, y1).</summary>
public static double Psnr(ReadOnlySpan<float> a, ReadOnlySpan<float> b, int width, int x0, int y0, int x1, int y1)
{
double sum = 0;
var n = 0;
for (var y = y0; y < y1; y++)
{
for (var x = x0; x < x1; x++)
{
var d = a[y * width + x] - (double)b[y * width + x];
sum += d * d;
n++;
}
}
var mse = sum / n;
return mse == 0 ? double.PositiveInfinity : 10 * double.Log10(1 / mse);
}
private static double[] Synthesize(int size, int seed, Func<double, double> envelope)
{
var random = new Random(seed);
var re = new double[size * size];
var im = new double[size * size];
for (var v = 0; v < size; v++)
{
for (var u = 0; u < size; u++)
{
// Nyquist bins stay empty so the phase-ramp shift is exact for a real image.
if (u == size / 2 || v == size / 2) continue;
double fx = Signed(u, size) / (double)size, fy = Signed(v, size) / (double)size;
var a = envelope(double.Sqrt(fx * fx + fy * fy));
re[v * size + u] = a * Gaussian(random);
im[v * size + u] = a * Gaussian(random);
}
}
re[0] = im[0] = 0;
Fourier.Inverse2D(re, im, size, size);
double mean = 0, sq = 0;
foreach (var x in re) mean += x;
mean /= re.Length;
foreach (var x in re) sq += (x - mean) * (x - mean);
var scale = 0.15 / double.Sqrt(sq / re.Length);
for (var i = 0; i < re.Length; i++) re[i] = 0.5 + (re[i] - mean) * scale;
return re;
}
private static double Gaussian(Random random)
{
var u1 = 1.0 - random.NextDouble();
var u2 = random.NextDouble();
return double.Sqrt(-2 * double.Log(u1)) * double.Cos(2 * double.Pi * u2);
}
private static int Signed(int index, int length) => index <= length / 2 ? index : index - length;
}