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
@@ -398,6 +398,131 @@ public sealed class WebPContainerTests
|
||||
})));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OnlyTheGroupsTheMetaImageNamesAreBuilt()
|
||||
{
|
||||
// An 8×8 image with meta codes of 4×4 blocks: a 2×2 meta image whose pixels name groups 5, 2, 2 and 5 (in
|
||||
// green; red 0). The stream holds the codes of groups 0 to 5; only 2 and 5 paint.
|
||||
static byte[] Stream(int groups, (int Meta0, int Meta1) names, Action<Vp8LBitWriter, int> unused)
|
||||
{
|
||||
var w = new Vp8LBitWriter();
|
||||
w.WriteBits(0x2F, 8);
|
||||
w.WriteBits(7, 14);
|
||||
w.WriteBits(7, 14);
|
||||
w.WriteBits(0, 4);
|
||||
w.WriteBits(0, 1); // no transform
|
||||
w.WriteBits(0, 1); // no colour cache
|
||||
w.WriteBits(1, 1); // meta codes
|
||||
w.WriteBits(0, 3); // meta bits 2: blocks of 4×4, a 2×2 meta image
|
||||
|
||||
// The meta image: no cache, green a two-symbol code (bit 0 → the smaller name, 1 → the larger), the rest
|
||||
// single symbols; the pixel bits pick larger, smaller, smaller, larger.
|
||||
w.WriteBits(0, 1);
|
||||
var (small, large) = names;
|
||||
w.WriteBits(1, 1);
|
||||
w.WriteBits(small == large ? 0u : 1u, 1);
|
||||
w.WriteBits(1, 1);
|
||||
w.WriteBits((uint)(small & 0xFF), 8);
|
||||
if (small != large)
|
||||
{
|
||||
w.WriteBits((uint)(large & 0xFF), 8);
|
||||
}
|
||||
|
||||
Single(w, small >> 8); // red: the high byte of the group
|
||||
Single(w, 0);
|
||||
Single(w, 0);
|
||||
Single(w, 0);
|
||||
foreach (var bit in (uint[])[1, 0, 0, 1])
|
||||
{
|
||||
if (small != large)
|
||||
{
|
||||
w.WriteBits(bit, 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (var g = 0; g < groups; g++)
|
||||
{
|
||||
if (g == small || g == large)
|
||||
{
|
||||
// Green g + 1, red g, blue 2·g, alpha 255.
|
||||
Single(w, g + 1);
|
||||
Single(w, g);
|
||||
Single(w, 2 * g);
|
||||
Single(w, 255);
|
||||
Single(w, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
unused(w, g);
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteBits(0, 32);
|
||||
return WebPTestFiles.Riff(("VP8L", w.ToArray()));
|
||||
}
|
||||
|
||||
static void Single(Vp8LBitWriter w, int symbol)
|
||||
{
|
||||
w.WriteBits(1, 1);
|
||||
w.WriteBits(0, 1);
|
||||
w.WriteBits(1, 1);
|
||||
w.WriteBits((uint)(symbol & 0xFF), 8);
|
||||
}
|
||||
|
||||
static void Cheap(Vp8LBitWriter w, int g)
|
||||
{
|
||||
for (var k = 0; k < 5; k++)
|
||||
{
|
||||
w.WriteBits(1, 1); // simple
|
||||
w.WriteBits(0, 1); // one symbol
|
||||
w.WriteBits(0, 1); // of one bit
|
||||
w.WriteBits(0, 1); // symbol 0
|
||||
}
|
||||
}
|
||||
|
||||
using (var image = WebPDecoder.Decode(Stream(6, (2, 5), Cheap)))
|
||||
{
|
||||
Assert.AreEqual(((byte)5, (byte)6, (byte)10, (byte)255), image.GetPixel(1, 1), "gruppo 5 in alto a sinistra");
|
||||
Assert.AreEqual(((byte)2, (byte)3, (byte)4, (byte)255), image.GetPixel(6, 1), "gruppo 2 in alto a destra");
|
||||
Assert.AreEqual(((byte)2, (byte)3, (byte)4, (byte)255), image.GetPixel(1, 6), "gruppo 2 in basso a sinistra");
|
||||
Assert.AreEqual(((byte)5, (byte)6, (byte)10, (byte)255), image.GetPixel(7, 7), "gruppo 5 in basso a destra");
|
||||
}
|
||||
|
||||
// A single meta pixel naming group 65535: 65,536 groups in the stream (about 160 KB of codes). Building all
|
||||
// of them took about 335 MB of tables; only one is built now, so a working budget of 4 MiB is enough.
|
||||
var huge = Stream(65536, (65535, 65535), Cheap);
|
||||
Assert.IsLessThan(200_000, huge.Length);
|
||||
using (var image = WebPDecoder.Decode(huge, new ImageLimits { MaxWorkingBytes = 4 * 1024 * 1024 }))
|
||||
{
|
||||
Assert.AreEqual(((byte)255, (byte)0, (byte)254, (byte)255), image.GetPixel(4, 4));
|
||||
}
|
||||
|
||||
// The codes of unused groups are still read and checked: three symbols of length 1 are no prefix code.
|
||||
Assert.ThrowsExactly<ImageDecodeException>(() => WebPDecoder.Decode(Stream(6, (2, 5), (w, g) =>
|
||||
{
|
||||
if (g != 3)
|
||||
{
|
||||
Cheap(w, g);
|
||||
return;
|
||||
}
|
||||
|
||||
w.WriteBits(0, 1); // normal code
|
||||
w.WriteBits(0, 4); // four code length codes: 17, 18, 0, 1
|
||||
w.WriteBits(0, 3);
|
||||
w.WriteBits(0, 3);
|
||||
w.WriteBits(1, 3); // length code 0 has length 1
|
||||
w.WriteBits(1, 3); // length code 1 has length 1
|
||||
w.WriteBits(1, 1); // max_symbol present
|
||||
w.WriteBits(0, 3); // length_nbits = 2
|
||||
w.WriteBits(1, 2); // max_symbol = 3
|
||||
w.WriteBits(7, 3); // three lengths of 1
|
||||
for (var k = 1; k < 5; k++)
|
||||
{
|
||||
Single(w, 0);
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StreamsCutShortAreRefusedOrReadWhole()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user