Unione di funzione/codec-immagini in funzione/decoder-h264 (catena della 0.3.0)

Porta nel decodificatore H.264 le regole senza componenti esterni, la sessione S4b e i codec
di immagini di casa (C1), così la richiesta di unione di questo ramo contiene già tutta la
catena. Conflitti risolti tenendo le due parti: in decisioni.md tutte le righe, prima quelle
della catena e poi quelle del decodificatore; in docker.md, processo.md e Sviluppo.md né
ffmpeg (uscito con questo ramo) né SkiaSharp (uscito con C1), con l'eccezione «da fare» delle
prove di conformità; nelle prove di Febe.Tests entrambe le cartelle di file copiati e, nelle
prove delle miniature, sia i video sia le immagini di riferimento.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-25 11:16:26 +01:00
commit 8bcc86e496
279 files changed
+25617 -816

No files matched your search

+32 -10
View File
@@ -68,7 +68,7 @@ internal static class ContentAnalysis
sha = Convert.ToHexStringLower(SHA256.HashData(bytes));
ct.ThrowIfCancellationRequested();
(width, height, hash) = Decode(() => new MemoryStream(bytes, writable: false));
(width, height, hash) = Decode(bytes);
}
else
{
@@ -81,25 +81,47 @@ internal static class ContentAnalysis
return new ContentFacts(type, length, sha, width, height, null, hash, date, null);
}
/// <summary>Size as shown and perceptual hash of a photo in memory; nulls for what Febe cannot decode (e.g. HEIC).</summary>
private static (int? Width, int? Height, ulong? Hash) Decode(byte[] bytes)
{
try
{
// The bytes are already in memory: one decode of them gives hash and size, with no copy.
var (hash, size) = PerceptualHash.ComputeWithSize(bytes);
return (size?.Width, size?.Height, hash);
}
catch (Exception ex) when (ex is OutOfMemoryException or ArgumentException or InvalidOperationException or IndexOutOfRangeException)
{
return (null, null, null);
}
}
/// <summary>
/// The same for a photo over <see cref="InMemoryLimit"/>, which the analysis does not keep for the copy: it is read once
/// more, whole (up to <see cref="ImageDecoding.MaxFileBytes"/>; the codecs need the bytes in memory), and decoded
/// once for both hash and size.
/// </summary>
private static (int? Width, int? Height, ulong? Hash) Decode(Func<Stream> open)
{
try
{
int? width = null, height = null;
byte[]? data;
using (var stream = open())
{
if (ImageDecoding.ReadSize(stream) is { } size)
{
(width, height) = size;
}
data = ImageDecoding.ReadAll(stream);
}
using var again = open();
return (width, height, PerceptualHash.Compute(again));
if (data is null)
{
return (null, null, null);
}
var (hash, size) = PerceptualHash.ComputeWithSize(data);
return (size?.Width, size?.Height, hash);
}
catch (Exception ex) when (ex is ArgumentException or InvalidOperationException or OutOfMemoryException)
catch (Exception ex) when (ex is OutOfMemoryException or ArgumentException or InvalidOperationException or IndexOutOfRangeException)
{
return (null, null, null); // a format SkiaSharp cannot decode (e.g. HEIC): no size, no hash
return (null, null, null); // formats Febe cannot decode (e.g. HEIC) already give nulls: no size, no hash
}
}
+4 -4
View File
@@ -517,11 +517,11 @@ public sealed class ImportCopier(ImportEnvironment env)
{
try
{
hash = PerceptualHash.ComputeFromFile(saved.FullPath);
await using var stream = File.OpenRead(saved.FullPath);
if (ImageDecoding.ReadSize(stream) is { } size)
// One read of the file gives both the perceptual hash and the size as shown.
(hash, var size) = PerceptualHash.ComputeWithSizeFromFile(saved.FullPath);
if (size is { } shown)
{
(width, height) = size;
(width, height) = shown;
}
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
+4 -18
View File
@@ -1,34 +1,20 @@
using Febe.Core.Library;
using SkiaSharp;
namespace Febe.Core.Import;
/// <summary>In-memory previews of source photos for the comparison panel (nothing is written to disk).</summary>
internal static class ImportPreview
{
private const int JpegQuality = 82;
/// <summary>A JPEG of the image, upright, at most <paramref name="longSide"/> pixels; null when it cannot be decoded.</summary>
public static byte[]? RenderJpeg(Stream encodedImage, int longSide)
{
using var bitmap = ImageDecoding.DecodeUpright(encodedImage, longSide);
if (bitmap is null)
using var image = ThumbnailStore.DecodeFor(encodedImage, longSide);
if (image is null)
{
return null;
}
var scale = Math.Min(1.0, (double)longSide / Math.Max(bitmap.Width, bitmap.Height));
var width = Math.Max(1, (int)Math.Round(bitmap.Width * scale));
var height = Math.Max(1, (int)Math.Round(bitmap.Height * scale));
using var surface = SKSurface.Create(new SKImageInfo(width, height, SKColorType.Rgba8888, SKAlphaType.Premul));
surface.Canvas.Clear(SKColors.White);
using (var image = SKImage.FromBitmap(bitmap))
{
surface.Canvas.DrawImage(image, new SKRect(0, 0, width, height), new SKSamplingOptions(SKCubicResampler.Mitchell), null);
}
using var snapshot = surface.Snapshot();
using var data = snapshot.Encode(SKEncodedImageFormat.Jpeg, JpegQuality);
return data?.ToArray();
using var small = ThumbnailStore.Render(image, longSide);
return ThumbnailStore.Jpeg(small);
}
}
+1 -1
View File
@@ -168,7 +168,7 @@ virgolette quando serve, apostrofo davanti a un testo che Excel prenderebbe per
primo all'ultimo tempo di presentazione, leggendo solo i primi 2 MB e l'ultimo MB. Un MPEG non ha data. La
miniatura viene solo dagli FLV H.264: WMV (VC-1) e MPEG-2 non si decodificano, e i campioni di un MPEG, spezzati nei
pacchetti PES, non si elencano, nemmeno se H.264.
- HEIC/HEIF: si riconoscono, ma SkiaSharp (pacchetto Linux senza dipendenze) non li decodifica: niente dimensioni,
- HEIC/HEIF: si riconoscono, ma i codec di Febe (PNG, JPEG, GIF, BMP, WebP) non li decodificano: niente dimensioni,
impronta e miniatura, e l'EXIF dentro HEIC non si legge. Contano solo SHA-256, nome e data di modifica.
- La sola lettura si riconosce dalle opzioni di montaggio (Linux, `ro`) o dai dischi ottici (Windows): una cartella
scrivibile per il sistema ma non per Febe non si riconosce; lì «Sposta» lascia l'originale e lo dice.