Flutter Engine
The Flutter Engine
|
#include <SkImage.h>
Classes | |
class | AsyncReadResult |
struct | RequiredProperties |
Public Types | |
enum | CachingHint { kAllow_CachingHint , kDisallow_CachingHint } |
enum class | RescaleGamma : bool { kSrc , kLinear } |
enum class | RescaleMode { kNearest , kLinear , kRepeatedLinear , kRepeatedCubic } |
enum | LegacyBitmapMode { kRO_LegacyBitmapMode } |
using | ReadPixelsContext = void * |
using | ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr< const AsyncReadResult >) |
Friends | |
class | SkBitmap |
class | SkImage_Base |
class | SkImage_Raster |
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.
See SkImages namespace for the static factory methods to make SkImages.
Clients should not subclass SkImage as there is a lot of internal machinery that is not publicly accessible.
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* |
enum SkImage::CachingHint |
Enumerator | |
---|---|
kAllow_CachingHint | allows internally caching decoded and copied pixels |
kDisallow_CachingHint | disallows internally caching decoded and copied pixels |
Definition at line 463 of file SkImage.h.
Deprecated.
Enumerator | |
---|---|
kRO_LegacyBitmapMode | returned bitmap is read-only and immutable |
Definition at line 825 of file SkImage.h.
|
strong |
|
strong |
SkAlphaType SkImage::alphaType | ( | ) | const |
Returns SkAlphaType.
SkAlphaType returned was a parameter to an SkImage constructor, or was parsed from encoded data.
example: https://fiddle.skia.org/c/@Image_alphaType
Definition at line 154 of file SkImage.cpp.
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 |
Definition at line 233 of file SkImage.cpp.
void SkImage::asyncRescaleAndReadPixels | ( | const SkImageInfo & | info, |
const SkIRect & | srcRect, | ||
RescaleGamma | rescaleGamma, | ||
RescaleMode | rescaleMode, | ||
ReadPixelsCallback | callback, | ||
ReadPixelsContext | context | ||
) | const |
Makes image pixel data available to caller, possibly asynchronously. It can also rescale the image pixels.
Currently asynchronous reads are only supported on the GPU backend and only when the underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all other cases this operates synchronously.
Data is read from the source sub-rectangle, is optionally converted to a linear gamma, is rescaled to the size indicated by 'info', is then converted to the color space, color type, and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the image causes failure.
When the pixel data is ready the caller's ReadPixelsCallback is called with a AsyncReadResult containing pixel data in the requested color type, alpha type, and color space. The AsyncReadResult will have count() == 1. Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU image this flushes work but a submit must occur to guarantee a finite time before the callback is called.
The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage is GPU-backed the data is immediately invalidated if the context is abandoned or destroyed.
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 |
Definition at line 64 of file SkImage.cpp.
void SkImage::asyncRescaleAndReadPixelsYUV420 | ( | SkYUVColorSpace | yuvColorSpace, |
sk_sp< SkColorSpace > | dstColorSpace, | ||
const SkIRect & | srcRect, | ||
const SkISize & | dstSize, | ||
RescaleGamma | rescaleGamma, | ||
RescaleMode | rescaleMode, | ||
ReadPixelsCallback | callback, | ||
ReadPixelsContext | context | ||
) | const |
Similar to asyncRescaleAndReadPixels but performs an additional conversion to YUV. The RGB->YUV conversion is controlled by 'yuvColorSpace'. The YUV data is returned as three planes ordered y, u, v. The u and v planes are half the width and height of the resized rectangle. The y, u, and v values are single bytes. Currently this fails if 'dstSize' width and height are not even. A 'srcRect' that is not contained by the bounds of the image causes failure.
When the pixel data is ready the caller's ReadPixelsCallback is called with a AsyncReadResult containing the planar data. The AsyncReadResult will have count() == 3. Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU image this flushes work but a submit must occur to guarantee a finite time before the callback is called.
The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage is GPU-backed the data is immediately invalidated if the context is abandoned or destroyed.
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 |
Definition at line 79 of file SkImage.cpp.
void SkImage::asyncRescaleAndReadPixelsYUVA420 | ( | SkYUVColorSpace | yuvColorSpace, |
sk_sp< SkColorSpace > | dstColorSpace, | ||
const SkIRect & | srcRect, | ||
const SkISize & | dstSize, | ||
RescaleGamma | rescaleGamma, | ||
RescaleMode | rescaleMode, | ||
ReadPixelsCallback | callback, | ||
ReadPixelsContext | context | ||
) | const |
Identical to asyncRescaleAndReadPixelsYUV420 but a fourth plane is returned in the AsyncReadResult passed to 'callback'. The fourth plane contains the alpha chanel at the same full resolution as the Y plane.
Definition at line 103 of file SkImage.cpp.
|
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.
example: https://fiddle.skia.org/c/@Image_colorSpace
Definition at line 156 of file SkImage.cpp.
SkColorType SkImage::colorType | ( | ) | const |
Returns SkColorType if known; otherwise, returns kUnknown_SkColorType.
example: https://fiddle.skia.org/c/@Image_colorType
Definition at line 152 of file SkImage.cpp.
|
inline |
bool SkImage::hasMipmaps | ( | ) | const |
Returns true if the image has mipmap levels.
Definition at line 292 of file SkImage.cpp.
|
inline |
|
inline |
Returns a SkImageInfo describing the width, height, color type, alpha type, and color space of the SkImage.
Definition at line 279 of file SkImage.h.
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.
example: https://fiddle.skia.org/c/@Image_isAlphaOnly
Definition at line 239 of file SkImage.cpp.
|
pure virtual |
Returns true if SkImage is backed by an image-generator or other service that creates and caches its pixels or texture on-demand.
example: https://fiddle.skia.org/c/@Image_isLazyGenerated_a example: https://fiddle.skia.org/c/@Image_isLazyGenerated_b
Implemented in SkImage_Base.
|
inline |
bool SkImage::isProtected | ( | ) | const |
Returns true if the image holds protected content.
Definition at line 294 of file SkImage.cpp.
|
pure virtual |
Returns true if the contents of SkImage was created on or uploaded to GPU memory, and is available as a GPU texture.
example: https://fiddle.skia.org/c/@Image_isTextureBacked
Implemented in SkImage_Base.
|
pure virtual |
Returns true if SkImage can be drawn on either raster surface or GPU surface. If context is nullptr, tests if SkImage draws on raster surface; otherwise, tests if SkImage draws on GPU surface associated with context.
SkImage backed by GPU texture may become invalid if associated context is invalid. lazy image may be invalid and may not draw to raster surface or GPU surface or both.
context | GPU context |
example: https://fiddle.skia.org/c/@Image_isValid
Implemented in SkImage_GaneshBase, skgpu::graphite::Image_Base, SkImage_Lazy, and SkImage_Raster.
|
pure virtual |
Creates SkImage in target SkColorSpace. Returns nullptr if SkImage could not be created.
Returns original SkImage if it is in target SkColorSpace. Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace. If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB.
If this image is texture-backed, the context parameter is required and must match the context of the source image.
direct | The GrDirectContext in play, if it exists |
target | SkColorSpace describing color range of returned SkImage |
example: https://fiddle.skia.org/c/@Image_makeColorSpace
Implemented in SkImage_Base.
|
pure virtual |
Creates SkImage in target SkColorSpace. Returns nullptr if SkImage could not be created.
Returns original SkImage if it is in target SkColorSpace. Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace. If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB.
If this image is graphite-backed, the recorder parameter is required.
targetColorSpace | SkColorSpace describing color range of returned SkImage |
recorder | The Recorder in which to create the new image |
RequiredProperties | properties the returned SkImage must possess (e.g. mipmaps) |
Implemented in SkImage_Base.
|
pure virtual |
Experimental. Creates SkImage in target SkColorType and SkColorSpace. Returns nullptr if SkImage could not be created.
Returns original SkImage if it is in target SkColorType and SkColorSpace.
If this image is texture-backed, the context parameter is required and must match the context of the source image.
direct | The GrDirectContext in play, if it exists |
targetColorType | SkColorType of returned SkImage |
targetColorSpace | SkColorSpace of returned SkImage |
Implemented in SkImage_GaneshBase, and SkImage_Base.
|
pure virtual |
Experimental. Creates SkImage in target SkColorType and SkColorSpace. Returns nullptr if SkImage could not be created.
Returns original SkImage if it is in target SkColorType and SkColorSpace.
If this image is graphite-backed, the recorder parameter is required.
targetColorType | SkColorType of returned SkImage |
targetColorSpace | SkColorSpace of returned SkImage |
recorder | The Recorder in which to create the new image |
RequiredProperties | properties the returned SkImage must possess (e.g. mipmaps) |
Implemented in skgpu::graphite::Image_Base, SkImage_GaneshBase, and SkImage_Base.
sk_sp< SkImage > SkImage::makeNonTextureImage | ( | GrDirectContext * | dContext = nullptr | ) | const |
Returns raster image or lazy image. Copies SkImage backed by GPU texture into CPU memory if needed. Returns original SkImage if decoded in raster bitmap, or if encoded in a stream.
Returns nullptr if backed by GPU texture and copy fails.
example: https://fiddle.skia.org/c/@Image_makeNonTextureImage
Definition at line 260 of file SkImage.cpp.
|
inline |
sk_sp< SkImage > SkImage::makeRasterImage | ( | GrDirectContext * | dContext, |
CachingHint | cachingHint = kDisallow_CachingHint |
||
) | const |
Returns raster image. Copies SkImage backed by GPU texture into CPU memory, or decodes SkImage from lazy image. Returns original SkImage if decoded in raster bitmap.
Returns nullptr if copy, decode, or pixel read fails.
If cachingHint is kAllow_CachingHint, pixels may be retained locally. If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
example: https://fiddle.skia.org/c/@Image_makeRasterImage
Definition at line 267 of file SkImage.cpp.
sk_sp< SkShader > SkImage::makeRawShader | ( | const SkSamplingOptions & | sampling, |
const SkMatrix & | lm | ||
) | const |
Defaults to clamp in both X and Y.
Definition at line 193 of file SkImage.cpp.
sk_sp< SkShader > SkImage::makeRawShader | ( | const SkSamplingOptions & | sampling, |
const SkMatrix * | lm = nullptr |
||
) | const |
Definition at line 200 of file SkImage.cpp.
sk_sp< SkShader > SkImage::makeRawShader | ( | SkTileMode | tmx, |
SkTileMode | tmy, | ||
const SkSamplingOptions & | sampling, | ||
const SkMatrix * | localMatrix = nullptr |
||
) | const |
makeRawShader functions like makeShader, but for images that contain non-color data. This includes images encoding things like normals, material properties (eg, roughness), heightmaps, or any other purely mathematical data that happens to be stored in an image. These types of images are useful with some programmable shaders (see: SkRuntimeEffect).
Raw image shaders work like regular image shaders (including filtering and tiling), with a few major differences:
Definition at line 207 of file SkImage.cpp.
sk_sp< SkShader > SkImage::makeRawShader | ( | SkTileMode | tmx, |
SkTileMode | tmy, | ||
const SkSamplingOptions & | sampling, | ||
const SkMatrix & | lm | ||
) | const |
Definition at line 186 of file SkImage.cpp.
sk_sp< SkShader > SkImage::makeShader | ( | const SkSamplingOptions & | sampling, |
const SkMatrix & | lm | ||
) | const |
Defaults to clamp in both X and Y.
Definition at line 160 of file SkImage.cpp.
sk_sp< SkShader > SkImage::makeShader | ( | const SkSamplingOptions & | sampling, |
const SkMatrix * | lm = nullptr |
||
) | const |
Definition at line 166 of file SkImage.cpp.
sk_sp< SkShader > SkImage::makeShader | ( | SkTileMode | tmx, |
SkTileMode | tmy, | ||
const SkSamplingOptions & | sampling, | ||
const SkMatrix * | localMatrix = nullptr |
||
) | const |
Make a shader with the specified tiling and mipmap sampling.
Definition at line 179 of file SkImage.cpp.
sk_sp< SkShader > SkImage::makeShader | ( | SkTileMode | tmx, |
SkTileMode | tmy, | ||
const SkSamplingOptions & | sampling, | ||
const SkMatrix & | lm | ||
) | const |
Definition at line 172 of file SkImage.cpp.
|
pure virtual |
Returns subset of this image.
Returns nullptr if any of the following are true:
If the source image was texture-backed, the resulting image will be texture-backed also. Otherwise, the returned image will be raster-backed.
direct | the GrDirectContext of the source image (nullptr is ok if the source image is not texture-backed). |
subset | bounds of returned SkImage |
example: https://fiddle.skia.org/c/@Image_makeSubset
Implemented in SkImage_GaneshBase, and SkImage_Base.
|
pure virtual |
Returns subset of this image.
Returns nullptr if any of the following are true:
If the source image was texture-backed, the resulting image will be texture-backed also. Otherwise, the returned image will be raster-backed.
recorder | the recorder of the source image (nullptr is ok if the source image was texture-backed). |
subset | bounds of returned SkImage |
RequiredProperties | properties the returned SkImage must possess (e.g. mipmaps) |
Implemented in SkImage_Base.
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 |
example: https://fiddle.skia.org/c/@Image_peekPixels
Definition at line 34 of file SkImage.cpp.
bool SkImage::readPixels | ( | const SkImageInfo & | dstInfo, |
void * | dstPixels, | ||
size_t | dstRowBytes, | ||
int | srcX, | ||
int | srcY, | ||
CachingHint | cachingHint = kAllow_CachingHint |
||
) | const |
Deprecated. Use the variants that accept a GrDirectContext.
Definition at line 48 of file SkImage.cpp.
bool SkImage::readPixels | ( | const SkPixmap & | dst, |
int | srcX, | ||
int | srcY, | ||
CachingHint | cachingHint = kAllow_CachingHint |
||
) | const |
Definition at line 227 of file SkImage.cpp.
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 |
Definition at line 42 of file SkImage.cpp.
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 |
Definition at line 220 of file SkImage.cpp.
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.
example: https://fiddle.skia.org/c/@Image_refColorSpace
Definition at line 158 of file SkImage.cpp.
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.
example: https://fiddle.skia.org/c/@Image_refEncodedData
Definition at line 214 of file SkImage.cpp.
sk_sp< SkImage > SkImage::reinterpretColorSpace | ( | sk_sp< SkColorSpace > | newColorSpace | ) | const |
Creates a new SkImage identical to this one, but with a different SkColorSpace. This does not convert the underlying pixel data, so the resulting image will draw differently.
Definition at line 241 of file SkImage.cpp.
bool SkImage::scalePixels | ( | const SkPixmap & | dst, |
const SkSamplingOptions & | sampling, | ||
CachingHint | cachingHint = kAllow_CachingHint |
||
) | const |
Copies SkImage to dst, scaling pixels to fit dst.width() and dst.height(), and converting pixels to match dst.colorType() and dst.alphaType(). Returns true if pixels are copied. Returns false if dst.addr() is nullptr, or dst.rowBytes() is less than dst SkImageInfo::minRowBytes.
Pixels are copied only if pixel conversion is possible. If SkImage SkColorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.colorType() must match. If SkImage SkColorType is kGray_8_SkColorType, dst.colorSpace() must match. If SkImage SkAlphaType is kOpaque_SkAlphaType, dst.alphaType() must match. If SkImage SkColorSpace is nullptr, dst.colorSpace() must match. Returns false if pixel conversion is not possible.
If cachingHint is kAllow_CachingHint, pixels may be retained locally. If cachingHint is kDisallow_CachingHint, pixels are not added to the local cache.
dst | destination SkPixmap: SkImageInfo, pixels, row bytes |
Definition at line 127 of file SkImage.cpp.
|
pure virtual |
Returns an approximation of the amount of texture memory used by the image. Returns zero if the image is not texture backed or if the texture has an external format.
Implemented in SkImage_Ganesh, SkImage_GaneshYUVA, skgpu::graphite::Image, skgpu::graphite::Image_YUVA, and SkImage_Base.
|
inline |
|
inline |
Returns an image with the same "base" pixels as the this image, but with mipmap levels automatically generated and attached.
Definition at line 305 of file SkImage.cpp.
|
friend |
|
friend |
|
friend |