| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1 | #Topic Pixmap | 
| Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2 | #Alias Pixmap_Reference ## | 
| Cary Clark | e4aa371 | 2017-09-15 02:56:12 -0400 | [diff] [blame] | 3 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4 | #Class SkPixmap | 
|  | 5 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 6 | Pixmap provides a utility to pair SkImageInfo with pixels and row bytes. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 7 | Pixmap is a low level class which provides convenience functions to access | 
|  | 8 | raster destinations. Canvas can not draw Pixmap, nor does Pixmap provide | 
|  | 9 | a direct drawing destination. | 
|  | 10 |  | 
|  | 11 | Use Bitmap to draw pixels referenced by Pixmap; use Surface to draw into | 
|  | 12 | pixels referenced by Pixmap. | 
|  | 13 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 14 | Pixmap does not try to manage the lifetime of the pixel memory. Use Pixel_Ref | 
|  | 15 | to manage pixel memory; Pixel_Ref is safe across threads. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 16 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 17 | #Subtopic Overview | 
|  | 18 | #Populate | 
|  | 19 | ## | 
|  | 20 |  | 
| Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 21 | #Subtopic Related_Function | 
| Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 22 | #Populate | 
| Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 23 | ## | 
|  | 24 |  | 
| Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 25 | #Subtopic Constructor | 
| Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 26 | #Populate | 
|  | 27 | ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 28 |  | 
| Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 29 | #Subtopic Member_Function | 
| Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 30 | #Populate | 
|  | 31 | ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 32 |  | 
|  | 33 | #Subtopic Initialization | 
| Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 34 | #Line # sets fields for use ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 35 |  | 
|  | 36 | # ------------------------------------------------------------------------------ | 
|  | 37 |  | 
|  | 38 | #Method SkPixmap() | 
|  | 39 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 40 | #In Initialization | 
|  | 41 | #Line # constructs with default values ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 42 | Creates an empty Pixmap without pixels, with kUnknown_SkColorType, with | 
|  | 43 | kUnknown_SkAlphaType, and with a width and height of zero. Use | 
|  | 44 | reset() to associate pixels, SkColorType, SkAlphaType, width, and height | 
|  | 45 | after Pixmap has been created. | 
|  | 46 |  | 
|  | 47 | #Return empty Pixmap ## | 
|  | 48 |  | 
|  | 49 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 50 | void draw(SkCanvas* canvas) { | 
|  | 51 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 52 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", | 
|  | 53 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 54 | SkPixmap pixmap; | 
|  | 55 | for (int i = 0; i < 2; ++i) { | 
|  | 56 | SkDebugf("width: %2d  height: %2d", pixmap.width(), pixmap.height()); | 
|  | 57 | SkDebugf("  color: k%s_SkColorType", colors[pixmap.colorType()]); | 
|  | 58 | SkDebugf("  alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]); | 
|  | 59 | pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType), | 
|  | 60 | nullptr, 0); | 
|  | 61 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 62 | } | 
|  | 63 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 64 | width:  0  height:  0  color: kUnknown_SkColorType  alpha: kUnknown_SkAlphaType | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 65 | width: 25  height: 35  color: kRGBA_8888_SkColorType  alpha: kOpaque_SkAlphaType | 
|  | 66 | ## | 
|  | 67 | ## | 
|  | 68 |  | 
|  | 69 | #SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType | 
|  | 70 |  | 
|  | 71 | ## | 
|  | 72 |  | 
|  | 73 | # ------------------------------------------------------------------------------ | 
|  | 74 |  | 
|  | 75 | #Method SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 76 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 77 | #In Initialization | 
|  | 78 | #Line # constructs from Image_Info, pixels ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 79 | Creates Pixmap from info width, height, SkAlphaType, and SkColorType. | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 80 | addr points to pixels, or nullptr. rowBytes should be info.width() times | 
|  | 81 | info.bytesPerPixel(), or larger. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 82 |  | 
|  | 83 | No parameter checking is performed; it is up to the caller to ensure that | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 84 | addr and rowBytes agree with info. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 85 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 86 | The memory lifetime of pixels is managed by the caller. When Pixmap goes | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 87 | out of scope, addr is unaffected. | 
|  | 88 |  | 
|  | 89 | Pixmap may be later modified by reset() to change its size, pixel type, or | 
|  | 90 | storage. | 
|  | 91 |  | 
|  | 92 | #Param info  width, height, SkAlphaType, SkColorType of Image_Info ## | 
|  | 93 | #Param addr  pointer to pixels allocated by caller; may be nullptr ## | 
|  | 94 | #Param rowBytes  size of one row of addr; width times pixel size, or larger ## | 
|  | 95 |  | 
|  | 96 | #Return initialized Pixmap ## | 
|  | 97 |  | 
|  | 98 | #Example | 
|  | 99 | #Image 3 | 
|  | 100 | #Description | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 101 | SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 102 | constructs a SkPixmap from the brace-delimited parameters. | 
|  | 103 | ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 104 | SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false"); | 
|  | 105 | SkPMColor pmColors = 0; | 
|  | 106 | sk_sp<SkImage> copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1), | 
|  | 107 | (uint8_t*)&pmColors, | 
|  | 108 | 1}); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 109 | SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false"); | 
|  | 110 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 111 | image alpha only = false | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 112 | copy alpha only = true | 
|  | 113 | ## | 
|  | 114 | ## | 
|  | 115 |  | 
|  | 116 | #SeeAlso SkPixmap() reset() SkAlphaType SkColorType | 
|  | 117 |  | 
|  | 118 | ## | 
|  | 119 |  | 
|  | 120 | # ------------------------------------------------------------------------------ | 
|  | 121 |  | 
|  | 122 | #Method void reset() | 
|  | 123 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 124 | #In Initialization | 
|  | 125 | #Line # reuses existing Pixmap with replacement values ## | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 126 | Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 127 | kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType. | 
|  | 128 |  | 
|  | 129 | The prior pixels are unaffected; it is up to the caller to release pixels | 
|  | 130 | memory if desired. | 
|  | 131 |  | 
|  | 132 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 133 | void draw(SkCanvas* canvas) { | 
|  | 134 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 135 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", | 
|  | 136 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 137 | SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType), | 
|  | 138 | nullptr, 0); | 
|  | 139 | for (int i = 0; i < 2; ++i) { | 
|  | 140 | SkDebugf("width: %2d  height: %2d", pixmap.width(), pixmap.height()); | 
|  | 141 | SkDebugf("  color: k%s_SkColorType", colors[pixmap.colorType()]); | 
|  | 142 | SkDebugf("  alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]); | 
|  | 143 | pixmap.reset(); | 
|  | 144 | } | 
|  | 145 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 146 | #StdOut | 
|  | 147 | width: 25  height: 35  color: kRGBA_8888_SkColorType  alpha: kOpaque_SkAlphaType | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 148 | width:  0  height:  0  color: kUnknown_SkColorType  alpha: kUnknown_SkAlphaType | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 149 | ## | 
|  | 150 | ## | 
|  | 151 |  | 
|  | 152 | #SeeAlso SkPixmap() SkAlphaType SkColorType | 
|  | 153 |  | 
|  | 154 | ## | 
|  | 155 |  | 
|  | 156 | # ------------------------------------------------------------------------------ | 
|  | 157 |  | 
|  | 158 | #Method void reset(const SkImageInfo& info, const void* addr, size_t rowBytes) | 
|  | 159 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 160 | #In Initialization | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 161 | Sets width, height, SkAlphaType, and SkColorType from info. | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 162 | Sets pixel address from addr, which may be nullptr. | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 163 | Sets row bytes from rowBytes, which should be info.width() times | 
|  | 164 | info.bytesPerPixel(), or larger. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 165 |  | 
|  | 166 | Does not check addr. Asserts if built with SK_DEBUG defined and if rowBytes is | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 167 | too small to hold one row of pixels. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 168 |  | 
|  | 169 | The memory lifetime pixels are managed by the caller. When Pixmap goes | 
|  | 170 | out of scope, addr is unaffected. | 
|  | 171 |  | 
|  | 172 | #Param info  width, height, SkAlphaType, SkColorType of Image_Info ## | 
|  | 173 | #Param addr  pointer to pixels allocated by caller; may be nullptr ## | 
|  | 174 | #Param rowBytes  size of one row of addr; width times pixel size, or larger ## | 
|  | 175 |  | 
|  | 176 | #Example | 
|  | 177 | #Image 4 | 
| Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 178 | #Height 64 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 179 | void draw(SkCanvas* canvas) { | 
|  | 180 | std::vector<int32_t> pixels; | 
|  | 181 | pixels.resize(image->height() * image->width() * 4); | 
|  | 182 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, | 
|  | 183 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); | 
|  | 184 | image->readPixels(pixmap, 0, 0); | 
|  | 185 | int x = 0; | 
|  | 186 | for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) { | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 187 | pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType, | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 188 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); | 
|  | 189 | SkBitmap bitmap; | 
|  | 190 | bitmap.installPixels(pixmap); | 
|  | 191 | canvas->drawBitmap(bitmap, x, 0); | 
|  | 192 | x += 128; | 
|  | 193 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 194 | } | 
|  | 195 | ## | 
|  | 196 |  | 
|  | 197 | #SeeAlso SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes) reset() SkAlphaType SkColorType | 
|  | 198 |  | 
|  | 199 | ## | 
|  | 200 |  | 
|  | 201 | # ------------------------------------------------------------------------------ | 
|  | 202 |  | 
|  | 203 | #Method void setColorSpace(sk_sp<SkColorSpace> colorSpace) | 
|  | 204 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 205 | #In Initialization | 
|  | 206 | #Line # sets Image_Info Color_Space ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 207 |  | 
|  | 208 | Changes Color_Space in Image_Info; preserves width, height, SkAlphaType, and | 
|  | 209 | SkColorType in Image, and leaves pixel address and row bytes unchanged. | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 210 | Color_Space reference count is incremented. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 211 |  | 
|  | 212 | #Param colorSpace  Color_Space moved to Image_Info ## | 
|  | 213 |  | 
|  | 214 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 215 | void draw(SkCanvas* canvas) { | 
|  | 216 | SkPixmap pixmap; | 
|  | 217 | sk_sp<SkColorSpace> colorSpace1 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, | 
|  | 218 | SkColorSpace::kRec2020_Gamut); | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 219 | SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not "); | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 220 | pixmap.setColorSpace(colorSpace1); | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 221 | SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not "); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 222 | } | 
|  | 223 | #StdOut | 
|  | 224 | is unique | 
|  | 225 | is not unique | 
|  | 226 | ## | 
|  | 227 | ## | 
|  | 228 |  | 
|  | 229 | #SeeAlso Color_Space SkImageInfo::makeColorSpace | 
|  | 230 |  | 
|  | 231 | ## | 
|  | 232 |  | 
|  | 233 | # ------------------------------------------------------------------------------ | 
|  | 234 |  | 
|  | 235 | #Method bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask) | 
| Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 236 | #Deprecated soon | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 237 | ## | 
|  | 238 |  | 
|  | 239 | # ------------------------------------------------------------------------------ | 
|  | 240 |  | 
|  | 241 | #Method bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const | 
|  | 242 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 243 | #In Initialization | 
|  | 244 | #Line # sets pointer to portion of original ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 245 | Sets subset width, height, pixel address to intersection of Pixmap with area, | 
|  | 246 | if intersection is not empty; and return true. Otherwise, leave subset unchanged | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 247 | and return false. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 248 |  | 
|  | 249 | Failing to read the return value generates a compile time warning. | 
|  | 250 |  | 
|  | 251 | #Param subset  storage for width, height, pixel address of intersection ## | 
|  | 252 | #Param area    bounds to intersect with Pixmap ## | 
|  | 253 |  | 
|  | 254 | #Return true if intersection of Pixmap and area is not empty ## | 
|  | 255 |  | 
|  | 256 | #Example | 
|  | 257 | #Image 3 | 
|  | 258 | #Height 128 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 259 | void draw(SkCanvas* canvas) { | 
|  | 260 | std::vector<int32_t> pixels; | 
|  | 261 | pixels.resize(image->height() * image->width() * 4); | 
|  | 262 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, | 
|  | 263 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); | 
|  | 264 | image->readPixels(pixmap, 0, 0); | 
|  | 265 | SkPixmap inset; | 
|  | 266 | if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) { | 
|  | 267 | SkBitmap bitmap; | 
|  | 268 | bitmap.installPixels(inset); | 
|  | 269 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 270 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 271 | } | 
|  | 272 | ## | 
|  | 273 |  | 
|  | 274 | #SeeAlso reset() SkIRect::intersect | 
|  | 275 |  | 
|  | 276 | ## | 
|  | 277 |  | 
|  | 278 | #Subtopic Initialization ## | 
|  | 279 |  | 
|  | 280 | #Subtopic Image_Info_Access | 
| Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 281 | #Line # returns all or part of Image_Info ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 282 |  | 
|  | 283 | # ------------------------------------------------------------------------------ | 
|  | 284 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 285 | #Method const SkImageInfo& info() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 286 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 287 | #In Image_Info_Access | 
|  | 288 | #Line # returns Image_Info ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 289 | Returns width, height, Alpha_Type, Color_Type, and Color_Space. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 290 |  | 
|  | 291 | #Return reference to ImageInfo  ## | 
|  | 292 |  | 
|  | 293 | #Example | 
|  | 294 | #Image 3 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 295 | std::vector<int32_t> pixels; | 
|  | 296 | pixels.resize(image->height() * image->width() * 4); | 
|  | 297 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, | 
|  | 298 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); | 
|  | 299 | image->readPixels(pixmap, 0, 0); | 
|  | 300 | SkPixmap inset; | 
|  | 301 | if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) { | 
|  | 302 | const SkImageInfo& info = inset.info(); | 
|  | 303 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 304 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", | 
|  | 305 | "RGB_888x", "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 306 | SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(), | 
|  | 307 | colors[info.colorType()], alphas[info.alphaType()]); | 
|  | 308 | } | 
|  | 309 | #StdOut | 
|  | 310 | width: 384 height: 384 color: BGRA_8888 alpha: Opaque | 
|  | 311 | ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 312 | ## | 
|  | 313 |  | 
|  | 314 | #SeeAlso Image_Info | 
|  | 315 |  | 
|  | 316 | ## | 
|  | 317 |  | 
|  | 318 | # ------------------------------------------------------------------------------ | 
|  | 319 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 320 | #Method size_t rowBytes() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 321 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 322 | #In Image_Info_Access | 
|  | 323 | #Line # returns interval between rows in bytes ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 324 | Returns row bytes, the interval from one pixel row to the next. Row bytes | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 325 | is at least as large as: | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 326 | #Formula | 
|  | 327 | width() * info().bytesPerPixel() | 
|  | 328 | ## | 
|  | 329 | . | 
|  | 330 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 331 | Returns zero if colorType is kUnknown_SkColorType. | 
|  | 332 | It is up to the Bitmap creator to ensure that row bytes is a useful value. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 333 |  | 
|  | 334 | #Return  byte length of pixel row ## | 
|  | 335 |  | 
|  | 336 | #Example | 
|  | 337 | SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2}; | 
|  | 338 | SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8}; | 
|  | 339 | for (auto& pixmap : { badPixmap, okPixmap } ) { | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 340 | SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(), | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 341 | pixmap.info().minRowBytes()); | 
|  | 342 | } | 
|  | 343 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 344 | rowBytes: 2 minRowBytes: 4 | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 345 | rowBytes: 8 minRowBytes: 4 | 
|  | 346 | ## | 
|  | 347 | ## | 
|  | 348 |  | 
|  | 349 | #SeeAlso addr() info() SkImageInfo::minRowBytes | 
|  | 350 |  | 
|  | 351 | ## | 
|  | 352 |  | 
|  | 353 | # ------------------------------------------------------------------------------ | 
|  | 354 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 355 | #Method const void* addr() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 356 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 357 | #In Image_Info_Access | 
|  | 358 | #Line # returns readable pixel address as void pointer ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 359 | Returns pixel address, the base address corresponding to the pixel origin. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 360 |  | 
|  | 361 | It is up to the Pixmap creator to ensure that pixel address is a useful value. | 
|  | 362 |  | 
|  | 363 | #Return  pixel address ## | 
|  | 364 |  | 
|  | 365 | #Example | 
|  | 366 | #Image 3 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 367 | std::vector<int32_t> pixels; | 
|  | 368 | pixels.resize(image->height() * image->width() * 4); | 
|  | 369 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, | 
|  | 370 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); | 
|  | 371 | image->readPixels(pixmap, 0, 0); | 
|  | 372 | SkDebugf("pixels address: 0x%llx\n", pixmap.addr()); | 
|  | 373 | SkPixmap inset; | 
|  | 374 | if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) { | 
|  | 375 | SkDebugf("inset address:  0x%llx\n", inset.addr()); | 
|  | 376 | } | 
|  | 377 | #StdOut | 
|  | 378 | #Volatile | 
|  | 379 | pixels address: 0x7f2a440bb010 | 
|  | 380 | inset address:  0x7f2a440fb210 | 
|  | 381 | ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 382 | ## | 
|  | 383 |  | 
|  | 384 | #SeeAlso addr(int x, int y) addr8 addr16 addr32 addr64 info() rowBytes() | 
|  | 385 |  | 
|  | 386 | ## | 
|  | 387 |  | 
|  | 388 | # ------------------------------------------------------------------------------ | 
|  | 389 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 390 | #Method int width() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 391 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 392 | #In Image_Info_Access | 
|  | 393 | #Line # returns pixel column count ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 394 | Returns pixel count in each pixel row. Should be equal or less than: | 
| Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 395 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 396 | #Formula | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 397 | rowBytes() / info().bytesPerPixel() | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 398 | ## | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 399 | . | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 400 |  | 
|  | 401 | #Return  pixel width in Image_Info ## | 
|  | 402 |  | 
|  | 403 | #Example | 
|  | 404 | SkImageInfo info = SkImageInfo::MakeA8(16, 32); | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 405 | SkPixmap pixmap(info, nullptr, 64); | 
|  | 406 | SkDebugf("pixmap width: %d  info width: %d\n", pixmap.width(), info.width()); | 
|  | 407 | #StdOut | 
|  | 408 | pixmap width: 16  info width: 16 | 
|  | 409 | ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 410 | ## | 
|  | 411 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 412 | #SeeAlso height() SkImageInfo::width() | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 413 |  | 
|  | 414 | ## | 
|  | 415 |  | 
|  | 416 | # ------------------------------------------------------------------------------ | 
|  | 417 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 418 | #Method int height() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 419 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 420 | #In Image_Info_Access | 
|  | 421 | #Line # returns pixel row count ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 422 | Returns pixel row count. | 
|  | 423 |  | 
|  | 424 | #Return  pixel height in Image_Info ## | 
|  | 425 |  | 
|  | 426 | #Example | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 427 | SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); | 
|  | 428 | SkDebugf("pixmap height: %d  info height: %d\n", pixmap.height(), pixmap.info().height()); | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 429 | #StdOut | 
|  | 430 | pixmap height: 32  info height: 32 | 
|  | 431 | ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 432 | ## | 
|  | 433 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 434 | #SeeAlso width() ImageInfo::height() | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 435 |  | 
|  | 436 | ## | 
|  | 437 |  | 
|  | 438 | # ------------------------------------------------------------------------------ | 
|  | 439 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 440 | #Method SkColorType colorType() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 441 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 442 | #In Image_Info_Access | 
|  | 443 | #Line # returns Image_Info Color_Type ## | 
| Cary Clark | 1a8d762 | 2018-03-05 13:26:16 -0500 | [diff] [blame] | 444 | Returns Color_Type, one of: #list_of_color_types#. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 445 |  | 
|  | 446 | #Return  Color_Type in Image_Info ## | 
|  | 447 |  | 
|  | 448 | #Example | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 449 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", | 
|  | 450 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 451 | SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); | 
|  | 452 | SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]); | 
|  | 453 | #StdOut | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 454 | color type: kAlpha_8_SkColorType | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 455 | ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 456 | ## | 
|  | 457 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 458 | #SeeAlso alphaType() SkImageInfo::colorType | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 459 |  | 
|  | 460 | ## | 
|  | 461 |  | 
|  | 462 | # ------------------------------------------------------------------------------ | 
|  | 463 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 464 | #Method SkAlphaType alphaType() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 465 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 466 | #In Image_Info_Access | 
|  | 467 | #Line # returns Image_Info Alpha_Type ## | 
| Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 468 | Returns Alpha_Type, one of: #list_of_alpha_types#. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 469 |  | 
|  | 470 | #Return  Alpha_Type in Image_Info ## | 
|  | 471 |  | 
|  | 472 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 473 | const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; | 
|  | 474 | SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); | 
|  | 475 | SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 476 | #StdOut | 
|  | 477 | alpha type: kPremul_SkAlphaType | 
|  | 478 | ## | 
|  | 479 | ## | 
|  | 480 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 481 | #SeeAlso colorType() SkImageInfo::alphaType | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 482 |  | 
|  | 483 | ## | 
|  | 484 |  | 
|  | 485 | # ------------------------------------------------------------------------------ | 
|  | 486 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 487 | #Method SkColorSpace* colorSpace() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 488 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 489 | #In Image_Info_Access | 
|  | 490 | #Line # returns Image_Info Color_Space ## | 
| Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 491 | Returns Color_Space, the range of colors, associated with Image_Info. The | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 492 | reference count of Color_Space is unchanged. The returned Color_Space is | 
|  | 493 | immutable. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 494 |  | 
| Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 495 | #Return Color_Space in Image_Info, or nullptr ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 496 |  | 
|  | 497 | #Example | 
|  | 498 | #Description | 
|  | 499 | SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma | 
|  | 500 | and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma. | 
|  | 501 | ## | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 502 | SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 503 | SkColorSpace::MakeSRGBLinear()), nullptr, 64); | 
|  | 504 | SkColorSpace* colorSpace = pixmap.colorSpace(); | 
|  | 505 | SkDebugf("gammaCloseToSRGB: %s  gammaIsLinear: %s  isSRGB: %s\n", | 
|  | 506 | colorSpace->gammaCloseToSRGB() ? "true" : "false", | 
|  | 507 | colorSpace->gammaIsLinear() ? "true" : "false", | 
|  | 508 | colorSpace->isSRGB() ? "true" : "false"); | 
|  | 509 | #StdOut | 
|  | 510 | gammaCloseToSRGB: false  gammaIsLinear: true  isSRGB: false | 
|  | 511 | ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 512 | ## | 
|  | 513 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 514 | #SeeAlso Color_Space SkImageInfo::colorSpace | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 515 |  | 
|  | 516 | ## | 
|  | 517 |  | 
|  | 518 | # ------------------------------------------------------------------------------ | 
|  | 519 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 520 | #Method bool isOpaque() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 521 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 522 | #In Image_Info_Access | 
|  | 523 | #Line # returns true if Image_Info describes opaque pixels ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 524 | Returns true if Alpha_Type is kOpaque_SkAlphaType. | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 525 | Does not check if Color_Type allows Alpha, or if any pixel value has | 
|  | 526 | transparency. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 527 |  | 
|  | 528 | #Return true if Image_Info has opaque Alpha_Type ## | 
|  | 529 |  | 
|  | 530 | #Example | 
|  | 531 | #Description | 
|  | 532 | isOpaque ignores whether all pixels are opaque or not. | 
|  | 533 | ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 534 | std::vector<uint32_t> pixels; | 
|  | 535 | const int height = 2; | 
|  | 536 | const int width = 2; | 
|  | 537 | pixels.resize(height * width * 4); | 
|  | 538 | SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType, | 
|  | 539 | kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4); | 
|  | 540 | for (int index = 0; index < 2; ++index) { | 
|  | 541 | pixmap.erase(0x00000000); | 
|  | 542 | SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false"); | 
|  | 543 | pixmap.erase(0xFFFFFFFF); | 
|  | 544 | SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false"); | 
|  | 545 | pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType), | 
|  | 546 | (const void*) &pixels.front(), width * 4); | 
|  | 547 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 548 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 549 | isOpaque: false | 
|  | 550 | isOpaque: false | 
|  | 551 | isOpaque: true | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 552 | isOpaque: true | 
|  | 553 | ## | 
|  | 554 | ## | 
|  | 555 |  | 
|  | 556 | #SeeAlso computeIsOpaque SkImageInfo::isOpaque | 
|  | 557 |  | 
|  | 558 | ## | 
|  | 559 |  | 
|  | 560 | # ------------------------------------------------------------------------------ | 
|  | 561 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 562 | #Method SkIRect bounds() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 563 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 564 | #In Image_Info_Access | 
|  | 565 | #Line # returns width and height as Rectangle ## | 
| Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 566 | Returns IRect { 0, 0, width(), height() }. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 567 |  | 
|  | 568 | #Return  integral rectangle from origin to width() and height() ## | 
|  | 569 |  | 
|  | 570 | #Example | 
|  | 571 | for (int width : { 0, 2 } ) { | 
|  | 572 | for (int height : { 0, 2 } ) { | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 573 | SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 574 | SkDebugf("width: %d height: %d empty: %s\n", width, height, | 
|  | 575 | pixmap.bounds().isEmpty() ? "true" : "false"); | 
|  | 576 | } | 
|  | 577 | } | 
|  | 578 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 579 | width: 0 height: 0 empty: true | 
|  | 580 | width: 0 height: 2 empty: true | 
|  | 581 | width: 2 height: 0 empty: true | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 582 | width: 2 height: 2 empty: false | 
|  | 583 | ## | 
|  | 584 | ## | 
|  | 585 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 586 | #SeeAlso height() width() IRect | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 587 |  | 
|  | 588 | ## | 
|  | 589 |  | 
|  | 590 | # ------------------------------------------------------------------------------ | 
|  | 591 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 592 | #Method int rowBytesAsPixels() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 593 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 594 | #In Image_Info_Access | 
|  | 595 | #Line # returns interval between rows in pixels ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 596 |  | 
|  | 597 | Returns number of pixels that fit on row. Should be greater than or equal to | 
|  | 598 | width(). | 
|  | 599 |  | 
|  | 600 | #Return  maximum pixels per row ## | 
|  | 601 |  | 
|  | 602 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 603 | for (int rowBytes : { 4, 5, 6, 7, 8} ) { | 
|  | 604 | SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes); | 
|  | 605 | SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels()); | 
|  | 606 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 607 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 608 | rowBytes: 4 rowBytesAsPixels: 1 | 
|  | 609 | rowBytes: 5 rowBytesAsPixels: 1 | 
|  | 610 | rowBytes: 6 rowBytesAsPixels: 1 | 
|  | 611 | rowBytes: 7 rowBytesAsPixels: 1 | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 612 | rowBytes: 8 rowBytesAsPixels: 2 | 
|  | 613 | ## | 
|  | 614 | ## | 
|  | 615 |  | 
|  | 616 | #SeeAlso rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel | 
|  | 617 |  | 
|  | 618 | ## | 
|  | 619 |  | 
|  | 620 | # ------------------------------------------------------------------------------ | 
|  | 621 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 622 | #Method int shiftPerPixel() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 623 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 624 | #In Image_Info_Access | 
|  | 625 | #Line # returns bit shift from pixels to bytes ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 626 | Returns bit shift converting row bytes to row pixels. | 
|  | 627 | Returns zero for kUnknown_SkColorType. | 
|  | 628 |  | 
|  | 629 | #Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ## | 
|  | 630 |  | 
|  | 631 | #Example | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 632 | const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", | 
|  | 633 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"}; | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 634 | SkImageInfo info = SkImageInfo::MakeA8(1, 1); | 
|  | 635 | for (SkColorType colorType : { kUnknown_SkColorType,   kAlpha_8_SkColorType, | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 636 | kRGB_565_SkColorType,   kARGB_4444_SkColorType, | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 637 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, | 
|  | 638 | kGray_8_SkColorType,    kRGBA_F16_SkColorType } ) { | 
|  | 639 | SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4); | 
|  | 640 | SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n", | 
|  | 641 | colors[colorType], 10 - strlen(colors[colorType]), " ", | 
|  | 642 | pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel()); | 
|  | 643 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 644 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 645 | color: kUnknown_SkColorType   bytesPerPixel: 0 shiftPerPixel: 0 | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 646 | color: kAlpha_8_SkColorType   bytesPerPixel: 1 shiftPerPixel: 0 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 647 | color: kRGB_565_SkColorType   bytesPerPixel: 2 shiftPerPixel: 1 | 
|  | 648 | color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1 | 
|  | 649 | color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2 | 
|  | 650 | color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2 | 
|  | 651 | color: kGray_8_SkColorType    bytesPerPixel: 1 shiftPerPixel: 0 | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 652 | color: kRGBA_F16_SkColorType  bytesPerPixel: 8 shiftPerPixel: 3 | 
|  | 653 | ## | 
|  | 654 | ## | 
|  | 655 |  | 
|  | 656 | #SeeAlso rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel | 
|  | 657 |  | 
|  | 658 | ## | 
|  | 659 |  | 
|  | 660 | # ------------------------------------------------------------------------------ | 
|  | 661 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 662 | #Method size_t computeByteSize() const | 
|  | 663 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 664 | #In Image_Info_Access | 
|  | 665 | #Line # returns size required for pixels ## | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 666 | Returns minimum memory required for pixel storage. | 
|  | 667 | Does not include unused memory on last row when rowBytesAsPixels exceeds width(). | 
|  | 668 | Returns zero if result does not fit in size_t. | 
|  | 669 | Returns zero if height() or width() is 0. | 
|  | 670 | Returns height() times rowBytes if colorType is kUnknown_SkColorType. | 
|  | 671 |  | 
|  | 672 | #Return size in bytes of image buffer ## | 
|  | 673 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 674 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 675 | SkPixmap pixmap; | 
|  | 676 | for (int width : { 1, 1000, 1000000 } ) { | 
|  | 677 | for (int height: { 1, 1000, 1000000 } ) { | 
|  | 678 | SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType); | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 679 | pixmap.reset(imageInfo, nullptr, width * 5); | 
|  | 680 | SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height, | 
|  | 681 | pixmap.computeByteSize()); | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 682 | } | 
|  | 683 | } | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 684 | #StdOut | 
| Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 685 | width:       1 height:       1 computeByteSize:             4 | 
|  | 686 | width:       1 height:    1000 computeByteSize:          4999 | 
|  | 687 | width:       1 height: 1000000 computeByteSize:       4999999 | 
|  | 688 | width:    1000 height:       1 computeByteSize:          4000 | 
|  | 689 | width:    1000 height:    1000 computeByteSize:       4999000 | 
|  | 690 | width:    1000 height: 1000000 computeByteSize:    4999999000 | 
|  | 691 | width: 1000000 height:       1 computeByteSize:       4000000 | 
|  | 692 | width: 1000000 height:    1000 computeByteSize:    4999000000 | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 693 | width: 1000000 height: 1000000 computeByteSize: 4999999000000 | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 694 | ## | 
|  | 695 | ## | 
|  | 696 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 697 | #SeeAlso SkImageInfo::computeByteSize | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 698 |  | 
|  | 699 | ## | 
|  | 700 |  | 
|  | 701 | #Subtopic Image_Info_Access ## | 
|  | 702 |  | 
|  | 703 | #Subtopic Reader | 
| Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 704 | #Line # examine pixel value ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 705 |  | 
|  | 706 | # ------------------------------------------------------------------------------ | 
|  | 707 |  | 
|  | 708 | #Method bool computeIsOpaque() const | 
|  | 709 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 710 | #In Reader | 
|  | 711 | #Line # returns true if all pixels are opaque ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 712 | Returns true if all pixels are opaque. Color_Type determines how pixels | 
|  | 713 | are encoded, and whether pixel describes Alpha. Returns true for Color_Types | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 714 | without alpha in each pixel; for other Color_Types, returns true if all | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 715 | pixels have alpha values equivalent to 1.0 or greater. | 
|  | 716 |  | 
|  | 717 | For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always | 
|  | 718 | returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType, | 
|  | 719 | kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255. | 
|  | 720 | For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15. | 
|  | 721 | For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or | 
|  | 722 | greater. | 
|  | 723 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 724 | Returns false for kUnknown_SkColorType. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 725 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 726 | #Return true if all pixels have opaque values or Color_Type is opaque  ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 727 |  | 
|  | 728 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 729 | std::vector<uint32_t> pixels; | 
|  | 730 | const int height = 2; | 
|  | 731 | const int width = 2; | 
|  | 732 | pixels.resize(height * width * 4); | 
|  | 733 | SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType, | 
|  | 734 | kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4); | 
|  | 735 | for (int index = 0; index < 2; ++index) { | 
|  | 736 | pixmap.erase(0x00000000); | 
|  | 737 | SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false"); | 
|  | 738 | pixmap.erase(0xFFFFFFFF); | 
|  | 739 | SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false"); | 
|  | 740 | pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType), | 
|  | 741 | (const void*) &pixels.front(), width * 4); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 742 | } | 
|  | 743 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 744 | computeIsOpaque: false | 
|  | 745 | computeIsOpaque: true | 
|  | 746 | computeIsOpaque: false | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 747 | computeIsOpaque: true | 
|  | 748 | ## | 
|  | 749 | ## | 
|  | 750 |  | 
|  | 751 | #SeeAlso isOpaque Color_Type Alpha | 
|  | 752 |  | 
|  | 753 | ## | 
|  | 754 |  | 
|  | 755 | # ------------------------------------------------------------------------------ | 
|  | 756 |  | 
|  | 757 | #Method SkColor getColor(int x, int y) const | 
|  | 758 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 759 | #In Reader | 
|  | 760 | #Line # returns one pixel as Unpremultiplied Color ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 761 | Returns pixel at (x, y) as Unpremultiplied Color. | 
|  | 762 | Returns black with Alpha if Color_Type is kAlpha_8_SkColorType. | 
|  | 763 |  | 
|  | 764 | Input is not validated: out of bounds values of x or y trigger an assert() if | 
|  | 765 | built with SK_DEBUG defined; and returns undefined values or may crash if | 
|  | 766 | SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or | 
|  | 767 | pixel address is nullptr. | 
|  | 768 |  | 
|  | 769 | 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] | 770 | conversion to Unpremultiplied Color; original pixel data may have additional | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 771 | precision. | 
|  | 772 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 773 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 774 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 775 |  | 
|  | 776 | #Return  pixel converted to Unpremultiplied Color ## | 
|  | 777 |  | 
|  | 778 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 779 | const int w = 4; | 
|  | 780 | const int h = 4; | 
|  | 781 | std::vector<SkPMColor> storage; | 
|  | 782 | storage.resize(w * h); | 
|  | 783 | SkDebugf("Premultiplied:\n"); | 
|  | 784 | for (int y = 0; y < h; ++y) { | 
|  | 785 | SkDebugf("(0, %d) ", y); | 
|  | 786 | for (int x = 0; x < w; ++x) { | 
|  | 787 | int a = 0xFF * (x + y) / (w - 1 + h - 1); | 
|  | 788 | storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a); | 
|  | 789 | SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' '); | 
|  | 790 | } | 
|  | 791 | } | 
|  | 792 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4); | 
|  | 793 | SkDebugf("Unpremultiplied:\n"); | 
|  | 794 | for (int y = 0; y < h; ++y) { | 
|  | 795 | SkDebugf("(0, %d) ", y); | 
|  | 796 | for (int x = 0; x < w; ++x) { | 
|  | 797 | SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' '); | 
|  | 798 | } | 
|  | 799 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 800 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 801 | Premultiplied: | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 802 | (0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f | 
|  | 803 | (0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa | 
|  | 804 | (0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4 | 
|  | 805 | (0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 806 | Unpremultiplied: | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 807 | (0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff | 
|  | 808 | (0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff | 
|  | 809 | (0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff | 
|  | 810 | (0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 811 | ## | 
|  | 812 | ## | 
|  | 813 |  | 
|  | 814 | #SeeAlso addr() readPixels | 
|  | 815 |  | 
|  | 816 | ## | 
|  | 817 |  | 
|  | 818 | #Subtopic Reader ## | 
|  | 819 |  | 
|  | 820 | #Subtopic Readable_Address | 
| Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 821 | #Line # returns read only pixels ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 822 |  | 
|  | 823 | # ------------------------------------------------------------------------------ | 
|  | 824 |  | 
|  | 825 | #Method const void* addr(int x, int y) const | 
|  | 826 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 827 | #In Readable_Address | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 828 | Returns readable pixel address at (x, y). Returns nullptr if Pixel_Ref is nullptr. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 829 |  | 
|  | 830 | Input is not validated: out of bounds values of x or y trigger an assert() if | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 831 | built with SK_DEBUG defined. Returns nullptr if Color_Type is kUnknown_SkColorType. | 
|  | 832 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 833 | Performs a lookup of pixel size; for better performance, call | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 834 | one of: addr8, addr16, addr32, addr64, or addrF16. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 835 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 836 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 837 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 838 |  | 
|  | 839 | #Return  readable generic pointer to pixel ## | 
|  | 840 |  | 
|  | 841 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 842 | const int w = 4; | 
|  | 843 | const int h = 4; | 
|  | 844 | std::vector<SkPMColor> storage; | 
|  | 845 | storage.resize(w * h); | 
|  | 846 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 847 | SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n", | 
|  | 848 | pixmap.addr(1, 2)  == &storage[1 + 2 * w] ? '=' : '!'); | 
|  | 849 | #StdOut | 
|  | 850 | pixmap.addr(1, 2) == &storage[1 + 2 * w] | 
|  | 851 | ## | 
|  | 852 | ## | 
|  | 853 |  | 
| Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 854 | #SeeAlso addr8 addr16 addr32 addr64 addrF16 getColor writable_addr SkBitmap::getAddr | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 855 |  | 
|  | 856 | ## | 
|  | 857 |  | 
|  | 858 | # ------------------------------------------------------------------------------ | 
|  | 859 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 860 | #Method const uint8_t* addr8() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 861 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 862 | #In Readable_Address | 
|  | 863 | #Line # returns readable pixel address as 8-bit pointer ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 864 | Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes. | 
|  | 865 | Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or | 
|  | 866 | kGray_8_SkColorType, and is built with SK_DEBUG defined. | 
|  | 867 |  | 
|  | 868 | One byte corresponds to one pixel. | 
|  | 869 |  | 
|  | 870 | #Return  readable unsigned 8-bit pointer to pixels ## | 
|  | 871 |  | 
|  | 872 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 873 | const int w = 4; | 
|  | 874 | const int h = 4; | 
|  | 875 | uint8_t storage[w * h]; | 
|  | 876 | SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType), | 
|  | 877 | storage, w * sizeof(storage[0])); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 878 | SkDebugf("pixmap.addr8() %c= storage\n", | 
|  | 879 | pixmap.addr8()  == storage ? '=' : '!'); | 
|  | 880 | #StdOut | 
|  | 881 | pixmap.addr8() == storage | 
|  | 882 | ## | 
|  | 883 | ## | 
|  | 884 |  | 
|  | 885 | #SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8 | 
|  | 886 |  | 
|  | 887 | ## | 
|  | 888 |  | 
|  | 889 | # ------------------------------------------------------------------------------ | 
|  | 890 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 891 | #Method const uint16_t* addr16() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 892 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 893 | #In Readable_Address | 
|  | 894 | #Line # returns readable pixel address as 16-bit pointer ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 895 | Returns readable base pixel address. Result is addressable as unsigned 16-bit words. | 
|  | 896 | Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or | 
|  | 897 | kARGB_4444_SkColorType, and is built with SK_DEBUG defined. | 
|  | 898 |  | 
|  | 899 | One word corresponds to one pixel. | 
|  | 900 |  | 
|  | 901 | #Return  readable unsigned 16-bit pointer to pixels ## | 
|  | 902 |  | 
|  | 903 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 904 | const int w = 4; | 
|  | 905 | const int h = 4; | 
|  | 906 | uint16_t storage[w * h]; | 
|  | 907 | SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType), | 
|  | 908 | storage, w * sizeof(storage[0])); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 909 | SkDebugf("pixmap.addr16() %c= storage\n", | 
|  | 910 | pixmap.addr16()  == storage ? '=' : '!'); | 
|  | 911 | #StdOut | 
|  | 912 | pixmap.addr16() == storage | 
|  | 913 | ## | 
|  | 914 | ## | 
|  | 915 |  | 
|  | 916 | #SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16 | 
|  | 917 |  | 
|  | 918 | ## | 
|  | 919 |  | 
|  | 920 | # ------------------------------------------------------------------------------ | 
|  | 921 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 922 | #Method const uint32_t* addr32() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 923 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 924 | #In Readable_Address | 
|  | 925 | #Line # returns readable pixel address as 32-bit pointer ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 926 | Returns readable base pixel address. Result is addressable as unsigned 32-bit words. | 
|  | 927 | Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or | 
|  | 928 | kBGRA_8888_SkColorType, and is built with SK_DEBUG defined. | 
|  | 929 |  | 
|  | 930 | One word corresponds to one pixel. | 
|  | 931 |  | 
|  | 932 | #Return  readable unsigned 32-bit pointer to pixels ## | 
|  | 933 |  | 
|  | 934 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 935 | const int w = 4; | 
|  | 936 | const int h = 4; | 
|  | 937 | uint32_t storage[w * h]; | 
|  | 938 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), | 
|  | 939 | storage, w * sizeof(storage[0])); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 940 | SkDebugf("pixmap.addr32() %c= storage\n", | 
|  | 941 | pixmap.addr32()  == storage ? '=' : '!'); | 
|  | 942 | #StdOut | 
|  | 943 | pixmap.addr32() == storage | 
|  | 944 | ## | 
|  | 945 | ## | 
|  | 946 |  | 
|  | 947 | #SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr32 | 
|  | 948 |  | 
|  | 949 | ## | 
|  | 950 |  | 
|  | 951 | # ------------------------------------------------------------------------------ | 
|  | 952 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 953 | #Method const uint64_t* addr64() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 954 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 955 | #In Readable_Address | 
|  | 956 | #Line # returns readable pixel address as 64-bit pointer ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 957 | Returns readable base pixel address. Result is addressable as unsigned 64-bit words. | 
|  | 958 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built | 
|  | 959 | with SK_DEBUG defined. | 
|  | 960 |  | 
|  | 961 | One word corresponds to one pixel. | 
|  | 962 |  | 
|  | 963 | #Return  readable unsigned 64-bit pointer to pixels ## | 
|  | 964 |  | 
|  | 965 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 966 | const int w = 4; | 
|  | 967 | const int h = 4; | 
|  | 968 | uint64_t storage[w * h]; | 
|  | 969 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), | 
|  | 970 | storage, w * sizeof(storage[0])); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 971 | SkDebugf("pixmap.addr64() %c= storage\n", | 
|  | 972 | pixmap.addr64()  == storage ? '=' : '!'); | 
|  | 973 | #StdOut | 
|  | 974 | pixmap.addr64() == storage | 
|  | 975 | ## | 
|  | 976 | ## | 
|  | 977 |  | 
|  | 978 | #SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64 | 
|  | 979 |  | 
|  | 980 | ## | 
|  | 981 |  | 
|  | 982 | # ------------------------------------------------------------------------------ | 
|  | 983 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 984 | #Method const uint16_t* addrF16() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 985 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 986 | #In Readable_Address | 
|  | 987 | #Line # returns readable pixel component address as 16-bit pointer ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 988 | Returns readable base pixel address. Result is addressable as unsigned 16-bit words. | 
|  | 989 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built | 
|  | 990 | with SK_DEBUG defined. | 
|  | 991 |  | 
|  | 992 | Each word represents one color component encoded as a half float. | 
|  | 993 | Four words correspond to one pixel. | 
|  | 994 |  | 
|  | 995 | #Return  readable unsigned 16-bit pointer to first component of pixels ## | 
|  | 996 |  | 
|  | 997 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 998 | const int w = 4; | 
|  | 999 | const int h = 4; | 
|  | 1000 | uint16_t storage[w * h * 4]; | 
|  | 1001 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), | 
|  | 1002 | storage, w * 4 * sizeof(storage[0])); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1003 | SkDebugf("pixmap.addrF16() %c= storage\n", | 
|  | 1004 | pixmap.addrF16()  == storage ? '=' : '!'); | 
|  | 1005 | #StdOut | 
|  | 1006 | pixmap.addrF16() == storage | 
|  | 1007 | ## | 
|  | 1008 | ## | 
|  | 1009 |  | 
|  | 1010 | #SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16 | 
|  | 1011 |  | 
|  | 1012 | ## | 
|  | 1013 |  | 
|  | 1014 | # ------------------------------------------------------------------------------ | 
|  | 1015 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1016 | #Method const uint8_t* addr8(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1017 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1018 | #In Readable_Address | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1019 | Returns readable pixel address at (x, y). | 
|  | 1020 |  | 
|  | 1021 | Input is not validated: out of bounds values of x or y trigger an assert() if | 
|  | 1022 | built with SK_DEBUG defined. | 
|  | 1023 |  | 
|  | 1024 | Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType or | 
|  | 1025 | kGray_8_SkColorType, and is built with SK_DEBUG defined. | 
|  | 1026 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1027 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1028 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1029 |  | 
|  | 1030 | #Return  readable unsigned 8-bit pointer to pixel at (x, y) ## | 
|  | 1031 |  | 
|  | 1032 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1033 | const int w = 4; | 
|  | 1034 | const int h = 4; | 
|  | 1035 | uint8_t storage[w * h]; | 
|  | 1036 | SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType), | 
|  | 1037 | storage, w * sizeof(storage[0])); | 
|  | 1038 | SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n", | 
|  | 1039 | pixmap.addr8(1, 2)  == &storage[1 + 2 * w] ? '=' : '!'); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1040 | #StdOut | 
|  | 1041 | pixmap.addr8(1, 2) == &storage[1 + 2 * w] | 
|  | 1042 | ## | 
|  | 1043 | ## | 
|  | 1044 |  | 
|  | 1045 | #SeeAlso addr() addr16 addr32 addr64 addrF16 getColor writable_addr writable_addr8 | 
|  | 1046 |  | 
|  | 1047 | ## | 
|  | 1048 |  | 
|  | 1049 | # ------------------------------------------------------------------------------ | 
|  | 1050 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1051 | #Method const uint16_t* addr16(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1052 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1053 | #In Readable_Address | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1054 | Returns readable pixel address at (x, y). | 
|  | 1055 |  | 
|  | 1056 | Input is not validated: out of bounds values of x or y trigger an assert() if | 
|  | 1057 | built with SK_DEBUG defined. | 
|  | 1058 |  | 
|  | 1059 | Will trigger an assert() if Color_Type is not kRGB_565_SkColorType or | 
|  | 1060 | kARGB_4444_SkColorType, and is built with SK_DEBUG defined. | 
|  | 1061 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1062 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1063 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1064 |  | 
|  | 1065 | #Return  readable unsigned 16-bit pointer to pixel at (x, y) ## | 
|  | 1066 |  | 
|  | 1067 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1068 | const int w = 4; | 
|  | 1069 | const int h = 4; | 
|  | 1070 | uint16_t storage[w * h]; | 
|  | 1071 | SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType), | 
|  | 1072 | storage, w * sizeof(storage[0])); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1073 | SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n", | 
|  | 1074 | pixmap.addr16(1, 2)  == &storage[1 + 2 * w] ? '=' : '!'); | 
|  | 1075 | #StdOut | 
|  | 1076 | pixmap.addr16(1, 2) == &storage[1 + 2 * w] | 
|  | 1077 | ## | 
|  | 1078 | ## | 
|  | 1079 |  | 
|  | 1080 | #SeeAlso addr() addr8 addr32 addr64 addrF16 getColor writable_addr writable_addr16 | 
|  | 1081 |  | 
|  | 1082 | ## | 
|  | 1083 |  | 
|  | 1084 | # ------------------------------------------------------------------------------ | 
|  | 1085 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1086 | #Method const uint32_t* addr32(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1087 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1088 | #In Readable_Address | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1089 | Returns readable pixel address at (x, y). | 
|  | 1090 |  | 
|  | 1091 | Input is not validated: out of bounds values of x or y trigger an assert() if | 
|  | 1092 | built with SK_DEBUG defined. | 
|  | 1093 |  | 
|  | 1094 | Will trigger an assert() if Color_Type is not kRGBA_8888_SkColorType or | 
|  | 1095 | kBGRA_8888_SkColorType, and is built with SK_DEBUG defined. | 
|  | 1096 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1097 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1098 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1099 |  | 
|  | 1100 | #Return  readable unsigned 32-bit pointer to pixel at (x, y) ## | 
|  | 1101 |  | 
|  | 1102 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1103 | const int w = 4; | 
|  | 1104 | const int h = 4; | 
|  | 1105 | uint32_t storage[w * h]; | 
|  | 1106 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType), | 
|  | 1107 | storage, w * sizeof(storage[0])); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1108 | SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n", | 
|  | 1109 | pixmap.addr32(1, 2)  == &storage[1 + 2 * w] ? '=' : '!'); | 
|  | 1110 | #StdOut | 
|  | 1111 | pixmap.addr32(1, 2) == &storage[1 + 2 * w] | 
|  | 1112 | ## | 
|  | 1113 | ## | 
|  | 1114 |  | 
| Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1115 | #SeeAlso addr() addr8 addr16 addr64 addrF16 getColor writable_addr writable_addr64 | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1116 |  | 
|  | 1117 | ## | 
|  | 1118 |  | 
|  | 1119 | # ------------------------------------------------------------------------------ | 
|  | 1120 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1121 | #Method const uint64_t* addr64(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1122 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1123 | #In Readable_Address | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1124 | Returns readable pixel address at (x, y). | 
|  | 1125 |  | 
|  | 1126 | Input is not validated: out of bounds values of x or y trigger an assert() if | 
|  | 1127 | built with SK_DEBUG defined. | 
|  | 1128 |  | 
|  | 1129 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built | 
|  | 1130 | with SK_DEBUG defined. | 
|  | 1131 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1132 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1133 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1134 |  | 
|  | 1135 | #Return  readable unsigned 64-bit pointer to pixel at (x, y) ## | 
|  | 1136 |  | 
|  | 1137 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1138 | const int w = 4; | 
|  | 1139 | const int h = 4; | 
|  | 1140 | uint64_t storage[w * h]; | 
|  | 1141 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), | 
|  | 1142 | storage, w * sizeof(storage[0])); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1143 | SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n", | 
|  | 1144 | pixmap.addr64(1, 2)  == &storage[1 + 2 * w] ? '=' : '!'); | 
|  | 1145 | #StdOut | 
|  | 1146 | pixmap.addr64(1, 2) == &storage[1 + 2 * w] | 
|  | 1147 | ## | 
|  | 1148 | ## | 
|  | 1149 |  | 
|  | 1150 | #SeeAlso addr() addr8 addr16 addr32 addrF16 getColor writable_addr writable_addr64 | 
|  | 1151 |  | 
|  | 1152 | ## | 
|  | 1153 |  | 
|  | 1154 | # ------------------------------------------------------------------------------ | 
|  | 1155 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1156 | #Method const uint16_t* addrF16(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1157 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1158 | #In Readable_Address | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1159 | Returns readable pixel address at (x, y). | 
|  | 1160 |  | 
|  | 1161 | Input is not validated: out of bounds values of x or y trigger an assert() if | 
|  | 1162 | built with SK_DEBUG defined. | 
|  | 1163 |  | 
|  | 1164 | Will trigger an assert() if Color_Type is not kRGBA_F16_SkColorType and is built | 
|  | 1165 | with SK_DEBUG defined. | 
|  | 1166 |  | 
|  | 1167 | Each unsigned 16-bit word represents one color component encoded as a half float. | 
|  | 1168 | Four words correspond to one pixel. | 
|  | 1169 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1170 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1171 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1172 |  | 
|  | 1173 | #Return  readable unsigned 16-bit pointer to pixel component at (x, y) ## | 
|  | 1174 |  | 
|  | 1175 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1176 | const int w = 4; | 
|  | 1177 | const int h = 4; | 
|  | 1178 | const int wordsPerPixel = 4; | 
|  | 1179 | const int rowWords = w * wordsPerPixel; | 
|  | 1180 | uint16_t storage[rowWords * h]; | 
|  | 1181 | SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), | 
|  | 1182 | storage, rowWords * sizeof(storage[0])); | 
|  | 1183 | SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n", | 
|  | 1184 | pixmap.addrF16(1, 2)  == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!'); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1185 | #StdOut | 
|  | 1186 | pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] | 
|  | 1187 | ## | 
|  | 1188 | ## | 
|  | 1189 |  | 
|  | 1190 | #SeeAlso addr() addr8 addr16 addr32 addr64 getColor writable_addr writable_addrF16 | 
|  | 1191 |  | 
|  | 1192 | ## | 
|  | 1193 |  | 
|  | 1194 | #Subtopic Readable_Address ## | 
|  | 1195 |  | 
|  | 1196 | #Subtopic Writable_Address | 
| Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1197 | #Line # returns writable pixels ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1198 |  | 
|  | 1199 | # ------------------------------------------------------------------------------ | 
|  | 1200 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1201 | #Method void* writable_addr() const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1202 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1203 | #In Writable_Address | 
|  | 1204 | #Line # returns writable pixel address as void pointer ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1205 | Returns writable base pixel address. | 
|  | 1206 |  | 
|  | 1207 | #Return  writable generic base pointer to pixels ## | 
|  | 1208 |  | 
|  | 1209 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1210 | const int w = 4; | 
|  | 1211 | const int h = 4; | 
|  | 1212 | SkPMColor storage[w * h * 4]; | 
|  | 1213 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4); | 
|  | 1214 | SkDebugf("pixmap.writable_addr() %c= (void *)storage\n", | 
|  | 1215 | pixmap.writable_addr()  == (void *)storage ? '=' : '!'); | 
|  | 1216 | pixmap.erase(0x00000000); | 
|  | 1217 | *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF; | 
|  | 1218 | SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n", | 
|  | 1219 | pixmap.getColor(0, 1)  == 0x00000000 ? '=' : '!'); | 
|  | 1220 | SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n", | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1221 | pixmap.getColor(0, 0)  == 0xFFFFFFFF ? '=' : '!'); | 
|  | 1222 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1223 | pixmap.writable_addr() == (void *)storage | 
|  | 1224 | pixmap.getColor(0, 1) == 0x00000000 | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1225 | pixmap.getColor(0, 0) == 0xFFFFFFFF | 
|  | 1226 | ## | 
|  | 1227 | ## | 
|  | 1228 |  | 
|  | 1229 | #SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() | 
|  | 1230 |  | 
|  | 1231 | ## | 
|  | 1232 |  | 
|  | 1233 | # ------------------------------------------------------------------------------ | 
|  | 1234 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1235 | #Method void* writable_addr(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1236 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1237 | #In Writable_Address | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1238 | Returns writable pixel address at (x, y). | 
|  | 1239 |  | 
|  | 1240 | Input is not validated: out of bounds values of x or y trigger an assert() if | 
|  | 1241 | built with SK_DEBUG defined. Returns zero if Color_Type is kUnknown_SkColorType. | 
|  | 1242 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1243 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1244 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1245 |  | 
|  | 1246 | #Return  writable generic pointer to pixel ## | 
|  | 1247 |  | 
|  | 1248 | #Example | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1249 | const int w = 4; | 
|  | 1250 | const int h = 4; | 
|  | 1251 | SkPMColor storage[w * h * 4]; | 
|  | 1252 | SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4); | 
|  | 1253 | SkDebugf("pixmap.writable_addr() %c= (void *)storage\n", | 
|  | 1254 | pixmap.writable_addr()  == (void *)storage ? '=' : '!'); | 
|  | 1255 | pixmap.erase(0x00000000); | 
|  | 1256 | *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF; | 
|  | 1257 | SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n", | 
|  | 1258 | pixmap.getColor(0, 0)  == 0x00000000 ? '=' : '!'); | 
|  | 1259 | SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n", | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1260 | pixmap.getColor(1, 2)  == 0xFFFFFFFF ? '=' : '!'); | 
|  | 1261 | #StdOut | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1262 | pixmap.writable_addr() == (void *)storage | 
|  | 1263 | pixmap.getColor(0, 0) == 0x00000000 | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1264 | pixmap.getColor(1, 2) == 0xFFFFFFFF | 
|  | 1265 | ## | 
|  | 1266 | ## | 
|  | 1267 |  | 
|  | 1268 | #SeeAlso writable_addr8 writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() | 
|  | 1269 |  | 
|  | 1270 | ## | 
|  | 1271 |  | 
|  | 1272 | # ------------------------------------------------------------------------------ | 
|  | 1273 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1274 | #Method uint8_t* writable_addr8(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1275 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1276 | #In Writable_Address | 
|  | 1277 | #Line # returns writable pixel address as 8-bit pointer ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1278 | Returns writable pixel address at (x, y). Result is addressable as unsigned | 
|  | 1279 | 8-bit bytes. Will trigger an assert() if Color_Type is not kAlpha_8_SkColorType | 
|  | 1280 | or kGray_8_SkColorType, and is built with SK_DEBUG defined. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1281 |  | 
|  | 1282 | One byte corresponds to one pixel. | 
|  | 1283 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1284 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1285 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1286 |  | 
|  | 1287 | #Return  writable unsigned 8-bit pointer to pixels ## | 
|  | 1288 |  | 
|  | 1289 | #Example | 
|  | 1290 | #Height 64 | 
|  | 1291 | #Description | 
|  | 1292 | Altering pixels after drawing Bitmap is not guaranteed to affect subsequent | 
|  | 1293 | drawing on all platforms. Adding a second SkBitmap::installPixels after editing | 
|  | 1294 | pixel memory is safer. | 
|  | 1295 | ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1296 | void draw(SkCanvas* canvas) { | 
|  | 1297 | uint8_t storage[][5] = {{ 0,   0,  64,   0,  0}, | 
|  | 1298 | { 0, 128, 255, 128,  0}, | 
|  | 1299 | {64, 255, 255, 255, 64}, | 
|  | 1300 | { 0, 128, 255, 128,  0}, | 
|  | 1301 | { 0,   0,  64,   0,  0}}; | 
|  | 1302 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType); | 
|  | 1303 | SkPixmap pixmap(imageInfo, storage[0], 5); | 
|  | 1304 | SkBitmap bitmap; | 
|  | 1305 | bitmap.installPixels(pixmap); | 
|  | 1306 | canvas->scale(10, 10); | 
|  | 1307 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1308 | *pixmap.writable_addr8(2, 2) = 0; | 
|  | 1309 | //  bitmap.installPixels(pixmap);      // uncomment to fix on GPU | 
|  | 1310 | canvas->drawBitmap(bitmap, 10, 0); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1311 | } | 
|  | 1312 | ## | 
|  | 1313 |  | 
|  | 1314 | #SeeAlso writable_addr writable_addr16 writable_addr32 writable_addr64 writable_addrF16 addr() addr8 | 
|  | 1315 |  | 
|  | 1316 | ## | 
|  | 1317 |  | 
|  | 1318 | # ------------------------------------------------------------------------------ | 
|  | 1319 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1320 | #Method uint16_t* writable_addr16(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1321 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1322 | #In Writable_Address | 
|  | 1323 | #Line # returns writable pixel address as 16-bit pointer ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1324 | Returns writable_addr pixel address at (x, y). Result is addressable as unsigned | 
|  | 1325 | 16-bit words. Will trigger an assert() if Color_Type is not kRGB_565_SkColorType | 
|  | 1326 | or kARGB_4444_SkColorType, and is built with SK_DEBUG defined. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1327 |  | 
|  | 1328 | One word corresponds to one pixel. | 
|  | 1329 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1330 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1331 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1332 |  | 
|  | 1333 | #Return  writable unsigned 16-bit pointer to pixel ## | 
|  | 1334 |  | 
|  | 1335 | #Example | 
|  | 1336 | #Description | 
|  | 1337 | Draw a five by five bitmap, and draw it again with a center black pixel. | 
|  | 1338 | The low nibble of the 16-bit word is Alpha. | 
|  | 1339 | ## | 
|  | 1340 | #Height 64 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1341 | uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B }, | 
|  | 1342 | { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 }, | 
|  | 1343 | { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 }, | 
|  | 1344 | { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 }, | 
|  | 1345 | { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }}; | 
|  | 1346 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType); | 
|  | 1347 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); | 
|  | 1348 | SkBitmap bitmap; | 
|  | 1349 | bitmap.installPixels(pixmap); | 
|  | 1350 | canvas->scale(10, 10); | 
|  | 1351 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1352 | *pixmap.writable_addr16(2, 2) = 0x000F; | 
|  | 1353 | bitmap.installPixels(pixmap); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1354 | canvas->drawBitmap(bitmap, 10, 0); | 
|  | 1355 | ## | 
|  | 1356 |  | 
|  | 1357 | #SeeAlso writable_addr writable_addr8 writable_addr32 writable_addr64 writable_addrF16 addr() addr16 | 
|  | 1358 |  | 
|  | 1359 | ## | 
|  | 1360 |  | 
|  | 1361 | # ------------------------------------------------------------------------------ | 
|  | 1362 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1363 | #Method uint32_t* writable_addr32(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1364 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1365 | #In Writable_Address | 
|  | 1366 | #Line # returns writable pixel address as 32-bit pointer ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1367 | Returns writable pixel address at (x, y). Result is addressable as unsigned | 
|  | 1368 | 32-bit words. Will trigger an assert() if Color_Type is not | 
|  | 1369 | kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG | 
|  | 1370 | defined. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1371 |  | 
|  | 1372 | One word corresponds to one pixel. | 
|  | 1373 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1374 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1375 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1376 |  | 
|  | 1377 | #Return  writable unsigned 32-bit pointer to pixel ## | 
|  | 1378 |  | 
|  | 1379 | #Example | 
|  | 1380 | #Image 4 | 
|  | 1381 | #Height 72 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1382 | std::vector<int32_t> pixels; | 
|  | 1383 | pixels.resize(image->height() * image->width() * 4); | 
|  | 1384 | SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, | 
|  | 1385 | image->alphaType()), (const void*) &pixels.front(), image->width() * 4); | 
|  | 1386 | image->readPixels(pixmap, 0, 0); | 
|  | 1387 | for (int y = 0; y < pixmap.height() / 2; ++y) { | 
|  | 1388 | for (int x = 0; x < pixmap.width(); ++x) { | 
|  | 1389 | if ((x & 4) == (y & 4)) { | 
| Cary Clark | 4d75975 | 2018-06-19 12:57:43 -0400 | [diff] [blame] | 1390 | *pixmap.writable_addr32(x, y) = | 
|  | 1391 | *pixmap.writable_addr32(pixmap.width() - x, pixmap.height() - y); | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1392 | } | 
|  | 1393 | } | 
|  | 1394 | } | 
|  | 1395 | SkBitmap bitmap; | 
|  | 1396 | bitmap.installPixels(pixmap); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1397 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1398 | ## | 
|  | 1399 |  | 
|  | 1400 | #SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr64 writable_addrF16 addr() addr32 | 
|  | 1401 |  | 
|  | 1402 | ## | 
|  | 1403 |  | 
|  | 1404 | # ------------------------------------------------------------------------------ | 
|  | 1405 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1406 | #Method uint64_t* writable_addr64(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1407 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1408 | #In Writable_Address | 
|  | 1409 | #Line # returns writable pixel address as 64-bit pointer ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1410 | Returns writable pixel address at (x, y). Result is addressable as unsigned | 
|  | 1411 | 64-bit words. Will trigger an assert() if Color_Type is not | 
|  | 1412 | kRGBA_F16_SkColorType and is built with SK_DEBUG defined. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1413 |  | 
|  | 1414 | One word corresponds to one pixel. | 
|  | 1415 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1416 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1417 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1418 |  | 
|  | 1419 | #Return  writable unsigned 64-bit pointer to pixel ## | 
|  | 1420 |  | 
|  | 1421 | #Example | 
| Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1422 | #Height 40 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1423 | SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType); | 
|  | 1424 | uint64_t storage[9]; | 
|  | 1425 | SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t)); | 
|  | 1426 | SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f }; | 
|  | 1427 | pixmap.erase(c4); | 
|  | 1428 | SkBitmap bitmap; | 
|  | 1429 | canvas->scale(10, 10); | 
|  | 1430 | bitmap.installPixels(pixmap); | 
|  | 1431 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1432 | *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL; | 
|  | 1433 | bitmap.installPixels(pixmap); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1434 | canvas->drawBitmap(bitmap, 10, 0); | 
|  | 1435 | ## | 
|  | 1436 |  | 
|  | 1437 | #SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addrF16 addr() addr64 | 
|  | 1438 |  | 
|  | 1439 | ## | 
|  | 1440 |  | 
|  | 1441 | # ------------------------------------------------------------------------------ | 
|  | 1442 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1443 | #Method uint16_t* writable_addrF16(int x, int y) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1444 |  | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1445 | #In Writable_Address | 
|  | 1446 | #Line # returns writable pixel component address as 16-bit pointer ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1447 | Returns writable pixel address at (x, y). Result is addressable as unsigned | 
|  | 1448 | 16-bit words. Will trigger an assert() if Color_Type is not | 
|  | 1449 | kRGBA_F16_SkColorType and is built with SK_DEBUG defined. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1450 |  | 
|  | 1451 | Each word represents one color component encoded as a half float. | 
|  | 1452 | Four words correspond to one pixel. | 
|  | 1453 |  | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1454 | #Param x  column index, zero or greater, and less than width() ## | 
|  | 1455 | #Param y  row index, zero or greater, and less than height() ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1456 |  | 
|  | 1457 | #Return  writable unsigned 16-bit pointer to first component of pixel ## | 
|  | 1458 |  | 
|  | 1459 | #Example | 
|  | 1460 | #Height 64 | 
|  | 1461 | #Description | 
|  | 1462 | Left bitmap is drawn with two pixels defined in half float format. Right bitmap | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1463 | is drawn after overwriting bottom half float color with top half float color. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1464 | ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1465 | SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType); | 
|  | 1466 | uint16_t storage[2][4]; | 
|  | 1467 | SkPixmap pixmap(info, storage[0], sizeof(uint64_t)); | 
|  | 1468 | SkIRect topPixelBounds = {0, 0, 1, 1}; | 
|  | 1469 | pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds); | 
|  | 1470 | SkIRect bottomPixelBounds = {0, 1, 1, 2}; | 
|  | 1471 | pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds); | 
|  | 1472 | SkBitmap bitmap; | 
|  | 1473 | canvas->scale(20, 20); | 
|  | 1474 | bitmap.installPixels(pixmap); | 
|  | 1475 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1476 | uint16_t* pixel2 = pixmap.writable_addrF16(0, 1); | 
|  | 1477 | for (int i = 0; i < 4; ++i) { | 
|  | 1478 | pixel2[i] = storage[0][i]; | 
|  | 1479 | } | 
|  | 1480 | bitmap.installPixels(pixmap); | 
|  | 1481 | canvas->drawBitmap(bitmap, 4, 0); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1482 | ## | 
|  | 1483 |  | 
|  | 1484 | #SeeAlso writable_addr writable_addr8 writable_addr16 writable_addr32 writable_addr64 addr() addrF16 | 
|  | 1485 |  | 
|  | 1486 | ## | 
|  | 1487 |  | 
|  | 1488 | #Subtopic Writable_Address ## | 
|  | 1489 |  | 
| Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1490 | #Subtopic Pixels | 
|  | 1491 | #Populate | 
|  | 1492 | #Line # read and write pixel values ## | 
|  | 1493 | ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1494 |  | 
|  | 1495 | # ------------------------------------------------------------------------------ | 
|  | 1496 |  | 
| Cary Clark | e80cd44 | 2018-07-17 13:19:56 -0400 | [diff] [blame] | 1497 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const | 
| Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1498 | #In Pixels | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1499 | #Line # copies and converts pixels ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1500 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1501 | Copies a Rect of pixels to dstPixels. Copy starts at (0, 0), and does not | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1502 | exceed Pixmap (width(), height()). | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1503 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1504 | dstInfo specifies width, height, Color_Type, Alpha_Type, and | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1505 | Color_Space of destination. dstRowBytes specifics the gap from one destination | 
|  | 1506 | row to the next. Returns true if pixels are copied. Returns false if | 
|  | 1507 | dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes. | 
|  | 1508 |  | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1509 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1510 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1511 | If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. | 
|  | 1512 | If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must | 
|  | 1513 | match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1514 | false if pixel conversion is not possible. | 
|  | 1515 |  | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1516 | Returns false if Pixmap width() or height() is zero or negative. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1517 |  | 
|  | 1518 | #Param dstInfo  destination width, height, Color_Type, Alpha_Type, Color_Space ## | 
|  | 1519 | #Param dstPixels  destination pixel storage ## | 
|  | 1520 | #Param dstRowBytes  destination row length ## | 
|  | 1521 |  | 
|  | 1522 | #Return  true if pixels are copied to dstPixels ## | 
|  | 1523 |  | 
|  | 1524 | #Example | 
|  | 1525 | #Height 128 | 
|  | 1526 | #Description | 
|  | 1527 | Transferring the gradient from 8 bits per component to 4 bits per component | 
|  | 1528 | creates visible banding. | 
|  | 1529 | ## | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1530 | std::vector<int32_t> pixels; | 
|  | 1531 | const int width = 256; | 
|  | 1532 | const int height = 64; | 
|  | 1533 | pixels.resize(height * width * 4); | 
|  | 1534 | SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height); | 
|  | 1535 | SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4); | 
|  | 1536 | SkColor  gradColors[] = { 0xFFAA3300, 0x7F881122 }; | 
|  | 1537 | SkPoint  gradPoints[] = { { 0, 0 }, { 256, 0 } }; | 
|  | 1538 | SkPaint paint; | 
|  | 1539 | paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, | 
|  | 1540 | SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); | 
|  | 1541 | SkBitmap bitmap; | 
|  | 1542 | bitmap.installPixels(srcPixmap); | 
|  | 1543 | SkCanvas srcCanvas(bitmap); | 
|  | 1544 | srcCanvas.drawRect(SkRect::MakeWH(width, height), paint); | 
|  | 1545 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1546 | std::vector<int32_t> dstPixels; | 
|  | 1547 | dstPixels.resize(height * width * 2); | 
|  | 1548 | SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType); | 
|  | 1549 | srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2); | 
|  | 1550 | SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2); | 
|  | 1551 | bitmap.installPixels(dstPixmap); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1552 | canvas->drawBitmap(bitmap, 0, 128); | 
|  | 1553 | ## | 
|  | 1554 |  | 
|  | 1555 | #SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels | 
|  | 1556 |  | 
|  | 1557 | ## | 
|  | 1558 |  | 
|  | 1559 | # ------------------------------------------------------------------------------ | 
|  | 1560 |  | 
|  | 1561 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1562 | int srcY) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1563 |  | 
|  | 1564 | Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1565 | exceed Pixmap (width(), height()). | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1566 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1567 | dstInfo specifies width, height, Color_Type, Alpha_Type, and | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1568 | Color_Space of destination. dstRowBytes specifics the gap from one destination | 
|  | 1569 | row to the next. Returns true if pixels are copied. Returns false if | 
|  | 1570 | dstInfo.addr() equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes. | 
|  | 1571 |  | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1572 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1573 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1574 | If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. | 
|  | 1575 | If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must | 
|  | 1576 | match. If Pixmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1577 | false if pixel conversion is not possible. | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1578 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1579 | srcX and srcY may be negative to copy only top or left of source. Returns | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1580 | false if Pixmap width() or height() is zero or negative. Returns false if: | 
| Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1581 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1582 | #Formula | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1583 | abs(srcX) >= Pixmap width() | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1584 | ## | 
|  | 1585 | , or if | 
|  | 1586 | #Formula | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1587 | abs(srcY) >= Pixmap height() | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1588 | ## | 
|  | 1589 | . | 
|  | 1590 |  | 
|  | 1591 | #Param dstInfo  destination width, height, Color_Type, Alpha_Type, Color_Space ## | 
|  | 1592 | #Param dstPixels  destination pixel storage ## | 
|  | 1593 | #Param dstRowBytes  destination row length ## | 
|  | 1594 | #Param srcX  column index whose absolute value is less than width() ## | 
|  | 1595 | #Param srcY  row index whose absolute value is less than height() ## | 
|  | 1596 |  | 
|  | 1597 | #Return  true if pixels are copied to dstPixels ## | 
|  | 1598 |  | 
|  | 1599 | #Example | 
|  | 1600 | #Image 3 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1601 | void draw(SkCanvas* canvas) { | 
|  | 1602 | SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); | 
|  | 1603 | std::vector<int32_t> srcPixels; | 
|  | 1604 | const int rowBytes = image->width() * 4; | 
|  | 1605 | srcPixels.resize(image->height() * rowBytes); | 
|  | 1606 | SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); | 
|  | 1607 | image->readPixels(pixmap, 0, 0); | 
|  | 1608 | for (int offset : { 32, 64, 96 } ) { | 
|  | 1609 | std::vector<int32_t> dstPixels; | 
|  | 1610 | dstPixels.resize(image->height() * rowBytes); | 
|  | 1611 | pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0); | 
|  | 1612 | SkBitmap bitmap; | 
|  | 1613 | SkPixmap dstmap(info, &dstPixels.front(), rowBytes); | 
|  | 1614 | bitmap.installPixels(dstmap); | 
|  | 1615 | canvas->translate(32, 32); | 
|  | 1616 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1617 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1618 | } | 
|  | 1619 | ## | 
|  | 1620 |  | 
|  | 1621 | #SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels | 
|  | 1622 |  | 
|  | 1623 | ## | 
|  | 1624 |  | 
|  | 1625 | # ------------------------------------------------------------------------------ | 
|  | 1626 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1627 | #Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1628 |  | 
|  | 1629 | Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1630 | exceed Pixmap (width(), height()). dst specifies width, height, Color_Type, | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1631 | Alpha_Type, and Color_Space of destination.  Returns true if pixels are copied. | 
|  | 1632 | Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than | 
|  | 1633 | dst SkImageInfo::minRowBytes. | 
|  | 1634 |  | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1635 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1636 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match. | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1637 | If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace must match. | 
|  | 1638 | If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType must | 
|  | 1639 | match. If Pixmap colorSpace is nullptr, dst.info().colorSpace must match. Returns | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1640 | false if pixel conversion is not possible. | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1641 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1642 | srcX and srcY may be negative to copy only top or left of source. Returns | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1643 | false Pixmap width() or height() is zero or negative. Returns false if: | 
| Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1644 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1645 | #Formula | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1646 | abs(srcX) >= Pixmap width() | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1647 | ## | 
|  | 1648 | , or if | 
|  | 1649 | #Formula | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1650 | abs(srcY) >= Pixmap height() | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1651 | ## | 
|  | 1652 | . | 
|  | 1653 |  | 
|  | 1654 | #Param dst  Image_Info and pixel address to write to ## | 
|  | 1655 | #Param srcX  column index whose absolute value is less than width() ## | 
|  | 1656 | #Param srcY  row index whose absolute value is less than height() ## | 
|  | 1657 |  | 
|  | 1658 | #Return  true if pixels are copied to dst ## | 
|  | 1659 |  | 
|  | 1660 | #Example | 
|  | 1661 | #Image 3 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1662 | void draw(SkCanvas* canvas) { | 
|  | 1663 | SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); | 
|  | 1664 | std::vector<int32_t> srcPixels; | 
|  | 1665 | const int rowBytes = image->width() * 4; | 
|  | 1666 | srcPixels.resize(image->height() * rowBytes); | 
|  | 1667 | SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); | 
|  | 1668 | image->readPixels(pixmap, 0, 0); | 
|  | 1669 | for (int offset : { 32, 64, 96 } ) { | 
|  | 1670 | std::vector<int32_t> dstPixels; | 
|  | 1671 | dstPixels.resize(image->height() * rowBytes); | 
|  | 1672 | SkPixmap dstmap(info, &dstPixels.front(), rowBytes); | 
|  | 1673 | pixmap.readPixels(dstmap, offset, 0); | 
|  | 1674 | SkBitmap bitmap; | 
|  | 1675 | bitmap.installPixels(dstmap); | 
|  | 1676 | canvas->translate(32, 32); | 
|  | 1677 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1678 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1679 | } | 
|  | 1680 | ## | 
|  | 1681 |  | 
|  | 1682 | #SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels | 
|  | 1683 |  | 
|  | 1684 | ## | 
|  | 1685 |  | 
|  | 1686 | # ------------------------------------------------------------------------------ | 
|  | 1687 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1688 | #Method bool readPixels(const SkPixmap& dst) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1689 |  | 
|  | 1690 | Copies pixels inside bounds() to dst. dst specifies width, height, Color_Type, | 
|  | 1691 | Alpha_Type, and Color_Space of destination.  Returns true if pixels are copied. | 
|  | 1692 | Returns false if dst.addr() equals nullptr, or dst.rowBytes is less than | 
|  | 1693 | dst SkImageInfo::minRowBytes. | 
|  | 1694 |  | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1695 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1696 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match. | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1697 | If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match. | 
|  | 1698 | If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must | 
|  | 1699 | match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1700 | false if pixel conversion is not possible. | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1701 |  | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1702 | Returns false if Pixmap width() or height() is zero or negative. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1703 |  | 
|  | 1704 | #Param dst  Image_Info and pixel address to write to ## | 
|  | 1705 |  | 
|  | 1706 | #Return  true if pixels are copied to dst ## | 
|  | 1707 |  | 
|  | 1708 | #Example | 
|  | 1709 | #Image 3 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1710 | void draw(SkCanvas* canvas) { | 
|  | 1711 | SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); | 
|  | 1712 | std::vector<int32_t> srcPixels; | 
|  | 1713 | const int rowBytes = image->width() * 4; | 
|  | 1714 | srcPixels.resize(image->height() * rowBytes); | 
|  | 1715 | SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); | 
|  | 1716 | image->readPixels(pixmap, 0, 0); | 
|  | 1717 | for (int index = 0; index < 3; ++index ) { | 
|  | 1718 | std::vector<int32_t> dstPixels; | 
|  | 1719 | dstPixels.resize(image->height() * rowBytes); | 
|  | 1720 | SkPixmap dstmap(info, &dstPixels.front(), rowBytes); | 
|  | 1721 | pixmap.readPixels(dstmap); | 
|  | 1722 | SkBitmap bitmap; | 
|  | 1723 | bitmap.installPixels(dstmap); | 
|  | 1724 | canvas->translate(32, 32); | 
|  | 1725 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1726 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1727 | } | 
|  | 1728 | ## | 
|  | 1729 |  | 
|  | 1730 | #SeeAlso erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels | 
|  | 1731 |  | 
|  | 1732 | ## | 
|  | 1733 |  | 
|  | 1734 | # ------------------------------------------------------------------------------ | 
|  | 1735 |  | 
|  | 1736 | #Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const | 
|  | 1737 |  | 
| Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1738 | #In Pixels | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1739 | #Line # scales and converts pixels ## | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1740 | Copies Bitmap to dst, scaling pixels to fit dst.width() and dst.height(), and | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1741 | converting pixels to match dst.colorType and dst.alphaType. Returns true if | 
|  | 1742 | pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is | 
|  | 1743 | less than dst SkImageInfo::minRowBytes. | 
|  | 1744 |  | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1745 | Pixels are copied only if pixel conversion is possible. If Pixmap colorType is | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1746 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match. | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1747 | If Pixmap colorType is kGray_8_SkColorType, dst Color_Space must match. | 
|  | 1748 | If Pixmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must | 
|  | 1749 | match. If Pixmap colorSpace is nullptr, dst Color_Space must match. Returns | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1750 | false if pixel conversion is not possible. | 
|  | 1751 |  | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1752 | Returns false if Bitmap width() or height() is zero or negative. | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1753 |  | 
|  | 1754 | Scales the image, with filterQuality, to match dst.width() and dst.height(). | 
|  | 1755 | filterQuality kNone_SkFilterQuality is fastest, typically implemented with | 
|  | 1756 | Filter_Quality_Nearest_Neighbor. kLow_SkFilterQuality is typically implemented with | 
|  | 1757 | Filter_Quality_Bilerp. kMedium_SkFilterQuality is typically implemented with | 
|  | 1758 | Filter_Quality_Bilerp, and Filter_Quality_MipMap when size is reduced. | 
|  | 1759 | kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic. | 
|  | 1760 |  | 
|  | 1761 | #Param dst  Image_Info and pixel address to write to ## | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1762 | #Param filterQuality  one of: kNone_SkFilterQuality, kLow_SkFilterQuality, | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1763 | kMedium_SkFilterQuality, kHigh_SkFilterQuality | 
|  | 1764 | ## | 
|  | 1765 |  | 
| Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1766 | #Return  true if pixels are scaled to fit dst ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1767 |  | 
|  | 1768 | #Example | 
|  | 1769 | #Image 3 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1770 | void draw(SkCanvas* canvas) { | 
|  | 1771 | SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); | 
|  | 1772 | std::vector<int32_t> srcPixels; | 
|  | 1773 | int rowBytes = image->width() * 4; | 
|  | 1774 | srcPixels.resize(image->height() * rowBytes); | 
|  | 1775 | SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); | 
|  | 1776 | image->readPixels(pixmap, 0, 0); | 
|  | 1777 | for (int offset : { 32, 64, 96 } ) { | 
|  | 1778 | info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height()); | 
|  | 1779 | rowBytes = info.width() * 4; | 
|  | 1780 | std::vector<int32_t> dstPixels; | 
|  | 1781 | dstPixels.resize(image->height() * rowBytes); | 
|  | 1782 | SkPixmap dstmap(info, &dstPixels.front(), rowBytes); | 
|  | 1783 | pixmap.scalePixels(dstmap, kMedium_SkFilterQuality); | 
|  | 1784 | SkBitmap bitmap; | 
|  | 1785 | bitmap.installPixels(dstmap); | 
|  | 1786 | canvas->translate(32, 32); | 
|  | 1787 | canvas->drawBitmap(bitmap, 0, 0); | 
|  | 1788 | } | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1789 | } | 
|  | 1790 | ## | 
|  | 1791 |  | 
|  | 1792 | #SeeAlso SkCanvas::drawBitmap SkImage::scalePixels | 
|  | 1793 |  | 
|  | 1794 | ## | 
|  | 1795 |  | 
|  | 1796 | # ------------------------------------------------------------------------------ | 
|  | 1797 |  | 
|  | 1798 | #Method bool erase(SkColor color, const SkIRect& subset) const | 
|  | 1799 |  | 
| Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1800 | #In Pixels | 
| Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1801 | #Line # writes Color to pixels ## | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1802 | Writes color to pixels bounded by subset; returns true on success. | 
|  | 1803 | Returns false if colorType is kUnknown_SkColorType, or if subset does | 
|  | 1804 | not intersect bounds(). | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1805 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1806 | #Param color  Unpremultiplied Color to write ## | 
|  | 1807 | #Param subset bounding integer Rect of written pixels ## | 
|  | 1808 |  | 
|  | 1809 | #Return  true if pixels are changed ## | 
|  | 1810 |  | 
|  | 1811 | #Example | 
| Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1812 | #Height 50 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1813 | uint32_t storage[2]; | 
|  | 1814 | SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2); | 
|  | 1815 | SkPixmap pixmap(info, storage, info.minRowBytes()); | 
|  | 1816 | pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1}); | 
|  | 1817 | pixmap.erase(SK_ColorRED, {0, 1, 1, 2}); | 
|  | 1818 | SkBitmap bitmap; | 
|  | 1819 | canvas->scale(20, 20); | 
|  | 1820 | bitmap.installPixels(pixmap); | 
|  | 1821 | canvas->drawBitmap(bitmap, 0, 0); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1822 | ## | 
|  | 1823 |  | 
|  | 1824 | #SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor | 
|  | 1825 |  | 
|  | 1826 | ## | 
|  | 1827 |  | 
|  | 1828 | # ------------------------------------------------------------------------------ | 
|  | 1829 |  | 
| Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1830 | #Method bool erase(SkColor color) const | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1831 |  | 
|  | 1832 | Writes color to pixels inside bounds(); returns true on success. | 
|  | 1833 | Returns false if colorType is kUnknown_SkColorType, or if bounds() | 
|  | 1834 | is empty. | 
|  | 1835 |  | 
|  | 1836 | #Param color  Unpremultiplied Color to write ## | 
|  | 1837 |  | 
|  | 1838 | #Return  true if pixels are changed ## | 
|  | 1839 |  | 
|  | 1840 | #Example | 
| Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1841 | #Height 50 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1842 | uint32_t storage[2]; | 
|  | 1843 | SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2); | 
|  | 1844 | SkPixmap pixmap(info, storage, info.minRowBytes()); | 
|  | 1845 | pixmap.erase(SK_ColorBLUE); | 
|  | 1846 | SkBitmap bitmap; | 
|  | 1847 | canvas->scale(20, 20); | 
|  | 1848 | bitmap.installPixels(pixmap); | 
|  | 1849 | canvas->drawBitmap(bitmap, 0, 0); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1850 | ## | 
|  | 1851 |  | 
|  | 1852 | #SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor | 
|  | 1853 |  | 
|  | 1854 | ## | 
|  | 1855 |  | 
|  | 1856 | # ------------------------------------------------------------------------------ | 
|  | 1857 |  | 
|  | 1858 | #Method bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const | 
|  | 1859 |  | 
|  | 1860 | Writes color to pixels bounded by subset; returns true on success. | 
|  | 1861 | if subset is nullptr, writes colors pixels inside bounds(). Returns false if | 
|  | 1862 | colorType is kUnknown_SkColorType, if subset is not nullptr and does | 
|  | 1863 | not intersect bounds(), or if subset is nullptr and bounds() is empty. | 
|  | 1864 |  | 
|  | 1865 | #Param color  Unpremultiplied Color to write ## | 
|  | 1866 | #Param subset  bounding integer Rect of pixels to write; may be nullptr ## | 
|  | 1867 |  | 
|  | 1868 | #Return  true if pixels are changed ## | 
|  | 1869 |  | 
|  | 1870 | #Example | 
| Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1871 | #Height 50 | 
| Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1872 | uint32_t storage[2]; | 
|  | 1873 | SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2); | 
|  | 1874 | SkPixmap pixmap(info, storage, info.minRowBytes()); | 
|  | 1875 | SkIRect topPixelBounds = {0, 0, 1, 1}; | 
|  | 1876 | pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds); | 
|  | 1877 | SkIRect bottomPixelBounds = {0, 1, 1, 2}; | 
|  | 1878 | pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds); | 
|  | 1879 | SkBitmap bitmap; | 
|  | 1880 | canvas->scale(20, 20); | 
|  | 1881 | bitmap.installPixels(pixmap); | 
|  | 1882 | canvas->drawBitmap(bitmap, 0, 0); | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1883 | ## | 
|  | 1884 |  | 
|  | 1885 | #SeeAlso SkBitmap::erase SkCanvas::clear SkCanvas::drawColor | 
|  | 1886 |  | 
|  | 1887 | ## | 
|  | 1888 |  | 
| Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1889 | #Class SkPixmap ## | 
|  | 1890 |  | 
|  | 1891 | #Topic Pixmap ## |