feat(tools): diagnose and fixtures commands with the CC0 RAW manifest
diagnose prints per file the format, managed decode tier (and why it is not native), delivered size, camera and capture time with its source, then a per-format summary; --formats prints the tier table. fixtures downloads tests/fixtures/manifest.json into tests/fixtures/external with HTTP range resume and SHA-256 verification, skipping verified files and recording the hash of first downloads whose manifest hash is null. External fixture tests (skipped when absent) check native decoding, size and agreement with the embedded preview. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
6 files changed
+429
-21
No files matched your search
@@ -12,7 +12,9 @@ namespace Titano.Core.Imaging.Decoders;
|
|||||||
/// <param name="Tier">Best tier available for this file.</param>
|
/// <param name="Tier">Best tier available for this file.</param>
|
||||||
/// <param name="Decoder">Decoder that would produce it ("managed-cr2", "managed-preview"…), null when unavailable.</param>
|
/// <param name="Decoder">Decoder that would produce it ("managed-cr2", "managed-preview"…), null when unavailable.</param>
|
||||||
/// <param name="Reason">Why the native tier is not used (unsupported body or encoding), else null.</param>
|
/// <param name="Reason">Why the native tier is not used (unsupported body or encoding), else null.</param>
|
||||||
public sealed record FileTier(ImageFileFormat Format, DecodeTier Tier, string? Decoder, string? Reason);
|
/// <param name="Width">Full-size width that tier delivers (developed RAW, preview or image size), oriented; 0 when unknown.</param>
|
||||||
|
/// <param name="Height">Full-size height, oriented; 0 when unknown.</param>
|
||||||
|
public sealed record FileTier(ImageFileFormat Format, DecodeTier Tier, string? Decoder, string? Reason, int Width, int Height);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The managed decoder (BRIEF §8.2), available on every platform and the only one on the server: JPEG, PNG and TIFF
|
/// The managed decoder (BRIEF §8.2), available on every platform and the only one on the server: JPEG, PNG and TIFF
|
||||||
@@ -66,34 +68,29 @@ public sealed class ManagedDecoderProvider : IImageDecoderProvider
|
|||||||
using var stream = Open(path);
|
using var stream = Open(path);
|
||||||
var format = ImageSignature.Detect(stream, path);
|
var format = ImageSignature.Detect(stream, path);
|
||||||
var family = ImageFormatInfo.Of(format).Family;
|
var family = ImageFormatInfo.Of(format).Family;
|
||||||
switch (family)
|
if (family is ImageFamily.Jpeg or ImageFamily.Png or ImageFamily.Tiff)
|
||||||
{
|
{
|
||||||
case ImageFamily.Jpeg:
|
var (w, h) = MetadataReader.Read(stream, path).OrientedSize;
|
||||||
return new FileTier(format, DecodeTier.Native, "managed-jpeg", null);
|
var decoder = family switch { ImageFamily.Jpeg => "managed-jpeg", ImageFamily.Png => "managed-png", _ => "managed-tiff" };
|
||||||
case ImageFamily.Png:
|
return new FileTier(format, DecodeTier.Native, decoder, null, w, h);
|
||||||
return new FileTier(format, DecodeTier.Native, "managed-png", null);
|
|
||||||
case ImageFamily.Tiff:
|
|
||||||
return new FileTier(format, DecodeTier.Native, "managed-tiff", null);
|
|
||||||
}
|
}
|
||||||
string? reason = null;
|
if (family is not (ImageFamily.Dng or ImageFamily.CameraRaw or ImageFamily.Heif))
|
||||||
if (family is ImageFamily.Dng or ImageFamily.CameraRaw && RawDecoder.Formats.Contains(format))
|
return new FileTier(format, DecodeTier.Unavailable, null, $"no managed decoder for {format}", 0, 0);
|
||||||
|
string reason;
|
||||||
|
if (RawDecoder.Formats.Contains(format))
|
||||||
{
|
{
|
||||||
var probe = RawDecoder.Probe(stream, path);
|
var probe = RawDecoder.Probe(stream, path);
|
||||||
if (probe.IsSupported) return new FileTier(format, DecodeTier.Native, probe.Info!.Decoder, null);
|
if (probe.Info is { } info) return new FileTier(format, DecodeTier.Native, info.Decoder, null, info.Width, info.Height);
|
||||||
reason = probe.Reason;
|
reason = probe.Reason ?? "unsupported";
|
||||||
}
|
|
||||||
else if (family is ImageFamily.Dng or ImageFamily.CameraRaw or ImageFamily.Heif)
|
|
||||||
{
|
|
||||||
reason = $"no managed decoder for {format}";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new FileTier(format, DecodeTier.Unavailable, null, $"no managed decoder for {format}");
|
reason = $"no managed decoder for {format}";
|
||||||
}
|
}
|
||||||
var previews = MetadataReader.Read(stream, path).Previews;
|
var metadata = MetadataReader.Read(stream, path);
|
||||||
return previews.Count > 0
|
if (metadata.LargestPreview is not { } preview) return new FileTier(format, DecodeTier.Unavailable, null, reason + "; no embedded preview", 0, 0);
|
||||||
? new FileTier(format, DecodeTier.EmbeddedPreview, "managed-preview", reason)
|
var (pw, ph) = PixelConvert.OrientedSize(preview.Width, preview.Height, metadata.Orientation);
|
||||||
: new FileTier(format, DecodeTier.Unavailable, null, reason + "; no embedded preview");
|
return new FileTier(format, DecodeTier.EmbeddedPreview, "managed-preview", reason, pw, ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FileStream Open(string path) =>
|
private static FileStream Open(string path) =>
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using Titano.Core.Imaging;
|
||||||
|
using Titano.Core.Imaging.Decoders;
|
||||||
|
using Titano.Core.Metadata;
|
||||||
|
|
||||||
|
namespace Titano.Tools.Commands;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Per-file decode report for a folder of photos: format, the tier the managed decoders reach (the server's view — WIC
|
||||||
|
/// does not exist in this tool), dimensions, camera, capture time and its source, warnings; then a summary per format.
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class DiagnoseCommand : ICommand
|
||||||
|
{
|
||||||
|
public string Name => "diagnose";
|
||||||
|
public string Summary => "Decode tiers and metadata of the photos in a folder (--recursive, --formats)";
|
||||||
|
|
||||||
|
public Task<int> RunAsync(string[] args)
|
||||||
|
{
|
||||||
|
var a = new Args(args, "recursive", "formats");
|
||||||
|
if (a.Has("formats")) PrintFormats();
|
||||||
|
if (a.Positional.Count == 0)
|
||||||
|
{
|
||||||
|
if (a.Has("formats")) return Task.FromResult(0);
|
||||||
|
throw new ToolException("Usage: diagnose <folder> [--recursive] [--formats]");
|
||||||
|
}
|
||||||
|
var folder = Path.GetFullPath(a.Positional[0]);
|
||||||
|
if (!Directory.Exists(folder)) throw new ToolException($"Folder not found: {folder}");
|
||||||
|
var files = Directory.EnumerateFiles(folder, "*", a.Has("recursive") ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
|
||||||
|
.Where(ImageFormatInfo.IsSupportedExtension)
|
||||||
|
.Order(StringComparer.OrdinalIgnoreCase)
|
||||||
|
.ToList();
|
||||||
|
Console.WriteLine($"{files.Count} photo(s) in {folder}. Tiers are the managed (server) view; WIC is not available in Titano.Tools.");
|
||||||
|
var provider = new ManagedDecoderProvider();
|
||||||
|
var summary = new SortedDictionary<string, int[]>(StringComparer.Ordinal);
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var line = Describe(provider, folder, file, out var format, out var tier);
|
||||||
|
Console.WriteLine(line);
|
||||||
|
if (!summary.TryGetValue(format, out var counts)) summary[format] = counts = new int[3];
|
||||||
|
counts[(int)tier - 1]++;
|
||||||
|
}
|
||||||
|
if (summary.Count > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine($"{"Format",-8} {"Files",6} {"Native",7} {"Preview",8} {"None",5}");
|
||||||
|
foreach (var (format, c) in summary) Console.WriteLine($"{format,-8} {c.Sum(),6} {c[0],7} {c[1],8} {c[2],5}");
|
||||||
|
}
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Describe(ManagedDecoderProvider provider, string folder, string file, out string format, out DecodeTier tier)
|
||||||
|
{
|
||||||
|
var name = Path.GetRelativePath(folder, file);
|
||||||
|
FrameMetadata metadata;
|
||||||
|
FileTier fileTier;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
metadata = MetadataReader.Read(file);
|
||||||
|
fileTier = provider.Probe(file);
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
format = ImageFormatInfo.FromPath(file).Format.ToString();
|
||||||
|
tier = DecodeTier.Unavailable;
|
||||||
|
return $"{name}\n unreadable: {ex.Message}";
|
||||||
|
}
|
||||||
|
format = fileTier.Format.ToString();
|
||||||
|
tier = fileTier.Tier;
|
||||||
|
var (w, h) = fileTier.Width > 0 ? (fileTier.Width, fileTier.Height) : metadata.OrientedSize;
|
||||||
|
var camera = string.Join(' ', new[] { metadata.Make, metadata.Model }.Where(s => !string.IsNullOrEmpty(s)));
|
||||||
|
var captured = metadata.CapturedAt is { } t
|
||||||
|
? $"{t.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture)} ({metadata.TimestampSource})"
|
||||||
|
: "unknown";
|
||||||
|
var tierText = fileTier.Tier switch
|
||||||
|
{
|
||||||
|
DecodeTier.Native => $"native ({fileTier.Decoder})",
|
||||||
|
DecodeTier.EmbeddedPreview => "embedded preview",
|
||||||
|
_ => "unavailable",
|
||||||
|
};
|
||||||
|
var lines = new List<string> { $"{name}\n {format,-5} {tierText,-24} {$"{w}x{h}",-11} {(camera.Length > 0 ? camera : "camera unknown")}; captured {captured}" };
|
||||||
|
if (fileTier.Reason is { } reason) lines.Add($" reason: {reason}");
|
||||||
|
lines.AddRange(metadata.Warnings.Select(warning => $" warning: {warning}"));
|
||||||
|
return string.Join('\n', lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PrintFormats()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Format tiers (managed decoders):");
|
||||||
|
foreach (var row in DecoderFactory.DescribeFormats(DecoderFactory.CreateServer()))
|
||||||
|
{
|
||||||
|
var tier = row.Tier switch
|
||||||
|
{
|
||||||
|
DecodeTier.Native => "native",
|
||||||
|
DecodeTier.EmbeddedPreview => "embedded preview",
|
||||||
|
_ => "unavailable",
|
||||||
|
};
|
||||||
|
Console.WriteLine($" {row.Format.Format,-8} {string.Join(' ', row.Format.Extensions),-18} {tier}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Titano.Tools.Commands;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches the CC0 RAW samples listed in <c>tests/fixtures/manifest.json</c> into <c>tests/fixtures/external</c> (BRIEF
|
||||||
|
/// §20.2): interrupted downloads resume from their <c>.part</c> file with an HTTP range request, every file is verified
|
||||||
|
/// against its SHA-256, and verified files are skipped. An entry whose <c>sha256</c> is null gets the hash of its first
|
||||||
|
/// download recorded in <c>external/recorded-hashes.json</c> (later runs verify against it) and printed so it can be
|
||||||
|
/// copied into the manifest.
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class FixturesCommand : ICommand
|
||||||
|
{
|
||||||
|
private const string RecordedHashesFile = "recorded-hashes.json";
|
||||||
|
|
||||||
|
public string Name => "fixtures";
|
||||||
|
public string Summary => "Download and verify the CC0 RAW samples in tests/fixtures/manifest.json (--manifest, --out)";
|
||||||
|
|
||||||
|
public async Task<int> RunAsync(string[] args)
|
||||||
|
{
|
||||||
|
var a = new Args(args);
|
||||||
|
var root = Args.RepoRoot();
|
||||||
|
var manifestPath = a.Get("manifest") ?? Path.Combine(root, "tests", "fixtures", "manifest.json");
|
||||||
|
var outDir = a.Get("out") ?? Path.Combine(root, "tests", "fixtures", "external");
|
||||||
|
if (!File.Exists(manifestPath)) throw new ToolException($"Manifest not found: {manifestPath}");
|
||||||
|
var entries = ReadManifest(manifestPath);
|
||||||
|
Directory.CreateDirectory(outDir);
|
||||||
|
var recordedPath = Path.Combine(outDir, RecordedHashesFile);
|
||||||
|
var recorded = File.Exists(recordedPath)
|
||||||
|
? JsonSerializer.Deserialize<Dictionary<string, string>>(await File.ReadAllTextAsync(recordedPath)) ?? []
|
||||||
|
: [];
|
||||||
|
var newlyRecorded = new List<string>();
|
||||||
|
var failures = 0;
|
||||||
|
using var http = new HttpClient { Timeout = TimeSpan.FromMinutes(10) };
|
||||||
|
http.DefaultRequestHeaders.UserAgent.ParseAdd("Titano.Tools/1.0 (+fixtures)");
|
||||||
|
foreach (var entry in entries)
|
||||||
|
{
|
||||||
|
var target = Path.Combine(outDir, entry.Name);
|
||||||
|
var expected = entry.Sha256 ?? recorded.GetValueOrDefault(entry.Name);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (File.Exists(target))
|
||||||
|
{
|
||||||
|
var hash = await HashAsync(target);
|
||||||
|
if (expected is null || hash.Equals(expected, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
if (expected is null) Record(entry.Name, hash);
|
||||||
|
Console.WriteLine($"ok {entry.Name} (verified)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Console.WriteLine($"mismatch {entry.Name}: downloading again");
|
||||||
|
File.Delete(target);
|
||||||
|
}
|
||||||
|
var actual = await DownloadAsync(http, entry, target);
|
||||||
|
if (expected is not null && !actual.Equals(expected, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
File.Delete(target);
|
||||||
|
throw new InvalidDataException($"SHA-256 {actual} does not match {expected}");
|
||||||
|
}
|
||||||
|
if (expected is null) Record(entry.Name, actual);
|
||||||
|
Console.WriteLine($"fetched {entry.Name} ({new FileInfo(target).Length / 1e6:F1} MB)");
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is HttpRequestException or IOException or InvalidDataException or TaskCanceledException or UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
failures++;
|
||||||
|
Console.Error.WriteLine($"failed {entry.Name}: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await File.WriteAllTextAsync(recordedPath, JsonSerializer.Serialize(recorded, new JsonSerializerOptions { WriteIndented = true }));
|
||||||
|
if (newlyRecorded.Count > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Recorded SHA-256 of first downloads (copy into the manifest to pin them):");
|
||||||
|
foreach (var line in newlyRecorded) Console.WriteLine(" " + line);
|
||||||
|
}
|
||||||
|
Console.WriteLine(failures == 0 ? $"{entries.Count} fixture(s) ready in {outDir}" : $"{failures} of {entries.Count} fixture(s) failed");
|
||||||
|
return failures == 0 ? 0 : 1;
|
||||||
|
|
||||||
|
void Record(string name, string hash)
|
||||||
|
{
|
||||||
|
if (recorded.GetValueOrDefault(name) == hash) return;
|
||||||
|
recorded[name] = hash;
|
||||||
|
newlyRecorded.Add($"{name}: {hash}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed record Entry(string Name, Uri Url, string? Sha256, long? Size);
|
||||||
|
|
||||||
|
internal static List<Entry> ReadManifest(string path)
|
||||||
|
{
|
||||||
|
using var doc = JsonDocument.Parse(File.ReadAllText(path));
|
||||||
|
if (!doc.RootElement.TryGetProperty("files", out var files) || files.ValueKind != JsonValueKind.Array) throw new ToolException("Manifest has no 'files' array");
|
||||||
|
var entries = new List<Entry>();
|
||||||
|
foreach (var f in files.EnumerateArray())
|
||||||
|
{
|
||||||
|
var name = f.GetProperty("name").GetString() ?? throw new ToolException("Fixture without a name");
|
||||||
|
if (name != Path.GetFileName(name) || name.StartsWith('.')) throw new ToolException($"Fixture name must be a plain file name: {name}");
|
||||||
|
if (!Uri.TryCreate(f.GetProperty("url").GetString(), UriKind.Absolute, out var url) || url.Scheme != Uri.UriSchemeHttps)
|
||||||
|
throw new ToolException($"Fixture {name} needs an https URL");
|
||||||
|
var sha = f.TryGetProperty("sha256", out var s) && s.ValueKind == JsonValueKind.String ? s.GetString() : null;
|
||||||
|
long? size = f.TryGetProperty("size", out var z) && z.ValueKind == JsonValueKind.Number ? z.GetInt64() : null;
|
||||||
|
entries.Add(new Entry(name, url, sha, size));
|
||||||
|
}
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Downloads into <c>target.part</c>, resuming from its length with a range request, then renames it.</summary>
|
||||||
|
private static async Task<string> DownloadAsync(HttpClient http, Entry entry, string target)
|
||||||
|
{
|
||||||
|
var part = target + ".part";
|
||||||
|
var existing = File.Exists(part) ? new FileInfo(part).Length : 0;
|
||||||
|
if (entry.Size is not { } size || existing < size)
|
||||||
|
{
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Get, entry.Url);
|
||||||
|
if (existing > 0) request.Headers.Range = new RangeHeaderValue(existing, null);
|
||||||
|
using var response = await http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
|
||||||
|
if (response.StatusCode == HttpStatusCode.RequestedRangeNotSatisfiable && existing > 0)
|
||||||
|
{
|
||||||
|
// The partial file is already complete (or the server lost it): verified below.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
var resume = response.StatusCode == HttpStatusCode.PartialContent;
|
||||||
|
await using var output = new FileStream(part, resume ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.None, 1 << 16, FileOptions.Asynchronous);
|
||||||
|
await using var input = await response.Content.ReadAsStreamAsync();
|
||||||
|
await input.CopyToAsync(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (entry.Size is { } expected && new FileInfo(part).Length is var length && length != expected)
|
||||||
|
{
|
||||||
|
File.Delete(part);
|
||||||
|
throw new InvalidDataException($"size {length} differs from {expected}");
|
||||||
|
}
|
||||||
|
var hash = await HashAsync(part);
|
||||||
|
File.Move(part, target, overwrite: true);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<string> HashAsync(string path)
|
||||||
|
{
|
||||||
|
await using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 1 << 16, FileOptions.Asynchronous | FileOptions.SequentialScan);
|
||||||
|
return Convert.ToHexStringLower(await SHA256.HashDataAsync(stream));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@ var commands = new ICommand[]
|
|||||||
new XamlLintCommand(),
|
new XamlLintCommand(),
|
||||||
new PackageGuardCommand(),
|
new PackageGuardCommand(),
|
||||||
new ChangelogCommand(),
|
new ChangelogCommand(),
|
||||||
|
new DiagnoseCommand(),
|
||||||
|
new FixturesCommand(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (args.Length == 0 || args[0] is "-h" or "--help" or "help")
|
if (args.Length == 0 || args[0] is "-h" or "--help" or "help")
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using Titano.Core.Imaging;
|
||||||
|
using Titano.Core.Imaging.Decoders;
|
||||||
|
using Titano.Core.Metadata;
|
||||||
|
using Titano.Testing;
|
||||||
|
|
||||||
|
namespace Titano.Core.Tests.Decoding;
|
||||||
|
|
||||||
|
/// <summary>Real camera files from tests/fixtures/manifest.json (fetched by <c>Titano.Tools fixtures</c>); each test is
|
||||||
|
/// skipped when its file is absent. A native decode must reach the expected size and look like the camera's own
|
||||||
|
/// embedded preview (luminance correlation), which catches wrong byte orders, CFA phases or colour matrices.</summary>
|
||||||
|
public sealed class ExternalFixtureTests(TestContext context)
|
||||||
|
{
|
||||||
|
private const int Edge = 256;
|
||||||
|
|
||||||
|
private static JsonElement Entry(string name)
|
||||||
|
{
|
||||||
|
var manifest = JsonDocument.Parse(File.ReadAllText(Path.Combine(TestContext.FixturesDirectory, "manifest.json")));
|
||||||
|
foreach (var f in manifest.RootElement.GetProperty("files").EnumerateArray())
|
||||||
|
{
|
||||||
|
if (f.GetProperty("name").GetString() == name) return f.Clone();
|
||||||
|
}
|
||||||
|
throw new InvalidOperationException("No manifest entry " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Case("google-pixel-4a.dng")]
|
||||||
|
[Case("canon-eos-5d-mark-iii.cr2")]
|
||||||
|
[Case("nikon-d850.nef")]
|
||||||
|
[Case("sony-ilce-7m3.arw")]
|
||||||
|
[Case("fujifilm-x-t2.raf")]
|
||||||
|
[Case("pentax-k-1.pef")]
|
||||||
|
[Timeout(20_000)]
|
||||||
|
public void DecodesNativelyAndMatchesThePreview(string name)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(TestContext.FixturesDirectory, "external", name);
|
||||||
|
if (!File.Exists(path)) TestContext.Skip($"{name} not fetched (run Titano.Tools fixtures)");
|
||||||
|
var entry = Entry(name);
|
||||||
|
var metadata = MetadataReader.Read(path);
|
||||||
|
Assert.Equal(entry.GetProperty("format").GetString(), metadata.Format.ToString());
|
||||||
|
var probe = new ManagedDecoderProvider().Probe(path);
|
||||||
|
context.Log($"{name}: {probe}; {metadata.Make} {metadata.Model}, {metadata.Width}x{metadata.Height}, orientation {metadata.Orientation}");
|
||||||
|
Assert.Equal(DecodeTier.Native, probe.Tier);
|
||||||
|
|
||||||
|
var decoder = DecoderFactory.CreateServer();
|
||||||
|
using var native = decoder.Decode(new DecodeRequest(path, Edge, DecodePurpose.Render, ApplyOrientation: false));
|
||||||
|
Assert.Equal(DecodeTier.Native, native!.Tier);
|
||||||
|
var (w, h) = (entry.GetProperty("width").GetInt32(), entry.GetProperty("height").GetInt32());
|
||||||
|
Assert.InRange(native.SourceWidth, w * 0.98, w * 1.02);
|
||||||
|
Assert.InRange(native.SourceHeight, h * 0.98, h * 1.02);
|
||||||
|
foreach (var v in native.Pixels.Data)
|
||||||
|
{
|
||||||
|
if (!float.IsFinite(v)) Assert.Fail("non-finite pixel");
|
||||||
|
}
|
||||||
|
|
||||||
|
using var preview = decoder.Decode(new DecodeRequest(path, Edge, DecodePurpose.Render, ApplyOrientation: false, ForcePreview: true));
|
||||||
|
if (preview is null || preview.Tier != DecodeTier.EmbeddedPreview) TestContext.Skip("no embedded preview to compare with");
|
||||||
|
var correlation = Correlation(native.Pixels, preview.Pixels);
|
||||||
|
context.Log($"luminance correlation with the embedded preview: {correlation:F3}");
|
||||||
|
Assert.Greater(correlation, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Pearson correlation of sRGB-encoded luminance after resizing both to a common 64-pixel-wide grid.</summary>
|
||||||
|
private static double Correlation(ImageBuffer a, ImageBuffer b)
|
||||||
|
{
|
||||||
|
var height = int.Max(1, (int)double.Round(64.0 * a.Height / a.Width));
|
||||||
|
using var ra = Resampler.Resize(a, 64, height, ResampleFilter.Box);
|
||||||
|
using var rb = Resampler.Resize(b, 64, height, ResampleFilter.Box);
|
||||||
|
var n = ra.PlaneLength;
|
||||||
|
double sa = 0, sb = 0, saa = 0, sbb = 0, sab = 0;
|
||||||
|
for (var i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
double la = ColorSpace.EncodeFast(ColorSpace.Luminance(ra.Plane(0)[i], ra.Plane(1)[i], ra.Plane(2)[i]));
|
||||||
|
double lb = ColorSpace.EncodeFast(ColorSpace.Luminance(rb.Plane(0)[i], rb.Plane(1)[i], rb.Plane(2)[i]));
|
||||||
|
sa += la;
|
||||||
|
sb += lb;
|
||||||
|
saa += la * la;
|
||||||
|
sbb += lb * lb;
|
||||||
|
sab += la * lb;
|
||||||
|
}
|
||||||
|
var cov = sab / n - sa / n * (sb / n);
|
||||||
|
return cov / double.Sqrt(double.Max(saa / n - sa / n * (sa / n), 1e-12) * double.Max(sbb / n - sb / n * (sb / n), 1e-12));
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+78
@@ -0,0 +1,78 @@
|
|||||||
|
{
|
||||||
|
"description": "CC0 RAW samples from raw.pixls.us (one per managed RAW decoder), fetched by 'Titano.Tools fixtures' into tests/fixtures/external (git-ignored, CI-cached on this file). sha256 null: the first download records its hash in external/recorded-hashes.json and prints it for pinning here. width/height: size the managed decoder develops (before orientation). urlVerified false: the URL follows the site's data/<make>/<model>/ layout but was written without network access; replace it with the sample's download link if the fetch reports 404.",
|
||||||
|
"license": "CC0-1.0",
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"name": "google-pixel-4a.dng",
|
||||||
|
"url": "https://raw.pixls.us/data/Google/Pixel%204a/PXL_20201101_120000000.dng",
|
||||||
|
"sha256": null,
|
||||||
|
"size": null,
|
||||||
|
"format": "Dng",
|
||||||
|
"make": "Google",
|
||||||
|
"model": "Pixel 4a",
|
||||||
|
"width": 4032,
|
||||||
|
"height": 3024,
|
||||||
|
"urlVerified": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "canon-eos-5d-mark-iii.cr2",
|
||||||
|
"url": "https://raw.pixls.us/data/Canon/EOS%205D%20Mark%20III/IMG_0001.CR2",
|
||||||
|
"sha256": null,
|
||||||
|
"size": null,
|
||||||
|
"format": "Cr2",
|
||||||
|
"make": "Canon",
|
||||||
|
"model": "Canon EOS 5D Mark III",
|
||||||
|
"width": 5760,
|
||||||
|
"height": 3840,
|
||||||
|
"urlVerified": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nikon-d850.nef",
|
||||||
|
"url": "https://raw.pixls.us/data/Nikon/D850/DSC_0001.NEF",
|
||||||
|
"sha256": null,
|
||||||
|
"size": null,
|
||||||
|
"format": "Nef",
|
||||||
|
"make": "NIKON CORPORATION",
|
||||||
|
"model": "NIKON D850",
|
||||||
|
"width": 8288,
|
||||||
|
"height": 5520,
|
||||||
|
"urlVerified": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "sony-ilce-7m3.arw",
|
||||||
|
"url": "https://raw.pixls.us/data/Sony/ILCE-7M3/DSC00001.ARW",
|
||||||
|
"sha256": null,
|
||||||
|
"size": null,
|
||||||
|
"format": "Arw",
|
||||||
|
"make": "SONY",
|
||||||
|
"model": "ILCE-7M3",
|
||||||
|
"width": 6048,
|
||||||
|
"height": 4024,
|
||||||
|
"urlVerified": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "fujifilm-x-t2.raf",
|
||||||
|
"url": "https://raw.pixls.us/data/Fujifilm/X-T2/DSCF0001.RAF",
|
||||||
|
"sha256": null,
|
||||||
|
"size": null,
|
||||||
|
"format": "Raf",
|
||||||
|
"make": "FUJIFILM",
|
||||||
|
"model": "X-T2",
|
||||||
|
"width": 6000,
|
||||||
|
"height": 4000,
|
||||||
|
"urlVerified": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pentax-k-1.pef",
|
||||||
|
"url": "https://raw.pixls.us/data/Pentax/K-1/IMGP0001.PEF",
|
||||||
|
"sha256": null,
|
||||||
|
"size": null,
|
||||||
|
"format": "Pef",
|
||||||
|
"make": "RICOH IMAGING COMPANY, LTD.",
|
||||||
|
"model": "PENTAX K-1",
|
||||||
|
"width": 7392,
|
||||||
|
"height": 4950,
|
||||||
|
"urlVerified": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user