Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1 | #Topic Image |
| 2 | #Alias Image_Reference |
| 3 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4 | #Subtopic Overview |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5 | #Subtopic Subtopic |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 6 | #Populate |
| 7 | ## |
| 8 | ## |
| 9 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 10 | #Class SkImage |
| 11 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 12 | Image describes a two dimensional array of pixels to draw. The pixels may be |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 13 | decoded in a Raster_Bitmap, encoded in a Picture or compressed data stream, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 14 | or located in GPU memory as a GPU_Texture. |
| 15 | |
| 16 | Image cannot be modified after it is created. Image may allocate additional |
| 17 | storage as needed; for instance, an encoded Image may decode when drawn. |
| 18 | |
| 19 | Image width and height are greater than zero. Creating an Image with zero width |
| 20 | or height returns Image equal to nullptr. |
| 21 | |
| 22 | Image may be created from Bitmap, Pixmap, Surface, Picture, encoded streams, |
| 23 | GPU_Texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 24 | include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 25 | vary with platform. |
| 26 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 27 | #Subtopic Raster_Image |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 28 | #Alias Raster_Image |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 29 | #Line # pixels decoded in Raster_Bitmap ## |
| 30 | Raster_Image pixels are decoded in a Raster_Bitmap. These pixels may be read |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 31 | directly and in most cases written to, although edited pixels may not be drawn |
| 32 | if Image has been copied internally. |
| 33 | ## |
| 34 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 35 | #Subtopic Texture_Image |
| 36 | #Line # pixels located on GPU ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 37 | Texture_Image are located on GPU and pixels are not accessible. Texture_Image |
| 38 | are allocated optimally for best performance. Raster_Image may |
| 39 | be drawn to GPU_Surface, but pixels are uploaded from CPU to GPU downgrading |
| 40 | performance. |
| 41 | ## |
| 42 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 43 | #Subtopic Lazy_Image |
| 44 | #Line # deferred pixel buffer ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 45 | Lazy_Image defer allocating buffer for Image pixels and decoding stream until |
| 46 | Image is drawn. Lazy_Image caches result if possible to speed up repeated |
| 47 | drawing. |
| 48 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 49 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 50 | #Subtopic Related_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 51 | #Populate |
| 52 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 53 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 54 | #Subtopic Class_or_Struct |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 55 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 56 | ## |
| 57 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 58 | #Subtopic Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 59 | #Populate |
| 60 | ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 61 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 62 | #Subtopic Member_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 63 | #Populate |
| 64 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 65 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 66 | #Typedef SkImageInfo Info |
| 67 | |
| 68 | ## |
| 69 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 70 | # ------------------------------------------------------------------------------ |
| 71 | |
| 72 | #Method static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 73 | #In Constructor |
| 74 | #Line # creates Image from Pixmap and copied pixels ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 75 | Creates Image from Pixmap and copy of pixels. Since pixels are copied, Pixmap |
| 76 | pixels may be modified or deleted without affecting Image. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 77 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 78 | Image is returned if Pixmap is valid. Valid Pixmap parameters include: |
| 79 | dimensions are greater than zero; |
| 80 | each dimension fits in 29 bits; |
| 81 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 82 | row bytes are large enough to hold one row of pixels; |
| 83 | pixel address is not nullptr. |
| 84 | |
| 85 | #Param pixmap Image_Info, pixel address, and row bytes ## |
| 86 | |
| 87 | #Return copy of Pixmap pixels, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 88 | |
| 89 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 90 | #Height 50 |
| 91 | #Description |
| 92 | Draw a five by five bitmap, and draw a copy in an Image. Editing the pixmap |
| 93 | alters the bitmap draw, but does not alter the Image draw since the Image |
| 94 | contains a copy of the pixels. |
| 95 | ## |
| 96 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 97 | { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, |
| 98 | { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, |
| 99 | { 0x90, 0x81, 0xC5, 0x71, 0x33 }, |
| 100 | { 0x75, 0x55, 0x44, 0x40, 0x30 }}; |
| 101 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 102 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 103 | SkBitmap bitmap; |
| 104 | bitmap.installPixels(pixmap); |
| 105 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 106 | *pixmap.writable_addr8(2, 2) = 0x00; |
| 107 | canvas->scale(10, 10); |
| 108 | canvas->drawBitmap(bitmap, 0, 0); |
| 109 | canvas->drawImage(image, 10, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 110 | ## |
| 111 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 112 | #SeeAlso MakeRasterData MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 113 | |
| 114 | #Method ## |
| 115 | |
| 116 | # ------------------------------------------------------------------------------ |
| 117 | |
| 118 | #Method static sk_sp<SkImage> MakeRasterData(const Info& info, sk_sp<SkData> pixels, size_t rowBytes) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 119 | #In Constructor |
| 120 | #Line # creates Image from Image_Info and shared pixels ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 121 | Creates Image from Image_Info, sharing pixels. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 122 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 123 | Image is returned if Image_Info is valid. Valid Image_Info parameters include: |
| 124 | dimensions are greater than zero; |
| 125 | each dimension fits in 29 bits; |
| 126 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 127 | rowBytes are large enough to hold one row of pixels; |
| 128 | pixels is not nullptr, and contains enough data for Image. |
| 129 | |
| 130 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 131 | #Param pixels address or pixel storage ## |
| 132 | #Param rowBytes size of pixel row or larger ## |
| 133 | |
| 134 | #Return Image sharing pixels, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 135 | |
| 136 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 137 | #Image 3 |
| 138 | size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType); |
| 139 | sk_sp<SkData> data = SkData::MakeUninitialized(rowBytes * image->height()); |
| 140 | SkImageInfo dstInfo = SkImageInfo::MakeN32(image->width(), image->height(), |
| 141 | kPremul_SkAlphaType); |
| 142 | image->readPixels(dstInfo, data->writable_data(), rowBytes, 0, 0, SkImage::kAllow_CachingHint); |
| 143 | sk_sp<SkImage> raw = SkImage::MakeRasterData(dstInfo.makeColorType(kRGBA_8888_SkColorType), |
| 144 | data, rowBytes); |
| 145 | canvas->drawImage(image, 0, 0); |
| 146 | canvas->drawImage(raw.get(), 128, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 147 | ## |
| 148 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 149 | #SeeAlso MakeRasterCopy MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 150 | |
| 151 | #Method ## |
| 152 | |
| 153 | # ------------------------------------------------------------------------------ |
| 154 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 155 | #Typedef void* ReleaseContext |
| 156 | |
| 157 | Caller data passed to RasterReleaseProc; may be nullptr. |
| 158 | |
| 159 | #SeeAlso MakeFromRaster RasterReleaseProc |
| 160 | |
| 161 | ## |
| 162 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 163 | #Typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext) |
| 164 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 165 | Function called when Image no longer shares pixels. ReleaseContext is |
| 166 | provided by caller when Image is created, and may be nullptr. |
| 167 | |
| 168 | #SeeAlso ReleaseContext MakeFromRaster |
| 169 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 170 | ## |
| 171 | |
| 172 | #Method static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap, |
| 173 | RasterReleaseProc rasterReleaseProc, |
| 174 | ReleaseContext releaseContext) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 175 | #In Constructor |
| 176 | #Line # creates Image from Pixmap, with release ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 177 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 178 | Creates Image from pixmap, sharing Pixmap pixels. Pixels must remain valid and |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 179 | unchanged until rasterReleaseProc is called. rasterReleaseProc is passed |
| 180 | releaseContext when Image is deleted or no longer refers to pixmap pixels. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 181 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 182 | Pass nullptr for rasterReleaseProc to share Pixmap without requiring a callback |
| 183 | when Image is released. Pass nullptr for releaseContext if rasterReleaseProc |
| 184 | does not require state. |
| 185 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 186 | Image is returned if pixmap is valid. Valid Pixmap parameters include: |
| 187 | dimensions are greater than zero; |
| 188 | each dimension fits in 29 bits; |
| 189 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 190 | row bytes are large enough to hold one row of pixels; |
| 191 | pixel address is not nullptr. |
| 192 | |
| 193 | #Param pixmap Image_Info, pixel address, and row bytes ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 194 | #Param rasterReleaseProc function called when pixels can be released; or nullptr ## |
| 195 | #Param releaseContext state passed to rasterReleaseProc; or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 196 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 197 | #Return Image sharing pixmap ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 198 | |
| 199 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 200 | #Function |
| 201 | static void releaseProc(const void* pixels, SkImage::ReleaseContext context) { |
| 202 | int* countPtr = static_cast<int*>(context); |
| 203 | *countPtr += 1; |
| 204 | } |
| 205 | ## |
| 206 | |
| 207 | void draw(SkCanvas* canvas) { |
| 208 | SkColor color = 0; |
| 209 | SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), &color, 4); |
| 210 | int releaseCount = 0; |
| 211 | sk_sp<SkImage> image(SkImage::MakeFromRaster(pixmap, releaseProc, &releaseCount)); |
| 212 | SkDebugf("before reset: %d\n", releaseCount); |
| 213 | image.reset(); |
| 214 | SkDebugf("after reset: %d\n", releaseCount); |
| 215 | } |
| 216 | #StdOut |
| 217 | before reset: 0 |
| 218 | after reset: 1 |
| 219 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 220 | ## |
| 221 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 222 | #SeeAlso MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 223 | |
| 224 | #Method ## |
| 225 | |
| 226 | # ------------------------------------------------------------------------------ |
| 227 | |
| 228 | #Method static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 229 | #In Constructor |
| 230 | #Line # creates Image from Bitmap, sharing or copying pixels ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 231 | Creates Image from bitmap, sharing or copying bitmap pixels. If the bitmap |
| 232 | is marked immutable, and its pixel memory is shareable, it may be shared |
| 233 | instead of copied. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 234 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 235 | Image is returned if bitmap is valid. Valid Bitmap parameters include: |
| 236 | dimensions are greater than zero; |
| 237 | each dimension fits in 29 bits; |
| 238 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 239 | row bytes are large enough to hold one row of pixels; |
| 240 | pixel address is not nullptr. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 241 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 242 | #Param bitmap Image_Info, row bytes, and pixels ## |
| 243 | |
| 244 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 245 | |
| 246 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 247 | #Description |
| 248 | The first Bitmap is shared; writing to the pixel memory changes the first |
| 249 | Image. |
| 250 | The second Bitmap is marked immutable, and is copied; writing to the pixel |
| 251 | memory does not alter the second Image. |
| 252 | ## |
| 253 | #Height 50 |
| 254 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 255 | { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, |
| 256 | { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, |
| 257 | { 0x90, 0x81, 0xC5, 0x71, 0x33 }, |
| 258 | { 0x75, 0x55, 0x44, 0x40, 0x30 }}; |
| 259 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 260 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 261 | SkBitmap bitmap; |
| 262 | bitmap.installPixels(pixmap); |
| 263 | sk_sp<SkImage> image1 = SkImage::MakeFromBitmap(bitmap); |
| 264 | bitmap.setImmutable(); |
| 265 | sk_sp<SkImage> image2 = SkImage::MakeFromBitmap(bitmap); |
| 266 | *pixmap.writable_addr8(2, 2) = 0x00; |
| 267 | canvas->scale(10, 10); |
| 268 | canvas->drawImage(image1, 0, 0); |
| 269 | canvas->drawImage(image2, 10, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 270 | ## |
| 271 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 272 | #SeeAlso MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 273 | |
| 274 | #Method ## |
| 275 | |
| 276 | # ------------------------------------------------------------------------------ |
| 277 | |
| 278 | #Method static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator, |
| 279 | const SkIRect* subset = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 280 | #In Constructor |
| 281 | #Line # creates Image from a stream of data ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 282 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 283 | Creates Image from data returned by imageGenerator. Generated data is owned by Image and may not |
| 284 | be shared or accessed. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 285 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 286 | subset allows selecting a portion of the full image. Pass nullptr to select the entire image; |
| 287 | otherwise, subset must be contained by image bounds. |
| 288 | |
| 289 | Image is returned if generator data is valid. Valid data parameters vary by type of data |
| 290 | and platform. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 291 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 292 | imageGenerator may wrap Picture data, codec data, or custom data. |
| 293 | |
| 294 | #Param imageGenerator stock or custom routines to retrieve Image ## |
| 295 | #Param subset bounds of returned Image; may be nullptr ## |
| 296 | |
| 297 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 298 | |
| 299 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 300 | #Height 128 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 301 | #Description |
| 302 | The generator returning Picture cannot be shared; std::move transfers ownership to generated Image. |
| 303 | ## |
| 304 | SkPictureRecorder recorder; |
| 305 | recorder.beginRecording(100, 100)->drawColor(SK_ColorRED); |
| 306 | auto picture = recorder.finishRecordingAsPicture(); |
| 307 | auto gen = SkImageGenerator::MakeFromPicture({100, 100}, picture, nullptr, nullptr, |
| 308 | SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); |
| 309 | sk_sp<SkImage> image = SkImage::MakeFromGenerator(std::move(gen)); |
| 310 | canvas->drawImage(image, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 311 | ## |
| 312 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 313 | #SeeAlso MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 314 | |
| 315 | #Method ## |
| 316 | |
| 317 | # ------------------------------------------------------------------------------ |
| 318 | |
| 319 | #Method static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 320 | #In Constructor |
| 321 | #Line # creates Image from encoded data ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 322 | Creates Image from encoded data. |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 323 | subset allows selecting a portion of the full image. Pass nullptr to select the entire image; |
| 324 | otherwise, subset must be contained by image bounds. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 325 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 326 | Image is returned if format of the encoded data is recognized and supported. |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 327 | Recognized formats vary by platform. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 328 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 329 | #Param encoded data of Image to decode ## |
| 330 | #Param subset bounds of returned Image; may be nullptr ## |
| 331 | |
| 332 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 333 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 334 | #Example |
| 335 | #Image 3 |
| 336 | int x = 0; |
| 337 | for (int quality : { 100, 50, 10, 1} ) { |
| 338 | sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, quality); |
| 339 | sk_sp<SkImage> image = SkImage::MakeFromEncoded(encodedData); |
| 340 | canvas->drawImage(image, x, 0); |
| 341 | x += 64; |
| 342 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 343 | ## |
| 344 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 345 | #SeeAlso MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 346 | |
| 347 | #Method ## |
| 348 | |
| 349 | # ------------------------------------------------------------------------------ |
| 350 | |
| 351 | #Typedef void (*TextureReleaseProc)(ReleaseContext releaseContext) |
| 352 | |
| 353 | ## |
| 354 | |
| 355 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 356 | const GrBackendTexture& backendTexture, |
| 357 | GrSurfaceOrigin origin, |
| 358 | SkAlphaType alphaType, |
| 359 | sk_sp<SkColorSpace> colorSpace) |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 360 | #Deprecated |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 361 | #Method ## |
| 362 | |
| 363 | # ------------------------------------------------------------------------------ |
| 364 | |
| 365 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 366 | const GrBackendTexture& backendTexture, |
| 367 | GrSurfaceOrigin origin, |
| 368 | SkAlphaType alphaType, |
| 369 | sk_sp<SkColorSpace> colorSpace, |
| 370 | TextureReleaseProc textureReleaseProc, |
| 371 | ReleaseContext releaseContext) |
| 372 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 373 | #Deprecated |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 374 | #Method ## |
| 375 | |
| 376 | # ------------------------------------------------------------------------------ |
| 377 | |
| 378 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 379 | const GrBackendTexture& backendTexture, |
| 380 | GrSurfaceOrigin origin, |
| 381 | SkColorType colorType, |
| 382 | SkAlphaType alphaType, |
| 383 | sk_sp<SkColorSpace> colorSpace) |
| 384 | |
| 385 | Creates Image from GPU_Texture associated with context. Caller is responsible for |
| 386 | managing the lifetime of GPU_Texture. |
| 387 | |
| 388 | Image is returned if format of backendTexture is recognized and supported. |
| 389 | Recognized formats vary by GPU back-end. |
| 390 | |
| 391 | #Param context GPU_Context ## |
| 392 | #Param backendTexture texture residing on GPU ## |
| 393 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 394 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 395 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 396 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 397 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 398 | ## |
| 399 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 400 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 401 | ## |
| 402 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 403 | |
| 404 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 405 | |
| 406 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 407 | #Image 3 |
| 408 | #Platform gpu |
| 409 | #Height 128 |
| 410 | #Description |
| 411 | A back-end texture has been created and uploaded to the GPU outside of this example. |
| 412 | ## |
| 413 | GrContext* context = canvas->getGrContext(); |
| 414 | if (!context) { |
| 415 | return; |
| 416 | } |
| 417 | canvas->scale(.25f, .25f); |
| 418 | int x = 0; |
| 419 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 420 | sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backEndTexture, |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 421 | origin, kOpaque_SkAlphaType, nullptr); |
| 422 | canvas->drawImage(image, x, 0); |
| 423 | x += 512; |
| 424 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 425 | ## |
| 426 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 427 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 428 | |
| 429 | #Method ## |
| 430 | |
| 431 | # ------------------------------------------------------------------------------ |
| 432 | |
| 433 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 434 | const GrBackendTexture& backendTexture, |
| 435 | GrSurfaceOrigin origin, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 436 | SkColorType colorType, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 437 | SkAlphaType alphaType, |
| 438 | sk_sp<SkColorSpace> colorSpace, |
| 439 | TextureReleaseProc textureReleaseProc, |
| 440 | ReleaseContext releaseContext) |
| 441 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 442 | Creates Image from GPU_Texture associated with context. GPU_Texture must stay |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 443 | valid and unchanged until textureReleaseProc is called. textureReleaseProc is |
| 444 | passed releaseContext when Image is deleted or no longer refers to texture. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 445 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 446 | Image is returned if format of backendTexture is recognized and supported. |
| 447 | Recognized formats vary by GPU back-end. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 448 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 449 | #Param context GPU_Context ## |
| 450 | #Param backendTexture texture residing on GPU ## |
| 451 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 452 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 453 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 454 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 455 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 456 | ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 457 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 458 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 459 | ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 460 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 461 | #Param textureReleaseProc function called when texture can be released ## |
| 462 | #Param releaseContext state passed to textureReleaseProc ## |
| 463 | |
| 464 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 465 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 466 | #ToDo |
| 467 | This doesn't do anything clever with TextureReleaseProc because it may not get called |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 468 | fwithin the lifetime of the example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 469 | ## |
| 470 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 471 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 472 | #Platform gpu |
| 473 | #Image 4 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 474 | GrContext* context = canvas->getGrContext(); |
| 475 | if (!context) { |
| 476 | return; |
| 477 | } |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 478 | auto debugster = [](SkImage::ReleaseContext releaseContext) -> void { |
| 479 | *((int *) releaseContext) += 128; |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 480 | }; |
| 481 | int x = 0; |
| 482 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 483 | sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backEndTexture, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 484 | origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, debugster, &x); |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 485 | canvas->drawImage(image, x, 0); |
| 486 | x += 128; |
| 487 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 488 | ## |
| 489 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 490 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 491 | |
| 492 | #Method ## |
| 493 | |
| 494 | # ------------------------------------------------------------------------------ |
| 495 | |
| 496 | #Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data, |
| 497 | bool buildMips, |
| 498 | SkColorSpace* dstColorSpace) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 499 | #In Constructor |
| 500 | #Line # creates Image from encoded data, and uploads to GPU ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 501 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 502 | Creates Image from encoded data. Image is uploaded to GPU back-end using context. |
| 503 | |
| 504 | Created Image is available to other GPU contexts, and is available across thread |
| 505 | boundaries. All contexts must be in the same GPU_Share_Group, or otherwise |
| 506 | share resources. |
| 507 | |
| 508 | When Image is no longer referenced, context releases texture memory |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 509 | asynchronously. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 510 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 511 | Texture decoded from data is uploaded to match Surface created with |
| 512 | dstColorSpace. Color_Space of Image is determined by encoded data. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 513 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 514 | Image is returned if format of data is recognized and supported, and if context |
| 515 | supports moving resources. Recognized formats vary by platform and GPU back-end. |
| 516 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 517 | Image is returned using MakeFromEncoded if context is nullptr or does not support |
| 518 | moving resources between contexts. |
| 519 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 520 | #Param context GPU_Context ## |
| 521 | #Param data Image to decode ## |
| 522 | #Param buildMips create Image as Mip_Map if true ## |
| 523 | #Param dstColorSpace range of colors of matching Surface on GPU ## |
| 524 | |
| 525 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 526 | |
| 527 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 528 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 529 | #Height 64 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 530 | GrContext* context = canvas->getGrContext(); |
| 531 | sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, 100); |
| 532 | sk_sp<SkImage> image = SkImage::MakeCrossContextFromEncoded(context, |
| 533 | encodedData, false, nullptr); |
| 534 | canvas->drawImage(image, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 535 | ## |
| 536 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 537 | #SeeAlso MakeCrossContextFromPixmap |
| 538 | |
| 539 | #Method ## |
| 540 | |
| 541 | # ------------------------------------------------------------------------------ |
| 542 | |
| 543 | #Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap, |
| 544 | bool buildMips, |
| 545 | SkColorSpace* dstColorSpace) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 546 | #In Constructor |
| 547 | #Line # creates Image from Pixmap, and uploads to GPU ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 548 | |
| 549 | Creates Image from pixmap. Image is uploaded to GPU back-end using context. |
| 550 | |
| 551 | Created Image is available to other GPU contexts, and is available across thread |
| 552 | boundaries. All contexts must be in the same GPU_Share_Group, or otherwise |
| 553 | share resources. |
| 554 | |
| 555 | When Image is no longer referenced, context releases texture memory |
| 556 | asynchronously. |
| 557 | |
| 558 | Texture created from pixmap is uploaded to match Surface created with |
| 559 | dstColorSpace. Color_Space of Image is determined by pixmap.colorSpace(). |
| 560 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 561 | Image is returned referring to GPU back-end if context is not nullptr, |
| 562 | format of data is recognized and supported, and if context supports moving |
| 563 | resources between contexts. Otherwise, pixmap pixel data is copied and Image |
| 564 | as returned in raster format if possible; nullptr may be returned. |
| 565 | Recognized GPU formats vary by platform and GPU back-end. |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 566 | |
| 567 | #Param context GPU_Context ## |
| 568 | #Param pixmap Image_Info, pixel address, and row bytes ## |
| 569 | #Param buildMips create Image as Mip_Map if true ## |
| 570 | #Param dstColorSpace range of colors of matching Surface on GPU ## |
| 571 | |
| 572 | #Return created Image, or nullptr ## |
| 573 | |
| 574 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 575 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 576 | #Height 64 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 577 | GrContext* context = canvas->getGrContext(); |
| 578 | SkPixmap pixmap; |
| 579 | if (source.peekPixels(&pixmap)) { |
| 580 | sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(context, pixmap, |
| 581 | false, nullptr); |
| 582 | canvas->drawImage(image, 0, 0); |
| 583 | } |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 584 | ## |
| 585 | |
| 586 | #SeeAlso MakeCrossContextFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 587 | |
| 588 | #Method ## |
| 589 | |
| 590 | # ------------------------------------------------------------------------------ |
| 591 | |
| 592 | #Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context, |
| 593 | const GrBackendTexture& backendTexture, |
| 594 | GrSurfaceOrigin surfaceOrigin, |
| 595 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 596 | sk_sp<SkColorSpace> colorSpace = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 597 | #Deprecated |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 598 | #Method ## |
| 599 | |
| 600 | # ------------------------------------------------------------------------------ |
| 601 | |
| 602 | #Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context, |
| 603 | const GrBackendTexture& backendTexture, |
| 604 | GrSurfaceOrigin surfaceOrigin, |
| 605 | SkColorType colorType, |
| 606 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 607 | sk_sp<SkColorSpace> colorSpace = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 608 | #In Constructor |
| 609 | #Line # creates Image from GPU_Texture, managed internally ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 610 | Creates Image from backendTexture associated with context. backendTexture and |
| 611 | returned Image are managed internally, and are released when no longer needed. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 612 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 613 | Image is returned if format of backendTexture is recognized and supported. |
| 614 | Recognized formats vary by GPU back-end. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 615 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 616 | #Param context GPU_Context ## |
| 617 | #Param backendTexture texture residing on GPU ## |
| 618 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 619 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 620 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 621 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 622 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 623 | ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 624 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 625 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 626 | ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 627 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 628 | |
| 629 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 630 | |
| 631 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 632 | #Image 5 |
| 633 | #Platform gpu |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 634 | if (!canvas->getGrContext()) { |
| 635 | return; |
| 636 | } |
| 637 | canvas->scale(.5f, .5f); |
| 638 | canvas->clear(0x7f3f5f7f); |
| 639 | int x = 0, y = 0; |
| 640 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 641 | for (auto alpha : { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
| 642 | sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(canvas->getGrContext(), |
| 643 | backEndTexture, origin, |
| 644 | kRGBA_8888_SkColorType, alpha); |
| 645 | canvas->drawImage(image, x, y); |
| 646 | x += 160; |
| 647 | } |
| 648 | x -= 160 * 3; |
| 649 | y += 256; |
| 650 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 651 | ## |
| 652 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 653 | #SeeAlso MakeFromTexture MakeFromYUVTexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 654 | |
| 655 | #Method ## |
| 656 | |
| 657 | # ------------------------------------------------------------------------------ |
| 658 | |
| 659 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, |
| 660 | const GrBackendObject yuvTextureHandles[3], |
| 661 | const SkISize yuvSizes[3], |
| 662 | GrSurfaceOrigin surfaceOrigin, |
| 663 | sk_sp<SkColorSpace> colorSpace = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 664 | #In Constructor |
| 665 | #Line # creates Image from YUV_ColorSpace data in three planes ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 666 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 667 | Creates Image from copy of yuvTextureHandles, an array of textures on GPU. |
| 668 | yuvTextureHandles contain pixels for YUV planes of Image. |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 669 | yuvSizes contain dimensions for each pixel plane. Dimensions must be greater than |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 670 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 671 | yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 672 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 673 | #Param context GPU_Context ## |
| 674 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 675 | kRec709_SkYUVColorSpace |
| 676 | ## |
| 677 | #Param yuvTextureHandles array of YUV textures on GPU ## |
| 678 | #Param yuvSizes dimensions of YUV textures ## |
| 679 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 680 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 681 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 682 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 683 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 684 | # seems too complicated to create an example for this |
| 685 | #ToDo |
| 686 | should this be moved to chrome only? |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 687 | ## |
| 688 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 689 | #NoExample |
| 690 | ## |
| 691 | |
| 692 | #SeeAlso MakeFromNV12TexturesCopy |
| 693 | |
| 694 | #Method ## |
| 695 | |
| 696 | # ------------------------------------------------------------------------------ |
| 697 | |
| 698 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, |
| 699 | const GrBackendTexture yuvTextureHandles[3], |
| 700 | const SkISize yuvSizes[3], |
| 701 | GrSurfaceOrigin surfaceOrigin, |
| 702 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 703 | |
| 704 | Creates Image from copy of yuvTextureHandles, an array of textures on GPU. |
| 705 | yuvTextureHandles contain pixels for YUV planes of Image. |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 706 | yuvSizes contain dimensions for each pixel plane. Dimensions must be greater than |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 707 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 708 | yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
| 709 | |
| 710 | #Param context GPU_Context ## |
| 711 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 712 | kRec709_SkYUVColorSpace |
| 713 | ## |
| 714 | #Param yuvTextureHandles array of YUV textures on GPU ## |
| 715 | #Param yuvSizes dimensions of YUV textures ## |
| 716 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 717 | #Param colorSpace range of colors; may be nullptr ## |
| 718 | |
| 719 | #Return created Image, or nullptr ## |
| 720 | |
| 721 | # seems too complicated to create an example for this |
| 722 | #ToDo |
| 723 | should this be moved to chrome only? |
| 724 | ## |
| 725 | |
| 726 | #NoExample |
| 727 | ## |
| 728 | |
| 729 | #SeeAlso MakeFromNV12TexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 730 | |
| 731 | #Method ## |
| 732 | |
| 733 | # ------------------------------------------------------------------------------ |
| 734 | |
| 735 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, |
| 736 | SkYUVColorSpace yuvColorSpace, |
| 737 | const GrBackendObject nv12TextureHandles[2], |
| 738 | const SkISize nv12Sizes[2], |
| 739 | GrSurfaceOrigin surfaceOrigin, |
| 740 | sk_sp<SkColorSpace> colorSpace = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 741 | #In Constructor |
| 742 | #Line # creates Image from YUV_ColorSpace data in two planes ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 743 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 744 | Creates Image from copy of nv12TextureHandles, an array of textures on GPU. |
| 745 | nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. |
| 746 | nv12TextureHandles[1] contains pixels for YUV_Component_U plane, |
| 747 | followed by pixels for YUV_Component_V plane. |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 748 | nv12Sizes contain dimensions for each pixel plane. Dimensions must be greater than |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 749 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 750 | nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 751 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 752 | #Param context GPU_Context ## |
| 753 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 754 | kRec709_SkYUVColorSpace |
| 755 | ## |
| 756 | #Param nv12TextureHandles array of YUV textures on GPU ## |
| 757 | #Param nv12Sizes dimensions of YUV textures ## |
| 758 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 759 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 760 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 761 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 762 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 763 | # seems too complicated to create an example for this |
| 764 | #ToDo |
| 765 | should this be moved to chrome only? |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 766 | ## |
| 767 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 768 | #NoExample |
| 769 | ## |
| 770 | |
| 771 | #SeeAlso MakeFromYUVTexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 772 | |
| 773 | #Method ## |
| 774 | |
| 775 | # ------------------------------------------------------------------------------ |
| 776 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 777 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, |
| 778 | SkYUVColorSpace yuvColorSpace, |
| 779 | const GrBackendTexture nv12TextureHandles[2], |
| 780 | const SkISize nv12Sizes[2], |
| 781 | GrSurfaceOrigin surfaceOrigin, |
| 782 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 783 | |
| 784 | Creates Image from copy of nv12TextureHandles, an array of textures on GPU. |
| 785 | nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. |
| 786 | nv12TextureHandles[1] contains pixels for YUV_Component_U plane, |
| 787 | followed by pixels for YUV_Component_V plane. |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 788 | nv12Sizes contain dimensions for each pixel plane. Dimensions must be greater than |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 789 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 790 | nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
| 791 | |
| 792 | #Param context GPU_Context ## |
| 793 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 794 | kRec709_SkYUVColorSpace |
| 795 | ## |
| 796 | #Param nv12TextureHandles array of YUV textures on GPU ## |
| 797 | #Param nv12Sizes dimensions of YUV textures ## |
| 798 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 799 | #Param colorSpace range of colors; may be nullptr ## |
| 800 | |
| 801 | #Return created Image, or nullptr ## |
| 802 | |
| 803 | # seems too complicated to create an example for this |
| 804 | #ToDo |
| 805 | should this be moved to chrome only? |
| 806 | ## |
| 807 | |
| 808 | #NoExample |
| 809 | ## |
| 810 | |
| 811 | #SeeAlso MakeFromYUVTexturesCopy |
| 812 | |
| 813 | #Method ## |
| 814 | |
| 815 | # ------------------------------------------------------------------------------ |
| 816 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 817 | # currently uncalled by any test or client ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 818 | #Bug 7424 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 819 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 820 | #Enum BitDepth |
| 821 | |
| 822 | #Code |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 823 | enum class BitDepth { |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 824 | kU8, |
| 825 | kF16, |
| 826 | }; |
| 827 | ## |
| 828 | |
| 829 | #Const kU8 0 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 830 | Use 8 bits per Color_ARGB component using unsigned integer format. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 831 | ## |
| 832 | #Const kF16 1 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 833 | Use 16 bits per Color_ARGB component using half-precision floating point format. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 834 | ## |
| 835 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 836 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 837 | ## |
| 838 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 839 | #SeeAlso MakeFromPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 840 | |
| 841 | #Enum ## |
| 842 | |
| 843 | # ------------------------------------------------------------------------------ |
| 844 | |
| 845 | #Method static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions, |
| 846 | const SkMatrix* matrix, const SkPaint* paint, |
| 847 | BitDepth bitDepth, |
| 848 | sk_sp<SkColorSpace> colorSpace) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 849 | #In Constructor |
| 850 | #Line # creates Image from Picture ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 851 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 852 | Creates Image from picture. Returned Image width and height are set by dimensions. |
| 853 | Image draws picture with matrix and paint, set to bitDepth and colorSpace. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 854 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 855 | If matrix is nullptr, draws with identity Matrix. If paint is nullptr, draws |
| 856 | with default Paint. colorSpace may be nullptr. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 857 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 858 | #Param picture stream of drawing commands ## |
| 859 | #Param dimensions width and height ## |
| 860 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 861 | #Param paint Paint to apply transparency, filtering, and so on; may be nullptr ## |
| 862 | #Param bitDepth 8 bit integer or 16 bit float: per component ## |
| 863 | #Param colorSpace range of colors; may be nullptr ## |
| 864 | |
| 865 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 866 | |
| 867 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 868 | SkPaint paint; |
| 869 | SkPictureRecorder recorder; |
| 870 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 871 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 872 | paint.setColor(color); |
| 873 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 874 | recordingCanvas->translate(10, 10); |
| 875 | recordingCanvas->scale(1.2f, 1.4f); |
| 876 | } |
| 877 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 878 | int x = 0, y = 0; |
| 879 | for (auto alpha : { 70, 140, 210 } ) { |
| 880 | paint.setAlpha(alpha); |
| 881 | auto srgbColorSpace = SkColorSpace::MakeSRGB(); |
| 882 | sk_sp<SkImage> image = SkImage::MakeFromPicture(playback, {50, 50}, nullptr, &paint, |
| 883 | SkImage::BitDepth::kU8, srgbColorSpace); |
| 884 | canvas->drawImage(image, x, y); |
| 885 | x += 70; y += 70; |
| 886 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 887 | ## |
| 888 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 889 | #SeeAlso SkCanvas::drawPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 890 | |
| 891 | #Method ## |
| 892 | |
| 893 | # ------------------------------------------------------------------------------ |
| 894 | |
| 895 | #Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer, |
| 896 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 897 | sk_sp<SkColorSpace> colorSpace = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 898 | #In Constructor |
| 899 | #Line # creates Image from Android hardware buffer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 900 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 901 | #Bug 7447 |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 902 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 903 | Creates Image from Android hardware buffer. |
| 904 | Returned Image takes a reference on the buffer. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 905 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 906 | Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 907 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 908 | #Param hardwareBuffer AHardwareBuffer Android hardware buffer ## |
| 909 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 910 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 911 | ## |
| 912 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 913 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 914 | #Return created Image, or nullptr ## |
| 915 | |
| 916 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 917 | ## |
| 918 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 919 | #SeeAlso MakeFromRaster |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 920 | |
| 921 | #Method ## |
| 922 | |
| 923 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 924 | #Subtopic Property |
| 925 | #Populate |
| 926 | #Line # values and attributes ## |
| 927 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 928 | |
| 929 | #Method int width() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 930 | #In Property |
| 931 | #Line # returns pixel column count ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 932 | Returns pixel count in each row. |
| 933 | |
| 934 | #Return pixel width in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 935 | |
| 936 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 937 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 938 | #Height 96 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 939 | canvas->translate(10, 10); |
| 940 | canvas->drawImage(image, 0, 0); |
| 941 | canvas->translate(0, image->height()); |
| 942 | SkPaint paint; |
| 943 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 944 | canvas->drawLine(0, 10, image->width(), 10, paint); |
| 945 | canvas->drawString("width", image->width() / 2, 25, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 946 | ## |
| 947 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 948 | #SeeAlso dimensions() height() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 949 | |
| 950 | #Method ## |
| 951 | |
| 952 | # ------------------------------------------------------------------------------ |
| 953 | |
| 954 | #Method int height() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 955 | #In Property |
| 956 | #Line # returns pixel row count ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 957 | Returns pixel row count. |
| 958 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 959 | #Return pixel height in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 960 | |
| 961 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 962 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 963 | #Height 96 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 964 | canvas->translate(10, 10); |
| 965 | canvas->drawImage(image, 0, 0); |
| 966 | canvas->translate(image->width(), 0); |
| 967 | SkPaint paint; |
| 968 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 969 | paint.setVerticalText(true); |
| 970 | canvas->drawLine(10, 0, 10, image->height(), paint); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 971 | canvas->drawString("height", 25, image->height() / 2, paint); |
| 972 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 973 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 974 | #SeeAlso dimensions() width() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 975 | |
| 976 | #Method ## |
| 977 | |
| 978 | # ------------------------------------------------------------------------------ |
| 979 | |
| 980 | #Method SkISize dimensions() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 981 | #In Property |
| 982 | #Line # returns width() and height() ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 983 | Returns ISize { width(), height() }. |
| 984 | |
| 985 | #Return integral size of width() and height() ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 986 | |
| 987 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 988 | #Image 4 |
| 989 | SkISize dimensions = image->dimensions(); |
| 990 | SkIRect bounds = image->bounds(); |
| 991 | SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions); |
| 992 | SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 993 | ## |
| 994 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 995 | #SeeAlso height() width() bounds() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 996 | |
| 997 | #Method ## |
| 998 | |
| 999 | # ------------------------------------------------------------------------------ |
| 1000 | |
| 1001 | #Method SkIRect bounds() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1002 | #In Property |
| 1003 | #Line # returns width() and height() as Rectangle ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1004 | Returns IRect { 0, 0, width(), height() }. |
| 1005 | |
| 1006 | #Return integral rectangle from origin to width() and height() ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1007 | |
| 1008 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1009 | #Height 128 |
| 1010 | #Image 4 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1011 | SkIRect bounds = image->bounds(); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1012 | for (int x : { 0, bounds.width() } ) { |
| 1013 | for (int y : { 0, bounds.height() } ) { |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1014 | canvas->drawImage(image, x, y); |
| 1015 | } |
| 1016 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1017 | ## |
| 1018 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1019 | #SeeAlso dimensions() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1020 | |
| 1021 | #Method ## |
| 1022 | |
| 1023 | # ------------------------------------------------------------------------------ |
| 1024 | |
| 1025 | #Method uint32_t uniqueID() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1026 | #In Property |
| 1027 | #Line # identifier for Image ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1028 | Returns value unique to image. Image contents cannot change after Image is |
| 1029 | created. Any operation to create a new Image will receive generate a new |
| 1030 | unique number. |
| 1031 | |
| 1032 | #Return unique identifier ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1033 | |
| 1034 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1035 | #Image 5 |
| 1036 | #Height 156 |
| 1037 | sk_sp<SkImage> subset = image->makeSubset({10, 20, 90, 100}); |
| 1038 | canvas->drawImage(image, 0, 0); |
| 1039 | canvas->drawImage(subset, 128, 0); |
| 1040 | SkPaint paint; |
| 1041 | SkString s; |
| 1042 | s.printf("original id: %d", image->uniqueID()); |
| 1043 | canvas->drawString(s, 20, image->height() + 20, paint); |
| 1044 | s.printf("subset id: %d", subset->uniqueID()); |
| 1045 | canvas->drawString(s, 148, subset->height() + 20, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1046 | ## |
| 1047 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1048 | #SeeAlso isLazyGenerated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1049 | |
| 1050 | #Method ## |
| 1051 | |
| 1052 | # ------------------------------------------------------------------------------ |
| 1053 | |
| 1054 | #Method SkAlphaType alphaType() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1055 | #In Property |
| 1056 | #Line # returns Alpha_Type ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1057 | Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 1058 | kPremul_SkAlphaType, kUnpremul_SkAlphaType. |
| 1059 | |
| 1060 | Alpha_Type returned was a parameter to an Image constructor, |
| 1061 | or was parsed from encoded data. |
| 1062 | |
| 1063 | #Return Alpha_Type in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1064 | |
| 1065 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1066 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1067 | #Height 96 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1068 | const char* alphaTypeStr[] = { "Unknown", "Opaque", "Premul", "Unpremul" }; |
| 1069 | SkAlphaType alphaType = image->alphaType(); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1070 | canvas->drawImage(image, 16, 0); |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1071 | SkPaint paint; |
| 1072 | canvas->drawString(alphaTypeStr[(int) alphaType], 20, image->height() + 20, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1073 | ## |
| 1074 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1075 | #SeeAlso SkImageInfo::alphaType |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1076 | |
| 1077 | #Method ## |
| 1078 | |
| 1079 | # ------------------------------------------------------------------------------ |
| 1080 | |
| 1081 | #Method SkColorSpace* colorSpace() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1082 | #In Property |
| 1083 | #Line # returns Color_Space ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1084 | Returns Color_Space, the range of colors, associated with Image. The |
| 1085 | reference count of Color_Space is unchanged. The returned Color_Space is |
| 1086 | immutable. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1087 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1088 | Color_Space returned was passed to an Image constructor, |
| 1089 | or was parsed from encoded data. Color_Space returned may be ignored when Image |
| 1090 | is drawn, depending on the capabilities of the Surface receiving the drawing. |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1091 | |
| 1092 | #Return Color_Space in Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1093 | |
| 1094 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1095 | #Image 3 |
| 1096 | #Set sRGB |
| 1097 | SkPixmap pixmap; |
| 1098 | source.peekPixels(&pixmap); |
| 1099 | canvas->scale(.25f, .25f); |
| 1100 | int y = 0; |
| 1101 | for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, |
| 1102 | SkColorSpace::kSRGB_RenderTargetGamma } ) { |
| 1103 | int x = 0; |
| 1104 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); |
| 1105 | for (int index = 0; index < 2; ++index) { |
| 1106 | pixmap.setColorSpace(colorSpace); |
| 1107 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 1108 | canvas->drawImage(image, x, y); |
| 1109 | colorSpace = image->colorSpace()->makeColorSpin(); |
| 1110 | x += 512; |
| 1111 | } |
| 1112 | y += 512; |
| 1113 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1114 | ## |
| 1115 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1116 | #SeeAlso refColorSpace makeColorSpace |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1117 | |
| 1118 | #Method ## |
| 1119 | |
| 1120 | # ------------------------------------------------------------------------------ |
| 1121 | |
| 1122 | #Method sk_sp<SkColorSpace> refColorSpace() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1123 | #In Property |
| 1124 | #Line # returns Image_Info Color_Space ## |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1125 | Returns a smart pointer to Color_Space, the range of colors, associated with |
| 1126 | Image. The smart pointer tracks the number of objects sharing this |
| 1127 | SkColorSpace reference so the memory is released when the owners destruct. |
| 1128 | |
| 1129 | The returned SkColorSpace is immutable. |
| 1130 | |
| 1131 | Color_Space returned was passed to an Image constructor, |
| 1132 | or was parsed from encoded data. Color_Space returned may be ignored when Image |
| 1133 | is drawn, depending on the capabilities of the Surface receiving the drawing. |
| 1134 | |
| 1135 | #Return Color_Space in Image, or nullptr, wrapped in a smart pointer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1136 | |
| 1137 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1138 | #Image 3 |
| 1139 | #Set sRGB |
| 1140 | SkPixmap pixmap; |
| 1141 | source.peekPixels(&pixmap); |
| 1142 | canvas->scale(.25f, .25f); |
| 1143 | int y = 0; |
| 1144 | for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, |
| 1145 | SkColorSpace::kSRGB_RenderTargetGamma } ) { |
| 1146 | int x = 0; |
| 1147 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); |
| 1148 | for (int index = 0; index < 2; ++index) { |
| 1149 | pixmap.setColorSpace(colorSpace); |
| 1150 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 1151 | canvas->drawImage(image, x, y); |
| 1152 | colorSpace = image->refColorSpace()->makeColorSpin(); |
| 1153 | x += 512; |
| 1154 | } |
| 1155 | y += 512; |
| 1156 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1157 | ## |
| 1158 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1159 | #SeeAlso colorSpace makeColorSpace |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1160 | |
| 1161 | #Method ## |
| 1162 | |
| 1163 | # ------------------------------------------------------------------------------ |
| 1164 | |
| 1165 | #Method bool isAlphaOnly() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1166 | #In Property |
| 1167 | #Line # returns if pixels represent a transparency mask ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1168 | Returns true if Image pixels represent transparency only. If true, each pixel |
| 1169 | is packed in 8 bits as defined by kAlpha_8_SkColorType. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1170 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1171 | #Return true if pixels represent a transparency mask ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1172 | |
| 1173 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1174 | uint8_t pmColors = 0; |
| 1175 | sk_sp<SkImage> image = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1), &pmColors, 1}); |
| 1176 | SkDebugf("alphaOnly = %s\n", image->isAlphaOnly() ? "true" : "false"); |
| 1177 | #StdOut |
| 1178 | alphaOnly = true |
| 1179 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1180 | ## |
| 1181 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1182 | #SeeAlso alphaType isOpaque |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1183 | |
| 1184 | #Method ## |
| 1185 | |
| 1186 | # ------------------------------------------------------------------------------ |
| 1187 | |
| 1188 | #Method bool isOpaque() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1189 | #In Property |
| 1190 | #Line # returns if Alpha_Type is kOpaque_SkAlphaType ## |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1191 | Returns true if pixels ignore their Alpha value and are treated as fully opaque. |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1192 | |
| 1193 | #Return true if Alpha_Type is kOpaque_SkAlphaType ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1194 | |
| 1195 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1196 | auto check_isopaque = [](const SkImageInfo& imageInfo) -> void { |
| 1197 | auto surface(SkSurface::MakeRaster(imageInfo)); |
| 1198 | auto image(surface->makeImageSnapshot()); |
| 1199 | SkDebugf("isOpaque = %s\n", image->isOpaque() ? "true" : "false"); |
| 1200 | }; |
| 1201 | |
| 1202 | check_isopaque(SkImageInfo::MakeN32Premul(5, 5)); |
| 1203 | check_isopaque(SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType)); |
| 1204 | #StdOut |
| 1205 | isOpaque = false |
| 1206 | isOpaque = true |
| 1207 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1208 | ## |
| 1209 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1210 | #SeeAlso alphaType isAlphaOnly |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1211 | |
| 1212 | #Method ## |
| 1213 | |
| 1214 | # ------------------------------------------------------------------------------ |
| 1215 | |
| 1216 | #Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2, |
| 1217 | const SkMatrix* localMatrix = nullptr) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1218 | #In Constructor |
| 1219 | #Line # creates Shader, Paint element that can tile Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1220 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1221 | Creates Shader from Image. Shader dimensions are taken from Image. Shader uses |
| 1222 | SkShader::TileMode rules to fill drawn area outside Image. localMatrix permits |
| 1223 | transforming Image before Canvas_Matrix is applied. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1224 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1225 | #Param tileMode1 tiling in x, one of: SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, |
| 1226 | SkShader::kMirror_TileMode |
| 1227 | ## |
| 1228 | #Param tileMode2 tiling in y, one of: SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, |
| 1229 | SkShader::kMirror_TileMode |
| 1230 | ## |
| 1231 | #Param localMatrix Image transformation, or nullptr ## |
| 1232 | |
| 1233 | #Return Shader containing Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1234 | |
| 1235 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1236 | #Image 4 |
| 1237 | SkMatrix matrix; |
| 1238 | matrix.setRotate(45); |
| 1239 | SkPaint paint; |
| 1240 | paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode, |
| 1241 | &matrix)); |
| 1242 | canvas->drawPaint(paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1243 | ## |
| 1244 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1245 | #SeeAlso scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1246 | |
| 1247 | #Method ## |
| 1248 | |
| 1249 | # ------------------------------------------------------------------------------ |
| 1250 | |
| 1251 | #Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const |
| 1252 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1253 | Creates Shader from Image. Shader dimensions are taken from Image. Shader uses |
| 1254 | SkShader::kClamp_TileMode to fill drawn area outside Image. localMatrix permits |
| 1255 | transforming Image before Canvas_Matrix is applied. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1256 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1257 | #Param localMatrix Image transformation, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1258 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1259 | #Return Shader containing Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1260 | |
| 1261 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 1262 | #Image 5 |
| 1263 | SkMatrix matrix; |
| 1264 | matrix.setRotate(45); |
| 1265 | matrix.postTranslate(125, 30); |
| 1266 | SkPaint paint; |
| 1267 | paint.setShader(image->makeShader(&matrix)); |
| 1268 | canvas->drawPaint(paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1269 | ## |
| 1270 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1271 | #SeeAlso scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1272 | |
| 1273 | #Method ## |
| 1274 | |
| 1275 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame^] | 1276 | #Subtopic Pixels |
| 1277 | #Populate |
| 1278 | #Line # read and write pixel values ## |
| 1279 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1280 | |
| 1281 | #Method bool peekPixels(SkPixmap* pixmap) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame^] | 1282 | #In Pixels |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1283 | #Line # returns Pixmap if possible ## |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1284 | Copies Image pixel address, row bytes, and Image_Info to pixmap, if address |
| 1285 | is available, and returns true. If pixel address is not available, return |
| 1286 | false and leave pixmap unchanged. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1287 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1288 | #Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1289 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1290 | #Return true if Image has direct access to pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1291 | |
| 1292 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1293 | SkBitmap bitmap; |
| 1294 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(12, 11)); |
| 1295 | SkCanvas offscreen(bitmap); |
| 1296 | offscreen.clear(SK_ColorWHITE); |
| 1297 | SkPaint paint; |
| 1298 | offscreen.drawString("%", 1, 10, paint); |
| 1299 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 1300 | SkPixmap pixmap; |
| 1301 | if (image->peekPixels(&pixmap)) { |
| 1302 | const SkPMColor* pixels = pixmap.addr32(); |
| 1303 | SkPMColor pmWhite = pixels[0]; |
| 1304 | for (int y = 0; y < image->height(); ++y) { |
| 1305 | for (int x = 0; x < image->width(); ++x) { |
| 1306 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 1307 | } |
| 1308 | SkDebugf("\n"); |
| 1309 | } |
| 1310 | } |
| 1311 | #StdOut |
| 1312 | ------------ |
| 1313 | --xx----x--- |
| 1314 | -x--x--x---- |
| 1315 | -x--x--x---- |
| 1316 | -x--x-x----- |
| 1317 | --xx-xx-xx-- |
| 1318 | -----x-x--x- |
| 1319 | ----x--x--x- |
| 1320 | ----x--x--x- |
| 1321 | ---x----xx-- |
| 1322 | ------------ |
| 1323 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1324 | ## |
| 1325 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1326 | #SeeAlso readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1327 | |
| 1328 | #Method ## |
| 1329 | |
| 1330 | # ------------------------------------------------------------------------------ |
| 1331 | |
| 1332 | #Method GrTexture* getTexture() const |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1333 | #Deprecated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1334 | #Method ## |
| 1335 | |
| 1336 | # ------------------------------------------------------------------------------ |
| 1337 | |
| 1338 | #Method bool isTextureBacked() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame^] | 1339 | #In Property |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1340 | #Line # returns if Image was created from GPU_Texture ## |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1341 | Returns true the contents of Image was created on or uploaded to GPU memory, |
| 1342 | and is available as a GPU_Texture. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1343 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1344 | #Return true if Image is a GPU_Texture ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1345 | |
| 1346 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1347 | #Image 5 |
| 1348 | #Platform gpu |
| 1349 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1350 | if (nullptr == image) { |
| 1351 | return; |
| 1352 | } |
| 1353 | SkPaint paint; |
| 1354 | paint.setAntiAlias(true); |
| 1355 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1356 | canvas->drawImage(image, 0, 0); |
| 1357 | canvas->drawString(label, image->width() / 2, image->height() / 4, paint); |
| 1358 | canvas->drawString(image->isTextureBacked() ? "is GPU texture" : "not GPU texture", |
| 1359 | image->width() / 2, image->height() * 3 / 4, paint); |
| 1360 | }; |
| 1361 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1362 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 1363 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 1364 | drawImage(image, "image"); |
| 1365 | canvas->translate(image->width(), 0); |
| 1366 | drawImage(bitmapImage, "source"); |
| 1367 | canvas->translate(-image->width(), image->height()); |
| 1368 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1369 | ## |
| 1370 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1371 | #SeeAlso MakeFromTexture isValid |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1372 | |
| 1373 | #Method ## |
| 1374 | |
| 1375 | # ------------------------------------------------------------------------------ |
| 1376 | |
| 1377 | #Method bool isValid(GrContext* context) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1378 | #In Property |
| 1379 | #Line # returns if Image can draw to Raster_Surface or GPU_Context ## |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1380 | Returns true if Image can be drawn on either Raster_Surface or GPU_Surface. |
| 1381 | If context is nullptr, tests if Image draws on Raster_Surface; |
| 1382 | otherwise, tests if Image draws on GPU_Surface associated with context. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1383 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1384 | Image backed by GPU_Texture may become invalid if associated GrContext is |
| 1385 | invalid. Lazy_Image may be invalid and may not draw to Raster_Surface or |
| 1386 | GPU_Surface or both. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1387 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1388 | #Param context GPU_Context ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1389 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1390 | #Return true if Image can be drawn ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1391 | |
| 1392 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1393 | #Image 5 |
| 1394 | #Platform gpu |
| 1395 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1396 | if (nullptr == image) { |
| 1397 | return; |
| 1398 | } |
| 1399 | SkPaint paint; |
| 1400 | paint.setAntiAlias(true); |
| 1401 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1402 | canvas->drawImage(image, 0, 0); |
| 1403 | canvas->drawString(label, image->width() / 2, image->height() / 4, paint); |
| 1404 | if (canvas->getGrContext()) { |
| 1405 | canvas->drawString(image->isValid(canvas->getGrContext()) ? "is valid on GPU" : |
| 1406 | "not valid on GPU", image->width() / 2, image->height() * 5 / 8, paint); |
| 1407 | } |
| 1408 | canvas->drawString(image->isValid(nullptr) ? "is valid on CPU" : |
| 1409 | "not valid on CPU", image->width() / 2, image->height() * 7 / 8, paint); |
| 1410 | }; |
| 1411 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1412 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 1413 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 1414 | drawImage(image, "image"); |
| 1415 | canvas->translate(image->width(), 0); |
| 1416 | drawImage(bitmapImage, "source"); |
| 1417 | canvas->translate(-image->width(), image->height()); |
| 1418 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1419 | ## |
| 1420 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1421 | #SeeAlso isTextureBacked isLazyGenerated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1422 | |
| 1423 | #Method ## |
| 1424 | |
| 1425 | # ------------------------------------------------------------------------------ |
| 1426 | |
| 1427 | #Method GrBackendObject getTextureHandle(bool flushPendingGrContextIO, |
| 1428 | GrSurfaceOrigin* origin = nullptr) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame^] | 1429 | #In Property |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1430 | #Line # returns GPU reference to Image as texture ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1431 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1432 | Retrieves the back-end API handle of texture. If flushPendingGrContextIO is true, |
| 1433 | complete deferred I/O operations. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1434 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1435 | If origin in not nullptr, copies location of content drawn into Image. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1436 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1437 | #Param flushPendingGrContextIO flag to flush outstanding requests ## |
| 1438 | #Param origin storage for one of: kTopLeft_GrSurfaceOrigin, |
| 1439 | kBottomLeft_GrSurfaceOrigin; or nullptr |
| 1440 | ## |
| 1441 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1442 | #Return back-end API texture handle, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1443 | |
| 1444 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1445 | #Image 4 |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1446 | #Platform gpu |
| 1447 | GrContext* context = canvas->getGrContext(); |
| 1448 | if (!context) { |
| 1449 | return; |
| 1450 | } |
| 1451 | SkPaint paint; |
| 1452 | paint.setAntiAlias(true); |
| 1453 | SkString str; |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1454 | int y = -10; |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1455 | for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) { |
| 1456 | sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context, |
| 1457 | backEndTexture, origin, kPremul_SkAlphaType, nullptr)); |
| 1458 | GrSurfaceOrigin readBackOrigin; |
| 1459 | GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1460 | str.printf("readBackHandle: 0x%x", readBackHandle); |
| 1461 | canvas->drawString(str, 5, y += 30, paint); |
| 1462 | canvas->drawImage(srcImage, 80, y += 10); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1463 | str.printf("origin: k%s_GrSurfaceOrigin", readBackOrigin ? "BottomLeft" : "TopLeft"); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1464 | canvas->drawString(str, 5, y += srcImage->height() + 10, paint); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1465 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1466 | ## |
| 1467 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1468 | #Example |
| 1469 | #Image 5 |
| 1470 | #Platform gpu |
| 1471 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1472 | if (nullptr == image) { |
| 1473 | return; |
| 1474 | } |
| 1475 | SkPaint paint; |
| 1476 | paint.setAntiAlias(true); |
| 1477 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1478 | canvas->drawImage(image, 0, image->height() / 4); |
| 1479 | canvas->drawString(label, image->width() / 2, image->height() / 8, paint); |
| 1480 | GrSurfaceOrigin readBackOrigin; |
| 1481 | GrBackendObject readBackHandle = image->getTextureHandle(false, &readBackOrigin); |
| 1482 | canvas->drawString(readBackHandle ? "has readBackHandle" : "no readBackHandle", |
| 1483 | image->width() / 2, image->height() * 11 / 8, paint); |
| 1484 | }; |
| 1485 | drawImage(image, "image"); |
| 1486 | canvas->translate(image->width(), 0); |
| 1487 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 1488 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 1489 | drawImage(textureImage, "backEndTexture"); |
| 1490 | ## |
| 1491 | |
| 1492 | #SeeAlso MakeFromTexture isTextureBacked |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1493 | |
| 1494 | #Method ## |
| 1495 | |
| 1496 | # ------------------------------------------------------------------------------ |
| 1497 | |
| 1498 | #Enum CachingHint |
| 1499 | |
| 1500 | #Code |
| 1501 | enum CachingHint { |
| 1502 | kAllow_CachingHint, |
| 1503 | kDisallow_CachingHint, |
| 1504 | }; |
| 1505 | ## |
| 1506 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1507 | CachingHint selects whether Skia may internally cache Bitmaps generated by |
| 1508 | decoding Image, or by copying Image from GPU to CPU. The default behavior |
| 1509 | allows caching Bitmaps. |
| 1510 | |
| 1511 | Choose kDisallow_CachingHint if Image pixels are to be used only once, or |
| 1512 | if Image pixels reside in a cache outside of Skia, or to reduce memory pressure. |
| 1513 | |
| 1514 | Choosing kAllow_CachingHint does not ensure that pixels will be cached. |
| 1515 | Image pixels may not be cached if memory requirements are too large or |
| 1516 | pixels are not accessible. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1517 | |
| 1518 | #Const kAllow_CachingHint 0 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1519 | Allows Skia to internally cache decoded and copied pixels. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1520 | ## |
| 1521 | #Const kDisallow_CachingHint 1 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1522 | Disallows Skia from internally caching decoded and copied pixels. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1523 | ## |
| 1524 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1525 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1526 | ## |
| 1527 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1528 | #SeeAlso readPixels scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1529 | |
| 1530 | #Enum ## |
| 1531 | |
| 1532 | # ------------------------------------------------------------------------------ |
| 1533 | |
| 1534 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 1535 | int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame^] | 1536 | #In Pixels |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1537 | #Line # copies and converts pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1538 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1539 | Copies Rect of pixels from Image to dstPixels. Copy starts at offset (srcX, srcY), |
| 1540 | and does not exceed Image (width(), height()). |
| 1541 | |
| 1542 | dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of |
| 1543 | destination. dstRowBytes specifics the gap from one destination row to the next. |
| 1544 | Returns true if pixels are copied. Returns false if: |
| 1545 | #List |
| 1546 | # dstInfo.addr() equals nullptr ## |
| 1547 | # dstRowBytes is less than dstInfo.minRowBytes ## |
| 1548 | # Pixel_Ref is nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1549 | ## |
| 1550 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1551 | Pixels are copied only if pixel conversion is possible. If Image Color_Type is |
| 1552 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. |
| 1553 | If Image Color_Type is kGray_8_SkColorType, dstInfo.colorSpace must match. |
| 1554 | If Image Alpha_Type is kOpaque_SkAlphaType, dstInfo.alphaType must |
| 1555 | match. If Image Color_Space is nullptr, dstInfo.colorSpace must match. Returns |
| 1556 | false if pixel conversion is not possible. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1557 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1558 | srcX and srcY may be negative to copy only top or left of source. Returns |
| 1559 | false if width() or height() is zero or negative. |
| 1560 | Returns false if |
| 1561 | #Formula |
| 1562 | abs(srcX) >= Image width() |
| 1563 | ## |
| 1564 | , or if |
| 1565 | #Formula |
| 1566 | abs(srcY) >= Image height() |
| 1567 | ## |
| 1568 | . |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1569 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1570 | If cachingHint is kAllow_CachingHint, pixels may be retained locally. |
| 1571 | If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. |
| 1572 | |
| 1573 | #Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ## |
| 1574 | #Param dstPixels destination pixel storage ## |
| 1575 | #Param dstRowBytes destination row length ## |
| 1576 | #Param srcX column index whose absolute value is less than width() ## |
| 1577 | #Param srcY row index whose absolute value is less than height() ## |
| 1578 | #Param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint ## |
| 1579 | |
| 1580 | #Return true if pixels are copied to dstPixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1581 | |
| 1582 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1583 | #Image 3 |
| 1584 | canvas->scale(.5f, .5f); |
| 1585 | const int width = 32; |
| 1586 | const int height = 32; |
| 1587 | std::vector<int32_t> dstPixels; |
| 1588 | dstPixels.resize(height * width * 4); |
| 1589 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 1590 | for (int y = 0; y < 512; y += height ) { |
| 1591 | for (int x = 0; x < 512; x += width ) { |
| 1592 | if (image->readPixels(info, &dstPixels.front(), width * 4, x, y)) { |
| 1593 | SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); |
| 1594 | SkBitmap bitmap; |
| 1595 | bitmap.installPixels(dstPixmap); |
| 1596 | canvas->drawBitmap(bitmap, 0, 0); |
| 1597 | } |
| 1598 | canvas->translate(48, 0); |
| 1599 | } |
| 1600 | canvas->translate(-16 * 48, 48); |
| 1601 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1602 | ## |
| 1603 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1604 | #SeeAlso scalePixels SkBitmap::readPixels SkPixmap::readPixels SkCanvas::readPixels SkSurface::readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1605 | |
| 1606 | #Method ## |
| 1607 | |
| 1608 | # ------------------------------------------------------------------------------ |
| 1609 | |
| 1610 | #Method bool readPixels(const SkPixmap& dst, int srcX, int srcY, |
| 1611 | CachingHint cachingHint = kAllow_CachingHint) const |
| 1612 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1613 | Copies a Rect of pixels from Image to dst. Copy starts at (srcX, srcY), and |
| 1614 | does not exceed Image (width(), height()). |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1615 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1616 | dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage, |
| 1617 | and row bytes of destination. dst.rowBytes specifics the gap from one destination |
| 1618 | row to the next. Returns true if pixels are copied. Returns false if: |
| 1619 | #List |
| 1620 | # dst pixel storage equals nullptr ## |
| 1621 | # dst.rowBytes is less than SkImageInfo::minRowBytes ## |
| 1622 | # Pixel_Ref is nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1623 | ## |
| 1624 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1625 | Pixels are copied only if pixel conversion is possible. If Image Color_Type is |
| 1626 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType must match. |
| 1627 | If Image Color_Type is kGray_8_SkColorType, dst.colorSpace must match. |
| 1628 | If Image Alpha_Type is kOpaque_SkAlphaType, dst.alphaType must |
| 1629 | match. If Image Color_Space is nullptr, dst.colorSpace must match. Returns |
| 1630 | false if pixel conversion is not possible. |
| 1631 | |
| 1632 | srcX and srcY may be negative to copy only top or left of source. Returns |
| 1633 | false if width() or height() is zero or negative. |
| 1634 | Returns false if |
| 1635 | #Formula |
| 1636 | abs(srcX) >= Image width() |
| 1637 | ## |
| 1638 | , or if |
| 1639 | #Formula |
| 1640 | abs(srcY) >= Image height() |
| 1641 | ## |
| 1642 | . |
| 1643 | |
| 1644 | If cachingHint is kAllow_CachingHint, pixels may be retained locally. |
| 1645 | If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. |
| 1646 | |
| 1647 | #Param dst destination Pixmap: Image_Info, pixels, row bytes ## |
| 1648 | #Param srcX column index whose absolute value is less than width() ## |
| 1649 | #Param srcY row index whose absolute value is less than height() ## |
| 1650 | #Param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint ## |
| 1651 | |
| 1652 | #Return true if pixels are copied to dst ## |
| 1653 | |
| 1654 | #Example |
| 1655 | #Image 3 |
| 1656 | std::vector<int32_t> srcPixels; |
| 1657 | int rowBytes = image->width() * 4; |
| 1658 | int quarterWidth = image->width() / 4; |
| 1659 | int quarterHeight = image->height() / 4; |
| 1660 | srcPixels.resize(image->height() * rowBytes); |
| 1661 | for (int y = 0; y < 4; ++y) { |
| 1662 | for (int x = 0; x < 4; ++x) { |
| 1663 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight), |
| 1664 | &srcPixels.front() + x * image->height() * quarterWidth + |
| 1665 | y * quarterWidth, rowBytes); |
| 1666 | image->readPixels(pixmap, x * quarterWidth, y * quarterHeight); |
| 1667 | } |
| 1668 | } |
| 1669 | canvas->scale(.5f, .5f); |
| 1670 | SkBitmap bitmap; |
| 1671 | bitmap.installPixels(SkImageInfo::MakeN32Premul(image->width(), image->height()), |
| 1672 | &srcPixels.front(), rowBytes); |
| 1673 | canvas->drawBitmap(bitmap, 0, 0); |
| 1674 | ## |
| 1675 | |
| 1676 | #SeeAlso scalePixels SkBitmap::readPixels SkPixmap::readPixels SkCanvas::readPixels SkSurface::readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1677 | |
| 1678 | #Method ## |
| 1679 | |
| 1680 | # ------------------------------------------------------------------------------ |
| 1681 | |
| 1682 | #Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality, |
| 1683 | CachingHint cachingHint = kAllow_CachingHint) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame^] | 1684 | #In Pixels |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1685 | #Line # scales and converts one Image to another ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1686 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1687 | Copies Image to dst, scaling pixels to fit dst.width() and dst.height(), and |
| 1688 | converting pixels to match dst.colorType and dst.alphaType. Returns true if |
| 1689 | pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes is |
| 1690 | less than dst SkImageInfo::minRowBytes. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1691 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1692 | Pixels are copied only if pixel conversion is possible. If Image Color_Type is |
| 1693 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType must match. |
| 1694 | If Image Color_Type is kGray_8_SkColorType, dst.colorSpace must match. |
| 1695 | If Image Alpha_Type is kOpaque_SkAlphaType, dst.alphaType must |
| 1696 | match. If Image Color_Space is nullptr, dst.colorSpace must match. Returns |
| 1697 | false if pixel conversion is not possible. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1698 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1699 | Scales the image, with filterQuality, to match dst.width() and dst.height(). |
| 1700 | filterQuality kNone_SkFilterQuality is fastest, typically implemented with |
| 1701 | Filter_Quality_Nearest_Neighbor. kLow_SkFilterQuality is typically implemented with |
| 1702 | Filter_Quality_Bilerp. kMedium_SkFilterQuality is typically implemented with |
| 1703 | Filter_Quality_Bilerp, and Filter_Quality_MipMap when size is reduced. |
| 1704 | kHigh_SkFilterQuality is slowest, typically implemented with Filter_Quality_BiCubic. |
| 1705 | |
| 1706 | If cachingHint is kAllow_CachingHint, pixels may be retained locally. |
| 1707 | If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. |
| 1708 | |
| 1709 | #Param dst destination Pixmap: Image_Info, pixels, row bytes ## |
| 1710 | #Param filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality, |
| 1711 | kMedium_SkFilterQuality, kHigh_SkFilterQuality |
| 1712 | ## |
| 1713 | #Param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint ## |
| 1714 | |
| 1715 | #Return true if pixels are scaled to fit dst ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1716 | |
| 1717 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1718 | #Image 3 |
| 1719 | #Height 128 |
| 1720 | std::vector<int32_t> srcPixels; |
| 1721 | int quarterWidth = image->width() / 16; |
| 1722 | int rowBytes = quarterWidth * 4; |
| 1723 | int quarterHeight = image->height() / 16; |
| 1724 | srcPixels.resize(quarterHeight * rowBytes); |
| 1725 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight), |
| 1726 | &srcPixels.front(), rowBytes); |
| 1727 | canvas->scale(4, 4); |
| 1728 | SkFilterQuality qualities[] = { kNone_SkFilterQuality, kLow_SkFilterQuality, |
| 1729 | kMedium_SkFilterQuality, kHigh_SkFilterQuality }; |
| 1730 | for (unsigned index = 0; index < SK_ARRAY_COUNT(qualities); ++index) { |
| 1731 | image->scalePixels(pixmap, qualities[index]); |
| 1732 | sk_sp<SkImage> filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr); |
| 1733 | canvas->drawImage(filtered, 16 * index, 0); |
| 1734 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1735 | ## |
| 1736 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1737 | #SeeAlso SkCanvas::drawImage readPixels SkPixmap::scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1738 | |
| 1739 | #Method ## |
| 1740 | |
| 1741 | # ------------------------------------------------------------------------------ |
| 1742 | |
| 1743 | #Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame^] | 1744 | #In Utility |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1745 | #Line # returns encoded Image as SkData ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1746 | Encodes Image pixels, returning result as SkData. |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1747 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1748 | Returns nullptr if encoding fails, or if encodedImageFormat is not supported. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1749 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1750 | Image encoding in a format requires both building with one or more of: |
| 1751 | SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY; and platform support |
| 1752 | for the encoded format. |
| 1753 | |
| 1754 | If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can |
| 1755 | additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP, |
| 1756 | SkEncodedImageFormat::kGIF. |
| 1757 | |
| 1758 | quality is a platform and format specific metric trading off size and encoding |
| 1759 | error. When used, quality equaling 100 encodes with the least error. quality may |
| 1760 | be ignored by the encoder. |
| 1761 | |
| 1762 | #Param encodedImageFormat one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG, |
| 1763 | SkEncodedImageFormat::kWEBP |
| 1764 | ## |
| 1765 | #Param quality encoder specific metric with 100 equaling best ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1766 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1767 | #Return encoded Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1768 | |
| 1769 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1770 | #Image 3 |
| 1771 | canvas->scale(4, 4); |
| 1772 | SkIRect subset = {0, 0, 16, 64}; |
| 1773 | int x = 0; |
| 1774 | for (int quality : { 0, 10, 50, 100 } ) { |
| 1775 | sk_sp<SkData> data(image->encodeToData(SkEncodedImageFormat::kJPEG, quality)); |
| 1776 | sk_sp<SkImage> filtered = SkImage::MakeFromEncoded(data, &subset); |
| 1777 | canvas->drawImage(filtered, x, 0); |
| 1778 | x += 16; |
| 1779 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1780 | ## |
| 1781 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1782 | #SeeAlso refEncodedData MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1783 | |
| 1784 | #Method ## |
| 1785 | |
| 1786 | # ------------------------------------------------------------------------------ |
| 1787 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1788 | #Method sk_sp<SkData> encodeToData() const |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1789 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1790 | Encodes Image pixels, returning result as SkData. Returns existing encoded data |
| 1791 | if present; otherwise, Image is encoded with SkEncodedImageFormat::kPNG. Skia |
| 1792 | must be built with SK_HAS_PNG_LIBRARY to encode Image. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1793 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1794 | Returns nullptr if existing encoded data is missing or invalid, and |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1795 | encoding fails. |
| 1796 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1797 | #Return encoded Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1798 | |
| 1799 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1800 | #Image 3 |
| 1801 | canvas->scale(4, 4); |
| 1802 | SkIRect subset = {136, 32, 200, 96}; |
| 1803 | sk_sp<SkData> data(image->encodeToData()); |
| 1804 | sk_sp<SkImage> eye = SkImage::MakeFromEncoded(data, &subset); |
| 1805 | canvas->drawImage(eye, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1806 | ## |
| 1807 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1808 | #SeeAlso refEncodedData MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1809 | |
| 1810 | #Method ## |
| 1811 | |
| 1812 | # ------------------------------------------------------------------------------ |
| 1813 | |
| 1814 | #Method sk_sp<SkData> refEncodedData() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame^] | 1815 | #In Utility |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1816 | #Line # returns Image encoded in SkData if present ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1817 | Returns encoded Image pixels as SkData, if Image was created from supported |
| 1818 | encoded stream format. Platform support for formats vary and may require building |
| 1819 | with one or more of: SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1820 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1821 | Returns nullptr if Image contents are not encoded. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1822 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1823 | #Return encoded Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1824 | |
| 1825 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1826 | #Image 3 |
| 1827 | #Platform gpu |
| 1828 | struct { |
| 1829 | const char* name; |
| 1830 | sk_sp<SkImage> image; |
| 1831 | } tests[] = { { "image", image }, { "bitmap", SkImage::MakeFromBitmap(source) }, |
| 1832 | { "texture", SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 1833 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr) } }; |
| 1834 | SkString string; |
| 1835 | SkPaint paint; |
| 1836 | for (const auto& test : tests ) { |
| 1837 | if (!test.image) { |
| 1838 | string.printf("no %s", test.name); |
| 1839 | } else { |
| 1840 | string.printf("%s" "encoded %s", test.image->refEncodedData() ? "" : "no ", test.name); |
| 1841 | } |
| 1842 | canvas->drawString(string, 10, 20, paint); |
| 1843 | canvas->translate(0, 20); |
| 1844 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1845 | ## |
| 1846 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1847 | #SeeAlso encodeToData MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1848 | |
| 1849 | #Method ## |
| 1850 | |
| 1851 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1852 | #Subtopic Utility |
| 1853 | #Populate |
| 1854 | #Line # rarely called management functions ## |
| 1855 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1856 | |
| 1857 | #Method const char* toString(SkString* string) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1858 | #In Utility |
| 1859 | #Line # converts Image to machine readable form ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1860 | Appends Image description to string, including unique ID, width, height, and |
| 1861 | whether the image is opaque. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1862 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1863 | #Param string storage for description; existing content is preserved ## |
| 1864 | |
| 1865 | #Return string appended with Image description ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1866 | |
| 1867 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1868 | #Image 4 |
| 1869 | struct { |
| 1870 | const char* name; |
| 1871 | sk_sp<SkImage> image; |
| 1872 | } tests[] = { { "image", image }, { "bitmap", SkImage::MakeFromBitmap(source) }, |
| 1873 | { "texture", SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 1874 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr) } }; |
| 1875 | SkString string; |
| 1876 | SkPaint paint; |
| 1877 | for (const auto& test : tests ) { |
| 1878 | string.printf("%s: ", test.name); |
| 1879 | test.image ? (void) test.image->toString(&string) : string.append("no image"); |
| 1880 | canvas->drawString(string, 10, 20, paint); |
| 1881 | canvas->translate(0, 20); |
| 1882 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1883 | ## |
| 1884 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1885 | #SeeAlso SkPaint::toString |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1886 | |
| 1887 | #Method ## |
| 1888 | |
| 1889 | # ------------------------------------------------------------------------------ |
| 1890 | |
| 1891 | #Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1892 | #In Constructor |
| 1893 | #Line # creates Image containing part of original ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1894 | Returns subset of Image. subset must be fully contained by Image dimensions(). |
| 1895 | The implementation may share pixels, or may copy them. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1896 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1897 | Returns nullptr if subset is empty, or subset is not contained by bounds, or |
| 1898 | pixels in Image could not be read or copied. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1899 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1900 | #Param subset bounds of returned Image ## |
| 1901 | |
| 1902 | #Return partial or full Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1903 | |
| 1904 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1905 | #Image 3 |
| 1906 | canvas->scale(.5f, .5f); |
| 1907 | const int width = 32; |
| 1908 | const int height = 32; |
| 1909 | for (int y = 0; y < 512; y += height ) { |
| 1910 | for (int x = 0; x < 512; x += width ) { |
| 1911 | sk_sp<SkImage> subset(image->makeSubset({x, y, x + width, y + height})); |
| 1912 | canvas->drawImage(subset, x * 3 / 2, y * 3 / 2); |
| 1913 | } |
| 1914 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1915 | ## |
| 1916 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1917 | #SeeAlso MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1918 | |
| 1919 | #Method ## |
| 1920 | |
| 1921 | # ------------------------------------------------------------------------------ |
| 1922 | |
| 1923 | #Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1924 | #In Constructor |
| 1925 | #Line # creates Image matching Color_Space if possible ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1926 | Returns Image backed by GPU_Texture associated with context. Returned Image is |
| 1927 | compatible with Surface created with dstColorSpace. Returns original |
| 1928 | Image if context and dstColorSpace match. |
| 1929 | |
| 1930 | Returns nullptr if context is nullptr, or if Image was created with another |
| 1931 | GrContext. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1932 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1933 | #Param context GPU_Context ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1934 | #Param dstColorSpace range of colors of matching Surface on GPU ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1935 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1936 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1937 | |
| 1938 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1939 | #Platform gpu |
| 1940 | #Image 5 |
| 1941 | auto drawImage = [=](sk_sp<SkImage> image, GrContext* context, const char* label) -> void { |
| 1942 | if (nullptr == image || nullptr == context) { |
| 1943 | return; |
| 1944 | } |
| 1945 | SkPaint paint; |
| 1946 | paint.setAntiAlias(true); |
| 1947 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1948 | sk_sp<SkImage> texture(image->makeTextureImage(context, nullptr)); |
| 1949 | canvas->drawImage(texture, 0, 0); |
| 1950 | canvas->drawString(label, texture->width() / 2, texture->height() / 4, paint); |
| 1951 | }; |
| 1952 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1953 | GrContext* context = canvas->getGrContext(); |
| 1954 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(context, backEndTexture, |
| 1955 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 1956 | drawImage(image, context, "image"); |
| 1957 | canvas->translate(image->width(), 0); |
| 1958 | drawImage(bitmapImage, context, "source"); |
| 1959 | canvas->translate(-image->width(), image->height()); |
| 1960 | drawImage(textureImage, context, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1961 | ## |
| 1962 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1963 | #SeeAlso MakeFromTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1964 | |
| 1965 | #Method ## |
| 1966 | |
| 1967 | # ------------------------------------------------------------------------------ |
| 1968 | |
| 1969 | #Method sk_sp<SkImage> makeNonTextureImage() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1970 | #In Constructor |
| 1971 | #Line # creates Image without dependency on GPU_Texture ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1972 | Returns Raster_Image or Lazy_Image. Copies Image backed by GPU_Texture into |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1973 | CPU memory if needed. Returns original Image if decoded in Raster_Bitmap, |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1974 | or if encoded in a stream. |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1975 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1976 | Returns nullptr if backed by GPU_Texture and copy fails. |
| 1977 | |
| 1978 | #Return Raster_Image, Lazy_Image, or nullptr ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1979 | |
| 1980 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1981 | #Image 5 |
| 1982 | #Platform gpu |
| 1983 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1984 | if (nullptr == image) { |
| 1985 | return; |
| 1986 | } |
| 1987 | SkPaint paint; |
| 1988 | paint.setAntiAlias(true); |
| 1989 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1990 | sk_sp<SkImage> nonTexture(image->makeNonTextureImage()); |
| 1991 | canvas->drawImage(nonTexture, 0, 0); |
| 1992 | canvas->drawString(label, nonTexture->width() / 2, nonTexture->height() / 4, paint); |
| 1993 | }; |
| 1994 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1995 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 1996 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 1997 | drawImage(image, "image"); |
| 1998 | canvas->translate(image->width(), 0); |
| 1999 | drawImage(bitmapImage, "source"); |
| 2000 | canvas->translate(-image->width(), image->height()); |
| 2001 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 2002 | ## |
| 2003 | |
| 2004 | #SeeAlso incomplete |
| 2005 | |
| 2006 | #Method ## |
| 2007 | |
| 2008 | # ------------------------------------------------------------------------------ |
| 2009 | |
| 2010 | #Method sk_sp<SkImage> makeRasterImage() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2011 | #In Constructor |
| 2012 | #Line # creates Image compatible with Raster_Surface if possible ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2013 | Returns Raster_Image. Copies Image backed by GPU_Texture into CPU memory, |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2014 | or decodes Image from Lazy_Image. Returns original Image if decoded in |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2015 | Raster_Bitmap. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2016 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2017 | Returns nullptr if copy, decode, or pixel read fails. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2018 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2019 | #Return Raster_Image, or nullptr ## |
| 2020 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2021 | #Bug 7479 |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2022 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2023 | #Image 5 |
| 2024 | #Platform gpu |
| 2025 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 2026 | if (nullptr == image) { |
| 2027 | return; |
| 2028 | } |
| 2029 | SkPaint paint; |
| 2030 | paint.setAntiAlias(true); |
| 2031 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 2032 | sk_sp<SkImage> raster(image->makeRasterImage()); |
| 2033 | canvas->drawImage(raster, 0, 0); |
| 2034 | canvas->drawString(label, raster->width() / 2, raster->height() / 4, paint); |
| 2035 | }; |
| 2036 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 2037 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 2038 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 2039 | drawImage(image, "image"); |
| 2040 | canvas->translate(image->width(), 0); |
| 2041 | drawImage(bitmapImage, "source"); |
| 2042 | canvas->translate(-image->width(), image->height()); |
| 2043 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2044 | ## |
| 2045 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2046 | #SeeAlso isTextureBacked isLazyGenerated MakeFromRaster |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2047 | |
| 2048 | #Method ## |
| 2049 | |
| 2050 | # ------------------------------------------------------------------------------ |
| 2051 | |
| 2052 | #Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset, |
| 2053 | const SkIRect& clipBounds, SkIRect* outSubset, |
| 2054 | SkIPoint* offset) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2055 | #In Constructor |
| 2056 | #Line # creates filtered, clipped Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2057 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2058 | Creates filtered Image. filter processes original Image, potentially changing |
| 2059 | color, position, and size. subset is the bounds of original Image processed |
| 2060 | by filter. clipBounds is the expected bounds of the filtered Image. outSubset |
| 2061 | is required storage for the actual bounds of the filtered Image. offset is |
| 2062 | required storage for translation of returned Image. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2063 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2064 | Returns nullptr if Image could not be created. If nullptr is returned, outSubset |
| 2065 | and offset are undefined. |
| 2066 | |
| 2067 | makeWithFilter is optimized to support Image backed by GPU_Texture drawn in an |
| 2068 | animation with SkImageFilter that vary in size from one frame to the next. The |
| 2069 | created Image is drawn at an increased size so that GPU_Texture can be reused |
| 2070 | with different sized effects. outSubset describes the valid bounds of GPU_Texture |
| 2071 | returned. The returned Image may be much larger than required for the filter. |
| 2072 | offset translates the returned Image to keep subsequent animation frames |
| 2073 | aligned with respect to each other. |
| 2074 | |
| 2075 | #Param filter how Image is sampled when transformed ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2076 | #Param subset incomplete ## |
| 2077 | #Param clipBounds incomplete ## |
| 2078 | #Param outSubset incomplete ## |
| 2079 | #Param offset incomplete ## |
| 2080 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2081 | #Return filtered Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2082 | |
| 2083 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2084 | #Description |
| 2085 | In each frame of the animation, filtered Image is drawn in a different location. |
| 2086 | By translating canvas by returned offset, Image appears stationary. |
| 2087 | ## |
| 2088 | #Image 5 |
| 2089 | #Platform gpu |
| 2090 | #Duration 5 |
| 2091 | sk_sp<SkImageFilter> shadowFilter = SkDropShadowImageFilter::Make( |
| 2092 | -10.0f * frame, 5.0f * frame, 3.0f, 3.0f, SK_ColorBLUE, |
| 2093 | SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
| 2094 | nullptr); |
| 2095 | sk_sp<SkImageFilter> offsetFilter = SkOffsetImageFilter::Make(40, 40, shadowFilter, nullptr); |
| 2096 | SkIRect subset = image->bounds(); |
| 2097 | SkIRect clipBounds = image->bounds(); |
| 2098 | clipBounds.outset(60, 60); |
| 2099 | SkIRect outSubset; |
| 2100 | SkIPoint offset; |
| 2101 | sk_sp<SkImage> filtered(image->makeWithFilter(offsetFilter.get(), subset, clipBounds, |
| 2102 | &outSubset, &offset)); |
| 2103 | SkPaint paint; |
| 2104 | paint.setAntiAlias(true); |
| 2105 | paint.setStyle(SkPaint::kStroke_Style); |
| 2106 | canvas->drawLine(0, 0, offset.fX, offset.fY, paint); |
| 2107 | canvas->translate(offset.fX, offset.fY); |
| 2108 | canvas->drawImage(filtered, 0, 0); |
| 2109 | canvas->drawRect(SkRect::MakeFromIRect(outSubset), paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2110 | ## |
| 2111 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2112 | #SeeAlso SkPaint::setImageFilter |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2113 | |
| 2114 | #Method ## |
| 2115 | |
| 2116 | # ------------------------------------------------------------------------------ |
| 2117 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 2118 | #Struct DeferredTextureImageUsageParams |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2119 | #Deprecated soon |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 2120 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2121 | Used only by Chrome. |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 2122 | |
| 2123 | ## |
| 2124 | |
| 2125 | #Method size_t getDeferredTextureImageData(const GrContextThreadSafeProxy& contextThreadSafeProxy, |
| 2126 | const DeferredTextureImageUsageParams deferredTextureImageUsageParams[], |
| 2127 | int paramCnt, |
| 2128 | void* buffer, |
| 2129 | SkColorSpace* dstColorSpace = nullptr, |
| 2130 | SkColorType dstColorType = kN32_SkColorType) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2131 | #Deprecated soon |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 2132 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2133 | Used only by Chrome. |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 2134 | ## |
| 2135 | |
| 2136 | #Method static sk_sp<SkImage> MakeFromDeferredTextureImageData(GrContext* context, const void* data, |
| 2137 | SkBudgeted budgeted) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2138 | #Deprecated soon |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 2139 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2140 | Used only by Chrome. |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 2141 | ## |
| 2142 | |
| 2143 | # ------------------------------------------------------------------------------ |
| 2144 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2145 | #Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc |
| 2146 | |
| 2147 | ## |
| 2148 | |
| 2149 | # ------------------------------------------------------------------------------ |
| 2150 | |
| 2151 | #Method static bool MakeBackendTextureFromSkImage(GrContext* context, |
| 2152 | sk_sp<SkImage> image, |
| 2153 | GrBackendTexture* backendTexture, |
| 2154 | BackendTextureReleaseProc* backendTextureReleaseProc) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2155 | #In Constructor |
| 2156 | #Line # creates GPU_Texture from Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2157 | |
| 2158 | Creates a GrBackendTexture from the provided SkImage. Returns true on success. The |
| 2159 | GrBackendTexture and BackendTextureReleaseProc are populated on success. It is the callers |
| 2160 | responsibility to call the BackendTextureReleaseProc once they have deleted the texture. |
| 2161 | Note that the BackendTextureReleaseProc allows Skia to clean up auxiliary data related |
| 2162 | to the GrBackendTexture, and is not a substitute for the client deleting the GrBackendTexture |
| 2163 | themselves. |
| 2164 | |
| 2165 | If image is both texture backed and singly referenced; that is, its only |
| 2166 | reference was transferred using std::move(): image is returned in backendTexture |
| 2167 | without conversion or making a copy. |
| 2168 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2169 | If Image is not texture backed, this function returns texture with Image |
| 2170 | contents. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2171 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 2172 | #Param context GPU_Context ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2173 | #Param image incomplete ## |
| 2174 | #Param backendTexture incomplete ## |
| 2175 | #Param backendTextureReleaseProc incomplete ## |
| 2176 | |
| 2177 | #Return incomplete ## |
| 2178 | |
| 2179 | #Example |
| 2180 | // incomplete |
| 2181 | ## |
| 2182 | |
| 2183 | #SeeAlso incomplete |
| 2184 | |
| 2185 | #Method ## |
| 2186 | |
| 2187 | # ------------------------------------------------------------------------------ |
| 2188 | |
| 2189 | #Enum LegacyBitmapMode |
| 2190 | |
| 2191 | #Code |
| 2192 | enum LegacyBitmapMode { |
| 2193 | kRO_LegacyBitmapMode, |
| 2194 | kRW_LegacyBitmapMode, |
| 2195 | }; |
| 2196 | ## |
| 2197 | |
| 2198 | Helper functions to convert to SkBitmap |
| 2199 | |
| 2200 | #Const kRO_LegacyBitmapMode 0 |
| 2201 | ## |
| 2202 | #Const kRW_LegacyBitmapMode 1 |
| 2203 | ## |
| 2204 | |
| 2205 | #Example |
| 2206 | // incomplete |
| 2207 | ## |
| 2208 | |
| 2209 | #SeeAlso incomplete |
| 2210 | |
| 2211 | #Enum ## |
| 2212 | |
| 2213 | # ------------------------------------------------------------------------------ |
| 2214 | |
| 2215 | #Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2216 | #In Constructor |
| 2217 | #Line # returns as Raster_Bitmap ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2218 | Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is |
| 2219 | kRO_LegacyBitmapMode, returned bitmap is read-only and immutable. |
| 2220 | Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if |
| 2221 | Bitmap write did not succeed. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2222 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 2223 | #Param bitmap storage for legacy Bitmap ## |
| 2224 | #Param legacyBitmapMode one of: kRO_LegacyBitmapMode, kRW_LegacyBitmapMode ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2225 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 2226 | #Return true if Bitmap was created ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2227 | |
| 2228 | #Example |
| 2229 | // incomplete |
| 2230 | ## |
| 2231 | |
| 2232 | #SeeAlso incomplete |
| 2233 | |
| 2234 | #Method ## |
| 2235 | |
| 2236 | # ------------------------------------------------------------------------------ |
| 2237 | |
| 2238 | #Method bool isLazyGenerated() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2239 | #In Property |
| 2240 | #Line # returns if Image is created as needed ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2241 | Returns true if Image is backed by an image-generator or other service that creates |
| 2242 | and caches its pixels or texture on-demand. |
| 2243 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 2244 | #Return true if Image is created as needed ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2245 | |
| 2246 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 2247 | #Height 80 |
| 2248 | #Function |
| 2249 | class TestImageGenerator : public SkImageGenerator { |
| 2250 | public: |
| 2251 | TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {} |
| 2252 | ~TestImageGenerator() override {} |
| 2253 | protected: |
| 2254 | bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes, |
| 2255 | const Options& options) override { |
| 2256 | SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr); |
| 2257 | for (int y = 0; y < info.height(); ++y) { |
| 2258 | for (int x = 0; x < info.width(); ++x) { |
| 2259 | pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811; |
| 2260 | } |
| 2261 | } |
| 2262 | return true; |
| 2263 | } |
| 2264 | }; |
| 2265 | ## |
| 2266 | void draw(SkCanvas* canvas) { |
| 2267 | auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator()); |
| 2268 | sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen))); |
| 2269 | SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy"); |
| 2270 | canvas->scale(8, 8); |
| 2271 | canvas->drawImage(image, 0, 0, nullptr); |
| 2272 | SkPaint paint; |
| 2273 | paint.setTextSize(4); |
| 2274 | canvas->drawString(lazy, 2, 5, paint); |
| 2275 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2276 | ## |
| 2277 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 2278 | #Example |
| 2279 | #Image 5 |
| 2280 | #Platform gpu |
| 2281 | void draw(SkCanvas* canvas) { |
| 2282 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 2283 | if (nullptr == image) { |
| 2284 | return; |
| 2285 | } |
| 2286 | SkPaint paint; |
| 2287 | paint.setAntiAlias(true); |
| 2288 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 2289 | canvas->drawImage(image, 0, 0); |
| 2290 | canvas->drawString(label, image->width() / 2, image->height() / 4, paint); |
| 2291 | canvas->drawString( |
| 2292 | image->isLazyGenerated() ? "is lazily generated" : "not lazily generated", |
| 2293 | image->width() / 2, image->height() * 3 / 4, paint); |
| 2294 | }; |
| 2295 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 2296 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 2297 | kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType, nullptr)); |
| 2298 | drawImage(image, "image"); |
| 2299 | canvas->translate(image->width(), 0); |
| 2300 | drawImage(bitmapImage, "source"); |
| 2301 | canvas->translate(-image->width(), image->height()); |
| 2302 | drawImage(textureImage, "backEndTexture"); |
| 2303 | } |
| 2304 | ## |
| 2305 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2306 | #SeeAlso isTextureBacked MakeNonTextureImage |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2307 | |
| 2308 | #Method ## |
| 2309 | |
| 2310 | # ------------------------------------------------------------------------------ |
| 2311 | |
| 2312 | #Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target, |
| 2313 | SkTransferFunctionBehavior premulBehavior) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2314 | #In Constructor |
| 2315 | #Line # creates Image matching Color_Space if possible ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2316 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2317 | Creates Image in target Color_Space. |
| 2318 | Returns nullptr if Image could not be created. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2319 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2320 | Returns original Image if it is in target Color_Space. |
| 2321 | Otherwise, converts pixels from Image Color_Space to target Color_Space. |
| 2322 | If Image colorSpace returns nullptr, Image Color_Space is assumed to be sRGB. |
| 2323 | |
| 2324 | SkTransferFunctionBehavior is to be deprecated. |
| 2325 | |
| 2326 | Set premulBehavior to SkTransferFunctionBehavior::kRespect to convert Image |
| 2327 | pixels to a linear space, before converting to destination Color_Type |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2328 | and Color_Space. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2329 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2330 | Set premulBehavior to SkTransferFunctionBehavior::kIgnore to treat Image |
| 2331 | pixels as linear, when converting to destination Color_Type |
| 2332 | and Color_Space, ignoring pixel encoding. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2333 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2334 | #Param target Color_Space describing color range of returned Image ## |
| 2335 | #Param premulBehavior one of: SkTransferFunctionBehavior::kRespect, |
| 2336 | SkTransferFunctionBehavior::kIgnore |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2337 | ## |
| 2338 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 2339 | #Return created Image in target Color_Space ## |
| 2340 | |
| 2341 | #Example |
| 2342 | #Image 5 |
| 2343 | #Set sRGB |
| 2344 | sk_sp<SkColorSpace> normalColorSpace = SkColorSpace::MakeRGB( |
| 2345 | SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kSRGB_Gamut); |
| 2346 | sk_sp<SkColorSpace> wackyColorSpace = normalColorSpace->makeColorSpin(); |
| 2347 | for (auto colorSpace : { normalColorSpace, wackyColorSpace } ) { |
| 2348 | for (auto transfer : { SkTransferFunctionBehavior::kRespect, |
| 2349 | SkTransferFunctionBehavior::kIgnore } ) { |
| 2350 | sk_sp<SkImage> colorSpaced = image->makeColorSpace(colorSpace, transfer); |
| 2351 | canvas->drawImage(colorSpaced, 0, 0); |
| 2352 | canvas->translate(128, 0); |
| 2353 | } |
| 2354 | canvas->translate(-256, 128); |
| 2355 | } |
| 2356 | ## |
| 2357 | |
| 2358 | #SeeAlso MakeFromPixture MakeFromTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 2359 | |
| 2360 | #Method ## |
| 2361 | |
| 2362 | #Class SkImage ## |
| 2363 | |
| 2364 | #Topic Image ## |