NV21 is an eight-bit YCbCr semiplanar pixel format using 4:2:0 chroma subsampling. It has a full-resolution luma plane followed by interleaved colour-difference samples in Cr, Cb order. NV12 uses the reverse pair order, Cb, Cr. The separately allocated Linux variant is NV21M.[ref]
Planar YUV formats in the Linux Kernel documentation. Semi-Planar overview table; NV12/NV21/NV12M/NV21M subsection
An original tightly stored image has eight luma bytes followed by four colour-difference bytes. Suppose the latter are
200 40 150 90. Under NV21, the two pairs are and . Reading the same bytes as NV12 instead assigns and . The buffer length remains correct while its colour-difference channels are exchanged.Converting this declared NV21 buffer to NV12 requires swapping adjacent bytes in the interleaved plane, giving
40 200 90 150, while retaining the luma data. This is a layout conversion, not a conversion to the RGB color model. The numerical colour interpretation still depends on the declared YCbCr encoding.The active footprint is bytes for even width and height under eight-bit 4:2:0 sampling. Framebuffer stride can add padding, so the next row need not start immediately after the last active sample. A converter must apply the actual row and plane boundaries: swapping pairs across padding or across the luma plane would corrupt the image rather than exchange the intended channels.
NV21M is a two-memory-plane semiplanar pixel format for eight-bit YCbCr with 4:2:0 chroma subsampling. Like NV21, its colour-difference plane stores Cr before Cb in each pair. Unlike ordinary contiguous NV21, the two image memory planes can have independent allocations.[ref]
Planar YUV formats in the Linux Kernel documentation. Semi-Planar table and NV12/NV21/NV12M/NV21M subsection
For an original example, stipulate an accepted width-four, height-four layout whose luma plane begins at 1000 with an eight-byte framebuffer stride, while its Cr/Cb plane begins at 5000 with a four-byte stride. Luma position is at . The corresponding subsampled cell has Cr at and Cb at 5007. This ordering is the reverse of NV12M.
The active sample count is bytes. The declared allocation sizes are bytes because luma rows have padding. Neither 40 nor 24 is an offset that can replace the explicitly supplied second-plane base.
A layout conversion to NV12M can exchange the two bytes in each active colour-difference pair while respecting each plane's stride. It does not require changing luma values or reducing the colour sample count. By contrast, choosing a different YCbCr matrix would be a colour conversion.
The distinction between a multi-planar format and the V4L2 multi-planar API matters here: the interface can carry formats with different memory organizations, while the format identifies which organization the supplied descriptors represent.[ref]
Single- and multi-planar APIs in the Linux Kernel documentation. §1.26.1, API versus format
Articles by others on the same topic
There are currently no matching articles.