Files
Febe/tests/Febe.Tests/Media/YuvToRgbTests.cs
Alby96andClaude Opus 5.5 7b10f4ad4c HEVC e HEIF: limiti di memoria contro i file danneggiati e correzioni della revisione (#58)
Un flusso HEVC di pochi byte poteva far allocare gigabyte: ora un SPS il cui
buffer supera il MaxDpbSize del livello 6.2 è rifiutato, il buffer non cresce
oltre quanto l'SPS dichiara e una sola immagine grigia, riusata, sta per ogni
riferimento mancante (il POC viaggia nelle liste). Nei file HEIF ogni immagine
deve avere la dimensione del suo ispe, controllata dal decodificatore prima di
allocare; i riquadri di una griglia devono coprire l'uscita senza traboccare,
i loro byte non superano il file né MaxTotalBytes, e ciò che va storto nei
riquadri decodificati in parallelo esce come HeifException.

Inoltre: SPS e PPS ripetuti identici dentro un'immagine sono accettati (7.4.2.4.4)
e uno cambiato vale dall'immagine dopo; le estensioni SCC sono rifiutate subito;
l'intervallo di luma_offset segue l'alta precisione; YCgCo convertito, le altre
matrici approssimate e documentate. «Oggetto» e «riquadro» al posto di
«elemento» e «tessera» per HEIF (glossario). Righe nuove in decisioni.md:
limiti, righe superate, consegne al binario dei documenti, piano per NSIS,
Node e tini.

Prove nuove su flussi HEVC scritti bit per bit con un codificatore CABAC di
prova, su file HEIF costruiti apposta e sulla conversione YCgCo.

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

38 lines
1.7 KiB
C#
Raw Permalink 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;
namespace Febe.Tests.Codecs;
/// <summary>The shared Y′CbCr to RGB conversion: the matrices that are not Y′CbCr ones.</summary>
[TestClass]
public sealed class YuvToRgbTests
{
[TestMethod]
[DataRow(128, 148, 128, true, 8, 108, 148, 108)]
[DataRow(100, 128, 150, true, 8, 122, 100, 78)]
[DataRow(200, 100, 160, true, 8, 255, 172, 196)]
[DataRow(512, 592, 512, true, 10, 108, 148, 108)]
[DataRow(16, 128, 128, false, 8, 0, 0, 0)]
[DataRow(235, 128, 128, false, 8, 255, 255, 255)]
[DataRow(126, 151, 128, false, 8, 102, 154, 102)]
public void YCgCoIsNotConvertedAsYCbCr(int y, int cg, int co, bool fullRange, int bitDepth, int r, int g, int b)
{
// matrix_coeffs 8 (H.273): G = Y + Cg, R = Y − Cg + Co, B = Y − Cg − Co, Cg and Co around the middle of their
// range and, in limited range, scaled as Cb and Cr are (224 steps), Y as luma (219 steps from 16).
var k = YuvToRgb.For(8, fullRange, bitDepth, bitDepth, 1080);
var planes = new YuvPlanes<ushort>([(ushort)y], [(ushort)cg], [(ushort)co], 1, 1, 0, 0, false, bitDepth, bitDepth);
var rgb = new byte[3];
YuvToRgb.Convert(planes, k, 1, rgb, 3, 3, 1, 1);
Assert.AreEqual((r, g, b), (rgb[0], rgb[1], rgb[2]));
}
[TestMethod]
public void YCgCoGreyStaysGrey()
{
var k = YuvToRgb.For(8, false, 8, 8, 1080);
var planes = new YuvPlanes<byte>([16, 126, 235], [128, 128, 128], [128, 128, 128], 3, 1, 0, 0, false, 8, 8);
var rgb = new byte[9];
YuvToRgb.Convert(planes, k, 1, rgb, 9, 3, 3, 1);
CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 128, 128, 128, 255, 255, 255 }, rgb);
}
}