/// <summary> /// Converts the 8x8 region of the image whose top-left corner is x,y to its YCbCr values. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="pixels">The pixel accessor.</param> /// <param name="tables">The reference to the tables instance.</param> /// <param name="x">The x-position within the image.</param> /// <param name="y">The y-position within the image.</param> /// <param name="yBlock">The luminance block.</param> /// <param name="cbBlock">The red chroma block.</param> /// <param name="crBlock">The blue chroma block.</param> /// <param name="rgbBytes">Temporal <see cref="PixelArea{TPixel}"/> provided by the caller</param> private static void ToYCbCr <TPixel>( PixelAccessor <TPixel> pixels, RgbToYCbCrTables *tables, int x, int y, Block8x8F *yBlock, Block8x8F *cbBlock, Block8x8F *crBlock, PixelArea <TPixel> rgbBytes) where TPixel : struct, IPixel <TPixel> { float *yBlockRaw = (float *)yBlock; float *cbBlockRaw = (float *)cbBlock; float *crBlockRaw = (float *)crBlock; rgbBytes.Reset(); pixels.CopyRGBBytesStretchedTo(rgbBytes, y, x); ref byte data0 = ref rgbBytes.Bytes[0];
public static void Allocate(ref float *yBlockRaw, ref float *cbBlockRaw, ref float *crBlockRaw, ref RgbToYCbCrTables *tables, int index, int r, int g, int b) { // float y = (0.299F * r) + (0.587F * g) + (0.114F * b); yBlockRaw[index] = (tables->YRTable[r] + tables->YGTable[g] + tables->YBTable[b]) >> ScaleBits; // float cb = 128F + ((-0.168736F * r) - (0.331264F * g) + (0.5F * b)); cbBlockRaw[index] = (tables->CbRTable[r] + tables->CbGTable[g] + tables->CbBTable[b]) >> ScaleBits; // float b = MathF.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero); crBlockRaw[index] = (tables->CbBTable[r] + tables->CrGTable[g] + tables->CrBTable[b]) >> ScaleBits; }