The MakerNote interval-shooting hint (Panasonic TimerRecording) is kept as FrameFlags.Intervalometer from indexing on, so it reaches the sidecar, the index, sync and the protocol. When most frames carry it, gaps in the cadence are the intervalometer's deliberate pauses and the advisor picks adaptive timing (Advisor.Reason.Timing.Intervalometer, BRIEF §10.3). Frames both analyses find undecodable are now one finding over the union of both lists at the higher severity: the deep pass also lists missing, corrupt and beyond-this-host frames, which the light analysis never flags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
112 lines
6.0 KiB
C#
112 lines
6.0 KiB
C#
using Titano.Core.Imaging;
|
|
using Titano.Core.Metadata;
|
|
using Titano.Core.Model;
|
|
|
|
namespace Titano.Core.Archiving;
|
|
|
|
/// <summary>Edits of the frame list of a <see cref="SequenceManifest"/>; frames stay in capture order with gap-free indexes.</summary>
|
|
public static class SequenceFrames
|
|
{
|
|
/// <summary>Capture time (unknown last), then file name.</summary>
|
|
public static readonly IComparer<SidecarFrame> CaptureOrder = Comparer<SidecarFrame>.Create((a, b) =>
|
|
{
|
|
var byTime = (a.CapturedAt ?? DateTime.MaxValue).CompareTo(b.CapturedAt ?? DateTime.MaxValue);
|
|
return byTime != 0 ? byTime : string.CompareOrdinal(a.File, b.File);
|
|
});
|
|
|
|
/// <summary>A frame record from light metadata (with <see cref="FrameFlags.Intervalometer"/> when the MakerNote says so).</summary>
|
|
/// <param name="file">Path relative to the sequence folder.</param>
|
|
/// <param name="fallbackCapture">Used when the file records no capture time of its own (only a file-system date).</param>
|
|
public static SidecarFrame FromMetadata(Guid id, string file, string? original, long size, string? sha256, FrameMetadata metadata,
|
|
DateTime? fallbackCapture = null)
|
|
{
|
|
var useFallback = fallbackCapture is not null && metadata.TimestampSource is TimestampSource.FileSystem or TimestampSource.Unknown;
|
|
return new SidecarFrame
|
|
{
|
|
Id = id,
|
|
File = file,
|
|
Original = original,
|
|
Size = size,
|
|
Sha256 = sha256?.ToLowerInvariant(),
|
|
CapturedAt = useFallback ? DateTime.SpecifyKind(fallbackCapture!.Value, DateTimeKind.Unspecified) : metadata.CapturedAt,
|
|
UtcOffset = useFallback ? null : metadata.UtcOffsetMinutes,
|
|
TimeSource = useFallback ? TimestampSource.Unknown : metadata.TimestampSource,
|
|
Exposure = metadata.ExposureTime,
|
|
FNumber = metadata.FNumber,
|
|
Iso = metadata.Iso,
|
|
Focal = metadata.FocalLength,
|
|
Bias = metadata.ExposureBias,
|
|
Wb = metadata.WhiteBalanceMode,
|
|
Orientation = metadata.Orientation,
|
|
W = metadata.Width,
|
|
H = metadata.Height,
|
|
Format = metadata.Format,
|
|
PreviewOffset = metadata.LargestPreview?.Offset,
|
|
PreviewLength = metadata.LargestPreview?.Length,
|
|
PreviewW = Positive(metadata.LargestPreview?.Width),
|
|
PreviewH = Positive(metadata.LargestPreview?.Height),
|
|
Flags = metadata.IntervalShooting == true ? FrameFlags.Intervalometer : FrameFlags.None,
|
|
};
|
|
}
|
|
|
|
/// <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.
|
|
/// </summary>
|
|
public static SequenceManifest Insert(SequenceManifest manifest, IReadOnlyList<SidecarFrame> added)
|
|
{
|
|
if (added.Count == 0) return manifest;
|
|
var incoming = added.Order(CaptureOrder).ToList();
|
|
var merged = new List<SidecarFrame>(manifest.Frames.Count + incoming.Count);
|
|
var next = 0;
|
|
foreach (var frame in manifest.Frames)
|
|
{
|
|
while (next < incoming.Count && CaptureOrder.Compare(incoming[next], frame) < 0) merged.Add(incoming[next++]);
|
|
merged.Add(frame);
|
|
}
|
|
while (next < incoming.Count) merged.Add(incoming[next++]);
|
|
return WithFrames(manifest, merged);
|
|
}
|
|
|
|
/// <summary>Replaces the frame list (indexes renumbered) and bumps the frames version.</summary>
|
|
public static SequenceManifest WithFrames(SequenceManifest manifest, IReadOnlyList<SidecarFrame> frames)
|
|
{
|
|
var renumbered = new SidecarFrame[frames.Count];
|
|
for (var i = 0; i < frames.Count; i++) renumbered[i] = frames[i].I == i ? frames[i] : frames[i] with { I = i };
|
|
return manifest with
|
|
{
|
|
Frames = renumbered,
|
|
Versions = manifest.Versions with { Frames = manifest.Versions.Frames + 1 },
|
|
UpdatedAt = DateTimeOffset.UtcNow,
|
|
};
|
|
}
|
|
|
|
/// <summary>Applies per-frame changes by id (flags, hashes); frames not in <paramref name="changes"/> are kept.</summary>
|
|
public static SequenceManifest Update(SequenceManifest manifest, IReadOnlyDictionary<Guid, Func<SidecarFrame, SidecarFrame>> changes)
|
|
{
|
|
var frames = manifest.Frames.Select(f => changes.TryGetValue(f.Id, out var change) ? change(f) : f).ToList();
|
|
return manifest with { Frames = frames, UpdatedAt = DateTimeOffset.UtcNow };
|
|
}
|
|
}
|