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_  // NOLINT
     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 #define FOURCC(a, b, c, d) ( \
     31     (static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \
     32     (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24))
     33 
     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 
     41 enum FourCC {
     42   // Canonical fourcc codes used in our code.
     43   FOURCC_I420 = FOURCC('I', '4', '2', '0'),
     44   FOURCC_I422 = FOURCC('I', '4', '2', '2'),
     45   FOURCC_I444 = FOURCC('I', '4', '4', '4'),
     46   FOURCC_I411 = FOURCC('I', '4', '1', '1'),
     47   FOURCC_I400 = FOURCC('I', '4', '0', '0'),
     48   FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'),  // Linux version of I420.
     49   FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'),
     50   FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'),
     51   FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'),
     52   FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'),
     53   FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'),
     54   FOURCC_M420 = FOURCC('M', '4', '2', '0'),
     55   FOURCC_Q420 = FOURCC('Q', '4', '2', '0'),
     56   FOURCC_V210 = FOURCC('V', '2', '1', '0'),
     57   FOURCC_24BG = FOURCC('2', '4', 'B', 'G'),
     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_RGBA = FOURCC('R', 'G', 'B', 'A'),
     62   FOURCC_RGBP = FOURCC('R', 'G', 'B', 'P'),  // bgr565.
     63   FOURCC_RGBO = FOURCC('R', 'G', 'B', 'O'),  // abgr1555.
     64   FOURCC_R444 = FOURCC('R', '4', '4', '4'),  // argb4444.
     65   FOURCC_RAW  = FOURCC('r', 'a', 'w', ' '),
     66   FOURCC_NV21 = FOURCC('N', 'V', '2', '1'),
     67   FOURCC_NV12 = FOURCC('N', 'V', '1', '2'),
     68   FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'),
     69   FOURCC_H264 = FOURCC('H', '2', '6', '4'),
     70   // Next four are Bayer RGB formats. The four characters define the order of
     71   // the colours in each 2x2 pixel grid, going left-to-right and top-to-bottom.
     72   FOURCC_RGGB = FOURCC('R', 'G', 'G', 'B'),
     73   FOURCC_BGGR = FOURCC('B', 'G', 'G', 'R'),
     74   FOURCC_GRBG = FOURCC('G', 'R', 'B', 'G'),
     75   FOURCC_GBRG = FOURCC('G', 'B', 'R', 'G'),
     76 
     77   // Aliases for canonical fourcc codes, replaced with their canonical
     78   // equivalents by CanonicalFourCC().
     79   FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'),  // Alias for I420.
     80   FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'),  // Alias for I422.
     81   FOURCC_YU24 = FOURCC('Y', 'U', '2', '4'),  // Alias for I444.
     82   FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'),  // Alias for YUY2.
     83   FOURCC_YUVS = FOURCC('y', 'u', 'v', 's'),  // Alias for YUY2 on Mac.
     84   FOURCC_HDYC = FOURCC('H', 'D', 'Y', 'C'),  // Alias for UYVY.
     85   FOURCC_2VUY = FOURCC('2', 'v', 'u', 'y'),  // Alias for UYVY.
     86   FOURCC_JPEG = FOURCC('J', 'P', 'E', 'G'),  // Alias for MJPG.
     87   FOURCC_DMB1 = FOURCC('d', 'm', 'b', '1'),  // Alias for MJPG on Mac.
     88   FOURCC_BA81 = FOURCC('B', 'A', '8', '1'),  // Alias for BGGR.
     89   FOURCC_RGB3 = FOURCC('R', 'G', 'B', '3'),  // Alias for RAW.
     90   FOURCC_BGR3 = FOURCC('B', 'G', 'R', '3'),  // Alias for 24BG.
     91 
     92   // Match any fourcc.
     93   FOURCC_ANY  = 0xFFFFFFFF,
     94 };
     95 
     96 enum FourCCBpp {
     97   // Canonical fourcc codes used in our code.
     98   FOURCC_BPP_I420 = 12,
     99   FOURCC_BPP_I422 = 16,
    100   FOURCC_BPP_I444 = 24,
    101   FOURCC_BPP_I411 = 12,
    102   FOURCC_BPP_I400 = 8,
    103   FOURCC_BPP_YU12 = 12,
    104   FOURCC_BPP_YV12 = 12,
    105   FOURCC_BPP_YV16 = 16,
    106   FOURCC_BPP_YV24 = 24,
    107   FOURCC_BPP_YUY2 = 16,
    108   FOURCC_BPP_UYVY = 16,
    109   FOURCC_BPP_M420 = 12,
    110   FOURCC_BPP_Q420 = 12,
    111   FOURCC_BPP_V210 = 22,  // 128 / 6 actually.
    112   FOURCC_BPP_24BG = 24,
    113   FOURCC_BPP_ARGB = 32,
    114   FOURCC_BPP_BGRA = 32,
    115   FOURCC_BPP_ABGR = 32,
    116   FOURCC_BPP_RGBA = 32,
    117   FOURCC_BPP_RGBP = 16,
    118   FOURCC_BPP_RGBO = 16,
    119   FOURCC_BPP_R444 = 16,
    120   FOURCC_BPP_RAW  = 24,
    121   FOURCC_BPP_NV21 = 12,
    122   FOURCC_BPP_NV12 = 12,
    123   FOURCC_BPP_MJPG = 0,  // 0 means unknown.
    124   FOURCC_BPP_H264 = 0,
    125   // Next four are Bayer RGB formats. The four characters define the order of
    126   // the colours in each 2x2 pixel grid, going left-to-right and top-to-bottom.
    127   FOURCC_BPP_RGGB = 8,
    128   FOURCC_BPP_BGGR = 8,
    129   FOURCC_BPP_GRBG = 8,
    130   FOURCC_BPP_GBRG = 8,
    131 
    132   // Aliases for canonical fourcc codes, replaced with their canonical
    133   // equivalents by CanonicalFourCC().
    134   FOURCC_BPP_IYUV = 12,
    135   FOURCC_BPP_YU16 = 16,
    136   FOURCC_BPP_YU24 = 24,
    137   FOURCC_BPP_YUYV = 16,
    138   FOURCC_BPP_YUVS = 16,
    139   FOURCC_BPP_HDYC = 16,
    140   FOURCC_BPP_2VUY = 16,
    141   FOURCC_BPP_JPEG = 1,
    142   FOURCC_BPP_DMB1 = 1,
    143   FOURCC_BPP_BA81 = 8,
    144   FOURCC_BPP_RGB3 = 24,
    145   FOURCC_BPP_BGR3 = 24,
    146 
    147   // Match any fourcc.
    148   FOURCC_BPP_ANY  = 0,  // 0 means unknown.
    149 };
    150 
    151 // Converts fourcc aliases into canonical ones.
    152 LIBYUV_API uint32 CanonicalFourCC(uint32 fourcc);
    153 
    154 #ifdef __cplusplus
    155 }  // extern "C"
    156 }  // namespace libyuv
    157 #endif
    158 
    159 #endif  // INCLUDE_LIBYUV_VIDEO_COMMON_H_  NOLINT
    160