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
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user