chore: bootstrap repository foundation

Solution layout, build rules with zero-package guard, in-house test
framework, localization runtime, brand mark rasteriser with ICO/PNG
generation, Core contracts (imaging, video, domain model, TIFF reader),
Titano.Tools (make-icon, i18n, xaml-lint, package-guard) and docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 08:59:40 +00:00
1 parent def3fadb6e
commit 83a54fb57b
109 files changed
+7523

No files matched your search

+112
View File
@@ -0,0 +1,112 @@
namespace Titano.Core.Imaging;
/// <summary>How a frame's pixels were obtained (BRIEF §8.2). Logged per frame.</summary>
public enum DecodeTier
{
/// <summary>Full-resolution decode of the main image (in-house or WIC).</summary>
Native = 1,
/// <summary>Largest embedded JPEG preview; output resolution is capped to its size.</summary>
EmbeddedPreview = 2,
/// <summary>No decoder could produce pixels; the frame is excluded from renders.</summary>
Unavailable = 3,
}
public enum DecodePurpose
{
Thumbnail,
Analysis,
Proxy,
Render,
}
/// <summary>A request to decode one file.</summary>
/// <param name="Path">Absolute path of the source file.</param>
/// <param name="MaxLongEdge">Maximum long edge of the result in pixels; 0 = native size.</param>
/// <param name="Purpose">Lets providers trade quality for speed (e.g. bilinear demosaic for thumbnails).</param>
/// <param name="ApplyOrientation">Rotate/flip according to the Exif orientation.</param>
/// <param name="AllowPreview">Accept the embedded-preview tier when native decode is impossible.</param>
/// <param name="ForcePreview">Use the embedded preview even when native decode is possible (fast paths).</param>
public sealed record DecodeRequest(
string Path,
int MaxLongEdge = 0,
DecodePurpose Purpose = DecodePurpose.Render,
bool ApplyOrientation = true,
bool AllowPreview = true,
bool ForcePreview = false);
/// <summary>Decoded pixels plus how they were produced. Dispose to return the buffer to the pool.</summary>
public sealed class DecodedImage(ImageBuffer pixels, DecodeTier tier, string decoder, int sourceWidth, int sourceHeight) : IDisposable
{
public ImageBuffer Pixels { get; } = pixels;
public DecodeTier Tier { get; } = tier;
/// <summary>Short provider/decoder name for logs ("wic", "managed-jpeg", "managed-dng").</summary>
public string Decoder { get; } = decoder;
/// <summary>Dimensions of the full-resolution source (before scaling), oriented.</summary>
public int SourceWidth { get; } = sourceWidth;
public int SourceHeight { get; } = sourceHeight;
public void Dispose() => Pixels.Dispose();
}
/// <summary>A platform image decoder (WIC on Windows, managed codecs everywhere).</summary>
public interface IImageDecoderProvider
{
/// <summary>Short name for logs and the Settings › Formats table.</summary>
string Name { get; }
/// <summary>The best tier this provider can deliver for the format on this machine, or null.</summary>
DecodeTier? TierFor(ImageFileFormat format);
bool CanDecode(ImageFormatInfo format) => TierFor(format.Format) is not null;
/// <summary>Decodes or returns null when this provider cannot handle the specific file.</summary>
DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default);
}
/// <summary>Tries providers in priority order and applies the tier rules of BRIEF §8.2.</summary>
public sealed class ImageDecoder(IReadOnlyList<IImageDecoderProvider> providers)
{
public IReadOnlyList<IImageDecoderProvider> Providers { get; } = providers;
/// <summary>Best tier available for <paramref name="format"/> across all providers.</summary>
public DecodeTier TierFor(ImageFileFormat format)
{
var best = DecodeTier.Unavailable;
foreach (var p in Providers)
{
if (p.TierFor(format) is { } t && t < best) best = t;
}
return best;
}
/// <summary>Decodes with the first provider that succeeds; null means <see cref="DecodeTier.Unavailable"/>.</summary>
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default)
{
var format = ImageFormatInfo.FromPath(request.Path);
List<Exception>? errors = null;
foreach (var provider in Providers.OrderBy(p => p.TierFor(format.Format) ?? DecodeTier.Unavailable))
{
if (provider.TierFor(format.Format) is null) continue;
cancellationToken.ThrowIfCancellationRequested();
try
{
var result = provider.Decode(request, cancellationToken);
if (result is not null) return result;
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex) when (ex is IOException or InvalidDataException or NotSupportedException or FormatException or InvalidOperationException or System.Runtime.InteropServices.COMException)
{
(errors ??= []).Add(ex);
}
}
return null;
}
}
+74
View File
@@ -0,0 +1,74 @@
using System.Buffers;
namespace Titano.Core.Imaging;
/// <summary>
/// Planar 32-bit float image in linear light (Rec.709/sRGB primaries). Channel 0..2 = R, G, B
/// (or a single luminance channel). Nominal range 0..1; highlights may exceed 1.
/// Storage is rented from <see cref="ArrayPool{T}"/> and returned on <see cref="Dispose"/>.
/// </summary>
public sealed class ImageBuffer : IDisposable
{
private float[]? _data;
public ImageBuffer(int width, int height, int channels = 3, bool clear = true)
{
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(width);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(height);
if (channels is not (1 or 3 or 4)) throw new ArgumentOutOfRangeException(nameof(channels), "1, 3 or 4 channels");
Width = width;
Height = height;
Channels = channels;
var length = checked(width * height * channels);
_data = ArrayPool<float>.Shared.Rent(length);
if (clear) Array.Clear(_data, 0, length);
}
public int Width { get; }
public int Height { get; }
public int Channels { get; }
public int PlaneLength => Width * Height;
/// <summary>All planes, channel-major: plane c starts at <c>c * Width * Height</c>.</summary>
public Span<float> Data => Storage.AsSpan(0, PlaneLength * Channels);
public Span<float> Plane(int channel)
{
if ((uint)channel >= (uint)Channels) throw new ArgumentOutOfRangeException(nameof(channel));
return Storage.AsSpan(channel * PlaneLength, PlaneLength);
}
public Span<float> Row(int channel, int y) => Plane(channel).Slice(y * Width, Width);
public float this[int channel, int x, int y]
{
get => Storage[channel * PlaneLength + y * Width + x];
set => Storage[channel * PlaneLength + y * Width + x] = value;
}
/// <summary>Underlying array (may be longer than the image). Exposed for SIMD kernels.</summary>
public float[] Storage => _data ?? throw new ObjectDisposedException(nameof(ImageBuffer));
public ImageBuffer Clone()
{
var copy = new ImageBuffer(Width, Height, Channels, clear: false);
Data.CopyTo(copy.Data);
return copy;
}
public void CopyTo(ImageBuffer target)
{
if (target.Width != Width || target.Height != Height || target.Channels != Channels)
throw new ArgumentException("Dimensions differ", nameof(target));
Data.CopyTo(target.Data);
}
/// <summary>Approximate managed memory held by the buffer, in bytes.</summary>
public long ByteSize => (long)PlaneLength * Channels * sizeof(float);
public void Dispose()
{
var data = Interlocked.Exchange(ref _data, null);
if (data is not null) ArrayPool<float>.Shared.Return(data);
}
}
+109
View File
@@ -0,0 +1,109 @@
namespace Titano.Core.Imaging;
/// <summary>Container/file formats recognised by signature and extension (BRIEF §8.1).</summary>
public enum ImageFileFormat
{
Unknown = 0,
Jpeg,
Png,
Tiff,
Dng,
Cr2,
Cr3,
Crw,
Nef,
Nrw,
Arw,
Srf,
Sr2,
Raf,
Orf,
Rw2,
Raw,
Pef,
Srw,
ThreeFr,
Fff,
Iiq,
Rwl,
Gpr,
Heif,
Avif,
WebP,
JpegXl,
JpegXr,
Bmp,
Gif,
}
public enum ImageFamily
{
Unknown,
Jpeg,
Png,
Tiff,
Dng,
CameraRaw,
Heif,
WebP,
Other,
}
/// <summary>Static facts about a format: family, extensions, whether it is a camera RAW.</summary>
public sealed record ImageFormatInfo(ImageFileFormat Format, ImageFamily Family, IReadOnlyList<string> Extensions)
{
public bool IsRaw => Family is ImageFamily.CameraRaw or ImageFamily.Dng;
private static readonly ImageFormatInfo[] All =
[
new(ImageFileFormat.Jpeg, ImageFamily.Jpeg, ["jpg", "jpeg", "jpe", "jfif"]),
new(ImageFileFormat.Png, ImageFamily.Png, ["png"]),
new(ImageFileFormat.Tiff, ImageFamily.Tiff, ["tif", "tiff"]),
new(ImageFileFormat.Dng, ImageFamily.Dng, ["dng"]),
new(ImageFileFormat.Cr2, ImageFamily.CameraRaw, ["cr2"]),
new(ImageFileFormat.Cr3, ImageFamily.CameraRaw, ["cr3"]),
new(ImageFileFormat.Crw, ImageFamily.CameraRaw, ["crw"]),
new(ImageFileFormat.Nef, ImageFamily.CameraRaw, ["nef"]),
new(ImageFileFormat.Nrw, ImageFamily.CameraRaw, ["nrw"]),
new(ImageFileFormat.Arw, ImageFamily.CameraRaw, ["arw"]),
new(ImageFileFormat.Srf, ImageFamily.CameraRaw, ["srf"]),
new(ImageFileFormat.Sr2, ImageFamily.CameraRaw, ["sr2"]),
new(ImageFileFormat.Raf, ImageFamily.CameraRaw, ["raf"]),
new(ImageFileFormat.Orf, ImageFamily.CameraRaw, ["orf"]),
new(ImageFileFormat.Rw2, ImageFamily.CameraRaw, ["rw2"]),
new(ImageFileFormat.Raw, ImageFamily.CameraRaw, ["raw"]),
new(ImageFileFormat.Pef, ImageFamily.CameraRaw, ["pef"]),
new(ImageFileFormat.Srw, ImageFamily.CameraRaw, ["srw"]),
new(ImageFileFormat.ThreeFr, ImageFamily.CameraRaw, ["3fr"]),
new(ImageFileFormat.Fff, ImageFamily.CameraRaw, ["fff"]),
new(ImageFileFormat.Iiq, ImageFamily.CameraRaw, ["iiq"]),
new(ImageFileFormat.Rwl, ImageFamily.CameraRaw, ["rwl"]),
new(ImageFileFormat.Gpr, ImageFamily.CameraRaw, ["gpr"]),
new(ImageFileFormat.Heif, ImageFamily.Heif, ["heic", "heif", "hif"]),
new(ImageFileFormat.Avif, ImageFamily.Heif, ["avif"]),
new(ImageFileFormat.WebP, ImageFamily.WebP, ["webp"]),
new(ImageFileFormat.JpegXl, ImageFamily.Other, ["jxl"]),
new(ImageFileFormat.JpegXr, ImageFamily.Other, ["jxr", "wdp", "hdp"]),
new(ImageFileFormat.Bmp, ImageFamily.Other, ["bmp"]),
new(ImageFileFormat.Gif, ImageFamily.Other, ["gif"]),
];
private static readonly Dictionary<string, ImageFormatInfo> ByExtension =
All.SelectMany(i => i.Extensions.Select(e => (e, i))).ToDictionary(p => p.e, p => p.i, StringComparer.OrdinalIgnoreCase);
public static IReadOnlyList<ImageFormatInfo> Known => All;
public static ImageFormatInfo Unknown { get; } = new(ImageFileFormat.Unknown, ImageFamily.Unknown, []);
public static ImageFormatInfo Of(ImageFileFormat format) => All.FirstOrDefault(i => i.Format == format) ?? Unknown;
/// <summary>Format implied by a file name's extension (signature sniffing lives in Metadata).</summary>
public static ImageFormatInfo FromPath(string path)
{
var ext = Path.GetExtension(path).TrimStart('.');
return ByExtension.TryGetValue(ext, out var info) ? info : Unknown;
}
/// <summary>True when the extension is one Titano imports as a photo.</summary>
public static bool IsSupportedExtension(string path) => FromPath(path).Format != ImageFileFormat.Unknown;
}