kodi
ColorManager.h
1 /*
2  * Copyright (C) 2016 Lauri Mylläri
3  * http://kodi.org
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #if defined(HAVE_LCMS2)
12 #include <lcms2.h>
13 #endif
14 
15 #include <cstdint>
16 #include <string>
17 
18 extern "C"
19 {
20 #include <libavutil/pixfmt.h>
21 }
22 
23 enum CMS_DATA_FORMAT
24 {
25  CMS_DATA_FMT_RGB,
26  CMS_DATA_FMT_RGBA,
27  CMS_DATA_FMT_COUNT
28 };
29 
30 enum CMS_MODE
31 {
32  CMS_MODE_3DLUT,
33  CMS_MODE_PROFILE,
34  CMS_MODE_COUNT
35 };
36 
37 enum CMS_WHITEPOINT
38 {
39  CMS_WHITEPOINT_D65,
40  CMS_WHITEPOINT_D93,
41  CMS_WHITEPOINT_COUNT
42 };
43 
44 enum CMS_PRIMARIES
45 {
46  CMS_PRIMARIES_AUTO,
47  CMS_PRIMARIES_BT709, // HDTV
48  CMS_PRIMARIES_170M, // SDTV
49  CMS_PRIMARIES_BT470M, // old NTSC (1953)
50  CMS_PRIMARIES_BT470BG, // old PAL/SECAM (1975)
51  CMS_PRIMARIES_240M, // old HDTV (1988)
52  CMS_PRIMARIES_BT2020, // UHDTV
53  CMS_PRIMARIES_COUNT
54 };
55 
56 enum CMS_TRC_TYPE
57 {
58  CMS_TRC_BT1886,
59  CMS_TRC_INPUT_OFFSET,
60  CMS_TRC_OUTPUT_OFFSET,
61  CMS_TRC_ABSOLUTE,
62  CMS_TRC_COUNT
63 };
64 
66 {
67 public:
68  CColorManager();
69  virtual ~CColorManager();
70 
75  bool IsEnabled() const;
76 
81  bool IsValid() const;
82 
92  bool GetVideo3dLut(AVColorPrimaries srcPrimaries, int* cmsToken, CMS_DATA_FORMAT format,
93  int clutSize, uint16_t* clutData);
94 
101  bool CheckConfiguration(int cmsToken, AVColorPrimaries srcPrimaries);
102 
110  static bool Get3dLutSize(CMS_DATA_FORMAT format, int *clutSize, int *dataSize);
111 
112 private:
118  static bool Probe3dLut(const std::string& filename, int* clutSize);
119 
127  static bool Load3dLut(const std::string& filename,
128  CMS_DATA_FORMAT format,
129  int clutSize,
130  uint16_t* clutData);
131 
132 
133 #if defined(HAVE_LCMS2)
134  // ProbeIccDisplayProfile
135 
136  // ProbeIccDeviceLink (?)
137 
138 
139  /* \brief Load an ICC display profile
140  \param filename full path and filename
141  \return display profile (cmsHPROFILE)
142  */
143  cmsHPROFILE LoadIccDisplayProfile(const std::string& filename);
144 
145  /* \brief Load an ICC device link
146  \param filename full path and filename
147  \return device link (cmsHTRANSFORM)
148  */
149  // LoadIccDeviceLink (?)
150 
151 
152  // create a gamma curve
153  cmsToneCurve* CreateToneCurve(CMS_TRC_TYPE gammaType, double gammaValue, cmsCIEXYZ blackPoint);
154 
155  // create a source profile
156  cmsHPROFILE CreateSourceProfile(CMS_PRIMARIES primaries, cmsToneCurve *gamma, CMS_WHITEPOINT whitepoint);
157 
158 
159  /* \brief Create 3D LUT
160  Samples a cmsHTRANSFORM object to create a 3D LUT of specified resolution
161  \param transform cmsHTRANSFORM object to sample
162  \param format of CLUT data
163  \param resolution size of the 3D LUT to create
164  \param clut pointer to LUT data
165  */
166  void Create3dLut(cmsHTRANSFORM transform, CMS_DATA_FORMAT format, int clutSize, uint16_t *clutData);
167 
168  // keep current display profile loaded here
169  cmsHPROFILE m_hProfile = nullptr;
170  cmsCIEXYZ m_blackPoint = { 0, 0, 0 };
171 
172  // display parameters (gamma, input/output offset, primaries, whitepoint, intent?)
173  CMS_WHITEPOINT m_curIccWhitePoint;
174  CMS_PRIMARIES m_curIccPrimaries;
175  CMS_TRC_TYPE m_m_curIccGammaMode;
176  int m_curIccGamma; // gamma multiplied by 100
177 #endif // defined(HAVE_LCMS2)
178 
179  // current configuration:
180  CMS_PRIMARIES m_curVideoPrimaries;
181  int m_curClutSize;
182  int m_curCmsToken;
183  // (compare the following to system settings to see if configuration is still valid)
184  int m_curCmsMode;
185  std::string m_cur3dlutFile;
186  std::string m_curIccProfile;
187 
188 };
189 
190 
static bool Get3dLutSize(CMS_DATA_FORMAT format, int *clutSize, int *dataSize)
Get a 3D LUT dimension and data size for video color correction.
Definition: ColorManager.cpp:104
bool IsValid() const
Check if configuration of color management is valid.
Definition: ColorManager.cpp:50
Definition: ColorManager.h:65
bool CheckConfiguration(int cmsToken, AVColorPrimaries srcPrimaries)
Check if a 3D LUT is still valid.
Definition: ColorManager.cpp:242
bool GetVideo3dLut(AVColorPrimaries srcPrimaries, int *cmsToken, CMS_DATA_FORMAT format, int clutSize, uint16_t *clutData)
Get a 3D LUT for video color correction.
Definition: ColorManager.cpp:154
bool IsEnabled() const
Check if user has requested color management.
Definition: ColorManager.cpp:45