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