| 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 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "third_party/skia/include/core/SkColorSpace.h" | 12 #include "third_party/skia/include/core/SkColorSpace.h" |
| 13 #include "third_party/skia/include/core/SkData.h" | 13 #include "third_party/skia/include/core/SkData.h" |
| 14 #include "third_party/skia/include/core/SkICC.h" | 14 #include "third_party/skia/include/core/SkICC.h" |
| 15 #include "ui/gfx/icc_profile.h" | 15 #include "ui/gfx/icc_profile.h" |
| 16 #include "ui/gfx/skia_color_space_util.h" | 16 #include "ui/gfx/skia_color_space_util.h" |
| 17 #include "ui/gfx/transform.h" | |
| 18 | 17 |
| 19 namespace gfx { | 18 namespace gfx { |
| 20 | 19 |
| 21 // static | 20 // static |
| 22 ColorSpace ColorSpace::CreateVideo(int video_primary, | 21 ColorSpace ColorSpace::CreateVideo(int video_primary, |
| 23 int video_transfer, | 22 int video_transfer, |
| 24 int video_matrix, | 23 int video_matrix, |
| 25 RangeID range_id) { | 24 RangeID range_id) { |
| 26 // TODO(hubbe): Use more context to decide how to handle UNSPECIFIED values. | 25 // TODO(hubbe): Use more context to decide how to handle UNSPECIFIED values. |
| 27 ColorSpace result; | 26 ColorSpace result; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 icc_profile_sk_color_space_(other.icc_profile_sk_color_space_) { | 180 icc_profile_sk_color_space_(other.icc_profile_sk_color_space_) { |
| 182 if (transfer_ == TransferID::CUSTOM) { | 181 if (transfer_ == TransferID::CUSTOM) { |
| 183 memcpy(custom_transfer_params_, other.custom_transfer_params_, | 182 memcpy(custom_transfer_params_, other.custom_transfer_params_, |
| 184 sizeof(custom_transfer_params_)); | 183 sizeof(custom_transfer_params_)); |
| 185 } | 184 } |
| 186 if (primaries_ == PrimaryID::CUSTOM) { | 185 if (primaries_ == PrimaryID::CUSTOM) { |
| 187 memcpy(custom_primary_matrix_, other.custom_primary_matrix_, | 186 memcpy(custom_primary_matrix_, other.custom_primary_matrix_, |
| 188 sizeof(custom_primary_matrix_)); | 187 sizeof(custom_primary_matrix_)); |
| 189 } | 188 } |
| 190 } | 189 } |
| 190 |
| 191 ColorSpace::ColorSpace(ColorSpace&& other) = default; |
| 192 |
| 193 ColorSpace& ColorSpace::operator=(const ColorSpace& other) = default; |
| 194 |
| 191 ColorSpace::~ColorSpace() = default; | 195 ColorSpace::~ColorSpace() = default; |
| 192 | 196 |
| 193 bool ColorSpace::IsValid() const { | 197 bool ColorSpace::IsValid() const { |
| 194 return primaries_ != PrimaryID::INVALID && transfer_ != TransferID::INVALID && | 198 return primaries_ != PrimaryID::INVALID && transfer_ != TransferID::INVALID && |
| 195 matrix_ != MatrixID::INVALID && range_ != RangeID::INVALID; | 199 matrix_ != MatrixID::INVALID && range_ != RangeID::INVALID; |
| 196 } | 200 } |
| 197 | 201 |
| 198 // static | 202 // static |
| 199 ColorSpace ColorSpace::CreateSRGB() { | 203 ColorSpace ColorSpace::CreateSRGB() { |
| 200 return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, | 204 return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 memcmp(custom_transfer_params_, other.custom_transfer_params_, | 329 memcmp(custom_transfer_params_, other.custom_transfer_params_, |
| 326 sizeof(custom_transfer_params_)); | 330 sizeof(custom_transfer_params_)); |
| 327 if (transfer_result < 0) | 331 if (transfer_result < 0) |
| 328 return true; | 332 return true; |
| 329 if (transfer_result > 0) | 333 if (transfer_result > 0) |
| 330 return false; | 334 return false; |
| 331 } | 335 } |
| 332 return false; | 336 return false; |
| 333 } | 337 } |
| 334 | 338 |
| 339 size_t ColorSpace::GetHash() const { |
| 340 size_t result = (static_cast<size_t>(primaries_) << 0) | |
| 341 (static_cast<size_t>(transfer_) << 8) | |
| 342 (static_cast<size_t>(matrix_) << 16) | |
| 343 (static_cast<size_t>(range_) << 24); |
| 344 if (primaries_ == PrimaryID::CUSTOM) { |
| 345 const uint32_t* params = |
| 346 reinterpret_cast<const uint32_t*>(custom_primary_matrix_); |
| 347 result ^= params[0]; |
| 348 result ^= params[4]; |
| 349 result ^= params[8]; |
| 350 } |
| 351 if (transfer_ == TransferID::CUSTOM) { |
| 352 const uint32_t* params = |
| 353 reinterpret_cast<const uint32_t*>(custom_transfer_params_); |
| 354 result ^= params[3]; |
| 355 result ^= params[6]; |
| 356 } |
| 357 return result; |
| 358 } |
| 359 |
| 335 std::string ColorSpace::ToString() const { | 360 std::string ColorSpace::ToString() const { |
| 336 std::stringstream ss; | 361 std::stringstream ss; |
| 337 ss << "{primaries:"; | 362 ss << "{primaries:"; |
| 338 if (primaries_ == PrimaryID::CUSTOM) { | 363 if (primaries_ == PrimaryID::CUSTOM) { |
| 339 ss << "["; | 364 ss << "["; |
| 340 for (size_t i = 0; i < 3; ++i) { | 365 for (size_t i = 0; i < 3; ++i) { |
| 341 ss << "["; | 366 ss << "["; |
| 342 for (size_t j = 0; j < 3; ++j) { | 367 for (size_t j = 0; j < 3; ++j) { |
| 343 ss << custom_primary_matrix_[3 * i + j]; | 368 ss << custom_primary_matrix_[3 * i + j]; |
| 344 ss << ","; | 369 ss << ","; |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); | 837 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); |
| 813 break; | 838 break; |
| 814 } | 839 } |
| 815 } | 840 } |
| 816 | 841 |
| 817 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) { | 842 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) { |
| 818 return out << color_space.ToString(); | 843 return out << color_space.ToString(); |
| 819 } | 844 } |
| 820 | 845 |
| 821 } // namespace gfx | 846 } // namespace gfx |
| OLD | NEW |