Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1 | #Topic Bitmap |
| 2 | #Alias Bitmaps |
| 3 | #Alias Bitmap_Reference |
| 4 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5 | #Subtopic Overview |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 6 | #Subtopic Subtopic |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 7 | #Populate |
| 8 | ## |
| 9 | ## |
| 10 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 11 | #Class SkBitmap |
| 12 | |
| 13 | Bitmap describes a two-dimensional raster pixel array. Bitmap is built on |
| 14 | Image_Info, containing integer width and height, Color_Type and Alpha_Type |
| 15 | describing the pixel format, and Color_Space describing the range of colors. |
| 16 | Bitmap points to Pixel_Ref, which describes the physical array of pixels. |
| 17 | Image_Info bounds may be located anywhere fully inside Pixel_Ref bounds. |
| 18 | |
| 19 | Bitmap can be drawn using Canvas. Bitmap can be a drawing destination for Canvas |
| 20 | draw methods. Bitmap flexibility as a pixel container limits some optimizations |
| 21 | available to the target platform. |
| 22 | |
| 23 | If pixel array is primarily read-only, use Image for better performance. |
| 24 | If pixel array is primarily written to, use Surface for better performance. |
| 25 | |
| 26 | Declaring SkBitmap const prevents altering Image_Info: the Bitmap height, width, |
| 27 | and so on cannot change. It does not affect Pixel_Ref: a caller may write its |
| 28 | pixels. Declaring SkBitmap const affects Bitmap configuration, not its contents. |
| 29 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 30 | Bitmap is not thread safe. Each thread must have its own copy of Bitmap fields, |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 31 | although threads may share the underlying pixel array. |
| 32 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 33 | #Subtopic Row_Bytes |
| 34 | #Line # interval from one row to the next ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 35 | Bitmap pixels may be contiguous, or may have a gap at the end of each row. |
| 36 | Row_Bytes is the interval from one row to the next. Row_Bytes may be specified; |
| 37 | sometimes passing zero will compute the Row_Bytes from the row width and the |
| 38 | number of bytes in a pixel. Row_Bytes may be larger than the row requires. This |
| 39 | is useful to position one or more Bitmaps within a shared pixel array. |
| 40 | ## |
| 41 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 42 | #Subtopic Related_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 43 | #Populate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 44 | ## |
| 45 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 46 | #Subtopic Constant |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 47 | #Populate |
| 48 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 49 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 50 | #Subtopic Class_or_Struct |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 51 | #Populate |
| 52 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 53 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 54 | #Subtopic Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 55 | #Populate |
| 56 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 57 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 58 | #Subtopic Operator |
| 59 | #Populate |
| 60 | ## |
| 61 | |
| 62 | #Subtopic Member_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 63 | #Populate |
| 64 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 65 | |
| 66 | # ------------------------------------------------------------------------------ |
| 67 | |
| 68 | #Class Allocator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 69 | #Line # abstract subclass of HeapAllocator ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 70 | #Code |
| 71 | class Allocator : public SkRefCnt { |
| 72 | public: |
| 73 | virtual bool allocPixelRef(SkBitmap* bitmap) = 0; |
| 74 | }; |
| 75 | ## |
| 76 | |
| 77 | Abstract subclass of HeapAllocator. |
| 78 | |
| 79 | # ------------------------------------------------------------------------------ |
| 80 | |
| 81 | #Method virtual bool allocPixelRef(SkBitmap* bitmap) = 0 |
| 82 | |
| 83 | Allocates the pixel memory for the bitmap, given its dimensions and |
| 84 | Color_Type. Returns true on success, where success means either setPixels |
| 85 | or setPixelRef was called. |
| 86 | |
| 87 | #Param bitmap Bitmap containing Image_Info as input, and Pixel_Ref as output ## |
| 88 | |
| 89 | #Return true if Pixel_Ref was allocated ## |
| 90 | |
| 91 | #NoExample |
| 92 | ## |
| 93 | |
| 94 | #SeeAlso HeapAllocator |
| 95 | |
| 96 | ## |
| 97 | |
| 98 | #Class Allocator ## |
| 99 | |
| 100 | # ------------------------------------------------------------------------------ |
| 101 | |
| 102 | #Class HeapAllocator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 103 | #Line # allocates pixel memory from heap ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 104 | |
| 105 | #Code |
| 106 | class HeapAllocator : public Allocator { |
| 107 | public: |
| 108 | bool allocPixelRef(SkBitmap* bitmap) override; |
| 109 | }; |
| 110 | ## |
| 111 | |
Cary Clark | 78c110e | 2018-02-09 16:49:09 -0500 | [diff] [blame] | 112 | Subclass of SkBitmap::Allocator that returns a Pixel_Ref that allocates its pixel |
| 113 | memory from the heap. This is the default SkBitmap::Allocator invoked by |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 114 | allocPixels. |
| 115 | |
| 116 | # ------------------------------------------------------------------------------ |
| 117 | |
| 118 | #Method bool allocPixelRef(SkBitmap* bitmap) override |
| 119 | |
| 120 | Allocates the pixel memory for the bitmap, given its dimensions and |
| 121 | Color_Type. Returns true on success, where success means either setPixels |
| 122 | or setPixelRef was called. |
| 123 | |
| 124 | #Param bitmap Bitmap containing Image_Info as input, and Pixel_Ref as output ## |
| 125 | |
| 126 | #Return true if pixels are allocated ## |
| 127 | |
| 128 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 129 | SkBitmap bitmap; |
| 130 | bitmap.setInfo(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType)); |
| 131 | SkDebugf("pixel address = %p\n", bitmap.getPixels()); |
| 132 | SkBitmap::HeapAllocator stdalloc; |
| 133 | if (!stdalloc.allocPixelRef(&bitmap)) { |
| 134 | SkDebugf("pixel allocation failed\n"); |
| 135 | } else { |
| 136 | SkDebugf("pixel address = %p\n", bitmap.getPixels()); |
| 137 | } |
| 138 | #StdOut |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 139 | #Volatile |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 140 | pixel address = (nil) |
| 141 | pixel address = 0x560ddd0ac670 |
| 142 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 143 | ## |
| 144 | |
Cary Clark | 78c110e | 2018-02-09 16:49:09 -0500 | [diff] [blame] | 145 | #SeeAlso SkBitmap::Allocator tryAllocPixels |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 146 | |
| 147 | ## |
| 148 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 149 | #Class HeapAllocator ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 150 | |
| 151 | # ------------------------------------------------------------------------------ |
| 152 | |
| 153 | #Method SkBitmap() |
| 154 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 155 | #Line # constructs with default values ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 156 | Creates an empty Bitmap without pixels, with kUnknown_SkColorType, |
| 157 | kUnknown_SkAlphaType, and with a width and height of zero. Pixel_Ref origin is |
| 158 | set to (0, 0). Bitmap is not volatile. |
| 159 | |
| 160 | Use setInfo to associate SkColorType, SkAlphaType, width, and height |
| 161 | after Bitmap has been created. |
| 162 | |
| 163 | #Return empty Bitmap ## |
| 164 | |
| 165 | #Example |
| 166 | void draw(SkCanvas* canvas) { |
| 167 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 168 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 169 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 170 | SkBitmap bitmap; |
| 171 | for (int i = 0; i < 2; ++i) { |
| 172 | SkDebugf("width: %2d height: %2d", bitmap.width(), bitmap.height()); |
| 173 | SkDebugf(" color: k%s_SkColorType", colors[bitmap.colorType()]); |
| 174 | SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[bitmap.alphaType()]); |
| 175 | bitmap.setInfo(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType), |
| 176 | 0); |
| 177 | } |
| 178 | } |
| 179 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 180 | width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 181 | width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType |
| 182 | ## |
| 183 | ## |
| 184 | |
| 185 | #SeeAlso setInfo |
| 186 | |
| 187 | ## |
| 188 | |
| 189 | # ------------------------------------------------------------------------------ |
| 190 | |
| 191 | #Method SkBitmap(const SkBitmap& src) |
| 192 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 193 | #Line # shares ownership of pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 194 | Copies settings from src to returned Bitmap. Shares pixels if src has pixels |
| 195 | allocated, so both bitmaps reference the same pixels. |
| 196 | |
| 197 | #Param src Bitmap to copy Image_Info, and share Pixel_Ref ## |
| 198 | |
| 199 | #Return copy of src ## |
| 200 | |
| 201 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 202 | void draw(SkCanvas* canvas) { |
| 203 | SkBitmap original; |
| 204 | original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 205 | SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false"); |
| 206 | SkBitmap copy(original); |
| 207 | SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false"); |
| 208 | SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 209 | } |
| 210 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 211 | original has pixels before copy: true |
| 212 | original has pixels after copy: true |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 213 | copy has pixels: true |
| 214 | ## |
| 215 | ## |
| 216 | |
| 217 | #SeeAlso setInfo setPixelRef setPixels swap |
| 218 | |
| 219 | ## |
| 220 | |
| 221 | # ------------------------------------------------------------------------------ |
| 222 | |
| 223 | #Method SkBitmap(SkBitmap&& src) |
| 224 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 225 | #Line # takes ownership of pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 226 | Copies settings from src to returned Bitmap. Moves ownership of src pixels to |
| 227 | Bitmap. |
| 228 | |
| 229 | #Param src Bitmap to copy Image_Info, and reassign Pixel_Ref ## |
| 230 | |
| 231 | #Return copy of src ## |
| 232 | |
| 233 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 234 | void draw(SkCanvas* canvas) { |
| 235 | SkBitmap original; |
| 236 | original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 237 | SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false"); |
| 238 | SkBitmap copy(std::move(original)); |
| 239 | SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false"); |
| 240 | SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); |
| 241 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 242 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 243 | original has pixels before move: true |
| 244 | original has pixels after move: false |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 245 | copy has pixels: true |
| 246 | ## |
| 247 | ## |
| 248 | |
| 249 | #SeeAlso setInfo setPixelRef setPixels swap |
| 250 | |
| 251 | ## |
| 252 | |
| 253 | # ------------------------------------------------------------------------------ |
| 254 | |
| 255 | #Method ~SkBitmap() |
| 256 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 257 | #Line # releases ownership of pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 258 | Decrements Pixel_Ref reference count, if Pixel_Ref is not nullptr. |
| 259 | |
| 260 | #NoExample |
| 261 | ## |
| 262 | |
| 263 | #SeeAlso Pixel_Ref |
| 264 | |
| 265 | ## |
| 266 | |
| 267 | # ------------------------------------------------------------------------------ |
| 268 | |
| 269 | #Method SkBitmap& operator=(const SkBitmap& src) |
| 270 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 271 | #Line # shares ownership of pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 272 | Copies settings from src to returned Bitmap. Shares pixels if src has pixels |
| 273 | allocated, so both bitmaps reference the same pixels. |
| 274 | |
| 275 | #Param src Bitmap to copy Image_Info, and share Pixel_Ref ## |
| 276 | |
| 277 | #Return copy of src ## |
| 278 | |
| 279 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 280 | void draw(SkCanvas* canvas) { |
| 281 | SkBitmap original; |
| 282 | original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 283 | SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false"); |
| 284 | SkBitmap copy = original; |
| 285 | SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false"); |
| 286 | SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 287 | } |
| 288 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 289 | original has pixels before copy: true |
| 290 | original has pixels after copy: true |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 291 | copy has pixels: true |
| 292 | ## |
| 293 | ## |
| 294 | |
| 295 | #SeeAlso setInfo setPixelRef setPixels swap |
| 296 | |
| 297 | ## |
| 298 | |
| 299 | # ------------------------------------------------------------------------------ |
| 300 | |
| 301 | #Method SkBitmap& operator=(SkBitmap&& src) |
| 302 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 303 | #Line # takes ownership of pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 304 | Copies settings from src to returned Bitmap. Moves ownership of src pixels to |
| 305 | Bitmap. |
| 306 | |
| 307 | #Param src Bitmap to copy Image_Info, and reassign Pixel_Ref ## |
| 308 | |
| 309 | #Return copy of src ## |
| 310 | |
| 311 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 312 | void draw(SkCanvas* canvas) { |
| 313 | SkBitmap original; |
| 314 | original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 315 | SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false"); |
| 316 | SkBitmap copy = std::move(original); |
| 317 | SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false"); |
| 318 | SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); |
| 319 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 320 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 321 | original has pixels before move: true |
| 322 | original has pixels after move: false |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 323 | copy has pixels: true |
| 324 | ## |
| 325 | ## |
| 326 | |
| 327 | #SeeAlso setInfo setPixelRef setPixels swap |
| 328 | |
| 329 | ## |
| 330 | |
| 331 | # ------------------------------------------------------------------------------ |
| 332 | |
| 333 | #Method void swap(SkBitmap& other) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 334 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 335 | #Line # exchanges Bitmap pair ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 336 | Swaps the fields of the two bitmaps. |
| 337 | |
| 338 | #Param other Bitmap exchanged with original ## |
| 339 | |
| 340 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 341 | void draw(SkCanvas* canvas) { |
| 342 | auto debugster = [](const char* prefix, const SkBitmap& b) -> void { |
| 343 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 344 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 345 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 346 | SkDebugf("%s width:%d height:%d colorType:k%s_SkColorType alphaType:k%s_SkAlphaType\n", |
| 347 | prefix, b.width(), b.height(), colors[b.colorType()], alphas[b.alphaType()]); |
| 348 | }; |
| 349 | SkBitmap one, two; |
| 350 | one.tryAllocPixels(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 351 | two.tryAllocPixels(SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType)); |
| 352 | for (int index = 0; index < 2; ++index) { |
| 353 | debugster("one", one); |
| 354 | debugster("two", two); |
| 355 | one.swap(two); |
| 356 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 357 | } |
| 358 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 359 | one width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType |
| 360 | two width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType |
| 361 | one width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 362 | two width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType |
| 363 | ## |
| 364 | ## |
| 365 | |
| 366 | #SeeAlso SkBitmap(SkBitmap&& src) operator=(SkBitmap&& src) |
| 367 | |
| 368 | ## |
| 369 | |
| 370 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 371 | #Subtopic Property |
| 372 | #Populate |
| 373 | #Line # metrics and attributes ## |
| 374 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 375 | |
Hal Canary | 99578d2 | 2017-12-14 21:13:47 -0500 | [diff] [blame] | 376 | #Method const SkPixmap& pixmap() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 377 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 378 | #Line # returns Pixmap ## |
Hal Canary | 99578d2 | 2017-12-14 21:13:47 -0500 | [diff] [blame] | 379 | Returns a constant reference to the Pixmap holding the Bitmap pixel |
| 380 | address, row bytes, and Image_Info. |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 381 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 382 | #Return reference to Pixmap describing this Bitmap ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 383 | |
| 384 | #Example |
| 385 | SkBitmap bitmap; |
| 386 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(10, 11)); |
| 387 | SkCanvas offscreen(bitmap); |
| 388 | offscreen.clear(SK_ColorWHITE); |
| 389 | SkPaint paint; |
| 390 | offscreen.drawString("&", 0, 10, paint); |
Hal Canary | 99578d2 | 2017-12-14 21:13:47 -0500 | [diff] [blame] | 391 | const SkPixmap& pixmap = bitmap.pixmap(); |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 392 | if (pixmap.addr()) { |
Hal Canary | 99578d2 | 2017-12-14 21:13:47 -0500 | [diff] [blame] | 393 | SkPMColor pmWhite = *pixmap.addr32(0, 0); |
| 394 | for (int y = 0; y < pixmap.height(); ++y) { |
| 395 | for (int x = 0; x < pixmap.width(); ++x) { |
| 396 | SkDebugf("%c", *pixmap.addr32(x, y) == pmWhite ? '-' : 'x'); |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 397 | } |
| 398 | SkDebugf("\n"); |
| 399 | } |
| 400 | } |
| 401 | #StdOut |
| 402 | ---------- |
| 403 | ---xx----- |
| 404 | --x--x---- |
| 405 | --x------- |
| 406 | --xx------ |
| 407 | --x-x---x- |
| 408 | -x---x--x- |
| 409 | -x----xx-- |
| 410 | -xx---x--- |
| 411 | --xxxx-xx- |
| 412 | ---------- |
| 413 | #StdOut ## |
| 414 | |
| 415 | ## |
| 416 | |
| 417 | #SeeAlso peekPixels installPixels readPixels writePixels |
| 418 | |
| 419 | ## |
| 420 | |
| 421 | # ------------------------------------------------------------------------------ |
| 422 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 423 | #Method const SkImageInfo& info() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 424 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 425 | #Line # returns Image_Info ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 426 | Returns width, height, Alpha_Type, Color_Type, and Color_Space. |
| 427 | |
| 428 | #Return reference to Image_Info ## |
| 429 | |
| 430 | #Example |
| 431 | #Image 4 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 432 | void draw(SkCanvas* canvas) { |
| 433 | // SkBitmap source; // pre-populated with soccer ball by fiddle.skia.org |
| 434 | const SkImageInfo& info = source.info(); |
| 435 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 436 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 437 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 438 | SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(), |
| 439 | colors[info.colorType()], alphas[info.alphaType()]); |
| 440 | #StdOut |
| 441 | width: 56 height: 56 color: BGRA_8888 alpha: Opaque |
| 442 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 443 | } |
| 444 | ## |
| 445 | |
| 446 | #SeeAlso Image_Info |
| 447 | |
| 448 | ## |
| 449 | |
| 450 | # ------------------------------------------------------------------------------ |
| 451 | |
| 452 | #Method int width() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 453 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 454 | #Line # returns pixel column count ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 455 | Returns pixel count in each row. Should be equal or less than: |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 456 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 457 | #Formula |
| 458 | rowBytes() / info().bytesPerPixel() |
| 459 | ## |
| 460 | . |
| 461 | |
| 462 | Maybe be less than pixelRef().width(). Will not exceed pixelRef().width() less |
| 463 | pixelRefOrigin().fX. |
| 464 | |
| 465 | #Return pixel width in Image_Info ## |
| 466 | |
| 467 | #Example |
| 468 | SkImageInfo info = SkImageInfo::MakeA8(16, 32); |
| 469 | SkBitmap bitmap; |
| 470 | bitmap.setInfo(info); |
| 471 | SkDebugf("bitmap width: %d info width: %d\n", bitmap.width(), info.width()); |
| 472 | #StdOut |
| 473 | bitmap width: 16 info width: 16 |
| 474 | ## |
| 475 | ## |
| 476 | |
| 477 | #SeeAlso height() SkPixelRef::width() SkImageInfo::width() |
| 478 | |
| 479 | ## |
| 480 | |
| 481 | # ------------------------------------------------------------------------------ |
| 482 | |
| 483 | #Method int height() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 484 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 485 | #Line # returns pixel row count ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 486 | Returns pixel row count. |
| 487 | |
| 488 | Maybe be less than pixelRef().height(). Will not exceed pixelRef().height() less |
| 489 | pixelRefOrigin().fY. |
| 490 | |
| 491 | #Return pixel height in Image_Info ## |
| 492 | |
| 493 | #Example |
| 494 | SkImageInfo info = SkImageInfo::MakeA8(16, 32); |
| 495 | SkBitmap bitmap; |
| 496 | bitmap.setInfo(info); |
| 497 | SkDebugf("bitmap height: %d info height: %d\n", bitmap.height(), info.height()); |
| 498 | #StdOut |
| 499 | bitmap height: 32 info height: 32 |
| 500 | ## |
| 501 | ## |
| 502 | |
| 503 | #SeeAlso width() SkPixelRef::height() SkImageInfo::height() |
| 504 | |
| 505 | ## |
| 506 | |
| 507 | # ------------------------------------------------------------------------------ |
| 508 | |
| 509 | #Method SkColorType colorType() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 510 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 511 | #Line # returns Image_Info Color_Type ## |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 512 | Returns Color_Type, one of: #list_of_color_types#. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 513 | |
| 514 | #Return Color_Type in Image_Info ## |
| 515 | |
| 516 | #Example |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 517 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 518 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 519 | SkBitmap bitmap; |
| 520 | bitmap.setInfo(SkImageInfo::MakeA8(16, 32)); |
| 521 | SkDebugf("color type: k" "%s" "_SkColorType\n", colors[bitmap.colorType()]); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 522 | #StdOut |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 523 | color type: kAlpha_8_SkColorType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 524 | ## |
| 525 | ## |
| 526 | |
| 527 | #SeeAlso alphaType() SkImageInfo::colorType |
| 528 | |
| 529 | ## |
| 530 | |
| 531 | # ------------------------------------------------------------------------------ |
| 532 | |
| 533 | #Method SkAlphaType alphaType() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 534 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 535 | #Line # returns Image_Info Alpha_Type ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 536 | Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 537 | kPremul_SkAlphaType, kUnpremul_SkAlphaType. |
| 538 | |
| 539 | #Return Alpha_Type in Image_Info ## |
| 540 | |
| 541 | #Example |
| 542 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; |
| 543 | SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); |
| 544 | SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]); |
| 545 | #StdOut |
| 546 | alpha type: kPremul_SkAlphaType |
| 547 | ## |
| 548 | ## |
| 549 | |
| 550 | #SeeAlso colorType() SkImageInfo::alphaType |
| 551 | |
| 552 | ## |
| 553 | |
| 554 | # ------------------------------------------------------------------------------ |
| 555 | |
| 556 | #Method SkColorSpace* colorSpace() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 557 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 558 | #Line # returns Image_Info Color_Space ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 559 | Returns Color_Space, the range of colors, associated with Image_Info. The |
| 560 | reference count of Color_Space is unchanged. The returned Color_Space is |
| 561 | immutable. |
| 562 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 563 | #Return Color_Space in Image_Info, or nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 564 | |
| 565 | #Example |
| 566 | #Description |
| 567 | SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma |
| 568 | and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma. |
| 569 | ## |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 570 | SkBitmap bitmap; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 571 | bitmap.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, |
| 572 | SkColorSpace::MakeSRGBLinear())); |
| 573 | SkColorSpace* colorSpace = bitmap.colorSpace(); |
| 574 | SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", |
| 575 | colorSpace->gammaCloseToSRGB() ? "true" : "false", |
| 576 | colorSpace->gammaIsLinear() ? "true" : "false", |
| 577 | colorSpace->isSRGB() ? "true" : "false"); |
| 578 | #StdOut |
| 579 | gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false |
| 580 | ## |
| 581 | ## |
| 582 | |
| 583 | #SeeAlso Color_Space SkImageInfo::colorSpace |
| 584 | |
| 585 | ## |
| 586 | |
| 587 | # ------------------------------------------------------------------------------ |
| 588 | |
| 589 | #Method sk_sp<SkColorSpace> refColorSpace() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 590 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 591 | #Line # returns Image_Info Color_Space ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 592 | Returns a smart pointer to Color_Space, the range of colors, associated with |
| 593 | Image_Info. The smart pointer tracks the number of objects sharing this |
| 594 | Color_Space reference so the memory is released when the owners destruct. |
| 595 | |
| 596 | The returned Color_Space is immutable. |
| 597 | |
| 598 | #Return Color_Space in Image_Info wrapped in a smart pointer ## |
| 599 | |
| 600 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 601 | SkBitmap bitmap1, bitmap2; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 602 | bitmap1.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, |
| 603 | SkColorSpace::MakeSRGBLinear())); |
| 604 | bitmap2.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, |
| 605 | bitmap1.refColorSpace())); |
| 606 | SkColorSpace* colorSpace = bitmap2.colorSpace(); |
| 607 | SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", |
| 608 | colorSpace->gammaCloseToSRGB() ? "true" : "false", |
| 609 | colorSpace->gammaIsLinear() ? "true" : "false", |
| 610 | colorSpace->isSRGB() ? "true" : "false"); |
| 611 | #StdOut |
| 612 | gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false |
| 613 | ## |
| 614 | ## |
| 615 | |
| 616 | #SeeAlso Color_Space SkImageInfo::colorSpace |
| 617 | |
| 618 | ## |
| 619 | |
| 620 | # ------------------------------------------------------------------------------ |
| 621 | |
| 622 | #Method int bytesPerPixel() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 623 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 624 | #Line # returns number of bytes in pixel based on Color_Type ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 625 | Returns number of bytes per pixel required by Color_Type. |
| 626 | Returns zero if colorType( is kUnknown_SkColorType. |
| 627 | |
| 628 | #Return bytes in pixel ## |
| 629 | |
| 630 | #Example |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 631 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 632 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 633 | SkImageInfo info = SkImageInfo::MakeA8(1, 1); |
| 634 | SkBitmap bitmap; |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 635 | for (SkColorType colorType : { #list_of_color_types# |
| 636 | } ) { |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 637 | bitmap.setInfo(info.makeColorType(colorType)); |
| 638 | SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n", |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 639 | colors[colorType], 13 - strlen(colors[colorType]), " ", |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 640 | bitmap.bytesPerPixel()); |
| 641 | } |
| 642 | #StdOut |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 643 | color: kUnknown_SkColorType bytesPerPixel: 0
|
| 644 | color: kAlpha_8_SkColorType bytesPerPixel: 1
|
| 645 | color: kRGB_565_SkColorType bytesPerPixel: 2
|
| 646 | color: kARGB_4444_SkColorType bytesPerPixel: 2
|
| 647 | color: kRGBA_8888_SkColorType bytesPerPixel: 4
|
| 648 | color: kRGB_888x_SkColorType bytesPerPixel: 4
|
| 649 | color: kBGRA_8888_SkColorType bytesPerPixel: 4
|
| 650 | color: kRGBA_1010102_SkColorType bytesPerPixel: 4
|
| 651 | color: kRGB_101010x_SkColorType bytesPerPixel: 4
|
| 652 | color: kGray_8_SkColorType bytesPerPixel: 1
|
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 653 | color: kRGBA_F16_SkColorType bytesPerPixel: 8 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 654 | ## |
| 655 | ## |
| 656 | |
| 657 | #SeeAlso rowBytes rowBytesAsPixels width shiftPerPixel |
| 658 | |
| 659 | ## |
| 660 | |
| 661 | # ------------------------------------------------------------------------------ |
| 662 | |
| 663 | #Method int rowBytesAsPixels() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 664 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 665 | #Line # returns interval between rows in pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 666 | Returns number of pixels that fit on row. Should be greater than or equal to |
| 667 | width(). |
| 668 | |
| 669 | #Return maximum pixels per row ## |
| 670 | |
| 671 | #Example |
| 672 | SkBitmap bitmap; |
| 673 | for (int rowBytes : { 4, 5, 6, 7, 8} ) { |
| 674 | bitmap.setInfo(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), rowBytes); |
| 675 | SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, bitmap.rowBytesAsPixels()); |
| 676 | } |
| 677 | #StdOut |
| 678 | rowBytes: 4 rowBytesAsPixels: 1 |
| 679 | rowBytes: 5 rowBytesAsPixels: 1 |
| 680 | rowBytes: 6 rowBytesAsPixels: 1 |
| 681 | rowBytes: 7 rowBytesAsPixels: 1 |
| 682 | rowBytes: 8 rowBytesAsPixels: 2 |
| 683 | ## |
| 684 | ## |
| 685 | |
| 686 | #SeeAlso rowBytes shiftPerPixel width bytesPerPixel |
| 687 | |
| 688 | ## |
| 689 | |
| 690 | # ------------------------------------------------------------------------------ |
| 691 | |
| 692 | #Method int shiftPerPixel() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 693 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 694 | #Line # returns bit shift from pixels to bytes ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 695 | Returns bit shift converting row bytes to row pixels. |
| 696 | Returns zero for kUnknown_SkColorType. |
| 697 | |
| 698 | #Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ## |
| 699 | |
| 700 | #Example |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 701 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 702 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 703 | SkImageInfo info = SkImageInfo::MakeA8(1, 1); |
| 704 | SkBitmap bitmap; |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 705 | for (SkColorType colorType : { #list_of_color_types# |
| 706 | } ) { |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 707 | bitmap.setInfo(info.makeColorType(colorType)); |
| 708 | SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n", |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 709 | colors[colorType], 14 - strlen(colors[colorType]), " ", |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 710 | bitmap.shiftPerPixel()); |
| 711 | } |
| 712 | #StdOut |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 713 | color: kUnknown_SkColorType shiftPerPixel: 0
|
| 714 | color: kAlpha_8_SkColorType shiftPerPixel: 0
|
| 715 | color: kRGB_565_SkColorType shiftPerPixel: 1
|
| 716 | color: kARGB_4444_SkColorType shiftPerPixel: 1
|
| 717 | color: kRGBA_8888_SkColorType shiftPerPixel: 2
|
| 718 | color: kRGB_888x_SkColorType shiftPerPixel: 2
|
| 719 | color: kBGRA_8888_SkColorType shiftPerPixel: 2
|
| 720 | color: kRGBA_1010102_SkColorType shiftPerPixel: 2
|
| 721 | color: kRGB_101010x_SkColorType shiftPerPixel: 2
|
| 722 | color: kGray_8_SkColorType shiftPerPixel: 0
|
| 723 | color: kRGBA_F16_SkColorType shiftPerPixel: 3 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 724 | ## |
| 725 | ## |
| 726 | |
| 727 | #SeeAlso rowBytes rowBytesAsPixels width bytesPerPixel |
| 728 | |
| 729 | ## |
| 730 | |
| 731 | # ------------------------------------------------------------------------------ |
| 732 | |
| 733 | #Method bool empty() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 734 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 735 | #Line # returns true if Image_Info has zero width() or height() ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 736 | Returns true if either width() or height() are zero. |
| 737 | |
| 738 | Does not check if Pixel_Ref is nullptr; call drawsNothing to check width(), |
| 739 | height(), and Pixel_Ref. |
| 740 | |
| 741 | #Return true if dimensions do not enclose area ## |
| 742 | |
| 743 | #Example |
| 744 | SkBitmap bitmap; |
| 745 | for (int width : { 0, 2 } ) { |
| 746 | for (int height : { 0, 2 } ) { |
| 747 | bitmap.setInfo(SkImageInfo::MakeA8(width, height)); |
| 748 | SkDebugf("width: %d height: %d empty: %s\n", width, height, |
| 749 | bitmap.empty() ? "true" : "false"); |
| 750 | } |
| 751 | } |
| 752 | #StdOut |
| 753 | width: 0 height: 0 empty: true |
| 754 | width: 0 height: 2 empty: true |
| 755 | width: 2 height: 0 empty: true |
| 756 | width: 2 height: 2 empty: false |
| 757 | ## |
| 758 | ## |
| 759 | |
| 760 | #SeeAlso height() width() drawsNothing |
| 761 | |
| 762 | ## |
| 763 | |
| 764 | # ------------------------------------------------------------------------------ |
| 765 | |
| 766 | #Method bool isNull() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 767 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 768 | #Line # returns true if Pixel_Ref is nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 769 | Return true if Pixel_Ref is nullptr. |
| 770 | |
| 771 | Does not check if width() or height() are zero; call drawsNothing to check |
| 772 | width(), height(), and Pixel_Ref. |
| 773 | |
| 774 | #Return true if no Pixel_Ref is associated ## |
| 775 | |
| 776 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 777 | SkBitmap bitmap; |
| 778 | SkDebugf("empty bitmap does %shave pixels\n", bitmap.isNull() ? "not " : ""); |
| 779 | bitmap.setInfo(SkImageInfo::MakeA8(8, 8)); |
| 780 | SkDebugf("bitmap with dimensions does %shave pixels\n", bitmap.isNull() ? "not " : ""); |
| 781 | bitmap.allocPixels(); |
| 782 | SkDebugf("allocated bitmap does %shave pixels\n", bitmap.isNull() ? "not " : ""); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 783 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 784 | empty bitmap does not have pixels |
| 785 | bitmap with dimensions does not have pixels |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 786 | allocated bitmap does have pixels |
| 787 | ## |
| 788 | ## |
| 789 | |
| 790 | #SeeAlso empty() drawsNothing pixelRef |
| 791 | |
| 792 | ## |
| 793 | |
| 794 | # ------------------------------------------------------------------------------ |
| 795 | |
| 796 | #Method bool drawsNothing() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 797 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 798 | #Line # returns true if no width(), no height(), or no Pixel_Ref ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 799 | Return true if width() or height() are zero, or if Pixel_Ref is nullptr. |
| 800 | If true, Bitmap has no effect when drawn or drawn into. |
| 801 | |
| 802 | #Return true if drawing has no effect ## |
| 803 | |
| 804 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 805 | SkBitmap bitmap; |
| 806 | for (int w : { 0, 8 } ) { |
| 807 | for (bool allocate : { false, true} ) { |
| 808 | bitmap.setInfo(SkImageInfo::MakeA8(w, 8)); |
| 809 | allocate ? bitmap.allocPixels() : (void) 0 ; |
| 810 | SkDebugf("empty:%s isNull:%s drawsNothing:%s\n", bitmap.empty() ? "true " : "false", |
| 811 | bitmap.isNull() ? "true " : "false", bitmap.drawsNothing() ? "true" : "false"); |
| 812 | } |
| 813 | } |
| 814 | #StdOut |
| 815 | empty:true isNull:true drawsNothing:true |
| 816 | empty:true isNull:false drawsNothing:true |
| 817 | empty:false isNull:true drawsNothing:true |
| 818 | empty:false isNull:false drawsNothing:false |
| 819 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 820 | ## |
| 821 | |
| 822 | #SeeAlso empty() isNull pixelRef |
| 823 | |
| 824 | ## |
| 825 | |
| 826 | # ------------------------------------------------------------------------------ |
| 827 | |
| 828 | #Method size_t rowBytes() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 829 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 830 | #Line # returns interval between rows in bytes ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 831 | Returns row bytes, the interval from one pixel row to the next. Row bytes |
| 832 | is at least as large as |
| 833 | #Formula |
| 834 | width() * info().bytesPerPixel() |
| 835 | ## |
| 836 | . |
| 837 | |
| 838 | Returns zero if colorType is kUnknown_SkColorType, or if row bytes supplied to |
| 839 | setInfo is not large enough to hold a row of pixels. |
| 840 | |
| 841 | #Return byte length of pixel row ## |
| 842 | |
| 843 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 844 | SkBitmap bitmap; |
| 845 | for (int rowBytes : { 2, 8 } ) { |
| 846 | bool result = bitmap.setInfo(SkImageInfo::MakeA8(4, 4), rowBytes); |
| 847 | SkDebugf("setInfo returned:%s rowBytes:%d\n", result ? "true " : "false", bitmap.rowBytes()); |
| 848 | } |
| 849 | #StdOut |
| 850 | setInfo returned:false rowBytes:0 |
| 851 | setInfo returned:true rowBytes:8 |
| 852 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 853 | ## |
| 854 | |
| 855 | #SeeAlso info() setInfo SkImageInfo::minRowBytes |
| 856 | |
| 857 | ## |
| 858 | |
| 859 | # ------------------------------------------------------------------------------ |
| 860 | |
| 861 | #Method bool setAlphaType(SkAlphaType alphaType) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 862 | #In Set |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 863 | #Line # sets Alpha_Type of shared pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 864 | Sets Alpha_Type, if alphaType is compatible with Color_Type. |
| 865 | Returns true unless alphaType is kUnknown_SkAlphaType and current Alpha_Type |
| 866 | is not kUnknown_SkAlphaType. |
| 867 | |
| 868 | Returns true if Color_Type is kUnknown_SkColorType. alphaType is ignored, and |
| 869 | Alpha_Type remains kUnknown_SkAlphaType. |
| 870 | |
| 871 | Returns true if Color_Type is kRGB_565_SkColorType or kGray_8_SkColorType. |
| 872 | alphaType is ignored, and Alpha_Type remains kOpaque_SkAlphaType. |
| 873 | |
| 874 | If Color_Type is kARGB_4444_SkColorType, kRGBA_8888_SkColorType, |
| 875 | kBGRA_8888_SkColorType, or kRGBA_F16_SkColorType: returns true unless |
| 876 | alphaType is kUnknown_SkAlphaType and Alpha_Type is not kUnknown_SkAlphaType. |
| 877 | If Alpha_Type is kUnknown_SkAlphaType, alphaType is ignored. |
| 878 | |
| 879 | If Color_Type is kAlpha_8_SkColorType, returns true unless |
| 880 | alphaType is kUnknown_SkAlphaType and Alpha_Type is not kUnknown_SkAlphaType. |
| 881 | If Alpha_Type is kUnknown_SkAlphaType, alphaType is ignored. If alphaType is |
| 882 | kUnpremul_SkAlphaType, it is treated as kPremul_SkAlphaType. |
| 883 | |
| 884 | This changes Alpha_Type in Pixel_Ref; all bitmaps sharing Pixel_Ref |
| 885 | are affected. |
| 886 | |
| 887 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 888 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 889 | ## |
| 890 | |
| 891 | #Return true if Alpha_Type is set ## |
| 892 | |
| 893 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 894 | void draw(SkCanvas* canvas) { |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 895 | const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 896 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" }; |
| 897 | const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"}; |
| 898 | SkBitmap bitmap; |
| 899 | SkAlphaType alphaTypes[] = { kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 900 | kPremul_SkAlphaType, kUnpremul_SkAlphaType }; |
| 901 | SkDebugf("%88s", "Canonical Unknown Opaque Premul Unpremul\n"); |
Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 902 | for (SkColorType colorType : { #list_of_color_types# |
| 903 | } ) { |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 904 | for (SkAlphaType canonicalAlphaType : alphaTypes) { |
| 905 | SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType ); |
| 906 | SkDebugf("%10s %10s ", colors[(int) colorType], alphas[(int) canonicalAlphaType ]); |
| 907 | for (SkAlphaType alphaType : alphaTypes) { |
| 908 | bitmap.setInfo(SkImageInfo::Make(4, 4, colorType, canonicalAlphaType)); |
| 909 | bool result = bitmap.setAlphaType(alphaType); |
| 910 | SkDebugf("%s %s ", result ? "true " : "false", alphas[(int) bitmap.alphaType()]); |
| 911 | } |
| 912 | SkDebugf("\n"); |
| 913 | } |
| 914 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 915 | } |
| 916 | ## |
| 917 | |
| 918 | #SeeAlso Alpha_Type Color_Type Image_Info setInfo |
| 919 | |
| 920 | ## |
| 921 | |
| 922 | # ------------------------------------------------------------------------------ |
| 923 | |
| 924 | #Method void* getPixels() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 925 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 926 | #Line # returns address of pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 927 | Returns pixel address, the base address corresponding to the pixel origin. |
| 928 | |
| 929 | #Return pixel address ## |
| 930 | |
| 931 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 932 | SkBitmap bitmap; |
| 933 | bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType)); |
| 934 | bitmap.allocPixels(); |
| 935 | bitmap.eraseColor(0x00000000); |
| 936 | void* baseAddr = bitmap.getPixels(); |
| 937 | *(SkPMColor*)baseAddr = 0xFFFFFFFF; |
| 938 | SkDebugf("bitmap.getColor(0, 1) %c= 0x00000000\n", |
| 939 | bitmap.getColor(0, 1) == 0x00000000 ? '=' : '!'); |
| 940 | SkDebugf("bitmap.getColor(0, 0) %c= 0xFFFFFFFF\n", |
| 941 | bitmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!'); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 942 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 943 | bitmap.getColor(0, 1) == 0x00000000 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 944 | bitmap.getColor(0, 0) == 0xFFFFFFFF |
| 945 | ## |
| 946 | ## |
| 947 | |
| 948 | #SeeAlso isNull drawsNothing |
| 949 | |
| 950 | ## |
| 951 | |
| 952 | # ------------------------------------------------------------------------------ |
| 953 | |
| 954 | #Method size_t computeByteSize() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 955 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 956 | #Line # returns size required for pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 957 | Returns minimum memory required for pixel storage. |
| 958 | Does not include unused memory on last row when rowBytesAsPixels exceeds width(). |
| 959 | Returns zero if result does not fit in size_t. |
| 960 | Returns zero if height() or width() is 0. |
| 961 | Returns height() times rowBytes if colorType is kUnknown_SkColorType. |
| 962 | |
| 963 | #Return size in bytes of image buffer ## |
| 964 | |
| 965 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 966 | SkBitmap bitmap; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 967 | for (int width : { 1, 1000, 1000000 } ) { |
| 968 | for (int height: { 1, 1000, 1000000 } ) { |
| 969 | SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType); |
| 970 | bitmap.setInfo(imageInfo, width * 5); |
| 971 | SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height, |
| 972 | bitmap.computeByteSize()); |
| 973 | } |
| 974 | } |
| 975 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 976 | width: 1 height: 1 computeByteSize: 4 |
| 977 | width: 1 height: 1000 computeByteSize: 4999 |
| 978 | width: 1 height: 1000000 computeByteSize: 4999999 |
| 979 | width: 1000 height: 1 computeByteSize: 4000 |
| 980 | width: 1000 height: 1000 computeByteSize: 4999000 |
| 981 | width: 1000 height: 1000000 computeByteSize: 4999999000 |
| 982 | width: 1000000 height: 1 computeByteSize: 4000000 |
| 983 | width: 1000000 height: 1000 computeByteSize: 4999000000 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 984 | width: 1000000 height: 1000000 computeByteSize: 4999999000000 |
| 985 | ## |
| 986 | ## |
| 987 | |
| 988 | #SeeAlso SkImageInfo::computeByteSize |
| 989 | |
| 990 | ## |
| 991 | |
| 992 | # ------------------------------------------------------------------------------ |
| 993 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 994 | #Method bool isImmutable() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 995 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 996 | #Line # returns true if pixels will not change ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 997 | Returns true if pixels can not change. |
| 998 | |
| 999 | Most immutable Bitmap checks trigger an assert only on debug builds. |
| 1000 | |
| 1001 | #Return true if pixels are immutable ## |
| 1002 | |
| 1003 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1004 | SkBitmap original; |
| 1005 | SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); |
| 1006 | if (original.tryAllocPixels(info)) { |
| 1007 | original.setImmutable(); |
| 1008 | SkBitmap copy; |
| 1009 | original.extractSubset(©, {5, 10, 15, 20}); |
| 1010 | SkDebugf("original is " "%s" "immutable\n", original.isImmutable() ? "" : "not "); |
| 1011 | SkDebugf("copy is " "%s" "immutable\n", copy.isImmutable() ? "" : "not "); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1012 | } |
| 1013 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1014 | original is immutable |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1015 | copy is immutable |
| 1016 | ## |
| 1017 | ## |
| 1018 | |
| 1019 | #SeeAlso setImmutable SkPixelRef::isImmutable SkImage |
| 1020 | |
| 1021 | ## |
| 1022 | |
| 1023 | # ------------------------------------------------------------------------------ |
| 1024 | |
| 1025 | #Method void setImmutable() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1026 | #In Set |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1027 | #Line # marks that pixels will not change ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1028 | Sets internal flag to mark Bitmap as immutable. Once set, pixels can not change. |
| 1029 | Any other bitmap sharing the same Pixel_Ref are also marked as immutable. |
| 1030 | Once Pixel_Ref is marked immutable, the setting cannot be cleared. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1031 | |
| 1032 | Writing to immutable Bitmap pixels triggers an assert on debug builds. |
| 1033 | |
| 1034 | #Example |
| 1035 | #Description |
| 1036 | Triggers assert if SK_DEBUG is true, runs fine otherwise. |
| 1037 | ## |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1038 | SkBitmap bitmap; |
| 1039 | bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType)); |
| 1040 | bitmap.allocPixels(); |
| 1041 | SkCanvas offscreen(bitmap); |
| 1042 | SkDebugf("draw white\n"); |
| 1043 | offscreen.clear(SK_ColorWHITE); |
| 1044 | bitmap.setImmutable(); |
| 1045 | SkDebugf("draw black\n"); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1046 | offscreen.clear(SK_ColorBLACK); |
| 1047 | ## |
| 1048 | |
| 1049 | #SeeAlso isImmutable SkPixelRef::setImmutable SkImage |
| 1050 | |
| 1051 | ## |
| 1052 | |
| 1053 | # ------------------------------------------------------------------------------ |
| 1054 | |
| 1055 | #Method bool isOpaque() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1056 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1057 | #Line # returns true if Image_Info describes opaque pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1058 | Returns true if Alpha_Type is kOpaque_SkAlphaType. |
| 1059 | Does not check if Color_Type allows Alpha, or if any pixel value has |
| 1060 | transparency. |
| 1061 | |
| 1062 | #Return true if Image_Info describes opaque Alpha ## |
| 1063 | |
| 1064 | #Example |
| 1065 | #Description |
| 1066 | isOpaque ignores whether all pixels are opaque or not. |
| 1067 | ## |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1068 | const int height = 2; |
| 1069 | const int width = 2; |
| 1070 | SkBitmap bitmap; |
| 1071 | bitmap.setInfo(SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType)); |
| 1072 | for (int index = 0; index < 2; ++index) { |
| 1073 | bitmap.allocPixels(); |
| 1074 | bitmap.eraseColor(0x00000000); |
| 1075 | SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false"); |
| 1076 | bitmap.eraseColor(0xFFFFFFFF); |
| 1077 | SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false"); |
| 1078 | bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType)); |
| 1079 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1080 | #StdOut |
| 1081 | isOpaque: false |
| 1082 | isOpaque: false |
| 1083 | isOpaque: true |
| 1084 | isOpaque: true |
| 1085 | ## |
| 1086 | ## |
| 1087 | |
| 1088 | #SeeAlso ComputeIsOpaque SkImageInfo::isOpaque |
| 1089 | |
| 1090 | ## |
| 1091 | |
| 1092 | # ------------------------------------------------------------------------------ |
| 1093 | |
| 1094 | #Method bool isVolatile() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1095 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1096 | #Line # returns true if pixels should not be cached ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1097 | If true, provides a hint to caller that pixels should not |
| 1098 | be cached. Only true if setIsVolatile has been called to mark as volatile. |
| 1099 | |
| 1100 | Volatile state is not shared by other bitmaps sharing the same Pixel_Ref. |
| 1101 | |
| 1102 | #Return true if marked volatile ## |
| 1103 | |
| 1104 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1105 | SkBitmap original; |
| 1106 | SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); |
| 1107 | if (original.tryAllocPixels(info)) { |
| 1108 | original.setIsVolatile(true); |
| 1109 | SkBitmap copy; |
| 1110 | original.extractSubset(©, {5, 10, 15, 20}); |
| 1111 | SkDebugf("original is " "%s" "volatile\n", original.isVolatile() ? "" : "not "); |
| 1112 | SkDebugf("copy is " "%s" "volatile\n", copy.isImmutable() ? "" : "not "); |
| 1113 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1114 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1115 | original is volatile |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1116 | copy is not volatile |
| 1117 | ## |
| 1118 | ## |
| 1119 | |
| 1120 | #SeeAlso setIsVolatile |
| 1121 | |
| 1122 | ## |
| 1123 | |
| 1124 | # ------------------------------------------------------------------------------ |
| 1125 | |
| 1126 | #Method void setIsVolatile(bool isVolatile) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1127 | #In Set |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1128 | #Line # marks if pixels should not be cached ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1129 | Sets if pixels should be read from Pixel_Ref on every access. Bitmaps are not |
| 1130 | volatile by default; a GPU back end may upload pixel values expecting them to be |
| 1131 | accessed repeatedly. Marking temporary Bitmaps as volatile provides a hint to |
| 1132 | Device that the Bitmap pixels should not be cached. This can |
| 1133 | improve performance by avoiding overhead and reducing resource |
| 1134 | consumption on Device. |
| 1135 | |
| 1136 | #Param isVolatile true if backing pixels are temporary ## |
| 1137 | |
| 1138 | #Example |
| 1139 | #Height 20 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1140 | SkBitmap bitmap; |
| 1141 | bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 1142 | bitmap.allocPixels(); |
| 1143 | bitmap.eraseColor(SK_ColorRED); |
| 1144 | canvas->scale(16, 16); |
| 1145 | canvas->drawBitmap(bitmap, 0, 0); |
| 1146 | *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE); |
| 1147 | canvas->drawBitmap(bitmap, 2, 0); |
| 1148 | bitmap.setIsVolatile(true); |
| 1149 | *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN); |
| 1150 | canvas->drawBitmap(bitmap, 4, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1151 | ## |
| 1152 | |
| 1153 | #SeeAlso isVolatile |
| 1154 | |
| 1155 | ## |
| 1156 | |
| 1157 | # ------------------------------------------------------------------------------ |
| 1158 | |
| 1159 | #Method void reset() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1160 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1161 | #Line # sets to default values, releases pixel ownership ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1162 | Resets to its initial state; all fields are set to zero, as if Bitmap had |
| 1163 | been initialized by SkBitmap(). |
| 1164 | |
| 1165 | Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to |
| 1166 | kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType. |
| 1167 | |
| 1168 | If Pixel_Ref is allocated, its reference count is decreased by one, releasing |
| 1169 | its memory if Bitmap is the sole owner. |
| 1170 | |
| 1171 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1172 | SkBitmap bitmap; |
| 1173 | bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 1174 | bitmap.allocPixels(); |
| 1175 | SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(), |
| 1176 | bitmap.isNull() ? "true" : "false"); |
| 1177 | bitmap.reset(); |
| 1178 | SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(), |
| 1179 | bitmap.isNull() ? "true" : "false"); |
| 1180 | #StdOut |
| 1181 | width:1 height:1 isNull:false |
| 1182 | width:0 height:0 isNull:true |
| 1183 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1184 | ## |
| 1185 | |
| 1186 | #SeeAlso SkBitmap() SkAlphaType SkColorType |
| 1187 | |
| 1188 | ## |
| 1189 | |
| 1190 | # ------------------------------------------------------------------------------ |
| 1191 | |
| 1192 | #Method static bool ComputeIsOpaque(const SkBitmap& bm) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1193 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1194 | #Line # returns true if all pixels are opaque ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1195 | Returns true if all pixels are opaque. Color_Type determines how pixels |
| 1196 | are encoded, and whether pixel describes Alpha. Returns true for Color_Types |
| 1197 | without alpha in each pixel; for other Color_Types, returns true if all |
| 1198 | pixels have alpha values equivalent to 1.0 or greater. |
| 1199 | |
| 1200 | For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always |
| 1201 | returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType, |
| 1202 | kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255. |
| 1203 | For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15. |
| 1204 | For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or |
| 1205 | greater. |
| 1206 | |
| 1207 | Returns false for kUnknown_SkColorType. |
| 1208 | |
| 1209 | #Param bm Bitmap to check ## |
| 1210 | |
| 1211 | #Return true if all pixels have opaque values or Color_Type is opaque ## |
| 1212 | |
| 1213 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1214 | SkBitmap bitmap; |
| 1215 | bitmap.setInfo(SkImageInfo::Make(2, 2, kN32_SkColorType, kPremul_SkAlphaType)); |
| 1216 | for (int index = 0; index < 2; ++index) { |
| 1217 | bitmap.allocPixels(); |
| 1218 | bitmap.eraseColor(0x00000000); |
| 1219 | SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false"); |
| 1220 | bitmap.eraseColor(0xFFFFFFFF); |
| 1221 | SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false"); |
| 1222 | bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType)); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1223 | } |
| 1224 | #StdOut |
| 1225 | computeIsOpaque: false |
| 1226 | computeIsOpaque: true |
| 1227 | computeIsOpaque: false |
| 1228 | computeIsOpaque: true |
| 1229 | ## |
| 1230 | ## |
| 1231 | |
| 1232 | #SeeAlso isOpaque Color_Type Alpha |
| 1233 | |
| 1234 | ## |
| 1235 | |
| 1236 | # ------------------------------------------------------------------------------ |
| 1237 | |
| 1238 | #Method void getBounds(SkRect* bounds) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1239 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1240 | #Line # returns width() and height() as Rectangle ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1241 | Returns Rect { 0, 0, width(), height() }. |
| 1242 | |
| 1243 | #Param bounds container for floating point rectangle ## |
| 1244 | |
| 1245 | #Example |
| 1246 | #Height 160 |
| 1247 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1248 | SkRect bounds; |
| 1249 | source.getBounds(&bounds); |
| 1250 | bounds.offset(100, 100); |
| 1251 | SkPaint paint; |
| 1252 | paint.setColor(SK_ColorGRAY); |
| 1253 | canvas->scale(.25f, .25f); |
| 1254 | canvas->drawRect(bounds, paint); |
| 1255 | canvas->drawBitmap(source, 40, 40); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1256 | ## |
| 1257 | |
| 1258 | #SeeAlso bounds() |
| 1259 | |
| 1260 | ## |
| 1261 | |
| 1262 | # ------------------------------------------------------------------------------ |
| 1263 | |
| 1264 | #Method void getBounds(SkIRect* bounds) const |
| 1265 | |
| 1266 | Returns IRect { 0, 0, width(), height() }. |
| 1267 | |
| 1268 | #Param bounds container for integral rectangle ## |
| 1269 | |
| 1270 | #Example |
| 1271 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1272 | SkIRect bounds; |
| 1273 | source.getBounds(&bounds); |
| 1274 | bounds.inset(100, 100); |
| 1275 | SkBitmap bitmap; |
| 1276 | source.extractSubset(&bitmap, bounds); |
| 1277 | canvas->scale(.5f, .5f); |
| 1278 | canvas->drawBitmap(bitmap, 10, 10); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1279 | ## |
| 1280 | |
| 1281 | #SeeAlso bounds() |
| 1282 | |
| 1283 | ## |
| 1284 | |
| 1285 | # ------------------------------------------------------------------------------ |
| 1286 | |
| 1287 | #Method SkIRect bounds() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1288 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1289 | #Line # returns width() and height() as Rectangle ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1290 | Returns IRect { 0, 0, width(), height() }. |
| 1291 | |
| 1292 | #Return integral rectangle from origin to width() and height() ## |
| 1293 | |
| 1294 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1295 | #Height 128 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1296 | #Image 4 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1297 | canvas->scale(.5f, .5f); |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1298 | SkIRect bounds = source.bounds(); |
| 1299 | for (int x : { 0, bounds.width() } ) { |
| 1300 | for (int y : { 0, bounds.height() } ) { |
| 1301 | canvas->drawBitmap(source, x, y); |
| 1302 | } |
| 1303 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1304 | ## |
| 1305 | |
| 1306 | #SeeAlso getBounds |
| 1307 | |
| 1308 | ## |
| 1309 | |
| 1310 | # ------------------------------------------------------------------------------ |
| 1311 | |
| 1312 | #Method SkISize dimensions() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1313 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1314 | #Line # returns width() and height() ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1315 | Returns ISize { width(), height() }. |
| 1316 | |
| 1317 | #Return integral size of width() and height() ## |
| 1318 | |
| 1319 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1320 | SkBitmap bitmap; |
| 1321 | bitmap.setInfo(SkImageInfo::MakeN32(33, 55, kOpaque_SkAlphaType)); |
| 1322 | SkISize dimensions = bitmap.dimensions(); |
| 1323 | SkRect bounds; |
| 1324 | bitmap.getBounds(&bounds); |
| 1325 | SkRect dimensionsAsBounds = SkRect::Make(dimensions); |
| 1326 | SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1327 | ## |
| 1328 | |
| 1329 | #SeeAlso height() width() |
| 1330 | |
| 1331 | ## |
| 1332 | |
| 1333 | # ------------------------------------------------------------------------------ |
| 1334 | |
| 1335 | #Method SkIRect getSubset() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1336 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1337 | #Line # returns bounds offset by origin ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1338 | Returns the bounds of this bitmap, offset by its Pixel_Ref origin. |
| 1339 | |
| 1340 | #Return bounds within Pixel_Ref bounds ## |
| 1341 | |
| 1342 | #Example |
| 1343 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1344 | SkIRect bounds; |
| 1345 | source.getBounds(&bounds); |
| 1346 | bounds.inset(100, 100); |
| 1347 | SkBitmap subset; |
| 1348 | source.extractSubset(&subset, bounds); |
| 1349 | SkIRect r = source.getSubset(); |
| 1350 | SkDebugf("source: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 1351 | r = subset.getSubset(); |
| 1352 | SkDebugf("subset: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 1353 | #StdOut |
| 1354 | source: 0, 0, 512, 512 |
| 1355 | subset: 100, 100, 412, 412 |
| 1356 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1357 | ## |
| 1358 | |
| 1359 | #SeeAlso extractSubset getBounds |
| 1360 | |
| 1361 | ## |
| 1362 | |
| 1363 | # ------------------------------------------------------------------------------ |
| 1364 | |
| 1365 | #Method bool setInfo(const SkImageInfo& imageInfo, size_t rowBytes = 0) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1366 | #In Set |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1367 | #Line # sets height, width, Color_Type, and so on, releasing pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1368 | Sets width, height, Alpha_Type, Color_Type, Color_Space, and optional |
| 1369 | rowBytes. Frees pixels, and returns true if successful. |
| 1370 | |
| 1371 | imageInfo.alphaType may be altered to a value permitted by imageInfo.colorSpace. |
| 1372 | If imageInfo.colorType is kUnknown_SkColorType, imageInfo.alphaType is |
| 1373 | set to kUnknown_SkAlphaType. |
| 1374 | If imageInfo.colorType is kAlpha_8_SkColorType and imageInfo.alphaType is |
| 1375 | kUnpremul_SkAlphaType, imageInfo.alphaType is replaced by kPremul_SkAlphaType. |
| 1376 | If imageInfo.colorType is kRGB_565_SkColorType or kGray_8_SkColorType, |
| 1377 | imageInfo.alphaType is set to kOpaque_SkAlphaType. |
| 1378 | If imageInfo.colorType is kARGB_4444_SkColorType, kRGBA_8888_SkColorType, |
| 1379 | kBGRA_8888_SkColorType, or kRGBA_F16_SkColorType: imageInfo.alphaType remains |
| 1380 | unchanged. |
| 1381 | |
| 1382 | rowBytes must equal or exceed imageInfo.minRowBytes. If imageInfo.colorSpace is |
| 1383 | kUnknown_SkColorType, rowBytes is ignored and treated as zero; for all other |
| 1384 | Color_Space values, rowBytes of zero is treated as imageInfo.minRowBytes. |
| 1385 | |
| 1386 | Calls reset() and returns false if: |
| 1387 | #List |
| 1388 | # rowBytes exceeds 31 bits ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1389 | # imageInfo.width() is negative ## |
| 1390 | # imageInfo.height() is negative ## |
| 1391 | # rowBytes is positive and less than imageInfo.width() times imageInfo.bytesPerPixel ## |
| 1392 | ## |
| 1393 | |
| 1394 | #Param imageInfo contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 1395 | #Param rowBytes imageInfo.minRowBytes or larger; or zero ## |
| 1396 | |
| 1397 | #Return true if Image_Info set successfully ## |
| 1398 | |
| 1399 | #Example |
| 1400 | #Height 96 |
| 1401 | ###^ |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1402 | SkBitmap bitmap; |
| 1403 | bitmap.setInfo(SkImageInfo::MakeN32(44, 16, kOpaque_SkAlphaType)); |
| 1404 | bitmap.allocPixels(); |
| 1405 | bitmap.eraseColor(SK_ColorGREEN); |
| 1406 | SkCanvas offscreen(bitmap); |
| 1407 | SkPaint paint; |
| 1408 | offscreen.drawString("!@#$%", 0, 12, paint); |
| 1409 | canvas->scale(6, 6); |
| 1410 | canvas->drawBitmap(bitmap, 0, 0); |
| 1411 | ^^^# |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1412 | ## |
| 1413 | |
| 1414 | #SeeAlso Alpha_Type Color_Type Color_Space height rowBytes width |
| 1415 | |
| 1416 | ## |
| 1417 | |
| 1418 | # ------------------------------------------------------------------------------ |
| 1419 | |
| 1420 | #Enum AllocFlags |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1421 | #Line # zero pixel memory ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1422 | #Code |
| 1423 | enum AllocFlags { |
| 1424 | kZeroPixels_AllocFlag = 1 << 0, |
| 1425 | }; |
| 1426 | ## |
| 1427 | |
| 1428 | AllocFlags provides the option to zero pixel memory when allocated. |
| 1429 | |
| 1430 | #Const kZeroPixels_AllocFlag 1 |
| 1431 | Instructs tryAllocPixelsFlags and allocPixelsFlags to zero pixel memory. |
| 1432 | ## |
| 1433 | |
| 1434 | #NoExample |
| 1435 | ## |
| 1436 | |
| 1437 | #SeeAlso tryAllocPixelsFlags allocPixelsFlags erase() eraseColor |
| 1438 | |
| 1439 | ## |
| 1440 | |
| 1441 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1442 | #Subtopic Allocate |
| 1443 | #Populate |
| 1444 | #Line # allocates storage for pixels ## |
| 1445 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1446 | |
| 1447 | #Method bool SK_WARN_UNUSED_RESULT tryAllocPixelsFlags(const SkImageInfo& info, uint32_t flags) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1448 | #In Allocate |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1449 | #Line # allocates pixels from Image_Info with options if possible ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1450 | Sets Image_Info to info following the rules in setInfo and allocates pixel |
| 1451 | memory. If flags is kZeroPixels_AllocFlag, memory is zeroed. |
| 1452 | |
| 1453 | Returns false and calls reset() if Image_Info could not be set, or memory could |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1454 | not be allocated, or memory could not optionally be zeroed. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1455 | |
| 1456 | On most platforms, allocating pixel memory may succeed even though there is |
| 1457 | not sufficient memory to hold pixels; allocation does not take place |
| 1458 | until the pixels are written to. The actual behavior depends on the platform |
| 1459 | implementation of malloc(), if flags is zero, and calloc(), if flags is |
| 1460 | kZeroPixels_AllocFlag. |
| 1461 | |
| 1462 | Passing kZeroPixels_AllocFlag is usually faster than separately calling |
| 1463 | eraseColor(SK_ColorTRANSPARENT). |
| 1464 | |
| 1465 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 1466 | #Param flags kZeroPixels_AllocFlag, or zero ## |
| 1467 | |
| 1468 | #Return true if pixels allocation is successful ## |
| 1469 | |
| 1470 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1471 | SkBitmap bitmap; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1472 | if (!bitmap.tryAllocPixelsFlags(SkImageInfo::MakeN32(10000, 10000, kOpaque_SkAlphaType), |
| 1473 | SkBitmap::kZeroPixels_AllocFlag)) { |
| 1474 | SkDebugf("bitmap allocation failed!\n"); |
| 1475 | } else { |
| 1476 | SkDebugf("bitmap allocation succeeded!\n"); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1477 | } |
| 1478 | #StdOut |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1479 | bitmap allocation succeeded! |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1480 | ## |
| 1481 | ## |
| 1482 | |
| 1483 | #SeeAlso allocPixelsFlags tryAllocPixels SkMallocPixelRef::MakeZeroed |
| 1484 | |
| 1485 | ## |
| 1486 | |
| 1487 | # ------------------------------------------------------------------------------ |
| 1488 | |
| 1489 | #Method void allocPixelsFlags(const SkImageInfo& info, uint32_t flags) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1490 | #In Allocate |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1491 | #Line # allocates pixels from Image_Info with options, or aborts ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1492 | Sets Image_Info to info following the rules in setInfo and allocates pixel |
| 1493 | memory. If flags is kZeroPixels_AllocFlag, memory is zeroed. |
| 1494 | |
| 1495 | Aborts execution if Image_Info could not be set, or memory could |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1496 | not be allocated, or memory could not optionally |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1497 | be zeroed. Abort steps may be provided by the user at compile time by defining |
| 1498 | SK_ABORT. |
| 1499 | |
| 1500 | On most platforms, allocating pixel memory may succeed even though there is |
| 1501 | not sufficient memory to hold pixels; allocation does not take place |
| 1502 | until the pixels are written to. The actual behavior depends on the platform |
| 1503 | implementation of malloc(), if flags is zero, and calloc(), if flags is |
| 1504 | kZeroPixels_AllocFlag. |
| 1505 | |
| 1506 | Passing kZeroPixels_AllocFlag is usually faster than separately calling |
| 1507 | eraseColor(SK_ColorTRANSPARENT). |
| 1508 | |
| 1509 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 1510 | #Param flags kZeroPixels_AllocFlag, or zero ## |
| 1511 | |
| 1512 | #Example |
| 1513 | #Height 128 |
| 1514 | #Description |
| 1515 | Text is drawn on a transparent background; drawing the bitmap a second time |
| 1516 | lets the first draw show through. |
| 1517 | ## |
| 1518 | ###^ |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1519 | SkBitmap bitmap; |
| 1520 | bitmap.allocPixelsFlags(SkImageInfo::MakeN32(44, 16, kPremul_SkAlphaType), |
| 1521 | SkBitmap::kZeroPixels_AllocFlag); |
| 1522 | SkCanvas offscreen(bitmap); |
| 1523 | SkPaint paint; |
| 1524 | offscreen.drawString("!@#$%", 0, 12, paint); |
| 1525 | canvas->scale(6, 6); |
| 1526 | canvas->drawBitmap(bitmap, 0, 0); |
| 1527 | canvas->drawBitmap(bitmap, 8, 8); |
| 1528 | ^^^# |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1529 | ## |
| 1530 | |
| 1531 | #SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeZeroed |
| 1532 | |
| 1533 | ## |
| 1534 | |
| 1535 | # ------------------------------------------------------------------------------ |
| 1536 | |
| 1537 | #Method bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, size_t rowBytes) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1538 | #In Allocate |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1539 | #Line # allocates pixels from Image_Info if possible ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1540 | #ToDo am I ever conflicted about setInfo rules. It needs to be able to be replicated |
| 1541 | if, for instance, I generate one-page-per-method HTML-style documentation |
| 1542 | I'm not so sure it makes sense to put the indirection in for .h either unless |
| 1543 | my mantra is that .h should abbreviate full documentation. And, what to do |
| 1544 | for generated markdown? At least there the rules are a click away, although |
| 1545 | a pop-down in place would be way better. Hmmm. |
| 1546 | ## |
| 1547 | |
| 1548 | Sets Image_Info to info following the rules in setInfo and allocates pixel |
| 1549 | memory. rowBytes must equal or exceed info.width() times info.bytesPerPixel(), |
| 1550 | or equal zero. Pass in zero for rowBytes to compute the minimum valid value. |
| 1551 | |
| 1552 | Returns false and calls reset() if Image_Info could not be set, or memory could |
| 1553 | not be allocated. |
| 1554 | |
| 1555 | On most platforms, allocating pixel memory may succeed even though there is |
| 1556 | not sufficient memory to hold pixels; allocation does not take place |
| 1557 | until the pixels are written to. The actual behavior depends on the platform |
| 1558 | implementation of malloc(). |
| 1559 | |
| 1560 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 1561 | #Param rowBytes size of pixel row or larger; may be zero ## |
| 1562 | |
| 1563 | #Return true if pixel storage is allocated ## |
| 1564 | |
| 1565 | #Example |
| 1566 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1567 | SkBitmap bitmap; |
| 1568 | SkImageInfo info = SkImageInfo::Make(64, 256, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 1569 | if (bitmap.tryAllocPixels(info, 0)) { |
| 1570 | SkCanvas offscreen(bitmap); |
| 1571 | offscreen.scale(.5f, .5f); |
| 1572 | for (int x : { 0, 64, 128, 192 } ) { |
| 1573 | offscreen.drawBitmap(source, -x, 0); |
| 1574 | canvas->drawBitmap(bitmap, x, 0); |
| 1575 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1576 | } |
| 1577 | ## |
| 1578 | |
| 1579 | #SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate |
| 1580 | |
| 1581 | ## |
| 1582 | |
| 1583 | # ------------------------------------------------------------------------------ |
| 1584 | |
| 1585 | #Method void allocPixels(const SkImageInfo& info, size_t rowBytes) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1586 | #In Allocate |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1587 | #Line # allocates pixels from Image_Info, or aborts ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1588 | Sets Image_Info to info following the rules in setInfo and allocates pixel |
| 1589 | memory. rowBytes must equal or exceed info.width() times info.bytesPerPixel(), |
| 1590 | or equal zero. Pass in zero for rowBytes to compute the minimum valid value. |
| 1591 | |
| 1592 | Aborts execution if Image_Info could not be set, or memory could |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1593 | not be allocated. Abort steps may be provided by |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1594 | the user at compile time by defining SK_ABORT. |
| 1595 | |
| 1596 | On most platforms, allocating pixel memory may succeed even though there is |
| 1597 | not sufficient memory to hold pixels; allocation does not take place |
| 1598 | until the pixels are written to. The actual behavior depends on the platform |
| 1599 | implementation of malloc(). |
| 1600 | |
| 1601 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 1602 | #Param rowBytes size of pixel row or larger; may be zero ## |
| 1603 | |
| 1604 | #Example |
| 1605 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1606 | SkBitmap bitmap; |
| 1607 | SkImageInfo info = SkImageInfo::Make(256, 64, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 1608 | bitmap.allocPixels(info, info.width() * info.bytesPerPixel() + 64); |
| 1609 | SkCanvas offscreen(bitmap); |
| 1610 | offscreen.scale(.5f, .5f); |
| 1611 | for (int y : { 0, 64, 128, 192 } ) { |
| 1612 | offscreen.drawBitmap(source, 0, -y); |
| 1613 | canvas->drawBitmap(bitmap, 0, y); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1614 | } |
| 1615 | ## |
| 1616 | |
| 1617 | #SeeAlso tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate |
| 1618 | |
| 1619 | ## |
| 1620 | |
| 1621 | # ------------------------------------------------------------------------------ |
| 1622 | |
| 1623 | #Method bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info) |
| 1624 | |
| 1625 | Sets Image_Info to info following the rules in setInfo and allocates pixel |
| 1626 | memory. |
| 1627 | |
| 1628 | Returns false and calls reset() if Image_Info could not be set, or memory could |
| 1629 | not be allocated. |
| 1630 | |
| 1631 | On most platforms, allocating pixel memory may succeed even though there is |
| 1632 | not sufficient memory to hold pixels; allocation does not take place |
| 1633 | until the pixels are written to. The actual behavior depends on the platform |
| 1634 | implementation of malloc(). |
| 1635 | |
| 1636 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 1637 | |
| 1638 | #Return true if pixel storage is allocated ## |
| 1639 | |
| 1640 | #Example |
| 1641 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1642 | SkBitmap bitmap; |
| 1643 | if (bitmap.tryAllocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType))) { |
| 1644 | SkCanvas offscreen(bitmap); |
| 1645 | offscreen.scale(.25f, .5f); |
| 1646 | for (int y : { 0, 64, 128, 192 } ) { |
| 1647 | offscreen.drawBitmap(source, -y, -y); |
| 1648 | canvas->drawBitmap(bitmap, y, y); |
| 1649 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1650 | } |
| 1651 | ## |
| 1652 | |
| 1653 | #SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate |
| 1654 | |
| 1655 | ## |
| 1656 | |
| 1657 | # ------------------------------------------------------------------------------ |
| 1658 | |
| 1659 | #Method void allocPixels(const SkImageInfo& info) |
| 1660 | |
| 1661 | Sets Image_Info to info following the rules in setInfo and allocates pixel |
| 1662 | memory. |
| 1663 | |
| 1664 | Aborts execution if Image_Info could not be set, or memory could |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1665 | not be allocated. Abort steps may be provided by |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1666 | the user at compile time by defining SK_ABORT. |
| 1667 | |
| 1668 | On most platforms, allocating pixel memory may succeed even though there is |
| 1669 | not sufficient memory to hold pixels; allocation does not take place |
| 1670 | until the pixels are written to. The actual behavior depends on the platform |
| 1671 | implementation of malloc(). |
| 1672 | |
| 1673 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 1674 | |
| 1675 | #Example |
| 1676 | #Image 4 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1677 | SkBitmap bitmap; |
| 1678 | bitmap.allocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType)); |
| 1679 | SkCanvas offscreen(bitmap); |
| 1680 | offscreen.scale(.5f, .5f); |
| 1681 | for (int y : { 0, 64, 128, 192 } ) { |
| 1682 | offscreen.drawBitmap(source, -y, -y); |
| 1683 | canvas->drawBitmap(bitmap, y, y); |
| 1684 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1685 | ## |
| 1686 | |
| 1687 | #SeeAlso tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate |
| 1688 | |
| 1689 | ## |
| 1690 | |
| 1691 | # ------------------------------------------------------------------------------ |
| 1692 | |
| 1693 | #Method bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1694 | #In Allocate |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1695 | #Line # allocates compatible Color_ARGB pixels if possible ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1696 | Sets Image_Info to width, height, and Native_Color_Type; and allocates |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1697 | pixel memory. If isOpaque is true, sets Image_Info to kOpaque_SkAlphaType; |
| 1698 | otherwise, sets to kPremul_SkAlphaType. |
| 1699 | |
| 1700 | Calls reset() and returns false if width exceeds 29 bits or is negative, |
| 1701 | or height is negative. |
| 1702 | |
| 1703 | Returns false if allocation fails. |
| 1704 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1705 | Use to create Bitmap that matches SkPMColor, the native pixel arrangement on |
| 1706 | the platform. Bitmap drawn to output device skips converting its pixel format. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1707 | |
| 1708 | #Param width pixel column count; must be zero or greater ## |
| 1709 | #Param height pixel row count; must be zero or greater ## |
| 1710 | #Param isOpaque true if pixels do not have transparency ## |
| 1711 | |
| 1712 | #Return true if pixel storage is allocated ## |
| 1713 | |
| 1714 | #Example |
| 1715 | #Height 160 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1716 | SkBitmap bitmap; |
| 1717 | if (bitmap.tryAllocN32Pixels(80, 80)) { |
| 1718 | bitmap.eraseColor(SK_ColorTRANSPARENT); |
| 1719 | bitmap.erase(0x7f3f7fff, SkIRect::MakeWH(50, 30)); |
| 1720 | bitmap.erase(0x3f7fff3f, SkIRect::MakeXYWH(20, 10, 50, 30)); |
| 1721 | bitmap.erase(0x5fff3f7f, SkIRect::MakeXYWH(40, 20, 50, 30)); |
| 1722 | canvas->drawBitmap(bitmap, 0, 0); |
| 1723 | for (int x : { 0, 30, 60, 90 } ) { |
| 1724 | canvas->drawBitmap(bitmap, x, 70); |
| 1725 | } |
| 1726 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1727 | ## |
| 1728 | |
| 1729 | #SeeAlso tryAllocPixels allocN32Pixels SkMallocPixelRef::MakeAllocate |
| 1730 | |
| 1731 | ## |
| 1732 | |
| 1733 | # ------------------------------------------------------------------------------ |
| 1734 | |
| 1735 | #Method void allocN32Pixels(int width, int height, bool isOpaque = false) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1736 | #In Allocate |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1737 | #Line # allocates compatible Color_ARGB pixels, or aborts ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1738 | Sets Image_Info to width, height, and the Native_Color_Type; and allocates |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1739 | pixel memory. If isOpaque is true, sets Image_Info to kPremul_SkAlphaType; |
| 1740 | otherwise, sets to kOpaque_SkAlphaType. |
| 1741 | |
| 1742 | Aborts if width exceeds 29 bits or is negative, or height is negative, or |
| 1743 | allocation fails. Abort steps may be provided by the user at compile time by |
| 1744 | defining SK_ABORT. |
| 1745 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1746 | Use to create Bitmap that matches SkPMColor, the native pixel arrangement on |
| 1747 | the platform. Bitmap drawn to output device skips converting its pixel format. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1748 | |
| 1749 | #Param width pixel column count; must be zero or greater ## |
| 1750 | #Param height pixel row count; must be zero or greater ## |
| 1751 | #Param isOpaque true if pixels do not have transparency ## |
| 1752 | |
| 1753 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1754 | SkRandom random; |
| 1755 | SkBitmap bitmap; |
| 1756 | bitmap.allocN32Pixels(64, 64); |
| 1757 | bitmap.eraseColor(SK_ColorTRANSPARENT); |
| 1758 | for (int y = 0; y < 256; y += 64) { |
| 1759 | for (int x = 0; x < 256; x += 64) { |
| 1760 | SkColor color = random.nextU(); |
| 1761 | uint32_t w = random.nextRangeU(4, 32); |
| 1762 | uint32_t cx = random.nextRangeU(0, 64 - w); |
| 1763 | uint32_t h = random.nextRangeU(4, 32); |
| 1764 | uint32_t cy = random.nextRangeU(0, 64 - h); |
| 1765 | bitmap.erase(color, SkIRect::MakeXYWH(cx, cy, w, h)); |
| 1766 | canvas->drawBitmap(bitmap, x, y); |
| 1767 | } |
| 1768 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1769 | ## |
| 1770 | |
| 1771 | #SeeAlso allocPixels tryAllocN32Pixels SkMallocPixelRef::MakeAllocate |
| 1772 | |
| 1773 | ## |
| 1774 | |
| 1775 | # ------------------------------------------------------------------------------ |
| 1776 | |
| 1777 | #Method bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
| 1778 | void (*releaseProc)(void* addr, void* context), void* context) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1779 | #In Allocate |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1780 | #Line # creates Pixel_Ref, with optional release function ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1781 | |
| 1782 | Sets Image_Info to info following the rules in setInfo, and creates Pixel_Ref |
| 1783 | containing pixels and rowBytes. releaseProc, if not nullptr, is called |
| 1784 | immediately on failure or when pixels are no longer referenced. context may be |
| 1785 | nullptr. |
| 1786 | |
| 1787 | If Image_Info could not be set, or rowBytes is less than info.minRowBytes: |
| 1788 | calls releaseProc if present, calls reset(), and returns false. |
| 1789 | |
| 1790 | Otherwise, if pixels equals nullptr: sets Image_Info, calls releaseProc if |
| 1791 | present, returns true. |
| 1792 | |
| 1793 | If Image_Info is set, pixels is not nullptr, and releaseProc is not nullptr: |
| 1794 | when pixels are no longer referenced, calls releaseProc with pixels and context |
| 1795 | as parameters. |
| 1796 | |
| 1797 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 1798 | #Param pixels address or pixel storage; may be nullptr ## |
| 1799 | #Param rowBytes size of pixel row or larger ## |
| 1800 | #Param releaseProc function called when pixels can be deleted; may be nullptr ## |
| 1801 | #Param context caller state passed to releaseProc; may be nullptr ## |
| 1802 | |
| 1803 | #Return true if Image_Info is set to info ## |
| 1804 | |
| 1805 | #Example |
| 1806 | #Description |
| 1807 | releaseProc is called immediately because rowBytes is too small for Pixel_Ref. |
| 1808 | ## |
| 1809 | #Function |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1810 | static void releaseProc(void* addr, void* ) { |
| 1811 | SkDebugf("releaseProc called\n"); |
| 1812 | delete[] (uint32_t*) addr; |
| 1813 | } |
| 1814 | |
| 1815 | ## |
| 1816 | |
| 1817 | void draw(SkCanvas* canvas) { |
| 1818 | SkBitmap bitmap; |
| 1819 | void* pixels = new uint32_t[8 * 8]; |
| 1820 | SkImageInfo info = SkImageInfo::MakeN32(8, 8, kOpaque_SkAlphaType); |
| 1821 | SkDebugf("before installPixels\n"); |
| 1822 | bool installed = bitmap.installPixels(info, pixels, 16, releaseProc, nullptr); |
| 1823 | SkDebugf("install " "%s" "successful\n", installed ? "" : "not "); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1824 | } |
| 1825 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1826 | before installPixels |
| 1827 | releaseProc called |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1828 | install not successful |
| 1829 | ## |
| 1830 | ## |
| 1831 | |
| 1832 | #SeeAlso allocPixels |
| 1833 | |
| 1834 | ## |
| 1835 | |
| 1836 | # ------------------------------------------------------------------------------ |
| 1837 | |
| 1838 | #Method bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) |
| 1839 | |
| 1840 | Sets Image_Info to info following the rules in setInfo, and creates Pixel_Ref |
| 1841 | containing pixels and rowBytes. |
| 1842 | |
| 1843 | If Image_Info could not be set, or rowBytes is less than info.minRowBytes: |
| 1844 | calls reset(), and returns false. |
| 1845 | |
| 1846 | Otherwise, if pixels equals nullptr: sets Image_Info, returns true. |
| 1847 | |
| 1848 | Caller must ensure that pixels are valid for the lifetime of Bitmap and Pixel_Ref. |
| 1849 | |
| 1850 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 1851 | #Param pixels address or pixel storage; may be nullptr ## |
| 1852 | #Param rowBytes size of pixel row or larger ## |
| 1853 | |
| 1854 | #Return true if Image_Info is set to info ## |
| 1855 | |
| 1856 | #Example |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1857 | #Bug 7079 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1858 | #Description |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1859 | GPU does not support kUnpremul_SkAlphaType, does not assert that it does not. |
| 1860 | ## |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1861 | void draw(SkCanvas* canvas) { |
| 1862 | SkRandom random; |
| 1863 | SkBitmap bitmap; |
| 1864 | const int width = 8; |
| 1865 | const int height = 8; |
| 1866 | uint32_t pixels[width * height]; |
| 1867 | for (unsigned x = 0; x < width * height; ++x) { |
| 1868 | pixels[x] = random.nextU(); |
| 1869 | } |
| 1870 | SkImageInfo info = SkImageInfo::MakeN32(width, height, kUnpremul_SkAlphaType); |
| 1871 | if (bitmap.installPixels(info, pixels, info.minRowBytes())) { |
| 1872 | canvas->scale(32, 32); |
| 1873 | canvas->drawBitmap(bitmap, 0, 0); |
| 1874 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1875 | } |
| 1876 | ## |
| 1877 | |
| 1878 | #SeeAlso allocPixels |
| 1879 | |
| 1880 | ## |
| 1881 | |
| 1882 | # ------------------------------------------------------------------------------ |
| 1883 | |
| 1884 | #Method bool installPixels(const SkPixmap& pixmap) |
| 1885 | |
| 1886 | Sets Image_Info to pixmap.info() following the rules in setInfo, and creates |
| 1887 | Pixel_Ref containing pixmap.addr() and pixmap.rowBytes. |
| 1888 | |
| 1889 | If Image_Info could not be set, or pixmap.rowBytes is less than |
| 1890 | SkImageInfo::minRowBytes: calls reset(), and returns false. |
| 1891 | |
| 1892 | Otherwise, if pixmap.addr() equals nullptr: sets Image_Info, returns true. |
| 1893 | |
| 1894 | Caller must ensure that pixmap is valid for the lifetime of Bitmap and Pixel_Ref. |
| 1895 | |
| 1896 | #Param pixmap Image_Info, pixel address, and rowBytes ## |
| 1897 | |
| 1898 | #Return true if Image_Info was set to pixmap.info() ## |
| 1899 | |
| 1900 | #Example |
| 1901 | #Description |
| 1902 | Draw a five by five bitmap, and draw it again with a center white pixel. |
| 1903 | ## |
| 1904 | #Height 64 |
| 1905 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 1906 | { 0xAC, 0xA8, 0x89, 0x47, 0x87 }, |
| 1907 | { 0x4B, 0x25, 0x25, 0x25, 0x46 }, |
| 1908 | { 0x90, 0x81, 0x25, 0x41, 0x33 }, |
| 1909 | { 0x75, 0x55, 0x44, 0x20, 0x00 }}; |
| 1910 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 1911 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 1912 | SkBitmap bitmap; |
| 1913 | bitmap.installPixels(pixmap); |
| 1914 | canvas->scale(10, 10); |
| 1915 | canvas->drawBitmap(bitmap, 0, 0); |
| 1916 | *pixmap.writable_addr8(2, 2) = 0xFF; |
| 1917 | bitmap.installPixels(pixmap); |
| 1918 | canvas->drawBitmap(bitmap, 10, 0); |
| 1919 | ## |
| 1920 | |
| 1921 | #SeeAlso allocPixels |
| 1922 | |
| 1923 | ## |
| 1924 | |
| 1925 | # ------------------------------------------------------------------------------ |
| 1926 | |
| 1927 | #Method bool installMaskPixels(const SkMask& mask) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1928 | #Deprecated soon |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1929 | ## |
| 1930 | |
| 1931 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1932 | #Subtopic Pixels |
| 1933 | #Populate |
| 1934 | #Line # read and write pixel values ## |
| 1935 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1936 | |
| 1937 | #Method void setPixels(void* pixels) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1938 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1939 | #Line # sets Pixel_Ref without an offset ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1940 | Replaces Pixel_Ref with pixels, preserving Image_Info and rowBytes. |
| 1941 | Sets Pixel_Ref origin to (0, 0). |
| 1942 | |
| 1943 | If pixels is nullptr, or if info().colorType equals kUnknown_SkColorType; |
| 1944 | release reference to Pixel_Ref, and set Pixel_Ref to nullptr. |
| 1945 | |
| 1946 | Caller is responsible for handling ownership pixel memory for the lifetime |
| 1947 | of Bitmap and Pixel_Ref. |
| 1948 | |
| 1949 | #Param pixels address of pixel storage, managed by caller ## |
| 1950 | |
| 1951 | #Example |
| 1952 | #Height 50 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1953 | uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }; |
| 1954 | uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 }; |
| 1955 | SkBitmap bitmap; |
| 1956 | bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5); |
| 1957 | canvas->scale(10, 50); |
| 1958 | canvas->drawBitmap(bitmap, 0, 0); |
| 1959 | bitmap.setPixels(set2); |
| 1960 | canvas->drawBitmap(bitmap, 10, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1961 | ## |
| 1962 | |
| 1963 | #SeeAlso installPixels allocPixels |
| 1964 | |
| 1965 | ## |
| 1966 | |
| 1967 | # ------------------------------------------------------------------------------ |
| 1968 | |
| 1969 | #Method bool SK_WARN_UNUSED_RESULT tryAllocPixels() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1970 | #In Allocate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1971 | Allocates pixel memory with HeapAllocator, and replaces existing Pixel_Ref. |
| 1972 | The allocation size is determined by Image_Info width, height, and Color_Type. |
| 1973 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1974 | Returns false if info().colorType is kUnknown_SkColorType, or allocation fails. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1975 | |
| 1976 | #Return true if the allocation succeeds |
| 1977 | ## |
| 1978 | |
| 1979 | #Example |
| 1980 | #Height 50 |
| 1981 | #Description |
| 1982 | Bitmap hosts and draws gray values in set1. tryAllocPixels replaces Pixel_Ref |
| 1983 | and erases it to black, but does not alter set1. setPixels replaces black |
| 1984 | Pixel_Ref with set1. |
| 1985 | ## |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 1986 | uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }; |
| 1987 | SkBitmap bitmap; |
| 1988 | bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5); |
| 1989 | canvas->scale(10, 50); |
| 1990 | canvas->drawBitmap(bitmap, 0, 0); |
| 1991 | if (bitmap.tryAllocPixels()) { |
| 1992 | bitmap.eraseColor(SK_ColorBLACK); |
| 1993 | canvas->drawBitmap(bitmap, 8, 0); |
| 1994 | bitmap.setPixels(set1); |
| 1995 | canvas->drawBitmap(bitmap, 16, 0); |
| 1996 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1997 | ## |
| 1998 | |
| 1999 | #SeeAlso allocPixels installPixels setPixels |
| 2000 | |
| 2001 | ## |
| 2002 | |
| 2003 | # ------------------------------------------------------------------------------ |
| 2004 | |
| 2005 | #Method void allocPixels() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2006 | #In Allocate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2007 | Allocates pixel memory with HeapAllocator, and replaces existing Pixel_Ref. |
| 2008 | The allocation size is determined by Image_Info width, height, and Color_Type. |
| 2009 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2010 | Aborts if info().colorType is kUnknown_SkColorType, or allocation fails. |
| 2011 | Abort steps may be provided by the user at compile |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2012 | time by defining SK_ABORT. |
| 2013 | |
| 2014 | #Example |
| 2015 | #Height 50 |
| 2016 | #Description |
| 2017 | Bitmap hosts and draws gray values in set1. allocPixels replaces Pixel_Ref |
| 2018 | and erases it to black, but does not alter set1. setPixels replaces black |
| 2019 | Pixel_Ref with set2. |
| 2020 | ## |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2021 | uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }; |
| 2022 | uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 }; |
| 2023 | SkBitmap bitmap; |
| 2024 | bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5); |
| 2025 | canvas->scale(10, 50); |
| 2026 | canvas->drawBitmap(bitmap, 0, 0); |
| 2027 | bitmap.allocPixels(); |
| 2028 | bitmap.eraseColor(SK_ColorBLACK); |
| 2029 | canvas->drawBitmap(bitmap, 8, 0); |
| 2030 | bitmap.setPixels(set2); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2031 | canvas->drawBitmap(bitmap, 16, 0); |
| 2032 | ## |
| 2033 | |
| 2034 | #SeeAlso tryAllocPixels installPixels setPixels |
| 2035 | |
| 2036 | ## |
| 2037 | |
| 2038 | # ------------------------------------------------------------------------------ |
| 2039 | |
| 2040 | #Method bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator* allocator) |
| 2041 | |
| 2042 | Allocates pixel memory with allocator, and replaces existing Pixel_Ref. |
| 2043 | The allocation size is determined by Image_Info width, height, and Color_Type. |
| 2044 | If allocator is nullptr, use HeapAllocator instead. |
| 2045 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2046 | Returns false if Allocator::allocPixelRef return false. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2047 | |
| 2048 | #Param allocator instance of SkBitmap::Allocator instantiation ## |
| 2049 | |
| 2050 | #Return true if custom allocator reports success |
| 2051 | ## |
| 2052 | |
| 2053 | #Example |
| 2054 | #Height 100 |
| 2055 | #Description |
| 2056 | HeapAllocator limits the maximum size of Bitmap to two gigabytes. Using |
| 2057 | a custom allocator, this limitation may be relaxed. This example can be |
| 2058 | modified to allocate an eight gigabyte Bitmap on a 64 bit platform with |
| 2059 | sufficient memory. |
| 2060 | ## |
| 2061 | #Function |
| 2062 | class LargePixelRef : public SkPixelRef { |
| 2063 | public: |
| 2064 | LargePixelRef(const SkImageInfo& info, char* storage, size_t rowBytes) |
| 2065 | : SkPixelRef(info.width(), info.height(), storage, rowBytes) { |
| 2066 | } |
| 2067 | |
| 2068 | ~LargePixelRef() override { |
| 2069 | delete[] (char* ) this->pixels(); |
| 2070 | } |
| 2071 | }; |
| 2072 | |
| 2073 | class LargeAllocator : public SkBitmap::Allocator { |
| 2074 | public: |
| 2075 | bool allocPixelRef(SkBitmap* bitmap) override { |
| 2076 | const SkImageInfo& info = bitmap->info(); |
| 2077 | uint64_t rowBytes = info.minRowBytes64(); |
| 2078 | uint64_t size = info.height() * rowBytes; |
| 2079 | char* addr = new char[size]; |
| 2080 | if (nullptr == addr) { |
| 2081 | return false; |
| 2082 | } |
| 2083 | sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(new LargePixelRef(info, addr, rowBytes)); |
| 2084 | if (!pr) { |
| 2085 | return false; |
| 2086 | } |
| 2087 | bitmap->setPixelRef(std::move(pr), 0, 0); |
| 2088 | return true; |
| 2089 | } |
| 2090 | }; |
| 2091 | |
| 2092 | ## |
| 2093 | |
| 2094 | void draw(SkCanvas* canvas) { |
| 2095 | LargeAllocator largeAllocator; |
| 2096 | SkBitmap bitmap; |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2097 | int width = 100; // make this 20000 |
| 2098 | int height = 100; // and this 100000 to allocate 8 gigs on a 64-bit platform |
| 2099 | bitmap.setInfo(SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType)); |
| 2100 | if (bitmap.tryAllocPixels(&largeAllocator)) { |
| 2101 | bitmap.eraseColor(0xff55aa33); |
| 2102 | canvas->drawBitmap(bitmap, 0, 0); |
| 2103 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | ## |
| 2107 | |
| 2108 | #SeeAlso allocPixels Allocator Pixel_Ref |
| 2109 | |
| 2110 | ## |
| 2111 | |
| 2112 | # ------------------------------------------------------------------------------ |
| 2113 | |
| 2114 | #Method void allocPixels(Allocator* allocator) |
| 2115 | |
| 2116 | Allocates pixel memory with allocator, and replaces existing Pixel_Ref. |
| 2117 | The allocation size is determined by Image_Info width, height, and Color_Type. |
| 2118 | If allocator is nullptr, use HeapAllocator instead. |
| 2119 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2120 | Aborts if Allocator::allocPixelRef return false. Abort steps may be provided by |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2121 | the user at compile time by defining SK_ABORT. |
| 2122 | |
| 2123 | #Param allocator instance of SkBitmap::Allocator instantiation ## |
| 2124 | |
| 2125 | #Example |
| 2126 | #Height 32 |
| 2127 | #Function |
| 2128 | class TinyAllocator : public SkBitmap::Allocator { |
| 2129 | public: |
| 2130 | bool allocPixelRef(SkBitmap* bitmap) override { |
| 2131 | const SkImageInfo& info = bitmap->info(); |
| 2132 | if (info.height() * info.minRowBytes() > sizeof(storage)) { |
| 2133 | return false; |
| 2134 | } |
| 2135 | sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>( |
| 2136 | new SkPixelRef(info.width(), info.height(), storage, info.minRowBytes())); |
| 2137 | bitmap->setPixelRef(std::move(pr), 0, 0); |
| 2138 | return true; |
| 2139 | } |
| 2140 | |
| 2141 | char storage[16]; |
| 2142 | }; |
| 2143 | |
| 2144 | ## |
| 2145 | |
| 2146 | void draw(SkCanvas* canvas) { |
| 2147 | TinyAllocator tinyAllocator; |
| 2148 | SkBitmap bitmap; |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2149 | bitmap.setInfo(SkImageInfo::MakeN32(2, 2, kOpaque_SkAlphaType)); |
| 2150 | if (bitmap.tryAllocPixels(&tinyAllocator)) { |
| 2151 | bitmap.eraseColor(0xff55aa33); |
| 2152 | bitmap.erase(0xffaa3355, SkIRect::MakeXYWH(1, 1, 1, 1)); |
| 2153 | canvas->scale(16, 16); |
| 2154 | canvas->drawBitmap(bitmap, 0, 0); |
| 2155 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2156 | } |
| 2157 | ## |
| 2158 | |
| 2159 | #SeeAlso allocPixels Allocator Pixel_Ref |
| 2160 | |
| 2161 | ## |
| 2162 | |
| 2163 | # ------------------------------------------------------------------------------ |
| 2164 | |
| 2165 | #Method SkPixelRef* pixelRef() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2166 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2167 | #Line # returns Pixel_Ref, or nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2168 | Returns Pixel_Ref, which contains: pixel base address; its dimensions; and |
| 2169 | rowBytes, the interval from one row to the next. Does not change Pixel_Ref |
| 2170 | reference count. Pixel_Ref may be shared by multiple bitmaps. |
| 2171 | If Pixel_Ref has not been set, returns nullptr. |
| 2172 | |
| 2173 | #Return Pixel_Ref, or nullptr ## |
| 2174 | |
| 2175 | #Example |
| 2176 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2177 | SkBitmap subset; |
| 2178 | source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256)); |
| 2179 | SkDebugf("src ref %c= sub ref\n", source.pixelRef() == subset.pixelRef() ? '=' : '!'); |
| 2180 | SkDebugf("src pixels %c= sub pixels\n", source.getPixels() == subset.getPixels() ? '=' : '!'); |
| 2181 | SkDebugf("src addr %c= sub addr\n", source.getAddr(32, 64) == subset.getAddr(0, 0) ? '=' : '!'); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2182 | ## |
| 2183 | |
| 2184 | #SeeAlso getPixels getAddr |
| 2185 | |
| 2186 | ## |
| 2187 | |
| 2188 | # ------------------------------------------------------------------------------ |
| 2189 | |
| 2190 | #Method SkIPoint pixelRefOrigin() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2191 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2192 | #Line # returns offset within Pixel_Ref ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2193 | Returns origin of pixels within Pixel_Ref. Bitmap bounds is always contained |
| 2194 | by Pixel_Ref bounds, which may be the same size or larger. Multiple Bitmaps |
| 2195 | can share the same Pixel_Ref, where each Bitmap has different bounds. |
| 2196 | |
| 2197 | The returned origin added to Bitmap dimensions equals or is smaller than the |
| 2198 | Pixel_Ref dimensions. |
| 2199 | |
| 2200 | Returns (0, 0) if Pixel_Ref is nullptr. |
| 2201 | |
| 2202 | #Return pixel origin within Pixel_Ref ## |
| 2203 | |
| 2204 | #Example |
| 2205 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2206 | SkBitmap subset; |
| 2207 | source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256)); |
| 2208 | SkIPoint sourceOrigin = source.pixelRefOrigin(); |
| 2209 | SkIPoint subsetOrigin = subset.pixelRefOrigin(); |
| 2210 | SkDebugf("source origin: %d, %d\n", sourceOrigin.fX, sourceOrigin.fY); |
| 2211 | SkDebugf("subset origin: %d, %d\n", subsetOrigin.fX, subsetOrigin.fY); |
| 2212 | #StdOut |
| 2213 | source origin: 0, 0 |
| 2214 | subset origin: 32, 64 |
| 2215 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2216 | ## |
| 2217 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2218 | #SeeAlso SkPixelRef getSubset setPixelRef |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2219 | |
| 2220 | ## |
| 2221 | |
| 2222 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2223 | #Subtopic Set |
| 2224 | #Line # updates values and attributes ## |
| 2225 | #Populate |
| 2226 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2227 | |
| 2228 | #Method void setPixelRef(sk_sp<SkPixelRef> pixelRef, int dx, int dy) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2229 | #In Set |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2230 | #Line # sets Pixel_Ref and offset ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2231 | Replaces pixelRef and origin in Bitmap. dx and dy specify the offset |
| 2232 | within the Pixel_Ref pixels for the top-left corner of the bitmap. |
| 2233 | |
| 2234 | Asserts in debug builds if dx or dy are out of range. Pins dx and dy |
| 2235 | to legal range in release builds. |
| 2236 | |
| 2237 | The caller is responsible for ensuring that the pixels match the |
| 2238 | Color_Type and Alpha_Type in Image_Info. |
| 2239 | |
| 2240 | #Param pixelRef Pixel_Ref describing pixel address and rowBytes ## |
| 2241 | #Param dx column offset in Pixel_Ref for bitmap origin ## |
| 2242 | #Param dy row offset in Pixel_Ref for bitmap origin ## |
| 2243 | |
| 2244 | #Example |
| 2245 | #Height 140 |
| 2246 | #Image 5 |
| 2247 | #Description |
| 2248 | Treating 32 bit data as 8 bit data is unlikely to produce useful results. |
| 2249 | ## |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2250 | SkBitmap bitmap; |
| 2251 | bitmap.setInfo(SkImageInfo::Make(source.width() - 5, source.height() - 5, |
| 2252 | kGray_8_SkColorType, kOpaque_SkAlphaType), source.rowBytes()); |
| 2253 | bitmap.setPixelRef(sk_ref_sp(source.pixelRef()), 5, 5); |
| 2254 | canvas->drawBitmap(bitmap, 10, 10); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2255 | ## |
| 2256 | |
| 2257 | #SeeAlso setInfo |
| 2258 | |
| 2259 | ## |
| 2260 | |
| 2261 | # ------------------------------------------------------------------------------ |
| 2262 | |
| 2263 | #Method bool readyToDraw() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2264 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2265 | #Line # returns true if address of pixels is not nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2266 | Returns true if Bitmap is can be drawn. |
| 2267 | |
| 2268 | #Return true if getPixels() is not nullptr ## |
| 2269 | |
| 2270 | #Example |
| 2271 | #Image 5 |
| 2272 | #Height 160 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2273 | if (source.readyToDraw()) { |
| 2274 | canvas->drawBitmap(source, 10, 10); |
| 2275 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2276 | ## |
| 2277 | |
| 2278 | #SeeAlso getPixels drawsNothing |
| 2279 | |
| 2280 | ## |
| 2281 | |
| 2282 | # ------------------------------------------------------------------------------ |
| 2283 | |
| 2284 | #Method uint32_t getGenerationID() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2285 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2286 | #Line # returns unique ID ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2287 | Returns a unique value corresponding to the pixels in Pixel_Ref. |
| 2288 | Returns a different value after notifyPixelsChanged has been called. |
| 2289 | Returns zero if Pixel_Ref is nullptr. |
| 2290 | |
| 2291 | Determines if pixels have changed since last examined. |
| 2292 | |
| 2293 | #Return unique value for pixels in Pixel_Ref ## |
| 2294 | |
| 2295 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2296 | SkBitmap bitmap; |
| 2297 | SkDebugf("empty id %u\n", bitmap.getGenerationID()); |
| 2298 | bitmap.allocPixels(SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType)); |
| 2299 | SkDebugf("alloc id %u\n", bitmap.getGenerationID()); |
| 2300 | bitmap.eraseColor(SK_ColorRED); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2301 | SkDebugf("erase id %u\n", bitmap.getGenerationID()); |
| 2302 | #StdOut |
| 2303 | #Volatile |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2304 | empty id 0 |
| 2305 | alloc id 4 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2306 | erase id 6 |
| 2307 | ## |
| 2308 | ## |
| 2309 | |
| 2310 | #SeeAlso notifyPixelsChanged Pixel_Ref |
| 2311 | |
| 2312 | ## |
| 2313 | |
| 2314 | # ------------------------------------------------------------------------------ |
| 2315 | |
| 2316 | #Method void notifyPixelsChanged() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2317 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2318 | #Line # marks pixels as changed, altering the unique ID ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2319 | Marks that pixels in Pixel_Ref have changed. Subsequent calls to |
| 2320 | getGenerationID() return a different value. |
| 2321 | |
| 2322 | #Example |
| 2323 | #Height 20 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2324 | SkBitmap bitmap; |
| 2325 | bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 2326 | bitmap.allocPixels(); |
| 2327 | bitmap.eraseColor(SK_ColorRED); |
| 2328 | canvas->scale(16, 16); |
| 2329 | canvas->drawBitmap(bitmap, 0, 0); |
| 2330 | *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE); |
| 2331 | canvas->drawBitmap(bitmap, 2, 0); |
| 2332 | bitmap.notifyPixelsChanged(); |
| 2333 | *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN); |
| 2334 | canvas->drawBitmap(bitmap, 4, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2335 | ## |
| 2336 | |
| 2337 | #SeeAlso getGenerationID isVolatile Pixel_Ref |
| 2338 | |
| 2339 | ## |
| 2340 | |
| 2341 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2342 | #Subtopic Draw |
| 2343 | #Populate |
| 2344 | #Line # set pixels to Color ## |
| 2345 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2346 | |
| 2347 | #Method void eraseColor(SkColor c) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2348 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2349 | #Line # writes Color to pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2350 | Replaces pixel values with c. All pixels contained by bounds() are affected. |
| 2351 | If the colorType is kGray_8_SkColorType or k565_SkColorType, then Color_Alpha |
| 2352 | is ignored; Color_RGB is treated as opaque. If colorType is kAlpha_8_SkColorType, |
| 2353 | then Color_RGB is ignored. |
| 2354 | |
| 2355 | #Param c Unpremultiplied Color ## |
| 2356 | |
| 2357 | #Example |
| 2358 | #Height 20 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2359 | SkBitmap bitmap; |
| 2360 | bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType)); |
| 2361 | bitmap.eraseColor(SK_ColorRED); |
| 2362 | canvas->scale(16, 16); |
| 2363 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2364 | ## |
| 2365 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2366 | #SeeAlso eraseARGB erase |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2367 | |
| 2368 | ## |
| 2369 | |
| 2370 | # ------------------------------------------------------------------------------ |
| 2371 | |
| 2372 | #Method void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2373 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2374 | #Line # writes Color to pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2375 | Replaces pixel values with Unpremultiplied Color built from a, r, g, and b. |
| 2376 | All pixels contained by bounds() are affected. |
| 2377 | If the colorType is kGray_8_SkColorType or k565_SkColorType, then a |
| 2378 | is ignored; r, g, and b are treated as opaque. If colorType is kAlpha_8_SkColorType, |
| 2379 | then r, g, and b are ignored. |
| 2380 | |
| 2381 | #Param a amount of Color_Alpha, from fully transparent (0) to fully opaque (255) ## |
| 2382 | #Param r amount of Color_RGB_Red, from no red (0) to full red (255) ## |
| 2383 | #Param g amount of Color_RGB_Green, from no green (0) to full green (255) ## |
| 2384 | #Param b amount of Color_RGB_Blue, from no blue (0) to full blue (255) ## |
| 2385 | |
| 2386 | #Example |
| 2387 | #Height 80 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2388 | SkBitmap bitmap; |
| 2389 | bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType)); |
| 2390 | bitmap.eraseARGB(0x7f, 0xff, 0x7f, 0x3f); |
| 2391 | canvas->scale(50, 50); |
| 2392 | canvas->drawBitmap(bitmap, 0, 0); |
| 2393 | canvas->drawBitmap(bitmap, .5f, .5f); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2394 | ## |
| 2395 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2396 | #SeeAlso eraseColor erase |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2397 | |
| 2398 | ## |
| 2399 | |
| 2400 | # ------------------------------------------------------------------------------ |
| 2401 | |
| 2402 | #Method void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2403 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2404 | #Line # deprecated ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2405 | Deprecated. Use eraseARGB or eraseColor. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2406 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2407 | #Param r amount of red ## |
| 2408 | #Param g amount of green ## |
| 2409 | #Param b amount of blue ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2410 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2411 | #NoExample |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2412 | ## |
| 2413 | |
| 2414 | #SeeAlso eraseColor eraseARGB erase |
| 2415 | |
| 2416 | ## |
| 2417 | |
| 2418 | # ------------------------------------------------------------------------------ |
| 2419 | |
| 2420 | #Method void erase(SkColor c, const SkIRect& area) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2421 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2422 | #Line # writes Color to rectangle of pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2423 | Replaces pixel values inside area with c. If area does not intersect bounds(), |
| 2424 | call has no effect. |
| 2425 | |
| 2426 | If the colorType is kGray_8_SkColorType or k565_SkColorType, then Color_Alpha |
| 2427 | is ignored; Color_RGB is treated as opaque. If colorType is kAlpha_8_SkColorType, |
| 2428 | then Color_RGB is ignored. |
| 2429 | |
| 2430 | #Param c Unpremultiplied Color ## |
| 2431 | #Param area rectangle to fill ## |
| 2432 | |
| 2433 | #Example |
| 2434 | #Height 70 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2435 | SkBitmap bitmap; |
| 2436 | bitmap.allocPixels(SkImageInfo::MakeN32(2, 2, kPremul_SkAlphaType)); |
| 2437 | bitmap.erase(0x7fff7f3f, SkIRect::MakeWH(1, 1)); |
| 2438 | bitmap.erase(0x7f7f3fff, SkIRect::MakeXYWH(0, 1, 1, 1)); |
| 2439 | bitmap.erase(0x7f3fff7f, SkIRect::MakeXYWH(1, 0, 1, 1)); |
| 2440 | bitmap.erase(0x7f1fbf5f, SkIRect::MakeXYWH(1, 1, 1, 1)); |
| 2441 | canvas->scale(25, 25); |
| 2442 | canvas->drawBitmap(bitmap, 0, 0); |
| 2443 | canvas->drawBitmap(bitmap, .5f, .5f); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2444 | |
| 2445 | ## |
| 2446 | |
| 2447 | #SeeAlso eraseColor eraseARGB eraseRGB SkCanvas::drawRect |
| 2448 | |
| 2449 | ## |
| 2450 | |
| 2451 | # ------------------------------------------------------------------------------ |
| 2452 | |
| 2453 | #Method void eraseArea(const SkIRect& area, SkColor c) const |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2454 | #Deprecated |
| 2455 | ## |
| 2456 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2457 | # ------------------------------------------------------------------------------ |
| 2458 | |
| 2459 | #Method SkColor getColor(int x, int y) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2460 | #In Property |
| 2461 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2462 | #Line # returns one pixel as Unpremultiplied Color ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2463 | Returns pixel at (x, y) as Unpremultiplied Color. |
| 2464 | Returns black with Alpha if Color_Type is kAlpha_8_SkColorType. |
| 2465 | |
| 2466 | Input is not validated: out of bounds values of x or y trigger an assert() if |
| 2467 | built with SK_DEBUG defined; and returns undefined values or may crash if |
| 2468 | SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or |
| 2469 | pixel address is nullptr. |
| 2470 | |
| 2471 | Color_Space in Image_Info is ignored. Some Color precision may be lost in the |
| 2472 | conversion to Unpremultiplied Color; original pixel data may have additional |
| 2473 | precision. |
| 2474 | |
| 2475 | #Param x column index, zero or greater, and less than width() ## |
| 2476 | #Param y row index, zero or greater, and less than height() ## |
| 2477 | |
| 2478 | #Return pixel converted to Unpremultiplied Color ## |
| 2479 | |
| 2480 | #Example |
| 2481 | const int w = 4; |
| 2482 | const int h = 4; |
| 2483 | SkColor colors[][w] = { |
| 2484 | 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f, |
| 2485 | 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa, |
| 2486 | 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4, |
| 2487 | 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff, |
| 2488 | }; |
| 2489 | SkDebugf("Premultiplied:\n"); |
| 2490 | for (int y = 0; y < h; ++y) { |
| 2491 | SkDebugf("(0, %d) ", y); |
| 2492 | for (int x = 0; x < w; ++x) { |
| 2493 | SkDebugf("0x%08x%c", colors[y][x], x == w - 1 ? '\n' : ' '); |
| 2494 | } |
| 2495 | } |
| 2496 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), colors, w * 4); |
| 2497 | SkBitmap bitmap; |
| 2498 | bitmap.installPixels(pixmap); |
| 2499 | SkDebugf("Unpremultiplied:\n"); |
| 2500 | for (int y = 0; y < h; ++y) { |
| 2501 | SkDebugf("(0, %d) ", y); |
| 2502 | for (int x = 0; x < w; ++x) { |
| 2503 | SkDebugf("0x%08x%c", bitmap.getColor(x, y), x == w - 1 ? '\n' : ' '); |
| 2504 | } |
| 2505 | } |
| 2506 | #StdOut |
| 2507 | Premultiplied: |
| 2508 | (0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f |
| 2509 | (0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa |
| 2510 | (0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4 |
| 2511 | (0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff |
| 2512 | Unpremultiplied: |
| 2513 | (0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff |
| 2514 | (0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff |
| 2515 | (0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff |
| 2516 | (0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff |
| 2517 | ## |
| 2518 | ## |
| 2519 | |
| 2520 | #SeeAlso getAddr readPixels |
| 2521 | |
| 2522 | ## |
| 2523 | |
| 2524 | # ------------------------------------------------------------------------------ |
| 2525 | |
| 2526 | #Method void* getAddr(int x, int y) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2527 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2528 | #Line # returns readable pixel address as void pointer ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2529 | Returns pixel address at (x, y). |
| 2530 | |
| 2531 | Input is not validated: out of bounds values of x or y, or kUnknown_SkColorType, |
| 2532 | trigger an assert() if built with SK_DEBUG defined. Returns nullptr if |
| 2533 | Color_Type is kUnknown_SkColorType, or Pixel_Ref is nullptr. |
| 2534 | |
| 2535 | Performs a lookup of pixel size; for better performance, call |
| 2536 | one of: getAddr8, getAddr16, or getAddr32. |
| 2537 | |
| 2538 | #Param x column index, zero or greater, and less than width() ## |
| 2539 | #Param y row index, zero or greater, and less than height() ## |
| 2540 | |
| 2541 | #Return generic pointer to pixel ## |
| 2542 | |
| 2543 | #Example |
| 2544 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2545 | char* row0 = (char* ) source.getAddr(0, 0); |
| 2546 | char* row1 = (char* ) source.getAddr(0, 1); |
| 2547 | SkDebugf("addr interval %c= rowBytes\n", row1 - row0 == source.rowBytes() ? '=' : '!'); |
| 2548 | #StdOut |
| 2549 | addr interval == rowBytes |
| 2550 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2551 | ## |
| 2552 | |
| 2553 | #SeeAlso getAddr8 getAddr16 getAddr32 readPixels SkPixmap::addr |
| 2554 | |
| 2555 | ## |
| 2556 | |
| 2557 | # ------------------------------------------------------------------------------ |
| 2558 | |
| 2559 | #Method inline uint32_t* getAddr32(int x, int y) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2560 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2561 | #Line # returns readable pixel address as 32-bit pointer ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2562 | Returns address at (x, y). |
| 2563 | |
| 2564 | Input is not validated. Triggers an assert() if built with SK_DEBUG defined and: |
| 2565 | #List |
| 2566 | # Pixel_Ref is nullptr ## |
| 2567 | # bytesPerPixel() is not four ## |
| 2568 | # x is negative, or not less than width() ## |
| 2569 | # y is negative, or not less than height() ## |
| 2570 | ## |
| 2571 | |
| 2572 | #Param x column index, zero or greater, and less than width() ## |
| 2573 | #Param y row index, zero or greater, and less than height() ## |
| 2574 | |
| 2575 | #Return unsigned 32-bit pointer to pixel at (x, y) ## |
| 2576 | |
| 2577 | #Example |
| 2578 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2579 | uint32_t* row0 = source.getAddr32(0, 0); |
| 2580 | uint32_t* row1 = source.getAddr32(0, 1); |
| 2581 | size_t interval = (row1 - row0) * source.bytesPerPixel(); |
| 2582 | SkDebugf("addr interval %c= rowBytes\n", interval == source.rowBytes() ? '=' : '!'); |
| 2583 | #StdOut |
| 2584 | addr interval == rowBytes |
| 2585 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2586 | ## |
| 2587 | |
| 2588 | #SeeAlso getAddr8 getAddr16 getAddr readPixels SkPixmap::addr32 |
| 2589 | |
| 2590 | ## |
| 2591 | |
| 2592 | # ------------------------------------------------------------------------------ |
| 2593 | |
| 2594 | #Method inline uint16_t* getAddr16(int x, int y) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2595 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2596 | #Line # returns readable pixel address as 16-bit pointer ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2597 | Returns address at (x, y). |
| 2598 | |
| 2599 | Input is not validated. Triggers an assert() if built with SK_DEBUG defined and: |
| 2600 | #List |
| 2601 | # Pixel_Ref is nullptr ## |
| 2602 | # bytesPerPixel() is not two ## |
| 2603 | # x is negative, or not less than width() ## |
| 2604 | # y is negative, or not less than height() ## |
| 2605 | ## |
| 2606 | |
| 2607 | #Param x column index, zero or greater, and less than width() ## |
| 2608 | #Param y row index, zero or greater, and less than height() ## |
| 2609 | |
| 2610 | #Return unsigned 16-bit pointer to pixel at (x, y)## |
| 2611 | |
| 2612 | #Example |
| 2613 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2614 | SkBitmap bitmap16; |
| 2615 | SkImageInfo dstInfo = SkImageInfo::Make(source.width(), source.height(), kARGB_4444_SkColorType, |
| 2616 | kPremul_SkAlphaType); |
| 2617 | bitmap16.allocPixels(dstInfo); |
| 2618 | if (source.readPixels(dstInfo, bitmap16.getPixels(), bitmap16.rowBytes(), 0, 0)) { |
| 2619 | uint16_t* row0 = bitmap16.getAddr16(0, 0); |
| 2620 | uint16_t* row1 = bitmap16.getAddr16(0, 1); |
| 2621 | size_t interval = (row1 - row0) * bitmap16.bytesPerPixel(); |
| 2622 | SkDebugf("addr interval %c= rowBytes\n", interval == bitmap16.rowBytes() ? '=' : '!'); |
| 2623 | } |
| 2624 | #StdOut |
| 2625 | addr interval == rowBytes |
| 2626 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2627 | ## |
| 2628 | |
| 2629 | #SeeAlso getAddr8 getAddr getAddr32 readPixels SkPixmap::addr16 |
| 2630 | |
| 2631 | ## |
| 2632 | |
| 2633 | # ------------------------------------------------------------------------------ |
| 2634 | |
| 2635 | #Method inline uint8_t* getAddr8(int x, int y) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2636 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2637 | #Line # returns readable pixel address as 8-bit pointer ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2638 | Returns address at (x, y). |
| 2639 | |
| 2640 | Input is not validated. Triggers an assert() if built with SK_DEBUG defined and: |
| 2641 | #List |
| 2642 | # Pixel_Ref is nullptr ## |
| 2643 | # bytesPerPixel() is not one ## |
| 2644 | # x is negative, or not less than width() ## |
| 2645 | # y is negative, or not less than height() ## |
| 2646 | ## |
| 2647 | |
| 2648 | #Param x column index, zero or greater, and less than width() ## |
| 2649 | #Param y row index, zero or greater, and less than height() ## |
| 2650 | |
| 2651 | #Return unsigned 8-bit pointer to pixel at (x, y) ## |
| 2652 | |
| 2653 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2654 | SkBitmap bitmap; |
| 2655 | const int width = 8; |
| 2656 | const int height = 8; |
| 2657 | uint8_t pixels[height][width]; |
| 2658 | SkImageInfo info = SkImageInfo::Make(width, height, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 2659 | if (bitmap.installPixels(info, pixels, info.minRowBytes())) { |
| 2660 | SkDebugf("&pixels[4][2] %c= bitmap.getAddr8(2, 4)\n", |
| 2661 | &pixels[4][2] == bitmap.getAddr8(2, 4) ? '=' : '!'); |
| 2662 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2663 | #StdOut |
| 2664 | &pixels[4][2] == bitmap.getAddr8(2, 4) |
| 2665 | ## |
| 2666 | ## |
| 2667 | |
| 2668 | #SeeAlso getAddr getAddr16 getAddr32 readPixels SkPixmap::addr8 |
| 2669 | |
| 2670 | ## |
| 2671 | |
| 2672 | # ------------------------------------------------------------------------------ |
| 2673 | |
| 2674 | #Method bool extractSubset(SkBitmap* dst, const SkIRect& subset) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2675 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2676 | #Line # creates Bitmap, sharing pixels if possible ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2677 | Shares Pixel_Ref with dst. Pixels are not copied; Bitmap and dst point |
| 2678 | to the same pixels; dst bounds() are set to the intersection of subset |
| 2679 | and the original bounds(). |
| 2680 | |
| 2681 | subset may be larger than bounds(). Any area outside of bounds() is ignored. |
| 2682 | |
| 2683 | Any contents of dst are discarded. isVolatile setting is copied to dst. |
| 2684 | dst is set to colorType, alphaType, and colorSpace. |
| 2685 | |
| 2686 | Return false if: |
| 2687 | #List |
| 2688 | # dst is nullptr ## |
| 2689 | # Pixel_Ref is nullptr ## |
| 2690 | # subset does not intersect bounds() ## |
| 2691 | ## |
| 2692 | |
| 2693 | |
| 2694 | #Param dst Bitmap set to subset ## |
| 2695 | #Param subset rectangle of pixels to reference ## |
| 2696 | |
| 2697 | #Return true if dst is replaced by subset |
| 2698 | ## |
| 2699 | |
| 2700 | #Example |
| 2701 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2702 | SkIRect bounds, s; |
| 2703 | source.getBounds(&bounds); |
| 2704 | SkDebugf("bounds: %d, %d, %d, %d\n", bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2705 | SkBitmap subset; |
| 2706 | for (int left: { -100, 0, 100, 1000 } ) { |
| 2707 | for (int right: { 0, 100, 1000 } ) { |
| 2708 | SkIRect b = SkIRect::MakeLTRB(left, 100, right, 200); |
| 2709 | bool success = source.extractSubset(&subset, b); |
| 2710 | SkDebugf("subset: %4d, %4d, %4d, %4d ", b.fLeft, b.fTop, b.fRight, b.fBottom); |
| 2711 | SkDebugf("success; %s", success ? "true" : "false"); |
| 2712 | if (success) { |
| 2713 | subset.getBounds(&s); |
| 2714 | SkDebugf(" subset: %d, %d, %d, %d", s.fLeft, s.fTop, s.fRight, s.fBottom); |
| 2715 | } |
| 2716 | SkDebugf("\n"); |
| 2717 | } |
| 2718 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2719 | #StdOut |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2720 | bounds: 0, 0, 512, 512 |
| 2721 | subset: -100, 100, 0, 200 success; false |
| 2722 | subset: -100, 100, 100, 200 success; true subset: 0, 0, 100, 100 |
| 2723 | subset: -100, 100, 1000, 200 success; true subset: 0, 0, 512, 100 |
| 2724 | subset: 0, 100, 0, 200 success; false |
| 2725 | subset: 0, 100, 100, 200 success; true subset: 0, 0, 100, 100 |
| 2726 | subset: 0, 100, 1000, 200 success; true subset: 0, 0, 512, 100 |
| 2727 | subset: 100, 100, 0, 200 success; false |
| 2728 | subset: 100, 100, 100, 200 success; false |
| 2729 | subset: 100, 100, 1000, 200 success; true subset: 0, 0, 412, 100 |
| 2730 | subset: 1000, 100, 0, 200 success; false |
| 2731 | subset: 1000, 100, 100, 200 success; false |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2732 | subset: 1000, 100, 1000, 200 success; false |
| 2733 | ## |
| 2734 | ## |
| 2735 | |
| 2736 | #SeeAlso readPixels writePixels SkCanvas::drawBitmap |
| 2737 | |
| 2738 | ## |
| 2739 | |
| 2740 | # ------------------------------------------------------------------------------ |
| 2741 | |
| 2742 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 2743 | int srcX, int srcY, SkTransferFunctionBehavior behavior) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2744 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2745 | #Line # copies and converts pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2746 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2747 | Copies Rect of pixels from Bitmap pixels to dstPixels. Copy starts at (srcX, srcY), |
| 2748 | and does not exceed Bitmap (width(), height()). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2749 | |
| 2750 | dstInfo specifies width, height, Color_Type, Alpha_Type, and |
| 2751 | Color_Space of destination. dstRowBytes specifics the gap from one destination |
| 2752 | row to the next. Returns true if pixels are copied. Returns false if: |
| 2753 | #List |
| 2754 | # dstInfo.addr() equals nullptr ## |
| 2755 | # dstRowBytes is less than dstInfo.minRowBytes ## |
| 2756 | # Pixel_Ref is nullptr ## |
| 2757 | ## |
| 2758 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2759 | Pixels are copied only if pixel conversion is possible. If Bitmap colorType is |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2760 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2761 | If Bitmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. |
| 2762 | If Bitmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must |
| 2763 | match. If Bitmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2764 | false if pixel conversion is not possible. |
| 2765 | |
| 2766 | srcX and srcY may be negative to copy only top or left of source. Returns |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2767 | false if width() or height() is zero or negative. |
| 2768 | Returns false if |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2769 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2770 | abs(srcX) >= Bitmap width() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2771 | ## |
| 2772 | , or if |
| 2773 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2774 | abs(srcY) >= Bitmap height() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2775 | ## |
| 2776 | . |
| 2777 | |
| 2778 | If behavior is SkTransferFunctionBehavior::kRespect: converts source |
| 2779 | pixels to a linear space before converting to dstInfo. |
| 2780 | If behavior is SkTransferFunctionBehavior::kIgnore: source |
| 2781 | pixels are treated as if they are linear, regardless of how they are encoded. |
| 2782 | |
| 2783 | #Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ## |
| 2784 | #Param dstPixels destination pixel storage ## |
| 2785 | #Param dstRowBytes destination row length ## |
| 2786 | #Param srcX column index whose absolute value is less than width() ## |
| 2787 | #Param srcY row index whose absolute value is less than height() ## |
| 2788 | #Param behavior one of: SkTransferFunctionBehavior::kRespect, |
| 2789 | SkTransferFunctionBehavior::kIgnore |
| 2790 | ## |
| 2791 | |
| 2792 | #Return true if pixels are copied to dstPixels ## |
| 2793 | |
| 2794 | #Example |
| 2795 | #Height 64 |
| 2796 | void draw(SkCanvas* canvas) { |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2797 | const int width = 256; |
| 2798 | const int height = 32; |
| 2799 | std::vector<int32_t> dstPixels; |
| 2800 | dstPixels.resize(height * width * 4); |
| 2801 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 2802 | SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; |
| 2803 | SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } }; |
| 2804 | SkPaint gradPaint; |
| 2805 | gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, |
| 2806 | SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); |
| 2807 | for (auto behavior : { SkTransferFunctionBehavior::kRespect, |
| 2808 | SkTransferFunctionBehavior::kIgnore} ) { |
| 2809 | SkBitmap bitmap; |
| 2810 | bitmap.allocPixels(info); |
| 2811 | SkCanvas srcCanvas(bitmap); |
| 2812 | srcCanvas.drawRect(SkRect::MakeWH(width, height), gradPaint); |
| 2813 | if (bitmap.readPixels(info, &dstPixels.front(), width * 4, 0, 0, behavior)) { |
| 2814 | SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); |
| 2815 | bitmap.installPixels(dstPixmap); |
| 2816 | canvas->drawBitmap(bitmap, 0, 0); |
| 2817 | } |
| 2818 | canvas->translate(0, height); |
| 2819 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2820 | } |
| 2821 | ## |
| 2822 | |
| 2823 | #SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels |
| 2824 | |
| 2825 | ## |
| 2826 | |
| 2827 | # ------------------------------------------------------------------------------ |
| 2828 | |
| 2829 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 2830 | int srcX, int srcY) const |
| 2831 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2832 | Copies a Rect of pixels from Bitmap to dstPixels. Copy starts at (srcX, srcY), |
| 2833 | and does not exceed Bitmap (width(), height()). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2834 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2835 | dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of |
| 2836 | destination. dstRowBytes specifics the gap from one destination row to the next. |
| 2837 | Returns true if pixels are copied. Returns false if: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2838 | #List |
| 2839 | # dstInfo.addr() equals nullptr ## |
| 2840 | # dstRowBytes is less than dstInfo.minRowBytes ## |
| 2841 | # Pixel_Ref is nullptr ## |
| 2842 | ## |
| 2843 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2844 | Pixels are copied only if pixel conversion is possible. If Bitmap colorType is |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2845 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2846 | If Bitmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. |
| 2847 | If Bitmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must |
| 2848 | match. If Bitmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2849 | false if pixel conversion is not possible. |
| 2850 | |
| 2851 | srcX and srcY may be negative to copy only top or left of source. Returns |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2852 | false if width() or height() is zero or negative. |
| 2853 | Returns false if |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2854 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2855 | abs(srcX) >= Bitmap width() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2856 | ## |
| 2857 | , or if |
| 2858 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2859 | abs(srcY) >= Bitmap height() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2860 | ## |
| 2861 | . |
| 2862 | |
| 2863 | #Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ## |
| 2864 | #Param dstPixels destination pixel storage ## |
| 2865 | #Param dstRowBytes destination row length ## |
| 2866 | #Param srcX column index whose absolute value is less than width() ## |
| 2867 | #Param srcY row index whose absolute value is less than height() ## |
| 2868 | |
| 2869 | #Return true if pixels are copied to dstPixels ## |
| 2870 | |
| 2871 | #Example |
| 2872 | #Height 128 |
| 2873 | #Description |
| 2874 | Transferring the gradient from 8 bits per component to 4 bits per component |
| 2875 | creates visible banding. |
| 2876 | ## |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2877 | const int width = 256; |
| 2878 | const int height = 64; |
| 2879 | SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height); |
| 2880 | SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; |
| 2881 | SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } }; |
| 2882 | SkPaint paint; |
| 2883 | paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, |
| 2884 | SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); |
| 2885 | SkBitmap bitmap; |
| 2886 | bitmap.allocPixels(srcInfo); |
| 2887 | SkCanvas srcCanvas(bitmap); |
| 2888 | srcCanvas.drawRect(SkRect::MakeWH(width, height), paint); |
| 2889 | canvas->drawBitmap(bitmap, 0, 0); |
| 2890 | SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType); |
| 2891 | std::vector<int16_t> dstPixels; |
| 2892 | dstPixels.resize(height * width); |
| 2893 | bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0); |
| 2894 | SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2); |
| 2895 | bitmap.installPixels(dstPixmap); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2896 | canvas->drawBitmap(bitmap, 0, 64); |
| 2897 | ## |
| 2898 | |
| 2899 | #SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels |
| 2900 | |
| 2901 | ## |
| 2902 | |
| 2903 | # ------------------------------------------------------------------------------ |
| 2904 | |
| 2905 | #Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const |
| 2906 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2907 | Copies a Rect of pixels from Bitmap to dst. Copy starts at (srcX, srcY), and |
| 2908 | does not exceed Bitmap (width(), height()). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2909 | |
| 2910 | dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage, |
| 2911 | and row bytes of destination. dst.rowBytes specifics the gap from one destination |
| 2912 | row to the next. Returns true if pixels are copied. Returns false if: |
| 2913 | #List |
| 2914 | # dst pixel storage equals nullptr ## |
| 2915 | # dst.rowBytes is less than SkImageInfo::minRowBytes ## |
| 2916 | # Pixel_Ref is nullptr ## |
| 2917 | ## |
| 2918 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2919 | Pixels are copied only if pixel conversion is possible. If Bitmap colorType is |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2920 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2921 | If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match. |
| 2922 | If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must |
| 2923 | match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2924 | false if pixel conversion is not possible. |
| 2925 | |
| 2926 | srcX and srcY may be negative to copy only top or left of source. Returns |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2927 | false if width() or height() is zero or negative. |
| 2928 | Returns false if |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2929 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2930 | abs(srcX) >= Bitmap width() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2931 | ## |
| 2932 | , or if |
| 2933 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2934 | abs(srcY) >= Bitmap height() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2935 | ## |
| 2936 | . |
| 2937 | |
| 2938 | #Param dst destination Pixmap: Image_Info, pixels, row bytes ## |
| 2939 | #Param srcX column index whose absolute value is less than width() ## |
| 2940 | #Param srcY row index whose absolute value is less than height() ## |
| 2941 | |
| 2942 | #Return true if pixels are copied to dst ## |
| 2943 | |
| 2944 | #Example |
| 2945 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2946 | std::vector<int32_t> srcPixels; |
| 2947 | srcPixels.resize(source.height() * source.rowBytes()); |
| 2948 | for (int y = 0; y < 4; ++y) { |
| 2949 | for (int x = 0; x < 4; ++x) { |
| 2950 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width() / 4, source.height() / 4), |
| 2951 | &srcPixels.front() + x * source.height() * source.width() / 4 + |
| 2952 | y * source.width() / 4, source.rowBytes()); |
| 2953 | source.readPixels(pixmap, x * source.width() / 4, y * source.height() / 4); |
| 2954 | } |
| 2955 | } |
| 2956 | canvas->scale(.5f, .5f); |
| 2957 | SkBitmap bitmap; |
| 2958 | bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width(), source.height()), |
| 2959 | &srcPixels.front(), source.rowBytes()); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2960 | canvas->drawBitmap(bitmap, 0, 0); |
| 2961 | ## |
| 2962 | |
| 2963 | #SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels |
| 2964 | |
| 2965 | ## |
| 2966 | |
| 2967 | # ------------------------------------------------------------------------------ |
| 2968 | |
| 2969 | #Method bool readPixels(const SkPixmap& dst) const |
| 2970 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2971 | Copies a Rect of pixels from Bitmap to dst. Copy starts at (0, 0), and |
| 2972 | does not exceed Bitmap (width(), height()). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2973 | |
| 2974 | dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage, |
| 2975 | and row bytes of destination. dst.rowBytes specifics the gap from one destination |
| 2976 | row to the next. Returns true if pixels are copied. Returns false if: |
| 2977 | #List |
| 2978 | # dst pixel storage equals nullptr ## |
| 2979 | # dst.rowBytes is less than SkImageInfo::minRowBytes ## |
| 2980 | # Pixel_Ref is nullptr ## |
| 2981 | ## |
| 2982 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2983 | Pixels are copied only if pixel conversion is possible. If Bitmap colorType is |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2984 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2985 | If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match. |
| 2986 | If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must |
| 2987 | match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2988 | false if pixel conversion is not possible. |
| 2989 | |
| 2990 | #Param dst destination Pixmap: Image_Info, pixels, row bytes ## |
| 2991 | |
| 2992 | #Return true if pixels are copied to dst ## |
| 2993 | |
| 2994 | #Example |
| 2995 | #Height 128 |
| 2996 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 2997 | std::vector<int32_t> srcPixels; |
| 2998 | srcPixels.resize(source.height() * source.width() * 8); |
| 2999 | for (int i = 0; i < 2; ++i) { |
| 3000 | SkPixmap pixmap(SkImageInfo::Make(source.width() * 2, source.height(), |
| 3001 | i ? kRGBA_8888_SkColorType : kBGRA_8888_SkColorType, kPremul_SkAlphaType), |
| 3002 | &srcPixels.front() + i * source.width(), source.rowBytes() * 2); |
| 3003 | source.readPixels(pixmap); |
| 3004 | } |
| 3005 | canvas->scale(.25f, .25f); |
| 3006 | SkBitmap bitmap; |
| 3007 | bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width() * 2, source.height()), |
| 3008 | &srcPixels.front(), source.rowBytes() * 2); |
| 3009 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3010 | ## |
| 3011 | |
| 3012 | #SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels |
| 3013 | |
| 3014 | ## |
| 3015 | |
| 3016 | # ------------------------------------------------------------------------------ |
| 3017 | |
| 3018 | #Method bool writePixels(const SkPixmap& src, int dstX, int dstY) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3019 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3020 | #Line # copies and converts pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3021 | Copies a Rect of pixels from src. Copy starts at (dstX, dstY), and does not exceed |
| 3022 | (src.width(), src.height()). |
| 3023 | |
| 3024 | src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage, |
| 3025 | and row bytes of source. src.rowBytes specifics the gap from one source |
| 3026 | row to the next. Returns true if pixels are copied. Returns false if: |
| 3027 | #List |
| 3028 | # src pixel storage equals nullptr ## |
| 3029 | # src.rowBytes is less than SkImageInfo::minRowBytes ## |
| 3030 | # Pixel_Ref is nullptr ## |
| 3031 | ## |
| 3032 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 3033 | Pixels are copied only if pixel conversion is possible. If Bitmap colorType is |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3034 | kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 3035 | If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match. |
| 3036 | If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must |
| 3037 | match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3038 | false if pixel conversion is not possible. |
| 3039 | |
| 3040 | dstX and dstY may be negative to copy only top or left of source. Returns |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3041 | false if width() or height() is zero or negative. |
| 3042 | Returns false if |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3043 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 3044 | abs(dstX) >= Bitmap width() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3045 | ## |
| 3046 | , or if |
| 3047 | #Formula |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 3048 | abs(dstY) >= Bitmap height() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3049 | ## |
| 3050 | . |
| 3051 | |
| 3052 | #Param src source Pixmap: Image_Info, pixels, row bytes ## |
| 3053 | #Param dstX column index whose absolute value is less than width() ## |
| 3054 | #Param dstY row index whose absolute value is less than height() ## |
| 3055 | |
| 3056 | #Return true if src pixels are copied to Bitmap ## |
| 3057 | |
| 3058 | #Example |
| 3059 | #Image 3 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 3060 | std::vector<int32_t> srcPixels; |
| 3061 | int width = image->width(); |
| 3062 | int height = image->height(); |
| 3063 | srcPixels.resize(height * width * 4); |
| 3064 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(width, height), (const void*) &srcPixels.front(), |
| 3065 | width * 4); |
| 3066 | image->readPixels(pixmap, 0, 0); |
| 3067 | canvas->scale(.5f, .5f); |
| 3068 | width /= 4; |
| 3069 | height /= 4; |
| 3070 | for (int y = 0; y < 4; ++y) { |
| 3071 | for (int x = 0; x < 4; ++x) { |
| 3072 | SkBitmap bitmap; |
| 3073 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height)); |
| 3074 | bitmap.writePixels(pixmap, -y * width, -x * height); |
| 3075 | canvas->drawBitmap(bitmap, x * width, y * height); |
| 3076 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3077 | } |
| 3078 | ## |
| 3079 | |
| 3080 | #SeeAlso readPixels |
| 3081 | |
| 3082 | ## |
| 3083 | |
| 3084 | # ------------------------------------------------------------------------------ |
| 3085 | |
| 3086 | #Method bool writePixels(const SkPixmap& src) |
| 3087 | |
| 3088 | Copies a Rect of pixels from src. Copy starts at (0, 0), and does not exceed |
| 3089 | (src.width(), src.height()). |
| 3090 | |
| 3091 | src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage, |
| 3092 | and row bytes of source. src.rowBytes specifics the gap from one source |
| 3093 | row to the next. Returns true if pixels are copied. Returns false if: |
| 3094 | #List |
| 3095 | # src pixel storage equals nullptr ## |
| 3096 | # src.rowBytes is less than SkImageInfo::minRowBytes ## |
| 3097 | # Pixel_Ref is nullptr ## |
| 3098 | ## |
| 3099 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 3100 | Pixels are copied only if pixel conversion is possible. If Bitmap colorType is |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3101 | kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 3102 | If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match. |
| 3103 | If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must |
| 3104 | match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3105 | false if pixel conversion is not possible. |
| 3106 | |
| 3107 | #Param src source Pixmap: Image_Info, pixels, row bytes ## |
| 3108 | |
| 3109 | #Return true if src pixels are copied to Bitmap ## |
| 3110 | |
| 3111 | #Example |
| 3112 | #Height 80 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 3113 | SkBitmap bitmap; |
| 3114 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2)); |
| 3115 | bitmap.eraseColor(SK_ColorGREEN); |
| 3116 | SkPMColor color = 0xFF5599BB; |
| 3117 | SkPixmap src(SkImageInfo::MakeN32Premul(1, 1), &color, 4); |
| 3118 | bitmap.writePixels(src); |
| 3119 | canvas->scale(40, 40); |
| 3120 | canvas->drawBitmap(bitmap, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3121 | ## |
| 3122 | |
| 3123 | #SeeAlso readPixels |
| 3124 | |
| 3125 | ## |
| 3126 | |
| 3127 | # ------------------------------------------------------------------------------ |
| 3128 | |
| 3129 | #Method bool writePixels(const SkPixmap& src, int x, int y, SkTransferFunctionBehavior behavior) |
| 3130 | |
| 3131 | Copies a Rect of pixels from src. Copy starts at (0, 0), and does not exceed |
| 3132 | (src.width(), src.height()). |
| 3133 | |
| 3134 | src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage, |
| 3135 | and row bytes of source. src.rowBytes specifics the gap from one source |
| 3136 | row to the next. Returns true if pixels are copied. Returns false if: |
| 3137 | #List |
| 3138 | # src pixel storage equals nullptr ## |
| 3139 | # src.rowBytes is less than SkImageInfo::minRowBytes ## |
| 3140 | # Pixel_Ref is nullptr ## |
| 3141 | ## |
| 3142 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 3143 | Pixels are copied only if pixel conversion is possible. If Bitmap colorType is |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3144 | kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 3145 | If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match. |
| 3146 | If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must |
| 3147 | match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3148 | false if pixel conversion is not possible. Returns false if width() or height() |
| 3149 | is zero or negative. |
| 3150 | |
| 3151 | If behavior is SkTransferFunctionBehavior::kRespect: converts src |
| 3152 | pixels to a linear space before converting to Image_Info. |
| 3153 | If behavior is SkTransferFunctionBehavior::kIgnore: src |
| 3154 | pixels are treated as if they are linear, regardless of how they are encoded. |
| 3155 | |
| 3156 | #Param src source Pixmap: Image_Info, pixels, row bytes ## |
| 3157 | #Param x column index whose absolute value is less than width() ## |
| 3158 | #Param y row index whose absolute value is less than height() ## |
| 3159 | #Param behavior one of: SkTransferFunctionBehavior::kRespect, |
| 3160 | SkTransferFunctionBehavior::kIgnore |
| 3161 | ## |
| 3162 | |
| 3163 | #Return true if src pixels are copied to Bitmap ## |
| 3164 | |
| 3165 | #Example |
| 3166 | #Height 64 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 3167 | const int width = 256; |
| 3168 | const int height = 32; |
| 3169 | std::vector<int32_t> dstPixels; |
| 3170 | dstPixels.resize(height * width * 4); |
| 3171 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 3172 | SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; |
| 3173 | SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } }; |
| 3174 | SkPaint gradPaint; |
| 3175 | gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, |
| 3176 | SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); |
| 3177 | for (auto behavior : { SkTransferFunctionBehavior::kRespect, |
| 3178 | SkTransferFunctionBehavior::kIgnore} ) { |
| 3179 | SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); |
| 3180 | SkBitmap bitmap; |
| 3181 | bitmap.installPixels(dstPixmap); |
| 3182 | SkCanvas srcCanvas(bitmap); |
| 3183 | srcCanvas.drawRect(SkRect::MakeWH(width, height), gradPaint); |
| 3184 | if (bitmap.writePixels(dstPixmap, 0, 0, behavior)) { |
| 3185 | canvas->drawBitmap(bitmap, 0, 0); |
| 3186 | } |
| 3187 | canvas->translate(0, height); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3188 | } |
| 3189 | ## |
| 3190 | |
| 3191 | #SeeAlso readPixels |
| 3192 | |
| 3193 | ## |
| 3194 | |
| 3195 | # ------------------------------------------------------------------------------ |
| 3196 | |
| 3197 | #Method bool hasHardwareMipMap() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3198 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3199 | #Line # returns Mip_Map support present; Android only ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3200 | #Private |
| 3201 | Android framework only. |
| 3202 | ## |
| 3203 | |
| 3204 | #Return true if setHasHardwareMipMap has been called with true ## |
| 3205 | |
| 3206 | #NoExample |
| 3207 | ## |
| 3208 | |
| 3209 | #SeeAlso setHasHardwareMipMap |
| 3210 | |
| 3211 | ## |
| 3212 | |
| 3213 | # ------------------------------------------------------------------------------ |
| 3214 | |
| 3215 | #Method void setHasHardwareMipMap(bool hasHardwareMipMap) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3216 | #In Set |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3217 | #Line # sets Mip_Map support present; Android only ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3218 | #Private |
| 3219 | Android framework only. |
| 3220 | ## |
| 3221 | |
| 3222 | #Param hasHardwareMipMap sets state ## |
| 3223 | |
| 3224 | #NoExample |
| 3225 | ## |
| 3226 | |
| 3227 | #SeeAlso hasHardwareMipMap |
| 3228 | |
| 3229 | ## |
| 3230 | |
| 3231 | # ------------------------------------------------------------------------------ |
| 3232 | |
| 3233 | #Method bool extractAlpha(SkBitmap* dst) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3234 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3235 | #Line # creates Bitmap containing Alpha of pixels ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3236 | Sets dst to Alpha described by pixels. Returns false if dst cannot be written to |
| 3237 | or dst pixels cannot be allocated. |
| 3238 | |
| 3239 | Uses HeapAllocator to reserve memory for dst Pixel_Ref. |
| 3240 | |
| 3241 | #Param dst holds Pixel_Ref to fill with alpha layer ## |
| 3242 | |
| 3243 | #Return true if Alpha layer was constructed in dst Pixel_Ref ## |
| 3244 | |
| 3245 | #Example |
| 3246 | #Height 100 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 3247 | SkBitmap alpha, bitmap; |
| 3248 | bitmap.allocN32Pixels(100, 100); |
| 3249 | SkCanvas offscreen(bitmap); |
| 3250 | offscreen.clear(0); |
| 3251 | SkPaint paint; |
| 3252 | paint.setAntiAlias(true); |
| 3253 | paint.setColor(SK_ColorBLUE); |
| 3254 | paint.setStyle(SkPaint::kStroke_Style); |
| 3255 | paint.setStrokeWidth(20); |
| 3256 | offscreen.drawCircle(50, 50, 39, paint); |
| 3257 | offscreen.flush(); |
| 3258 | bitmap.extractAlpha(&alpha); |
| 3259 | paint.setColor(SK_ColorRED); |
| 3260 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3261 | canvas->drawBitmap(alpha, 100, 0, &paint); |
| 3262 | ## |
| 3263 | |
| 3264 | #SeeAlso extractSubset |
| 3265 | |
| 3266 | ## |
| 3267 | |
| 3268 | # ------------------------------------------------------------------------------ |
| 3269 | |
| 3270 | #Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint, |
| 3271 | SkIPoint* offset) const |
| 3272 | |
| 3273 | Sets dst to Alpha described by pixels. Returns false if dst cannot be written to |
| 3274 | or dst pixels cannot be allocated. |
| 3275 | |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 3276 | If paint is not nullptr and contains Mask_Filter, SkMaskFilter |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3277 | generates Mask_Alpha from Bitmap. Uses HeapAllocator to reserve memory for dst |
| 3278 | Pixel_Ref. Sets offset to top-left position for dst for alignment with Bitmap; |
| 3279 | (0, 0) unless SkMaskFilter generates mask. |
| 3280 | |
| 3281 | #Param dst holds Pixel_Ref to fill with alpha layer ## |
| 3282 | #Param paint holds optional Mask_Filter; may be nullptr ## |
| 3283 | #Param offset top-left position for dst; may be nullptr ## |
| 3284 | |
| 3285 | #Return true if Alpha layer was constructed in dst Pixel_Ref ## |
| 3286 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3287 | #Bug 7103 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3288 | #Example |
| 3289 | #Height 160 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 3290 | SkBitmap alpha, bitmap; |
| 3291 | bitmap.allocN32Pixels(100, 100); |
| 3292 | SkCanvas offscreen(bitmap); |
| 3293 | offscreen.clear(0); |
| 3294 | SkPaint paint; |
| 3295 | paint.setAntiAlias(true); |
| 3296 | paint.setColor(SK_ColorBLUE); |
| 3297 | paint.setStyle(SkPaint::kStroke_Style); |
| 3298 | paint.setStrokeWidth(20); |
| 3299 | offscreen.drawCircle(50, 50, 39, paint); |
| 3300 | offscreen.flush(); |
| 3301 | const SkScalar kBlurSigma = SkBlurMaskFilter::ConvertRadiusToSigma(SkIntToScalar(25)); |
| 3302 | paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, kBlurSigma, |
| 3303 | SkBlurMaskFilter::kHighQuality_BlurFlag)); |
| 3304 | SkIPoint offset; |
| 3305 | bitmap.extractAlpha(&alpha, &paint, &offset); |
| 3306 | paint.setColor(SK_ColorRED); |
| 3307 | canvas->drawBitmap(bitmap, 0, -offset.fY, &paint); |
| 3308 | canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3309 | ## |
| 3310 | |
| 3311 | #SeeAlso extractSubset |
| 3312 | |
| 3313 | ## |
| 3314 | |
| 3315 | # ------------------------------------------------------------------------------ |
| 3316 | |
| 3317 | #Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator, |
| 3318 | SkIPoint* offset) const |
| 3319 | |
| 3320 | Sets dst to Alpha described by pixels. Returns false if dst cannot be written to |
| 3321 | or dst pixels cannot be allocated. |
| 3322 | |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 3323 | If paint is not nullptr and contains Mask_Filter, SkMaskFilter |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3324 | generates Mask_Alpha from Bitmap. allocator may reference a custom allocation |
| 3325 | class or be set to nullptr to use HeapAllocator. Sets offset to top-left |
| 3326 | position for dst for alignment with Bitmap; (0, 0) unless SkMaskFilter generates |
| 3327 | mask. |
| 3328 | |
| 3329 | #Param dst holds Pixel_Ref to fill with alpha layer ## |
| 3330 | #Param paint holds optional Mask_Filter; may be nullptr ## |
| 3331 | #Param allocator method to reserve memory for Pixel_Ref; may be nullptr ## |
| 3332 | #Param offset top-left position for dst; may be nullptr ## |
| 3333 | |
| 3334 | #Return true if Alpha layer was constructed in dst Pixel_Ref ## |
| 3335 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3336 | #Bug 7104 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3337 | #Example |
| 3338 | #Height 128 |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 3339 | SkBitmap alpha, bitmap; |
| 3340 | bitmap.allocN32Pixels(100, 100); |
| 3341 | SkCanvas offscreen(bitmap); |
| 3342 | offscreen.clear(0); |
| 3343 | SkPaint paint; |
| 3344 | paint.setAntiAlias(true); |
| 3345 | paint.setColor(SK_ColorBLUE); |
| 3346 | paint.setStyle(SkPaint::kStroke_Style); |
| 3347 | paint.setStrokeWidth(20); |
| 3348 | offscreen.drawCircle(50, 50, 39, paint); |
| 3349 | offscreen.flush(); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3350 | paint.setMaskFilter(SkBlurMaskFilter::Make(kOuter_SkBlurStyle, 3)); |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 3351 | SkIPoint offset; |
| 3352 | bitmap.extractAlpha(&alpha, &paint, nullptr, &offset); |
| 3353 | paint.setColor(SK_ColorRED); |
| 3354 | canvas->drawBitmap(bitmap, 0, -offset.fY, &paint); |
| 3355 | canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3356 | ## |
| 3357 | |
| 3358 | #SeeAlso extractSubset |
| 3359 | |
| 3360 | ## |
| 3361 | |
| 3362 | # ------------------------------------------------------------------------------ |
| 3363 | |
| 3364 | #Method bool peekPixels(SkPixmap* pixmap) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3365 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3366 | #Line # returns Pixmap if possible ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3367 | Copies Bitmap pixel address, row bytes, and Image_Info to pixmap, if address |
| 3368 | is available, and returns true. If pixel address is not available, return |
| 3369 | false and leave pixmap unchanged. |
| 3370 | |
| 3371 | pixmap contents become invalid on any future change to Bitmap. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3372 | |
| 3373 | #Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ## |
| 3374 | |
| 3375 | #Return true if Bitmap has direct access to pixels ## |
| 3376 | |
| 3377 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 3378 | SkBitmap bitmap; |
| 3379 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(6, 11)); |
| 3380 | SkCanvas offscreen(bitmap); |
| 3381 | offscreen.clear(SK_ColorWHITE); |
| 3382 | SkPaint paint; |
| 3383 | offscreen.drawString("?", 0, 10, paint); |
| 3384 | SkPixmap pixmap; |
| 3385 | if (bitmap.peekPixels(&pixmap)) { |
| 3386 | const SkPMColor* pixels = pixmap.addr32(); |
| 3387 | SkPMColor pmWhite = pixels[0]; |
| 3388 | for (int y = 0; y < bitmap.height(); ++y) { |
| 3389 | for (int x = 0; x < bitmap.width(); ++x) { |
| 3390 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 3391 | } |
| 3392 | SkDebugf("\n"); |
| 3393 | } |
| 3394 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3395 | #StdOut |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3396 | ------ |
| 3397 | -xxx-- |
| 3398 | x---x- |
| 3399 | ----x- |
| 3400 | ---x-- |
| 3401 | --x--- |
| 3402 | --x--- |
| 3403 | ------ |
| 3404 | --x--- |
| 3405 | --x--- |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 3406 | ------ |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3407 | #StdOut ## |
| 3408 | ## |
| 3409 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 3410 | #SeeAlso pixmap() installPixels readPixels writePixels |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3411 | |
| 3412 | ## |
| 3413 | |
| 3414 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3415 | #Subtopic Utility |
| 3416 | #Populate |
| 3417 | #Line # rarely called management functions ## |
| 3418 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3419 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3420 | #Method void validate() const; |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3421 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3422 | #Line # asserts if Bitmap is invalid (debug only) ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3423 | Asserts if internal values are illegal or inconsistent. Only available if |
| 3424 | SK_DEBUG is defined at compile time. |
| 3425 | |
| 3426 | #NoExample |
| 3427 | ## |
| 3428 | |
| 3429 | #SeeAlso SkImageInfo::validate() |
| 3430 | |
| 3431 | ## |
| 3432 | |
| 3433 | # ------------------------------------------------------------------------------ |
| 3434 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3435 | #Method void toString(SkString* str) const; |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3436 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3437 | #Line # converts Bitmap to machine readable form ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3438 | #DefinedBy SK_TO_STRING_NONVIRT() ## |
| 3439 | |
| 3440 | #Private |
| 3441 | macro expands to: void toString(SkString* str) const; |
| 3442 | ## |
| 3443 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 3444 | Creates string representation of Bitmap. The representation is read by |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3445 | internal debugging tools. The interface and implementation may be |
| 3446 | suppressed by defining SK_IGNORE_TO_STRING. |
| 3447 | |
| 3448 | #Param str storage for string representation ## |
| 3449 | |
| 3450 | #Example |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 3451 | SkBitmap bitmap; |
| 3452 | int width = 6; |
| 3453 | int height = 11; |
| 3454 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height)); |
| 3455 | SkString string; |
| 3456 | bitmap.toString(&string); |
| 3457 | SkString match; |
| 3458 | match.printf("(%d, %d)", width, height); |
| 3459 | int start = string.find(match.c_str()); |
| 3460 | if (start >= 0) { |
| 3461 | SkString whStr(&string.c_str()[start], match.size()); |
| 3462 | SkDebugf("bitmap dimensions %s\n", whStr.c_str()); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3463 | } |
| 3464 | #StdOut |
| 3465 | bitmap dimensions (6, 11) |
| 3466 | ## |
| 3467 | ## |
| 3468 | |
| 3469 | #SeeAlso SkPaint::toString |
| 3470 | |
| 3471 | ## |
| 3472 | |
| 3473 | #Class SkBitmap ## |
| 3474 | |
| 3475 | #Topic Bitmap ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3476 | |