OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/base/video_color_space.h" |
| 6 |
| 7 namespace media { |
| 8 |
| 9 VideoColorSpace::PrimaryID VideoColorSpace::GetPrimaryID(int primary) { |
| 10 if (primary < 1 || primary > 22 || primary == 3) |
| 11 return PrimaryID::INVALID; |
| 12 if (primary > 12 && primary < 22) |
| 13 return PrimaryID::INVALID; |
| 14 return static_cast<PrimaryID>(primary); |
| 15 } |
| 16 |
| 17 VideoColorSpace::TransferID VideoColorSpace::GetTransferID(int transfer) { |
| 18 if (transfer < 1 || transfer > 18 || transfer == 3) |
| 19 return TransferID::INVALID; |
| 20 return static_cast<TransferID>(transfer); |
| 21 } |
| 22 |
| 23 VideoColorSpace::MatrixID VideoColorSpace::GetMatrixID(int matrix) { |
| 24 if (matrix < 0 || matrix > 11 || matrix == 3) |
| 25 return MatrixID::INVALID; |
| 26 return static_cast<MatrixID>(matrix); |
| 27 } |
| 28 |
| 29 VideoColorSpace::VideoColorSpace() {} |
| 30 |
| 31 VideoColorSpace::VideoColorSpace(PrimaryID primaries, |
| 32 TransferID transfer, |
| 33 MatrixID matrix, |
| 34 gfx::ColorSpace::RangeID range) |
| 35 : primaries(primaries), transfer(transfer), matrix(matrix), range(range) {} |
| 36 |
| 37 VideoColorSpace::VideoColorSpace(int primaries, |
| 38 int transfer, |
| 39 int matrix, |
| 40 gfx::ColorSpace::RangeID range) |
| 41 : primaries(GetPrimaryID(primaries)), |
| 42 transfer(GetTransferID(transfer)), |
| 43 matrix(GetMatrixID(matrix)), |
| 44 range(range) {} |
| 45 |
| 46 gfx::ColorSpace VideoColorSpace::ToGfxColorSpace() const { |
| 47 // TODO(hubbe): Make this type-safe. |
| 48 return gfx::ColorSpace::CreateVideo(static_cast<int>(primaries), |
| 49 static_cast<int>(transfer), |
| 50 static_cast<int>(matrix), range); |
| 51 } |
| 52 |
| 53 VideoColorSpace VideoColorSpace::BT709() { |
| 54 return VideoColorSpace(PrimaryID::BT709, TransferID::BT709, MatrixID::BT709, |
| 55 gfx::ColorSpace::RangeID::LIMITED); |
| 56 } |
| 57 |
| 58 } // namespace |
OLD | NEW |