reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 SkPixmap_DEFINED |
| 9 | #define SkPixmap_DEFINED |
| 10 | |
reed | 7aefe03 | 2015-06-08 10:22:22 -0700 | [diff] [blame] | 11 | #include "SkColor.h" |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 12 | #include "SkFilterQuality.h" |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 13 | #include "SkImageInfo.h" |
| 14 | |
fmalita | 3a94c6c | 2016-02-04 13:09:59 -0800 | [diff] [blame] | 15 | class SkData; |
reed | 183b57f | 2015-06-05 14:33:17 -0700 | [diff] [blame] | 16 | struct SkMask; |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 17 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 18 | /** \class SkPixmap |
| 19 | SkPixmap provides a utility to pair SkImageInfo with pixels and row bytes. |
| 20 | SkPixmap is a low level class which provides convenience functions to access |
| 21 | raster destinations. SkCanvas can not draw SkPixmap, nor does SkPixmap provide |
| 22 | a direct drawing destination. |
| 23 | |
| 24 | Use SkBitmap to draw pixels referenced by SkPixmap; use SkSurface to draw into |
| 25 | pixels referenced by SkPixmap. |
| 26 | |
| 27 | SkPixmap does not try to manage the lifetime of the pixel memory. Use PixelRef |
| 28 | to manage pixel memory; PixelRef is safe across threads. |
| 29 | */ |
fmalita | 9a5d1ab | 2015-07-27 10:27:28 -0700 | [diff] [blame] | 30 | class SK_API SkPixmap { |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 31 | public: |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 32 | |
| 33 | /** Creates an empty SkPixmap without pixels, with kUnknown_SkColorType, with |
| 34 | kUnknown_SkAlphaType, and with a width and height of zero. Use |
| 35 | reset() to associate pixels, SkColorType, SkAlphaType, width, and height |
| 36 | after SkPixmap has been created. |
| 37 | |
| 38 | @return empty SkPixmap |
| 39 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 40 | SkPixmap() |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 41 | : fPixels(nullptr), fRowBytes(0), fInfo(SkImageInfo::MakeUnknown(0, 0)) |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 42 | {} |
| 43 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 44 | /** Creates SkPixmap from info width, height, SkAlphaType, and SkColorType. |
| 45 | addr points to pixels, or nullptr. rowBytes should be info.width() times |
| 46 | info.bytesPerPixel(), or larger. |
| 47 | |
| 48 | No parameter checking is performed; it is up to the caller to ensure that |
| 49 | addr and rowBytes agree with info. |
| 50 | |
| 51 | The memory lifetime of pixels is managed by the caller. When SkPixmap goes |
| 52 | out of scope, addr is unaffected. |
| 53 | |
| 54 | SkPixmap may be later modified by reset() to change its size, pixel type, or |
| 55 | storage. |
| 56 | |
| 57 | @param info width, height, SkAlphaType, SkColorType of SkImageInfo |
| 58 | @param addr pointer to pixels allocated by caller; may be nullptr |
| 59 | @param rowBytes size of one row of addr; width times pixel size, or larger |
| 60 | @return initialized SkPixmap |
| 61 | */ |
Mike Reed | 086a427 | 2017-07-18 10:53:11 -0400 | [diff] [blame] | 62 | SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) |
Mike Reed | 26e9ddd | 2017-07-17 17:33:53 -0400 | [diff] [blame] | 63 | : fPixels(addr), fRowBytes(rowBytes), fInfo(info) |
| 64 | {} |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 65 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 66 | /** Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to |
| 67 | kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType. |
| 68 | |
| 69 | The prior pixels are unaffected; it is up to the caller to release pixels |
| 70 | memory if desired. |
| 71 | */ |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 72 | void reset(); |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 73 | |
| 74 | /** Sets width, height, SkAlphaType, and SkColorType from info. |
| 75 | Sets pixel address from addr, which may be nullptr. |
| 76 | Sets row bytes from rowBytes, which should be info.width() times |
| 77 | info.bytesPerPixel(), or larger. |
| 78 | |
| 79 | Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is |
| 80 | too small to hold one row of pixels. |
| 81 | |
| 82 | The memory lifetime pixels are managed by the caller. When SkPixmap goes |
| 83 | out of scope, addr is unaffected. |
| 84 | |
| 85 | @param info width, height, SkAlphaType, SkColorType of SkImageInfo |
| 86 | @param addr pointer to pixels allocated by caller; may be nullptr |
| 87 | @param rowBytes size of one row of addr; width times pixel size, or larger |
| 88 | */ |
Mike Reed | 086a427 | 2017-07-18 10:53:11 -0400 | [diff] [blame] | 89 | void reset(const SkImageInfo& info, const void* addr, size_t rowBytes); |
reed | 183b57f | 2015-06-05 14:33:17 -0700 | [diff] [blame] | 90 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 91 | /** Changes SkColorSpace in SkImageInfo; preserves width, height, SkAlphaType, and |
| 92 | SkColorType in SkImage, and leaves pixel address and row bytes unchanged. |
| 93 | SkColorSpace reference count is incremented. |
| 94 | |
| 95 | @param colorSpace SkColorSpace moved to SkImageInfo |
| 96 | */ |
Cary Clark | ec2455b | 2017-09-05 09:42:43 -0400 | [diff] [blame] | 97 | void setColorSpace(sk_sp<SkColorSpace> colorSpace); |
msarett | 804b461 | 2016-06-09 11:03:45 -0700 | [diff] [blame] | 98 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 99 | /** Sets width, height, pixel address, and row bytes to SkMask properties, if SkMask |
| 100 | format is SkMask::kA8_Format; and returns true. Otherwise sets width, height, |
| 101 | row bytes to zero; pixel address to nullptr; SkColorType to kUnknown_SkColorType; |
| 102 | and SkAlphaType to kUnknown_SkAlphaType; and returns false. |
| 103 | |
| 104 | Failing to read the return value generates a compile time warning. |
| 105 | |
| 106 | @param mask SkMask containing pixels and dimensions |
| 107 | @return true if set to SkMask properties |
| 108 | */ |
Cary Clark | ec2455b | 2017-09-05 09:42:43 -0400 | [diff] [blame] | 109 | bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask); |
reed | 183b57f | 2015-06-05 14:33:17 -0700 | [diff] [blame] | 110 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 111 | /** Sets subset width, height, pixel address to intersection of SkPixmap with area, |
| 112 | if intersection is not empty; and return true. Otherwise, leave subset unchanged |
| 113 | and return false. |
| 114 | |
| 115 | Failing to read the return value generates a compile time warning. |
| 116 | |
| 117 | @param subset storage for width, height, pixel address of intersection |
| 118 | @param area bounds to intersect with SkPixmap |
| 119 | @return true if intersection of SkPixmap and area is not empty |
| 120 | */ |
reed | 183b57f | 2015-06-05 14:33:17 -0700 | [diff] [blame] | 121 | bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const; |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 122 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 123 | /** Returns width, height, SkAlphaType, SkColorType, and SkColorSpace. |
| 124 | |
| 125 | @return reference to ImageInfo |
| 126 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 127 | const SkImageInfo& info() const { return fInfo; } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 128 | |
| 129 | /** Returns row bytes, the interval from one pixel row to the next. Row bytes |
| 130 | is at least as large as |
| 131 | width() * info().bytesPerPixel(). |
| 132 | |
| 133 | It is up to the SkPixmap creator to ensure that row bytes is a useful value. |
| 134 | |
| 135 | @return byte length of pixel row |
| 136 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 137 | size_t rowBytes() const { return fRowBytes; } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 138 | |
| 139 | /** Returns pixel address, the base address corresponding to the pixel origin. |
| 140 | |
| 141 | It is up to the SkPixmap creator to ensure that pixel address is a useful value. |
| 142 | |
| 143 | @return pixel address |
| 144 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 145 | const void* addr() const { return fPixels; } |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 146 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 147 | /** Returns pixel count in each pixel row. Should be equal or less than: |
| 148 | rowBytes() / info.bytesPerPixel(). |
| 149 | |
| 150 | @return pixel width in SkImageInfo |
| 151 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 152 | int width() const { return fInfo.width(); } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 153 | |
| 154 | /** Returns pixel row count. |
| 155 | |
| 156 | @return pixel height in SkImageInfo |
| 157 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 158 | int height() const { return fInfo.height(); } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 159 | |
| 160 | /** Returns SkColorType, one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 161 | kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, |
| 162 | kBGRA_8888_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType. |
| 163 | |
| 164 | @return SkColorType in SkImageInfo |
| 165 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 166 | SkColorType colorType() const { return fInfo.colorType(); } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 167 | |
| 168 | /** Returns SkAlphaType, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 169 | kPremul_SkAlphaType, kUnpremul_SkAlphaType. |
| 170 | |
| 171 | @return SkAlphaType in SkImageInfo |
| 172 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 173 | SkAlphaType alphaType() const { return fInfo.alphaType(); } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 174 | |
| 175 | /** Returns SkColorSpace associated with SkImageInfo. |
| 176 | |
| 177 | @return SkColorSpace in SkImageInfo |
| 178 | */ |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 179 | SkColorSpace* colorSpace() const { return fInfo.colorSpace(); } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 180 | |
| 181 | /** Returns true if SkAlphaType is kOpaque_SkAlphaType. |
| 182 | Does not check if SkColorType allows alpha, or alpha in pixel values. |
| 183 | |
| 184 | @return true if SkImageInfo has opaque SkAlphaType |
| 185 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 186 | bool isOpaque() const { return fInfo.isOpaque(); } |
| 187 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 188 | /** Returns SkIRect |
| 189 | { 0, 0, width(), height() }. |
| 190 | |
| 191 | @return integral rectangle from origin to width() and height() |
| 192 | */ |
reed | ad7ae6c | 2015-06-04 14:12:25 -0700 | [diff] [blame] | 193 | SkIRect bounds() const { return SkIRect::MakeWH(this->width(), this->height()); } |
| 194 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 195 | /** Returns number of pixels that fit on row. Should be greater than or equal to |
| 196 | width(). |
| 197 | |
| 198 | @return maximum pixels per row |
| 199 | */ |
robertphillips | 3b5bea9 | 2016-03-24 11:21:25 -0700 | [diff] [blame] | 200 | int rowBytesAsPixels() const { return int(fRowBytes >> this->shiftPerPixel()); } |
| 201 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 202 | /** Returns bit shift converting row bytes to row pixels. |
| 203 | Returns zero for kUnknown_SkColorType. |
| 204 | |
| 205 | @return one of: 0, 1, 2, 3; left shift to convert pixels to bytes |
| 206 | */ |
reed | 8c3fd4f | 2016-04-15 06:59:38 -0700 | [diff] [blame] | 207 | int shiftPerPixel() const { return fInfo.shiftPerPixel(); } |
robertphillips | 3b5bea9 | 2016-03-24 11:21:25 -0700 | [diff] [blame] | 208 | |
Mike Reed | cd284c5 | 2017-09-29 15:22:56 -0400 | [diff] [blame^] | 209 | #ifdef SK_SUPPORT_LEGACY_SAFESIZE64 |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 210 | /** Returns conservative memory required for pixel storage. |
| 211 | Includes unused memory on last row when rowBytesAsPixels() exceeds width(). |
| 212 | |
| 213 | @return conservative pixel storage size |
| 214 | */ |
reed | 95d343f | 2015-05-23 13:21:06 -0700 | [diff] [blame] | 215 | uint64_t getSize64() const { return sk_64_mul(fInfo.height(), fRowBytes); } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 216 | |
| 217 | /** Returns minimum memory required for pixel storage. |
| 218 | Does not include unused memory on last row when rowBytesAsPixels() exceeds width(). |
| 219 | |
| 220 | @return exact pixel storage size |
| 221 | */ |
reed | 95d343f | 2015-05-23 13:21:06 -0700 | [diff] [blame] | 222 | uint64_t getSafeSize64() const { return fInfo.getSafeSize64(fRowBytes); } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 223 | |
| 224 | /** Returns minimum memory required for pixel storage. |
| 225 | Does not include unused memory on last row when rowBytesAsPixels() exceeds width(). |
| 226 | Returns zero if value is does not fit in a signed 32-bit integer. |
| 227 | The largest value than can be returned is 2,147,483,647. |
| 228 | |
| 229 | @return exact pixel storage size if size fits in signed 32 bits |
| 230 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 231 | size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); } |
Mike Reed | cd284c5 | 2017-09-29 15:22:56 -0400 | [diff] [blame^] | 232 | #endif |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 233 | |
Mike Reed | e74dafc | 2017-09-29 13:41:58 -0400 | [diff] [blame] | 234 | /** |
| 235 | * Returns the size (in bytes) of the pixmap's image buffer. |
| 236 | * If the calculation overflows, or if the height is 0, this returns 0. |
| 237 | */ |
| 238 | size_t computeByteSize() const { return fInfo.computeByteSize(fRowBytes); } |
| 239 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 240 | /** Returns true if all pixels are opaque. SkColorType determines how pixels |
| 241 | are encoded, and whether pixel describes alpha. Returns true for SkColorType |
| 242 | without alpha in each pixel; for other SkColorType, returns true if all |
| 243 | pixels have alpha values equivalent to 1.0 or greater. |
| 244 | |
| 245 | For SkColorType kRGB_565_SkColorType or kGray_8_SkColorType: always |
| 246 | returns true. For SkColorType kAlpha_8_SkColorType, kBGRA_8888_SkColorType, |
| 247 | kRGBA_8888_SkColorType: returns true if all pixel alpha values are 255. |
| 248 | For SkColorType kARGB_4444_SkColorType: returns true if all pixel alpha values are 15. |
| 249 | For kRGBA_F16_SkColorType: returns true if all pixel alpha values are 1.0 or |
| 250 | greater. |
| 251 | |
| 252 | Returns false for kUnknown_SkColorType. |
| 253 | |
| 254 | @return true all pixels have opaque values or SkColorType is opaque |
| 255 | */ |
Hal Canary | 58a7694 | 2016-12-07 15:24:59 -0500 | [diff] [blame] | 256 | bool computeIsOpaque() const; |
| 257 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 258 | /** Returns pixel at (x, y) as unpremultiplied color. |
| 259 | Returns black with alpha if SkColorType is kAlpha_8_SkColorType. |
| 260 | |
| 261 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 262 | built with SK_DEBUG defined; and returns undefined values or may crash if |
| 263 | SK_RELEASE is defined. Fails if SkColorType is kUnknown_SkColorType or |
| 264 | pixel address is nullptr. |
| 265 | |
| 266 | SkColorSpace in SkImageInfo is ignored. Some color precision may be lost in the |
| 267 | conversion to unpremultiplied color; original pixel data may have additional |
| 268 | precision. |
| 269 | |
| 270 | @param x column index, zero or greater, and less than width() |
| 271 | @param y row index, zero or greater, and less than height() |
| 272 | @return pixel converted to unpremultiplied color |
| 273 | */ |
Hal Canary | 94e1a2f | 2016-10-31 09:38:12 -0400 | [diff] [blame] | 274 | SkColor getColor(int x, int y) const; |
| 275 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 276 | /** Returns readable pixel address at (x, y). |
| 277 | |
| 278 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 279 | built with SK_DEBUG defined. Returns zero if SkColorType is kUnknown_SkColorType. |
| 280 | |
| 281 | @param x column index, zero or greater, and less than width() |
| 282 | @param y row index, zero or greater, and less than height() |
| 283 | @return readable generic pointer to pixel |
| 284 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 285 | const void* addr(int x, int y) const { |
| 286 | return (const char*)fPixels + fInfo.computeOffset(x, y, fRowBytes); |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 287 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 288 | |
| 289 | /** Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes. |
| 290 | Will trigger an assert() if SkColorType is not kAlpha_8_SkColorType or |
| 291 | kGray_8_SkColorType, and is built with SK_DEBUG defined. |
| 292 | |
| 293 | One byte corresponds to one pixel. |
| 294 | |
| 295 | @return readable unsigned 8-bit pointer to pixels |
| 296 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 297 | const uint8_t* addr8() const { |
| 298 | SkASSERT(1 == SkColorTypeBytesPerPixel(fInfo.colorType())); |
| 299 | return reinterpret_cast<const uint8_t*>(fPixels); |
| 300 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 301 | |
| 302 | /** Returns readable base pixel address. Result is addressable as unsigned 16-bit words. |
| 303 | Will trigger an assert() if SkColorType is not kRGB_565_SkColorType or |
| 304 | kARGB_4444_SkColorType, and is built with SK_DEBUG defined. |
| 305 | |
| 306 | One word corresponds to one pixel. |
| 307 | |
| 308 | @return readable unsigned 16-bit pointer to pixels |
| 309 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 310 | const uint16_t* addr16() const { |
| 311 | SkASSERT(2 == SkColorTypeBytesPerPixel(fInfo.colorType())); |
| 312 | return reinterpret_cast<const uint16_t*>(fPixels); |
| 313 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 314 | |
| 315 | /** Returns readable base pixel address. Result is addressable as unsigned 32-bit words. |
| 316 | Will trigger an assert() if SkColorType is not kRGBA_8888_SkColorType or |
| 317 | kBGRA_8888_SkColorType, and is built with SK_DEBUG defined. |
| 318 | |
| 319 | One word corresponds to one pixel. |
| 320 | |
| 321 | @return readable unsigned 32-bit pointer to pixels |
| 322 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 323 | const uint32_t* addr32() const { |
| 324 | SkASSERT(4 == SkColorTypeBytesPerPixel(fInfo.colorType())); |
| 325 | return reinterpret_cast<const uint32_t*>(fPixels); |
| 326 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 327 | |
| 328 | /** Returns readable base pixel address. Result is addressable as unsigned 64-bit words. |
| 329 | Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built |
| 330 | with SK_DEBUG defined. |
| 331 | |
| 332 | One word corresponds to one pixel. |
| 333 | |
| 334 | @return readable unsigned 64-bit pointer to pixels |
| 335 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 336 | const uint64_t* addr64() const { |
| 337 | SkASSERT(8 == SkColorTypeBytesPerPixel(fInfo.colorType())); |
| 338 | return reinterpret_cast<const uint64_t*>(fPixels); |
| 339 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 340 | |
| 341 | /** Returns readable base pixel address. Result is addressable as unsigned 16-bit words. |
| 342 | Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built |
| 343 | with SK_DEBUG defined. |
| 344 | |
| 345 | Each word represents one color component encoded as a half float. |
| 346 | Four words correspond to one pixel. |
| 347 | |
| 348 | @return readable unsigned 16-bit pointer to first component of pixels |
| 349 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 350 | const uint16_t* addrF16() const { |
| 351 | SkASSERT(8 == SkColorTypeBytesPerPixel(fInfo.colorType())); |
| 352 | SkASSERT(kRGBA_F16_SkColorType == fInfo.colorType()); |
| 353 | return reinterpret_cast<const uint16_t*>(fPixels); |
| 354 | } |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 355 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 356 | /** Returns readable pixel address at (x, y). |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 357 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 358 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 359 | built with SK_DEBUG defined. |
| 360 | |
| 361 | Will trigger an assert() if SkColorType is not kAlpha_8_SkColorType or |
| 362 | kGray_8_SkColorType, and is built with SK_DEBUG defined. |
| 363 | |
| 364 | @param x column index, zero or greater, and less than width() |
| 365 | @param y row index, zero or greater, and less than height() |
| 366 | @return readable unsigned 8-bit pointer to pixel at (x, y) |
| 367 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 368 | const uint8_t* addr8(int x, int y) const { |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 369 | SkASSERT((unsigned)x < (unsigned)fInfo.width()); |
| 370 | SkASSERT((unsigned)y < (unsigned)fInfo.height()); |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 371 | return (const uint8_t*)((const char*)this->addr8() + y * fRowBytes + (x << 0)); |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 372 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 373 | |
| 374 | /** Returns readable pixel address at (x, y). |
| 375 | |
| 376 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 377 | built with SK_DEBUG defined. |
| 378 | |
| 379 | Will trigger an assert() if SkColorType is not kRGB_565_SkColorType or |
| 380 | kARGB_4444_SkColorType, and is built with SK_DEBUG defined. |
| 381 | |
| 382 | @param x column index, zero or greater, and less than width() |
| 383 | @param y row index, zero or greater, and less than height() |
| 384 | @return readable unsigned 16-bit pointer to pixel at (x, y) |
| 385 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 386 | const uint16_t* addr16(int x, int y) const { |
| 387 | SkASSERT((unsigned)x < (unsigned)fInfo.width()); |
| 388 | SkASSERT((unsigned)y < (unsigned)fInfo.height()); |
| 389 | return (const uint16_t*)((const char*)this->addr16() + y * fRowBytes + (x << 1)); |
| 390 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 391 | |
| 392 | /** Returns readable pixel address at (x, y). |
| 393 | |
| 394 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 395 | built with SK_DEBUG defined. |
| 396 | |
| 397 | Will trigger an assert() if SkColorType is not kRGBA_8888_SkColorType or |
| 398 | kBGRA_8888_SkColorType, and is built with SK_DEBUG defined. |
| 399 | |
| 400 | @param x column index, zero or greater, and less than width() |
| 401 | @param y row index, zero or greater, and less than height() |
| 402 | @return readable unsigned 32-bit pointer to pixel at (x, y) |
| 403 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 404 | const uint32_t* addr32(int x, int y) const { |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 405 | SkASSERT((unsigned)x < (unsigned)fInfo.width()); |
| 406 | SkASSERT((unsigned)y < (unsigned)fInfo.height()); |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 407 | return (const uint32_t*)((const char*)this->addr32() + y * fRowBytes + (x << 2)); |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 408 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 409 | |
| 410 | /** Returns readable pixel address at (x, y). |
| 411 | |
| 412 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 413 | built with SK_DEBUG defined. |
| 414 | |
| 415 | Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built |
| 416 | with SK_DEBUG defined. |
| 417 | |
| 418 | @param x column index, zero or greater, and less than width() |
| 419 | @param y row index, zero or greater, and less than height() |
| 420 | @return readable unsigned 64-bit pointer to pixel at (x, y) |
| 421 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 422 | const uint64_t* addr64(int x, int y) const { |
| 423 | SkASSERT((unsigned)x < (unsigned)fInfo.width()); |
| 424 | SkASSERT((unsigned)y < (unsigned)fInfo.height()); |
| 425 | return (const uint64_t*)((const char*)this->addr64() + y * fRowBytes + (x << 3)); |
| 426 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 427 | |
| 428 | /** Returns readable pixel address at (x, y). |
| 429 | |
| 430 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 431 | built with SK_DEBUG defined. |
| 432 | |
| 433 | Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built |
| 434 | with SK_DEBUG defined. |
| 435 | |
| 436 | Each unsigned 16-bit word represents one color component encoded as a half float. |
| 437 | Four words correspond to one pixel. |
| 438 | |
| 439 | @param x column index, zero or greater, and less than width() |
| 440 | @param y row index, zero or greater, and less than height() |
| 441 | @return readable unsigned 16-bit pointer to pixel component at (x, y) |
| 442 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 443 | const uint16_t* addrF16(int x, int y) const { |
| 444 | SkASSERT(kRGBA_F16_SkColorType == fInfo.colorType()); |
| 445 | return reinterpret_cast<const uint16_t*>(this->addr64(x, y)); |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 448 | /** Returns writable base pixel address. |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 449 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 450 | @return writable generic base pointer to pixels |
| 451 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 452 | void* writable_addr() const { return const_cast<void*>(fPixels); } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 453 | |
| 454 | /** Returns writable pixel address at (x, y). |
| 455 | |
| 456 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 457 | built with SK_DEBUG defined. Returns zero if SkColorType is kUnknown_SkColorType. |
| 458 | |
| 459 | @param x column index, zero or greater, and less than width() |
| 460 | @param y row index, zero or greater, and less than height() |
| 461 | @return writable generic pointer to pixel |
| 462 | */ |
reed | 8c3fd4f | 2016-04-15 06:59:38 -0700 | [diff] [blame] | 463 | void* writable_addr(int x, int y) const { |
| 464 | return const_cast<void*>(this->addr(x, y)); |
| 465 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 466 | |
| 467 | /** Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 468 | 8-bit bytes. Will trigger an assert() if SkColorType is not kAlpha_8_SkColorType |
| 469 | or kGray_8_SkColorType, and is built with SK_DEBUG defined. |
| 470 | |
| 471 | One byte corresponds to one pixel. |
| 472 | |
| 473 | @param x column index, zero or greater, and less than width() |
| 474 | @param y row index, zero or greater, and less than height() |
| 475 | @return writable unsigned 8-bit pointer to pixels |
| 476 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 477 | uint8_t* writable_addr8(int x, int y) const { |
| 478 | return const_cast<uint8_t*>(this->addr8(x, y)); |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 479 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 480 | |
| 481 | /** Returns writable_addr pixel address at (x, y). Result is addressable as unsigned |
| 482 | 16-bit words. Will trigger an assert() if SkColorType is not kRGB_565_SkColorType |
| 483 | or kARGB_4444_SkColorType, and is built with SK_DEBUG defined. |
| 484 | |
| 485 | One word corresponds to one pixel. |
| 486 | |
| 487 | @param x column index, zero or greater, and less than width() |
| 488 | @param y row index, zero or greater, and less than height() |
| 489 | @return writable unsigned 16-bit pointer to pixel |
| 490 | */ |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 491 | uint16_t* writable_addr16(int x, int y) const { |
| 492 | return const_cast<uint16_t*>(this->addr16(x, y)); |
| 493 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 494 | |
| 495 | /** Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 496 | 32-bit words. Will trigger an assert() if SkColorType is not |
| 497 | kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG |
| 498 | defined. |
| 499 | |
| 500 | One word corresponds to one pixel. |
| 501 | |
| 502 | @param x column index, zero or greater, and less than width() |
| 503 | @param y row index, zero or greater, and less than height() |
| 504 | @return writable unsigned 32-bit pointer to pixel |
| 505 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 506 | uint32_t* writable_addr32(int x, int y) const { |
| 507 | return const_cast<uint32_t*>(this->addr32(x, y)); |
| 508 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 509 | |
| 510 | /** Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 511 | 64-bit words. Will trigger an assert() if SkColorType is not |
| 512 | kRGBA_F16_SkColorType and is built with SK_DEBUG defined. |
| 513 | |
| 514 | One word corresponds to one pixel. |
| 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 | @return writable unsigned 64-bit pointer to pixel |
| 519 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 520 | uint64_t* writable_addr64(int x, int y) const { |
| 521 | return const_cast<uint64_t*>(this->addr64(x, y)); |
| 522 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 523 | |
| 524 | /** Returns writable pixel address at (x, y). Result is addressable as unsigned |
| 525 | 16-bit words. Will trigger an assert() if SkColorType is not |
| 526 | kRGBA_F16_SkColorType and is built with SK_DEBUG defined. |
| 527 | |
| 528 | Each word represents one color component encoded as a half float. |
| 529 | Four words correspond to one pixel. |
| 530 | |
| 531 | @param x column index, zero or greater, and less than width() |
| 532 | @param y row index, zero or greater, and less than height() |
| 533 | @return writable unsigned 16-bit pointer to first component of pixel |
| 534 | */ |
reed | 3601f28 | 2016-02-05 11:18:39 -0800 | [diff] [blame] | 535 | uint16_t* writable_addrF16(int x, int y) const { |
| 536 | return reinterpret_cast<uint16_t*>(writable_addr64(x, y)); |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 539 | /** Copies a SkRect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not exceed |
| 540 | (this->width(), this->height()). |
reed | 95d343f | 2015-05-23 13:21:06 -0700 | [diff] [blame] | 541 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 542 | dstInfo specifies width, height, SkColorType, SkAlphaType, and |
| 543 | SkColorSpace of destination. dstRowBytes specifics the gap from one destination |
| 544 | row to the next. Returns true if pixels are copied. Returns false if |
| 545 | dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes(). |
| 546 | |
| 547 | Pixels are copied only if pixel conversion is possible. If this->colorType() is |
| 548 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. |
| 549 | If this->colorType() is kGray_8_SkColorType, dstInfo.colorSpace() must match. |
| 550 | If this->alphaType() is kOpaque_SkAlphaType, dstInfo.alphaType() must |
| 551 | match. If this->colorSpace() is nullptr, dstInfo.colorSpace() must match. Returns |
| 552 | false if pixel conversion is not possible. |
| 553 | |
| 554 | srcX and srcY may be negative to copy only top or left of source. Returns |
| 555 | false if width() or height() is zero or negative. Returns false if |
| 556 | abs(srcX) >= this->width(), or if |
| 557 | abs(srcY) >= this->height(). |
| 558 | |
| 559 | If behavior is SkTransferFunctionBehavior::kRespect: converts source |
| 560 | pixels to a linear space before converting to dstInfo. |
| 561 | If behavior is SkTransferFunctionBehavior::kIgnore: source |
| 562 | pixels are treated as if they are linear, regardless of their encoding. |
| 563 | |
| 564 | @param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace |
| 565 | @param dstPixels destination pixel storage |
| 566 | @param dstRowBytes destination row length |
| 567 | @param srcX column index whose absolute value is less than width() |
| 568 | @param srcY row index whose absolute value is less than height() |
| 569 | @param behavior one of: SkTransferFunctionBehavior::kRespect, |
| 570 | SkTransferFunctionBehavior::kIgnore |
| 571 | @return true if pixels are copied to dstPixels |
| 572 | */ |
reed | 95d343f | 2015-05-23 13:21:06 -0700 | [diff] [blame] | 573 | bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
Matt Sarett | 3928ff8 | 2017-06-06 10:11:34 -0400 | [diff] [blame] | 574 | int srcX, int srcY, SkTransferFunctionBehavior behavior) const; |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 575 | |
| 576 | /** Copies a SkRect of pixels to dstPixels. Copy starts at (0, 0), and does not |
| 577 | exceed |
| 578 | (this->width(), this->height()). |
| 579 | |
| 580 | dstInfo specifies width, height, SkColorType, SkAlphaType, and |
| 581 | SkColorSpace of destination. dstRowBytes specifics the gap from one destination |
| 582 | row to the next. Returns true if pixels are copied. Returns false if |
| 583 | dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes(). |
| 584 | |
| 585 | Pixels are copied only if pixel conversion is possible. If this->colorType() is |
| 586 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. |
| 587 | If this->colorType() is kGray_8_SkColorType, dstInfo.colorSpace() must match. |
| 588 | If this->alphaType() is kOpaque_SkAlphaType, dstInfo.alphaType() must |
| 589 | match. If this->colorSpace() is nullptr, dstInfo.colorSpace() must match. Returns |
| 590 | false if pixel conversion is not possible. |
| 591 | |
| 592 | Returns false if this->width() or this->height() is zero or negative. |
| 593 | |
| 594 | @param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace |
| 595 | @param dstPixels destination pixel storage |
| 596 | @param dstRowBytes destination row length |
| 597 | @return true if pixels are copied to dstPixels |
| 598 | */ |
reed | 95d343f | 2015-05-23 13:21:06 -0700 | [diff] [blame] | 599 | bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const { |
| 600 | return this->readPixels(dstInfo, dstPixels, dstRowBytes, 0, 0); |
| 601 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 602 | |
| 603 | /** Copies a SkRect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not |
| 604 | exceed |
| 605 | (this->width(), this->height()). |
| 606 | |
| 607 | dstInfo specifies width, height, SkColorType, SkAlphaType, and |
| 608 | SkColorSpace of destination. dstRowBytes specifics the gap from one destination |
| 609 | row to the next. Returns true if pixels are copied. Returns false if |
| 610 | dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes(). |
| 611 | |
| 612 | Pixels are copied only if pixel conversion is possible. If this->colorType() is |
| 613 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. |
| 614 | If this->colorType() is kGray_8_SkColorType, dstInfo.colorSpace() must match. |
| 615 | If this->alphaType() is kOpaque_SkAlphaType, dstInfo.alphaType() must |
| 616 | match. If this->colorSpace() is nullptr, dstInfo.colorSpace() must match. Returns |
| 617 | false if pixel conversion is not possible. |
| 618 | |
| 619 | srcX and srcY may be negative to copy only top or left of source. Returns |
| 620 | false if this->width() or this->height() is zero or negative. Returns false if |
| 621 | abs(srcX) >= this->width(), or if |
| 622 | abs(srcY) >= this->height(). |
| 623 | |
| 624 | @param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace |
| 625 | @param dstPixels destination pixel storage |
| 626 | @param dstRowBytes destination row length |
| 627 | @param srcX column index whose absolute value is less than width() |
| 628 | @param srcY row index whose absolute value is less than height() |
| 629 | @return true if pixels are copied to dstPixels |
| 630 | */ |
Matt Sarett | 3928ff8 | 2017-06-06 10:11:34 -0400 | [diff] [blame] | 631 | bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, |
| 632 | int srcY) const { |
| 633 | return this->readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY, |
| 634 | SkTransferFunctionBehavior::kRespect); |
| 635 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 636 | |
| 637 | /** Copies a SkRect of pixels to dst. Copy starts at (srcX, srcY), and does not |
| 638 | exceed (this->width(), this->height()). dst specifies width, height, SkColorType, |
| 639 | SkAlphaType, and SkColorSpace of destination. Returns true if pixels are copied. |
| 640 | Returns false if dst.addr() equals nullptr, or dst.rowBytes() is less than |
| 641 | dst SkImageInfo::minRowBytes. |
| 642 | |
| 643 | Pixels are copied only if pixel conversion is possible. If this->colorType() is |
| 644 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match. |
| 645 | If this->colorType() is kGray_8_SkColorType, dst.info().colorSpace must match. |
| 646 | If this->alphaType() is kOpaque_SkAlphaType, dst.info().alphaType must |
| 647 | match. If this->colorSpace() is nullptr, dst.info().colorSpace must match. Returns |
| 648 | false if pixel conversion is not possible. |
| 649 | |
| 650 | srcX and srcY may be negative to copy only top or left of source. Returns |
| 651 | false this->width() or this->height() is zero or negative. Returns false if |
| 652 | abs(srcX) >= this->width(), or if |
| 653 | abs(srcY) >= this->height(). |
| 654 | |
| 655 | @param dst SkImageInfo and pixel address to write to |
| 656 | @param srcX column index whose absolute value is less than width() |
| 657 | @param srcY row index whose absolute value is less than height() |
| 658 | @return true if pixels are copied to dst |
| 659 | */ |
reed | 95d343f | 2015-05-23 13:21:06 -0700 | [diff] [blame] | 660 | bool readPixels(const SkPixmap& dst, int srcX, int srcY) const { |
| 661 | return this->readPixels(dst.info(), dst.writable_addr(), dst.rowBytes(), srcX, srcY); |
| 662 | } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 663 | |
| 664 | /** Copies pixels inside bounds() to dst. dst specifies width, height, SkColorType, |
| 665 | SkAlphaType, and SkColorSpace of destination. Returns true if pixels are copied. |
| 666 | Returns false if dst.addr() equals nullptr, or dst.rowBytes() is less than |
| 667 | dst SkImageInfo::minRowBytes. |
| 668 | |
| 669 | Pixels are copied only if pixel conversion is possible. If this->colorType() is |
| 670 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match. |
| 671 | If this->colorType() is kGray_8_SkColorType, dst SkColorSpace must match. |
| 672 | If this->alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must |
| 673 | match. If this->colorSpace() is nullptr, dst SkColorSpace must match. Returns |
| 674 | false if pixel conversion is not possible. |
| 675 | |
| 676 | Returns false if this->width() or this->height() is zero or negative. |
| 677 | |
| 678 | @param dst SkImageInfo and pixel address to write to |
| 679 | @return true if pixels are copied to dst |
| 680 | */ |
reed | 95d343f | 2015-05-23 13:21:06 -0700 | [diff] [blame] | 681 | bool readPixels(const SkPixmap& dst) const { |
| 682 | return this->readPixels(dst.info(), dst.writable_addr(), dst.rowBytes(), 0, 0); |
| 683 | } |
| 684 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 685 | /** Copies this to dst, scaling pixels to fit dst.width() and dst.height(), and |
| 686 | converting pixels to match dst.colorType() and dst.alphaType(). Returns true if |
| 687 | pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes() is |
| 688 | less than dst SkImageInfo::minRowBytes. |
| 689 | |
| 690 | Pixels are copied only if pixel conversion is possible. If this->colorType() is |
| 691 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match. |
| 692 | If this->colorType() is kGray_8_SkColorType, dst SkColorSpace must match. |
| 693 | If this->alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must |
| 694 | match. If this->colorSpace() is nullptr, dst SkColorSpace must match. Returns |
| 695 | false if pixel conversion is not possible. |
| 696 | |
| 697 | Returns false if this->width() or this->height() is zero or negative. |
| 698 | |
| 699 | Scales the image, with filterQuality, to match dst.width() and dst.height(). |
| 700 | filterQuality kNone_SkFilterQuality is fastest, typically implemented with |
| 701 | nearest neighbor filter. kLow_SkFilterQuality is typically implemented with |
| 702 | bilerp filter. kMedium_SkFilterQuality is typically implemented with |
| 703 | bilerp filter, and Filter_Quality_MipMap when size is reduced. |
| 704 | kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic. |
| 705 | |
| 706 | @param dst SkImageInfo and pixel address to write to |
| 707 | @param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality, |
| 708 | kMedium_SkFilterQuality, kHigh_SkFilterQuality |
| 709 | @return true if pixels are copied to dst |
| 710 | */ |
Cary Clark | ed294b4 | 2017-09-14 10:36:51 -0400 | [diff] [blame] | 711 | bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const; |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 712 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 713 | /** Writes color to pixels bounded by subset; returns true on success. |
| 714 | Returns false if colorType() is kUnknown_SkColorType, or if subset does |
| 715 | not intersect bounds(). |
| 716 | |
| 717 | @param color unpremultiplied color to write |
| 718 | @param subset bounding integer SkRect of written pixels |
| 719 | @return true if pixels are changed |
| 720 | */ |
Cary Clark | ed294b4 | 2017-09-14 10:36:51 -0400 | [diff] [blame] | 721 | bool erase(SkColor color, const SkIRect& subset) const; |
reed | 7aefe03 | 2015-06-08 10:22:22 -0700 | [diff] [blame] | 722 | |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 723 | /** Writes color to pixels inside bounds(); returns true on success. |
| 724 | Returns false if colorType() is kUnknown_SkColorType, or if bounds() |
| 725 | is empty. |
| 726 | |
| 727 | @param color unpremultiplied color to write |
| 728 | @return true if pixels are changed |
| 729 | */ |
reed | 7aefe03 | 2015-06-08 10:22:22 -0700 | [diff] [blame] | 730 | bool erase(SkColor color) const { return this->erase(color, this->bounds()); } |
Cary Clark | 8a02b0b | 2017-09-21 12:28:43 -0400 | [diff] [blame] | 731 | |
| 732 | /** Writes color to pixels bounded by subset; returns true on success. |
| 733 | if subset is nullptr, writes colors pixels inside bounds(). Returns false if |
| 734 | colorType() is kUnknown_SkColorType, if subset is not nullptr and does |
| 735 | not intersect bounds(), or if subset is nullptr and bounds() is empty. |
| 736 | |
| 737 | @param color unpremultiplied color to write |
| 738 | @param subset bounding integer SkRect of pixels to write; may be nullptr |
| 739 | @return true if pixels are changed |
| 740 | */ |
Cary Clark | ec2455b | 2017-09-05 09:42:43 -0400 | [diff] [blame] | 741 | bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const; |
reed | 7aefe03 | 2015-06-08 10:22:22 -0700 | [diff] [blame] | 742 | |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 743 | private: |
| 744 | const void* fPixels; |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 745 | size_t fRowBytes; |
| 746 | SkImageInfo fInfo; |
| 747 | }; |
| 748 | |
reed | 92fc2ae | 2015-05-22 08:06:21 -0700 | [diff] [blame] | 749 | #endif |