Files
Chronos/tests/Titano.Core.Windows.Tests/Wic/OrientationMapTests.cs
T
Claude 3cbf72610e feat(windows): add WIC decoder provider and codec inventory
WicDecoderProvider decodes through a pull chain (decoder, Fant scaler to
MaxLongEdge, format converter) read in bounded row bands. Integer sources are
requested as 64bppRGBA and linearised with the exact sRGB EOTF (Linear16);
float/fixed sources as 128bppRGBAFloat (scRGB, already linear). The Exif
orientation (photo policy, then raw IFD queries) is applied while
de-interleaving instead of through IWICBitmapFlipRotator, which Microsoft
documents as quadratic over scanline decoders.

CodecInventory enumerates installed decoders (CreateComponentEnumerator),
probes HEVC/AV1 decoders with MFTEnumEx and identifies the Raw Image
Extension by package family, since it shares the in-box RAW codec's CLSID.
It maps every ImageFileFormat to its decoder, native flag and the Store
extensions (product ids, ms-windows-store links) that would unlock it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 09:46:19 +00:00

68 lines
2.2 KiB
C#

using Titano.Core.Windows.Wic;
using Titano.Testing;
namespace Titano.Core.Windows.Tests.Wic;
public sealed class OrientationMapTests
{
[Theory]
[Case(1)]
[Case(2)]
[Case(3)]
[Case(4)]
[Case(5)]
[Case(6)]
[Case(7)]
[Case(8)]
public void MatchesTheExifDefinition(int orientation)
{
const int width = 5, height = 3;
var map = OrientationMap.Create(orientation, width, height);
var swapped = OrientationMap.SwapsAxes(orientation);
Assert.Equal(swapped ? height : width, map.Width);
Assert.Equal(swapped ? width : height, map.Height);
var seen = new HashSet<int>();
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
var (dx, dy) = Reference(orientation, x, y, width, height);
Assert.Equal((dy * map.Width) + dx, map.IndexOf(x, y), $"orientation {orientation}, pixel ({x},{y})");
seen.Add(map.IndexOf(x, y));
}
}
Assert.Equal(width * height, seen.Count);
}
[Test]
public void UnknownValuesActAsIdentity() => Assert.Equal(OrientationMap.Create(1, 4, 2), OrientationMap.Create(0, 4, 2));
[Theory]
[Case(4000u, 3000u, 1920, 1920u, 1440u)]
[Case(400u, 100u, 100, 100u, 25u)]
[Case(3000u, 4000u, 1000, 750u, 1000u)]
[Case(640u, 480u, 0, 640u, 480u)]
[Case(640u, 480u, 2000, 640u, 480u)]
[Case(2u, 1000u, 10, 1u, 10u)]
public void TargetSizeFitsTheLongEdge(uint width, uint height, int maxLongEdge, uint expectedWidth, uint expectedHeight)
{
var (w, h) = WicDecoderProvider.TargetSize(width, height, maxLongEdge);
Assert.Equal(expectedWidth, w);
Assert.Equal(expectedHeight, h);
}
/// <summary>Displayed position of stored pixel (x, y), straight from the Exif 2.3 orientation table.</summary>
private static (int X, int Y) Reference(int orientation, int x, int y, int w, int h) => orientation switch
{
2 => (w - 1 - x, y),
3 => (w - 1 - x, h - 1 - y),
4 => (x, h - 1 - y),
5 => (y, x),
6 => (h - 1 - y, x),
7 => (h - 1 - y, w - 1 - x),
8 => (y, w - 1 - x),
_ => (x, y),
};
}