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 #include "ui/gfx/color_space.h" | 5 #include "ui/gfx/color_space.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "ui/gfx/icc_profile.h" | 11 #include "ui/gfx/icc_profile.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 | 14 |
| 15 ColorSpace::PrimaryID ColorSpace::PrimaryIDFromInt(int primary_id) { |
| 16 if (primary_id < 0 || primary_id > static_cast<int>(PrimaryID::LAST)) |
| 17 return PrimaryID::UNKNOWN; |
| 18 if (primary_id > static_cast<int>(PrimaryID::LAST_STANDARD_VALUE) && |
| 19 primary_id < 1000) |
| 20 return PrimaryID::UNKNOWN; |
| 21 return static_cast<PrimaryID>(primary_id); |
| 22 } |
| 23 |
| 24 ColorSpace::TransferID ColorSpace::TransferIDFromInt(int transfer_id) { |
| 25 if (transfer_id < 0 || transfer_id > static_cast<int>(TransferID::LAST)) |
| 26 return TransferID::UNKNOWN; |
| 27 if (transfer_id > static_cast<int>(TransferID::LAST_STANDARD_VALUE) && |
| 28 transfer_id < 1000) |
| 29 return TransferID::UNKNOWN; |
| 30 return static_cast<TransferID>(transfer_id); |
| 31 } |
| 32 |
| 33 ColorSpace::MatrixID ColorSpace::MatrixIDFromInt(int matrix_id) { |
| 34 if (matrix_id < 0 || matrix_id > static_cast<int>(MatrixID::LAST)) |
| 35 return MatrixID::UNKNOWN; |
| 36 if (matrix_id > static_cast<int>(MatrixID::LAST_STANDARD_VALUE) && |
| 37 matrix_id < 1000) |
| 38 return MatrixID::UNKNOWN; |
| 39 return static_cast<MatrixID>(matrix_id); |
| 40 } |
| 41 |
15 ColorSpace::ColorSpace() { | 42 ColorSpace::ColorSpace() { |
16 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); | 43 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); |
17 } | 44 } |
18 | 45 |
19 ColorSpace::ColorSpace(PrimaryID primaries, | 46 ColorSpace::ColorSpace(PrimaryID primaries, |
20 TransferID transfer, | 47 TransferID transfer, |
21 MatrixID matrix, | 48 MatrixID matrix, |
22 RangeID range) | 49 RangeID range) |
23 : primaries_(primaries), | 50 : primaries_(primaries), |
24 transfer_(transfer), | 51 transfer_(transfer), |
25 matrix_(matrix), | 52 matrix_(matrix), |
26 range_(range) { | 53 range_(range) { |
27 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); | 54 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); |
28 // TODO: Set profile_id_ | 55 // TODO: Set profile_id_ |
29 } | 56 } |
30 | 57 |
| 58 ColorSpace::ColorSpace(int primaries, int transfer, int matrix, RangeID range) |
| 59 : primaries_(PrimaryIDFromInt(primaries)), |
| 60 transfer_(TransferIDFromInt(transfer)), |
| 61 matrix_(MatrixIDFromInt(matrix)), |
| 62 range_(range) { |
| 63 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); |
| 64 // TODO: Set profile_id_ |
| 65 } |
| 66 |
31 // static | 67 // static |
32 ColorSpace ColorSpace::CreateSRGB() { | 68 ColorSpace ColorSpace::CreateSRGB() { |
33 return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, | 69 return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, |
34 RangeID::FULL); | 70 RangeID::FULL); |
35 } | 71 } |
36 | 72 |
37 // Static | 73 // Static |
38 ColorSpace ColorSpace::CreateXYZD50() { | 74 ColorSpace ColorSpace::CreateXYZD50() { |
39 return ColorSpace(PrimaryID::XYZ_D50, TransferID::LINEAR, MatrixID::RGB, | 75 return ColorSpace(PrimaryID::XYZ_D50, TransferID::LINEAR, MatrixID::RGB, |
40 RangeID::FULL); | 76 RangeID::FULL); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 if (range_ > other.range_) | 121 if (range_ > other.range_) |
86 return true; | 122 return true; |
87 | 123 |
88 // TODO(hubbe): For "CUSTOM" primaries or tranfer functions, compare their | 124 // TODO(hubbe): For "CUSTOM" primaries or tranfer functions, compare their |
89 // coefficients here | 125 // coefficients here |
90 | 126 |
91 return false; | 127 return false; |
92 } | 128 } |
93 | 129 |
94 } // namespace gfx | 130 } // namespace gfx |
OLD | NEW |