• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkImageInfo_DEFINED
9 #define SkImageInfo_DEFINED
10 
11 #include "include/core/SkAlphaType.h"
12 #include "include/core/SkColorType.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkRefCnt.h"
15 #include "include/core/SkSize.h"
16 #include "include/private/base/SkAPI.h"
17 #include "include/private/base/SkDebug.h"
18 #include "include/private/base/SkMath.h"
19 #include "include/private/base/SkTFitsIn.h"
20 
21 #include <cstddef>
22 #include <cstdint>
23 #include <utility>
24 
25 class SkColorSpace;
26 
27 /** Returns the number of bytes required to store a pixel, including unused padding.
28     Returns zero if ct is kUnknown_SkColorType or invalid.
29 
30     @return    bytes per pixel
31 */
32 SK_API int SkColorTypeBytesPerPixel(SkColorType ct);
33 
34 /** Returns true if SkColorType always decodes alpha to 1.0, making the pixel
35     fully opaque. If true, SkColorType does not reserve bits to encode alpha.
36 
37     @return    true if alpha is always set to 1.0
38 */
39 SK_API bool SkColorTypeIsAlwaysOpaque(SkColorType ct);
40 
41 /** Returns true if canonical can be set to a valid SkAlphaType for colorType. If
42     there is more than one valid canonical SkAlphaType, set to alphaType, if valid.
43     If true is returned and canonical is not nullptr, store valid SkAlphaType.
44 
45     Returns false only if alphaType is kUnknown_SkAlphaType, color type is not
46     kUnknown_SkColorType, and SkColorType is not always opaque. If false is returned,
47     canonical is ignored.
48 
49     @param canonical  storage for SkAlphaType
50     @return           true if valid SkAlphaType can be associated with colorType
51 */
52 SK_API bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
53                                          SkAlphaType* canonical = nullptr);
54 
55 /** \enum SkImageInfo::SkYUVColorSpace
56     Describes color range of YUV pixels. The color mapping from YUV to RGB varies
57     depending on the source. YUV pixels may be generated by JPEG images, standard
58     video streams, or high definition video streams. Each has its own mapping from
59     YUV to RGB.
60 
61     JPEG YUV values encode the full range of 0 to 255 for all three components.
62     Video YUV values often range from 16 to 235 for Y and from 16 to 240 for U and V (limited).
63     Details of encoding and conversion to RGB are described in YCbCr color space.
64 
65     The identity colorspace exists to provide a utility mapping from Y to R, U to G and V to B.
66     It can be used to visualize the YUV planes or to explicitly post process the YUV channels.
67 */
68 enum SkYUVColorSpace : int {
69     kJPEG_Full_SkYUVColorSpace,                 //!< describes full range
70     kRec601_Limited_SkYUVColorSpace,            //!< describes SDTV range
71     kRec709_Full_SkYUVColorSpace,               //!< describes HDTV range
72     kRec709_Limited_SkYUVColorSpace,
73     kBT2020_8bit_Full_SkYUVColorSpace,          //!< describes UHDTV range, non-constant-luminance
74     kBT2020_8bit_Limited_SkYUVColorSpace,
75     kBT2020_10bit_Full_SkYUVColorSpace,
76     kBT2020_10bit_Limited_SkYUVColorSpace,
77     kBT2020_12bit_Full_SkYUVColorSpace,
78     kBT2020_12bit_Limited_SkYUVColorSpace,
79     kIdentity_SkYUVColorSpace,                  //!< maps Y->R, U->G, V->B
80 
81     kLastEnum_SkYUVColorSpace = kIdentity_SkYUVColorSpace, //!< last valid value
82 
83     // Legacy (deprecated) names:
84     kJPEG_SkYUVColorSpace = kJPEG_Full_SkYUVColorSpace,
85     kRec601_SkYUVColorSpace = kRec601_Limited_SkYUVColorSpace,
86     kRec709_SkYUVColorSpace = kRec709_Limited_SkYUVColorSpace,
87     kBT2020_SkYUVColorSpace = kBT2020_8bit_Limited_SkYUVColorSpace,
88 };
89 
90 /** \struct SkColorInfo
91     Describes pixel and encoding. SkImageInfo can be created from SkColorInfo by
92     providing dimensions.
93 
94     It encodes how pixel bits describe alpha, transparency; color components red, blue,
95     and green; and SkColorSpace, the range and linearity of colors.
96 */
97 class SK_API SkColorInfo {
98 public:
99     /** Creates an SkColorInfo with kUnknown_SkColorType, kUnknown_SkAlphaType,
100         and no SkColorSpace.
101 
102         @return  empty SkImageInfo
103     */
104     SkColorInfo();
105     ~SkColorInfo();
106 
107     /** Creates SkColorInfo from SkColorType ct, SkAlphaType at, and optionally SkColorSpace cs.
108 
109         If SkColorSpace cs is nullptr and SkColorInfo is part of drawing source: SkColorSpace
110         defaults to sRGB, mapping into SkSurface SkColorSpace.
111 
112         Parameters are not validated to see if their values are legal, or that the
113         combination is supported.
114         @return        created SkColorInfo
115     */
116     SkColorInfo(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs);
117 
118     SkColorInfo(const SkColorInfo&);
119     SkColorInfo(SkColorInfo&&);
120 
121     SkColorInfo& operator=(const SkColorInfo&);
122     SkColorInfo& operator=(SkColorInfo&&);
123 
124     SkColorSpace* colorSpace() const;
125     sk_sp<SkColorSpace> refColorSpace() const;
colorType()126     SkColorType colorType() const { return fColorType; }
alphaType()127     SkAlphaType alphaType() const { return fAlphaType; }
128 
isOpaque()129     bool isOpaque() const {
130         return SkAlphaTypeIsOpaque(fAlphaType)
131             || SkColorTypeIsAlwaysOpaque(fColorType);
132     }
133 
134     bool gammaCloseToSRGB() const;
135 
136     /** Does other represent the same color type, alpha type, and color space? */
137     bool operator==(const SkColorInfo& other) const;
138 
139     /** Does other represent a different color type, alpha type, or color space? */
140     bool operator!=(const SkColorInfo& other) const;
141 
142     /** Creates SkColorInfo with same SkColorType, SkColorSpace, with SkAlphaType set
143         to newAlphaType.
144 
145         Created SkColorInfo contains newAlphaType even if it is incompatible with
146         SkColorType, in which case SkAlphaType in SkColorInfo is ignored.
147     */
148     SkColorInfo makeAlphaType(SkAlphaType newAlphaType) const;
149 
150     /** Creates new SkColorInfo with same SkAlphaType, SkColorSpace, with SkColorType
151         set to newColorType.
152     */
153     SkColorInfo makeColorType(SkColorType newColorType) const;
154 
155     /** Creates SkColorInfo with same SkAlphaType, SkColorType, with SkColorSpace
156         set to cs. cs may be nullptr.
157     */
158     SkColorInfo makeColorSpace(sk_sp<SkColorSpace> cs) const;
159 
160     /** Returns number of bytes per pixel required by SkColorType.
161         Returns zero if colorType() is kUnknown_SkColorType.
162 
163         @return  bytes in pixel
164 
165         example: https://fiddle.skia.org/c/@ImageInfo_bytesPerPixel
166     */
167     int bytesPerPixel() const;
168 
169     /** Returns bit shift converting row bytes to row pixels.
170         Returns zero for kUnknown_SkColorType.
171 
172         @return  one of: 0, 1, 2, 3, 4; left shift to convert pixels to bytes
173 
174         example: https://fiddle.skia.org/c/@ImageInfo_shiftPerPixel
175     */
176     int shiftPerPixel() const;
177 
178 private:
179     sk_sp<SkColorSpace> fColorSpace;
180     SkColorType fColorType = kUnknown_SkColorType;
181     SkAlphaType fAlphaType = kUnknown_SkAlphaType;
182 };
183 
184 /** \struct SkImageInfo
185     Describes pixel dimensions and encoding. SkBitmap, SkImage, PixMap, and SkSurface
186     can be created from SkImageInfo. SkImageInfo can be retrieved from SkBitmap and
187     SkPixmap, but not from SkImage and SkSurface. For example, SkImage and SkSurface
188     implementations may defer pixel depth, so may not completely specify SkImageInfo.
189 
190     SkImageInfo contains dimensions, the pixel integral width and height. It encodes
191     how pixel bits describe alpha, transparency; color components red, blue,
192     and green; and SkColorSpace, the range and linearity of colors.
193 */
194 struct SK_API SkImageInfo {
195 public:
196 
197     /** Creates an empty SkImageInfo with kUnknown_SkColorType, kUnknown_SkAlphaType,
198         a width and height of zero, and no SkColorSpace.
199 
200         @return  empty SkImageInfo
201     */
202     SkImageInfo() = default;
203 
204     /** Creates SkImageInfo from integral dimensions width and height, SkColorType ct,
205         SkAlphaType at, and optionally SkColorSpace cs.
206 
207         If SkColorSpace cs is nullptr and SkImageInfo is part of drawing source: SkColorSpace
208         defaults to sRGB, mapping into SkSurface SkColorSpace.
209 
210         Parameters are not validated to see if their values are legal, or that the
211         combination is supported.
212 
213         @param width   pixel column count; must be zero or greater
214         @param height  pixel row count; must be zero or greater
215         @param cs      range of colors; may be nullptr
216         @return        created SkImageInfo
217     */
218     static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at);
219     static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
220                             sk_sp<SkColorSpace> cs);
221     static SkImageInfo Make(SkISize dimensions, SkColorType ct, SkAlphaType at);
222     static SkImageInfo Make(SkISize dimensions, SkColorType ct, SkAlphaType at,
223                             sk_sp<SkColorSpace> cs);
224 
225     /** Creates SkImageInfo from integral dimensions and SkColorInfo colorInfo,
226 
227         Parameters are not validated to see if their values are legal, or that the
228         combination is supported.
229 
230         @param dimensions   pixel column and row count; must be zeros or greater
231         @param SkColorInfo  the pixel encoding consisting of SkColorType, SkAlphaType, and
232                             SkColorSpace (which may be nullptr)
233         @return        created SkImageInfo
234     */
MakeSkImageInfo235     static SkImageInfo Make(SkISize dimensions, const SkColorInfo& colorInfo) {
236         return SkImageInfo(dimensions, colorInfo);
237     }
MakeSkImageInfo238     static SkImageInfo Make(SkISize dimensions, SkColorInfo&& colorInfo) {
239         return SkImageInfo(dimensions, std::move(colorInfo));
240     }
241 
242     /** Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType,
243         SkAlphaType at, and optionally SkColorSpace cs. kN32_SkColorType will equal either
244         kBGRA_8888_SkColorType or kRGBA_8888_SkColorType, whichever is optimal.
245 
246         If SkColorSpace cs is nullptr and SkImageInfo is part of drawing source: SkColorSpace
247         defaults to sRGB, mapping into SkSurface SkColorSpace.
248 
249         Parameters are not validated to see if their values are legal, or that the
250         combination is supported.
251 
252         @param width   pixel column count; must be zero or greater
253         @param height  pixel row count; must be zero or greater
254         @param cs      range of colors; may be nullptr
255         @return        created SkImageInfo
256     */
257     static SkImageInfo MakeN32(int width, int height, SkAlphaType at);
258     static SkImageInfo MakeN32(int width, int height, SkAlphaType at, sk_sp<SkColorSpace> cs);
259 
260     /** Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType,
261         SkAlphaType at, with sRGB SkColorSpace.
262 
263         Parameters are not validated to see if their values are legal, or that the
264         combination is supported.
265 
266         @param width   pixel column count; must be zero or greater
267         @param height  pixel row count; must be zero or greater
268         @return        created SkImageInfo
269 
270         example: https://fiddle.skia.org/c/@ImageInfo_MakeS32
271     */
272     static SkImageInfo MakeS32(int width, int height, SkAlphaType at);
273 
274     /** Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType,
275         kPremul_SkAlphaType, with optional SkColorSpace.
276 
277         If SkColorSpace cs is nullptr and SkImageInfo is part of drawing source: SkColorSpace
278         defaults to sRGB, mapping into SkSurface SkColorSpace.
279 
280         Parameters are not validated to see if their values are legal, or that the
281         combination is supported.
282 
283         @param width   pixel column count; must be zero or greater
284         @param height  pixel row count; must be zero or greater
285         @param cs      range of colors; may be nullptr
286         @return        created SkImageInfo
287     */
288     static SkImageInfo MakeN32Premul(int width, int height);
289     static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs);
290 
291     /** Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType,
292         kPremul_SkAlphaType, with SkColorSpace set to nullptr.
293 
294         If SkImageInfo is part of drawing source: SkColorSpace defaults to sRGB, mapping
295         into SkSurface SkColorSpace.
296 
297         Parameters are not validated to see if their values are legal, or that the
298         combination is supported.
299 
300         @param dimensions  width and height, each must be zero or greater
301         @param cs          range of colors; may be nullptr
302         @return            created SkImageInfo
303     */
304     static SkImageInfo MakeN32Premul(SkISize dimensions);
305     static SkImageInfo MakeN32Premul(SkISize dimensions, sk_sp<SkColorSpace> cs);
306 
307     /** Creates SkImageInfo from integral dimensions width and height, kAlpha_8_SkColorType,
308         kPremul_SkAlphaType, with SkColorSpace set to nullptr.
309 
310         @param width   pixel column count; must be zero or greater
311         @param height  pixel row count; must be zero or greater
312         @return        created SkImageInfo
313     */
314     static SkImageInfo MakeA8(int width, int height);
315     /** Creates SkImageInfo from integral dimensions, kAlpha_8_SkColorType,
316         kPremul_SkAlphaType, with SkColorSpace set to nullptr.
317 
318         @param dimensions   pixel row and column count; must be zero or greater
319         @return             created SkImageInfo
320     */
321     static SkImageInfo MakeA8(SkISize dimensions);
322 
323     /** Creates SkImageInfo from integral dimensions width and height, kUnknown_SkColorType,
324         kUnknown_SkAlphaType, with SkColorSpace set to nullptr.
325 
326         Returned SkImageInfo as part of source does not draw, and as part of destination
327         can not be drawn to.
328 
329         @param width   pixel column count; must be zero or greater
330         @param height  pixel row count; must be zero or greater
331         @return        created SkImageInfo
332     */
333     static SkImageInfo MakeUnknown(int width, int height);
334 
335     /** Creates SkImageInfo from integral dimensions width and height set to zero,
336         kUnknown_SkColorType, kUnknown_SkAlphaType, with SkColorSpace set to nullptr.
337 
338         Returned SkImageInfo as part of source does not draw, and as part of destination
339         can not be drawn to.
340 
341         @return  created SkImageInfo
342     */
MakeUnknownSkImageInfo343     static SkImageInfo MakeUnknown() {
344         return MakeUnknown(0, 0);
345     }
346 
347     /** Returns pixel count in each row.
348 
349         @return  pixel width
350     */
widthSkImageInfo351     int width() const { return fDimensions.width(); }
352 
353     /** Returns pixel row count.
354 
355         @return  pixel height
356     */
heightSkImageInfo357     int height() const { return fDimensions.height(); }
358 
colorTypeSkImageInfo359     SkColorType colorType() const { return fColorInfo.colorType(); }
360 
alphaTypeSkImageInfo361     SkAlphaType alphaType() const { return fColorInfo.alphaType(); }
362 
363     /** Returns SkColorSpace, the range of colors. The reference count of
364         SkColorSpace is unchanged. The returned SkColorSpace is immutable.
365 
366         @return  SkColorSpace, or nullptr
367     */
368     SkColorSpace* colorSpace() const;
369 
370     /** Returns smart pointer to SkColorSpace, the range of colors. The smart pointer
371         tracks the number of objects sharing this SkColorSpace reference so the memory
372         is released when the owners destruct.
373 
374         The returned SkColorSpace is immutable.
375 
376         @return  SkColorSpace wrapped in a smart pointer
377     */
378     sk_sp<SkColorSpace> refColorSpace() const;
379 
380     /** Returns if SkImageInfo describes an empty area of pixels by checking if either
381         width or height is zero or smaller.
382 
383         @return  true if either dimension is zero or smaller
384     */
isEmptySkImageInfo385     bool isEmpty() const { return fDimensions.isEmpty(); }
386 
387     /** Returns the dimensionless SkColorInfo that represents the same color type,
388         alpha type, and color space as this SkImageInfo.
389      */
colorInfoSkImageInfo390     const SkColorInfo& colorInfo() const { return fColorInfo; }
391 
392     /** Returns true if SkAlphaType is set to hint that all pixels are opaque; their
393         alpha value is implicitly or explicitly 1.0. If true, and all pixels are
394         not opaque, Skia may draw incorrectly.
395 
396         Does not check if SkColorType allows alpha, or if any pixel value has
397         transparency.
398 
399         @return  true if SkAlphaType is kOpaque_SkAlphaType
400     */
isOpaqueSkImageInfo401     bool isOpaque() const { return fColorInfo.isOpaque(); }
402 
403     /** Returns SkISize { width(), height() }.
404 
405         @return  integral size of width() and height()
406     */
dimensionsSkImageInfo407     SkISize dimensions() const { return fDimensions; }
408 
409     /** Returns SkIRect { 0, 0, width(), height() }.
410 
411         @return  integral rectangle from origin to width() and height()
412     */
boundsSkImageInfo413     SkIRect bounds() const { return SkIRect::MakeSize(fDimensions); }
414 
415     /** Returns true if associated SkColorSpace is not nullptr, and SkColorSpace gamma
416         is approximately the same as sRGB.
417         This includes the
418 
419         @return  true if SkColorSpace gamma is approximately the same as sRGB
420     */
gammaCloseToSRGBSkImageInfo421     bool gammaCloseToSRGB() const { return fColorInfo.gammaCloseToSRGB(); }
422 
423     /** Creates SkImageInfo with the same SkColorType, SkColorSpace, and SkAlphaType,
424         with dimensions set to width and height.
425 
426         @param newWidth   pixel column count; must be zero or greater
427         @param newHeight  pixel row count; must be zero or greater
428         @return           created SkImageInfo
429     */
makeWHSkImageInfo430     SkImageInfo makeWH(int newWidth, int newHeight) const {
431         return Make({newWidth, newHeight}, fColorInfo);
432     }
433 
434     /** Creates SkImageInfo with the same SkColorType, SkColorSpace, and SkAlphaType,
435         with dimensions set to newDimensions.
436 
437         @param newSize   pixel column and row count; must be zero or greater
438         @return          created SkImageInfo
439     */
makeDimensionsSkImageInfo440     SkImageInfo makeDimensions(SkISize newSize) const {
441         return Make(newSize, fColorInfo);
442     }
443 
444     /** Creates SkImageInfo with same SkColorType, SkColorSpace, width, and height,
445         with SkAlphaType set to newAlphaType.
446 
447         Created SkImageInfo contains newAlphaType even if it is incompatible with
448         SkColorType, in which case SkAlphaType in SkImageInfo is ignored.
449 
450         @return              created SkImageInfo
451     */
makeAlphaTypeSkImageInfo452     SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const {
453         return Make(fDimensions, fColorInfo.makeAlphaType(newAlphaType));
454     }
455 
456     /** Creates SkImageInfo with same SkAlphaType, SkColorSpace, width, and height,
457         with SkColorType set to newColorType.
458 
459         @return              created SkImageInfo
460     */
makeColorTypeSkImageInfo461     SkImageInfo makeColorType(SkColorType newColorType) const {
462         return Make(fDimensions, fColorInfo.makeColorType(newColorType));
463     }
464 
465     /** Creates SkImageInfo with same SkAlphaType, SkColorType, width, and height,
466         with SkColorSpace set to cs.
467 
468         @param cs  range of colors; may be nullptr
469         @return    created SkImageInfo
470     */
471     SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const;
472 
473     /** Returns number of bytes per pixel required by SkColorType.
474         Returns zero if colorType( is kUnknown_SkColorType.
475 
476         @return  bytes in pixel
477     */
bytesPerPixelSkImageInfo478     int bytesPerPixel() const { return fColorInfo.bytesPerPixel(); }
479 
480     /** Returns bit shift converting row bytes to row pixels.
481         Returns zero for kUnknown_SkColorType.
482 
483         @return  one of: 0, 1, 2, 3; left shift to convert pixels to bytes
484     */
shiftPerPixelSkImageInfo485     int shiftPerPixel() const { return fColorInfo.shiftPerPixel(); }
486 
487     /** Returns minimum bytes per row, computed from pixel width() and SkColorType, which
488         specifies bytesPerPixel(). SkBitmap maximum value for row bytes must fit
489         in 31 bits.
490 
491         @return  width() times bytesPerPixel() as unsigned 64-bit integer
492     */
minRowBytes64SkImageInfo493     uint64_t minRowBytes64() const {
494         return (uint64_t)sk_64_mul(this->width(), this->bytesPerPixel());
495     }
496 
497     /** Returns minimum bytes per row, computed from pixel width() and SkColorType, which
498         specifies bytesPerPixel(). SkBitmap maximum value for row bytes must fit
499         in 31 bits.
500 
501         @return  width() times bytesPerPixel() as size_t
502     */
minRowBytesSkImageInfo503     size_t minRowBytes() const {
504         uint64_t minRowBytes = this->minRowBytes64();
505         if (!SkTFitsIn<int32_t>(minRowBytes)) {
506             return 0;
507         }
508         return (size_t)minRowBytes;
509     }
510 
511     /** Returns byte offset of pixel from pixel base address.
512 
513         Asserts in debug build if x or y is outside of bounds. Does not assert if
514         rowBytes is smaller than minRowBytes(), even though result may be incorrect.
515 
516         @param x         column index, zero or greater, and less than width()
517         @param y         row index, zero or greater, and less than height()
518         @param rowBytes  size of pixel row or larger
519         @return          offset within pixel array
520 
521         example: https://fiddle.skia.org/c/@ImageInfo_computeOffset
522     */
523     size_t computeOffset(int x, int y, size_t rowBytes) const;
524 
525     /** Compares SkImageInfo with other, and returns true if width, height, SkColorType,
526         SkAlphaType, and SkColorSpace are equivalent.
527 
528         @param other  SkImageInfo to compare
529         @return       true if SkImageInfo equals other
530     */
531     bool operator==(const SkImageInfo& other) const {
532         return fDimensions == other.fDimensions && fColorInfo == other.fColorInfo;
533     }
534 
535     /** Compares SkImageInfo with other, and returns true if width, height, SkColorType,
536         SkAlphaType, and SkColorSpace are not equivalent.
537 
538         @param other  SkImageInfo to compare
539         @return       true if SkImageInfo is not equal to other
540     */
541     bool operator!=(const SkImageInfo& other) const {
542         return !(*this == other);
543     }
544 
545     /** Returns storage required by pixel array, given SkImageInfo dimensions, SkColorType,
546         and rowBytes. rowBytes is assumed to be at least as large as minRowBytes().
547 
548         Returns zero if height is zero.
549         Returns SIZE_MAX if answer exceeds the range of size_t.
550 
551         @param rowBytes  size of pixel row or larger
552         @return          memory required by pixel buffer
553 
554         example: https://fiddle.skia.org/c/@ImageInfo_computeByteSize
555     */
556     size_t computeByteSize(size_t rowBytes) const;
557 
558     /** Returns storage required by pixel array, given SkImageInfo dimensions, and
559         SkColorType. Uses minRowBytes() to compute bytes for pixel row.
560 
561         Returns zero if height is zero.
562         Returns SIZE_MAX if answer exceeds the range of size_t.
563 
564         @return  least memory required by pixel buffer
565     */
computeMinByteSizeSkImageInfo566     size_t computeMinByteSize() const {
567         return this->computeByteSize(this->minRowBytes());
568     }
569 
570     /** Returns true if byteSize equals SIZE_MAX. computeByteSize() and
571         computeMinByteSize() return SIZE_MAX if size_t can not hold buffer size.
572 
573         @param byteSize  result of computeByteSize() or computeMinByteSize()
574         @return          true if computeByteSize() or computeMinByteSize() result exceeds size_t
575     */
ByteSizeOverflowedSkImageInfo576     static bool ByteSizeOverflowed(size_t byteSize) {
577         return SIZE_MAX == byteSize;
578     }
579 
580     /** Returns true if rowBytes is valid for this SkImageInfo.
581 
582         @param rowBytes  size of pixel row including padding
583         @return          true if rowBytes is large enough to contain pixel row and is properly
584                          aligned
585     */
validRowBytesSkImageInfo586     bool validRowBytes(size_t rowBytes) const {
587         if (rowBytes < this->minRowBytes64()) {
588             return false;
589         }
590         int shift = this->shiftPerPixel();
591         size_t alignedRowBytes = rowBytes >> shift << shift;
592         return alignedRowBytes == rowBytes;
593     }
594 
595     /** Creates an empty SkImageInfo with kUnknown_SkColorType, kUnknown_SkAlphaType,
596         a width and height of zero, and no SkColorSpace.
597     */
resetSkImageInfo598     void reset() { *this = {}; }
599 
600     /** Asserts if internal values are illegal or inconsistent. Only available if
601         SK_DEBUG is defined at compile time.
602     */
603     SkDEBUGCODE(void validate() const;)
604 
605 private:
606     SkColorInfo fColorInfo;
607     SkISize fDimensions = {0, 0};
608 
SkImageInfoSkImageInfo609     SkImageInfo(SkISize dimensions, const SkColorInfo& colorInfo)
610             : fColorInfo(colorInfo), fDimensions(dimensions) {}
611 
SkImageInfoSkImageInfo612     SkImageInfo(SkISize dimensions, SkColorInfo&& colorInfo)
613             : fColorInfo(std::move(colorInfo)), fDimensions(dimensions) {}
614 };
615 
616 #endif
617