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 | |
Jim Van Verth | c8429ad | 2018-11-20 11:12:37 -0500 | [diff] [blame^] | 465 | #Method static sk_sp<SkImage> MakeFromYUVAPixmaps( |
| 466 | GrContext* context, |
| 467 | SkYUVColorSpace yuvColorSpace, |
| 468 | const SkPixmap yuvaPixmaps[], |
| 469 | const SkYUVAIndex yuvaIndices[4], |
| 470 | SkISize imageSize, |
| 471 | GrSurfaceOrigin imageOrigin, |
| 472 | bool buildMips, |
| 473 | bool limitToMaxTextureSize = false, |
| 474 | sk_sp<SkColorSpace> imageColorSpace = nullptr); |
| 475 | |
| 476 | #In Constructor |
| 477 | #Line # creates Image from YUV_ColorSpace data ## |
| 478 | #Populate |
| 479 | |
| 480 | #NoExample |
| 481 | ## |
| 482 | |
| 483 | #SeeAlso MakeFromYUVATextures |
| 484 | |
| 485 | #Method ## |
Cary Clark | 1801b94 | 2018-10-30 21:10:03 -0400 | [diff] [blame] | 486 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 487 | # ------------------------------------------------------------------------------ |
| 488 | |
| 489 | #Method static sk_sp<SkImage> MakeFromYUVATexturesCopyWithExternalBackend( |
| 490 | GrContext* context, |
| 491 | SkYUVColorSpace yuvColorSpace, |
| 492 | const GrBackendTexture yuvaTextures[], |
| 493 | const SkYUVAIndex yuvaIndices[4], |
| 494 | SkISize imageSize, |
| 495 | GrSurfaceOrigin imageOrigin, |
| 496 | const GrBackendTexture& backendTexture, |
| 497 | sk_sp<SkColorSpace> imageColorSpace = nullptr) |
| 498 | #In Constructor |
| 499 | #Line # creates Image from planar YUV_ColorSpace, stored in texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 500 | #Populate |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 501 | |
| 502 | #NoExample |
| 503 | ## |
| 504 | |
Cary Clark | 1801b94 | 2018-10-30 21:10:03 -0400 | [diff] [blame] | 505 | #SeeAlso MakeFromYUVATexturesCopy MakeFromYUVATextures |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 506 | |
| 507 | #Method ## |
| 508 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 509 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace, |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 510 | const GrBackendTexture yuvTextures[3], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 511 | GrSurfaceOrigin imageOrigin, |
| 512 | sk_sp<SkColorSpace> imageColorSpace = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 513 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 514 | #Line # creates Image from YUV_ColorSpace data in three planes ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 515 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 516 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 517 | #NoExample |
| 518 | ## |
| 519 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 520 | #SeeAlso MakeFromYUVTexturesCopyWithExternalBackend MakeFromNV12TexturesCopy MakeFromYUVATexturesCopy |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 521 | |
| 522 | #Method ## |
| 523 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 524 | # ------------------------------------------------------------------------------ |
| 525 | |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 526 | #Method static sk_sp<SkImage> MakeFromYUVTexturesCopyWithExternalBackend( |
| 527 | GrContext* context, SkYUVColorSpace yuvColorSpace, |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 528 | const GrBackendTexture yuvTextures[3], GrSurfaceOrigin imageOrigin, |
| 529 | const GrBackendTexture& backendTexture, sk_sp<SkColorSpace> imageColorSpace = nullptr); |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 530 | #In Constructors |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 531 | #Line # creates Image from planar YUV_ColorSpace, stored in texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 532 | #Populate |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 533 | |
| 534 | #NoExample |
| 535 | ## |
| 536 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 537 | #SeeAlso MakeFromYUVTexturesCopy MakeFromNV12TexturesCopy MakeFromYUVATexturesCopyWithExternalBackend |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 538 | |
| 539 | #Method ## |
| 540 | |
| 541 | # ------------------------------------------------------------------------------ |
| 542 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 543 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, |
| 544 | SkYUVColorSpace yuvColorSpace, |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 545 | const GrBackendTexture nv12Textures[2], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 546 | GrSurfaceOrigin imageOrigin, |
| 547 | sk_sp<SkColorSpace> imageColorSpace = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 548 | #In Constructors |
Brian Salomon | 6a426c1 | 2018-03-15 12:16:02 -0400 | [diff] [blame] | 549 | #Line # creates Image from YUV_ColorSpace data in three planes ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 550 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 551 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 552 | #NoExample |
| 553 | ## |
| 554 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 555 | #SeeAlso MakeFromNV12TexturesCopyWithExternalBackend MakeFromYUVTexturesCopy MakeFromYUVATexturesCopy |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 556 | |
| 557 | #Method ## |
| 558 | |
| 559 | #Method static sk_sp<SkImage> MakeFromNV12TexturesCopyWithExternalBackend( |
| 560 | GrContext* context, |
| 561 | SkYUVColorSpace yuvColorSpace, |
| 562 | const GrBackendTexture nv12Textures[2], |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 563 | GrSurfaceOrigin imageOrigin, |
| 564 | const GrBackendTexture& backendTexture, |
| 565 | sk_sp<SkColorSpace> imageColorSpace = nullptr); |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 566 | #In Constructors |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 567 | #Line # creates Image from planar YUV_ColorSpace, stored in texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 568 | #Populate |
Cary Clark | cdc371a | 2018-09-18 07:31:37 -0400 | [diff] [blame] | 569 | |
| 570 | #NoExample |
| 571 | ## |
| 572 | |
Robert Phillips | b6df1c1 | 2018-10-05 10:31:34 -0400 | [diff] [blame] | 573 | #SeeAlso MakeFromNV12TexturesCopy MakeFromYUVTexturesCopy MakeFromYUVATexturesCopyWithExternalBackend |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 574 | |
| 575 | #Method ## |
| 576 | |
| 577 | # ------------------------------------------------------------------------------ |
| 578 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 579 | # currently uncalled by any test or client ## |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 580 | #Bug 7424 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 581 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 582 | #EnumClass BitDepth |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 583 | #Line # options for MakeFromPicture ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 584 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 585 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 586 | ## |
| 587 | |
| 588 | #Const kU8 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 589 | #Line # uses 8-bit unsigned int per Color component ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 590 | Use 8 bits per ARGB component using unsigned integer format. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 591 | ## |
| 592 | #Const kF16 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 593 | #Line # uses 16-bit float per Color component ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 594 | Use 16 bits per ARGB component using half-precision floating point format. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 595 | ## |
| 596 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 597 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 598 | ## |
| 599 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 600 | #SeeAlso MakeFromPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 601 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 602 | #EnumClass ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 603 | |
| 604 | # ------------------------------------------------------------------------------ |
| 605 | |
| 606 | #Method static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions, |
| 607 | const SkMatrix* matrix, const SkPaint* paint, |
| 608 | BitDepth bitDepth, |
| 609 | sk_sp<SkColorSpace> colorSpace) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 610 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 611 | #Line # creates Image from Picture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 612 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 613 | |
| 614 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 615 | SkPaint paint; |
| 616 | SkPictureRecorder recorder; |
| 617 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 618 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 619 | paint.setColor(color); |
| 620 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 621 | recordingCanvas->translate(10, 10); |
| 622 | recordingCanvas->scale(1.2f, 1.4f); |
| 623 | } |
| 624 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 625 | int x = 0, y = 0; |
| 626 | for (auto alpha : { 70, 140, 210 } ) { |
| 627 | paint.setAlpha(alpha); |
| 628 | auto srgbColorSpace = SkColorSpace::MakeSRGB(); |
| 629 | sk_sp<SkImage> image = SkImage::MakeFromPicture(playback, {50, 50}, nullptr, &paint, |
| 630 | SkImage::BitDepth::kU8, srgbColorSpace); |
| 631 | canvas->drawImage(image, x, y); |
| 632 | x += 70; y += 70; |
| 633 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 634 | ## |
| 635 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 636 | #SeeAlso SkCanvas::drawPicture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 637 | |
| 638 | #Method ## |
| 639 | |
| 640 | # ------------------------------------------------------------------------------ |
| 641 | |
Cary Clark | 9548ea9 | 2018-09-13 15:26:33 -0400 | [diff] [blame] | 642 | #Method static sk_sp<SkImage> MakeFromAHardwareBuffer( |
| 643 | AHardwareBuffer* hardwareBuffer, |
| 644 | SkAlphaType alphaType = kPremul_SkAlphaType, |
| 645 | sk_sp<SkColorSpace> colorSpace = nullptr, |
| 646 | GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 647 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 648 | #Line # creates Image from Android hardware buffer ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 649 | #Populate |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 650 | |
| 651 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 652 | ## |
| 653 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 654 | #SeeAlso MakeFromRaster |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 655 | |
| 656 | #Method ## |
| 657 | |
| 658 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 659 | #Subtopic Property |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 660 | #Line # values and attributes ## |
| 661 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 662 | |
| 663 | #Method int width() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 664 | #In Property |
| 665 | #Line # returns pixel column count ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 666 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 667 | |
| 668 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 669 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 670 | #Height 96 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 671 | canvas->translate(10, 10); |
| 672 | canvas->drawImage(image, 0, 0); |
| 673 | canvas->translate(0, image->height()); |
| 674 | SkPaint paint; |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 675 | canvas->drawLine(0, 10, image->width(), 10, paint); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 676 | canvas->drawString("width", image->width() / 2 - 15, 25, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 677 | ## |
| 678 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 679 | #SeeAlso dimensions() height() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 680 | |
| 681 | #Method ## |
| 682 | |
| 683 | # ------------------------------------------------------------------------------ |
| 684 | |
| 685 | #Method int height() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 686 | #In Property |
| 687 | #Line # returns pixel row count ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 688 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 689 | |
| 690 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 691 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 692 | #Height 96 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 693 | canvas->translate(10, 10); |
| 694 | canvas->drawImage(image, 0, 0); |
| 695 | canvas->translate(image->width(), 0); |
| 696 | SkPaint paint; |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 697 | canvas->drawLine(10, 0, 10, image->height(), paint); |
Cary Clark | 92694be | 2018-10-25 08:15:36 -0400 | [diff] [blame] | 698 | canvas->drawString("height", 34, image->height() / 2, paint); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 699 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 700 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 701 | #SeeAlso dimensions() width() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 702 | |
| 703 | #Method ## |
| 704 | |
| 705 | # ------------------------------------------------------------------------------ |
| 706 | |
| 707 | #Method SkISize dimensions() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 708 | #In Property |
| 709 | #Line # returns width() and height() ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 710 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 711 | |
| 712 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 713 | #Image 4 |
| 714 | SkISize dimensions = image->dimensions(); |
| 715 | SkIRect bounds = image->bounds(); |
| 716 | SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions); |
| 717 | SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 718 | #StdOut |
| 719 | dimensionsAsBounds == bounds |
| 720 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 721 | ## |
| 722 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 723 | #SeeAlso height() width() bounds() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 724 | |
| 725 | #Method ## |
| 726 | |
| 727 | # ------------------------------------------------------------------------------ |
| 728 | |
| 729 | #Method SkIRect bounds() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 730 | #In Property |
| 731 | #Line # returns width() and height() as Rectangle ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 732 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 733 | |
| 734 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 735 | #Height 128 |
| 736 | #Image 4 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 737 | SkIRect bounds = image->bounds(); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 738 | for (int x : { 0, bounds.width() } ) { |
| 739 | for (int y : { 0, bounds.height() } ) { |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 740 | canvas->drawImage(image, x, y); |
| 741 | } |
| 742 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 743 | ## |
| 744 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 745 | #SeeAlso dimensions() |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 746 | |
| 747 | #Method ## |
| 748 | |
| 749 | # ------------------------------------------------------------------------------ |
| 750 | |
| 751 | #Method uint32_t uniqueID() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 752 | #In Property |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 753 | #Line # returns identifier for Image ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 754 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 755 | |
| 756 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 757 | #Image 5 |
| 758 | #Height 156 |
| 759 | sk_sp<SkImage> subset = image->makeSubset({10, 20, 90, 100}); |
| 760 | canvas->drawImage(image, 0, 0); |
| 761 | canvas->drawImage(subset, 128, 0); |
| 762 | SkPaint paint; |
| 763 | SkString s; |
| 764 | s.printf("original id: %d", image->uniqueID()); |
| 765 | canvas->drawString(s, 20, image->height() + 20, paint); |
| 766 | s.printf("subset id: %d", subset->uniqueID()); |
| 767 | canvas->drawString(s, 148, subset->height() + 20, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 768 | ## |
| 769 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 770 | #SeeAlso isLazyGenerated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 771 | |
| 772 | #Method ## |
| 773 | |
| 774 | # ------------------------------------------------------------------------------ |
| 775 | |
| 776 | #Method SkAlphaType alphaType() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 777 | #In Property |
| 778 | #Line # returns Alpha_Type ## |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 779 | Returns Alpha_Type, one of: #list_of_alpha_types#. |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 780 | |
| 781 | Alpha_Type returned was a parameter to an Image constructor, |
| 782 | or was parsed from encoded data. |
| 783 | |
| 784 | #Return Alpha_Type in Image ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 785 | |
| 786 | #Example |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 787 | #Image 4 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 788 | #Height 96 |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 789 | const char* alphaTypeStr[] = { "Unknown", "Opaque", "Premul", "Unpremul" }; |
| 790 | SkAlphaType alphaType = image->alphaType(); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 791 | canvas->drawImage(image, 16, 0); |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 792 | canvas->drawString(alphaTypeStr[(int) alphaType], 20, image->height() + 20, SkPaint()); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 793 | ## |
| 794 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 795 | #SeeAlso SkImageInfo::alphaType |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 796 | |
| 797 | #Method ## |
| 798 | |
| 799 | # ------------------------------------------------------------------------------ |
| 800 | |
Greg Daniel | 56008aa | 2018-03-14 15:33:42 -0400 | [diff] [blame] | 801 | #Method SkColorType colorType() const |
| 802 | #In Property |
| 803 | #Line # returns Color_Type ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 804 | #Populate |
Greg Daniel | 56008aa | 2018-03-14 15:33:42 -0400 | [diff] [blame] | 805 | |
| 806 | #Example |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 807 | #Image 4 |
| 808 | #Height 96 |
| 809 | const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", |
| 810 | "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" }; |
| 811 | SkColorType colorType = image->colorType(); |
| 812 | canvas->drawImage(image, 16, 0); |
| 813 | canvas->drawString(colors[(int) colorType], 20, image->height() + 20, SkPaint()); |
Greg Daniel | 56008aa | 2018-03-14 15:33:42 -0400 | [diff] [blame] | 814 | ## |
| 815 | |
| 816 | #SeeAlso SkImageInfo::colorType |
| 817 | |
| 818 | #Method ## |
| 819 | |
| 820 | # ------------------------------------------------------------------------------ |
| 821 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 822 | #Method SkColorSpace* colorSpace() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 823 | #In Property |
| 824 | #Line # returns Color_Space ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 825 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 826 | |
| 827 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 828 | #Image 3 |
| 829 | #Set sRGB |
| 830 | SkPixmap pixmap; |
| 831 | source.peekPixels(&pixmap); |
| 832 | canvas->scale(.25f, .25f); |
| 833 | int y = 0; |
| 834 | for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, |
| 835 | SkColorSpace::kSRGB_RenderTargetGamma } ) { |
| 836 | int x = 0; |
| 837 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); |
| 838 | for (int index = 0; index < 2; ++index) { |
| 839 | pixmap.setColorSpace(colorSpace); |
| 840 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 841 | canvas->drawImage(image, x, y); |
| 842 | colorSpace = image->colorSpace()->makeColorSpin(); |
| 843 | x += 512; |
| 844 | } |
| 845 | y += 512; |
| 846 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 847 | ## |
| 848 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 849 | #SeeAlso refColorSpace makeColorSpace |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 850 | |
| 851 | #Method ## |
| 852 | |
| 853 | # ------------------------------------------------------------------------------ |
| 854 | |
| 855 | #Method sk_sp<SkColorSpace> refColorSpace() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 856 | #In Property |
| 857 | #Line # returns Image_Info Color_Space ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 858 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 859 | |
| 860 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 861 | #Image 3 |
| 862 | #Set sRGB |
| 863 | SkPixmap pixmap; |
| 864 | source.peekPixels(&pixmap); |
| 865 | canvas->scale(.25f, .25f); |
| 866 | int y = 0; |
| 867 | for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, |
| 868 | SkColorSpace::kSRGB_RenderTargetGamma } ) { |
| 869 | int x = 0; |
| 870 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); |
| 871 | for (int index = 0; index < 2; ++index) { |
| 872 | pixmap.setColorSpace(colorSpace); |
| 873 | sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap); |
| 874 | canvas->drawImage(image, x, y); |
| 875 | colorSpace = image->refColorSpace()->makeColorSpin(); |
| 876 | x += 512; |
| 877 | } |
| 878 | y += 512; |
| 879 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 880 | ## |
| 881 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 882 | #SeeAlso colorSpace makeColorSpace |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 883 | |
| 884 | #Method ## |
| 885 | |
| 886 | # ------------------------------------------------------------------------------ |
| 887 | |
| 888 | #Method bool isAlphaOnly() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 889 | #In Property |
| 890 | #Line # returns if pixels represent a transparency mask ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 891 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 892 | |
| 893 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 894 | uint8_t pmColors = 0; |
| 895 | sk_sp<SkImage> image = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1), &pmColors, 1}); |
| 896 | SkDebugf("alphaOnly = %s\n", image->isAlphaOnly() ? "true" : "false"); |
| 897 | #StdOut |
| 898 | alphaOnly = true |
| 899 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 900 | ## |
| 901 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 902 | #SeeAlso alphaType isOpaque |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 903 | |
| 904 | #Method ## |
| 905 | |
| 906 | # ------------------------------------------------------------------------------ |
| 907 | |
| 908 | #Method bool isOpaque() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 909 | #In Property |
| 910 | #Line # returns if Alpha_Type is kOpaque_SkAlphaType ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 911 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 912 | |
| 913 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 914 | auto check_isopaque = [](const SkImageInfo& imageInfo) -> void { |
| 915 | auto surface(SkSurface::MakeRaster(imageInfo)); |
| 916 | auto image(surface->makeImageSnapshot()); |
| 917 | SkDebugf("isOpaque = %s\n", image->isOpaque() ? "true" : "false"); |
| 918 | }; |
| 919 | |
| 920 | check_isopaque(SkImageInfo::MakeN32Premul(5, 5)); |
| 921 | check_isopaque(SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType)); |
| 922 | #StdOut |
| 923 | isOpaque = false |
| 924 | isOpaque = true |
| 925 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 926 | ## |
| 927 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 928 | #SeeAlso alphaType isAlphaOnly |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 929 | |
| 930 | #Method ## |
| 931 | |
| 932 | # ------------------------------------------------------------------------------ |
| 933 | |
| 934 | #Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2, |
| 935 | const SkMatrix* localMatrix = nullptr) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 936 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 937 | #Line # creates Shader, Paint element that can tile Image ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 938 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 939 | |
| 940 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 941 | #Image 4 |
| 942 | SkMatrix matrix; |
| 943 | matrix.setRotate(45); |
| 944 | SkPaint paint; |
| 945 | paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode, |
| 946 | &matrix)); |
| 947 | canvas->drawPaint(paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 948 | ## |
| 949 | |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 950 | #SeeAlso scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 951 | |
| 952 | #Method ## |
| 953 | |
| 954 | # ------------------------------------------------------------------------------ |
| 955 | |
| 956 | #Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 957 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 958 | |
| 959 | #Example |
Cary Clark | 61dfc3a | 2018-01-03 08:37:53 -0500 | [diff] [blame] | 960 | #Image 5 |
| 961 | SkMatrix matrix; |
| 962 | matrix.setRotate(45); |
| 963 | matrix.postTranslate(125, 30); |
| 964 | SkPaint paint; |
| 965 | paint.setShader(image->makeShader(&matrix)); |
| 966 | canvas->drawPaint(paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 967 | ## |
| 968 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 969 | #SeeAlso scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 970 | |
| 971 | #Method ## |
| 972 | |
| 973 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 974 | #Subtopic Pixels |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 975 | #Line # read and write pixel values ## |
| 976 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 977 | |
| 978 | #Method bool peekPixels(SkPixmap* pixmap) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 979 | #In Pixels |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 980 | #Line # returns Pixmap if possible ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 981 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 982 | |
| 983 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 984 | SkBitmap bitmap; |
| 985 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(12, 11)); |
| 986 | SkCanvas offscreen(bitmap); |
| 987 | offscreen.clear(SK_ColorWHITE); |
| 988 | SkPaint paint; |
| 989 | offscreen.drawString("%", 1, 10, paint); |
| 990 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 991 | SkPixmap pixmap; |
| 992 | if (image->peekPixels(&pixmap)) { |
| 993 | const SkPMColor* pixels = pixmap.addr32(); |
| 994 | SkPMColor pmWhite = pixels[0]; |
| 995 | for (int y = 0; y < image->height(); ++y) { |
| 996 | for (int x = 0; x < image->width(); ++x) { |
| 997 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 998 | } |
| 999 | SkDebugf("\n"); |
| 1000 | } |
| 1001 | } |
| 1002 | #StdOut |
| 1003 | ------------ |
| 1004 | --xx----x--- |
| 1005 | -x--x--x---- |
| 1006 | -x--x--x---- |
| 1007 | -x--x-x----- |
| 1008 | --xx-xx-xx-- |
| 1009 | -----x-x--x- |
| 1010 | ----x--x--x- |
| 1011 | ----x--x--x- |
| 1012 | ---x----xx-- |
| 1013 | ------------ |
| 1014 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1015 | ## |
| 1016 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1017 | #SeeAlso readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1018 | |
| 1019 | #Method ## |
| 1020 | |
| 1021 | # ------------------------------------------------------------------------------ |
| 1022 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1023 | #Method bool isTextureBacked() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1024 | #In Property |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1025 | #Line # returns if Image was created from GPU_Texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1026 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1027 | |
| 1028 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1029 | #Image 5 |
| 1030 | #Platform gpu |
| 1031 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1032 | if (nullptr == image) { |
| 1033 | return; |
| 1034 | } |
| 1035 | SkPaint paint; |
| 1036 | paint.setAntiAlias(true); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1037 | canvas->drawImage(image, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1038 | canvas->drawString(label, 30, image->height() / 4, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1039 | canvas->drawString(image->isTextureBacked() ? "is GPU texture" : "not GPU texture", |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1040 | 20, image->height() * 3 / 4, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1041 | }; |
| 1042 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1043 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1044 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1045 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1046 | drawImage(image, "image"); |
| 1047 | canvas->translate(image->width(), 0); |
| 1048 | drawImage(bitmapImage, "source"); |
| 1049 | canvas->translate(-image->width(), image->height()); |
| 1050 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1051 | ## |
| 1052 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1053 | #SeeAlso MakeFromTexture isValid |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1054 | |
| 1055 | #Method ## |
| 1056 | |
| 1057 | # ------------------------------------------------------------------------------ |
| 1058 | |
| 1059 | #Method bool isValid(GrContext* context) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1060 | #In Property |
| 1061 | #Line # returns if Image can draw to Raster_Surface or GPU_Context ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1062 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1063 | |
| 1064 | #Example |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1065 | #Image 5 |
| 1066 | #Platform gpu |
| 1067 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1068 | if (nullptr == image) { |
| 1069 | return; |
| 1070 | } |
| 1071 | SkPaint paint; |
| 1072 | paint.setAntiAlias(true); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1073 | canvas->drawImage(image, 0, 0); |
| 1074 | canvas->drawString(label, image->width() / 2, image->height() / 4, paint); |
| 1075 | if (canvas->getGrContext()) { |
| 1076 | canvas->drawString(image->isValid(canvas->getGrContext()) ? "is valid on GPU" : |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1077 | "not valid on GPU", 20, image->height() * 5 / 8, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1078 | } |
| 1079 | canvas->drawString(image->isValid(nullptr) ? "is valid on CPU" : |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1080 | "not valid on CPU", 20, image->height() * 7 / 8, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1081 | }; |
| 1082 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1083 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1084 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1085 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1086 | drawImage(image, "image"); |
| 1087 | canvas->translate(image->width(), 0); |
| 1088 | drawImage(bitmapImage, "source"); |
| 1089 | canvas->translate(-image->width(), image->height()); |
| 1090 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1091 | ## |
| 1092 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1093 | #SeeAlso isTextureBacked isLazyGenerated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1094 | |
| 1095 | #Method ## |
| 1096 | |
| 1097 | # ------------------------------------------------------------------------------ |
| 1098 | |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 1099 | #Method GrBackendTexture getBackendTexture(bool flushPendingGrContextIO, |
| 1100 | GrSurfaceOrigin* origin = nullptr) const |
| 1101 | #In Property |
| 1102 | #Line # returns GPU reference to Image as texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1103 | #Populate |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 1104 | |
Cary Clark | ba75aee | 2018-04-05 08:18:41 -0400 | [diff] [blame] | 1105 | #Example |
| 1106 | #Image 3 |
| 1107 | #Platform gpu |
Brian Osman | 584b501 | 2018-04-13 15:48:26 -0400 | [diff] [blame] | 1108 | GrContext* grContext = canvas->getGrContext(); |
| 1109 | if (!grContext) { |
| 1110 | canvas->drawString("GPU only!", 20, 40, SkPaint()); |
| 1111 | return; |
| 1112 | } |
| 1113 | sk_sp<SkImage> imageFromBackend = SkImage::MakeFromAdoptedTexture(grContext, backEndTexture, |
| 1114 | kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); |
| 1115 | GrBackendTexture textureFromImage = imageFromBackend->getBackendTexture(false); |
| 1116 | if (!textureFromImage.isValid()) { |
| 1117 | return; |
| 1118 | } |
| 1119 | sk_sp<SkImage> imageFromTexture = SkImage::MakeFromAdoptedTexture(grContext, textureFromImage, |
| 1120 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); |
| 1121 | canvas->drawImage(imageFromTexture, 0, 0); |
Cary Clark | ba75aee | 2018-04-05 08:18:41 -0400 | [diff] [blame] | 1122 | canvas->drawImage(imageFromBackend, 128, 128); |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 1123 | ## |
| 1124 | |
| 1125 | #SeeAlso MakeFromTexture isTextureBacked |
| 1126 | |
| 1127 | #Method ## |
| 1128 | |
| 1129 | # ------------------------------------------------------------------------------ |
| 1130 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1131 | #Enum CachingHint |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1132 | #Line # options for readPixels and scalePixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1133 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1134 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1135 | ## |
| 1136 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1137 | CachingHint selects whether Skia may internally cache Bitmaps generated by |
| 1138 | 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] | 1139 | allows caching Bitmaps. |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1140 | |
| 1141 | Choose kDisallow_CachingHint if Image pixels are to be used only once, or |
| 1142 | if Image pixels reside in a cache outside of Skia, or to reduce memory pressure. |
| 1143 | |
| 1144 | Choosing kAllow_CachingHint does not ensure that pixels will be cached. |
| 1145 | Image pixels may not be cached if memory requirements are too large or |
| 1146 | pixels are not accessible. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1147 | |
| 1148 | #Const kAllow_CachingHint 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1149 | #Line # allows internally caching decoded and copied pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1150 | ## |
| 1151 | #Const kDisallow_CachingHint 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1152 | #Line # disallows internally caching decoded and copied pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1153 | ## |
| 1154 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1155 | #NoExample |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1156 | ## |
| 1157 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1158 | #SeeAlso readPixels scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1159 | |
| 1160 | #Enum ## |
| 1161 | |
| 1162 | # ------------------------------------------------------------------------------ |
| 1163 | |
| 1164 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 1165 | int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1166 | #In Pixels |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1167 | #Line # copies and converts pixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1168 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1169 | 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] | 1170 | and does not exceed Image (width(), height()). |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1171 | |
| 1172 | dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of |
| 1173 | destination. dstRowBytes specifics the gap from one destination row to the next. |
| 1174 | Returns true if pixels are copied. Returns false if: |
| 1175 | #List |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 1176 | # dstInfo has no address ## |
| 1177 | # dstRowBytes is less than dstInfo.minRowBytes() ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1178 | # Pixel_Ref is nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1179 | ## |
| 1180 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1181 | 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] | 1182 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. |
| 1183 | If Image Color_Type is kGray_8_SkColorType, dstInfo.colorSpace() must match. |
| 1184 | If Image Alpha_Type is kOpaque_SkAlphaType, dstInfo.alphaType() must |
| 1185 | match. If Image Color_Space is nullptr, dstInfo.colorSpace() must match. Returns |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1186 | false if pixel conversion is not possible. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1187 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1188 | 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] | 1189 | false if width() or height() is zero or negative. |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 1190 | 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] | 1191 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1192 | If cachingHint is kAllow_CachingHint, pixels may be retained locally. |
| 1193 | If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. |
| 1194 | |
| 1195 | #Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ## |
| 1196 | #Param dstPixels destination pixel storage ## |
| 1197 | #Param dstRowBytes destination row length ## |
| 1198 | #Param srcX column index whose absolute value is less than width() ## |
| 1199 | #Param srcY row index whose absolute value is less than height() ## |
| 1200 | #Param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint ## |
| 1201 | |
| 1202 | #Return true if pixels are copied to dstPixels ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1203 | |
| 1204 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1205 | #Image 3 |
| 1206 | canvas->scale(.5f, .5f); |
| 1207 | const int width = 32; |
| 1208 | const int height = 32; |
| 1209 | std::vector<int32_t> dstPixels; |
| 1210 | dstPixels.resize(height * width * 4); |
| 1211 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 1212 | for (int y = 0; y < 512; y += height ) { |
| 1213 | for (int x = 0; x < 512; x += width ) { |
| 1214 | if (image->readPixels(info, &dstPixels.front(), width * 4, x, y)) { |
| 1215 | SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); |
| 1216 | SkBitmap bitmap; |
| 1217 | bitmap.installPixels(dstPixmap); |
| 1218 | canvas->drawBitmap(bitmap, 0, 0); |
| 1219 | } |
| 1220 | canvas->translate(48, 0); |
| 1221 | } |
| 1222 | canvas->translate(-16 * 48, 48); |
| 1223 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1224 | ## |
| 1225 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1226 | #SeeAlso scalePixels SkBitmap::readPixels SkPixmap::readPixels SkCanvas::readPixels SkSurface::readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1227 | |
| 1228 | #Method ## |
| 1229 | |
| 1230 | # ------------------------------------------------------------------------------ |
| 1231 | |
| 1232 | #Method bool readPixels(const SkPixmap& dst, int srcX, int srcY, |
| 1233 | CachingHint cachingHint = kAllow_CachingHint) const |
| 1234 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1235 | 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] | 1236 | does not exceed Image (width(), height()). |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1237 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1238 | dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage, |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 1239 | 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] | 1240 | row to the next. Returns true if pixels are copied. Returns false if: |
| 1241 | #List |
| 1242 | # dst pixel storage equals nullptr ## |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 1243 | # dst.rowBytes() is less than SkImageInfo::minRowBytes ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1244 | # Pixel_Ref is nullptr ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1245 | ## |
| 1246 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1247 | 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] | 1248 | kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match. |
| 1249 | If Image Color_Type is kGray_8_SkColorType, dst.colorSpace() must match. |
| 1250 | If Image Alpha_Type is kOpaque_SkAlphaType, dst.alphaType() must |
| 1251 | match. If Image Color_Space is nullptr, dst.colorSpace() must match. Returns |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1252 | false if pixel conversion is not possible. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1253 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1254 | 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] | 1255 | false if width() or height() is zero or negative. |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 1256 | 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] | 1257 | |
| 1258 | If cachingHint is kAllow_CachingHint, pixels may be retained locally. |
| 1259 | If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache. |
| 1260 | |
| 1261 | #Param dst destination Pixmap: Image_Info, pixels, row bytes ## |
| 1262 | #Param srcX column index whose absolute value is less than width() ## |
| 1263 | #Param srcY row index whose absolute value is less than height() ## |
| 1264 | #Param cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint ## |
| 1265 | |
| 1266 | #Return true if pixels are copied to dst ## |
| 1267 | |
| 1268 | #Example |
| 1269 | #Image 3 |
| 1270 | std::vector<int32_t> srcPixels; |
| 1271 | int rowBytes = image->width() * 4; |
| 1272 | int quarterWidth = image->width() / 4; |
| 1273 | int quarterHeight = image->height() / 4; |
| 1274 | srcPixels.resize(image->height() * rowBytes); |
| 1275 | for (int y = 0; y < 4; ++y) { |
| 1276 | for (int x = 0; x < 4; ++x) { |
| 1277 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight), |
| 1278 | &srcPixels.front() + x * image->height() * quarterWidth + |
| 1279 | y * quarterWidth, rowBytes); |
| 1280 | image->readPixels(pixmap, x * quarterWidth, y * quarterHeight); |
| 1281 | } |
| 1282 | } |
| 1283 | canvas->scale(.5f, .5f); |
| 1284 | SkBitmap bitmap; |
| 1285 | bitmap.installPixels(SkImageInfo::MakeN32Premul(image->width(), image->height()), |
| 1286 | &srcPixels.front(), rowBytes); |
| 1287 | canvas->drawBitmap(bitmap, 0, 0); |
| 1288 | ## |
| 1289 | |
| 1290 | #SeeAlso scalePixels SkBitmap::readPixels SkPixmap::readPixels SkCanvas::readPixels SkSurface::readPixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1291 | |
| 1292 | #Method ## |
| 1293 | |
| 1294 | # ------------------------------------------------------------------------------ |
| 1295 | |
| 1296 | #Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality, |
| 1297 | CachingHint cachingHint = kAllow_CachingHint) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1298 | #In Pixels |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1299 | #Line # scales and converts one Image to another ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1300 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1301 | |
| 1302 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1303 | #Image 3 |
| 1304 | #Height 128 |
| 1305 | std::vector<int32_t> srcPixels; |
| 1306 | int quarterWidth = image->width() / 16; |
| 1307 | int rowBytes = quarterWidth * 4; |
| 1308 | int quarterHeight = image->height() / 16; |
| 1309 | srcPixels.resize(quarterHeight * rowBytes); |
| 1310 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight), |
| 1311 | &srcPixels.front(), rowBytes); |
| 1312 | canvas->scale(4, 4); |
| 1313 | SkFilterQuality qualities[] = { kNone_SkFilterQuality, kLow_SkFilterQuality, |
| 1314 | kMedium_SkFilterQuality, kHigh_SkFilterQuality }; |
| 1315 | for (unsigned index = 0; index < SK_ARRAY_COUNT(qualities); ++index) { |
| 1316 | image->scalePixels(pixmap, qualities[index]); |
| 1317 | sk_sp<SkImage> filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr); |
| 1318 | canvas->drawImage(filtered, 16 * index, 0); |
| 1319 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1320 | ## |
| 1321 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1322 | #SeeAlso SkCanvas::drawImage readPixels SkPixmap::scalePixels |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1323 | |
| 1324 | #Method ## |
| 1325 | |
| 1326 | # ------------------------------------------------------------------------------ |
| 1327 | |
| 1328 | #Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1329 | #In Utility |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1330 | #Line # returns encoded Image as SkData ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1331 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1332 | |
| 1333 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1334 | #Image 3 |
| 1335 | canvas->scale(4, 4); |
| 1336 | SkIRect subset = {0, 0, 16, 64}; |
| 1337 | int x = 0; |
| 1338 | for (int quality : { 0, 10, 50, 100 } ) { |
| 1339 | sk_sp<SkData> data(image->encodeToData(SkEncodedImageFormat::kJPEG, quality)); |
| 1340 | sk_sp<SkImage> filtered = SkImage::MakeFromEncoded(data, &subset); |
| 1341 | canvas->drawImage(filtered, x, 0); |
| 1342 | x += 16; |
| 1343 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1344 | ## |
| 1345 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1346 | #SeeAlso refEncodedData MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1347 | |
| 1348 | #Method ## |
| 1349 | |
| 1350 | # ------------------------------------------------------------------------------ |
| 1351 | |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1352 | #Method sk_sp<SkData> encodeToData() const |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1353 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1354 | |
| 1355 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1356 | #Image 3 |
| 1357 | canvas->scale(4, 4); |
| 1358 | SkIRect subset = {136, 32, 200, 96}; |
| 1359 | sk_sp<SkData> data(image->encodeToData()); |
| 1360 | sk_sp<SkImage> eye = SkImage::MakeFromEncoded(data, &subset); |
| 1361 | canvas->drawImage(eye, 0, 0); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1362 | ## |
| 1363 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1364 | #SeeAlso refEncodedData MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1365 | |
| 1366 | #Method ## |
| 1367 | |
| 1368 | # ------------------------------------------------------------------------------ |
| 1369 | |
| 1370 | #Method sk_sp<SkData> refEncodedData() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 1371 | #In Utility |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1372 | #Line # returns Image encoded in SkData if present ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1373 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1374 | |
| 1375 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1376 | #Image 3 |
| 1377 | #Platform gpu |
| 1378 | struct { |
| 1379 | const char* name; |
| 1380 | sk_sp<SkImage> image; |
| 1381 | } tests[] = { { "image", image }, { "bitmap", SkImage::MakeFromBitmap(source) }, |
| 1382 | { "texture", SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1383 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1384 | kOpaque_SkAlphaType, nullptr) } }; |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1385 | SkString string; |
| 1386 | SkPaint paint; |
| 1387 | for (const auto& test : tests ) { |
| 1388 | if (!test.image) { |
| 1389 | string.printf("no %s", test.name); |
| 1390 | } else { |
| 1391 | string.printf("%s" "encoded %s", test.image->refEncodedData() ? "" : "no ", test.name); |
| 1392 | } |
| 1393 | canvas->drawString(string, 10, 20, paint); |
| 1394 | canvas->translate(0, 20); |
| 1395 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1396 | ## |
| 1397 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1398 | #SeeAlso encodeToData MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1399 | |
| 1400 | #Method ## |
| 1401 | |
| 1402 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1403 | #Subtopic Utility |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1404 | #Line # rarely called management functions ## |
| 1405 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1406 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1407 | #Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1408 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1409 | #Line # creates Image containing part of original ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1410 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1411 | |
| 1412 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1413 | #Image 3 |
| 1414 | canvas->scale(.5f, .5f); |
Cary Clark | c30382f | 2018-07-24 08:09:27 -0400 | [diff] [blame] | 1415 | const int width = 64; |
| 1416 | const int height = 64; |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1417 | for (int y = 0; y < 512; y += height ) { |
| 1418 | for (int x = 0; x < 512; x += width ) { |
| 1419 | sk_sp<SkImage> subset(image->makeSubset({x, y, x + width, y + height})); |
| 1420 | canvas->drawImage(subset, x * 3 / 2, y * 3 / 2); |
| 1421 | } |
| 1422 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1423 | ## |
| 1424 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1425 | #SeeAlso MakeFromEncoded |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1426 | |
| 1427 | #Method ## |
| 1428 | |
| 1429 | # ------------------------------------------------------------------------------ |
| 1430 | |
Greg Daniel | 5f4b09d | 2018-06-12 16:39:59 -0400 | [diff] [blame] | 1431 | #Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace, |
| 1432 | GrMipMapped mipMapped = GrMipMapped::kNo) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1433 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1434 | #Line # creates Image matching Color_Space if possible ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1435 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1436 | |
| 1437 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1438 | #Platform gpu |
| 1439 | #Image 5 |
| 1440 | auto drawImage = [=](sk_sp<SkImage> image, GrContext* context, const char* label) -> void { |
| 1441 | if (nullptr == image || nullptr == context) { |
| 1442 | return; |
| 1443 | } |
| 1444 | SkPaint paint; |
| 1445 | paint.setAntiAlias(true); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1446 | sk_sp<SkImage> texture(image->makeTextureImage(context, nullptr)); |
| 1447 | canvas->drawImage(texture, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1448 | canvas->drawString(label, 20, texture->height() / 4, paint); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1449 | }; |
| 1450 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1451 | GrContext* context = canvas->getGrContext(); |
| 1452 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(context, backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1453 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1454 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1455 | drawImage(image, context, "image"); |
| 1456 | canvas->translate(image->width(), 0); |
| 1457 | drawImage(bitmapImage, context, "source"); |
| 1458 | canvas->translate(-image->width(), image->height()); |
| 1459 | drawImage(textureImage, context, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1460 | ## |
| 1461 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1462 | #SeeAlso MakeFromTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1463 | |
| 1464 | #Method ## |
| 1465 | |
| 1466 | # ------------------------------------------------------------------------------ |
| 1467 | |
| 1468 | #Method sk_sp<SkImage> makeNonTextureImage() const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1469 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1470 | #Line # creates Image without dependency on GPU_Texture ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1471 | #Populate |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1472 | |
| 1473 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1474 | #Image 5 |
| 1475 | #Platform gpu |
| 1476 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1477 | if (nullptr == image) { |
| 1478 | return; |
| 1479 | } |
| 1480 | SkPaint paint; |
| 1481 | paint.setAntiAlias(true); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1482 | sk_sp<SkImage> nonTexture(image->makeNonTextureImage()); |
| 1483 | canvas->drawImage(nonTexture, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1484 | canvas->drawString(label, 20, nonTexture->height() / 4, paint); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1485 | }; |
| 1486 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1487 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1488 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1489 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1490 | drawImage(image, "image"); |
| 1491 | canvas->translate(image->width(), 0); |
| 1492 | drawImage(bitmapImage, "source"); |
| 1493 | canvas->translate(-image->width(), image->height()); |
| 1494 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1495 | ## |
| 1496 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1497 | #SeeAlso makeTextureImage makeRasterImage MakeBackendTextureFromSkImage |
Cary Clark | 61ca7c5 | 2018-01-02 11:34:14 -0500 | [diff] [blame] | 1498 | |
| 1499 | #Method ## |
| 1500 | |
| 1501 | # ------------------------------------------------------------------------------ |
| 1502 | |
| 1503 | #Method sk_sp<SkImage> makeRasterImage() const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1504 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1505 | #Line # creates Image compatible with Raster_Surface if possible ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1506 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1507 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1508 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1509 | #Image 5 |
| 1510 | #Platform gpu |
| 1511 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1512 | if (nullptr == image) { |
| 1513 | return; |
| 1514 | } |
| 1515 | SkPaint paint; |
| 1516 | paint.setAntiAlias(true); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1517 | sk_sp<SkImage> raster(image->makeRasterImage()); |
| 1518 | canvas->drawImage(raster, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1519 | canvas->drawString(label, 20, raster->height() / 4, paint); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1520 | }; |
| 1521 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1522 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1523 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1524 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1525 | drawImage(image, "image"); |
| 1526 | canvas->translate(image->width(), 0); |
| 1527 | drawImage(bitmapImage, "source"); |
| 1528 | canvas->translate(-image->width(), image->height()); |
| 1529 | drawImage(textureImage, "backEndTexture"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1530 | ## |
| 1531 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1532 | #SeeAlso isTextureBacked isLazyGenerated MakeFromRaster |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1533 | |
| 1534 | #Method ## |
| 1535 | |
| 1536 | # ------------------------------------------------------------------------------ |
| 1537 | |
| 1538 | #Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset, |
| 1539 | const SkIRect& clipBounds, SkIRect* outSubset, |
| 1540 | SkIPoint* offset) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1541 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1542 | #Line # creates filtered, clipped Image ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1543 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1544 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1545 | #Example |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1546 | #Description |
| 1547 | In each frame of the animation, filtered Image is drawn in a different location. |
| 1548 | By translating canvas by returned offset, Image appears stationary. |
| 1549 | ## |
| 1550 | #Image 5 |
| 1551 | #Platform gpu |
Cary Clark | 5717e82 | 2018-09-21 11:36:41 -0400 | [diff] [blame] | 1552 | #Duration 1 |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1553 | sk_sp<SkImageFilter> shadowFilter = SkDropShadowImageFilter::Make( |
| 1554 | -10.0f * frame, 5.0f * frame, 3.0f, 3.0f, SK_ColorBLUE, |
| 1555 | SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
| 1556 | nullptr); |
| 1557 | sk_sp<SkImageFilter> offsetFilter = SkOffsetImageFilter::Make(40, 40, shadowFilter, nullptr); |
| 1558 | SkIRect subset = image->bounds(); |
| 1559 | SkIRect clipBounds = image->bounds(); |
| 1560 | clipBounds.outset(60, 60); |
| 1561 | SkIRect outSubset; |
| 1562 | SkIPoint offset; |
| 1563 | sk_sp<SkImage> filtered(image->makeWithFilter(offsetFilter.get(), subset, clipBounds, |
| 1564 | &outSubset, &offset)); |
| 1565 | SkPaint paint; |
| 1566 | paint.setAntiAlias(true); |
| 1567 | paint.setStyle(SkPaint::kStroke_Style); |
| 1568 | canvas->drawLine(0, 0, offset.fX, offset.fY, paint); |
| 1569 | canvas->translate(offset.fX, offset.fY); |
| 1570 | canvas->drawImage(filtered, 0, 0); |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 1571 | canvas->drawRect(SkRect::Make(outSubset), paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1572 | ## |
| 1573 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1574 | #SeeAlso makeShader SkPaint::setImageFilter |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1575 | |
| 1576 | #Method ## |
| 1577 | |
| 1578 | # ------------------------------------------------------------------------------ |
| 1579 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1580 | #Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1581 | #Line # parameter type for MakeBackendTextureFromSkImage ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1582 | |
| 1583 | #Code |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1584 | #Populate |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1585 | ## |
| 1586 | |
Cary Clark | 0d22539 | 2018-06-07 09:59:07 -0400 | [diff] [blame] | 1587 | Defines a callback function, taking one parameter of type GrBackendTexture with |
| 1588 | 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] | 1589 | ## |
| 1590 | |
| 1591 | # ------------------------------------------------------------------------------ |
| 1592 | |
| 1593 | #Method static bool MakeBackendTextureFromSkImage(GrContext* context, |
| 1594 | sk_sp<SkImage> image, |
| 1595 | GrBackendTexture* backendTexture, |
| 1596 | BackendTextureReleaseProc* backendTextureReleaseProc) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1597 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1598 | #Line # creates GPU_Texture from Image ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1599 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1600 | |
| 1601 | #Example |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1602 | #Platform gpu |
| 1603 | #Height 64 |
| 1604 | #Function |
Brian Salomon | 67f8584 | 2018-02-09 08:50:22 -0500 | [diff] [blame] | 1605 | static sk_sp<SkImage> create_gpu_image(GrContext* grContext) { |
| 1606 | const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
| 1607 | auto surface(SkSurface::MakeRenderTarget(grContext, SkBudgeted::kNo, info)); |
| 1608 | SkCanvas* canvas = surface->getCanvas(); |
| 1609 | canvas->clear(SK_ColorWHITE); |
| 1610 | SkPaint paint; |
| 1611 | paint.setColor(SK_ColorBLACK); |
| 1612 | canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); |
| 1613 | return surface->makeImageSnapshot(); |
| 1614 | } |
| 1615 | ## |
| 1616 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1617 | void draw(SkCanvas* canvas) { |
Brian Salomon | 67f8584 | 2018-02-09 08:50:22 -0500 | [diff] [blame] | 1618 | GrContext* grContext = canvas->getGrContext(); |
| 1619 | if (!grContext) { |
| 1620 | return; |
| 1621 | } |
| 1622 | sk_sp<SkImage> backEndImage = create_gpu_image(grContext); |
| 1623 | canvas->drawImage(backEndImage, 0, 0); |
| 1624 | GrBackendTexture texture; |
| 1625 | SkImage::BackendTextureReleaseProc proc; |
| 1626 | if (!SkImage::MakeBackendTextureFromSkImage(grContext, std::move(backEndImage), |
| 1627 | &texture, &proc)) { |
| 1628 | return; |
| 1629 | } |
| 1630 | sk_sp<SkImage> i2 = SkImage::MakeFromTexture(grContext, texture, kTopLeft_GrSurfaceOrigin, |
| 1631 | kN32_SkColorType, kOpaque_SkAlphaType, nullptr); |
| 1632 | canvas->drawImage(i2, 30, 30); |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1633 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1634 | ## |
| 1635 | |
Cary Clark | 5635631 | 2018-02-08 14:45:18 -0500 | [diff] [blame] | 1636 | #SeeAlso MakeFromTexture makeTextureImage |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1637 | |
| 1638 | #Method ## |
| 1639 | |
| 1640 | # ------------------------------------------------------------------------------ |
| 1641 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1642 | #Method bool isLazyGenerated() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1643 | #In Property |
| 1644 | #Line # returns if Image is created as needed ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1645 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1646 | |
| 1647 | #Example |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 1648 | #Height 80 |
| 1649 | #Function |
| 1650 | class TestImageGenerator : public SkImageGenerator { |
| 1651 | public: |
| 1652 | TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {} |
| 1653 | ~TestImageGenerator() override {} |
| 1654 | protected: |
| 1655 | bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes, |
| 1656 | const Options& options) override { |
| 1657 | SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr); |
| 1658 | for (int y = 0; y < info.height(); ++y) { |
| 1659 | for (int x = 0; x < info.width(); ++x) { |
| 1660 | pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811; |
| 1661 | } |
| 1662 | } |
| 1663 | return true; |
| 1664 | } |
| 1665 | }; |
| 1666 | ## |
| 1667 | void draw(SkCanvas* canvas) { |
| 1668 | auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator()); |
| 1669 | sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen))); |
| 1670 | SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy"); |
| 1671 | canvas->scale(8, 8); |
| 1672 | canvas->drawImage(image, 0, 0, nullptr); |
| 1673 | SkPaint paint; |
| 1674 | paint.setTextSize(4); |
| 1675 | canvas->drawString(lazy, 2, 5, paint); |
| 1676 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1677 | ## |
| 1678 | |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1679 | #Example |
| 1680 | #Image 5 |
| 1681 | #Platform gpu |
| 1682 | void draw(SkCanvas* canvas) { |
| 1683 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 1684 | if (nullptr == image) { |
| 1685 | return; |
| 1686 | } |
| 1687 | SkPaint paint; |
| 1688 | paint.setAntiAlias(true); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1689 | canvas->drawImage(image, 0, 0); |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1690 | canvas->drawString(label, 30, image->height() / 4, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1691 | canvas->drawString( |
| 1692 | image->isLazyGenerated() ? "is lazily generated" : "not lazily generated", |
Cary Clark | 14768f6 | 2018-10-29 20:33:51 -0400 | [diff] [blame] | 1693 | 20, image->height() * 3 / 4, paint); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1694 | }; |
| 1695 | sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source)); |
| 1696 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, |
Cary Clark | ae957c4 | 2018-06-07 17:07:17 -0400 | [diff] [blame] | 1697 | kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, |
| 1698 | kOpaque_SkAlphaType, nullptr)); |
Cary Clark | f5404bb | 2018-01-05 12:10:09 -0500 | [diff] [blame] | 1699 | drawImage(image, "image"); |
| 1700 | canvas->translate(image->width(), 0); |
| 1701 | drawImage(bitmapImage, "source"); |
| 1702 | canvas->translate(-image->width(), image->height()); |
| 1703 | drawImage(textureImage, "backEndTexture"); |
| 1704 | } |
| 1705 | ## |
| 1706 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 1707 | #SeeAlso isTextureBacked makeNonTextureImage |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1708 | |
| 1709 | #Method ## |
| 1710 | |
| 1711 | # ------------------------------------------------------------------------------ |
| 1712 | |
Cary Clark | e80cd44 | 2018-07-17 13:19:56 -0400 | [diff] [blame] | 1713 | #Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target) const |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1714 | #In Constructors |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1715 | #Line # creates Image matching Color_Space if possible ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1716 | #Populate |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1717 | |
| 1718 | #Example |
| 1719 | #Image 5 |
| 1720 | #Set sRGB |
| 1721 | sk_sp<SkColorSpace> normalColorSpace = SkColorSpace::MakeRGB( |
| 1722 | SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kSRGB_Gamut); |
| 1723 | sk_sp<SkColorSpace> wackyColorSpace = normalColorSpace->makeColorSpin(); |
| 1724 | for (auto colorSpace : { normalColorSpace, wackyColorSpace } ) { |
Cary Clark | c3c1c31 | 2018-07-18 09:25:15 -0400 | [diff] [blame] | 1725 | sk_sp<SkImage> colorSpaced = image->makeColorSpace(colorSpace); |
| 1726 | canvas->drawImage(colorSpaced, 0, 0); |
| 1727 | canvas->translate(128, 0); |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1728 | } |
| 1729 | ## |
| 1730 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 1731 | #SeeAlso MakeFromPicture MakeFromTexture |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1732 | |
| 1733 | #Method ## |
| 1734 | |
| 1735 | #Class SkImage ## |
| 1736 | |
| 1737 | #Topic Image ## |