1 /*
2 * Copyright (c) 2016-2017, 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 #include <stdint.h>
34 
35 typedef enum ColorRange {
36   Range_Limited = 0,
37   Range_Full    = 1,
38   Range_Max     = 0xff,
39 } ColorRange;
40 
41 // The following values matches the HEVC spec
42 typedef enum ColorPrimaries {
43   // Unused = 0;
44   ColorPrimaries_BT709_5     = 1,  // ITU-R BT.709-5 or equivalent
45   /* Unspecified = 2, Reserved = 3*/
46   ColorPrimaries_BT470_6M    = 4,  // ITU-R BT.470-6 System M or equivalent
47   ColorPrimaries_BT601_6_625 = 5,  // ITU-R BT.601-6 625 or equivalent
48   ColorPrimaries_BT601_6_525 = 6,  // ITU-R BT.601-6 525 or equivalent
49   ColorPrimaries_SMPTE_240M  = 7,  // SMPTE_240M
50   ColorPrimaries_GenericFilm = 8,  // Generic Film
51   ColorPrimaries_BT2020      = 9,  // ITU-R BT.2020 or equivalent
52   ColorPrimaries_SMPTE_ST428 = 10,  // SMPTE_240M
53   ColorPrimaries_AdobeRGB    = 11,
54   ColorPrimaries_DCIP3       = 12,
55   ColorPrimaries_EBU3213     = 22,
56   ColorPrimaries_Max         = 0xff,
57 } ColorPrimaries;
58 
59 typedef enum GammaTransfer {
60   // Unused = 0;
61   Transfer_sRGB            = 1,  // ITR-BT.709-5
62   /* Unspecified = 2, Reserved = 3 */
63   Transfer_Gamma2_2        = 4,
64   Transfer_Gamma2_8        = 5,
65   Transfer_SMPTE_170M      = 6,  // BT.601-6 525 or 625
66   Transfer_SMPTE_240M      = 7,  // SMPTE_240M
67   Transfer_Linear          = 8,
68   Transfer_Log             = 9,
69   Transfer_Log_Sqrt        = 10,
70   Transfer_XvYCC           = 11,  // IEC 61966-2-4
71   Transfer_BT1361          = 12,  // Rec.ITU-R BT.1361 extended gamut
72   Transfer_sYCC            = 13,  // IEC 61966-2-1 sRGB or sYCC
73   Transfer_BT2020_2_1      = 14,  // Rec. ITU-R BT.2020-2 (same as the values 1, 6, and 15)
74   Transfer_BT2020_2_2      = 15,  // Rec. ITU-R BT.2020-2 (same as the values 1, 6, and 14)
75   Transfer_SMPTE_ST2084    = 16,  // 2084
76   // transfers unlikely to be required by Android
77   Transfer_ST_428          = 17,  // SMPTE ST 428-1
78   Transfer_HLG             = 18,  // ARIB STD-B67
79   Transfer_Max             = 0xff,
80 } GammaTransfer;
81 
82 typedef enum MatrixCoEfficients {
83   MatrixCoEff_Identity           = 0,
84   MatrixCoEff_BT709_5            = 1,
85   /* Unspecified = 2, Reserved = 3 */
86   MatrixCoeff_FCC_73_682         = 4,
87   MatrixCoEff_BT601_6_625        = 5,
88   MatrixCoEff_BT601_6_525        = 6,
89   MatrixCoEff_SMPTE240M          = 7,  // used with 601_525_Unadjusted
90   MatrixCoEff_YCgCo              = 8,
91   MatrixCoEff_BT2020             = 9,
92   MatrixCoEff_BT2020Constant     = 10,
93   MatrixCoEff_BT601_6_Unadjusted = 11,  // Used with BT601_625(KR=0.222, KB=0.071)
94   MatrixCoEff_DCIP3              = 12,
95   MatrixCoEff_Chroma_NonConstant = 13,
96   MatrixCoEff_Max                = 0xff,
97 } MatrixCoEfficients;
98 
99 typedef struct Primaries {
100   uint32_t rgbPrimaries[3][2];  // unit 1/50000;
101   uint32_t whitePoint[2];  // unit 1/50000;
102 } Primaries;
103 
104 typedef struct MasteringDisplay {
105   bool      colorVolumeSEIEnabled;
106   Primaries primaries;
107   uint32_t  maxDisplayLuminance;  // unit: cd/m^2.
108   uint32_t  minDisplayLuminance;  // unit: 1/10000 cd/m^2.
109 } MasteringDisplay;
110 
111 typedef struct ContentLightLevel {
112   bool     lightLevelSEIEnabled;
113   uint32_t maxContentLightLevel;  // unit: cd/m^2.
114   uint32_t minPicAverageLightLevel;  // unit: 1/10000 cd/m^2.
115 } ContentLightLevel;
116 
117 typedef struct ColorRemappingInfo {
118   bool               criEnabled;
119   uint32_t           crId;
120   uint32_t           crCancelFlag;
121   uint32_t           crPersistenceFlag;
122   uint32_t           crVideoSignalInfoPresentFlag;
123   uint32_t           crRange;
124   ColorPrimaries     crPrimaries;
125   GammaTransfer      crTransferFunction;
126   MatrixCoEfficients crMatrixCoefficients;
127   uint32_t           crInputBitDepth;
128   uint32_t           crOutputBitDepth;
129   uint32_t           crPreLutNumValMinusOne[3];
130   uint32_t           crPreLutCodedValue[3*33];
131   uint32_t           crPreLutTargetValue[3*33];
132   uint32_t           crMatrixPresentFlag;
133   uint32_t           crLog2MatrixDenom;
134   int32_t            crCoefficients[3*3];
135   uint32_t           crPostLutNumValMinusOne[3];
136   uint32_t           crPostLutCodedValue[3*33];
137   uint32_t           crPostLutTargetValue[3*33];
138 } ColorRemappingInfo;
139 
140 #define HDR_DYNAMIC_META_DATA_SZ 1024
141 typedef struct ColorMetaData {
142   // Default values based on sRGB, needs to be overridden in gralloc
143   // based on the format and size.
144   ColorPrimaries     colorPrimaries;
145   ColorRange         range;
146   GammaTransfer      transfer;
147   MatrixCoEfficients matrixCoefficients;
148 
149   MasteringDisplay   masteringDisplayInfo;
150   ContentLightLevel  contentLightLevel;
151   ColorRemappingInfo cRI;
152 
153   // Dynamic meta data elements
154   bool dynamicMetaDataValid;
155   uint32_t dynamicMetaDataLen;
156   uint8_t dynamicMetaDataPayload[HDR_DYNAMIC_META_DATA_SZ];
157 } ColorMetaData;
158 
159 typedef struct Color10Bit {
160   uint32_t R: 10;
161   uint32_t G: 10;
162   uint32_t B: 10;
163   uint32_t A: 2;
164 } Color10Bit;
165 
166 typedef struct Lut3d {
167   uint16_t dim;  // dimension of each side of LUT cube (ex: 13, 17)in lutEntries
168   uint16_t gridSize;  // number of elements in the gridEntries
169   /* Matrix ordering convension
170   for (b = 0; b < dim; b++) {
171     for (g = 0; g < dim; g++) {
172       for (r = 0; r < dim; r++) {
173         read/write [mR mG mB] associated w/ 3DLUT[r][g][b] to/from file
174       }
175     }
176   } */
177   Color10Bit *lutEntries;
178   bool validLutEntries;  // Indicates if entries are valid and can be used.
179   /*
180    The grid is a 1D LUT for each of the R,G,B channels that can be
181    used to apply an independent nonlinear transformation to each
182    channel before it is used as a coordinate for addressing
183    the uniform 3D LUT.  This effectively creates a non-uniformly
184    sampled 3D LUT.  This is useful for having independent control
185    of the sampling grid density along each dimension for greater
186    precision in spite of having a relatively small number of samples.i
187   */
188   Color10Bit *gridEntries;
189   bool validGridEntries;  // Indicates if entries are valid and can be used.
190 } Lut3d;
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif  // __COLOR_METADATA_H__
197