8 #ifndef SkImageInfo_DEFINED
9 #define SkImageInfo_DEFINED
11 #include "SkColorSpace.h"
46 kUnpremul_SkAlphaType,
48 kLastEnum_SkAlphaType = kUnpremul_SkAlphaType
51 static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) {
52 return kOpaque_SkAlphaType == at;
55 static inline bool SkAlphaTypeIsValid(
unsigned value) {
56 return value <= kLastEnum_SkAlphaType;
72 kARGB_4444_SkColorType,
73 kRGBA_8888_SkColorType,
74 kBGRA_8888_SkColorType,
77 kRGBA_F16_SkColorType,
79 kLastEnum_SkColorType = kRGBA_F16_SkColorType,
81 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
82 kN32_SkColorType = kBGRA_8888_SkColorType,
83 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
84 kN32_SkColorType = kRGBA_8888_SkColorType,
86 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order"
90 static int SkColorTypeBytesPerPixel(SkColorType ct) {
91 static const uint8_t gSize[] = {
102 static_assert(SK_ARRAY_COUNT(gSize) == (
size_t)(kLastEnum_SkColorType + 1),
103 "size_mismatch_with_SkColorType_enum");
105 SkASSERT((
size_t)ct < SK_ARRAY_COUNT(gSize));
109 static int SkColorTypeShiftPerPixel(SkColorType ct) {
110 static const uint8_t gShift[] = {
121 static_assert(SK_ARRAY_COUNT(gShift) == (
size_t)(kLastEnum_SkColorType + 1),
122 "size_mismatch_with_SkColorType_enum");
124 SkASSERT((
size_t)ct < SK_ARRAY_COUNT(gShift));
128 static inline size_t SkColorTypeMinRowBytes(SkColorType ct,
int width) {
129 return width * SkColorTypeBytesPerPixel(ct);
132 static inline bool SkColorTypeIsValid(
unsigned value) {
133 return value <= kLastEnum_SkColorType;
136 static inline size_t SkColorTypeComputeOffset(SkColorType ct,
int x,
int y,
size_t rowBytes) {
137 if (kUnknown_SkColorType == ct) {
140 return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct));
149 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
150 SkAlphaType* canonical = NULL);
157 enum SkYUVColorSpace {
159 kJPEG_SkYUVColorSpace,
162 kRec601_SkYUVColorSpace,
165 kRec709_SkYUVColorSpace,
167 kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace
172 enum class SkDestinationSurfaceColorMode {
174 kGammaAndColorSpaceAware,
184 : fColorSpace(
nullptr)
187 , fColorType(kUnknown_SkColorType)
188 , fAlphaType(kUnknown_SkAlphaType)
191 static SkImageInfo Make(
int width,
int height, SkColorType ct, SkAlphaType at,
193 return SkImageInfo(width, height, ct, at, std::move(cs));
201 return Make(width, height, kN32_SkColorType, at, cs);
207 static SkImageInfo MakeS32(
int width,
int height, SkAlphaType at);
213 return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, cs);
217 return MakeN32Premul(size.width(), size.height());
221 return Make(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType,
nullptr);
224 static SkImageInfo MakeUnknown(
int width,
int height) {
225 return Make(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType,
nullptr);
229 return MakeUnknown(0, 0);
232 int width()
const {
return fWidth; }
233 int height()
const {
return fHeight; }
234 SkColorType colorType()
const {
return fColorType; }
235 SkAlphaType alphaType()
const {
return fAlphaType; }
236 SkColorSpace* colorSpace()
const {
return fColorSpace.get(); }
239 bool isEmpty()
const {
return fWidth <= 0 || fHeight <= 0; }
241 bool isOpaque()
const {
242 return SkAlphaTypeIsOpaque(fAlphaType);
245 SkISize dimensions()
const {
return SkISize::Make(fWidth, fHeight); }
246 SkIRect bounds()
const {
return SkIRect::MakeWH(fWidth, fHeight); }
248 bool gammaCloseToSRGB()
const {
249 return fColorSpace && fColorSpace->gammaCloseToSRGB();
257 return Make(newWidth, newHeight, fColorType, fAlphaType, fColorSpace);
260 SkImageInfo makeAlphaType(SkAlphaType newAlphaType)
const {
261 return Make(fWidth, fHeight, fColorType, newAlphaType, fColorSpace);
264 SkImageInfo makeColorType(SkColorType newColorType)
const {
265 return Make(fWidth, fHeight, newColorType, fAlphaType, fColorSpace);
269 return Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs));
272 int bytesPerPixel()
const {
return SkColorTypeBytesPerPixel(fColorType); }
274 int shiftPerPixel()
const {
return SkColorTypeShiftPerPixel(fColorType); }
276 uint64_t minRowBytes64()
const {
277 return sk_64_mul(fWidth, this->bytesPerPixel());
280 size_t minRowBytes()
const {
281 uint64_t minRowBytes = this->minRowBytes64();
282 if (!sk_64_isS32(minRowBytes)) {
285 return sk_64_asS32(minRowBytes);
288 size_t computeOffset(
int x,
int y,
size_t rowBytes)
const {
289 SkASSERT((
unsigned)x < (
unsigned)fWidth);
290 SkASSERT((
unsigned)y < (
unsigned)fHeight);
291 return SkColorTypeComputeOffset(fColorType, x, y, rowBytes);
295 return fWidth == other.fWidth && fHeight == other.fHeight &&
296 fColorType == other.fColorType && fAlphaType == other.fAlphaType &&
300 return !(*
this == other);
303 void unflatten(SkReadBuffer&);
306 int64_t getSafeSize64(
size_t rowBytes)
const {
310 return sk_64_mul(fHeight - 1, rowBytes) + sk_64_mul(fWidth, this->bytesPerPixel());
313 size_t getSafeSize(
size_t rowBytes)
const {
314 int64_t size = this->getSafeSize64(rowBytes);
315 if (!sk_64_isS32(size)) {
318 return sk_64_asS32(size);
321 bool validRowBytes(
size_t rowBytes)
const {
322 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel());
323 return rowBytes >= rb;
327 fColorSpace =
nullptr;
330 fColorType = kUnknown_SkColorType;
331 fAlphaType = kUnknown_SkAlphaType;
334 SkDEBUGCODE(
void validate()
const;)
340 SkColorType fColorType;
341 SkAlphaType fAlphaType;
344 : fColorSpace(std::move(cs))
Definition: SkColorSpace.h:59
Describe an image's dimensions and pixel type.
Definition: SkImageInfo.h:181
static SkImageInfo MakeN32(int width, int height, SkAlphaType at, sk_sp< SkColorSpace > cs=nullptr)
Sets colortype to the native ARGB32 type.
Definition: SkImageInfo.h:199
static SkImageInfo MakeN32Premul(int width, int height, sk_sp< SkColorSpace > cs=nullptr)
Sets colortype to the native ARGB32 type, and the alphatype to premul.
Definition: SkImageInfo.h:212
Definition: SkWriteBuffer.h:27
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
SkImageInfo makeWH(int newWidth, int newHeight) const
Return a new ImageInfo with the same colortype and alphatype as this info, but with the specified wid...
Definition: SkImageInfo.h:256
static bool Equals(const SkColorSpace *src, const SkColorSpace *dst)
If both are null, we return true.