YUV420P & YV12

YUV

YUV is a color space typically used as part of a color image pipeline. It encodes a color image or video taking human perception into account, allowing reduced bandwidth for chrominance components, thereby typically enabling transmission errors or compression artifacts to be more efficiently masked by the human perception than using a "direct" RGB-representation.

  • YUV是一种色彩空间模型.
  • YUV比RGB更节省带宽.

The Y′UV model defines a color space in terms of one luma (Y′) and two chrominance (UV) components.
The Y′UV color model is used in the PAL and SECAM composite color video standards.
Previous black-and-white systems used only luma (Y′) information.
Color information (U and V) was added separately via a sub-carrier so that a black-and-white receiver would still be able to receive and display a color picture transmission in the receiver's native black-and-white format.

  • YUV也是为了兼容黑白电视等, 黑白电视只显示Y分量(亮度)即可.

YUV420P & YV12

  • YUV420P

Y′UV420p is a planar format, meaning that the Y′, U, and V values are grouped together instead of interspersed(分散).
The reason for this is that by grouping the U and V values together, the image becomes much more compressible. When given an array of an image in the Y′UV420p format, all the Y′ values come first, followed by all the U values, followed finally by all the V values.

存放顺序: Y->U->V.

  • YV12

The Y′V12 format is essentially the same as Y′UV420p, but it has the U and V data switched: the Y′ values are followed by the V values, with the U values last. As long as care is taken to extract U and V values from the proper locations, both Y′UV420p and Y′V12 can be processed using the same algorithm.

All of the Y samples appear first in memory as an array of unsigned char values. This array is followed immediately by all of the V (Cr) samples. The stride of the V plane is half the stride of the Y plane, and the V plane contains half as many lines as the Y plane. The V plane is followed immediately by all of the U (Cb) samples, with the same stride and number of lines as the V plane (Figure 12).
Figure 12:


YUV420P & YV12_第1张图片
YV12

存放顺序: Y->V->U.
YUV420P & YV12可用相同的算法进行处理.

As with most Y′UV formats, there are as many Y′ values as there are pixels. Where X equals the height multiplied by the width, the first X indices in the array are Y′ values that correspond to each individual pixel. However, there are only one fourth as many U and V values. The U and V values correspond to each 2 by 2 block of the image, meaning each U and V entry applies to four pixels. After the Y′ values, the next X/4 indices are the U values for each 2 by 2 block, and the next X/4 indices after that are the V values that also apply to each 2 by 2 block.

YUV420P & YV12_第2张图片
Yuv420.svg

As shown in the above image, the Y′, U and V components in Y′UV420 are encoded separately in sequential blocks. A Y′ value is stored for every pixel, followed by a U value for each 2×2 square block of pixels, and finally a V value for each 2×2 block. Corresponding Y′, U and V values are shown using the same color in the diagram above. Read line-by-line as a byte stream from a device, the Y′ block would be found at position 0, the U block at position x×y (6×4 = 24 in this example) and the V block at position x×y + (x×y)/4 (here, 6×4 + (6×4)/4 = 30).

每个像素点会存储一个Y值.
图中的Y1 Y2 Y7 Y8 + U1 + V1是一组.
可以看出采样点比例其实是4:1:1. (其实叫420是历史原因)

References:
https://en.wikipedia.org/wiki/YUV#cite_note-13
https://en.wikipedia.org/wiki/YUV
https://msdn.microsoft.com/en-us/library/aa904813

你可能感兴趣的:(YUV420P & YV12)