video_common.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright 2011 The LibYuv Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. // Common definitions for video, including fourcc and VideoFormat.
  11. #ifndef INCLUDE_LIBYUV_VIDEO_COMMON_H_
  12. #define INCLUDE_LIBYUV_VIDEO_COMMON_H_
  13. #include "libyuv/basic_types.h"
  14. #ifdef __cplusplus
  15. namespace libyuv {
  16. extern "C" {
  17. #endif
  18. //////////////////////////////////////////////////////////////////////////////
  19. // Definition of FourCC codes
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Convert four characters to a FourCC code.
  22. // Needs to be a macro otherwise the OS X compiler complains when the kFormat*
  23. // constants are used in a switch.
  24. #ifdef __cplusplus
  25. #define FOURCC(a, b, c, d) \
  26. ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \
  27. (static_cast<uint32_t>(c) << 16) | /* NOLINT */ \
  28. (static_cast<uint32_t>(d) << 24)) /* NOLINT */
  29. #else
  30. #define FOURCC(a, b, c, d) \
  31. (((uint32_t)(a)) | ((uint32_t)(b) << 8) | /* NOLINT */ \
  32. ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) /* NOLINT */
  33. #endif
  34. // Some pages discussing FourCC codes:
  35. // http://www.fourcc.org/yuv.php
  36. // http://v4l2spec.bytesex.org/spec/book1.htm
  37. // http://developer.apple.com/quicktime/icefloe/dispatch020.html
  38. // http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12
  39. // http://people.xiph.org/~xiphmont/containers/nut/nut4cc.txt
  40. // FourCC codes grouped according to implementation efficiency.
  41. // Primary formats should convert in 1 efficient step.
  42. // Secondary formats are converted in 2 steps.
  43. // Auxilliary formats call primary converters.
  44. enum FourCC {
  45. // 10 Primary YUV formats: 5 planar, 2 biplanar, 2 packed.
  46. FOURCC_I420 = FOURCC('I', '4', '2', '0'),
  47. FOURCC_I422 = FOURCC('I', '4', '2', '2'),
  48. FOURCC_I444 = FOURCC('I', '4', '4', '4'),
  49. FOURCC_I400 = FOURCC('I', '4', '0', '0'),
  50. FOURCC_NV21 = FOURCC('N', 'V', '2', '1'),
  51. FOURCC_NV12 = FOURCC('N', 'V', '1', '2'),
  52. FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'),
  53. FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'),
  54. FOURCC_I010 = FOURCC('I', '0', '1', '0'), // bt.601 10 bit 420
  55. FOURCC_I210 = FOURCC('I', '0', '1', '0'), // bt.601 10 bit 422
  56. // 1 Secondary YUV format: row biplanar.
  57. FOURCC_M420 = FOURCC('M', '4', '2', '0'),
  58. // 11 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp, 1 10 bpc
  59. FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B'),
  60. FOURCC_BGRA = FOURCC('B', 'G', 'R', 'A'),
  61. FOURCC_ABGR = FOURCC('A', 'B', 'G', 'R'),
  62. FOURCC_AR30 = FOURCC('A', 'R', '3', '0'), // 10 bit per channel. 2101010.
  63. FOURCC_AB30 = FOURCC('A', 'B', '3', '0'), // ABGR version of 10 bit
  64. FOURCC_24BG = FOURCC('2', '4', 'B', 'G'),
  65. FOURCC_RAW = FOURCC('r', 'a', 'w', ' '),
  66. FOURCC_RGBA = FOURCC('R', 'G', 'B', 'A'),
  67. FOURCC_RGBP = FOURCC('R', 'G', 'B', 'P'), // rgb565 LE.
  68. FOURCC_RGBO = FOURCC('R', 'G', 'B', 'O'), // argb1555 LE.
  69. FOURCC_R444 = FOURCC('R', '4', '4', '4'), // argb4444 LE.
  70. // 1 Primary Compressed YUV format.
  71. FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'),
  72. // 14 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias.
  73. FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'),
  74. FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'),
  75. FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'),
  76. FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Linux version of I420.
  77. FOURCC_J420 = FOURCC('J', '4', '2', '0'), // jpeg (bt.601 full), unofficial fourcc
  78. FOURCC_J422 = FOURCC('J', '4', '2', '2'), // jpeg (bt.601 full), unofficial fourcc
  79. FOURCC_J444 = FOURCC('J', '4', '4', '4'), // jpeg (bt.601 full), unofficial fourcc
  80. FOURCC_J400 = FOURCC('J', '4', '0', '0'), // jpeg (bt.601 full), unofficial fourcc
  81. FOURCC_H420 = FOURCC('H', '4', '2', '0'), // bt.709, unofficial fourcc
  82. FOURCC_H422 = FOURCC('H', '4', '2', '2'), // bt.709, unofficial fourcc
  83. FOURCC_H444 = FOURCC('H', '4', '4', '4'), // bt.709, unofficial fourcc
  84. FOURCC_U420 = FOURCC('U', '4', '2', '0'), // bt.2020, unofficial fourcc
  85. FOURCC_U422 = FOURCC('U', '4', '2', '2'), // bt.2020, unofficial fourcc
  86. FOURCC_U444 = FOURCC('U', '4', '4', '4'), // bt.2020, unofficial fourcc
  87. FOURCC_H010 = FOURCC('H', '0', '1', '0'), // bt.709 10 bit 420
  88. FOURCC_U010 = FOURCC('U', '0', '1', '0'), // bt.2020 10 bit 420
  89. FOURCC_H210 = FOURCC('H', '0', '1', '0'), // bt.709 10 bit 422
  90. FOURCC_U210 = FOURCC('U', '0', '1', '0'), // bt.2020 10 bit 422
  91. // 14 Auxiliary aliases. CanonicalFourCC() maps these to canonical fourcc.
  92. FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420.
  93. FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'), // Alias for I422.
  94. FOURCC_YU24 = FOURCC('Y', 'U', '2', '4'), // Alias for I444.
  95. FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'), // Alias for YUY2.
  96. FOURCC_YUVS = FOURCC('y', 'u', 'v', 's'), // Alias for YUY2 on Mac.
  97. FOURCC_HDYC = FOURCC('H', 'D', 'Y', 'C'), // Alias for UYVY.
  98. FOURCC_2VUY = FOURCC('2', 'v', 'u', 'y'), // Alias for UYVY on Mac.
  99. FOURCC_JPEG = FOURCC('J', 'P', 'E', 'G'), // Alias for MJPG.
  100. FOURCC_DMB1 = FOURCC('d', 'm', 'b', '1'), // Alias for MJPG on Mac.
  101. FOURCC_BA81 = FOURCC('B', 'A', '8', '1'), // Alias for BGGR.
  102. FOURCC_RGB3 = FOURCC('R', 'G', 'B', '3'), // Alias for RAW.
  103. FOURCC_BGR3 = FOURCC('B', 'G', 'R', '3'), // Alias for 24BG.
  104. FOURCC_CM32 = FOURCC(0, 0, 0, 32), // Alias for BGRA kCMPixelFormat_32ARGB
  105. FOURCC_CM24 = FOURCC(0, 0, 0, 24), // Alias for RAW kCMPixelFormat_24RGB
  106. FOURCC_L555 = FOURCC('L', '5', '5', '5'), // Alias for RGBO.
  107. FOURCC_L565 = FOURCC('L', '5', '6', '5'), // Alias for RGBP.
  108. FOURCC_5551 = FOURCC('5', '5', '5', '1'), // Alias for RGBO.
  109. // deprecated formats. Not supported, but defined for backward compatibility.
  110. FOURCC_I411 = FOURCC('I', '4', '1', '1'),
  111. FOURCC_Q420 = FOURCC('Q', '4', '2', '0'),
  112. FOURCC_RGGB = FOURCC('R', 'G', 'G', 'B'),
  113. FOURCC_BGGR = FOURCC('B', 'G', 'G', 'R'),
  114. FOURCC_GRBG = FOURCC('G', 'R', 'B', 'G'),
  115. FOURCC_GBRG = FOURCC('G', 'B', 'R', 'G'),
  116. FOURCC_H264 = FOURCC('H', '2', '6', '4'),
  117. // Match any fourcc.
  118. FOURCC_ANY = -1,
  119. };
  120. enum FourCCBpp {
  121. // Canonical fourcc codes used in our code.
  122. FOURCC_BPP_I420 = 12,
  123. FOURCC_BPP_I422 = 16,
  124. FOURCC_BPP_I444 = 24,
  125. FOURCC_BPP_I411 = 12,
  126. FOURCC_BPP_I400 = 8,
  127. FOURCC_BPP_NV21 = 12,
  128. FOURCC_BPP_NV12 = 12,
  129. FOURCC_BPP_YUY2 = 16,
  130. FOURCC_BPP_UYVY = 16,
  131. FOURCC_BPP_M420 = 12,
  132. FOURCC_BPP_Q420 = 12,
  133. FOURCC_BPP_ARGB = 32,
  134. FOURCC_BPP_BGRA = 32,
  135. FOURCC_BPP_ABGR = 32,
  136. FOURCC_BPP_RGBA = 32,
  137. FOURCC_BPP_AR30 = 32,
  138. FOURCC_BPP_AB30 = 32,
  139. FOURCC_BPP_24BG = 24,
  140. FOURCC_BPP_RAW = 24,
  141. FOURCC_BPP_RGBP = 16,
  142. FOURCC_BPP_RGBO = 16,
  143. FOURCC_BPP_R444 = 16,
  144. FOURCC_BPP_RGGB = 8,
  145. FOURCC_BPP_BGGR = 8,
  146. FOURCC_BPP_GRBG = 8,
  147. FOURCC_BPP_GBRG = 8,
  148. FOURCC_BPP_YV12 = 12,
  149. FOURCC_BPP_YV16 = 16,
  150. FOURCC_BPP_YV24 = 24,
  151. FOURCC_BPP_YU12 = 12,
  152. FOURCC_BPP_J420 = 12,
  153. FOURCC_BPP_J400 = 8,
  154. FOURCC_BPP_H420 = 12,
  155. FOURCC_BPP_H422 = 16,
  156. FOURCC_BPP_H010 = 24,
  157. FOURCC_BPP_MJPG = 0, // 0 means unknown.
  158. FOURCC_BPP_H264 = 0,
  159. FOURCC_BPP_IYUV = 12,
  160. FOURCC_BPP_YU16 = 16,
  161. FOURCC_BPP_YU24 = 24,
  162. FOURCC_BPP_YUYV = 16,
  163. FOURCC_BPP_YUVS = 16,
  164. FOURCC_BPP_HDYC = 16,
  165. FOURCC_BPP_2VUY = 16,
  166. FOURCC_BPP_JPEG = 1,
  167. FOURCC_BPP_DMB1 = 1,
  168. FOURCC_BPP_BA81 = 8,
  169. FOURCC_BPP_RGB3 = 24,
  170. FOURCC_BPP_BGR3 = 24,
  171. FOURCC_BPP_CM32 = 32,
  172. FOURCC_BPP_CM24 = 24,
  173. // Match any fourcc.
  174. FOURCC_BPP_ANY = 0, // 0 means unknown.
  175. };
  176. // Converts fourcc aliases into canonical ones.
  177. LIBYUV_API uint32_t CanonicalFourCC(uint32_t fourcc);
  178. #ifdef __cplusplus
  179. } // extern "C"
  180. } // namespace libyuv
  181. #endif
  182. #endif // INCLUDE_LIBYUV_VIDEO_COMMON_H_