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