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:
1 parent
d6a6a68496
commit
7e8296e790
32 files changed
+1120
-132
No files matched your search
@@ -46,6 +46,14 @@ internal sealed partial class JpegFile
|
||||
var eobRun = 0;
|
||||
for (var mcu = 0; mcu < total; mcu++)
|
||||
{
|
||||
// Past the end the reader gives zero bits, which are valid codes: without this check a file cut after
|
||||
// its headers would be decoded to the last MCU before failing. Padding once used stays used until a
|
||||
// restart, so failing at the first MCU row that needed it changes only when the error comes.
|
||||
if (mcu > 0 && mcu % perRow == 0 && reader.UsedPadding)
|
||||
{
|
||||
throw Truncated(reader.ReachedEnd, "blocco");
|
||||
}
|
||||
|
||||
if (_restartInterval > 0 && mcu > 0 && mcu % _restartInterval == 0)
|
||||
{
|
||||
if (reader.UsedPadding)
|
||||
@@ -130,12 +138,16 @@ internal sealed partial class JpegFile
|
||||
|
||||
if (reader.UsedPadding)
|
||||
{
|
||||
throw reader.ReachedEnd ? new ImageDecodeException("JPEG troncato: i dati compressi finiscono prima dell'ultimo blocco.") : InterruptedScan();
|
||||
throw Truncated(reader.ReachedEnd, "blocco");
|
||||
}
|
||||
|
||||
return FindNextMarker(reader.Position);
|
||||
}
|
||||
|
||||
/// <summary>The error for a scan that needed bits it did not have: cut short (<paramref name="reachedEnd"/>) or interrupted by a marker.</summary>
|
||||
private static ImageDecodeException Truncated(bool reachedEnd, string unit) =>
|
||||
reachedEnd ? new ImageDecodeException($"JPEG troncato: i dati compressi finiscono prima dell'ultimo {unit}.") : InterruptedScan();
|
||||
|
||||
private static ImageDecodeException InterruptedScan() =>
|
||||
new("JPEG danneggiato: i dati compressi di una scansione si interrompono prima dell'ultimo blocco.");
|
||||
|
||||
@@ -317,6 +329,12 @@ internal sealed partial class JpegFile
|
||||
{
|
||||
var mx = mcu % perRow;
|
||||
var my = mcu / perRow;
|
||||
if (mx == 0 && mcu > 0 && reader.UsedPadding)
|
||||
{
|
||||
// As in DecodeHuffmanScan: fail at the first MCU row that ran out of data, not after the last one.
|
||||
throw Truncated(reader.ReachedEnd, "campione");
|
||||
}
|
||||
|
||||
if (_restartInterval > 0 && mcu > 0 && mcu % _restartInterval == 0)
|
||||
{
|
||||
if (reader.UsedPadding)
|
||||
@@ -347,7 +365,7 @@ internal sealed partial class JpegFile
|
||||
> 16 => throw BadValue(),
|
||||
_ => reader.ReceiveExtend(s),
|
||||
};
|
||||
predictor.Store(c, x, y, difference);
|
||||
predictor.Store(ci, c, x, y, difference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,7 +373,7 @@ internal sealed partial class JpegFile
|
||||
|
||||
if (reader.UsedPadding)
|
||||
{
|
||||
throw reader.ReachedEnd ? new ImageDecodeException("JPEG troncato: i dati compressi finiscono prima dell'ultimo campione.") : InterruptedScan();
|
||||
throw Truncated(reader.ReachedEnd, "campione");
|
||||
}
|
||||
|
||||
predictor.Finish();
|
||||
@@ -389,15 +407,16 @@ internal sealed partial class JpegFile
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Whether (x, y) of component <paramref name="c"/> is on the first line of the scan or restart interval.</summary>
|
||||
public bool IsFirstLine(JpegComponent c, int y) => y == _firstRow[Array.IndexOf(_scan.Components, c)];
|
||||
/// <summary>Whether row <paramref name="y"/> of scan component <paramref name="ci"/> is the first line of the scan or restart interval.</summary>
|
||||
public bool IsFirstLine(int ci, int y) => y == _firstRow[ci];
|
||||
|
||||
public int Predict(JpegComponent c, int x, int y)
|
||||
/// <summary>The prediction for (x, y) of <paramref name="c"/>, the scan's component <paramref name="ci"/>.</summary>
|
||||
public int Predict(int ci, JpegComponent c, int x, int y)
|
||||
{
|
||||
var samples = c.Samples!;
|
||||
var stride = c.PlaneStride;
|
||||
var i = (y * stride) + x;
|
||||
if (IsFirstLine(c, y))
|
||||
if (y == _firstRow[ci])
|
||||
{
|
||||
return x == 0 ? _initial : samples[i - 1];
|
||||
}
|
||||
@@ -422,9 +441,9 @@ internal sealed partial class JpegFile
|
||||
};
|
||||
}
|
||||
|
||||
public void Store(JpegComponent c, int x, int y, int difference)
|
||||
public void Store(int ci, JpegComponent c, int x, int y, int difference)
|
||||
{
|
||||
var predicted = Predict(c, x, y);
|
||||
var predicted = Predict(ci, c, x, y);
|
||||
c.Samples![(y * c.PlaneStride) + x] = (ushort)((predicted + difference) & 0xFFFF);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user