Home | History | Annotate | Download | only in libyuv
      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 
     11 // Common definitions for video, including fourcc and VideoFormat.
     12 
     13 #ifndef INCLUDE_LIBYUV_VIDEO_COMMON_H_
     14 #define INCLUDE_LIBYUV_VIDEO_COMMON_H_
     15 
     16 #include "libyuv/basic_types.h"
     17 
     18 #ifdef __cplusplus
     19 namespace libyuv {
     20 extern "C" {
     21 #endif
     22 
     23 //////////////////////////////////////////////////////////////////////////////
     24 // Definition of FourCC codes
     25 //////////////////////////////////////////////////////////////////////////////
     26 
     27 // Convert four characters to a FourCC code.
     28 // Needs to be a macro otherwise the OS X compiler complains when the kFormat*
     29 // constants are used in a switch.
     30 #ifdef __cplusplus
     31 #define FOURCC(a, b, c, d)                                    \
     32   ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \
     33    (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24))
     34 #else
     35 #define FOURCC(a, b, c, d)                                 \
     36   (((uint32)(a)) | ((uint32)(b) << 8) |       /* NOLINT */ \
     37    ((uint32)(c) << 16) | ((uint32)(d) << 24)) /* NOLINT */
     38 #endif
     39 
     40 // Some pages discussing FourCC codes:
     41 //   http://www.fourcc.org/yuv.php
     42 //   http://v4l2spec.bytesex.org/spec/book1.htm
     43 //   http://developer.apple.com/quicktime/icefloe/dispatch020.html
     44 //   http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12
     45 //   http://people.xiph.org/~xiphmont/containers/nut/nut4cc.txt
     46 
     47 // FourCC codes grouped according to implementation efficiency.
     48 // Primary formats should convert in 1 efficient step.
     49 // Secondary formats are converted in 2 steps.
     50 // Auxilliary formats call primary converters.
     51 enum FourCC {
     52   // 8 Primary YUV formats: 5 planar, 2 biplanar, 2 packed.
     53   FOURCC_I420 = FOURCC('I', '4', '2', '0'),
     54   FOURCC_I422 = FOURCC('I', '4', '2', '2'),
     55   FOURCC_I444 = FOURCC('I', '4', '4', '4'),
     56   FOURCC_I411 = FOURCC('I', '4', '1', '1'),  // deprecated.
     57   FOURCC_I400 = FOURCC('I', '4', '0', '0'),
     58   FOURCC_NV21 = FOURCC('N', 'V', '2', '1'),
     59   FOURCC_NV12 = FOURCC('N', 'V', '1', '2'),
     60   FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'),
     61   FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'),
     62 
     63   // 1 Secondary YUV format: row biplanar.
     64   FOURCC_M420 = FOURCC('M', '4', '2', '0'),
     65   FOURCC_Q420 = FOURCC('Q', '4', '2', '0'),  // deprecated.
     66 
     67   // 9 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp.
     68   FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B'),
     69   FOURCC_BGRA = FOURCC('B', 'G', 'R', 'A'),
     70   FOURCC_ABGR = FOURCC('A', 'B', 'G', 'R'),
     71   FOURCC_24BG = FOURCC('2', '4', 'B', 'G'),
     72   FOURCC_RAW = FOURCC('r', 'a', 'w', ' '),
     73   FOURCC_RGBA = FOURCC('R', 'G', 'B', 'A'),
     74   FOURCC_RGBP = FOURCC('R', 'G', 'B', 'P'),  // rgb565 LE.
     75   FOURCC_RGBO = FOURCC('R', 'G', 'B', 'O'),  // argb1555 LE.
     76   FOURCC_R444 = FOURCC('R', '4', '4', '4'),  // argb4444 LE.
     77 
     78   // 4 Secondary RGB formats: 4 Bayer Patterns. deprecated.
     79   FOURCC_RGGB = FOURCC('R', 'G', 'G', 'B'),
     80   FOURCC_BGGR = FOURCC('B', 'G', 'G', 'R'),
     81   FOURCC_GRBG = FOURCC('G', 'R', 'B', 'G'),
     82   FOURCC_GBRG = FOURCC('G', 'B', 'R', 'G'),
     83 
     84   // 1 Primary Compressed YUV format.
     85   FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'),
     86 
     87   // 5 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias.
     88   FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'),
     89   FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'),
     90   FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'),
     91   FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'),  // Linux version of I420.
     92   FOURCC_J420 = FOURCC('J', '4', '2', '0'),
     93   FOURCC_J400 = FOURCC('J', '4', '0', '0'),  // unofficial fourcc
     94   FOURCC_H420 = FOURCC('H', '4', '2', '0'),  // unofficial fourcc
     95 
     96   // 14 Auxiliary aliases.  CanonicalFourCC() maps these to canonical fourcc.
     97   FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'),  // Alias for I420.
     98   FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'),  // Alias for I422.
     99   FOURCC_YU24 = FOURCC('Y', 'U', '2', '4'),  // Alias for I444.
    100   FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'),  // Alias for YUY2.
    101   FOURCC_YUVS = FOURCC('y', 'u', 'v', 's'),  // Alias for YUY2 on Mac.
    102   FOURCC_HDYC = FOURCC('H', 'D', 'Y', 'C'),  // Alias for UYVY.
    103   FOURCC_2VUY = FOURCC('2', 'v', 'u', 'y'),  // Alias for UYVY on Mac.
    104   FOURCC_JPEG = FOURCC('J', 'P', 'E', 'G'),  // Alias for MJPG.
    105   FOURCC_DMB1 = FOURCC('d', 'm', 'b', '1'),  // Alias for MJPG on Mac.
    106   FOURCC_BA81 = FOURCC('B', 'A', '8', '1'),  // Alias for BGGR.
    107   FOURCC_RGB3 = FOURCC('R', 'G', 'B', '3'),  // Alias for RAW.
    108   FOURCC_BGR3 = FOURCC('B', 'G', 'R', '3'),  // Alias for 24BG.
    109   FOURCC_CM32 = FOURCC(0, 0, 0, 32),  // Alias for BGRA kCMPixelFormat_32ARGB
    110   FOURCC_CM24 = FOURCC(0, 0, 0, 24),  // Alias for RAW kCMPixelFormat_24RGB
    111   FOURCC_L555 = FOURCC('L', '5', '5', '5'),  // Alias for RGBO.
    112   FOURCC_L565 = FOURCC('L', '5', '6', '5'),  // Alias for RGBP.
    113   FOURCC_5551 = FOURCC('5', '5', '5', '1'),  // Alias for RGBO.
    114 
    115   // 1 Auxiliary compressed YUV format set aside for capturer.
    116   FOURCC_H264 = FOURCC('H', '2', '6', '4'),
    117 
    118   // Match any fourcc.
    119   FOURCC_ANY = -1,
    120 };
    121 
    122 enum FourCCBpp {
    123   // Canonical fourcc codes used in our code.
    124   FOURCC_BPP_I420 = 12,
    125   FOURCC_BPP_I422 = 16,
    126   FOURCC_BPP_I444 = 24,
    127   FOURCC_BPP_I411 = 12,
    128   FOURCC_BPP_I400 = 8,
    129   FOURCC_BPP_NV21 = 12,
    130   FOURCC_BPP_NV12 = 12,
    131   FOURCC_BPP_YUY2 = 16,
    132   FOURCC_BPP_UYVY = 16,
    133   FOURCC_BPP_M420 = 12,
    134   FOURCC_BPP_Q420 = 12,
    135   FOURCC_BPP_ARGB = 32,
    136   FOURCC_BPP_BGRA = 32,
    137   FOURCC_BPP_ABGR = 32,
    138   FOURCC_BPP_RGBA = 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_MJPG = 0,  // 0 means unknown.
    156   FOURCC_BPP_H264 = 0,
    157   FOURCC_BPP_IYUV = 12,
    158   FOURCC_BPP_YU16 = 16,
    159   FOURCC_BPP_YU24 = 24,
    160   FOURCC_BPP_YUYV = 16,
    161   FOURCC_BPP_YUVS = 16,
    162   FOURCC_BPP_HDYC = 16,
    163   FOURCC_BPP_2VUY = 16,
    164   FOURCC_BPP_JPEG = 1,
    165   FOURCC_BPP_DMB1 = 1,
    166   FOURCC_BPP_BA81 = 8,
    167   FOURCC_BPP_RGB3 = 24,
    168   FOURCC_BPP_BGR3 = 24,
    169   FOURCC_BPP_CM32 = 32,
    170   FOURCC_BPP_CM24 = 24,
    171 
    172   // Match any fourcc.
    173   FOURCC_BPP_ANY = 0,  // 0 means unknown.
    174 };
    175 
    176 // Converts fourcc aliases into canonical ones.
    177 LIBYUV_API uint32 CanonicalFourCC(uint32 fourcc);
    178 
    179 #ifdef __cplusplus
    180 }  // extern "C"
    181 }  // namespace libyuv
    182 #endif
    183 
    184 #endif  // INCLUDE_LIBYUV_VIDEO_COMMON_H_
    185