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

198 lines
6.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 System.Text;
using Chronos.Testing;
namespace Chronos.Core.Tests.Video;
/// <summary>Minimal GIF89a decoder used to verify <c>GifEncoder</c> output (composition with disposal 0–3).</summary>
internal sealed class GifTestDecoder
{
public sealed record Frame(byte[] Canvas, int DelayCs, int Left, int Top, int Width, int Height, int Disposal, bool Transparent, bool LocalTable);
public int Width { get; private set; }
public int Height { get; private set; }
public bool GlobalTable { get; private set; }
public int? LoopCount { get; private set; }
public List<Frame> Frames { get; } = [];
public static GifTestDecoder Decode(byte[] data)
{
var gif = new GifTestDecoder();
Assert.Equal("GIF89a", Encoding.ASCII.GetString(data, 0, 6));
gif.Width = data[6] | data[7] << 8;
gif.Height = data[8] | data[9] << 8;
var pos = 13;
byte[]? global = null;
if ((data[10] & 0x80) != 0)
{
gif.GlobalTable = true;
var size = 3 << ((data[10] & 7) + 1);
global = data.AsSpan(pos, size).ToArray();
pos += size;
}
var canvas = new byte[gif.Width * gif.Height * 4];
int delay = 0, disposal = 0, transparentIndex = -1;
while (true)
{
var block = data[pos++];
if (block == 0x3B) break;
if (block == 0x21)
{
var label = data[pos++];
if (label == 0xF9)
{
Assert.Equal((byte)4, data[pos]);
disposal = (data[pos + 1] >> 2) & 7;
transparentIndex = (data[pos + 1] & 1) != 0 ? data[pos + 4] : -1;
delay = data[pos + 2] | data[pos + 3] << 8;
pos += 6;
}
else if (label == 0xFF && Encoding.ASCII.GetString(data, pos + 1, 11) == "NETSCAPE2.0")
{
gif.LoopCount = data[pos + 14] | data[pos + 15] << 8;
pos += 12;
pos = SkipSubBlocks(data, pos);
}
else
{
pos = SkipSubBlocks(data, pos);
}
continue;
}
Assert.Equal((byte)0x2C, block);
var left = data[pos] | data[pos + 1] << 8;
var top = data[pos + 2] | data[pos + 3] << 8;
var w = data[pos + 4] | data[pos + 5] << 8;
var h = data[pos + 6] | data[pos + 7] << 8;
var packed = data[pos + 8];
pos += 9;
var table = global;
var local = (packed & 0x80) != 0;
if (local)
{
var size = 3 << ((packed & 7) + 1);
table = data.AsSpan(pos, size).ToArray();
pos += size;
}
Assert.False((packed & 0x40) != 0, "interlaced frames are not produced");
Assert.True(left + w <= gif.Width && top + h <= gif.Height, "frame inside the logical screen");
var minCode = data[pos++];
using var lzw = new MemoryStream();
while (data[pos] != 0)
{
lzw.Write(data, pos + 1, data[pos]);
pos += data[pos] + 1;
}
pos++;
var indices = DecodeLzw(lzw.ToArray(), minCode, w * h);
var saved = disposal == 3 ? (byte[])canvas.Clone() : null;
for (var y = 0; y < h; y++)
{
for (var x = 0; x < w; x++)
{
var index = indices[y * w + x];
if (index == transparentIndex) continue;
var o = ((top + y) * gif.Width + left + x) * 4;
canvas[o] = table![index * 3];
canvas[o + 1] = table[index * 3 + 1];
canvas[o + 2] = table[index * 3 + 2];
canvas[o + 3] = 255;
}
}
gif.Frames.Add(new Frame((byte[])canvas.Clone(), delay, left, top, w, h, disposal, transparentIndex >= 0, local));
if (disposal == 2)
{
for (var y = 0; y < h; y++) canvas.AsSpan(((top + y) * gif.Width + left) * 4, w * 4).Clear();
}
else if (disposal == 3)
{
canvas = saved!;
}
delay = 0;
disposal = 0;
transparentIndex = -1;
}
return gif;
}
private static int SkipSubBlocks(byte[] data, int pos)
{
while (data[pos] != 0) pos += data[pos] + 1;
return pos + 1;
}
private static byte[] DecodeLzw(byte[] data, int minCode, int pixels)
{
var output = new List<byte>(pixels);
var prefix = new short[4096];
var suffix = new byte[4096];
var stack = new byte[4097];
var clear = 1 << minCode;
var end = clear + 1;
var codeSize = minCode + 1;
var next = end + 1;
var old = -1;
long bits = 0;
var count = 0;
var pos = 0;
while (true)
{
while (count < codeSize && pos < data.Length)
{
bits |= (long)data[pos++] << count;
count += 8;
}
Assert.True(count >= codeSize, "LZW data ended before the end code");
var code = (int)(bits & ((1 << codeSize) - 1));
bits >>= codeSize;
count -= codeSize;
if (code == clear)
{
codeSize = minCode + 1;
next = end + 1;
old = -1;
continue;
}
if (code == end) break;
if (old == -1)
{
Assert.True(code < clear, "first code after clear is a literal");
output.Add((byte)code);
old = code;
continue;
}
Assert.True(code <= next, $"LZW code {code} beyond the table ({next})");
var depth = 0;
var c = code;
if (code == next)
{
stack[depth++] = First(old, prefix, suffix, clear);
c = old;
}
while (c >= clear)
{
stack[depth++] = suffix[c];
c = prefix[c];
}
stack[depth++] = (byte)c;
var firstByte = (byte)c;
for (var i = depth - 1; i >= 0; i--) output.Add(stack[i]);
if (next < 4096)
{
prefix[next] = (short)old;
suffix[next] = firstByte;
next++;
if (next == 1 << codeSize && codeSize < 12) codeSize++;
}
old = code;
}
Assert.Equal(pixels, output.Count);
return [.. output];
}
private static byte First(int code, short[] prefix, byte[] suffix, int clear)
{
while (code >= clear) code = prefix[code];
return (byte)code;
}
}