| Index: ui/gfx/color_space.cc
|
| diff --git a/ui/gfx/color_space.cc b/ui/gfx/color_space.cc
|
| index 0f5a42b601841ca529d42c456df504512c708914..f526b0ac4715f39684763b6259a3a15b6ecde046 100644
|
| --- a/ui/gfx/color_space.cc
|
| +++ b/ui/gfx/color_space.cc
|
| @@ -15,31 +15,77 @@
|
|
|
| namespace gfx {
|
|
|
| -ColorSpace::PrimaryID ColorSpace::PrimaryIDFromInt(int primary_id) {
|
| - if (primary_id < 0 || primary_id > static_cast<int>(PrimaryID::LAST))
|
| - return PrimaryID::UNKNOWN;
|
| - if (primary_id > static_cast<int>(PrimaryID::LAST_STANDARD_VALUE) &&
|
| - primary_id < 1000)
|
| - return PrimaryID::UNKNOWN;
|
| - return static_cast<PrimaryID>(primary_id);
|
| -}
|
| +// static
|
| +ColorSpace ColorSpace::CreateVideo(int video_primary,
|
| + int video_transfer,
|
| + int video_matrix,
|
| + RangeID range_id) {
|
| + ColorSpace result;
|
| +
|
| + int first_primary = static_cast<int>(PrimaryID::FIRST_VIDEO_VALUE);
|
| + int last_primary = static_cast<int>(PrimaryID::LAST_VIDEO_VALUE);
|
| + if (video_primary < 0 || video_primary > last_primary - first_primary) {
|
| + result.primaries_ = PrimaryID::BT709;
|
| + } else {
|
| + result.primaries_ = static_cast<PrimaryID>(video_primary + first_primary);
|
| + }
|
| +
|
| + int first_transfer = static_cast<int>(TransferID::FIRST_VIDEO_VALUE);
|
| + int last_transfer = static_cast<int>(TransferID::LAST_VIDEO_VALUE);
|
| + if (video_transfer < 0 || video_transfer > last_transfer - first_transfer) {
|
| + result.transfer_ = TransferID::BT709;
|
| + } else {
|
| + result.transfer_ = static_cast<TransferID>(video_transfer + first_transfer);
|
| + }
|
| +
|
| + int first_matrix = static_cast<int>(MatrixID::FIRST_VIDEO_VALUE);
|
| + int last_matrix = static_cast<int>(MatrixID::LAST_VIDEO_VALUE);
|
| + if (video_matrix < 0 || video_matrix > last_matrix - first_matrix) {
|
| + result.matrix_ = MatrixID::BT709;
|
| + } else {
|
| + result.matrix_ = static_cast<MatrixID>(video_matrix + first_matrix);
|
| + }
|
|
|
| -ColorSpace::TransferID ColorSpace::TransferIDFromInt(int transfer_id) {
|
| - if (transfer_id < 0 || transfer_id > static_cast<int>(TransferID::LAST))
|
| - return TransferID::UNKNOWN;
|
| - if (transfer_id > static_cast<int>(TransferID::LAST_STANDARD_VALUE) &&
|
| - transfer_id < 1000)
|
| - return TransferID::UNKNOWN;
|
| - return static_cast<TransferID>(transfer_id);
|
| + result.range_ = range_id;
|
| + return result;
|
| }
|
|
|
| -ColorSpace::MatrixID ColorSpace::MatrixIDFromInt(int matrix_id) {
|
| - if (matrix_id < 0 || matrix_id > static_cast<int>(MatrixID::LAST))
|
| - return MatrixID::UNKNOWN;
|
| - if (matrix_id > static_cast<int>(MatrixID::LAST_STANDARD_VALUE) &&
|
| - matrix_id < 1000)
|
| - return MatrixID::UNKNOWN;
|
| - return static_cast<MatrixID>(matrix_id);
|
| +void ColorSpace::GetVideoParameters(int* video_primary,
|
| + int* video_transfer,
|
| + int* video_matrix,
|
| + bool* full_range) {
|
| + int first_primary = static_cast<int>(PrimaryID::FIRST_VIDEO_VALUE);
|
| + int last_primary = static_cast<int>(PrimaryID::LAST_VIDEO_VALUE);
|
| + *video_primary = static_cast<int>(primaries_) - first_primary;
|
| + if (*video_primary < 0 || *video_primary > last_primary - first_primary) {
|
| + *video_primary = static_cast<int>(PrimaryID::BT709) - first_primary;
|
| + }
|
| +
|
| + int first_transfer = static_cast<int>(TransferID::FIRST_VIDEO_VALUE);
|
| + int last_transfer = static_cast<int>(TransferID::LAST_VIDEO_VALUE);
|
| + *video_transfer = static_cast<int>(transfer_) - first_transfer;
|
| + if (*video_transfer < 0 || *video_transfer > last_transfer - first_transfer) {
|
| + *video_transfer = static_cast<int>(TransferID::BT709) - first_transfer;
|
| + }
|
| +
|
| + int first_matrix = static_cast<int>(MatrixID::FIRST_VIDEO_VALUE);
|
| + int last_matrix = static_cast<int>(MatrixID::LAST_VIDEO_VALUE);
|
| + *video_matrix = static_cast<int>(matrix_) - first_matrix;
|
| + if (*video_matrix < 0 || *video_matrix > last_matrix - first_matrix) {
|
| + *video_matrix = static_cast<int>(MatrixID::BT709) - first_matrix;
|
| + }
|
| +
|
| + switch (range_) {
|
| + case RangeID::FULL:
|
| + *full_range = true;
|
| + break;
|
| + case RangeID::UNSPECIFIED:
|
| + case RangeID::LIMITED:
|
| + case RangeID::DERIVED:
|
| + case RangeID::INVALID:
|
| + *full_range = false;
|
| + break;
|
| + }
|
| }
|
|
|
| ColorSpace::ColorSpace() {}
|
| @@ -60,12 +106,6 @@ ColorSpace::ColorSpace(PrimaryID primaries,
|
| matrix_(matrix),
|
| range_(range) {}
|
|
|
| -ColorSpace::ColorSpace(int primaries, int transfer, int matrix, RangeID range)
|
| - : primaries_(PrimaryIDFromInt(primaries)),
|
| - transfer_(TransferIDFromInt(transfer)),
|
| - matrix_(MatrixIDFromInt(matrix)),
|
| - range_(range) {}
|
| -
|
| ColorSpace::ColorSpace(const ColorSpace& other)
|
| : primaries_(other.primaries_),
|
| transfer_(other.transfer_),
|
| @@ -82,11 +122,11 @@ ColorSpace::ColorSpace(const ColorSpace& other)
|
| sizeof(custom_primary_matrix_));
|
| }
|
| }
|
| -
|
| ColorSpace::~ColorSpace() = default;
|
|
|
| bool ColorSpace::IsValid() const {
|
| - return *this != gfx::ColorSpace();
|
| + return primaries_ != PrimaryID::INVALID && transfer_ != TransferID::INVALID &&
|
| + matrix_ != MatrixID::INVALID && range_ != RangeID::INVALID;
|
| }
|
|
|
| // static
|
| @@ -197,10 +237,8 @@ sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const {
|
| return icc_profile_sk_color_space_;
|
|
|
| // Unspecified color spaces correspond to the null SkColorSpace.
|
| - if (primaries_ == PrimaryID::UNSPECIFIED ||
|
| - transfer_ == TransferID::UNSPECIFIED) {
|
| + if (!IsValid())
|
| return nullptr;
|
| - }
|
|
|
| // Handle only full-range RGB spaces.
|
| if (matrix_ != MatrixID::RGB) {
|
| @@ -249,10 +287,13 @@ void ColorSpace::GetPrimaryMatrix(SkMatrix44* to_XYZD50) const {
|
| to_XYZD50->set3x3RowMajorf(custom_primary_matrix_);
|
| return;
|
|
|
| + case ColorSpace::PrimaryID::INVALID:
|
| + to_XYZD50->setIdentity();
|
| + return;
|
| +
|
| case ColorSpace::PrimaryID::RESERVED0:
|
| case ColorSpace::PrimaryID::RESERVED:
|
| case ColorSpace::PrimaryID::UNSPECIFIED:
|
| - case ColorSpace::PrimaryID::UNKNOWN:
|
| case ColorSpace::PrimaryID::BT709:
|
| // BT709 is our default case. Put it after the switch just
|
| // in case we somehow get an id which is not listed in the switch.
|
| @@ -417,8 +458,6 @@ bool ColorSpace::GetTransferFunction(SkColorSpaceTransferFn* fn) const {
|
| case ColorSpace::TransferID::RESERVED0:
|
| case ColorSpace::TransferID::RESERVED:
|
| case ColorSpace::TransferID::UNSPECIFIED:
|
| - case ColorSpace::TransferID::UNKNOWN:
|
| - // All unknown values default to BT709
|
| case ColorSpace::TransferID::BT709:
|
| case ColorSpace::TransferID::SMPTE170M:
|
| case ColorSpace::TransferID::BT2020_10:
|
| @@ -458,6 +497,7 @@ bool ColorSpace::GetTransferFunction(SkColorSpaceTransferFn* fn) const {
|
| case ColorSpace::TransferID::LOG_SQRT:
|
| case ColorSpace::TransferID::SMPTEST2084:
|
| case ColorSpace::TransferID::SMPTEST2084_NON_HDR:
|
| + case ColorSpace::TransferID::INVALID:
|
| break;
|
| }
|
|
|
| @@ -476,13 +516,13 @@ void ColorSpace::GetTransferMatrix(SkMatrix44* matrix) const {
|
| float Kb = 0;
|
| switch (matrix_) {
|
| case ColorSpace::MatrixID::RGB:
|
| + case ColorSpace::MatrixID::INVALID:
|
| matrix->setIdentity();
|
| return;
|
|
|
| case ColorSpace::MatrixID::BT709:
|
| case ColorSpace::MatrixID::UNSPECIFIED:
|
| case ColorSpace::MatrixID::RESERVED:
|
| - case ColorSpace::MatrixID::UNKNOWN:
|
| Kr = 0.2126f;
|
| Kb = 0.0722f;
|
| break;
|
| @@ -563,6 +603,7 @@ void ColorSpace::GetRangeAdjustMatrix(SkMatrix44* matrix) const {
|
| switch (range_) {
|
| case RangeID::FULL:
|
| case RangeID::UNSPECIFIED:
|
| + case RangeID::INVALID:
|
| matrix->setIdentity();
|
| return;
|
|
|
| @@ -572,6 +613,7 @@ void ColorSpace::GetRangeAdjustMatrix(SkMatrix44* matrix) const {
|
| }
|
| switch (matrix_) {
|
| case MatrixID::RGB:
|
| + case MatrixID::INVALID:
|
| case MatrixID::YCOCG:
|
| matrix->setScale(255.0f/219.0f, 255.0f/219.0f, 255.0f/219.0f);
|
| matrix->postTranslate(-16.0f/219.0f, -16.0f/219.0f, -16.0f/219.0f);
|
| @@ -587,7 +629,6 @@ void ColorSpace::GetRangeAdjustMatrix(SkMatrix44* matrix) const {
|
| case MatrixID::BT2020_NCL:
|
| case MatrixID::BT2020_CL:
|
| case MatrixID::YDZDX:
|
| - case MatrixID::UNKNOWN:
|
| matrix->setScale(255.0f/219.0f, 255.0f/224.0f, 255.0f/224.0f);
|
| matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f);
|
| break;
|
|
|