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
@@ -79,6 +79,7 @@ internal sealed partial class JpegFile : IDisposable
|
||||
|
||||
private bool _allocated;
|
||||
private bool _pooledArrays;
|
||||
private int _scaleShift;
|
||||
private int _scanCount;
|
||||
private int _sosEnd;
|
||||
|
||||
@@ -119,6 +120,25 @@ internal sealed partial class JpegFile : IDisposable
|
||||
|
||||
public JpegComponent[] Components { get; private set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The reduction of a DCT image decoded to samples, as a power of two (0 full size, 1 half, 2 quarter, 3 eighth):
|
||||
/// each 8×8 block gives (8 >> shift)² samples, the means of its squares of samples (only its DC term at an
|
||||
/// eighth). Set before <see cref="Run"/>; a lossless file is always decoded at full size.
|
||||
/// </summary>
|
||||
public int ScaleShift
|
||||
{
|
||||
get => _scaleShift;
|
||||
set => _scaleShift = Math.Clamp(value, 0, 3);
|
||||
}
|
||||
|
||||
/// <summary>Width of the decoded image: <see cref="Width"/> reduced by <see cref="ScaleShift"/>, rounded up.</summary>
|
||||
public int OutputWidth => Reduce(Width);
|
||||
|
||||
/// <summary>Height of the decoded image: <see cref="Height"/> reduced by <see cref="ScaleShift"/>, rounded up.</summary>
|
||||
public int OutputHeight => Reduce(Height);
|
||||
|
||||
private int Reduce(int length) => (length + (1 << _scaleShift) - 1) >> _scaleShift;
|
||||
|
||||
public int MaxH { get; private set; }
|
||||
|
||||
public int MaxV { get; private set; }
|
||||
@@ -767,14 +787,19 @@ internal sealed partial class JpegFile : IDisposable
|
||||
|
||||
private void Allocate()
|
||||
{
|
||||
_limits.CheckSize(Width, Height);
|
||||
if (Lossless || _mode != Mode.Pixels)
|
||||
{
|
||||
_scaleShift = 0;
|
||||
}
|
||||
|
||||
_limits.CheckSize(OutputWidth, OutputHeight);
|
||||
var keepCoefficients = Progressive || _mode == Mode.Coefficients;
|
||||
long bytes = 0;
|
||||
foreach (var c in Components)
|
||||
{
|
||||
var unit = Lossless ? 1 : 8;
|
||||
long samples = (long)c.PaddedUnitsWide * unit * c.PaddedUnitsHigh * unit;
|
||||
bytes += samples;
|
||||
bytes += samples >> (2 * _scaleShift);
|
||||
if (keepCoefficients && !Lossless)
|
||||
{
|
||||
bytes += samples * 2;
|
||||
@@ -792,11 +817,12 @@ internal sealed partial class JpegFile : IDisposable
|
||||
foreach (var c in Components)
|
||||
{
|
||||
var unit = Lossless ? 1 : 8;
|
||||
c.PlaneStride = c.PaddedUnitsWide * unit;
|
||||
var planeUnit = unit >> _scaleShift;
|
||||
c.PlaneStride = c.PaddedUnitsWide * planeUnit;
|
||||
var samples = c.PlaneStride * c.PaddedUnitsHigh * unit;
|
||||
if (_mode == Mode.Pixels)
|
||||
{
|
||||
c.Plane = ArrayPool<byte>.Shared.Rent(samples);
|
||||
c.Plane = ArrayPool<byte>.Shared.Rent(c.PlaneStride * c.PaddedUnitsHigh * planeUnit);
|
||||
}
|
||||
|
||||
if (Lossless)
|
||||
@@ -984,11 +1010,26 @@ internal sealed partial class JpegFile : IDisposable
|
||||
for (var bx = 0; bx < c.UnitsWide; bx++)
|
||||
{
|
||||
var block = coefficients.AsSpan(((by * c.PaddedUnitsWide) + bx) * 64, 64);
|
||||
JpegDct.Inverse(block, c.Quantization, plane.AsSpan((by * 8 * c.PlaneStride) + (bx * 8)), c.PlaneStride, Precision, to8);
|
||||
TransformBlock(c, plane, block, bx, by, to8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The samples of one block into the plane of its component, at the scale of <see cref="ScaleShift"/>.</summary>
|
||||
private void TransformBlock(JpegComponent c, byte[] plane, ReadOnlySpan<short> block, int bx, int by, ReadOnlySpan<byte> to8)
|
||||
{
|
||||
var n = 8 >> _scaleShift;
|
||||
var output = plane.AsSpan((by * n * c.PlaneStride) + (bx * n));
|
||||
if (_scaleShift == 0)
|
||||
{
|
||||
JpegDct.Inverse(block, c.Quantization, output, c.PlaneStride, Precision, to8);
|
||||
}
|
||||
else
|
||||
{
|
||||
JpegDct.InverseReduced(block, c.Quantization, output, c.PlaneStride, Precision, to8, _scaleShift);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>12-bit samples to 8 bits, rounded.</summary>
|
||||
private static class Twelve
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user