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 29extern "C" { 30#else 31#include <stdbool.h> 32#endif 33 34typedef 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 41typedef 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_Max = 0xff, 55} ColorPrimaries; 56 57typedef enum GammaTransfer { 58 // Unused = 0; 59 Transfer_sRGB = 1, // ITR-BT.709-5 60 /* Unspecified = 2, Reserved = 3 */ 61 Transfer_Gamma2_2 = 4, 62 Transfer_Gamma2_8 = 5, 63 Transfer_SMPTE_170M = 6, // BT.601-6 525 or 625 64 Transfer_SMPTE_240M = 7, // SMPTE_240M 65 Transfer_Linear = 8, 66 Transfer_HLG = 9, 67 Transfer_XvYCC = 11, // IEC 61966-2-4 68 Transfer_BT1361 = 12, // Rec.ITU-R BT.1361 extended gamut 69 Transfer_SMPTE_ST2084 = 16, // 2084 70 // transfers unlikely to be required by Android 71 Transfer_ST_428 = 17, // SMPTE ST 428-1 72 Transfer_Max = 0xff, 73} GammaTransfer; 74 75typedef enum MatrixCoEfficients { 76 MatrixCoEff_Identity = 0, 77 MatrixCoEff_BT709_5 = 1, 78 /* Unspecified = 2, Reserved = 3 */ 79 MatrixCoEff_BT601_6_625 = 5, 80 MatrixCoEff_BT601_6_525 = 6, 81 MatrixCoEff_SMPTE240M = 7, // used with 601_525_Unadjusted 82 MatrixCoEff_BT2020 = 9, 83 MatrixCoEff_BT2020Constant = 10, 84 MatrixCoEff_BT601_6_Unadjusted = 11, // Used with BT601_625(KR=0.222, KB=0.071) 85 MatrixCoEff_DCIP3 = 12, 86 MatrixCoEff_Max = 0xff, 87} MatrixCoEfficients; 88 89typedef struct Primaries { 90 uint32_t rgbPrimaries[3][2]; // unit 1/50000; 91 uint32_t whitePoint[2]; // unit 1/50000; 92} Primaries; 93 94typedef struct MasteringDisplay { 95 bool colorVolumeSEIEnabled; 96 Primaries primaries; 97 uint32_t maxDisplayLuminance; // unit: cd/m^2. 98 uint32_t minDisplayLuminance; // unit: 1/10000 cd/m^2. 99} MasteringDisplay; 100 101typedef struct ContentLightLevel { 102 bool lightLevelSEIEnabled; 103 uint32_t maxContentLightLevel; // unit: cd/m^2. 104 uint32_t minPicAverageLightLevel; // unit: 1/10000 cd/m^2. 105} ContentLightLevel; 106 107typedef struct ColorRemappingInfo { 108 bool criEnabled; 109 uint32_t crId; 110 uint32_t crCancelFlag; 111 uint32_t crPersistenceFlag; 112 uint32_t crVideoSignalInfoPresentFlag; 113 uint32_t crRange; 114 ColorPrimaries crPrimaries; 115 GammaTransfer crTransferFunction; 116 MatrixCoEfficients crMatrixCoefficients; 117 uint32_t crInputBitDepth; 118 uint32_t crOutputBitDepth; 119 uint32_t crPreLutNumValMinusOne[3]; 120 uint32_t crPreLutCodedValue[3*33]; 121 uint32_t crPreLutTargetValue[3*33]; 122 uint32_t crMatrixPresentFlag; 123 uint32_t crLog2MatrixDenom; 124 int32_t crCoefficients[3*3]; 125 uint32_t crPostLutNumValMinusOne[3]; 126 uint32_t crPostLutCodedValue[3*33]; 127 uint32_t crPostLutTargetValue[3*33]; 128} ColorRemappingInfo; 129 130typedef struct ColorMetaData { 131 // Default values based on sRGB, needs to be overridden in gralloc 132 // based on the format and size. 133 ColorPrimaries colorPrimaries; 134 ColorRange range; 135 GammaTransfer transfer; 136 MatrixCoEfficients matrixCoefficients; 137 138 MasteringDisplay masteringDisplayInfo; 139 ContentLightLevel contentLightLevel; 140 ColorRemappingInfo cRI; 141} ColorMetaData; 142 143typedef struct Color10Bit { 144 uint32_t R: 10; 145 uint32_t G: 10; 146 uint32_t B: 10; 147 uint32_t A: 2; 148} Color10Bit; 149 150typedef struct Lut3d { 151 uint16_t dim; // dimension of each side of LUT cube (ex: 13, 17)in lutEntries 152 uint16_t gridSize; // number of elements in the gridEntries 153 /* Matrix ordering convension 154 for (b = 0; b < dim; b++) { 155 for (g = 0; g < dim; g++) { 156 for (r = 0; r < dim; r++) { 157 read/write [mR mG mB] associated w/ 3DLUT[r][g][b] to/from file 158 } 159 } 160 } */ 161 Color10Bit *lutEntries; 162 bool validLutEntries; // Indicates if entries are valid and can be used. 163 /* 164 The grid is a 1D LUT for each of the R,G,B channels that can be 165 used to apply an independent nonlinear transformation to each 166 channel before it is used as a coordinate for addressing 167 the uniform 3D LUT. This effectively creates a non-uniformly 168 sampled 3D LUT. This is useful for having independent control 169 of the sampling grid density along each dimension for greater 170 precision in spite of having a relatively small number of samples.i 171 */ 172 Color10Bit *gridEntries; 173 bool validGridEntries; // Indicates if entries are valid and can be used. 174} Lut3d; 175 176#ifdef __cplusplus 177} 178#endif 179 180#endif // __COLOR_METADATA_H__ 181