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