Search code examples
c#yuvcolor-space

YUV color spacing


I want to know some information about YV12 image format.

1st question is YV12 Image format is equal to YUV420p format or YVU420p or YUV420Sp or YVU420Sp. I know that U and V have the same amount of memory in the format so in the case of planer image formats does swapping U and V makes some major difference. and if it does can some body explain me what is that.

Also i have heard that YV12 and NV12 are both 12 bits formats. Then can some body tell me that what is 4:2:0? it will be great if some can explain me in simple words thanks


Solution

  • According to this site, YV12 looks the same as NV12 except that NV12 is interleaved and YV12 is not. I think that YV12 correspond to YVU420p and NV12 is YVU420sp, but I'm not 100% sure about that.

    What this means however, is that instead of having triplets [yuv][yuv][yuv][...] repeated all over your buffer to draw the image, one triplet per pixel, you have a large buffer of [y], then a buffer 1/4 of the [y] size containing all the [u], then another one 1/4 of [y] containing the [v]. For an image of 320x240 (76800 pixels), you will have 76800 Ys at the start of your buffer, then 19200 Us, then 19200 Vs.

    In the NV12 case, you have a large buffer of [y], then a buffer 1/2 of the [y] size containing [uv] pairs. When drawing the image, or converting to another format such as RGB, you need a least 2 pointers, one that will read Ys and another one that will read the Us and Vs

    When reading such as compressed format, the trick is that you have one Y per pixel, but the UV components change only on odd rows and odd columns and your eye will not see the difference. You reuse the same UV values for 4 pixels at a time while changing the Y for every pixel.