| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 { |
| 31 // The first 0-255 values should match the H264 specification (see Table E-3 | 31 INVALID, |
| 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, |
| 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, |
| 85 | 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, // // AKA hybrid-log gamma, HLG. |
| 86 // This is an ad-hoc transfer function that decodes SMPTE 2084 content | 67 // 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 | 68 // into a 0-1 range more or less suitable for viewing on a non-hdr |
| 88 // display. | 69 // display. |
| 89 SMPTEST2084_NON_HDR, | 70 SMPTEST2084_NON_HDR, |
| 90 | |
| 91 // Like LINEAR, but intended for HDR. (can go outside of 0-1) | 71 // Like LINEAR, but intended for HDR. (can go outside of 0-1) |
| 92 LINEAR_HDR, | 72 LINEAR_HDR, |
| 93 // TODO(hubbe): Need to store an approximation of the gamma function(s). | |
| 94 CUSTOM, | 73 CUSTOM, |
| 95 LAST = CUSTOM, | 74 LAST = CUSTOM, |
| 96 }; | 75 }; |
| 97 | 76 |
| 98 enum class MatrixID : int16_t { | 77 enum class MatrixID : int16_t { |
| 99 // The first 0-255 values should match the H264 specification (see Table E-5 | 78 INVALID, |
| 100 // Matrix Coefficients in https://www.itu.int/rec/T-REC-H.264/en). | 79 RGB, |
| 101 RGB = 0, | 80 BT709, |
| 102 BT709 = 1, | 81 FCC, |
| 103 UNSPECIFIED = 2, | 82 BT470BG, |
| 104 RESERVED = 3, | 83 SMPTE170M, |
| 105 FCC = 4, | 84 SMPTE240M, |
| 106 BT470BG = 5, | 85 YCOCG, |
| 107 SMPTE170M = 6, | 86 BT2020_NCL, |
| 108 SMPTE240M = 7, | 87 BT2020_CL, |
| 109 YCOCG = 8, | 88 YDZDX, |
| 110 BT2020_NCL = 9, | 89 LAST = YDZDX, |
| 111 BT2020_CL = 10, | |
| 112 YDZDX = 11, | |
| 113 | |
| 114 LAST_STANDARD_VALUE = YDZDX, | |
| 115 | |
| 116 // Chrome-specific values start at 1000 | |
| 117 UNKNOWN = 1000, | |
| 118 LAST = UNKNOWN, | |
| 119 }; | 90 }; |
| 120 | 91 |
| 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 { | 92 enum class RangeID : int8_t { |
| 126 // Range is not explicitly specified / unknown. | 93 INVALID, |
| 127 UNSPECIFIED = 0, | |
| 128 | |
| 129 // Limited Rec. 709 color range with RGB values ranging from 16 to 235. | 94 // Limited Rec. 709 color range with RGB values ranging from 16 to 235. |
| 130 LIMITED = 1, | 95 LIMITED, |
| 131 | |
| 132 // Full RGB color range with RGB valees from 0 to 255. | 96 // Full RGB color range with RGB valees from 0 to 255. |
| 133 FULL = 2, | 97 FULL, |
| 134 | |
| 135 // Range is defined by TransferID/MatrixID. | 98 // Range is defined by TransferID/MatrixID. |
| 136 DERIVED = 3, | 99 DERIVED, |
| 137 | 100 LAST = DERIVED, |
| 138 LAST = DERIVED | |
| 139 }; | 101 }; |
| 140 | 102 |
| 141 ColorSpace(); | 103 ColorSpace(); |
| 142 ColorSpace(PrimaryID primaries, TransferID transfer); | 104 ColorSpace(PrimaryID primaries, TransferID transfer); |
| 143 ColorSpace(PrimaryID primaries, | 105 ColorSpace(PrimaryID primaries, |
| 144 TransferID transfer, | 106 TransferID transfer, |
| 145 MatrixID matrix, | 107 MatrixID matrix, |
| 146 RangeID full_range); | 108 RangeID full_range); |
| 147 ColorSpace(const ColorSpace& other); | 109 ColorSpace(const ColorSpace& other); |
| 148 ColorSpace(int primaries, int transfer, int matrix, RangeID full_range); | |
| 149 ~ColorSpace(); | 110 ~ColorSpace(); |
| 150 | 111 |
| 151 static PrimaryID PrimaryIDFromInt(int primary_id); | 112 // Create a color space with primary, transfer and matrix values from the |
| 152 static TransferID TransferIDFromInt(int transfer_id); | 113 // H264 specification (Table E-3 Colour Primaries, E-4 Transfer |
| 153 static MatrixID MatrixIDFromInt(int matrix_id); | 114 // Characteristics, and E-5 Matrix Coefficients in |
| 115 // https://www.itu.int/rec/T-REC-H.264/en). |
| 116 static ColorSpace CreateVideo(int h264_primary, |
| 117 int h264_transfer, |
| 118 int h264_matrix, |
| 119 RangeID range_id); |
| 154 | 120 |
| 155 // Returns true if this is not the default-constructor object. | 121 // Returns true if this is not the default-constructor object. |
| 156 bool IsValid() const; | 122 bool IsValid() const; |
| 157 | 123 |
| 158 static ColorSpace CreateSRGB(); | 124 static ColorSpace CreateSRGB(); |
| 159 static ColorSpace CreateCustom(const SkMatrix44& to_XYZD50, | 125 static ColorSpace CreateCustom(const SkMatrix44& to_XYZD50, |
| 160 const SkColorSpaceTransferFn& fn); | 126 const SkColorSpaceTransferFn& fn); |
| 161 // scRGB is like RGB, but linear and values outside of 0-1 are allowed. | 127 // scRGB is like RGB, but linear and values outside of 0-1 are allowed. |
| 162 // scRGB is normally used with fp16 textures. | 128 // scRGB is normally used with fp16 textures. |
| 163 static ColorSpace CreateSCRGBLinear(); | 129 static ColorSpace CreateSCRGBLinear(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 180 | 146 |
| 181 void GetPrimaryMatrix(SkMatrix44* to_XYZD50) const; | 147 void GetPrimaryMatrix(SkMatrix44* to_XYZD50) const; |
| 182 bool GetTransferFunction(SkColorSpaceTransferFn* fn) const; | 148 bool GetTransferFunction(SkColorSpaceTransferFn* fn) const; |
| 183 bool GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const; | 149 bool GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const; |
| 184 | 150 |
| 185 // For most formats, this is the RGB to YUV matrix. | 151 // For most formats, this is the RGB to YUV matrix. |
| 186 void GetTransferMatrix(SkMatrix44* matrix) const; | 152 void GetTransferMatrix(SkMatrix44* matrix) const; |
| 187 void GetRangeAdjustMatrix(SkMatrix44* matrix) const; | 153 void GetRangeAdjustMatrix(SkMatrix44* matrix) const; |
| 188 | 154 |
| 189 private: | 155 private: |
| 190 PrimaryID primaries_ = PrimaryID::UNSPECIFIED; | 156 PrimaryID primaries_ = PrimaryID::INVALID; |
| 191 TransferID transfer_ = TransferID::UNSPECIFIED; | 157 TransferID transfer_ = TransferID::INVALID; |
| 192 MatrixID matrix_ = MatrixID::UNSPECIFIED; | 158 MatrixID matrix_ = MatrixID::INVALID; |
| 193 RangeID range_ = RangeID::LIMITED; | 159 RangeID range_ = RangeID::INVALID; |
| 194 | 160 |
| 195 // Only used if primaries_ is PrimaryID::CUSTOM. | 161 // Only used if primaries_ is PrimaryID::CUSTOM. |
| 196 float custom_primary_matrix_[9] = {0, 0, 0, 0, 0, 0, 0, 0}; | 162 float custom_primary_matrix_[9] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 197 | 163 |
| 198 // Only used if transfer_ is TransferID::CUSTOM. This array consists of the A | 164 // Only used if transfer_ is TransferID::CUSTOM. This array consists of the A |
| 199 // through G entries of the SkColorSpaceTransferFn structure in alphabetical | 165 // through G entries of the SkColorSpaceTransferFn structure in alphabetical |
| 200 // order. | 166 // order. |
| 201 float custom_transfer_params_[7] = {0, 0, 0, 0, 0, 0, 0}; | 167 float custom_transfer_params_[7] = {0, 0, 0, 0, 0, 0, 0}; |
| 202 | 168 |
| 203 // This is used to look up the ICCProfile from which this ColorSpace was | 169 // This is used to look up the ICCProfile from which this ColorSpace was |
| 204 // created, if possible. | 170 // created, if possible. |
| 205 uint64_t icc_profile_id_ = 0; | 171 uint64_t icc_profile_id_ = 0; |
| 206 sk_sp<SkColorSpace> icc_profile_sk_color_space_; | 172 sk_sp<SkColorSpace> icc_profile_sk_color_space_; |
| 207 | 173 |
| 208 friend class ICCProfile; | 174 friend class ICCProfile; |
| 209 friend class ColorTransform; | 175 friend class ColorTransform; |
| 210 friend class ColorTransformInternal; | 176 friend class ColorTransformInternal; |
| 211 friend class ColorSpaceWin; | 177 friend class ColorSpaceWin; |
| 212 friend struct IPC::ParamTraits<gfx::ColorSpace>; | 178 friend struct IPC::ParamTraits<gfx::ColorSpace>; |
| 213 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace); | 179 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace); |
| 214 }; | 180 }; |
| 215 | 181 |
| 216 } // namespace gfx | 182 } // namespace gfx |
| 217 | 183 |
| 218 #endif // UI_GFX_COLOR_SPACE_H_ | 184 #endif // UI_GFX_COLOR_SPACE_H_ |
| OLD | NEW |