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