Type Alias freya_engine::prelude::Image
pub type Image = RCHandle<SkImage>;Expand description
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], crate::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.
Aliased Type§
struct Image(/* private fields */);Implementations§
§impl RCHandle<SkImage>
impl RCHandle<SkImage>
pub fn from_raster_data(
info: &Handle<SkImageInfo>,
pixels: impl Into<RCHandle<SkData>>,
row_bytes: usize
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use images::raster_from_data()
pub fn from_raster_data( info: &Handle<SkImageInfo>, pixels: impl Into<RCHandle<SkData>>, row_bytes: usize ) -> Option<RCHandle<SkImage>>
Creates Image from [ImageInfo], sharing pixels.
Image is returned if [ImageInfo] is valid. Valid [ImageInfo] parameters include:
dimensions are greater than zero;
each dimension fits in 29 bits;
ColorType and [AlphaType] are valid, and ColorType is not ColorType::Unknown;
rowBytes are large enough to hold one row of pixels;
pixels is not nullptr, and contains enough data for Image.
infocontains width, height, [AlphaType],ColorType,ColorSpacepixelsaddress or pixel storagerowBytessize of pixel row or larger Returns:Imagesharing pixels, orNone
pub fn from_bitmap(bitmap: &Handle<SkBitmap>) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use images::raster_from_bitmap()
pub fn from_bitmap(bitmap: &Handle<SkBitmap>) -> Option<RCHandle<SkImage>>
Creates Image 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.
Image is returned if bitmap is valid. Valid [Bitmap] parameters include:
dimensions are greater than zero;
each dimension fits in 29 bits;
ColorType and [AlphaType] are valid, and ColorType is not ColorType::Unknown;
row bytes are large enough to hold one row of pixels;
pixel address is not null.
bitmap[ImageInfo], row bytes, and pixels Returns: createdImage, orNone
pub fn from_generator(
image_generator: RefHandle<SkImageGenerator>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use images::deferred_from_generator()
pub fn from_generator( image_generator: RefHandle<SkImageGenerator> ) -> Option<RCHandle<SkImage>>
pub fn from_encoded(
data: impl Into<RCHandle<SkData>>
) -> Option<RCHandle<SkImage>>
pub fn from_encoded( data: impl Into<RCHandle<SkData>> ) -> Option<RCHandle<SkImage>>
See [Self::from_encoded_with_alpha_type()]
pub fn from_encoded_with_alpha_type(
data: impl Into<RCHandle<SkData>>,
alpha_type: impl Into<Option<SkAlphaType>>
) -> Option<RCHandle<SkImage>>
pub fn from_encoded_with_alpha_type( data: impl Into<RCHandle<SkData>>, alpha_type: impl Into<Option<SkAlphaType>> ) -> Option<RCHandle<SkImage>>
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.
If alphaType is None, the image’s alpha type will be chosen automatically based on the
image format. Transparent images will default to [AlphaType::Premul]. If alphaType contains
[AlphaType::Premul] or [AlphaType::Unpremul], that alpha type will be used. Forcing opaque
(passing [AlphaType::Opaque]) is not allowed, and will return nullptr.
This is similar to decode_to_{raster,texture}, but this method will attempt to defer the
actual decode, while the decode_to… method explicitly decode and allocate the backend
when the call is made.
If the encoded format is not supported, None is returned.
encodedthe encoded data Returns: createdImage, orNone
pub fn decode_to_raster(_encoded: &[u8], _subset: impl Into<Option<IRect>>) -> !
pub fn new_raster_from_compressed(
data: impl Into<RCHandle<SkData>>,
dimensions: impl Into<ISize>,
ty: SkTextureCompressionType
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use images::raster_from_compressed_texture_data()
pub fn new_raster_from_compressed( data: impl Into<RCHandle<SkData>>, dimensions: impl Into<ISize>, ty: SkTextureCompressionType ) -> Option<RCHandle<SkImage>>
Creates a CPU-backed Image 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.
pub fn from_picture(
picture: impl Into<RCHandle<SkPicture>>,
dimensions: impl Into<ISize>,
matrix: Option<&Matrix>,
paint: Option<&Handle<SkPaint>>,
bit_depth: SkImages_BitDepth,
color_space: impl Into<Option<RCHandle<SkColorSpace>>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use images::deferred_from_picture()
pub fn from_picture( picture: impl Into<RCHandle<SkPicture>>, dimensions: impl Into<ISize>, matrix: Option<&Matrix>, paint: Option<&Handle<SkPaint>>, bit_depth: SkImages_BitDepth, color_space: impl Into<Option<RCHandle<SkColorSpace>>> ) -> Option<RCHandle<SkImage>>
See [Self::from_picture_with_props()]
pub fn from_picture_with_props(
picture: impl Into<RCHandle<SkPicture>>,
dimensions: impl Into<ISize>,
matrix: Option<&Matrix>,
paint: Option<&Handle<SkPaint>>,
bit_depth: SkImages_BitDepth,
color_space: impl Into<Option<RCHandle<SkColorSpace>>>,
props: SurfaceProps
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use images::deferred_from_picture()
pub fn from_picture_with_props( picture: impl Into<RCHandle<SkPicture>>, dimensions: impl Into<ISize>, matrix: Option<&Matrix>, paint: Option<&Handle<SkPaint>>, bit_depth: SkImages_BitDepth, color_space: impl Into<Option<RCHandle<SkColorSpace>>>, props: SurfaceProps ) -> Option<RCHandle<SkImage>>
Creates Image from picture. Returned Image width and height are set by dimensions.
Image draws picture with matrix and paint, set to bitDepth and colorSpace.
If matrix is None, draws with identity Matrix. If paint is None, draws
with default Paint. color_space may be None.
picturestream of drawing commandsdimensionswidth and heightmatrixMatrixto rotate, scale, translate, and so on; may beNonepaintPaintto apply transparency, filtering, and so on; may beNonebitDepth8-bit integer or 16-bit float: per componentcolor_spacerange of colors; may beNonepropsprops to use when rasterizing the picture Returns: createdImage, orNone
pub fn new_texture_from_compressed(
context: &mut RCHandle<GrDirectContext>,
data: RCHandle<SkData>,
dimensions: impl Into<ISize>,
ty: SkTextureCompressionType,
mipmapped: impl Into<Option<skgpu_Mipmapped>>,
is_protected: impl Into<Option<skgpu_Protected>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use gpu::images::texture_from_compressed_texture_data()
pub fn new_texture_from_compressed( context: &mut RCHandle<GrDirectContext>, data: RCHandle<SkData>, dimensions: impl Into<ISize>, ty: SkTextureCompressionType, mipmapped: impl Into<Option<skgpu_Mipmapped>>, is_protected: impl Into<Option<skgpu_Protected>> ) -> Option<RCHandle<SkImage>>
Creates a GPU-backed Image from compressed data.
This method will return an Image 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
[gpu::RecordingContext::compressed_backend_format].
contextGPU contextdatacompressed data to store inImagewidthwidth of fullImageheightheight of fullImagetytype of compression usedmipmappeddoes ‘data’ contain data for all the mipmap levels?is_protecteddo the contents of ‘data’ require DRM protection (on Vulkan)? Returns: createdImage, orNone
pub fn from_compressed( _context: &mut RCHandle<GrRecordingContext>, _data: RCHandle<SkData>, _dimensions: impl Into<ISize>, _ct: SkTextureCompressionType ) -> !
pub fn from_texture(
context: &mut RCHandle<GrRecordingContext>,
backend_texture: &RefHandle<GrBackendTexture>,
origin: GrSurfaceOrigin,
color_type: ColorType,
alpha_type: SkAlphaType,
color_space: impl Into<Option<RCHandle<SkColorSpace>>>
) -> Option<RCHandle<SkImage>>
pub fn from_texture( context: &mut RCHandle<GrRecordingContext>, backend_texture: &RefHandle<GrBackendTexture>, origin: GrSurfaceOrigin, color_type: ColorType, alpha_type: SkAlphaType, color_space: impl Into<Option<RCHandle<SkColorSpace>>> ) -> Option<RCHandle<SkImage>>
Creates Image from GPU texture associated with context. GPU texture must stay
valid and unchanged until texture_release_proc is called. texture_release_proc is
passed release_context when Image is deleted or no longer refers to texture.
Image is returned if format of backend_texture is recognized and supported.
Recognized formats vary by GPU back-end.
Note: When using a DDL recording context, texture_release_proc will be called on the
GPU thread after the DDL is played back on the direct context.
contextGPU contextbackend_textureTexture residing on GPUoriginOrigin ofbackend_texturecolor_typeColor type of the resulting imagealpha_typeAlpha type of the resulting imagecolor_spaceThis 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 linearcolor_spaceshould be supplied (e.g., [ColorSpace::new_srgb_linear()])). If the format of the backend texture is linear, then thecolor_spaceshould include a description of the transfer function as well (e.g.,ColorSpace::MakeSRGB).texture_release_procFunction called when texture can be releasedrelease_contextState passed totexture_release_procReturns: CreatedImage, orNone
pub fn from_pixmap_cross_context( context: &mut RCHandle<GrDirectContext>, pixmap: &Pixmap<'_>, build_mips: bool, limit_to_max_texture_size: impl Into<Option<bool>> ) -> Option<RCHandle<SkImage>>
pub fn new_cross_context_from_pixmap(
context: &mut RCHandle<GrDirectContext>,
pixmap: &Pixmap<'_>,
build_mips: bool,
limit_to_max_texture_size: impl Into<Option<bool>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use gpu::images::cross_context_texture_from_pixmap()
pub fn new_cross_context_from_pixmap( context: &mut RCHandle<GrDirectContext>, pixmap: &Pixmap<'_>, build_mips: bool, limit_to_max_texture_size: impl Into<Option<bool>> ) -> Option<RCHandle<SkImage>>
Creates Image from pixmap. Image is uploaded to GPU back-end using context.
Created Image 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 Image is no longer referenced, context releases texture memory
asynchronously.
ColorSpace of Image is determined by pixmap.color_space().
Image is returned referring to GPU back-end if context is not None,
format of data is recognized and supported, and if context supports moving
resources between contexts. Otherwise, pixmap pixel data is copied and Image
as returned in raster format if possible; None may be returned.
Recognized GPU formats vary by platform and GPU back-end.
pub fn from_adopted_texture(
context: &mut RCHandle<GrRecordingContext>,
backend_texture: &RefHandle<GrBackendTexture>,
texture_origin: GrSurfaceOrigin,
color_type: ColorType,
alpha_type: impl Into<Option<SkAlphaType>>,
color_space: impl Into<Option<RCHandle<SkColorSpace>>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use gpu::images::adopt_texture_from()
pub fn from_adopted_texture( context: &mut RCHandle<GrRecordingContext>, backend_texture: &RefHandle<GrBackendTexture>, texture_origin: GrSurfaceOrigin, color_type: ColorType, alpha_type: impl Into<Option<SkAlphaType>>, color_space: impl Into<Option<RCHandle<SkColorSpace>>> ) -> Option<RCHandle<SkImage>>
Creates Image from backend_texture associated with context. backend_texture and
returned Image are managed internally, and are released when no longer needed.
Image is returned if format of backend_texture is recognized and supported.
Recognized formats vary by GPU back-end.
contextGPU contextbackend_texturetexture residing on GPUtexture_originorigin ofbackend_texturecolor_typecolor type of the resulting imagealpha_typealpha type of the resulting imagecolor_spacerange of colors; may beNoneReturns: createdImage, orNone
pub fn from_yuva_textures(
context: &mut RCHandle<GrRecordingContext>,
yuva_textures: &Handle<GrYUVABackendTextures>,
image_color_space: impl Into<Option<RCHandle<SkColorSpace>>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use gpu::images::texture_from_yuva_textures()
pub fn from_yuva_textures( context: &mut RCHandle<GrRecordingContext>, yuva_textures: &Handle<GrYUVABackendTextures>, image_color_space: impl Into<Option<RCHandle<SkColorSpace>>> ) -> Option<RCHandle<SkImage>>
Creates an Image 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.
contextGPU contextyuva_texturesA set of textures containing YUVA data and a description of the data and transformation to RGBA.image_color_spacerange of colors of the resulting image after conversion to RGB; may beNonetexture_release_proccalled when the backend textures can be releasedrelease_contextstate passed totexture_release_procReturns: createdImage, orNone
pub fn from_yuva_pixmaps(
context: &mut RCHandle<GrRecordingContext>,
yuva_pixmaps: &Handle<SkYUVAPixmaps>,
build_mips: impl Into<Option<skgpu_Mipmapped>>,
limit_to_max_texture_size: impl Into<Option<bool>>,
image_color_space: impl Into<Option<RCHandle<SkColorSpace>>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.63.0: use gpu::images::texture_from_yuva_pixmaps()
pub fn from_yuva_pixmaps( context: &mut RCHandle<GrRecordingContext>, yuva_pixmaps: &Handle<SkYUVAPixmaps>, build_mips: impl Into<Option<skgpu_Mipmapped>>, limit_to_max_texture_size: impl Into<Option<bool>>, image_color_space: impl Into<Option<RCHandle<SkColorSpace>>> ) -> Option<RCHandle<SkImage>>
Creates Image from [crate::YUVAPixmaps].
The image will remain planar with each plane converted to a texture using the passed
gpu::RecordingContext.
[crate::YUVAPixmaps] has a [crate::YUVAInfo] which specifies the transformation from YUV to RGB.
The ColorSpace of the resulting RGB values is specified by image_color_space. This will
be the ColorSpace 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 None.
[crate::YUVAPixmaps] does not need to remain valid after this returns.
contextGPU contextpixmapsThe planes as pixmaps with supported [crate::YUVAInfo] that specifies conversion to RGB.build_mipscreate internal YUVA textures as mip map ifYes. This is silently ignored if the context does not support mip maps.limit_to_max_texture_sizedownscale image to GPU maximum texture size, if necessaryimage_color_spacerange of colors of the resulting image; may beNoneReturns: createdImage, orNone
pub fn from_nv12_textures_copy( _context: &mut RCHandle<GrDirectContext>, _yuv_color_space: SkYUVColorSpace, _nv12_textures: &[RefHandle<GrBackendTexture>; 2], _image_origin: GrSurfaceOrigin, _image_color_space: impl Into<Option<RCHandle<SkColorSpace>>> ) -> !
pub fn image_info(&self) -> &Handle<SkImageInfo>
pub fn image_info(&self) -> &Handle<SkImageInfo>
pub fn dimensions(&self) -> ISize
pub fn dimensions(&self) -> ISize
Returns [ISize] { width(), height() }.
Returns: integral size of width() and height()
pub fn bounds(&self) -> IRect
pub fn bounds(&self) -> IRect
Returns IRect { 0, 0, width(), height() }.
Returns: integral rectangle from origin to width() and height()
pub fn alpha_type(&self) -> SkAlphaType
pub fn alpha_type(&self) -> SkAlphaType
pub fn color_type(&self) -> ColorType
pub fn color_type(&self) -> ColorType
Returns ColorType if known; otherwise, returns ColorType::Unknown.
pub fn color_space(&self) -> RCHandle<SkColorSpace>
pub fn color_space(&self) -> RCHandle<SkColorSpace>
Returns a smart pointer to ColorSpace, the range of colors, associated with
Image. The smart pointer tracks the number of objects sharing this
ColorSpace reference so the memory is released when the owners destruct.
The returned ColorSpace is immutable.
ColorSpace returned was passed to an Image constructor,
or was parsed from encoded data. ColorSpace returned may be ignored when Image
is drawn, depending on the capabilities of the crate::Surface receiving the drawing.
Returns: ColorSpace in Image, or None, wrapped in a smart pointer
pub fn is_alpha_only(&self) -> bool
pub fn is_alpha_only(&self) -> bool
Returns true if Image pixels represent transparency only. If true, each pixel
is packed in 8 bits as defined by ColorType::Alpha8.
Returns: true if pixels represent a transparency mask
pub fn is_opaque(&self) -> bool
pub fn is_opaque(&self) -> bool
Returns true if pixels ignore their alpha value and are treated as fully opaque.
Returns: true if [AlphaType] is [AlphaType::Opaque]
pub fn to_shader<'a>(
&self,
tile_modes: impl Into<Option<(SkTileMode, SkTileMode)>>,
sampling: impl Into<SamplingOptions>,
local_matrix: impl Into<Option<&'a Matrix>>
) -> Option<RCHandle<SkShader>>
pub fn to_shader<'a>( &self, tile_modes: impl Into<Option<(SkTileMode, SkTileMode)>>, sampling: impl Into<SamplingOptions>, local_matrix: impl Into<Option<&'a Matrix>> ) -> Option<RCHandle<SkShader>>
Make a shader with the specified tiling and mipmap sampling.
pub fn to_raw_shader<'a>(
&self,
tile_modes: impl Into<Option<(SkTileMode, SkTileMode)>>,
sampling: impl Into<SamplingOptions>,
local_matrix: impl Into<Option<&'a Matrix>>
) -> Option<RCHandle<SkShader>>
pub fn to_raw_shader<'a>( &self, tile_modes: impl Into<Option<(SkTileMode, SkTileMode)>>, sampling: impl Into<SamplingOptions>, local_matrix: impl Into<Option<&'a Matrix>> ) -> Option<RCHandle<SkShader>>
to_raw_shader functions like to_shader, 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: crate::RuntimeEffect).
Raw image shaders work like regular image shaders (including filtering and tiling), with a few major differences:
- No color space transformation is ever applied (the color space of the image is ignored).
- Images with an alpha type of
Unpremulare not automatically premultiplied. - Bicubic filtering is not supported. If [
SamplingOptions::use_cubic] istrue, these factories will returnNone.
pub fn peek_pixels(&self) -> Option<Pixmap<'_>>
pub fn peek_pixels(&self) -> Option<Pixmap<'_>>
Copies Image pixel address, row bytes, and [ImageInfo] to pixmap, if address
is available, and returns true. If pixel address is not available, return
false and leave pixmap unchanged.
pixmapstorage for pixel state if pixels are readable; otherwise, ignored Returns:trueifImagehas direct access to pixels
pub fn is_texture_backed(&self) -> bool
pub fn is_texture_backed(&self) -> bool
pub fn texture_size(&self) -> usize
pub fn texture_size(&self) -> usize
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.
pub fn is_valid(&self, context: &mut RCHandle<GrRecordingContext>) -> bool
pub fn is_valid(&self, context: &mut RCHandle<GrRecordingContext>) -> bool
Returns true if Image can be drawn on either raster surface or GPU surface.
If context is None, tests if Image draws on raster surface;
otherwise, tests if Image draws on GPU surface associated with context.
Image 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.
contextGPU context Returns:trueifImagecan be drawn
pub fn flush<'a>(
&self,
context: &mut RCHandle<GrDirectContext>,
flush_info: impl Into<Option<&'a FlushInfo>>
) -> GrSemaphoresSubmitted
👎Deprecated since 0.63.0: use gpu::DirectContext::flush()
pub fn flush<'a>( &self, context: &mut RCHandle<GrDirectContext>, flush_info: impl Into<Option<&'a FlushInfo>> ) -> GrSemaphoresSubmitted
See [Self::flush_with_info()]
pub fn flush_with_info(
&self,
context: &mut RCHandle<GrDirectContext>,
flush_info: &FlushInfo
) -> GrSemaphoresSubmitted
👎Deprecated since 0.46.0: use gpu::DirectContext::flush()
pub fn flush_with_info( &self, context: &mut RCHandle<GrDirectContext>, flush_info: &FlushInfo ) -> GrSemaphoresSubmitted
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 gpu::DirectContext 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 gpu::DirectContext then this is a no-op unless the [gpu::FlushInfo] contains semaphores or
a finish proc. Those are respected even when the image has not been used.
contextthe context on which to flush pending usages of the image.infoflush options
pub fn flush_and_submit(&self, context: &mut RCHandle<GrDirectContext>)
👎Deprecated since 0.63.0: use gpu::DirectContext::flush_and_submit()
pub fn flush_and_submit(&self, context: &mut RCHandle<GrDirectContext>)
Version of flush() that uses a default [gpu::FlushInfo]. Also submits the flushed work to the
GPU.
pub fn backend_texture(
&self,
flush_pending_gr_context_io: bool
) -> Option<(RefHandle<GrBackendTexture>, GrSurfaceOrigin)>
👎Deprecated since 0.63.0: use gpu::images::get_backend_texture_from_image()
pub fn backend_texture( &self, flush_pending_gr_context_io: bool ) -> Option<(RefHandle<GrBackendTexture>, GrSurfaceOrigin)>
Retrieves the back-end texture. If Image has no back-end texture, Noneis returned.
If flush_pending_gr_context_io is true, completes deferred I/O operations.
If origin in not None, copies location of content drawn into Image.
flush_pending_gr_context_ioflag to flush outstanding requests Returns: back-end API texture handle; invalid on failure
pub fn read_pixels_with_context<'a, P>(
&self,
context: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>,
dst_info: &Handle<SkImageInfo>,
pixels: &mut [P],
dst_row_bytes: usize,
src: impl Into<IPoint>,
caching_hint: SkImage_CachingHint
) -> bool
pub fn read_pixels_with_context<'a, P>( &self, context: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>, dst_info: &Handle<SkImageInfo>, pixels: &mut [P], dst_row_bytes: usize, src: impl Into<IPoint>, caching_hint: SkImage_CachingHint ) -> bool
Copies crate::Rect of pixels from Image to dst_pixels. Copy starts at offset (src_x, src_y),
and does not exceed Image (width(), height()).
dst_info specifies width, height, ColorType, [AlphaType], and ColorSpace of
destination. dst_row_bytes specifies the gap from one destination row to the next.
Returns true if pixels are copied. Returns false if:
dst_info.addr()equalsNonedst_row_bytesis less thandst_info.min_row_bytes()- [
crate::PixelRef] isNone
Pixels are copied only if pixel conversion is possible. If Image ColorType is
ColorType::Gray8, or ColorType::Alpha8; dst_info.color_type() must match.
If Image ColorType is ColorType::Gray8, dst_info.color_space() must match.
If Image [AlphaType] is [AlphaType::Opaque], dst_info.alpha_type() must
match. If Image ColorSpace is None, dst_info.color_space() must match. Returns
false if pixel conversion is not possible.
src_x and src_y 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(src_x) >= Image width(), or if abs(src_y) >= Image height().
If caching_hint is [CachingHint::Allow], pixels may be retained locally.
If caching_hint is [CachingHint::Disallow], pixels are not added to the local cache.
contextthegpu::DirectContextin play, if it existsdst_infodestination width, height,ColorType, [AlphaType],ColorSpacedst_pixelsdestination pixel storagedst_row_bytesdestination row lengthsrc_xcolumn index whose absolute value is less thanwidth()src_yrow index whose absolute value is less thanheight()caching_hintwhether the pixels should be cached locally Returns:trueif pixels are copied todst_pixels
pub fn read_pixels_to_pixmap_with_context<'a>(
&self,
context: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>,
dst: &Pixmap<'_>,
src: impl Into<IPoint>,
caching_hint: SkImage_CachingHint
) -> bool
pub fn read_pixels_to_pixmap_with_context<'a>( &self, context: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>, dst: &Pixmap<'_>, src: impl Into<IPoint>, caching_hint: SkImage_CachingHint ) -> bool
Copies a crate::Rect of pixels from Image to dst. Copy starts at (src_x, src_y), and
does not exceed Image (width(), height()).
dst specifies width, height, ColorType, [AlphaType], ColorSpace, pixel storage,
and row bytes of destination. dst.row_bytes() specifics the gap from one destination
row to the next. Returns true if pixels are copied. Returns false if:
- dst pixel storage equals
None - dst.
row_bytesis less than [ImageInfo::min_row_bytes] - [
crate::PixelRef] isNone
Pixels are copied only if pixel conversion is possible. If Image ColorType is
ColorType::Gray8, or ColorType::Alpha8; dst.color_type() must match.
If Image ColorType is ColorType::Gray8, dst.color_space() must match.
If Image [AlphaType] is [AlphaType::Opaque], dst.alpha_type() must
match. If Image ColorSpace is None, dst.color_space() must match. Returns
false if pixel conversion is not possible.
src_x and src_y 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(src_x) >= Image width(), or if abs(src_y) >= Image height().
If caching_hint is [CachingHint::Allow], pixels may be retained locally.
If caching_hint is [CachingHint::Disallow], pixels are not added to the local cache.
contextthegpu::DirectContextin play, if it existsdstdestination [Pixmap]:[ImageInfo], pixels, row bytessrc_xcolumn index whose absolute value is less thanwidth()src_yrow index whose absolute value is less thanheight()caching_hintwhether the pixels should be cachedlocally_zReturns:trueif pixels are copied to dst
pub fn read_pixels<P>(
&self,
dst_info: &Handle<SkImageInfo>,
pixels: &mut [P],
dst_row_bytes: usize,
src: impl Into<IPoint>,
caching_hint: SkImage_CachingHint
) -> bool
pub fn read_pixels<P>( &self, dst_info: &Handle<SkImageInfo>, pixels: &mut [P], dst_row_bytes: usize, src: impl Into<IPoint>, caching_hint: SkImage_CachingHint ) -> bool
See [Self::read_pixels_with_context()]
pub unsafe fn read_pixels_to_pixmap(
&self,
dst: &Pixmap<'_>,
src: impl Into<IPoint>,
caching_hint: SkImage_CachingHint
) -> bool
pub unsafe fn read_pixels_to_pixmap( &self, dst: &Pixmap<'_>, src: impl Into<IPoint>, caching_hint: SkImage_CachingHint ) -> bool
See [Self::read_pixels_to_pixmap_with_context()]
pub fn scale_pixels(
&self,
dst: &Pixmap<'_>,
sampling: impl Into<SamplingOptions>,
caching_hint: impl Into<Option<SkImage_CachingHint>>
) -> bool
pub fn scale_pixels( &self, dst: &Pixmap<'_>, sampling: impl Into<SamplingOptions>, caching_hint: impl Into<Option<SkImage_CachingHint>> ) -> bool
Copies Image to dst, scaling pixels to fit dst.width() and dst.height(), and
converting pixels to match dst.color_type() and dst.alpha_type(). Returns true if
pixels are copied. Returns false if dst.addr() is None, or dst.row_bytes() is
less than dst [ImageInfo::min_row_bytes].
Pixels are copied only if pixel conversion is possible. If Image ColorType is
ColorType::Gray8, or ColorType::Alpha8; dst.color_type() must match.
If Image ColorType is ColorType::Gray8, dst.color_space() must match.
If Image [AlphaType] is [AlphaType::Opaque], dst.alpha_type() must
match. If Image ColorSpace is None, dst.color_space() must match. Returns
false if pixel conversion is not possible.
If caching_hint is [CachingHint::Allow], pixels may be retained locally.
If caching_hint is [CachingHint::Disallow], pixels are not added to the local cache.
dstdestination [Pixmap]:[ImageInfo], pixels, row bytes Returns:trueif pixels are scaled to fit dst
pub fn encode_to_data_with_context(
&self,
context: impl Into<Option<RCHandle<GrDirectContext>>>,
image_format: SkEncodedImageFormat,
quality: impl Into<Option<u32>>
) -> Option<RCHandle<SkData>>
👎Deprecated since 0.63.0: Use encode
pub fn encode_to_data_with_context( &self, context: impl Into<Option<RCHandle<GrDirectContext>>>, image_format: SkEncodedImageFormat, quality: impl Into<Option<u32>> ) -> Option<RCHandle<SkData>>
Encodes Image pixels, returning result as Data.
Returns None if encoding fails, or if encoded_image_format is not supported.
Image 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, encoded_image_format can
additionally be one of: [EncodedImageFormat::ICO], [EncodedImageFormat::BMP],
[EncodedImageFormat::GIF].
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.
context- thegpu::DirectContextin play, if it exists; can beNoneencoded_image_format- one of: [EncodedImageFormat::JPEG], [EncodedImageFormat::PNG], [EncodedImageFormat::WEBP]quality- encoder specific metric with 100 equaling best Returns: encodedImage, orNone
pub fn encode_to_data(
&self,
image_format: SkEncodedImageFormat
) -> Option<RCHandle<SkData>>
👎Deprecated since 0.63.0: Support for encoding GPU backed images without a context was removed, use encode_to_data_with_context instead
pub fn encode_to_data( &self, image_format: SkEncodedImageFormat ) -> Option<RCHandle<SkData>>
encode_to_data_with_context insteadSee [Self::encode_to_data_with_quality]
pub fn encode_to_data_with_quality(
&self,
image_format: SkEncodedImageFormat,
quality: u32
) -> Option<RCHandle<SkData>>
👎Deprecated since 0.63.0: Support for encoding GPU backed images without a context was removed, use encode_to_data_with_context instead
pub fn encode_to_data_with_quality( &self, image_format: SkEncodedImageFormat, quality: u32 ) -> Option<RCHandle<SkData>>
encode_to_data_with_context insteadEncodes Image pixels, returning result as Data.
Returns None if encoding fails, or if encoded_image_format is not supported.
Image 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, encoded_image_format can
additionally be one of: [EncodedImageFormat::ICO], [EncodedImageFormat::BMP],
[EncodedImageFormat::GIF].
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.
encoded_image_formatone of: [EncodedImageFormat::JPEG], [EncodedImageFormat::PNG], [EncodedImageFormat::WEBP]qualityencoder specific metric with 100 equaling best Returns: encodedImage, orNone
pub fn encoded_data(&self) -> Option<RCHandle<SkData>>
pub fn encoded_data(&self) -> Option<RCHandle<SkData>>
Returns encoded Image pixels as Data, if Image 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 None if Image contents are not encoded.
Returns: encoded Image, or None
pub fn new_subset(&self, rect: impl AsRef<IRect>) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.64.0: use make_subset()
pub fn new_subset(&self, rect: impl AsRef<IRect>) -> Option<RCHandle<SkImage>>
See [Self::new_subset_with_context]
pub fn new_subset_with_context<'a>(
&self,
rect: impl AsRef<IRect>,
direct: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.64.0: use make_subset()
pub fn new_subset_with_context<'a>( &self, rect: impl AsRef<IRect>, direct: impl Into<Option<&'a mut RCHandle<GrDirectContext>>> ) -> Option<RCHandle<SkImage>>
Returns subset of this image.
Returns None if any of the following are true:
- Subset is empty
- Subset is not contained inside the image’s bounds
- Pixels in the image could not be read or copied
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.
subsetbounds of returnedImagecontextthegpu::DirectContextin play, if it exists Returns: the subsetted image, orNone
pub fn make_subset<'a>(
&self,
direct: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>,
subset: impl AsRef<IRect>
) -> Option<RCHandle<SkImage>>
pub fn make_subset<'a>( &self, direct: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>, subset: impl AsRef<IRect> ) -> Option<RCHandle<SkImage>>
Returns subset of this image.
Returns None if any of the following are true:
- Subset is empty - Subset is not contained inside the image’s bounds
- Pixels in the source image could not be read or copied
- This image is texture-backed and the provided context is null or does not match the
source image’s context.
If the source image was texture-backed, the resulting image will be texture-backed also. Otherwise, the returned image will be raster-backed.
direct- thegpu::DirectContextof the source image (Noneis ok if the source image is not texture-backed).subset- bounds of returnedImageReturns: the subsetted image, orNone
pub fn has_mipmaps(&self) -> bool
pub fn has_mipmaps(&self) -> bool
Returns true if the image has mipmap levels.
pub fn with_default_mipmaps(&self) -> Option<RCHandle<SkImage>>
pub fn with_default_mipmaps(&self) -> Option<RCHandle<SkImage>>
Returns an image with the same “base” pixels as the this image, but with mipmap levels automatically generated and attached.
pub fn new_texture_image(
&self,
context: &mut RCHandle<GrDirectContext>,
mipmapped: skgpu_Mipmapped
) -> Option<RCHandle<SkImage>>
pub fn new_texture_image( &self, context: &mut RCHandle<GrDirectContext>, mipmapped: skgpu_Mipmapped ) -> Option<RCHandle<SkImage>>
See [Self::new_texture_image_budgeted]
pub fn new_texture_image_budgeted(
&self,
direct_context: &mut RCHandle<GrDirectContext>,
mipmapped: skgpu_Mipmapped,
budgeted: Budgeted
) -> Option<RCHandle<SkImage>>
pub fn new_texture_image_budgeted( &self, direct_context: &mut RCHandle<GrDirectContext>, mipmapped: skgpu_Mipmapped, budgeted: Budgeted ) -> Option<RCHandle<SkImage>>
Returns Image backed by GPU texture associated with context. Returned Image is
compatible with crate::Surface created with dst_color_space. The returned Image respects
mipmapped setting; if mipmapped equals [gpu::Mipmapped::Yes], the backing texture
allocates mip map levels.
The mipmapped parameter is effectively treated as No if MIP maps are not supported by the
GPU.
Returns original Image if the image is already texture-backed, the context matches, and
mipmapped is compatible with the backing GPU texture. [crate::Budgeted] is ignored in this case.
Returns None if context is None, or if Image was created with another
gpu::DirectContext.
direct_contextthegpu::DirectContextin play, if it existsmipmappedwhether createdImagetexture must allocate mip map levelsbudgetedwhether to count a newly created texture for the returned image counts against the context’s budget. Returns: createdImage, orNone
pub fn to_non_texture_image(&self) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.64.0: use make_non_texture_image()
pub fn to_non_texture_image(&self) -> Option<RCHandle<SkImage>>
Returns raster image or lazy image. Copies Image backed by GPU texture into
CPU memory if needed. Returns original Image if decoded in raster bitmap,
or if encoded in a stream.
Returns None if backed by GPU texture and copy fails.
Returns: raster image, lazy image, or None
example: https://fiddle.skia.org/c/@Image_makeNonTextureImage
pub fn make_non_texture_image<'a>(
&self,
context: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>
) -> Option<RCHandle<SkImage>>
pub fn make_non_texture_image<'a>( &self, context: impl Into<Option<&'a mut RCHandle<GrDirectContext>>> ) -> Option<RCHandle<SkImage>>
Returns raster image or lazy image. Copies Image backed by GPU texture into
CPU memory if needed. Returns original Image if decoded in raster bitmap,
or if encoded in a stream.
Returns None if backed by GPU texture and copy fails.
Returns: raster image, lazy image, or None
example: https://fiddle.skia.org/c/@Image_makeNonTextureImage
pub fn to_raster_image(
&self,
caching_hint: impl Into<Option<SkImage_CachingHint>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.64.0: use make_raster_image()
pub fn to_raster_image( &self, caching_hint: impl Into<Option<SkImage_CachingHint>> ) -> Option<RCHandle<SkImage>>
Returns raster image. Copies Image backed by GPU texture into CPU memory,
or decodes Image from lazy image. Returns original Image if decoded in
raster bitmap.
Returns None if copy, decode, or pixel read fails.
If caching_hint is [CachingHint::Allow], pixels may be retained locally.
If caching_hint is [CachingHint::Disallow], pixels are not added to the local cache.
Returns: raster image, or None
pub fn make_raster_image<'a>(
&self,
context: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>,
caching_hint: impl Into<Option<SkImage_CachingHint>>
) -> Option<RCHandle<SkImage>>
pub fn make_raster_image<'a>( &self, context: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>, caching_hint: impl Into<Option<SkImage_CachingHint>> ) -> Option<RCHandle<SkImage>>
Returns raster image. Copies Image backed by GPU texture into CPU memory,
or decodes Image from lazy image. Returns original Image if decoded in
raster bitmap.
Returns None if copy, decode, or pixel read fails.
If caching_hint is [CachingHint::Allow], pixels may be retained locally.
If caching_hint is [CachingHint::Disallow], pixels are not added to the local cache.
Returns: raster image, or None
pub fn new_with_filter(
&self,
context: Option<&mut RCHandle<GrRecordingContext>>,
filter: &RCHandle<SkImageFilter>,
clip_bounds: impl Into<IRect>,
subset: impl Into<IRect>
) -> Option<(RCHandle<SkImage>, IRect, IPoint)>
👎Deprecated since 0.67.0: use images::make_with_filter()
pub fn new_with_filter( &self, context: Option<&mut RCHandle<GrRecordingContext>>, filter: &RCHandle<SkImageFilter>, clip_bounds: impl Into<IRect>, subset: impl Into<IRect> ) -> Option<(RCHandle<SkImage>, IRect, IPoint)>
Creates filtered Image. filter processes original Image, potentially changing
color, position, and size. subset is the bounds of original Image processed
by filter. clip_bounds is the expected bounds of the filtered Image. out_subset
is required storage for the actual bounds of the filtered Image. offset is
required storage for translation of returned Image.
Returns None if Image could not be created or if the recording context provided doesn’t
match the GPU context in which the image was created. If None is returned, out_subset
and offset are undefined.
Useful for animation of [ImageFilter] that varies size from frame to frame.
Returned Image is created larger than required by filter so that GPU texture
can be reused with different sized effects. out_subset describes the valid bounds
of GPU texture returned. offset translates the returned Image to keep subsequent
animation frames aligned with respect to each other.
contextthegpu::RecordingContextin play - if it existsfilterhowImageis sampled when transformedsubsetbounds ofImageprocessed by filterclip_boundsexpected bounds of filteredImageout_subsetstorage for returnedImageboundsoffsetstorage for returnedImagetranslation Returns: filteredImage, orNone
pub fn is_lazy_generated(&self) -> bool
pub fn is_lazy_generated(&self) -> bool
Returns true if Image is backed by an image-generator or other service that creates
and caches its pixels or texture on-demand.
Returns: true if Image is created as needed
example: https://fiddle.skia.org/c/@Image_isLazyGenerated_a example: https://fiddle.skia.org/c/@Image_isLazyGenerated_b
pub fn new_color_space(
&self,
color_space: impl Into<Option<RCHandle<SkColorSpace>>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.64.0: use make_color_space()
pub fn new_color_space( &self, color_space: impl Into<Option<RCHandle<SkColorSpace>>> ) -> Option<RCHandle<SkImage>>
See [Self::new_color_space_with_context]
pub fn new_color_space_with_context<'a>(
&self,
color_space: impl Into<Option<RCHandle<SkColorSpace>>>,
direct: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>
) -> Option<RCHandle<SkImage>>
👎Deprecated since 0.64.0: use make_color_space()
pub fn new_color_space_with_context<'a>( &self, color_space: impl Into<Option<RCHandle<SkColorSpace>>>, direct: impl Into<Option<&'a mut RCHandle<GrDirectContext>>> ) -> Option<RCHandle<SkImage>>
Creates Image in target ColorSpace.
Returns None if Image could not be created.
Returns original Image if it is in target ColorSpace.
Otherwise, converts pixels from Image ColorSpace to target ColorSpace.
If Image color_space() returns None, Image ColorSpace is assumed to be s_rgb.
If this image is texture-backed, the context parameter is required and must match the context of the source image.
targetColorSpacedescribing color range of returnedImagedirectThegpu::DirectContextin play, if it exists Returns: createdImagein targetColorSpace
pub fn make_color_space<'a>(
&self,
direct: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>,
color_space: impl Into<Option<RCHandle<SkColorSpace>>>
) -> Option<RCHandle<SkImage>>
pub fn make_color_space<'a>( &self, direct: impl Into<Option<&'a mut RCHandle<GrDirectContext>>>, color_space: impl Into<Option<RCHandle<SkColorSpace>>> ) -> Option<RCHandle<SkImage>>
Creates Image in target ColorSpace.
Returns None if Image could not be created.
Returns original Image if it is in target ColorSpace.
Otherwise, converts pixels from Image ColorSpace to target ColorSpace.
If Image color_space() returns None, Image ColorSpace is assumed to be s_rgb.
If this image is texture-backed, the context parameter is required and must match the context of the source image.
directThegpu::DirectContextin play, if it existstargetColorSpacedescribing color range of returnedImageReturns: createdImagein targetColorSpace
pub fn reinterpret_color_space(
&self,
new_color_space: impl Into<RCHandle<SkColorSpace>>
) -> Option<RCHandle<SkImage>>
pub fn reinterpret_color_space( &self, new_color_space: impl Into<RCHandle<SkColorSpace>> ) -> Option<RCHandle<SkImage>>
Creates a new Image identical to this one, but with a different ColorSpace.
This does not convert the underlying pixel data, so the resulting image will draw
differently.
Trait Implementations§
§impl<H> ConditionallySend for RCHandle<H>where
H: NativeRefCountedBase,
impl<H> ConditionallySend for RCHandle<H>where H: NativeRefCountedBase,
RCHandle<H> is conditionally Send and can be sent to
another thread when its reference count is 1.
§impl<N> Flattenable for RCHandle<N>where
N: NativeFlattenable + NativeRefCountedBase,
impl<N> Flattenable for RCHandle<N>where N: NativeFlattenable + NativeRefCountedBase,
§impl<N> From<&RCHandle<N>> for RCHandle<N>where
N: NativeRefCounted,
impl<N> From<&RCHandle<N>> for RCHandle<N>where N: NativeRefCounted,
A reference counted handle is cheap to clone, so we do support a conversion from a reference to a ref counter to an owned handle.