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

+19 -11
View File
@@ -18,19 +18,22 @@ public sealed class FrameImageRenderer(ImageDecoder decoder)
public const int ThumbnailQuality = 80;
/// <summary>A 320 px q80 thumbnail, or null when no decoder can read the frame.</summary>
public EncodedImage? Thumbnail(SequencePaths sequence, SidecarFrame frame, CancellationToken cancellationToken = default)
/// <param name="companion">Where a GPR's JPEG is kept when it is not beside it (<see cref="DecodeRequest.Companion"/>).</param>
public EncodedImage? Thumbnail(SequencePaths sequence, SidecarFrame frame, CancellationToken cancellationToken = default, string? companion = null)
{
using var decoded = Decode(sequence.File(frame.File), frame, ThumbnailLongEdge, DecodePurpose.Thumbnail, preferPreview: true, cancellationToken);
using var decoded = Decode(sequence.File(frame.File), frame, ThumbnailLongEdge, DecodePurpose.Thumbnail, preferPreview: true, companion, cancellationToken);
if (decoded is null) return null;
using var small = Resampler.Thumbnail(decoded.Pixels, ThumbnailLongEdge);
return Encode(small, new JpegEncodeOptions { Quality = ThumbnailQuality }, decoded.Tier);
}
/// <summary>A proxy at the policy's long edge and quality with capture time and camera in its Exif; null when undecodable.</summary>
public EncodedImage? Proxy(SequencePaths sequence, SidecarFrame frame, SidecarCamera? camera, ProxyPolicy policy, CancellationToken cancellationToken = default)
/// <param name="companion">Where a GPR's JPEG is kept when it is not beside it (<see cref="DecodeRequest.Companion"/>).</param>
public EncodedImage? Proxy(SequencePaths sequence, SidecarFrame frame, SidecarCamera? camera, ProxyPolicy policy, CancellationToken cancellationToken = default,
string? companion = null)
{
if (policy.LongEdge == ProxyPolicy.Disabled) throw new InvalidOperationException("Proxies are disabled for this archive.");
using var decoded = Decode(sequence.File(frame.File), frame, policy.LongEdge, DecodePurpose.Proxy, preferPreview: false, cancellationToken);
using var decoded = Decode(sequence.File(frame.File), frame, policy.LongEdge, DecodePurpose.Proxy, preferPreview: false, companion, cancellationToken);
if (decoded is null) return null;
var source = decoded.Pixels;
var (w, h) = policy.LongEdge == ProxyPolicy.FullSize ? (source.Width, source.Height) : Resampler.FitWithin(source.Width, source.Height, policy.LongEdge);
@@ -59,25 +62,30 @@ public sealed class FrameImageRenderer(ImageDecoder decoder)
/// <summary>
/// The frame's pixels: a JPEG through the managed decoder, the stored embedded preview when <paramref name="preferPreview"/>
/// and it reaches <paramref name="maxLongEdge"/> (a smaller one would be upscaled or leave the thumbnail short), then
/// the host's decoders, and the stored preview as the last resort. Null when nothing decodes.
/// the host's decoders (with the GPR's <paramref name="companion"/>), and the stored preview as the last resort. Null
/// when nothing decodes.
/// </summary>
private DecodedFrame? Decode(string path, SidecarFrame frame, int maxLongEdge, DecodePurpose purpose, bool preferPreview, CancellationToken cancellationToken)
/// <exception cref="IOException">The file could not be read.</exception>
private DecodedFrame? Decode(string path, SidecarFrame frame, int maxLongEdge, DecodePurpose purpose, bool preferPreview, string? companion,
CancellationToken cancellationToken)
{
if (frame.Format == ImageFileFormat.Jpeg && DecodeJpeg(File.ReadAllBytes(path), maxLongEdge, frame.Orientation, DecodeTier.Native) is { } jpeg) return jpeg;
byte[]? preview = null;
if (preferPreview && (preview = ReadPreview(path, frame)) is not null && Reaches(preview, frame, maxLongEdge)
if (preferPreview && (preview = ReadPreview(path, frame)) is not null && Reaches(preview, maxLongEdge)
&& DecodeJpeg(preview, maxLongEdge, frame.Orientation, DecodeTier.EmbeddedPreview) is { } fast)
return fast;
var request = new DecodeRequest(path, System.Math.Max(0, maxLongEdge), purpose, ApplyOrientation: true, AllowPreview: true);
var request = new DecodeRequest(path, System.Math.Max(0, maxLongEdge), purpose, ApplyOrientation: true, AllowPreview: true, Companion: companion);
if (decoder.Decode(request, cancellationToken) is { } decoded) return new DecodedFrame(decoded.Pixels, decoded.Tier);
return (preview ?? ReadPreview(path, frame)) is { } fallback ? DecodeJpeg(fallback, maxLongEdge, frame.Orientation, DecodeTier.EmbeddedPreview) : null;
}
/// <summary>Whether the stored preview's long edge reaches <paramref name="maxLongEdge"/> (the sidecar's size, else the JPEG's own).</summary>
private static bool Reaches(byte[] preview, SidecarFrame frame, int maxLongEdge)
/// <summary>
/// Whether the stored preview's long edge reaches <paramref name="maxLongEdge"/>, from the JPEG's own header: the
/// sidecar's preview size may be a GPR companion's, larger than the preview embedded in the file.
/// </summary>
private static bool Reaches(byte[] preview, int maxLongEdge)
{
if (maxLongEdge <= 0) return true;
if (frame is { PreviewW: { } w, PreviewH: { } h }) return int.Max(w, h) >= maxLongEdge;
try
{
var info = JpegDecoder.ReadInfo(preview);