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 SkSourceGammaTreatment {
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(); }
238 bool isEmpty()
const {
return fWidth <= 0 || fHeight <= 0; }
240 bool isOpaque()
const {
241 return SkAlphaTypeIsOpaque(fAlphaType);
244 SkISize dimensions()
const {
return SkISize::Make(fWidth, fHeight); }
245 SkIRect bounds()
const {
return SkIRect::MakeWH(fWidth, fHeight); }
247 bool gammaCloseToSRGB()
const {
248 return fColorSpace && fColorSpace->gammaCloseToSRGB();
256 return Make(newWidth, newHeight, fColorType, fAlphaType, fColorSpace);
259 SkImageInfo makeAlphaType(SkAlphaType newAlphaType)
const {
260 return Make(fWidth, fHeight, fColorType, newAlphaType, fColorSpace);
263 SkImageInfo makeColorType(SkColorType newColorType)
const {
264 return Make(fWidth, fHeight, newColorType, fAlphaType, fColorSpace);
268 return Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs));
271 int bytesPerPixel()
const {
return SkColorTypeBytesPerPixel(fColorType); }
273 int shiftPerPixel()
const {
return SkColorTypeShiftPerPixel(fColorType); }
275 uint64_t minRowBytes64()
const {
276 return sk_64_mul(fWidth, this->bytesPerPixel());
279 size_t minRowBytes()
const {
280 return (
size_t)this->minRowBytes64();
283 size_t computeOffset(
int x,
int y,
size_t rowBytes)
const {
284 SkASSERT((
unsigned)x < (
unsigned)fWidth);
285 SkASSERT((
unsigned)y < (
unsigned)fHeight);
286 return SkColorTypeComputeOffset(fColorType, x, y, rowBytes);
290 return fWidth == other.fWidth && fHeight == other.fHeight &&
291 fColorType == other.fColorType && fAlphaType == other.fAlphaType &&
295 return !(*
this == other);
298 void unflatten(SkReadBuffer&);
301 int64_t getSafeSize64(
size_t rowBytes)
const {
305 return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel();
308 size_t getSafeSize(
size_t rowBytes)
const {
309 int64_t size = this->getSafeSize64(rowBytes);
310 if (!sk_64_isS32(size)) {
313 return sk_64_asS32(size);
316 bool validRowBytes(
size_t rowBytes)
const {
317 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel());
318 return rowBytes >= rb;
322 fColorSpace =
nullptr;
325 fColorType = kUnknown_SkColorType;
326 fAlphaType = kUnknown_SkAlphaType;
329 SkDEBUGCODE(
void validate()
const;)
335 SkColorType fColorType;
336 SkAlphaType fAlphaType;
339 : fColorSpace(std::move(cs))
349 static inline bool SkColorAndColorSpaceAreGammaCorrect(SkColorType ct,
SkColorSpace* cs) {
352 return (cs !=
nullptr) || kRGBA_F16_SkColorType == ct;
355 static inline bool SkImageInfoIsGammaCorrect(
const SkImageInfo& info) {
356 return SkColorAndColorSpaceAreGammaCorrect(info.colorType(), info.colorSpace());
Definition: SkColorSpace.h:16
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:26
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:255
static bool Equals(const SkColorSpace *src, const SkColorSpace *dst)
If both are null, we return true.