fix(imaging): record only what decoding proves and find GPR JPEGs across sequences

- Preview sizes come from probes and unscaled decodes: a size-limited decode
  picks the smallest preview that reaches its edge (CR3 PRVW 1620x1080), so
  renders and deep passes record its tier without a size and the output cap
  keeps the largest preview's.
- A read error is not an undecodable file: ImageDecoder.Decode throws the
  IOException when a provider could not read the file and none produced
  pixels. Deep passes never flag frames they could not read or that
  vanished, and frames only an interrupted earlier run found undecodable
  are decoded again before they are flagged.
- Renders resolve stand-ins only for frames the pipeline asks for; frames
  the read-ahead meets on the way (skipped by speed-ups) are left alone.
- A GoPro GPR finds its JPEG in the index when an import or upload kept it
  in a sequence of its own (same original stem and capture time), for
  probes, deep analysis, renders, thumbnails, proxies and the editor;
  GPRs whose JPEG is indexed later are probed again.
- Thumbnails judge an embedded preview by its own JPEG header.
- PostgreSQL writes tier fields 1000 frames per statement.

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-12 11:17:49 +00:00
1 parent 366dd9f303
commit 5599e4de89
19 files changed
+689 -111

No files matched your search

@@ -260,6 +260,52 @@ public sealed class ManagedDecoderProviderTests(TestContext context)
Assert.Equal("managed-preview", new ManagedDecoderProvider().Probe(big).Decoder);
}
[Test]
public void GoProRawDecodesThroughItsJpegWhereTheImportKeptIt()
{
// An import splits sessions per format: the JPEG lives in another sequence folder, under its imported name.
var gpr = Write("GOPR0003.GPR", Gpr(previewWidth: 64, previewHeight: 48));
var elsewhere = Path.Combine(context.CreateTempDirectory("jpeg-sequence"), "2026-09-28_0003.JPG");
File.WriteAllBytes(elsewhere, JpegFile(160, 120, 1));
var server = DecoderFactory.CreateServer();
using (var decoded = server.Decode(new DecodeRequest(gpr, Companion: elsewhere)))
Assert.Equal(("managed-sidecar", 160, 120), (decoded!.Decoder, decoded.SourceWidth, decoded.SourceHeight));
var probe = server.Probe(gpr, ImageFileFormat.Gpr, elsewhere);
Assert.Equal((DecodeTier.EmbeddedPreview, "managed-sidecar", 160, 120), (probe.Tier, probe.Decoder, probe.Width, probe.Height));
// A JPEG that is gone (deleted since) leaves the embedded preview; other formats ignore the companion.
var gone = Path.Combine(_dir, "gone.JPG");
using (var preview = server.Decode(new DecodeRequest(gpr, Companion: gone)))
Assert.Equal(("managed-preview", 64), (preview!.Decoder, preview.Pixels.Width));
Assert.Equal("managed-preview", server.Probe(gpr, ImageFileFormat.Gpr, gone).Decoder);
var jpeg = Write("plain.jpg", JpegFile(64, 48, 1));
using (var plain = server.Decode(new DecodeRequest(jpeg, Companion: elsewhere)))
Assert.Equal(("managed-jpeg", 64), (plain!.Decoder, plain.SourceWidth));
}
[Test]
public void AFileNoProviderCouldReadIsAReadErrorNotAnUndecodableFile()
{
var path = Write("locked.jpg", JpegFile(64, 48, 1));
// Every provider failed to read the file (locked by another program, a network read failed): nothing is known
// about its content, so the caller gets the read error instead of "nothing decodes it".
var unreadable = new ImageDecoder([new ScriptedProvider("a", _ => throw new IOException("sharing violation"))]);
Assert.Throws<IOException>(() => unreadable.Decode(new DecodeRequest(path)));
// One provider read it and found nothing, another could not read it: still unproven.
var mixed = new ImageDecoder([new ScriptedProvider("a", _ => null), new ScriptedProvider("b", _ => throw new IOException("short read"))]);
Assert.Throws<IOException>(() => mixed.Decode(new DecodeRequest(path)));
// A provider that produces pixels wins over one that could not read the file.
var recovered = new ImageDecoder([new ScriptedProvider("a", _ => throw new IOException("busy")), new ManagedDecoderProvider()]);
using (var image = recovered.Decode(new DecodeRequest(path)))
Assert.Equal("managed-jpeg", image!.Decoder);
// Providers that read the file and found it malformed prove it undecodable.
var damaged = new ImageDecoder([new ScriptedProvider("a", _ => throw new InvalidDataException("bad marker"))]);
Assert.Null(damaged.Decode(new DecodeRequest(path)));
Assert.Null(DecoderFactory.CreateServer().Decode(new DecodeRequest(Write("garbage.jpg", new byte[3000]))));
Assert.Throws<FileNotFoundException>(() => DecoderFactory.CreateServer().Decode(new DecodeRequest(Path.Combine(_dir, "vanished.jpg"))));
}
/// <summary>A GoPro GPR as far as Titano reads it: a DNG made by "GoPro" whose only decodable image is a YCbCr JPEG preview.</summary>
private static byte[] Gpr(int previewWidth, int previewHeight)
{
@@ -286,4 +332,12 @@ public sealed class ManagedDecoderProviderTests(TestContext context)
return null;
}
}
/// <summary>A JPEG provider whose decode does what the test says (return nothing, or throw).</summary>
private sealed class ScriptedProvider(string name, Func<DecodeRequest, DecodedImage?> decode) : IImageDecoderProvider
{
public string Name => name;
public DecodeTier? TierFor(ImageFileFormat format) => format == ImageFileFormat.Jpeg ? DecodeTier.Native : null;
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default) => decode(request);
}
}