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:
1 parent
b4383a6110
commit
d6a6a68496
47 files changed
+3391
-562
No files matched your search
@@ -38,6 +38,53 @@ public static class ImageDecoder
|
||||
var other => throw NotSupported(other),
|
||||
};
|
||||
|
||||
/// <summary>Decodes an image to straight RGBA8 and returns what <see cref="Identify"/> returns as well.</summary>
|
||||
/// <exception cref="ImageFormatNotSupportedException">The format is not known or has no decoder yet.</exception>
|
||||
/// <exception cref="ImageDecodeException">The file is damaged.</exception>
|
||||
/// <exception cref="ImageLimitException">The image is larger than <paramref name="limits"/> allow.</exception>
|
||||
public static RgbaImage Decode(ReadOnlyMemory<byte> data, out ImageInfo info, ImageLimits? limits = null, bool pooled = false)
|
||||
{
|
||||
switch (ImageFormatSniffer.Detect(data.Span))
|
||||
{
|
||||
case ImageFormat.Png:
|
||||
return PngDecoder.Decode(data, out info, limits, pooled);
|
||||
case ImageFormat.Jpeg:
|
||||
return JpegDecoder.Decode(data, out info, limits, pooled);
|
||||
case ImageFormat.Gif:
|
||||
return GifDecoder.Decode(data, out info, limits, pooled);
|
||||
case ImageFormat.Bmp:
|
||||
return BmpDecoder.Decode(data, out info, limits, pooled);
|
||||
case ImageFormat.WebP:
|
||||
return WebPDecoder.Decode(data, out info, limits, pooled);
|
||||
case var other:
|
||||
throw NotSupported(other);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes an image no smaller than <paramref name="minLongSide"/> on its long side where the format allows a
|
||||
/// cheaper reduced decode (JPEG: a half, a quarter or an eighth, the smallest that keeps that side), at full size
|
||||
/// otherwise; with what <see cref="Identify"/> returns (the full size). The result may still need resizing.
|
||||
/// </summary>
|
||||
public static RgbaImage DecodeAtLeast(ReadOnlyMemory<byte> data, int minLongSide, out ImageInfo info, ImageLimits? limits = null, bool pooled = false)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(minLongSide);
|
||||
if (ImageFormatSniffer.Detect(data.Span) != ImageFormat.Jpeg)
|
||||
{
|
||||
return Decode(data, out info, limits, pooled);
|
||||
}
|
||||
|
||||
var header = JpegDecoder.Identify(data, limits);
|
||||
var longSide = Math.Max(header.Width, header.Height);
|
||||
var reduction = 0;
|
||||
while (reduction < 3 && ((longSide + (2 << reduction) - 1) >> (reduction + 1)) >= minLongSide)
|
||||
{
|
||||
reduction++;
|
||||
}
|
||||
|
||||
return JpegDecoder.DecodeReduced(data, reduction, out info, limits, pooled);
|
||||
}
|
||||
|
||||
private static ImageFormatNotSupportedException NotSupported(ImageFormat format) =>
|
||||
format == ImageFormat.Unknown
|
||||
? new ImageFormatNotSupportedException("Formato d'immagine non riconosciuto.")
|
||||
|
||||
Reference in new issue
Block a user