OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "media/base/video_color_space.h" | 5 #include "media/base/video_color_space.h" |
6 | 6 |
7 namespace media { | 7 namespace media { |
8 | 8 |
9 VideoColorSpace::PrimaryID VideoColorSpace::GetPrimaryID(int primary) { | 9 VideoColorSpace::PrimaryID VideoColorSpace::GetPrimaryID(int primary) { |
10 if (primary < 1 || primary > 22 || primary == 3) | 10 if (primary < 1 || primary > 22 || primary == 3) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return primaries == other.primaries && transfer == other.transfer && | 47 return primaries == other.primaries && transfer == other.transfer && |
48 matrix == other.matrix && range == other.range; | 48 matrix == other.matrix && range == other.range; |
49 } | 49 } |
50 | 50 |
51 bool VideoColorSpace::operator!=(const VideoColorSpace& other) const { | 51 bool VideoColorSpace::operator!=(const VideoColorSpace& other) const { |
52 return primaries != other.primaries || transfer != other.transfer || | 52 return primaries != other.primaries || transfer != other.transfer || |
53 matrix != other.matrix || range != other.range; | 53 matrix != other.matrix || range != other.range; |
54 } | 54 } |
55 | 55 |
56 gfx::ColorSpace VideoColorSpace::ToGfxColorSpace() const { | 56 gfx::ColorSpace VideoColorSpace::ToGfxColorSpace() const { |
57 // TODO(hubbe): Make this type-safe. | 57 gfx::ColorSpace::PrimaryID primary_id; |
58 return gfx::ColorSpace::CreateVideo(static_cast<int>(primaries), | 58 gfx::ColorSpace::TransferID transfer_id; |
59 static_cast<int>(transfer), | 59 gfx::ColorSpace::MatrixID matrix_id; |
60 static_cast<int>(matrix), range); | 60 |
| 61 switch (primaries) { |
| 62 case PrimaryID::INVALID: |
| 63 case PrimaryID::BT709: |
| 64 case PrimaryID::UNSPECIFIED: |
| 65 primary_id = gfx::ColorSpace::PrimaryID::BT709; |
| 66 break; |
| 67 case PrimaryID::BT470M: |
| 68 primary_id = gfx::ColorSpace::PrimaryID::BT470M; |
| 69 break; |
| 70 case PrimaryID::BT470BG: |
| 71 primary_id = gfx::ColorSpace::PrimaryID::BT470BG; |
| 72 break; |
| 73 case PrimaryID::SMPTE170M: |
| 74 primary_id = gfx::ColorSpace::PrimaryID::SMPTE170M; |
| 75 break; |
| 76 case PrimaryID::SMPTE240M: |
| 77 primary_id = gfx::ColorSpace::PrimaryID::SMPTE240M; |
| 78 break; |
| 79 case PrimaryID::FILM: |
| 80 primary_id = gfx::ColorSpace::PrimaryID::FILM; |
| 81 break; |
| 82 case PrimaryID::BT2020: |
| 83 primary_id = gfx::ColorSpace::PrimaryID::BT2020; |
| 84 break; |
| 85 case PrimaryID::SMPTEST428_1: |
| 86 primary_id = gfx::ColorSpace::PrimaryID::SMPTEST428_1; |
| 87 break; |
| 88 case PrimaryID::SMPTEST431_2: |
| 89 primary_id = gfx::ColorSpace::PrimaryID::SMPTEST431_2; |
| 90 break; |
| 91 case PrimaryID::SMPTEST432_1: |
| 92 primary_id = gfx::ColorSpace::PrimaryID::SMPTEST432_1; |
| 93 case PrimaryID::EBU_3213_E: |
| 94 // TODO(uzair.jaleel) Need to check this once. |
| 95 primary_id = gfx::ColorSpace::PrimaryID::INVALID; |
| 96 break; |
| 97 } |
| 98 |
| 99 switch (transfer) { |
| 100 case TransferID::INVALID: |
| 101 case TransferID::BT709: |
| 102 case TransferID::UNSPECIFIED: |
| 103 transfer_id = gfx::ColorSpace::TransferID::BT709; |
| 104 break; |
| 105 case TransferID::GAMMA22: |
| 106 transfer_id = gfx::ColorSpace::TransferID::GAMMA22; |
| 107 break; |
| 108 case TransferID::GAMMA28: |
| 109 transfer_id = gfx::ColorSpace::TransferID::GAMMA28; |
| 110 break; |
| 111 case TransferID::SMPTE170M: |
| 112 transfer_id = gfx::ColorSpace::TransferID::SMPTE170M; |
| 113 break; |
| 114 case TransferID::SMPTE240M: |
| 115 transfer_id = gfx::ColorSpace::TransferID::SMPTE240M; |
| 116 break; |
| 117 case TransferID::LINEAR: |
| 118 transfer_id = gfx::ColorSpace::TransferID::LINEAR; |
| 119 break; |
| 120 case TransferID::LOG: |
| 121 transfer_id = gfx::ColorSpace::TransferID::LOG; |
| 122 break; |
| 123 case TransferID::LOG_SQRT: |
| 124 transfer_id = gfx::ColorSpace::TransferID::LOG_SQRT; |
| 125 break; |
| 126 case TransferID::IEC61966_2_4: |
| 127 transfer_id = gfx::ColorSpace::TransferID::IEC61966_2_4; |
| 128 break; |
| 129 case TransferID::BT1361_ECG: |
| 130 transfer_id = gfx::ColorSpace::TransferID::BT1361_ECG; |
| 131 break; |
| 132 case TransferID::IEC61966_2_1: |
| 133 transfer_id = gfx::ColorSpace::TransferID::IEC61966_2_1; |
| 134 break; |
| 135 case TransferID::BT2020_10: |
| 136 transfer_id = gfx::ColorSpace::TransferID::BT2020_10; |
| 137 break; |
| 138 case TransferID::BT2020_12: |
| 139 transfer_id = gfx::ColorSpace::TransferID::BT2020_12; |
| 140 break; |
| 141 case TransferID::SMPTEST2084: |
| 142 transfer_id = gfx::ColorSpace::TransferID::SMPTEST2084; |
| 143 break; |
| 144 case TransferID::SMPTEST428_1: |
| 145 transfer_id = gfx::ColorSpace::TransferID::SMPTEST428_1; |
| 146 break; |
| 147 case TransferID::ARIB_STD_B67: |
| 148 transfer_id = gfx::ColorSpace::TransferID::ARIB_STD_B67; |
| 149 break; |
| 150 } |
| 151 |
| 152 switch (matrix) { |
| 153 case MatrixID::RGB: |
| 154 matrix_id = gfx::ColorSpace::MatrixID::RGB; |
| 155 break; |
| 156 case MatrixID::INVALID: |
| 157 case MatrixID::BT709: |
| 158 case MatrixID::UNSPECIFIED: |
| 159 matrix_id = gfx::ColorSpace::MatrixID::BT709; |
| 160 break; |
| 161 case MatrixID::FCC: |
| 162 matrix_id = gfx::ColorSpace::MatrixID::FCC; |
| 163 break; |
| 164 case MatrixID::BT470BG: |
| 165 matrix_id = gfx::ColorSpace::MatrixID::BT470BG; |
| 166 break; |
| 167 case MatrixID::SMPTE170M: |
| 168 matrix_id = gfx::ColorSpace::MatrixID::SMPTE170M; |
| 169 break; |
| 170 case MatrixID::SMPTE240M: |
| 171 matrix_id = gfx::ColorSpace::MatrixID::SMPTE240M; |
| 172 break; |
| 173 case MatrixID::YCOCG: |
| 174 matrix_id = gfx::ColorSpace::MatrixID::YCOCG; |
| 175 break; |
| 176 case MatrixID::BT2020_NCL: |
| 177 matrix_id = gfx::ColorSpace::MatrixID::BT2020_NCL; |
| 178 break; |
| 179 case MatrixID::BT2020_CL: |
| 180 matrix_id = gfx::ColorSpace::MatrixID::BT2020_CL; |
| 181 break; |
| 182 case MatrixID::YDZDX: |
| 183 matrix_id = gfx::ColorSpace::MatrixID::YDZDX; |
| 184 break; |
| 185 } |
| 186 |
| 187 return gfx::ColorSpace(primary_id, transfer_id, matrix_id, range); |
61 } | 188 } |
62 | 189 |
63 VideoColorSpace VideoColorSpace::REC709() { | 190 VideoColorSpace VideoColorSpace::REC709() { |
64 return VideoColorSpace(PrimaryID::BT709, TransferID::BT709, MatrixID::BT709, | 191 return VideoColorSpace(PrimaryID::BT709, TransferID::BT709, MatrixID::BT709, |
65 gfx::ColorSpace::RangeID::LIMITED); | 192 gfx::ColorSpace::RangeID::LIMITED); |
66 } | 193 } |
67 VideoColorSpace VideoColorSpace::REC601() { | 194 VideoColorSpace VideoColorSpace::REC601() { |
68 return VideoColorSpace(PrimaryID::SMPTE170M, TransferID::SMPTE170M, | 195 return VideoColorSpace(PrimaryID::SMPTE170M, TransferID::SMPTE170M, |
69 MatrixID::SMPTE170M, | 196 MatrixID::SMPTE170M, |
70 gfx::ColorSpace::RangeID::LIMITED); | 197 gfx::ColorSpace::RangeID::LIMITED); |
71 } | 198 } |
72 VideoColorSpace VideoColorSpace::JPEG() { | 199 VideoColorSpace VideoColorSpace::JPEG() { |
73 // TODO(ccameron): Determine which primaries and transfer function were | 200 // TODO(ccameron): Determine which primaries and transfer function were |
74 // intended here. | 201 // intended here. |
75 return VideoColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, | 202 return VideoColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, |
76 MatrixID::SMPTE170M, gfx::ColorSpace::RangeID::FULL); | 203 MatrixID::SMPTE170M, gfx::ColorSpace::RangeID::FULL); |
77 } | 204 } |
78 | 205 |
79 } // namespace | 206 } // namespace |
OLD | NEW |