![]() |
Skia
2D Graphics Library
|
#include <SkImage.h>
Classes | |
class | AsyncReadResult |
The result from asyncRescaleAndReadPixels() or asyncRescaleAndReadPixelsYUV420(). More... | |
Public Member Functions | |
const SkImageInfo & | imageInfo () const |
Returns a SkImageInfo describing the width, height, color type, alpha type, and color space of the SkImage. More... | |
int | width () const |
Returns pixel count in each row. More... | |
int | height () const |
Returns pixel row count. More... | |
SkISize | dimensions () const |
Returns SkISize { width(), height() }. More... | |
SkIRect | bounds () const |
Returns SkIRect { 0, 0, width(), height() }. More... | |
uint32_t | uniqueID () const |
Returns value unique to image. More... | |
SkAlphaType | alphaType () const |
Returns SkAlphaType. More... | |
SkColorType | colorType () const |
Returns SkColorType if known; otherwise, returns kUnknown_SkColorType. More... | |
SkColorSpace * | colorSpace () const |
Returns SkColorSpace, the range of colors, associated with SkImage. More... | |
sk_sp< SkColorSpace > | refColorSpace () const |
Returns a smart pointer to SkColorSpace, the range of colors, associated with SkImage. More... | |
bool | isAlphaOnly () const |
Returns true if SkImage pixels represent transparency only. More... | |
bool | isOpaque () const |
Returns true if pixels ignore their alpha value and are treated as fully opaque. More... | |
sk_sp< SkShader > | makeShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const |
Make a shader with the specified tiling and mipmap sampling. More... | |
sk_sp< SkShader > | makeShader (SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix &lm) const |
sk_sp< SkShader > | makeShader (const SkSamplingOptions &sampling, const SkMatrix &lm) const |
sk_sp< SkShader > | makeShader (const SkSamplingOptions &sampling, const SkMatrix *lm=nullptr) const |
bool | peekPixels (SkPixmap *pixmap) const |
Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address is available, and returns true. More... | |
bool | isTextureBacked () const |
Returns true the contents of SkImage was created on or uploaded to GPU memory, and is available as a GPU texture. More... | |
size_t | textureSize () const |
Returns an approximation of the amount of texture memory used by the image. More... | |
bool | isValid (GrRecordingContext *context) const |
Returns true if SkImage can be drawn on either raster surface or GPU surface. More... | |
GrSemaphoresSubmitted | flush (GrDirectContext *context, const GrFlushInfo &flushInfo) |
Flushes any pending uses of texture-backed images in the GPU backend. More... | |
void | flush (GrDirectContext *context) |
void | flushAndSubmit (GrDirectContext *) |
Version of flush() that uses a default GrFlushInfo. More... | |
GrBackendTexture | getBackendTexture (bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr) const |
Retrieves the back-end texture. More... | |
bool | 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. More... | |
bool | readPixels (GrDirectContext *context, const SkPixmap &dst, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const |
Copies a SkRect of pixels from SkImage to dst. More... | |
bool | readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const |
Deprecated. More... | |
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) |
Makes image pixel data available to caller, possibly asynchronously. More... | |
void | asyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) |
Similar to asyncRescaleAndReadPixels but performs an additional conversion to YUV. More... | |
bool | scalePixels (const SkPixmap &dst, const SkSamplingOptions &, 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(). More... | |
sk_sp< SkData > | encodeToData (SkEncodedImageFormat encodedImageFormat, int quality) const |
Encodes SkImage pixels, returning result as SkData. More... | |
sk_sp< SkData > | encodeToData () const |
Encodes SkImage pixels, returning result as SkData. More... | |
sk_sp< SkData > | refEncodedData () const |
Returns encoded SkImage pixels as SkData, if SkImage was created from supported encoded stream format. More... | |
sk_sp< SkImage > | makeSubset (const SkIRect &subset, GrDirectContext *direct=nullptr) const |
Returns subset of this image. More... | |
bool | hasMipmaps () const |
Returns true if the image has mipmap levels. More... | |
sk_sp< SkImage > | withDefaultMipmaps () const |
Returns an image with the same "base" pixels as the this image, but with mipmap levels automatically generated and attached. More... | |
sk_sp< SkImage > | makeTextureImage (GrDirectContext *, GrMipmapped=GrMipmapped::kNo, SkBudgeted=SkBudgeted::kYes) const |
Returns SkImage backed by GPU texture associated with context. More... | |
sk_sp< SkImage > | makeNonTextureImage () const |
Returns raster image or lazy image. More... | |
sk_sp< SkImage > | makeRasterImage (CachingHint cachingHint=kDisallow_CachingHint) const |
Returns raster image. More... | |
sk_sp< SkImage > | makeWithFilter (GrRecordingContext *context, const SkImageFilter *filter, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset) const |
Creates filtered SkImage. More... | |
bool | asLegacyBitmap (SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const |
Deprecated. More... | |
bool | isLazyGenerated () const |
Returns true if SkImage is backed by an image-generator or other service that creates and caches its pixels or texture on-demand. More... | |
sk_sp< SkImage > | makeColorSpace (sk_sp< SkColorSpace > target, GrDirectContext *direct=nullptr) const |
Creates SkImage in target SkColorSpace. More... | |
sk_sp< SkImage > | makeColorTypeAndColorSpace (SkColorType targetColorType, sk_sp< SkColorSpace > targetColorSpace, GrDirectContext *direct=nullptr) const |
Experimental. More... | |
sk_sp< SkImage > | reinterpretColorSpace (sk_sp< SkColorSpace > newColorSpace) const |
Creates a new SkImage identical to this one, but with a different SkColorSpace. More... | |
bool | unique () const |
May return true if the caller is the only owner. More... | |
void | ref () const |
Increment the reference count. More... | |
void | unref () const |
Decrement the reference count. More... | |
Static Public Member Functions | |
static sk_sp< SkImage > | MakeRasterCopy (const SkPixmap &pixmap) |
Creates SkImage from SkPixmap and copy of pixels. More... | |
static sk_sp< SkImage > | MakeRasterData (const SkImageInfo &info, sk_sp< SkData > pixels, size_t rowBytes) |
Creates SkImage from SkImageInfo, sharing pixels. More... | |
static sk_sp< SkImage > | MakeFromRaster (const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext) |
Creates SkImage from pixmap, sharing SkPixmap pixels. More... | |
static sk_sp< SkImage > | MakeFromBitmap (const SkBitmap &bitmap) |
Creates SkImage from bitmap, sharing or copying bitmap pixels. More... | |
static sk_sp< SkImage > | MakeFromGenerator (std::unique_ptr< SkImageGenerator > imageGenerator) |
Creates SkImage from data returned by imageGenerator. More... | |
static sk_sp< SkImage > | MakeFromEncoded (sk_sp< SkData > encoded) |
Return an image backed by the encoded data, but attempt to defer decoding until the image is actually used/drawn. More... | |
static sk_sp< SkImage > | MakeTextureFromCompressed (GrDirectContext *direct, sk_sp< SkData > data, int width, int height, CompressionType type, GrMipmapped mipMapped=GrMipmapped::kNo, GrProtected isProtected=GrProtected::kNo) |
Creates a GPU-backed SkImage from compressed data. More... | |
static sk_sp< SkImage > | MakeRasterFromCompressed (sk_sp< SkData > data, int width, int height, CompressionType type) |
Creates a CPU-backed SkImage from compressed data. More... | |
static sk_sp< SkImage > | MakeFromTexture (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr) |
Creates SkImage from GPU texture associated with context. More... | |
static sk_sp< SkImage > | MakeFromCompressedTexture (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr) |
Creates an SkImage from a GPU backend texture. More... | |
static sk_sp< SkImage > | MakeCrossContextFromPixmap (GrDirectContext *context, const SkPixmap &pixmap, bool buildMips, bool limitToMaxTextureSize=false) |
Creates SkImage from pixmap. More... | |
static sk_sp< SkImage > | MakeFromAdoptedTexture (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin textureOrigin, SkColorType colorType, SkAlphaType alphaType=kPremul_SkAlphaType, sk_sp< SkColorSpace > colorSpace=nullptr) |
Creates SkImage from backendTexture associated with context. More... | |
static sk_sp< SkImage > | MakeFromYUVATextures (GrRecordingContext *context, const GrYUVABackendTextures &yuvaTextures, sk_sp< SkColorSpace > imageColorSpace=nullptr, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr) |
Creates an SkImage from YUV[A] planar textures. More... | |
static sk_sp< SkImage > | MakeFromYUVAPixmaps (GrRecordingContext *context, const SkYUVAPixmaps &pixmaps, GrMipMapped buildMips=GrMipmapped::kNo, bool limitToMaxTextureSize=false, sk_sp< SkColorSpace > imageColorSpace=nullptr) |
Creates SkImage from SkYUVAPixmaps. More... | |
static sk_sp< SkImage > | MakeFromPicture (sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace) |
Creates SkImage from picture. More... | |
static sk_sp< SkImage > | MakePromiseTexture (sk_sp< GrContextThreadSafeProxy > gpuContextProxy, const GrBackendFormat &backendFormat, SkISize dimensions, GrMipmapped mipMapped, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, PromiseImageTextureFulfillProc textureFulfillProc, PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContext) |
Create a new SkImage that is very similar to an SkImage created by MakeFromTexture. More... | |
static sk_sp< SkImage > | MakePromiseYUVATexture (sk_sp< GrContextThreadSafeProxy > gpuContextProxy, const GrYUVABackendTextureInfo &backendTextureInfo, sk_sp< SkColorSpace > imageColorSpace, PromiseImageTextureFulfillProc textureFulfillProc, PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContexts[]) |
This entry point operates like 'MakePromiseTexture' but it is used to construct a SkImage from YUV[A] data. More... | |
static bool | MakeBackendTextureFromSkImage (GrDirectContext *context, sk_sp< SkImage > image, GrBackendTexture *backendTexture, BackendTextureReleaseProc *backendTextureReleaseProc) |
Creates a GrBackendTexture from the provided SkImage. More... | |
Static Public Attributes | |
static constexpr int | kCompressionTypeCount = static_cast<int>(CompressionType::kLast) + 1 |
static const CompressionType | kETC1_CompressionType = CompressionType::kETC2_RGB8_UNORM |
Friends | |
class | SkBitmap |
class | SkImage_Base |
class | SkMipmapBuilder |
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.
typedef std::function<void(GrBackendTexture)> SkImage::BackendTextureReleaseProc |
Defines a callback function, taking one parameter of type GrBackendTexture with no return value.
Function is called when back-end texture is to be released.
using SkImage::PromiseImageTextureContext = void* |
using SkImage::PromiseImageTextureFulfillProc = sk_sp<SkPromiseImageTexture> (*)(PromiseImageTextureContext) |
using SkImage::PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext) |
typedef void(* SkImage::RasterReleaseProc) (const void *pixels, ReleaseContext) |
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.
using SkImage::ReadPixelsContext = void* |
Client-provided context that is passed to client-provided ReadPixelsContext.
typedef void* SkImage::ReleaseContext |
Caller data passed to RasterReleaseProc; may be nullptr.
typedef void(* SkImage::TextureReleaseProc) (ReleaseContext releaseContext) |
User function called when supplied texture may be deleted.
|
strong |
enum SkImage::CachingHint |
|
strong |
|
strong |
|
strong |
SkAlphaType SkImage::alphaType | ( | ) | const |
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.
bitmap | storage for legacy SkBitmap |
legacyBitmapMode | bitmap is read-only and immutable |
void SkImage::asyncRescaleAndReadPixels | ( | const SkImageInfo & | info, |
const SkIRect & | srcRect, | ||
RescaleGamma | rescaleGamma, | ||
RescaleMode | rescaleMode, | ||
ReadPixelsCallback | callback, | ||
ReadPixelsContext | context | ||
) |
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.
info | info of the requested pixels |
srcRect | subrectangle of image to read |
rescaleGamma | controls whether rescaling is done in the image's gamma or whether the source data is transformed to a linear gamma before rescaling. |
rescaleMode | controls the technique (and cost) of the rescaling |
callback | function to call with result of the read |
context | passed to callback |
void SkImage::asyncRescaleAndReadPixelsYUV420 | ( | SkYUVColorSpace | yuvColorSpace, |
sk_sp< SkColorSpace > | dstColorSpace, | ||
const SkIRect & | srcRect, | ||
const SkISize & | dstSize, | ||
RescaleGamma | rescaleGamma, | ||
RescaleMode | rescaleMode, | ||
ReadPixelsCallback | callback, | ||
ReadPixelsContext | context | ||
) |
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.
yuvColorSpace | The transformation from RGB to YUV. Applied to the resized image after it is converted to dstColorSpace. |
dstColorSpace | The color space to convert the resized image to, after rescaling. |
srcRect | The portion of the image to rescale and convert to YUV planes. |
dstSize | The size to rescale srcRect to |
rescaleGamma | controls whether rescaling is done in the image's gamma or whether the source data is transformed to a linear gamma before rescaling. |
rescaleMode | controls the technique (and cost) of the rescaling |
callback | function to call with the planar read result |
context | passed to callback |
|
inline |
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.
SkColorType SkImage::colorType | ( | ) | const |
Returns SkColorType if known; otherwise, returns kUnknown_SkColorType.
|
inline |
Encodes SkImage pixels, returning result as SkData.
Returns existing encoded data if present; otherwise, SkImage is encoded with SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode SkImage.
Returns nullptr if existing encoded data is missing or invalid, and encoding fails.
sk_sp<SkData> SkImage::encodeToData | ( | SkEncodedImageFormat | encodedImageFormat, |
int | quality | ||
) | const |
Encodes SkImage pixels, returning result as SkData.
Returns nullptr if encoding fails, or if encodedImageFormat is not supported.
SkImage encoding in a format requires both building with one or more of: SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP; and platform support for the encoded format.
If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP, SkEncodedImageFormat::kGIF.
quality is a platform and format specific metric trading off size and encoding error. When used, quality equaling 100 encodes with the least error. quality may be ignored by the encoder.
encodedImageFormat | one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kWEBP |
quality | encoder specific metric with 100 equaling best |
|
inline |
GrSemaphoresSubmitted SkImage::flush | ( | GrDirectContext * | context, |
const GrFlushInfo & | flushInfo | ||
) |
Flushes any pending uses of texture-backed images in the GPU backend.
If the image is not texture-backed (including promise texture images) or if the GrDirectContext does not have the same context ID as the context backing the image then this is a no-op.
If the image was not used in any non-culled draws in the current queue of work for the passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or a finish proc. Those are respected even when the image has not been used.
context | the context on which to flush pending usages of the image. |
info | flush options |
void SkImage::flushAndSubmit | ( | GrDirectContext * | ) |
Version of flush() that uses a default GrFlushInfo.
Also submits the flushed work to the GPU.
GrBackendTexture SkImage::getBackendTexture | ( | bool | flushPendingGrContextIO, |
GrSurfaceOrigin * | origin = nullptr |
||
) | const |
Retrieves the back-end texture.
If SkImage has no back-end texture, an invalid object is returned. Call GrBackendTexture::isValid to determine if the result is valid.
If flushPendingGrContextIO is true, completes deferred I/O operations.
If origin in not nullptr, copies location of content drawn into SkImage.
flushPendingGrContextIO | flag to flush outstanding requests |
bool SkImage::hasMipmaps | ( | ) | const |
Returns true if the image has mipmap levels.
|
inline |
Returns pixel row count.
|
inline |
Returns a SkImageInfo describing the width, height, color type, alpha type, and color space of the SkImage.
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.
bool SkImage::isLazyGenerated | ( | ) | const |
Returns true if SkImage is backed by an image-generator or other service that creates and caches its pixels or texture on-demand.
example: https://fiddle.skia.org/c/@Image_isLazyGenerated_a example: https://fiddle.skia.org/c/@Image_isLazyGenerated_b
|
inline |
Returns true if pixels ignore their alpha value and are treated as fully opaque.
bool SkImage::isTextureBacked | ( | ) | const |
bool SkImage::isValid | ( | GrRecordingContext * | context | ) | const |
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.
context | GPU context |
|
static |
Creates a GrBackendTexture from the provided SkImage.
Returns true and stores result in backendTexture and backendTextureReleaseProc if texture is created; otherwise, returns false and leaves backendTexture and backendTextureReleaseProc unmodified.
Call backendTextureReleaseProc after deleting backendTexture. backendTextureReleaseProc cleans up auxiliary data related to returned backendTexture. The caller must delete returned backendTexture after use.
If SkImage is both texture backed and singly referenced, image is returned in backendTexture without conversion or making a copy. SkImage is singly referenced if its was transferred solely using std::move().
If SkImage is not texture backed, returns texture with SkImage contents.
context | GPU context |
image | SkImage used for texture |
backendTexture | storage for back-end texture |
backendTextureReleaseProc | storage for clean up function |
sk_sp<SkImage> SkImage::makeColorSpace | ( | sk_sp< SkColorSpace > | target, |
GrDirectContext * | direct = nullptr |
||
) | const |
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.
target | SkColorSpace describing color range of returned SkImage |
direct | The GrDirectContext in play, if it exists |
sk_sp<SkImage> SkImage::makeColorTypeAndColorSpace | ( | SkColorType | targetColorType, |
sk_sp< SkColorSpace > | targetColorSpace, | ||
GrDirectContext * | direct = nullptr |
||
) | const |
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.
targetColorType | SkColorType of returned SkImage |
targetColorSpace | SkColorSpace of returned SkImage |
direct | The GrDirectContext in play, if it exists |
|
static |
Creates SkImage from pixmap.
SkImage is uploaded to GPU back-end using context.
Created SkImage is available to other GPU contexts, and is available across thread boundaries. All contexts must be in the same GPU share group, or otherwise share resources.
When SkImage is no longer referenced, context releases texture memory asynchronously.
GrBackendTexture created from pixmap is uploaded to match SkSurface created with dstColorSpace. SkColorSpace of SkImage is determined by pixmap.colorSpace().
SkImage is returned referring to GPU back-end if context is not nullptr, format of data is recognized and supported, and if context supports moving resources between contexts. Otherwise, pixmap pixel data is copied and SkImage as returned in raster format if possible; nullptr may be returned. Recognized GPU formats vary by platform and GPU back-end.
context | GPU context |
pixmap | SkImageInfo, pixel address, and row bytes |
buildMips | create SkImage as mip map if true |
dstColorSpace | range of colors of matching SkSurface on GPU |
limitToMaxTextureSize | downscale image to GPU maximum texture size, if necessary |
|
static |
Creates SkImage from backendTexture associated with context.
backendTexture and returned SkImage are managed internally, and are released when no longer needed.
SkImage is returned if format of backendTexture is recognized and supported. Recognized formats vary by GPU back-end.
context | GPU context |
backendTexture | texture residing on GPU |
textureOrigin | origin of backendTexture |
colorType | color type of the resulting image |
alphaType | alpha type of the resulting image |
colorSpace | range of colors; may be nullptr |
Creates SkImage from bitmap, sharing or copying bitmap pixels.
If the bitmap is marked immutable, and its pixel memory is shareable, it may be shared instead of copied.
SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: dimensions are greater than zero; each dimension fits in 29 bits; SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; row bytes are large enough to hold one row of pixels; pixel address is not nullptr.
bitmap | SkImageInfo, row bytes, and pixels |
|
static |
Creates an SkImage from a GPU backend texture.
The backend texture must stay valid and unchanged until textureReleaseProc is called. The textureReleaseProc is called when the SkImage is deleted or no longer refers to the texture and will be passed the releaseContext.
An SkImage is returned if the format of backendTexture is recognized and supported. Recognized formats vary by GPU back-end.
context | the GPU context |
backendTexture | a texture already allocated by the GPU |
alphaType | This characterizes the nature of the alpha values in the backend texture. For opaque compressed formats (e.g., ETC1) this should usually be set to kOpaque_SkAlphaType. |
colorSpace | This describes the color space of this image's contents, as seen after sampling. In general, if the format of the backend texture is SRGB, some linear colorSpace should be supplied (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the backend texture is linear, then the colorSpace should include a description of the transfer function as well (e.g., SkColorSpace::MakeSRGB()). |
textureReleaseProc | function called when the backend texture can be released |
releaseContext | state passed to textureReleaseProc |
Return an image backed by the encoded data, but attempt to defer decoding until the image is actually used/drawn.
This deferral allows the system to cache the result, either on the CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may be purged, causing the next draw of the image to have to re-decode.
The subset parameter specifies a area within the decoded image to create the image from. If subset is null, then the entire image is returned.
This is similar to DecodeTo[Raster,Texture], but this method will attempt to defer the actual decode, while the DecodeTo... method explicitly decode and allocate the backend when the call is made.
If the encoded format is not supported, or subset is outside of the bounds of the decoded image, nullptr is returned.
encoded | the encoded data |
length | the number of bytes of encoded data |
|
static |
Creates SkImage from data returned by imageGenerator.
Generated data is owned by SkImage and may not be shared or accessed.
SkImage is returned if generator data is valid. Valid data parameters vary by type of data and platform.
imageGenerator may wrap SkPicture data, codec data, or custom data.
imageGenerator | stock or custom routines to retrieve SkImage |
|
static |
Creates SkImage from picture.
Returned SkImage width and height are set by dimensions. SkImage draws picture with matrix and paint, set to bitDepth and colorSpace.
If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws with default SkPaint. colorSpace may be nullptr.
picture | stream of drawing commands |
dimensions | width and height |
matrix | SkMatrix to rotate, scale, translate, and so on; may be nullptr |
paint | SkPaint to apply transparency, filtering, and so on; may be nullptr |
bitDepth | 8-bit integer or 16-bit float: per component |
colorSpace | range of colors; may be nullptr |
|
static |
Creates SkImage from pixmap, sharing SkPixmap pixels.
Pixels must remain valid and unchanged until rasterReleaseProc is called. rasterReleaseProc is passed releaseContext when SkImage is deleted or no longer refers to pixmap pixels.
Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc does not require state.
SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: dimensions are greater than zero; each dimension fits in 29 bits; SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; row bytes are large enough to hold one row of pixels; pixel address is not nullptr.
pixmap | SkImageInfo, pixel address, and row bytes |
rasterReleaseProc | function called when pixels can be released; or nullptr |
releaseContext | state passed to rasterReleaseProc; or nullptr |
|
static |
Creates SkImage from GPU texture associated with context.
GPU texture must stay valid and unchanged until textureReleaseProc is called. textureReleaseProc is passed releaseContext when SkImage is deleted or no longer refers to texture.
SkImage is returned if format of backendTexture is recognized and supported. Recognized formats vary by GPU back-end.
context | GPU context |
backendTexture | texture residing on GPU |
colorSpace | This describes the color space of this image's contents, as seen after sampling. In general, if the format of the backend texture is SRGB, some linear colorSpace should be supplied (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the backend texture is linear, then the colorSpace should include a description of the transfer function as well (e.g., SkColorSpace::MakeSRGB()). |
textureReleaseProc | function called when texture can be released |
releaseContext | state passed to textureReleaseProc |
|
static |
Creates SkImage from SkYUVAPixmaps.
The image will remain planar with each plane converted to a texture using the passed GrRecordingContext.
SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will be the SkColorSpace reported by the image and when drawn the RGB values will be converted from this space into the destination space (if the destination is tagged).
Currently, this is only supported using the GPU backend and will fail if context is nullptr.
SkYUVAPixmaps does not need to remain valid after this returns.
context | GPU context |
pixmaps | The planes as pixmaps with supported SkYUVAInfo that specifies conversion to RGB. |
buildMips | create internal YUVA textures as mip map if kYes. This is silently ignored if the context does not support mip maps. |
limitToMaxTextureSize | downscale image to GPU maximum texture size, if necessary |
imageColorSpace | range of colors of the resulting image; may be nullptr |
|
static |
Creates an SkImage from YUV[A] planar textures.
This requires that the textures stay valid for the lifetime of the image. The ReleaseContext can be used to know when it is safe to either delete or overwrite the textures. If ReleaseProc is provided it is also called before return on failure.
context | GPU context |
yuvaTextures | A set of textures containing YUVA data and a description of the data and transformation to RGBA. |
imageColorSpace | range of colors of the resulting image after conversion to RGB; may be nullptr |
textureReleaseProc | called when the backend textures can be released |
releaseContext | state passed to textureReleaseProc |
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.
example: https://fiddle.skia.org/c/@Image_makeNonTextureImage
|
static |
Create a new SkImage that is very similar to an SkImage created by MakeFromTexture.
The difference is that the caller need not have created the texture nor populated it with the image pixel data. Moreover, the SkImage may be created on a thread as the creation of the image does not require access to the backend API or GrDirectContext. Instead of passing a GrBackendTexture the client supplies a description of the texture consisting of GrBackendFormat, width, height, and GrMipmapped state. The resulting SkImage can be drawn to a SkDeferredDisplayListRecorder or directly to a GPU-backed SkSurface.
When the actual texture is required to perform a backend API draw, textureFulfillProc will be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match those set during the SkImage creation, and it must refer to a valid existing texture in the backend API context/device, and be populated with the image pixel data. The texture cannot be deleted until textureReleaseProc is called.
There is at most one call to each of textureFulfillProc and textureReleaseProc. textureReleaseProc is always called even if image creation fails or if the image is never fulfilled (e.g. it is never drawn or all draws are clipped out)
gpuContextProxy | the thread-safe proxy of the gpu context. required. |
backendFormat | format of promised gpu texture |
dimensions | width & height of promised gpu texture |
mipMapped | mip mapped state of promised gpu texture |
origin | surface origin of promised gpu texture |
colorType | color type of promised gpu texture |
alphaType | alpha type of promised gpu texture |
colorSpace | range of colors; may be nullptr |
textureFulfillProc | function called to get actual gpu texture |
textureReleaseProc | function called when texture can be deleted |
textureContext | state passed to textureFulfillProc and textureReleaseProc |
|
static |
This entry point operates like 'MakePromiseTexture' but it is used to construct a SkImage from YUV[A] data.
The source data may be planar (i.e. spread across multiple textures). In the extreme Y, U, V, and A are all in different planes and thus the image is specified by four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and 'textureReleaseProc' calls are made for each texture. Each texture has its own PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one entry for each of the up to four textures, as indicated by 'backendTextureInfo'.
Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the near future it will be required that if it is kYes then textureFulfillProc must return a mip mapped texture for each plane in order to successfully draw the image.
gpuContextProxy | the thread-safe proxy of the gpu context. required. |
backendTextureInfo | info about the promised yuva gpu texture |
imageColorSpace | range of colors; may be nullptr |
textureFulfillProc | function called to get actual gpu texture |
textureReleaseProc | function called when texture can be deleted |
textureContexts | state passed to textureFulfillProc and textureReleaseProc |
Creates SkImage from SkPixmap and copy of pixels.
Since pixels are copied, SkPixmap pixels may be modified or deleted without affecting SkImage.
SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: dimensions are greater than zero; each dimension fits in 29 bits; SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; row bytes are large enough to hold one row of pixels; pixel address is not nullptr.
pixmap | SkImageInfo, pixel address, and row bytes |
|
static |
Creates SkImage from SkImageInfo, sharing pixels.
SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: dimensions are greater than zero; each dimension fits in 29 bits; SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; rowBytes are large enough to hold one row of pixels; pixels is not nullptr, and contains enough data for SkImage.
info | contains width, height, SkAlphaType, SkColorType, SkColorSpace |
pixels | address or pixel storage |
rowBytes | size of pixel row or larger |
|
static |
Creates a CPU-backed SkImage from compressed data.
This method will decompress the compressed data and create an image wrapping it. Any mipmap levels present in the compressed data are discarded.
data | compressed data to store in SkImage |
width | width of full SkImage |
height | height of full SkImage |
type | type of compression used |
sk_sp<SkImage> SkImage::makeRasterImage | ( | 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.
|
inline |
|
inline |
sk_sp<SkShader> SkImage::makeShader | ( | SkTileMode | tmx, |
SkTileMode | tmy, | ||
const SkSamplingOptions & | , | ||
const SkMatrix * | localMatrix = nullptr |
||
) | const |
Make a shader with the specified tiling and mipmap sampling.
|
inline |
sk_sp<SkImage> SkImage::makeSubset | ( | const SkIRect & | subset, |
GrDirectContext * | direct = nullptr |
||
) | const |
Returns subset of this image.
Returns nullptr if any of the following are true:
If this image is texture-backed, the context parameter is required and must match the context of the source image. If the context parameter is provided, and the image is raster-backed, the subset will be converted to texture-backed.
subset | bounds of returned SkImage |
context | the GrDirectContext in play, if it exists |
|
static |
Creates a GPU-backed SkImage from compressed data.
This method will return an SkImage representing the compressed data. If the GPU doesn't support the specified compression method, the data will be decompressed and then wrapped in a GPU-backed image.
Note: one can query the supported compression formats via GrRecordingContext::compressedBackendFormat.
context | GPU context |
data | compressed data to store in SkImage |
width | width of full SkImage |
height | height of full SkImage |
type | type of compression used |
mipMapped | does 'data' contain data for all the mipmap levels? |
isProtected | do the contents of 'data' require DRM protection (on Vulkan)? |
sk_sp<SkImage> SkImage::makeTextureImage | ( | GrDirectContext * | , |
GrMipmapped | = GrMipmapped::kNo , |
||
SkBudgeted | = SkBudgeted::kYes |
||
) | const |
Returns SkImage backed by GPU texture associated with context.
Returned SkImage is compatible with SkSurface created with dstColorSpace. The returned SkImage respects mipMapped setting; if mipMapped equals GrMipmapped::kYes, the backing texture allocates mip map levels.
The mipMapped parameter is effectively treated as kNo if MIP maps are not supported by the GPU.
Returns original SkImage if the image is already texture-backed, the context matches, and mipMapped is compatible with the backing GPU texture. SkBudgeted is ignored in this case.
Returns nullptr if context is nullptr, or if SkImage was created with another GrDirectContext.
GrDirectContext | the GrDirectContext in play, if it exists |
GrMipmapped | whether created SkImage texture must allocate mip map levels |
SkBudgeted | whether to count a newly created texture for the returned image counts against the context's budget. |
sk_sp<SkImage> SkImage::makeWithFilter | ( | GrRecordingContext * | context, |
const SkImageFilter * | filter, | ||
const SkIRect & | subset, | ||
const SkIRect & | clipBounds, | ||
SkIRect * | outSubset, | ||
SkIPoint * | offset | ||
) | const |
Creates filtered SkImage.
filter processes original SkImage, potentially changing color, position, and size. subset is the bounds of original SkImage processed by filter. clipBounds is the expected bounds of the filtered SkImage. outSubset is required storage for the actual bounds of the filtered SkImage. offset is required storage for translation of returned SkImage.
Returns nullptr if SkImage could not be created or if the recording context provided doesn't match the GPU context in which the image was created. If nullptr is returned, outSubset and offset are undefined.
Useful for animation of SkImageFilter that varies size from frame to frame. Returned SkImage is created larger than required by filter so that GPU texture can be reused with different sized effects. outSubset describes the valid bounds of GPU texture returned. offset translates the returned SkImage to keep subsequent animation frames aligned with respect to each other.
context | the GrRecordingContext in play - if it exists |
filter | how SkImage is sampled when transformed |
subset | bounds of SkImage processed by filter |
clipBounds | expected bounds of filtered SkImage |
outSubset | storage for returned SkImage bounds |
offset | storage for returned SkImage translation |
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.
pixmap | storage for pixel state if pixels are readable; otherwise, ignored |
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.
bool SkImage::readPixels | ( | const SkPixmap & | dst, |
int | srcX, | ||
int | srcY, | ||
CachingHint | cachingHint = kAllow_CachingHint |
||
) | const |
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:
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.
context | the GrDirectContext in play, if it exists |
dstInfo | destination width, height, SkColorType, SkAlphaType, SkColorSpace |
dstPixels | destination pixel storage |
dstRowBytes | destination row length |
srcX | column index whose absolute value is less than width() |
srcY | row index whose absolute value is less than height() |
cachingHint | whether the pixels should be cached locally |
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.
context | the GrDirectContext in play, if it exists |
dst | destination SkPixmap: SkImageInfo, pixels, row bytes |
srcX | column index whose absolute value is less than width() |
srcY | row index whose absolute value is less than height() |
cachingHint | whether the pixels should be cached locallyZ |
|
inlineinherited |
Increment the reference count.
Must be balanced by a call to unref().
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 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.
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.
bool SkImage::scalePixels | ( | const SkPixmap & | dst, |
const SkSamplingOptions & | , | ||
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.
dst | destination SkPixmap: SkImageInfo, pixels, row bytes |
size_t SkImage::textureSize | ( | ) | const |
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.
|
inlineinherited |
May return true if the caller is the only owner.
Ensures that all previous owner's actions are complete.
|
inline |
|
inlineinherited |
Decrement the reference count.
If the reference count is 1 before the decrement, then delete the object. Note that if this is the case, then the object needs to have been allocated via new, and not on the stack.
|
inline |
Returns pixel count in each row.
Returns an image with the same "base" pixels as the this image, but with mipmap levels automatically generated and attached.
|
friend |
|
friend |
|
friend |
|
staticconstexpr |
|
static |