NV12 (source code)

= NV12
{c}

\b[NV12] is an eight-bit <YCbCr> <semiplanar pixel format> with 4:2:0 <chroma subsampling>. A full-resolution plane holds <luma (video)> samples. The following plane stores alternating Cb and Cr samples, with half as many sample positions in each spatial direction. Linux specifies ordinary untiled NV12 with adjacent planes; the separately allocated variant is <NV12M>.<Planar YUV formats in the Linux Kernel documentation>[Semi-Planar overview table; NV12/NV21/NV12M/NV21M subsection]{ref}

For even dimensions $W,H$, active samples occupy $WH$ luma <bytes> plus $WH/2$ interleaved colour-difference bytes. This is $3WH/2$ bytes, or an average of 12 <bits> per original <pixel>. It does not give every pixel its own three-component triple: neighbouring pixels share the lower-resolution colour-difference samples.

For an original address calculation, choose width six, height four and an eight-byte <framebuffer stride> in both planes. Put the first luma row at address 1000. The luma allocation occupies $4(8)=32$ bytes, so the colour-difference plane starts at 1032 and occupies another $2(8)=16$ bytes. There are 36 active bytes in 48 allocated bytes, including row padding.

With zero-based indices, luma position $(r,c)=(3,5)$ is at $1000+3(8)+5=1029$. Its associated subsampled grid cell has indices $(\lfloor r/2\rfloor,\lfloor c/2\rfloor)=(1,2)$ in this declared layout. That cell's Cb and Cr bytes are at 1044 and 1045. Colour reconstruction additionally needs a sampling-location and filtering convention; these address calculations alone do not specify it.

The <pixel format> identifies storage. A decoder must also know the <YCbCr> matrix and code ranges to interpret the numbers as colour.