reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 11 | #include "SkMath.h" |
halcanary | f622a6c | 2014-10-24 12:54:53 -0700 | [diff] [blame] | 12 | #include "SkRect.h" |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 13 | #include "SkSize.h" |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 14 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 15 | class SkReadBuffer; |
halcanary | f622a6c | 2014-10-24 12:54:53 -0700 | [diff] [blame] | 16 | class SkWriteBuffer; |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 17 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 18 | /** |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 19 | * This enum provides information about "how" an image will be used. For older GPUs that do not |
| 20 | * support non-power-of-2 tiling, some routines need to know this information before they create |
| 21 | * a texture. |
| 22 | */ |
| 23 | enum SkImageUsageType { |
| 24 | /* Image will not be tiled (regardless of filtering) */ |
| 25 | kUntiled_SkImageUsageType, |
| 26 | |
| 27 | /* Image will be tiled, but not filtered */ |
| 28 | kTiled_Unfiltered_SkImageUsageType, |
| 29 | |
| 30 | /* Image will be tiled and filtered */ |
| 31 | kTiled_Filtered_SkImageUsageType, |
| 32 | }; |
| 33 | |
| 34 | /** |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 35 | * Describes how to interpret the alpha compoent of a pixel. |
| 36 | */ |
| 37 | enum SkAlphaType { |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 38 | kUnknown_SkAlphaType, |
skia.committer@gmail.com | 73a5d53 | 2013-11-14 07:02:31 +0000 | [diff] [blame] | 39 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 40 | /** |
| 41 | * All pixels are stored as opaque. This differs slightly from kIgnore in |
| 42 | * that kOpaque has correct "opaque" values stored in the pixels, while |
| 43 | * kIgnore may not, but in both cases the caller should treat the pixels |
| 44 | * as opaque. |
| 45 | */ |
| 46 | kOpaque_SkAlphaType, |
skia.committer@gmail.com | 73a5d53 | 2013-11-14 07:02:31 +0000 | [diff] [blame] | 47 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 48 | /** |
| 49 | * All pixels have their alpha premultiplied in their color components. |
| 50 | * This is the natural format for the rendering target pixels. |
| 51 | */ |
| 52 | kPremul_SkAlphaType, |
skia.committer@gmail.com | 73a5d53 | 2013-11-14 07:02:31 +0000 | [diff] [blame] | 53 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 54 | /** |
| 55 | * All pixels have their color components stored without any regard to the |
| 56 | * alpha. e.g. this is the default configuration for PNG images. |
| 57 | * |
| 58 | * This alpha-type is ONLY supported for input images. Rendering cannot |
| 59 | * generate this on output. |
| 60 | */ |
| 61 | kUnpremul_SkAlphaType, |
skia.committer@gmail.com | 73a5d53 | 2013-11-14 07:02:31 +0000 | [diff] [blame] | 62 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 63 | kLastEnum_SkAlphaType = kUnpremul_SkAlphaType |
| 64 | }; |
| 65 | |
| 66 | static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) { |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 67 | return kOpaque_SkAlphaType == at; |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 68 | } |
| 69 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 70 | static inline bool SkAlphaTypeIsValid(unsigned value) { |
| 71 | return value <= kLastEnum_SkAlphaType; |
| 72 | } |
| 73 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 74 | /////////////////////////////////////////////////////////////////////////////// |
| 75 | |
| 76 | /** |
| 77 | * Describes how to interpret the components of a pixel. |
reed | 6c6ddb8 | 2014-06-30 12:44:03 -0700 | [diff] [blame] | 78 | * |
| 79 | * kN32_SkColorType is an alias for whichever 32bit ARGB format is the "native" |
| 80 | * form for skia's blitters. Use this if you don't have a swizzle preference |
| 81 | * for 32bit pixels. |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 82 | */ |
| 83 | enum SkColorType { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 84 | kUnknown_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 85 | kAlpha_8_SkColorType, |
| 86 | kRGB_565_SkColorType, |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 87 | kARGB_4444_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 88 | kRGBA_8888_SkColorType, |
| 89 | kBGRA_8888_SkColorType, |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 90 | kIndex_8_SkColorType, |
reed | 0c9b1a8 | 2015-03-17 17:44:06 -0700 | [diff] [blame] | 91 | kGray_8_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 92 | |
reed | 0c9b1a8 | 2015-03-17 17:44:06 -0700 | [diff] [blame] | 93 | kLastEnum_SkColorType = kGray_8_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 94 | |
| 95 | #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 96 | kN32_SkColorType = kBGRA_8888_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 97 | #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 98 | kN32_SkColorType = kRGBA_8888_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 99 | #else |
reed | 3b40ee6 | 2014-12-21 14:29:04 -0800 | [diff] [blame] | 100 | #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 101 | #endif |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static int SkColorTypeBytesPerPixel(SkColorType ct) { |
| 105 | static const uint8_t gSize[] = { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 106 | 0, // Unknown |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 107 | 1, // Alpha_8 |
| 108 | 2, // RGB_565 |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 109 | 2, // ARGB_4444 |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 110 | 4, // RGBA_8888 |
| 111 | 4, // BGRA_8888 |
| 112 | 1, // kIndex_8 |
reed | 0c9b1a8 | 2015-03-17 17:44:06 -0700 | [diff] [blame] | 113 | 1, // kGray_8 |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 114 | }; |
bungeman | 99fe822 | 2015-08-20 07:57:51 -0700 | [diff] [blame^] | 115 | static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), |
| 116 | "size_mismatch_with_SkColorType_enum"); |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 117 | |
| 118 | SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); |
| 119 | return gSize[ct]; |
| 120 | } |
| 121 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 122 | static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { |
| 123 | return width * SkColorTypeBytesPerPixel(ct); |
| 124 | } |
| 125 | |
| 126 | static inline bool SkColorTypeIsValid(unsigned value) { |
| 127 | return value <= kLastEnum_SkColorType; |
| 128 | } |
| 129 | |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 130 | static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) { |
| 131 | int shift = 0; |
| 132 | switch (SkColorTypeBytesPerPixel(ct)) { |
| 133 | case 4: shift = 2; break; |
| 134 | case 2: shift = 1; break; |
| 135 | case 1: shift = 0; break; |
| 136 | default: return 0; |
| 137 | } |
| 138 | return y * rowBytes + (x << shift); |
| 139 | } |
| 140 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 141 | /////////////////////////////////////////////////////////////////////////////// |
| 142 | |
| 143 | /** |
scroggo | 2fd0d14 | 2014-07-01 07:08:19 -0700 | [diff] [blame] | 144 | * Return true if alphaType is supported by colorType. If there is a canonical |
| 145 | * alphaType for this colorType, return it in canonical. |
| 146 | */ |
| 147 | bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, |
| 148 | SkAlphaType* canonical = NULL); |
| 149 | |
| 150 | /////////////////////////////////////////////////////////////////////////////// |
| 151 | |
| 152 | /** |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 153 | * Describes the color space a YUV pixel. |
| 154 | */ |
| 155 | enum SkYUVColorSpace { |
| 156 | /** Standard JPEG color space. */ |
| 157 | kJPEG_SkYUVColorSpace, |
| 158 | /** SDTV standard Rec. 601 color space. Uses "studio swing" [16, 235] color |
| 159 | range. See http://en.wikipedia.org/wiki/Rec._601 for details. */ |
| 160 | kRec601_SkYUVColorSpace, |
rileya | 1340039 | 2015-07-20 15:00:03 -0700 | [diff] [blame] | 161 | /** HDTV standard Rec. 709 color space. Uses "studio swing" [16, 235] color |
| 162 | range. See http://en.wikipedia.org/wiki/Rec._709 for details. */ |
| 163 | kRec709_SkYUVColorSpace, |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 164 | |
rileya | 1340039 | 2015-07-20 15:00:03 -0700 | [diff] [blame] | 165 | kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | /////////////////////////////////////////////////////////////////////////////// |
| 169 | |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 170 | enum SkColorProfileType { |
| 171 | kLinear_SkColorProfileType, |
| 172 | kSRGB_SkColorProfileType, |
| 173 | |
| 174 | kLastEnum_SkColorProfileType = kSRGB_SkColorProfileType |
| 175 | }; |
| 176 | |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 177 | /** |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 178 | * Describe an image's dimensions and pixel type. |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 179 | * Used for both src images and render-targets (surfaces). |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 180 | */ |
reed | 4181492 | 2015-01-30 14:54:38 -0800 | [diff] [blame] | 181 | struct SK_API SkImageInfo { |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 182 | public: |
| 183 | SkImageInfo() |
| 184 | : fWidth(0) |
| 185 | , fHeight(0) |
| 186 | , fColorType(kUnknown_SkColorType) |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 187 | , fAlphaType(kUnknown_SkAlphaType) |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 188 | , fProfileType(kLinear_SkColorProfileType) |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 189 | {} |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 190 | |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 191 | static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at, |
| 192 | SkColorProfileType pt = kLinear_SkColorProfileType) { |
| 193 | return SkImageInfo(width, height, ct, at, pt); |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Sets colortype to the native ARGB32 type. |
| 198 | */ |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 199 | static SkImageInfo MakeN32(int width, int height, SkAlphaType at, |
| 200 | SkColorProfileType pt = kLinear_SkColorProfileType) { |
| 201 | return SkImageInfo(width, height, kN32_SkColorType, at, pt); |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
| 206 | */ |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 207 | static SkImageInfo MakeN32Premul(int width, int height, |
| 208 | SkColorProfileType pt = kLinear_SkColorProfileType) { |
| 209 | return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType, pt); |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 210 | } |
skia.committer@gmail.com | d77b3ec | 2014-01-15 07:01:43 +0000 | [diff] [blame] | 211 | |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 212 | /** |
| 213 | * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
| 214 | */ |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 215 | static SkImageInfo MakeN32Premul(const SkISize& size, |
| 216 | SkColorProfileType pt = kLinear_SkColorProfileType) { |
| 217 | return MakeN32Premul(size.width(), size.height(), pt); |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 218 | } |
skia.committer@gmail.com | d77b3ec | 2014-01-15 07:01:43 +0000 | [diff] [blame] | 219 | |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 220 | static SkImageInfo MakeA8(int width, int height) { |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 221 | return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType, |
| 222 | kLinear_SkColorProfileType); |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 223 | } |
skia.committer@gmail.com | d77b3ec | 2014-01-15 07:01:43 +0000 | [diff] [blame] | 224 | |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 225 | static SkImageInfo MakeUnknown(int width, int height) { |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 226 | return SkImageInfo(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType, |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 227 | kLinear_SkColorProfileType); |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 228 | } |
| 229 | |
reed | f252f64 | 2014-06-14 04:24:56 -0700 | [diff] [blame] | 230 | static SkImageInfo MakeUnknown() { |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 231 | return SkImageInfo(); |
reed | f252f64 | 2014-06-14 04:24:56 -0700 | [diff] [blame] | 232 | } |
| 233 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 234 | int width() const { return fWidth; } |
| 235 | int height() const { return fHeight; } |
| 236 | SkColorType colorType() const { return fColorType; } |
| 237 | SkAlphaType alphaType() const { return fAlphaType; } |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 238 | SkColorProfileType profileType() const { return fProfileType; } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 239 | |
| 240 | bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } |
| 241 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 242 | bool isOpaque() const { |
| 243 | return SkAlphaTypeIsOpaque(fAlphaType); |
| 244 | } |
| 245 | |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 246 | bool isLinear() const { return kLinear_SkColorProfileType == fProfileType; } |
| 247 | bool isSRGB() const { return kSRGB_SkColorProfileType == fProfileType; } |
| 248 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 249 | SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 250 | SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 251 | |
reed | c77392e | 2014-06-02 13:07:26 -0700 | [diff] [blame] | 252 | /** |
| 253 | * Return a new ImageInfo with the same colortype and alphatype as this info, |
| 254 | * but with the specified width and height. |
| 255 | */ |
| 256 | SkImageInfo makeWH(int newWidth, int newHeight) const { |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 257 | return SkImageInfo::Make(newWidth, newHeight, fColorType, fAlphaType, fProfileType); |
reed | c77392e | 2014-06-02 13:07:26 -0700 | [diff] [blame] | 258 | } |
| 259 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 260 | SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 261 | return SkImageInfo::Make(fWidth, fHeight, fColorType, newAlphaType, fProfileType); |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | SkImageInfo makeColorType(SkColorType newColorType) const { |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 265 | return SkImageInfo::Make(fWidth, fHeight, newColorType, fAlphaType, fProfileType); |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 266 | } |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 267 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 268 | int bytesPerPixel() const { |
| 269 | return SkColorTypeBytesPerPixel(fColorType); |
| 270 | } |
| 271 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 272 | uint64_t minRowBytes64() const { |
| 273 | return sk_64_mul(fWidth, this->bytesPerPixel()); |
| 274 | } |
| 275 | |
mike@reedtribe.org | 169a0ed | 2014-02-11 02:20:17 +0000 | [diff] [blame] | 276 | size_t minRowBytes() const { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 277 | return (size_t)this->minRowBytes64(); |
mike@reedtribe.org | 169a0ed | 2014-02-11 02:20:17 +0000 | [diff] [blame] | 278 | } |
skia.committer@gmail.com | 8ed6443 | 2014-02-11 03:02:13 +0000 | [diff] [blame] | 279 | |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 280 | size_t computeOffset(int x, int y, size_t rowBytes) const { |
| 281 | SkASSERT((unsigned)x < (unsigned)fWidth); |
| 282 | SkASSERT((unsigned)y < (unsigned)fHeight); |
| 283 | return SkColorTypeComputeOffset(fColorType, x, y, rowBytes); |
| 284 | } |
| 285 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 286 | bool operator==(const SkImageInfo& other) const { |
| 287 | return 0 == memcmp(this, &other, sizeof(other)); |
| 288 | } |
| 289 | bool operator!=(const SkImageInfo& other) const { |
| 290 | return 0 != memcmp(this, &other, sizeof(other)); |
| 291 | } |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 292 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 293 | void unflatten(SkReadBuffer&); |
| 294 | void flatten(SkWriteBuffer&) const; |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 295 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 296 | int64_t getSafeSize64(size_t rowBytes) const { |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 297 | if (0 == fHeight) { |
| 298 | return 0; |
| 299 | } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 300 | return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel(); |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 301 | } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 302 | |
| 303 | size_t getSafeSize(size_t rowBytes) const { |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 304 | int64_t size = this->getSafeSize64(rowBytes); |
| 305 | if (!sk_64_isS32(size)) { |
| 306 | return 0; |
| 307 | } |
| 308 | return sk_64_asS32(size); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | bool validRowBytes(size_t rowBytes) const { |
| 312 | uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
| 313 | return rowBytes >= rb; |
| 314 | } |
| 315 | |
| 316 | SkDEBUGCODE(void validate() const;) |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 317 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 318 | private: |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 319 | int fWidth; |
| 320 | int fHeight; |
| 321 | SkColorType fColorType; |
| 322 | SkAlphaType fAlphaType; |
reed | c2e6827 | 2015-08-01 07:03:20 -0700 | [diff] [blame] | 323 | SkColorProfileType fProfileType; |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 324 | |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 325 | SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, SkColorProfileType pt) |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 326 | : fWidth(width) |
| 327 | , fHeight(height) |
| 328 | , fColorType(ct) |
| 329 | , fAlphaType(at) |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 330 | , fProfileType(pt) |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 331 | {} |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | #endif |