Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1 | #Topic Image |
| 2 | #Alias Image_Reference |
| 3 | |
| 4 | #Class SkImage |
| 5 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 6 | Image describes a two dimensional array of pixels to draw. The pixels may be |
| 7 | unencoded in a Raster_Bitmap, encoded in a Picture or compressed data stream, |
| 8 | or located in GPU memory as a GPU_Texture. |
| 9 | |
| 10 | Image cannot be modified after it is created. Image may allocate additional |
| 11 | storage as needed; for instance, an encoded Image may decode when drawn. |
| 12 | |
| 13 | Image width and height are greater than zero. Creating an Image with zero width |
| 14 | or height returns Image equal to nullptr. |
| 15 | |
| 16 | Image may be created from Bitmap, Pixmap, Surface, Picture, encoded streams, |
| 17 | GPU_Texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported |
| 18 | include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encodings details |
| 19 | vary with platform. |
| 20 | |
| 21 | #Topic Raster_Image |
| 22 | #Alias Raster_Image |
| 23 | Raster_Image pixels are unencoded in a Raster_Bitmap. These pixels may be read |
| 24 | directly and in most cases written to, although edited pixels may not be drawn |
| 25 | if Image has been copied internally. |
| 26 | ## |
| 27 | |
| 28 | #Topic Texture_Image |
| 29 | Texture_Image are located on GPU and pixels are not accessible. Texture_Image |
| 30 | are allocated optimally for best performance. Raster_Image may |
| 31 | be drawn to GPU_Surface, but pixels are uploaded from CPU to GPU downgrading |
| 32 | performance. |
| 33 | ## |
| 34 | |
| 35 | #Topic Lazy_Image |
| 36 | Lazy_Image defer allocating buffer for Image pixels and decoding stream until |
| 37 | Image is drawn. Lazy_Image caches result if possible to speed up repeated |
| 38 | drawing. |
| 39 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 40 | |
| 41 | #Topic Overview |
| 42 | |
| 43 | #Subtopic Subtopics |
| 44 | #ToDo manually add subtopics ## |
| 45 | #Table |
| 46 | #Legend |
| 47 | # topics # description ## |
| 48 | #Legend ## |
| 49 | #Table ## |
| 50 | ## |
| 51 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 52 | #Subtopic Member_Functions |
| 53 | #Table |
| 54 | #Legend |
| 55 | # description # function ## |
| 56 | #Legend ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 57 | # MakeBackendTextureFromSkImage # Creates GPU_Texture from Image. ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 58 | # MakeCrossContextFromEncoded # Creates Image from encoded data, and uploads to GPU. ## |
| 59 | # MakeFromAHardwareBuffer # Creates Image from Android hardware buffer. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 60 | # MakeFromAdoptedTexture # Creates Image from GPU_Texture, managed internally. ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 61 | # MakeFromBitmap # Creates Image from Bitmap, sharing or copying pixels. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 62 | # MakeFromDeferredTextureImageData # ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 63 | # MakeFromEncoded # Creates Image from encoded data. ## |
| 64 | # MakeFromGenerator # Creates Image from a stream of data. ## |
| 65 | # MakeFromNV12TexturesCopy # Creates Image from YUV_ColorSpace data in two planes. ## |
| 66 | # MakeFromPicture # Creates Image from Picture. ## |
| 67 | # MakeFromRaster # Creates Image from Pixmap, with release. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 68 | # MakeFromTexture # Creates Image from GPU_Texture, managed externally. ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 69 | # MakeFromYUVTexturesCopy # Creates Image from YUV_ColorSpace data in three planes. ## |
| 70 | # MakeRasterCopy # Creates Image from Pixmap and copied pixels. ## |
| 71 | # MakeRasterData # Creates Image from Image_Info and shared pixels. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 72 | # alphaType # Returns Alpha_Type. ## |
| 73 | # asLegacyBitmap # Returns as Raster_Bitmap. ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 74 | # bounds() # Returns width() and height() as Rectangle. ## |
| 75 | # colorSpace # Returns Color_Space. ## |
| 76 | # dimensions() # Returns width() and height(). ## |
| 77 | # encodeToData # Returns encoded Image as SkData. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 78 | # getDeferredTextureImageData # ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 79 | # getTexture # Deprecated. ## |
| 80 | # getTextureHandle # Returns GPU reference to Image as texture. ## |
| 81 | # height() # Returns pixel row count. ## |
| 82 | # isAlphaOnly # Returns if pixels represent a transparency mask. ## |
| 83 | # isLazyGenerated # Returns if Image is created as needed. ## |
| 84 | # isOpaque # Returns if Alpha_Type is kOpaque_SkAlphaType. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 85 | # isTextureBacked # Returns if Image was created from GPU_Texture. ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 86 | # isValid # Returns if Image can draw to Raster_Surface or GPU_Context. ## |
| 87 | # makeColorSpace # Creates Image matching Color_Space if possible. ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 88 | # makeNonTextureImage # Creates Image without dependency on GPU_Texture. ## |
| 89 | # makeRasterImage # Creates Image compatible with Raster_Surface if possible. ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 90 | # makeShader # Creates Shader, Paint element that can tile Image. ## |
| 91 | # makeSubset # Creates Image containing part of original. ## |
| 92 | # makeTextureImage # Creates Image matching Color_Space if possible. ## |
| 93 | # makeWithFilter # Creates filtered, clipped Image. ## |
| 94 | # peekPixels # Returns Pixmap if possible. ## |
| 95 | # readPixels # Copies and converts pixels. ## |
| 96 | # refColorSpace # Returns Image_Info Color_Space. ## |
| 97 | # refEncodedData # Returns Image encoded in SkData if present. ## |
| 98 | # scalePixels # Scales and converts one Image to another. ## |
| 99 | # toString # Converts Image to machine readable form. ## |
| 100 | # uniqueID # Identifier for Image. ## |
| 101 | # width() # Returns pixel column count. ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 102 | #Table ## |
| 103 | #Subtopic ## |
| 104 | |
| 105 | #Topic ## |
| 106 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 107 | #Typedef SkImageInfo Info |
| 108 | |
| 109 | ## |
| 110 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 111 | # ------------------------------------------------------------------------------ |
| 112 | |
| 113 | #Method static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap) |
| 114 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 115 | Creates Image from Pixmap and copy of pixels. Since pixels are copied, Pixmap |
| 116 | pixels may be modified or deleted without affecting Image. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 117 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 118 | Image is returned if Pixmap is valid. Valid Pixmap parameters include: |
| 119 | dimensions are greater than zero; |
| 120 | each dimension fits in 29 bits; |
| 121 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 122 | row bytes are large enough to hold one row of pixels; |
| 123 | pixel address is not nullptr. |
| 124 | |
| 125 | #Param pixmap Image_Info, pixel address, and row bytes ## |
| 126 | |
| 127 | #Return copy of Pixmap pixels, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 128 | |
| 129 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 130 | #Height 50 |
| 131 | #Description |
| 132 | Draw a five by five bitmap, and draw a copy in an Image. Editing the pixmap |
| 133 | alters the bitmap draw, but does not alter the Image draw since the Image |
| 134 | contains a copy of the pixels. |
| 135 | ## |
| 136 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 137 | { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, |
| 138 | { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, |
| 139 | { 0x90, 0x81, 0xC5, 0x71, 0x33 }, |
| 140 | { 0x75, 0x55, 0x44, 0x40, 0x30 }}; |
| 141 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 142 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 143 | SkBitmap bitmap; |
| 144 | bitmap.installPixels(pixmap); |
| 145 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 146 | *pixmap.writable_addr8(2, 2) = 0x00; |
| 147 | canvas->scale(10, 10); |
| 148 | canvas->drawBitmap(bitmap, 0, 0); |
| 149 | canvas->drawImage(image, 10, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 150 | ## |
| 151 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 152 | #SeeAlso MakeRasterData MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 153 | |
| 154 | #Method ## |
| 155 | |
| 156 | # ------------------------------------------------------------------------------ |
| 157 | |
| 158 | #Method static sk_sp<SkImage> MakeRasterData(const Info& info, sk_sp<SkData> pixels, size_t rowBytes) |
| 159 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 160 | Creates Image from Image_Info, sharing pixels. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 161 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 162 | Image is returned if Image_Info is valid. Valid Image_Info parameters include: |
| 163 | dimensions are greater than zero; |
| 164 | each dimension fits in 29 bits; |
| 165 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 166 | rowBytes are large enough to hold one row of pixels; |
| 167 | pixels is not nullptr, and contains enough data for Image. |
| 168 | |
| 169 | #Param info contains width, height, Alpha_Type, Color_Type, Color_Space ## |
| 170 | #Param pixels address or pixel storage ## |
| 171 | #Param rowBytes size of pixel row or larger ## |
| 172 | |
| 173 | #Return Image sharing pixels, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 174 | |
| 175 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 176 | #Image 3 |
| 177 | size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType); |
| 178 | sk_sp<SkData> data = SkData::MakeUninitialized(rowBytes * image->height()); |
| 179 | SkImageInfo dstInfo = SkImageInfo::MakeN32(image->width(), image->height(), |
| 180 | kPremul_SkAlphaType); |
| 181 | image->readPixels(dstInfo, data->writable_data(), rowBytes, 0, 0, SkImage::kAllow_CachingHint); |
| 182 | sk_sp<SkImage> raw = SkImage::MakeRasterData(dstInfo.makeColorType(kRGBA_8888_SkColorType), |
| 183 | data, rowBytes); |
| 184 | canvas->drawImage(image, 0, 0); |
| 185 | canvas->drawImage(raw.get(), 128, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 186 | ## |
| 187 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 188 | #SeeAlso MakeRasterCopy MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 189 | |
| 190 | #Method ## |
| 191 | |
| 192 | # ------------------------------------------------------------------------------ |
| 193 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 194 | #Typedef void* ReleaseContext |
| 195 | |
| 196 | Caller data passed to RasterReleaseProc; may be nullptr. |
| 197 | |
| 198 | #SeeAlso MakeFromRaster RasterReleaseProc |
| 199 | |
| 200 | ## |
| 201 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 202 | #Typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext) |
| 203 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 204 | Function called when Image no longer shares pixels. ReleaseContext is |
| 205 | provided by caller when Image is created, and may be nullptr. |
| 206 | |
| 207 | #SeeAlso ReleaseContext MakeFromRaster |
| 208 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 209 | ## |
| 210 | |
| 211 | #Method static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap, |
| 212 | RasterReleaseProc rasterReleaseProc, |
| 213 | ReleaseContext releaseContext) |
| 214 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 215 | Creates Image from pixmap, sharing Pixmap pixels. Pixels must remain valid and |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 216 | unchanged until rasterReleaseProc is called. rasterReleaseProc is passed |
| 217 | releaseContext when Image is deleted or no longer refers to pixmap pixels. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 218 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 219 | Pass nullptr for rasterReleaseProc to share Pixmap without requiring a callback |
| 220 | when Image is released. Pass nullptr for releaseContext if rasterReleaseProc |
| 221 | does not require state. |
| 222 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 223 | Image is returned if pixmap is valid. Valid Pixmap parameters include: |
| 224 | dimensions are greater than zero; |
| 225 | each dimension fits in 29 bits; |
| 226 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 227 | row bytes are large enough to hold one row of pixels; |
| 228 | pixel address is not nullptr. |
| 229 | |
| 230 | #Param pixmap Image_Info, pixel address, and row bytes ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 231 | #Param rasterReleaseProc function called when pixels can be released; or nullptr ## |
| 232 | #Param releaseContext state passed to rasterReleaseProc; or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 233 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 234 | #Return Image sharing pixmap ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 235 | |
| 236 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 237 | #Function |
| 238 | static void releaseProc(const void* pixels, SkImage::ReleaseContext context) { |
| 239 | int* countPtr = static_cast<int*>(context); |
| 240 | *countPtr += 1; |
| 241 | } |
| 242 | ## |
| 243 | |
| 244 | void draw(SkCanvas* canvas) { |
| 245 | SkColor color = 0; |
| 246 | SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), &color, 4); |
| 247 | int releaseCount = 0; |
| 248 | sk_sp<SkImage> image(SkImage::MakeFromRaster(pixmap, releaseProc, &releaseCount)); |
| 249 | SkDebugf("before reset: %d\n", releaseCount); |
| 250 | image.reset(); |
| 251 | SkDebugf("after reset: %d\n", releaseCount); |
| 252 | } |
| 253 | #StdOut |
| 254 | before reset: 0 |
| 255 | after reset: 1 |
| 256 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 257 | ## |
| 258 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 259 | #SeeAlso MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 260 | |
| 261 | #Method ## |
| 262 | |
| 263 | # ------------------------------------------------------------------------------ |
| 264 | |
| 265 | #Method static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap) |
| 266 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 267 | Creates Image from bitmap, sharing or copying bitmap pixels. If the bitmap |
| 268 | is marked immutable, and its pixel memory is shareable, it may be shared |
| 269 | instead of copied. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 270 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 271 | Image is returned if bitmap is valid. Valid Bitmap parameters include: |
| 272 | dimensions are greater than zero; |
| 273 | each dimension fits in 29 bits; |
| 274 | Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType; |
| 275 | row bytes are large enough to hold one row of pixels; |
| 276 | pixel address is not nullptr. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 277 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 278 | #Param bitmap Image_Info, row bytes, and pixels ## |
| 279 | |
| 280 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 281 | |
| 282 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 283 | #Description |
| 284 | The first Bitmap is shared; writing to the pixel memory changes the first |
| 285 | Image. |
| 286 | The second Bitmap is marked immutable, and is copied; writing to the pixel |
| 287 | memory does not alter the second Image. |
| 288 | ## |
| 289 | #Height 50 |
| 290 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 291 | { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, |
| 292 | { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, |
| 293 | { 0x90, 0x81, 0xC5, 0x71, 0x33 }, |
| 294 | { 0x75, 0x55, 0x44, 0x40, 0x30 }}; |
| 295 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 296 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 297 | SkBitmap bitmap; |
| 298 | bitmap.installPixels(pixmap); |
| 299 | sk_sp<SkImage> image1 = SkImage::MakeFromBitmap(bitmap); |
| 300 | bitmap.setImmutable(); |
| 301 | sk_sp<SkImage> image2 = SkImage::MakeFromBitmap(bitmap); |
| 302 | *pixmap.writable_addr8(2, 2) = 0x00; |
| 303 | canvas->scale(10, 10); |
| 304 | canvas->drawImage(image1, 0, 0); |
| 305 | canvas->drawImage(image2, 10, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 306 | ## |
| 307 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 308 | #SeeAlso MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 309 | |
| 310 | #Method ## |
| 311 | |
| 312 | # ------------------------------------------------------------------------------ |
| 313 | |
| 314 | #Method static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator, |
| 315 | const SkIRect* subset = nullptr) |
| 316 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 317 | Creates Image from data returned by imageGenerator. Generated data is owned by Image and may not |
| 318 | be shared or accessed. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 319 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 320 | subset allows selecting a portion of the full image. Pass nullptr to select the entire image; |
| 321 | otherwise, subset must be contained by image bounds. |
| 322 | |
| 323 | Image is returned if generator data is valid. Valid data parameters vary by type of data |
| 324 | and platform. |
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 | imageGenerator may wrap Picture data, codec data, or custom data. |
| 327 | |
| 328 | #Param imageGenerator stock or custom routines to retrieve Image ## |
| 329 | #Param subset bounds of returned Image; may be nullptr ## |
| 330 | |
| 331 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 332 | |
| 333 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 334 | #Description |
| 335 | The generator returning Picture cannot be shared; std::move transfers ownership to generated Image. |
| 336 | ## |
| 337 | SkPictureRecorder recorder; |
| 338 | recorder.beginRecording(100, 100)->drawColor(SK_ColorRED); |
| 339 | auto picture = recorder.finishRecordingAsPicture(); |
| 340 | auto gen = SkImageGenerator::MakeFromPicture({100, 100}, picture, nullptr, nullptr, |
| 341 | SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); |
| 342 | sk_sp<SkImage> image = SkImage::MakeFromGenerator(std::move(gen)); |
| 343 | canvas->drawImage(image, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 344 | ## |
| 345 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 346 | #SeeAlso MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 347 | |
| 348 | #Method ## |
| 349 | |
| 350 | # ------------------------------------------------------------------------------ |
| 351 | |
| 352 | #Method static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr) |
| 353 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 354 | Creates Image from encoded data. |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 355 | subset allows selecting a portion of the full image. Pass nullptr to select the entire image; |
| 356 | otherwise, subset must be contained by image bounds. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 357 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 358 | Image is returned if format of the encoded data is recognized and supported. |
| 359 | Recognized formats vary by platfrom. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 360 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 361 | #Param encoded data of Image to decode ## |
| 362 | #Param subset bounds of returned Image; may be nullptr ## |
| 363 | |
| 364 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 365 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 366 | #Example |
| 367 | #Image 3 |
| 368 | int x = 0; |
| 369 | for (int quality : { 100, 50, 10, 1} ) { |
| 370 | sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, quality); |
| 371 | sk_sp<SkImage> image = SkImage::MakeFromEncoded(encodedData); |
| 372 | canvas->drawImage(image, x, 0); |
| 373 | x += 64; |
| 374 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 375 | ## |
| 376 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 377 | #SeeAlso MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 378 | |
| 379 | #Method ## |
| 380 | |
| 381 | # ------------------------------------------------------------------------------ |
| 382 | |
| 383 | #Typedef void (*TextureReleaseProc)(ReleaseContext releaseContext) |
| 384 | |
| 385 | ## |
| 386 | |
| 387 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 388 | const GrBackendTexture& backendTexture, |
| 389 | GrSurfaceOrigin origin, |
| 390 | SkAlphaType alphaType, |
| 391 | sk_sp<SkColorSpace> colorSpace) |
| 392 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 393 | Deprecated. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 394 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 395 | #Param context GPU_Context ## |
| 396 | #Param backendTexture texture residing on GPU ## |
| 397 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 398 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 399 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 400 | ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 401 | #Param colorSpace range of colors; may be nullptr ## |
| 402 | |
| 403 | #Return created Image, or nullptr ## |
| 404 | |
| 405 | #NoExample |
| 406 | ## |
| 407 | |
| 408 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
| 409 | |
| 410 | #Method ## |
| 411 | |
| 412 | # ------------------------------------------------------------------------------ |
| 413 | |
| 414 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 415 | const GrBackendTexture& backendTexture, |
| 416 | GrSurfaceOrigin origin, |
| 417 | SkAlphaType alphaType, |
| 418 | sk_sp<SkColorSpace> colorSpace, |
| 419 | TextureReleaseProc textureReleaseProc, |
| 420 | ReleaseContext releaseContext) |
| 421 | |
| 422 | Deprecated. |
| 423 | |
| 424 | #Param context GPU_Context ## |
| 425 | #Param backendTexture texture residing on GPU ## |
| 426 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 427 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 428 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 429 | ## |
| 430 | #Param colorSpace range of colors; may be nullptr ## |
| 431 | #Param textureReleaseProc function called when texture can be released ## |
| 432 | #Param releaseContext state passed to textureReleaseProc ## |
| 433 | |
| 434 | #Return created Image, or nullptr ## |
| 435 | |
| 436 | #NoExample |
| 437 | ## |
| 438 | |
| 439 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
| 440 | |
| 441 | #Method ## |
| 442 | |
| 443 | # ------------------------------------------------------------------------------ |
| 444 | |
| 445 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 446 | const GrBackendTexture& backendTexture, |
| 447 | GrSurfaceOrigin origin, |
| 448 | SkColorType colorType, |
| 449 | SkAlphaType alphaType, |
| 450 | sk_sp<SkColorSpace> colorSpace) |
| 451 | |
| 452 | Creates Image from GPU_Texture associated with context. Caller is responsible for |
| 453 | managing the lifetime of GPU_Texture. |
| 454 | |
| 455 | Image is returned if format of backendTexture is recognized and supported. |
| 456 | Recognized formats vary by GPU back-end. |
| 457 | |
| 458 | #Param context GPU_Context ## |
| 459 | #Param backendTexture texture residing on GPU ## |
| 460 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 461 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 462 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 463 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 464 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 465 | ## |
| 466 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 467 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 468 | ## |
| 469 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 470 | |
| 471 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 472 | |
| 473 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 474 | #Image 3 |
| 475 | #Platform gpu |
| 476 | #Height 128 |
| 477 | #Description |
| 478 | A back-end texture has been created and uploaded to the GPU outside of this example. |
| 479 | ## |
| 480 | GrContext* context = canvas->getGrContext(); |
| 481 | if (!context) { |
| 482 | return; |
| 483 | } |
| 484 | canvas->scale(.25f, .25f); |
| 485 | int x = 0; |
| 486 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 487 | sk_sp<SkImage> image = SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
| 488 | origin, kOpaque_SkAlphaType, nullptr); |
| 489 | canvas->drawImage(image, x, 0); |
| 490 | x += 512; |
| 491 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 492 | ## |
| 493 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 494 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 495 | |
| 496 | #Method ## |
| 497 | |
| 498 | # ------------------------------------------------------------------------------ |
| 499 | |
| 500 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 501 | const GrBackendTexture& backendTexture, |
| 502 | GrSurfaceOrigin origin, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 503 | SkColorType colorType, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 504 | SkAlphaType alphaType, |
| 505 | sk_sp<SkColorSpace> colorSpace, |
| 506 | TextureReleaseProc textureReleaseProc, |
| 507 | ReleaseContext releaseContext) |
| 508 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 509 | Creates Image from GPU_Texture associated with context. GPU_Texture must stay |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 510 | valid and unchanged until textureReleaseProc is called. textureReleaseProc is |
| 511 | passed releaseContext when Image is deleted or no longer refers to texture. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 512 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 513 | Image is returned if format of backendTexture is recognized and supported. |
| 514 | Recognized formats vary by GPU back-end. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 515 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 516 | #Param context GPU_Context ## |
| 517 | #Param backendTexture texture residing on GPU ## |
| 518 | #Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 519 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 520 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 521 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 522 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 523 | ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 524 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 525 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 526 | ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 527 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 528 | #Param textureReleaseProc function called when texture can be released ## |
| 529 | #Param releaseContext state passed to textureReleaseProc ## |
| 530 | |
| 531 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 532 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 533 | #ToDo |
| 534 | 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] | 535 | fwithin the lifetime of the example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 536 | ## |
| 537 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 538 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 539 | GrContext* context = canvas->getGrContext(); |
| 540 | if (!context) { |
| 541 | return; |
| 542 | } |
| 543 | auto debugster = [](SkImage::ReleaseContext context) -> void { |
| 544 | *((int *) context) += 128; |
| 545 | }; |
| 546 | int x = 0; |
| 547 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 548 | sk_sp<SkImage> image = SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 549 | origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, debugster, &x); |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 550 | canvas->drawImage(image, x, 0); |
| 551 | x += 128; |
| 552 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 553 | ## |
| 554 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 555 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 556 | |
| 557 | #Method ## |
| 558 | |
| 559 | # ------------------------------------------------------------------------------ |
| 560 | |
| 561 | #Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data, |
| 562 | bool buildMips, |
| 563 | SkColorSpace* dstColorSpace) |
| 564 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 565 | Creates Image from encoded data. Image is uploaded to GPU back-end using context. |
| 566 | |
| 567 | Created Image is available to other GPU contexts, and is available across thread |
| 568 | boundaries. All contexts must be in the same GPU_Share_Group, or otherwise |
| 569 | share resources. |
| 570 | |
| 571 | When Image is no longer referenced, context releases texture memory |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 572 | asynchronously. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 573 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 574 | Texture decoded from data is uploaded to match Surface created with |
| 575 | dstColorSpace. Color_Space of Image is determined by encoded data. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 576 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 577 | Image is returned if format of data is recognized and supported, and if context |
| 578 | supports moving resources. Recognized formats vary by platform and GPU back-end. |
| 579 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 580 | Image is returned using MakeFromEncoded if context is nullptr or does not support |
| 581 | moving resources between contexts. |
| 582 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 583 | #Param context GPU_Context ## |
| 584 | #Param data Image to decode ## |
| 585 | #Param buildMips create Image as Mip_Map if true ## |
| 586 | #Param dstColorSpace range of colors of matching Surface on GPU ## |
| 587 | |
| 588 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 589 | |
| 590 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 591 | #Image 4 |
| 592 | #Height 128 |
| 593 | GrContext* context = canvas->getGrContext(); |
| 594 | sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, 100); |
| 595 | sk_sp<SkImage> image = SkImage::MakeCrossContextFromEncoded(context, |
| 596 | encodedData, false, nullptr); |
| 597 | canvas->drawImage(image, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 598 | ## |
| 599 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 600 | #SeeAlso MakeCrossContextFromPixmap |
| 601 | |
| 602 | #Method ## |
| 603 | |
| 604 | # ------------------------------------------------------------------------------ |
| 605 | |
| 606 | #Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap, |
| 607 | bool buildMips, |
| 608 | SkColorSpace* dstColorSpace) |
| 609 | |
| 610 | Creates Image from pixmap. Image is uploaded to GPU back-end using context. |
| 611 | |
| 612 | Created Image is available to other GPU contexts, and is available across thread |
| 613 | boundaries. All contexts must be in the same GPU_Share_Group, or otherwise |
| 614 | share resources. |
| 615 | |
| 616 | When Image is no longer referenced, context releases texture memory |
| 617 | asynchronously. |
| 618 | |
| 619 | Texture created from pixmap is uploaded to match Surface created with |
| 620 | dstColorSpace. Color_Space of Image is determined by pixmap.colorSpace(). |
| 621 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 622 | Image is returned referring to GPU back-end if context is not nullptr, |
| 623 | format of data is recognized and supported, and if context supports moving |
| 624 | resources between contexts. Otherwise, pixmap pixel data is copied and Image |
| 625 | as returned in raster format if possible; nullptr may be returned. |
| 626 | Recognized GPU formats vary by platform and GPU back-end. |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 627 | |
| 628 | #Param context GPU_Context ## |
| 629 | #Param pixmap Image_Info, pixel address, and row bytes ## |
| 630 | #Param buildMips create Image as Mip_Map if true ## |
| 631 | #Param dstColorSpace range of colors of matching Surface on GPU ## |
| 632 | |
| 633 | #Return created Image, or nullptr ## |
| 634 | |
| 635 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 636 | #Image 4 |
| 637 | #Height 128 |
| 638 | GrContext* context = canvas->getGrContext(); |
| 639 | SkPixmap pixmap; |
| 640 | if (source.peekPixels(&pixmap)) { |
| 641 | sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(context, pixmap, |
| 642 | false, nullptr); |
| 643 | canvas->drawImage(image, 0, 0); |
| 644 | } |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 645 | ## |
| 646 | |
| 647 | #SeeAlso MakeCrossContextFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 648 | |
| 649 | #Method ## |
| 650 | |
| 651 | # ------------------------------------------------------------------------------ |
| 652 | |
| 653 | #Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context, |
| 654 | const GrBackendTexture& backendTexture, |
| 655 | GrSurfaceOrigin surfaceOrigin, |
| 656 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 657 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 658 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 659 | Deprecated. |
| 660 | |
| 661 | #Param context GPU_Context ## |
| 662 | #Param backendTexture texture residing on GPU ## |
| 663 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 664 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 665 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 666 | ## |
| 667 | #Param colorSpace range of colors; may be nullptr ## |
| 668 | |
| 669 | #Return created Image, or nullptr ## |
| 670 | |
| 671 | #NoExample |
| 672 | ## |
| 673 | |
| 674 | #SeeAlso MakeFromTexture MakeFromYUVTexturesCopy |
| 675 | |
| 676 | #Method ## |
| 677 | |
| 678 | # ------------------------------------------------------------------------------ |
| 679 | |
| 680 | #Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context, |
| 681 | const GrBackendTexture& backendTexture, |
| 682 | GrSurfaceOrigin surfaceOrigin, |
| 683 | SkColorType colorType, |
| 684 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 685 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 686 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 687 | Creates Image from backendTexture associated with context. backendTexture and |
| 688 | returned Image are managed internally, and are released when no longer needed. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 689 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 690 | Image is returned if format of backendTexture is recognized and supported. |
| 691 | Recognized formats vary by GPU back-end. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 692 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 693 | #Param context GPU_Context ## |
| 694 | #Param backendTexture texture residing on GPU ## |
| 695 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 696 | #Param colorType one of: kUnknown_SkColorType, kAlpha_8_SkColorType, |
| 697 | kRGB_565_SkColorType, kARGB_4444_SkColorType, |
| 698 | kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, |
| 699 | kGray_8_SkColorType, kRGBA_F16_SkColorType |
| 700 | ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 701 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 702 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 703 | ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 704 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 705 | |
| 706 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 707 | |
| 708 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 709 | if (!canvas->getGrContext()) { |
| 710 | return; |
| 711 | } |
| 712 | canvas->scale(.5f, .5f); |
| 713 | canvas->clear(0x7f3f5f7f); |
| 714 | int x = 0, y = 0; |
| 715 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 716 | for (auto alpha : { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
| 717 | sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(canvas->getGrContext(), |
| 718 | backEndTexture, origin, |
| 719 | kRGBA_8888_SkColorType, alpha); |
| 720 | canvas->drawImage(image, x, y); |
| 721 | x += 160; |
| 722 | } |
| 723 | x -= 160 * 3; |
| 724 | y += 256; |
| 725 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 726 | ## |
| 727 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 728 | #SeeAlso MakeFromTexture MakeFromYUVTexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 729 | |
| 730 | #Method ## |
| 731 | |
| 732 | # ------------------------------------------------------------------------------ |
| 733 | |
| 734 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, |
| 735 | const GrBackendObject yuvTextureHandles[3], |
| 736 | const SkISize yuvSizes[3], |
| 737 | GrSurfaceOrigin surfaceOrigin, |
| 738 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 739 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 740 | Creates Image from copy of yuvTextureHandles, an array of textures on GPU. |
| 741 | yuvTextureHandles contain pixels for YUV planes of Image. |
| 742 | yuvSizes conain dimensions for each pixel plane. Dimensions must be greater than |
| 743 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 744 | yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 745 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 746 | #Param context GPU_Context ## |
| 747 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 748 | kRec709_SkYUVColorSpace |
| 749 | ## |
| 750 | #Param yuvTextureHandles array of YUV textures on GPU ## |
| 751 | #Param yuvSizes dimensions of YUV textures ## |
| 752 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 753 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 754 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 755 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 756 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 757 | # seems too complicated to create an example for this |
| 758 | #ToDo |
| 759 | should this be moved to chrome only? |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 760 | ## |
| 761 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 762 | #NoExample |
| 763 | ## |
| 764 | |
| 765 | #SeeAlso MakeFromNV12TexturesCopy |
| 766 | |
| 767 | #Method ## |
| 768 | |
| 769 | # ------------------------------------------------------------------------------ |
| 770 | |
| 771 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, |
| 772 | const GrBackendTexture yuvTextureHandles[3], |
| 773 | const SkISize yuvSizes[3], |
| 774 | GrSurfaceOrigin surfaceOrigin, |
| 775 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 776 | |
| 777 | Creates Image from copy of yuvTextureHandles, an array of textures on GPU. |
| 778 | yuvTextureHandles contain pixels for YUV planes of Image. |
| 779 | yuvSizes conain dimensions for each pixel plane. Dimensions must be greater than |
| 780 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 781 | yuvSizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
| 782 | |
| 783 | #Param context GPU_Context ## |
| 784 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 785 | kRec709_SkYUVColorSpace |
| 786 | ## |
| 787 | #Param yuvTextureHandles array of YUV textures on GPU ## |
| 788 | #Param yuvSizes dimensions of YUV textures ## |
| 789 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 790 | #Param colorSpace range of colors; may be nullptr ## |
| 791 | |
| 792 | #Return created Image, or nullptr ## |
| 793 | |
| 794 | # seems too complicated to create an example for this |
| 795 | #ToDo |
| 796 | should this be moved to chrome only? |
| 797 | ## |
| 798 | |
| 799 | #NoExample |
| 800 | ## |
| 801 | |
| 802 | #SeeAlso MakeFromNV12TexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 803 | |
| 804 | #Method ## |
| 805 | |
| 806 | # ------------------------------------------------------------------------------ |
| 807 | |
| 808 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, |
| 809 | SkYUVColorSpace yuvColorSpace, |
| 810 | const GrBackendObject nv12TextureHandles[2], |
| 811 | const SkISize nv12Sizes[2], |
| 812 | GrSurfaceOrigin surfaceOrigin, |
| 813 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 814 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 815 | Creates Image from copy of nv12TextureHandles, an array of textures on GPU. |
| 816 | nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. |
| 817 | nv12TextureHandles[1] contains pixels for YUV_Component_U plane, |
| 818 | followed by pixels for YUV_Component_V plane. |
| 819 | nv12Sizes conain dimensions for each pixel plane. Dimensions must be greater than |
| 820 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 821 | nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 822 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 823 | #Param context GPU_Context ## |
| 824 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 825 | kRec709_SkYUVColorSpace |
| 826 | ## |
| 827 | #Param nv12TextureHandles array of YUV textures on GPU ## |
| 828 | #Param nv12Sizes dimensions of YUV textures ## |
| 829 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 830 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 831 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 832 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 833 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 834 | # seems too complicated to create an example for this |
| 835 | #ToDo |
| 836 | should this be moved to chrome only? |
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 | #NoExample |
| 840 | ## |
| 841 | |
| 842 | #SeeAlso MakeFromYUVTexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 843 | |
| 844 | #Method ## |
| 845 | |
| 846 | # ------------------------------------------------------------------------------ |
| 847 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 848 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, |
| 849 | SkYUVColorSpace yuvColorSpace, |
| 850 | const GrBackendTexture nv12TextureHandles[2], |
| 851 | const SkISize nv12Sizes[2], |
| 852 | GrSurfaceOrigin surfaceOrigin, |
| 853 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 854 | |
| 855 | Creates Image from copy of nv12TextureHandles, an array of textures on GPU. |
| 856 | nv12TextureHandles[0] contains pixels for YUV_Component_Y plane. |
| 857 | nv12TextureHandles[1] contains pixels for YUV_Component_U plane, |
| 858 | followed by pixels for YUV_Component_V plane. |
| 859 | nv12Sizes conain dimensions for each pixel plane. Dimensions must be greater than |
| 860 | zero but may differ from plane to plane. Returned Image has the dimensions |
| 861 | nv12Sizes[0]. yuvColorSpace describes how YUV colors convert to RGB colors. |
| 862 | |
| 863 | #Param context GPU_Context ## |
| 864 | #Param yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, |
| 865 | kRec709_SkYUVColorSpace |
| 866 | ## |
| 867 | #Param nv12TextureHandles array of YUV textures on GPU ## |
| 868 | #Param nv12Sizes dimensions of YUV textures ## |
| 869 | #Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## |
| 870 | #Param colorSpace range of colors; may be nullptr ## |
| 871 | |
| 872 | #Return created Image, or nullptr ## |
| 873 | |
| 874 | # seems too complicated to create an example for this |
| 875 | #ToDo |
| 876 | should this be moved to chrome only? |
| 877 | ## |
| 878 | |
| 879 | #NoExample |
| 880 | ## |
| 881 | |
| 882 | #SeeAlso MakeFromYUVTexturesCopy |
| 883 | |
| 884 | #Method ## |
| 885 | |
| 886 | # ------------------------------------------------------------------------------ |
| 887 | |
| 888 | #Bug 7424 |
| 889 | currently uncalled by any test or client |
| 890 | ## |
| 891 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 892 | #Enum BitDepth |
| 893 | |
| 894 | #Code |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 895 | enum class BitDepth { |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 896 | kU8, |
| 897 | kF16, |
| 898 | }; |
| 899 | ## |
| 900 | |
| 901 | #Const kU8 0 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 902 | Use 8 bits per Color_ARGB component using unsigned integer format. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 903 | ## |
| 904 | #Const kF16 1 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 905 | 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] | 906 | ## |
| 907 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 908 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 909 | ## |
| 910 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 911 | #SeeAlso MakeFromPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 912 | |
| 913 | #Enum ## |
| 914 | |
| 915 | # ------------------------------------------------------------------------------ |
| 916 | |
| 917 | #Method static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions, |
| 918 | const SkMatrix* matrix, const SkPaint* paint, |
| 919 | BitDepth bitDepth, |
| 920 | sk_sp<SkColorSpace> colorSpace) |
| 921 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 922 | Creates Image from picture. Returned Image width and height are set by dimensions. |
| 923 | Image draws picture with matrix and paint, set to bitDepth and colorSpace. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 924 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 925 | If matrix is nullptr, draws with identity Matrix. If paint is nullptr, draws |
| 926 | with default Paint. colorSpace may be nullptr. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 927 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 928 | #Param picture stream of drawing commands ## |
| 929 | #Param dimensions width and height ## |
| 930 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 931 | #Param paint Paint to apply transparency, filtering, and so on; may be nullptr ## |
| 932 | #Param bitDepth 8 bit integer or 16 bit float: per component ## |
| 933 | #Param colorSpace range of colors; may be nullptr ## |
| 934 | |
| 935 | #Return created Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 936 | |
| 937 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 938 | SkPaint paint; |
| 939 | SkPictureRecorder recorder; |
| 940 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 941 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 942 | paint.setColor(color); |
| 943 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 944 | recordingCanvas->translate(10, 10); |
| 945 | recordingCanvas->scale(1.2f, 1.4f); |
| 946 | } |
| 947 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 948 | int x = 0, y = 0; |
| 949 | for (auto alpha : { 70, 140, 210 } ) { |
| 950 | paint.setAlpha(alpha); |
| 951 | auto srgbColorSpace = SkColorSpace::MakeSRGB(); |
| 952 | sk_sp<SkImage> image = SkImage::MakeFromPicture(playback, {50, 50}, nullptr, &paint, |
| 953 | SkImage::BitDepth::kU8, srgbColorSpace); |
| 954 | canvas->drawImage(image, x, y); |
| 955 | x += 70; y += 70; |
| 956 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 957 | ## |
| 958 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 959 | #SeeAlso SkCanvas::drawPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 960 | |
| 961 | #Method ## |
| 962 | |
| 963 | # ------------------------------------------------------------------------------ |
| 964 | |
| 965 | #Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer, |
| 966 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 967 | sk_sp<SkColorSpace> colorSpace = nullptr) |
| 968 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 969 | #Bug 7447 ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 970 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 971 | Creates Image from Android hardware buffer. |
| 972 | Returned Image takes a reference on the buffer. |
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 | 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] | 975 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 976 | #Param hardwareBuffer AHardwareBuffer Android hardware buffer ## |
| 977 | #Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 978 | kPremul_SkAlphaType, kUnpremul_SkAlphaType |
| 979 | ## |
| 980 | #Param colorSpace range of colors; may be nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 981 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 982 | #Return created Image, or nullptr ## |
| 983 | |
| 984 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 985 | ## |
| 986 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 987 | #SeeAlso MakeFromRaster |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 988 | |
| 989 | #Method ## |
| 990 | |
| 991 | # ------------------------------------------------------------------------------ |
| 992 | |
| 993 | #Method int width() const |
| 994 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 995 | Returns pixel count in each row. |
| 996 | |
| 997 | #Return pixel width in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 998 | |
| 999 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1000 | #Image 4 |
| 1001 | #Height 168 |
| 1002 | canvas->translate(10, 10); |
| 1003 | canvas->drawImage(image, 0, 0); |
| 1004 | canvas->translate(0, image->height()); |
| 1005 | SkPaint paint; |
| 1006 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1007 | canvas->drawLine(0, 10, image->width(), 10, paint); |
| 1008 | canvas->drawString("width", image->width() / 2, 25, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1009 | ## |
| 1010 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1011 | #SeeAlso dimensions() height() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1012 | |
| 1013 | #Method ## |
| 1014 | |
| 1015 | # ------------------------------------------------------------------------------ |
| 1016 | |
| 1017 | #Method int height() const |
| 1018 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1019 | Returns pixel row count. |
| 1020 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1021 | #Return pixel height in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1022 | |
| 1023 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1024 | #Image 4 |
| 1025 | #Height 148 |
| 1026 | canvas->translate(10, 10); |
| 1027 | canvas->drawImage(image, 0, 0); |
| 1028 | canvas->translate(image->width(), 0); |
| 1029 | SkPaint paint; |
| 1030 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 1031 | paint.setVerticalText(true); |
| 1032 | canvas->drawLine(10, 0, 10, image->height(), paint); |
| 1033 | canvas->drawString("height", 25, image->height() / 2, paint);## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1034 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1035 | #SeeAlso dimensions() width() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1036 | |
| 1037 | #Method ## |
| 1038 | |
| 1039 | # ------------------------------------------------------------------------------ |
| 1040 | |
| 1041 | #Method SkISize dimensions() const |
| 1042 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1043 | Returns ISize { width(), height() }. |
| 1044 | |
| 1045 | #Return integral size of width() and height() ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1046 | |
| 1047 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1048 | #Image 4 |
| 1049 | SkISize dimensions = image->dimensions(); |
| 1050 | SkIRect bounds = image->bounds(); |
| 1051 | SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions); |
| 1052 | SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1053 | ## |
| 1054 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1055 | #SeeAlso height() width() bounds() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1056 | |
| 1057 | #Method ## |
| 1058 | |
| 1059 | # ------------------------------------------------------------------------------ |
| 1060 | |
| 1061 | #Method SkIRect bounds() const |
| 1062 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1063 | Returns IRect { 0, 0, width(), height() }. |
| 1064 | |
| 1065 | #Return integral rectangle from origin to width() and height() ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1066 | |
| 1067 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1068 | #Height 128 |
| 1069 | #Image 4 |
| 1070 | canvas->scale(.5f, .5f); |
| 1071 | SkIRect bounds = image->bounds(); |
| 1072 | for (int x : { 0, image->width() } ) { |
| 1073 | for (int y : { 0, image->height() } ) { |
| 1074 | canvas->drawImage(image, x, y); |
| 1075 | } |
| 1076 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1077 | ## |
| 1078 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1079 | #SeeAlso dimensions() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1080 | |
| 1081 | #Method ## |
| 1082 | |
| 1083 | # ------------------------------------------------------------------------------ |
| 1084 | |
| 1085 | #Method uint32_t uniqueID() const |
| 1086 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1087 | Returns value unique to image. Image contents cannot change after Image is |
| 1088 | created. Any operation to create a new Image will receive generate a new |
| 1089 | unique number. |
| 1090 | |
| 1091 | #Return unique identifier ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1092 | |
| 1093 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1094 | #Image 5 |
| 1095 | #Height 156 |
| 1096 | sk_sp<SkImage> subset = image->makeSubset({10, 20, 90, 100}); |
| 1097 | canvas->drawImage(image, 0, 0); |
| 1098 | canvas->drawImage(subset, 128, 0); |
| 1099 | SkPaint paint; |
| 1100 | SkString s; |
| 1101 | s.printf("original id: %d", image->uniqueID()); |
| 1102 | canvas->drawString(s, 20, image->height() + 20, paint); |
| 1103 | s.printf("subset id: %d", subset->uniqueID()); |
| 1104 | canvas->drawString(s, 148, subset->height() + 20, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1105 | ## |
| 1106 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1107 | #SeeAlso isLazyGenerated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1108 | |
| 1109 | #Method ## |
| 1110 | |
| 1111 | # ------------------------------------------------------------------------------ |
| 1112 | |
| 1113 | #Method SkAlphaType alphaType() const |
| 1114 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1115 | Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, |
| 1116 | kPremul_SkAlphaType, kUnpremul_SkAlphaType. |
| 1117 | |
| 1118 | Alpha_Type returned was a parameter to an Image constructor, |
| 1119 | or was parsed from encoded data. |
| 1120 | |
| 1121 | #Return Alpha_Type in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1122 | |
| 1123 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1124 | #Image 4 |
| 1125 | #Height 156 |
| 1126 | const char* alphaTypeStr[] = { "Unknown", "Opaque", "Premul", "Unpremul" }; |
| 1127 | SkAlphaType alphaType = image->alphaType(); |
| 1128 | canvas->drawImage(image, 0, 0); |
| 1129 | SkPaint paint; |
| 1130 | canvas->drawString(alphaTypeStr[(int) alphaType], 20, image->height() + 20, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1131 | ## |
| 1132 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1133 | #SeeAlso SkImageInfo::alphaType |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1134 | |
| 1135 | #Method ## |
| 1136 | |
| 1137 | # ------------------------------------------------------------------------------ |
| 1138 | |
| 1139 | #Method SkColorSpace* colorSpace() const |
| 1140 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1141 | Returns Color_Space, the range of colors, associated with Image. The |
| 1142 | reference count of Color_Space is unchanged. The returned Color_Space is |
| 1143 | immutable. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1144 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1145 | Color_Space returned was a parameter to an Image constructor, |
| 1146 | or was parsed from encoded data. Color_Space may be ignored when |
| 1147 | drawing Image, and when drawing into Surface constructed with Color_Space. |
| 1148 | |
| 1149 | #Return Color_Space in Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1150 | |
| 1151 | #Example |
| 1152 | // incomplete |
| 1153 | ## |
| 1154 | |
| 1155 | #SeeAlso incomplete |
| 1156 | |
| 1157 | #Method ## |
| 1158 | |
| 1159 | # ------------------------------------------------------------------------------ |
| 1160 | |
| 1161 | #Method sk_sp<SkColorSpace> refColorSpace() const |
| 1162 | |
| 1163 | #Return incomplete ## |
| 1164 | |
| 1165 | #Example |
| 1166 | // incomplete |
| 1167 | ## |
| 1168 | |
| 1169 | #SeeAlso incomplete |
| 1170 | |
| 1171 | #Method ## |
| 1172 | |
| 1173 | # ------------------------------------------------------------------------------ |
| 1174 | |
| 1175 | #Method bool isAlphaOnly() const |
| 1176 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1177 | Returns true if Image pixels represent transparency only. If true, each pixel |
| 1178 | is packed in 8 bits as defined by kAlpha_8_SkColorType. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1179 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1180 | #Return true if pixels represent a transparency mask ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1181 | |
| 1182 | #Example |
| 1183 | // incomplete |
| 1184 | ## |
| 1185 | |
| 1186 | #SeeAlso incomplete |
| 1187 | |
| 1188 | #Method ## |
| 1189 | |
| 1190 | # ------------------------------------------------------------------------------ |
| 1191 | |
| 1192 | #Method bool isOpaque() const |
| 1193 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1194 | Returns if all pixels ignore any Alpha value and are treated as fully opaque. |
| 1195 | |
| 1196 | #Return true if Alpha_Type is kOpaque_SkAlphaType ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1197 | |
| 1198 | #Example |
| 1199 | // incomplete |
| 1200 | ## |
| 1201 | |
| 1202 | #SeeAlso incomplete |
| 1203 | |
| 1204 | #Method ## |
| 1205 | |
| 1206 | # ------------------------------------------------------------------------------ |
| 1207 | |
| 1208 | #Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2, |
| 1209 | const SkMatrix* localMatrix = nullptr) const |
| 1210 | |
| 1211 | #Param tileMode1 incomplete ## |
| 1212 | #Param tileMode2 incomplete ## |
| 1213 | #Param localMatrix incomplete ## |
| 1214 | |
| 1215 | #Return incomplete ## |
| 1216 | |
| 1217 | #Example |
| 1218 | // incomplete |
| 1219 | ## |
| 1220 | |
| 1221 | #SeeAlso incomplete |
| 1222 | |
| 1223 | #Method ## |
| 1224 | |
| 1225 | # ------------------------------------------------------------------------------ |
| 1226 | |
| 1227 | #Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const |
| 1228 | |
| 1229 | Helper version of makeShader() that specifies SkShader::kClamp_TileMode. |
| 1230 | |
| 1231 | #Param localMatrix incomplete ## |
| 1232 | |
| 1233 | #Return incomplete ## |
| 1234 | |
| 1235 | #Example |
| 1236 | // incomplete |
| 1237 | ## |
| 1238 | |
| 1239 | #SeeAlso incomplete |
| 1240 | |
| 1241 | #Method ## |
| 1242 | |
| 1243 | # ------------------------------------------------------------------------------ |
| 1244 | |
| 1245 | #Method bool peekPixels(SkPixmap* pixmap) const |
| 1246 | |
| 1247 | If the image has direct access to its pixels (i.e. they are in local RAM) |
| 1248 | return true, and if not null, return in the pixmap parameter the info about the |
| 1249 | images pixels. |
| 1250 | On failure, return false and ignore the pixmap parameter. |
| 1251 | |
| 1252 | #Param pixmap incomplete ## |
| 1253 | |
| 1254 | #Return incomplete ## |
| 1255 | |
| 1256 | #Example |
| 1257 | // incomplete |
| 1258 | ## |
| 1259 | |
| 1260 | #SeeAlso incomplete |
| 1261 | |
| 1262 | #Method ## |
| 1263 | |
| 1264 | # ------------------------------------------------------------------------------ |
| 1265 | |
| 1266 | #Method GrTexture* getTexture() const |
| 1267 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1268 | Deprecated. |
| 1269 | |
| 1270 | #Deprecated |
| 1271 | ## |
| 1272 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1273 | #Private |
| 1274 | currently used by Canvas2DLayerBridge in Chromium. |
| 1275 | ## |
| 1276 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1277 | #Method ## |
| 1278 | |
| 1279 | # ------------------------------------------------------------------------------ |
| 1280 | |
| 1281 | #Method bool isTextureBacked() const |
| 1282 | |
| 1283 | Returns true if the image is texture backed. |
| 1284 | |
| 1285 | #Return incomplete ## |
| 1286 | |
| 1287 | #Example |
| 1288 | // incomplete |
| 1289 | ## |
| 1290 | |
| 1291 | #SeeAlso incomplete |
| 1292 | |
| 1293 | #Method ## |
| 1294 | |
| 1295 | # ------------------------------------------------------------------------------ |
| 1296 | |
| 1297 | #Method bool isValid(GrContext* context) const |
| 1298 | |
| 1299 | Returns true if Image can be drawn. If context |
| 1300 | is nullptr, tests if Image draws on Raster_Surface; Otherwise, tests if Image |
| 1301 | draws on GPU_Surface associated with context. |
| 1302 | |
| 1303 | Texture-backed images may become invalid if their underlying GrContext is abandoned. Some |
| 1304 | generator-backed images may be invalid for CPU and/or GPU. |
| 1305 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1306 | #Param context GPU_Context ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1307 | |
| 1308 | #Return incomplete ## |
| 1309 | |
| 1310 | #Example |
| 1311 | // incomplete |
| 1312 | ## |
| 1313 | |
| 1314 | #SeeAlso incomplete |
| 1315 | |
| 1316 | #Method ## |
| 1317 | |
| 1318 | # ------------------------------------------------------------------------------ |
| 1319 | |
| 1320 | #Method GrBackendObject getTextureHandle(bool flushPendingGrContextIO, |
| 1321 | GrSurfaceOrigin* origin = nullptr) const |
| 1322 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1323 | Retrieves the back-end API handle of texture. If flushPendingGrContextIO is true, |
| 1324 | complete deferred I/O operations. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1325 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1326 | If origin in not nullptr, copies location of content drawn into Image. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1327 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1328 | #Param flushPendingGrContextIO flag to flush outstanding requests ## |
| 1329 | #Param origin storage for one of: kTopLeft_GrSurfaceOrigin, |
| 1330 | kBottomLeft_GrSurfaceOrigin; or nullptr |
| 1331 | ## |
| 1332 | |
| 1333 | #Return back-end API texture handle ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1334 | |
| 1335 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1336 | #Image 3 |
| 1337 | #Platform gpu |
| 1338 | GrContext* context = canvas->getGrContext(); |
| 1339 | if (!context) { |
| 1340 | return; |
| 1341 | } |
| 1342 | SkPaint paint; |
| 1343 | paint.setAntiAlias(true); |
| 1344 | SkString str; |
| 1345 | int y = 0; |
| 1346 | for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) { |
| 1347 | sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context, |
| 1348 | backEndTexture, origin, kPremul_SkAlphaType, nullptr)); |
| 1349 | GrSurfaceOrigin readBackOrigin; |
| 1350 | GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin); |
| 1351 | str.printf("readBackHandle: %x", readBackHandle); |
| 1352 | canvas->drawString(str, 5, y += 20, paint); |
| 1353 | str.printf("origin: k%s_GrSurfaceOrigin", readBackOrigin ? "BottomLeft" : "TopLeft"); |
| 1354 | canvas->drawString(str, 5, y += 20, paint); |
| 1355 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1356 | ## |
| 1357 | |
| 1358 | #SeeAlso incomplete |
| 1359 | |
| 1360 | #Method ## |
| 1361 | |
| 1362 | # ------------------------------------------------------------------------------ |
| 1363 | |
| 1364 | #Enum CachingHint |
| 1365 | |
| 1366 | #Code |
| 1367 | enum CachingHint { |
| 1368 | kAllow_CachingHint, |
| 1369 | kDisallow_CachingHint, |
| 1370 | }; |
| 1371 | ## |
| 1372 | |
| 1373 | Hints to image calls where the system might cache computed intermediates (e.g. the results |
| 1374 | of decoding or a read-back from the GPU. Passing kAllow_CachingHint signals that the system's default |
| 1375 | behavior is fine. Passing kDisallow_CachingHint signals that caching should be avoided. |
| 1376 | |
| 1377 | #Const kAllow_CachingHint 0 |
| 1378 | ## |
| 1379 | #Const kDisallow_CachingHint 1 |
| 1380 | ## |
| 1381 | |
| 1382 | #Example |
| 1383 | // incomplete |
| 1384 | ## |
| 1385 | |
| 1386 | #SeeAlso incomplete |
| 1387 | |
| 1388 | #Enum ## |
| 1389 | |
| 1390 | # ------------------------------------------------------------------------------ |
| 1391 | |
| 1392 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 1393 | int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const |
| 1394 | |
| 1395 | Copy the pixels from the image into the specified buffer (dstPixels + dstRowBytes), |
| 1396 | converting them into the requested format (dstInfo). The image pixels are read |
| 1397 | starting at the specified (srcX, srcY) location. |
| 1398 | dstInfo and (srcX, srcY) offset specifies a source rectangle: |
| 1399 | #Code |
| 1400 | SkRect srcR; |
| 1401 | srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height()); |
| 1402 | ## |
| 1403 | |
| 1404 | The source rectangle is intersected with the bounds of the image. If this intersection is not empty, |
| 1405 | then we have two sets of pixels (of equal size). Replace dstPixels with the |
| 1406 | corresponding Image pixels, performing any Color_Type/Alpha_Type transformations needed |
| 1407 | (in the case where Image and dstInfo have different Color_Types or Alpha_Types). |
| 1408 | This call can fail, returning false, for several reasons: |
| 1409 | if source rectangle does not intersect the image bounds; |
| 1410 | if the requested Color_Type/Alpha_Type cannot be converted from the image's types. |
| 1411 | |
| 1412 | #Param dstInfo incomplete ## |
| 1413 | #Param dstPixels incomplete ## |
| 1414 | #Param dstRowBytes incomplete ## |
| 1415 | #Param srcX incomplete ## |
| 1416 | #Param srcY incomplete ## |
| 1417 | #Param cachingHint incomplete ## |
| 1418 | |
| 1419 | #Return incomplete ## |
| 1420 | |
| 1421 | #Example |
| 1422 | // incomplete |
| 1423 | ## |
| 1424 | |
| 1425 | #SeeAlso incomplete |
| 1426 | |
| 1427 | #Method ## |
| 1428 | |
| 1429 | # ------------------------------------------------------------------------------ |
| 1430 | |
| 1431 | #Method bool readPixels(const SkPixmap& dst, int srcX, int srcY, |
| 1432 | CachingHint cachingHint = kAllow_CachingHint) const |
| 1433 | |
| 1434 | #Param dst incomplete ## |
| 1435 | #Param srcX incomplete ## |
| 1436 | #Param srcY incomplete ## |
| 1437 | #Param cachingHint incomplete ## |
| 1438 | |
| 1439 | #Return incomplete ## |
| 1440 | |
| 1441 | #Example |
| 1442 | // incomplete |
| 1443 | ## |
| 1444 | |
| 1445 | #SeeAlso incomplete |
| 1446 | |
| 1447 | #Method ## |
| 1448 | |
| 1449 | # ------------------------------------------------------------------------------ |
| 1450 | |
| 1451 | #Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality, |
| 1452 | CachingHint cachingHint = kAllow_CachingHint) const |
| 1453 | |
| 1454 | Copies Image pixels into dst, converting to dst Color_Type and Alpha_Type. |
| 1455 | If the conversion cannot be performed, false is returned. |
| 1456 | If dst dimensions differ from Image dimensions, Image is scaled, applying |
| 1457 | filterQuality. |
| 1458 | |
| 1459 | #Param dst incomplete ## |
| 1460 | #Param filterQuality incomplete ## |
| 1461 | #Param cachingHint incomplete ## |
| 1462 | |
| 1463 | #Return incomplete ## |
| 1464 | |
| 1465 | #Example |
| 1466 | // incomplete |
| 1467 | ## |
| 1468 | |
| 1469 | #SeeAlso incomplete |
| 1470 | |
| 1471 | #Method ## |
| 1472 | |
| 1473 | # ------------------------------------------------------------------------------ |
| 1474 | |
| 1475 | #Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const |
| 1476 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1477 | Encodes Image pixels, returning result as SkData. |
| 1478 | |
| 1479 | Returns nullptr if encoding fails, or encodedImageFormat is not supported. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1480 | |
| 1481 | #Param encodedImageFormat incomplete ## |
| 1482 | #Param quality incomplete ## |
| 1483 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1484 | #Return encoded Image, or nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1485 | |
| 1486 | #Example |
| 1487 | // incomplete |
| 1488 | ## |
| 1489 | |
| 1490 | #SeeAlso incomplete |
| 1491 | |
| 1492 | #Method ## |
| 1493 | |
| 1494 | # ------------------------------------------------------------------------------ |
| 1495 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1496 | #Method sk_sp<SkData> encodeToData() const |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1497 | |
| 1498 | Encodes Image and returns result as SkData. Will reuse existing encoded data |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1499 | if present, as returned by refEncodedData. If encoded data is missing or invalid, |
| 1500 | Image is encoded as PNG. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1501 | |
| 1502 | Returns nullptr if existing encoded data is missing or invalid and |
| 1503 | encoding fails. |
| 1504 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1505 | #Return incomplete ## |
| 1506 | |
| 1507 | #Example |
| 1508 | // incomplete |
| 1509 | ## |
| 1510 | |
| 1511 | #SeeAlso incomplete |
| 1512 | |
| 1513 | #Method ## |
| 1514 | |
| 1515 | # ------------------------------------------------------------------------------ |
| 1516 | |
| 1517 | #Method sk_sp<SkData> refEncodedData() const |
| 1518 | |
| 1519 | If the image already has its contents in encoded form (e.g. PNG or JPEG), return that |
| 1520 | as SkData. If the image does not already has its contents in encoded form, return nullptr. |
| 1521 | |
| 1522 | To force the image to return its contents as encoded data, call encodeToData. |
| 1523 | |
| 1524 | #Return incomplete ## |
| 1525 | |
| 1526 | #Example |
| 1527 | // incomplete |
| 1528 | ## |
| 1529 | |
| 1530 | #SeeAlso incomplete |
| 1531 | |
| 1532 | #Method ## |
| 1533 | |
| 1534 | # ------------------------------------------------------------------------------ |
| 1535 | |
| 1536 | #Method const char* toString(SkString* string) const |
| 1537 | |
| 1538 | #Param string incomplete ## |
| 1539 | |
| 1540 | #Return incomplete ## |
| 1541 | |
| 1542 | #Example |
| 1543 | // incomplete |
| 1544 | ## |
| 1545 | |
| 1546 | #SeeAlso incomplete |
| 1547 | |
| 1548 | #Method ## |
| 1549 | |
| 1550 | # ------------------------------------------------------------------------------ |
| 1551 | |
| 1552 | #Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const |
| 1553 | |
| 1554 | Return a new image that is a subset of this image. The underlying implementation may |
| 1555 | share the pixels, or it may make a copy. |
| 1556 | If subset does not intersect the bounds of this image, or the copy/share cannot be made, |
| 1557 | nullptr will be returned. |
| 1558 | |
| 1559 | #Param subset incomplete ## |
| 1560 | |
| 1561 | #Return incomplete ## |
| 1562 | |
| 1563 | #Example |
| 1564 | // incomplete |
| 1565 | ## |
| 1566 | |
| 1567 | #SeeAlso incomplete |
| 1568 | |
| 1569 | #Method ## |
| 1570 | |
| 1571 | # ------------------------------------------------------------------------------ |
| 1572 | |
| 1573 | #Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const |
| 1574 | |
| 1575 | Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use |
| 1576 | with surfaces that have the supplied destination color space. If no transformation is |
| 1577 | required, the returned image may be the same as this image. If this image is from a |
| 1578 | different GrContext, this will fail. |
| 1579 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1580 | #Param context GPU_Context ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1581 | #Param dstColorSpace incomplete ## |
| 1582 | |
| 1583 | #Return incomplete ## |
| 1584 | |
| 1585 | #Example |
| 1586 | // incomplete |
| 1587 | ## |
| 1588 | |
| 1589 | #SeeAlso incomplete |
| 1590 | |
| 1591 | #Method ## |
| 1592 | |
| 1593 | # ------------------------------------------------------------------------------ |
| 1594 | |
| 1595 | #Method sk_sp<SkImage> makeNonTextureImage() const |
| 1596 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1597 | Creates raster Image if Image contains GPU_Texture and raster Image , this will make a raster copy of it (or nullptr if reading back |
| 1598 | the pixels fails). Otherwise, it returns the original image. |
| 1599 | |
| 1600 | #Return incomplete ## |
| 1601 | |
| 1602 | #Example |
| 1603 | // incomplete |
| 1604 | ## |
| 1605 | |
| 1606 | #SeeAlso incomplete |
| 1607 | |
| 1608 | #Method ## |
| 1609 | |
| 1610 | # ------------------------------------------------------------------------------ |
| 1611 | |
| 1612 | #Method sk_sp<SkImage> makeRasterImage() const |
| 1613 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1614 | If the image is texture-backed this will make a raster copy of it (or nullptr if reading back |
| 1615 | the pixels fails). Otherwise, it returns the original image. |
| 1616 | |
| 1617 | #Return incomplete ## |
| 1618 | |
| 1619 | #Example |
| 1620 | // incomplete |
| 1621 | ## |
| 1622 | |
| 1623 | #SeeAlso incomplete |
| 1624 | |
| 1625 | #Method ## |
| 1626 | |
| 1627 | # ------------------------------------------------------------------------------ |
| 1628 | |
| 1629 | #Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset, |
| 1630 | const SkIRect& clipBounds, SkIRect* outSubset, |
| 1631 | SkIPoint* offset) const |
| 1632 | |
| 1633 | Apply a given image filter to this image, and return the filtered result. |
| 1634 | The subset represents the active portion of this image. The return value is similarly an |
| 1635 | SkImage, with an active subset (outSubset). This is usually used with texture-backed |
| 1636 | images, where the texture may be approx-match and thus larger than the required size. |
| 1637 | clipBounds constrains the device-space extent of the image, stored in outSubset. |
| 1638 | offset is storage, set to the amount to translate the result when drawn. |
| 1639 | If the result image cannot be created, or the result would be transparent black, null |
| 1640 | is returned, in which case the offset and outSubset parameters should be ignored by the |
| 1641 | caller. |
| 1642 | |
| 1643 | #Param filter incomplete ## |
| 1644 | #Param subset incomplete ## |
| 1645 | #Param clipBounds incomplete ## |
| 1646 | #Param outSubset incomplete ## |
| 1647 | #Param offset incomplete ## |
| 1648 | |
| 1649 | #Return incomplete ## |
| 1650 | |
| 1651 | #Example |
| 1652 | // incomplete |
| 1653 | ## |
| 1654 | |
| 1655 | #SeeAlso incomplete |
| 1656 | |
| 1657 | #Method ## |
| 1658 | |
| 1659 | # ------------------------------------------------------------------------------ |
| 1660 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1661 | #Struct DeferredTextureImageUsageParams |
| 1662 | |
| 1663 | #Code |
| 1664 | struct DeferredTextureImageUsageParams { |
| 1665 | DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality, |
| 1666 | int preScaleMipLevel); |
| 1667 | SkMatrix fMatrix; |
| 1668 | SkFilterQuality fQuality; |
| 1669 | int fPreScaleMipLevel; |
| 1670 | }; |
| 1671 | ## |
| 1672 | |
| 1673 | #Member SkMatrix fMatrix |
| 1674 | ## |
| 1675 | |
| 1676 | #Member SkFilterQuality fQuality |
| 1677 | ## |
| 1678 | |
| 1679 | #Member int fPreScaleMipLevel |
| 1680 | ## |
| 1681 | |
| 1682 | #Method DeferredTextureImageUsageParams(const SkMatrix matrix, const SkFilterQuality quality, |
| 1683 | int preScaleMipLevel) |
| 1684 | |
| 1685 | #Param matrix incomplete ## |
| 1686 | #Param quality incomplete ## |
| 1687 | #Param preScaleMipLevel incomplete ## |
| 1688 | |
| 1689 | #Return incomplete ## |
| 1690 | |
| 1691 | #Example |
| 1692 | // incomplete |
| 1693 | ## |
| 1694 | |
| 1695 | #SeeAlso incomplete |
| 1696 | |
| 1697 | ## |
| 1698 | |
| 1699 | #Example |
| 1700 | // incomplete |
| 1701 | ## |
| 1702 | |
| 1703 | #SeeAlso incomplete |
| 1704 | |
| 1705 | ## |
| 1706 | |
| 1707 | #Method size_t getDeferredTextureImageData(const GrContextThreadSafeProxy& contextThreadSafeProxy, |
| 1708 | const DeferredTextureImageUsageParams deferredTextureImageUsageParams[], |
| 1709 | int paramCnt, |
| 1710 | void* buffer, |
| 1711 | SkColorSpace* dstColorSpace = nullptr, |
| 1712 | SkColorType dstColorType = kN32_SkColorType) const |
| 1713 | |
| 1714 | This method allows clients to capture the data necessary to turn a SkImage into a texture- |
| 1715 | backed image. If the original image is codec-backed this will decode into a format optimized |
| 1716 | for the context represented by the proxy. This method is thread safe with respect to the |
| 1717 | GrContext whence the proxy came. Clients allocate and manage the storage of the deferred |
| 1718 | texture data and control its lifetime. No cleanup is required, thus it is safe to simply free |
| 1719 | the memory out from under the data. |
| 1720 | |
| 1721 | The same method is used both for getting the size necessary for pre-uploaded texture data |
| 1722 | and for retrieving the data. The params array represents the set of draws over which to |
| 1723 | optimize the pre-upload data. |
| 1724 | |
| 1725 | When called with a null buffer this returns the size that the client must allocate in order |
| 1726 | to create deferred texture data for this image (or zero if this is an inappropriate |
| 1727 | candidate). The buffer allocated by the client should be 8 byte aligned. |
| 1728 | |
| 1729 | When buffer is not null this fills in the deferred texture data for this image in the |
| 1730 | provided buffer (assuming this is an appropriate candidate image and the buffer is |
| 1731 | appropriately aligned). Upon success the size written is returned, otherwise 0. |
| 1732 | |
| 1733 | dstColorSpace is the color space of the surface where this texture will ultimately be used. |
| 1734 | If the method determines that mip-maps are needed, this helps determine the correct strategy |
| 1735 | for building them (gamma-correct or not). |
| 1736 | |
| 1737 | dstColorType is the color type of the surface where this texture will ultimately be used. |
| 1738 | This determines the format with which the image will be uploaded to the GPU. If dstColorType |
| 1739 | does not support color spaces (low bit depth types such as kARGB_4444_SkColorType), |
| 1740 | then dstColorSpace must be null. |
| 1741 | |
| 1742 | #Param contextThreadSafeProxy incomplete ## |
| 1743 | #Param deferredTextureImageUsageParams incomplete ## |
| 1744 | #Param paramCnt incomplete ## |
| 1745 | #Param buffer incomplete ## |
| 1746 | #Param dstColorSpace incomplete ## |
| 1747 | #Param dstColorType incomplete ## |
| 1748 | |
| 1749 | #Return incomplete ## |
| 1750 | |
| 1751 | #Example |
| 1752 | // incomplete |
| 1753 | ## |
| 1754 | |
| 1755 | #SeeAlso incomplete |
| 1756 | |
| 1757 | ## |
| 1758 | |
| 1759 | #Method static sk_sp<SkImage> MakeFromDeferredTextureImageData(GrContext* context, const void* data, |
| 1760 | SkBudgeted budgeted) |
| 1761 | |
| 1762 | Returns a texture-backed image from data produced in SkImage::getDeferredTextureImageData. |
| 1763 | The context must be the context that provided the proxy passed to |
| 1764 | getDeferredTextureImageData. |
| 1765 | |
| 1766 | #Param context GPU_Context ## |
| 1767 | #Param data incomplete ## |
| 1768 | #Param budgeted incomplete ## |
| 1769 | |
| 1770 | #Return incomplete ## |
| 1771 | |
| 1772 | #Example |
| 1773 | // incomplete |
| 1774 | ## |
| 1775 | |
| 1776 | #SeeAlso incomplete |
| 1777 | |
| 1778 | ## |
| 1779 | |
| 1780 | # ------------------------------------------------------------------------------ |
| 1781 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1782 | #Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc |
| 1783 | |
| 1784 | ## |
| 1785 | |
| 1786 | # ------------------------------------------------------------------------------ |
| 1787 | |
| 1788 | #Method static bool MakeBackendTextureFromSkImage(GrContext* context, |
| 1789 | sk_sp<SkImage> image, |
| 1790 | GrBackendTexture* backendTexture, |
| 1791 | BackendTextureReleaseProc* backendTextureReleaseProc) |
| 1792 | |
| 1793 | Creates a GrBackendTexture from the provided SkImage. Returns true on success. The |
| 1794 | GrBackendTexture and BackendTextureReleaseProc are populated on success. It is the callers |
| 1795 | responsibility to call the BackendTextureReleaseProc once they have deleted the texture. |
| 1796 | Note that the BackendTextureReleaseProc allows Skia to clean up auxiliary data related |
| 1797 | to the GrBackendTexture, and is not a substitute for the client deleting the GrBackendTexture |
| 1798 | themselves. |
| 1799 | |
| 1800 | If image is both texture backed and singly referenced; that is, its only |
| 1801 | reference was transferred using std::move(): image is returned in backendTexture |
| 1802 | without conversion or making a copy. |
| 1803 | |
| 1804 | If the SkImage is not texture backed, this function will generate a texture with the image's |
| 1805 | contents and return that. |
| 1806 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1807 | #Param context GPU_Context ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1808 | #Param image incomplete ## |
| 1809 | #Param backendTexture incomplete ## |
| 1810 | #Param backendTextureReleaseProc incomplete ## |
| 1811 | |
| 1812 | #Return incomplete ## |
| 1813 | |
| 1814 | #Example |
| 1815 | // incomplete |
| 1816 | ## |
| 1817 | |
| 1818 | #SeeAlso incomplete |
| 1819 | |
| 1820 | #Method ## |
| 1821 | |
| 1822 | # ------------------------------------------------------------------------------ |
| 1823 | |
| 1824 | #Enum LegacyBitmapMode |
| 1825 | |
| 1826 | #Code |
| 1827 | enum LegacyBitmapMode { |
| 1828 | kRO_LegacyBitmapMode, |
| 1829 | kRW_LegacyBitmapMode, |
| 1830 | }; |
| 1831 | ## |
| 1832 | |
| 1833 | Helper functions to convert to SkBitmap |
| 1834 | |
| 1835 | #Const kRO_LegacyBitmapMode 0 |
| 1836 | ## |
| 1837 | #Const kRW_LegacyBitmapMode 1 |
| 1838 | ## |
| 1839 | |
| 1840 | #Example |
| 1841 | // incomplete |
| 1842 | ## |
| 1843 | |
| 1844 | #SeeAlso incomplete |
| 1845 | |
| 1846 | #Enum ## |
| 1847 | |
| 1848 | # ------------------------------------------------------------------------------ |
| 1849 | |
| 1850 | #Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const |
| 1851 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1852 | Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is kRO_LegacyBitmapMode, |
| 1853 | returned bitmap is read-only and immutable. |
| 1854 | Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if Bitmap |
| 1855 | write did not succeed. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1856 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1857 | #Param bitmap storage for legacy Bitmap ## |
| 1858 | #Param legacyBitmapMode one of: kRO_LegacyBitmapMode, kRW_LegacyBitmapMode ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1859 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 1860 | #Return true if Bitmap was created ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1861 | |
| 1862 | #Example |
| 1863 | // incomplete |
| 1864 | ## |
| 1865 | |
| 1866 | #SeeAlso incomplete |
| 1867 | |
| 1868 | #Method ## |
| 1869 | |
| 1870 | # ------------------------------------------------------------------------------ |
| 1871 | |
| 1872 | #Method bool isLazyGenerated() const |
| 1873 | |
| 1874 | Returns true if Image is backed by an image-generator or other service that creates |
| 1875 | and caches its pixels or texture on-demand. |
| 1876 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1877 | #Return true if Image is created as needed ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1878 | |
| 1879 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1880 | #Height 80 |
| 1881 | #Function |
| 1882 | class TestImageGenerator : public SkImageGenerator { |
| 1883 | public: |
| 1884 | TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {} |
| 1885 | ~TestImageGenerator() override {} |
| 1886 | protected: |
| 1887 | bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes, |
| 1888 | const Options& options) override { |
| 1889 | SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr); |
| 1890 | for (int y = 0; y < info.height(); ++y) { |
| 1891 | for (int x = 0; x < info.width(); ++x) { |
| 1892 | pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811; |
| 1893 | } |
| 1894 | } |
| 1895 | return true; |
| 1896 | } |
| 1897 | }; |
| 1898 | ## |
| 1899 | void draw(SkCanvas* canvas) { |
| 1900 | auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator()); |
| 1901 | sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen))); |
| 1902 | SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy"); |
| 1903 | canvas->scale(8, 8); |
| 1904 | canvas->drawImage(image, 0, 0, nullptr); |
| 1905 | SkPaint paint; |
| 1906 | paint.setTextSize(4); |
| 1907 | canvas->drawString(lazy, 2, 5, paint); |
| 1908 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1909 | ## |
| 1910 | |
| 1911 | #SeeAlso incomplete |
| 1912 | |
| 1913 | #Method ## |
| 1914 | |
| 1915 | # ------------------------------------------------------------------------------ |
| 1916 | |
| 1917 | #Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target, |
| 1918 | SkTransferFunctionBehavior premulBehavior) const |
| 1919 | |
| 1920 | If target is supported, returns an SkImage in target color space. |
| 1921 | Otherwise, returns nullptr. |
| 1922 | This will leave the image as is if it already in target color space. |
| 1923 | Otherwise, it will convert the pixels from Image color space to target |
| 1924 | color space. If this->colorSpace() is nullptr, Image color space will be |
| 1925 | treated as sRGB. |
| 1926 | |
| 1927 | If premulBehavior is SkTransferFunctionBehavior::kRespect: converts Image |
| 1928 | pixels to a linear space before converting to match destination Color_Type |
| 1929 | and Color_Space. |
| 1930 | If premulBehavior is SkTransferFunctionBehavior::kIgnore: Image |
| 1931 | pixels are treated as if they are linear, regardless of how they are encoded. |
| 1932 | |
| 1933 | #Param target incomplete ## |
| 1934 | #Param premulBehavior incomplete ## |
| 1935 | |
| 1936 | #Return incomplete ## |
| 1937 | |
| 1938 | #Example |
| 1939 | // incomplete |
| 1940 | ## |
| 1941 | |
| 1942 | #SeeAlso incomplete |
| 1943 | |
| 1944 | #Method ## |
| 1945 | |
| 1946 | #Class SkImage ## |
| 1947 | |
| 1948 | #Topic Image ## |