Files
Chronos/tests/Chronos.Core.Tests/Codecs/LinearDngWriterTests.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

125 lines
5.8 KiB
C#

using Chronos.Core.Codecs.Dng;
using Chronos.Core.Codecs.Tiff;
using Chronos.Core.Imaging;
using Chronos.Core.Metadata.Tiff;
using Chronos.Testing;
namespace Chronos.Core.Tests.Codecs;
public sealed class LinearDngWriterTests
{
private static ImageBuffer Scene(int w, int h)
{
var image = new ImageBuffer(w, h);
for (var y = 0; y < h; y++)
{
for (var x = 0; x < w; x++)
{
image[0, x, y] = x / (float)(w - 1);
image[1, x, y] = y / (float)(h - 1) * 0.6f;
image[2, x, y] = (x * y % 97) / 96f;
}
}
image[0, 0, 0] = 1.7f; // highlight above white: clipped
return image;
}
[Theory]
[Case(DngCompression.LosslessJpeg)]
[Case(DngCompression.Uncompressed)]
public void PixelsRoundTripThroughTheTiffReader(DngCompression compression)
{
using var image = Scene(300, 70);
var dng = LinearDngWriter.Write(image, new LinearDngOptions { Compression = compression, TileSize = 128 });
var reader = TiffReader.Open(new MemoryStream(dng))!;
var raster = TiffImageReader.ReadRaster(reader, reader.ReadChain()[0]);
Assert.Empty(raster.Warnings);
Assert.Equal(34892, raster.Photometric);
Assert.SequenceEqual(PixelConvert.ToInterleaved16(image, 3, TransferFunction.Linear), raster.Samples!);
using var back = TiffImageReader.Decode(dng);
Assert.Approximately(1.0, back[0, 0, 0], 1e-6);
for (var i = 1; i < image.Data.Length; i += 37)
{
Assert.Approximately(Math.Clamp(image.Data[i], 0, 1), back.Data[i], 1.0 / 65535);
}
}
[Test]
public void TagsDescribeLinearRec709()
{
using var image = Scene(40, 30);
var dng = LinearDngWriter.Write(image);
var r = TiffReader.Open(new MemoryStream(dng))!;
Assert.True(r.LittleEndian);
var ifd = r.ReadChain()[0];
Assert.SequenceEqual(new uint[] { 1, 4, 0, 0 }, r.GetUInts(ifd, TiffTags.DngVersion)!);
Assert.Equal(0u, r.GetUInt(ifd, TiffTags.NewSubfileType));
Assert.Equal(34892u, r.GetUInt(ifd, TiffTags.PhotometricInterpretation));
Assert.Equal(3u, r.GetUInt(ifd, TiffTags.SamplesPerPixel));
Assert.SequenceEqual(new uint[] { 16, 16, 16 }, r.GetUInts(ifd, TiffTags.BitsPerSample)!);
Assert.Equal(7u, r.GetUInt(ifd, TiffTags.Compression));
Assert.Equal("Chronos", r.GetString(ifd, TiffTags.UniqueCameraModel));
Assert.Equal(21u, r.GetUInt(ifd, TiffTags.CalibrationIlluminant1));
Assert.SequenceEqual(new[] { 1.0, 1.0, 1.0 }, r.GetDoubles(ifd, TiffTags.AsShotNeutral)!);
Assert.Equal(0.0, r.GetDouble(ifd, TiffTags.BaselineExposure));
Assert.SequenceEqual(new uint[] { 65535, 65535, 65535 }, r.GetUInts(ifd, TiffTags.WhiteLevel)!);
Assert.True(ifd.Has(TiffTags.TileWidth) && ifd.Has(TiffTags.TileOffsets) && ifd.Has(TiffTags.TileByteCounts));
// ColorMatrix1 maps XYZ to camera space: D65 white must land on the camera neutral (1, 1, 1),
// and its product with sRGB → XYZ(D65) must be the identity (camera space = linear sRGB).
var cm = r.GetDoubles(ifd, TiffTags.ColorMatrix1)!;
Assert.Equal(9, cm.Length);
double[] d65 = [0.95047, 1.0, 1.08883];
double[] srgbToXyz = [0.4124564, 0.3575761, 0.1804375, 0.2126729, 0.7151522, 0.0721750, 0.0193339, 0.1191920, 0.9503041];
for (var row = 0; row < 3; row++)
{
Assert.Approximately(1.0, cm[row * 3] * d65[0] + cm[row * 3 + 1] * d65[1] + cm[row * 3 + 2] * d65[2], 2e-3);
for (var col = 0; col < 3; col++)
{
var p = 0.0;
for (var k = 0; k < 3; k++) p += cm[row * 3 + k] * srgbToXyz[k * 3 + col];
Assert.Approximately(row == col ? 1 : 0, p, 2e-4);
}
}
// ForwardMatrix1 maps the white-balanced neutral to D50 (the DNG SDK's xy 0.3457, 0.3585).
var fm = r.GetDoubles(ifd, TiffTags.ForwardMatrix1)!;
double[] d50 = [0.3457 / 0.3585, 1.0, (1 - 0.3457 - 0.3585) / 0.3585];
for (var row = 0; row < 3; row++) Assert.Approximately(d50[row], fm[row * 3] + fm[row * 3 + 1] + fm[row * 3 + 2], 3e-4);
}
[Test]
public void GrayInputExifAndNonSeekableOutput()
{
using var gray = new ImageBuffer(33, 20, 1);
for (var i = 0; i < gray.PlaneLength; i++) gray.Plane(0)[i] = i / (float)gray.PlaneLength;
using var sink = new MemoryStream();
LinearDngWriter.Write(new ForwardOnlyStream(sink), gray, new LinearDngOptions { Exif = TiffTests.ExifBlock() });
var dng = sink.ToArray();
TiffTests.AssertExif(dng);
using var back = TiffImageReader.Decode(dng);
Assert.Equal(3, back.Channels);
Assert.Approximately(gray[0, 20, 10], back[2, 20, 10], 1.0 / 65535);
}
/// <summary>A write-only, non-seekable stream (pipes, network) to exercise the buffering path.</summary>
private sealed class ForwardOnlyStream(Stream inner) : Stream
{
public override bool CanRead => false;
public override bool CanSeek => false;
public override bool CanWrite => true;
public override long Length => throw new NotSupportedException();
public override long Position
{
get => throw new NotSupportedException();
set => throw new NotSupportedException();
}
public override void Write(byte[] buffer, int offset, int count) => inner.Write(buffer, offset, count);
public override void Flush() => inner.Flush();
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
public override void SetLength(long value) => throw new NotSupportedException();
}
}