Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: ui/gfx/color_space.cc

Issue 2738713003: color: Ensure that VideoResourceUpdater give consistent colors (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/color_space.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
9 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
10 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
11 #include "third_party/skia/include/core/SkColorSpace.h" 12 #include "third_party/skia/include/core/SkColorSpace.h"
12 #include "third_party/skia/include/core/SkData.h" 13 #include "third_party/skia/include/core/SkData.h"
13 #include "third_party/skia/include/core/SkICC.h" 14 #include "third_party/skia/include/core/SkICC.h"
14 #include "ui/gfx/icc_profile.h" 15 #include "ui/gfx/icc_profile.h"
15 #include "ui/gfx/skia_color_space_util.h" 16 #include "ui/gfx/skia_color_space_util.h"
16 #include "ui/gfx/transform.h" 17 #include "ui/gfx/transform.h"
17 18
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 memcmp(custom_transfer_params_, other.custom_transfer_params_, 318 memcmp(custom_transfer_params_, other.custom_transfer_params_,
318 sizeof(custom_transfer_params_)); 319 sizeof(custom_transfer_params_));
319 if (transfer_result < 0) 320 if (transfer_result < 0)
320 return true; 321 return true;
321 if (transfer_result > 0) 322 if (transfer_result > 0)
322 return false; 323 return false;
323 } 324 }
324 return false; 325 return false;
325 } 326 }
326 327
328 std::string ColorSpace::ToString() const {
329 std::stringstream ss;
330 ss << "{primaries:";
331 if (primaries_ == PrimaryID::CUSTOM) {
332 ss << "[";
333 for (size_t i = 0; i < 3; ++i) {
334 ss << "[";
335 for (size_t j = 0; j < 3; ++j) {
336 ss << custom_primary_matrix_[3 * i + j];
337 ss << ",";
338 }
339 ss << "],";
340 }
341 ss << "]";
342 } else {
343 ss << static_cast<int>(primaries_);
344 }
345 ss << ", transfer:";
346 if (transfer_ == TransferID::CUSTOM) {
347 ss << "[";
348 for (size_t i = 0; i < 7; ++i)
349 ss << custom_transfer_params_[i];
350 ss << "]";
351 } else {
352 ss << static_cast<int>(transfer_);
353 }
354 ss << ", matrix:" << static_cast<int>(matrix_);
355 ss << ", range:" << static_cast<int>(range_);
356 ss << ", icc_profile_id:" << icc_profile_id_;
357 ss << "}";
358 return ss.str();
359 }
360
361 ColorSpace ColorSpace::GetAsFullRangeRGB() const {
362 ColorSpace result(*this);
363 if (!IsValid())
364 return result;
365 result.matrix_ = MatrixID::RGB;
366 result.range_ = RangeID::FULL;
367 return result;
368 }
369
327 sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const { 370 sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const {
328 // If we got a specific SkColorSpace from the ICCProfile that this color space 371 // If we got a specific SkColorSpace from the ICCProfile that this color space
329 // was created from, use that. 372 // was created from, use that.
330 if (icc_profile_sk_color_space_) 373 if (icc_profile_sk_color_space_)
331 return icc_profile_sk_color_space_; 374 return icc_profile_sk_color_space_;
332 375
333 // Unspecified color spaces correspond to the null SkColorSpace. 376 // Unspecified color spaces correspond to the null SkColorSpace.
334 if (!IsValid()) 377 if (!IsValid())
335 return nullptr; 378 return nullptr;
336 379
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 sk_sp<SkColorSpace> result = SkColorSpace::MakeRGB( 442 sk_sp<SkColorSpace> result = SkColorSpace::MakeRGB(
400 tr_fn, primaries, SkColorSpace::kNonLinearBlending_ColorSpaceFlag); 443 tr_fn, primaries, SkColorSpace::kNonLinearBlending_ColorSpaceFlag);
401 if (!result) { 444 if (!result) {
402 DLOG(ERROR) << "Failed to create nonlinearly blended SkColorSpace"; 445 DLOG(ERROR) << "Failed to create nonlinearly blended SkColorSpace";
403 CreateSRGB().GetTransferFunction(&tr_fn); 446 CreateSRGB().GetTransferFunction(&tr_fn);
404 } 447 }
405 return result; 448 return result;
406 } 449 }
407 450
408 bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const { 451 bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const {
409 if (!IsValid()) 452 if (!IsValid()) {
453 DLOG(ERROR) << "Cannot fetch ICCProfile for invalid space.";
410 return false; 454 return false;
455 }
456 if (matrix_ != MatrixID::RGB) {
457 DLOG(ERROR) << "Not creating non-RGB ICCProfile";
458 return false;
459 }
460 if (range_ != RangeID::FULL) {
461 DLOG(ERROR) << "Not creating non-full-range ICCProfile";
462 return false;
463 }
411 464
412 // If this was created from an ICC profile, retrieve that exact profile. 465 // If this was created from an ICC profile, retrieve that exact profile.
413 ICCProfile result; 466 ICCProfile result;
414 if (ICCProfile::FromId(icc_profile_id_, false, icc_profile)) 467 if (ICCProfile::FromId(icc_profile_id_, false, icc_profile))
415 return true; 468 return true;
416 469
417 // Otherwise, construct an ICC profile based on the best approximated 470 // Otherwise, construct an ICC profile based on the best approximated
418 // primaries and matrix. 471 // primaries and matrix.
419 SkMatrix44 to_XYZD50_matrix; 472 SkMatrix44 to_XYZD50_matrix;
420 GetPrimaryMatrix(&to_XYZD50_matrix); 473 GetPrimaryMatrix(&to_XYZD50_matrix);
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 case MatrixID::SMPTE240M: 829 case MatrixID::SMPTE240M:
777 case MatrixID::BT2020_NCL: 830 case MatrixID::BT2020_NCL:
778 case MatrixID::BT2020_CL: 831 case MatrixID::BT2020_CL:
779 case MatrixID::YDZDX: 832 case MatrixID::YDZDX:
780 matrix->setScale(255.0f/219.0f, 255.0f/224.0f, 255.0f/224.0f); 833 matrix->setScale(255.0f/219.0f, 255.0f/224.0f, 255.0f/224.0f);
781 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); 834 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f);
782 break; 835 break;
783 } 836 }
784 } 837 }
785 838
839 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) {
840 return out << color_space.ToString();
841 }
842
786 } // namespace gfx 843 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/color_space.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698