Table of Contents

Enum YuvPackedFormat

Namespace
Egami.Pixels
Assembly
Egami.dll

The interleaved YUV layouts that operating system decoders, GPUs and webcams hand out, which a YuvRaster copies to and from its planes with CopyFromPacked(YuvPackedFormat, ReadOnlySpan<byte>, int, ReadOnlySpan<byte>, int) and CopyToPacked(YuvPackedFormat, Span<byte>, int, Span<byte>, int).

public enum YuvPackedFormat

Fields

Nv12 = 0

8-bit 4:2:0 in two planes: Y, then U and V interleaved (U first) at half width and height.

Nv21 = 1

8-bit 4:2:0 in two planes: Y, then V and U interleaved (V first) at half width and height.

P010 = 2

10-bit 4:2:0 in two planes of little-endian 16-bit words, samples in the high 10 bits: Y, then U and V interleaved.

P016 = 3

4:2:0 in two planes of little-endian 16-bit words, samples in the high bits (16, or 10 or 12 with zero low bits): Y, then U and V interleaved.

Uyvy = 5

8-bit 4:2:2 in one plane, four bytes for two pixels: U, Y0, V, Y1.

Yuyv = 4

8-bit 4:2:2 in one plane, four bytes for two pixels: Y0, U, Y1, V (also called YUY2).

Examples

// An NV12 frame from Media Foundation or MediaCodec: Y rows, then interleaved U, V rows, both at the same stride.
int width = 640, height = 360, stride = 704;
byte[] nv12 = new byte[stride * height * 3 / 2];
using YuvRaster<byte> frame = YuvRaster.Create(width, height, ChromaFormat.Yuv420, YuvColor.Bt709Limited);
frame.CopyFromPacked(YuvPackedFormat.Nv12, nv12, stride);

// A webcam's YUYV, 4:2:2 in one plane, the other way.
using YuvRaster<byte> webcam = YuvRaster.Create(width, height, ChromaFormat.Yuv422, YuvColor.Bt601Limited);
byte[] yuyv = new byte[width * 2 * height];
webcam.CopyToPacked(YuvPackedFormat.Yuyv, yuyv);