fix(imaging): record decode tiers per frame and keep undecodable frames out of renders

BRIEF §8.2 tiers 2 and 3 had no writer: PreviewOnly and Undecodable were never set,
so the advisor could not cap the output at the preview size and one unreadable frame
failed a whole render.

- ImageDecoder.Probe names a file's tier without decoding it (JPEG, PNG and TIFF
  without opening the file); the light analysis probes frames whose tier is unknown,
  and the deep analysis, renders from originals and thumbnail/proxy passes record
  what decoding actually found (FrameTiers). Sidecar frames gain "tier", "previewW"
  and "previewH"; the index gains frames.preview_width/height and
  sequences.preview_only_count (migration 0005, SQLite and PostgreSQL).
- SequenceContext takes the preview size from preview-only frames, so the advisor's
  output cap applies; the light analysis reports format tiers (preview-only frames as
  information, undecodable ones as a warning under the deep analysis' key, listed
  once); a sequence that gains undecodable frames warns at once.
- Only a file in a format the host decodes natively is flagged undecodable; files
  beyond the host's decoders keep their tier without the flag, so render nodes and
  proxies can still supply them.
- A frame that stops decoding during a render is replaced by its nearest planned
  neighbour and logged instead of failing the job; the render fails only when no
  planned frame decodes.
- The Library card shows a preview-only chip with the count (local and server
  sequences: SequenceDto.PreviewOnlyCount, FrameDto preview size).
- GoPro GPR decodes through the JPEG the camera writes beside it when that is larger
  than the embedded preview (BRIEF §8.1).
- Thumbnails use a stored embedded preview only when it reaches 320 px; a smaller one
  sends the frame through the host's decoders instead (BRIEF §8.5).

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 09:58:36 +00:00
1 parent 61d913baa9
commit 4d321a84b0
48 files changed
+1132 -87

No files matched your search

+60 -12
View File
@@ -4,6 +4,7 @@ using Titano.Core.Advice;
using Titano.Core.Analysis;
using Titano.Core.Analysis.Deep;
using Titano.Core.Archiving;
using Titano.Core.Imaging;
using Titano.Core.Model;
using Titano.Data.Archiving;
using Titano.Data.Repositories;
@@ -20,13 +21,17 @@ internal sealed record AnalysisOutcome(Sequence Sequence, int Frames, int Warnin
/// <summary>
/// Light (BRIEF §10.1) and deep (§10.2) analysis of archived sequences, followed by the advisor (§10.3–10.4) filling the
/// Auto values of the project. The light pass reads the index only (plus one file for the GPS fix); the deep pass decodes
/// every frame, checkpointing into <c>.titano/analysis.partial</c> so a cancelled, paused or crashed run resumes, and
/// saves <c>analysis.json</c> atomically. Results land in the sidecar status, the index (status, warning count, compact
/// summary, per-frame light statistics) and <c>project.json</c>.
/// Auto values of the project. The light pass reads the index, probes the decode tier (§8.2) of frames whose tier is not
/// known yet (headers only, once per frame) and reads one file for the GPS fix; the deep pass decodes every frame,
/// checkpointing into <c>.titano/analysis.partial</c> so a cancelled, paused or crashed run resumes, records the tier
/// each frame decoded at (or that it did not decode) and saves <c>analysis.json</c> atomically. Results land in the
/// sidecar (status, tiers), the index (status, warning count, compact summary, tier flags, per-frame light statistics)
/// and <c>project.json</c>.
/// </summary>
internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions options, SequenceWriter writer, ArchiveIndexer indexer, ProjectStore projects)
{
private readonly FrameTiers _tiers = new(db, writer, indexer);
/// <summary>Analyses one sequence; null when it is no longer in the index.</summary>
/// <exception cref="ArchiveOfflineException">The archive is offline or read-only.</exception>
public async Task<AnalysisOutcome?> AnalyseAsync(Guid sequenceId, bool deep, IProgress<AnalysisProgress>? progress, CancellationToken cancellationToken)
@@ -37,12 +42,23 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
ArchiveVolume.EnsureWritable(paths);
var folder = paths.Sequence(sequence.Folder);
var frames = await SequenceFrames.LoadAsync(db, archive, sequence, useProxies: false, cancellationToken).ConfigureAwait(false);
// Format tiers (BRIEF §10.1): frames indexed since the last analysis are probed with this host's decoders.
var probed = _tiers.ProbeUnknown(folder, ManifestStore.ReadSequence(folder.ManifestPath), cancellationToken);
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, probed, cancellationToken).ConfigureAwait(false));
var metadata = frames.LightFrames();
var light = LightAnalyzer.Analyze(metadata);
var report = deep
? await AnalyseDeepAsync(frames, metadata, folder, progress, cancellationToken).ConfigureAwait(false)
: ReadReport(folder, frames.Count);
DeepAnalysisReport? report;
if (deep)
{
(report, var observed) = await AnalyseDeepAsync(frames, metadata, folder, progress, cancellationToken).ConfigureAwait(false);
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, Decoded(frames, report, observed), cancellationToken).ConfigureAwait(false));
metadata = [.. metadata.Select((m, i) => m with { Flags = frames.Frames[i].Flags })];
}
else
{
report = ReadReport(folder, frames.Count);
}
var light = LightAnalyzer.Analyze(metadata);
var context = SequenceContext.FromFrames(frames.Frames, options.AdvisorCodecs);
bool changed, unreadable = false;
@@ -100,15 +116,47 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
}
}
private async Task<DeepAnalysisReport> AnalyseDeepAsync(SequenceFrames frames, IReadOnlyList<LightFrame> metadata, SequencePaths folder,
IProgress<AnalysisProgress>? progress, CancellationToken cancellationToken)
/// <summary>The frame rows with the tier fields of <paramref name="changed"/> sidecar frames.</summary>
private static SequenceFrames WithTiers(SequenceFrames frames, IReadOnlyList<SidecarFrame> changed)
{
if (changed.Count == 0) return frames;
var byId = changed.ToDictionary(f => f.Id);
var rows = frames.Frames.Select(f => byId.TryGetValue(f.Id, out var s)
? f with { Flags = s.Flags, PreviewWidth = s.PreviewW ?? 0, PreviewHeight = s.PreviewH ?? 0 }
: f).ToList();
return frames with { Frames = rows };
}
/// <summary>
/// What the deep pass learnt about each frame's tier: the tier this run decoded it at, else (for frames analysed by
/// an interrupted earlier run) unavailable when the report says it did not decode. Missing and corrupt frames are not
/// decoded at all, so they say nothing.
/// </summary>
private static Dictionary<Guid, FileTier> Decoded(SequenceFrames frames, DeepAnalysisReport report, IReadOnlyDictionary<int, FileTier> observed)
{
var tiers = new Dictionary<Guid, FileTier>();
foreach (var (index, tier) in observed) tiers[frames.Frames[index].Id] = tier;
foreach (var index in report.Issues.Undecodable)
{
if (index >= frames.Count || observed.ContainsKey(index) || frames.Files[index] is null
|| (frames.Frames[index].Flags & SequenceFrames.NotAnalysed) != 0) continue;
var frame = frames.Frames[index];
tiers[frame.Id] = new FileTier(frame.Format, DecodeTier.Unavailable, null, "no decoder produced pixels", 0, 0);
}
return tiers;
}
private async Task<(DeepAnalysisReport Report, IReadOnlyDictionary<int, FileTier> Observed)> AnalyseDeepAsync(SequenceFrames frames,
IReadOnlyList<LightFrame> metadata, SequencePaths folder, IProgress<AnalysisProgress>? progress, CancellationToken cancellationToken)
{
var file = new DeepAnalysisCheckpointFile(Path.Combine(folder.MetaDirectory, DeepAnalysisCheckpointFile.FileName));
DeepAnalysisReport report;
await using (var source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder))
IReadOnlyDictionary<int, FileTier> observed;
await using (var source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder) { Originals = true })
{
report = await DeepAnalyzer.AnalyzeAsync(source, options.DeepAnalysis, new FramesCheckpoint(file, ContentKey(frames)), progress, cancellationToken)
.ConfigureAwait(false);
observed = source.Observed.ToDictionary();
}
report.Save(folder.AnalysisPath);
file.Delete();
@@ -118,7 +166,7 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
for (var i = 0; i < stats.Length; i++)
stats[i] = new FrameLightStats(frames.Frames[i].Id, columns.LogLuminance[i], columns.ClipLow[i], columns.ClipHigh[i]);
await db.Frames.UpdateLightStatsAsync(stats, cancellationToken).ConfigureAwait(false);
return report;
return (report, observed);
}
/// <summary>Identity of the analysed content: frames replaced or renumbered since a checkpoint was written (with the