blob: 7a0bc330e6fc8c830380a5b357139a037116c1af [file] [log] [blame]
Cary Clarka560c472017-11-27 10:44:06 -05001#Topic Image
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias Image_Reference ##
Cary Clarka560c472017-11-27 10:44:06 -05003
4#Class SkImage
5
Cary Clark61313f32018-10-08 14:57:48 -04006#Code
7#Populate
8##
9
Cary Clark61ca7c52018-01-02 11:34:14 -050010Image describes a two dimensional array of pixels to draw. The pixels may be
Cary Clark4855f782018-02-06 09:41:53 -050011decoded in a Raster_Bitmap, encoded in a Picture or compressed data stream,
Cary Clark61ca7c52018-01-02 11:34:14 -050012or located in GPU memory as a GPU_Texture.
13
14Image cannot be modified after it is created. Image may allocate additional
15storage as needed; for instance, an encoded Image may decode when drawn.
16
17Image width and height are greater than zero. Creating an Image with zero width
18or height returns Image equal to nullptr.
19
20Image may be created from Bitmap, Pixmap, Surface, Picture, encoded streams,
21GPU_Texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported
Cary Clark4855f782018-02-06 09:41:53 -050022include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details
Cary Clark61ca7c52018-01-02 11:34:14 -050023vary with platform.
24
Cary Clark08895c42018-02-01 09:37:32 -050025#Subtopic Raster_Image
Cary Clark137b8742018-05-30 09:21:49 -040026#Alias Raster_Image ##
Cary Clark4855f782018-02-06 09:41:53 -050027#Line # pixels decoded in Raster_Bitmap ##
28Raster_Image pixels are decoded in a Raster_Bitmap. These pixels may be read
Cary Clark61ca7c52018-01-02 11:34:14 -050029directly and in most cases written to, although edited pixels may not be drawn
30if Image has been copied internally.
31##
32
Cary Clark08895c42018-02-01 09:37:32 -050033#Subtopic Texture_Image
34#Line # pixels located on GPU ##
Cary Clark61ca7c52018-01-02 11:34:14 -050035Texture_Image are located on GPU and pixels are not accessible. Texture_Image
36are allocated optimally for best performance. Raster_Image may
37be drawn to GPU_Surface, but pixels are uploaded from CPU to GPU downgrading
38performance.
39##
40
Cary Clark08895c42018-02-01 09:37:32 -050041#Subtopic Lazy_Image
42#Line # deferred pixel buffer ##
Cary Clark61ca7c52018-01-02 11:34:14 -050043Lazy_Image defer allocating buffer for Image pixels and decoding stream until
44Image is drawn. Lazy_Image caches result if possible to speed up repeated
45drawing.
46##
Cary Clarka560c472017-11-27 10:44:06 -050047
Cary Clarka560c472017-11-27 10:44:06 -050048# ------------------------------------------------------------------------------
49
50#Method static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap)
Cary Clark61313f32018-10-08 14:57:48 -040051#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -050052#Line # creates Image from Pixmap and copied pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -040053#Populate
Cary Clarka560c472017-11-27 10:44:06 -050054
55#Example
Cary Clark2f466242017-12-11 16:03:17 -050056#Height 50
57#Description
58Draw a five by five bitmap, and draw a copy in an Image. Editing the pixmap
59alters the bitmap draw, but does not alter the Image draw since the Image
60contains 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 Clarka560c472017-11-27 10:44:06 -050076##
77
Cary Clark3cd22cc2017-12-01 11:49:58 -050078#SeeAlso MakeRasterData MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -050079
80#Method ##
81
82# ------------------------------------------------------------------------------
83
Cary Clarkcc45cc72018-05-15 16:06:12 -040084#Method static sk_sp<SkImage> MakeRasterData(const SkImageInfo& info, sk_sp<SkData> pixels, size_t rowBytes)
Cary Clark61313f32018-10-08 14:57:48 -040085#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -050086#Line # creates Image from Image_Info and shared pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -040087#Populate
Cary Clarka560c472017-11-27 10:44:06 -050088
89#Example
Cary Clark0c5f5462017-12-15 11:21:51 -050090#Image 3
91 size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType);
92 sk_sp<SkData> data = SkData::MakeUninitialized(rowBytes * image->height());
Cary Clark682c58d2018-05-16 07:07:07 -040093 SkImageInfo dstInfo = SkImageInfo::MakeN32(image->width(), image->height(),
Cary Clark0c5f5462017-12-15 11:21:51 -050094 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 Clarka560c472017-11-27 10:44:06 -0500100##
101
Cary Clark3cd22cc2017-12-01 11:49:58 -0500102#SeeAlso MakeRasterCopy MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500103
104#Method ##
105
106# ------------------------------------------------------------------------------
107
Cary Clark3cd22cc2017-12-01 11:49:58 -0500108#Typedef void* ReleaseContext
Cary Clark682c58d2018-05-16 07:07:07 -0400109#Line # parameter type for MakeFromRaster ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400110
111#Code
Cary Clarka90ea222018-10-16 10:30:28 -0400112#Populate
Cary Clarkffb3d682018-05-17 12:17:28 -0400113##
114
Cary Clark3cd22cc2017-12-01 11:49:58 -0500115Caller data passed to RasterReleaseProc; may be nullptr.
116
117#SeeAlso MakeFromRaster RasterReleaseProc
118
119##
120
Cary Clarka560c472017-11-27 10:44:06 -0500121#Typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext)
Cary Clark682c58d2018-05-16 07:07:07 -0400122#Line # parameter type for MakeFromRaster ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400123
124#Code
Cary Clarka90ea222018-10-16 10:30:28 -0400125#Populate
Cary Clarkffb3d682018-05-17 12:17:28 -0400126##
127
Cary Clark3cd22cc2017-12-01 11:49:58 -0500128Function called when Image no longer shares pixels. ReleaseContext is
Cary Clark682c58d2018-05-16 07:07:07 -0400129provided by caller when Image is created, and may be nullptr.
Cary Clark3cd22cc2017-12-01 11:49:58 -0500130
131#SeeAlso ReleaseContext MakeFromRaster
132
Cary Clarka560c472017-11-27 10:44:06 -0500133##
134
135#Method static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap,
136 RasterReleaseProc rasterReleaseProc,
137 ReleaseContext releaseContext)
Cary Clark61313f32018-10-08 14:57:48 -0400138#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500139#Line # creates Image from Pixmap, with release ##
Cary Clark09d80c02018-10-31 12:14:03 -0400140#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500141
142#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500143#Function
144static void releaseProc(const void* pixels, SkImage::ReleaseContext context) {
145 int* countPtr = static_cast<int*>(context);
146 *countPtr += 1;
147}
148##
149
150void 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
160before reset: 0
161after reset: 1
162##
Cary Clarka560c472017-11-27 10:44:06 -0500163##
164
Cary Clark3cd22cc2017-12-01 11:49:58 -0500165#SeeAlso MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext
Cary Clarka560c472017-11-27 10:44:06 -0500166
167#Method ##
168
169# ------------------------------------------------------------------------------
170
171#Method static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap)
Cary Clark61313f32018-10-08 14:57:48 -0400172#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500173#Line # creates Image from Bitmap, sharing or copying pixels ##
Cary Clark09d80c02018-10-31 12:14:03 -0400174#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500175
176#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500177#Description
178The first Bitmap is shared; writing to the pixel memory changes the first
179Image.
180The second Bitmap is marked immutable, and is copied; writing to the pixel
181memory 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 Clarka560c472017-11-27 10:44:06 -0500200##
201
Cary Clark3cd22cc2017-12-01 11:49:58 -0500202#SeeAlso MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData
Cary Clarka560c472017-11-27 10:44:06 -0500203
204#Method ##
205
206# ------------------------------------------------------------------------------
207
208#Method static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator,
209 const SkIRect* subset = nullptr)
Cary Clark61313f32018-10-08 14:57:48 -0400210#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500211#Line # creates Image from a stream of data ##
Cary Clark09d80c02018-10-31 12:14:03 -0400212#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500213
214#Example
Cary Clarkac47b882018-01-11 10:35:44 -0500215#Height 128
Cary Clark0c5f5462017-12-15 11:21:51 -0500216#Description
217The 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 Clarka560c472017-11-27 10:44:06 -0500226##
227
Cary Clark3cd22cc2017-12-01 11:49:58 -0500228#SeeAlso MakeFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500229
230#Method ##
231
232# ------------------------------------------------------------------------------
233
234#Method static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr)
Cary Clark61313f32018-10-08 14:57:48 -0400235#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500236#Line # creates Image from encoded data ##
Cary Clark09d80c02018-10-31 12:14:03 -0400237#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500238
Cary Clark61ca7c52018-01-02 11:34:14 -0500239#Example
240#Image 3
241int x = 0;
242for (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 Clarka560c472017-11-27 10:44:06 -0500248##
249
Cary Clark3cd22cc2017-12-01 11:49:58 -0500250#SeeAlso MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500251
252#Method ##
253
254# ------------------------------------------------------------------------------
255
256#Typedef void (*TextureReleaseProc)(ReleaseContext releaseContext)
Cary Clark682c58d2018-05-16 07:07:07 -0400257#Line # parameter type for MakeFromTexture ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400258
259#Code
Cary Clarka90ea222018-10-16 10:30:28 -0400260#Populate
Cary Clarkffb3d682018-05-17 12:17:28 -0400261##
262
Cary Clark682c58d2018-05-16 07:07:07 -0400263User function called when supplied texture may be deleted.
264#SeeAlso MakeFromTexture
Cary Clarka560c472017-11-27 10:44:06 -0500265##
266
267#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
268 const GrBackendTexture& backendTexture,
269 GrSurfaceOrigin origin,
Cary Clark61ca7c52018-01-02 11:34:14 -0500270 SkColorType colorType,
271 SkAlphaType alphaType,
272 sk_sp<SkColorSpace> colorSpace)
Cary Clark61313f32018-10-08 14:57:48 -0400273#In Constructors
Cary Clarkf895a422018-02-27 09:54:21 -0500274#Line # creates Image from GPU_Texture ##
Cary Clark09d80c02018-10-31 12:14:03 -0400275#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500276
277#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500278#Image 3
279#Platform gpu
280#Height 128
281#Description
282A back-end texture has been created and uploaded to the GPU outside of this example.
283##
284GrContext* context = canvas->getGrContext();
285if (!context) {
286 return;
287}
288canvas->scale(.25f, .25f);
289int x = 0;
290for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
Cary Clarkac47b882018-01-11 10:35:44 -0500291 sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backEndTexture,
Cary Clarkae957c42018-06-07 17:07:17 -0400292 origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr);
Cary Clark0c5f5462017-12-15 11:21:51 -0500293 canvas->drawImage(image, x, 0);
294x += 512;
295}
Cary Clarka560c472017-11-27 10:44:06 -0500296##
297
Cary Clark3cd22cc2017-12-01 11:49:58 -0500298#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500299
300#Method ##
301
302# ------------------------------------------------------------------------------
303
304#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
305 const GrBackendTexture& backendTexture,
306 GrSurfaceOrigin origin,
Cary Clark61ca7c52018-01-02 11:34:14 -0500307 SkColorType colorType,
Cary Clarka560c472017-11-27 10:44:06 -0500308 SkAlphaType alphaType,
309 sk_sp<SkColorSpace> colorSpace,
310 TextureReleaseProc textureReleaseProc,
311 ReleaseContext releaseContext)
Cary Clark09d80c02018-10-31 12:14:03 -0400312#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500313
Cary Clarka560c472017-11-27 10:44:06 -0500314#Example
Cary Clarkac47b882018-01-11 10:35:44 -0500315#Platform gpu
316#Image 4
Cary Clark0c5f5462017-12-15 11:21:51 -0500317GrContext* context = canvas->getGrContext();
318if (!context) {
319 return;
320}
Cary Clarkac47b882018-01-11 10:35:44 -0500321auto debugster = [](SkImage::ReleaseContext releaseContext) -> void {
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400322 // broken
Cary Clark08417bc2018-10-03 10:44:13 -0400323 // *((int *) releaseContext) += 128;
Cary Clark0c5f5462017-12-15 11:21:51 -0500324};
325int x = 0;
326for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
Cary Clarkac47b882018-01-11 10:35:44 -0500327 sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backEndTexture,
Cary Clark61ca7c52018-01-02 11:34:14 -0500328 origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, debugster, &x);
Cary Clark0c5f5462017-12-15 11:21:51 -0500329 canvas->drawImage(image, x, 0);
330 x += 128;
331}
Cary Clarka560c472017-11-27 10:44:06 -0500332##
333
Cary Clark3cd22cc2017-12-01 11:49:58 -0500334#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500335
336#Method ##
337
338# ------------------------------------------------------------------------------
339
340#Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
341 bool buildMips,
Brian Osman584b5012018-04-13 15:48:26 -0400342 SkColorSpace* dstColorSpace,
343 bool limitToMaxTextureSize = false)
Cary Clark61313f32018-10-08 14:57:48 -0400344#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500345#Line # creates Image from encoded data, and uploads to GPU ##
Cary Clark09d80c02018-10-31 12:14:03 -0400346#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500347
348#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500349#Image 4
Cary Clarkac47b882018-01-11 10:35:44 -0500350#Height 64
Cary Clark61ca7c52018-01-02 11:34:14 -0500351GrContext* context = canvas->getGrContext();
352sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, 100);
353sk_sp<SkImage> image = SkImage::MakeCrossContextFromEncoded(context,
354 encodedData, false, nullptr);
355canvas->drawImage(image, 0, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500356##
357
Cary Clark3cd22cc2017-12-01 11:49:58 -0500358#SeeAlso MakeCrossContextFromPixmap
359
360#Method ##
361
362# ------------------------------------------------------------------------------
363
364#Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
365 bool buildMips,
Brian Osman584b5012018-04-13 15:48:26 -0400366 SkColorSpace* dstColorSpace,
367 bool limitToMaxTextureSize = false)
Cary Clark61313f32018-10-08 14:57:48 -0400368#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500369#Line # creates Image from Pixmap, and uploads to GPU ##
Cary Clark09d80c02018-10-31 12:14:03 -0400370#Populate
Cary Clark3cd22cc2017-12-01 11:49:58 -0500371
372#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500373#Image 4
Cary Clarkac47b882018-01-11 10:35:44 -0500374#Height 64
Cary Clark61ca7c52018-01-02 11:34:14 -0500375GrContext* context = canvas->getGrContext();
376SkPixmap pixmap;
377if (source.peekPixels(&pixmap)) {
378 sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(context, pixmap,
379 false, nullptr);
380 canvas->drawImage(image, 0, 0);
381}
Cary Clark3cd22cc2017-12-01 11:49:58 -0500382##
383
384#SeeAlso MakeCrossContextFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500385
386#Method ##
387
388# ------------------------------------------------------------------------------
389
390#Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
391 const GrBackendTexture& backendTexture,
392 GrSurfaceOrigin surfaceOrigin,
Cary Clark61ca7c52018-01-02 11:34:14 -0500393 SkColorType colorType,
394 SkAlphaType alphaType = kPremul_SkAlphaType,
395 sk_sp<SkColorSpace> colorSpace = nullptr)
Cary Clark61313f32018-10-08 14:57:48 -0400396#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500397#Line # creates Image from GPU_Texture, managed internally ##
Cary Clark09d80c02018-10-31 12:14:03 -0400398#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500399
400#Example
Cary Clarkac47b882018-01-11 10:35:44 -0500401#Image 5
402#Platform gpu
Cary Clark61ca7c52018-01-02 11:34:14 -0500403 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 Clark682c58d2018-05-16 07:07:07 -0400412 backEndTexture, origin,
Cary Clark61ca7c52018-01-02 11:34:14 -0500413 kRGBA_8888_SkColorType, alpha);
414 canvas->drawImage(image, x, y);
415 x += 160;
416 }
417 x -= 160 * 3;
418 y += 256;
419 }
Cary Clarka560c472017-11-27 10:44:06 -0500420##
421
Cary Clark61ca7c52018-01-02 11:34:14 -0500422#SeeAlso MakeFromTexture MakeFromYUVTexturesCopy
Cary Clarka560c472017-11-27 10:44:06 -0500423
424#Method ##
425
426# ------------------------------------------------------------------------------
427
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400428#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 Clark09d80c02018-10-31 12:14:03 -0400437#Populate
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400438
439#NoExample
440##
441
Cary Clark1801b942018-10-30 21:10:03 -0400442#SeeAlso MakeFromYUVATexturesCopyWithExternalBackend MakeFromYUVATextures
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400443
444#Method ##
445
Cary Clark1801b942018-10-30 21:10:03 -0400446#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 Clark09d80c02018-10-31 12:14:03 -0400456#Populate
Cary Clark1801b942018-10-30 21:10:03 -0400457
458#NoExample
459##
460
461#SeeAlso MakeFromYUVATexturesCopy MakeFromYUVATexturesCopyWithExternalBackend
462
463#Method ##
464
Jim Van Verthc8429ad2018-11-20 11:12:37 -0500465#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 Clark1801b942018-10-30 21:10:03 -0400486
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400487# ------------------------------------------------------------------------------
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 Clark09d80c02018-10-31 12:14:03 -0400500#Populate
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400501
502#NoExample
503##
504
Cary Clark1801b942018-10-30 21:10:03 -0400505#SeeAlso MakeFromYUVATexturesCopy MakeFromYUVATextures
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400506
507#Method ##
508
Cary Clarka560c472017-11-27 10:44:06 -0500509#Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
Brian Salomon6a426c12018-03-15 12:16:02 -0400510 const GrBackendTexture yuvTextures[3],
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400511 GrSurfaceOrigin imageOrigin,
512 sk_sp<SkColorSpace> imageColorSpace = nullptr)
Cary Clark61313f32018-10-08 14:57:48 -0400513#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500514#Line # creates Image from YUV_ColorSpace data in three planes ##
Cary Clark09d80c02018-10-31 12:14:03 -0400515#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500516
Cary Clark61ca7c52018-01-02 11:34:14 -0500517#NoExample
518##
519
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400520#SeeAlso MakeFromYUVTexturesCopyWithExternalBackend MakeFromNV12TexturesCopy MakeFromYUVATexturesCopy
Cary Clarkcdc371a2018-09-18 07:31:37 -0400521
522#Method ##
523
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400524# ------------------------------------------------------------------------------
525
Cary Clarkcdc371a2018-09-18 07:31:37 -0400526#Method static sk_sp<SkImage> MakeFromYUVTexturesCopyWithExternalBackend(
527 GrContext* context, SkYUVColorSpace yuvColorSpace,
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400528 const GrBackendTexture yuvTextures[3], GrSurfaceOrigin imageOrigin,
529 const GrBackendTexture& backendTexture, sk_sp<SkColorSpace> imageColorSpace = nullptr);
Cary Clark61313f32018-10-08 14:57:48 -0400530#In Constructors
Cary Clarkcdc371a2018-09-18 07:31:37 -0400531#Line # creates Image from planar YUV_ColorSpace, stored in texture ##
Cary Clark09d80c02018-10-31 12:14:03 -0400532#Populate
Cary Clarkcdc371a2018-09-18 07:31:37 -0400533
534#NoExample
535##
536
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400537#SeeAlso MakeFromYUVTexturesCopy MakeFromNV12TexturesCopy MakeFromYUVATexturesCopyWithExternalBackend
Cary Clark61ca7c52018-01-02 11:34:14 -0500538
539#Method ##
540
541# ------------------------------------------------------------------------------
542
Cary Clarka560c472017-11-27 10:44:06 -0500543#Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context,
544 SkYUVColorSpace yuvColorSpace,
Brian Salomon6a426c12018-03-15 12:16:02 -0400545 const GrBackendTexture nv12Textures[2],
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400546 GrSurfaceOrigin imageOrigin,
547 sk_sp<SkColorSpace> imageColorSpace = nullptr)
Cary Clark61313f32018-10-08 14:57:48 -0400548#In Constructors
Brian Salomon6a426c12018-03-15 12:16:02 -0400549#Line # creates Image from YUV_ColorSpace data in three planes ##
Cary Clark09d80c02018-10-31 12:14:03 -0400550#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500551
Cary Clark61ca7c52018-01-02 11:34:14 -0500552#NoExample
553##
554
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400555#SeeAlso MakeFromNV12TexturesCopyWithExternalBackend MakeFromYUVTexturesCopy MakeFromYUVATexturesCopy
Cary Clarkcdc371a2018-09-18 07:31:37 -0400556
557#Method ##
558
559#Method static sk_sp<SkImage> MakeFromNV12TexturesCopyWithExternalBackend(
560 GrContext* context,
561 SkYUVColorSpace yuvColorSpace,
562 const GrBackendTexture nv12Textures[2],
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400563 GrSurfaceOrigin imageOrigin,
564 const GrBackendTexture& backendTexture,
565 sk_sp<SkColorSpace> imageColorSpace = nullptr);
Cary Clark61313f32018-10-08 14:57:48 -0400566#In Constructors
Cary Clarkcdc371a2018-09-18 07:31:37 -0400567#Line # creates Image from planar YUV_ColorSpace, stored in texture ##
Cary Clark09d80c02018-10-31 12:14:03 -0400568#Populate
Cary Clarkcdc371a2018-09-18 07:31:37 -0400569
570#NoExample
571##
572
Robert Phillipsb6df1c12018-10-05 10:31:34 -0400573#SeeAlso MakeFromNV12TexturesCopy MakeFromYUVTexturesCopy MakeFromYUVATexturesCopyWithExternalBackend
Cary Clarka560c472017-11-27 10:44:06 -0500574
575#Method ##
576
577# ------------------------------------------------------------------------------
578
Cary Clark4855f782018-02-06 09:41:53 -0500579# currently uncalled by any test or client ##
Cary Clark61ca7c52018-01-02 11:34:14 -0500580#Bug 7424
Cary Clark61ca7c52018-01-02 11:34:14 -0500581
Cary Clark56356312018-02-08 14:45:18 -0500582#EnumClass BitDepth
Cary Clark682c58d2018-05-16 07:07:07 -0400583#Line # options for MakeFromPicture ##
Cary Clarka560c472017-11-27 10:44:06 -0500584#Code
Cary Clarka90ea222018-10-16 10:30:28 -0400585#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500586##
587
588#Const kU8 0
Cary Clark682c58d2018-05-16 07:07:07 -0400589#Line # uses 8-bit unsigned int per Color component ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400590Use 8 bits per ARGB component using unsigned integer format.
Cary Clarka560c472017-11-27 10:44:06 -0500591##
592#Const kF16 1
Cary Clark682c58d2018-05-16 07:07:07 -0400593#Line # uses 16-bit float per Color component ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400594Use 16 bits per ARGB component using half-precision floating point format.
Cary Clarka560c472017-11-27 10:44:06 -0500595##
596
Cary Clark61ca7c52018-01-02 11:34:14 -0500597#NoExample
Cary Clarka560c472017-11-27 10:44:06 -0500598##
599
Cary Clark61ca7c52018-01-02 11:34:14 -0500600#SeeAlso MakeFromPicture
Cary Clarka560c472017-11-27 10:44:06 -0500601
Cary Clark56356312018-02-08 14:45:18 -0500602#EnumClass ##
Cary Clarka560c472017-11-27 10:44:06 -0500603
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 Clark61313f32018-10-08 14:57:48 -0400610#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500611#Line # creates Image from Picture ##
Cary Clark09d80c02018-10-31 12:14:03 -0400612#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500613
614#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500615 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 Clarka560c472017-11-27 10:44:06 -0500634##
635
Cary Clark61ca7c52018-01-02 11:34:14 -0500636#SeeAlso SkCanvas::drawPicture
Cary Clarka560c472017-11-27 10:44:06 -0500637
638#Method ##
639
640# ------------------------------------------------------------------------------
641
Cary Clark9548ea92018-09-13 15:26:33 -0400642#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 Clark61313f32018-10-08 14:57:48 -0400647#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500648#Line # creates Image from Android hardware buffer ##
Cary Clark09d80c02018-10-31 12:14:03 -0400649#Populate
Cary Clark61ca7c52018-01-02 11:34:14 -0500650
651#NoExample
Cary Clarka560c472017-11-27 10:44:06 -0500652##
653
Cary Clark61ca7c52018-01-02 11:34:14 -0500654#SeeAlso MakeFromRaster
Cary Clarka560c472017-11-27 10:44:06 -0500655
656#Method ##
657
658# ------------------------------------------------------------------------------
Cary Clark4855f782018-02-06 09:41:53 -0500659#Subtopic Property
Cary Clark4855f782018-02-06 09:41:53 -0500660#Line # values and attributes ##
661##
Cary Clarka560c472017-11-27 10:44:06 -0500662
663#Method int width() const
Cary Clark4855f782018-02-06 09:41:53 -0500664#In Property
665#Line # returns pixel column count ##
Cary Clark09d80c02018-10-31 12:14:03 -0400666#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500667
668#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500669#Image 4
Cary Clarkac47b882018-01-11 10:35:44 -0500670#Height 96
Cary Clark61ca7c52018-01-02 11:34:14 -0500671 canvas->translate(10, 10);
672 canvas->drawImage(image, 0, 0);
673 canvas->translate(0, image->height());
674 SkPaint paint;
Cary Clark61ca7c52018-01-02 11:34:14 -0500675 canvas->drawLine(0, 10, image->width(), 10, paint);
Cary Clark14768f62018-10-29 20:33:51 -0400676 canvas->drawString("width", image->width() / 2 - 15, 25, paint);
Cary Clarka560c472017-11-27 10:44:06 -0500677##
678
Cary Clark61ca7c52018-01-02 11:34:14 -0500679#SeeAlso dimensions() height()
Cary Clarka560c472017-11-27 10:44:06 -0500680
681#Method ##
682
683# ------------------------------------------------------------------------------
684
685#Method int height() const
Cary Clark4855f782018-02-06 09:41:53 -0500686#In Property
687#Line # returns pixel row count ##
Cary Clark09d80c02018-10-31 12:14:03 -0400688#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500689
690#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500691#Image 4
Cary Clarkac47b882018-01-11 10:35:44 -0500692#Height 96
Cary Clark61ca7c52018-01-02 11:34:14 -0500693 canvas->translate(10, 10);
694 canvas->drawImage(image, 0, 0);
695 canvas->translate(image->width(), 0);
696 SkPaint paint;
Cary Clark61ca7c52018-01-02 11:34:14 -0500697 canvas->drawLine(10, 0, 10, image->height(), paint);
Cary Clark92694be2018-10-25 08:15:36 -0400698 canvas->drawString("height", 34, image->height() / 2, paint);
Cary Clarkac47b882018-01-11 10:35:44 -0500699##
Cary Clarka560c472017-11-27 10:44:06 -0500700
Cary Clark61ca7c52018-01-02 11:34:14 -0500701#SeeAlso dimensions() width()
Cary Clarka560c472017-11-27 10:44:06 -0500702
703#Method ##
704
705# ------------------------------------------------------------------------------
706
707#Method SkISize dimensions() const
Cary Clark4855f782018-02-06 09:41:53 -0500708#In Property
709#Line # returns width() and height() ##
Cary Clark09d80c02018-10-31 12:14:03 -0400710#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500711
712#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500713#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 Clark681287e2018-03-16 11:34:15 -0400718#StdOut
719dimensionsAsBounds == bounds
720##
Cary Clarka560c472017-11-27 10:44:06 -0500721##
722
Cary Clark61ca7c52018-01-02 11:34:14 -0500723#SeeAlso height() width() bounds()
Cary Clarka560c472017-11-27 10:44:06 -0500724
725#Method ##
726
727# ------------------------------------------------------------------------------
728
729#Method SkIRect bounds() const
Cary Clark4855f782018-02-06 09:41:53 -0500730#In Property
731#Line # returns width() and height() as Rectangle ##
Cary Clark09d80c02018-10-31 12:14:03 -0400732#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500733
734#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500735#Height 128
736#Image 4
Cary Clark61ca7c52018-01-02 11:34:14 -0500737 SkIRect bounds = image->bounds();
Cary Clarkac47b882018-01-11 10:35:44 -0500738 for (int x : { 0, bounds.width() } ) {
739 for (int y : { 0, bounds.height() } ) {
Cary Clark61ca7c52018-01-02 11:34:14 -0500740 canvas->drawImage(image, x, y);
741 }
742 }
Cary Clarka560c472017-11-27 10:44:06 -0500743##
744
Cary Clark682c58d2018-05-16 07:07:07 -0400745#SeeAlso dimensions()
Cary Clarka560c472017-11-27 10:44:06 -0500746
747#Method ##
748
749# ------------------------------------------------------------------------------
750
751#Method uint32_t uniqueID() const
Cary Clark4855f782018-02-06 09:41:53 -0500752#In Property
Cary Clark682c58d2018-05-16 07:07:07 -0400753#Line # returns identifier for Image ##
Cary Clark09d80c02018-10-31 12:14:03 -0400754#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500755
756#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500757#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 Clarka560c472017-11-27 10:44:06 -0500768##
769
Cary Clark61ca7c52018-01-02 11:34:14 -0500770#SeeAlso isLazyGenerated
Cary Clarka560c472017-11-27 10:44:06 -0500771
772#Method ##
773
774# ------------------------------------------------------------------------------
775
776#Method SkAlphaType alphaType() const
Cary Clark4855f782018-02-06 09:41:53 -0500777#In Property
778#Line # returns Alpha_Type ##
Cary Clark681287e2018-03-16 11:34:15 -0400779Returns Alpha_Type, one of: #list_of_alpha_types#.
Cary Clark61ca7c52018-01-02 11:34:14 -0500780
781Alpha_Type returned was a parameter to an Image constructor,
782or was parsed from encoded data.
783
784#Return Alpha_Type in Image ##
Cary Clarka560c472017-11-27 10:44:06 -0500785
786#Example
Cary Clark61ca7c52018-01-02 11:34:14 -0500787#Image 4
Cary Clarkac47b882018-01-11 10:35:44 -0500788#Height 96
Cary Clark61ca7c52018-01-02 11:34:14 -0500789 const char* alphaTypeStr[] = { "Unknown", "Opaque", "Premul", "Unpremul" };
790 SkAlphaType alphaType = image->alphaType();
Cary Clarkac47b882018-01-11 10:35:44 -0500791 canvas->drawImage(image, 16, 0);
Cary Clarkffb3d682018-05-17 12:17:28 -0400792 canvas->drawString(alphaTypeStr[(int) alphaType], 20, image->height() + 20, SkPaint());
Cary Clarka560c472017-11-27 10:44:06 -0500793##
794
Cary Clark61ca7c52018-01-02 11:34:14 -0500795#SeeAlso SkImageInfo::alphaType
Cary Clarka560c472017-11-27 10:44:06 -0500796
797#Method ##
798
799# ------------------------------------------------------------------------------
800
Greg Daniel56008aa2018-03-14 15:33:42 -0400801#Method SkColorType colorType() const
802#In Property
803#Line # returns Color_Type ##
Cary Clark09d80c02018-10-31 12:14:03 -0400804#Populate
Greg Daniel56008aa2018-03-14 15:33:42 -0400805
806#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400807#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 Daniel56008aa2018-03-14 15:33:42 -0400814##
815
816#SeeAlso SkImageInfo::colorType
817
818#Method ##
819
820# ------------------------------------------------------------------------------
821
Cary Clarka560c472017-11-27 10:44:06 -0500822#Method SkColorSpace* colorSpace() const
Cary Clark4855f782018-02-06 09:41:53 -0500823#In Property
824#Line # returns Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -0400825#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500826
827#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -0500828#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 Clarka560c472017-11-27 10:44:06 -0500847##
848
Cary Clark61dfc3a2018-01-03 08:37:53 -0500849#SeeAlso refColorSpace makeColorSpace
Cary Clarka560c472017-11-27 10:44:06 -0500850
851#Method ##
852
853# ------------------------------------------------------------------------------
854
855#Method sk_sp<SkColorSpace> refColorSpace() const
Cary Clark4855f782018-02-06 09:41:53 -0500856#In Property
857#Line # returns Image_Info Color_Space ##
Cary Clark09d80c02018-10-31 12:14:03 -0400858#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500859
860#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -0500861#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 Clarka560c472017-11-27 10:44:06 -0500880##
881
Cary Clark61dfc3a2018-01-03 08:37:53 -0500882#SeeAlso colorSpace makeColorSpace
Cary Clarka560c472017-11-27 10:44:06 -0500883
884#Method ##
885
886# ------------------------------------------------------------------------------
887
888#Method bool isAlphaOnly() const
Cary Clark4855f782018-02-06 09:41:53 -0500889#In Property
890#Line # returns if pixels represent a transparency mask ##
Cary Clark09d80c02018-10-31 12:14:03 -0400891#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500892
893#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -0500894 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
898alphaOnly = true
899##
Cary Clarka560c472017-11-27 10:44:06 -0500900##
901
Cary Clark61dfc3a2018-01-03 08:37:53 -0500902#SeeAlso alphaType isOpaque
Cary Clarka560c472017-11-27 10:44:06 -0500903
904#Method ##
905
906# ------------------------------------------------------------------------------
907
908#Method bool isOpaque() const
Cary Clark4855f782018-02-06 09:41:53 -0500909#In Property
910#Line # returns if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clark09d80c02018-10-31 12:14:03 -0400911#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500912
913#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -0500914 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
923isOpaque = false
924isOpaque = true
925##
Cary Clarka560c472017-11-27 10:44:06 -0500926##
927
Cary Clark61dfc3a2018-01-03 08:37:53 -0500928#SeeAlso alphaType isAlphaOnly
Cary Clarka560c472017-11-27 10:44:06 -0500929
930#Method ##
931
932# ------------------------------------------------------------------------------
933
934#Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2,
935 const SkMatrix* localMatrix = nullptr) const
Cary Clark61313f32018-10-08 14:57:48 -0400936#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -0500937#Line # creates Shader, Paint element that can tile Image ##
Cary Clark09d80c02018-10-31 12:14:03 -0400938#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500939
940#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -0500941#Image 4
942SkMatrix matrix;
943matrix.setRotate(45);
944SkPaint paint;
945paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode,
946 &matrix));
947canvas->drawPaint(paint);
Cary Clarka560c472017-11-27 10:44:06 -0500948##
949
Cary Clark61dfc3a2018-01-03 08:37:53 -0500950#SeeAlso scalePixels
Cary Clarka560c472017-11-27 10:44:06 -0500951
952#Method ##
953
954# ------------------------------------------------------------------------------
955
956#Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const
Cary Clark09d80c02018-10-31 12:14:03 -0400957#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500958
959#Example
Cary Clark61dfc3a2018-01-03 08:37:53 -0500960#Image 5
961SkMatrix matrix;
962matrix.setRotate(45);
963matrix.postTranslate(125, 30);
964SkPaint paint;
965paint.setShader(image->makeShader(&matrix));
966canvas->drawPaint(paint);
Cary Clarka560c472017-11-27 10:44:06 -0500967##
968
Cary Clarkf5404bb2018-01-05 12:10:09 -0500969#SeeAlso scalePixels
Cary Clarka560c472017-11-27 10:44:06 -0500970
971#Method ##
972
973# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -0500974#Subtopic Pixels
Cary Clark78de7512018-02-07 07:27:09 -0500975#Line # read and write pixel values ##
976##
Cary Clarka560c472017-11-27 10:44:06 -0500977
978#Method bool peekPixels(SkPixmap* pixmap) const
Cary Clark78de7512018-02-07 07:27:09 -0500979#In Pixels
Cary Clark4855f782018-02-06 09:41:53 -0500980#Line # returns Pixmap if possible ##
Cary Clark09d80c02018-10-31 12:14:03 -0400981#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500982
983#Example
Cary Clarkf5404bb2018-01-05 12:10:09 -0500984 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 Clarka560c472017-11-27 10:44:06 -05001015##
1016
Cary Clarkf5404bb2018-01-05 12:10:09 -05001017#SeeAlso readPixels
Cary Clarka560c472017-11-27 10:44:06 -05001018
1019#Method ##
1020
1021# ------------------------------------------------------------------------------
1022
Cary Clarka560c472017-11-27 10:44:06 -05001023#Method bool isTextureBacked() const
Cary Clark78de7512018-02-07 07:27:09 -05001024#In Property
Cary Clark4855f782018-02-06 09:41:53 -05001025#Line # returns if Image was created from GPU_Texture ##
Cary Clark09d80c02018-10-31 12:14:03 -04001026#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001027
1028#Example
Cary Clarkf5404bb2018-01-05 12:10:09 -05001029#Image 5
1030#Platform gpu
1031auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void {
1032 if (nullptr == image) {
1033 return;
1034 }
1035 SkPaint paint;
1036 paint.setAntiAlias(true);
Cary Clarkf5404bb2018-01-05 12:10:09 -05001037 canvas->drawImage(image, 0, 0);
Cary Clark14768f62018-10-29 20:33:51 -04001038 canvas->drawString(label, 30, image->height() / 4, paint);
Cary Clarkf5404bb2018-01-05 12:10:09 -05001039 canvas->drawString(image->isTextureBacked() ? "is GPU texture" : "not GPU texture",
Cary Clark14768f62018-10-29 20:33:51 -04001040 20, image->height() * 3 / 4, paint);
Cary Clarkf5404bb2018-01-05 12:10:09 -05001041};
1042sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
1043sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
Cary Clarkae957c42018-06-07 17:07:17 -04001044 kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
1045 kOpaque_SkAlphaType, nullptr));
Cary Clarkf5404bb2018-01-05 12:10:09 -05001046drawImage(image, "image");
1047canvas->translate(image->width(), 0);
1048drawImage(bitmapImage, "source");
1049canvas->translate(-image->width(), image->height());
1050drawImage(textureImage, "backEndTexture");
Cary Clarka560c472017-11-27 10:44:06 -05001051##
1052
Cary Clarkf5404bb2018-01-05 12:10:09 -05001053#SeeAlso MakeFromTexture isValid
Cary Clarka560c472017-11-27 10:44:06 -05001054
1055#Method ##
1056
1057# ------------------------------------------------------------------------------
1058
1059#Method bool isValid(GrContext* context) const
Cary Clark4855f782018-02-06 09:41:53 -05001060#In Property
1061#Line # returns if Image can draw to Raster_Surface or GPU_Context ##
Cary Clark09d80c02018-10-31 12:14:03 -04001062#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001063
1064#Example
Cary Clarkf5404bb2018-01-05 12:10:09 -05001065#Image 5
1066#Platform gpu
1067auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void {
1068 if (nullptr == image) {
1069 return;
1070 }
1071 SkPaint paint;
1072 paint.setAntiAlias(true);
Cary Clarkf5404bb2018-01-05 12:10:09 -05001073 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 Clark14768f62018-10-29 20:33:51 -04001077 "not valid on GPU", 20, image->height() * 5 / 8, paint);
Cary Clarkf5404bb2018-01-05 12:10:09 -05001078 }
1079 canvas->drawString(image->isValid(nullptr) ? "is valid on CPU" :
Cary Clark14768f62018-10-29 20:33:51 -04001080 "not valid on CPU", 20, image->height() * 7 / 8, paint);
Cary Clarkf5404bb2018-01-05 12:10:09 -05001081};
1082sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
1083sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
Cary Clarkae957c42018-06-07 17:07:17 -04001084 kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
1085 kOpaque_SkAlphaType, nullptr));
Cary Clarkf5404bb2018-01-05 12:10:09 -05001086drawImage(image, "image");
1087canvas->translate(image->width(), 0);
1088drawImage(bitmapImage, "source");
1089canvas->translate(-image->width(), image->height());
1090drawImage(textureImage, "backEndTexture");
Cary Clarka560c472017-11-27 10:44:06 -05001091##
1092
Cary Clarkf5404bb2018-01-05 12:10:09 -05001093#SeeAlso isTextureBacked isLazyGenerated
Cary Clarka560c472017-11-27 10:44:06 -05001094
1095#Method ##
1096
1097# ------------------------------------------------------------------------------
1098
Robert Phillipsc5509952018-04-04 15:54:55 -04001099#Method GrBackendTexture getBackendTexture(bool flushPendingGrContextIO,
1100 GrSurfaceOrigin* origin = nullptr) const
1101#In Property
1102#Line # returns GPU reference to Image as texture ##
Cary Clark09d80c02018-10-31 12:14:03 -04001103#Populate
Robert Phillipsc5509952018-04-04 15:54:55 -04001104
Cary Clarkba75aee2018-04-05 08:18:41 -04001105#Example
1106#Image 3
1107#Platform gpu
Brian Osman584b5012018-04-13 15:48:26 -04001108 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 Clarkba75aee2018-04-05 08:18:41 -04001122 canvas->drawImage(imageFromBackend, 128, 128);
Robert Phillipsc5509952018-04-04 15:54:55 -04001123##
1124
1125#SeeAlso MakeFromTexture isTextureBacked
1126
1127#Method ##
1128
1129# ------------------------------------------------------------------------------
1130
Cary Clarka560c472017-11-27 10:44:06 -05001131#Enum CachingHint
Cary Clark682c58d2018-05-16 07:07:07 -04001132#Line # options for readPixels and scalePixels ##
Cary Clarka560c472017-11-27 10:44:06 -05001133#Code
Cary Clarka90ea222018-10-16 10:30:28 -04001134#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001135##
1136
Cary Clarkac47b882018-01-11 10:35:44 -05001137CachingHint selects whether Skia may internally cache Bitmaps generated by
1138decoding Image, or by copying Image from GPU to CPU. The default behavior
Cary Clark682c58d2018-05-16 07:07:07 -04001139allows caching Bitmaps.
Cary Clarkac47b882018-01-11 10:35:44 -05001140
1141Choose kDisallow_CachingHint if Image pixels are to be used only once, or
1142if Image pixels reside in a cache outside of Skia, or to reduce memory pressure.
1143
1144Choosing kAllow_CachingHint does not ensure that pixels will be cached.
1145Image pixels may not be cached if memory requirements are too large or
1146pixels are not accessible.
Cary Clarka560c472017-11-27 10:44:06 -05001147
1148#Const kAllow_CachingHint 0
Cary Clark682c58d2018-05-16 07:07:07 -04001149#Line # allows internally caching decoded and copied pixels ##
Cary Clarka560c472017-11-27 10:44:06 -05001150##
1151#Const kDisallow_CachingHint 1
Cary Clark682c58d2018-05-16 07:07:07 -04001152#Line # disallows internally caching decoded and copied pixels ##
Cary Clarka560c472017-11-27 10:44:06 -05001153##
1154
Cary Clarkac47b882018-01-11 10:35:44 -05001155#NoExample
Cary Clarka560c472017-11-27 10:44:06 -05001156##
1157
Cary Clarkac47b882018-01-11 10:35:44 -05001158#SeeAlso readPixels scalePixels
Cary Clarka560c472017-11-27 10:44:06 -05001159
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 Clark78de7512018-02-07 07:27:09 -05001166#In Pixels
Cary Clark4855f782018-02-06 09:41:53 -05001167#Line # copies and converts pixels ##
Cary Clarka560c472017-11-27 10:44:06 -05001168
Cary Clarkac47b882018-01-11 10:35:44 -05001169Copies Rect of pixels from Image to dstPixels. Copy starts at offset (srcX, srcY),
Cary Clark682c58d2018-05-16 07:07:07 -04001170and does not exceed Image (width(), height()).
Cary Clarkac47b882018-01-11 10:35:44 -05001171
1172dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of
1173destination. dstRowBytes specifics the gap from one destination row to the next.
1174Returns true if pixels are copied. Returns false if:
1175#List
Cary Clark77b3f3a2018-11-07 14:59:03 -05001176# dstInfo has no address ##
1177# dstRowBytes is less than dstInfo.minRowBytes() ##
Cary Clarkac47b882018-01-11 10:35:44 -05001178# Pixel_Ref is nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001179##
1180
Cary Clarkac47b882018-01-11 10:35:44 -05001181Pixels are copied only if pixel conversion is possible. If Image Color_Type is
Cary Clark77b3f3a2018-11-07 14:59:03 -05001182kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
1183If Image Color_Type is kGray_8_SkColorType, dstInfo.colorSpace() must match.
1184If Image Alpha_Type is kOpaque_SkAlphaType, dstInfo.alphaType() must
1185match. If Image Color_Space is nullptr, dstInfo.colorSpace() must match. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001186false if pixel conversion is not possible.
Cary Clarka560c472017-11-27 10:44:06 -05001187
Cary Clarkac47b882018-01-11 10:35:44 -05001188srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark682c58d2018-05-16 07:07:07 -04001189false if width() or height() is zero or negative.
Cary Clark2be81cf2018-09-13 12:04:30 -04001190Returns false if #Formula # abs(srcX) >= Image width() ##, or if #Formula # abs(srcY) >= Image height() ##.
Cary Clarka560c472017-11-27 10:44:06 -05001191
Cary Clarkac47b882018-01-11 10:35:44 -05001192If cachingHint is kAllow_CachingHint, pixels may be retained locally.
1193If 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 Clarka560c472017-11-27 10:44:06 -05001203
1204#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001205#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 Clarka560c472017-11-27 10:44:06 -05001224##
1225
Cary Clarkac47b882018-01-11 10:35:44 -05001226#SeeAlso scalePixels SkBitmap::readPixels SkPixmap::readPixels SkCanvas::readPixels SkSurface::readPixels
Cary Clarka560c472017-11-27 10:44:06 -05001227
1228#Method ##
1229
1230# ------------------------------------------------------------------------------
1231
1232#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY,
1233 CachingHint cachingHint = kAllow_CachingHint) const
1234
Cary Clarkac47b882018-01-11 10:35:44 -05001235Copies a Rect of pixels from Image to dst. Copy starts at (srcX, srcY), and
Cary Clark682c58d2018-05-16 07:07:07 -04001236does not exceed Image (width(), height()).
Cary Clarka560c472017-11-27 10:44:06 -05001237
Cary Clarkac47b882018-01-11 10:35:44 -05001238dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
Cary Clark77b3f3a2018-11-07 14:59:03 -05001239and row bytes of destination. dst.rowBytes() specifics the gap from one destination
Cary Clarkac47b882018-01-11 10:35:44 -05001240row to the next. Returns true if pixels are copied. Returns false if:
1241#List
1242# dst pixel storage equals nullptr ##
Cary Clark77b3f3a2018-11-07 14:59:03 -05001243# dst.rowBytes() is less than SkImageInfo::minRowBytes ##
Cary Clarkac47b882018-01-11 10:35:44 -05001244# Pixel_Ref is nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001245##
1246
Cary Clarkac47b882018-01-11 10:35:44 -05001247Pixels are copied only if pixel conversion is possible. If Image Color_Type is
Cary Clark77b3f3a2018-11-07 14:59:03 -05001248kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match.
1249If Image Color_Type is kGray_8_SkColorType, dst.colorSpace() must match.
1250If Image Alpha_Type is kOpaque_SkAlphaType, dst.alphaType() must
1251match. If Image Color_Space is nullptr, dst.colorSpace() must match. Returns
Cary Clarkac47b882018-01-11 10:35:44 -05001252false if pixel conversion is not possible.
Cary Clark682c58d2018-05-16 07:07:07 -04001253
Cary Clarkac47b882018-01-11 10:35:44 -05001254srcX and srcY may be negative to copy only top or left of source. Returns
Cary Clark682c58d2018-05-16 07:07:07 -04001255false if width() or height() is zero or negative.
Cary Clark2be81cf2018-09-13 12:04:30 -04001256Returns false if #Formula # abs(srcX) >= Image width() ##, or if #Formula # abs(srcY) >= Image height() ##.
Cary Clarkac47b882018-01-11 10:35:44 -05001257
1258If cachingHint is kAllow_CachingHint, pixels may be retained locally.
1259If 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 Clarka560c472017-11-27 10:44:06 -05001291
1292#Method ##
1293
1294# ------------------------------------------------------------------------------
1295
1296#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
1297 CachingHint cachingHint = kAllow_CachingHint) const
Cary Clark78de7512018-02-07 07:27:09 -05001298#In Pixels
Cary Clark4855f782018-02-06 09:41:53 -05001299#Line # scales and converts one Image to another ##
Cary Clark09d80c02018-10-31 12:14:03 -04001300#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001301
1302#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001303#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 Clarka560c472017-11-27 10:44:06 -05001320##
1321
Cary Clarkac47b882018-01-11 10:35:44 -05001322#SeeAlso SkCanvas::drawImage readPixels SkPixmap::scalePixels
Cary Clarka560c472017-11-27 10:44:06 -05001323
1324#Method ##
1325
1326# ------------------------------------------------------------------------------
1327
1328#Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const
Cary Clark78de7512018-02-07 07:27:09 -05001329#In Utility
Cary Clark4855f782018-02-06 09:41:53 -05001330#Line # returns encoded Image as SkData ##
Cary Clark09d80c02018-10-31 12:14:03 -04001331#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001332
1333#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001334#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 Clarka560c472017-11-27 10:44:06 -05001344##
1345
Cary Clarkac47b882018-01-11 10:35:44 -05001346#SeeAlso refEncodedData MakeFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -05001347
1348#Method ##
1349
1350# ------------------------------------------------------------------------------
1351
Cary Clark61ca7c52018-01-02 11:34:14 -05001352#Method sk_sp<SkData> encodeToData() const
Cary Clark09d80c02018-10-31 12:14:03 -04001353#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001354
1355#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001356#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 Clarka560c472017-11-27 10:44:06 -05001362##
1363
Cary Clarkac47b882018-01-11 10:35:44 -05001364#SeeAlso refEncodedData MakeFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -05001365
1366#Method ##
1367
1368# ------------------------------------------------------------------------------
1369
1370#Method sk_sp<SkData> refEncodedData() const
Cary Clark78de7512018-02-07 07:27:09 -05001371#In Utility
Cary Clark4855f782018-02-06 09:41:53 -05001372#Line # returns Image encoded in SkData if present ##
Cary Clark09d80c02018-10-31 12:14:03 -04001373#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001374
1375#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001376#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 Clarkae957c42018-06-07 17:07:17 -04001383 kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
1384 kOpaque_SkAlphaType, nullptr) } };
Cary Clarkac47b882018-01-11 10:35:44 -05001385 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 Clarka560c472017-11-27 10:44:06 -05001396##
1397
Cary Clarkac47b882018-01-11 10:35:44 -05001398#SeeAlso encodeToData MakeFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -05001399
1400#Method ##
1401
1402# ------------------------------------------------------------------------------
Cary Clark4855f782018-02-06 09:41:53 -05001403#Subtopic Utility
Cary Clark4855f782018-02-06 09:41:53 -05001404#Line # rarely called management functions ##
1405##
Cary Clarka560c472017-11-27 10:44:06 -05001406
Cary Clarka560c472017-11-27 10:44:06 -05001407#Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const
Cary Clark61313f32018-10-08 14:57:48 -04001408#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -05001409#Line # creates Image containing part of original ##
Cary Clark09d80c02018-10-31 12:14:03 -04001410#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001411
1412#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001413#Image 3
1414 canvas->scale(.5f, .5f);
Cary Clarkc30382f2018-07-24 08:09:27 -04001415 const int width = 64;
1416 const int height = 64;
Cary Clarkac47b882018-01-11 10:35:44 -05001417 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 Clarka560c472017-11-27 10:44:06 -05001423##
1424
Cary Clarkac47b882018-01-11 10:35:44 -05001425#SeeAlso MakeFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -05001426
1427#Method ##
1428
1429# ------------------------------------------------------------------------------
1430
Greg Daniel5f4b09d2018-06-12 16:39:59 -04001431#Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace,
1432 GrMipMapped mipMapped = GrMipMapped::kNo) const
Cary Clark61313f32018-10-08 14:57:48 -04001433#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -05001434#Line # creates Image matching Color_Space if possible ##
Cary Clark09d80c02018-10-31 12:14:03 -04001435#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001436
1437#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001438#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 Clarkac47b882018-01-11 10:35:44 -05001446 sk_sp<SkImage> texture(image->makeTextureImage(context, nullptr));
1447 canvas->drawImage(texture, 0, 0);
Cary Clark14768f62018-10-29 20:33:51 -04001448 canvas->drawString(label, 20, texture->height() / 4, paint);
Cary Clarkac47b882018-01-11 10:35:44 -05001449 };
1450 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
1451 GrContext* context = canvas->getGrContext();
1452 sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(context, backEndTexture,
Cary Clarkae957c42018-06-07 17:07:17 -04001453 kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
1454 kOpaque_SkAlphaType, nullptr));
Cary Clarkac47b882018-01-11 10:35:44 -05001455 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 Clarka560c472017-11-27 10:44:06 -05001460##
1461
Cary Clarkac47b882018-01-11 10:35:44 -05001462#SeeAlso MakeFromTexture
Cary Clarka560c472017-11-27 10:44:06 -05001463
1464#Method ##
1465
1466# ------------------------------------------------------------------------------
1467
1468#Method sk_sp<SkImage> makeNonTextureImage() const
Cary Clark61313f32018-10-08 14:57:48 -04001469#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -05001470#Line # creates Image without dependency on GPU_Texture ##
Cary Clark09d80c02018-10-31 12:14:03 -04001471#Populate
Cary Clark61ca7c52018-01-02 11:34:14 -05001472
1473#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001474#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 Clarkac47b882018-01-11 10:35:44 -05001482 sk_sp<SkImage> nonTexture(image->makeNonTextureImage());
1483 canvas->drawImage(nonTexture, 0, 0);
Cary Clark14768f62018-10-29 20:33:51 -04001484 canvas->drawString(label, 20, nonTexture->height() / 4, paint);
Cary Clarkac47b882018-01-11 10:35:44 -05001485 };
1486 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
1487 sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
Cary Clarkae957c42018-06-07 17:07:17 -04001488 kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
1489 kOpaque_SkAlphaType, nullptr));
Cary Clarkac47b882018-01-11 10:35:44 -05001490 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 Clark61ca7c52018-01-02 11:34:14 -05001495##
1496
Cary Clark56356312018-02-08 14:45:18 -05001497#SeeAlso makeTextureImage makeRasterImage MakeBackendTextureFromSkImage
Cary Clark61ca7c52018-01-02 11:34:14 -05001498
1499#Method ##
1500
1501# ------------------------------------------------------------------------------
1502
1503#Method sk_sp<SkImage> makeRasterImage() const
Cary Clark61313f32018-10-08 14:57:48 -04001504#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -05001505#Line # creates Image compatible with Raster_Surface if possible ##
Cary Clark09d80c02018-10-31 12:14:03 -04001506#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001507
Cary Clarka560c472017-11-27 10:44:06 -05001508#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001509#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 Clarkac47b882018-01-11 10:35:44 -05001517 sk_sp<SkImage> raster(image->makeRasterImage());
1518 canvas->drawImage(raster, 0, 0);
Cary Clark14768f62018-10-29 20:33:51 -04001519 canvas->drawString(label, 20, raster->height() / 4, paint);
Cary Clarkac47b882018-01-11 10:35:44 -05001520 };
1521 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
1522 sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
Cary Clarkae957c42018-06-07 17:07:17 -04001523 kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
1524 kOpaque_SkAlphaType, nullptr));
Cary Clarkac47b882018-01-11 10:35:44 -05001525 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 Clarka560c472017-11-27 10:44:06 -05001530##
1531
Cary Clarkac47b882018-01-11 10:35:44 -05001532#SeeAlso isTextureBacked isLazyGenerated MakeFromRaster
Cary Clarka560c472017-11-27 10:44:06 -05001533
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 Clark61313f32018-10-08 14:57:48 -04001541#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -05001542#Line # creates filtered, clipped Image ##
Cary Clark09d80c02018-10-31 12:14:03 -04001543#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001544
Cary Clarka560c472017-11-27 10:44:06 -05001545#Example
Cary Clarkac47b882018-01-11 10:35:44 -05001546#Description
1547In each frame of the animation, filtered Image is drawn in a different location.
1548By translating canvas by returned offset, Image appears stationary.
1549##
1550#Image 5
1551#Platform gpu
Cary Clark5717e822018-09-21 11:36:41 -04001552#Duration 1
Cary Clarkac47b882018-01-11 10:35:44 -05001553 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 Clark681287e2018-03-16 11:34:15 -04001571 canvas->drawRect(SkRect::Make(outSubset), paint);
Cary Clarka560c472017-11-27 10:44:06 -05001572##
1573
Cary Clark56356312018-02-08 14:45:18 -05001574#SeeAlso makeShader SkPaint::setImageFilter
Cary Clarka560c472017-11-27 10:44:06 -05001575
1576#Method ##
1577
1578# ------------------------------------------------------------------------------
1579
Cary Clarka560c472017-11-27 10:44:06 -05001580#Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc
Cary Clark682c58d2018-05-16 07:07:07 -04001581#Line # parameter type for MakeBackendTextureFromSkImage ##
Cary Clarkffb3d682018-05-17 12:17:28 -04001582
1583#Code
Cary Clarka90ea222018-10-16 10:30:28 -04001584#Populate
Cary Clarkffb3d682018-05-17 12:17:28 -04001585##
1586
Cary Clark0d225392018-06-07 09:59:07 -04001587Defines a callback function, taking one parameter of type GrBackendTexture with
1588no return value. Function is called when back-end texture is to be released.
Cary Clarka560c472017-11-27 10:44:06 -05001589##
1590
1591# ------------------------------------------------------------------------------
1592
1593#Method static bool MakeBackendTextureFromSkImage(GrContext* context,
1594 sk_sp<SkImage> image,
1595 GrBackendTexture* backendTexture,
1596 BackendTextureReleaseProc* backendTextureReleaseProc)
Cary Clark61313f32018-10-08 14:57:48 -04001597#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -05001598#Line # creates GPU_Texture from Image ##
Cary Clark09d80c02018-10-31 12:14:03 -04001599#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001600
1601#Example
Cary Clark56356312018-02-08 14:45:18 -05001602#Platform gpu
1603#Height 64
1604#Function
Brian Salomon67f85842018-02-09 08:50:22 -05001605static 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 Clark682c58d2018-05-16 07:07:07 -04001617void draw(SkCanvas* canvas) {
Brian Salomon67f85842018-02-09 08:50:22 -05001618 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 Clark56356312018-02-08 14:45:18 -05001633}
Cary Clarka560c472017-11-27 10:44:06 -05001634##
1635
Cary Clark56356312018-02-08 14:45:18 -05001636#SeeAlso MakeFromTexture makeTextureImage
Cary Clarka560c472017-11-27 10:44:06 -05001637
1638#Method ##
1639
1640# ------------------------------------------------------------------------------
1641
Cary Clarka560c472017-11-27 10:44:06 -05001642#Method bool isLazyGenerated() const
Cary Clark4855f782018-02-06 09:41:53 -05001643#In Property
1644#Line # returns if Image is created as needed ##
Cary Clark09d80c02018-10-31 12:14:03 -04001645#Populate
Cary Clarka560c472017-11-27 10:44:06 -05001646
1647#Example
Cary Clark2f466242017-12-11 16:03:17 -05001648#Height 80
1649#Function
1650class TestImageGenerator : public SkImageGenerator {
1651public:
1652 TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {}
1653 ~TestImageGenerator() override {}
1654protected:
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##
1667void 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 Clarka560c472017-11-27 10:44:06 -05001677##
1678
Cary Clarkf5404bb2018-01-05 12:10:09 -05001679#Example
1680#Image 5
1681#Platform gpu
1682void 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 Clarkf5404bb2018-01-05 12:10:09 -05001689 canvas->drawImage(image, 0, 0);
Cary Clark14768f62018-10-29 20:33:51 -04001690 canvas->drawString(label, 30, image->height() / 4, paint);
Cary Clarkf5404bb2018-01-05 12:10:09 -05001691 canvas->drawString(
1692 image->isLazyGenerated() ? "is lazily generated" : "not lazily generated",
Cary Clark14768f62018-10-29 20:33:51 -04001693 20, image->height() * 3 / 4, paint);
Cary Clarkf5404bb2018-01-05 12:10:09 -05001694 };
1695 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
1696 sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
Cary Clarkae957c42018-06-07 17:07:17 -04001697 kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
1698 kOpaque_SkAlphaType, nullptr));
Cary Clarkf5404bb2018-01-05 12:10:09 -05001699 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 Clark77b3f3a2018-11-07 14:59:03 -05001707#SeeAlso isTextureBacked makeNonTextureImage
Cary Clarka560c472017-11-27 10:44:06 -05001708
1709#Method ##
1710
1711# ------------------------------------------------------------------------------
1712
Cary Clarke80cd442018-07-17 13:19:56 -04001713#Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target) const
Cary Clark61313f32018-10-08 14:57:48 -04001714#In Constructors
Cary Clark4855f782018-02-06 09:41:53 -05001715#Line # creates Image matching Color_Space if possible ##
Cary Clark09d80c02018-10-31 12:14:03 -04001716#Populate
Cary Clarkac47b882018-01-11 10:35:44 -05001717
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 Clarkc3c1c312018-07-18 09:25:15 -04001725 sk_sp<SkImage> colorSpaced = image->makeColorSpace(colorSpace);
1726 canvas->drawImage(colorSpaced, 0, 0);
1727 canvas->translate(128, 0);
Cary Clarkac47b882018-01-11 10:35:44 -05001728 }
1729##
1730
Cary Clark77b3f3a2018-11-07 14:59:03 -05001731#SeeAlso MakeFromPicture MakeFromTexture
Cary Clarka560c472017-11-27 10:44:06 -05001732
1733#Method ##
1734
1735#Class SkImage ##
1736
1737#Topic Image ##