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