Correzioni della revisione dei codec di casa (C1)

Correggo i difetti confermati dalla revisione di funzione/codec-immagini e
aggiungo le prove che li avrebbero trovati.

- JPEG: una tabella di Huffman con troppi codici corti dava
  ArgumentOutOfRangeException invece di ImageDecodeException, e un file
  rovinato faceva fallire importazione e ricostruzione; ora il controllo si
  fa prima di scrivere le voci. La prova che diceva di coprirlo cadeva invece
  su «tabella troncata»: ora tiene il totale giusto e controlla il messaggio.
- JPEG: il troncamento delle scansioni di Huffman si vede a ogni riga di MCU,
  non dopo l'ultimo MCU (un file tagliato dopo le intestazioni costava 6,7 s).
- JPEG: IDCT ridotta a 1/2 e 1/4 calcolata dai coefficienti; miniatura di una
  foto 4000x3000 da 126 a 59 ms in Release. Il predittore senza perdita non
  cerca più l'indice della componente a ogni campione.
- WebP: con livello del filtro del fotogramma 0 il filtro è spento, come nei
  decodificatori di riferimento; VP8L costruisce solo i gruppi nominati dai
  meta codici (prima fino a 335 MB di tabelle da 160 KB di file).
- BMP OS/2: altezza senza segno e sempre dal basso.
- Array di lavoro dei codec oltre 16 MiB fuori dal pool condiviso, che li
  avrebbe tenuti dopo l'uso.
- Conversione: profilo ICC copiato solo se RGB, profondità oltre 8 bit e
  blocchi gAMA/cHRM/sRGB dichiarati in NotCarried, Lossy vero quando si perde
  precisione.
- Impronta e misure di una foto da una sola lettura e decodifica; ReadSize
  legge solo l'inizio di JPEG, GIF e BMP.
- docs: decisioni (righe aggiunte, con la correzione dei 2,0 MB del set di
  riferimento) e windows.md (Febe.exe rimisurato: 85,6 MB, a capo sistemato).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 16:52:17 +01:00
1 parent d6a6a68496
commit 7e8296e790
32 files changed
+1120 -132

No files matched your search

+17 -10
View File
@@ -85,8 +85,9 @@ internal static class ContentAnalysis
{
try
{
var size = ImageDecoding.ReadSize(bytes);
return (size?.Width, size?.Height, PerceptualHash.Compute(new MemoryStream(bytes, writable: false)));
// 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)
{
@@ -94,22 +95,28 @@ internal static class ContentAnalysis
}
}
/// <summary>The same for a photo too large to keep in memory, opened twice.</summary>
/// <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 OutOfMemoryException or ArgumentException or InvalidOperationException or IndexOutOfRangeException)
{
+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)