Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GFX_COLOR_SPACE_H_ | 5 #ifndef UI_GFX_COLOR_SPACE_H_ |
| 6 #define UI_GFX_COLOR_SPACE_H_ | 6 #define UI_GFX_COLOR_SPACE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "third_party/skia/include/core/SkColorSpace.h" | 13 #include "third_party/skia/include/core/SkColorSpace.h" |
| 14 #include "ui/gfx/gfx_export.h" | 14 #include "ui/gfx/gfx_export.h" |
| 15 | 15 |
| 16 namespace IPC { | 16 namespace IPC { |
| 17 template <class P> | 17 template <class P> |
| 18 struct ParamTraits; | 18 struct ParamTraits; |
| 19 } // namespace IPC | 19 } // namespace IPC |
| 20 | 20 |
| 21 namespace gfx { | 21 namespace gfx { |
| 22 | 22 |
| 23 class ICCProfile; | 23 class ICCProfile; |
| 24 | 24 |
| 25 // Used to represet a color space for the purpose of color conversion. | 25 // Used to represet a color space for the purpose of color conversion. |
| 26 // This is designed to be safe and compact enough to send over IPC | 26 // This is designed to be safe and compact enough to send over IPC |
| 27 // between any processes. | 27 // between any processes. |
| 28 class GFX_EXPORT ColorSpace { | 28 class GFX_EXPORT ColorSpace { |
| 29 public: | 29 public: |
| 30 enum class PrimaryID : uint16_t { | 30 enum class PrimaryID : uint16_t { |
|
hubbe
2017/02/15 23:30:43
uint8_t (ditto below)
| |
| 31 // The first 0-255 values should match the H264 specification (see Table E-3 | 31 INVALID = 0, |
| 32 // Colour Primaries in https://www.itu.int/rec/T-REC-H.264/en). | 32 BT709, |
| 33 RESERVED0 = 0, | 33 BT470M, |
| 34 BT709 = 1, | 34 BT470BG, |
| 35 UNSPECIFIED = 2, | 35 SMPTE170M, |
| 36 RESERVED = 3, | 36 SMPTE240M, |
| 37 BT470M = 4, | 37 FILM, |
| 38 BT470BG = 5, | 38 BT2020, |
| 39 SMPTE170M = 6, | 39 SMPTEST428_1, |
| 40 SMPTE240M = 7, | 40 SMPTEST431_2, |
| 41 FILM = 8, | 41 SMPTEST432_1, |
| 42 BT2020 = 9, | |
| 43 SMPTEST428_1 = 10, | |
| 44 SMPTEST431_2 = 11, | |
| 45 SMPTEST432_1 = 12, | |
| 46 | |
| 47 LAST_STANDARD_VALUE = SMPTEST432_1, | |
| 48 | |
| 49 // Chrome-specific values start at 1000. | |
| 50 UNKNOWN = 1000, | |
| 51 XYZ_D50, | 42 XYZ_D50, |
| 52 ADOBE_RGB, | 43 ADOBE_RGB, |
| 53 CUSTOM, | 44 CUSTOM, |
| 54 LAST = CUSTOM | 45 LAST = CUSTOM |
| 55 }; | 46 }; |
| 56 | 47 |
| 57 enum class TransferID : uint16_t { | 48 enum class TransferID : uint16_t { |
| 58 // The first 0-255 values should match the H264 specification (see Table E-4 | 49 INVALID = 0, |
| 59 // Transfer Characteristics in https://www.itu.int/rec/T-REC-H.264/en). | 50 BT709, |
| 60 RESERVED0 = 0, | 51 GAMMA22, |
| 61 BT709 = 1, | |
| 62 UNSPECIFIED = 2, | |
| 63 RESERVED = 3, | |
| 64 GAMMA22 = 4, | |
| 65 GAMMA28 = 5, | |
| 66 SMPTE170M = 6, | |
| 67 SMPTE240M = 7, | |
| 68 LINEAR = 8, | |
| 69 LOG = 9, | |
| 70 LOG_SQRT = 10, | |
| 71 IEC61966_2_4 = 11, | |
| 72 BT1361_ECG = 12, | |
| 73 IEC61966_2_1 = 13, | |
| 74 BT2020_10 = 14, | |
| 75 BT2020_12 = 15, | |
| 76 SMPTEST2084 = 16, | |
| 77 SMPTEST428_1 = 17, | |
| 78 ARIB_STD_B67 = 18, // AKA hybrid-log gamma, HLG. | |
| 79 | |
| 80 LAST_STANDARD_VALUE = SMPTEST428_1, | |
| 81 | |
| 82 // Chrome-specific values start at 1000. | |
| 83 UNKNOWN = 1000, | |
| 84 GAMMA24, | 52 GAMMA24, |
| 53 GAMMA28, | |
| 54 SMPTE170M, | |
| 55 SMPTE240M, | |
| 56 LINEAR, | |
| 57 LOG, | |
| 58 LOG_SQRT, | |
| 59 IEC61966_2_4, | |
| 60 BT1361_ECG, | |
| 61 IEC61966_2_1, | |
| 62 BT2020_10, | |
| 63 BT2020_12, | |
| 64 SMPTEST2084, | |
| 65 SMPTEST428_1, | |
| 66 ARIB_STD_B67, | |
| 85 | 67 |
| 86 // This is an ad-hoc transfer function that decodes SMPTE 2084 content | 68 // This is an ad-hoc transfer function that decodes SMPTE 2084 content |
| 87 // into a 0-1 range more or less suitable for viewing on a non-hdr | 69 // into a 0-1 range more or less suitable for viewing on a non-hdr |
| 88 // display. | 70 // display. |
| 89 SMPTEST2084_NON_HDR, | 71 SMPTEST2084_NON_HDR, |
| 90 | 72 |
| 91 // Like LINEAR, but intended for HDR. (can go outside of 0-1) | 73 // Like LINEAR, but intended for HDR. (can go outside of 0-1) |
| 92 LINEAR_HDR, | 74 LINEAR_HDR, |
| 93 // TODO(hubbe): Need to store an approximation of the gamma function(s). | 75 |
| 94 CUSTOM, | 76 CUSTOM, |
| 95 LAST = CUSTOM, | 77 LAST = CUSTOM, |
| 96 }; | 78 }; |
| 97 | 79 |
| 98 enum class MatrixID : int16_t { | 80 enum class MatrixID : int16_t { |
| 99 // The first 0-255 values should match the H264 specification (see Table E-5 | |
| 100 // Matrix Coefficients in https://www.itu.int/rec/T-REC-H.264/en). | |
| 101 RGB = 0, | 81 RGB = 0, |
| 102 BT709 = 1, | 82 BT709, |
| 103 UNSPECIFIED = 2, | 83 FCC, |
| 104 RESERVED = 3, | 84 BT470BG, |
| 105 FCC = 4, | 85 SMPTE170M, |
| 106 BT470BG = 5, | 86 SMPTE240M, |
| 107 SMPTE170M = 6, | 87 YCOCG, |
| 108 SMPTE240M = 7, | 88 BT2020_NCL, |
| 109 YCOCG = 8, | 89 BT2020_CL, |
| 110 BT2020_NCL = 9, | 90 YDZDX, |
| 111 BT2020_CL = 10, | 91 LAST = YDZDX, |
| 112 YDZDX = 11, | |
| 113 | |
| 114 LAST_STANDARD_VALUE = YDZDX, | |
| 115 | |
| 116 // Chrome-specific values start at 1000 | |
| 117 UNKNOWN = 1000, | |
| 118 LAST = UNKNOWN, | |
| 119 }; | 92 }; |
| 120 | 93 |
| 121 // This corresponds to the WebM Range enum which is part of WebM color data | |
| 122 // (see http://www.webmproject.org/docs/container/#Range). | |
| 123 // H.264 only uses a bool, which corresponds to the LIMITED/FULL values. | |
| 124 // Chrome-specific values start at 1000. | |
| 125 enum class RangeID : int8_t { | 94 enum class RangeID : int8_t { |
| 126 // Range is not explicitly specified / unknown. | 95 // Full RGB color range with RGB valees from 0 to 255. |
| 127 UNSPECIFIED = 0, | 96 FULL = 0, |
| 128 | |
| 129 // Limited Rec. 709 color range with RGB values ranging from 16 to 235. | 97 // Limited Rec. 709 color range with RGB values ranging from 16 to 235. |
| 130 LIMITED = 1, | 98 LIMITED, |
| 131 | |
| 132 // Full RGB color range with RGB valees from 0 to 255. | |
| 133 FULL = 2, | |
| 134 | |
| 135 // Range is defined by TransferID/MatrixID. | 99 // Range is defined by TransferID/MatrixID. |
| 136 DERIVED = 3, | 100 DERIVED, |
| 137 | |
| 138 LAST = DERIVED | 101 LAST = DERIVED |
| 139 }; | 102 }; |
| 140 | 103 |
| 141 ColorSpace(); | 104 ColorSpace(); |
| 142 ColorSpace(PrimaryID primaries, TransferID transfer); | 105 ColorSpace(PrimaryID primaries, TransferID transfer); |
| 143 ColorSpace(PrimaryID primaries, | 106 ColorSpace(PrimaryID primaries, |
| 144 TransferID transfer, | 107 TransferID transfer, |
| 145 MatrixID matrix, | 108 MatrixID matrix, |
| 146 RangeID full_range); | 109 RangeID full_range); |
| 147 ColorSpace(const ColorSpace& other); | 110 ColorSpace(const ColorSpace& other); |
| 148 ColorSpace(int primaries, int transfer, int matrix, RangeID full_range); | |
| 149 ~ColorSpace(); | 111 ~ColorSpace(); |
| 150 | 112 |
| 151 static PrimaryID PrimaryIDFromInt(int primary_id); | 113 // Return the PrimaryID for values from the H264 specification (see Table E-3 |
| 152 static TransferID TransferIDFromInt(int transfer_id); | 114 // Colour Primaries in https://www.itu.int/rec/T-REC-H.264/en). |
| 153 static MatrixID MatrixIDFromInt(int matrix_id); | 115 static PrimaryID PrimaryIDFromH264(int primary_id); |
| 116 | |
| 117 // Return the TransferID for value from the H264 specification (see Table E-4 | |
| 118 // Transfer Characteristics in https://www.itu.int/rec/T-REC-H.264/en). | |
| 119 static TransferID TransferIDFromH264(int transfer_id); | |
| 120 | |
| 121 // Return the MatrixID for values from the H264 specification (see Table E-5 | |
| 122 // Matrix Coefficients in https://www.itu.int/rec/T-REC-H.264/en). | |
| 123 static MatrixID MatrixIDFromH264(int matrix_id); | |
| 154 | 124 |
| 155 // Returns true if this is not the default-constructor object. | 125 // Returns true if this is not the default-constructor object. |
| 156 bool IsValid() const; | 126 bool IsValid() const; |
| 157 | 127 |
| 158 static ColorSpace CreateSRGB(); | 128 static ColorSpace CreateSRGB(); |
| 159 static ColorSpace CreateCustom(const SkMatrix44& to_XYZD50, | 129 static ColorSpace CreateCustom(const SkMatrix44& to_XYZD50, |
| 160 const SkColorSpaceTransferFn& fn); | 130 const SkColorSpaceTransferFn& fn); |
| 161 // scRGB is like RGB, but linear and values outside of 0-1 are allowed. | 131 // scRGB is like RGB, but linear and values outside of 0-1 are allowed. |
| 162 // scRGB is normally used with fp16 textures. | 132 // scRGB is normally used with fp16 textures. |
| 163 static ColorSpace CreateSCRGBLinear(); | 133 static ColorSpace CreateSCRGBLinear(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 180 | 150 |
| 181 void GetPrimaryMatrix(SkMatrix44* to_XYZD50) const; | 151 void GetPrimaryMatrix(SkMatrix44* to_XYZD50) const; |
| 182 bool GetTransferFunction(SkColorSpaceTransferFn* fn) const; | 152 bool GetTransferFunction(SkColorSpaceTransferFn* fn) const; |
| 183 bool GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const; | 153 bool GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const; |
| 184 | 154 |
| 185 // For most formats, this is the RGB to YUV matrix. | 155 // For most formats, this is the RGB to YUV matrix. |
| 186 void GetTransferMatrix(SkMatrix44* matrix) const; | 156 void GetTransferMatrix(SkMatrix44* matrix) const; |
| 187 void GetRangeAdjustMatrix(SkMatrix44* matrix) const; | 157 void GetRangeAdjustMatrix(SkMatrix44* matrix) const; |
| 188 | 158 |
| 189 private: | 159 private: |
| 190 PrimaryID primaries_ = PrimaryID::UNSPECIFIED; | 160 PrimaryID primaries_ = PrimaryID::INVALID; |
| 191 TransferID transfer_ = TransferID::UNSPECIFIED; | 161 TransferID transfer_ = TransferID::INVALID; |
| 192 MatrixID matrix_ = MatrixID::UNSPECIFIED; | 162 MatrixID matrix_ = MatrixID::RGB; |
|
hubbe
2017/02/15 23:30:43
I think we should default matrix_ & range_ to INVA
| |
| 193 RangeID range_ = RangeID::LIMITED; | 163 RangeID range_ = RangeID::FULL; |
| 194 | 164 |
| 195 // Only used if primaries_ is PrimaryID::CUSTOM. | 165 // Only used if primaries_ is PrimaryID::CUSTOM. |
| 196 float custom_primary_matrix_[9] = {0, 0, 0, 0, 0, 0, 0, 0}; | 166 float custom_primary_matrix_[9] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 197 | 167 |
| 198 // Only used if transfer_ is TransferID::CUSTOM. This array consists of the A | 168 // Only used if transfer_ is TransferID::CUSTOM. This array consists of the A |
| 199 // through G entries of the SkColorSpaceTransferFn structure in alphabetical | 169 // through G entries of the SkColorSpaceTransferFn structure in alphabetical |
| 200 // order. | 170 // order. |
| 201 float custom_transfer_params_[7] = {0, 0, 0, 0, 0, 0, 0}; | 171 float custom_transfer_params_[7] = {0, 0, 0, 0, 0, 0, 0}; |
| 202 | 172 |
| 203 // This is used to look up the ICCProfile from which this ColorSpace was | 173 // This is used to look up the ICCProfile from which this ColorSpace was |
| 204 // created, if possible. | 174 // created, if possible. |
| 205 uint64_t icc_profile_id_ = 0; | 175 uint64_t icc_profile_id_ = 0; |
| 206 sk_sp<SkColorSpace> icc_profile_sk_color_space_; | 176 sk_sp<SkColorSpace> icc_profile_sk_color_space_; |
| 207 | 177 |
| 208 friend class ICCProfile; | 178 friend class ICCProfile; |
| 209 friend class ColorTransform; | 179 friend class ColorTransform; |
| 210 friend class ColorTransformInternal; | 180 friend class ColorTransformInternal; |
| 211 friend class ColorSpaceWin; | 181 friend class ColorSpaceWin; |
| 212 friend struct IPC::ParamTraits<gfx::ColorSpace>; | 182 friend struct IPC::ParamTraits<gfx::ColorSpace>; |
| 213 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace); | 183 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace); |
| 214 }; | 184 }; |
| 215 | 185 |
| 216 } // namespace gfx | 186 } // namespace gfx |
| 217 | 187 |
| 218 #endif // UI_GFX_COLOR_SPACE_H_ | 188 #endif // UI_GFX_COLOR_SPACE_H_ |
| OLD | NEW |