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:
48 files changed
+1132
-87
No files matched your search
@@ -88,6 +88,60 @@ public sealed class ArchiveJobTests(TestContext context)
|
||||
Assert.Contains("3 made, 3 reused", done.LogTail);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AThumbnailPassFlagsFramesNothingDecodesAndClearsThemOnceTheyDecode()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var files = Photos.WriteSeries(Path.Combine(fx.Paths.Root, "a"), Start, 6);
|
||||
await fx.ScanAsync();
|
||||
var a = (await LocationsAsync(fx))[0];
|
||||
var sequence = (await fx.Db.Sequences.GetAsync(a.Id))!;
|
||||
var paths = fx.Paths.Sequence(a.Folder);
|
||||
var original = await File.ReadAllBytesAsync(files[2], fx.Ct);
|
||||
await File.WriteAllBytesAsync(files[2], new byte[original.Length], fx.Ct);
|
||||
|
||||
var result = await fx.Service.Images.BuildThumbnailsAsync(fx.Archive, sequence, false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
|
||||
|
||||
Assert.Equal((5, 1), (result.Built, result.Undecodable));
|
||||
var frame = ManifestStore.ReadSequence(paths.ManifestPath).Frames[2];
|
||||
Assert.Equal((Titano.Core.Imaging.DecodeTier.Unavailable, FrameFlags.Undecodable), (frame.Tier, frame.Flags));
|
||||
Assert.Equal(FrameFlags.Undecodable, (await fx.Db.Frames.ListBySequenceAsync(a.Id))[2].Flags);
|
||||
Assert.True((await fx.Db.Sequences.GetAsync(a.Id))!.Status.HasFlag(SequenceStatus.HasWarnings), "the sequence warns at once");
|
||||
|
||||
// Restored from a copy: the next pass decodes the frame and clears the flag; the others are reused.
|
||||
await File.WriteAllBytesAsync(files[2], original, fx.Ct);
|
||||
result = await fx.Service.Images.BuildThumbnailsAsync(fx.Archive, sequence, false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
|
||||
Assert.Equal((1, 5, 0), (result.Built, result.Reused, result.Undecodable));
|
||||
frame = ManifestStore.ReadSequence(paths.ManifestPath).Frames[2];
|
||||
Assert.Equal((Titano.Core.Imaging.DecodeTier.Native, FrameFlags.None), (frame.Tier, frame.Flags));
|
||||
Assert.Equal(FrameFlags.None, (await fx.Db.Frames.ListBySequenceAsync(a.Id))[2].Flags);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AHostWithoutADecoderForTheFormatRecordsTheTierWithoutFlaggingTheFrames()
|
||||
{
|
||||
// The fixture's decoder chain is empty: only JPEG decodes here (its decoder is built in), PNG does not.
|
||||
await using var fx = await CreateAsync(context);
|
||||
var folder = Path.Combine(fx.Paths.Root, "p");
|
||||
Directory.CreateDirectory(folder);
|
||||
using (var image = new Titano.Core.Imaging.ImageBuffer(32, 24))
|
||||
{
|
||||
for (var i = 0; i < 3; i++) File.WriteAllBytes(Path.Combine(folder, $"P{i}.png"), Titano.Core.Codecs.Png.PngEncoder.Encode(image));
|
||||
}
|
||||
await fx.ScanAsync();
|
||||
var p = (await LocationsAsync(fx)).Single();
|
||||
|
||||
var result = await fx.Service.Images.BuildThumbnailsAsync(fx.Archive, (await fx.Db.Sequences.GetAsync(p.Id))!, false, 0,
|
||||
(_, _) => ValueTask.CompletedTask, fx.Ct);
|
||||
|
||||
// Another host (or a proxy) may still provide the pixels: the tier is recorded, the frames stay renderable.
|
||||
Assert.Equal(3, result.Undecodable);
|
||||
var frames = ManifestStore.ReadSequence(fx.Paths.Sequence(p.Folder).ManifestPath).Frames;
|
||||
Assert.True(frames.All(f => f.Tier == Titano.Core.Imaging.DecodeTier.Unavailable && f.Flags == FrameFlags.None), "tier without flag");
|
||||
Assert.True((await fx.Db.Frames.ListBySequenceAsync(p.Id)).All(f => f.Flags == FrameFlags.None), "index flags");
|
||||
Assert.False((await fx.Db.Sequences.GetAsync(p.Id))!.Status.HasFlag(SequenceStatus.HasWarnings), "no warning");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AMaintenanceJobResumesAfterItsDoneSteps()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using Titano.Core.Advice;
|
||||
using Titano.Core.Analysis;
|
||||
using Titano.Core.Analysis.Deep;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Diagnostics.Synthetic;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
@@ -62,6 +65,75 @@ public sealed class AnalysisJobTests(TestContext context)
|
||||
Assert.Equal(version, (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!.SettingsVersion);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task LightAnalysisRecordsFormatTiersAndTheAdvisorCapsTheOutputAtThePreviews()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Flickering(12));
|
||||
// This host reads the first ten files only through 48×32 embedded previews and cannot decode the last one.
|
||||
for (var i = 0; i < 10; i++)
|
||||
fx.Decoder.Tiers[ProcessingFixture.FileName(i)] = new FileTier(ImageFileFormat.Jpeg, DecodeTier.EmbeddedPreview, "test-preview", "test", 48, 32);
|
||||
fx.Decoder.Tiers[ProcessingFixture.FileName(11)] = new FileTier(ImageFileFormat.Jpeg, DecodeTier.Unavailable, null, "test", 0, 0);
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var job = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([sequence.Id]));
|
||||
await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var folder = fx.Folder(sequence);
|
||||
var sidecar = ManifestStore.ReadSequence(folder.ManifestPath).Frames;
|
||||
Assert.Equal((DecodeTier.EmbeddedPreview, FrameFlags.PreviewOnly, (int?)48, (int?)32), (sidecar[0].Tier, sidecar[0].Flags, sidecar[0].PreviewW, sidecar[0].PreviewH));
|
||||
Assert.Equal((DecodeTier.Native, FrameFlags.None), (sidecar[10].Tier, sidecar[10].Flags));
|
||||
Assert.Equal((DecodeTier.Unavailable, FrameFlags.Undecodable), (sidecar[11].Tier, sidecar[11].Flags));
|
||||
var rows = await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct);
|
||||
Assert.Equal((FrameFlags.PreviewOnly, 48, 32), (rows[3].Flags, rows[3].PreviewWidth, rows[3].PreviewHeight));
|
||||
Assert.Equal(FrameFlags.Undecodable, rows[11].Flags);
|
||||
var row = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
|
||||
Assert.Equal(10, row.PreviewOnlyCount);
|
||||
Assert.GreaterOrEqual(row.WarningCount, 1);
|
||||
Assert.True(row.Status.HasFlag(SequenceStatus.HasWarnings), "the undecodable frame is a sequence warning");
|
||||
|
||||
// The advisor reads the preview size from the index and caps the output there (BRIEF §8.2 tier 2).
|
||||
var tiers = SequenceContext.FromFrames(rows);
|
||||
Assert.Equal((10, 48, 32), (tiers.PreviewOnlyCount, tiers.PreviewWidth, tiers.PreviewHeight));
|
||||
var light = LightAnalyzer.Analyze(rows);
|
||||
var advice = Advisor.Recommend(light, null, tiers);
|
||||
Assert.Equal(AdvisorKeys.ResolutionPreview, advice.Find(AdvisorParameters.Resolution)!.ReasonKey);
|
||||
Assert.Contains(advice.Findings, f => f.Key == FindingKeys.PreviewOnly && Equals(f.Arguments[0], 10));
|
||||
Assert.Contains(advice.Findings, f => f.Key == DeepFindingKeys.UnreadableFrames && f.Frames.SequenceEqual([11]));
|
||||
|
||||
// Probed once: a second pass opens no file for its tier and leaves the sidecar alone.
|
||||
fx.Decoder.Tiers.Clear();
|
||||
var written = File.GetLastWriteTimeUtc(folder.ManifestPath);
|
||||
var again = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([sequence.Id]));
|
||||
await fx.WaitForAsync(again.Id, JobState.Done);
|
||||
Assert.Equal(FrameFlags.PreviewOnly, ManifestStore.ReadSequence(folder.ManifestPath).Frames[0].Flags);
|
||||
Assert.Equal(written, File.GetLastWriteTimeUtc(folder.ManifestPath));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeepAnalysisFlagsFramesItCannotDecodeAndListsThemOnce()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Flickering(12));
|
||||
// Damaged after indexing: the header probe still says JPEG, only decoding finds out.
|
||||
await File.WriteAllBytesAsync(Path.Combine(fx.Folder(sequence).Folder, ProcessingFixture.FileName(4)), new byte[3000], fx.Ct);
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var job = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
|
||||
var done = await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var sidecar = ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath).Frames;
|
||||
Assert.Equal((DecodeTier.Unavailable, FrameFlags.Undecodable), (sidecar[4].Tier, sidecar[4].Flags));
|
||||
Assert.Equal(DecodeTier.Native, sidecar[5].Tier);
|
||||
Assert.Equal(FrameFlags.Undecodable, (await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct))[4].Flags);
|
||||
var report = SequenceAnalyser.ReadReport(fx.Folder(sequence), sequence.FrameCount)!;
|
||||
var rows = await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct);
|
||||
var findings = Advisor.Recommend(LightAnalyzer.Analyze(rows), report, SequenceContext.FromFrames(rows)).Findings;
|
||||
Assert.Count(1, findings.Where(f => f.Key == DeepFindingKeys.UnreadableFrames));
|
||||
Assert.True((await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!.WarningCount >= 1, "listed in the sequence warnings");
|
||||
Assert.Equal(JobState.Done, done.State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeepAnalysisResumesAfterCancellationWithTheSameReport()
|
||||
{
|
||||
|
||||
@@ -123,8 +123,15 @@ internal sealed class GateDecoder : IImageDecoderProvider
|
||||
Hold = ProcessingFixture.FileName(index);
|
||||
}
|
||||
|
||||
/// <summary>Tiers <see cref="Probe"/> reports per file name instead of the managed provider's (a host that reads them
|
||||
/// only as previews, or not at all).</summary>
|
||||
public ConcurrentDictionary<string, FileTier> Tiers { get; } = new();
|
||||
|
||||
public DecodeTier? TierFor(ImageFileFormat format) => _managed.TierFor(format);
|
||||
|
||||
public FileTier Probe(string path, ImageFileFormat format) =>
|
||||
Tiers.TryGetValue(Path.GetFileName(path), out var tier) ? tier : _managed.Probe(path, format);
|
||||
|
||||
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Requests.Enqueue(request);
|
||||
|
||||
@@ -86,18 +86,48 @@ public sealed class RenderJobTests(TestContext context)
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
// Damaged after indexing: nothing flags the frame, so only decoding finds out.
|
||||
await File.WriteAllBytesAsync(Path.Combine(fx.Archive.Paths.Root, "Synthetic", ProcessingFixture.FileName(10)), new byte[5000], fx.Ct);
|
||||
// Every file damaged after indexing: nothing flags them, and no frame can stand in for another.
|
||||
for (var i = 0; i < Frames; i++)
|
||||
await File.WriteAllBytesAsync(Path.Combine(fx.Archive.Paths.Root, "Synthetic", ProcessingFixture.FileName(i)), new byte[5000], fx.Ct);
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var job = await fx.EnqueueAsync(ProcessingJobs.Render(sequence, Mjpeg, 96, 64));
|
||||
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Equal(Loc.L(SequenceFrameSource.FrameUnreadableKey, "11", ProcessingFixture.FileName(10)), failed.Error);
|
||||
Assert.Equal(Loc.L(SequenceFrameSource.FrameUnreadableKey, "1", ProcessingFixture.FileName(0)), failed.Error);
|
||||
Assert.Empty(Entries(fx.Folder(sequence).Exports));
|
||||
Assert.Empty(await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFrameThatNoLongerDecodesIsReplacedByItsNeighbourAndLeftOutNextTime()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
// Damaged after indexing: nothing flags the frame, so only decoding finds out (BRIEF §8.2 tier 3).
|
||||
await File.WriteAllBytesAsync(Path.Combine(fx.Archive.Paths.Root, "Synthetic", ProcessingFixture.FileName(10)), new byte[5000], fx.Ct);
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var job = await fx.EnqueueAsync(ProcessingJobs.Render(sequence, Mjpeg, 96, 64));
|
||||
var done = await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
Assert.Contains(Loc.L("Export.Log.StandIns", "11"), done.LogTail);
|
||||
Assert.SequenceEqual(["clip-MJPEG.avi"], Entries(fx.Folder(sequence).Exports));
|
||||
var row = (await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct))[10];
|
||||
Assert.Equal(FrameFlags.Undecodable, row.Flags);
|
||||
var sidecar = Titano.Core.Archiving.ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath);
|
||||
Assert.Equal((DecodeTier.Unavailable, FrameFlags.Undecodable), (sidecar.Frames[10].Tier, sidecar.Frames[10].Flags));
|
||||
Assert.Equal(DecodeTier.Native, sidecar.Frames[9].Tier);
|
||||
Assert.True(sidecar.Status.HasFlag(SequenceStatus.HasWarnings), "the sequence warns at once");
|
||||
Assert.True((await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!.Status.HasFlag(SequenceStatus.HasWarnings), "index status");
|
||||
|
||||
// The next render plans without the frame, so nothing has to stand in for it.
|
||||
var again = await fx.EnqueueAsync(ProcessingJobs.Render(sequence, Mjpeg, 96, 64));
|
||||
var second = await fx.WaitForAsync(again.Id, JobState.Done);
|
||||
Assert.False(second.LogTail?.Contains(Loc.L("Export.Log.StandIns", "11"), StringComparison.Ordinal) == true, "no stand-in");
|
||||
Assert.Count(2, await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARenderInterruptedByACrashStartsItsOutputAgainCleanly()
|
||||
{
|
||||
|
||||
@@ -51,6 +51,7 @@ public abstract class CatalogRepositoryTests(TestContext context) : RepositoryTe
|
||||
FramesVersion = 7,
|
||||
OwnerUserId = Guid.CreateVersion7(),
|
||||
WarningCount = 2,
|
||||
PreviewOnlyCount = 1150,
|
||||
Tags = ["Sunset", "harbour", "SUNSET"],
|
||||
};
|
||||
await db.Sequences.UpsertAsync(sequence, Ct);
|
||||
@@ -248,6 +249,8 @@ public abstract class CatalogRepositoryTests(TestContext context) : RepositoryTe
|
||||
Orientation = 6,
|
||||
PreviewOffset = 1024,
|
||||
PreviewLength = 65536,
|
||||
PreviewWidth = 1620,
|
||||
PreviewHeight = 1080,
|
||||
MeanLogLuminance = -2.5,
|
||||
ClipLow = 0.01,
|
||||
ClipHigh = 0.02,
|
||||
@@ -307,6 +310,27 @@ public abstract class CatalogRepositoryTests(TestContext context) : RepositoryTe
|
||||
Assert.Equal(1200, await db.Frames.DeleteBySequenceAsync(sequence.Id, Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FrameTiersUpdateInBulkAndSurviveASyncFromTheSidecar()
|
||||
{
|
||||
var db = await OpenTitanoAsync();
|
||||
var archive = TestData.Archive();
|
||||
await db.Archives.UpsertAsync(archive, Ct);
|
||||
var sequence = TestData.Sequence(archive.Id);
|
||||
await db.Sequences.UpsertAsync(sequence, Ct);
|
||||
var frames = Enumerable.Range(0, 40).Select(i => TestData.Frame(sequence.Id, i) with { Flags = FrameFlags.Duplicate }).ToList();
|
||||
await db.Frames.BulkInsertAsync(frames, Ct);
|
||||
|
||||
var tiers = frames.Select(f => new FrameTierFields(f.Id, f.Index % 2 == 0 ? FrameFlags.PreviewOnly : FrameFlags.Undecodable, 1620 + f.Index, 1080)).ToList();
|
||||
Assert.Equal(40, await db.Frames.UpdateTiersAsync(tiers, Ct));
|
||||
var read = await db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: Ct);
|
||||
Assert.SequenceEqual(tiers.Select(t => (t.Flags, t.PreviewWidth, t.PreviewHeight)), read.Select(f => (f.Flags, f.PreviewWidth, f.PreviewHeight)));
|
||||
|
||||
// A sync from the sidecar writes the tier fields like every other one.
|
||||
await db.Frames.SyncSequenceAsync(sequence.Id, [.. read.Select(f => f with { PreviewWidth = 4, PreviewHeight = 3, Flags = FrameFlags.None })], Ct);
|
||||
Assert.True((await db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: Ct)).All(f => (f.Flags, f.PreviewWidth, f.PreviewHeight) == (FrameFlags.None, 4, 3)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RendersKeepTheSequenceCountInStep()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user