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
@@ -29,7 +29,7 @@ Dependencies point one way: `Core` ← `Core.Windows`, `Data`, `Protocol` ← `S
|
||||
|
||||
| Folder / namespace | Content |
|
||||
|---|---|
|
||||
| `Imaging` (+ `Decoders`, `Geometry`, `Thumbnails`) | `ImageBuffer` (planar float, linear light), `IImageDecoderProvider`, `DecoderFactory` (decode tiers: native → embedded preview), `ManagedDecoderProvider`, `FrameWindow` (read-ahead, memory budget, float32 spill), resampler, thumbnail cache |
|
||||
| `Imaging` (+ `Decoders`, `Geometry`, `Thumbnails`) | `ImageBuffer` (planar float, linear light), `IImageDecoderProvider`, `DecoderFactory` (decode tiers: native → embedded preview; `ImageDecoder.Probe` names a file's tier without decoding it), `ManagedDecoderProvider`, `FrameWindow` (read-ahead, memory budget, float32 spill), resampler, thumbnail cache |
|
||||
| `Metadata` (+ `Tiff`, `Jpeg`, `Bmff`, `Raf`, `Riff`, `Png`, `Xmp`, `MakerNotes`) | Signature sniffing, Exif/GPS/XMP/MakerNotes, ISO-BMFF (HEIF, CR3), `MetadataReader`, `MetadataBuilder` (all fallback chains), `ExifWriter` |
|
||||
| `Codecs` (`Jpeg`, `Png`, `Tiff`, `Dng`, `Raw`, `Gif`, `Apng`, `Ico`) | Pure managed codecs; native RAW development (DNG, CR2, NEF, ARW, PEF, RAF) |
|
||||
| `Analysis` (+ `Deep`) | Luminance statistics, deflicker, regions, holy grail, white balance, colour temperature, light analysis, streaming deep analysis with checkpoints |
|
||||
@@ -56,7 +56,7 @@ Dependencies point one way: `Core` ← `Core.Windows`, `Data`, `Protocol` ← `S
|
||||
| `Migrations/{sqlite,postgres}/NNNN_name.sql` | Embedded, applied in one transaction at open (`MigrationRunner`) |
|
||||
| `Repositories` | `TitanoDatabase` facade: archives, sequences, frames, tags, renders, jobs, cards, users, tokens, uploads, render nodes, settings, audit |
|
||||
| `Jobs` | `JobEngine`, `IJobHandler`, `IJobHandlerProvider`, `JobContext` (progress, checkpoints, follow-up jobs) |
|
||||
| `Archiving` | `ArchiveService` (create/adopt/open), `ArchiveIndexer` (scan, rebuild), `ArchiveIngest` (uploads and imports), `ImportService`, `ArchiveVerifier`, `ArchiveImages`, `ArchiveMaintenance`, `MassRenamer`, `SequenceTrash` (delete into the archive's hidden trash with a dry run, restore; the folder moves back when the index step fails), job handlers |
|
||||
| `Archiving` | `ArchiveService` (create/adopt/open), `ArchiveIndexer` (scan, rebuild), `ArchiveIngest` (uploads and imports), `ImportService`, `ArchiveVerifier`, `ArchiveImages`, `FrameTiers` (decode tier, `PreviewOnly`/`Undecodable` flags and preview size of frames, written to sidecar and index by the light analysis, deep analysis, renders and image passes), `ArchiveMaintenance`, `MassRenamer`, `SequenceTrash` (delete into the archive's hidden trash with a dry run, restore; the folder moves back when the index step fails), job handlers |
|
||||
| `Processing` | `ProcessingService`, `SequenceAnalyser`, `SequenceRender`, `ProjectStore`, `RenderNodeClient`, job handlers |
|
||||
| `Sync` | `SyncService` (sync table of one server: compare, link by content, settle conflicts, enqueue transfers), `SyncRules` (status, settings merge and differences, no I/O), `SyncLinkStore` (`sync_links`, `sync_state`), `SyncTransfers` and `SyncJobHandler` (resumable, hash-verified uploads and downloads as jobs; downloads commit through the archive ingest), `SyncAgent` (background comparison, server events, backoff, offline proxies), `ProxyCache` and `RemoteSequence` (server sequences opened with proxies), `ISyncRemote` (the server calls; `TitanoSyncRemote` over `TitanoClient`) |
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<data name="Advisor.Finding.NoTimestamps" xml:space="preserve"><value>Only {0} of {1} frames have a capture time, so cadence and gaps cannot be measured.</value><comment>{0} frames with a capture time; {1} frames in total</comment></data>
|
||||
<data name="Advisor.Finding.NonMonotonicTimestamps" xml:space="preserve"><value>{0} frames are out of time order.</value><comment>{0} frame count</comment></data>
|
||||
<data name="Advisor.Finding.Panning" xml:space="preserve"><value>The view drifts by {0:0.##} px per frame (pan or slider).</value><comment>{0} drift in source pixels per frame</comment></data>
|
||||
<data name="Advisor.Finding.PreviewOnly" xml:space="preserve"><value>Frames decoding only from their embedded preview: {0}.</value><comment>{0} frame count</comment></data>
|
||||
<data name="Advisor.Finding.SceneChanges" xml:space="preserve"><value>The view jumps at {0} frames (camera moved or bumped).</value><comment>{0} frame count</comment></data>
|
||||
<data name="Advisor.Finding.Sessions" xml:space="preserve"><value>Shot in {0} separate sessions.</value><comment>{0} session count</comment></data>
|
||||
<data name="Advisor.Finding.Shake" xml:space="preserve"><value>The camera shakes by {0:0.##} px RMS; hiding it costs {1:0.#}% of the frame.</value><comment>{0} shake RMS in source pixels; {1} crop cost in percent of the area</comment></data>
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
<data name="Export.Log.Failed" xml:space="preserve"><value>{0} failed: {1}</value><comment>long: job log line; {0} preset name; {1} reason</comment></data>
|
||||
<data name="Export.Log.NoRenderNode" xml:space="preserve"><value>No render node can encode {1}; {0} is rendered as {2} instead.</value><comment>long: job log line; {0} preset name; {1} codec asked for; {2} managed codec used</comment></data>
|
||||
<data name="Export.Log.Rendered" xml:space="preserve"><value>{0} saved as {1}</value><comment>long: job log line; {0} preset name; {1} output file name</comment></data>
|
||||
<data name="Export.Log.StandIns" xml:space="preserve"><value>Undecodable frames shown as a neighbour: {0}.</value><comment>long: job log line; {0} frame numbers from 1, comma-separated</comment></data>
|
||||
<data name="Export.Plan.FrameRateIgnored" xml:space="preserve"><value>Playback rate not understood; the export frame rate is used.</value><comment>long</comment></data>
|
||||
<data name="Export.Plan.NoCaptureTimes" xml:space="preserve"><value>No capture times: frames are spaced evenly.</value><comment>long</comment></data>
|
||||
<data name="Export.Plan.NoFrames" xml:space="preserve"><value>Every frame is excluded.</value><comment>long</comment></data>
|
||||
|
||||
@@ -399,6 +399,8 @@
|
||||
<data name="Tooltips.Library.Status.LocalAhead" xml:space="preserve"><value>This PC has originals or settings the server does not have yet</value></data>
|
||||
<data name="Tooltips.Library.Status.NoProxies" xml:space="preserve"><value>No proxies yet; editing reads the originals</value></data>
|
||||
<data name="Tooltips.Library.Status.NotAnalysed" xml:space="preserve"><value>Not analysed yet</value></data>
|
||||
<data name="Tooltips.Library.Status.PreviewOnly.one" xml:space="preserve"><value>{0:N0} frame decodes only from its embedded preview; renders are capped at its size</value></data>
|
||||
<data name="Tooltips.Library.Status.PreviewOnly.other" xml:space="preserve"><value>{0:N0} frames decode only from their embedded previews; renders are capped at their size</value></data>
|
||||
<data name="Tooltips.Library.Status.Proxies" xml:space="preserve"><value>JPEG proxies built for fast editing</value></data>
|
||||
<data name="Tooltips.Library.Status.Remote" xml:space="preserve"><value>Lives on the server; this PC has proxies at most</value></data>
|
||||
<data name="Tooltips.Library.Status.Rendered.one" xml:space="preserve"><value>Rendered once</value></data>
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<data name="Advisor.Finding.NoTimestamps" xml:space="preserve"><value>Solo {0} fotogrammi su {1} hanno un orario di scatto: cadenza e pause non sono misurabili.</value></data>
|
||||
<data name="Advisor.Finding.NonMonotonicTimestamps" xml:space="preserve"><value>{0} fotogrammi sono fuori ordine temporale.</value></data>
|
||||
<data name="Advisor.Finding.Panning" xml:space="preserve"><value>L'inquadratura scorre di {0:0.##} px per fotogramma (panoramica o slider).</value></data>
|
||||
<data name="Advisor.Finding.PreviewOnly" xml:space="preserve"><value>Fotogrammi decodificati solo dall'anteprima incorporata: {0}.</value></data>
|
||||
<data name="Advisor.Finding.SceneChanges" xml:space="preserve"><value>L'inquadratura salta in {0} fotogrammi (fotocamera spostata o urtata).</value></data>
|
||||
<data name="Advisor.Finding.Sessions" xml:space="preserve"><value>Ripreso in {0} sessioni separate.</value></data>
|
||||
<data name="Advisor.Finding.Shake" xml:space="preserve"><value>La fotocamera vibra di {0:0.##} px RMS; compensarla costa il {1:0.#}% dell'inquadratura.</value></data>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<data name="Export.Log.Failed" xml:space="preserve"><value>{0} non riuscito: {1}</value></data>
|
||||
<data name="Export.Log.NoRenderNode" xml:space="preserve"><value>Nessun nodo di rendering può codificare {1}; {0} viene esportato in {2}.</value></data>
|
||||
<data name="Export.Log.Rendered" xml:space="preserve"><value>{0} salvato come {1}</value></data>
|
||||
<data name="Export.Log.StandIns" xml:space="preserve"><value>Fotogrammi non decodificabili sostituiti da un vicino: {0}.</value></data>
|
||||
<data name="Export.Plan.FrameRateIgnored" xml:space="preserve"><value>Velocità di riproduzione non valida; viene usata la frequenza di esportazione.</value></data>
|
||||
<data name="Export.Plan.NoCaptureTimes" xml:space="preserve"><value>Nessun orario di scatto: fotogrammi distribuiti in modo uniforme.</value></data>
|
||||
<data name="Export.Plan.NoFrames" xml:space="preserve"><value>Tutti i fotogrammi sono esclusi.</value></data>
|
||||
|
||||
@@ -399,6 +399,8 @@
|
||||
<data name="Tooltips.Library.Status.LocalAhead" xml:space="preserve"><value>Questo PC ha originali o impostazioni che il server non ha ancora</value></data>
|
||||
<data name="Tooltips.Library.Status.NoProxies" xml:space="preserve"><value>Ancora nessun proxy; la modifica legge gli originali</value></data>
|
||||
<data name="Tooltips.Library.Status.NotAnalysed" xml:space="preserve"><value>Non ancora analizzata</value></data>
|
||||
<data name="Tooltips.Library.Status.PreviewOnly.one" xml:space="preserve"><value>{0:N0} fotogramma si decodifica solo dall'anteprima incorporata; i render sono limitati alla sua dimensione</value></data>
|
||||
<data name="Tooltips.Library.Status.PreviewOnly.other" xml:space="preserve"><value>{0:N0} fotogrammi si decodificano solo dalle anteprime incorporate; i render sono limitati alla loro dimensione</value></data>
|
||||
<data name="Tooltips.Library.Status.Proxies" xml:space="preserve"><value>Proxy JPEG pronti per una modifica veloce</value></data>
|
||||
<data name="Tooltips.Library.Status.Remote" xml:space="preserve"><value>Si trova sul server; questo PC ne ha al massimo i proxy</value></data>
|
||||
<data name="Tooltips.Library.Status.Rendered.one" xml:space="preserve"><value>Esportata una volta</value></data>
|
||||
|
||||
@@ -456,7 +456,7 @@ public sealed class SampleData
|
||||
var now = new DateTime(2026, 9, 28, 18, 2, 11);
|
||||
(Sequence, string[], bool) Make(string? title, string folder, string make, string model, int frames, TimeSpan span, double interval, int daysAgo,
|
||||
SequenceStatus status, string[] colours, int renders = 0, int warnings = 0, SequenceOrigin origin = SequenceOrigin.Local,
|
||||
SyncState sync = SyncState.LocalOnly, bool raw = false)
|
||||
SyncState sync = SyncState.LocalOnly, bool raw = false, int previewOnly = 0)
|
||||
{
|
||||
var start = now.AddDays(-daysAgo);
|
||||
return (new Sequence
|
||||
@@ -475,6 +475,7 @@ public sealed class SampleData
|
||||
Status = status,
|
||||
RenderedCount = renders,
|
||||
WarningCount = warnings,
|
||||
PreviewOnlyCount = previewOnly,
|
||||
Origin = origin,
|
||||
SyncState = sync,
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
@@ -490,7 +491,7 @@ public sealed class SampleData
|
||||
yield return Make(null, "2026/2026-09-27 Sony ILCE-7M4", "SONY", "ILCE-7M4", 2_140, new TimeSpan(1, 11, 0), 2, 1, Analysed,
|
||||
["#4A7FB5", "#A9C9E6", "#6F7D6A"]);
|
||||
yield return Make("Aurora, Tromsø", "2026/2026-02-20 Nikon Z 8", "NIKON CORPORATION", "NIKON Z 8", 1_860, new TimeSpan(4, 8, 0), 8, 220, Full,
|
||||
["#0C2A3A", "#1AA08C", "#0B1A26"], sync: SyncState.InSync);
|
||||
["#0C2A3A", "#1AA08C", "#0B1A26"], sync: SyncState.InSync, previewOnly: 1_860);
|
||||
yield return Make("Construction cam · week 38", "2026/2026-09-14 Brinno TLC2020", "Brinno", "TLC2020", 8_920, TimeSpan.FromDays(7), 60, 14,
|
||||
SequenceStatus.None, ["#7C8AA0", "#C9CFD6", "#4C5058"], origin: SequenceOrigin.Server, sync: SyncState.RemoteOnly);
|
||||
yield return Make("Milan skyline dusk", "2026/2026-06-03 Apple iPhone 16 Pro", "Apple", "iPhone 16 Pro", 2_400, new TimeSpan(1, 20, 0), 2, 117, Full,
|
||||
|
||||
@@ -103,6 +103,7 @@ public sealed class RemoteSequenceSource : ISequenceSource
|
||||
RenderedCount = dto.RenderedCount,
|
||||
HeroFrameId = dto.HeroFrameId,
|
||||
WarningCount = dto.WarningCount,
|
||||
PreviewOnlyCount = dto.PreviewOnlyCount,
|
||||
SettingsJson = manifest.SettingsJson,
|
||||
SettingsVersion = manifest.SettingsVersion,
|
||||
UpdatedAt = dto.UpdatedAt,
|
||||
|
||||
@@ -43,6 +43,7 @@ public static class RemoteCards
|
||||
SettingsVersion = dto.SettingsVersion,
|
||||
FramesVersion = dto.FramesVersion,
|
||||
WarningCount = dto.WarningCount,
|
||||
PreviewOnlyCount = dto.PreviewOnlyCount,
|
||||
OwnerUserId = dto.OwnerUserId,
|
||||
UpdatedAt = dto.UpdatedAt,
|
||||
Origin = SequenceOrigin.Server,
|
||||
|
||||
@@ -237,10 +237,13 @@ public sealed class SequenceItem : ObservableObject
|
||||
_ => null,
|
||||
};
|
||||
|
||||
/// <summary>Card status row: analysed, proxies, renders, errors or warnings, sync (Main.html); the sync glyph is last so a narrow card cuts it first.</summary>
|
||||
/// <summary>
|
||||
/// Card status row: analysed, proxies, renders, preview-only frames (BRIEF §8.2), errors or warnings, sync (Main.html);
|
||||
/// the sync glyph is last so a narrow card cuts it first.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<CardStatus> BuildStatuses(Sequence s, bool analysing)
|
||||
{
|
||||
var list = new List<CardStatus>(5);
|
||||
var list = new List<CardStatus>(6);
|
||||
if (analysing) list.Add(new CardStatus(StatusKind.Analysing, Loc.L("Library.Status.Analysing"), Loc.L("Tooltips.Library.Status.Analysing")));
|
||||
else if ((s.Status & SequenceStatus.AnalyzedLight) != 0) list.Add(new CardStatus(StatusKind.Analysed, Loc.L("Library.Status.Analysed"), Loc.L("Tooltips.Library.Status.Analysed")));
|
||||
else list.Add(new CardStatus(StatusKind.NotAnalysed, Loc.L("Library.Status.Analysed"), Loc.L("Tooltips.Library.Status.NotAnalysed")));
|
||||
@@ -258,6 +261,8 @@ public sealed class SequenceItem : ObservableObject
|
||||
|
||||
if (s.RenderedCount > 0)
|
||||
list.Add(new CardStatus(StatusKind.Rendered, Formatting.Count(s.RenderedCount), Loc.Plural("Tooltips.Library.Status.Rendered", s.RenderedCount)));
|
||||
if (s.PreviewOnlyCount > 0)
|
||||
list.Add(new CardStatus(StatusKind.PreviewOnly, Formatting.Count(s.PreviewOnlyCount), Loc.Plural("Tooltips.Library.Status.PreviewOnly", s.PreviewOnlyCount)));
|
||||
if ((s.Status & SequenceStatus.HasErrors) != 0)
|
||||
list.Add(new CardStatus(StatusKind.Error, Formatting.Count(Math.Max(1, s.WarningCount)), Loc.L("Tooltips.Library.Status.Errors")));
|
||||
else if (s.WarningCount > 0 || (s.Status & SequenceStatus.HasWarnings) != 0)
|
||||
|
||||
@@ -16,14 +16,17 @@ public static class Advisor
|
||||
{
|
||||
/// <summary>
|
||||
/// Recommendations for every parameter the rules cover (see <see cref="AdvisorRules"/>), in section order, plus
|
||||
/// every finding of both analyses. Without a deep report, pixel-based parameters get missing-data recommendations.
|
||||
/// every finding of both analyses; a finding both report (frames that cannot be decoded: the light analysis reads
|
||||
/// the flags the deep pass recorded) is listed once, as the light analysis has it. Without a deep report,
|
||||
/// pixel-based parameters get missing-data recommendations.
|
||||
/// </summary>
|
||||
public static AdvisorResult Recommend(LightAnalysisReport light, DeepAnalysisReport? deep, SequenceContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(light);
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
var findings = new List<Finding>(light.Findings);
|
||||
if (deep is not null) findings.AddRange(deep.Findings.Select(f => f.ToFinding()));
|
||||
var lightKeys = light.Findings.Select(f => f.Key).ToHashSet(StringComparer.Ordinal);
|
||||
if (deep is not null) findings.AddRange(deep.Findings.Select(f => f.ToFinding()).Where(f => !lightKeys.Contains(f.Key)));
|
||||
return new AdvisorResult(new AdvisorRules(light, deep, context).Run(), findings);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,27 +143,38 @@ public sealed record SequenceContext
|
||||
/// <summary>Wanted video length ("fit to N seconds"), when the user set one.</summary>
|
||||
public double? TargetDurationSeconds { get; init; }
|
||||
|
||||
/// <summary>Context from the archive's frame rows: count, dominant oriented size, preview-only count, median shutter time.</summary>
|
||||
/// <summary>
|
||||
/// Context from the archive's frame rows: count, dominant oriented size, preview-only count with the dominant oriented
|
||||
/// size of those frames' previews, median shutter time.
|
||||
/// </summary>
|
||||
public static SequenceContext FromFrames(IReadOnlyList<Frame> frames, IReadOnlyList<EncoderCapability>? codecs = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(frames);
|
||||
var sizes = new Dictionary<(int, int), int>();
|
||||
var previews = new Dictionary<(int, int), int>();
|
||||
var exposures = new List<double>();
|
||||
var previewOnly = 0;
|
||||
foreach (var f in frames)
|
||||
{
|
||||
var size = f.Orientation is >= 5 and <= 8 ? (f.Height, f.Width) : (f.Width, f.Height);
|
||||
var rotated = f.Orientation is >= 5 and <= 8;
|
||||
var size = rotated ? (f.Height, f.Width) : (f.Width, f.Height);
|
||||
if (size.Item1 > 0 && size.Item2 > 0) sizes[size] = sizes.GetValueOrDefault(size) + 1;
|
||||
if (f.ExposureTime is > 0 and var t) exposures.Add(t);
|
||||
if ((f.Flags & FrameFlags.PreviewOnly) != 0) previewOnly++;
|
||||
if ((f.Flags & FrameFlags.PreviewOnly) == 0) continue;
|
||||
previewOnly++;
|
||||
var preview = rotated ? (f.PreviewHeight, f.PreviewWidth) : (f.PreviewWidth, f.PreviewHeight);
|
||||
if (preview.Item1 > 0 && preview.Item2 > 0) previews[preview] = previews.GetValueOrDefault(preview) + 1;
|
||||
}
|
||||
var (width, height) = sizes.Count > 0 ? sizes.MaxBy(kv => kv.Value).Key : (0, 0);
|
||||
var (previewWidth, previewHeight) = previews.Count > 0 ? previews.MaxBy(kv => kv.Value).Key : (0, 0);
|
||||
return new SequenceContext
|
||||
{
|
||||
FrameCount = frames.Count,
|
||||
SourceWidth = width,
|
||||
SourceHeight = height,
|
||||
PreviewOnlyCount = previewOnly,
|
||||
PreviewWidth = previewWidth,
|
||||
PreviewHeight = previewHeight,
|
||||
MedianExposureSeconds = exposures.Count > 0 ? Statistics.Median(exposures.ToArray()) : null,
|
||||
Codecs = codecs ?? [],
|
||||
};
|
||||
|
||||
@@ -114,6 +114,7 @@ public sealed record DeepFinding(string Key, FindingSeverity Severity, double[]
|
||||
/// <summary>Resource keys of the findings produced by the deep analysis; arguments are numbers.</summary>
|
||||
public static class DeepFindingKeys
|
||||
{
|
||||
/// <summary>Frames nothing decodes; the light analysis reports the frames flagged so under it too (format tier 3).</summary>
|
||||
public const string UnreadableFrames = "Advisor.Finding.UnreadableFrames";
|
||||
public const string BlackFrames = "Advisor.Finding.BlackFrames";
|
||||
public const string WhiteFrames = "Advisor.Finding.WhiteFrames";
|
||||
|
||||
@@ -33,6 +33,9 @@ public static class FindingKeys
|
||||
public const string LensChanged = "Advisor.Finding.LensChanged";
|
||||
public const string MixedResolution = "Advisor.Finding.MixedResolution";
|
||||
public const string MixedOrientation = "Advisor.Finding.MixedOrientation";
|
||||
|
||||
/// <summary>Frames that decode only through their embedded preview (format tier 2); {0} frame count.</summary>
|
||||
public const string PreviewOnly = "Advisor.Finding.PreviewOnly";
|
||||
public const string TimeZoneEstimated = "Advisor.Finding.TimeZoneEstimated";
|
||||
public const string DayNightTransition = "Advisor.Finding.DayNightTransition";
|
||||
}
|
||||
@@ -131,5 +131,11 @@ public sealed record LightAnalysisReport
|
||||
/// <summary>Light condition per frame from GPS position and capture time; all null without GPS.</summary>
|
||||
public DayPhase?[] DayPhases { get; init; } = [];
|
||||
|
||||
/// <summary>Frames that decode only through their embedded preview (format tier 2, BRIEF §8.2).</summary>
|
||||
public IReadOnlyList<int> PreviewOnlyFrames { get; init; } = [];
|
||||
|
||||
/// <summary>Frames that nothing decodes (format tier 3): renders skip them.</summary>
|
||||
public IReadOnlyList<int> UndecodableFrames { get; init; } = [];
|
||||
|
||||
public IReadOnlyList<Finding> Findings { get; init; } = [];
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Titano.Core.Analysis.Deep;
|
||||
using Titano.Core.Mathematics;
|
||||
using Titano.Core.Model;
|
||||
|
||||
@@ -5,8 +6,9 @@ namespace Titano.Core.Analysis;
|
||||
|
||||
/// <summary>
|
||||
/// Metadata-only sequence analysis run at import/scan (BRIEF §10.1): cadence, gaps and sessions, timestamp
|
||||
/// sanity, exposure series and steps, camera/lens identity, size and orientation consistency, and day phases
|
||||
/// from GPS. Linear in the number of frames apart from two medians; deterministic.
|
||||
/// sanity, exposure series and steps, camera/lens identity, size and orientation consistency, format tiers (from the
|
||||
/// frames' decode-tier flags) and day phases from GPS. Linear in the number of frames apart from two medians;
|
||||
/// deterministic.
|
||||
/// </summary>
|
||||
public static class LightAnalyzer
|
||||
{
|
||||
@@ -31,6 +33,7 @@ public static class LightAnalyzer
|
||||
var exposure = AnalyzeExposure(frames, options, findings);
|
||||
var identity = AnalyzeIdentity(frames, findings);
|
||||
var (dominantSize, sizeOutliers, orientation, orientationOutliers) = AnalyzeGeometry(frames, findings);
|
||||
var (previewOnly, undecodable) = AnalyzeTiers(frames, findings);
|
||||
var phases = AnalyzeDayPhases(frames, timing.Adjusted, findings);
|
||||
|
||||
return new LightAnalysisReport
|
||||
@@ -56,6 +59,8 @@ public static class LightAnalyzer
|
||||
DominantOrientation = orientation,
|
||||
OrientationOutliers = orientationOutliers,
|
||||
DayPhases = phases,
|
||||
PreviewOnlyFrames = previewOnly,
|
||||
UndecodableFrames = undecodable,
|
||||
Findings = findings,
|
||||
};
|
||||
}
|
||||
@@ -331,6 +336,25 @@ public static class LightAnalyzer
|
||||
return (dominant, sizeOutliers, orientation, orientationOutliers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Format tiers (BRIEF §8.2): frames that decode only through their embedded preview, which caps the output at the
|
||||
/// preview size, and frames that nothing decodes, which renders skip (a warning, under the key the deep analysis uses
|
||||
/// for the frames it could not decode, so the advisor lists them once).
|
||||
/// </summary>
|
||||
private static (List<int> PreviewOnly, List<int> Undecodable) AnalyzeTiers(IReadOnlyList<LightFrame> frames, List<Finding> findings)
|
||||
{
|
||||
var previewOnly = new List<int>();
|
||||
var undecodable = new List<int>();
|
||||
for (var i = 0; i < frames.Count; i++)
|
||||
{
|
||||
if ((frames[i].Flags & FrameFlags.Undecodable) != 0) undecodable.Add(i);
|
||||
else if ((frames[i].Flags & FrameFlags.PreviewOnly) != 0) previewOnly.Add(i);
|
||||
}
|
||||
if (previewOnly.Count > 0) findings.Add(new Finding(FindingKeys.PreviewOnly, FindingSeverity.Info, [previewOnly.Count], Cap(previewOnly)));
|
||||
if (undecodable.Count > 0) findings.Add(new Finding(DeepFindingKeys.UnreadableFrames, FindingSeverity.Warning, [undecodable.Count], Cap(undecodable)));
|
||||
return (previewOnly, undecodable);
|
||||
}
|
||||
|
||||
private static DayPhase?[] AnalyzeDayPhases(IReadOnlyList<LightFrame> frames, DateTime?[] adjusted, List<Finding> findings)
|
||||
{
|
||||
var n = frames.Count;
|
||||
|
||||
@@ -31,6 +31,9 @@ public sealed record LightFrame
|
||||
/// <summary>GPS (satellite) UTC time stamp, used to infer the camera clock's UTC offset.</summary>
|
||||
public DateTime? GpsUtc { get; init; }
|
||||
|
||||
/// <summary>The archived frame's flags; the decode-tier bits feed the format-tier findings.</summary>
|
||||
public FrameFlags Flags { get; init; }
|
||||
|
||||
/// <summary>Exposure value at ISO 100: log2(N²/t) − log2(ISO/100).</summary>
|
||||
public double? ExposureValue => ExposureTime is > 0 && FNumber is > 0
|
||||
? Math.Log2(FNumber.Value * FNumber.Value / ExposureTime.Value) - Math.Log2((Iso is > 0 ? Iso.Value : 100) / 100.0)
|
||||
@@ -54,6 +57,7 @@ public sealed record LightFrame
|
||||
Width = frame.Width,
|
||||
Height = frame.Height,
|
||||
Orientation = frame.Orientation,
|
||||
Flags = frame.Flags,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@ namespace Titano.Core.Archiving;
|
||||
public sealed record EncodedImage(byte[] Jpeg, int Width, int Height, DecodeTier Tier);
|
||||
|
||||
/// <summary>
|
||||
/// Makes thumbnails and proxies of frames (BRIEF §8.5): the embedded preview or the managed JPEG decoder first, then
|
||||
/// the host's decode providers (WIC on Windows); orientation applied, resampled in linear light, encoded in-house.
|
||||
/// Makes thumbnails and proxies of frames (BRIEF §8.5): the managed JPEG decoder, or for thumbnails an embedded preview
|
||||
/// at least 320 px long, first, then the host's decode providers (WIC on Windows); orientation applied, resampled in
|
||||
/// linear light, encoded in-house. <see cref="EncodedImage.Tier"/> says how the pixels were obtained.
|
||||
/// </summary>
|
||||
public sealed class FrameImageRenderer(ImageDecoder decoder)
|
||||
{
|
||||
@@ -55,13 +56,37 @@ public sealed class FrameImageRenderer(ImageDecoder decoder)
|
||||
private static EncodedImage Encode(ImageBuffer pixels, JpegEncodeOptions options, DecodeTier tier) =>
|
||||
new(JpegEncoder.Encode(pixels, options), pixels.Width, pixels.Height, tier);
|
||||
|
||||
/// <summary>
|
||||
/// The frame's pixels: a JPEG through the managed decoder, the stored embedded preview when <paramref name="preferPreview"/>
|
||||
/// and it reaches <paramref name="maxLongEdge"/> (a smaller one would be upscaled or leave the thumbnail short), then
|
||||
/// the host's decoders, and the stored preview as the last resort. Null when nothing decodes.
|
||||
/// </summary>
|
||||
private DecodedFrame? Decode(string path, SidecarFrame frame, int maxLongEdge, DecodePurpose purpose, bool preferPreview, CancellationToken cancellationToken)
|
||||
{
|
||||
if (frame.Format == ImageFileFormat.Jpeg) return DecodeJpeg(File.ReadAllBytes(path), maxLongEdge, frame.Orientation, DecodeTier.Native);
|
||||
if (preferPreview && ReadPreview(path, frame) is { } preview) return DecodeJpeg(preview, maxLongEdge, frame.Orientation, DecodeTier.EmbeddedPreview);
|
||||
if (frame.Format == ImageFileFormat.Jpeg && DecodeJpeg(File.ReadAllBytes(path), maxLongEdge, frame.Orientation, DecodeTier.Native) is { } jpeg) return jpeg;
|
||||
byte[]? preview = null;
|
||||
if (preferPreview && (preview = ReadPreview(path, frame)) is not null && Reaches(preview, frame, maxLongEdge)
|
||||
&& DecodeJpeg(preview, maxLongEdge, frame.Orientation, DecodeTier.EmbeddedPreview) is { } fast)
|
||||
return fast;
|
||||
var request = new DecodeRequest(path, System.Math.Max(0, maxLongEdge), purpose, ApplyOrientation: true, AllowPreview: true);
|
||||
if (decoder.Decode(request, cancellationToken) is { } decoded) return new DecodedFrame(decoded.Pixels, decoded.Tier);
|
||||
return ReadPreview(path, frame) is { } fallback ? DecodeJpeg(fallback, maxLongEdge, frame.Orientation, DecodeTier.EmbeddedPreview) : null;
|
||||
return (preview ?? ReadPreview(path, frame)) is { } fallback ? DecodeJpeg(fallback, maxLongEdge, frame.Orientation, DecodeTier.EmbeddedPreview) : null;
|
||||
}
|
||||
|
||||
/// <summary>Whether the stored preview's long edge reaches <paramref name="maxLongEdge"/> (the sidecar's size, else the JPEG's own).</summary>
|
||||
private static bool Reaches(byte[] preview, SidecarFrame frame, int maxLongEdge)
|
||||
{
|
||||
if (maxLongEdge <= 0) return true;
|
||||
if (frame is { PreviewW: { } w, PreviewH: { } h }) return int.Max(w, h) >= maxLongEdge;
|
||||
try
|
||||
{
|
||||
var info = JpegDecoder.ReadInfo(preview);
|
||||
return int.Max(info.Width, info.Height) >= maxLongEdge;
|
||||
}
|
||||
catch (InvalidDataException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static DecodedFrame? DecodeJpeg(byte[] data, int maxLongEdge, int orientation, DecodeTier tier)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Metadata;
|
||||
using Titano.Core.Model;
|
||||
|
||||
@@ -42,9 +43,32 @@ public static class SequenceFrames
|
||||
Format = metadata.Format,
|
||||
PreviewOffset = metadata.LargestPreview?.Offset,
|
||||
PreviewLength = metadata.LargestPreview?.Length,
|
||||
PreviewW = Positive(metadata.LargestPreview?.Width),
|
||||
PreviewH = Positive(metadata.LargestPreview?.Height),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The frame with its decode tier (BRIEF §8.2) and the flags that follow it: <see cref="FrameFlags.PreviewOnly"/> for
|
||||
/// the embedded-preview tier, <see cref="FrameFlags.Undecodable"/> for none. <paramref name="tier"/>'s size, oriented
|
||||
/// like every <see cref="FileTier"/>, replaces the stored preview size when it is a preview's.
|
||||
/// </summary>
|
||||
/// <param name="damaged">For the unavailable tier: whether that proves the file unreadable. False when the host has no
|
||||
/// native decoder for the format, so a client or render node with one (or a proxy) may still produce its pixels: the
|
||||
/// tier is kept and <see cref="FrameFlags.Undecodable"/> is left as it was.</param>
|
||||
public static SidecarFrame WithTier(SidecarFrame frame, FileTier tier, bool damaged = true)
|
||||
{
|
||||
var flags = frame.Flags & ~(FrameFlags.PreviewOnly | FrameFlags.Undecodable);
|
||||
if (tier.Tier == DecodeTier.EmbeddedPreview) flags |= FrameFlags.PreviewOnly;
|
||||
else if (tier.Tier == DecodeTier.Unavailable) flags |= damaged ? FrameFlags.Undecodable : frame.Flags & FrameFlags.Undecodable;
|
||||
var (w, h) = tier.Tier == DecodeTier.EmbeddedPreview && tier.Width > 0 && tier.Height > 0
|
||||
? PixelConvert.OrientedSize(tier.Width, tier.Height, frame.Orientation)
|
||||
: (frame.PreviewW ?? 0, frame.PreviewH ?? 0);
|
||||
return frame with { Tier = tier.Tier, Flags = flags, PreviewW = Positive(w), PreviewH = Positive(h) };
|
||||
}
|
||||
|
||||
private static int? Positive(int? value) => value > 0 ? value : null;
|
||||
|
||||
/// <summary>
|
||||
/// Merges <paramref name="added"/> into the frame list by capture time (existing frames keep their relative order),
|
||||
/// renumbers indexes and bumps the frames version.
|
||||
|
||||
@@ -109,6 +109,20 @@ public sealed record SidecarFrame
|
||||
public long? PreviewOffset { get; init; }
|
||||
public long? PreviewLength { get; init; }
|
||||
|
||||
/// <summary>Size of the largest embedded preview (or GPR companion JPEG), stored like <see cref="W"/> and <see cref="H"/>
|
||||
/// before orientation; null when the file has none or it is not known yet.</summary>
|
||||
public int? PreviewW { get; init; }
|
||||
|
||||
public int? PreviewH { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Decode tier of the file (BRIEF §8.2) as the host that indexed or decoded it last found it; omitted until it is
|
||||
/// known. <see cref="FrameFlags.PreviewOnly"/> and <see cref="FrameFlags.Undecodable"/> follow it.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(TolerantEnumConverter<DecodeTier>))]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public DecodeTier Tier { get; init; }
|
||||
|
||||
/// <summary><see cref="FrameFlags"/> bits, stored as a number so bits of newer builds survive.</summary>
|
||||
public FrameFlags Flags { get; init; }
|
||||
|
||||
|
||||
@@ -7,19 +7,11 @@ using Titano.Core.Metadata;
|
||||
|
||||
namespace Titano.Core.Imaging.Decoders;
|
||||
|
||||
/// <summary>Tier a provider would use for one specific file, with the reason when it is not native.</summary>
|
||||
/// <param name="Format">Format detected from the file's signature (extension only breaks ties).</param>
|
||||
/// <param name="Tier">Best tier available for this file.</param>
|
||||
/// <param name="Decoder">Decoder that would produce it ("managed-cr2", "managed-preview"…), null when unavailable.</param>
|
||||
/// <param name="Reason">Why the native tier is not used (unsupported body or encoding), else null.</param>
|
||||
/// <param name="Width">Full-size width that tier delivers (developed RAW, preview or image size), oriented; 0 when unknown.</param>
|
||||
/// <param name="Height">Full-size height, oriented; 0 when unknown.</param>
|
||||
public sealed record FileTier(ImageFileFormat Format, DecodeTier Tier, string? Decoder, string? Reason, int Width, int Height);
|
||||
|
||||
/// <summary>
|
||||
/// The managed decoder (BRIEF §8.2), available on every platform and the only one on the server: JPEG, PNG and TIFF
|
||||
/// natively; DNG and the supported camera RAWs (CR2, NEF, ARW, PEF, RAF) through <see cref="RawDecoder"/>; every other
|
||||
/// RAW, CR3 and HEIF through the largest suitable embedded JPEG preview; nothing for formats without either.
|
||||
/// RAW, CR3 and HEIF through the largest suitable embedded JPEG preview, and GoPro GPR through the JPEG the camera writes
|
||||
/// beside it when that is larger (BRIEF §8.1; VC-5 is out of scope); nothing for formats without either.
|
||||
/// <see cref="DecodeRequest"/> fast paths: JPEG DCT scaling and RAW CFA binning when <see cref="DecodeRequest.MaxLongEdge"/>
|
||||
/// allows, bilinear demosaicing for thumbnails and analysis, and <see cref="DecodeRequest.ForcePreview"/> to skip native
|
||||
/// RAW development. Results fit within MaxLongEdge (never upscaled) and are always RGB.
|
||||
@@ -29,6 +21,7 @@ public sealed class ManagedDecoderProvider : IImageDecoderProvider
|
||||
private const string LogCategory = "Decode";
|
||||
private const int FileBufferSize = 1 << 16;
|
||||
private const long MaxPreviewBytes = 256L << 20;
|
||||
private static readonly string[] CompanionExtensions = [".JPG", ".jpg", ".JPEG", ".jpeg"];
|
||||
|
||||
public string Name => "managed";
|
||||
|
||||
@@ -62,6 +55,18 @@ public sealed class ManagedDecoderProvider : IImageDecoderProvider
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tier for a file whose signature format is already known (the index's): JPEG, PNG and TIFF decode natively
|
||||
/// whatever they hold (damage shows only when decoding), so only RAW and HEIF files are opened.
|
||||
/// </summary>
|
||||
public FileTier Probe(string path, ImageFileFormat format)
|
||||
{
|
||||
var family = ImageFormatInfo.Of(format).Family;
|
||||
if (family is not (ImageFamily.Jpeg or ImageFamily.Png or ImageFamily.Tiff)) return Probe(path);
|
||||
var decoder = family switch { ImageFamily.Jpeg => "managed-jpeg", ImageFamily.Png => "managed-png", _ => "managed-tiff" };
|
||||
return new FileTier(format, DecodeTier.Native, decoder, null, 0, 0);
|
||||
}
|
||||
|
||||
/// <summary>The tier this provider would use for the file at <paramref name="path"/>, without decoding pixels.</summary>
|
||||
public FileTier Probe(string path)
|
||||
{
|
||||
@@ -88,11 +93,32 @@ public sealed class ManagedDecoderProvider : IImageDecoderProvider
|
||||
reason = $"no managed decoder for {format}";
|
||||
}
|
||||
var metadata = MetadataReader.Read(stream, path);
|
||||
if (metadata.LargestPreview is not { } preview) return new FileTier(format, DecodeTier.Unavailable, null, reason + "; no embedded preview", 0, 0);
|
||||
var (pw, ph) = PixelConvert.OrientedSize(preview.Width, preview.Height, metadata.Orientation);
|
||||
var (pw, ph) = metadata.LargestPreview is { } preview ? PixelConvert.OrientedSize(preview.Width, preview.Height, metadata.Orientation) : (0, 0);
|
||||
if (format == ImageFileFormat.Gpr && CompanionJpeg(path) is { } companion)
|
||||
{
|
||||
var jpeg = MetadataReader.Read(companion);
|
||||
var (cw, ch) = jpeg.OrientedSize;
|
||||
if (jpeg.Format == ImageFileFormat.Jpeg && int.Max(cw, ch) > int.Max(pw, ph))
|
||||
return new FileTier(format, DecodeTier.EmbeddedPreview, "managed-sidecar", reason, cw, ch);
|
||||
}
|
||||
if (metadata.LargestPreview is null) return new FileTier(format, DecodeTier.Unavailable, null, reason + "; no embedded preview", 0, 0);
|
||||
return new FileTier(format, DecodeTier.EmbeddedPreview, "managed-preview", reason, pw, ph);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The JPEG a GoPro writes beside a GPR (same name, <c>.JPG</c>), or null. Only the usual spellings are tried, so a
|
||||
/// folder of thousands of frames is never listed once per frame.
|
||||
/// </summary>
|
||||
internal static string? CompanionJpeg(string path)
|
||||
{
|
||||
var stem = Path.Combine(Path.GetDirectoryName(path) ?? string.Empty, Path.GetFileNameWithoutExtension(path));
|
||||
foreach (var extension in CompanionExtensions)
|
||||
{
|
||||
if (File.Exists(stem + extension)) return stem + extension;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static FileStream Open(string path) =>
|
||||
new(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, FileBufferSize, FileOptions.RandomAccess);
|
||||
|
||||
@@ -147,7 +173,37 @@ public sealed class ManagedDecoderProvider : IImageDecoderProvider
|
||||
Log.Debug(LogCategory, $"{Path.GetFileName(request.Path)}: native decode unavailable ({ex.Message}); trying the embedded preview");
|
||||
}
|
||||
}
|
||||
return request.AllowPreview || request.ForcePreview ? Preview(stream, request, adequateOnly: false, cancellationToken) : null;
|
||||
if (!request.AllowPreview && !request.ForcePreview) return null;
|
||||
if (format == ImageFileFormat.Gpr && Companion(stream, request, cancellationToken) is { } companion) return companion;
|
||||
return Preview(stream, request, adequateOnly: false, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GPR's pixel source: the GoPro's own JPEG beside it when it is larger than every embedded preview (the camera writes
|
||||
/// it at full size), decoded with DCT scaling and oriented by its own Exif; null when there is none.
|
||||
/// </summary>
|
||||
private static DecodedImage? Companion(Stream raw, DecodeRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (CompanionJpeg(request.Path) is not { } path) return null;
|
||||
var previews = MetadataReader.Read(raw, request.Path, cancellationToken: cancellationToken).Previews;
|
||||
var largestPreview = previews.Count > 0 ? int.Max(previews[0].Width, previews[0].Height) : 0;
|
||||
using var stream = Open(path);
|
||||
if (stream.Length > MaxPreviewBytes) return null;
|
||||
var data = ReadAll(stream);
|
||||
JpegInfo info;
|
||||
try
|
||||
{
|
||||
info = JpegDecoder.ReadInfo(data);
|
||||
}
|
||||
catch (InvalidDataException ex)
|
||||
{
|
||||
Log.Debug(LogCategory, $"{Path.GetFileName(path)}: not a usable JPEG ({ex.Message}); using the embedded preview");
|
||||
return null;
|
||||
}
|
||||
if (int.Max(info.Width, info.Height) <= largestPreview) return null;
|
||||
var image = JpegDecoder.DecodeToLinear(data, new JpegDecodeOptions { MaxLongEdge = request.MaxLongEdge }, expandGray: true);
|
||||
var orientation = request.ApplyOrientation ? MetadataReader.Read(stream, path, cancellationToken: cancellationToken).Orientation : 1;
|
||||
return Finish(image, orientation, request, info.Width, info.Height, DecodeTier.EmbeddedPreview, "managed-sidecar");
|
||||
}
|
||||
|
||||
/// <summary>Embedded-preview tier: the smallest preview whose long edge still reaches MaxLongEdge (the largest when none
|
||||
|
||||
@@ -53,6 +53,15 @@ public sealed class DecodedImage(ImageBuffer pixels, DecodeTier tier, string dec
|
||||
public void Dispose() => Pixels.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>Tier a provider would use for one specific file, with the reason when it is not native.</summary>
|
||||
/// <param name="Format">Format of the file (detected from its signature; the extension only breaks ties).</param>
|
||||
/// <param name="Tier">Best tier available for this file.</param>
|
||||
/// <param name="Decoder">Decoder that would produce it ("managed-cr2", "managed-preview"…), null when unavailable.</param>
|
||||
/// <param name="Reason">Why the native tier is not used (unsupported body or encoding), else null.</param>
|
||||
/// <param name="Width">Full-size width that tier delivers (developed RAW, preview or image size), oriented; 0 when unknown.</param>
|
||||
/// <param name="Height">Full-size height, oriented; 0 when unknown.</param>
|
||||
public sealed record FileTier(ImageFileFormat Format, DecodeTier Tier, string? Decoder, string? Reason, int Width, int Height);
|
||||
|
||||
/// <summary>A platform image decoder (WIC on Windows, managed codecs everywhere).</summary>
|
||||
public interface IImageDecoderProvider
|
||||
{
|
||||
@@ -64,6 +73,17 @@ public interface IImageDecoderProvider
|
||||
|
||||
bool CanDecode(ImageFormatInfo format) => TierFor(format.Format) is not null;
|
||||
|
||||
/// <summary>
|
||||
/// The tier this provider would use for the file at <paramref name="path"/>, whose signature says
|
||||
/// <paramref name="format"/>, without decoding pixels. The default trusts <see cref="TierFor"/>; a provider whose
|
||||
/// support depends on the file itself (camera body, encoding, embedded previews) looks inside it.
|
||||
/// </summary>
|
||||
/// <exception cref="IOException">The file cannot be read.</exception>
|
||||
/// <exception cref="InvalidDataException">The file is malformed where the provider looks.</exception>
|
||||
FileTier Probe(string path, ImageFileFormat format) => TierFor(format) is { } tier
|
||||
? new FileTier(format, tier, Name, null, 0, 0)
|
||||
: new FileTier(format, DecodeTier.Unavailable, null, $"{Name}: no decoder for {format}", 0, 0);
|
||||
|
||||
/// <summary>Decodes or returns null when this provider cannot handle the specific file.</summary>
|
||||
DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -84,6 +104,39 @@ public sealed class ImageDecoder(IReadOnlyList<IImageDecoderProvider> providers)
|
||||
return best;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tier this chain would use for the file at <paramref name="path"/> (signature format <paramref name="format"/>)
|
||||
/// without decoding pixels (BRIEF §8.2): the first provider whose probe reaches the native tier, else the largest
|
||||
/// embedded preview a provider offers, else unavailable with the first reason given. A provider that finds the file
|
||||
/// malformed is skipped like in <see cref="Decode"/>.
|
||||
/// </summary>
|
||||
/// <exception cref="IOException">The file cannot be read.</exception>
|
||||
public FileTier Probe(string path, ImageFileFormat format)
|
||||
{
|
||||
FileTier? preview = null;
|
||||
string? reason = null;
|
||||
foreach (var provider in Providers.OrderBy(p => p.TierFor(format) ?? DecodeTier.Unavailable))
|
||||
{
|
||||
if (provider.TierFor(format) is null) continue;
|
||||
FileTier tier;
|
||||
try
|
||||
{
|
||||
tier = provider.Probe(path, format);
|
||||
}
|
||||
catch (Exception ex) when (ex is InvalidDataException or NotSupportedException or FormatException or InvalidOperationException
|
||||
or System.Runtime.InteropServices.COMException)
|
||||
{
|
||||
reason ??= $"{provider.Name}: {ex.Message}";
|
||||
continue;
|
||||
}
|
||||
if (tier.Tier == DecodeTier.Native) return tier;
|
||||
if (tier.Tier == DecodeTier.EmbeddedPreview && (preview is null || long.Max(tier.Width, tier.Height) > long.Max(preview.Width, preview.Height)))
|
||||
preview = tier;
|
||||
reason ??= tier.Reason;
|
||||
}
|
||||
return preview ?? new FileTier(format, DecodeTier.Unavailable, null, reason ?? $"no decoder for {format}", 0, 0);
|
||||
}
|
||||
|
||||
/// <summary>Decodes with the first provider that succeeds; null means <see cref="DecodeTier.Unavailable"/>.</summary>
|
||||
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
@@ -59,6 +59,10 @@ public sealed record Sequence
|
||||
public int FramesVersion { get; init; }
|
||||
public Guid? OwnerUserId { get; init; }
|
||||
public int WarningCount { get; init; }
|
||||
|
||||
/// <summary>Frames that decode only through their embedded preview (<see cref="FrameFlags.PreviewOnly"/>, BRIEF §8.2).</summary>
|
||||
public int PreviewOnlyCount { get; init; }
|
||||
|
||||
public DateTimeOffset UpdatedAt { get; init; }
|
||||
|
||||
/// <summary>The title, else capture date and camera, else the folder name (never empty).</summary>
|
||||
@@ -112,6 +116,12 @@ public sealed record Frame
|
||||
public long? PreviewOffset { get; init; }
|
||||
public long? PreviewLength { get; init; }
|
||||
|
||||
/// <summary>Size of the largest embedded preview like <see cref="Width"/> and <see cref="Height"/> (before orientation);
|
||||
/// 0 when there is none or it is not known.</summary>
|
||||
public int PreviewWidth { get; init; }
|
||||
|
||||
public int PreviewHeight { get; init; }
|
||||
|
||||
/// <summary>Mean log2 luminance once analysed.</summary>
|
||||
public double? MeanLogLuminance { get; init; }
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.IO;
|
||||
using Titano.Core.Metadata;
|
||||
using Titano.Core.Model;
|
||||
@@ -12,7 +13,8 @@ public sealed record ImagePassResult(int Built, int Reused, int Undecodable);
|
||||
/// <summary>
|
||||
/// Thumbnails (<c>thumbs.pack</c>) and proxies (<c>proxies/0001.jpg</c>) of sequences (BRIEF §8.5). Both are
|
||||
/// regenerable and self-validating: a thumbnail carries its source fingerprint, a proxy its capture time, so after
|
||||
/// frames were renumbered the stale ones are rebuilt and the rest reused.
|
||||
/// frames were renumbered the stale ones are rebuilt and the rest reused. A frame nothing decodes is flagged undecodable
|
||||
/// (BRIEF §8.2 tier 3); one flagged so that decodes after all gets its tier probed again.
|
||||
/// </summary>
|
||||
public sealed class ArchiveImages
|
||||
{
|
||||
@@ -23,6 +25,7 @@ public sealed class ArchiveImages
|
||||
private readonly SequenceWriter _writer;
|
||||
private readonly ArchiveIndexer _indexer;
|
||||
private readonly FrameImageRenderer _renderer;
|
||||
private readonly FrameTiers _tiers;
|
||||
|
||||
internal ArchiveImages(TitanoDatabase db, SequenceWriter writer, ArchiveIndexer indexer)
|
||||
{
|
||||
@@ -30,6 +33,7 @@ public sealed class ArchiveImages
|
||||
_writer = writer;
|
||||
_indexer = indexer;
|
||||
_renderer = new FrameImageRenderer(writer.Options.Decoder);
|
||||
_tiers = new FrameTiers(db, writer, indexer);
|
||||
}
|
||||
|
||||
/// <param name="startFrame">Resume point inside the sequence (frames before it were done by an earlier run).</param>
|
||||
@@ -42,6 +46,7 @@ public sealed class ArchiveImages
|
||||
var folder = paths.Sequence(sequence.Folder);
|
||||
var manifest = ManifestStore.ReadSequence(folder.ManifestPath);
|
||||
int built = 0, reused = 0, undecodable = 0;
|
||||
var tiers = new Dictionary<Guid, FileTier>();
|
||||
// Thumbnail writers exclude each other only; ingest keeps committing meanwhile.
|
||||
using (await LeaseFile.AcquireAsync(paths.LocksDirectory, $"thumbs-{sequence.Id:N}", _writer.Options.Owner, _writer.Options.LeaseWait,
|
||||
_writer.Options.LeaseDuration, cancellationToken).ConfigureAwait(false))
|
||||
@@ -58,7 +63,7 @@ public sealed class ArchiveImages
|
||||
reused++;
|
||||
continue;
|
||||
}
|
||||
if (Render(() => _renderer.Thumbnail(folder, frame, cancellationToken)) is { } image)
|
||||
if (Render(folder, frame, tiers, () => _renderer.Thumbnail(folder, frame, cancellationToken)) is { } image)
|
||||
{
|
||||
pack.Append(frame.I, image.Width, image.Height, fingerprint, image.Jpeg);
|
||||
built++;
|
||||
@@ -75,6 +80,7 @@ public sealed class ArchiveImages
|
||||
}
|
||||
pack.Commit();
|
||||
}
|
||||
await _tiers.RecordAsync(archive, sequence, tiers, cancellationToken).ConfigureAwait(false);
|
||||
await MarkAsync(archive, paths, sequence, SequenceStatus.ThumbsBuilt, undecodable == 0, cancellationToken).ConfigureAwait(false);
|
||||
return new ImagePassResult(built, reused, undecodable);
|
||||
}
|
||||
@@ -91,6 +97,7 @@ public sealed class ArchiveImages
|
||||
var manifest = ManifestStore.ReadSequence(folder.ManifestPath);
|
||||
Directory.CreateDirectory(folder.Proxies);
|
||||
int built = 0, reused = 0, undecodable = 0;
|
||||
var tiers = new Dictionary<Guid, FileTier>();
|
||||
var cadence = new Cadence();
|
||||
for (var i = startFrame; i < manifest.Frames.Count; i++)
|
||||
{
|
||||
@@ -102,7 +109,7 @@ public sealed class ArchiveImages
|
||||
reused++;
|
||||
continue;
|
||||
}
|
||||
if (Render(() => _renderer.Proxy(folder, frame, manifest.Camera, policy, cancellationToken)) is { } image)
|
||||
if (Render(folder, frame, tiers, () => _renderer.Proxy(folder, frame, manifest.Camera, policy, cancellationToken)) is { } image)
|
||||
{
|
||||
AtomicFile.WriteAllBytes(path, image.Jpeg);
|
||||
built++;
|
||||
@@ -113,6 +120,7 @@ public sealed class ArchiveImages
|
||||
}
|
||||
if (cadence.Due()) await checkpoint(i + 1, manifest.Frames.Count).ConfigureAwait(false);
|
||||
}
|
||||
await _tiers.RecordAsync(archive, sequence, tiers, cancellationToken).ConfigureAwait(false);
|
||||
await MarkAsync(archive, paths, sequence, SequenceStatus.ProxiesBuilt, undecodable == 0, cancellationToken).ConfigureAwait(false);
|
||||
return new ImagePassResult(built, reused, undecodable);
|
||||
}
|
||||
@@ -131,18 +139,52 @@ public sealed class ArchiveImages
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A frame no decoder can read is skipped and counted; it never stops the pass.</summary>
|
||||
private static EncodedImage? Render(Func<EncodedImage?> render)
|
||||
/// <summary>
|
||||
/// A frame no decoder can read is skipped and counted; it never stops the pass. What decoding found goes into
|
||||
/// <paramref name="tiers"/>: unavailable when nothing decoded a file that is there (a read error proves nothing), and
|
||||
/// the probed tier when a frame flagged undecodable decoded after all.
|
||||
/// </summary>
|
||||
private EncodedImage? Render(SequencePaths folder, SidecarFrame frame, Dictionary<Guid, FileTier> tiers, Func<EncodedImage?> render)
|
||||
{
|
||||
var path = folder.File(frame.File);
|
||||
EncodedImage? image;
|
||||
try
|
||||
{
|
||||
return render();
|
||||
image = render();
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or NotSupportedException)
|
||||
catch (IOException ex)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("archive", "Frame image could not be rendered", ex);
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex) when (ex is InvalidDataException or NotSupportedException)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("archive", "Frame image could not be rendered", ex);
|
||||
image = null;
|
||||
}
|
||||
if (image is null)
|
||||
{
|
||||
if (File.Exists(path)) tiers[frame.Id] = new FileTier(frame.Format, DecodeTier.Unavailable, null, "no decoder produced pixels", 0, 0);
|
||||
}
|
||||
else if ((frame.Flags & FrameFlags.Undecodable) != 0)
|
||||
{
|
||||
tiers[frame.Id] = Reprobe(path, frame, image.Tier);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/// <summary>The tier of a frame that decoded after it was flagged undecodable (the image's own tier when probing finds none).</summary>
|
||||
private FileTier Reprobe(string path, SidecarFrame frame, DecodeTier decoded)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_writer.Options.Decoder.Probe(path, frame.Format) is { Tier: not DecodeTier.Unavailable } tier) return tier;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("archive", $"{path} could not be probed", ex);
|
||||
}
|
||||
return new FileTier(frame.Format, decoded, null, null, 0, 0);
|
||||
}
|
||||
|
||||
/// <summary>Commit/checkpoint rhythm: every <see cref="CommitFrames"/> rendered frames or <see cref="CommitInterval"/>.</summary>
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Repositories;
|
||||
|
||||
namespace Titano.Data.Archiving;
|
||||
|
||||
/// <summary>
|
||||
/// Decode tiers of archived frames (BRIEF §8.2) written to the sidecar and the index together: the tier, the
|
||||
/// <see cref="FrameFlags.PreviewOnly"/> and <see cref="FrameFlags.Undecodable"/> flags that follow it and the preview
|
||||
/// size, then the sequence row (its preview-only count for the Library chip). A sequence that gains undecodable frames
|
||||
/// shows a warning at once; its next light analysis lists them. Tiers describe the host that probed or decoded the files
|
||||
/// last. Only a file in a format this host decodes natively is flagged undecodable (it is damaged); one beyond this
|
||||
/// host's decoders (HEIF or an unsupported RAW without a preview on the server) keeps its tier but no flag, so render
|
||||
/// nodes and proxies can still provide its pixels, and a host that decodes a flagged frame clears the flag.
|
||||
/// </summary>
|
||||
internal sealed class FrameTiers(TitanoDatabase db, SequenceWriter writer, ArchiveIndexer indexer)
|
||||
{
|
||||
/// <summary>
|
||||
/// The tier of every frame of <paramref name="manifest"/> whose tier is not known yet, probed with the host's decoders
|
||||
/// without decoding pixels; missing and unreadable files are left for later.
|
||||
/// </summary>
|
||||
public Dictionary<Guid, FileTier> ProbeUnknown(SequencePaths folder, SequenceManifest manifest, CancellationToken cancellationToken)
|
||||
{
|
||||
var tiers = new Dictionary<Guid, FileTier>();
|
||||
foreach (var frame in manifest.Frames)
|
||||
{
|
||||
if (frame.Tier != 0 || (frame.Flags & FrameFlags.Missing) != 0) continue;
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var path = folder.File(frame.File);
|
||||
try
|
||||
{
|
||||
var tier = writer.Options.Decoder.Probe(path, frame.Format);
|
||||
Core.Diagnostics.Log.Debug("archive", $"{frame.File}: {tier.Tier} via {tier.Decoder ?? "none"}{(tier.Reason is { } why ? $" ({why})" : "")}");
|
||||
tiers[frame.Id] = tier;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("archive", $"{path} could not be probed", ex);
|
||||
}
|
||||
}
|
||||
return tiers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records <paramref name="tiers"/> (by frame id) where they change what the sidecar says, and returns the frames that
|
||||
/// changed as they are now. Frames no longer in the sequence are ignored.
|
||||
/// </summary>
|
||||
/// <exception cref="ArchiveOfflineException">The archive is offline or read-only.</exception>
|
||||
public async Task<IReadOnlyList<SidecarFrame>> RecordAsync(Archive archive, Sequence sequence, IReadOnlyDictionary<Guid, FileTier> tiers,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (tiers.Count == 0) return [];
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
ArchiveVolume.EnsureWritable(paths);
|
||||
var changed = new List<SidecarFrame>();
|
||||
var manifest = await writer.UpdateAsync(paths, sequence.Id, sequence.Folder, m =>
|
||||
{
|
||||
changed.Clear();
|
||||
var gained = false;
|
||||
var frames = new SidecarFrame[m.Frames.Count];
|
||||
for (var i = 0; i < frames.Length; i++)
|
||||
{
|
||||
var frame = m.Frames[i];
|
||||
frames[i] = frame;
|
||||
if (!tiers.TryGetValue(frame.Id, out var tier)) continue;
|
||||
var updated = SequenceFrames.WithTier(frame, tier, DecodesNatively(frame.Format));
|
||||
if (updated.Tier == frame.Tier && updated.Flags == frame.Flags && updated.PreviewW == frame.PreviewW && updated.PreviewH == frame.PreviewH)
|
||||
continue;
|
||||
gained |= (updated.Flags & ~frame.Flags & FrameFlags.Undecodable) != 0;
|
||||
frames[i] = updated;
|
||||
changed.Add(updated);
|
||||
}
|
||||
if (changed.Count == 0) return null;
|
||||
return m with
|
||||
{
|
||||
Frames = frames,
|
||||
Status = gained ? m.Status | SequenceStatus.HasWarnings : m.Status,
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
if (changed.Count == 0) return [];
|
||||
await db.Frames.UpdateTiersAsync(changed.ConvertAll(f => new FrameTierFields(f.Id, f.Flags, f.PreviewW ?? 0, f.PreviewH ?? 0)), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
var folder = paths.Sequence(sequence.Folder);
|
||||
if (await db.Sequences.GetAsync(sequence.Id, cancellationToken).ConfigureAwait(false) is { } existing)
|
||||
await db.Sequences.UpsertAsync(SequenceMapping.ToSequence(manifest, archive.Id, folder, existing), cancellationToken).ConfigureAwait(false);
|
||||
await indexer.RecordStampsAsync(archive, folder, sequence.Id, cancellationToken).ConfigureAwait(false);
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether this host decodes <paramref name="format"/> natively, so a file of it that yields no pixels is damaged
|
||||
/// rather than beyond this host (JPEG always: the managed JPEG decoder is part of every host).
|
||||
/// </summary>
|
||||
private bool DecodesNatively(ImageFileFormat format) =>
|
||||
format == ImageFileFormat.Jpeg || writer.Options.Decoder.TierFor(format) == DecodeTier.Native;
|
||||
}
|
||||
@@ -32,6 +32,8 @@ internal static class SequenceMapping
|
||||
Format = f.Format,
|
||||
PreviewOffset = f.PreviewOffset,
|
||||
PreviewLength = f.PreviewLength,
|
||||
PreviewWidth = f.PreviewW ?? 0,
|
||||
PreviewHeight = f.PreviewH ?? 0,
|
||||
Flags = f.Flags,
|
||||
};
|
||||
|
||||
@@ -76,6 +78,7 @@ internal static class SequenceMapping
|
||||
SyncState = existing?.SyncState ?? SyncState.LocalOnly,
|
||||
OwnerUserId = existing?.OwnerUserId ?? (Guid.TryParse(m.CreatedBy, out var owner) ? owner : null),
|
||||
WarningCount = existing?.WarningCount ?? 0,
|
||||
PreviewOnlyCount = m.Frames.Count(f => (f.Flags & FrameFlags.PreviewOnly) != 0),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Decode tiers (BRIEF §8.2): the size of each frame's largest embedded preview (before orientation, like width and
|
||||
-- height), which caps the output of sequences whose frames decode only through it, and per sequence the number of
|
||||
-- those preview-only frames for the Library chip. Mirrors sqlite/0005_decode_tiers.sql.
|
||||
|
||||
ALTER TABLE frames ADD COLUMN preview_width integer NOT NULL DEFAULT 0;
|
||||
ALTER TABLE frames ADD COLUMN preview_height integer NOT NULL DEFAULT 0;
|
||||
ALTER TABLE sequences ADD COLUMN preview_only_count integer NOT NULL DEFAULT 0;
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Decode tiers (BRIEF §8.2): the size of each frame's largest embedded preview (before orientation, like width and
|
||||
-- height), which caps the output of sequences whose frames decode only through it, and per sequence the number of
|
||||
-- those preview-only frames for the Library chip. Mirrors postgres/0005_decode_tiers.sql.
|
||||
|
||||
ALTER TABLE frames ADD COLUMN preview_width INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE frames ADD COLUMN preview_height INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE sequences ADD COLUMN preview_only_count INTEGER NOT NULL DEFAULT 0;
|
||||
@@ -6,6 +6,7 @@ using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Core.Render;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Data.Jobs;
|
||||
|
||||
namespace Titano.Data.Processing.Jobs;
|
||||
@@ -14,14 +15,15 @@ namespace Titano.Data.Processing.Jobs;
|
||||
/// <see cref="JobKind.Render"/> on this machine (BRIEF §11.5): target = the sequence; parameters = Protocol
|
||||
/// <c>RenderJobParameters</c> whose preset JSON is the export section of a project (preset, overrides, name template,
|
||||
/// folder, batch). The project is the embedded one or the sequence's own; frames flagged missing, corrupt, excluded or
|
||||
/// undecodable are left out. The preset and every batch preset render after one preparation pass into the sequence's
|
||||
/// <c>exports/</c> (or the export folder, never on a server), named by the template without taking a name another render
|
||||
/// of this process is writing, and each finished output is recorded at once (its row id derives from the job and the
|
||||
/// entry, so every attempt knows what is recorded). Checkpoint: the entries recorded and the output being written, so a
|
||||
/// crashed attempt's leftovers are removed and only unfinished entries render again. A failed entry fails the job after
|
||||
/// the others ran; retrying renders it alone.
|
||||
/// undecodable are left out, and a frame found undecodable while rendering is shown as its nearest neighbour, logged
|
||||
/// and (when the originals were read) flagged so later renders leave it out (BRIEF §8.2). The preset and every batch
|
||||
/// preset render after one preparation pass into the sequence's <c>exports/</c> (or the export folder, never on a
|
||||
/// server), named by the template without taking a name another render of this process is writing, and each finished
|
||||
/// output is recorded at once (its row id derives from the job and the entry, so every attempt knows what is recorded).
|
||||
/// Checkpoint: the entries recorded and the output being written, so a crashed attempt's leftovers are removed and only
|
||||
/// unfinished entries render again. A failed entry fails the job after the others ran; retrying renders it alone.
|
||||
/// </summary>
|
||||
internal sealed class RenderJobHandler(TitanoDatabase db, ProcessingOptions options) : IJobHandler
|
||||
internal sealed class RenderJobHandler(TitanoDatabase db, ProcessingOptions options, FrameTiers tiers) : IJobHandler
|
||||
{
|
||||
public JobKind Kind => JobKind.Render;
|
||||
|
||||
@@ -64,7 +66,7 @@ internal sealed class RenderJobHandler(TitanoDatabase db, ProcessingOptions opti
|
||||
|
||||
var frames = await SequenceFrames.LoadAsync(db, archive, sequence, parameters.UseProxies, cancellation).ConfigureAwait(false);
|
||||
IReadOnlyList<TargetOutcome> outcomes;
|
||||
await using (var render = new SequenceRender(frames, project, SequenceAnalyser.ReadReport(folder, frames.Count), options))
|
||||
await using (var render = new SequenceRender(frames, project, SequenceAnalyser.ReadReport(folder, frames.Count), options, originals: !parameters.UseProxies))
|
||||
{
|
||||
outcomes = await render.RenderAllAsync(
|
||||
targets,
|
||||
@@ -87,6 +89,20 @@ internal sealed class RenderJobHandler(TitanoDatabase db, ProcessingOptions opti
|
||||
},
|
||||
context.ReportAsync,
|
||||
cancellation).ConfigureAwait(false);
|
||||
if (render.StandIns.Count > 0)
|
||||
context.Log(Loc.L("Export.Log.StandIns", string.Join(", ", render.StandIns.Select(i => (i + 1).ToString(Loc.Culture)))));
|
||||
// Recorded without the job's token: what decoding found holds even if the job is cancelled meanwhile, and a
|
||||
// sidecar that cannot be written now only leaves it to the next analysis or render.
|
||||
try
|
||||
{
|
||||
var decoded = render.Decoded.ToDictionary(kv => frames.Frames[kv.Key].Id, kv => kv.Value);
|
||||
await tiers.RecordAsync(archive, sequence, decoded, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or LeaseUnavailableException
|
||||
or ArchiveOfflineException)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("processing", $"The decode tiers of {sequence.DisplayTitle} could not be recorded", ex);
|
||||
}
|
||||
}
|
||||
var failed = outcomes.Where(o => o.Error is not null).ToList();
|
||||
foreach (var outcome in failed) context.Log(Loc.L("Export.Log.Failed", outcome.Target.PresetName, outcome.Error));
|
||||
|
||||
@@ -17,6 +17,7 @@ public sealed class ProcessingService : IJobHandlerProvider
|
||||
{
|
||||
private readonly TitanoDatabase _db;
|
||||
private readonly SequenceAnalyser _analyser;
|
||||
private readonly FrameTiers _tiers;
|
||||
|
||||
public ProcessingService(TitanoDatabase db, ProcessingOptions? options = null)
|
||||
{
|
||||
@@ -24,7 +25,9 @@ public sealed class ProcessingService : IJobHandlerProvider
|
||||
Options = options ?? new ProcessingOptions();
|
||||
// Sidecar and project writes coordinate with the archive engine through the archive's lease files.
|
||||
var writer = new SequenceWriter(Options.Archive);
|
||||
_analyser = new SequenceAnalyser(db, Options, writer, new ArchiveIndexer(db, writer), new ProjectStore(db, writer));
|
||||
var indexer = new ArchiveIndexer(db, writer);
|
||||
_tiers = new FrameTiers(db, writer, indexer);
|
||||
_analyser = new SequenceAnalyser(db, Options, writer, indexer, new ProjectStore(db, writer));
|
||||
}
|
||||
|
||||
public ProcessingOptions Options { get; }
|
||||
@@ -32,7 +35,7 @@ public sealed class ProcessingService : IJobHandlerProvider
|
||||
/// <summary>Handlers for <see cref="JobKind.LightAnalyse"/>, <see cref="JobKind.DeepAnalyse"/> and <see cref="JobKind.Render"/>.</summary>
|
||||
public IReadOnlyList<IJobHandler> CreateJobHandlers()
|
||||
{
|
||||
var render = new RenderJobHandler(_db, Options);
|
||||
var render = new RenderJobHandler(_db, Options, _tiers);
|
||||
return
|
||||
[
|
||||
new AnalyseJobHandler(_db, _analyser, JobKind.LightAnalyse),
|
||||
|
||||
@@ -464,6 +464,8 @@ public sealed class RenderNodeClient : IAsyncDisposable
|
||||
Height = f.Height,
|
||||
Format = Enum.TryParse<ImageFileFormat>(f.Format, ignoreCase: true, out var format) ? format : default,
|
||||
Flags = (FrameFlags)f.Flags,
|
||||
PreviewWidth = f.PreviewWidth,
|
||||
PreviewHeight = f.PreviewHeight,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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,17 @@ 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)
|
||||
{
|
||||
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 +42,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, cancellationToken).ConfigureAwait(false);
|
||||
// Format tiers (BRIEF §10.1): frames indexed since the last analysis are probed with this host's decoders.
|
||||
var probed = _tiers.ProbeUnknown(folder, ManifestStore.ReadSequence(folder.ManifestPath), cancellationToken);
|
||||
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 observed) = await AnalyseDeepAsync(frames, metadata, folder, progress, cancellationToken).ConfigureAwait(false);
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, Decoded(frames, report, observed), 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,15 +116,47 @@ 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: the tier this run decoded it at, else (for frames analysed by
|
||||
/// an interrupted earlier run) unavailable when the report says it did not decode. Missing and corrupt frames are not
|
||||
/// decoded at all, so they say nothing.
|
||||
/// </summary>
|
||||
private static Dictionary<Guid, FileTier> Decoded(SequenceFrames frames, DeepAnalysisReport report, IReadOnlyDictionary<int, FileTier> observed)
|
||||
{
|
||||
var tiers = new Dictionary<Guid, FileTier>();
|
||||
foreach (var (index, tier) in observed) tiers[frames.Frames[index].Id] = tier;
|
||||
foreach (var index in report.Issues.Undecodable)
|
||||
{
|
||||
if (index >= frames.Count || observed.ContainsKey(index) || frames.Files[index] is null
|
||||
|| (frames.Frames[index].Flags & SequenceFrames.NotAnalysed) != 0) continue;
|
||||
var frame = frames.Frames[index];
|
||||
tiers[frame.Id] = new FileTier(frame.Format, DecodeTier.Unavailable, null, "no decoder produced pixels", 0, 0);
|
||||
}
|
||||
return tiers;
|
||||
}
|
||||
|
||||
private async Task<(DeepAnalysisReport Report, IReadOnlyDictionary<int, FileTier> Observed)> AnalyseDeepAsync(SequenceFrames frames,
|
||||
IReadOnlyList<LightFrame> metadata, SequencePaths folder, IProgress<AnalysisProgress>? progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var file = new DeepAnalysisCheckpointFile(Path.Combine(folder.MetaDirectory, DeepAnalysisCheckpointFile.FileName));
|
||||
DeepAnalysisReport report;
|
||||
await using (var source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder))
|
||||
IReadOnlyDictionary<int, FileTier> observed;
|
||||
await using (var source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder) { Originals = true })
|
||||
{
|
||||
report = await DeepAnalyzer.AnalyzeAsync(source, options.DeepAnalysis, new FramesCheckpoint(file, ContentKey(frames)), progress, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
observed = source.Observed.ToDictionary();
|
||||
}
|
||||
report.Save(folder.AnalysisPath);
|
||||
file.Delete();
|
||||
@@ -118,7 +166,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, observed);
|
||||
}
|
||||
|
||||
/// <summary>Identity of the analysed content: frames replaced or renumbered since a checkpoint was written (with the
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Globalization;
|
||||
using Titano.Core.Advice;
|
||||
using Titano.Core.Analysis;
|
||||
@@ -10,9 +11,11 @@ namespace Titano.Data.Processing;
|
||||
/// <summary>
|
||||
/// The frames of a <see cref="SequenceFrames"/> decoded by the host's <see cref="ImageDecoder"/> (oriented, linear
|
||||
/// light, embedded previews when nothing else decodes). For the deep analysis a frame that is missing, corrupt or
|
||||
/// unreadable is null, as <see cref="IFrameSource"/> expects. Renders exclude flagged frames from the plan, so a
|
||||
/// frame that still cannot be decoded stops the render with <see cref="FrameUnreadableKey"/>; render reads go through
|
||||
/// a <see cref="FrameWindow"/> per decode size, which decodes ahead in index order and spills under memory pressure.
|
||||
/// unreadable is null, as <see cref="IFrameSource"/> expects. Renders exclude flagged frames from the plan; a frame that
|
||||
/// still cannot be decoded stops the render with <see cref="FrameUnreadableKey"/>, unless the render gave
|
||||
/// <see cref="RenderExcluded"/>: then the nearest planned frame that decodes stands in for it (BRIEF §8.2 tier 3: one
|
||||
/// unreadable frame never stops a render) and it is listed in <see cref="StandIns"/>. Render reads go through a
|
||||
/// <see cref="FrameWindow"/> per decode size, which decodes ahead in index order and spills under memory pressure.
|
||||
/// </summary>
|
||||
internal sealed class SequenceFrameSource : IFrameSource, IRenderFrameSource, IAsyncDisposable
|
||||
{
|
||||
@@ -27,6 +30,9 @@ internal sealed class SequenceFrameSource : IFrameSource, IRenderFrameSource, IA
|
||||
private readonly FrameWindowOptions _windowOptions;
|
||||
private readonly Lazy<(int Width, int Height)> _size;
|
||||
private readonly SemaphoreSlim _gate = new(1, 1);
|
||||
private readonly ConcurrentDictionary<int, FileTier> _observed = new();
|
||||
private readonly ConcurrentDictionary<int, byte> _standIns = new();
|
||||
private readonly ConcurrentDictionary<int, byte> _failed = new();
|
||||
private FrameWindow? _window;
|
||||
private (int Edge, DecodePurpose Purpose) _windowKey;
|
||||
|
||||
@@ -40,6 +46,24 @@ internal sealed class SequenceFrameSource : IFrameSource, IRenderFrameSource, IA
|
||||
_size = new Lazy<(int, int)>(MeasureSize);
|
||||
}
|
||||
|
||||
/// <summary>The files are the archive's originals, so what decoding finds describes the frames (<see cref="Observed"/>).</summary>
|
||||
public bool Originals { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Positions the render plan leaves out. When set, a render frame that does not decode is replaced by the nearest
|
||||
/// planned frame that does, instead of failing the render.
|
||||
/// </summary>
|
||||
public IReadOnlySet<int>? RenderExcluded { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Decode tier each frame decoded at, or <see cref="DecodeTier.Unavailable"/> when nothing decoded its file (sizes
|
||||
/// oriented, as <see cref="DecodedImage"/> reports them); recorded only for <see cref="Originals"/>.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<int, FileTier> Observed => _observed;
|
||||
|
||||
/// <summary>Positions a render showed a neighbour for because they did not decode, ascending.</summary>
|
||||
public IReadOnlyList<int> StandIns => [.. _standIns.Keys.Order()];
|
||||
|
||||
public int Count => _frames.Count;
|
||||
|
||||
public int FrameCount => _frames.Count;
|
||||
@@ -92,35 +116,77 @@ internal sealed class SequenceFrameSource : IFrameSource, IRenderFrameSource, IA
|
||||
}
|
||||
}
|
||||
|
||||
private ImageBuffer DecodeForRender(int index, int maxLongEdge, DecodePurpose purpose, CancellationToken cancellationToken) =>
|
||||
Decode(index, maxLongEdge, purpose, cancellationToken)?.Pixels ?? throw Unreadable(index);
|
||||
private ImageBuffer DecodeForRender(int index, int maxLongEdge, DecodePurpose purpose, CancellationToken cancellationToken)
|
||||
{
|
||||
if (Decode(index, maxLongEdge, purpose, cancellationToken) is { } decoded) return decoded.Pixels;
|
||||
// A frame the plan leaves out is reached only by the window's read-ahead, which never hands it to the pipeline.
|
||||
if (RenderExcluded is not { } excluded || excluded.Contains(index)) throw Unreadable(index);
|
||||
// Flagged frames never get here, so this one became unreadable after it was last analysed (or is beyond this host's
|
||||
// decoders): the nearest planned frame stands in, earlier first, and the render job records what decoding found.
|
||||
_failed.TryAdd(index, 0);
|
||||
for (var distance = 1; distance < Count; distance++)
|
||||
{
|
||||
ReadOnlySpan<int> neighbours = [index - distance, index + distance];
|
||||
foreach (var neighbour in neighbours)
|
||||
{
|
||||
if (neighbour < 0 || neighbour >= Count || excluded.Contains(neighbour) || _failed.ContainsKey(neighbour)) continue;
|
||||
if (Decode(neighbour, maxLongEdge, purpose, cancellationToken) is not { } standIn)
|
||||
{
|
||||
_failed.TryAdd(neighbour, 0);
|
||||
continue;
|
||||
}
|
||||
_standIns.TryAdd(index, 0);
|
||||
Core.Diagnostics.Log.Warning("processing", $"Frame {index + 1} ({_frames.Frames[index].FileName}) does not decode; frame {neighbour + 1} stands in");
|
||||
return standIn.Pixels;
|
||||
}
|
||||
}
|
||||
throw Unreadable(index);
|
||||
}
|
||||
|
||||
private DecodedImage? Decode(int index, int maxLongEdge, DecodePurpose purpose, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_frames.Files[index] is not { } file) return null;
|
||||
DecodedImage? decoded;
|
||||
try
|
||||
{
|
||||
return _decoder.Decode(new DecodeRequest(file, maxLongEdge, purpose), cancellationToken);
|
||||
decoded = _decoder.Decode(new DecodeRequest(file, maxLongEdge, purpose), cancellationToken);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("processing", $"Frame {file} could not be read", ex);
|
||||
return null;
|
||||
}
|
||||
// A file that vanished is missing, not undecodable (a verify flags it); only what decoding found is recorded.
|
||||
if (Originals && (decoded is not null || File.Exists(file)))
|
||||
{
|
||||
var format = _frames.Frames[index].Format;
|
||||
_observed[index] = decoded is null
|
||||
? new FileTier(format, DecodeTier.Unavailable, null, "no decoder produced pixels", 0, 0)
|
||||
: new FileTier(format, decoded.Tier, decoded.Decoder, null, decoded.SourceWidth, decoded.SourceHeight);
|
||||
}
|
||||
return decoded;
|
||||
}
|
||||
|
||||
/// <summary>The dominant oriented size from the metadata, else the size the first renderable frame decodes to.</summary>
|
||||
/// <summary>
|
||||
/// The dominant oriented size from the metadata, else the size the first renderable frame decodes to (frames that do
|
||||
/// not decode are passed over while a render may stand in for them).
|
||||
/// </summary>
|
||||
private (int, int) MeasureSize()
|
||||
{
|
||||
var context = SequenceContext.FromFrames(_frames.Frames);
|
||||
if (context.SourceWidth > 0 && context.SourceHeight > 0) return (context.SourceWidth, context.SourceHeight);
|
||||
var skipped = _frames.NotRenderable().ToHashSet();
|
||||
if (RenderExcluded is { } excluded) skipped.UnionWith(excluded);
|
||||
int? first = null;
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
if (skipped.Contains(i)) continue;
|
||||
using var probe = Decode(i, ProbeLongEdge, DecodePurpose.Thumbnail, CancellationToken.None) ?? throw Unreadable(i);
|
||||
return (probe.SourceWidth, probe.SourceHeight);
|
||||
using var probe = Decode(i, ProbeLongEdge, DecodePurpose.Thumbnail, CancellationToken.None);
|
||||
if (probe is not null) return (probe.SourceWidth, probe.SourceHeight);
|
||||
first ??= i;
|
||||
if (RenderExcluded is null) break;
|
||||
}
|
||||
if (first is { } unreadable) throw Unreadable(unreadable);
|
||||
throw new RenderException("Export.Render.NoFrames", "Every frame is excluded.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Titano.Core.Analysis;
|
||||
using Titano.Core.Analysis.Deep;
|
||||
using Titano.Core.Export;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
@@ -30,23 +31,36 @@ internal sealed class SequenceRender : IAsyncDisposable
|
||||
private readonly RenderOptions _options;
|
||||
|
||||
/// <param name="analysis">The sequence's deep report, when current: its luminance spares the preparation a decode pass.</param>
|
||||
public SequenceRender(SequenceFrames frames, ProjectSettings project, DeepAnalysisReport? analysis, ProcessingOptions options)
|
||||
/// <param name="originals">The frames' files are the archive's originals (no proxies), so <see cref="Decoded"/> describes them.</param>
|
||||
public SequenceRender(SequenceFrames frames, ProjectSettings project, DeepAnalysisReport? analysis, ProcessingOptions options, bool originals = false)
|
||||
{
|
||||
var metadata = frames.LightFrames();
|
||||
_source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder, options.FrameWindow);
|
||||
var planned = project with { ExcludedFrames = [.. project.ExcludedFrames.Union(frames.NotRenderable()).Order()] };
|
||||
// A frame that turns out not to decode is shown as its nearest planned neighbour instead of failing the render.
|
||||
_source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder, options.FrameWindow)
|
||||
{
|
||||
Originals = originals,
|
||||
RenderExcluded = planned.ExcludedFrames.ToHashSet(),
|
||||
};
|
||||
_processing = options;
|
||||
_options = options.Render;
|
||||
Input = new RenderInput
|
||||
{
|
||||
Source = _source,
|
||||
Frames = SourceFrameInfo.From(frames.Frames, LightAnalyzer.Analyze(metadata).AdjustedTimes),
|
||||
Project = project with { ExcludedFrames = [.. project.ExcludedFrames.Union(frames.NotRenderable()).Order()] },
|
||||
Project = planned,
|
||||
Analysis = analysis?.FrameCount == frames.Count ? new PrecomputedAnalysis { LogLuminance = Luminance(analysis.Frames) } : null,
|
||||
};
|
||||
}
|
||||
|
||||
public RenderInput Input { get; }
|
||||
|
||||
/// <summary>Positions that did not decode during the render; a neighbour stood in for each (ascending).</summary>
|
||||
public IReadOnlyList<int> StandIns => _source.StandIns;
|
||||
|
||||
/// <summary>The decode tier each frame was read at so far (unavailable when it did not decode); originals only.</summary>
|
||||
public IReadOnlyDictionary<int, FileTier> Decoded => _source.Observed;
|
||||
|
||||
/// <summary>Encoder, geometry and plan of an export before its output is named.</summary>
|
||||
public RenderSetup Setup(ResolvedExport export) => Pipeline(export).Setup(Input, new RenderTarget(export, ExportNaming.FallbackName), _options);
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@ public sealed record DuplicateFrame(string Sha256, Guid FrameId, Guid SequenceId
|
||||
/// <summary>Light statistics of one frame, written by the analysis job.</summary>
|
||||
public readonly record struct FrameLightStats(Guid FrameId, double? MeanLogLuminance, double? ClipLow, double? ClipHigh);
|
||||
|
||||
/// <summary>Decode-tier fields of one frame (BRIEF §8.2): its flags and the stored size of its largest embedded preview.</summary>
|
||||
public readonly record struct FrameTierFields(Guid FrameId, FrameFlags Flags, int PreviewWidth, int PreviewHeight);
|
||||
|
||||
/// <summary>Per-format totals and flagged-frame counts of one sequence.</summary>
|
||||
public sealed record SequenceFrameStats(IReadOnlyList<FormatBucket> ByFormat, long Missing, long Corrupt, long Duplicate, long Excluded);
|
||||
|
||||
@@ -27,7 +30,7 @@ public sealed class FrameRepository
|
||||
"id", "sequence_id", "idx", "relative_path", "file_name", "original_file_name", "size", "sha256", "captured_at",
|
||||
"utc_offset_minutes", "timestamp_source", "exposure_time", "f_number", "iso", "focal_length", "exposure_bias",
|
||||
"white_balance", "orientation", "width", "height", "format", "preview_offset", "preview_length",
|
||||
"mean_log_luminance", "clip_low", "clip_high", "flags",
|
||||
"mean_log_luminance", "clip_low", "clip_high", "flags", "preview_width", "preview_height",
|
||||
];
|
||||
|
||||
private static readonly string Columns = string.Join(", ", ColumnNames);
|
||||
@@ -37,7 +40,7 @@ public sealed class FrameRepository
|
||||
/// <summary>Rows per statement of the batched PostgreSQL updates (4 or fewer parameters per row).</summary>
|
||||
private const int Batch = 1000;
|
||||
|
||||
/// <summary>Rows per multi-row upsert: 30 x 27 parameters stays below SQLite's historical 999-variable limit.</summary>
|
||||
/// <summary>Rows per multi-row upsert: 30 x 29 parameters stays below SQLite's historical 999-variable limit.</summary>
|
||||
private const int UpsertRows = 30;
|
||||
|
||||
/// <summary>Light statistics belong to the analysis job; a sync from the sidecar never clears them.</summary>
|
||||
@@ -130,6 +133,19 @@ public sealed class FrameRepository
|
||||
return updated;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>Writes the decode-tier fields of many frames in one transaction; returns the number of frames updated.</summary>
|
||||
public Task<int> UpdateTiersAsync(IReadOnlyList<FrameTierFields> frames, CancellationToken cancellationToken = default) =>
|
||||
_db.InTransactionAsync(async session =>
|
||||
{
|
||||
var updated = 0;
|
||||
foreach (var f in frames)
|
||||
{
|
||||
updated += await session.ExecuteAsync("UPDATE frames SET flags = $2, preview_width = $3, preview_height = $4 WHERE id = $1",
|
||||
[f.FrameId, (int)f.Flags, f.PreviewWidth, f.PreviewHeight], cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
return updated;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Makes the frames of a sequence exactly <paramref name="frames"/> (from its sidecar): rows are upserted by id,
|
||||
/// rows not listed are deleted, light statistics of kept rows survive. Indexes may be renumbered freely.
|
||||
@@ -239,7 +255,7 @@ public sealed class FrameRepository
|
||||
f.Id, f.SequenceId, f.Index, f.RelativePath, f.FileName, f.OriginalFileName, f.Size, f.Sha256?.ToLowerInvariant(),
|
||||
SequenceRepository.Wall(f.CapturedAt), f.UtcOffsetMinutes, (int)f.TimestampSource, f.ExposureTime, f.FNumber, f.Iso,
|
||||
f.FocalLength, f.ExposureBias, f.WhiteBalance, f.Orientation, f.Width, f.Height, (int)f.Format, f.PreviewOffset,
|
||||
f.PreviewLength, f.MeanLogLuminance, f.ClipLow, f.ClipHigh, (int)f.Flags,
|
||||
f.PreviewLength, f.MeanLogLuminance, f.ClipLow, f.ClipHigh, (int)f.Flags, f.PreviewWidth, f.PreviewHeight,
|
||||
];
|
||||
|
||||
private static Frame Map(DbRow r) => new()
|
||||
@@ -271,5 +287,7 @@ public sealed class FrameRepository
|
||||
ClipLow = r.GetDoubleOrNull(24),
|
||||
ClipHigh = r.GetDoubleOrNull(25),
|
||||
Flags = (FrameFlags)r.GetInt32(26),
|
||||
PreviewWidth = r.GetInt32(27),
|
||||
PreviewHeight = r.GetInt32(28),
|
||||
};
|
||||
}
|
||||
@@ -122,7 +122,8 @@ public sealed class SequenceRepository
|
||||
private const string Columns =
|
||||
"s.id, s.archive_id, s.title, s.folder, s.camera_make, s.camera_model, s.camera_serial, s.lens, s.first_capture, s.last_capture, " +
|
||||
"s.frame_count, s.median_interval, s.total_bytes, s.status, s.rendered_count, s.verified_at, s.hero_frame_id, s.rating, s.notes, " +
|
||||
"s.settings_json, s.analysis_json, s.origin, s.sync_state, s.settings_version, s.frames_version, s.owner_user_id, s.warning_count, s.updated_at";
|
||||
"s.settings_json, s.analysis_json, s.origin, s.sync_state, s.settings_version, s.frames_version, s.owner_user_id, s.warning_count, s.updated_at, " +
|
||||
"s.preview_only_count";
|
||||
|
||||
/// <summary>rendered_count is owned by <see cref="RenderRepository"/> once the row exists.</summary>
|
||||
private static readonly string UpsertSql = SqlDialect.Upsert("sequences",
|
||||
@@ -130,12 +131,12 @@ public sealed class SequenceRepository
|
||||
"id", "archive_id", "title", "title_key", "search_text", "folder", "camera_make", "camera_model", "camera_serial", "lens",
|
||||
"first_capture", "last_capture", "frame_count", "median_interval", "total_bytes", "status", "rendered_count", "verified_at",
|
||||
"hero_frame_id", "rating", "notes", "settings_json", "analysis_json", "origin", "sync_state", "settings_version",
|
||||
"frames_version", "owner_user_id", "warning_count", "updated_at",
|
||||
"frames_version", "owner_user_id", "warning_count", "updated_at", "preview_only_count",
|
||||
], 1, ["rendered_count"]);
|
||||
|
||||
/// <summary>Ordinal of the tag list after <see cref="Columns"/>, and of the sort key a listing appends after it.</summary>
|
||||
private const int TagsOrdinal = 28;
|
||||
private const int SortKeyOrdinal = 29;
|
||||
private const int TagsOrdinal = 29;
|
||||
private const int SortKeyOrdinal = 30;
|
||||
|
||||
private readonly DbAccess _db;
|
||||
private readonly string _select;
|
||||
@@ -445,7 +446,7 @@ public sealed class SequenceRepository
|
||||
s.Id, s.ArchiveId, s.Title, s.DisplayTitle.ToLowerInvariant(), search, s.Folder, s.CameraMake, s.CameraModel, s.CameraSerial, s.Lens,
|
||||
Wall(s.FirstCapture), Wall(s.LastCapture), s.FrameCount, s.MedianInterval, s.TotalBytes, (int)s.Status, s.RenderedCount, s.VerifiedAt,
|
||||
s.HeroFrameId, s.Rating, s.Notes, DbParam.Json(s.SettingsJson), DbParam.Json(s.AnalysisJson), (int)s.Origin, (int)s.SyncState,
|
||||
s.SettingsVersion, s.FramesVersion, s.OwnerUserId, s.WarningCount, s.UpdatedAt,
|
||||
s.SettingsVersion, s.FramesVersion, s.OwnerUserId, s.WarningCount, s.UpdatedAt, s.PreviewOnlyCount,
|
||||
], cancellationToken);
|
||||
}
|
||||
|
||||
@@ -523,6 +524,7 @@ public sealed class SequenceRepository
|
||||
OwnerUserId = r.GetGuidOrNull(25),
|
||||
WarningCount = r.GetInt32(26),
|
||||
UpdatedAt = r.GetDateTimeOffset(27),
|
||||
PreviewOnlyCount = r.GetInt32(28),
|
||||
Tags = tags,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace Titano.Protocol;
|
||||
|
||||
/// <summary>Sequence summary for lists (BRIEF §12.2 card data).</summary>
|
||||
/// <param name="PreviewOnlyCount">Frames that decode only through their embedded preview (BRIEF §8.2 tier 2).</param>
|
||||
public sealed record SequenceDto(
|
||||
Guid Id,
|
||||
string? Title,
|
||||
@@ -24,7 +25,8 @@ public sealed record SequenceDto(
|
||||
int FramesVersion,
|
||||
int WarningCount,
|
||||
Guid? OwnerUserId,
|
||||
DateTimeOffset UpdatedAt);
|
||||
DateTimeOffset UpdatedAt,
|
||||
int PreviewOnlyCount = 0);
|
||||
|
||||
/// <summary>A page of results with an opaque keyset cursor; null cursor = last page.</summary>
|
||||
public sealed record Page<T>(IReadOnlyList<T> Items, string? NextCursor, long? Total);
|
||||
@@ -45,6 +47,8 @@ public sealed record UpdateSequenceRequest(
|
||||
int? ExpectedSettingsVersion,
|
||||
Guid? HeroFrameId = null);
|
||||
|
||||
/// <param name="PreviewWidth">Width of the largest embedded preview before orientation, like <paramref name="Width"/>; 0 when unknown.</param>
|
||||
/// <param name="PreviewHeight">Height of that preview before orientation; 0 when unknown.</param>
|
||||
public sealed record FrameDto(
|
||||
Guid Id,
|
||||
Guid SequenceId,
|
||||
@@ -62,7 +66,9 @@ public sealed record FrameDto(
|
||||
int Width,
|
||||
int Height,
|
||||
string Format,
|
||||
long Flags);
|
||||
long Flags,
|
||||
int PreviewWidth = 0,
|
||||
int PreviewHeight = 0);
|
||||
|
||||
/// <summary><c>GET /api/v1/sequences/{id}/manifest</c>: what a client needs to diff a sequence (BRIEF §14.5).</summary>
|
||||
public sealed record SequenceManifest(
|
||||
|
||||
@@ -17,11 +17,11 @@ public static class Dto
|
||||
public static SequenceDto Sequence(Sequence s) => new(
|
||||
s.Id, s.Title, s.DisplayTitle, s.Folder, s.CameraMake, s.CameraModel, s.Lens, s.FirstCapture, s.LastCapture, s.FrameCount,
|
||||
s.MedianInterval, s.TotalBytes, (long)s.Status, s.RenderedCount, s.HeroFrameId, s.Tags, s.Rating, s.Notes, s.SettingsVersion,
|
||||
s.FramesVersion, s.WarningCount, s.OwnerUserId, s.UpdatedAt);
|
||||
s.FramesVersion, s.WarningCount, s.OwnerUserId, s.UpdatedAt, s.PreviewOnlyCount);
|
||||
|
||||
public static FrameDto Frame(Frame f) => new(
|
||||
f.Id, f.SequenceId, f.Index, f.FileName, f.Size, f.Sha256, f.CapturedAt, f.UtcOffsetMinutes, f.ExposureTime, f.FNumber, f.Iso,
|
||||
f.FocalLength, f.Orientation, f.Width, f.Height, f.Format.ToString().ToLowerInvariant(), (long)f.Flags);
|
||||
f.FocalLength, f.Orientation, f.Width, f.Height, f.Format.ToString().ToLowerInvariant(), (long)f.Flags, f.PreviewWidth, f.PreviewHeight);
|
||||
|
||||
public static RenderDto Render(Render r) => new(r.Id, r.PresetName, r.Codec, r.Width, r.Height, r.Fps, r.DurationSeconds, r.Bytes, r.Created, r.ProducedBy);
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ public enum StatusKind
|
||||
Paused,
|
||||
Online,
|
||||
Offline,
|
||||
|
||||
/// <summary>Frames that decode only through their embedded preview (BRIEF §8.2 tier 2).</summary>
|
||||
PreviewOnly,
|
||||
}
|
||||
|
||||
/// <summary>Glyph + text in the colour of the status kind.</summary>
|
||||
|
||||
@@ -1356,6 +1356,9 @@
|
||||
<Trigger Property="Kind" Value="Rendered">
|
||||
<Setter TargetName="Glyph" Property="Glyph" Value="{StaticResource Icon.TriangleRight}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Kind" Value="PreviewOnly">
|
||||
<Setter TargetName="Glyph" Property="Glyph" Value="{StaticResource Icon.Image}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Kind" Value="Synced"><Setter Property="Foreground" Value="{DynamicResource Brush.Accent}" /></Trigger>
|
||||
<Trigger Property="Kind" Value="Remote"><Setter Property="Foreground" Value="{DynamicResource Brush.Accent}" /></Trigger>
|
||||
<Trigger Property="Kind" Value="Running"><Setter Property="Foreground" Value="{DynamicResource Brush.Accent}" /></Trigger>
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
using System.Text;
|
||||
using Titano.Core.Advice;
|
||||
using Titano.Core.Analysis;
|
||||
using Titano.Core.Analysis.Deep;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Codecs.Jpeg;
|
||||
using Titano.Core.Diagnostics.Synthetic;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Imaging.Decoders;
|
||||
using Titano.Core.Metadata;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Tests.Analysis.Deep;
|
||||
using Titano.Core.Tests.Raw;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Archiving;
|
||||
|
||||
/// <summary>Decode tiers of frames (BRIEF §8.2): sidecar fields, flags, thumbnails from previews, and what the advisor reads.</summary>
|
||||
[Category("archive")]
|
||||
public sealed class DecodeTierTests(TestContext context)
|
||||
{
|
||||
private static readonly DateTime Start = new(2026, 9, 28, 18, 0, 0);
|
||||
|
||||
private static SidecarFrame Sidecar(int orientation = 1, int? previewW = null, int? previewH = null) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
File = "originals/IMG_0001.CR2",
|
||||
Format = ImageFileFormat.Cr2,
|
||||
W = 6000,
|
||||
H = 4000,
|
||||
Orientation = orientation,
|
||||
PreviewW = previewW,
|
||||
PreviewH = previewH,
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void TheTierSetsItsFlagsAndThePreviewSize()
|
||||
{
|
||||
var frame = Sidecar(orientation: 6) with { Flags = FrameFlags.Duplicate };
|
||||
// FileTier sizes are oriented; the sidecar keeps them like W and H, before orientation.
|
||||
var preview = SequenceFrames.WithTier(frame, new FileTier(ImageFileFormat.Cr2, DecodeTier.EmbeddedPreview, "managed-preview", "body", 1080, 1620));
|
||||
Assert.Equal((DecodeTier.EmbeddedPreview, FrameFlags.Duplicate | FrameFlags.PreviewOnly, (int?)1620, (int?)1080),
|
||||
(preview.Tier, preview.Flags, preview.PreviewW, preview.PreviewH));
|
||||
|
||||
var none = SequenceFrames.WithTier(preview, new FileTier(ImageFileFormat.Cr2, DecodeTier.Unavailable, null, "nothing", 0, 0));
|
||||
Assert.Equal((FrameFlags.Duplicate | FrameFlags.Undecodable, (int?)1620), (none.Flags, none.PreviewW));
|
||||
|
||||
var native = SequenceFrames.WithTier(none, new FileTier(ImageFileFormat.Cr2, DecodeTier.Native, "wic", null, 4000, 6000));
|
||||
Assert.Equal((DecodeTier.Native, FrameFlags.Duplicate, (int?)1620), (native.Tier, native.Flags, native.PreviewW));
|
||||
|
||||
// A host without a native decoder for the format proves nothing about the file: tier kept, flag left as it was.
|
||||
var beyond = SequenceFrames.WithTier(native, new FileTier(ImageFileFormat.Cr2, DecodeTier.Unavailable, null, "nothing here", 0, 0), damaged: false);
|
||||
Assert.Equal((DecodeTier.Unavailable, FrameFlags.Duplicate), (beyond.Tier, beyond.Flags));
|
||||
Assert.Equal(FrameFlags.Duplicate | FrameFlags.Undecodable,
|
||||
SequenceFrames.WithTier(none, new FileTier(ImageFileFormat.Cr2, DecodeTier.Unavailable, null, "nothing here", 0, 0), damaged: false).Flags);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SidecarsKeepTheTierAndThePreviewSizeAndOlderOnesReadAsUnknown()
|
||||
{
|
||||
var path = Path.Combine(context.CreateTempDirectory(), "sequence.json");
|
||||
var frame = SequenceFrames.WithTier(Sidecar(previewW: 1620, previewH: 1080),
|
||||
new FileTier(ImageFileFormat.Cr2, DecodeTier.EmbeddedPreview, "managed-preview", null, 1620, 1080));
|
||||
ManifestStore.WriteSequence(path, new SequenceManifest { Id = Guid.CreateVersion7(), Frames = [frame] });
|
||||
var json = File.ReadAllText(path);
|
||||
Assert.Contains("\"tier\":\"EmbeddedPreview\"", json);
|
||||
Assert.Contains("\"previewW\":1620", json);
|
||||
var read = ManifestStore.ReadSequence(path).Frames.Single();
|
||||
Assert.Equal((DecodeTier.EmbeddedPreview, FrameFlags.PreviewOnly, (int?)1620, (int?)1080), (read.Tier, read.Flags, read.PreviewW, read.PreviewH));
|
||||
|
||||
// A frame never probed writes no tier, and a sidecar from before tiers reads as unknown.
|
||||
ManifestStore.WriteSequence(path, new SequenceManifest { Id = Guid.CreateVersion7(), Frames = [Sidecar()] });
|
||||
Assert.DoesNotContain("tier", File.ReadAllText(path).Split('"'));
|
||||
var older = ManifestStore.ParseSequence(Encoding.UTF8.GetBytes(
|
||||
"""{"id":"0192f7a0-0000-7000-8000-000000000001","frames":[{"id":"0192f7a0-0000-7000-8000-000000000002","file":"a.jpg","tier":"SomethingNew"}]}"""), "test");
|
||||
Assert.Equal((DecodeTier)0, older.Frames.Single().Tier);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IndexingKeepsTheSizeOfTheLargestPreview()
|
||||
{
|
||||
var metadata = new FrameMetadata
|
||||
{
|
||||
Format = ImageFileFormat.Cr2,
|
||||
Width = 6000,
|
||||
Height = 4000,
|
||||
Previews = [new EmbeddedPreview(4096, 90_000, 1620, 1080, PreviewKind.Preview), new EmbeddedPreview(100, 4000, 160, 120, PreviewKind.Thumbnail)],
|
||||
};
|
||||
var frame = SequenceFrames.FromMetadata(Guid.CreateVersion7(), "a.cr2", "a.cr2", 10, null, metadata);
|
||||
Assert.Equal((4096L, (int?)1620, (int?)1080, (DecodeTier)0), (frame.PreviewOffset!.Value, frame.PreviewW, frame.PreviewH, frame.Tier));
|
||||
Assert.Null(SequenceFrames.FromMetadata(Guid.CreateVersion7(), "b.jpg", "b.jpg", 10, null, new FrameMetadata { Format = ImageFileFormat.Jpeg }).PreviewW);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThumbnailsUseAStoredPreviewOnlyWhenItReachesTheThumbnailSize()
|
||||
{
|
||||
var archive = new ArchivePaths(context.CreateTempDirectory("archive"));
|
||||
var sequence = archive.Sequence("s");
|
||||
Directory.CreateDirectory(sequence.Originals);
|
||||
using var scene = SyntheticRaw.Smooth(640, 480);
|
||||
var dng = SyntheticDng.Write(scene, new DngSpec());
|
||||
var renderer = new FrameImageRenderer(DecoderFactory.CreateServer());
|
||||
|
||||
EncodedImage Thumbnail(string name, int previewWidth, bool sizeKnown)
|
||||
{
|
||||
// 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 frame = new SidecarFrame
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
File = "originals/" + name,
|
||||
Format = ImageFileFormat.Dng,
|
||||
W = 640,
|
||||
H = 480,
|
||||
PreviewOffset = dng.Length,
|
||||
PreviewLength = preview.Length,
|
||||
PreviewW = sizeKnown ? previewWidth : null,
|
||||
PreviewH = sizeKnown ? previewWidth * 3 / 4 : null,
|
||||
};
|
||||
return renderer.Thumbnail(sequence, frame)!;
|
||||
}
|
||||
|
||||
// A 200 px preview would leave the thumbnail short of 320 px (ENG-10): the RAW is developed instead.
|
||||
var small = Thumbnail("small.dng", 200, sizeKnown: true);
|
||||
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));
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheAdvisorCapsTheOutputAtThePreviewsOfPreviewOnlyFrames()
|
||||
{
|
||||
var sequence = Guid.CreateVersion7();
|
||||
Frame Row(int index, FrameFlags flags, int previewW, int previewH) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
SequenceId = sequence,
|
||||
Index = index,
|
||||
RelativePath = $"s/{index}.cr3",
|
||||
FileName = $"{index}.cr3",
|
||||
CapturedAt = Start.AddSeconds(5 * index),
|
||||
ExposureTime = 1.0 / 250,
|
||||
FNumber = 8,
|
||||
Iso = 100,
|
||||
Width = 6000,
|
||||
Height = 4000,
|
||||
Orientation = 6,
|
||||
Flags = flags,
|
||||
PreviewWidth = previewW,
|
||||
PreviewHeight = previewH,
|
||||
};
|
||||
var rows = Enumerable.Range(0, 20)
|
||||
.Select(i => Row(i, i == 19 ? FrameFlags.Undecodable : i < 15 ? FrameFlags.PreviewOnly : FrameFlags.None, i == 3 ? 1280 : 1620, i == 3 ? 960 : 1080))
|
||||
.ToList();
|
||||
|
||||
var context = SequenceContext.FromFrames(rows);
|
||||
// Portrait frames: the previews are oriented like the main image; the most common preview size wins.
|
||||
Assert.Equal((4000, 6000, 15, 1080, 1620), (context.SourceWidth, context.SourceHeight, context.PreviewOnlyCount, context.PreviewWidth, context.PreviewHeight));
|
||||
|
||||
var light = LightAnalyzer.Analyze(rows);
|
||||
Assert.SequenceEqual(Enumerable.Range(0, 15), light.PreviewOnlyFrames);
|
||||
Assert.SequenceEqual([19], light.UndecodableFrames);
|
||||
var preview = light.Findings.Single(f => f.Key == FindingKeys.PreviewOnly);
|
||||
Assert.Equal((FindingSeverity.Info, (object)15), (preview.Severity, preview.Arguments[0]));
|
||||
Assert.Equal(FindingSeverity.Warning, light.Findings.Single(f => f.Key == DeepFindingKeys.UnreadableFrames).Severity);
|
||||
|
||||
var result = Advisor.Recommend(light, null, context);
|
||||
var resolution = result.Find(AdvisorParameters.Resolution)!;
|
||||
Assert.Equal(AdvisorKeys.ResolutionPreview, resolution.ReasonKey);
|
||||
Assert.SequenceEqual([15, 1080, 1620], resolution.ReasonArgs.Select(Convert.ToInt32));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FramesBothAnalysesFoundUndecodableAreListedOnce()
|
||||
{
|
||||
var source = new SyntheticFrameSource(SyntheticSequence.Create(new SyntheticSequenceOptions { Width = 96, Height = 64, FrameCount = 12 }))
|
||||
{
|
||||
Undecodable = [4],
|
||||
};
|
||||
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.
|
||||
var unflagged = Advisor.Recommend(LightAnalyzer.Analyze(metadata), deep, context).Findings.Where(f => f.Key == DeepFindingKeys.UnreadableFrames).ToList();
|
||||
Assert.SequenceEqual([4], unflagged.Single().Frames);
|
||||
|
||||
// Once flagged, the light analysis lists it and the deep finding is not repeated.
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ using Titano.Core.Codecs.Tiff;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Imaging.Decoders;
|
||||
using Titano.Core.Metadata;
|
||||
using Titano.Core.Metadata.Tiff;
|
||||
using Titano.Core.Tests.Metadata.Builders;
|
||||
using Titano.Core.Tests.Raw;
|
||||
using Titano.Testing;
|
||||
using static Titano.Core.Tests.Raw.NativeRawWriters;
|
||||
@@ -201,6 +203,76 @@ public sealed class ManagedDecoderProviderTests(TestContext context)
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheChainProbesEachFileForItsTier()
|
||||
{
|
||||
var server = DecoderFactory.CreateServer();
|
||||
// JPEG, PNG and TIFF decode natively whatever they hold: the probe does not even open them.
|
||||
Assert.Equal(DecodeTier.Native, server.Probe(Path.Combine(_dir, "absent.jpg"), ImageFileFormat.Jpeg).Tier);
|
||||
|
||||
var supported = server.Probe(Write("IMG_5.CR2", Cr2File("Canon EOS 5D Mark III")), ImageFileFormat.Cr2);
|
||||
Assert.Equal((DecodeTier.Native, "managed-cr2"), (supported.Tier, supported.Decoder));
|
||||
|
||||
// An unsupported body decodes only through its 64×48 preview, rotated like the main image (orientation 6).
|
||||
var preview = server.Probe(Write("IMG_6.CR2", Cr2File("Canon EOS R99", orientation: 6)), ImageFileFormat.Cr2);
|
||||
Assert.Equal((DecodeTier.EmbeddedPreview, 48, 64), (preview.Tier, preview.Width, preview.Height));
|
||||
Assert.Contains("no colour matrix", preview.Reason);
|
||||
|
||||
using var scene = SyntheticRaw.Smooth(W, H);
|
||||
var nef = Nef(Sensor(scene, "Nikon D850", CfaPattern.Bayer("RGGB"), W, H, 0, 0, 600, 16383), 14, NefEncoding.Lossless);
|
||||
var unknownBody = System.Text.Encoding.Latin1.GetBytes(System.Text.Encoding.Latin1.GetString(nef).Replace("NIKON D850", "NIKON Z99X"));
|
||||
var none = server.Probe(Write("DSC_7.NEF", unknownBody), ImageFileFormat.Nef);
|
||||
Assert.Equal(DecodeTier.Unavailable, none.Tier);
|
||||
Assert.Contains("no embedded preview", none.Reason);
|
||||
|
||||
// A Windows-like provider native for CR3 answers from its codec list, before the managed preview tier.
|
||||
var client = DecoderFactory.CreateClient(new FakeProvider());
|
||||
var cr3 = client.Probe(Path.Combine(_dir, "absent.cr3"), ImageFileFormat.Cr3);
|
||||
Assert.Equal((DecodeTier.Native, "fake"), (cr3.Tier, cr3.Decoder));
|
||||
Assert.Equal(DecodeTier.Unavailable, client.Probe(Write("y.webp", Fixtures.WebP()), ImageFileFormat.WebP).Tier);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GoProRawDecodesThroughTheJpegBesideIt()
|
||||
{
|
||||
var gpr = Write("GOPR0001.GPR", Gpr(previewWidth: 64, previewHeight: 48));
|
||||
var server = DecoderFactory.CreateServer();
|
||||
// Alone, a GPR (VC-5, out of scope) shows its embedded preview.
|
||||
using (var alone = server.Decode(new DecodeRequest(gpr)))
|
||||
Assert.Equal(("managed-preview", 64), (alone!.Decoder, alone.Pixels.Width));
|
||||
|
||||
Write("GOPR0001.JPG", JpegFile(160, 120, 1));
|
||||
using (var withJpeg = server.Decode(new DecodeRequest(gpr)))
|
||||
{
|
||||
Assert.Equal((DecodeTier.EmbeddedPreview, "managed-sidecar"), (withJpeg!.Tier, withJpeg.Decoder));
|
||||
Assert.Equal((160, 120, 160, 120), (withJpeg.Pixels.Width, withJpeg.Pixels.Height, withJpeg.SourceWidth, withJpeg.SourceHeight));
|
||||
}
|
||||
using (var scaled = server.Decode(new DecodeRequest(gpr, MaxLongEdge: 40, Purpose: DecodePurpose.Thumbnail)))
|
||||
Assert.Equal(40, scaled!.Pixels.Width);
|
||||
var probe = new ManagedDecoderProvider().Probe(gpr);
|
||||
Assert.Equal((DecodeTier.EmbeddedPreview, "managed-sidecar", 160, 120), (probe.Tier, probe.Decoder, probe.Width, probe.Height));
|
||||
|
||||
// A companion smaller than the embedded preview is not the better source.
|
||||
var big = Write("GOPR0002.GPR", Gpr(previewWidth: 320, previewHeight: 240));
|
||||
Write("GOPR0002.JPG", JpegFile(160, 120, 1));
|
||||
using (var preview = server.Decode(new DecodeRequest(big)))
|
||||
Assert.Equal(("managed-preview", 320), (preview!.Decoder, preview.Pixels.Width));
|
||||
Assert.Equal("managed-preview", new ManagedDecoderProvider().Probe(big).Decoder);
|
||||
}
|
||||
|
||||
/// <summary>A GoPro GPR as far as Titano reads it: a DNG made by "GoPro" whose only decodable image is a YCbCr JPEG preview.</summary>
|
||||
private static byte[] Gpr(int previewWidth, int previewHeight)
|
||||
{
|
||||
var preview = new IfdSpec().Long(TiffTags.NewSubfileType, 1)
|
||||
.Long(TiffTags.ImageWidth, (uint)previewWidth).Long(TiffTags.ImageLength, (uint)previewHeight)
|
||||
.Short(TiffTags.BitsPerSample, 8, 8, 8).Short(TiffTags.Compression, 7)
|
||||
.Short(TiffTags.PhotometricInterpretation, 6).Strip(JpegFile(previewWidth, previewHeight, 1));
|
||||
var ifd0 = Fixtures.Ifd0("GoPro", "HERO8 Black", 1)
|
||||
.Bytes(TiffTags.DngVersion, 1, 4, 0, 0)
|
||||
.Child(TiffTags.SubIfds, preview);
|
||||
return TiffFile.Build(ifd0);
|
||||
}
|
||||
|
||||
/// <summary>A Windows-like provider claiming native support for everything but declining every file.</summary>
|
||||
private sealed class FakeProvider : IImageDecoderProvider
|
||||
{
|
||||
|
||||
@@ -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