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