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