1*4e366538SXin Li# Introduction 2*4e366538SXin Li 3*4e366538SXin LiFormats (FOURCC) supported by libyuv are detailed here. 4*4e366538SXin Li 5*4e366538SXin Li# Core Formats 6*4e366538SXin Li 7*4e366538SXin LiThere are 2 core formats supported by libyuv - I420 and ARGB. 8*4e366538SXin Li All YUV formats can be converted to/from I420. 9*4e366538SXin Li All RGB formats can be converted to/from ARGB. 10*4e366538SXin Li 11*4e366538SXin LiFiltering functions such as scaling and planar functions work on I420 and/or ARGB. 12*4e366538SXin Li 13*4e366538SXin Li# OSX Core Media Pixel Formats 14*4e366538SXin Li 15*4e366538SXin LiThis is how OSX formats map to libyuv 16*4e366538SXin Li 17*4e366538SXin Li enum { 18*4e366538SXin Li kCMPixelFormat_32ARGB = 32, FOURCC_BGRA 19*4e366538SXin Li kCMPixelFormat_32BGRA = 'BGRA', FOURCC_ARGB 20*4e366538SXin Li kCMPixelFormat_24RGB = 24, FOURCC_RAW 21*4e366538SXin Li kCMPixelFormat_16BE555 = 16, Not supported. 22*4e366538SXin Li kCMPixelFormat_16BE565 = 'B565', Not supported. 23*4e366538SXin Li kCMPixelFormat_16LE555 = 'L555', FOURCC_RGBO 24*4e366538SXin Li kCMPixelFormat_16LE565 = 'L565', FOURCC_RGBP 25*4e366538SXin Li kCMPixelFormat_16LE5551 = '5551', FOURCC_RGBO 26*4e366538SXin Li kCMPixelFormat_422YpCbCr8 = '2vuy', FOURCC_UYVY 27*4e366538SXin Li kCMPixelFormat_422YpCbCr8_yuvs = 'yuvs', FOURCC_YUY2 28*4e366538SXin Li kCMPixelFormat_444YpCbCr8 = 'v308', FOURCC_I444 ? 29*4e366538SXin Li kCMPixelFormat_4444YpCbCrA8 = 'v408', Not supported. 30*4e366538SXin Li kCMPixelFormat_422YpCbCr16 = 'v216', Not supported. 31*4e366538SXin Li kCMPixelFormat_422YpCbCr10 = 'v210', FOURCC_V210 previously. Removed now. 32*4e366538SXin Li kCMPixelFormat_444YpCbCr10 = 'v410', Not supported. 33*4e366538SXin Li kCMPixelFormat_8IndexedGray_WhiteIsZero = 0x00000028, Not supported. 34*4e366538SXin Li }; 35*4e366538SXin Li 36*4e366538SXin Li 37*4e366538SXin Li# FOURCC (Four Charactacter Code) List 38*4e366538SXin Li 39*4e366538SXin LiThe following is extracted from video_common.h as a complete list of formats supported by libyuv. 40*4e366538SXin Li enum FourCC { 41*4e366538SXin Li // 10 Primary YUV formats: 5 planar, 2 biplanar, 2 packed. 42*4e366538SXin Li FOURCC_I420 = FOURCC('I', '4', '2', '0'), 43*4e366538SXin Li FOURCC_I422 = FOURCC('I', '4', '2', '2'), 44*4e366538SXin Li FOURCC_I444 = FOURCC('I', '4', '4', '4'), 45*4e366538SXin Li FOURCC_I400 = FOURCC('I', '4', '0', '0'), 46*4e366538SXin Li FOURCC_NV21 = FOURCC('N', 'V', '2', '1'), 47*4e366538SXin Li FOURCC_NV12 = FOURCC('N', 'V', '1', '2'), 48*4e366538SXin Li FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'), 49*4e366538SXin Li FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'), 50*4e366538SXin Li FOURCC_H010 = FOURCC('H', '0', '1', '0'), // unofficial fourcc. 10 bit lsb 51*4e366538SXin Li FOURCC_U010 = FOURCC('U', '0', '1', '0'), // bt.2020, unofficial fourcc. 52*4e366538SXin Li // 10 bit lsb 53*4e366538SXin Li 54*4e366538SXin Li // 1 Secondary YUV format: row biplanar. 55*4e366538SXin Li FOURCC_M420 = FOURCC('M', '4', '2', '0'), // deprecated. 56*4e366538SXin Li 57*4e366538SXin Li // 13 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp, 1 10 bpc, 2 64 bpp 58*4e366538SXin Li FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B'), 59*4e366538SXin Li FOURCC_BGRA = FOURCC('B', 'G', 'R', 'A'), 60*4e366538SXin Li FOURCC_ABGR = FOURCC('A', 'B', 'G', 'R'), 61*4e366538SXin Li FOURCC_AR30 = FOURCC('A', 'R', '3', '0'), // 10 bit per channel. 2101010. 62*4e366538SXin Li FOURCC_AB30 = FOURCC('A', 'B', '3', '0'), // ABGR version of 10 bit 63*4e366538SXin Li FOURCC_AR64 = FOURCC('A', 'R', '6', '4'), // 16 bit per channel. 64*4e366538SXin Li FOURCC_AB64 = FOURCC('A', 'B', '6', '4'), // ABGR version of 16 bit 65*4e366538SXin Li FOURCC_24BG = FOURCC('2', '4', 'B', 'G'), 66*4e366538SXin Li FOURCC_RAW = FOURCC('r', 'a', 'w', ' '), 67*4e366538SXin Li FOURCC_RGBA = FOURCC('R', 'G', 'B', 'A'), 68*4e366538SXin Li FOURCC_RGBP = FOURCC('R', 'G', 'B', 'P'), // rgb565 LE. 69*4e366538SXin Li FOURCC_RGBO = FOURCC('R', 'G', 'B', 'O'), // argb1555 LE. 70*4e366538SXin Li FOURCC_R444 = FOURCC('R', '4', '4', '4'), // argb4444 LE. 71*4e366538SXin Li 72*4e366538SXin Li // 1 Primary Compressed YUV format. 73*4e366538SXin Li FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'), 74*4e366538SXin Li 75*4e366538SXin Li // 11 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias. 76*4e366538SXin Li FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'), 77*4e366538SXin Li FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'), 78*4e366538SXin Li FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'), 79*4e366538SXin Li FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Linux version of I420. 80*4e366538SXin Li FOURCC_J420 = FOURCC('J', '4', '2', '0'), 81*4e366538SXin Li FOURCC_J400 = FOURCC('J', '4', '0', '0'), // unofficial fourcc 82*4e366538SXin Li FOURCC_H420 = FOURCC('H', '4', '2', '0'), // unofficial fourcc 83*4e366538SXin Li FOURCC_H422 = FOURCC('H', '4', '2', '2'), // unofficial fourcc 84*4e366538SXin Li FOURCC_U420 = FOURCC('U', '4', '2', '0'), // bt.2020, unofficial fourcc 85*4e366538SXin Li FOURCC_U422 = FOURCC('U', '4', '2', '2'), // bt.2020, unofficial fourcc 86*4e366538SXin Li FOURCC_U444 = FOURCC('U', '4', '4', '4'), // bt.2020, unofficial fourcc 87*4e366538SXin Li 88*4e366538SXin Li // 14 Auxiliary aliases. CanonicalFourCC() maps these to canonical fourcc. 89*4e366538SXin Li FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420. 90*4e366538SXin Li FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'), // Alias for I422. 91*4e366538SXin Li FOURCC_YU24 = FOURCC('Y', 'U', '2', '4'), // Alias for I444. 92*4e366538SXin Li FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'), // Alias for YUY2. 93*4e366538SXin Li FOURCC_YUVS = FOURCC('y', 'u', 'v', 's'), // Alias for YUY2 on Mac. 94*4e366538SXin Li FOURCC_HDYC = FOURCC('H', 'D', 'Y', 'C'), // Alias for UYVY. 95*4e366538SXin Li FOURCC_2VUY = FOURCC('2', 'v', 'u', 'y'), // Alias for UYVY on Mac. 96*4e366538SXin Li FOURCC_JPEG = FOURCC('J', 'P', 'E', 'G'), // Alias for MJPG. 97*4e366538SXin Li FOURCC_DMB1 = FOURCC('d', 'm', 'b', '1'), // Alias for MJPG on Mac. 98*4e366538SXin Li FOURCC_BA81 = FOURCC('B', 'A', '8', '1'), // Alias for BGGR. 99*4e366538SXin Li FOURCC_RGB3 = FOURCC('R', 'G', 'B', '3'), // Alias for RAW. 100*4e366538SXin Li FOURCC_BGR3 = FOURCC('B', 'G', 'R', '3'), // Alias for 24BG. 101*4e366538SXin Li FOURCC_CM32 = FOURCC(0, 0, 0, 32), // Alias for BGRA kCMPixelFormat_32ARGB 102*4e366538SXin Li FOURCC_CM24 = FOURCC(0, 0, 0, 24), // Alias for RAW kCMPixelFormat_24RGB 103*4e366538SXin Li FOURCC_L555 = FOURCC('L', '5', '5', '5'), // Alias for RGBO. 104*4e366538SXin Li FOURCC_L565 = FOURCC('L', '5', '6', '5'), // Alias for RGBP. 105*4e366538SXin Li FOURCC_5551 = FOURCC('5', '5', '5', '1'), // Alias for RGBO. 106*4e366538SXin Li 107*4e366538SXin Li# Planar YUV 108*4e366538SXin Li The following formats contains a full size Y plane followed by 1 or 2 109*4e366538SXin Li planes for UV: I420, I422, I444, I400, NV21, NV12, I400 110*4e366538SXin Li The size (subsampling) of the UV varies. 111*4e366538SXin Li I420, NV12 and NV21 are half width, half height 112*4e366538SXin Li I422, NV16 and NV61 are half width, full height 113*4e366538SXin Li I444, NV24 and NV42 are full width, full height 114*4e366538SXin Li I400 and J400 have no chroma channel. 115*4e366538SXin Li 116*4e366538SXin Li# Color space 117*4e366538SXin Li The YUV formats start with a letter to specify the color space. e.g. I420 118*4e366538SXin Li I = BT.601 limited range 119*4e366538SXin Li J = BT.601 full range (J = JPEG that uses this) 120*4e366538SXin Li H = BT.709 limited range (H for HD) 121*4e366538SXin Li F = BT.709 full range (F for Full range) 122*4e366538SXin Li U = BT.2020 limited range (U for UHD) 123*4e366538SXin Li V = BT.2020 full range 124*4e366538SXin Li For YUV to RGB conversions, a matrix can be passed. See also convert_argh.h 125*4e366538SXin Li 126*4e366538SXin Li# HDR formats 127*4e366538SXin Li Planar formats with 10 or 12 bits use the following fourcc: 128*4e366538SXin Li I010, I012, P010, P012 are half width, half height 129*4e366538SXin Li I210, I212, P210, P212 are half width, full height 130*4e366538SXin Li I410, I412, P410, P412 are full width, full height 131*4e366538SXin Li where 132*4e366538SXin Li I is the color space (see above) and 3 planes: Y, U and V. 133*4e366538SXin Li P is a biplanar format, similar to NV12 but 16 bits, with the valid bits in the high bits. There is a Y plane and a UV plane. 134*4e366538SXin Li 0, 2 or 4 is the last digit of subsampling: 4:2:0, 4:2:2, or 4:4:4 135*4e366538SXin Li 10 or 12 is the bits per channel. The bits are in the low bits of a 16 bit channel. 136*4e366538SXin Li 137*4e366538SXin Li# The ARGB FOURCC 138*4e366538SXin Li 139*4e366538SXin LiThere are 4 ARGB layouts - ARGB, BGRA, ABGR and RGBA. ARGB is most common by far, used for screen formats, and windows webcam drivers. 140*4e366538SXin Li 141*4e366538SXin LiThe fourcc describes the order of channels in a ***register***. 142*4e366538SXin Li 143*4e366538SXin LiA fourcc provided by capturer, can be thought of string, e.g. "ARGB". 144*4e366538SXin Li 145*4e366538SXin LiOn little endian machines, as an int, this would have 'A' in the lowest byte. The FOURCC macro reverses the order: 146*4e366538SXin Li 147*4e366538SXin Li #define FOURCC(a, b, c, d) (((uint32)(a)) | ((uint32)(b) << 8) | ((uint32)(c) << 16) | ((uint32)(d) << 24)) 148*4e366538SXin Li 149*4e366538SXin LiSo the "ARGB" string, read as an uint32, is 150*4e366538SXin Li 151*4e366538SXin Li FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B') 152*4e366538SXin Li 153*4e366538SXin LiIf you were to read ARGB pixels as uint32's, the alpha would be in the high byte, and the blue in the lowest byte. In memory, these are stored little endian, so 'B' is first, then 'G', 'R' and 'A' last. 154*4e366538SXin Li 155*4e366538SXin LiWhen calling conversion functions, the names match the FOURCC, so in this case it would be I420ToARGB(). 156*4e366538SXin Li 157*4e366538SXin LiAll formats can be converted to/from ARGB. 158*4e366538SXin Li 159*4e366538SXin LiMost 'planar_functions' work on ARGB (e.g. ARGBBlend). 160*4e366538SXin Li 161*4e366538SXin LiSome are channel order agnostic (e.g. ARGBScale). 162*4e366538SXin Li 163*4e366538SXin LiSome functions are symmetric (e.g. ARGBToBGRA is the same as BGRAToARGB, so its a macro). 164*4e366538SXin Li 165*4e366538SXin LiARGBBlend expects preattenuated ARGB. The R,G,B are premultiplied by alpha. Other functions don't care. 166*4e366538SXin Li 167*4e366538SXin Li# RGB24 and RAW 168*4e366538SXin Li 169*4e366538SXin LiThere are 2 RGB layouts - RGB24 (aka 24BG) and RAW 170*4e366538SXin Li 171*4e366538SXin LiRGB24 is B,G,R in memory 172*4e366538SXin LiRAW is R,G,B in memory 173*4e366538SXin Li 174*4e366538SXin Li# AR30 and XR30 175*4e366538SXin Li 176*4e366538SXin LiAR30 is 2 10 10 10 ARGB stored in little endian order. 177*4e366538SXin LiThe 2 bit alpha has 4 values. Here are the comparable 8 bit alpha values. 178*4e366538SXin Li0 - 0. 00000000b = 0x00 = 0 179*4e366538SXin Li1 - 33%. 01010101b = 0x55 = 85 180*4e366538SXin Li2 - 66%. 10101010b = 0xaa = 170 181*4e366538SXin Li3 - 100%. 11111111b = 0xff = 255 182*4e366538SXin LiThe 10 bit RGB values range from 0 to 1023. 183*4e366538SXin LiXR30 is the same as AR30 but with no alpha channel. 184*4e366538SXin Li 185*4e366538SXin Li# AB64 and AR64 186*4e366538SXin Li 187*4e366538SXin LiAB64 is similar to ABGR, with 16 bit (2 bytes) per channel. Each channel stores an unsigned short. 188*4e366538SXin LiIn memory R is the lowest and A is the highest. 189*4e366538SXin LiEach channel has value ranges from 0 to 65535. 190*4e366538SXin LiAR64 is similar to ARGB. 191*4e366538SXin Li 192*4e366538SXin Li# NV12 and NV21 193*4e366538SXin Li 194*4e366538SXin LiNV12 is a biplanar format with a full sized Y plane followed by a single 195*4e366538SXin Lichroma plane with weaved U and V values. 196*4e366538SXin LiNV21 is the same but with weaved V and U values. 197*4e366538SXin LiThe 12 in NV12 refers to 12 bits per pixel. NV12 has a half width and half 198*4e366538SXin Liheight chroma channel, and therefore is a 420 subsampling. 199*4e366538SXin LiNV16 is 16 bits per pixel, with half width and full height. aka 422. 200*4e366538SXin LiNV24 is 24 bits per pixel with full sized chroma channel. aka 444. 201*4e366538SXin LiMost NV12 functions allow the destination Y pointer to be NULL. 202*4e366538SXin Li 203*4e366538SXin Li# YUY2 and UYVY 204*4e366538SXin Li 205*4e366538SXin LiYUY2 is a packed YUV format with half width, full height. 206*4e366538SXin Li 207*4e366538SXin LiYUY2 is YUYV in memory 208*4e366538SXin LiUYVY is UYVY in memory 209