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