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