Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Friends | List of all members
SkImage Class Referenceabstract

#include <SkImage.h>

Inheritance diagram for SkImage:
SkRefCnt SkRefCntBase SkImage_Base SkImage_GaneshBase SkImage_Lazy SkImage_Raster skgpu::graphite::Image_Base SkImage_Ganesh SkImage_GaneshYUVA SkImage_LazyTexture SkImage_Picture SkImage_RasterPinnable skgpu::graphite::Image skgpu::graphite::Image_YUVA

Classes

class  AsyncReadResult
 
struct  RequiredProperties
 

Public Types

enum  CachingHint { kAllow_CachingHint , kDisallow_CachingHint }
 
enum class  RescaleGamma : bool { kSrc , kLinear }
 
enum class  RescaleMode { kNearest , kLinear , kRepeatedLinear , kRepeatedCubic }
 
enum  LegacyBitmapMode { kRO_LegacyBitmapMode }
 
using ReadPixelsContext = void *
 
using ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr< const AsyncReadResult >)
 

Public Member Functions

const SkImageInfoimageInfo () const
 
int width () const
 
int height () const
 
SkISize dimensions () const
 
SkIRect bounds () const
 
uint32_t uniqueID () const
 
SkAlphaType alphaType () const
 
SkColorType colorType () const
 
SkColorSpacecolorSpace () const
 
sk_sp< SkColorSpacerefColorSpace () const
 
bool isAlphaOnly () const
 
bool isOpaque () const
 
sk_sp< SkShadermakeShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
 
sk_sp< SkShadermakeShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &lm) const
 
sk_sp< SkShadermakeShader (const SkSamplingOptions &sampling, const SkMatrix &lm) const
 
sk_sp< SkShadermakeShader (const SkSamplingOptions &sampling, const SkMatrix *lm=nullptr) const
 
sk_sp< SkShadermakeRawShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
 
sk_sp< SkShadermakeRawShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &lm) const
 
sk_sp< SkShadermakeRawShader (const SkSamplingOptions &sampling, const SkMatrix &lm) const
 
sk_sp< SkShadermakeRawShader (const SkSamplingOptions &sampling, const SkMatrix *lm=nullptr) const
 
bool peekPixels (SkPixmap *pixmap) const
 
virtual bool isTextureBacked () const =0
 
virtual size_t textureSize () const =0
 
virtual bool isValid (GrRecordingContext *context) const =0
 
bool readPixels (GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
 
bool readPixels (GrDirectContext *context, const SkPixmap &dst, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
 
bool readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
 
bool readPixels (const SkPixmap &dst, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
 
void asyncRescaleAndReadPixels (const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) const
 
void asyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) const
 
void asyncRescaleAndReadPixelsYUVA420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) const
 
bool scalePixels (const SkPixmap &dst, const SkSamplingOptions &, CachingHint cachingHint=kAllow_CachingHint) const
 
sk_sp< SkDatarefEncodedData () const
 
virtual sk_sp< SkImagemakeSubset (GrDirectContext *direct, const SkIRect &subset) const =0
 
virtual sk_sp< SkImagemakeSubset (skgpu::graphite::Recorder *, const SkIRect &subset, RequiredProperties) const =0
 
bool hasMipmaps () const
 
bool isProtected () const
 
sk_sp< SkImagewithDefaultMipmaps () const
 
sk_sp< SkImagemakeNonTextureImage (GrDirectContext *=nullptr) const
 
sk_sp< SkImagemakeRasterImage (GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
 
sk_sp< SkImagemakeRasterImage (CachingHint cachingHint=kDisallow_CachingHint) const
 
bool asLegacyBitmap (SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
 
virtual bool isLazyGenerated () const =0
 
virtual sk_sp< SkImagemakeColorSpace (GrDirectContext *direct, sk_sp< SkColorSpace > target) const =0
 
virtual sk_sp< SkImagemakeColorSpace (skgpu::graphite::Recorder *, sk_sp< SkColorSpace > targetColorSpace, RequiredProperties) const =0
 
virtual sk_sp< SkImagemakeColorTypeAndColorSpace (GrDirectContext *direct, SkColorType targetColorType, sk_sp< SkColorSpace > targetCS) const =0
 
virtual sk_sp< SkImagemakeColorTypeAndColorSpace (skgpu::graphite::Recorder *, SkColorType targetColorType, sk_sp< SkColorSpace > targetColorSpace, RequiredProperties) const =0
 
sk_sp< SkImagereinterpretColorSpace (sk_sp< SkColorSpace > newColorSpace) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Friends

class SkBitmap
 
class SkImage_Base
 
class SkImage_Raster
 
class SkMipmapBuilder
 

Detailed Description

SkImage describes a two dimensional array of pixels to draw. The pixels may be decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, or located in GPU memory as a GPU texture.

SkImage cannot be modified after it is created. SkImage may allocate additional storage as needed; for instance, an encoded SkImage may decode when drawn.

SkImage width and height are greater than zero. Creating an SkImage with zero width or height returns SkImage equal to nullptr.

SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details vary with platform.

See SkImages namespace for the static factory methods to make SkImages.

Clients should not subclass SkImage as there is a lot of internal machinery that is not publicly accessible.

Definition at line 272 of file SkImage.h.

Member Typedef Documentation

◆ ReadPixelsCallback

using SkImage::ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr<const AsyncReadResult>)

Client-provided callback to asyncRescaleAndReadPixels() or asyncRescaleAndReadPixelsYUV420() that is called when read result is ready or on failure.

Definition at line 583 of file SkImage.h.

◆ ReadPixelsContext

Client-provided context that is passed to client-provided ReadPixelsContext.

Definition at line 578 of file SkImage.h.

Member Enumeration Documentation

◆ CachingHint

Enumerator
kAllow_CachingHint 

allows internally caching decoded and copied pixels

kDisallow_CachingHint 

disallows internally caching decoded and copied pixels

Definition at line 463 of file SkImage.h.

463 {
464 kAllow_CachingHint, //!< allows internally caching decoded and copied pixels
465 kDisallow_CachingHint, //!< disallows internally caching decoded and copied pixels
466 };
@ kDisallow_CachingHint
disallows internally caching decoded and copied pixels
Definition SkImage.h:465
@ kAllow_CachingHint
allows internally caching decoded and copied pixels
Definition SkImage.h:464

◆ LegacyBitmapMode

Deprecated.

Enumerator
kRO_LegacyBitmapMode 

returned bitmap is read-only and immutable

Definition at line 825 of file SkImage.h.

825 {
826 kRO_LegacyBitmapMode, //!< returned bitmap is read-only and immutable
827 };
@ kRO_LegacyBitmapMode
returned bitmap is read-only and immutable
Definition SkImage.h:826

◆ RescaleGamma

enum class SkImage::RescaleGamma : bool
strong
Enumerator
kSrc 
kLinear 

Definition at line 585 of file SkImage.h.

◆ RescaleMode

enum class SkImage::RescaleMode
strong
Enumerator
kNearest 
kLinear 
kRepeatedLinear 
kRepeatedCubic 

Definition at line 587 of file SkImage.h.

Member Function Documentation

◆ alphaType()

SkAlphaType SkImage::alphaType ( ) const

Returns SkAlphaType.

SkAlphaType returned was a parameter to an SkImage constructor, or was parsed from encoded data.

Returns
SkAlphaType in SkImage

example: https://fiddle.skia.org/c/@Image_alphaType

Definition at line 154 of file SkImage.cpp.

154{ return fInfo.alphaType(); }
SkAlphaType alphaType() const

◆ asLegacyBitmap()

bool SkImage::asLegacyBitmap ( SkBitmap bitmap,
LegacyBitmapMode  legacyBitmapMode = kRO_LegacyBitmapMode 
) const

Deprecated. Creates raster SkBitmap with same pixels as SkImage. If legacyBitmapMode is kRO_LegacyBitmapMode, returned bitmap is read-only and immutable. Returns true if SkBitmap is stored in bitmap. Returns false and resets bitmap if SkBitmap write did not succeed.

Parameters
bitmapstorage for legacy SkBitmap
legacyBitmapModebitmap is read-only and immutable
Returns
true if SkBitmap was created

Definition at line 233 of file SkImage.cpp.

233 {
234 // Context TODO: Elevate GrDirectContext requirement to public API.
235 auto dContext = as_IB(this)->directContext();
236 return as_IB(this)->onAsLegacyBitmap(dContext, bitmap);
237}
static SkImage_Base * as_IB(SkImage *image)
virtual bool onAsLegacyBitmap(GrDirectContext *, SkBitmap *) const
virtual GrDirectContext * directContext() const

◆ asyncRescaleAndReadPixels()

void SkImage::asyncRescaleAndReadPixels ( const SkImageInfo info,
const SkIRect srcRect,
RescaleGamma  rescaleGamma,
RescaleMode  rescaleMode,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
) const

Makes image pixel data available to caller, possibly asynchronously. It can also rescale the image pixels.

Currently asynchronous reads are only supported on the GPU backend and only when the underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all other cases this operates synchronously.

Data is read from the source sub-rectangle, is optionally converted to a linear gamma, is rescaled to the size indicated by 'info', is then converted to the color space, color type, and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the image causes failure.

When the pixel data is ready the caller's ReadPixelsCallback is called with a AsyncReadResult containing pixel data in the requested color type, alpha type, and color space. The AsyncReadResult will have count() == 1. Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU image this flushes work but a submit must occur to guarantee a finite time before the callback is called.

The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage is GPU-backed the data is immediately invalidated if the context is abandoned or destroyed.

Parameters
infoinfo of the requested pixels
srcRectsubrectangle of image to read
rescaleGammacontrols whether rescaling is done in the image's gamma or whether the source data is transformed to a linear gamma before rescaling.
rescaleModecontrols the technique (and cost) of the rescaling
callbackfunction to call with result of the read
contextpassed to callback

Definition at line 64 of file SkImage.cpp.

69 {
70 if (!SkIRect::MakeWH(this->width(), this->height()).contains(srcRect) ||
72 callback(context, nullptr);
73 return;
74 }
76 info, srcRect, rescaleGamma, rescaleMode, callback, context);
77}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static bool SkImageInfoIsValid(const SkImageInfo &info)
static bool contains(const SkRect &r, SkPoint p)
virtual void onAsyncRescaleAndReadPixels(const SkImageInfo &, SkIRect srcRect, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56

◆ asyncRescaleAndReadPixelsYUV420()

void SkImage::asyncRescaleAndReadPixelsYUV420 ( SkYUVColorSpace  yuvColorSpace,
sk_sp< SkColorSpace dstColorSpace,
const SkIRect srcRect,
const SkISize dstSize,
RescaleGamma  rescaleGamma,
RescaleMode  rescaleMode,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
) const

Similar to asyncRescaleAndReadPixels but performs an additional conversion to YUV. The RGB->YUV conversion is controlled by 'yuvColorSpace'. The YUV data is returned as three planes ordered y, u, v. The u and v planes are half the width and height of the resized rectangle. The y, u, and v values are single bytes. Currently this fails if 'dstSize' width and height are not even. A 'srcRect' that is not contained by the bounds of the image causes failure.

When the pixel data is ready the caller's ReadPixelsCallback is called with a AsyncReadResult containing the planar data. The AsyncReadResult will have count() == 3. Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU image this flushes work but a submit must occur to guarantee a finite time before the callback is called.

The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage is GPU-backed the data is immediately invalidated if the context is abandoned or destroyed.

Parameters
yuvColorSpaceThe transformation from RGB to YUV. Applied to the resized image after it is converted to dstColorSpace.
dstColorSpaceThe color space to convert the resized image to, after rescaling.
srcRectThe portion of the image to rescale and convert to YUV planes.
dstSizeThe size to rescale srcRect to
rescaleGammacontrols whether rescaling is done in the image's gamma or whether the source data is transformed to a linear gamma before rescaling.
rescaleModecontrols the technique (and cost) of the rescaling
callbackfunction to call with the planar read result
contextpassed to callback

Definition at line 79 of file SkImage.cpp.

86 {
87 if (!SkIRect::MakeWH(this->width(), this->height()).contains(srcRect) || dstSize.isZero() ||
88 (dstSize.width() & 0b1) || (dstSize.height() & 0b1)) {
89 callback(context, nullptr);
90 return;
91 }
92 as_IB(this)->onAsyncRescaleAndReadPixelsYUV420(yuvColorSpace,
93 /*readAlpha=*/false,
94 std::move(dstColorSpace),
95 srcRect,
96 dstSize,
97 rescaleGamma,
98 rescaleMode,
100 context);
101}
virtual void onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37
bool isZero() const
Definition SkSize.h:28

◆ asyncRescaleAndReadPixelsYUVA420()

void SkImage::asyncRescaleAndReadPixelsYUVA420 ( SkYUVColorSpace  yuvColorSpace,
sk_sp< SkColorSpace dstColorSpace,
const SkIRect srcRect,
const SkISize dstSize,
RescaleGamma  rescaleGamma,
RescaleMode  rescaleMode,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
) const

Identical to asyncRescaleAndReadPixelsYUV420 but a fourth plane is returned in the AsyncReadResult passed to 'callback'. The fourth plane contains the alpha chanel at the same full resolution as the Y plane.

Definition at line 103 of file SkImage.cpp.

110 {
111 if (!SkIRect::MakeWH(this->width(), this->height()).contains(srcRect) || dstSize.isZero() ||
112 (dstSize.width() & 0b1) || (dstSize.height() & 0b1)) {
113 callback(context, nullptr);
114 return;
115 }
116 as_IB(this)->onAsyncRescaleAndReadPixelsYUV420(yuvColorSpace,
117 /*readAlpha=*/true,
118 std::move(dstColorSpace),
119 srcRect,
120 dstSize,
121 rescaleGamma,
122 rescaleMode,
123 callback,
124 context);
125}

◆ bounds()

SkIRect SkImage::bounds ( ) const
inline

Returns SkIRect { 0, 0, width(), height() }.

Returns
integral rectangle from origin to width() and height()

Definition at line 303 of file SkImage.h.

303{ return SkIRect::MakeWH(fInfo.width(), fInfo.height()); }
int width() const
int height() const

◆ colorSpace()

SkColorSpace * SkImage::colorSpace ( ) const

Returns SkColorSpace, the range of colors, associated with SkImage. The reference count of SkColorSpace is unchanged. The returned SkColorSpace is immutable.

SkColorSpace returned was passed to an SkImage constructor, or was parsed from encoded data. SkColorSpace returned may be ignored when SkImage is drawn, depending on the capabilities of the SkSurface receiving the drawing.

Returns
SkColorSpace in SkImage, or nullptr

example: https://fiddle.skia.org/c/@Image_colorSpace

Definition at line 156 of file SkImage.cpp.

156{ return fInfo.colorSpace(); }
SkColorSpace * colorSpace() const

◆ colorType()

SkColorType SkImage::colorType ( ) const

Returns SkColorType if known; otherwise, returns kUnknown_SkColorType.

Returns
SkColorType of SkImage

example: https://fiddle.skia.org/c/@Image_colorType

Definition at line 152 of file SkImage.cpp.

152{ return fInfo.colorType(); }
SkColorType colorType() const

◆ dimensions()

SkISize SkImage::dimensions ( ) const
inline

Returns SkISize { width(), height() }.

Returns
integral size of width() and height()

Definition at line 297 of file SkImage.h.

297{ return SkISize::Make(fInfo.width(), fInfo.height()); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

◆ hasMipmaps()

bool SkImage::hasMipmaps ( ) const

Returns true if the image has mipmap levels.

Definition at line 292 of file SkImage.cpp.

292{ return as_IB(this)->onHasMipmaps(); }
virtual bool onHasMipmaps() const =0

◆ height()

int SkImage::height ( ) const
inline

Returns pixel row count.

Returns
pixel height in SkImage

Definition at line 291 of file SkImage.h.

291{ return fInfo.height(); }

◆ imageInfo()

const SkImageInfo & SkImage::imageInfo ( ) const
inline

Returns a SkImageInfo describing the width, height, color type, alpha type, and color space of the SkImage.

Returns
image info of SkImage.

Definition at line 279 of file SkImage.h.

279{ return fInfo; }

◆ isAlphaOnly()

bool SkImage::isAlphaOnly ( ) const

Returns true if SkImage pixels represent transparency only. If true, each pixel is packed in 8 bits as defined by kAlpha_8_SkColorType.

Returns
true if pixels represent a transparency mask

example: https://fiddle.skia.org/c/@Image_isAlphaOnly

Definition at line 239 of file SkImage.cpp.

239{ return SkColorTypeIsAlphaOnly(fInfo.colorType()); }
static bool SkColorTypeIsAlphaOnly(SkColorType ct)

◆ isLazyGenerated()

virtual bool SkImage::isLazyGenerated ( ) const
pure virtual

Returns true if SkImage is backed by an image-generator or other service that creates and caches its pixels or texture on-demand.

Returns
true if SkImage is created as needed

example: https://fiddle.skia.org/c/@Image_isLazyGenerated_a example: https://fiddle.skia.org/c/@Image_isLazyGenerated_b

Implemented in SkImage_Base.

◆ isOpaque()

bool SkImage::isOpaque ( ) const
inline

Returns true if pixels ignore their alpha value and are treated as fully opaque.

Returns
true if SkAlphaType is kOpaque_SkAlphaType

Definition at line 375 of file SkImage.h.

375{ return SkAlphaTypeIsOpaque(this->alphaType()); }
static bool SkAlphaTypeIsOpaque(SkAlphaType at)
Definition SkAlphaType.h:41
SkAlphaType alphaType() const
Definition SkImage.cpp:154

◆ isProtected()

bool SkImage::isProtected ( ) const

Returns true if the image holds protected content.

Definition at line 294 of file SkImage.cpp.

294{ return as_IB(this)->onIsProtected(); }
virtual bool onIsProtected() const =0

◆ isTextureBacked()

virtual bool SkImage::isTextureBacked ( ) const
pure virtual

Returns true if the contents of SkImage was created on or uploaded to GPU memory, and is available as a GPU texture.

Returns
true if SkImage is a GPU texture

example: https://fiddle.skia.org/c/@Image_isTextureBacked

Implemented in SkImage_Base.

◆ isValid()

virtual bool SkImage::isValid ( GrRecordingContext context) const
pure virtual

Returns true if SkImage can be drawn on either raster surface or GPU surface. If context is nullptr, tests if SkImage draws on raster surface; otherwise, tests if SkImage draws on GPU surface associated with context.

SkImage backed by GPU texture may become invalid if associated context is invalid. lazy image may be invalid and may not draw to raster surface or GPU surface or both.

Parameters
contextGPU context
Returns
true if SkImage can be drawn

example: https://fiddle.skia.org/c/@Image_isValid

Implemented in SkImage_GaneshBase, skgpu::graphite::Image_Base, SkImage_Lazy, and SkImage_Raster.

◆ makeColorSpace() [1/2]

virtual sk_sp< SkImage > SkImage::makeColorSpace ( GrDirectContext direct,
sk_sp< SkColorSpace target 
) const
pure virtual

Creates SkImage in target SkColorSpace. Returns nullptr if SkImage could not be created.

Returns original SkImage if it is in target SkColorSpace. Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace. If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB.

If this image is texture-backed, the context parameter is required and must match the context of the source image.

Parameters
directThe GrDirectContext in play, if it exists
targetSkColorSpace describing color range of returned SkImage
Returns
created SkImage in target SkColorSpace

example: https://fiddle.skia.org/c/@Image_makeColorSpace

Implemented in SkImage_Base.

◆ makeColorSpace() [2/2]

virtual sk_sp< SkImage > SkImage::makeColorSpace ( skgpu::graphite::Recorder ,
sk_sp< SkColorSpace targetColorSpace,
RequiredProperties   
) const
pure virtual

Creates SkImage in target SkColorSpace. Returns nullptr if SkImage could not be created.

Returns original SkImage if it is in target SkColorSpace. Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace. If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB.

If this image is graphite-backed, the recorder parameter is required.

Parameters
targetColorSpaceSkColorSpace describing color range of returned SkImage
recorderThe Recorder in which to create the new image
RequiredPropertiesproperties the returned SkImage must possess (e.g. mipmaps)
Returns
created SkImage in target SkColorSpace

Implemented in SkImage_Base.

◆ makeColorTypeAndColorSpace() [1/2]

virtual sk_sp< SkImage > SkImage::makeColorTypeAndColorSpace ( GrDirectContext direct,
SkColorType  targetColorType,
sk_sp< SkColorSpace targetCS 
) const
pure virtual

Experimental. Creates SkImage in target SkColorType and SkColorSpace. Returns nullptr if SkImage could not be created.

Returns original SkImage if it is in target SkColorType and SkColorSpace.

If this image is texture-backed, the context parameter is required and must match the context of the source image.

Parameters
directThe GrDirectContext in play, if it exists
targetColorTypeSkColorType of returned SkImage
targetColorSpaceSkColorSpace of returned SkImage
Returns
created SkImage in target SkColorType and SkColorSpace

Implemented in SkImage_GaneshBase, and SkImage_Base.

◆ makeColorTypeAndColorSpace() [2/2]

virtual sk_sp< SkImage > SkImage::makeColorTypeAndColorSpace ( skgpu::graphite::Recorder ,
SkColorType  targetColorType,
sk_sp< SkColorSpace targetColorSpace,
RequiredProperties   
) const
pure virtual

Experimental. Creates SkImage in target SkColorType and SkColorSpace. Returns nullptr if SkImage could not be created.

Returns original SkImage if it is in target SkColorType and SkColorSpace.

If this image is graphite-backed, the recorder parameter is required.

Parameters
targetColorTypeSkColorType of returned SkImage
targetColorSpaceSkColorSpace of returned SkImage
recorderThe Recorder in which to create the new image
RequiredPropertiesproperties the returned SkImage must possess (e.g. mipmaps)
Returns
created SkImage in target SkColorType and SkColorSpace

Implemented in skgpu::graphite::Image_Base, SkImage_GaneshBase, and SkImage_Base.

◆ makeNonTextureImage()

sk_sp< SkImage > SkImage::makeNonTextureImage ( GrDirectContext dContext = nullptr) const

Returns raster image or lazy image. Copies SkImage backed by GPU texture into CPU memory if needed. Returns original SkImage if decoded in raster bitmap, or if encoded in a stream.

Returns nullptr if backed by GPU texture and copy fails.

Returns
raster image, lazy image, or nullptr

example: https://fiddle.skia.org/c/@Image_makeNonTextureImage

Definition at line 260 of file SkImage.cpp.

260 {
261 if (!this->isTextureBacked()) {
262 return sk_ref_sp(const_cast<SkImage*>(this));
263 }
264 return this->makeRasterImage(dContext, kDisallow_CachingHint);
265}
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition SkImage.cpp:267
virtual bool isTextureBacked() const =0

◆ makeRasterImage() [1/2]

sk_sp< SkImage > SkImage::makeRasterImage ( CachingHint  cachingHint = kDisallow_CachingHint) const
inline

Definition at line 818 of file SkImage.h.

818 {
819 return this->makeRasterImage(nullptr, cachingHint);
820 }

◆ makeRasterImage() [2/2]

sk_sp< SkImage > SkImage::makeRasterImage ( GrDirectContext dContext,
CachingHint  cachingHint = kDisallow_CachingHint 
) const

Returns raster image. Copies SkImage backed by GPU texture into CPU memory, or decodes SkImage from lazy image. Returns original SkImage if decoded in raster bitmap.

Returns nullptr if copy, decode, or pixel read fails.

If cachingHint is kAllow_CachingHint, pixels may be retained locally. If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.

Returns
raster image, or nullptr

example: https://fiddle.skia.org/c/@Image_makeRasterImage

Definition at line 267 of file SkImage.cpp.

267 {
268 SkPixmap pm;
269 if (this->peekPixels(&pm)) {
270 return sk_ref_sp(const_cast<SkImage*>(this));
271 }
272
273 const size_t rowBytes = fInfo.minRowBytes();
274 size_t size = fInfo.computeByteSize(rowBytes);
276 return nullptr;
277 }
278
279 if (!dContext) {
280 // Try to get the saved context if the client didn't pass it in (but they really should).
281 dContext = as_IB(this)->directContext();
282 }
284 pm = {fInfo.makeColorSpace(nullptr), data->writable_data(), fInfo.minRowBytes()};
285 if (!this->readPixels(dContext, pm, 0, 0, chint)) {
286 return nullptr;
287 }
288
289 return SkImages::RasterFromData(fInfo, std::move(data), rowBytes);
290}
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition SkData.cpp:116
bool readPixels(GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
Definition SkImage.cpp:42
bool peekPixels(SkPixmap *pixmap) const
Definition SkImage.cpp:34
SK_API sk_sp< SkImage > RasterFromData(const SkImageInfo &info, sk_sp< SkData > pixels, size_t rowBytes)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
static bool ByteSizeOverflowed(size_t byteSize)
size_t minRowBytes() const
size_t computeByteSize(size_t rowBytes) const
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const

◆ makeRawShader() [1/4]

sk_sp< SkShader > SkImage::makeRawShader ( const SkSamplingOptions sampling,
const SkMatrix lm 
) const

Defaults to clamp in both X and Y.

Definition at line 193 of file SkImage.cpp.

194 {
195 return SkImageShader::MakeRaw(sk_ref_sp(const_cast<SkImage*>(this)),
197 sampling, &lm);
198}
static sk_sp< SkShader > MakeRaw(sk_sp< SkImage >, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix)

◆ makeRawShader() [2/4]

sk_sp< SkShader > SkImage::makeRawShader ( const SkSamplingOptions sampling,
const SkMatrix lm = nullptr 
) const

Definition at line 200 of file SkImage.cpp.

201 {
202 return SkImageShader::MakeRaw(sk_ref_sp(const_cast<SkImage*>(this)),
204 sampling, localMatrix);
205}

◆ makeRawShader() [3/4]

sk_sp< SkShader > SkImage::makeRawShader ( SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions sampling,
const SkMatrix localMatrix = nullptr 
) const

makeRawShader functions like makeShader, but for images that contain non-color data. This includes images encoding things like normals, material properties (eg, roughness), heightmaps, or any other purely mathematical data that happens to be stored in an image. These types of images are useful with some programmable shaders (see: SkRuntimeEffect).

Raw image shaders work like regular image shaders (including filtering and tiling), with a few major differences:

  • No color space transformation is ever applied (the color space of the image is ignored).
  • Images with an alpha type of kUnpremul are not automatically premultiplied.
  • Bicubic filtering is not supported. If SkSamplingOptions::useCubic is true, these factories will return nullptr.

Definition at line 207 of file SkImage.cpp.

209 {
210 return SkImageShader::MakeRaw(sk_ref_sp(const_cast<SkImage*>(this)), tmx, tmy,
211 sampling, localMatrix);
212}
SkTileMode tmy
SkTileMode tmx

◆ makeRawShader() [4/4]

sk_sp< SkShader > SkImage::makeRawShader ( SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions sampling,
const SkMatrix lm 
) const

Definition at line 186 of file SkImage.cpp.

188 {
189 return SkImageShader::MakeRaw(sk_ref_sp(const_cast<SkImage*>(this)), tmx, tmy,
190 sampling, &lm);
191}

◆ makeShader() [1/4]

sk_sp< SkShader > SkImage::makeShader ( const SkSamplingOptions sampling,
const SkMatrix lm 
) const

Defaults to clamp in both X and Y.

Definition at line 160 of file SkImage.cpp.

160 {
161 return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)),
163 sampling, &lm);
164}
static sk_sp< SkShader > Make(sk_sp< SkImage >, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix, bool clampAsIfUnpremul=false)

◆ makeShader() [2/4]

sk_sp< SkShader > SkImage::makeShader ( const SkSamplingOptions sampling,
const SkMatrix lm = nullptr 
) const

Definition at line 166 of file SkImage.cpp.

166 {
167 return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)),
169 sampling, lm);
170}

◆ makeShader() [3/4]

sk_sp< SkShader > SkImage::makeShader ( SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions sampling,
const SkMatrix localMatrix = nullptr 
) const

Make a shader with the specified tiling and mipmap sampling.

Definition at line 179 of file SkImage.cpp.

181 {
182 return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tmx, tmy,
183 sampling, localMatrix);
184}

◆ makeShader() [4/4]

sk_sp< SkShader > SkImage::makeShader ( SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions sampling,
const SkMatrix lm 
) const

Definition at line 172 of file SkImage.cpp.

174 {
175 return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tmx, tmy,
176 sampling, &lm);
177}

◆ makeSubset() [1/2]

virtual sk_sp< SkImage > SkImage::makeSubset ( GrDirectContext direct,
const SkIRect subset 
) const
pure virtual

Returns subset of this image.

Returns nullptr if any of the following are true:

  • Subset is empty
  • Subset is not contained inside the image's bounds
  • Pixels in the source image could not be read or copied
  • This image is texture-backed and the provided context is null or does not match the source image's context.

If the source image was texture-backed, the resulting image will be texture-backed also. Otherwise, the returned image will be raster-backed.

Parameters
directthe GrDirectContext of the source image (nullptr is ok if the source image is not texture-backed).
subsetbounds of returned SkImage
Returns
the subsetted image, or nullptr

example: https://fiddle.skia.org/c/@Image_makeSubset

Implemented in SkImage_GaneshBase, and SkImage_Base.

◆ makeSubset() [2/2]

virtual sk_sp< SkImage > SkImage::makeSubset ( skgpu::graphite::Recorder ,
const SkIRect subset,
RequiredProperties   
) const
pure virtual

Returns subset of this image.

Returns nullptr if any of the following are true:

  • Subset is empty
  • Subset is not contained inside the image's bounds
  • Pixels in the image could not be read or copied
  • This image is texture-backed and the provided context is null or does not match the source image's context.

If the source image was texture-backed, the resulting image will be texture-backed also. Otherwise, the returned image will be raster-backed.

Parameters
recorderthe recorder of the source image (nullptr is ok if the source image was texture-backed).
subsetbounds of returned SkImage
RequiredPropertiesproperties the returned SkImage must possess (e.g. mipmaps)
Returns
the subsetted image, or nullptr

Implemented in SkImage_Base.

◆ peekPixels()

bool SkImage::peekPixels ( SkPixmap pixmap) const

Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address is available, and returns true. If pixel address is not available, return false and leave pixmap unchanged.

Parameters
pixmapstorage for pixel state if pixels are readable; otherwise, ignored
Returns
true if SkImage has direct access to pixels

example: https://fiddle.skia.org/c/@Image_peekPixels

Definition at line 34 of file SkImage.cpp.

34 {
35 SkPixmap tmp;
36 if (!pm) {
37 pm = &tmp;
38 }
39 return as_IB(this)->onPeekPixels(pm);
40}
virtual bool onPeekPixels(SkPixmap *) const

◆ readPixels() [1/4]

bool SkImage::readPixels ( const SkImageInfo dstInfo,
void *  dstPixels,
size_t  dstRowBytes,
int  srcX,
int  srcY,
CachingHint  cachingHint = kAllow_CachingHint 
) const

Deprecated. Use the variants that accept a GrDirectContext.

Definition at line 48 of file SkImage.cpp.

49 {
50 auto dContext = as_IB(this)->directContext();
51 return this->readPixels(dContext, dstInfo, dstPixels, dstRowBytes, srcX, srcY, chint);
52}

◆ readPixels() [2/4]

bool SkImage::readPixels ( const SkPixmap dst,
int  srcX,
int  srcY,
CachingHint  cachingHint = kAllow_CachingHint 
) const

Definition at line 227 of file SkImage.cpp.

227 {
228 auto dContext = as_IB(this)->directContext();
229 return this->readPixels(dContext, pmap, srcX, srcY, chint);
230}

◆ readPixels() [3/4]

bool SkImage::readPixels ( GrDirectContext context,
const SkImageInfo dstInfo,
void *  dstPixels,
size_t  dstRowBytes,
int  srcX,
int  srcY,
CachingHint  cachingHint = kAllow_CachingHint 
) const

Copies SkRect of pixels from SkImage to dstPixels. Copy starts at offset (srcX, srcY), and does not exceed SkImage (width(), height()).

dstInfo specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of destination. dstRowBytes specifies the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:

  • dstInfo.addr() equals nullptr
  • dstRowBytes is less than dstInfo.minRowBytes()
  • SkPixelRef is nullptr

Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. If SkImage SkColorType is kGray_8_SkColorType, dstInfo.colorSpace() must match. If SkImage SkAlphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must match. If SkImage SkColorSpace is nullptr, dstInfo.colorSpace() must match. Returns false if pixel conversion is not possible.

srcX and srcY may be negative to copy only top or left of source. Returns false if width() or height() is zero or negative. Returns false if abs(srcX) >= Image width(), or if abs(srcY) >= Image height().

If cachingHint is kAllow_CachingHint, pixels may be retained locally. If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.

Parameters
contextthe GrDirectContext in play, if it exists
dstInfodestination width, height, SkColorType, SkAlphaType, SkColorSpace
dstPixelsdestination pixel storage
dstRowBytesdestination row length
srcXcolumn index whose absolute value is less than width()
srcYrow index whose absolute value is less than height()
cachingHintwhether the pixels should be cached locally
Returns
true if pixels are copied to dstPixels

Definition at line 42 of file SkImage.cpp.

43 {
44 return as_IB(this)->onReadPixels(dContext, dstInfo, dstPixels, dstRowBytes, srcX, srcY, chint);
45}
virtual bool onReadPixels(GrDirectContext *, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint) const =0

◆ readPixels() [4/4]

bool SkImage::readPixels ( GrDirectContext context,
const SkPixmap dst,
int  srcX,
int  srcY,
CachingHint  cachingHint = kAllow_CachingHint 
) const

Copies a SkRect of pixels from SkImage to dst. Copy starts at (srcX, srcY), and does not exceed SkImage (width(), height()).

dst specifies width, height, SkColorType, SkAlphaType, SkColorSpace, pixel storage, and row bytes of destination. dst.rowBytes() specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:

Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match. If SkImage SkColorType is kGray_8_SkColorType, dst.colorSpace() must match. If SkImage SkAlphaType is kOpaque_SkAlphaType, dst.alphaType() must match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns false if pixel conversion is not possible.

srcX and srcY may be negative to copy only top or left of source. Returns false if width() or height() is zero or negative. Returns false if abs(srcX) >= Image width(), or if abs(srcY) >= Image height().

If cachingHint is kAllow_CachingHint, pixels may be retained locally. If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.

Parameters
contextthe GrDirectContext in play, if it exists
dstdestination SkPixmap: SkImageInfo, pixels, row bytes
srcXcolumn index whose absolute value is less than width()
srcYrow index whose absolute value is less than height()
cachingHintwhether the pixels should be cached locallyZ
Returns
true if pixels are copied to dst

Definition at line 220 of file SkImage.cpp.

221 {
222 return this->readPixels(dContext, pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX,
223 srcY, chint);
224}

◆ refColorSpace()

sk_sp< SkColorSpace > SkImage::refColorSpace ( ) const

Returns a smart pointer to SkColorSpace, the range of colors, associated with SkImage. The smart pointer tracks the number of objects sharing this SkColorSpace reference so the memory is released when the owners destruct.

The returned SkColorSpace is immutable.

SkColorSpace returned was passed to an SkImage constructor, or was parsed from encoded data. SkColorSpace returned may be ignored when SkImage is drawn, depending on the capabilities of the SkSurface receiving the drawing.

Returns
SkColorSpace in SkImage, or nullptr, wrapped in a smart pointer

example: https://fiddle.skia.org/c/@Image_refColorSpace

Definition at line 158 of file SkImage.cpp.

158{ return fInfo.refColorSpace(); }
sk_sp< SkColorSpace > refColorSpace() const

◆ refEncodedData()

sk_sp< SkData > SkImage::refEncodedData ( ) const

Returns encoded SkImage pixels as SkData, if SkImage was created from supported encoded stream format. Platform support for formats vary and may require building with one or more of: SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP.

Returns nullptr if SkImage contents are not encoded.

Returns
encoded SkImage, or nullptr

example: https://fiddle.skia.org/c/@Image_refEncodedData

Definition at line 214 of file SkImage.cpp.

214 {
215 return sk_sp<SkData>(as_IB(this)->onRefEncoded());
216}

◆ reinterpretColorSpace()

sk_sp< SkImage > SkImage::reinterpretColorSpace ( sk_sp< SkColorSpace newColorSpace) const

Creates a new SkImage identical to this one, but with a different SkColorSpace. This does not convert the underlying pixel data, so the resulting image will draw differently.

Definition at line 241 of file SkImage.cpp.

241 {
242 if (!target) {
243 return nullptr;
244 }
245
246 // No need to create a new image if:
247 // (1) The color spaces are equal.
248 // (2) The color type is kAlpha8.
250 if (!colorSpace) {
252 }
253 if (SkColorSpace::Equals(colorSpace, target.get()) || this->isAlphaOnly()) {
254 return sk_ref_sp(const_cast<SkImage*>(this));
255 }
256
257 return as_IB(this)->onReinterpretColorSpace(std::move(target));
258}
SkColorSpace * sk_srgb_singleton()
static bool Equals(const SkColorSpace *, const SkColorSpace *)
virtual sk_sp< SkImage > onReinterpretColorSpace(sk_sp< SkColorSpace >) const =0
SkColorSpace * colorSpace() const
Definition SkImage.cpp:156
uint32_t * target

◆ scalePixels()

bool SkImage::scalePixels ( const SkPixmap dst,
const SkSamplingOptions sampling,
CachingHint  cachingHint = kAllow_CachingHint 
) const

Copies SkImage to dst, scaling pixels to fit dst.width() and dst.height(), and converting pixels to match dst.colorType() and dst.alphaType(). Returns true if pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes() is less than dst SkImageInfo::minRowBytes.

Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match. If SkImage SkColorType is kGray_8_SkColorType, dst.colorSpace() must match. If SkImage SkAlphaType is kOpaque_SkAlphaType, dst.alphaType() must match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns false if pixel conversion is not possible.

If cachingHint is kAllow_CachingHint, pixels may be retained locally. If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.

Parameters
dstdestination SkPixmap: SkImageInfo, pixels, row bytes
Returns
true if pixels are scaled to fit dst

Definition at line 127 of file SkImage.cpp.

128 {
129 // Context TODO: Elevate GrDirectContext requirement to public API.
130 auto dContext = as_IB(this)->directContext();
131 if (this->width() == dst.width() && this->height() == dst.height()) {
132 return this->readPixels(dContext, dst, 0, 0, chint);
133 }
134
135 // Idea: If/when SkImageGenerator supports a native-scaling API (where the generator itself
136 // can scale more efficiently) we should take advantage of it here.
137 //
138 SkBitmap bm;
139 if (as_IB(this)->getROPixels(dContext, &bm, chint)) {
140 SkPixmap pmap;
141 // Note: By calling the pixmap scaler, we never cache the final result, so the chint
142 // is (currently) only being applied to the getROPixels. If we get a request to
143 // also attempt to cache the final (scaled) result, we would add that logic here.
144 //
145 return bm.peekPixels(&pmap) && pmap.scalePixels(dst, sampling);
146 }
147 return false;
148}
bool peekPixels(SkPixmap *pixmap) const
Definition SkBitmap.cpp:635
bool scalePixels(const SkPixmap &dst, const SkSamplingOptions &) const
int width() const
Definition SkPixmap.h:160
dst
Definition cp.py:12

◆ textureSize()

virtual size_t SkImage::textureSize ( ) const
pure virtual

Returns an approximation of the amount of texture memory used by the image. Returns zero if the image is not texture backed or if the texture has an external format.

Implemented in SkImage_Ganesh, SkImage_GaneshYUVA, skgpu::graphite::Image, skgpu::graphite::Image_YUVA, and SkImage_Base.

◆ uniqueID()

uint32_t SkImage::uniqueID ( ) const
inline

Returns value unique to image. SkImage contents cannot change after SkImage is created. Any operation to create a new SkImage will receive generate a new unique number.

Returns
unique identifier

Definition at line 311 of file SkImage.h.

311{ return fUniqueID; }

◆ width()

int SkImage::width ( ) const
inline

Returns pixel count in each row.

Returns
pixel width in SkImage

Definition at line 285 of file SkImage.h.

285{ return fInfo.width(); }

◆ withDefaultMipmaps()

sk_sp< SkImage > SkImage::withDefaultMipmaps ( ) const

Returns an image with the same "base" pixels as the this image, but with mipmap levels automatically generated and attached.

Definition at line 305 of file SkImage.cpp.

305 {
306 return this->withMipmaps(nullptr);
307}

Friends And Related Symbol Documentation

◆ SkBitmap

friend class SkBitmap
friend

Definition at line 935 of file SkImage.h.

◆ SkImage_Base

friend class SkImage_Base
friend

Definition at line 936 of file SkImage.h.

◆ SkImage_Raster

friend class SkImage_Raster
friend

Definition at line 937 of file SkImage.h.

◆ SkMipmapBuilder

friend class SkMipmapBuilder
friend

Definition at line 938 of file SkImage.h.


The documentation for this class was generated from the following files: