Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
SkYUVAPixmapInfo Class Reference

#include <SkYUVAPixmaps.h>

Classes

class  SupportedDataTypes
 

Public Types

enum class  DataType {
  kUnorm8 , kUnorm16 , kFloat16 , kUnorm10_Unorm2 ,
  kLast = kUnorm10_Unorm2
}
 
using PlaneConfig = SkYUVAInfo::PlaneConfig
 
using Subsampling = SkYUVAInfo::Subsampling
 

Public Member Functions

 SkYUVAPixmapInfo ()=default
 
 SkYUVAPixmapInfo (const SkYUVAInfo &, const SkColorType[kMaxPlanes], const size_t rowBytes[kMaxPlanes])
 
 SkYUVAPixmapInfo (const SkYUVAInfo &, DataType, const size_t rowBytes[kMaxPlanes])
 
 SkYUVAPixmapInfo (const SkYUVAPixmapInfo &)=default
 
SkYUVAPixmapInfooperator= (const SkYUVAPixmapInfo &)=default
 
bool operator== (const SkYUVAPixmapInfo &) const
 
bool operator!= (const SkYUVAPixmapInfo &that) const
 
const SkYUVAInfoyuvaInfo () const
 
SkYUVColorSpace yuvColorSpace () const
 
int numPlanes () const
 
DataType dataType () const
 
size_t rowBytes (int i) const
 
const SkImageInfoplaneInfo (int i) const
 
size_t computeTotalBytes (size_t planeSizes[kMaxPlanes]=nullptr) const
 
bool initPixmapsFromSingleAllocation (void *memory, SkPixmap pixmaps[kMaxPlanes]) const
 
bool isValid () const
 
bool isSupported (const SupportedDataTypes &) const
 

Static Public Member Functions

static constexpr SkColorType DefaultColorTypeForDataType (DataType dataType, int numChannels)
 
static std::tuple< int, DataTypeNumChannelsAndDataType (SkColorType)
 

Static Public Attributes

static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes
 
static constexpr int kDataTypeCnt = static_cast<int>(DataType::kLast) + 1
 

Detailed Description

SkYUVAInfo combined with per-plane SkColorTypes and row bytes. Fully specifies the SkPixmaps for a YUVA image without the actual pixel memory and data.

Definition at line 30 of file SkYUVAPixmaps.h.

Member Typedef Documentation

◆ PlaneConfig

Definition at line 34 of file SkYUVAPixmaps.h.

◆ Subsampling

Definition at line 35 of file SkYUVAPixmaps.h.

Member Enumeration Documentation

◆ DataType

enum class SkYUVAPixmapInfo::DataType
strong

Data type for Y, U, V, and possibly A channels independent of how values are packed into planes.

Enumerator
kUnorm8 

8 bit unsigned normalized

kUnorm16 

16 bit unsigned normalized

kFloat16 

16 bit (half) floating point

kUnorm10_Unorm2 

10 bit unorm for Y, U, and V. 2 bit unorm for alpha (if present).

kLast 

Definition at line 41 of file SkYUVAPixmaps.h.

41 {
42 kUnorm8, ///< 8 bit unsigned normalized
43 kUnorm16, ///< 16 bit unsigned normalized
44 kFloat16, ///< 16 bit (half) floating point
45 kUnorm10_Unorm2, ///< 10 bit unorm for Y, U, and V. 2 bit unorm for alpha (if present).
46
48 };
@ kUnorm10_Unorm2
10 bit unorm for Y, U, and V. 2 bit unorm for alpha (if present).
@ kUnorm8
8 bit unsigned normalized
@ kUnorm16
16 bit unsigned normalized
@ kFloat16
16 bit (half) floating point

Constructor & Destructor Documentation

◆ SkYUVAPixmapInfo() [1/4]

SkYUVAPixmapInfo::SkYUVAPixmapInfo ( )
default

Default SkYUVAPixmapInfo is invalid.

◆ SkYUVAPixmapInfo() [2/4]

SkYUVAPixmapInfo::SkYUVAPixmapInfo ( const SkYUVAInfo yuvaInfo,
const SkColorType  colorTypes[kMaxPlanes],
const size_t  rowBytes[kMaxPlanes] 
)

Initializes the SkYUVAPixmapInfo from a SkYUVAInfo with per-plane color types and row bytes. This will be invalid if the colorTypes aren't compatible with the SkYUVAInfo or if a rowBytes entry is not valid for the plane dimensions and color type. Color type and row byte values beyond the number of planes in SkYUVAInfo are ignored. All SkColorTypes must have the same DataType or this will be invalid.

If rowBytes is nullptr then bpp*width is assumed for each plane.

Definition at line 56 of file SkYUVAPixmaps.cpp.

59 : fYUVAInfo(yuvaInfo) {
60 if (!yuvaInfo.isValid()) {
61 *this = {};
62 SkASSERT(!this->isValid());
63 return;
64 }
65 SkISize planeDimensions[4];
66 int n = yuvaInfo.planeDimensions(planeDimensions);
67 size_t tempRowBytes[kMaxPlanes];
68 if (!rowBytes) {
69 for (int i = 0; i < n; ++i) {
70 tempRowBytes[i] = SkColorTypeBytesPerPixel(colorTypes[i]) * planeDimensions[i].width();
71 }
72 rowBytes = tempRowBytes;
73 }
74 bool ok = true;
75 for (size_t i = 0; i < static_cast<size_t>(n); ++i) {
76 fRowBytes[i] = rowBytes[i];
77 // Use kUnpremul so that we never multiply alpha when copying data in.
78 fPlaneInfos[i] = SkImageInfo::Make(planeDimensions[i],
79 colorTypes[i],
81 int numRequiredChannels = yuvaInfo.numChannelsInPlane(i);
82 SkASSERT(numRequiredChannels > 0);
83 auto [numColorTypeChannels, colorTypeDataType] = NumChannelsAndDataType(colorTypes[i]);
84 ok &= i == 0 || colorTypeDataType == fDataType;
85 ok &= numColorTypeChannels >= numRequiredChannels;
86 ok &= fPlaneInfos[i].validRowBytes(fRowBytes[i]);
87 fDataType = colorTypeDataType;
88 }
89 if (!ok) {
90 *this = {};
91 SkASSERT(!this->isValid());
92 } else {
93 SkASSERT(this->isValid());
94 }
95}
kUnpremul_SkAlphaType
#define SkASSERT(cond)
Definition SkAssert.h:116
static bool ok(int result)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
int planeDimensions(SkISize planeDimensions[kMaxPlanes]) const
Definition SkYUVAInfo.h:192
bool isValid() const
Definition SkYUVAInfo.h:233
int numChannelsInPlane(int i) const
Definition SkYUVAInfo.h:206
size_t rowBytes(int i) const
const SkYUVAInfo & yuvaInfo() const
bool isValid() const
static std::tuple< int, DataType > NumChannelsAndDataType(SkColorType)
static constexpr auto kMaxPlanes
constexpr int32_t width() const
Definition SkSize.h:36
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ SkYUVAPixmapInfo() [3/4]

SkYUVAPixmapInfo::SkYUVAPixmapInfo ( const SkYUVAInfo yuvaInfo,
DataType  dataType,
const size_t  rowBytes[kMaxPlanes] 
)

Like above but uses DefaultColorTypeForDataType to determine each plane's SkColorType. If rowBytes is nullptr then bpp*width is assumed for each plane.

Definition at line 97 of file SkYUVAPixmaps.cpp.

99 {
100 SkColorType colorTypes[kMaxPlanes] = {};
102 for (int i = 0; i < numPlanes; ++i) {
103 int numChannels = yuvaInfo.numChannelsInPlane(i);
104 colorTypes[i] = DefaultColorTypeForDataType(dataType, numChannels);
105 }
106 *this = SkYUVAPixmapInfo(yuvaInfo, colorTypes, rowBytes);
107}
SkColorType
Definition SkColorType.h:19
int numPlanes() const
Definition SkYUVAInfo.h:204
SkYUVAPixmapInfo()=default
DataType dataType() const
int numPlanes() const
static constexpr SkColorType DefaultColorTypeForDataType(DataType dataType, int numChannels)

◆ SkYUVAPixmapInfo() [4/4]

SkYUVAPixmapInfo::SkYUVAPixmapInfo ( const SkYUVAPixmapInfo )
default

Member Function Documentation

◆ computeTotalBytes()

size_t SkYUVAPixmapInfo::computeTotalBytes ( size_t  planeSizes[kMaxPlanes] = nullptr) const

Determine size to allocate for all planes. Optionally retrieves the per-plane sizes in planeSizes if not null. If total size overflows will return SIZE_MAX and set all planeSizes to SIZE_MAX. Returns 0 and fills planesSizes with 0 if this SkYUVAPixmapInfo is not valid.

Definition at line 117 of file SkYUVAPixmaps.cpp.

117 {
118 if (!this->isValid()) {
119 if (planeSizes) {
120 std::fill_n(planeSizes, kMaxPlanes, 0);
121 }
122 return 0;
123 }
124 return fYUVAInfo.computeTotalBytes(fRowBytes.data(), planeSizes);
125}
size_t computeTotalBytes(const size_t rowBytes[kMaxPlanes], size_t planeSizes[kMaxPlanes]=nullptr) const

◆ dataType()

DataType SkYUVAPixmapInfo::dataType ( ) const
inline

The per-YUV[A] channel data type.

Definition at line 126 of file SkYUVAPixmaps.h.

126{ return fDataType; }

◆ DefaultColorTypeForDataType()

constexpr SkColorType SkYUVAPixmapInfo::DefaultColorTypeForDataType ( DataType  dataType,
int  numChannels 
)
staticconstexpr

Gets the default SkColorType to use with numChannels channels, each represented as DataType. Returns kUnknown_SkColorType if no such color type.

Definition at line 293 of file SkYUVAPixmaps.h.

294 {
295 switch (numChannels) {
296 case 1:
297 switch (dataType) {
302 }
303 break;
304 case 2:
305 switch (dataType) {
310 }
311 break;
312 case 3:
313 // None of these are tightly packed. The intended use case is for interleaved YUVA
314 // planes where we're forcing opaqueness by ignoring the alpha values.
315 // There are "x" rather than "A" variants for Unorm8 and Unorm10_Unorm2 but we don't
316 // choose them because 1) there is no inherent advantage and 2) there is better support
317 // in the GPU backend for the "A" versions.
318 switch (dataType) {
323 }
324 break;
325 case 4:
326 switch (dataType) {
331 }
332 break;
333 }
335}
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
Definition SkColorType.h:50
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
Definition SkColorType.h:43
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
Definition SkColorType.h:48
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition SkColorType.h:38
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition SkColorType.h:35
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kA16_float_SkColorType
pixel with a half float for alpha
Definition SkColorType.h:45
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition SkColorType.h:27
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
Definition SkColorType.h:49
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
@ kR16G16_float_SkColorType
pixel with a half float for red and green
Definition SkColorType.h:46

◆ initPixmapsFromSingleAllocation()

bool SkYUVAPixmapInfo::initPixmapsFromSingleAllocation ( void *  memory,
SkPixmap  pixmaps[kMaxPlanes] 
) const

Takes an allocation that is assumed to be at least computeTotalBytes() in size and configures the first numPlanes() entries in pixmaps array to point into that memory. The remaining entries of pixmaps are default initialized. Fails if this SkYUVAPixmapInfo not valid.

Definition at line 127 of file SkYUVAPixmaps.cpp.

128 {
129 if (!this->isValid()) {
130 return false;
131 }
132 SkASSERT(pixmaps);
133 char* addr = static_cast<char*>(memory);
134 int n = this->numPlanes();
135 for (int i = 0; i < n; ++i) {
136 SkASSERT(fPlaneInfos[i].validRowBytes(fRowBytes[i]));
137 pixmaps[i].reset(fPlaneInfos[i], addr, fRowBytes[i]);
138 size_t planeSize = pixmaps[i].rowBytes()*pixmaps[i].height();
139 SkASSERT(planeSize);
140 addr += planeSize;
141 }
142 for (int i = n; i < kMaxPlanes; ++i) {
143 pixmaps[i] = {};
144 }
145 return true;
146}
size_t rowBytes() const
Definition SkPixmap.h:145
int height() const
Definition SkPixmap.h:166
void reset()
Definition SkPixmap.cpp:32

◆ isSupported()

bool SkYUVAPixmapInfo::isSupported ( const SupportedDataTypes supportedDataTypes) const

Is this valid and does it use color types allowed by the passed SupportedDataTypes?

Definition at line 148 of file SkYUVAPixmaps.cpp.

148 {
149 if (!this->isValid()) {
150 return false;
151 }
152 return supportedDataTypes.supported(fYUVAInfo.planeConfig(), fDataType);
153}
PlaneConfig planeConfig() const
Definition SkYUVAInfo.h:160

◆ isValid()

bool SkYUVAPixmapInfo::isValid ( ) const
inline

Returns true if this has been configured with a non-empty dimensioned SkYUVAInfo with compatible color types and row bytes.

Definition at line 155 of file SkYUVAPixmaps.h.

155{ return fYUVAInfo.isValid(); }

◆ NumChannelsAndDataType()

std::tuple< int, SkYUVAPixmapInfo::DataType > SkYUVAPixmapInfo::NumChannelsAndDataType ( SkColorType  ct)
static

If the SkColorType is supported for YUVA pixmaps this will return the number of YUVA channels that can be stored in a plane of this color type and what the DataType is of those channels. If the SkColorType is not supported as a YUVA plane the number of channels is reported as 0 and the DataType returned should be ignored.

Definition at line 29 of file SkYUVAPixmaps.cpp.

30 {
31 // We could allow BGR[A] color types, but then we'd have to decide whether B should be the 0th
32 // or 2nd channel. Our docs currently say channel order is always R=0, G=1, B=2[, A=3].
33 switch (ct) {
35 case kGray_8_SkColorType: return {1, DataType::kUnorm8 };
38
42
45
51
52 default: return {0, DataType::kUnorm8 };
53 }
54}
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition SkColorType.h:21
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:29
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:25
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition SkColorType.h:36

◆ numPlanes()

int SkYUVAPixmapInfo::numPlanes ( ) const
inline

The number of SkPixmap planes, 0 if this SkYUVAPixmapInfo is invalid.

Definition at line 123 of file SkYUVAPixmaps.h.

123{ return fYUVAInfo.numPlanes(); }

◆ operator!=()

bool SkYUVAPixmapInfo::operator!= ( const SkYUVAPixmapInfo that) const
inline

Definition at line 116 of file SkYUVAPixmaps.h.

116{ return !(*this == that); }

◆ operator=()

SkYUVAPixmapInfo & SkYUVAPixmapInfo::operator= ( const SkYUVAPixmapInfo )
default

◆ operator==()

bool SkYUVAPixmapInfo::operator== ( const SkYUVAPixmapInfo that) const

Definition at line 109 of file SkYUVAPixmaps.cpp.

109 {
110 bool result = fYUVAInfo == that.fYUVAInfo &&
111 fPlaneInfos == that.fPlaneInfos &&
112 fRowBytes == that.fRowBytes;
113 SkASSERT(!result || fDataType == that.fDataType);
114 return result;
115}
GAsyncResult * result

◆ planeInfo()

const SkImageInfo & SkYUVAPixmapInfo::planeInfo ( int  i) const
inline

Image info for the ith plane, or default SkImageInfo if i >= numPlanes()

Definition at line 135 of file SkYUVAPixmaps.h.

135{ return fPlaneInfos[static_cast<size_t>(i)]; }

◆ rowBytes()

size_t SkYUVAPixmapInfo::rowBytes ( int  i) const
inline

Row bytes for the ith plane. Returns zero if i >= numPlanes() or this SkYUVAPixmapInfo is invalid.

Definition at line 132 of file SkYUVAPixmaps.h.

132{ return fRowBytes[static_cast<size_t>(i)]; }

◆ yuvaInfo()

const SkYUVAInfo & SkYUVAPixmapInfo::yuvaInfo ( ) const
inline

Definition at line 118 of file SkYUVAPixmaps.h.

118{ return fYUVAInfo; }

◆ yuvColorSpace()

SkYUVColorSpace SkYUVAPixmapInfo::yuvColorSpace ( ) const
inline

Definition at line 120 of file SkYUVAPixmaps.h.

120{ return fYUVAInfo.yuvColorSpace(); }
SkYUVColorSpace yuvColorSpace() const
Definition SkYUVAInfo.h:175

Member Data Documentation

◆ kDataTypeCnt

constexpr int SkYUVAPixmapInfo::kDataTypeCnt = static_cast<int>(DataType::kLast) + 1
staticconstexpr

Definition at line 49 of file SkYUVAPixmaps.h.

◆ kMaxPlanes

constexpr auto SkYUVAPixmapInfo::kMaxPlanes = SkYUVAInfo::kMaxPlanes
staticconstexpr

Definition at line 32 of file SkYUVAPixmaps.h.


The documentation for this class was generated from the following files: