Skia
2D Graphics Library
SkImages Namespace Reference

Typedefs

using ReleaseContext = void *
 Caller data passed to RasterReleaseProc; may be nullptr. More...
 
using RasterReleaseProc = void(const void *pixels, ReleaseContext)
 Function called when SkImage no longer shares pixels. More...
 

Enumerations

enum class  BitDepth { kU8 , kF16 }
 

Functions

SK_API sk_sp< SkImageRasterFromBitmap (const SkBitmap &bitmap)
 Creates a CPU-backed SkImage from bitmap, sharing or copying bitmap pixels. More...
 
SK_API sk_sp< SkImageRasterFromCompressedTextureData (sk_sp< SkData > data, int width, int height, SkTextureCompressionType type)
 Creates a CPU-backed SkImage from compressed data. More...
 
SK_API sk_sp< SkImageDeferredFromEncodedData (sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
 Return a SkImage using the encoded data, but attempts to defer decoding until the image is actually used/drawn. More...
 
SK_API sk_sp< SkImageDeferredFromGenerator (std::unique_ptr< SkImageGenerator > imageGenerator)
 Creates SkImage from data returned by imageGenerator. More...
 
SK_API sk_sp< SkImageDeferredFromPicture (sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace, SkSurfaceProps props)
 Creates SkImage from picture. More...
 
SK_API sk_sp< SkImageDeferredFromPicture (sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace)
 
SK_API sk_sp< SkImageRasterFromPixmapCopy (const SkPixmap &pixmap)
 Creates a CPU-backed SkImage from pixmap, copying the pixel data. More...
 
SK_API sk_sp< SkImageRasterFromPixmap (const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
 Creates CPU-backed SkImage from pixmap, sharing SkPixmap pixels. More...
 
SK_API sk_sp< SkImageRasterFromData (const SkImageInfo &info, sk_sp< SkData > pixels, size_t rowBytes)
 Creates CPU-backed SkImage from pixel data described by info. More...
 
SK_API sk_sp< SkImageMakeWithFilter (sk_sp< SkImage > src, const SkImageFilter *filter, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset)
 Creates a filtered SkImage on the CPU. More...
 

Typedef Documentation

◆ RasterReleaseProc

using SkImages::RasterReleaseProc = typedef void(const void* pixels, ReleaseContext)

Function called when SkImage no longer shares pixels.

ReleaseContext is provided by caller when SkImage is created, and may be nullptr.

◆ ReleaseContext

using SkImages::ReleaseContext = typedef void*

Caller data passed to RasterReleaseProc; may be nullptr.

Enumeration Type Documentation

◆ BitDepth

enum SkImages::BitDepth
strong
Enumerator
kU8 

uses 8-bit unsigned int per color component

kF16 

uses 16-bit float per color component

Function Documentation

◆ DeferredFromEncodedData()

SK_API sk_sp<SkImage> SkImages::DeferredFromEncodedData ( sk_sp< SkData encoded,
std::optional< SkAlphaType alphaType = std::nullopt 
)

Return a SkImage using the encoded data, but attempts 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.

If alphaType is nullopt, the image's alpha type will be chosen automatically based on the image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr.

If the encoded format is not supported, nullptr is returned.

Parameters
encodedthe encoded data
Returns
created SkImage, or nullptr

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

◆ DeferredFromGenerator()

SK_API sk_sp<SkImage> SkImages::DeferredFromGenerator ( std::unique_ptr< SkImageGenerator imageGenerator)

Creates SkImage from data returned by imageGenerator.

The image data will not be created (on either the CPU or GPU) until the image is actually drawn. 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.

Parameters
imageGeneratorstock or custom routines to retrieve SkImage
Returns
created SkImage, or nullptr

◆ DeferredFromPicture() [1/2]

SK_API sk_sp<SkImage> SkImages::DeferredFromPicture ( sk_sp< SkPicture picture,
const SkISize dimensions,
const SkMatrix matrix,
const SkPaint paint,
BitDepth  bitDepth,
sk_sp< SkColorSpace colorSpace 
)

◆ DeferredFromPicture() [2/2]

SK_API sk_sp<SkImage> SkImages::DeferredFromPicture ( sk_sp< SkPicture picture,
const SkISize dimensions,
const SkMatrix matrix,
const SkPaint paint,
BitDepth  bitDepth,
sk_sp< SkColorSpace colorSpace,
SkSurfaceProps  props 
)

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.

The Picture data is not turned into an image (CPU or GPU) until it is drawn.

If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws with default SkPaint. colorSpace may be nullptr.

Parameters
picturestream of drawing commands
dimensionswidth and height
matrixSkMatrix to rotate, scale, translate, and so on; may be nullptr
paintSkPaint to apply transparency, filtering, and so on; may be nullptr
bitDepth8-bit integer or 16-bit float: per component
colorSpacerange of colors; may be nullptr
propsprops to use when rasterizing the picture
Returns
created SkImage, or nullptr

◆ MakeWithFilter()

SK_API sk_sp<SkImage> SkImages::MakeWithFilter ( sk_sp< SkImage src,
const SkImageFilter filter,
const SkIRect subset,
const SkIRect clipBounds,
SkIRect outSubset,
SkIPoint *  offset 
)

Creates a filtered SkImage on the CPU.

filter processes the src image, potentially changing the color, position, and size. subset is the bounds of src that are 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 a filtered result 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. outSubset describes the valid bounds of returned image. offset translates the returned SkImage to keep subsequent animation frames aligned with respect to each other.

Parameters
srcthe image to be filtered
filterthe image filter to be applied
subsetbounds of SkImage processed by filter
clipBoundsexpected bounds of filtered SkImage
outSubsetstorage for returned SkImage bounds
offsetstorage for returned SkImage translation
Returns
filtered SkImage, or nullptr

◆ RasterFromBitmap()

SK_API sk_sp<SkImage> SkImages::RasterFromBitmap ( const SkBitmap bitmap)

Creates a CPU-backed 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
bitmapSkImageInfo, row bytes, and pixels
Returns
created SkImage, or nullptr

◆ RasterFromCompressedTextureData()

SK_API sk_sp<SkImage> SkImages::RasterFromCompressedTextureData ( sk_sp< SkData data,
int  width,
int  height,
SkTextureCompressionType  type 
)

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.

Parameters
datacompressed data to store in SkImage
widthwidth of full SkImage
heightheight of full SkImage
typetype of compression used
Returns
created SkImage, or nullptr

◆ RasterFromData()

SK_API sk_sp<SkImage> SkImages::RasterFromData ( const SkImageInfo info,
sk_sp< SkData pixels,
size_t  rowBytes 
)

Creates CPU-backed SkImage from pixel data described by info.

The pixels data will not be copied.

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
infocontains width, height, SkAlphaType, SkColorType, SkColorSpace
pixelsaddress or pixel storage
rowBytessize of pixel row or larger
Returns
SkImage sharing pixels, or nullptr

◆ RasterFromPixmap()

SK_API sk_sp<SkImage> SkImages::RasterFromPixmap ( const SkPixmap pixmap,
RasterReleaseProc  rasterReleaseProc,
ReleaseContext  releaseContext 
)

Creates CPU-backed 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
pixmapSkImageInfo, pixel address, and row bytes
rasterReleaseProcfunction called when pixels can be released; or nullptr
releaseContextstate passed to rasterReleaseProc; or nullptr
Returns
SkImage sharing pixmap

◆ RasterFromPixmapCopy()

SK_API sk_sp<SkImage> SkImages::RasterFromPixmapCopy ( const SkPixmap pixmap)

Creates a CPU-backed SkImage from pixmap, copying the pixel data.

As a result, pixmap 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
pixmapSkImageInfo, pixel address, and row bytes
Returns
copy of SkPixmap pixels, or nullptr

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