| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifndef SkYUVAInfo_DEFINED |
| 9 |
#define SkYUVAInfo_DEFINED |
| 10 |
|
| 11 |
#include "include/codec/SkEncodedOrigin.h" |
| 12 |
#include "include/core/SkImageInfo.h" |
| 13 |
#include "include/core/SkMatrix.h" |
| 14 |
#include "include/core/SkSize.h" |
| 15 |
#include "include/core/SkTypes.h" |
| 16 |
|
| 17 |
#include <array> |
| 18 |
#include <cstddef> |
| 19 |
#include <cstdint> |
| 20 |
#include <tuple> |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
class SK_API SkYUVAInfo { |
| 27 |
public: |
| 28 |
enum YUVAChannels { kY, kU, kV, kA, kLast = kA }; |
| 29 |
static constexpr int kYUVAChannelCount = static_cast<int>(YUVAChannels::kLast + 1); |
| 30 |
|
| 31 |
struct YUVALocation; |
| 32 |
using YUVALocations = std::array<YUVALocation, kYUVAChannelCount>; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
enum class PlaneConfig { |
| 48 |
kUnknown, |
| 49 |
|
| 50 |
kY_U_V, |
| 51 |
kY_V_U, |
| 52 |
kY_UV, |
| 53 |
kY_VU, |
| 54 |
kYUV, |
| 55 |
kUYV, |
| 56 |
|
| 57 |
kY_U_V_A, |
| 58 |
kY_V_U_A, |
| 59 |
kY_UV_A, |
| 60 |
kY_VU_A, |
| 61 |
kYUVA, |
| 62 |
kUYVA, |
| 63 |
|
| 64 |
kLast = kUYVA |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
enum class Subsampling { |
| 74 |
kUnknown, |
| 75 |
|
| 76 |
k444, |
| 77 |
k422, |
| 78 |
k420, |
| 79 |
k440, |
| 80 |
k411, |
| 81 |
k410, |
| 82 |
|
| 83 |
kLast = k410 |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
enum class Siting { |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
kCentered, |
| 96 |
}; |
| 97 |
|
| 98 |
static constexpr int kMaxPlanes = 4; |
| 99 |
|
| 100 |
|
| 101 |
static std::tuple<int, int> SubsamplingFactors(Subsampling); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
static std::tuple<int, int> PlaneSubsamplingFactors(PlaneConfig, Subsampling, int planeIdx); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
static int PlaneDimensions(SkISize imageDimensions, |
| 119 |
PlaneConfig, |
| 120 |
Subsampling, |
| 121 |
SkEncodedOrigin, |
| 122 |
SkISize planeDimensions[kMaxPlanes]); |
| 123 |
|
| 124 |
|
| 125 |
static constexpr int NumPlanes(PlaneConfig); |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
static constexpr int NumChannelsInPlane(PlaneConfig, int i); |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
static YUVALocations GetYUVALocations(PlaneConfig, const uint32_t* planeChannelFlags); |
| 139 |
|
| 140 |
|
| 141 |
static bool HasAlpha(PlaneConfig); |
| 142 |
|
| 143 |
SkYUVAInfo() = default; |
| 144 |
SkYUVAInfo(const SkYUVAInfo&) = default; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
SkYUVAInfo(SkISize dimensions, |
| 151 |
PlaneConfig, |
| 152 |
Subsampling, |
| 153 |
SkYUVColorSpace, |
| 154 |
SkEncodedOrigin origin = kTopLeft_SkEncodedOrigin, |
| 155 |
Siting sitingX = Siting::kCentered, |
| 156 |
Siting sitingY = Siting::kCentered); |
| 157 |
|
| 158 |
SkYUVAInfo& operator=(const SkYUVAInfo& that) = default; |
| 159 |
|
| 160 |
PlaneConfig planeConfig() const { return fPlaneConfig; } |
| 161 |
Subsampling subsampling() const { return fSubsampling; } |
| 162 |
|
| 163 |
std::tuple<int, int> planeSubsamplingFactors(int planeIdx) const { |
| 164 |
return PlaneSubsamplingFactors(fPlaneConfig, fSubsampling, planeIdx); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
SkISize dimensions() const { return fDimensions; } |
| 172 |
int width() const { return fDimensions.width(); } |
| 173 |
int height() const { return fDimensions.height(); } |
| 174 |
|
| 175 |
SkYUVColorSpace yuvColorSpace() const { return fYUVColorSpace; } |
| 176 |
Siting sitingX() const { return fSitingX; } |
| 177 |
Siting sitingY() const { return fSitingY; } |
| 178 |
|
| 179 |
SkEncodedOrigin origin() const { return fOrigin; } |
| 180 |
|
| 181 |
SkMatrix originMatrix() const { |
| 182 |
return SkEncodedOriginToMatrix(fOrigin, this->width(), this->height()); |
| 183 |
} |
| 184 |
SkMatrix inverseOriginMatrix() const { |
| 185 |
return SkEncodedOriginToMatrixInverse(fOrigin, this->width(), this->height()); |
| 186 |
} |
| 187 |
|
| 188 |
bool hasAlpha() const { return HasAlpha(fPlaneConfig); } |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
int planeDimensions(SkISize planeDimensions[kMaxPlanes]) const { |
| 196 |
return PlaneDimensions(fDimensions, fPlaneConfig, fSubsampling, fOrigin, planeDimensions); |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
size_t computeTotalBytes(const size_t rowBytes[kMaxPlanes], |
| 205 |
size_t planeSizes[kMaxPlanes] = nullptr) const; |
| 206 |
|
| 207 |
int numPlanes() const { return NumPlanes(fPlaneConfig); } |
| 208 |
|
| 209 |
int numChannelsInPlane(int i) const { return NumChannelsInPlane(fPlaneConfig, i); } |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
YUVALocations toYUVALocations(const uint32_t* channelFlags) const; |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
SkYUVAInfo makeSubsampling(SkYUVAInfo::Subsampling) const; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
SkYUVAInfo makeDimensions(SkISize) const; |
| 232 |
|
| 233 |
bool operator==(const SkYUVAInfo& that) const; |
| 234 |
bool operator!=(const SkYUVAInfo& that) const { return !(*this == that); } |
| 235 |
|
| 236 |
bool isValid() const { return fPlaneConfig != PlaneConfig::kUnknown; } |
| 237 |
|
| 238 |
private: |
| 239 |
SkISize fDimensions = {0, 0}; |
| 240 |
|
| 241 |
PlaneConfig fPlaneConfig = PlaneConfig::kUnknown; |
| 242 |
Subsampling fSubsampling = Subsampling::kUnknown; |
| 243 |
|
| 244 |
SkYUVColorSpace fYUVColorSpace = SkYUVColorSpace::kIdentity_SkYUVColorSpace; |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
SkEncodedOrigin fOrigin = kTopLeft_SkEncodedOrigin; |
| 251 |
|
| 252 |
Siting fSitingX = Siting::kCentered; |
| 253 |
Siting fSitingY = Siting::kCentered; |
| 254 |
}; |
| 255 |
|
| 256 |
constexpr int SkYUVAInfo::NumPlanes(PlaneConfig planeConfig) { |
| 257 |
switch (planeConfig) { |
| 258 |
case PlaneConfig::kUnknown: return 0; |
| 259 |
case PlaneConfig::kY_U_V: return 3; |
| 260 |
case PlaneConfig::kY_V_U: return 3; |
| 261 |
case PlaneConfig::kY_UV: return 2; |
| 262 |
case PlaneConfig::kY_VU: return 2; |
| 263 |
case PlaneConfig::kYUV: return 1; |
| 264 |
case PlaneConfig::kUYV: return 1; |
| 265 |
case PlaneConfig::kY_U_V_A: return 4; |
| 266 |
case PlaneConfig::kY_V_U_A: return 4; |
| 267 |
case PlaneConfig::kY_UV_A: return 3; |
| 268 |
case PlaneConfig::kY_VU_A: return 3; |
| 269 |
case PlaneConfig::kYUVA: return 1; |
| 270 |
case PlaneConfig::kUYVA: return 1; |
| 271 |
} |
| 272 |
SkUNREACHABLE; |
| 273 |
} |
| 274 |
|
| 275 |
constexpr int SkYUVAInfo::NumChannelsInPlane(PlaneConfig config, int i) { |
| 276 |
switch (config) { |
| 277 |
case PlaneConfig::kUnknown: |
| 278 |
return 0; |
| 279 |
|
| 280 |
case SkYUVAInfo::PlaneConfig::kY_U_V: |
| 281 |
case SkYUVAInfo::PlaneConfig::kY_V_U: |
| 282 |
return i >= 0 && i < 3 ? 1 : 0; |
| 283 |
case SkYUVAInfo::PlaneConfig::kY_UV: |
| 284 |
case SkYUVAInfo::PlaneConfig::kY_VU: |
| 285 |
switch (i) { |
| 286 |
case 0: return 1; |
| 287 |
case 1: return 2; |
| 288 |
default: return 0; |
| 289 |
} |
| 290 |
case SkYUVAInfo::PlaneConfig::kYUV: |
| 291 |
case SkYUVAInfo::PlaneConfig::kUYV: |
| 292 |
return i == 0 ? 3 : 0; |
| 293 |
case SkYUVAInfo::PlaneConfig::kY_U_V_A: |
| 294 |
case SkYUVAInfo::PlaneConfig::kY_V_U_A: |
| 295 |
return i >= 0 && i < 4 ? 1 : 0; |
| 296 |
case SkYUVAInfo::PlaneConfig::kY_UV_A: |
| 297 |
case SkYUVAInfo::PlaneConfig::kY_VU_A: |
| 298 |
switch (i) { |
| 299 |
case 0: return 1; |
| 300 |
case 1: return 2; |
| 301 |
case 2: return 1; |
| 302 |
default: return 0; |
| 303 |
} |
| 304 |
case SkYUVAInfo::PlaneConfig::kYUVA: |
| 305 |
case SkYUVAInfo::PlaneConfig::kUYVA: |
| 306 |
return i == 0 ? 4 : 0; |
| 307 |
} |
| 308 |
return 0; |
| 309 |
} |
| 310 |
|
| 311 |
#endif |