using Febe.Core.Codecs; namespace Febe.Tests.Codecs; /// The shared Y′CbCr to RGB conversion: the matrices that are not Y′CbCr ones. [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)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([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); } }