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 #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 "third_party/skia/include/core/SkColorSpace.h" | |
| 11 #include "ui/gfx/icc_profile.h" | 12 #include "ui/gfx/icc_profile.h" |
| 12 | 13 |
| 13 namespace gfx { | 14 namespace gfx { |
| 14 | 15 |
| 15 ColorSpace::ColorSpace() { | 16 ColorSpace::ColorSpace() { |
| 16 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); | 17 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); |
| 17 } | 18 } |
| 18 | 19 |
| 19 ColorSpace::ColorSpace(PrimaryID primaries, | 20 ColorSpace::ColorSpace(PrimaryID primaries, |
| 20 TransferID transfer, | 21 TransferID transfer, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 } | 54 } |
| 54 | 55 |
| 55 // static | 56 // static |
| 56 ColorSpace ColorSpace::CreateREC709() { | 57 ColorSpace ColorSpace::CreateREC709() { |
| 57 return ColorSpace(PrimaryID::BT709, TransferID::BT709, MatrixID::BT709, | 58 return ColorSpace(PrimaryID::BT709, TransferID::BT709, MatrixID::BT709, |
| 58 RangeID::LIMITED); | 59 RangeID::LIMITED); |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool ColorSpace::operator==(const ColorSpace& other) const { | 62 bool ColorSpace::operator==(const ColorSpace& other) const { |
| 62 return primaries_ == other.primaries_ && transfer_ == other.transfer_ && | 63 return primaries_ == other.primaries_ && transfer_ == other.transfer_ && |
| 63 matrix_ == other.matrix_ && range_ == other.range_; | 64 matrix_ == other.matrix_ && range_ == other.range_ && |
| 65 !memcmp(custom_primary_matrix_, other.custom_primary_matrix_, | |
|
hubbe
2016/09/19 19:21:27
We should only do this if primaries_ == CUSTOM I t
ccameron
2016/09/19 22:23:15
Done.
| |
| 66 sizeof(custom_primary_matrix_)); | |
| 64 } | 67 } |
| 65 | 68 |
| 66 bool ColorSpace::operator!=(const ColorSpace& other) const { | 69 bool ColorSpace::operator!=(const ColorSpace& other) const { |
| 67 return !(*this == other); | 70 return !(*this == other); |
| 68 } | 71 } |
| 69 | 72 |
| 70 bool ColorSpace::operator<(const ColorSpace& other) const { | 73 bool ColorSpace::operator<(const ColorSpace& other) const { |
| 71 if (primaries_ < other.primaries_) | 74 if (primaries_ < other.primaries_) |
| 72 return true; | 75 return true; |
| 73 if (primaries_ > other.primaries_) | 76 if (primaries_ > other.primaries_) |
| 74 return false; | 77 return false; |
| 75 if (transfer_ < other.transfer_) | 78 if (transfer_ < other.transfer_) |
| 76 return true; | 79 return true; |
| 77 if (transfer_ > other.transfer_) | 80 if (transfer_ > other.transfer_) |
| 78 return false; | 81 return false; |
| 79 if (matrix_ < other.matrix_) | 82 if (matrix_ < other.matrix_) |
| 80 return true; | 83 return true; |
| 81 if (matrix_ > other.matrix_) | 84 if (matrix_ > other.matrix_) |
| 82 return false; | 85 return false; |
| 83 if (range_ < other.range_) | 86 if (range_ < other.range_) |
| 84 return true; | 87 return true; |
| 85 if (range_ > other.range_) | 88 if (range_ > other.range_) |
| 89 return false; | |
| 90 int primary_result = | |
| 91 memcmp(custom_primary_matrix_, other.custom_primary_matrix_, | |
| 92 sizeof(custom_primary_matrix_)); | |
| 93 if (primary_result < 0) | |
| 86 return true; | 94 return true; |
| 87 | 95 if (primary_result > 0) |
| 88 // TODO(hubbe): For "CUSTOM" primaries or tranfer functions, compare their | 96 return false; |
| 89 // coefficients here | |
| 90 | 97 |
| 91 return false; | 98 return false; |
| 92 } | 99 } |
| 93 | 100 |
| 101 sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const { | |
| 102 // TODO(crbug.com/634102): Make this conversion more robust. | |
| 103 std::vector<char> icc_data = | |
| 104 gfx::ICCProfile::FromColorSpace(*this).GetData(); | |
|
hubbe
2016/09/19 19:21:27
1) Shouldn't we implement FromColorSpace() first?
ccameron
2016/09/19 22:23:15
This is to un-block work on rasterization, and ras
hubbe
2016/09/19 22:53:19
Then maybe remove the DCHECK and tell callers to e
| |
| 105 sk_sp<SkColorSpace> result = | |
| 106 SkColorSpace::NewICC(icc_data.data(), icc_data.size()); | |
| 107 DCHECK(result); | |
| 108 return result; | |
| 109 } | |
| 110 | |
| 94 } // namespace gfx | 111 } // namespace gfx |
| OLD | NEW |