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