private static IEnumerable<string> GetPixelLayoutStrings(YCbCrPixelLayout pixelLayout) { var strings = new List<string> { "Cb Offset: " + pixelLayout.CbOffset, "Cb Pitch: " + pixelLayout.CbPitch, "Cb X Pitch: " + pixelLayout.CbXPitch, "Cr Offset: " + pixelLayout.CrOffset, "Cr Pitch: " + pixelLayout.CrPitch, "Cr X Pitch: " + pixelLayout.CrXPitch }; return strings; }
private void GetYCbCrFromPixel(YCbCrPixelLayout layout, byte[] currentPreviewBuffer, int xFramePos, int yFramePos, out byte y, out int cr, out int cb) { // Find the bytes corresponding to the pixel location in the frame. int yBufferIndex = layout.YOffset + yFramePos * layout.YPitch + xFramePos * layout.YXPitch; int crBufferIndex = layout.CrOffset + (yFramePos / 2) * layout.CrPitch + (xFramePos / 2) * layout.CrXPitch; int cbBufferIndex = layout.CbOffset + (yFramePos / 2) * layout.CbPitch + (xFramePos / 2) * layout.CbXPitch; // The luminance value is always positive. y = currentPreviewBuffer[yBufferIndex]; // The preview buffer contains an unsigned value between 255 and 0. // The buffer value is cast from a byte to an integer. cr = currentPreviewBuffer[crBufferIndex]; // Convert to a signed value between 127 and -128. cr -= 128; // The preview buffer contains an unsigned value between 255 and 0. // The buffer value is cast from a byte to an integer. cb = currentPreviewBuffer[cbBufferIndex]; // Convert to a signed value between 127 and -128. cb -= 128; }
/// <summary> /// Gets the Y, Cb and Cr values from pixel. /// </summary> /// <param name="layout">The layout.</param> /// <param name="currentPreviewBuffer">The current preview buffer.</param> /// <param name="xFramePos">The x frame pos.</param> /// <param name="yFramePos">The y frame pos.</param> /// <param name="y">The y.</param> /// <param name="cr">The cr.</param> /// <param name="cb">The cb.</param> private void GetYCbCrFromPixel(YCbCrPixelLayout layout, byte[] currentPreviewBuffer, int xFramePos, int yFramePos, out byte y, out int cr, out int cb) { // Find the bytes corresponding to the pixel location in the frame. int yBufferIndex = layout.YOffset + (yFramePos * layout.YPitch) + (xFramePos * layout.YXPitch); int crBufferIndex = layout.CrOffset + ((yFramePos / 2) * layout.CrPitch) + ((xFramePos / 2) * layout.CrXPitch); int cbBufferIndex = layout.CbOffset + ((yFramePos / 2) * layout.CbPitch) + ((xFramePos / 2) * layout.CbXPitch); // The luminance value is always positive. y = currentPreviewBuffer[yBufferIndex]; // The preview buffer contains an unsigned value between 255 and 0. // The buffer value is cast from a byte to an integer. cr = currentPreviewBuffer[crBufferIndex]; // Convert to a signed value between 127 and -128. cr -= 128; // The preview buffer contains an unsigned value between 255 and 0. // The buffer value is cast from a byte to an integer. cb = currentPreviewBuffer[cbBufferIndex]; // Convert to a signed value between 127 and -128. cb -= 128; }