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 | |
msarett | 23c5110 | 2016-05-27 07:39:02 -0700 | [diff] [blame] | 11 | #include "SkColorSpace.h" |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 12 | #include "SkMath.h" |
halcanary | f622a6c | 2014-10-24 12:54:53 -0700 | [diff] [blame] | 13 | #include "SkRect.h" |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 14 | #include "SkSize.h" |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 16 | class SkReadBuffer; |
halcanary | f622a6c | 2014-10-24 12:54:53 -0700 | [diff] [blame] | 17 | class SkWriteBuffer; |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 18 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 19 | /** |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 20 | * Describes how to interpret the alpha component of a pixel. |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 21 | */ |
| 22 | enum SkAlphaType { |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 23 | kUnknown_SkAlphaType, |
skia.committer@gmail.com | 73a5d53 | 2013-11-14 07:02:31 +0000 | [diff] [blame] | 24 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 25 | /** |
| 26 | * All pixels are stored as opaque. This differs slightly from kIgnore in |
| 27 | * that kOpaque has correct "opaque" values stored in the pixels, while |
| 28 | * kIgnore may not, but in both cases the caller should treat the pixels |
| 29 | * as opaque. |
| 30 | */ |
| 31 | kOpaque_SkAlphaType, |
skia.committer@gmail.com | 73a5d53 | 2013-11-14 07:02:31 +0000 | [diff] [blame] | 32 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 33 | /** |
| 34 | * All pixels have their alpha premultiplied in their color components. |
| 35 | * This is the natural format for the rendering target pixels. |
| 36 | */ |
| 37 | kPremul_SkAlphaType, |
skia.committer@gmail.com | 73a5d53 | 2013-11-14 07:02:31 +0000 | [diff] [blame] | 38 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 39 | /** |
| 40 | * All pixels have their color components stored without any regard to the |
| 41 | * alpha. e.g. this is the default configuration for PNG images. |
| 42 | * |
| 43 | * This alpha-type is ONLY supported for input images. Rendering cannot |
| 44 | * generate this on output. |
| 45 | */ |
| 46 | kUnpremul_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 | kLastEnum_SkAlphaType = kUnpremul_SkAlphaType |
| 49 | }; |
| 50 | |
| 51 | static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) { |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 52 | return kOpaque_SkAlphaType == at; |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 53 | } |
| 54 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 55 | static inline bool SkAlphaTypeIsValid(unsigned value) { |
| 56 | return value <= kLastEnum_SkAlphaType; |
| 57 | } |
| 58 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 59 | /////////////////////////////////////////////////////////////////////////////// |
| 60 | |
| 61 | /** |
| 62 | * Describes how to interpret the components of a pixel. |
reed | 6c6ddb8 | 2014-06-30 12:44:03 -0700 | [diff] [blame] | 63 | * |
| 64 | * kN32_SkColorType is an alias for whichever 32bit ARGB format is the "native" |
| 65 | * form for skia's blitters. Use this if you don't have a swizzle preference |
| 66 | * for 32bit pixels. |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 67 | */ |
| 68 | enum SkColorType { |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 69 | kUnknown_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 70 | kAlpha_8_SkColorType, |
| 71 | kRGB_565_SkColorType, |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 72 | kARGB_4444_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 73 | kRGBA_8888_SkColorType, |
| 74 | kBGRA_8888_SkColorType, |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 75 | kIndex_8_SkColorType, |
reed | 0c9b1a8 | 2015-03-17 17:44:06 -0700 | [diff] [blame] | 76 | kGray_8_SkColorType, |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 77 | kRGBA_F16_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 78 | |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 79 | kLastEnum_SkColorType = kRGBA_F16_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 80 | |
| 81 | #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 82 | kN32_SkColorType = kBGRA_8888_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 83 | #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 84 | kN32_SkColorType = kRGBA_8888_SkColorType, |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 85 | #else |
reed | 3b40ee6 | 2014-12-21 14:29:04 -0800 | [diff] [blame] | 86 | #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] | 87 | #endif |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
reed | 6d7cd1f | 2016-04-15 10:03:03 -0700 | [diff] [blame] | 90 | static int SkColorTypeBytesPerPixel(SkColorType ct) { |
reed | 9d453b0 | 2016-04-16 12:24:09 -0700 | [diff] [blame] | 91 | static const uint8_t gSize[] = { |
| 92 | 0, // Unknown |
| 93 | 1, // Alpha_8 |
| 94 | 2, // RGB_565 |
| 95 | 2, // ARGB_4444 |
| 96 | 4, // RGBA_8888 |
| 97 | 4, // BGRA_8888 |
| 98 | 1, // kIndex_8 |
| 99 | 1, // kGray_8 |
| 100 | 8, // kRGBA_F16 |
| 101 | }; |
| 102 | static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), |
| 103 | "size_mismatch_with_SkColorType_enum"); |
| 104 | |
| 105 | SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); |
| 106 | return gSize[ct]; |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 107 | } |
| 108 | |
reed | 8c3fd4f | 2016-04-15 06:59:38 -0700 | [diff] [blame] | 109 | static int SkColorTypeShiftPerPixel(SkColorType ct) { |
reed | 9d453b0 | 2016-04-16 12:24:09 -0700 | [diff] [blame] | 110 | static const uint8_t gShift[] = { |
| 111 | 0, // Unknown |
| 112 | 0, // Alpha_8 |
| 113 | 1, // RGB_565 |
| 114 | 1, // ARGB_4444 |
| 115 | 2, // RGBA_8888 |
| 116 | 2, // BGRA_8888 |
| 117 | 0, // kIndex_8 |
| 118 | 0, // kGray_8 |
| 119 | 3, // kRGBA_F16 |
| 120 | }; |
| 121 | static_assert(SK_ARRAY_COUNT(gShift) == (size_t)(kLastEnum_SkColorType + 1), |
| 122 | "size_mismatch_with_SkColorType_enum"); |
| 123 | |
| 124 | SkASSERT((size_t)ct < SK_ARRAY_COUNT(gShift)); |
| 125 | return gShift[ct]; |
reed | 8c3fd4f | 2016-04-15 06:59:38 -0700 | [diff] [blame] | 126 | } |
| 127 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 128 | static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { |
| 129 | return width * SkColorTypeBytesPerPixel(ct); |
| 130 | } |
| 131 | |
| 132 | static inline bool SkColorTypeIsValid(unsigned value) { |
| 133 | return value <= kLastEnum_SkColorType; |
| 134 | } |
| 135 | |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 136 | static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) { |
reed | 8c3fd4f | 2016-04-15 06:59:38 -0700 | [diff] [blame] | 137 | if (kUnknown_SkColorType == ct) { |
| 138 | return 0; |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 139 | } |
reed | 8c3fd4f | 2016-04-15 06:59:38 -0700 | [diff] [blame] | 140 | return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct)); |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 141 | } |
| 142 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 143 | /////////////////////////////////////////////////////////////////////////////// |
| 144 | |
| 145 | /** |
scroggo | 2fd0d14 | 2014-07-01 07:08:19 -0700 | [diff] [blame] | 146 | * Return true if alphaType is supported by colorType. If there is a canonical |
| 147 | * alphaType for this colorType, return it in canonical. |
| 148 | */ |
| 149 | bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, |
| 150 | SkAlphaType* canonical = NULL); |
| 151 | |
| 152 | /////////////////////////////////////////////////////////////////////////////// |
| 153 | |
| 154 | /** |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 155 | * Describes the color space a YUV pixel. |
| 156 | */ |
| 157 | enum SkYUVColorSpace { |
| 158 | /** Standard JPEG color space. */ |
| 159 | kJPEG_SkYUVColorSpace, |
| 160 | /** SDTV standard Rec. 601 color space. Uses "studio swing" [16, 235] color |
| 161 | range. See http://en.wikipedia.org/wiki/Rec._601 for details. */ |
| 162 | kRec601_SkYUVColorSpace, |
rileya | 1340039 | 2015-07-20 15:00:03 -0700 | [diff] [blame] | 163 | /** HDTV standard Rec. 709 color space. Uses "studio swing" [16, 235] color |
| 164 | range. See http://en.wikipedia.org/wiki/Rec._709 for details. */ |
| 165 | kRec709_SkYUVColorSpace, |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 166 | |
rileya | 1340039 | 2015-07-20 15:00:03 -0700 | [diff] [blame] | 167 | kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | /////////////////////////////////////////////////////////////////////////////// |
| 171 | |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 172 | enum class SkDestinationSurfaceColorMode { |
| 173 | kLegacy, |
| 174 | kGammaAndColorSpaceAware, |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 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() |
msarett | 23c5110 | 2016-05-27 07:39:02 -0700 | [diff] [blame] | 184 | : fColorSpace(nullptr) |
| 185 | , fWidth(0) |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 186 | , fHeight(0) |
| 187 | , fColorType(kUnknown_SkColorType) |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 188 | , fAlphaType(kUnknown_SkAlphaType) |
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, |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 192 | sk_sp<SkColorSpace> cs = nullptr) { |
| 193 | return SkImageInfo(width, height, ct, at, std::move(cs)); |
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, |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 200 | sk_sp<SkColorSpace> cs = nullptr) { |
| 201 | return Make(width, height, kN32_SkColorType, at, cs); |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 202 | } |
skia.committer@gmail.com | d77b3ec | 2014-01-15 07:01:43 +0000 | [diff] [blame] | 203 | |
reed | fbce71f | 2016-06-02 12:40:22 -0700 | [diff] [blame] | 204 | /** |
| 205 | * Create an ImageInfo marked as SRGB with N32 swizzle. |
| 206 | */ |
| 207 | static SkImageInfo MakeS32(int width, int height, SkAlphaType at); |
| 208 | |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 209 | /** |
| 210 | * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
| 211 | */ |
reed | dabe5d3 | 2016-06-21 10:28:14 -0700 | [diff] [blame] | 212 | static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr) { |
| 213 | return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, cs); |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static SkImageInfo MakeN32Premul(const SkISize& size) { |
| 217 | return MakeN32Premul(size.width(), size.height()); |
| 218 | } |
| 219 | |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 220 | static SkImageInfo MakeA8(int width, int height) { |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 221 | return Make(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr); |
commit-bot@chromium.org | 32678d9 | 2014-01-15 02:38:22 +0000 | [diff] [blame] | 222 | } |
skia.committer@gmail.com | d77b3ec | 2014-01-15 07:01:43 +0000 | [diff] [blame] | 223 | |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 224 | static SkImageInfo MakeUnknown(int width, int height) { |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 225 | return Make(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType, nullptr); |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 226 | } |
| 227 | |
reed | f252f64 | 2014-06-14 04:24:56 -0700 | [diff] [blame] | 228 | static SkImageInfo MakeUnknown() { |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 229 | return MakeUnknown(0, 0); |
reed | f252f64 | 2014-06-14 04:24:56 -0700 | [diff] [blame] | 230 | } |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 231 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 232 | int width() const { return fWidth; } |
| 233 | int height() const { return fHeight; } |
| 234 | SkColorType colorType() const { return fColorType; } |
| 235 | SkAlphaType alphaType() const { return fAlphaType; } |
msarett | 23c5110 | 2016-05-27 07:39:02 -0700 | [diff] [blame] | 236 | SkColorSpace* colorSpace() const { return fColorSpace.get(); } |
| 237 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 238 | bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } |
| 239 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 240 | bool isOpaque() const { |
| 241 | return SkAlphaTypeIsOpaque(fAlphaType); |
| 242 | } |
| 243 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 244 | SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 245 | SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 246 | |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 247 | bool gammaCloseToSRGB() const { |
| 248 | return fColorSpace && fColorSpace->gammaCloseToSRGB(); |
| 249 | } |
| 250 | |
reed | c77392e | 2014-06-02 13:07:26 -0700 | [diff] [blame] | 251 | /** |
| 252 | * Return a new ImageInfo with the same colortype and alphatype as this info, |
| 253 | * but with the specified width and height. |
| 254 | */ |
| 255 | SkImageInfo makeWH(int newWidth, int newHeight) const { |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 256 | return Make(newWidth, newHeight, fColorType, fAlphaType, fColorSpace); |
reed | c77392e | 2014-06-02 13:07:26 -0700 | [diff] [blame] | 257 | } |
| 258 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 259 | SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 260 | return Make(fWidth, fHeight, fColorType, newAlphaType, fColorSpace); |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | SkImageInfo makeColorType(SkColorType newColorType) const { |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 264 | return Make(fWidth, fHeight, newColorType, fAlphaType, fColorSpace); |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 265 | } |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 266 | |
msarett | 804b461 | 2016-06-09 11:03:45 -0700 | [diff] [blame] | 267 | SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const { |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 268 | return Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs)); |
msarett | 804b461 | 2016-06-09 11:03:45 -0700 | [diff] [blame] | 269 | } |
| 270 | |
reed | 8c3fd4f | 2016-04-15 06:59:38 -0700 | [diff] [blame] | 271 | int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } |
| 272 | |
| 273 | int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); } |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 274 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 275 | uint64_t minRowBytes64() const { |
| 276 | return sk_64_mul(fWidth, this->bytesPerPixel()); |
| 277 | } |
| 278 | |
mike@reedtribe.org | 169a0ed | 2014-02-11 02:20:17 +0000 | [diff] [blame] | 279 | size_t minRowBytes() const { |
Matt Sarett | 29121eb | 2016-10-17 14:32:46 -0400 | [diff] [blame] | 280 | uint64_t minRowBytes = this->minRowBytes64(); |
| 281 | if (!sk_64_isS32(minRowBytes)) { |
| 282 | return 0; |
| 283 | } |
| 284 | return sk_64_asS32(minRowBytes); |
mike@reedtribe.org | 169a0ed | 2014-02-11 02:20:17 +0000 | [diff] [blame] | 285 | } |
skia.committer@gmail.com | 8ed6443 | 2014-02-11 03:02:13 +0000 | [diff] [blame] | 286 | |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 287 | size_t computeOffset(int x, int y, size_t rowBytes) const { |
| 288 | SkASSERT((unsigned)x < (unsigned)fWidth); |
| 289 | SkASSERT((unsigned)y < (unsigned)fHeight); |
| 290 | return SkColorTypeComputeOffset(fColorType, x, y, rowBytes); |
| 291 | } |
| 292 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 293 | bool operator==(const SkImageInfo& other) const { |
msarett | 23c5110 | 2016-05-27 07:39:02 -0700 | [diff] [blame] | 294 | return fWidth == other.fWidth && fHeight == other.fHeight && |
| 295 | fColorType == other.fColorType && fAlphaType == other.fAlphaType && |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 296 | SkColorSpace::Equals(fColorSpace.get(), other.fColorSpace.get()); |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 297 | } |
| 298 | bool operator!=(const SkImageInfo& other) const { |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 299 | return !(*this == other); |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 300 | } |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 301 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 302 | void unflatten(SkReadBuffer&); |
| 303 | void flatten(SkWriteBuffer&) const; |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 304 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 305 | int64_t getSafeSize64(size_t rowBytes) const { |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 306 | if (0 == fHeight) { |
| 307 | return 0; |
| 308 | } |
Matt Sarett | 29121eb | 2016-10-17 14:32:46 -0400 | [diff] [blame] | 309 | return sk_64_mul(fHeight - 1, rowBytes) + sk_64_mul(fWidth, this->bytesPerPixel()); |
reed@google.com | 9230ea2 | 2013-12-09 22:01:03 +0000 | [diff] [blame] | 310 | } |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 311 | |
| 312 | size_t getSafeSize(size_t rowBytes) const { |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 313 | int64_t size = this->getSafeSize64(rowBytes); |
| 314 | if (!sk_64_isS32(size)) { |
| 315 | return 0; |
| 316 | } |
| 317 | return sk_64_asS32(size); |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | bool validRowBytes(size_t rowBytes) const { |
| 321 | uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
| 322 | return rowBytes >= rb; |
| 323 | } |
| 324 | |
msarett | 23c5110 | 2016-05-27 07:39:02 -0700 | [diff] [blame] | 325 | void reset() { |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 326 | fColorSpace = nullptr; |
msarett | 23c5110 | 2016-05-27 07:39:02 -0700 | [diff] [blame] | 327 | fWidth = 0; |
| 328 | fHeight = 0; |
| 329 | fColorType = kUnknown_SkColorType; |
| 330 | fAlphaType = kUnknown_SkAlphaType; |
msarett | 23c5110 | 2016-05-27 07:39:02 -0700 | [diff] [blame] | 331 | } |
| 332 | |
commit-bot@chromium.org | 61e96cd | 2014-02-11 18:21:45 +0000 | [diff] [blame] | 333 | SkDEBUGCODE(void validate() const;) |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 334 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 335 | private: |
msarett | 23c5110 | 2016-05-27 07:39:02 -0700 | [diff] [blame] | 336 | sk_sp<SkColorSpace> fColorSpace; |
reed | 7c74885 | 2014-11-10 08:57:21 -0800 | [diff] [blame] | 337 | int fWidth; |
| 338 | int fHeight; |
| 339 | SkColorType fColorType; |
| 340 | SkAlphaType fAlphaType; |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 341 | |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 342 | SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs) |
msarett | 23c5110 | 2016-05-27 07:39:02 -0700 | [diff] [blame] | 343 | : fColorSpace(std::move(cs)) |
| 344 | , fWidth(width) |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 345 | , fHeight(height) |
| 346 | , fColorType(ct) |
| 347 | , fAlphaType(at) |
| 348 | {} |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 349 | }; |
| 350 | |
reed@google.com | 3443fd8 | 2013-11-13 19:09:13 +0000 | [diff] [blame] | 351 | #endif |