video_common.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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>(a)) | (static_cast<uint32>(b) << 8) | \
  27. (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24))
  28. #else
  29. #define FOURCC(a, b, c, d) \
  30. (((uint32)(a)) | ((uint32)(b) << 8) | /* NOLINT */ \
  31. ((uint32)(c) << 16) | ((uint32)(d) << 24)) /* NOLINT */
  32. #endif
  33. // Some pages discussing FourCC codes:
  34. // http://www.fourcc.org/yuv.php
  35. // http://v4l2spec.bytesex.org/spec/book1.htm
  36. // http://developer.apple.com/quicktime/icefloe/dispatch020.html
  37. // http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12
  38. // http://people.xiph.org/~xiphmont/containers/nut/nut4cc.txt
  39. // FourCC codes grouped according to implementation efficiency.
  40. // Primary formats should convert in 1 efficient step.
  41. // Secondary formats are converted in 2 steps.
  42. // Auxilliary formats call primary converters.
  43. enum FourCC {
  44. // 8 Primary YUV formats: 5 planar, 2 biplanar, 2 packed.
  45. FOURCC_I420 = FOURCC('I', '4', '2', '0'),
  46. FOURCC_I422 = FOURCC('I', '4', '2', '2'),
  47. FOURCC_I444 = FOURCC('I', '4', '4', '4'),
  48. FOURCC_I411 = FOURCC('I', '4', '1', '1'), // deprecated.
  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. // 1 Secondary YUV format: row biplanar.
  55. FOURCC_M420 = FOURCC('M', '4', '2', '0'),
  56. FOURCC_Q420 = FOURCC('Q', '4', '2', '0'), // deprecated.
  57. // 9 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp.
  58. FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B'),
  59. FOURCC_BGRA = FOURCC('B', 'G', 'R', 'A'),
  60. FOURCC_ABGR = FOURCC('A', 'B', 'G', 'R'),
  61. FOURCC_24BG = FOURCC('2', '4', 'B', 'G'),
  62. FOURCC_RAW = FOURCC('r', 'a', 'w', ' '),
  63. FOURCC_RGBA = FOURCC('R', 'G', 'B', 'A'),
  64. FOURCC_RGBP = FOURCC('R', 'G', 'B', 'P'), // rgb565 LE.
  65. FOURCC_RGBO = FOURCC('R', 'G', 'B', 'O'), // argb1555 LE.
  66. FOURCC_R444 = FOURCC('R', '4', '4', '4'), // argb4444 LE.
  67. // 4 Secondary RGB formats: 4 Bayer Patterns. deprecated.
  68. FOURCC_RGGB = FOURCC('R', 'G', 'G', 'B'),
  69. FOURCC_BGGR = FOURCC('B', 'G', 'G', 'R'),
  70. FOURCC_GRBG = FOURCC('G', 'R', 'B', 'G'),
  71. FOURCC_GBRG = FOURCC('G', 'B', 'R', 'G'),
  72. // 1 Primary Compressed YUV format.
  73. FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'),
  74. // 5 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias.
  75. FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'),
  76. FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'),
  77. FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'),
  78. FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Linux version of I420.
  79. FOURCC_J420 = FOURCC('J', '4', '2', '0'),
  80. FOURCC_J400 = FOURCC('J', '4', '0', '0'), // unofficial fourcc
  81. FOURCC_H420 = FOURCC('H', '4', '2', '0'), // unofficial fourcc
  82. // 14 Auxiliary aliases. CanonicalFourCC() maps these to canonical fourcc.
  83. FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420.
  84. FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'), // Alias for I422.
  85. FOURCC_YU24 = FOURCC('Y', 'U', '2', '4'), // Alias for I444.
  86. FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'), // Alias for YUY2.
  87. FOURCC_YUVS = FOURCC('y', 'u', 'v', 's'), // Alias for YUY2 on Mac.
  88. FOURCC_HDYC = FOURCC('H', 'D', 'Y', 'C'), // Alias for UYVY.
  89. FOURCC_2VUY = FOURCC('2', 'v', 'u', 'y'), // Alias for UYVY on Mac.
  90. FOURCC_JPEG = FOURCC('J', 'P', 'E', 'G'), // Alias for MJPG.
  91. FOURCC_DMB1 = FOURCC('d', 'm', 'b', '1'), // Alias for MJPG on Mac.
  92. FOURCC_BA81 = FOURCC('B', 'A', '8', '1'), // Alias for BGGR.
  93. FOURCC_RGB3 = FOURCC('R', 'G', 'B', '3'), // Alias for RAW.
  94. FOURCC_BGR3 = FOURCC('B', 'G', 'R', '3'), // Alias for 24BG.
  95. FOURCC_CM32 = FOURCC(0, 0, 0, 32), // Alias for BGRA kCMPixelFormat_32ARGB
  96. FOURCC_CM24 = FOURCC(0, 0, 0, 24), // Alias for RAW kCMPixelFormat_24RGB
  97. FOURCC_L555 = FOURCC('L', '5', '5', '5'), // Alias for RGBO.
  98. FOURCC_L565 = FOURCC('L', '5', '6', '5'), // Alias for RGBP.
  99. FOURCC_5551 = FOURCC('5', '5', '5', '1'), // Alias for RGBO.
  100. // 1 Auxiliary compressed YUV format set aside for capturer.
  101. FOURCC_H264 = FOURCC('H', '2', '6', '4'),
  102. // Match any fourcc.
  103. FOURCC_ANY = -1,
  104. };
  105. enum FourCCBpp {
  106. // Canonical fourcc codes used in our code.
  107. FOURCC_BPP_I420 = 12,
  108. FOURCC_BPP_I422 = 16,
  109. FOURCC_BPP_I444 = 24,
  110. FOURCC_BPP_I411 = 12,
  111. FOURCC_BPP_I400 = 8,
  112. FOURCC_BPP_NV21 = 12,
  113. FOURCC_BPP_NV12 = 12,
  114. FOURCC_BPP_YUY2 = 16,
  115. FOURCC_BPP_UYVY = 16,
  116. FOURCC_BPP_M420 = 12,
  117. FOURCC_BPP_Q420 = 12,
  118. FOURCC_BPP_ARGB = 32,
  119. FOURCC_BPP_BGRA = 32,
  120. FOURCC_BPP_ABGR = 32,
  121. FOURCC_BPP_RGBA = 32,
  122. FOURCC_BPP_24BG = 24,
  123. FOURCC_BPP_RAW = 24,
  124. FOURCC_BPP_RGBP = 16,
  125. FOURCC_BPP_RGBO = 16,
  126. FOURCC_BPP_R444 = 16,
  127. FOURCC_BPP_RGGB = 8,
  128. FOURCC_BPP_BGGR = 8,
  129. FOURCC_BPP_GRBG = 8,
  130. FOURCC_BPP_GBRG = 8,
  131. FOURCC_BPP_YV12 = 12,
  132. FOURCC_BPP_YV16 = 16,
  133. FOURCC_BPP_YV24 = 24,
  134. FOURCC_BPP_YU12 = 12,
  135. FOURCC_BPP_J420 = 12,
  136. FOURCC_BPP_J400 = 8,
  137. FOURCC_BPP_H420 = 12,
  138. FOURCC_BPP_MJPG = 0, // 0 means unknown.
  139. FOURCC_BPP_H264 = 0,
  140. FOURCC_BPP_IYUV = 12,
  141. FOURCC_BPP_YU16 = 16,
  142. FOURCC_BPP_YU24 = 24,
  143. FOURCC_BPP_YUYV = 16,
  144. FOURCC_BPP_YUVS = 16,
  145. FOURCC_BPP_HDYC = 16,
  146. FOURCC_BPP_2VUY = 16,
  147. FOURCC_BPP_JPEG = 1,
  148. FOURCC_BPP_DMB1 = 1,
  149. FOURCC_BPP_BA81 = 8,
  150. FOURCC_BPP_RGB3 = 24,
  151. FOURCC_BPP_BGR3 = 24,
  152. FOURCC_BPP_CM32 = 32,
  153. FOURCC_BPP_CM24 = 24,
  154. // Match any fourcc.
  155. FOURCC_BPP_ANY = 0, // 0 means unknown.
  156. };
  157. // Converts fourcc aliases into canonical ones.
  158. LIBYUV_API uint32 CanonicalFourCC(uint32 fourcc);
  159. #ifdef __cplusplus
  160. } // extern "C"
  161. } // namespace libyuv
  162. #endif
  163. #endif // INCLUDE_LIBYUV_VIDEO_COMMON_H_