refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
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

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>
This commit was merged in pull request #6.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-10-23 12:45:18 +02:00
1 parent c99842cc86
commit f2b58522b9
1801 files changed
+11804 -10676

No files matched your search

+462
View File
@@ -0,0 +1,462 @@
using System.Globalization;
using Chronos.Core.Analysis;
using Chronos.Core.Export;
using Chronos.Core.Imaging;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Motion;
using Chronos.Core.Project;
using Chronos.Core.Render;
namespace Chronos.App.Editor;
/// <summary>What the preview shows of the frame: the output picture, or the whole source frame with the crop marked.</summary>
public enum PreviewFraming
{
/// <summary>Through the render geometry (stabilisation, virtual camera, crop): what the video shows.</summary>
Output,
/// <summary>The whole frame, exposure-corrected; <see cref="PreviewFrame.Crop"/> marks what the output keeps.</summary>
Source,
}
/// <param name="LongEdge">Long edge of the preview picture in pixels (the source's own for 1:1).</param>
/// <param name="Vectors">Also measure the motion field to the next frame.</param>
/// <param name="Waveform">Also measure the luma waveform of the corrected picture.</param>
public sealed record PreviewRequest(int Index, ProjectSettings Project, int LongEdge, PreviewFraming Framing, bool Vectors = false, bool Waveform = false);
/// <summary>A motion sample in preview pixels: origin and displacement to the next frame.</summary>
public readonly record struct VectorSample(float X, float Y, float Dx, float Dy);
/// <summary>One rendered preview: the corrected and the original picture over the same area, and the overlays.</summary>
public sealed class PreviewFrame(int index, ImageBuffer corrected, ImageBuffer original) : IDisposable
{
public int Index { get; } = index;
public ImageBuffer Corrected { get; } = corrected;
public ImageBuffer Original { get; } = original;
/// <summary>The output's part of the picture, normalised (the whole picture in <see cref="PreviewFraming.Output"/>).</summary>
public RectD Crop { get; init; } = new(0, 0, 1, 1);
/// <summary>Sky/land boundary in picture pixels; empty when the analysis found no horizon.</summary>
public IReadOnlyList<(double X, double Y)> Horizon { get; init; } = [];
public IReadOnlyList<VectorSample> Vectors { get; init; } = [];
/// <summary>Luma waveform of the corrected picture, when requested.</summary>
public LumaWaveform? Waveform { get; init; }
public void Dispose()
{
Corrected.Dispose();
Original.Dispose();
}
}
/// <summary>
/// The corrected-frame preview through the render pipeline at preview size (BRIEF §12.3). The render pipeline has no
/// single-frame entry point, so the per-frame steps of <c>RenderRun</c> are followed here: corrections from
/// <see cref="RenderPreparation"/> exactly as a render prepares them, then each frame through the render's exposure
/// stage, its single geometry warp and the highlight knee. Stacking and motion blur need neighbouring frames and are
/// left to the render.
/// <para>
/// Preparing is split so a slider never decodes the sequence again: a measuring preparation (luminance, colour means,
/// stabilisation; keyed on the settings that change what is measured) runs once, and every other change re-solves
/// from its series (<see cref="PrecomputedAnalysis"/>) and its white-balance gains. Analysis-size decodes are kept in
/// half precision within a memory budget, so region curves and segmentation re-measure from memory.
/// </para>
/// </summary>
public sealed class PreviewRenderer(SequenceContent content, ISequenceSource source)
{
/// <summary>Long edge of the frames the preparation measures (the render uses 512; the preview trades precision for speed).</summary>
public const int AnalysisLongEdge = 128;
private const int VectorLongEdge = 320;
/// <summary>Motion arrows across the picture's long edge.</summary>
private const int VectorColumns = 40;
private static readonly RenderOptions Options = new() { AnalysisLongEdge = AnalysisLongEdge };
private readonly CompactFrames _frames = new(content, source);
private readonly Lock _gate = new();
private (string Key, RenderCorrections Corrections)? _latest;
private (string Key, RenderCorrections Corrections)? _measured;
/// <summary>Frames the preparations decoded so far (tests: a re-solve decodes nothing).</summary>
public int Decodes => _frames.Decodes;
/// <summary>Corrections for <paramref name="project"/> when already prepared, else null.</summary>
public RenderCorrections? Cached(ProjectSettings project)
{
var key = Key(project);
lock (_gate) return _latest is { } latest && latest.Key == key ? latest.Corrections : null;
}
/// <summary>The most recently prepared corrections, whatever settings they were made for.</summary>
public RenderCorrections? Latest
{
get
{
lock (_gate) return _latest?.Corrections;
}
}
/// <summary>
/// Prepares the corrections for <paramref name="project"/> (or returns them when prepared already). Requests come
/// one after the other (the editor cancels the previous one); only the caches are shared between calls.
/// </summary>
public async Task<RenderCorrections> PrepareAsync(ProjectSettings project, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(project);
if (Cached(project) is { } cached) return cached;
var key = Key(project);
var measured = await MeasureAsync(project, cancellationToken).ConfigureAwait(false);
// Nothing is measured again: white balance comes from the measuring preparation, and a stabilisation it could
// not solve (its warning is kept) is not tried again.
var solveProject = project with
{
Exposure = project.Exposure with { WhiteBalanceSmoothing = project.Exposure.WhiteBalanceSmoothing.WithManual(false) },
Motion = measured.Stabilization is null ? project.Motion with { Stabilize = project.Motion.Stabilize.WithManual(false) } : project.Motion,
};
var solved = await RenderPreparation.PrepareAsync(Input(solveProject, Reuse(measured, project)), Options, null, cancellationToken).ConfigureAwait(false);
var corrections = solved with
{
// Gains depend only on the measured colour means, which the measuring preparation keyed on.
WhiteBalance = measured.WhiteBalance,
Report = solved.Report with
{
MeasuredFrames = measured.Report.MeasuredFrames + solved.Report.MeasuredFrames,
Warnings = [.. measured.Report.Warnings.Concat(solved.Report.Warnings).DistinctBy(w => w.ToString())],
},
};
lock (_gate) _latest = (key, corrections);
return corrections;
}
/// <summary>Renders one preview with <paramref name="corrections"/> (identity when null); null when the frame cannot be read.</summary>
public async Task<PreviewFrame?> RenderAsync(PreviewRequest request, RenderCorrections? corrections, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(request);
var setup = Geometry(request, corrections);
if (setup is null) return null;
var (geometry, edge) = setup.Value;
var frame = await PictureAsync(request.Index, request, corrections, geometry, edge, cancellationToken).ConfigureAwait(false);
if (frame is null) return null;
var (corrected, original, plan) = frame.Value;
try
{
var vectors = request.Vectors && request.Index + 1 < content.Count
? await VectorsAsync(request, corrections, corrected.Width, corrected.Height, cancellationToken).ConfigureAwait(false)
: [];
return new PreviewFrame(request.Index, corrected, original)
{
Crop = request.Framing == PreviewFraming.Source ? CropOf(plan, corrected.Width, corrected.Height) : new RectD(0, 0, 1, 1),
Horizon = request.Framing == PreviewFraming.Source ? HorizonOf(corrected.Width, corrected.Height) : [],
Vectors = vectors,
Waveform = request.Waveform ? LumaWaveform.Measure(corrected) : null,
};
}
catch
{
corrected.Dispose();
original.Dispose();
throw;
}
}
/// <summary>Cache key of the corrections: every setting <see cref="RenderPreparation"/> reads.</summary>
internal static string Key(ProjectSettings project) => new ProjectSettings
{
Exposure = project.Exposure,
Motion = new MotionSettings { Stabilize = project.Motion.Stabilize, StabilizeSmoothing = project.Motion.StabilizeSmoothing },
ExcludedFrames = project.ExcludedFrames,
}.ToJson();
/// <summary>Cache key of the measuring preparation: the settings that change what is measured, resolved as the preparation resolves them.</summary>
private string MeasureKey(ProjectSettings project)
{
var (luminance, whiteBalance, stabilize, smoothing) = Measured(project);
return string.Join('|', luminance, whiteBalance, stabilize, smoothing.ToString("R", CultureInfo.InvariantCulture), string.Join(',', project.ExcludedFrames));
}
/// <summary>
/// What the measuring preparation measures for <paramref name="project"/>: luminance when the deep analysis has it
/// (free) or a module needs it, colour means for white-balance smoothing, the stabilisation path.
/// </summary>
private (bool Luminance, bool WhiteBalance, bool Stabilize, double Smoothing) Measured(ProjectSettings project) => (
HasDeepAnalysis || project.Exposure.Deflicker.Resolve(false) || project.Exposure.HolyGrail.Resolve(false),
project.Exposure.WhiteBalanceSmoothing.Resolve(false),
project.Motion.Stabilize.Resolve(false),
project.Motion.StabilizeSmoothing.Resolve(new StabilizerOptions().SmoothingSigma));
/// <summary>The deep analysis describes the current frames (its luminance is reused).</summary>
private bool HasDeepAnalysis => content.Deep is { } deep && deep.FrameCount == content.Count;
private PrecomputedAnalysis? DeepLuminance => HasDeepAnalysis
? new PrecomputedAnalysis { LogLuminance = [.. content.Deep!.Frames.LogLuminance.Select(v => v ?? double.NaN)] }
: null;
/// <summary>
/// Luminance (deflicker forced on while it is wanted, so it is measured or taken from the deep analysis), colour
/// means and the stabilisation path for the project's exclusions, prepared once per <see cref="MeasureKey"/>.
/// </summary>
private async Task<RenderCorrections> MeasureAsync(ProjectSettings project, CancellationToken cancellationToken)
{
var key = MeasureKey(project);
lock (_gate)
{
if (_measured is { } measured && measured.Key == key) return measured.Corrections;
}
var (luminance, whiteBalance, stabilize, smoothing) = Measured(project);
var basis = new ProjectSettings();
var measuring = basis with
{
Exposure = basis.Exposure with
{
Deflicker = basis.Exposure.Deflicker.WithManual(luminance),
WhiteBalanceSmoothing = basis.Exposure.WhiteBalanceSmoothing.WithManual(whiteBalance),
},
Motion = basis.Motion with { Stabilize = basis.Motion.Stabilize.WithManual(stabilize), StabilizeSmoothing = basis.Motion.StabilizeSmoothing.WithManual(smoothing) },
ExcludedFrames = project.ExcludedFrames,
};
var corrections = await RenderPreparation.PrepareAsync(Input(measuring, DeepLuminance), Options, null, cancellationToken).ConfigureAwait(false);
lock (_gate) _measured = (key, corrections);
return corrections;
}
/// <summary>The measured series a re-solve reuses.</summary>
private PrecomputedAnalysis Reuse(RenderCorrections measured, ProjectSettings project) => new()
{
LogLuminance = Measured(project).Luminance ? measured.MeasuredLogLuminance : null,
Stabilization = measured.Stabilization is { } corrections
// The zoom is 1 / max(crop scale, 0.75), so its inverse is the crop scale the render zooms by.
? new StabilizationResult([], [], [], corrections, measured.Report.ShakeRms ?? 0, 1 / measured.StabilizationZoom, false)
: null,
StabilizationWidth = measured.StabilizationWidth,
StabilizationHeight = measured.StabilizationHeight,
StabilizationSmoothing = Measured(project).Smoothing,
};
private RenderInput Input(ProjectSettings project, PrecomputedAnalysis? analysis) => new()
{
Source = _frames,
Frames = SourceFrameInfo.From(content.Frames, content.Light.AdjustedTimes.Length == content.Count ? content.Light.AdjustedTimes : null),
Project = project with { ExcludedFrames = [.. project.ExcludedFrames.Union(content.NotRenderable()).Order()] },
Analysis = analysis,
};
private (RenderGeometry Geometry, int DecodeEdge)? Geometry(PreviewRequest request, RenderCorrections? corrections)
{
if ((uint)request.Index >= (uint)content.Count || content.SourceWidth <= 0 || content.SourceHeight <= 0) return null;
var export = ExportResolver.Resolve(request.Project.Export);
var full = RenderGeometry.Create(request.Project.Camera, export, content.SourceWidth, content.SourceHeight, corrections?.StabilizationZoom ?? 1,
request.LongEdge);
var (width, height) = Resampler.FitWithin(full.OutputWidth, full.OutputHeight, request.LongEdge);
var geometry = full.WithOutputSize(int.Max(1, width), int.Max(1, height));
var edge = request.Framing == PreviewFraming.Source ? request.LongEdge : geometry.WorkingLongEdge;
return (geometry, int.Max(16, edge));
}
/// <summary>Decodes, corrects and frames one source frame: (corrected, original, output→picture plan).</summary>
private async Task<(ImageBuffer, ImageBuffer, GeometryPlan?)?> PictureAsync(int index, PreviewRequest request, RenderCorrections? corrections,
RenderGeometry geometry, int edge, CancellationToken cancellationToken)
{
var decoded = await source.DecodeAsync(index, edge, DecodePurpose.Proxy, cancellationToken).ConfigureAwait(false);
if (decoded is null) return null;
var raw = Rgb(decoded);
ImageBuffer? corrected = null;
try
{
corrected = raw.Clone();
if (corrections is not null && corrections.FrameCount == content.Count) ApplyExposure(corrected, index, corrections);
var settings = geometry.For(raw.Width, raw.Height, index, corrections?.StabilizationAt(index, raw.Width, raw.Height) ?? Affine2D.Identity);
var plan = GeometryStage.Plan(raw.Width, raw.Height, settings);
if (request.Framing == PreviewFraming.Output)
{
var framed = GeometryStage.Apply(corrected, settings, cancellationToken);
corrected.Dispose();
corrected = framed;
framed = GeometryStage.Apply(raw, settings, cancellationToken);
raw.Dispose();
raw = framed;
}
if (request.Project.Exposure.HighlightKnee is > 0 and < 1 and var knee) ExposureProcessor.Apply(corrected, 0, null, knee);
return (corrected, raw, request.Framing == PreviewFraming.Output ? null : plan);
}
catch
{
corrected?.Dispose();
raw.Dispose();
throw;
}
}
/// <summary>The render's exposure stage: region curves through the resampled sky mask, else the global correction, with white-balance gains.</summary>
private static void ApplyExposure(ImageBuffer frame, int index, RenderCorrections corrections)
{
var gains = corrections.WhiteBalance?[index];
if (corrections is { Regions: { } mask, SkyEv: { } sky, LandEv: { } land })
{
ExposureProcessor.ApplyRegion(frame, mask.Resample(frame.Width, frame.Height).Sky, sky[index], land[index], gains);
return;
}
var ev = corrections.ExposureEv[index];
if (ev != 0 || (gains is { } g && g != ChannelGains.Identity)) ExposureProcessor.Apply(frame, ev, gains);
}
/// <summary>
/// Optical flow from this frame to the next, both rendered small the same way (whatever the preview's size, even
/// 1:1), sampled on a grid and scaled to the <paramref name="width"/>×<paramref name="height"/> picture.
/// </summary>
private async Task<IReadOnlyList<VectorSample>> VectorsAsync(PreviewRequest request, RenderCorrections? corrections, int width, int height,
CancellationToken cancellationToken)
{
var small = request with { LongEdge = int.Min(request.LongEdge, VectorLongEdge), Vectors = false, Waveform = false };
if (Geometry(small, corrections) is not var (geometry, edge)) return [];
var current = await PictureAsync(request.Index, small, corrections, geometry, edge, cancellationToken).ConfigureAwait(false);
if (current is not var (a, aOriginal, _)) return [];
aOriginal.Dispose();
using (a)
{
var next = await PictureAsync(request.Index + 1, small, corrections, geometry, edge, cancellationToken).ConfigureAwait(false);
if (next is not var (b, bOriginal, _)) return [];
bOriginal.Dispose();
using (b)
{
using var conformed = b.Width == a.Width && b.Height == a.Height ? null : Resampler.Resize(b, a.Width, a.Height);
using var engine = new OpticalFlowEngine(FlowQuality.Draft);
using var field = engine.Compute(a, conformed ?? b, cancellationToken);
var (sx, sy) = ((double)width / a.Width, (double)height / a.Height);
var spacing = double.Max(8, int.Max(width, height) / (double)VectorColumns);
var samples = new List<VectorSample>();
for (var y = spacing / 2; y < height; y += spacing)
{
for (var x = spacing / 2; x < width; x += spacing)
{
var (u, v) = field.Sample(x / sx, y / sy);
samples.Add(new VectorSample((float)x, (float)y, (float)(u * sx), (float)(v * sy)));
}
}
return samples;
}
}
}
/// <summary>The output's footprint on the source picture (bounding box of the warped output corners), normalised.</summary>
private static RectD CropOf(GeometryPlan? plan, int width, int height)
{
if (plan is not { } p) return new RectD(0, 0, 1, 1);
double left = double.MaxValue, top = double.MaxValue, right = double.MinValue, bottom = double.MinValue;
foreach (var (u, v) in new[] { (-0.5, -0.5), (p.OutputWidth - 0.5, -0.5), (-0.5, p.OutputHeight - 0.5), (p.OutputWidth - 0.5, p.OutputHeight - 0.5) })
{
var (x, y) = p.OutputToSource.Apply(u, v);
(left, top, right, bottom) = (double.Min(left, x + 0.5), double.Min(top, y + 0.5), double.Max(right, x + 0.5), double.Max(bottom, y + 0.5));
}
left = double.Clamp(left / width, 0, 1);
top = double.Clamp(top / height, 0, 1);
return new RectD(left, top, double.Clamp(right / width, 0, 1) - left, double.Clamp(bottom / height, 0, 1) - top);
}
/// <summary>The analysed horizon (normalised rows at evenly spaced columns) in pixels of the whole-frame picture.</summary>
private IReadOnlyList<(double X, double Y)> HorizonOf(int width, int height)
{
if (content.Deep?.Regions is not { Horizon: { Length: > 1 } rows }) return [];
var points = new (double X, double Y)[rows.Length];
for (var k = 0; k < rows.Length; k++) points[k] = ((double)k / (rows.Length - 1) * width, rows[k] * height);
return points;
}
/// <summary>Gray sources become RGB and alpha is dropped, as in the render.</summary>
private static ImageBuffer Rgb(ImageBuffer frame)
{
if (frame.Channels == 3) return frame;
using (frame)
{
if (frame.Channels == 1) return PixelConvert.GrayToRgb(frame);
var rgb = new ImageBuffer(frame.Width, frame.Height, 3, clear: false);
frame.Data[..(3 * frame.PlaneLength)].CopyTo(rgb.Data);
return rgb;
}
}
/// <summary>
/// The sequence as the preparations read it. Analysis-size decodes are kept in half precision (a quarter of a
/// 128-px frame in floats, about 65 KB) within a budget of 1/16 of the memory available to the process (64–512 MB,
/// several thousand frames), least recently decoded dropped first, so changing a setting re-measures from memory.
/// </summary>
private sealed class CompactFrames(SequenceContent content, ISequenceSource source) : IRenderFrameSource
{
private static readonly long Budget = long.Clamp(GC.GetGCMemoryInfo().TotalAvailableMemoryBytes / 16, 64L << 20, 512L << 20);
private readonly Lock _gate = new();
private readonly Dictionary<(int Index, int Edge), Stored> _cache = [];
private readonly LinkedList<(int Index, int Edge)> _order = new();
private long _bytes;
private int _decodes;
public int FrameCount => content.Count;
public int Width => content.SourceWidth;
public int Height => content.SourceHeight;
public int Decodes => Volatile.Read(ref _decodes);
public async ValueTask<ImageBuffer> GetFrameAsync(int index, int maxLongEdge, DecodePurpose purpose, CancellationToken cancellationToken)
{
Stored? hit;
lock (_gate)
{
if (_cache.TryGetValue((index, maxLongEdge), out hit))
{
_order.Remove(hit.Node);
_order.AddLast(hit.Node);
}
}
if (hit is not null) return hit.Expand();
var frame = await source.DecodeAsync(index, maxLongEdge, purpose, cancellationToken).ConfigureAwait(false)
?? throw new RenderException("Export.Render.FrameUnreadable", $"Frame {index + 1} could not be decoded.",
[(index + 1).ToString(CultureInfo.InvariantCulture), content.Frames[index].FileName]);
Interlocked.Increment(ref _decodes);
var stored = Stored.From(frame, new LinkedListNode<(int, int)>((index, maxLongEdge)));
lock (_gate)
{
if (stored.Bytes <= Budget && _cache.TryAdd((index, maxLongEdge), stored))
{
_order.AddLast(stored.Node);
_bytes += stored.Bytes;
while (_bytes > Budget && _order.First is { } oldest)
{
_order.RemoveFirst();
if (_cache.Remove(oldest.Value, out var dropped)) _bytes -= dropped.Bytes;
}
}
}
return frame;
}
private sealed class Stored(int width, int height, int channels, Half[] samples, LinkedListNode<(int, int)> node)
{
public LinkedListNode<(int, int)> Node { get; } = node;
public long Bytes => (long)samples.Length * sizeof(short);
public static Stored From(ImageBuffer frame, LinkedListNode<(int, int)> node)
{
var data = frame.Data;
var samples = new Half[data.Length];
for (var i = 0; i < data.Length; i++) samples[i] = (Half)data[i];
return new Stored(frame.Width, frame.Height, frame.Channels, samples, node);
}
public ImageBuffer Expand()
{
var frame = new ImageBuffer(width, height, channels, clear: false);
var data = frame.Data;
for (var i = 0; i < data.Length; i++) data[i] = (float)samples[i];
return frame;
}
}
}
}