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