blob: d0cb2fa0d8f45d28e877f1fb46f24380f6cb0b9d [file] [log] [blame]
Cary Clarka560c472017-11-27 10:44:06 -05001#Topic Image
2#Alias Image_Reference
3
4#Class SkImage
5
6SkImage is an abstraction for drawing a rectangle of pixels, though the
7particular type of image could be actually storing its data on the GPU, or
8as drawing commands (picture or PDF or otherwise), ready to be played back
9into another canvas.
10The content of SkImage is always immutable, though the actual storage may
11change, if for example that image can be re-created via encoded data or
12other means.
13SkImage always has a non-zero dimensions. If there is a request to create a new
14image, either directly or via SkSurface, and either of the requested dimensions
15are zero, then nullptr will be returned.
16
17#Topic Overview
18
19#Subtopic Subtopics
20#ToDo manually add subtopics ##
21#Table
22#Legend
23# topics # description ##
24#Legend ##
25#Table ##
26##
27
Cary Clarka560c472017-11-27 10:44:06 -050028#Subtopic Member_Functions
29#Table
30#Legend
31# description # function ##
32#Legend ##
Cary Clark3cd22cc2017-12-01 11:49:58 -050033# MakeBackendTextureFromSkImage # Creates GPU texture from Image. ##
34# MakeCrossContextFromEncoded # Creates Image from encoded data, and uploads to GPU. ##
35# MakeFromAHardwareBuffer # Creates Image from Android hardware buffer. ##
36# MakeFromAdoptedTexture # Creates Image from GPU texture, managed internally. ##
37# MakeFromBitmap # Creates Image from Bitmap, sharing or copying pixels. ##
Cary Clark3cd22cc2017-12-01 11:49:58 -050038# MakeFromEncoded # Creates Image from encoded data. ##
39# MakeFromGenerator # Creates Image from a stream of data. ##
40# MakeFromNV12TexturesCopy # Creates Image from YUV_ColorSpace data in two planes. ##
41# MakeFromPicture # Creates Image from Picture. ##
42# MakeFromRaster # Creates Image from Pixmap, with release. ##
43# MakeFromTexture # Creates Image from GPU texture, managed externally. ##
44# MakeFromYUVTexturesCopy # Creates Image from YUV_ColorSpace data in three planes. ##
45# MakeRasterCopy # Creates Image from Pixmap and copied pixels. ##
46# MakeRasterData # Creates Image from Image_Info and shared pixels. ##
47# alphaType # Returns Alpha_Type ##
Cary Clark2f466242017-12-11 16:03:17 -050048# asLegacyBitmap # Returns as Raster_Bitmap ##
49# bounds() # Returns width() and height() as Rectangle. ##
50# colorSpace # Returns Color_Space. ##
51# dimensions() # Returns width() and height(). ##
52# encodeToData # Returns encoded Image as SkData. ##
53# getTexture # Deprecated. ##
54# getTextureHandle # Returns GPU reference to Image as texture. ##
55# height() # Returns pixel row count. ##
56# isAlphaOnly # Returns if pixels represent a transparency mask. ##
57# isLazyGenerated # Returns if Image is created as needed. ##
58# isOpaque # Returns if Alpha_Type is kOpaque_SkAlphaType. ##
59# isTextureBacked # Returns if Image was created from GPU texture. ##
60# isValid # Returns if Image can draw to Raster_Surface or GPU_Context. ##
61# makeColorSpace # Creates Image matching Color_Space if possible. ##
62# makeNonTextureImage # Creates Raster_Image if possible. ##
63# makeShader # Creates Shader, Paint element that can tile Image. ##
64# makeSubset # Creates Image containing part of original. ##
65# makeTextureImage # Creates Image matching Color_Space if possible. ##
66# makeWithFilter # Creates filtered, clipped Image. ##
67# peekPixels # Returns Pixmap if possible. ##
68# readPixels # Copies and converts pixels. ##
69# refColorSpace # Returns Image_Info Color_Space. ##
70# refEncodedData # Returns Image encoded in SkData if present. ##
71# scalePixels # Scales and converts one Image to another. ##
72# toString # Converts Image to machine readable form. ##
73# uniqueID # Identifier for Image. ##
74# width() # Returns pixel column count. ##
Cary Clarka560c472017-11-27 10:44:06 -050075#Table ##
76#Subtopic ##
77
78#Topic ##
79
Cary Clarka560c472017-11-27 10:44:06 -050080#Typedef SkImageInfo Info
81
82##
83
Cary Clarka560c472017-11-27 10:44:06 -050084# ------------------------------------------------------------------------------
85
86#Method static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap)
87
Cary Clark2f466242017-12-11 16:03:17 -050088Creates Image from Pixmap and copy of pixels. Since pixels are copied, Pixmap
89pixels may be modified or deleted without affecting Image.
Cary Clarka560c472017-11-27 10:44:06 -050090
Cary Clark3cd22cc2017-12-01 11:49:58 -050091Image is returned if Pixmap is valid. Valid Pixmap parameters include:
92dimensions are greater than zero;
93each dimension fits in 29 bits;
94Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
95row bytes are large enough to hold one row of pixels;
96pixel address is not nullptr.
97
98#Param pixmap Image_Info, pixel address, and row bytes ##
99
100#Return copy of Pixmap pixels, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500101
102#Example
Cary Clark2f466242017-12-11 16:03:17 -0500103#Height 50
104#Description
105Draw a five by five bitmap, and draw a copy in an Image. Editing the pixmap
106alters the bitmap draw, but does not alter the Image draw since the Image
107contains a copy of the pixels.
108##
109 uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
110 { 0xAC, 0xA8, 0x89, 0xA7, 0x87 },
111 { 0x9B, 0xB5, 0xE5, 0x95, 0x46 },
112 { 0x90, 0x81, 0xC5, 0x71, 0x33 },
113 { 0x75, 0x55, 0x44, 0x40, 0x30 }};
114 SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
115 SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
116 SkBitmap bitmap;
117 bitmap.installPixels(pixmap);
118 sk_sp<SkImage> image = SkImage::MakeRasterCopy(pixmap);
119 *pixmap.writable_addr8(2, 2) = 0x00;
120 canvas->scale(10, 10);
121 canvas->drawBitmap(bitmap, 0, 0);
122 canvas->drawImage(image, 10, 0);
Cary Clarka560c472017-11-27 10:44:06 -0500123##
124
Cary Clark3cd22cc2017-12-01 11:49:58 -0500125#SeeAlso MakeRasterData MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500126
127#Method ##
128
129# ------------------------------------------------------------------------------
130
131#Method static sk_sp<SkImage> MakeRasterData(const Info& info, sk_sp<SkData> pixels, size_t rowBytes)
132
Cary Clark3cd22cc2017-12-01 11:49:58 -0500133Creates Image from Image_Info, sharing pixels.
Cary Clarka560c472017-11-27 10:44:06 -0500134
Cary Clark3cd22cc2017-12-01 11:49:58 -0500135Image is returned if Image_Info is valid. Valid Image_Info parameters include:
136dimensions are greater than zero;
137each dimension fits in 29 bits;
138Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
139rowBytes are large enough to hold one row of pixels;
140pixels is not nullptr, and contains enough data for Image.
141
142#Param info contains width, height, Alpha_Type, Color_Type, Color_Space ##
143#Param pixels address or pixel storage ##
144#Param rowBytes size of pixel row or larger ##
145
146#Return Image sharing pixels, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500147
148#Example
149// incomplete
150##
151
Cary Clark3cd22cc2017-12-01 11:49:58 -0500152#SeeAlso MakeRasterCopy MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500153
154#Method ##
155
156# ------------------------------------------------------------------------------
157
Cary Clark3cd22cc2017-12-01 11:49:58 -0500158#Typedef void* ReleaseContext
159
160Caller data passed to RasterReleaseProc; may be nullptr.
161
162#SeeAlso MakeFromRaster RasterReleaseProc
163
164##
165
Cary Clarka560c472017-11-27 10:44:06 -0500166#Typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext)
167
Cary Clark3cd22cc2017-12-01 11:49:58 -0500168Function called when Image no longer shares pixels. ReleaseContext is
169provided by caller when Image is created, and may be nullptr.
170
171#SeeAlso ReleaseContext MakeFromRaster
172
Cary Clarka560c472017-11-27 10:44:06 -0500173##
174
175#Method static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap,
176 RasterReleaseProc rasterReleaseProc,
177 ReleaseContext releaseContext)
178
Cary Clark3cd22cc2017-12-01 11:49:58 -0500179Creates Image from pixmap, sharing pixmap pixels. Pixels must remain valid and
180unchanged until rasterReleaseProc is called. rasterReleaseProc is passed
181releaseContext when Image is deleted or no longer refers to pixmap pixels.
Cary Clarka560c472017-11-27 10:44:06 -0500182
Cary Clark3cd22cc2017-12-01 11:49:58 -0500183Image is returned if pixmap is valid. Valid Pixmap parameters include:
184dimensions are greater than zero;
185each dimension fits in 29 bits;
186Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
187row bytes are large enough to hold one row of pixels;
188pixel address is not nullptr.
189
190#Param pixmap Image_Info, pixel address, and row bytes ##
191#Param rasterReleaseProc function called when pixels can be released ##
192#Param releaseContext state passed to rasterReleaseProc ##
Cary Clarka560c472017-11-27 10:44:06 -0500193
194#Return incomplete ##
195
196#Example
197// incomplete
198##
199
Cary Clark3cd22cc2017-12-01 11:49:58 -0500200#SeeAlso MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext
Cary Clarka560c472017-11-27 10:44:06 -0500201
202#Method ##
203
204# ------------------------------------------------------------------------------
205
206#Method static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap)
207
Cary Clark3cd22cc2017-12-01 11:49:58 -0500208Creates Image from bitmap, sharing or copying bitmap pixels. If the bitmap
209is marked immutable, and its pixel memory is shareable, it may be shared
210instead of copied.
Cary Clarka560c472017-11-27 10:44:06 -0500211
Cary Clark3cd22cc2017-12-01 11:49:58 -0500212Image is returned if bitmap is valid. Valid Bitmap parameters include:
213dimensions are greater than zero;
214each dimension fits in 29 bits;
215Color_Type and Alpha_Type are valid, and Color_Type is not kUnknown_SkColorType;
216row bytes are large enough to hold one row of pixels;
217pixel address is not nullptr.
Cary Clarka560c472017-11-27 10:44:06 -0500218
Cary Clark3cd22cc2017-12-01 11:49:58 -0500219#Param bitmap Image_Info, row bytes, and pixels ##
220
221#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500222
223#Example
224// incomplete
225##
226
Cary Clark3cd22cc2017-12-01 11:49:58 -0500227#SeeAlso MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData
Cary Clarka560c472017-11-27 10:44:06 -0500228
229#Method ##
230
231# ------------------------------------------------------------------------------
232
233#Method static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator,
234 const SkIRect* subset = nullptr)
235
Cary Clark3cd22cc2017-12-01 11:49:58 -0500236Creates Image based from imageGenerator.
237Takes ownership of imageGenerator; it may not be used elsewhere.
238If subset is not nullptr, it must be contained within imageGenerator data bounds.
Cary Clarka560c472017-11-27 10:44:06 -0500239
Cary Clark3cd22cc2017-12-01 11:49:58 -0500240Image is returned if generator data is valid. Valid data parameters vary
241by type of data and platform.
Cary Clarka560c472017-11-27 10:44:06 -0500242
Cary Clark3cd22cc2017-12-01 11:49:58 -0500243imageGenerator may wrap Picture data, codec data, or custom data.
244
245#Param imageGenerator stock or custom routines to retrieve Image ##
246#Param subset bounds of returned Image; may be nullptr ##
247
248#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500249
250#Example
251// incomplete
252##
253
Cary Clark3cd22cc2017-12-01 11:49:58 -0500254#SeeAlso MakeFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500255
256#Method ##
257
258# ------------------------------------------------------------------------------
259
260#Method static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr)
261
Cary Clark3cd22cc2017-12-01 11:49:58 -0500262Creates Image from encoded data.
263If a subset is not nullptr, it must be contained within encoded data bounds.
Cary Clarka560c472017-11-27 10:44:06 -0500264
Cary Clark3cd22cc2017-12-01 11:49:58 -0500265Image is returned if format of the encoded data is recognized and supported.
266Recognized formats vary by platfrom.
Cary Clarka560c472017-11-27 10:44:06 -0500267
Cary Clark3cd22cc2017-12-01 11:49:58 -0500268#Param encoded data of Image to decode ##
269#Param subset bounds of returned Image; may be nullptr ##
270
271#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500272
273#Example
274// incomplete
275##
276
Cary Clark3cd22cc2017-12-01 11:49:58 -0500277#SeeAlso MakeFromGenerator
Cary Clarka560c472017-11-27 10:44:06 -0500278
279#Method ##
280
281# ------------------------------------------------------------------------------
282
283#Typedef void (*TextureReleaseProc)(ReleaseContext releaseContext)
284
285##
286
287#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
288 const GrBackendTexture& backendTexture,
289 GrSurfaceOrigin origin,
290 SkAlphaType alphaType,
291 sk_sp<SkColorSpace> colorSpace)
292
Cary Clark3cd22cc2017-12-01 11:49:58 -0500293Creates Image from GPU texture associated with context. Caller is responsible for
294managing the lifetime of GPU texture.
Cary Clarka560c472017-11-27 10:44:06 -0500295
Cary Clark3cd22cc2017-12-01 11:49:58 -0500296Image is returned if format of backendTexture is recognized and supported.
297Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500298
Cary Clark3cd22cc2017-12-01 11:49:58 -0500299#Param context GPU_Context ##
300#Param backendTexture texture residing on GPU ##
301#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
302#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
303 kPremul_SkAlphaType, kUnpremul_SkAlphaType
304##
305#Param colorSpace range of colors ##
306
307#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500308
309#Example
310// incomplete
311##
312
Cary Clark3cd22cc2017-12-01 11:49:58 -0500313#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500314
315#Method ##
316
317# ------------------------------------------------------------------------------
318
319#Method static sk_sp<SkImage> MakeFromTexture(GrContext* context,
320 const GrBackendTexture& backendTexture,
321 GrSurfaceOrigin origin,
322 SkAlphaType alphaType,
323 sk_sp<SkColorSpace> colorSpace,
324 TextureReleaseProc textureReleaseProc,
325 ReleaseContext releaseContext)
326
Cary Clark3cd22cc2017-12-01 11:49:58 -0500327Creates Image from GPU texture associated with context. GPU texture must stay
328valid and unchanged until textureReleaseProc is called. textureReleaseProc is
329passed releaseContext when Image is deleted or no longer refers to texture.
Cary Clarka560c472017-11-27 10:44:06 -0500330
Cary Clark3cd22cc2017-12-01 11:49:58 -0500331Image is returned if format of backendTexture is recognized and supported.
332Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500333
Cary Clark3cd22cc2017-12-01 11:49:58 -0500334#Param context GPU_Context ##
335#Param backendTexture texture residing on GPU ##
336#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
337#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
338 kPremul_SkAlphaType, kUnpremul_SkAlphaType
339##
340#Param colorSpace range of colors ##
341#Param textureReleaseProc function called when texture can be released ##
342#Param releaseContext state passed to textureReleaseProc ##
343
344#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500345
346#Example
347// incomplete
348##
349
Cary Clark3cd22cc2017-12-01 11:49:58 -0500350#SeeAlso MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture
Cary Clarka560c472017-11-27 10:44:06 -0500351
352#Method ##
353
354# ------------------------------------------------------------------------------
355
356#Method static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
357 bool buildMips,
358 SkColorSpace* dstColorSpace)
359
Cary Clark3cd22cc2017-12-01 11:49:58 -0500360Creates Image from encoded data. Image is uploaded to GPU back-end using context.
361
362Created Image is available to other GPU contexts, and is available across thread
363boundaries. All contexts must be in the same GPU_Share_Group, or otherwise
364share resources.
365
366When Image is no longer referenced, context releases texture memory
Cary Clarka560c472017-11-27 10:44:06 -0500367asynchronously.
Cary Clarka560c472017-11-27 10:44:06 -0500368
Cary Clark3cd22cc2017-12-01 11:49:58 -0500369Texture decoded from data is uploaded to match Surface created with
370dstColorSpace. Color_Space of Image is determined by encoded data.
Cary Clarka560c472017-11-27 10:44:06 -0500371
Cary Clark3cd22cc2017-12-01 11:49:58 -0500372Image is returned if format of data is recognized and supported, and if context
373supports moving resources. Recognized formats vary by platform and GPU back-end.
374
375#Param context GPU_Context ##
376#Param data Image to decode ##
377#Param buildMips create Image as Mip_Map if true ##
378#Param dstColorSpace range of colors of matching Surface on GPU ##
379
380#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500381
382#Example
383// incomplete
384##
385
Cary Clark3cd22cc2017-12-01 11:49:58 -0500386#SeeAlso MakeCrossContextFromPixmap
387
388#Method ##
389
390# ------------------------------------------------------------------------------
391
392#Method static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
393 bool buildMips,
394 SkColorSpace* dstColorSpace)
395
396Creates Image from pixmap. Image is uploaded to GPU back-end using context.
397
398Created Image is available to other GPU contexts, and is available across thread
399boundaries. All contexts must be in the same GPU_Share_Group, or otherwise
400share resources.
401
402When Image is no longer referenced, context releases texture memory
403asynchronously.
404
405Texture created from pixmap is uploaded to match Surface created with
406dstColorSpace. Color_Space of Image is determined by pixmap.colorSpace().
407
408Image is returned referring to GPU back-end if format of data is recognized and
409supported, and if context supports moving resources. Otherwise, pixmap pixel
410data is copied and Image as returned in raster format if possible; nullptr may
411be returned. Recognized GPU formats vary by platform and GPU back-end.
412
413#Param context GPU_Context ##
414#Param pixmap Image_Info, pixel address, and row bytes ##
415#Param buildMips create Image as Mip_Map if true ##
416#Param dstColorSpace range of colors of matching Surface on GPU ##
417
418#Return created Image, or nullptr ##
419
420#Example
421// incomplete
422##
423
424#SeeAlso MakeCrossContextFromEncoded
Cary Clarka560c472017-11-27 10:44:06 -0500425
426#Method ##
427
428# ------------------------------------------------------------------------------
429
430#Method static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
431 const GrBackendTexture& backendTexture,
432 GrSurfaceOrigin surfaceOrigin,
433 SkAlphaType alphaType = kPremul_SkAlphaType,
434 sk_sp<SkColorSpace> colorSpace = nullptr)
435
Cary Clark3cd22cc2017-12-01 11:49:58 -0500436Creates Image from backendTexture associated with context. backendTexture and
437returned Image are managed internally, and are released when no longer needed.
Cary Clarka560c472017-11-27 10:44:06 -0500438
Cary Clark3cd22cc2017-12-01 11:49:58 -0500439Image is returned if format of backendTexture is recognized and supported.
440Recognized formats vary by GPU back-end.
Cary Clarka560c472017-11-27 10:44:06 -0500441
Cary Clark3cd22cc2017-12-01 11:49:58 -0500442#Param context GPU_Context ##
443#Param backendTexture texture residing on GPU ##
444#Param surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ##
445#Param alphaType one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType,
446 kPremul_SkAlphaType, kUnpremul_SkAlphaType
447##
448#Param colorSpace range of colors ##
449
450#Return created Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500451
452#Example
453// incomplete
454##
455
456#SeeAlso incomplete
457
458#Method ##
459
460# ------------------------------------------------------------------------------
461
462#Method static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
463 const GrBackendObject yuvTextureHandles[3],
464 const SkISize yuvSizes[3],
465 GrSurfaceOrigin surfaceOrigin,
466 sk_sp<SkColorSpace> colorSpace = nullptr)
467
468Create a new image by copying the pixels from the specified y, u, v textures. The data
469from the textures is immediately ingested into the image and the textures can be modified or
470deleted after the function returns. The image will have the dimensions of the y texture.
471
472#Param context incomplete ##
473#Param yuvColorSpace incomplete ##
474#Param yuvTextureHandles incomplete ##
475#Param yuvSizes incomplete ##
476#Param surfaceOrigin incomplete ##
477#Param colorSpace incomplete ##
478
479#Return incomplete ##
480
481#Example
482// incomplete
483##
484
485#SeeAlso incomplete
486
487#Method ##
488
489# ------------------------------------------------------------------------------
490
491#Method static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context,
492 SkYUVColorSpace yuvColorSpace,
493 const GrBackendObject nv12TextureHandles[2],
494 const SkISize nv12Sizes[2],
495 GrSurfaceOrigin surfaceOrigin,
496 sk_sp<SkColorSpace> colorSpace = nullptr)
497
498Create a new image by copying the pixels from the specified y and UV_Mapping. The data
499from the textures is immediately ingested into the image and the textures can be modified or
500deleted after the function returns. The image will have the dimensions of the y texture.
501
502#Param context incomplete ##
503#Param yuvColorSpace incomplete ##
504#Param nv12TextureHandles incomplete ##
505#Param nv12Sizes incomplete ##
506#Param surfaceOrigin incomplete ##
507#Param colorSpace incomplete ##
508
509#Return incomplete ##
510
511#Example
512// incomplete
513##
514
515#SeeAlso incomplete
516
517#Method ##
518
519# ------------------------------------------------------------------------------
520
521#Enum BitDepth
522
523#Code
524 enum BitDepth {
525 kU8,
526 kF16,
527 };
528##
529
530#Const kU8 0
531##
532#Const kF16 1
533##
534
535#Example
536// incomplete
537##
538
539#SeeAlso incomplete
540
541#Enum ##
542
543# ------------------------------------------------------------------------------
544
545#Method static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
546 const SkMatrix* matrix, const SkPaint* paint,
547 BitDepth bitDepth,
548 sk_sp<SkColorSpace> colorSpace)
549
550Create a new image from the specified picture.
551On creation of the SkImage, snap the SkPicture to a particular BitDepth and SkColorSpace.
552
553#Param picture incomplete ##
554#Param dimensions incomplete ##
555#Param matrix incomplete ##
556#Param paint incomplete ##
557#Param bitDepth incomplete ##
558#Param colorSpace incomplete ##
559
560#Return incomplete ##
561
562#Example
563// incomplete
564##
565
566#SeeAlso incomplete
567
568#Method ##
569
570# ------------------------------------------------------------------------------
571
572#Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer,
573 SkAlphaType alphaType = kPremul_SkAlphaType,
574 sk_sp<SkColorSpace> colorSpace = nullptr)
575
576 Create a new image from the an Android hardware buffer.
577 The new image takes a reference on the buffer.
578
579 Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
580
581#Param hardwareBuffer incomplete ##
582#Param alphaType incomplete ##
583#Param colorSpace incomplete ##
584
585#Return incomplete ##
586
587#Example
588// incomplete
589##
590
591#SeeAlso incomplete
592
593#Method ##
594
595# ------------------------------------------------------------------------------
596
597#Method static sk_sp<SkImage> MakeFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer,
598 SkAlphaType alphaType = kPremul_SkAlphaType,
599 sk_sp<SkColorSpace> colorSpace = nullptr)
600
601Create a new image from the an Android hardware buffer.
602The new image takes a reference on the buffer.
603
604#Param hardwareBuffer incomplete ##
605#Param alphaType incomplete ##
606#Param colorSpace incomplete ##
607
608#Return incomplete ##
609
610#Example
611// incomplete
612##
613
614#SeeAlso incomplete
615
616#Method ##
617
618# ------------------------------------------------------------------------------
619
620#Method int width() const
621
622#Return incomplete ##
623
624#Example
625// incomplete
626##
627
628#SeeAlso incomplete
629
630#Method ##
631
632# ------------------------------------------------------------------------------
633
634#Method int height() const
635
Cary Clark2f466242017-12-11 16:03:17 -0500636Returns pixel row count.
637
Cary Clarka560c472017-11-27 10:44:06 -0500638#Return incomplete ##
639
640#Example
641// incomplete
642##
643
644#SeeAlso incomplete
645
646#Method ##
647
648# ------------------------------------------------------------------------------
649
650#Method SkISize dimensions() const
651
Cary Clark2f466242017-12-11 16:03:17 -0500652Returns ISize { width(), height() }.
653
654#Return integral size of width() and height() ##
Cary Clarka560c472017-11-27 10:44:06 -0500655
656#Example
657// incomplete
658##
659
Cary Clark2f466242017-12-11 16:03:17 -0500660#SeeAlso height() width()
Cary Clarka560c472017-11-27 10:44:06 -0500661
662#Method ##
663
664# ------------------------------------------------------------------------------
665
666#Method SkIRect bounds() const
667
Cary Clark2f466242017-12-11 16:03:17 -0500668Returns IRect { 0, 0, width(), height() }.
669
670#Return integral rectangle from origin to width() and height() ##
Cary Clarka560c472017-11-27 10:44:06 -0500671
672#Example
673// incomplete
674##
675
676#SeeAlso incomplete
677
678#Method ##
679
680# ------------------------------------------------------------------------------
681
682#Method uint32_t uniqueID() const
683
684#Return incomplete ##
685
686#Example
687// incomplete
688##
689
690#SeeAlso incomplete
691
692#Method ##
693
694# ------------------------------------------------------------------------------
695
696#Method SkAlphaType alphaType() const
697
698#Return incomplete ##
699
700#Example
701// incomplete
702##
703
704#SeeAlso incomplete
705
706#Method ##
707
708# ------------------------------------------------------------------------------
709
710#Method SkColorSpace* colorSpace() const
711
Cary Clark2f466242017-12-11 16:03:17 -0500712Returns Color_Space, the range of colors, associated with Image. The
713reference count of Color_Space is unchanged. The returned Color_Space is
714immutable.
Cary Clarka560c472017-11-27 10:44:06 -0500715
Cary Clark2f466242017-12-11 16:03:17 -0500716Color_Space returned was a parameter to an Image constructor,
717or was parsed from encoded data. Color_Space may be ignored when
718drawing Image, and when drawing into Surface constructed with Color_Space.
719
720#Return Color_Space in Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -0500721
722#Example
723// incomplete
724##
725
726#SeeAlso incomplete
727
728#Method ##
729
730# ------------------------------------------------------------------------------
731
732#Method sk_sp<SkColorSpace> refColorSpace() const
733
734#Return incomplete ##
735
736#Example
737// incomplete
738##
739
740#SeeAlso incomplete
741
742#Method ##
743
744# ------------------------------------------------------------------------------
745
746#Method bool isAlphaOnly() const
747
Cary Clark2f466242017-12-11 16:03:17 -0500748Returns true if Image pixels represent transparency only. If true, each pixel
749is packed in 8 bits as defined by kAlpha_8_SkColorType.
Cary Clarka560c472017-11-27 10:44:06 -0500750
Cary Clark2f466242017-12-11 16:03:17 -0500751#Return true if pixels represent a transparency mask ##
Cary Clarka560c472017-11-27 10:44:06 -0500752
753#Example
754// incomplete
755##
756
757#SeeAlso incomplete
758
759#Method ##
760
761# ------------------------------------------------------------------------------
762
763#Method bool isOpaque() const
764
Cary Clark2f466242017-12-11 16:03:17 -0500765Returns if all pixels ignore any Alpha value and are treated as fully opaque.
766
767#Return true if Alpha_Type is kOpaque_SkAlphaType ##
Cary Clarka560c472017-11-27 10:44:06 -0500768
769#Example
770// incomplete
771##
772
773#SeeAlso incomplete
774
775#Method ##
776
777# ------------------------------------------------------------------------------
778
779#Method sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2,
780 const SkMatrix* localMatrix = nullptr) const
781
782#Param tileMode1 incomplete ##
783#Param tileMode2 incomplete ##
784#Param localMatrix incomplete ##
785
786#Return incomplete ##
787
788#Example
789// incomplete
790##
791
792#SeeAlso incomplete
793
794#Method ##
795
796# ------------------------------------------------------------------------------
797
798#Method sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const
799
800Helper version of makeShader() that specifies SkShader::kClamp_TileMode.
801
802#Param localMatrix incomplete ##
803
804#Return incomplete ##
805
806#Example
807// incomplete
808##
809
810#SeeAlso incomplete
811
812#Method ##
813
814# ------------------------------------------------------------------------------
815
816#Method bool peekPixels(SkPixmap* pixmap) const
817
818If the image has direct access to its pixels (i.e. they are in local RAM)
819return true, and if not null, return in the pixmap parameter the info about the
820images pixels.
821On failure, return false and ignore the pixmap parameter.
822
823#Param pixmap incomplete ##
824
825#Return incomplete ##
826
827#Example
828// incomplete
829##
830
831#SeeAlso incomplete
832
833#Method ##
834
835# ------------------------------------------------------------------------------
836
837#Method GrTexture* getTexture() const
838
Cary Clark2f466242017-12-11 16:03:17 -0500839Deprecated.
840
841#Deprecated
842##
843
Cary Clarka560c472017-11-27 10:44:06 -0500844#Private
845currently used by Canvas2DLayerBridge in Chromium.
846##
847
Cary Clarka560c472017-11-27 10:44:06 -0500848#Method ##
849
850# ------------------------------------------------------------------------------
851
852#Method bool isTextureBacked() const
853
854Returns true if the image is texture backed.
855
856#Return incomplete ##
857
858#Example
859// incomplete
860##
861
862#SeeAlso incomplete
863
864#Method ##
865
866# ------------------------------------------------------------------------------
867
868#Method bool isValid(GrContext* context) const
869
870Returns true if Image can be drawn. If context
871is nullptr, tests if Image draws on Raster_Surface; Otherwise, tests if Image
872draws on GPU_Surface associated with context.
873
874Texture-backed images may become invalid if their underlying GrContext is abandoned. Some
875generator-backed images may be invalid for CPU and/or GPU.
876
877#Param context incomplete ##
878
879#Return incomplete ##
880
881#Example
882// incomplete
883##
884
885#SeeAlso incomplete
886
887#Method ##
888
889# ------------------------------------------------------------------------------
890
891#Method GrBackendObject getTextureHandle(bool flushPendingGrContextIO,
892 GrSurfaceOrigin* origin = nullptr) const
893
Cary Clark2f466242017-12-11 16:03:17 -0500894Retrieves the back-end API handle of texture. If flushPendingGrContextIO is true,
895complete deferred I/O operations.
Cary Clarka560c472017-11-27 10:44:06 -0500896
Cary Clark2f466242017-12-11 16:03:17 -0500897If origin in not nullptr, copies location of content drawn into Image.
Cary Clarka560c472017-11-27 10:44:06 -0500898
Cary Clark2f466242017-12-11 16:03:17 -0500899#Param flushPendingGrContextIO flag to flush outstanding requests ##
900#Param origin storage for one of: kTopLeft_GrSurfaceOrigin,
901 kBottomLeft_GrSurfaceOrigin; or nullptr
902##
903
904#Return back-end API texture handle ##
Cary Clarka560c472017-11-27 10:44:06 -0500905
906#Example
Cary Clark2f466242017-12-11 16:03:17 -0500907#Image 3
908#Platform gpu
909GrContext* context = canvas->getGrContext();
910if (!context) {
911 return;
912}
913SkPaint paint;
914paint.setAntiAlias(true);
915SkString str;
916int y = 0;
917for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) {
918 sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context,
919 backEndTexture, origin, kPremul_SkAlphaType, nullptr));
920 GrSurfaceOrigin readBackOrigin;
921 GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin);
922 str.printf("readBackHandle: %x", readBackHandle);
923 canvas->drawString(str, 5, y += 20, paint);
924 str.printf("origin: k%s_GrSurfaceOrigin", readBackOrigin ? "BottomLeft" : "TopLeft");
925 canvas->drawString(str, 5, y += 20, paint);
926}
Cary Clarka560c472017-11-27 10:44:06 -0500927##
928
929#SeeAlso incomplete
930
931#Method ##
932
933# ------------------------------------------------------------------------------
934
935#Enum CachingHint
936
937#Code
938 enum CachingHint {
939 kAllow_CachingHint,
940 kDisallow_CachingHint,
941 };
942##
943
944Hints to image calls where the system might cache computed intermediates (e.g. the results
945of decoding or a read-back from the GPU. Passing kAllow_CachingHint signals that the system's default
946behavior is fine. Passing kDisallow_CachingHint signals that caching should be avoided.
947
948#Const kAllow_CachingHint 0
949##
950#Const kDisallow_CachingHint 1
951##
952
953#Example
954// incomplete
955##
956
957#SeeAlso incomplete
958
959#Enum ##
960
961# ------------------------------------------------------------------------------
962
963#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
964 int srcX, int srcY, CachingHint cachingHint = kAllow_CachingHint) const
965
966Copy the pixels from the image into the specified buffer (dstPixels + dstRowBytes),
967converting them into the requested format (dstInfo). The image pixels are read
968starting at the specified (srcX, srcY) location.
969dstInfo and (srcX, srcY) offset specifies a source rectangle:
970#Code
971SkRect srcR;
972srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
973##
974
975The source rectangle is intersected with the bounds of the image. If this intersection is not empty,
976then we have two sets of pixels (of equal size). Replace dstPixels with the
977corresponding Image pixels, performing any Color_Type/Alpha_Type transformations needed
978(in the case where Image and dstInfo have different Color_Types or Alpha_Types).
979This call can fail, returning false, for several reasons:
980if source rectangle does not intersect the image bounds;
981if the requested Color_Type/Alpha_Type cannot be converted from the image's types.
982
983#Param dstInfo incomplete ##
984#Param dstPixels incomplete ##
985#Param dstRowBytes incomplete ##
986#Param srcX incomplete ##
987#Param srcY incomplete ##
988#Param cachingHint incomplete ##
989
990#Return incomplete ##
991
992#Example
993// incomplete
994##
995
996#SeeAlso incomplete
997
998#Method ##
999
1000# ------------------------------------------------------------------------------
1001
1002#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY,
1003 CachingHint cachingHint = kAllow_CachingHint) const
1004
1005#Param dst incomplete ##
1006#Param srcX incomplete ##
1007#Param srcY incomplete ##
1008#Param cachingHint incomplete ##
1009
1010#Return incomplete ##
1011
1012#Example
1013// incomplete
1014##
1015
1016#SeeAlso incomplete
1017
1018#Method ##
1019
1020# ------------------------------------------------------------------------------
1021
1022#Method bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
1023 CachingHint cachingHint = kAllow_CachingHint) const
1024
1025Copies Image pixels into dst, converting to dst Color_Type and Alpha_Type.
1026If the conversion cannot be performed, false is returned.
1027If dst dimensions differ from Image dimensions, Image is scaled, applying
1028filterQuality.
1029
1030#Param dst incomplete ##
1031#Param filterQuality incomplete ##
1032#Param cachingHint incomplete ##
1033
1034#Return incomplete ##
1035
1036#Example
1037// incomplete
1038##
1039
1040#SeeAlso incomplete
1041
1042#Method ##
1043
1044# ------------------------------------------------------------------------------
1045
1046#Method sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const
1047
Cary Clark2f466242017-12-11 16:03:17 -05001048Encodes Image pixels, returning result as SkData.
1049
1050Returns nullptr if encoding fails, or encodedImageFormat is not supported.
Cary Clarka560c472017-11-27 10:44:06 -05001051
1052#Param encodedImageFormat incomplete ##
1053#Param quality incomplete ##
1054
Cary Clark2f466242017-12-11 16:03:17 -05001055#Return encoded Image, or nullptr ##
Cary Clarka560c472017-11-27 10:44:06 -05001056
1057#Example
1058// incomplete
1059##
1060
1061#SeeAlso incomplete
1062
1063#Method ##
1064
1065# ------------------------------------------------------------------------------
1066
1067#Method sk_sp<SkData> encodeToData(SkPixelSerializer* pixelSerializer = nullptr) const
1068
1069Encodes Image and returns result as SkData. Will reuse existing encoded data
1070if present, as returned by refEncodedData. pixelSerializer validates existing
1071encoded data, and encodes Image when existing encoded data is missing or
1072invalid.
1073
1074Passing nullptr for pixelSerializer selects default serialization which
1075accepts all data and encodes to PNG.
1076
1077Returns nullptr if existing encoded data is missing or invalid and
1078encoding fails.
1079
1080#Param pixelSerializer incomplete ##
1081
1082#Return incomplete ##
1083
1084#Example
1085// incomplete
1086##
1087
1088#SeeAlso incomplete
1089
1090#Method ##
1091
1092# ------------------------------------------------------------------------------
1093
1094#Method sk_sp<SkData> refEncodedData() const
1095
1096If the image already has its contents in encoded form (e.g. PNG or JPEG), return that
1097as SkData. If the image does not already has its contents in encoded form, return nullptr.
1098
1099To force the image to return its contents as encoded data, call encodeToData.
1100
1101#Return incomplete ##
1102
1103#Example
1104// incomplete
1105##
1106
1107#SeeAlso incomplete
1108
1109#Method ##
1110
1111# ------------------------------------------------------------------------------
1112
1113#Method const char* toString(SkString* string) const
1114
1115#Param string incomplete ##
1116
1117#Return incomplete ##
1118
1119#Example
1120// incomplete
1121##
1122
1123#SeeAlso incomplete
1124
1125#Method ##
1126
1127# ------------------------------------------------------------------------------
1128
1129#Method sk_sp<SkImage> makeSubset(const SkIRect& subset) const
1130
1131Return a new image that is a subset of this image. The underlying implementation may
1132share the pixels, or it may make a copy.
1133If subset does not intersect the bounds of this image, or the copy/share cannot be made,
1134nullptr will be returned.
1135
1136#Param subset incomplete ##
1137
1138#Return incomplete ##
1139
1140#Example
1141// incomplete
1142##
1143
1144#SeeAlso incomplete
1145
1146#Method ##
1147
1148# ------------------------------------------------------------------------------
1149
1150#Method sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const
1151
1152Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use
1153with surfaces that have the supplied destination color space. If no transformation is
1154required, the returned image may be the same as this image. If this image is from a
1155different GrContext, this will fail.
1156
1157#Param context incomplete ##
1158#Param dstColorSpace incomplete ##
1159
1160#Return incomplete ##
1161
1162#Example
1163// incomplete
1164##
1165
1166#SeeAlso incomplete
1167
1168#Method ##
1169
1170# ------------------------------------------------------------------------------
1171
1172#Method sk_sp<SkImage> makeNonTextureImage() const
1173
1174If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
1175the pixels fails). Otherwise, it returns the original image.
1176
1177#Return incomplete ##
1178
1179#Example
1180// incomplete
1181##
1182
1183#SeeAlso incomplete
1184
1185#Method ##
1186
1187# ------------------------------------------------------------------------------
1188
1189#Method sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
1190 const SkIRect& clipBounds, SkIRect* outSubset,
1191 SkIPoint* offset) const
1192
1193Apply a given image filter to this image, and return the filtered result.
1194The subset represents the active portion of this image. The return value is similarly an
1195SkImage, with an active subset (outSubset). This is usually used with texture-backed
1196images, where the texture may be approx-match and thus larger than the required size.
1197clipBounds constrains the device-space extent of the image, stored in outSubset.
1198offset is storage, set to the amount to translate the result when drawn.
1199If the result image cannot be created, or the result would be transparent black, null
1200is returned, in which case the offset and outSubset parameters should be ignored by the
1201caller.
1202
1203#Param filter incomplete ##
1204#Param subset incomplete ##
1205#Param clipBounds incomplete ##
1206#Param outSubset incomplete ##
1207#Param offset incomplete ##
1208
1209#Return incomplete ##
1210
1211#Example
1212// incomplete
1213##
1214
1215#SeeAlso incomplete
1216
1217#Method ##
1218
1219# ------------------------------------------------------------------------------
1220
Cary Clarka560c472017-11-27 10:44:06 -05001221#Typedef std::function<void(GrBackendTexture)> BackendTextureReleaseProc
1222
1223##
1224
1225# ------------------------------------------------------------------------------
1226
1227#Method static bool MakeBackendTextureFromSkImage(GrContext* context,
1228 sk_sp<SkImage> image,
1229 GrBackendTexture* backendTexture,
1230 BackendTextureReleaseProc* backendTextureReleaseProc)
1231
1232Creates a GrBackendTexture from the provided SkImage. Returns true on success. The
1233GrBackendTexture and BackendTextureReleaseProc are populated on success. It is the callers
1234responsibility to call the BackendTextureReleaseProc once they have deleted the texture.
1235Note that the BackendTextureReleaseProc allows Skia to clean up auxiliary data related
1236to the GrBackendTexture, and is not a substitute for the client deleting the GrBackendTexture
1237themselves.
1238
1239If image is both texture backed and singly referenced; that is, its only
1240reference was transferred using std::move(): image is returned in backendTexture
1241without conversion or making a copy.
1242
1243If the SkImage is not texture backed, this function will generate a texture with the image's
1244contents and return that.
1245
1246#Param context incomplete ##
1247#Param image incomplete ##
1248#Param backendTexture incomplete ##
1249#Param backendTextureReleaseProc incomplete ##
1250
1251#Return incomplete ##
1252
1253#Example
1254// incomplete
1255##
1256
1257#SeeAlso incomplete
1258
1259#Method ##
1260
1261# ------------------------------------------------------------------------------
1262
1263#Enum LegacyBitmapMode
1264
1265#Code
1266 enum LegacyBitmapMode {
1267 kRO_LegacyBitmapMode,
1268 kRW_LegacyBitmapMode,
1269 };
1270##
1271
1272Helper functions to convert to SkBitmap
1273
1274#Const kRO_LegacyBitmapMode 0
1275##
1276#Const kRW_LegacyBitmapMode 1
1277##
1278
1279#Example
1280// incomplete
1281##
1282
1283#SeeAlso incomplete
1284
1285#Enum ##
1286
1287# ------------------------------------------------------------------------------
1288
1289#Method bool asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode legacyBitmapMode) const
1290
Cary Clark3cd22cc2017-12-01 11:49:58 -05001291Creates raster Bitmap with same pixels as Image. If legacyBitmapMode is kRO_LegacyBitmapMode,
1292returned bitmap is read-only and immutable.
1293Returns true if Bitmap is stored in bitmap. Returns false and resets bitmap if Bitmap
1294write did not succeed.
Cary Clarka560c472017-11-27 10:44:06 -05001295
Cary Clark3cd22cc2017-12-01 11:49:58 -05001296#Param bitmap storage for legacy Bitmap ##
1297#Param legacyBitmapMode one of: kRO_LegacyBitmapMode, kRW_LegacyBitmapMode ##
Cary Clarka560c472017-11-27 10:44:06 -05001298
Cary Clark3cd22cc2017-12-01 11:49:58 -05001299#Return true if Bitmap was created ##
Cary Clarka560c472017-11-27 10:44:06 -05001300
1301#Example
1302// incomplete
1303##
1304
1305#SeeAlso incomplete
1306
1307#Method ##
1308
1309# ------------------------------------------------------------------------------
1310
1311#Method bool isLazyGenerated() const
1312
1313Returns true if Image is backed by an image-generator or other service that creates
1314and caches its pixels or texture on-demand.
1315
Cary Clark2f466242017-12-11 16:03:17 -05001316#Return true if Image is created as needed ##
Cary Clarka560c472017-11-27 10:44:06 -05001317
1318#Example
Cary Clark2f466242017-12-11 16:03:17 -05001319#Height 80
1320#Function
1321class TestImageGenerator : public SkImageGenerator {
1322public:
1323 TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {}
1324 ~TestImageGenerator() override {}
1325protected:
1326 bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes,
1327 const Options& options) override {
1328 SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr);
1329 for (int y = 0; y < info.height(); ++y) {
1330 for (int x = 0; x < info.width(); ++x) {
1331 pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811;
1332 }
1333 }
1334 return true;
1335 }
1336};
1337##
1338void draw(SkCanvas* canvas) {
1339 auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator());
1340 sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen)));
1341 SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy");
1342 canvas->scale(8, 8);
1343 canvas->drawImage(image, 0, 0, nullptr);
1344 SkPaint paint;
1345 paint.setTextSize(4);
1346 canvas->drawString(lazy, 2, 5, paint);
1347}
Cary Clarka560c472017-11-27 10:44:06 -05001348##
1349
1350#SeeAlso incomplete
1351
1352#Method ##
1353
1354# ------------------------------------------------------------------------------
1355
1356#Method sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target,
1357 SkTransferFunctionBehavior premulBehavior) const
1358
1359If target is supported, returns an SkImage in target color space.
1360Otherwise, returns nullptr.
1361This will leave the image as is if it already in target color space.
1362Otherwise, it will convert the pixels from Image color space to target
1363color space. If this->colorSpace() is nullptr, Image color space will be
1364treated as sRGB.
1365
1366If premulBehavior is SkTransferFunctionBehavior::kRespect: converts Image
1367pixels to a linear space before converting to match destination Color_Type
1368and Color_Space.
1369If premulBehavior is SkTransferFunctionBehavior::kIgnore: Image
1370pixels are treated as if they are linear, regardless of how they are encoded.
1371
1372#Param target incomplete ##
1373#Param premulBehavior incomplete ##
1374
1375#Return incomplete ##
1376
1377#Example
1378// incomplete
1379##
1380
1381#SeeAlso incomplete
1382
1383#Method ##
1384
1385#Class SkImage ##
1386
1387#Topic Image ##