Home | History | Annotate | Download | only in include
      1 /*
      2 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
      3 *
      4 * Redistribution and use in source and binary forms, with or without modification, are permitted
      5 * provided that the following conditions are met:
      6 *    * Redistributions of source code must retain the above copyright notice, this list of
      7 *      conditions and the following disclaimer.
      8 *    * Redistributions in binary form must reproduce the above copyright notice, this list of
      9 *      conditions and the following disclaimer in the documentation and/or other materials provided
     10 *      with the distribution.
     11 *    * Neither the name of The Linux Foundation nor the names of its contributors may be used to
     12 *      endorse or promote products derived from this software without specific prior written
     13 *      permission.
     14 *
     15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     17 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
     18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23 */
     24 
     25 #ifndef __COLOR_METADATA_H__
     26 #define __COLOR_METADATA_H__
     27 
     28 #ifdef __cplusplus
     29 extern "C" {
     30 #else
     31 #include <stdbool.h>
     32 #endif
     33 
     34 typedef enum ColorRange {
     35   Range_Limited = 0,
     36   Range_Full    = 1,
     37   Range_Max     = 0xff,
     38 } ColorRange;
     39 
     40 // The following values matches the HEVC spec
     41 typedef enum ColorPrimaries {
     42   // Unused = 0;
     43   ColorPrimaries_BT709_5     = 1,  // ITU-R BT.709-5 or equivalent
     44   /* Unspecified = 2, Reserved = 3*/
     45   ColorPrimaries_BT470_6M    = 4,  // ITU-R BT.470-6 System M or equivalent
     46   ColorPrimaries_BT601_6_625 = 5,  // ITU-R BT.601-6 625 or equivalent
     47   ColorPrimaries_BT601_6_525 = 6,  // ITU-R BT.601-6 525 or equivalent
     48   ColorPrimaries_SMPTE_240M  = 7,  // SMPTE_240M
     49   ColorPrimaries_GenericFilm = 8,  // Generic Film
     50   ColorPrimaries_BT2020      = 9,  // ITU-R BT.2020 or equivalent
     51   ColorPrimaries_SMPTE_ST428 = 10,  // SMPTE_240M
     52   ColorPrimaries_AdobeRGB    = 11,
     53   ColorPrimaries_DCIP3       = 12,
     54   ColorPrimaries_EBU3213     = 22,
     55   ColorPrimaries_Max         = 0xff,
     56 } ColorPrimaries;
     57 
     58 typedef enum GammaTransfer {
     59   // Unused = 0;
     60   Transfer_sRGB            = 1,  // ITR-BT.709-5
     61   /* Unspecified = 2, Reserved = 3 */
     62   Transfer_Gamma2_2        = 4,
     63   Transfer_Gamma2_8        = 5,
     64   Transfer_SMPTE_170M      = 6,  // BT.601-6 525 or 625
     65   Transfer_SMPTE_240M      = 7,  // SMPTE_240M
     66   Transfer_Linear          = 8,
     67   Transfer_Log             = 9,
     68   Transfer_Log_Sqrt        = 10,
     69   Transfer_XvYCC           = 11,  // IEC 61966-2-4
     70   Transfer_BT1361          = 12,  // Rec.ITU-R BT.1361 extended gamut
     71   Transfer_sYCC            = 13,  // IEC 61966-2-1 sRGB or sYCC
     72   Transfer_BT2020_2_1      = 14,  // Rec. ITU-R BT.2020-2 (same as the values 1, 6, and 15)
     73   Transfer_BT2020_2_2      = 15,  // Rec. ITU-R BT.2020-2 (same as the values 1, 6, and 14)
     74   Transfer_SMPTE_ST2084    = 16,  // 2084
     75   // transfers unlikely to be required by Android
     76   Transfer_ST_428          = 17,  // SMPTE ST 428-1
     77   Transfer_HLG             = 18,  // ARIB STD-B67
     78   Transfer_Max             = 0xff,
     79 } GammaTransfer;
     80 
     81 typedef enum MatrixCoEfficients {
     82   MatrixCoEff_Identity           = 0,
     83   MatrixCoEff_BT709_5            = 1,
     84   /* Unspecified = 2, Reserved = 3 */
     85   MatrixCoeff_FCC_73_682         = 4,
     86   MatrixCoEff_BT601_6_625        = 5,
     87   MatrixCoEff_BT601_6_525        = 6,
     88   MatrixCoEff_SMPTE240M          = 7,  // used with 601_525_Unadjusted
     89   MatrixCoEff_YCgCo              = 8,
     90   MatrixCoEff_BT2020             = 9,
     91   MatrixCoEff_BT2020Constant     = 10,
     92   MatrixCoEff_BT601_6_Unadjusted = 11,  // Used with BT601_625(KR=0.222, KB=0.071)
     93   MatrixCoEff_DCIP3              = 12,
     94   MatrixCoEff_Chroma_NonConstant = 13,
     95   MatrixCoEff_Max                = 0xff,
     96 } MatrixCoEfficients;
     97 
     98 typedef struct Primaries {
     99   uint32_t rgbPrimaries[3][2];  // unit 1/50000;
    100   uint32_t whitePoint[2];  // unit 1/50000;
    101 } Primaries;
    102 
    103 typedef struct MasteringDisplay {
    104   bool      colorVolumeSEIEnabled;
    105   Primaries primaries;
    106   uint32_t  maxDisplayLuminance;  // unit: cd/m^2.
    107   uint32_t  minDisplayLuminance;  // unit: 1/10000 cd/m^2.
    108 } MasteringDisplay;
    109 
    110 typedef struct ContentLightLevel {
    111   bool     lightLevelSEIEnabled;
    112   uint32_t maxContentLightLevel;  // unit: cd/m^2.
    113   uint32_t minPicAverageLightLevel;  // unit: 1/10000 cd/m^2.
    114 } ContentLightLevel;
    115 
    116 typedef struct ColorRemappingInfo {
    117   bool               criEnabled;
    118   uint32_t           crId;
    119   uint32_t           crCancelFlag;
    120   uint32_t           crPersistenceFlag;
    121   uint32_t           crVideoSignalInfoPresentFlag;
    122   uint32_t           crRange;
    123   ColorPrimaries     crPrimaries;
    124   GammaTransfer      crTransferFunction;
    125   MatrixCoEfficients crMatrixCoefficients;
    126   uint32_t           crInputBitDepth;
    127   uint32_t           crOutputBitDepth;
    128   uint32_t           crPreLutNumValMinusOne[3];
    129   uint32_t           crPreLutCodedValue[3*33];
    130   uint32_t           crPreLutTargetValue[3*33];
    131   uint32_t           crMatrixPresentFlag;
    132   uint32_t           crLog2MatrixDenom;
    133   int32_t            crCoefficients[3*3];
    134   uint32_t           crPostLutNumValMinusOne[3];
    135   uint32_t           crPostLutCodedValue[3*33];
    136   uint32_t           crPostLutTargetValue[3*33];
    137 } ColorRemappingInfo;
    138 
    139 typedef struct ColorMetaData {
    140   // Default values based on sRGB, needs to be overridden in gralloc
    141   // based on the format and size.
    142   ColorPrimaries     colorPrimaries;
    143   ColorRange         range;
    144   GammaTransfer      transfer;
    145   MatrixCoEfficients matrixCoefficients;
    146 
    147   MasteringDisplay   masteringDisplayInfo;
    148   ContentLightLevel  contentLightLevel;
    149   ColorRemappingInfo cRI;
    150 } ColorMetaData;
    151 
    152 typedef struct Color10Bit {
    153   uint32_t R: 10;
    154   uint32_t G: 10;
    155   uint32_t B: 10;
    156   uint32_t A: 2;
    157 } Color10Bit;
    158 
    159 typedef struct Lut3d {
    160   uint16_t dim;  // dimension of each side of LUT cube (ex: 13, 17)in lutEntries
    161   uint16_t gridSize;  // number of elements in the gridEntries
    162   /* Matrix ordering convension
    163   for (b = 0; b < dim; b++) {
    164     for (g = 0; g < dim; g++) {
    165       for (r = 0; r < dim; r++) {
    166         read/write [mR mG mB] associated w/ 3DLUT[r][g][b] to/from file
    167       }
    168     }
    169   } */
    170   Color10Bit *lutEntries;
    171   bool validLutEntries;  // Indicates if entries are valid and can be used.
    172   /*
    173    The grid is a 1D LUT for each of the R,G,B channels that can be
    174    used to apply an independent nonlinear transformation to each
    175    channel before it is used as a coordinate for addressing
    176    the uniform 3D LUT.  This effectively creates a non-uniformly
    177    sampled 3D LUT.  This is useful for having independent control
    178    of the sampling grid density along each dimension for greater
    179    precision in spite of having a relatively small number of samples.i
    180   */
    181   Color10Bit *gridEntries;
    182   bool validGridEntries;  // Indicates if entries are valid and can be used.
    183 } Lut3d;
    184 
    185 #ifdef __cplusplus
    186 }
    187 #endif
    188 
    189 #endif  // __COLOR_METADATA_H__
    190