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