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