Codec di casa al posto di SkiaSharp (C1, passo 5)

SkiaSharp e SkiaSharp.NativeAssets.Linux.NoDependencies escono da
Directory.Packages.props e da ogni progetto, per la regola «niente
componenti esterni». Tutto ciò che leggeva, ridimensionava o disegnava
immagini con Skia ora usa codice scritto in casa sulla BCL:

- ImageResampler: Lanczos3 separabile o media per area, alfa
  premoltiplicata, luce lineare facoltativa; ImageGray per l'impronta.
- Il lettore JPEG decodifica ridotto a 1/2, 1/4, 1/8; le miniature
  chiedono almeno il doppio del lato lungo, così l'ultimo passo resta a
  Lanczos e la miniatura resta uguale alla lettura intera.
- ImageOrientation applica l'EXIF in un punto solo (miniature, impronte,
  anteprime, dimensioni mostrate).
- ImageConverter cambia formato fra JPEG, PNG e WebP portando EXIF, ICC,
  XMP e testi, con l'etichetta d'orientamento e i pixel non ruotati;
  PngEncoder scrive anche i testi (tEXt o iTXt).
- Febe.Core.Drawing: rasterizzatore con antialiasing (tracciati,
  riempimenti, tratti, gradienti) per icona, immagini dimostrative,
  riquadro neutro dei video, foto del sito di prova e prove. Febe.ico
  rigenerata.
- ThumbnailStore legge anche i BMP a 24 bit, come quelli del decoder
  video del ramo funzione/decoder-h264.

Le impronte salvate restano confrontabili (390 su 393 campioni identiche,
le altre a distanza 2, soglia 6): nessun ricalcolo. Un PNG o JPEG
troncato ora non ha miniatura né impronta. Documenti, elenco dei
componenti della pagina «Informazioni» e decisioni aggiornati; nuove
prove per ridimensionamento, orientamento, lettura ridotta, conversione
con metadati, testi PNG e rasterizzatore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 16:02:03 +01:00
1 parent b4383a6110
commit d6a6a68496
47 files changed
+3391 -562

No files matched your search

+18 -3
View File
@@ -67,7 +67,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
{
@@ -80,6 +80,21 @@ 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
{
var size = ImageDecoding.ReadSize(bytes);
return (size?.Width, size?.Height, PerceptualHash.Compute(new MemoryStream(bytes, writable: false)));
}
catch (Exception ex) when (ex is OutOfMemoryException or ArgumentException or InvalidOperationException or IndexOutOfRangeException)
{
return (null, null, null);
}
}
/// <summary>The same for a photo too large to keep in memory, opened twice.</summary>
private static (int? Width, int? Height, ulong? Hash) Decode(Func<Stream> open)
{
try
@@ -96,9 +111,9 @@ internal static class ContentAnalysis
using var again = open();
return (width, height, PerceptualHash.Compute(again));
}
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 -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
@@ -159,7 +159,7 @@ virgolette quando serve, apostrofo davanti a un testo che Excel prenderebbe per
## Limiti noti
- 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.