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
@@ -1,9 +1,17 @@
|
||||
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;
|
||||
@@ -62,6 +70,207 @@ 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 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()
|
||||
{
|
||||
|
||||
@@ -123,18 +123,43 @@ internal sealed class GateDecoder : IImageDecoderProvider
|
||||
Hold = ProcessingFixture.FileName(index);
|
||||
}
|
||||
|
||||
/// <summary>Tiers <see cref="Probe(string, ImageFileFormat)"/> 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();
|
||||
|
||||
/// <summary>Files (by name) whose decodes report the embedded-preview tier from a preview of this oriented size, as
|
||||
/// a size-limited decode that picked a smaller preview would.</summary>
|
||||
public ConcurrentDictionary<string, (int Width, int Height)> PreviewDecodes { get; } = new();
|
||||
|
||||
/// <summary>Files (by name) that cannot be read: their decodes throw <see cref="IOException"/> (a sharing violation).</summary>
|
||||
public ConcurrentDictionary<string, byte> Unreadable { get; } = new();
|
||||
|
||||
/// <summary>File name and decoder of every decode that produced pixels.</summary>
|
||||
public ConcurrentQueue<(string File, string Decoder)> Decoded { get; } = new();
|
||||
|
||||
public DecodeTier? TierFor(ImageFileFormat format) => _managed.TierFor(format);
|
||||
|
||||
public FileTier Probe(string path, ImageFileFormat format) => Probe(path, format, null);
|
||||
|
||||
public FileTier Probe(string path, ImageFileFormat format, string? companion) =>
|
||||
Tiers.TryGetValue(Path.GetFileName(path), out var tier) ? tier : _managed.Probe(path, format, companion);
|
||||
|
||||
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Requests.Enqueue(request);
|
||||
if (Hold is { } hold && Path.GetFileName(request.Path) == hold && (HoldPurpose ?? request.Purpose) == request.Purpose
|
||||
var name = Path.GetFileName(request.Path);
|
||||
if (Hold is { } hold && name == hold && (HoldPurpose ?? request.Purpose) == request.Purpose
|
||||
&& (HoldEdge ?? request.MaxLongEdge) == request.MaxLongEdge)
|
||||
{
|
||||
Holding.TrySetResult();
|
||||
cancellationToken.WaitHandle.WaitOne(TimeSpan.FromSeconds(30));
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
return _managed.Decode(request, cancellationToken);
|
||||
if (Unreadable.ContainsKey(name)) throw new IOException($"The process cannot access the file '{request.Path}' because it is being used by another process.");
|
||||
var decoded = _managed.Decode(request, cancellationToken);
|
||||
if (decoded is null) return null;
|
||||
Decoded.Enqueue((name, decoded.Decoder));
|
||||
if (!PreviewDecodes.TryGetValue(name, out var preview)) return decoded;
|
||||
return new DecodedImage(decoded.Pixels, DecodeTier.EmbeddedPreview, "test-preview", preview.Width, preview.Height);
|
||||
}
|
||||
}
|
||||
@@ -113,18 +113,148 @@ 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 AFrameThatCannotBeReadIsShownAsItsNeighbourButNeverFlagged()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
// Another program holds the file during the render (antivirus, backup): a read error says nothing about the file.
|
||||
fx.Decoder.Unreadable[ProcessingFixture.FileName(10)] = 0;
|
||||
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);
|
||||
var sidecar = Titano.Core.Archiving.ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath);
|
||||
Assert.Equal(FrameFlags.None, sidecar.Frames[10].Flags & FrameFlags.Undecodable);
|
||||
Assert.NotEqual(DecodeTier.Unavailable, sidecar.Frames[10].Tier);
|
||||
Assert.False(sidecar.Status.HasFlag(SequenceStatus.HasWarnings), "no warning");
|
||||
Assert.Equal(FrameFlags.None, (await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct))[10].Flags);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASmallRenderKeepsTheStoredSizeOfTheLargestPreview()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
// A CR3 on the server: the probe finds its full-size 6000×4000 preview, which caps the output.
|
||||
for (var i = 0; i < Frames; i++)
|
||||
fx.Decoder.Tiers[ProcessingFixture.FileName(i)] = new FileTier(ImageFileFormat.Jpeg, DecodeTier.EmbeddedPreview, "test-preview", "test", 6000, 4000);
|
||||
await fx.StartEngineAsync();
|
||||
var light = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([sequence.Id]));
|
||||
await fx.WaitForAsync(light.Id, JobState.Done);
|
||||
var probed = Titano.Core.Archiving.ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath).Frames[3];
|
||||
Assert.Equal((FrameFlags.PreviewOnly, (int?)6000, (int?)4000), (probed.Flags, probed.PreviewW, probed.PreviewH));
|
||||
|
||||
// A small render decodes the smallest preview that reaches its size (1620×1080): that is not the largest.
|
||||
for (var i = 0; i < Frames; i++) fx.Decoder.PreviewDecodes[ProcessingFixture.FileName(i)] = (1620, 1080);
|
||||
var job = await fx.EnqueueAsync(ProcessingJobs.Render(sequence, Mjpeg, 96, 64));
|
||||
await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var frames = Titano.Core.Archiving.ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath).Frames;
|
||||
Assert.True(frames.All(f => f is { Tier: DecodeTier.EmbeddedPreview, PreviewW: 6000, PreviewH: 4000 }), "sidecar preview sizes kept");
|
||||
var rows = await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct);
|
||||
Assert.True(rows.All(f => (f.PreviewWidth, f.PreviewHeight) == (6000, 4000)), "index preview sizes kept");
|
||||
Assert.Equal((6000, 4000), (Titano.Core.Advice.SequenceContext.FromFrames(rows).PreviewWidth, Titano.Core.Advice.SequenceContext.FromFrames(rows).PreviewHeight));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FramesARenderNodeReceivesKeepTheirTierFields()
|
||||
{
|
||||
var dto = new Titano.Protocol.FrameDto(Guid.CreateVersion7(), Guid.CreateVersion7(), 3, "IMG_0004.CR3", 25_000_000, new string('a', 64),
|
||||
new DateTime(2026, 9, 28, 18, 0, 20), 120, 1.0 / 250, 8, 100, 24, 6, 6000, 4000, "cr3",
|
||||
(long)(FrameFlags.PreviewOnly | FrameFlags.Intervalometer), 1620, 1080);
|
||||
|
||||
var frame = RenderNodeClient.ToFrame(dto);
|
||||
Assert.Equal((ImageFileFormat.Cr3, FrameFlags.PreviewOnly | FrameFlags.Intervalometer, 1620, 1080),
|
||||
(frame.Format, frame.Flags, frame.PreviewWidth, frame.PreviewHeight));
|
||||
// The node's advisor caps a portrait sequence at its previews, oriented like the main image.
|
||||
var tiers = Titano.Core.Advice.SequenceContext.FromFrames([frame]);
|
||||
Assert.Equal((1, 1080, 1620), (tiers.PreviewOnlyCount, tiers.PreviewWidth, tiers.PreviewHeight));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OnlyFramesTheRenderShowsGetAStandIn()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
foreach (var i in new[] { 1, 3 })
|
||||
await File.WriteAllBytesAsync(Path.Combine(fx.Archive.Paths.Root, "Synthetic", ProcessingFixture.FileName(i)), new byte[5000], fx.Ct);
|
||||
var decoder = new ImageDecoder([fx.Decoder]);
|
||||
var frames = await SequenceFrames.LoadAsync(fx.Db, fx.Archive.Archive, sequence, useProxies: false, decoder, fx.Ct);
|
||||
|
||||
// A plan that skips the odd frames (a speed-up): the read-ahead meets frames 1 and 3, the pipeline never asks.
|
||||
var source = new SequenceFrameSource(frames, frames.LightFrames(), decoder, new FrameWindowOptions { Ahead = 4 })
|
||||
{
|
||||
Originals = true,
|
||||
RenderExcluded = new HashSet<int>(),
|
||||
};
|
||||
await using (source)
|
||||
{
|
||||
foreach (var index in new[] { 0, 2, 4, 6 })
|
||||
{
|
||||
using var frame = await source.GetFrameAsync(index, 64, DecodePurpose.Render, fx.Ct);
|
||||
Assert.Equal(64, frame.Width);
|
||||
}
|
||||
// The read-ahead decodes in the background: wait until it has met frame 4 (index 3).
|
||||
for (var waited = 0; !source.Observed.ContainsKey(3) && waited < 200; waited++) await Task.Delay(50, fx.Ct);
|
||||
}
|
||||
Assert.Equal(DecodeTier.Unavailable, source.Observed[3].Tier);
|
||||
Assert.Empty(source.StandIns);
|
||||
|
||||
// Asked for, a damaged frame shows its neighbour and is listed.
|
||||
await using var asked = new SequenceFrameSource(frames, frames.LightFrames(), new ImageDecoder([fx.Decoder]))
|
||||
{
|
||||
RenderExcluded = new HashSet<int>(),
|
||||
};
|
||||
using (var standIn = await asked.GetFrameAsync(3, 64, DecodePurpose.Render, fx.Ct))
|
||||
Assert.Equal(64, standIn.Width);
|
||||
Assert.SequenceEqual([3], asked.StandIns);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARenderInterruptedByACrashStartsItsOutputAgainCleanly()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user