Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1 | #Topic Image |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2 | #Alias Image_Reference ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 3 | |
| 4 | #Class SkImage |
| 5 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 6 | #Code |
| 7 | #Populate |
| 8 | ## |
| 9 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 10 | Image describes a two dimensional array of pixels to draw. The pixels may be |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 11 | decoded in a Raster_Bitmap, encoded in a Picture or compressed data stream, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 12 | or located in GPU memory as a GPU_Texture. |
| 13 | |
| 14 | Image cannot be modified after it is created. Image may allocate additional |
| 15 | storage as needed; for instance, an encoded Image may decode when drawn. |
| 16 | |
| 17 | Image width and height are greater than zero. Creating an Image with zero width |
| 18 | or height returns Image equal to nullptr. |
| 19 | |
| 20 | Image may be created from Bitmap, Pixmap, Surface, Picture, encoded streams, |
| 21 | GPU_Texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 22 | include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 23 | vary with platform. |
| 24 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 25 | #Subtopic Raster_Image |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 26 | #Alias Raster_Image ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 27 | #Line # pixels decoded in Raster_Bitmap ## |
| 28 | Raster_Image pixels are decoded in a Raster_Bitmap. These pixels may be read |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 29 | directly and in most cases written to, although edited pixels may not be drawn |
| 30 | if Image has been copied internally. |
| 31 | ## |
| 32 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 33 | #Subtopic Texture_Image |
| 34 | #Line # pixels located on GPU ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 35 | Texture_Image are located on GPU and pixels are not accessible. Texture_Image |
| 36 | are allocated optimally for best performance. Raster_Image may |
| 37 | be drawn to GPU_Surface, but pixels are uploaded from CPU to GPU downgrading |
| 38 | performance. |
| 39 | ## |
| 40 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 41 | #Subtopic Lazy_Image |
| 42 | #Line # deferred pixel buffer ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 43 | Lazy_Image defer allocating buffer for Image pixels and decoding stream until |
| 44 | Image is drawn. Lazy_Image caches result if possible to speed up repeated |
| 45 | drawing. |
| 46 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 47 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 48 | # ------------------------------------------------------------------------------ |
| 49 | |
| 50 | #Method static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 51 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 52 | #Line # creates Image from Pixmap and copied pixels ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 53 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 54 | |
| 55 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 56 | #Height 50 |
| 57 | #Description |
| 58 | Draw a five by five bitmap, and draw a copy in an Image. Editing the pixmap |
| 59 | alters the bitmap draw, but does not alter the Image draw since the Image |
| 60 | contains a copy of the pixels. |
| 61 | ## |
| 62 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 63 | { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, |
| 64 | { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, |
| 65 | { 0x90, 0x81, 0xC5, 0x71, 0x33 }, |
| 66 | { 0x75, 0x55, 0x44, 0x40, 0x30 }}; |
| 67 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 68 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 69 | SkBitmap bitmap; |
| 70 | bitmap.installPixels(pixmap); |
| 71 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 72 | *pixmap.writable_addr8(2, 2) = 0x00; |
| 73 | canvas->scale(10, 10); |
| 74 | canvas->drawBitmap(bitmap, 0, 0); |
| 75 | canvas->drawImage(image, 10, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 76 | ## |
| 77 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 78 | #SeeAlso MakeRasterData MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 79 | |
| 80 | #Method ## |
| 81 | |
| 82 | # ------------------------------------------------------------------------------ |
| 83 | |
Cary Clark | cc45cc7 | 2018-05-15 16:06:12 -0400 | [diff] [blame] | 84 | #Method static sk_sp<SkImage> MakeRasterData(const SkImageInfo& info, sk_sp<SkData> pixels, size_t rowBytes) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 85 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 86 | #Line # creates Image from Image_Info and shared pixels ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 87 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 88 | |
| 89 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 90 | #Image 3 |
| 91 | size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType); |
| 92 | sk_sp<SkData> data = SkData::MakeUninitialized(rowBytes * image->height()); |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 93 | SkImageInfo dstInfo = SkImageInfo::MakeN32(image->width(), image->height(), |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 94 | kPremul_SkAlphaType); |
| 95 | image->readPixels(dstInfo, data->writable_data(), rowBytes, 0, 0, SkImage::kAllow_CachingHint); |
| 96 | sk_sp<SkImage> raw = SkImage::MakeRasterData(dstInfo.makeColorType(kRGBA_8888_SkColorType), |
| 97 | data, rowBytes); |
| 98 | canvas->drawImage(image, 0, 0); |
| 99 | canvas->drawImage(raw.get(), 128, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 100 | ## |
| 101 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 102 | #SeeAlso MakeRasterCopy MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 103 | |
| 104 | #Method ## |
| 105 | |
| 106 | # ------------------------------------------------------------------------------ |
| 107 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 108 | #Typedef void* ReleaseContext |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 109 | #Line # parameter type for MakeFromRaster ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 110 | |
| 111 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 112 | #Populate |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 113 | ## |
| 114 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 115 | Caller data passed to RasterReleaseProc; may be nullptr. |
| 116 | |
| 117 | #SeeAlso MakeFromRaster RasterReleaseProc |
| 118 | |
| 119 | ## |
| 120 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 121 | #Typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext) |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 122 | #Line # parameter type for MakeFromRaster ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 123 | |
| 124 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 125 | #Populate |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 126 | ## |
| 127 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 128 | Function called when Image no longer shares pixels. ReleaseContext is |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 129 | provided by caller when Image is created, and may be nullptr. |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 130 | |
| 131 | #SeeAlso ReleaseContext MakeFromRaster |
| 132 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 133 | ## |
| 134 | |
| 135 | #Method static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap, |
| 136 | RasterReleaseProc rasterReleaseProc, |
| 137 | ReleaseContext releaseContext) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 138 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 139 | #Line # creates Image from Pixmap, with release ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 140 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 141 | |
| 142 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 143 | #Function |
| 144 | static void releaseProc(const void* pixels, SkImage::ReleaseContext context) { |
| 145 | int* countPtr = static_cast<int*>(context); |
| 146 | *countPtr += 1; |
| 147 | } |
| 148 | ## |
| 149 | |
| 150 | void draw(SkCanvas* canvas) { |
| 151 | SkColor color = 0; |
| 152 | SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), &color, 4); |
| 153 | int releaseCount = 0; |
| 154 | sk_sp<SkImage> image(SkImage::MakeFromRaster(pixmap, releaseProc, &releaseCount)); |
| 155 | SkDebugf("before reset: %d\n", releaseCount); |
| 156 | image.reset(); |
| 157 | SkDebugf("after reset: %d\n", releaseCount); |
| 158 | } |
| 159 | #StdOut |
| 160 | before reset: 0 |
| 161 | after reset: 1 |
| 162 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 163 | ## |
| 164 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 165 | #SeeAlso MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 166 | |
| 167 | #Method ## |
| 168 | |
| 169 | # ------------------------------------------------------------------------------ |
| 170 | |
| 171 | #Method static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 172 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 173 | #Line # creates Image from Bitmap, sharing or copying pixels ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 174 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 175 | |
| 176 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 177 | #Description |
| 178 | The first Bitmap is shared; writing to the pixel memory changes the first |
| 179 | Image. |
| 180 | The second Bitmap is marked immutable, and is copied; writing to the pixel |
| 181 | memory does not alter the second Image. |
| 182 | ## |
| 183 | #Height 50 |
| 184 | uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, |
| 185 | { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, |
| 186 | { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, |
| 187 | { 0x90, 0x81, 0xC5, 0x71, 0x33 }, |
| 188 | { 0x75, 0x55, 0x44, 0x40, 0x30 }}; |
| 189 | SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); |
| 190 | SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); |
| 191 | SkBitmap bitmap; |
| 192 | bitmap.installPixels(pixmap); |
| 193 | sk_sp<SkImage> image1 = SkImage::MakeFromBitmap(bitmap); |
| 194 | bitmap.setImmutable(); |
| 195 | sk_sp<SkImage> image2 = SkImage::MakeFromBitmap(bitmap); |
| 196 | *pixmap.writable_addr8(2, 2) = 0x00; |
| 197 | canvas->scale(10, 10); |
| 198 | canvas->drawImage(image1, 0, 0); |
| 199 | canvas->drawImage(image2, 10, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 200 | ## |
| 201 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 202 | #SeeAlso MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 203 | |
| 204 | #Method ## |
| 205 | |
| 206 | # ------------------------------------------------------------------------------ |
| 207 | |
| 208 | #Method static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator, |
| 209 | const SkIRect* subset = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 210 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 211 | #Line # creates Image from a stream of data ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 212 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 213 | |
| 214 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 215 | #Height 128 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 216 | #Description |
| 217 | The generator returning Picture cannot be shared; std::move transfers ownership to generated Image. |
| 218 | ## |
| 219 | SkPictureRecorder recorder; |
| 220 | recorder.beginRecording(100, 100)->drawColor(SK_ColorRED); |
| 221 | auto picture = recorder.finishRecordingAsPicture(); |
| 222 | auto gen = SkImageGenerator::MakeFromPicture({100, 100}, picture, nullptr, nullptr, |
| 223 | SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); |
| 224 | sk_sp<SkImage> image = SkImage::MakeFromGenerator(std::move(gen)); |
| 225 | canvas->drawImage(image, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 226 | ## |
| 227 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 228 | #SeeAlso MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 229 | |
| 230 | #Method ## |
| 231 | |
| 232 | # ------------------------------------------------------------------------------ |
| 233 | |
| 234 | #Method static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 235 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 236 | #Line # creates Image from encoded data ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 237 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 238 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 239 | #Example |
| 240 | #Image 3 |
| 241 | int x = 0; |
| 242 | for (int quality : { 100, 50, 10, 1} ) { |
| 243 | sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, quality); |
| 244 | sk_sp<SkImage> image = SkImage::MakeFromEncoded(encodedData); |
| 245 | canvas->drawImage(image, x, 0); |
| 246 | x += 64; |
| 247 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 248 | ## |
| 249 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 250 | #SeeAlso MakeFromGenerator |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 251 | |
| 252 | #Method ## |
| 253 | |
| 254 | # ------------------------------------------------------------------------------ |
| 255 | |
| 256 | #Typedef void (*TextureReleaseProc)(ReleaseContext releaseContext) |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 257 | #Line # parameter type for MakeFromTexture ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 258 | |
| 259 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 260 | #Populate |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 261 | ## |
| 262 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 263 | User function called when supplied texture may be deleted. |
| 264 | #SeeAlso MakeFromTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 265 | ## |
| 266 | |
| 267 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 268 | const GrBackendTexture& backendTexture, |
| 269 | GrSurfaceOrigin origin, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 270 | SkColorType colorType, |
| 271 | SkAlphaType alphaType, |
| 272 | sk_sp<SkColorSpace> colorSpace) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 273 | #In Constructors |
Cary Clark | f895a42 | 2018-02-27 09:54:21 -0500 | [diff] [blame] | 274 | #Line # creates Image from GPU_Texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 275 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 276 | |
| 277 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 278 | #Image 3 |
| 279 | #Platform gpu |
| 280 | #Height 128 |
| 281 | #Description |
| 282 | A back-end texture has been created and uploaded to the GPU outside of this example. |
| 283 | ## |
| 284 | GrContext* context = canvas->getGrContext(); |
| 285 | if (!context) { |
| 286 | return; |
| 287 | } |
| 288 | canvas->scale(.25f, .25f); |
| 289 | int x = 0; |
| 290 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 291 | sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 292 | origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr); |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 293 | canvas->drawImage(image, x, 0); |
| 294 | x += 512; |
| 295 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 296 | ## |
| 297 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 298 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 299 | |
| 300 | #Method ## |
| 301 | |
| 302 | # ------------------------------------------------------------------------------ |
| 303 | |
| 304 | #Method static sk_sp<SkImage> MakeFromTexture(GrContext* context, |
| 305 | const GrBackendTexture& backendTexture, |
| 306 | GrSurfaceOrigin origin, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 307 | SkColorType colorType, |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 308 | SkAlphaType alphaType, |
| 309 | sk_sp<SkColorSpace> colorSpace, |
| 310 | TextureReleaseProc textureReleaseProc, |
| 311 | ReleaseContext releaseContext) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 312 | #Populate |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 313 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 314 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 315 | #Platform gpu |
| 316 | #Image 4 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 317 | GrContext* context = canvas->getGrContext(); |
| 318 | if (!context) { |
| 319 | return; |
| 320 | } |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 321 | auto debugster = [](SkImage::ReleaseContext releaseContext) -> void { |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 322 | // broken |
Cary Clark | 08417bc | 2018-10-03 10:44:13 -0400 | [diff] [blame] | 323 | // *((int *) releaseContext) += 128; |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 324 | }; |
| 325 | int x = 0; |
| 326 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 327 | sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backEndTexture, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 328 | origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, debugster, &x); |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 329 | canvas->drawImage(image, x, 0); |
| 330 | x += 128; |
| 331 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 332 | ## |
| 333 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 334 | #SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 335 | |
| 336 | #Method ## |
| 337 | |
| 338 | # ------------------------------------------------------------------------------ |
| 339 | |
| 340 | #Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data, |
| 341 | bool buildMips, |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 342 | SkColorSpace* dstColorSpace, |
| 343 | bool limitToMaxTextureSize = false) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 344 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 345 | #Line # creates Image from encoded data, and uploads to GPU ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 346 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 347 | |
| 348 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 349 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 350 | #Height 64 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 351 | GrContext* context = canvas->getGrContext(); |
| 352 | sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, 100); |
| 353 | sk_sp<SkImage> image = SkImage::MakeCrossContextFromEncoded(context, |
| 354 | encodedData, false, nullptr); |
| 355 | canvas->drawImage(image, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 356 | ## |
| 357 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 358 | #SeeAlso MakeCrossContextFromPixmap |
| 359 | |
| 360 | #Method ## |
| 361 | |
| 362 | # ------------------------------------------------------------------------------ |
| 363 | |
| 364 | #Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap, |
| 365 | bool buildMips, |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 366 | SkColorSpace* dstColorSpace, |
| 367 | bool limitToMaxTextureSize = false) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 368 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 369 | #Line # creates Image from Pixmap, and uploads to GPU ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 370 | #Populate |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 371 | |
| 372 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 373 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 374 | #Height 64 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 375 | GrContext* context = canvas->getGrContext(); |
| 376 | SkPixmap pixmap; |
| 377 | if (source.peekPixels(&pixmap)) { |
| 378 | sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(context, pixmap, |
| 379 | false, nullptr); |
| 380 | canvas->drawImage(image, 0, 0); |
| 381 | } |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 382 | ## |
| 383 | |
| 384 | #SeeAlso MakeCrossContextFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 385 | |
| 386 | #Method ## |
| 387 | |
| 388 | # ------------------------------------------------------------------------------ |
| 389 | |
| 390 | #Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context, |
| 391 | const GrBackendTexture& backendTexture, |
| 392 | GrSurfaceOrigin surfaceOrigin, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 393 | SkColorType colorType, |
| 394 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 395 | sk_sp<SkColorSpace> colorSpace = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 396 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 397 | #Line # creates Image from GPU_Texture, managed internally ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 398 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 399 | |
| 400 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 401 | #Image 5 |
| 402 | #Platform gpu |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 403 | if (!canvas->getGrContext()) { |
| 404 | return; |
| 405 | } |
| 406 | canvas->scale(.5f, .5f); |
| 407 | canvas->clear(0x7f3f5f7f); |
| 408 | int x = 0, y = 0; |
| 409 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 410 | for (auto alpha : { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
| 411 | sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(canvas->getGrContext(), |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 412 | backEndTexture, origin, |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 413 | kRGBA_8888_SkColorType, alpha); |
| 414 | canvas->drawImage(image, x, y); |
| 415 | x += 160; |
| 416 | } |
| 417 | x -= 160 * 3; |
| 418 | y += 256; |
| 419 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 420 | ## |
| 421 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 422 | #SeeAlso MakeFromTexture MakeFromYUVTexturesCopy |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 423 | |
| 424 | #Method ## |
| 425 | |
| 426 | # ------------------------------------------------------------------------------ |
| 427 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 428 | #Method static sk_sp<SkImage> MakeFromYUVATexturesCopy(GrContext* context, |
| 429 | SkYUVColorSpace yuvColorSpace, |
| 430 | const GrBackendTexture yuvaTextures[], |
| 431 | const SkYUVAIndex yuvaIndices[4], |
| 432 | SkISize imageSize, |
| 433 | GrSurfaceOrigin imageOrigin, |
| 434 | sk_sp<SkColorSpace> imageColorSpace = nullptr) |
| 435 | #In Constructor |
| 436 | #Line # creates Image from YUV_ColorSpace data ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 437 | #Populate |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 438 | |
| 439 | #NoExample |
| 440 | ## |
| 441 | |
Cary Clark | 1801b94 | 2018-10-30 21:10:03 -0400 | [diff] [blame] | 442 | #SeeAlso MakeFromYUVATexturesCopyWithExternalBackend MakeFromYUVATextures |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 443 | |
| 444 | #Method ## |
| 445 | |
Cary Clark | 1801b94 | 2018-10-30 21:10:03 -0400 | [diff] [blame] | 446 | #Method static sk_sp<SkImage> MakeFromYUVATextures(GrContext* context, |
| 447 | SkYUVColorSpace yuvColorSpace, |
| 448 | const GrBackendTexture yuvaTextures[], |
| 449 | const SkYUVAIndex yuvaIndices[4], |
| 450 | SkISize imageSize, |
| 451 | GrSurfaceOrigin imageOrigin, |
| 452 | sk_sp<SkColorSpace> imageColorSpace = nullptr); |
| 453 | |
| 454 | #In Constructor |
| 455 | #Line # creates Image from YUV_ColorSpace data ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 456 | #Populate |
Cary Clark | 1801b94 | 2018-10-30 21:10:03 -0400 | [diff] [blame] | 457 | |
| 458 | #NoExample |
| 459 | ## |
| 460 | |
| 461 | #SeeAlso MakeFromYUVATexturesCopy MakeFromYUVATexturesCopyWithExternalBackend |
| 462 | |
| 463 | #Method ## |
| 464 | |
| 465 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 466 | # ------------------------------------------------------------------------------ |
| 467 | |
| 468 | #Method static sk_sp<SkImage> MakeFromYUVATexturesCopyWithExternalBackend( |
| 469 | GrContext* context, |
| 470 | SkYUVColorSpace yuvColorSpace, |
| 471 | const GrBackendTexture yuvaTextures[], |
| 472 | const SkYUVAIndex yuvaIndices[4], |
| 473 | SkISize imageSize, |
| 474 | GrSurfaceOrigin imageOrigin, |
| 475 | const GrBackendTexture& backendTexture, |
| 476 | sk_sp<SkColorSpace> imageColorSpace = nullptr) |
| 477 | #In Constructor |
| 478 | #Line # creates Image from planar YUV_ColorSpace, stored in texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 479 | #Populate |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 480 | |
| 481 | #NoExample |
| 482 | ## |
| 483 | |
Cary Clark | 1801b94 | 2018-10-30 21:10:03 -0400 | [diff] [blame] | 484 | #SeeAlso MakeFromYUVATexturesCopy MakeFromYUVATextures |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 485 | |
| 486 | #Method ## |
| 487 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 488 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 489 | const GrBackendTexture yuvTextures[3], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 490 | GrSurfaceOrigin imageOrigin, |
| 491 | sk_sp<SkColorSpace> imageColorSpace = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 492 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 493 | #Line # creates Image from YUV_ColorSpace data in three planes ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 494 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 495 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 496 | #NoExample |
| 497 | ## |
| 498 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 499 | #SeeAlso MakeFromYUVTexturesCopyWithExternalBackend MakeFromNV12TexturesCopy MakeFromYUVATexturesCopy |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 500 | |
| 501 | #Method ## |
| 502 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 503 | # ------------------------------------------------------------------------------ |
| 504 | |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 505 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopyWithExternalBackend( |
| 506 | GrContext* context, SkYUVColorSpace yuvColorSpace, |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 507 | const GrBackendTexture yuvTextures[3], GrSurfaceOrigin imageOrigin, |
| 508 | const GrBackendTexture& backendTexture, sk_sp<SkColorSpace> imageColorSpace = nullptr); |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 509 | #In Constructors |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 510 | #Line # creates Image from planar YUV_ColorSpace, stored in texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 511 | #Populate |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 512 | |
| 513 | #NoExample |
| 514 | ## |
| 515 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 516 | #SeeAlso MakeFromYUVTexturesCopy MakeFromNV12TexturesCopy MakeFromYUVATexturesCopyWithExternalBackend |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 517 | |
| 518 | #Method ## |
| 519 | |
| 520 | # ------------------------------------------------------------------------------ |
| 521 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 522 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, |
| 523 | SkYUVColorSpace yuvColorSpace, |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 524 | const GrBackendTexture nv12Textures[2], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 525 | GrSurfaceOrigin imageOrigin, |
| 526 | sk_sp<SkColorSpace> imageColorSpace = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 527 | #In Constructors |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 528 | #Line # creates Image from YUV_ColorSpace data in three planes ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 529 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 530 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 531 | #NoExample |
| 532 | ## |
| 533 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 534 | #SeeAlso MakeFromNV12TexturesCopyWithExternalBackend MakeFromYUVTexturesCopy MakeFromYUVATexturesCopy |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 535 | |
| 536 | #Method ## |
| 537 | |
| 538 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopyWithExternalBackend( |
| 539 | GrContext* context, |
| 540 | SkYUVColorSpace yuvColorSpace, |
| 541 | const GrBackendTexture nv12Textures[2], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 542 | GrSurfaceOrigin imageOrigin, |
| 543 | const GrBackendTexture& backendTexture, |
| 544 | sk_sp<SkColorSpace> imageColorSpace = nullptr); |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 545 | #In Constructors |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 546 | #Line # creates Image from planar YUV_ColorSpace, stored in texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 547 | #Populate |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 548 | |
| 549 | #NoExample |
| 550 | ## |
| 551 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 552 | #SeeAlso MakeFromNV12TexturesCopy MakeFromYUVTexturesCopy MakeFromYUVATexturesCopyWithExternalBackend |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 553 | |
| 554 | #Method ## |
| 555 | |
| 556 | # ------------------------------------------------------------------------------ |
| 557 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 558 | # currently uncalled by any test or client ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 559 | #Bug 7424 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 560 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 561 | #EnumClass BitDepth |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 562 | #Line # options for MakeFromPicture ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 563 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 564 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 565 | ## |
| 566 | |
| 567 | #Const kU8 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 568 | #Line # uses 8-bit unsigned int per Color component ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 569 | Use 8 bits per ARGB component using unsigned integer format. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 570 | ## |
| 571 | #Const kF16 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 572 | #Line # uses 16-bit float per Color component ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 573 | Use 16 bits per ARGB component using half-precision floating point format. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 574 | ## |
| 575 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 576 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 577 | ## |
| 578 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 579 | #SeeAlso MakeFromPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 580 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 581 | #EnumClass ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 582 | |
| 583 | # ------------------------------------------------------------------------------ |
| 584 | |
| 585 | #Method static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions, |
| 586 | const SkMatrix* matrix, const SkPaint* paint, |
| 587 | BitDepth bitDepth, |
| 588 | sk_sp<SkColorSpace> colorSpace) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 589 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 590 | #Line # creates Image from Picture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 591 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 592 | |
| 593 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 594 | SkPaint paint; |
| 595 | SkPictureRecorder recorder; |
| 596 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 597 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 598 | paint.setColor(color); |
| 599 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 600 | recordingCanvas->translate(10, 10); |
| 601 | recordingCanvas->scale(1.2f, 1.4f); |
| 602 | } |
| 603 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 604 | int x = 0, y = 0; |
| 605 | for (auto alpha : { 70, 140, 210 } ) { |
| 606 | paint.setAlpha(alpha); |
| 607 | auto srgbColorSpace = SkColorSpace::MakeSRGB(); |
| 608 | sk_sp<SkImage> image = SkImage::MakeFromPicture(playback, {50, 50}, nullptr, &paint, |
| 609 | SkImage::BitDepth::kU8, srgbColorSpace); |
| 610 | canvas->drawImage(image, x, y); |
| 611 | x += 70; y += 70; |
| 612 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 613 | ## |
| 614 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 615 | #SeeAlso SkCanvas::drawPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 616 | |
| 617 | #Method ## |
| 618 | |
| 619 | # ------------------------------------------------------------------------------ |
| 620 | |
Cary Clark | 9548ea9 | 2018-09-13 15:26:33 -0400 | [diff] [blame] | 621 | #Method static sk_sp<SkImage> MakeFromAHardwareBuffer( |
| 622 | AHardwareBuffer* hardwareBuffer, |
| 623 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 624 | sk_sp<SkColorSpace> colorSpace = nullptr, |
| 625 | GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 626 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 627 | #Line # creates Image from Android hardware buffer ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 628 | #Populate |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 629 | |
| 630 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 631 | ## |
| 632 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 633 | #SeeAlso MakeFromRaster |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 634 | |
| 635 | #Method ## |
| 636 | |
| 637 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 638 | #Subtopic Property |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 639 | #Line # values and attributes ## |
| 640 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 641 | |
| 642 | #Method int width() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 643 | #In Property |
| 644 | #Line # returns pixel column count ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 645 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 646 | |
| 647 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 648 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 649 | #Height 96 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 650 | canvas->translate(10, 10); |
| 651 | canvas->drawImage(image, 0, 0); |
| 652 | canvas->translate(0, image->height()); |
| 653 | SkPaint paint; |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 654 | canvas->drawLine(0, 10, image->width(), 10, paint); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 655 | canvas->drawString("width", image->width() / 2 - 15, 25, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 656 | ## |
| 657 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 658 | #SeeAlso dimensions() height() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 659 | |
| 660 | #Method ## |
| 661 | |
| 662 | # ------------------------------------------------------------------------------ |
| 663 | |
| 664 | #Method int height() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 665 | #In Property |
| 666 | #Line # returns pixel row count ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 667 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 668 | |
| 669 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 670 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 671 | #Height 96 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 672 | canvas->translate(10, 10); |
| 673 | canvas->drawImage(image, 0, 0); |
| 674 | canvas->translate(image->width(), 0); |
| 675 | SkPaint paint; |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 676 | canvas->drawLine(10, 0, 10, image->height(), paint); |
Cary Clark | 92694be | 2018-10-25 08:15:36 -0400 | [diff] [blame] | 677 | canvas->drawString("height", 34, image->height() / 2, paint); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 678 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 679 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 680 | #SeeAlso dimensions() width() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 681 | |
| 682 | #Method ## |
| 683 | |
| 684 | # ------------------------------------------------------------------------------ |
| 685 | |
| 686 | #Method SkISize dimensions() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 687 | #In Property |
| 688 | #Line # returns width() and height() ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 689 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 690 | |
| 691 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 692 | #Image 4 |
| 693 | SkISize dimensions = image->dimensions(); |
| 694 | SkIRect bounds = image->bounds(); |
| 695 | SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions); |
| 696 | SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 697 | #StdOut |
| 698 | dimensionsAsBounds == bounds |
| 699 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 700 | ## |
| 701 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 702 | #SeeAlso height() width() bounds() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 703 | |
| 704 | #Method ## |
| 705 | |
| 706 | # ------------------------------------------------------------------------------ |
| 707 | |
| 708 | #Method SkIRect bounds() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 709 | #In Property |
| 710 | #Line # returns width() and height() as Rectangle ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 711 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 712 | |
| 713 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 714 | #Height 128 |
| 715 | #Image 4 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 716 | SkIRect bounds = image->bounds(); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 717 | for (int x : { 0, bounds.width() } ) { |
| 718 | for (int y : { 0, bounds.height() } ) { |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 719 | canvas->drawImage(image, x, y); |
| 720 | } |
| 721 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 722 | ## |
| 723 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 724 | #SeeAlso dimensions() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 725 | |
| 726 | #Method ## |
| 727 | |
| 728 | # ------------------------------------------------------------------------------ |
| 729 | |
| 730 | #Method uint32_t uniqueID() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 731 | #In Property |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 732 | #Line # returns identifier for Image ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 733 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 734 | |
| 735 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 736 | #Image 5 |
| 737 | #Height 156 |
| 738 | sk_sp<SkImage> subset = image->makeSubset({10, 20, 90, 100}); |
| 739 | canvas->drawImage(image, 0, 0); |
| 740 | canvas->drawImage(subset, 128, 0); |
| 741 | SkPaint paint; |
| 742 | SkString s; |
| 743 | s.printf("original id: %d", image->uniqueID()); |
| 744 | canvas->drawString(s, 20, image->height() + 20, paint); |
| 745 | s.printf("subset id: %d", subset->uniqueID()); |
| 746 | canvas->drawString(s, 148, subset->height() + 20, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 747 | ## |
| 748 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 749 | #SeeAlso isLazyGenerated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 750 | |
| 751 | #Method ## |
| 752 | |
| 753 | # ------------------------------------------------------------------------------ |
| 754 | |
| 755 | #Method SkAlphaType alphaType() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 756 | #In Property |
| 757 | #Line # returns Alpha_Type ## |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 758 | Returns Alpha_Type, one of: #list_of_alpha_types#. |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 759 | |
| 760 | Alpha_Type returned was a parameter to an Image constructor, |
| 761 | or was parsed from encoded data. |
| 762 | |
| 763 | #Return Alpha_Type in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 764 | |
| 765 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 766 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 767 | #Height 96 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 768 | const char* alphaTypeStr[] = { "Unknown", "Opaque", "Premul", "Unpremul" }; |
| 769 | SkAlphaType alphaType = image->alphaType(); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 770 | canvas->drawImage(image, 16, 0); |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 771 | canvas->drawString(alphaTypeStr[(int) alphaType], 20, image->height() + 20, SkPaint()); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 772 | ## |
| 773 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 774 | #SeeAlso SkImageInfo::alphaType |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 775 | |
| 776 | #Method ## |
| 777 | |
| 778 | # ------------------------------------------------------------------------------ |
| 779 | |
Greg Daniel | 56008aa | 2018-03-14 15:33:42 -0400 | [diff] [blame] | 780 | #Method SkColorType colorType() const |
| 781 | #In Property |
| 782 | #Line # returns Color_Type ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 783 | #Populate |
Greg Daniel | 56008aa | 2018-03-14 15:33:42 -0400 | [diff] [blame] | 784 | |
| 785 | #Example |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 786 | #Image 4 |
| 787 | #Height 96 |
| 788 | const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 789 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" }; |
| 790 | SkColorType colorType = image->colorType(); |
| 791 | canvas->drawImage(image, 16, 0); |
| 792 | canvas->drawString(colors[(int) colorType], 20, image->height() + 20, SkPaint()); |
Greg Daniel | 56008aa | 2018-03-14 15:33:42 -0400 | [diff] [blame] | 793 | ## |
| 794 | |
| 795 | #SeeAlso SkImageInfo::colorType |
| 796 | |
| 797 | #Method ## |
| 798 | |
| 799 | # ------------------------------------------------------------------------------ |
| 800 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 801 | #Method SkColorSpace* colorSpace() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 802 | #In Property |
| 803 | #Line # returns Color_Space ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 804 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 805 | |
| 806 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 807 | #Image 3 |
| 808 | #Set sRGB |
| 809 | SkPixmap pixmap; |
| 810 | source.peekPixels(&pixmap); |
| 811 | canvas->scale(.25f, .25f); |
| 812 | int y = 0; |
| 813 | for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, |
| 814 | SkColorSpace::kSRGB_RenderTargetGamma } ) { |
| 815 | int x = 0; |
| 816 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); |
| 817 | for (int index = 0; index < 2; ++index) { |
| 818 | pixmap.setColorSpace(colorSpace); |
| 819 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 820 | canvas->drawImage(image, x, y); |
| 821 | colorSpace = image->colorSpace()->makeColorSpin(); |
| 822 | x += 512; |
| 823 | } |
| 824 | y += 512; |
| 825 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 826 | ## |
| 827 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 828 | #SeeAlso refColorSpace makeColorSpace |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 829 | |
| 830 | #Method ## |
| 831 | |
| 832 | # ------------------------------------------------------------------------------ |
| 833 | |
| 834 | #Method sk_sp<SkColorSpace> refColorSpace() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 835 | #In Property |
| 836 | #Line # returns Image_Info Color_Space ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 837 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 838 | |
| 839 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 840 | #Image 3 |
| 841 | #Set sRGB |
| 842 | SkPixmap pixmap; |
| 843 | source.peekPixels(&pixmap); |
| 844 | canvas->scale(.25f, .25f); |
| 845 | int y = 0; |
| 846 | for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, |
| 847 | SkColorSpace::kSRGB_RenderTargetGamma } ) { |
| 848 | int x = 0; |
| 849 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); |
| 850 | for (int index = 0; index < 2; ++index) { |
| 851 | pixmap.setColorSpace(colorSpace); |
| 852 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 853 | canvas->drawImage(image, x, y); |
| 854 | colorSpace = image->refColorSpace()->makeColorSpin(); |
| 855 | x += 512; |
| 856 | } |
| 857 | y += 512; |
| 858 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 859 | ## |
| 860 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 861 | #SeeAlso colorSpace makeColorSpace |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 862 | |
| 863 | #Method ## |
| 864 | |
| 865 | # ------------------------------------------------------------------------------ |
| 866 | |
| 867 | #Method bool isAlphaOnly() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 868 | #In Property |
| 869 | #Line # returns if pixels represent a transparency mask ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 870 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 871 | |
| 872 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 873 | uint8_t pmColors = 0; |
| 874 | sk_sp<SkImage> image = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1), &pmColors, 1}); |
| 875 | SkDebugf("alphaOnly = %s\n", image->isAlphaOnly() ? "true" : "false"); |
| 876 | #StdOut |
| 877 | alphaOnly = true |
| 878 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 879 | ## |
| 880 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 881 | #SeeAlso alphaType isOpaque |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 882 | |
| 883 | #Method ## |
| 884 | |
| 885 | # ------------------------------------------------------------------------------ |
| 886 | |
| 887 | #Method bool isOpaque() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 888 | #In Property |
| 889 | #Line # returns if Alpha_Type is kOpaque_SkAlphaType ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 890 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 891 | |
| 892 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 893 | auto check_isopaque = [](const SkImageInfo& imageInfo) -> void { |
| 894 | auto surface(SkSurface::MakeRaster(imageInfo)); |
| 895 | auto image(surface->makeImageSnapshot()); |
| 896 | SkDebugf("isOpaque = %s\n", image->isOpaque() ? "true" : "false"); |
| 897 | }; |
| 898 | |
| 899 | check_isopaque(SkImageInfo::MakeN32Premul(5, 5)); |
| 900 | check_isopaque(SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType)); |
| 901 | #StdOut |
| 902 | isOpaque = false |
| 903 | isOpaque = true |
| 904 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 905 | ## |
| 906 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 907 | #SeeAlso alphaType isAlphaOnly |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 908 | |
| 909 | #Method ## |
| 910 | |
| 911 | # ------------------------------------------------------------------------------ |
| 912 | |
| 913 | #Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2, |
| 914 | const SkMatrix* localMatrix = nullptr) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 915 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 916 | #Line # creates Shader, Paint element that can tile Image ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 917 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 918 | |
| 919 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 920 | #Image 4 |
| 921 | SkMatrix matrix; |
| 922 | matrix.setRotate(45); |
| 923 | SkPaint paint; |
| 924 | paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode, |
| 925 | &matrix)); |
| 926 | canvas->drawPaint(paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 927 | ## |
| 928 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 929 | #SeeAlso scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 930 | |
| 931 | #Method ## |
| 932 | |
| 933 | # ------------------------------------------------------------------------------ |
| 934 | |
| 935 | #Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 936 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 937 | |
| 938 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 939 | #Image 5 |
| 940 | SkMatrix matrix; |
| 941 | matrix.setRotate(45); |
| 942 | matrix.postTranslate(125, 30); |
| 943 | SkPaint paint; |
| 944 | paint.setShader(image->makeShader(&matrix)); |
| 945 | canvas->drawPaint(paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 946 | ## |
| 947 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 948 | #SeeAlso scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 949 | |
| 950 | #Method ## |
| 951 | |
| 952 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 953 | #Subtopic Pixels |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 954 | #Line # read and write pixel values ## |
| 955 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 956 | |
| 957 | #Method bool peekPixels(SkPixmap* pixmap) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 958 | #In Pixels |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 959 | #Line # returns Pixmap if possible ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 960 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 961 | |
| 962 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 963 | SkBitmap bitmap; |
| 964 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(12, 11)); |
| 965 | SkCanvas offscreen(bitmap); |
| 966 | offscreen.clear(SK_ColorWHITE); |
| 967 | SkPaint paint; |
| 968 | offscreen.drawString("%", 1, 10, paint); |
| 969 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 970 | SkPixmap pixmap; |
| 971 | if (image->peekPixels(&pixmap)) { |
| 972 | const SkPMColor* pixels = pixmap.addr32(); |
| 973 | SkPMColor pmWhite = pixels[0]; |
| 974 | for (int y = 0; y < image->height(); ++y) { |
| 975 | for (int x = 0; x < image->width(); ++x) { |
| 976 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 977 | } |
| 978 | SkDebugf("\n"); |
| 979 | } |
| 980 | } |
| 981 | #StdOut |
| 982 | ------------ |
| 983 | --xx----x--- |
| 984 | -x--x--x---- |
| 985 | -x--x--x---- |
| 986 | -x--x-x----- |
| 987 | --xx-xx-xx-- |
| 988 | -----x-x--x- |
| 989 | ----x--x--x- |
| 990 | ----x--x--x- |
| 991 | ---x----xx-- |
| 992 | ------------ |
| 993 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 994 | ## |
| 995 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 996 | #SeeAlso readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 997 | |
| 998 | #Method ## |
| 999 | |
| 1000 | # ------------------------------------------------------------------------------ |
| 1001 | |
| 1002 | #Method GrTexture* getTexture() const |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1003 | #Deprecated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1004 | #Method ## |
| 1005 | |
| 1006 | # ------------------------------------------------------------------------------ |
| 1007 | |
| 1008 | #Method bool isTextureBacked() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1009 | #In Property |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1010 | #Line # returns if Image was created from GPU_Texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1011 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1012 | |
| 1013 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1014 | #Image 5 |
| 1015 | #Platform gpu |
| 1016 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1017 | if (nullptr == image) { |
| 1018 | return; |
| 1019 | } |
| 1020 | SkPaint paint; |
| 1021 | paint.setAntiAlias(true); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1022 | canvas->drawImage(image, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1023 | canvas->drawString(label, 30, image->height() / 4, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1024 | canvas->drawString(image->isTextureBacked() ? "is GPU texture" : "not GPU texture", |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1025 | 20, image->height() * 3 / 4, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1026 | }; |
| 1027 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1028 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1029 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1030 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1031 | drawImage(image, "image"); |
| 1032 | canvas->translate(image->width(), 0); |
| 1033 | drawImage(bitmapImage, "source"); |
| 1034 | canvas->translate(-image->width(), image->height()); |
| 1035 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1036 | ## |
| 1037 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1038 | #SeeAlso MakeFromTexture isValid |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1039 | |
| 1040 | #Method ## |
| 1041 | |
| 1042 | # ------------------------------------------------------------------------------ |
| 1043 | |
| 1044 | #Method bool isValid(GrContext* context) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1045 | #In Property |
| 1046 | #Line # returns if Image can draw to Raster_Surface or GPU_Context ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1047 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1048 | |
| 1049 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1050 | #Image 5 |
| 1051 | #Platform gpu |
| 1052 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1053 | if (nullptr == image) { |
| 1054 | return; |
| 1055 | } |
| 1056 | SkPaint paint; |
| 1057 | paint.setAntiAlias(true); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1058 | canvas->drawImage(image, 0, 0); |
| 1059 | canvas->drawString(label, image->width() / 2, image->height() / 4, paint); |
| 1060 | if (canvas->getGrContext()) { |
| 1061 | canvas->drawString(image->isValid(canvas->getGrContext()) ? "is valid on GPU" : |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1062 | "not valid on GPU", 20, image->height() * 5 / 8, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1063 | } |
| 1064 | canvas->drawString(image->isValid(nullptr) ? "is valid on CPU" : |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1065 | "not valid on CPU", 20, image->height() * 7 / 8, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1066 | }; |
| 1067 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1068 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1069 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1070 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1071 | drawImage(image, "image"); |
| 1072 | canvas->translate(image->width(), 0); |
| 1073 | drawImage(bitmapImage, "source"); |
| 1074 | canvas->translate(-image->width(), image->height()); |
| 1075 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1076 | ## |
| 1077 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1078 | #SeeAlso isTextureBacked isLazyGenerated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1079 | |
| 1080 | #Method ## |
| 1081 | |
| 1082 | # ------------------------------------------------------------------------------ |
| 1083 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 1084 | #Method GrBackendTexture getBackendTexture(bool flushPendingGrContextIO, |
| 1085 | GrSurfaceOrigin* origin = nullptr) const |
| 1086 | #In Property |
| 1087 | #Line # returns GPU reference to Image as texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1088 | #Populate |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 1089 | |
Cary Clark | ba75aee | 2018-04-05 08:18:41 -0400 | [diff] [blame] | 1090 | #Example |
| 1091 | #Image 3 |
| 1092 | #Platform gpu |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 1093 | GrContext* grContext = canvas->getGrContext(); |
| 1094 | if (!grContext) { |
| 1095 | canvas->drawString("GPU only!", 20, 40, SkPaint()); |
| 1096 | return; |
| 1097 | } |
| 1098 | sk_sp<SkImage> imageFromBackend = SkImage::MakeFromAdoptedTexture(grContext, backEndTexture, |
| 1099 | kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); |
| 1100 | GrBackendTexture textureFromImage = imageFromBackend->getBackendTexture(false); |
| 1101 | if (!textureFromImage.isValid()) { |
| 1102 | return; |
| 1103 | } |
| 1104 | sk_sp<SkImage> imageFromTexture = SkImage::MakeFromAdoptedTexture(grContext, textureFromImage, |
| 1105 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); |
| 1106 | canvas->drawImage(imageFromTexture, 0, 0); |
Cary Clark | ba75aee | 2018-04-05 08:18:41 -0400 | [diff] [blame] | 1107 | canvas->drawImage(imageFromBackend, 128, 128); |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 1108 | ## |
| 1109 | |
| 1110 | #SeeAlso MakeFromTexture isTextureBacked |
| 1111 | |
| 1112 | #Method ## |
| 1113 | |
| 1114 | # ------------------------------------------------------------------------------ |
| 1115 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1116 | #Enum CachingHint |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1117 | #Line # options for readPixels and scalePixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1118 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1119 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1120 | ## |
| 1121 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1122 | CachingHint selects whether Skia may internally cache Bitmaps generated by |
| 1123 | decoding Image, or by copying Image from GPU to CPU. The default behavior |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1124 | allows caching Bitmaps. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1125 | |
| 1126 | Choose kDisallow_CachingHint if Image pixels are to be used only once, or |
| 1127 | if Image pixels reside in a cache outside of Skia, or to reduce memory pressure. |
| 1128 | |
| 1129 | Choosing kAllow_CachingHint does not ensure that pixels will be cached. |
| 1130 | Image pixels may not be cached if memory requirements are too large or |
| 1131 | pixels are not accessible. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1132 | |
| 1133 | #Const kAllow_CachingHint 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1134 | #Line # allows internally caching decoded and copied pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1135 | ## |
| 1136 | #Const kDisallow_CachingHint 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1137 | #Line # disallows internally caching decoded and copied pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1138 | ## |
| 1139 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1140 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1141 | ## |
| 1142 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1143 | #SeeAlso readPixels scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1144 | |
| 1145 | #Enum ## |
| 1146 | |
| 1147 | # ------------------------------------------------------------------------------ |
| 1148 | |
| 1149 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 1150 | int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1151 | #In Pixels |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1152 | #Line # copies and converts pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1153 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1154 | Copies Rect of pixels from Image to dstPixels. Copy starts at offset (srcX, srcY), |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1155 | and does not exceed Image (width(), height()). |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1156 | |
| 1157 | dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of |
| 1158 | destination. dstRowBytes specifics the gap from one destination row to the next. |
| 1159 | Returns true if pixels are copied. Returns false if: |
| 1160 | #List |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame^] | 1161 | # dstInfo has no address ## |
| 1162 | # dstRowBytes is less than dstInfo.minRowBytes() ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1163 | # Pixel_Ref is nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1164 | ## |
| 1165 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1166 | Pixels are copied only if pixel conversion is possible. If Image Color_Type is |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame^] | 1167 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. |
| 1168 | If Image Color_Type is kGray_8_SkColorType, dstInfo.colorSpace() must match. |
| 1169 | If Image Alpha_Type is kOpaque_SkAlphaType, dstInfo.alphaType() must |
| 1170 | match. If Image Color_Space is nullptr, dstInfo.colorSpace() must match. Returns |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1171 | false if pixel conversion is not possible. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1172 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1173 | srcX and srcY may be negative to copy only top or left of source. Returns |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1174 | false if width() or height() is zero or negative. |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 1175 | Returns false if #Formula # abs(srcX) >= Image width() ##, or if #Formula # abs(srcY) >= Image height() ##. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1176 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1177 | If cachingHint is kAllow_CachingHint, pixels may be retained locally. |
| 1178 | If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. |
| 1179 | |
| 1180 | #Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ## |
| 1181 | #Param dstPixels destination pixel storage ## |
| 1182 | #Param dstRowBytes destination row length ## |
| 1183 | #Param srcX column index whose absolute value is less than width() ## |
| 1184 | #Param srcY row index whose absolute value is less than height() ## |
| 1185 | #Param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint ## |
| 1186 | |
| 1187 | #Return true if pixels are copied to dstPixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1188 | |
| 1189 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1190 | #Image 3 |
| 1191 | canvas->scale(.5f, .5f); |
| 1192 | const int width = 32; |
| 1193 | const int height = 32; |
| 1194 | std::vector<int32_t> dstPixels; |
| 1195 | dstPixels.resize(height * width * 4); |
| 1196 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 1197 | for (int y = 0; y < 512; y += height ) { |
| 1198 | for (int x = 0; x < 512; x += width ) { |
| 1199 | if (image->readPixels(info, &dstPixels.front(), width * 4, x, y)) { |
| 1200 | SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); |
| 1201 | SkBitmap bitmap; |
| 1202 | bitmap.installPixels(dstPixmap); |
| 1203 | canvas->drawBitmap(bitmap, 0, 0); |
| 1204 | } |
| 1205 | canvas->translate(48, 0); |
| 1206 | } |
| 1207 | canvas->translate(-16 * 48, 48); |
| 1208 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1209 | ## |
| 1210 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1211 | #SeeAlso scalePixels SkBitmap::readPixels SkPixmap::readPixels SkCanvas::readPixels SkSurface::readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1212 | |
| 1213 | #Method ## |
| 1214 | |
| 1215 | # ------------------------------------------------------------------------------ |
| 1216 | |
| 1217 | #Method bool readPixels(const SkPixmap& dst, int srcX, int srcY, |
| 1218 | CachingHint cachingHint = kAllow_CachingHint) const |
| 1219 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1220 | Copies a Rect of pixels from Image to dst. Copy starts at (srcX, srcY), and |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1221 | does not exceed Image (width(), height()). |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1222 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1223 | dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage, |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame^] | 1224 | and row bytes of destination. dst.rowBytes() specifics the gap from one destination |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1225 | row to the next. Returns true if pixels are copied. Returns false if: |
| 1226 | #List |
| 1227 | # dst pixel storage equals nullptr ## |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame^] | 1228 | # dst.rowBytes() is less than SkImageInfo::minRowBytes ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1229 | # Pixel_Ref is nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1230 | ## |
| 1231 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1232 | Pixels are copied only if pixel conversion is possible. If Image Color_Type is |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame^] | 1233 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match. |
| 1234 | If Image Color_Type is kGray_8_SkColorType, dst.colorSpace() must match. |
| 1235 | If Image Alpha_Type is kOpaque_SkAlphaType, dst.alphaType() must |
| 1236 | match. If Image Color_Space is nullptr, dst.colorSpace() must match. Returns |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1237 | false if pixel conversion is not possible. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1238 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1239 | srcX and srcY may be negative to copy only top or left of source. Returns |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1240 | false if width() or height() is zero or negative. |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 1241 | Returns false if #Formula # abs(srcX) >= Image width() ##, or if #Formula # abs(srcY) >= Image height() ##. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1242 | |
| 1243 | If cachingHint is kAllow_CachingHint, pixels may be retained locally. |
| 1244 | If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. |
| 1245 | |
| 1246 | #Param dst destination Pixmap: Image_Info, pixels, row bytes ## |
| 1247 | #Param srcX column index whose absolute value is less than width() ## |
| 1248 | #Param srcY row index whose absolute value is less than height() ## |
| 1249 | #Param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint ## |
| 1250 | |
| 1251 | #Return true if pixels are copied to dst ## |
| 1252 | |
| 1253 | #Example |
| 1254 | #Image 3 |
| 1255 | std::vector<int32_t> srcPixels; |
| 1256 | int rowBytes = image->width() * 4; |
| 1257 | int quarterWidth = image->width() / 4; |
| 1258 | int quarterHeight = image->height() / 4; |
| 1259 | srcPixels.resize(image->height() * rowBytes); |
| 1260 | for (int y = 0; y < 4; ++y) { |
| 1261 | for (int x = 0; x < 4; ++x) { |
| 1262 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight), |
| 1263 | &srcPixels.front() + x * image->height() * quarterWidth + |
| 1264 | y * quarterWidth, rowBytes); |
| 1265 | image->readPixels(pixmap, x * quarterWidth, y * quarterHeight); |
| 1266 | } |
| 1267 | } |
| 1268 | canvas->scale(.5f, .5f); |
| 1269 | SkBitmap bitmap; |
| 1270 | bitmap.installPixels(SkImageInfo::MakeN32Premul(image->width(), image->height()), |
| 1271 | &srcPixels.front(), rowBytes); |
| 1272 | canvas->drawBitmap(bitmap, 0, 0); |
| 1273 | ## |
| 1274 | |
| 1275 | #SeeAlso scalePixels SkBitmap::readPixels SkPixmap::readPixels SkCanvas::readPixels SkSurface::readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1276 | |
| 1277 | #Method ## |
| 1278 | |
| 1279 | # ------------------------------------------------------------------------------ |
| 1280 | |
| 1281 | #Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality, |
| 1282 | CachingHint cachingHint = kAllow_CachingHint) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1283 | #In Pixels |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1284 | #Line # scales and converts one Image to another ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1285 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1286 | |
| 1287 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1288 | #Image 3 |
| 1289 | #Height 128 |
| 1290 | std::vector<int32_t> srcPixels; |
| 1291 | int quarterWidth = image->width() / 16; |
| 1292 | int rowBytes = quarterWidth * 4; |
| 1293 | int quarterHeight = image->height() / 16; |
| 1294 | srcPixels.resize(quarterHeight * rowBytes); |
| 1295 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight), |
| 1296 | &srcPixels.front(), rowBytes); |
| 1297 | canvas->scale(4, 4); |
| 1298 | SkFilterQuality qualities[] = { kNone_SkFilterQuality, kLow_SkFilterQuality, |
| 1299 | kMedium_SkFilterQuality, kHigh_SkFilterQuality }; |
| 1300 | for (unsigned index = 0; index < SK_ARRAY_COUNT(qualities); ++index) { |
| 1301 | image->scalePixels(pixmap, qualities[index]); |
| 1302 | sk_sp<SkImage> filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr); |
| 1303 | canvas->drawImage(filtered, 16 * index, 0); |
| 1304 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1305 | ## |
| 1306 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1307 | #SeeAlso SkCanvas::drawImage readPixels SkPixmap::scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1308 | |
| 1309 | #Method ## |
| 1310 | |
| 1311 | # ------------------------------------------------------------------------------ |
| 1312 | |
| 1313 | #Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1314 | #In Utility |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1315 | #Line # returns encoded Image as SkData ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1316 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1317 | |
| 1318 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1319 | #Image 3 |
| 1320 | canvas->scale(4, 4); |
| 1321 | SkIRect subset = {0, 0, 16, 64}; |
| 1322 | int x = 0; |
| 1323 | for (int quality : { 0, 10, 50, 100 } ) { |
| 1324 | sk_sp<SkData> data(image->encodeToData(SkEncodedImageFormat::kJPEG, quality)); |
| 1325 | sk_sp<SkImage> filtered = SkImage::MakeFromEncoded(data, &subset); |
| 1326 | canvas->drawImage(filtered, x, 0); |
| 1327 | x += 16; |
| 1328 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1329 | ## |
| 1330 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1331 | #SeeAlso refEncodedData MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1332 | |
| 1333 | #Method ## |
| 1334 | |
| 1335 | # ------------------------------------------------------------------------------ |
| 1336 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1337 | #Method sk_sp<SkData> encodeToData() const |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1338 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1339 | |
| 1340 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1341 | #Image 3 |
| 1342 | canvas->scale(4, 4); |
| 1343 | SkIRect subset = {136, 32, 200, 96}; |
| 1344 | sk_sp<SkData> data(image->encodeToData()); |
| 1345 | sk_sp<SkImage> eye = SkImage::MakeFromEncoded(data, &subset); |
| 1346 | canvas->drawImage(eye, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1347 | ## |
| 1348 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1349 | #SeeAlso refEncodedData MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1350 | |
| 1351 | #Method ## |
| 1352 | |
| 1353 | # ------------------------------------------------------------------------------ |
| 1354 | |
| 1355 | #Method sk_sp<SkData> refEncodedData() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1356 | #In Utility |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1357 | #Line # returns Image encoded in SkData if present ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1358 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1359 | |
| 1360 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1361 | #Image 3 |
| 1362 | #Platform gpu |
| 1363 | struct { |
| 1364 | const char* name; |
| 1365 | sk_sp<SkImage> image; |
| 1366 | } tests[] = { { "image", image }, { "bitmap", SkImage::MakeFromBitmap(source) }, |
| 1367 | { "texture", SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1368 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1369 | kOpaque_SkAlphaType, nullptr) } }; |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1370 | SkString string; |
| 1371 | SkPaint paint; |
| 1372 | for (const auto& test : tests ) { |
| 1373 | if (!test.image) { |
| 1374 | string.printf("no %s", test.name); |
| 1375 | } else { |
| 1376 | string.printf("%s" "encoded %s", test.image->refEncodedData() ? "" : "no ", test.name); |
| 1377 | } |
| 1378 | canvas->drawString(string, 10, 20, paint); |
| 1379 | canvas->translate(0, 20); |
| 1380 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1381 | ## |
| 1382 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1383 | #SeeAlso encodeToData MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1384 | |
| 1385 | #Method ## |
| 1386 | |
| 1387 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1388 | #Subtopic Utility |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1389 | #Line # rarely called management functions ## |
| 1390 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1391 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1392 | #Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1393 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1394 | #Line # creates Image containing part of original ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1395 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1396 | |
| 1397 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1398 | #Image 3 |
| 1399 | canvas->scale(.5f, .5f); |
Cary Clark | c30382f | 2018-07-24 08:09:27 -0400 | [diff] [blame] | 1400 | const int width = 64; |
| 1401 | const int height = 64; |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1402 | for (int y = 0; y < 512; y += height ) { |
| 1403 | for (int x = 0; x < 512; x += width ) { |
| 1404 | sk_sp<SkImage> subset(image->makeSubset({x, y, x + width, y + height})); |
| 1405 | canvas->drawImage(subset, x * 3 / 2, y * 3 / 2); |
| 1406 | } |
| 1407 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1408 | ## |
| 1409 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1410 | #SeeAlso MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1411 | |
| 1412 | #Method ## |
| 1413 | |
| 1414 | # ------------------------------------------------------------------------------ |
| 1415 | |
Greg Daniel | 5f4b09d | 2018-06-12 16:39:59 -0400 | [diff] [blame] | 1416 | #Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace, |
| 1417 | GrMipMapped mipMapped = GrMipMapped::kNo) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1418 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1419 | #Line # creates Image matching Color_Space if possible ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1420 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1421 | |
| 1422 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1423 | #Platform gpu |
| 1424 | #Image 5 |
| 1425 | auto drawImage = [=](sk_sp<SkImage> image, GrContext* context, const char* label) -> void { |
| 1426 | if (nullptr == image || nullptr == context) { |
| 1427 | return; |
| 1428 | } |
| 1429 | SkPaint paint; |
| 1430 | paint.setAntiAlias(true); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1431 | sk_sp<SkImage> texture(image->makeTextureImage(context, nullptr)); |
| 1432 | canvas->drawImage(texture, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1433 | canvas->drawString(label, 20, texture->height() / 4, paint); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1434 | }; |
| 1435 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1436 | GrContext* context = canvas->getGrContext(); |
| 1437 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(context, backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1438 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1439 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1440 | drawImage(image, context, "image"); |
| 1441 | canvas->translate(image->width(), 0); |
| 1442 | drawImage(bitmapImage, context, "source"); |
| 1443 | canvas->translate(-image->width(), image->height()); |
| 1444 | drawImage(textureImage, context, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1445 | ## |
| 1446 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1447 | #SeeAlso MakeFromTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1448 | |
| 1449 | #Method ## |
| 1450 | |
| 1451 | # ------------------------------------------------------------------------------ |
| 1452 | |
| 1453 | #Method sk_sp<SkImage> makeNonTextureImage() const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1454 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1455 | #Line # creates Image without dependency on GPU_Texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1456 | #Populate |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1457 | |
| 1458 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1459 | #Image 5 |
| 1460 | #Platform gpu |
| 1461 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1462 | if (nullptr == image) { |
| 1463 | return; |
| 1464 | } |
| 1465 | SkPaint paint; |
| 1466 | paint.setAntiAlias(true); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1467 | sk_sp<SkImage> nonTexture(image->makeNonTextureImage()); |
| 1468 | canvas->drawImage(nonTexture, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1469 | canvas->drawString(label, 20, nonTexture->height() / 4, paint); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1470 | }; |
| 1471 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1472 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1473 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1474 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1475 | drawImage(image, "image"); |
| 1476 | canvas->translate(image->width(), 0); |
| 1477 | drawImage(bitmapImage, "source"); |
| 1478 | canvas->translate(-image->width(), image->height()); |
| 1479 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1480 | ## |
| 1481 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1482 | #SeeAlso makeTextureImage makeRasterImage MakeBackendTextureFromSkImage |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1483 | |
| 1484 | #Method ## |
| 1485 | |
| 1486 | # ------------------------------------------------------------------------------ |
| 1487 | |
| 1488 | #Method sk_sp<SkImage> makeRasterImage() const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1489 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1490 | #Line # creates Image compatible with Raster_Surface if possible ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1491 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1492 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1493 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1494 | #Image 5 |
| 1495 | #Platform gpu |
| 1496 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1497 | if (nullptr == image) { |
| 1498 | return; |
| 1499 | } |
| 1500 | SkPaint paint; |
| 1501 | paint.setAntiAlias(true); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1502 | sk_sp<SkImage> raster(image->makeRasterImage()); |
| 1503 | canvas->drawImage(raster, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1504 | canvas->drawString(label, 20, raster->height() / 4, paint); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1505 | }; |
| 1506 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1507 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1508 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1509 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1510 | drawImage(image, "image"); |
| 1511 | canvas->translate(image->width(), 0); |
| 1512 | drawImage(bitmapImage, "source"); |
| 1513 | canvas->translate(-image->width(), image->height()); |
| 1514 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1515 | ## |
| 1516 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1517 | #SeeAlso isTextureBacked isLazyGenerated MakeFromRaster |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1518 | |
| 1519 | #Method ## |
| 1520 | |
| 1521 | # ------------------------------------------------------------------------------ |
| 1522 | |
| 1523 | #Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset, |
| 1524 | const SkIRect& clipBounds, SkIRect* outSubset, |
| 1525 | SkIPoint* offset) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1526 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1527 | #Line # creates filtered, clipped Image ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1528 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1529 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1530 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1531 | #Description |
| 1532 | In each frame of the animation, filtered Image is drawn in a different location. |
| 1533 | By translating canvas by returned offset, Image appears stationary. |
| 1534 | ## |
| 1535 | #Image 5 |
| 1536 | #Platform gpu |
Cary Clark | 5717e82 | 2018-09-21 11:36:41 -0400 | [diff] [blame] | 1537 | #Duration 1 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1538 | sk_sp<SkImageFilter> shadowFilter = SkDropShadowImageFilter::Make( |
| 1539 | -10.0f * frame, 5.0f * frame, 3.0f, 3.0f, SK_ColorBLUE, |
| 1540 | SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
| 1541 | nullptr); |
| 1542 | sk_sp<SkImageFilter> offsetFilter = SkOffsetImageFilter::Make(40, 40, shadowFilter, nullptr); |
| 1543 | SkIRect subset = image->bounds(); |
| 1544 | SkIRect clipBounds = image->bounds(); |
| 1545 | clipBounds.outset(60, 60); |
| 1546 | SkIRect outSubset; |
| 1547 | SkIPoint offset; |
| 1548 | sk_sp<SkImage> filtered(image->makeWithFilter(offsetFilter.get(), subset, clipBounds, |
| 1549 | &outSubset, &offset)); |
| 1550 | SkPaint paint; |
| 1551 | paint.setAntiAlias(true); |
| 1552 | paint.setStyle(SkPaint::kStroke_Style); |
| 1553 | canvas->drawLine(0, 0, offset.fX, offset.fY, paint); |
| 1554 | canvas->translate(offset.fX, offset.fY); |
| 1555 | canvas->drawImage(filtered, 0, 0); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1556 | canvas->drawRect(SkRect::Make(outSubset), paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1557 | ## |
| 1558 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1559 | #SeeAlso makeShader SkPaint::setImageFilter |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1560 | |
| 1561 | #Method ## |
| 1562 | |
| 1563 | # ------------------------------------------------------------------------------ |
| 1564 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1565 | #Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1566 | #Line # parameter type for MakeBackendTextureFromSkImage ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1567 | |
| 1568 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1569 | #Populate |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1570 | ## |
| 1571 | |
Cary Clark | 0d22539 | 2018-06-07 09:59:07 -0400 | [diff] [blame] | 1572 | Defines a callback function, taking one parameter of type GrBackendTexture with |
| 1573 | no return value. Function is called when back-end texture is to be released. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1574 | ## |
| 1575 | |
| 1576 | # ------------------------------------------------------------------------------ |
| 1577 | |
| 1578 | #Method static bool MakeBackendTextureFromSkImage(GrContext* context, |
| 1579 | sk_sp<SkImage> image, |
| 1580 | GrBackendTexture* backendTexture, |
| 1581 | BackendTextureReleaseProc* backendTextureReleaseProc) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1582 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1583 | #Line # creates GPU_Texture from Image ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1584 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1585 | |
| 1586 | #Example |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1587 | #Platform gpu |
| 1588 | #Height 64 |
| 1589 | #Function |
Brian Salomon | 67f8584 | 2018-02-09 08:50:22 -0500 | [diff] [blame] | 1590 | static sk_sp<SkImage> create_gpu_image(GrContext* grContext) { |
| 1591 | const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
| 1592 | auto surface(SkSurface::MakeRenderTarget(grContext, SkBudgeted::kNo, info)); |
| 1593 | SkCanvas* canvas = surface->getCanvas(); |
| 1594 | canvas->clear(SK_ColorWHITE); |
| 1595 | SkPaint paint; |
| 1596 | paint.setColor(SK_ColorBLACK); |
| 1597 | canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); |
| 1598 | return surface->makeImageSnapshot(); |
| 1599 | } |
| 1600 | ## |
| 1601 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1602 | void draw(SkCanvas* canvas) { |
Brian Salomon | 67f8584 | 2018-02-09 08:50:22 -0500 | [diff] [blame] | 1603 | GrContext* grContext = canvas->getGrContext(); |
| 1604 | if (!grContext) { |
| 1605 | return; |
| 1606 | } |
| 1607 | sk_sp<SkImage> backEndImage = create_gpu_image(grContext); |
| 1608 | canvas->drawImage(backEndImage, 0, 0); |
| 1609 | GrBackendTexture texture; |
| 1610 | SkImage::BackendTextureReleaseProc proc; |
| 1611 | if (!SkImage::MakeBackendTextureFromSkImage(grContext, std::move(backEndImage), |
| 1612 | &texture, &proc)) { |
| 1613 | return; |
| 1614 | } |
| 1615 | sk_sp<SkImage> i2 = SkImage::MakeFromTexture(grContext, texture, kTopLeft_GrSurfaceOrigin, |
| 1616 | kN32_SkColorType, kOpaque_SkAlphaType, nullptr); |
| 1617 | canvas->drawImage(i2, 30, 30); |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1618 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1619 | ## |
| 1620 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1621 | #SeeAlso MakeFromTexture makeTextureImage |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1622 | |
| 1623 | #Method ## |
| 1624 | |
| 1625 | # ------------------------------------------------------------------------------ |
| 1626 | |
| 1627 | #Enum LegacyBitmapMode |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1628 | #Deprecated soon |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1629 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1630 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1631 | ## |
| 1632 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1633 | #Const kRO_LegacyBitmapMode 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1634 | #Line # returned bitmap is read-only and immutable ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1635 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1636 | |
| 1637 | #Enum ## |
| 1638 | |
| 1639 | # ------------------------------------------------------------------------------ |
| 1640 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1641 | #Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode = kRO_LegacyBitmapMode) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1642 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1643 | #Line # returns as Raster_Bitmap ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1644 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1645 | |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1646 | #Example |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1647 | #Image 4 |
| 1648 | #Platform gpu |
Brian Salomon | 67f8584 | 2018-02-09 08:50:22 -0500 | [diff] [blame] | 1649 | SkBitmap bitImage; |
| 1650 | if (image->asLegacyBitmap(&bitImage, SkImage::kRO_LegacyBitmapMode)) { |
| 1651 | canvas->drawBitmap(bitImage, 0, 0); |
| 1652 | } |
| 1653 | GrContext* grContext = canvas->getGrContext(); |
| 1654 | if (!grContext) { |
| 1655 | return; |
| 1656 | } |
| 1657 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(grContext, backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1658 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1659 | kOpaque_SkAlphaType, nullptr)); |
Brian Salomon | 67f8584 | 2018-02-09 08:50:22 -0500 | [diff] [blame] | 1660 | canvas->drawImage(textureImage, 45, 45); |
| 1661 | if (textureImage->asLegacyBitmap(&bitImage, SkImage::kRO_LegacyBitmapMode)) { |
| 1662 | canvas->drawBitmap(bitImage, 90, 90); |
| 1663 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1664 | ## |
| 1665 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1666 | #SeeAlso MakeRasterData makeRasterImage makeNonTextureImage |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1667 | |
| 1668 | #Method ## |
| 1669 | |
| 1670 | # ------------------------------------------------------------------------------ |
| 1671 | |
| 1672 | #Method bool isLazyGenerated() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1673 | #In Property |
| 1674 | #Line # returns if Image is created as needed ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1675 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1676 | |
| 1677 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1678 | #Height 80 |
| 1679 | #Function |
| 1680 | class TestImageGenerator : public SkImageGenerator { |
| 1681 | public: |
| 1682 | TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {} |
| 1683 | ~TestImageGenerator() override {} |
| 1684 | protected: |
| 1685 | bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes, |
| 1686 | const Options& options) override { |
| 1687 | SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr); |
| 1688 | for (int y = 0; y < info.height(); ++y) { |
| 1689 | for (int x = 0; x < info.width(); ++x) { |
| 1690 | pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811; |
| 1691 | } |
| 1692 | } |
| 1693 | return true; |
| 1694 | } |
| 1695 | }; |
| 1696 | ## |
| 1697 | void draw(SkCanvas* canvas) { |
| 1698 | auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator()); |
| 1699 | sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen))); |
| 1700 | SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy"); |
| 1701 | canvas->scale(8, 8); |
| 1702 | canvas->drawImage(image, 0, 0, nullptr); |
| 1703 | SkPaint paint; |
| 1704 | paint.setTextSize(4); |
| 1705 | canvas->drawString(lazy, 2, 5, paint); |
| 1706 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1707 | ## |
| 1708 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1709 | #Example |
| 1710 | #Image 5 |
| 1711 | #Platform gpu |
| 1712 | void draw(SkCanvas* canvas) { |
| 1713 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1714 | if (nullptr == image) { |
| 1715 | return; |
| 1716 | } |
| 1717 | SkPaint paint; |
| 1718 | paint.setAntiAlias(true); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1719 | canvas->drawImage(image, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1720 | canvas->drawString(label, 30, image->height() / 4, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1721 | canvas->drawString( |
| 1722 | image->isLazyGenerated() ? "is lazily generated" : "not lazily generated", |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1723 | 20, image->height() * 3 / 4, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1724 | }; |
| 1725 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1726 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1727 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1728 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1729 | drawImage(image, "image"); |
| 1730 | canvas->translate(image->width(), 0); |
| 1731 | drawImage(bitmapImage, "source"); |
| 1732 | canvas->translate(-image->width(), image->height()); |
| 1733 | drawImage(textureImage, "backEndTexture"); |
| 1734 | } |
| 1735 | ## |
| 1736 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame^] | 1737 | #SeeAlso isTextureBacked makeNonTextureImage |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1738 | |
| 1739 | #Method ## |
| 1740 | |
| 1741 | # ------------------------------------------------------------------------------ |
| 1742 | |
Cary Clark | e80cd44 | 2018-07-17 13:19:56 -0400 | [diff] [blame] | 1743 | #Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1744 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1745 | #Line # creates Image matching Color_Space if possible ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1746 | #Populate |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1747 | |
| 1748 | #Example |
| 1749 | #Image 5 |
| 1750 | #Set sRGB |
| 1751 | sk_sp<SkColorSpace> normalColorSpace = SkColorSpace::MakeRGB( |
| 1752 | SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kSRGB_Gamut); |
| 1753 | sk_sp<SkColorSpace> wackyColorSpace = normalColorSpace->makeColorSpin(); |
| 1754 | for (auto colorSpace : { normalColorSpace, wackyColorSpace } ) { |
Cary Clark | c3c1c31 | 2018-07-18 09:25:15 -0400 | [diff] [blame] | 1755 | sk_sp<SkImage> colorSpaced = image->makeColorSpace(colorSpace); |
| 1756 | canvas->drawImage(colorSpaced, 0, 0); |
| 1757 | canvas->translate(128, 0); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1758 | } |
| 1759 | ## |
| 1760 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame^] | 1761 | #SeeAlso MakeFromPicture MakeFromTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1762 | |
| 1763 | #Method ## |
| 1764 | |
| 1765 | #Class SkImage ## |
| 1766 | |
| 1767 | #Topic Image ## |