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