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>
164 lines
6.5 KiB
C#
164 lines
6.5 KiB
C#
using Chronos.Core.Imaging;
|
||
using Chronos.Core.Windows.Wic;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.Core.Windows.Tests.Wic;
|
||
|
||
[WindowsOnly]
|
||
public sealed class WicDecoderProviderTests(TestContext context)
|
||
{
|
||
private static readonly Lazy<WicDecoderProvider> SharedProvider = new(() => new WicDecoderProvider());
|
||
private static readonly double MidGrey = ColorSpace.SrgbToLinear(128 / 255.0);
|
||
|
||
private static WicDecoderProvider Provider => SharedProvider.Value;
|
||
|
||
[Test]
|
||
public void BuiltInFormatsAreNative()
|
||
{
|
||
Assert.Equal("wic", Provider.Name);
|
||
foreach (var format in new[] { ImageFileFormat.Jpeg, ImageFileFormat.Png, ImageFileFormat.Tiff, ImageFileFormat.Bmp, ImageFileFormat.Gif })
|
||
Assert.Equal<DecodeTier?>(DecodeTier.Native, Provider.TierFor(format), format.ToString());
|
||
Assert.Null(Provider.TierFor(ImageFileFormat.Unknown));
|
||
}
|
||
|
||
[Test]
|
||
public void PngMidGreyDecodesToLinearLight()
|
||
{
|
||
var path = Path.Combine(context.CreateTempDirectory(), "grey.png");
|
||
WicTestImages.WriteRgbPng(path, 64, 48, (_, _) => (128, 128, 128));
|
||
|
||
using var image = Assert.NotNull(Provider.Decode(new DecodeRequest(path)));
|
||
Assert.Equal(DecodeTier.Native, image.Tier);
|
||
Assert.Equal("wic", image.Decoder);
|
||
Assert.Equal(64, image.Pixels.Width);
|
||
Assert.Equal(48, image.Pixels.Height);
|
||
Assert.Equal(3, image.Pixels.Channels);
|
||
Assert.Equal(64, image.SourceWidth);
|
||
Assert.Equal(48, image.SourceHeight);
|
||
AssertUniform(image.Pixels, MidGrey, 1e-3);
|
||
}
|
||
|
||
[Test]
|
||
public void PngChannelsKeepTheirOrder()
|
||
{
|
||
var path = Path.Combine(context.CreateTempDirectory(), "red-blue.png");
|
||
WicTestImages.WriteRgbPng(path, 32, 16, (x, _) => x < 16 ? ((byte)255, (byte)0, (byte)0) : ((byte)0, (byte)0, (byte)255));
|
||
|
||
using var image = Assert.NotNull(Provider.Decode(new DecodeRequest(path)));
|
||
var p = image.Pixels;
|
||
Assert.Approximately(1.0, p[0, 4, 8], 1e-4);
|
||
Assert.Approximately(0.0, p[1, 4, 8], 1e-4);
|
||
Assert.Approximately(0.0, p[2, 4, 8], 1e-4);
|
||
Assert.Approximately(0.0, p[0, 28, 8], 1e-4);
|
||
Assert.Approximately(1.0, p[2, 28, 8], 1e-4);
|
||
}
|
||
|
||
[Test]
|
||
public void SixteenBitPngKeepsPrecision()
|
||
{
|
||
var path = Path.Combine(context.CreateTempDirectory(), "grey16.png");
|
||
WicTestImages.WriteGray16Png(path, 8, 8, 0x8000);
|
||
|
||
using var image = Assert.NotNull(Provider.Decode(new DecodeRequest(path)));
|
||
AssertUniform(image.Pixels, ColorSpace.Linear16(0x8000), 1e-4);
|
||
}
|
||
|
||
[Test]
|
||
public void JpegMidGreyDecodesToLinearLight()
|
||
{
|
||
var path = Path.Combine(context.CreateTempDirectory(), "grey.jpg");
|
||
WicTestImages.WriteGrayJpeg(path, 64, 48, (_, _) => 128);
|
||
|
||
using var image = Assert.NotNull(Provider.Decode(new DecodeRequest(path)));
|
||
Assert.Equal(64, image.Pixels.Width);
|
||
Assert.Equal(48, image.Pixels.Height);
|
||
AssertUniform(image.Pixels, MidGrey, 1e-3);
|
||
}
|
||
|
||
[Test]
|
||
public void ScalingToMaxLongEdgeKeepsAspect()
|
||
{
|
||
var path = Path.Combine(context.CreateTempDirectory(), "wide.png");
|
||
WicTestImages.WriteRgbPng(path, 400, 100, (_, _) => (128, 128, 128));
|
||
|
||
using var image = Assert.NotNull(Provider.Decode(new DecodeRequest(path, MaxLongEdge: 100)));
|
||
Assert.Equal(100, image.Pixels.Width);
|
||
Assert.Equal(25, image.Pixels.Height);
|
||
Assert.Equal(400, image.SourceWidth);
|
||
Assert.Equal(100, image.SourceHeight);
|
||
AssertUniform(image.Pixels, MidGrey, 2e-3);
|
||
}
|
||
|
||
[Test]
|
||
public void Orientation6RotatesClockwise()
|
||
{
|
||
// Stored 64×32 with a white 16×16 block at the top-left; displayed 32×64 with the block at the top-right.
|
||
var path = Path.Combine(context.CreateTempDirectory(), "rotated.jpg");
|
||
WicTestImages.WriteGrayJpeg(path, 64, 32, (x, y) => x < 16 && y < 16 ? (byte)255 : (byte)0, exifOrientation: 6);
|
||
|
||
using var image = Assert.NotNull(Provider.Decode(new DecodeRequest(path)));
|
||
Assert.Equal(32, image.Pixels.Width);
|
||
Assert.Equal(64, image.Pixels.Height);
|
||
Assert.Equal(32, image.SourceWidth);
|
||
Assert.Equal(64, image.SourceHeight);
|
||
Assert.Greater(image.Pixels[1, 24, 8], 0.8);
|
||
Assert.Less(image.Pixels[1, 8, 8], 0.05);
|
||
Assert.Less(image.Pixels[1, 24, 40], 0.05);
|
||
}
|
||
|
||
[Test]
|
||
public void OrientationIsIgnoredWhenNotRequested()
|
||
{
|
||
var path = Path.Combine(context.CreateTempDirectory(), "rotated.jpg");
|
||
WicTestImages.WriteGrayJpeg(path, 64, 32, (x, y) => x < 16 && y < 16 ? (byte)255 : (byte)0, exifOrientation: 6);
|
||
|
||
using var image = Assert.NotNull(Provider.Decode(new DecodeRequest(path, ApplyOrientation: false)));
|
||
Assert.Equal(64, image.Pixels.Width);
|
||
Assert.Equal(32, image.Pixels.Height);
|
||
Assert.Greater(image.Pixels[1, 8, 8], 0.8);
|
||
}
|
||
|
||
[Test]
|
||
public void DecodesAFileAnotherProcessHasOpenForWriting()
|
||
{
|
||
var path = Path.Combine(context.CreateTempDirectory(), "busy.png");
|
||
WicTestImages.WriteRgbPng(path, 16, 16, (_, _) => (128, 128, 128));
|
||
using var writer = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||
|
||
using var image = Assert.NotNull(Provider.Decode(new DecodeRequest(path)));
|
||
Assert.Equal(16, image.Pixels.Width);
|
||
}
|
||
|
||
[Test]
|
||
public void UnrecognisedContentReturnsNull()
|
||
{
|
||
var path = Path.Combine(context.CreateTempDirectory(), "noise.png");
|
||
File.WriteAllBytes(path, Enumerable.Range(0, 4096).Select(i => (byte)(i * 37)).ToArray());
|
||
Assert.Null(Provider.Decode(new DecodeRequest(path)));
|
||
}
|
||
|
||
[Test]
|
||
public void MissingFileThrowsFileNotFound()
|
||
{
|
||
var path = Path.Combine(context.CreateTempDirectory(), "missing.png");
|
||
Assert.Throws<FileNotFoundException>(() => Provider.Decode(new DecodeRequest(path)));
|
||
}
|
||
|
||
[Test]
|
||
public void ForcedPreviewIsLeftToOtherProviders() =>
|
||
Assert.Null(Provider.Decode(new DecodeRequest(Path.Combine(context.CreateTempDirectory(), "any.jpg"), ForcePreview: true)));
|
||
|
||
private static void AssertUniform(ImageBuffer image, double expected, double tolerance)
|
||
{
|
||
for (var c = 0; c < image.Channels; c++)
|
||
{
|
||
var plane = image.Plane(c);
|
||
for (var i = 0; i < plane.Length; i++)
|
||
{
|
||
if (Math.Abs(plane[i] - expected) > tolerance)
|
||
Assert.Fail($"channel {c} pixel {i}: expected {expected:F5} ± {tolerance}, actual {plane[i]:F5}");
|
||
}
|
||
}
|
||
}
|
||
}
|