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>
184 lines
8.3 KiB
C#
184 lines
8.3 KiB
C#
using Chronos.Core.Codecs.Raw;
|
||
using Chronos.Core.Imaging;
|
||
using Chronos.Testing;
|
||
using static Chronos.Core.Tests.Raw.NativeRawWriters;
|
||
|
||
namespace Chronos.Core.Tests.Raw;
|
||
|
||
/// <summary>Native RAW decoders on synthetic files written in each container's layout: the decoded image must match the
|
||
/// scene the sensor data was generated from (camera matrix, as-shot white balance, black/white levels, crop).</summary>
|
||
public sealed class NativeRawTests(TestContext context)
|
||
{
|
||
private const int W = 96, H = 64;
|
||
|
||
private RawDecodeResult Decode(byte[] file, string name, RawDecodeOptions? options = null)
|
||
{
|
||
var result = RawDecoder.Decode(new MemoryStream(file), name, options);
|
||
context.Log($"{name}: {result.Info} warnings: {string.Join("; ", result.Warnings)}");
|
||
return result;
|
||
}
|
||
|
||
private static void AssertScene(ImageBuffer scene, ImageBuffer image, double minimum, TestContext context)
|
||
{
|
||
Assert.Equal(scene.Width, image.Width);
|
||
Assert.Equal(scene.Height, image.Height);
|
||
var psnr = SyntheticRaw.Psnr(scene, image, 4);
|
||
context.Log($"PSNR {psnr:F1} dB");
|
||
Assert.GreaterOrEqual(psnr, minimum);
|
||
}
|
||
|
||
[Test]
|
||
public void Cr2SlicedLosslessJpegWithMaskedBlack()
|
||
{
|
||
using var scene = SyntheticRaw.Smooth(W, H);
|
||
// 24 masked columns left and 4 rows on top; Canon's CFA is RGGB at the raster origin.
|
||
var active = new RawRect(24, 4, 24 + W, 4 + H);
|
||
var sensor = Sensor(scene, "Canon EOS 5D Mark III", CfaPattern.Bayer("RGGB"), 128, 72, active.Left, active.Top, 2048, 16383);
|
||
using var result = Decode(Cr2(sensor, active), "IMG_0001.CR2");
|
||
Assert.Equal("managed-cr2", result.Info.Decoder);
|
||
Assert.Equal("RGGB", result.Info.Layout);
|
||
AssertScene(scene, result.Image, 38, context);
|
||
}
|
||
|
||
[Theory]
|
||
[Case(NefEncoding.Lossless, 14)]
|
||
[Case(NefEncoding.Lossless, 12)]
|
||
[Case(NefEncoding.Unpacked, 12)]
|
||
[Case(NefEncoding.Packed, 12)]
|
||
public void NefEncodings(NefEncoding encoding, int bits)
|
||
{
|
||
using var scene = SyntheticRaw.Smooth(W, H);
|
||
var sensor = Sensor(scene, "Nikon D850", CfaPattern.Bayer("RGGB"), W, H, 0, 0, 600 >> (14 - bits), (1 << bits) - 1);
|
||
using var result = Decode(Nef(sensor, bits, encoding), "DSC_0001.NEF");
|
||
Assert.Equal("managed-nef", result.Info.Decoder);
|
||
AssertScene(scene, result.Image, 38, context);
|
||
}
|
||
|
||
[Theory]
|
||
[Case(NefEncoding.LossyType1, 12, 0)]
|
||
[Case(NefEncoding.LossyType2, 14, 0)]
|
||
[Case(NefEncoding.LossyType2, 14, 40)]
|
||
public void NefLossyCurves(NefEncoding encoding, int bits, int split)
|
||
{
|
||
// A square-law curve: dense codes in the shadows, coarse in the highlights.
|
||
var size = encoding == NefEncoding.LossyType1 ? 683 : 1 << bits;
|
||
var curve = Enumerable.Range(0, size).Select(i => (ushort)double.Round(((1 << bits) - 1) * (i / (double)(size - 1)) * (i / (double)(size - 1)))).ToArray();
|
||
var white = encoding == NefEncoding.LossyType1 ? curve[^1] : InterpolatedCurve(curve, bits).Max();
|
||
// After the split row the tree has no unshifted codes for 9–12-bit differences: keep that scene gentle.
|
||
using var scene = split > 0 ? Gentle() : SyntheticRaw.Smooth(W, H);
|
||
var sensor = Sensor(scene, "Nikon D850", CfaPattern.Bayer("RGGB"), W, H, 0, 0, 600 >> (14 - bits), white);
|
||
using var result = Decode(Nef(sensor, bits, encoding, curve: curve, split: split), "DSC_0002.NEF");
|
||
AssertScene(scene, result.Image, 36, context);
|
||
}
|
||
|
||
[Theory]
|
||
[Case(true)]
|
||
[Case(false)]
|
||
public void ArwCompressedAndUncompressed(bool compressed)
|
||
{
|
||
ushort[] knots = [8000, 10400, 12900, 14100];
|
||
var curve = ToneCurve(knots);
|
||
double white = compressed ? curve[0x7FF << 1] : 16383;
|
||
using var scene = SyntheticRaw.Smooth(W, H);
|
||
var sensor = Sensor(scene, "Sony ILCE-7M3", CfaPattern.Bayer("RGGB"), W, H, 0, 0, 512, white);
|
||
using var result = Decode(Arw(sensor, knots, compressed), "DSC00001.ARW");
|
||
Assert.Equal("managed-arw", result.Info.Decoder);
|
||
Assert.Contains(result.Warnings, w => w.Contains("daylight"));
|
||
AssertScene(scene, result.Image, compressed ? 36 : 38, context);
|
||
}
|
||
|
||
[Theory]
|
||
[Case(true)]
|
||
[Case(false)]
|
||
public void PefHuffmanAndUncompressed(bool compressed)
|
||
{
|
||
using var scene = SyntheticRaw.Smooth(W, H);
|
||
var sensor = Sensor(scene, "Pentax K-1", CfaPattern.Bayer("BGGR"), W, H, 0, 0, 512, 16383);
|
||
using var result = Decode(Pef(sensor, 14, compressed), "IMGP0001.PEF");
|
||
Assert.Equal("managed-pef", result.Info.Decoder);
|
||
Assert.Equal("BGGR", result.Info.Layout);
|
||
AssertScene(scene, result.Image, 38, context);
|
||
}
|
||
|
||
[Theory]
|
||
[Case(true)]
|
||
[Case(false)]
|
||
public void RafXTransAndBayerLayouts(bool xtrans)
|
||
{
|
||
using var scene = SyntheticRaw.Smooth(W, H);
|
||
var rasterCfa = xtrans ? DemosaicTests.XTrans : CfaPattern.Bayer("GRBG");
|
||
// Crop starts at an odd offset so the pattern must be re-anchored.
|
||
var crop = new RawRect(5, 3, 5 + W, 3 + H);
|
||
var sensor = Sensor(scene, "Fujifilm X-T2", rasterCfa, W + 8, H + 6, crop.Left, crop.Top, 1024, 16383);
|
||
using var result = Decode(Raf(sensor, Expand(rasterCfa), crop, orientation: 1), "DSCF0001.RAF");
|
||
Assert.Equal("managed-raf", result.Info.Decoder);
|
||
Assert.Equal("X-T2", result.Info.Model);
|
||
AssertScene(scene, result.Image, xtrans ? 34 : 38, context);
|
||
using var binned = Decode(Raf(sensor, Expand(rasterCfa), crop), "DSCF0001.RAF", new RawDecodeOptions { MaxLongEdge = 1 });
|
||
Assert.Equal(W / (xtrans ? 3 : 2), binned.Image.Width);
|
||
}
|
||
|
||
[Test]
|
||
public void OrientationComesFromTheContainer()
|
||
{
|
||
using var scene = SyntheticRaw.Smooth(W, H);
|
||
var sensor = Sensor(scene, "Nikon D850", CfaPattern.Bayer("RGGB"), W, H, 0, 0, 600, 16383);
|
||
using var result = Decode(Nef(sensor, 14, NefEncoding.Lossless, orientation: 8), "DSC_0003.NEF");
|
||
Assert.Equal(H, result.Image.Width);
|
||
Assert.Equal(W, result.Image.Height);
|
||
Assert.Equal(H, result.Info.Width);
|
||
}
|
||
|
||
[Test]
|
||
public void UnknownBodyIsUnsupported()
|
||
{
|
||
using var scene = SyntheticRaw.Smooth(W, H);
|
||
var active = new RawRect(24, 4, 24 + W, 4 + H);
|
||
var sensor = Sensor(scene, "Canon EOS 5D Mark III", CfaPattern.Bayer("RGGB"), 128, 72, active.Left, active.Top, 2048, 16383);
|
||
var probe = RawDecoder.Probe(new MemoryStream(Cr2(sensor, active, model: "Canon EOS R99")), "x.cr2");
|
||
Assert.False(probe.IsSupported);
|
||
Assert.Contains("no colour matrix", probe.Reason);
|
||
Assert.Throws<InvalidDataException>(() => RawDecoder.Decode(new MemoryStream(Cr2(sensor, active, model: "Canon EOS R99")), "x.cr2"));
|
||
}
|
||
|
||
[Test]
|
||
public void CameraNamesNormalise()
|
||
{
|
||
Assert.Equal("Nikon D850", NativeRaw.CameraName("NIKON CORPORATION", "NIKON D850"));
|
||
Assert.Equal("Canon EOS 5D Mark III", NativeRaw.CameraName("Canon", "Canon EOS 5D Mark III"));
|
||
Assert.Equal("Sony ILCE-7M3", NativeRaw.CameraName("SONY", "ILCE-7M3"));
|
||
Assert.Equal("Pentax K-1", NativeRaw.CameraName("RICOH IMAGING COMPANY, LTD.", "PENTAX K-1"));
|
||
Assert.Equal("Fujifilm X-T2", NativeRaw.CameraName("FUJIFILM", "X-T2"));
|
||
// Every tabulated matrix maps D65 to a positive camera neutral with green the strongest channel.
|
||
foreach (var name in CameraMatrices.Names)
|
||
{
|
||
var m = CameraMatrices.Find(name)!.Value;
|
||
var n = m * Chronos.Core.Mathematics.Chromaticity.D65.ToXyz();
|
||
Assert.True(n.X > 0 && n.Z > 0 && n.Y > n.X && n.Y > n.Z, name);
|
||
}
|
||
}
|
||
|
||
private static ImageBuffer Gentle()
|
||
{
|
||
var scene = new ImageBuffer(W, H);
|
||
for (var y = 0; y < H; y++)
|
||
{
|
||
for (var x = 0; x < W; x++)
|
||
{
|
||
scene[0, x, y] = 0.3f + 0.03f * x / W;
|
||
scene[1, x, y] = 0.32f + 0.02f * y / H;
|
||
scene[2, x, y] = 0.25f + 0.01f * (x + y) / (W + H);
|
||
}
|
||
}
|
||
return scene;
|
||
}
|
||
|
||
/// <summary>The pattern written into the RAF layout record, expanded to 6×6.</summary>
|
||
private static CfaPattern Expand(CfaPattern cfa)
|
||
{
|
||
var colors = new byte[36];
|
||
for (var i = 0; i < 36; i++) colors[i] = (byte)cfa.ColorAt(i % 6, i / 6);
|
||
return new CfaPattern(6, 6, colors);
|
||
}
|
||
}
|