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:
19 files changed
+689
-111
No files matched your search
@@ -2,11 +2,16 @@ using Titano.Core.Advice;
|
||||
using Titano.Core.Analysis;
|
||||
using Titano.Core.Analysis.Deep;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Codecs.Dng;
|
||||
using Titano.Core.Codecs.Jpeg;
|
||||
using Titano.Core.Diagnostics.Synthetic;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Metadata;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data.Archiving.Jobs;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Data.Processing.Jobs;
|
||||
using Titano.Data.Repositories;
|
||||
@@ -134,6 +139,138 @@ public sealed class AnalysisJobTests(TestContext context)
|
||||
Assert.Equal(JobState.Done, done.State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnImportedGoProRawDecodesThroughTheJpegItsImportKeptInAnotherSequence()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
// A GoPro card: each GPR (VC-5, without a usable embedded image here) has the camera's full-size JPEG beside it.
|
||||
// An upload may send the GPRs first: they arrive as two cards here.
|
||||
var raws = Path.Combine(context.CreateTempDirectory("card"), "DCIM", "100GOPRO");
|
||||
var jpegs = Path.Combine(context.CreateTempDirectory("card"), "DCIM", "100GOPRO");
|
||||
Directory.CreateDirectory(raws);
|
||||
Directory.CreateDirectory(jpegs);
|
||||
var start = new DateTime(2026, 9, 28, 18, 0, 0);
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
var metadata = new FrameMetadata { Make = "GoPro", Model = "HERO12 Black", BodySerial = "C3501", CapturedAt = start.AddSeconds(5 * i) };
|
||||
using var sensor = new ImageBuffer(64, 48);
|
||||
File.WriteAllBytes(Path.Combine(raws, $"GOPR{i + 1:0000}.GPR"),
|
||||
LinearDngWriter.Write(sensor, new LinearDngOptions { Exif = ExifWriter.BuildTiff(metadata), TileSize = 64 }));
|
||||
using var picture = new ImageBuffer(160, 120);
|
||||
picture.Plane(1).Fill(0.25f * (i + 1));
|
||||
File.WriteAllBytes(Path.Combine(jpegs, $"GOPR{i + 1:0000}.JPG"),
|
||||
JpegEncoder.Encode(picture, new JpegEncodeOptions { App1Segments = [ExifWriter.BuildJpegApp1(metadata)[4..]] }));
|
||||
}
|
||||
var service = fx.Archive.Service;
|
||||
async Task<ImportPlan> ImportAsync(string card)
|
||||
{
|
||||
var plan = await service.PlanImportAsync(fx.Archive.Archive.Id, Path.GetDirectoryName(Path.GetDirectoryName(card))!, new ImportOptions(),
|
||||
cancellationToken: fx.Ct);
|
||||
await service.Imports.ExecuteAsync(new ImportJobParameters(fx.Archive.Archive.Id, plan, null, true, null), Guid.NewGuid(), 0,
|
||||
_ => ValueTask.CompletedTask, null, fx.Ct);
|
||||
return plan;
|
||||
}
|
||||
var gprSession = (await ImportAsync(raws)).Sessions.Single();
|
||||
Assert.Equal(ImageFileFormat.Gpr, gprSession.Format);
|
||||
var id = await fx.Db.Sequences.FindBySessionKeyAsync(fx.Archive.Archive.Id, gprSession.SessionKey, fx.Ct);
|
||||
var sequence = (await fx.Db.Sequences.GetAsync(id!.Value, fx.Ct))!;
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
// Alone, a GPR without an embedded preview gives no pixels here, which proves nothing about the file.
|
||||
var first = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([sequence.Id]));
|
||||
await fx.WaitForAsync(first.Id, JobState.Done);
|
||||
var alone = ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath).Frames;
|
||||
Assert.True(alone.All(f => f is { Tier: DecodeTier.Unavailable, Flags: FrameFlags.None, PreviewW: null }), "unavailable, not flagged");
|
||||
|
||||
// The JPEGs arrive as a sequence of their own (the import splits per file format, DECISIONS 2026-10-02); the next
|
||||
// probe finds each GPR's JPEG there, so the output cap is the JPEG's size.
|
||||
Assert.Equal(ImageFileFormat.Jpeg, (await ImportAsync(jpegs)).Sessions.Single().Format);
|
||||
var jpegFrame = (await fx.Db.Frames.ListByCaptureRangeAsync(fx.Archive.Archive.Id, ImageFileFormat.Jpeg, start, start.AddMinutes(1), fx.Ct))[0];
|
||||
Assert.NotEqual(Path.GetDirectoryName(fx.Folder(sequence).File(alone[0].File)), Path.GetDirectoryName(fx.Archive.Paths.FromRelative(jpegFrame.RelativePath)),
|
||||
"not beside the GPR");
|
||||
var light = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([sequence.Id]));
|
||||
await fx.WaitForAsync(light.Id, JobState.Done);
|
||||
var sidecar = ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath).Frames;
|
||||
Assert.True(sidecar.All(f => f is { Tier: DecodeTier.EmbeddedPreview, Flags: FrameFlags.PreviewOnly, PreviewW: 160, PreviewH: 120 }),
|
||||
"preview-only at the JPEG's size");
|
||||
|
||||
// The deep pass decodes the GPRs through those JPEGs (decoder "managed-sidecar"), never failing a frame.
|
||||
var deep = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
|
||||
await fx.WaitForAsync(deep.Id, JobState.Done);
|
||||
var gprs = fx.Decoder.Decoded.Where(d => d.File.EndsWith(".GPR", StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
Assert.NotEmpty(gprs);
|
||||
Assert.True(gprs.All(d => d.Decoder == "managed-sidecar"), string.Join(", ", gprs.Select(d => d.Decoder).Distinct()));
|
||||
Assert.Empty(SequenceAnalyser.ReadReport(fx.Folder(sequence), sequence.FrameCount)!.Issues.Undecodable);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeepAnalysisNeverFlagsFramesThatVanishedOrCouldNotBeRead()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Flickering(12));
|
||||
// Deleted after indexing (a verify flags it missing), and held by another program during the pass.
|
||||
File.Delete(Path.Combine(fx.Folder(sequence).Folder, ProcessingFixture.FileName(3)));
|
||||
fx.Decoder.Unreadable[ProcessingFixture.FileName(6)] = 0;
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var job = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
|
||||
await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The pass could not read them, so it lists them as unreadable, but nothing proves the files undecodable.
|
||||
var report = SequenceAnalyser.ReadReport(fx.Folder(sequence), sequence.FrameCount)!;
|
||||
Assert.SequenceEqual([3, 6], report.Issues.Undecodable);
|
||||
var sidecar = ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath).Frames;
|
||||
foreach (var index in new[] { 3, 6 })
|
||||
{
|
||||
Assert.Equal(FrameFlags.None, sidecar[index].Flags & FrameFlags.Undecodable);
|
||||
Assert.NotEqual(DecodeTier.Unavailable, sidecar[index].Tier);
|
||||
}
|
||||
var rows = await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct);
|
||||
Assert.True(rows.All(f => (f.Flags & FrameFlags.Undecodable) == 0), "no frame flagged in the index");
|
||||
var unreadable = Advisor.Recommend(LightAnalyzer.Analyze(rows), report, SequenceContext.FromFrames(rows)).Findings
|
||||
.Single(f => f.Key == DeepFindingKeys.UnreadableFrames);
|
||||
Assert.SequenceEqual([3, 6], unreadable.Frames);
|
||||
|
||||
// Back in place and readable, the next pass reads both frames.
|
||||
fx.Decoder.Unreadable.Clear();
|
||||
await File.WriteAllBytesAsync(Path.Combine(fx.Folder(sequence).Folder, ProcessingFixture.FileName(3)),
|
||||
await File.ReadAllBytesAsync(Path.Combine(fx.Folder(sequence).Folder, ProcessingFixture.FileName(2)), fx.Ct), fx.Ct);
|
||||
var again = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
|
||||
await fx.WaitForAsync(again.Id, JobState.Done);
|
||||
Assert.Empty(SequenceAnalyser.ReadReport(fx.Folder(sequence), sequence.FrameCount)!.Issues.Undecodable);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AResumedDeepAnalysisDecodesAgainWhatTheEarlierRunCouldNotRead()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Flickering());
|
||||
// The first run cannot read frame 12 (held by another program) and is cancelled later, at frame 26.
|
||||
fx.Decoder.Unreadable[ProcessingFixture.FileName(11)] = 0;
|
||||
fx.Decoder.HoldFrame(25);
|
||||
await fx.StartEngineAsync();
|
||||
var job = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
|
||||
await fx.Decoder.Holding.Task.WaitAsync(TimeSpan.FromSeconds(60), fx.Ct);
|
||||
await fx.Engine.CancelAsync(job.Id, fx.Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Cancelled);
|
||||
|
||||
// Readable again; the resumed run takes frame 12 from its checkpoint (it is not in the region sample).
|
||||
fx.Decoder.Unreadable.Clear();
|
||||
fx.Decoder.Hold = null;
|
||||
while (fx.Decoder.Requests.TryDequeue(out _))
|
||||
{
|
||||
}
|
||||
await fx.Engine.ResumeAsync(job.Id, fx.Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
Assert.Contains(11, SequenceAnalyser.ReadReport(fx.Folder(sequence), sequence.FrameCount)!.Issues.Undecodable);
|
||||
// That verdict was a read error: decoding the frame again shows it is fine, so nothing flags it.
|
||||
Assert.Count(1, fx.Decoder.Requests.Where(r => Path.GetFileName(r.Path) == ProcessingFixture.FileName(11)));
|
||||
var frame = ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath).Frames[11];
|
||||
Assert.Equal((DecodeTier.Native, FrameFlags.None), (frame.Tier, frame.Flags & FrameFlags.Undecodable));
|
||||
Assert.Equal(FrameFlags.None, (await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct))[11].Flags);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeepAnalysisResumesAfterCancellationWithTheSameReport()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user