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