Struct rsvg::surface_utils::shared_surface::ImageSurface
source · pub struct ImageSurface<T> {
surface: ImageSurface,
data_ptr: NonNull<u8>,
width: i32,
height: i32,
stride: isize,
surface_type: SurfaceType,
_state: PhantomData<T>,
}
Expand description
Wrapper for a Cairo image surface that enforces exclusive access when modifying it.
Shared access to cairo::ImageSurface
is tricky since a read-only borrowed reference
can still be cloned and then modified. We can’t simply use cairo::ImageSurface::data()
because in the filter code we have surfaces referenced from multiple places and it would
probably add more complexity to remove that and start passing around references.
This wrapper asserts the uniqueness of its image surface.
It uses the typestate pattern to ensure that the surface can be modified only when
it is in the Exclusive
state, while in the Shared
state it only allows read-only access.
Fields§
§surface: ImageSurface
§data_ptr: NonNull<u8>
§width: i32
§height: i32
§stride: isize
§surface_type: SurfaceType
§_state: PhantomData<T>
Implementations§
source§impl<T> ImageSurface<T>
impl<T> ImageSurface<T>
sourcepub fn wrap(
surface: ImageSurface,
surface_type: SurfaceType
) -> Result<SharedImageSurface, Error>
pub fn wrap( surface: ImageSurface, surface_type: SurfaceType ) -> Result<SharedImageSurface, Error>
Creates a SharedImageSurface
from a unique cairo::ImageSurface
.
§Panics
Panics if the surface format isn’t ARgb32
and if the surface is not unique, that is, its
reference count isn’t 1.
sourcepub fn copy_from_surface(surface: &ImageSurface) -> Result<Self, Error>
pub fn copy_from_surface(surface: &ImageSurface) -> Result<Self, Error>
Creates a SharedImageSurface
copying from a cairo::ImageSurface
, even if it
does not have a reference count of 1.
sourcepub fn empty(
width: i32,
height: i32,
surface_type: SurfaceType
) -> Result<Self, Error>
pub fn empty( width: i32, height: i32, surface_type: SurfaceType ) -> Result<Self, Error>
Creates an empty SharedImageSurface
of the given size and type
.
sourcepub fn into_image_surface(self) -> Result<ImageSurface, Error>
pub fn into_image_surface(self) -> Result<ImageSurface, Error>
Converts this SharedImageSurface
back into a Cairo image surface.
pub fn from_image( image: &DynamicImage, content_type: Option<&str>, mime_data: Option<Vec<u8>> ) -> Result<SharedImageSurface, Error>
sourcefn is_alpha_only(&self) -> bool
fn is_alpha_only(&self) -> bool
Returns true
if the surface contains meaningful data only in the alpha channel.
sourcepub fn surface_type(&self) -> SurfaceType
pub fn surface_type(&self) -> SurfaceType
Returns the type of this surface.
sourcepub fn get_pixel(&self, x: u32, y: u32) -> Pixel
pub fn get_pixel(&self, x: u32, y: u32) -> Pixel
Retrieves the pixel value at the given coordinates.
sourcepub fn get_pixel_by_offset(&self, offset: isize) -> Pixel
pub fn get_pixel_by_offset(&self, offset: isize) -> Pixel
Retrieves the pixel value by offset into the pixel data array.
sourcepub fn set_as_source_surface(
&self,
cr: &Context,
x: f64,
y: f64
) -> Result<(), Error>
pub fn set_as_source_surface( &self, cr: &Context, x: f64, y: f64 ) -> Result<(), Error>
Calls set_source_surface()
on the given Cairo context.
sourcepub fn to_cairo_pattern(&self) -> SurfacePattern
pub fn to_cairo_pattern(&self) -> SurfacePattern
Creates a Cairo surface pattern from the surface
sourcefn copy_surface(&self, bounds: IRect) -> Result<ImageSurface, Error>
fn copy_surface(&self, bounds: IRect) -> Result<ImageSurface, Error>
Returns a new cairo::ImageSurface
with the same contents as the one stored in this
SharedImageSurface
within the given bounds.
sourcepub fn scale_to(
&self,
width: i32,
height: i32,
bounds: IRect,
x: f64,
y: f64
) -> Result<SharedImageSurface, Error>
pub fn scale_to( &self, width: i32, height: i32, bounds: IRect, x: f64, y: f64 ) -> Result<SharedImageSurface, Error>
Scales the given surface by x
and y
into a surface width
×height
in size, clipped by
bounds
.
sourcepub fn scale(
&self,
bounds: IRect,
x: f64,
y: f64
) -> Result<(SharedImageSurface, IRect), Error>
pub fn scale( &self, bounds: IRect, x: f64, y: f64 ) -> Result<(SharedImageSurface, IRect), Error>
Returns a scaled version of a surface and bounds.
sourcepub fn extract_alpha(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
pub fn extract_alpha(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
Returns a surface with black background and alpha channel matching this surface.
sourcepub fn to_luminance_mask(&self) -> Result<SharedImageSurface, Error>
pub fn to_luminance_mask(&self) -> Result<SharedImageSurface, Error>
Returns a surface whose alpha channel for each pixel is equal to the luminance of that pixel’s unpremultiplied RGB values. The resulting surface’s RGB values are not meanignful; only the alpha channel has useful luminance data.
This is to get a mask suitable for use with cairo_mask_surface().
sourcepub fn unpremultiply(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
pub fn unpremultiply(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
Returns a surface with pre-multiplication of color values undone.
HACK: this is storing unpremultiplied pixels in an ARGB32 image surface (which is supposed to be premultiplied pixels).
sourcepub fn to_linear_rgb(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
pub fn to_linear_rgb(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
Converts the surface to the linear sRGB color space.
sourcepub fn to_srgb(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
pub fn to_srgb(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
Converts the surface to the sRGB color space.
sourcepub fn convolve<R: Dim, C: Dim, S: Storage<f64, R, C>>(
&self,
bounds: IRect,
target: (i32, i32),
kernel: &Matrix<f64, R, C, S>,
edge_mode: EdgeMode
) -> Result<SharedImageSurface, Error>
pub fn convolve<R: Dim, C: Dim, S: Storage<f64, R, C>>( &self, bounds: IRect, target: (i32, i32), kernel: &Matrix<f64, R, C, S>, edge_mode: EdgeMode ) -> Result<SharedImageSurface, Error>
Performs a convolution.
Note that kernel
is rotated 180 degrees.
The target
parameter determines the position of the kernel relative to each pixel of the
image. The value of (0, 0)
indicates that the top left pixel of the (180-degrees-rotated)
kernel corresponds to the current pixel, and the rest of the kernel is to the right and
bottom of the pixel. The value of (cols / 2, rows / 2)
centers a kernel with an odd
number of rows and columns.
§Panics
Panics if kernel
has zero rows or columns.
sourcepub fn box_blur_loop<B: BlurDirection, A: IsAlphaOnly>(
&self,
output_surface: &mut ImageSurface,
bounds: IRect,
kernel_size: usize,
target: usize
)
pub fn box_blur_loop<B: BlurDirection, A: IsAlphaOnly>( &self, output_surface: &mut ImageSurface, bounds: IRect, kernel_size: usize, target: usize )
Performs a horizontal or vertical box blur.
The target
parameter determines the position of the kernel relative to each pixel of the
image. The value of 0
indicates that the first pixel of the kernel corresponds to the
current pixel, and the rest of the kernel is to the right or bottom of the pixel. The value
of kernel_size / 2
centers a kernel with an odd size.
§Panics
Panics if kernel_size
is 0
or if target >= kernel_size
.
sourcepub fn box_blur<B: BlurDirection>(
&self,
bounds: IRect,
kernel_size: usize,
target: usize
) -> Result<SharedImageSurface, Error>
pub fn box_blur<B: BlurDirection>( &self, bounds: IRect, kernel_size: usize, target: usize ) -> Result<SharedImageSurface, Error>
Performs a horizontal or vertical box blur.
The target
parameter determines the position of the kernel relative to each pixel of the
image. The value of 0
indicates that the first pixel of the kernel corresponds to the
current pixel, and the rest of the kernel is to the right or bottom of the pixel. The value
of kernel_size / 2
centers a kernel with an odd size.
§Panics
Panics if kernel_size
is 0
or if target >= kernel_size
.
sourcepub fn flood(
&self,
bounds: IRect,
color: Color
) -> Result<SharedImageSurface, Error>
pub fn flood( &self, bounds: IRect, color: Color ) -> Result<SharedImageSurface, Error>
Fills the with a specified color.
sourcepub fn offset(
&self,
bounds: Rect,
dx: f64,
dy: f64
) -> Result<SharedImageSurface, Error>
pub fn offset( &self, bounds: Rect, dx: f64, dy: f64 ) -> Result<SharedImageSurface, Error>
Offsets the image of the specified amount.
sourcepub fn paint_image(
&self,
bounds: Rect,
image: &SharedImageSurface,
rect: Option<Rect>,
interpolation: Interpolation
) -> Result<SharedImageSurface, Error>
pub fn paint_image( &self, bounds: Rect, image: &SharedImageSurface, rect: Option<Rect>, interpolation: Interpolation ) -> Result<SharedImageSurface, Error>
Returns a new surface of the same size, with the contents of the specified image, optionally transformed to match a given box
sourcepub fn tile(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
pub fn tile(&self, bounds: IRect) -> Result<SharedImageSurface, Error>
Creates a new surface with the size and content specified in bounds
§Panics
Panics if bounds
is an empty rectangle, since SharedImageSurface
cannot
represent zero-sized images.
sourcepub fn paint_image_tiled(
&self,
bounds: IRect,
image: &SharedImageSurface,
x: i32,
y: i32
) -> Result<SharedImageSurface, Error>
pub fn paint_image_tiled( &self, bounds: IRect, image: &SharedImageSurface, x: i32, y: i32 ) -> Result<SharedImageSurface, Error>
Returns a new surface of the same size, with the contents of the specified image repeated to fill the bounds and starting from the given position.
sourcepub fn compose(
&self,
other: &SharedImageSurface,
bounds: IRect,
operator: Operator
) -> Result<SharedImageSurface, Error>
pub fn compose( &self, other: &SharedImageSurface, bounds: IRect, operator: Operator ) -> Result<SharedImageSurface, Error>
Performs the combination of two input surfaces using Porter-Duff compositing operators.
§Panics
Panics if the two surface types are not compatible.
sourcepub fn compose_arithmetic(
&self,
other: &SharedImageSurface,
bounds: IRect,
k1: f64,
k2: f64,
k3: f64,
k4: f64
) -> Result<SharedImageSurface, Error>
pub fn compose_arithmetic( &self, other: &SharedImageSurface, bounds: IRect, k1: f64, k2: f64, k3: f64, k4: f64 ) -> Result<SharedImageSurface, Error>
Performs the combination of two input surfaces.
Each pixel of the resulting image is computed using the following formula:
res = k1*i1*i2 + k2*i1 + k3*i2 + k4
§Panics
Panics if the two surface types are not compatible.
pub fn rows(&self) -> Rows<'_> ⓘ
source§impl ImageSurface<Exclusive>
impl ImageSurface<Exclusive>
pub fn new( width: i32, height: i32, surface_type: SurfaceType ) -> Result<ExclusiveImageSurface, Error>
sourcepub fn modify(
&mut self,
draw_fn: &mut dyn FnMut(&mut ImageSurfaceData<'_>, usize)
)
pub fn modify( &mut self, draw_fn: &mut dyn FnMut(&mut ImageSurfaceData<'_>, usize) )
Modify the image data
sourcepub fn draw(
&mut self,
draw_fn: &mut dyn FnMut(Context) -> Result<(), InternalRenderingError>
) -> Result<(), InternalRenderingError>
pub fn draw( &mut self, draw_fn: &mut dyn FnMut(Context) -> Result<(), InternalRenderingError> ) -> Result<(), InternalRenderingError>
Draw on the surface using cairo
pub fn rows_mut(&mut self) -> RowsMut<'_> ⓘ
Trait Implementations§
source§impl<T: Clone> Clone for ImageSurface<T>
impl<T: Clone> Clone for ImageSurface<T>
source§fn clone(&self) -> ImageSurface<T>
fn clone(&self) -> ImageSurface<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<T> RefUnwindSafe for ImageSurface<T>where
T: RefUnwindSafe,
impl<T> !Send for ImageSurface<T>
impl<T> !Sync for ImageSurface<T>
impl<T> Unpin for ImageSurface<T>where
T: Unpin,
impl<T> UnwindSafe for ImageSurface<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.