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" |
| (...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 RESERVED0 = 1000, |
| 32 // Colour Primaries in https://www.itu.int/rec/T-REC-H.264/en). | 32 FIRST_VIDEO_VALUE = RESERVED0, |
| 33 RESERVED0 = 0, | 33 BT709 = 1001, |
| 34 BT709 = 1, | 34 UNSPECIFIED = 1002, |
| 35 UNSPECIFIED = 2, | 35 RESERVED = 1003, |
| 36 RESERVED = 3, | 36 BT470M = 1004, |
| 37 BT470M = 4, | 37 BT470BG = 1005, |
| 38 BT470BG = 5, | 38 SMPTE170M = 1006, |
| 39 SMPTE170M = 6, | 39 SMPTE240M = 1007, |
| 40 SMPTE240M = 7, | 40 FILM = 1008, |
| 41 FILM = 8, | 41 BT2020 = 1009, |
| 42 BT2020 = 9, | 42 SMPTEST428_1 = 1010, |
| 43 SMPTEST428_1 = 10, | 43 SMPTEST431_2 = 1011, |
| 44 SMPTEST431_2 = 11, | 44 SMPTEST432_1 = 1012, |
| 45 SMPTEST432_1 = 12, | 45 LAST_VIDEO_VALUE = SMPTEST432_1, |
| 46 | 46 |
| 47 LAST_STANDARD_VALUE = SMPTEST432_1, | |
| 48 | |
| 49 // Chrome-specific values start at 1000. | |
| 50 UNKNOWN = 1000, | |
| 51 XYZ_D50, | 47 XYZ_D50, |
| 52 ADOBE_RGB, | 48 ADOBE_RGB, |
| 53 CUSTOM, | 49 CUSTOM, |
| 54 LAST = CUSTOM | 50 INVALID, |
| 51 LAST = INVALID | |
| 55 }; | 52 }; |
| 56 | 53 |
| 57 enum class TransferID : uint16_t { | 54 enum class TransferID : uint16_t { |
| 58 // The first 0-255 values should match the H264 specification (see Table E-4 | 55 RESERVED0 = 1000, |
|
hubbe
2017/02/16 05:02:39
Actually, this is really weird to me.
Either we em
| |
| 59 // Transfer Characteristics in https://www.itu.int/rec/T-REC-H.264/en). | 56 FIRST_VIDEO_VALUE = RESERVED0, |
| 60 RESERVED0 = 0, | 57 BT709 = 1001, |
| 61 BT709 = 1, | 58 UNSPECIFIED = 1002, |
| 62 UNSPECIFIED = 2, | 59 RESERVED = 1003, |
| 63 RESERVED = 3, | 60 GAMMA22 = 1004, |
| 64 GAMMA22 = 4, | 61 GAMMA28 = 1005, |
| 65 GAMMA28 = 5, | 62 SMPTE170M = 1006, |
| 66 SMPTE170M = 6, | 63 SMPTE240M = 1007, |
| 67 SMPTE240M = 7, | 64 LINEAR = 1008, |
| 68 LINEAR = 8, | 65 LOG = 1009, |
| 69 LOG = 9, | 66 LOG_SQRT = 1010, |
| 70 LOG_SQRT = 10, | 67 IEC61966_2_4 = 1011, |
| 71 IEC61966_2_4 = 11, | 68 BT1361_ECG = 1012, |
| 72 BT1361_ECG = 12, | 69 IEC61966_2_1 = 1013, |
| 73 IEC61966_2_1 = 13, | 70 BT2020_10 = 1014, |
| 74 BT2020_10 = 14, | 71 BT2020_12 = 1015, |
| 75 BT2020_12 = 15, | 72 SMPTEST2084 = 1016, |
| 76 SMPTEST2084 = 16, | 73 SMPTEST428_1 = 1017, |
| 77 SMPTEST428_1 = 17, | 74 ARIB_STD_B67 = 1018, // AKA hybrid-log gamma, HLG. |
| 78 ARIB_STD_B67 = 18, // AKA hybrid-log gamma, HLG. | 75 LAST_VIDEO_VALUE = ARIB_STD_B67, |
| 79 | 76 |
| 80 LAST_STANDARD_VALUE = SMPTEST428_1, | |
| 81 | |
| 82 // Chrome-specific values start at 1000. | |
| 83 UNKNOWN = 1000, | |
| 84 GAMMA24, | 77 GAMMA24, |
| 85 | 78 |
| 86 // This is an ad-hoc transfer function that decodes SMPTE 2084 content | 79 // 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 | 80 // into a 0-1 range more or less suitable for viewing on a non-hdr |
| 88 // display. | 81 // display. |
| 89 SMPTEST2084_NON_HDR, | 82 SMPTEST2084_NON_HDR, |
| 90 | 83 |
| 91 // Like LINEAR, but intended for HDR. (can go outside of 0-1) | 84 // Like LINEAR, but intended for HDR. (can go outside of 0-1) |
| 92 LINEAR_HDR, | 85 LINEAR_HDR, |
| 93 // TODO(hubbe): Need to store an approximation of the gamma function(s). | |
| 94 CUSTOM, | 86 CUSTOM, |
| 95 LAST = CUSTOM, | 87 INVALID, |
| 88 LAST = INVALID, | |
| 96 }; | 89 }; |
| 97 | 90 |
| 98 enum class MatrixID : int16_t { | 91 enum class MatrixID : int16_t { |
| 99 // The first 0-255 values should match the H264 specification (see Table E-5 | 92 RGB = 1000, |
| 100 // Matrix Coefficients in https://www.itu.int/rec/T-REC-H.264/en). | 93 FIRST_VIDEO_VALUE = RGB, |
| 101 RGB = 0, | 94 BT709 = 1001, |
| 102 BT709 = 1, | 95 UNSPECIFIED = 1002, |
| 103 UNSPECIFIED = 2, | 96 RESERVED = 1003, |
| 104 RESERVED = 3, | 97 FCC = 1004, |
| 105 FCC = 4, | 98 BT470BG = 1005, |
| 106 BT470BG = 5, | 99 SMPTE170M = 1006, |
| 107 SMPTE170M = 6, | 100 SMPTE240M = 1007, |
| 108 SMPTE240M = 7, | 101 YCOCG = 1008, |
| 109 YCOCG = 8, | 102 BT2020_NCL = 1009, |
| 110 BT2020_NCL = 9, | 103 BT2020_CL = 1010, |
| 111 BT2020_CL = 10, | 104 YDZDX = 1011, |
| 112 YDZDX = 11, | 105 LAST_VIDEO_VALUE = YDZDX, |
| 113 | 106 INVALID, |
| 114 LAST_STANDARD_VALUE = YDZDX, | 107 LAST = INVALID, |
| 115 | |
| 116 // Chrome-specific values start at 1000 | |
| 117 UNKNOWN = 1000, | |
| 118 LAST = UNKNOWN, | |
| 119 }; | 108 }; |
| 120 | 109 |
| 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 { | 110 enum class RangeID : int8_t { |
| 126 // Range is not explicitly specified / unknown. | 111 // Range is not explicitly specified / unknown. |
| 127 UNSPECIFIED = 0, | 112 UNSPECIFIED = 0, |
| 128 | 113 |
| 129 // Limited Rec. 709 color range with RGB values ranging from 16 to 235. | 114 // Limited Rec. 709 color range with RGB values ranging from 16 to 235. |
| 130 LIMITED = 1, | 115 LIMITED = 1, |
| 131 | 116 |
| 132 // Full RGB color range with RGB valees from 0 to 255. | 117 // Full RGB color range with RGB valees from 0 to 255. |
| 133 FULL = 2, | 118 FULL = 2, |
| 134 | 119 |
| 135 // Range is defined by TransferID/MatrixID. | 120 // Range is defined by TransferID/MatrixID. |
| 136 DERIVED = 3, | 121 DERIVED = 3, |
| 137 | 122 |
| 138 LAST = DERIVED | 123 INVALID, |
| 124 LAST = INVALID | |
| 139 }; | 125 }; |
| 140 | 126 |
| 141 ColorSpace(); | 127 ColorSpace(); |
| 142 ColorSpace(PrimaryID primaries, TransferID transfer); | 128 ColorSpace(PrimaryID primaries, TransferID transfer); |
| 143 ColorSpace(PrimaryID primaries, | 129 ColorSpace(PrimaryID primaries, |
| 144 TransferID transfer, | 130 TransferID transfer, |
| 145 MatrixID matrix, | 131 MatrixID matrix, |
| 146 RangeID full_range); | 132 RangeID full_range); |
| 147 ColorSpace(const ColorSpace& other); | 133 ColorSpace(const ColorSpace& other); |
| 148 ColorSpace(int primaries, int transfer, int matrix, RangeID full_range); | |
| 149 ~ColorSpace(); | 134 ~ColorSpace(); |
| 150 | 135 |
| 151 static PrimaryID PrimaryIDFromInt(int primary_id); | 136 // Create a color space with primary, transfer and matrix values from the |
| 152 static TransferID TransferIDFromInt(int transfer_id); | 137 // H264 specification (Table E-3 Colour Primaries, E-4 Transfer |
| 153 static MatrixID MatrixIDFromInt(int matrix_id); | 138 // Characteristics, and E-5 Matrix Coefficients in |
| 139 // https://www.itu.int/rec/T-REC-H.264/en). | |
| 140 static ColorSpace CreateVideo(int h264_primary, | |
| 141 int h264_transfer, | |
| 142 int h264_matrix, | |
| 143 RangeID range_id); | |
| 144 // Retrieve the H264 parameters. | |
| 145 void GetVideoParameters(int* h264_primary, | |
|
hubbe
2017/02/16 05:02:39
I'd rather have four individual accessors.
| |
| 146 int* h264_transfer, | |
| 147 int* h264_matrix, | |
| 148 bool* full_range); | |
| 154 | 149 |
| 155 // Returns true if this is not the default-constructor object. | 150 // Returns true if this is not the default-constructor object. |
| 156 bool IsValid() const; | 151 bool IsValid() const; |
| 157 | 152 |
| 158 static ColorSpace CreateSRGB(); | 153 static ColorSpace CreateSRGB(); |
| 159 static ColorSpace CreateCustom(const SkMatrix44& to_XYZD50, | 154 static ColorSpace CreateCustom(const SkMatrix44& to_XYZD50, |
| 160 const SkColorSpaceTransferFn& fn); | 155 const SkColorSpaceTransferFn& fn); |
| 161 // scRGB is like RGB, but linear and values outside of 0-1 are allowed. | 156 // scRGB is like RGB, but linear and values outside of 0-1 are allowed. |
| 162 // scRGB is normally used with fp16 textures. | 157 // scRGB is normally used with fp16 textures. |
| 163 static ColorSpace CreateSCRGBLinear(); | 158 static ColorSpace CreateSCRGBLinear(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 180 | 175 |
| 181 void GetPrimaryMatrix(SkMatrix44* to_XYZD50) const; | 176 void GetPrimaryMatrix(SkMatrix44* to_XYZD50) const; |
| 182 bool GetTransferFunction(SkColorSpaceTransferFn* fn) const; | 177 bool GetTransferFunction(SkColorSpaceTransferFn* fn) const; |
| 183 bool GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const; | 178 bool GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const; |
| 184 | 179 |
| 185 // For most formats, this is the RGB to YUV matrix. | 180 // For most formats, this is the RGB to YUV matrix. |
| 186 void GetTransferMatrix(SkMatrix44* matrix) const; | 181 void GetTransferMatrix(SkMatrix44* matrix) const; |
| 187 void GetRangeAdjustMatrix(SkMatrix44* matrix) const; | 182 void GetRangeAdjustMatrix(SkMatrix44* matrix) const; |
| 188 | 183 |
| 189 private: | 184 private: |
| 190 PrimaryID primaries_ = PrimaryID::UNSPECIFIED; | 185 PrimaryID primaries_ = PrimaryID::INVALID; |
| 191 TransferID transfer_ = TransferID::UNSPECIFIED; | 186 TransferID transfer_ = TransferID::INVALID; |
| 192 MatrixID matrix_ = MatrixID::UNSPECIFIED; | 187 MatrixID matrix_ = MatrixID::INVALID; |
| 193 RangeID range_ = RangeID::LIMITED; | 188 RangeID range_ = RangeID::INVALID; |
| 194 | 189 |
| 195 // Only used if primaries_ is PrimaryID::CUSTOM. | 190 // Only used if primaries_ is PrimaryID::CUSTOM. |
| 196 float custom_primary_matrix_[9] = {0, 0, 0, 0, 0, 0, 0, 0}; | 191 float custom_primary_matrix_[9] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 197 | 192 |
| 198 // Only used if transfer_ is TransferID::CUSTOM. This array consists of the A | 193 // Only used if transfer_ is TransferID::CUSTOM. This array consists of the A |
| 199 // through G entries of the SkColorSpaceTransferFn structure in alphabetical | 194 // through G entries of the SkColorSpaceTransferFn structure in alphabetical |
| 200 // order. | 195 // order. |
| 201 float custom_transfer_params_[7] = {0, 0, 0, 0, 0, 0, 0}; | 196 float custom_transfer_params_[7] = {0, 0, 0, 0, 0, 0, 0}; |
| 202 | 197 |
| 203 // This is used to look up the ICCProfile from which this ColorSpace was | 198 // This is used to look up the ICCProfile from which this ColorSpace was |
| 204 // created, if possible. | 199 // created, if possible. |
| 205 uint64_t icc_profile_id_ = 0; | 200 uint64_t icc_profile_id_ = 0; |
| 206 sk_sp<SkColorSpace> icc_profile_sk_color_space_; | 201 sk_sp<SkColorSpace> icc_profile_sk_color_space_; |
| 207 | 202 |
| 208 friend class ICCProfile; | 203 friend class ICCProfile; |
| 209 friend class ColorTransform; | 204 friend class ColorTransform; |
| 210 friend class ColorTransformInternal; | 205 friend class ColorTransformInternal; |
| 211 friend class ColorSpaceWin; | 206 friend class ColorSpaceWin; |
| 212 friend struct IPC::ParamTraits<gfx::ColorSpace>; | 207 friend struct IPC::ParamTraits<gfx::ColorSpace>; |
| 213 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace); | 208 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace); |
| 214 }; | 209 }; |
| 215 | 210 |
| 216 } // namespace gfx | 211 } // namespace gfx |
| 217 | 212 |
| 218 #endif // UI_GFX_COLOR_SPACE_H_ | 213 #endif // UI_GFX_COLOR_SPACE_H_ |
| OLD | NEW |