Community Issues Reference Playground

SkImage Reference


class SkImage : public SkRefCnt {

    typedef void* ReleaseContext;

    static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap);
    static sk_sp<SkImage> MakeRasterData(const SkImageInfo& info, sk_sp<SkData> pixels,
                                         size_t rowBytes);

    typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext);

    static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap,
                                         RasterReleaseProc rasterReleaseProc,
                                         ReleaseContext releaseContext);
    static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap);
    static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator,
                                            const SkIRect* subset = nullptr);
    static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr);

    typedef void (*TextureReleaseProc)(ReleaseContext releaseContext);

    static sk_sp<SkImage> MakeFromTexture(GrContext* context,
                                          const GrBackendTexture& backendTexture,
                                          GrSurfaceOrigin origin,
                                          SkColorType colorType,
                                          SkAlphaType alphaType,
                                          sk_sp<SkColorSpace> colorSpace);
    static sk_sp<SkImage> MakeFromTexture(GrContext* context,
                                          const GrBackendTexture& backendTexture,
                                          GrSurfaceOrigin origin,
                                          SkColorType colorType,
                                          SkAlphaType alphaType,
                                          sk_sp<SkColorSpace> colorSpace,
                                          TextureReleaseProc textureReleaseProc,
                                          ReleaseContext releaseContext);
    static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
                                                      bool buildMips, SkColorSpace* dstColorSpace,
                                                      bool limitToMaxTextureSize = false);
    static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
                                                     bool buildMips, SkColorSpace* dstColorSpace,
                                                     bool limitToMaxTextureSize = false);
    static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
                                                 const GrBackendTexture& backendTexture,
                                                 GrSurfaceOrigin surfaceOrigin,
                                                 SkColorType colorType,
                                                 SkAlphaType alphaType = kPremul_SkAlphaType,
                                                 sk_sp<SkColorSpace> colorSpace = nullptr);
    static sk_sp<SkImage> MakeFromYUVATexturesCopy(GrContext* context,
                                                   SkYUVColorSpace yuvColorSpace,
                                                   const GrBackendTexture yuvaTextures[],
                                                   const SkYUVAIndex yuvaIndices[4],
                                                   SkISize imageSize,
                                                   GrSurfaceOrigin imageOrigin,
                                                   sk_sp<SkColorSpace> imageColorSpace = nullptr);
    static sk_sp<SkImage> MakeFromYUVATexturesCopyWithExternalBackend(
            GrContext* context,
            SkYUVColorSpace yuvColorSpace,
            const GrBackendTexture yuvaTextures[],
            const SkYUVAIndex yuvaIndices[4],
            SkISize imageSize,
            GrSurfaceOrigin imageOrigin,
            const GrBackendTexture& backendTexture,
            sk_sp<SkColorSpace> imageColorSpace = nullptr);
    static sk_sp<SkImage> MakeFromYUVATextures(GrContext* context,
                                               SkYUVColorSpace yuvColorSpace,
                                               const GrBackendTexture yuvaTextures[],
                                               const SkYUVAIndex yuvaIndices[4],
                                               SkISize imageSize,
                                               GrSurfaceOrigin imageOrigin,
                                               sk_sp<SkColorSpace> imageColorSpace = nullptr);
    static sk_sp<SkImage> MakeFromYUVAPixmaps(
            GrContext* context, SkYUVColorSpace yuvColorSpace, const SkPixmap yuvaPixmaps[],
            const SkYUVAIndex yuvaIndices[4], SkISize imageSize, GrSurfaceOrigin imageOrigin,
            bool buildMips, bool limitToMaxTextureSize = false,
            sk_sp<SkColorSpace> imageColorSpace = nullptr);
    static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
                                                  const GrBackendTexture yuvTextures[3],
                                                  GrSurfaceOrigin imageOrigin,
                                                  sk_sp<SkColorSpace> imageColorSpace = nullptr);
    static sk_sp<SkImage> MakeFromYUVTexturesCopyWithExternalBackend(
            GrContext* context, SkYUVColorSpace yuvColorSpace,
            const GrBackendTexture yuvTextures[3], GrSurfaceOrigin imageOrigin,
            const GrBackendTexture& backendTexture, sk_sp<SkColorSpace> imageColorSpace = nullptr);
    static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context,
                                                   SkYUVColorSpace yuvColorSpace,
                                                   const GrBackendTexture nv12Textures[2],
                                                   GrSurfaceOrigin imageOrigin,
                                                   sk_sp<SkColorSpace> imageColorSpace = nullptr);
    static sk_sp<SkImage> MakeFromNV12TexturesCopyWithExternalBackend(
            GrContext* context,
            SkYUVColorSpace yuvColorSpace,
            const GrBackendTexture nv12Textures[2],
            GrSurfaceOrigin imageOrigin,
            const GrBackendTexture& backendTexture,
            sk_sp<SkColorSpace> imageColorSpace = nullptr);

    enum class BitDepth {
        kU8,
        kF16,
    };

    static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
                                          const SkMatrix* matrix, const SkPaint* paint,
                                          BitDepth bitDepth,
                                          sk_sp<SkColorSpace> colorSpace);
    static sk_sp<SkImage> MakeFromAHardwareBuffer(
            AHardwareBuffer* hardwareBuffer,
            SkAlphaType alphaType = kPremul_SkAlphaType,
            sk_sp<SkColorSpace> colorSpace = nullptr,
            GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);
    int width() const;
    int height() const;
    SkISize dimensions() const;
    SkIRect bounds() const;
    uint32_t uniqueID() const;
    SkAlphaType alphaType() const;
    SkColorType colorType() const;
    SkColorSpace* colorSpace() const;
    sk_sp<SkColorSpace> refColorSpace() const;
    bool isAlphaOnly() const;
    bool isOpaque() const;
    sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2,
                               const SkMatrix* localMatrix = nullptr) const;
    sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const;
    bool peekPixels(SkPixmap* pixmap) const;
    bool isTextureBacked() const;
    bool isValid(GrContext* context) const;
    GrBackendTexture getBackendTexture(bool flushPendingGrContextIO,
                                       GrSurfaceOrigin* origin = nullptr) const;

    enum CachingHint {
        kAllow_CachingHint,
        kDisallow_CachingHint,
    };

    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;
    bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
                     CachingHint cachingHint = kAllow_CachingHint) const;
    sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const;
    sk_sp<SkData> encodeToData() const;
    sk_sp<SkData> refEncodedData() const;
    sk_sp<SkImage> makeSubset(const SkIRect& subset) const;
    sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace,
                                    GrMipMapped mipMapped = GrMipMapped::kNo) const;
    sk_sp<SkImage> makeNonTextureImage() const;
    sk_sp<SkImage> makeRasterImage() const;
    sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
                                  const SkIRect& clipBounds, SkIRect* outSubset,
                                  SkIPoint* offset) const;

    typedef std::functionGrBackendTexture)> BackendTextureReleaseProc;

    static bool MakeBackendTextureFromSkImage(GrContext* context,
                                              sk_sp<SkImage> image,
                                              GrBackendTexture* backendTexture,
                                              BackendTextureReleaseProc* backendTextureReleaseProc);
    bool isLazyGenerated() const;
    sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target) const;
};

Image describes a two dimensional array of pixels to draw. The pixels may be decoded in a Raster_Bitmap, encoded in a Picture or compressed data stream, or located in GPU memory as a GPU_Texture.

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

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

Image may be created from Bitmap, Pixmap, Surface, Picture, 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.

Raster_Image pixels are decoded in a Raster_Bitmap. These pixels may be read directly and in most cases written to, although edited pixels may not be drawn if Image has been copied internally.

Texture_Image are located on GPU and pixels are not accessible. Texture_Image are allocated optimally for best performance. Raster_Image may be drawn to GPU_Surface, but pixels are uploaded from CPU to GPU downgrading performance.

Lazy_Image defer allocating buffer for Image pixels and decoding stream until Image is drawn. Lazy_Image caches result if possible to speed up repeated drawing.


static sk_sp<SkImage> MakeRasterCopy(const SkPixmap& pixmap)

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.

Parameters

pixmap SkImageInfo, pixel address, and row bytes

Return Value

copy of SkPixmap pixels, or nullptr

Example

Draw a five by five bitmap, and draw a copy in an Image. Editing the pixmap alters the bitmap draw, but does not alter the Image draw since the Image contains a copy of the pixels.

See Also

MakeRasterData MakeFromGenerator


static sk_sp<SkImage> MakeRasterData(const SkImageInfo& info, sk_sp<SkData> pixels, size_t rowBytes)

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.

Parameters

info contains width, height, SkAlphaType, SkColorType, SkColorSpace
pixels address or pixel storage
rowBytes size of pixel row or larger

Return Value

SkImage sharing pixels, or nullptr

Example

See Also

MakeRasterCopy MakeFromGenerator


    typedef void* ReleaseContext;

Caller data passed to RasterReleaseProc; may be nullptr.

See Also

MakeFromRaster RasterReleaseProc


    typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext);

Function called when Image no longer shares pixels. ReleaseContext is provided by caller when Image is created, and may be nullptr.

See Also

ReleaseContext MakeFromRaster


static sk_sp<SkImage> MakeFromRaster(const SkPixmap& pixmap, RasterReleaseProc rasterReleaseProc,
                                     ReleaseContext releaseContext)

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.

Parameters

pixmap SkImageInfo, pixel address, and row bytes
rasterReleaseProc function called when pixels can be released; or nullptr
releaseContext state passed to rasterReleaseProc; or nullptr

Return Value

SkImage sharing pixmap

Example

#### Example Output ~~~~ before reset: 0 after reset: 1 ~~~~

See Also

MakeRasterCopy MakeRasterData MakeFromGenerator RasterReleaseProc ReleaseContext


static sk_sp<SkImage> MakeFromBitmap(const SkBitmap& bitmap)

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.

Parameters

bitmap SkImageInfo, row bytes, and pixels

Return Value

created SkImage, or nullptr

Example

The first Bitmap is shared; writing to the pixel memory changes the first Image. The second Bitmap is marked immutable, and is copied; writing to the pixel memory does not alter the second Image.

See Also

MakeFromRaster MakeRasterCopy MakeFromGenerator MakeRasterData


static sk_sp<SkImage> MakeFromGenerator(std::unique_ptr<SkImageGenerator> imageGenerator,
                                 const SkIRect* subset = nullptr)

Creates SkImage from data returned by imageGenerator. Generated data is owned by SkImage and may not be shared or accessed.

subset allows selecting a portion of the full image. Pass nullptr to select the entire image; otherwise, subset must be contained by image bounds.

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.

Parameters

imageGenerator stock or custom routines to retrieve SkImage
subset bounds of returned SkImage; may be nullptr

Return Value

created SkImage, or nullptr

Example

The generator returning Picture cannot be shared; std::move transfers ownership to generated Image.

See Also

MakeFromEncoded


static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = nullptr)

Creates SkImage from encoded data. subset allows selecting a portion of the full image. Pass nullptr to select the entire image; otherwise, subset must be contained by image bounds.

SkImage is returned if format of the encoded data is recognized and supported. Recognized formats vary by platform.

Parameters

encoded data of SkImage to decode
subset bounds of returned SkImage; may be nullptr

Return Value

created SkImage, or nullptr

Example

See Also

MakeFromGenerator


    typedef void (*TextureReleaseProc)(ReleaseContext releaseContext);

User function called when supplied texture may be deleted.

See Also

MakeFromTexture


static sk_sp<SkImage> MakeFromTexture(GrContext* context, const GrBackendTexture& backendTexture,
                                      GrSurfaceOrigin origin, SkColorType colorType,
                                      SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace)

Creates SkImage from GPU texture associated with context. Caller is responsible for managing the lifetime of GPU texture.

SkImage is returned if format of backendTexture is recognized and supported. Recognized formats vary by GPU back-end.

Parameters

context GPU context
backendTexture texture residing on GPU
origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
colorType one of:

kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType

Parameters

alphaType one of:

kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType

Parameters

colorSpace range of colors; may be nullptr

Return Value

created SkImage, or nullptr

Example

A back-end texture has been created and uploaded to the GPU outside of this example.

See Also

MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture


static sk_sp<SkImage> MakeFromTexture(GrContext* context, const GrBackendTexture& backendTexture,
                                      GrSurfaceOrigin origin, SkColorType colorType,
                                      SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace,
                                      TextureReleaseProc textureReleaseProc,
                                      ReleaseContext releaseContext)

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.

Parameters

context GPU context
backendTexture texture residing on GPU
origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
colorType one of:

kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType

Parameters

alphaType one of:

kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType

Parameters

colorSpace range of colors; may be nullptr
textureReleaseProc function called when texture can be released
releaseContext state passed to textureReleaseProc

Return Value

created SkImage, or nullptr

Example

textureReleaseProc may be called at some later point in time. In this example, textureReleaseProc has no effect on the drawing.

See Also

MakeFromAdoptedTexture SkSurface::MakeFromBackendTexture


static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
                                                  bool buildMips, SkColorSpace* dstColorSpace,
                                                  bool limitToMaxTextureSize = false)

Creates SkImage from encoded data. 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 decoded from data is uploaded to match SkSurface created with dstColorSpace. SkColorSpace of SkImage is determined by encoded data.

SkImage is returned if format of data is recognized and supported, and if context supports moving resources. Recognized formats vary by platform and GPU back-end.

SkImage is returned using MakeFromEncoded() if context is nullptr or does not support moving resources between contexts.

Parameters

context GPU context
data SkImage to decode
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

Return Value

created SkImage, or nullptr

Example

See Also

MakeCrossContextFromPixmap


static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
                                                 bool buildMips, SkColorSpace* dstColorSpace,
                                                 bool limitToMaxTextureSize = false)

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.

Parameters

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

Return Value

created SkImage, or nullptr

Example

See Also

MakeCrossContextFromEncoded


static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext* context,
                                             const GrBackendTexture& backendTexture,
                                             GrSurfaceOrigin surfaceOrigin, SkColorType colorType,
                                             SkAlphaType alphaType = kPremul_SkAlphaType,
                                             sk_sp<SkColorSpace> colorSpace = nullptr)

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.

Parameters

context GPU context
backendTexture texture residing on GPU
surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
colorType one of:

kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType

Parameters

alphaType one of:

kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType

Parameters

colorSpace range of colors; may be nullptr

Return Value

created SkImage, or nullptr

Example

See Also

MakeFromTexture MakeFromYUVTexturesCopy


static sk_sp<SkImage> MakeFromYUVATexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
                                               const GrBackendTexture yuvaTextures[],
                                               const SkYUVAIndex yuvaIndices[4], SkISize imageSize,
                                               GrSurfaceOrigin imageOrigin,
                                               sk_sp<SkColorSpace> imageColorSpace = nullptr)

Creates an SkImage by flattening the specified YUVA planes into a single, interleaved RGBA image.

Parameters

context GPU context
yuvColorSpace How the YUV values are converted to RGB. One of:

kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace

Parameters

yuvaTextures array of (up to four) YUVA textures on GPU which contain the,

possibly interleaved, YUVA planes

Parameters

yuvaIndices array indicating which texture in yuvaTextures, and channel

in that texture, maps to each component of YUVA.

Parameters

imageSize size of the resulting image
imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin,

kTopLeft_GrSurfaceOrigin

Parameters

imageColorSpace range of colors of the resulting image; may be nullptr

Return Value

created SkImage, or nullptr

See Also

MakeFromYUVATexturesCopyWithExternalBackend MakeFromYUVATextures


static sk_sp<SkImage> MakeFromYUVATextures(GrContext* context, SkYUVColorSpace yuvColorSpace,
                                           const GrBackendTexture yuvaTextures[],
                                           const SkYUVAIndex yuvaIndices[4], SkISize imageSize,
                                           GrSurfaceOrigin imageOrigin,
                                           sk_sp<SkColorSpace> imageColorSpace = nullptr) ;

Creates an SkImage by storing the specified YUVA planes into an image, to be rendered via multitexturing.

Parameters

context GPU context
yuvColorSpace How the YUV values are converted to RGB. One of:

kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace

Parameters

yuvaTextures array of (up to four) YUVA textures on GPU which contain the,

possibly interleaved, YUVA planes

Parameters

yuvaIndices array indicating which texture in yuvaTextures, and channel

in that texture, maps to each component of YUVA.

Parameters

imageSize size of the resulting image
imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin,

kTopLeft_GrSurfaceOrigin

Parameters

imageColorSpace range of colors of the resulting image; may be nullptr

Return Value

created SkImage, or nullptr

See Also

MakeFromYUVATexturesCopy MakeFromYUVATexturesCopyWithExternalBackend


static sk_sp<SkImage> 
             MakeFromYUVAPixmaps(
                                               GrContext* context,
             SkYUVColorSpace yuvColorSpace, const SkPixmap yuvaPixmaps[],
             const SkYUVAIndex yuvaIndices[4], SkISize imageSize, GrSurfaceOrigin imageOrigin,
             bool buildMips, bool limitToMaxTextureSize = false,
             sk_sp<SkColorSpace> imageColorSpace = nullptr) ;

Creates SkImage from pixmap array representing YUVA data. SkImage is uploaded to GPU back-end using context.

Each GrBackendTexture created from yuvaPixmaps array is uploaded to match SkSurface using SkColorSpace of SkPixmap. SkColorSpace of SkImage is determined by imageColorSpace.

SkImage is returned referring to GPU back-end if context is not nullptr and format of data is recognized and supported. Otherwise, nullptr is returned. Recognized GPU formats vary by platform and GPU back-end.

Parameters

context GPU context
yuvColorSpace How the YUV values are converted to RGB. One of:

kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace

Parameters

yuvaPixmaps array of (up to four) SkPixmap which contain the,

possibly interleaved, YUVA planes

Parameters

yuvaIndices array indicating which pixmap in yuvaPixmaps, and channel

in that pixmap, maps to each component of YUVA.

Parameters

imageSize size of the resulting image
imageOrigin origin of the resulting image. One of:

kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin

Parameters

buildMips create internal YUVA textures as mip map if true
limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary
imageColorSpace range of colors of the resulting image; may be nullptr

Return Value

created SkImage, or nullptr

See Also

MakeFromYUVATextures


static sk_sp<SkImage> MakeFromYUVATexturesCopyWithExternalBackend(
            GrContext* context,
                        SkYUVColorSpace yuvColorSpace, const GrBackendTexture yuvaTextures[],
                        const SkYUVAIndex yuvaIndices[4], SkISize imageSize,
                        GrSurfaceOrigin imageOrigin, const GrBackendTexture& backendTexture,
                        sk_sp<SkColorSpace> imageColorSpace = nullptr)

Creates an SkImage by flattening the specified YUVA planes into a single, interleaved RGBA image. ‘backendTexture’ is used to store the result of the flattening.

Parameters

context GPU context
yuvColorSpace How the YUV values are converted to RGB. One of:

kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace, kRec709_SkYUVColorSpace

Parameters

yuvaTextures array of (up to four) YUVA textures on GPU which contain the,

possibly interleaved, YUVA planes

Parameters

yuvaIndices array indicating which texture in yuvaTextures, and channel

in that texture, maps to each component of YUVA.

Parameters

imageSize size of the resulting image
imageOrigin origin of the resulting image. One of: kBottomLeft_GrSurfaceOrigin,

kTopLeft_GrSurfaceOrigin

Parameters

backendTexture the resource that stores the final pixels
imageColorSpace range of colors of the resulting image; may be nullptr

Return Value

created SkImage, or nullptr

See Also

MakeFromYUVATexturesCopy MakeFromYUVATextures


static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
                                              const GrBackendTexture yuvTextures[3],
                                              GrSurfaceOrigin imageOrigin,
                                              sk_sp<SkColorSpace> imageColorSpace = nullptr)

To be deprecated.

See Also

MakeFromYUVTexturesCopyWithExternalBackend MakeFromNV12TexturesCopy MakeFromYUVATexturesCopy


static sk_sp<SkImage> MakeFromYUVTexturesCopyWithExternalBackend(
        GrContext* context,
                             SkYUVColorSpace yuvColorSpace, const GrBackendTexture yuvTextures[3],
                             GrSurfaceOrigin imageOrigin, const GrBackendTexture& backendTexture,
                             sk_sp<SkColorSpace> imageColorSpace = nullptr) ;

To be deprecated.

See Also

MakeFromYUVTexturesCopy MakeFromNV12TexturesCopy MakeFromYUVATexturesCopyWithExternalBackend


static sk_sp<SkImage> MakeFromNV12TexturesCopy(GrContext* context, SkYUVColorSpace yuvColorSpace,
                                               const GrBackendTexture nv12Textures[2],
                                               GrSurfaceOrigin imageOrigin,
                                               sk_sp<SkColorSpace> imageColorSpace = nullptr)

Creates SkImage from copy of nv12Textures, an array of textures on GPU. nv12Textures[0] contains pixels for YUV component y plane. nv12Textures[1] contains pixels for YUV component u plane, followed by pixels for YUV component v plane. Returned SkImage has the dimensions nv12Textures[2]. yuvColorSpace describes how YUV colors convert to RGB colors.

Parameters

context GPU context
yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,

kRec709_SkYUVColorSpace

Parameters

nv12Textures array of YUV textures on GPU
imageOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
imageColorSpace range of colors; may be nullptr

Return Value

created SkImage, or nullptr

See Also

MakeFromNV12TexturesCopyWithExternalBackend MakeFromYUVTexturesCopy MakeFromYUVATexturesCopy


static sk_sp<SkImage> MakeFromNV12TexturesCopyWithExternalBackend(
            GrContext* context,
                        SkYUVColorSpace yuvColorSpace, const GrBackendTexture nv12Textures[2],
                        GrSurfaceOrigin imageOrigin, const GrBackendTexture& backendTexture,
                        sk_sp<SkColorSpace> imageColorSpace = nullptr) ;

Creates SkImage from copy of nv12Textures, an array of textures on GPU. nv12Textures[0] contains pixels for YUV component y plane. nv12Textures[1] contains pixels for YUV component u plane, followed by pixels for YUV component v plane. Returned SkImage has the dimensions nv12Textures[2] and stores pixels in backendTexture. yuvColorSpace describes how YUV colors convert to RGB colors.

Parameters

context GPU context
yuvColorSpace one of: kJPEG_SkYUVColorSpace, kRec601_SkYUVColorSpace,

kRec709_SkYUVColorSpace

Parameters

nv12Textures array of YUV textures on GPU
imageOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin
backendTexture the resource that stores the final pixels
imageColorSpace range of colors; may be nullptr

Return Value

created SkImage, or nullptr

See Also

MakeFromNV12TexturesCopy MakeFromYUVTexturesCopy MakeFromYUVATexturesCopyWithExternalBackend


    enum class BitDepth {
        kU8,
        kF16,
    };

Constants

Const Value Description
SkImage::BitDepth::kU8 0 Use 8 bits per ARGB component using unsigned integer format.
SkImage::BitDepth::kF16 1 Use 16 bits per ARGB component using half-precision floating point format.

See Also

MakeFromPicture


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. 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.

Parameters

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

Return Value

created SkImage, or nullptr

Example

See Also

SkCanvas::drawPicture


static sk_sp<SkImage> MakeFromAHardwareBuffer(
        AHardwareBuffer* hardwareBuffer,
                                   SkAlphaType alphaType = kPremul_SkAlphaType,
                                   sk_sp<SkColorSpace> colorSpace = nullptr,
                                   GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin)

(See Skia bug 7447) Creates SkImage from Android hardware buffer. Returned SkImage takes a reference on the buffer.

Only available on Android, when ANDROID_API is defined to be 26 or greater.

Parameters

hardwareBuffer AHardwareBuffer Android hardware buffer
alphaType one of:

kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType

Parameters

colorSpace range of colors; may be nullptr
surfaceOrigin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin

Return Value

created SkImage, or nullptr

See Also

MakeFromRaster


int width()const

Returns pixel count in each row.

Return Value

pixel width in SkImage

Example

See Also

dimensions() height()


int height()const

Returns pixel row count.

Return Value

pixel height in SkImage

Example

See Also

dimensions() width()


SkISize dimensions()const

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

Return Value

integral size of width() and height()

Example

#### Example Output ~~~~ dimensionsAsBounds == bounds ~~~~

See Also

height() width() bounds()


SkIRect bounds()const

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

Return Value

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

Example

See Also

dimensions()


uint32_t uniqueID()const

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.

Return Value

unique identifier

Example

See Also

isLazyGenerated


SkAlphaType alphaType()const

Returns Alpha_Type, one of: kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType .

Alpha_Type returned was a parameter to an Image constructor, or was parsed from encoded data.

Return Value

Alpha_Type in Image

Example

See Also

SkImageInfo::alphaType


SkColorType colorType()const

Returns SkColorType if known; otherwise, returns kUnknown_SkColorType.

Return Value

SkColorType of SkImage

Example

See Also

SkImageInfo::colorType


SkColorSpace* 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.

Return Value

SkColorSpace in SkImage, or nullptr

Example

See Also

refColorSpace makeColorSpace


sk_sp<SkColorSpace> 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.

Return Value

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

Example

See Also

colorSpace makeColorSpace


bool 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.

Return Value

true if pixels represent a transparency mask

Example

#### Example Output ~~~~ alphaOnly = true ~~~~

See Also

alphaType isOpaque


bool isOpaque()const

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

Return Value

true if SkAlphaType is kOpaque_SkAlphaType

Example

#### Example Output ~~~~ isOpaque = false isOpaque = true ~~~~

See Also

alphaType isAlphaOnly


sk_sp<SkShader> makeShader(SkShader::TileMode tileMode1, SkShader::TileMode tileMode2,
                           const SkMatrix* localMatrix = nullptr)const

Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses SkShader::TileMode rules to fill drawn area outside SkImage. localMatrix permits transforming SkImage before SkCanvas matrix is applied.

Parameters

tileMode1 tiling on x-axis, one of: SkShader::kClamp_TileMode,

SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode

Parameters

tileMode2 tiling on y-axis, one of: SkShader::kClamp_TileMode,

SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode

Parameters

localMatrix SkImage transformation, or nullptr

Return Value

SkShader containing SkImage

Example

See Also

scalePixels


sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr)const

Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses SkShader::kClamp_TileMode to fill drawn area outside SkImage. localMatrix permits transforming SkImage before SkCanvas matrix is applied.

Parameters

localMatrix SkImage transformation, or nullptr

Return Value

SkShader containing SkImage

Example

See Also

scalePixels


bool 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

pixmap storage for pixel state if pixels are readable; otherwise, ignored

Return Value

true if SkImage has direct access to pixels

Example

#### Example Output ~~~~ ------------ --xx----x--- -x--x--x---- -x--x--x---- -x--x-x----- --xx-xx-xx-- -----x-x--x- ----x--x--x- ----x--x--x- ---x----xx-- ------------ ~~~~

See Also

readPixels


bool isTextureBacked()const

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

Return Value

true if SkImage is a GPU texture

Example

See Also

MakeFromTexture isValid


bool isValid(GrContext* 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 GrContext is invalid. lazy image may be invalid and may not draw to raster surface or GPU surface or both.

Parameters

context GPU context

Return Value

true if SkImage can be drawn

Example

See Also

isTextureBacked isLazyGenerated


GrBackendTexture 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.

Parameters

flushPendingGrContextIO flag to flush outstanding requests
origin storage for one of: kTopLeft_GrSurfaceOrigin,

kBottomLeft_GrSurfaceOrigin; or nullptr

Return Value

back-end API texture handle; invalid on failure

Example

See Also

MakeFromTexture isTextureBacked


    enum CachingHint {
        kAllow_CachingHint,
        kDisallow_CachingHint,
    };

CachingHint selects whether Skia may internally cache Bitmaps generated by decoding Image, or by copying Image from GPU to CPU. The default behavior allows caching Bitmaps.

Choose kDisallow_CachingHint if Image pixels are to be used only once, or if Image pixels reside in a cache outside of Skia, or to reduce memory pressure.

Choosing kAllow_CachingHint does not ensure that pixels will be cached. Image pixels may not be cached if memory requirements are too large or pixels are not accessible.

Constants

Const Value Description
SkImage::kAllow_CachingHint 0 allows internally caching decoded and copied pixels
SkImage::kDisallow_CachingHint 1 disallows internally caching decoded and copied pixels

See Also

readPixels scalePixels


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

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

dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:

dstInfo has no address
dstRowBytes is less than dstInfo.minRowBytes()
Pixel_Ref is nullptr

Pixels are copied only if pixel conversion is possible. If Image Color_Type is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. If Image Color_Type is kGray_8_SkColorType, dstInfo.colorSpace() must match. If Image Alpha_Type is kOpaque_SkAlphaType, dstInfo.alphaType() must match. If Image Color_Space 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

dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space
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 one of: kAllow_CachingHint, kDisallow_CachingHint

Return Value

true if pixels are copied to dstPixels

Example

See Also

scalePixels SkBitmap::readPixels SkPixmap::readPixels SkCanvas::readPixels SkSurface::readPixels


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

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

dst specifies width, height, Color_Type, Alpha_Type, Color_Space, 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:

dst pixel storage equals nullptr
dst.rowBytes() is less than SkImageInfo::minRowBytes
Pixel_Ref is nullptr

Pixels are copied only if pixel conversion is possible. If Image Color_Type is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match. If Image Color_Type is kGray_8_SkColorType, dst.colorSpace() must match. If Image Alpha_Type is kOpaque_SkAlphaType, dst.alphaType() must match. If Image Color_Space 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

dst destination Pixmap: Image_Info, pixels, row bytes
srcX column index whose absolute value is less than width()
srcY row index whose absolute value is less than height()
cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint

Return Value

true if pixels are copied to dst

Example

See Also

scalePixels SkBitmap::readPixels SkPixmap::readPixels SkCanvas::readPixels SkSurface::readPixels


bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality,
                 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.

Scales the image, with filterQuality, to match dst.width() and dst.height(). filterQuality kNone_SkFilterQuality is fastest, typically implemented with nearest neighbor filter. kLow_SkFilterQuality is typically implemented with bilerp filter. kMedium_SkFilterQuality is typically implemented with bilerp filter, and mip-map filter when size is reduced. kHigh_SkFilterQuality is slowest, typically implemented with bicubic filter.

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

Parameters

dst destination SkPixmap: SkImageInfo, pixels, row bytes
filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,

kMedium_SkFilterQuality, kHigh_SkFilterQuality

Parameters

cachingHint one of: kAllow_CachingHint, kDisallow_CachingHint

Return Value

true if pixels are scaled to fit dst

Example

See Also

SkCanvas::drawImage readPixels SkPixmap::scalePixels


sk_sp<SkData> 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_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY; 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.

Parameters

encodedImageFormat one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG,

SkEncodedImageFormat::kWEBP

Parameters

quality encoder specific metric with 100 equaling best

Return Value

encoded SkImage, or nullptr

Example

See Also

refEncodedData MakeFromEncoded


sk_sp<SkData> encodeToData()const

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_HAS_PNG_LIBRARY to encode SkImage.

Returns nullptr if existing encoded data is missing or invalid, and encoding fails.

Return Value

encoded SkImage, or nullptr

Example

See Also

refEncodedData MakeFromEncoded


sk_sp<SkData> 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_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY.

Returns nullptr if SkImage contents are not encoded.

Return Value

encoded SkImage, or nullptr

Example

See Also

encodeToData MakeFromEncoded


sk_sp<SkImage> makeSubset(const SkIRect& subset)const

Returns subset of SkImage. subset must be fully contained by SkImage dimensions(). The implementation may share pixels, or may copy them.

Returns nullptr if subset is empty, or subset is not contained by bounds, or pixels in SkImage could not be read or copied.

Parameters

subset bounds of returned SkImage

Return Value

partial or full SkImage, or nullptr

Example

See Also

MakeFromEncoded


sk_sp<SkImage> makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace,
                                GrMipMapped mipMapped = GrMipMapped::kNo)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. Returns original SkImage if context and dstColorSpace match and mipMapped is compatible with backing GPU texture.

Returns nullptr if context is nullptr, or if SkImage was created with another GrContext.

Parameters

context GPU context
dstColorSpace range of colors of matching SkSurface on GPU
mipMapped whether created SkImage texture must allocate mip map levels

Return Value

created SkImage, or nullptr

Example

See Also

MakeFromTexture


sk_sp<SkImage> makeNonTextureImage()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.

Return Value

raster image, lazy image, or nullptr

Example

See Also

makeTextureImage makeRasterImage MakeBackendTextureFromSkImage


sk_sp<SkImage> makeRasterImage()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.

Return Value

raster image, or nullptr

Example

See Also

isTextureBacked isLazyGenerated MakeFromRaster


sk_sp<SkImage> makeWithFilter(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. 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.

Parameters

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

Return Value

filtered SkImage, or nullptr

Example

In each frame of the animation, filtered Image is drawn in a different location. By translating canvas by returned offset, Image appears stationary.

See Also

makeShader SkPaint::setImageFilter


BackendTextureReleaseProc

    typedef std::functionGrBackendTexture)> 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.


static bool MakeBackendTextureFromSkImage(GrContext* context, sk_sp<SkImage> image,
                                          GrBackendTexture* backendTexture,
                                          BackendTextureReleaseProc* backendTextureReleaseProc)

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.

Parameters

context GPU context
image SkImage used for texture
backendTexture storage for back-end texture
backendTextureReleaseProc storage for clean up function

Return Value

true if back-end texture was created

Example

See Also

MakeFromTexture makeTextureImage


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.

Return Value

true if SkImage is created as needed

Example

Example

See Also

isTextureBacked makeNonTextureImage


sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target)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.

Parameters

target SkColorSpace describing color range of returned SkImage

Return Value

created SkImage in target SkColorSpace

Example

See Also

MakeFromPicture MakeFromTexture