Merge branch 'fix/imaging-metadata': decode tiers, preview-only and undecodable frames, GPR companions, MakerNote fields
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
70 files changed
+2201
-124
No files matched your search
@@ -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,20 @@ 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)
|
||||
{
|
||||
/// <summary>Long edge of the decode that confirms a frame an interrupted earlier run found undecodable.</summary>
|
||||
private const int ConfirmLongEdge = 64;
|
||||
|
||||
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 +45,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, options.Archive.Decoder, cancellationToken).ConfigureAwait(false);
|
||||
// Format tiers (BRIEF §10.1): frames indexed since the last analysis are probed with this host's decoders.
|
||||
var probed = await _tiers.ProbeUnknownAsync(archive, folder, ManifestStore.ReadSequence(folder.ManifestPath), cancellationToken).ConfigureAwait(false);
|
||||
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 decoded) = await AnalyseDeepAsync(archive, frames, metadata, folder, progress, cancellationToken).ConfigureAwait(false);
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, decoded, 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,18 +119,64 @@ 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, by frame id: the tier this run decoded it at. A frame this run
|
||||
/// tried to read and recorded nothing for vanished or could not be read, which says nothing about its content. A frame
|
||||
/// only an interrupted earlier run analysed and found undecodable is decoded again (small) to confirm it: that run's
|
||||
/// failure may have been a read error too. Missing and corrupt frames are not decoded at all.
|
||||
/// </summary>
|
||||
private Dictionary<Guid, FileTier> Decoded(SequenceFrames frames, DeepAnalysisReport report, SequenceFrameSource source,
|
||||
IReadOnlyDictionary<Guid, string> companions, CancellationToken cancellationToken)
|
||||
{
|
||||
var tiers = new Dictionary<Guid, FileTier>();
|
||||
foreach (var (index, tier) in source.Observed) tiers[frames.Frames[index].Id] = tier;
|
||||
var read = source.Read.ToHashSet();
|
||||
foreach (var index in report.Issues.Undecodable)
|
||||
{
|
||||
if (index >= frames.Count || read.Contains(index) || frames.Files[index] is not { } path
|
||||
|| (frames.Frames[index].Flags & SequenceFrames.NotAnalysed) != 0) continue;
|
||||
var frame = frames.Frames[index];
|
||||
try
|
||||
{
|
||||
using var decoded = options.Archive.Decoder.Decode(
|
||||
new DecodeRequest(path, ConfirmLongEdge, DecodePurpose.Analysis, Companion: companions.GetValueOrDefault(frame.Id)), cancellationToken);
|
||||
if (decoded is not null) tiers[frame.Id] = new FileTier(frame.Format, decoded.Tier, decoded.Decoder, null, 0, 0);
|
||||
else if (File.Exists(path)) tiers[frame.Id] = new FileTier(frame.Format, DecodeTier.Unavailable, null, "no decoder produced pixels", 0, 0);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("processing", $"Frame {path} could not be read", ex);
|
||||
}
|
||||
}
|
||||
return tiers;
|
||||
}
|
||||
|
||||
private async Task<(DeepAnalysisReport Report, Dictionary<Guid, FileTier> Decoded)> AnalyseDeepAsync(Archive archive, SequenceFrames frames,
|
||||
IReadOnlyList<LightFrame> metadata, SequencePaths folder, IProgress<AnalysisProgress>? progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var file = new DeepAnalysisCheckpointFile(Path.Combine(folder.MetaDirectory, DeepAnalysisCheckpointFile.FileName));
|
||||
// The host's analysis parameters as they are now (Settings › Analysis on the desktop). Those that change per-frame
|
||||
// results are part of the checkpoint's fingerprint, so a partial run made with other values starts again.
|
||||
var analysis = options.Current.DeepAnalysis;
|
||||
var companions = await GprCompanions.FindAsync(db, archive, frames.Frames, cancellationToken).ConfigureAwait(false);
|
||||
DeepAnalysisReport report;
|
||||
await using (var source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder))
|
||||
Dictionary<Guid, FileTier> decoded;
|
||||
await using (var source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder) { Originals = true, Companions = companions })
|
||||
{
|
||||
report = await DeepAnalyzer.AnalyzeAsync(source, analysis, new FramesCheckpoint(file, ContentKey(frames)), progress, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
decoded = Decoded(frames, report, source, companions, cancellationToken);
|
||||
}
|
||||
report.Save(folder.AnalysisPath);
|
||||
file.Delete();
|
||||
@@ -121,7 +186,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, decoded);
|
||||
}
|
||||
|
||||
/// <summary>Identity of the analysed content: frames replaced or renumbered since a checkpoint was written (with the
|
||||
|
||||
Reference in new issue
Block a user