Files
Febe/tests/Febe.Tests/Media/H264/H264TablesTests.cs
T
Alby96andClaude Opus 5.5 da84c79f7e Decodificatore H.264 per i formati dei profili High: 4:2:2, 4:4:4, piani separati, 4:0:0, da 8 a 14 bit, senza perdita (#58)
Il decodificatore rifiutava tutto ciò che non era 4:2:0 a 8 bit, così i video
4:2:2, monocromatici o a 10 bit restavano senza miniatura. Ora i campioni stanno
in piani di uno o due byte e i nuclei di predizione, trasformata e filtro sono
generici su byte e ushort, specializzati dal JIT: a 8 bit i tempi restano quelli
di prima (misurati sui flussi di conformità, 100,4%).

- 4:2:2: DC della crominanza 2x4 con qP + 3, tabelle CAVLC di nC -2, contesti
  CABAC per NumC8x8, predizione intra 8x16, vettore verticale a piena
  risoluzione, bordi della crominanza alle righe 4, 8 e 12.
- 4:4:4: Cb e Cr codificati come la luminanza in CAVLC, con le loro matrici
  e il filtro della luminanza; separate_colour_plane_flag come tre immagini
  monocromatiche con i propri dati di macroblocco e di moto.
- 4:0:0 senza sintassi della crominanza; in uscita la crominanza 4:2:0 al
  valore medio, come il file ufficiale.
- Profondità da 8 a 14 bit: QP da -QpBdOffset, soglie del deblocking e scarti
  dei pesi scalati; uscita a due byte little-endian.
- Senza perdita: qpprime_y_zero_transform_bypass_flag a QP'Y 0, con la DPCM
  della predizione intra orizzontale e verticale.
- VideoFrameDecoder converte in RGB alla profondità e al campionamento del
  fotogramma.

I dieci flussi 4:2:2 (8 e 10 bit) e 4:0:0 della serie ITU-T coincidono con la
ricostruzione ufficiale e passano fra i verificati. 4:4:4, piani separati,
senza perdita e 11-14 bit si provano con flussi sintetici (H264FormatTests).
Il CABAC in 4:4:4 con i piani insieme si rifiuta: mancano i contesti 460-1023.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 17:31:12 +01:00

95 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Febe.Core.Codecs.H264;
namespace Febe.Tests.Codecs.H264;
/// <summary>The constant tables of the decoder: shape checks and a few values taken from the text of the standard.</summary>
[TestClass]
public sealed class H264TablesTests
{
[TestMethod]
public void VariableLengthCodesArePrefixFree()
{
foreach (var (name, codes) in CavlcTables.AllCodeTables())
{
var present = codes.Where(c => c is not null).Select(c => c!).ToList();
for (var i = 0; i < present.Count; i++)
{
for (var j = 0; j < present.Count; j++)
{
if (i != j)
{
Assert.IsFalse(present[j].StartsWith(present[i], StringComparison.Ordinal), $"{name}: {present[i]} è prefisso di {present[j]}");
}
}
}
}
}
[TestMethod]
public void DeblockingTablesCoverEveryIndex()
{
Assert.AreEqual(52, H264Tables.Alpha.Length);
Assert.AreEqual(52, H264Tables.Beta.Length);
Assert.AreEqual(52 * 3, H264Tables.Tc0.Length);
Assert.AreEqual(25, H264Tables.Tc0[(51 * 3) + 2]);
Assert.AreEqual(52, H264Tables.ChromaQp.Length);
Assert.AreEqual(39, H264Tables.ChromaQp[51]);
}
[TestMethod]
public void CodedBlockPatternTablesArePermutations()
{
CollectionAssert.AreEquivalent(Enumerable.Range(0, 48).ToArray(), H264Tables.CbpIntra.Select(b => (int)b).ToArray());
CollectionAssert.AreEquivalent(Enumerable.Range(0, 48).ToArray(), H264Tables.CbpInter.Select(b => (int)b).ToArray());
CollectionAssert.AreEquivalent(Enumerable.Range(0, 16).ToArray(), H264Tables.CbpIntraNoChroma.Select(b => (int)b).ToArray());
CollectionAssert.AreEquivalent(Enumerable.Range(0, 16).ToArray(), H264Tables.CbpInterNoChroma.Select(b => (int)b).ToArray());
}
[TestMethod]
public void ScansArePermutations()
{
CollectionAssert.AreEquivalent(Enumerable.Range(0, 16).ToArray(), H264Tables.ZigZag4x4.Select(b => (int)b).ToArray());
CollectionAssert.AreEquivalent(Enumerable.Range(0, 64).ToArray(), H264Tables.ZigZag8x8.Select(b => (int)b).ToArray());
CollectionAssert.AreEquivalent(Enumerable.Range(0, 16).ToArray(), H264Tables.FieldScan4x4.Select(b => (int)b).ToArray());
CollectionAssert.AreEquivalent(Enumerable.Range(0, 64).ToArray(), H264Tables.FieldScan8x8.Select(b => (int)b).ToArray());
}
[TestMethod]
public void FieldScansGoDownBeforeAcross()
{
// Field scans (Tables 8-13 and 8-14) favour vertical frequencies: the first coefficients after DC are the ones
// below it.
CollectionAssert.AreEqual(new byte[] { 0, 4, 1, 8, 12, 5 }, H264Tables.FieldScan4x4[..6]);
CollectionAssert.AreEqual(new byte[] { 0, 8, 16, 1, 9, 24, 32, 17 }, H264Tables.FieldScan8x8[..8]);
Assert.AreEqual(63, H264Tables.FieldScan8x8[63]);
}
[TestMethod]
public void FieldSignificanceContextsOf8x8BlocksMatchTheStandard()
{
// Table 9-43, ctxIdxInc of significant_coeff_flag for field coded 8×8 blocks: 63 values from 0 to 14.
var table = H264Tables.SignificantContext8x8Field;
Assert.AreEqual(63, table.Length);
Assert.AreEqual(0, table[0]);
Assert.AreEqual(14, table.Max());
Assert.AreEqual(14, table[62]);
Assert.AreEqual(H264Tables.SignificantContext8x8.Length, table.Length);
}
[TestMethod]
[DataRow(-1, 402, -17, 120)]
[DataRow(0, 11, 23, 33)]
[DataRow(1, 417, 17, -10)] // once taken from the field table by mistake
[DataRow(1, 426, -5, 71)]
[DataRow(1, 178, 102, -94)]
[DataRow(2, 435, -10, 79)]
[DataRow(2, 165, -22, 127)]
public void ContextInitialisationMatchesTheStandard(int idc, int ctx, int m, int n)
{
var table = idc < 0 ? CabacTables.InitI : CabacTables.InitPB[idc];
Assert.AreEqual(CabacTables.ContextCount * 2, table.Length);
Assert.AreEqual(m, table[ctx * 2]);
Assert.AreEqual(n, table[(ctx * 2) + 1]);
}
}