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

95 lines
3.7 KiB
C#

using Chronos.Core.Codecs.Jpeg;
using Chronos.Core.Imaging;
using Chronos.Testing;
using static Chronos.Core.Tests.Codecs.CodecTestData;
namespace Chronos.Core.Tests.Codecs;
/// <summary>DCT-domain scaling (1/2, 1/4, 1/8) and the linear-light decode path.</summary>
public sealed class JpegScalingTests(TestContext context)
{
private const int W = 256, H = 192;
[Theory]
[Case(0, 256, 192)]
[Case(200, 256, 192)]
[Case(128, 128, 96)]
[Case(100, 128, 96)]
[Case(64, 64, 48)]
[Case(33, 64, 48)]
[Case(32, 32, 24)]
[Case(1, 32, 24)]
public void MaxLongEdgePicksSmallestSufficientScale(int maxLongEdge, int width, int height)
{
var jpeg = JpegEncoder.Encode(SmoothImage(W, H), W, H, 3);
var image = JpegDecoder.Decode(jpeg, new JpegDecodeOptions { MaxLongEdge = maxLongEdge });
Assert.Equal(width, image.Width);
Assert.Equal(height, image.Height);
Assert.Equal(W, image.Info.Width);
}
[Theory]
[Case(2, 38.0)]
[Case(4, 34.0)]
[Case(8, 30.0)]
public void ScaledDecodeApproximatesAreaAverage(int factor, double minPsnr)
{
var jpeg = JpegEncoder.Encode(SmoothImage(W, H), W, H, 3, new JpegEncodeOptions { Quality = 92 });
var full = JpegDecoder.Decode(jpeg).Pixels8!;
var scaled = JpegDecoder.Decode(jpeg, new JpegDecodeOptions { MaxLongEdge = W / factor });
Assert.Equal(W / factor, scaled.Width);
int sw = W / factor, sh = H / factor;
var expected = new byte[sw * sh * 3];
for (var y = 0; y < sh; y++)
{
for (var x = 0; x < sw; x++)
{
for (var c = 0; c < 3; c++)
{
var sum = 0;
for (var dy = 0; dy < factor; dy++)
{
for (var dx = 0; dx < factor; dx++) sum += full[((y * factor + dy) * W + x * factor + dx) * 3 + c];
}
expected[(y * sw + x) * 3 + c] = (byte)((sum + factor * factor / 2) / (factor * factor));
}
}
}
var psnr = Psnr(scaled.Pixels8, expected);
context.Log($"1/{factor}: {psnr:F1} dB vs area average");
Assert.Greater(psnr, minPsnr);
}
[Test]
public void ScaledOddSizeKeepsEdges()
{
var image = JpegDecoder.Decode(Fixture("jpeg/b420.jpg"), new JpegDecodeOptions { MaxLongEdge = 31 });
Assert.Equal(31, image.Width);
Assert.Equal(23, image.Height);
var reference = ReadPnm(Fixture("src.ppm"));
// Bottom-right pixel of the scaled image must still resemble the source corner (no padding garbage).
var pixels = image.Pixels8!;
var last = pixels.AsSpan(pixels.Length - 3);
var src = reference.Samples.AsSpan(reference.Samples.Length - 3);
for (var c = 0; c < 3; c++) Assert.InRange(last[c], src[c] - 70, src[c] + 70);
}
[Test]
public void LinearDecodeMatchesLookupOfEightBitDecode()
{
var data = Fixture("jpeg/b422.jpg");
var bytes = JpegDecoder.Decode(data).Pixels8!;
using var linear = JpegDecoder.DecodeToLinear(data);
Assert.Equal(3, linear.Channels);
for (var i = 0; i < 61 * 45; i += 17)
{
for (var c = 0; c < 3; c++) Assert.Equal(ColorSpace.Linear8(bytes[i * 3 + c]), linear.Plane(c)[i]);
}
using var gray = JpegDecoder.DecodeToLinear(Fixture("jpeg/gray.jpg"));
Assert.Equal(1, gray.Channels);
using var expanded = JpegDecoder.DecodeToLinear(Fixture("jpeg/gray.jpg"), expandGray: true);
Assert.Equal(3, expanded.Channels);
Assert.SequenceEqual(gray.Plane(0).ToArray(), expanded.Plane(2).ToArray());
}
}