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