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
@@ -9,6 +9,7 @@ using Titano.Core.Imaging;
|
||||
using Titano.Core.Imaging.Decoders;
|
||||
using Titano.Core.Metadata;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Core.Tests.Analysis.Deep;
|
||||
using Titano.Core.Tests.Raw;
|
||||
using Titano.Testing;
|
||||
@@ -101,11 +102,12 @@ public sealed class DecodeTierTests(TestContext context)
|
||||
var dng = SyntheticDng.Write(scene, new DngSpec());
|
||||
var renderer = new FrameImageRenderer(DecoderFactory.CreateServer());
|
||||
|
||||
EncodedImage Thumbnail(string name, int previewWidth, bool sizeKnown)
|
||||
EncodedImage Thumbnail(string name, int previewWidth, bool sizeKnown, int? storedWidth = null)
|
||||
{
|
||||
// The preview is appended after the DNG, which the TIFF offsets never reach.
|
||||
var preview = TestPhotos.Jpeg(Start, 3, width: previewWidth, height: previewWidth * 3 / 4);
|
||||
File.WriteAllBytes(Path.Combine(sequence.Originals, name), [.. dng, .. preview]);
|
||||
var stored = storedWidth ?? previewWidth;
|
||||
var frame = new SidecarFrame
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
@@ -115,8 +117,8 @@ public sealed class DecodeTierTests(TestContext context)
|
||||
H = 480,
|
||||
PreviewOffset = dng.Length,
|
||||
PreviewLength = preview.Length,
|
||||
PreviewW = sizeKnown ? previewWidth : null,
|
||||
PreviewH = sizeKnown ? previewWidth * 3 / 4 : null,
|
||||
PreviewW = sizeKnown ? stored : null,
|
||||
PreviewH = sizeKnown ? stored * 3 / 4 : null,
|
||||
};
|
||||
return renderer.Thumbnail(sequence, frame)!;
|
||||
}
|
||||
@@ -126,6 +128,9 @@ public sealed class DecodeTierTests(TestContext context)
|
||||
Assert.Equal((320, 240, DecodeTier.Native), (small.Width, small.Height, small.Tier));
|
||||
var unknown = Thumbnail("unknown.dng", 200, sizeKnown: false);
|
||||
Assert.Equal((320, DecodeTier.Native), (unknown.Width, unknown.Tier));
|
||||
// The stored size can be a GPR companion's, larger than the embedded preview: the JPEG's own header decides.
|
||||
var companionSized = Thumbnail("companion.dng", 200, sizeKnown: true, storedWidth: 4000);
|
||||
Assert.Equal((320, DecodeTier.Native), (companionSized.Width, companionSized.Tier));
|
||||
var large = Thumbnail("large.dng", 400, sizeKnown: true);
|
||||
Assert.Equal((320, 240, DecodeTier.EmbeddedPreview), (large.Width, large.Height, large.Tier));
|
||||
Assert.Equal(320, JpegDecoder.ReadInfo(large.Jpeg).Width);
|
||||
@@ -177,22 +182,60 @@ public sealed class DecodeTierTests(TestContext context)
|
||||
[Test]
|
||||
public async Task FramesBothAnalysesFoundUndecodableAreListedOnce()
|
||||
{
|
||||
// Frame 4 does not decode; frame 7 is not read either (missing, or beyond this host), which never flags it.
|
||||
var source = new SyntheticFrameSource(SyntheticSequence.Create(new SyntheticSequenceOptions { Width = 96, Height = 64, FrameCount = 12 }))
|
||||
{
|
||||
Undecodable = [4],
|
||||
Undecodable = [4, 7],
|
||||
};
|
||||
var deep = await DeepAnalyzer.AnalyzeAsync(source, DeepScenes.Options);
|
||||
var metadata = Enumerable.Range(0, source.Count).Select(source.Metadata).ToList();
|
||||
var context = new SequenceContext { FrameCount = source.Count, SourceWidth = 96, SourceHeight = 64 };
|
||||
|
||||
// Before the deep pass flagged the frame, only its own finding names it.
|
||||
// Before the deep pass flagged the frame, only its own finding names them.
|
||||
var unflagged = Advisor.Recommend(LightAnalyzer.Analyze(metadata), deep, context).Findings.Where(f => f.Key == DeepFindingKeys.UnreadableFrames).ToList();
|
||||
Assert.SequenceEqual([4], unflagged.Single().Frames);
|
||||
Assert.SequenceEqual([4, 7], unflagged.Single().Frames);
|
||||
|
||||
// Once flagged, the light analysis lists it and the deep finding is not repeated.
|
||||
// Once frame 4 is flagged both analyses report it: one finding over both lists, counted once.
|
||||
var flagged = metadata.Select(m => m.Index == 4 ? m with { Flags = FrameFlags.Undecodable } : m).ToList();
|
||||
var light = LightAnalyzer.Analyze(flagged);
|
||||
var findings = Advisor.Recommend(light, deep, context).Findings.Where(f => f.Key == DeepFindingKeys.UnreadableFrames).ToList();
|
||||
Assert.Same(light.Findings.Single(f => f.Key == DeepFindingKeys.UnreadableFrames), findings.Single());
|
||||
Assert.SequenceEqual([4], light.Findings.Single(f => f.Key == DeepFindingKeys.UnreadableFrames).Frames);
|
||||
var merged = Advisor.Recommend(light, deep, context).Findings.Single(f => f.Key == DeepFindingKeys.UnreadableFrames);
|
||||
Assert.SequenceEqual([4, 7], merged.Frames);
|
||||
Assert.Equal((FindingSeverity.Warning, 2), (merged.Severity, Convert.ToInt32(merged.Arguments.Single())));
|
||||
|
||||
// A frame flagged since the deep pass (a render found it broken) joins the list too.
|
||||
var later = LightAnalyzer.Analyze(flagged.Select(m => m.Index == 9 ? m with { Flags = FrameFlags.Undecodable } : m).ToList());
|
||||
var all = Advisor.Recommend(later, deep, context).Findings.Single(f => f.Key == DeepFindingKeys.UnreadableFrames);
|
||||
Assert.Equal((3, 3), (all.Frames.Count, Convert.ToInt32(all.Arguments.Single())));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FramesTheCamerasIntervalometerShotTimeTheirGapsAdaptively()
|
||||
{
|
||||
var metadata = new FrameMetadata { Format = ImageFileFormat.Rw2, IntervalShooting = true };
|
||||
Assert.Equal(FrameFlags.Intervalometer, SequenceFrames.FromMetadata(Guid.CreateVersion7(), "a.rw2", "a.rw2", 10, null, metadata).Flags);
|
||||
Assert.Equal(FrameFlags.None, SequenceFrames.FromMetadata(Guid.CreateVersion7(), "b.rw2", "b.rw2", 10, null, metadata with { IntervalShooting = false }).Flags);
|
||||
|
||||
// 60 frames 10 s apart with one 40 s gap: a sparse gap alone keeps the timing constant (motion unmeasured).
|
||||
LightFrame Frame(int i, FrameFlags flags) => new()
|
||||
{
|
||||
Index = i,
|
||||
CapturedAt = Start.AddSeconds(10 * i + (i >= 30 ? 30 : 0)),
|
||||
Width = 6000,
|
||||
Height = 4000,
|
||||
Flags = flags,
|
||||
};
|
||||
var context = new SequenceContext { FrameCount = 60, SourceWidth = 6000, SourceHeight = 4000 };
|
||||
var plain = LightAnalyzer.Analyze([.. Enumerable.Range(0, 60).Select(i => Frame(i, FrameFlags.None))]);
|
||||
Assert.Equal(0, plain.IntervalometerFrames);
|
||||
var free = Advisor.Recommend(plain, null, context).Find(AdvisorParameters.TimingMode)!;
|
||||
Assert.Equal((AdvisorKeys.TimingSparseGaps, (object?)TimingMode.Constant), (free.ReasonKey, free.Value));
|
||||
|
||||
// The camera's own intervalometer shot them: its pause was deliberate, so adaptive timing keeps it short.
|
||||
var shot = LightAnalyzer.Analyze([.. Enumerable.Range(0, 60).Select(i => Frame(i, FrameFlags.Intervalometer))]);
|
||||
Assert.Equal(60, shot.IntervalometerFrames);
|
||||
var advice = Advisor.Recommend(shot, null, context).Find(AdvisorParameters.TimingMode)!;
|
||||
Assert.Equal((AdvisorKeys.TimingIntervalometer, (object?)TimingMode.Adaptive), (advice.ReasonKey, advice.Value));
|
||||
Assert.Equal(1, Convert.ToInt32(advice.ReasonArgs.Single()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user