[][src]Struct rsvg_internals::surface_utils::shared_surface::ImageSurface

pub struct ImageSurface<T> {
    state: T,
    surface: ImageSurface,
    data_ptr: NonNull<u8>,
    width: i32,
    height: i32,
    stride: isize,
    surface_type: SurfaceType,
}

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::get_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

state: Tsurface: ImageSurfacedata_ptr: NonNull<u8>width: i32height: i32stride: isizesurface_type: SurfaceType

Implementations

impl<T> ImageSurface<T>[src]

pub fn width(&self) -> i32[src]

Returns the surface width.

pub fn height(&self) -> i32[src]

Returns the surface height.

pub fn stride(&self) -> isize[src]

Returns the surface stride.

impl ImageSurface<Shared>[src]

pub fn wrap(
    surface: ImageSurface,
    surface_type: SurfaceType
) -> Result<SharedImageSurface, Status>
[src]

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.

pub fn copy_from_surface(surface: &ImageSurface) -> Result<Self, Status>[src]

Creates a SharedImageSurface copying from a cairo::ImageSurface, even if it does not have a reference count of 1.

pub fn empty(
    width: i32,
    height: i32,
    surface_type: SurfaceType
) -> Result<Self, Status>
[src]

Creates an empty SharedImageSurface of the given size and type.

pub fn into_image_surface(self) -> Result<ImageSurface, Status>[src]

Converts this SharedImageSurface back into a Cairo image surface.

pub fn from_pixbuf(
    pixbuf: &Pixbuf,
    data: Option<Vec<u8>>,
    content_type: Option<&str>
) -> Result<SharedImageSurface, Status>
[src]

pub fn is_alpha_only(&self) -> bool[src]

Returns true if the surface contains meaningful data only in the alpha channel.

pub fn surface_type(&self) -> SurfaceType[src]

Returns the type of this surface.

pub fn get_pixel(&self, x: u32, y: u32) -> Pixel[src]

Retrieves the pixel value at the given coordinates.

pub fn get_pixel_by_offset(&self, offset: isize) -> Pixel[src]

Retrieves the pixel value by offset into the pixel data array.

pub fn set_as_source_surface(&self, cr: &Context, x: f64, y: f64)[src]

Calls set_source_surface() on the given Cairo context.

pub fn to_cairo_pattern(&self) -> SurfacePattern[src]

Creates a Cairo surface pattern from the surface

fn copy_surface(&self, bounds: IRect) -> Result<ImageSurface, Status>[src]

Returns a new cairo::ImageSurface with the same contents as the one stored in this SharedImageSurface within the given bounds.

pub fn scale_to(
    &self,
    width: i32,
    height: i32,
    bounds: IRect,
    x: f64,
    y: f64
) -> Result<SharedImageSurface, Status>
[src]

Scales the given surface by x and y into a surface width×height in size, clipped by bounds.

pub fn scale(
    &self,
    bounds: IRect,
    x: f64,
    y: f64
) -> Result<(SharedImageSurface, IRect), Status>
[src]

Returns a scaled version of a surface and bounds.

pub fn extract_alpha(&self, bounds: IRect) -> Result<SharedImageSurface, Status>[src]

Returns a surface with black background and alpha channel matching this surface.

pub fn to_mask(
    &self,
    opacity: UnitInterval
) -> Result<SharedImageSurface, Status>
[src]

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

pub fn unpremultiply(&self, bounds: IRect) -> Result<SharedImageSurface, Status>[src]

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

pub fn to_linear_rgb(&self, bounds: IRect) -> Result<SharedImageSurface, Status>[src]

Converts the surface to the linear sRGB color space.

pub fn to_srgb(&self, bounds: IRect) -> Result<SharedImageSurface, Status>[src]

Converts the surface to the sRGB color space.

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, Status>
[src]

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.

pub fn box_blur_loop<B: BlurDirection, A: IsAlphaOnly>(
    &self,
    output_surface: &mut ImageSurface,
    bounds: IRect,
    kernel_size: usize,
    target: usize
)
[src]

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.

pub fn box_blur<B: BlurDirection>(
    &self,
    bounds: IRect,
    kernel_size: usize,
    target: usize
) -> Result<SharedImageSurface, Status>
[src]

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.

pub fn flood(
    &self,
    bounds: IRect,
    color: RGBA,
    opacity: UnitInterval
) -> Result<SharedImageSurface, Status>
[src]

Fills the with a specified color.

pub fn offset(
    &self,
    bounds: IRect,
    dx: f64,
    dy: f64
) -> Result<SharedImageSurface, Status>
[src]

Offsets the image of the specified amount.

pub fn paint_image(
    &self,
    bounds: Rect,
    image: &SharedImageSurface,
    rect: Option<Rect>
) -> Result<SharedImageSurface, Status>
[src]

Returns a new surface of the same size, with the contents of the specified image, optionally transformed to match a given box

pub fn tile(&self, bounds: IRect) -> Result<SharedImageSurface, Status>[src]

Creates a new surface with the size and content specified in bounds

pub fn paint_image_tiled(
    &self,
    bounds: IRect,
    image: &SharedImageSurface,
    x: i32,
    y: i32
) -> Result<SharedImageSurface, Status>
[src]

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.

pub fn compose(
    &self,
    other: &SharedImageSurface,
    bounds: IRect,
    operator: Operator
) -> Result<SharedImageSurface, Status>
[src]

Performs the combination of two input surfaces using Porter-Duff compositing operators

Panics

Panics if the two surface types are not compatible.

pub fn compose_arithmetic(
    &self,
    other: &SharedImageSurface,
    bounds: IRect,
    k1: f64,
    k2: f64,
    k3: f64,
    k4: f64
) -> Result<SharedImageSurface, Status>
[src]

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[src]

impl ImageSurface<Exclusive>[src]

pub fn new(
    width: i32,
    height: i32,
    surface_type: SurfaceType
) -> Result<ExclusiveImageSurface, Status>
[src]

pub fn share(self) -> Result<SharedImageSurface, Status>[src]

pub fn get_data(&mut self) -> ImageSurfaceData[src]

Raw access to the image data as a slice

pub fn modify(&mut self, draw_fn: &mut dyn FnMut(&mut ImageSurfaceData, usize))[src]

Modify the image data

pub fn draw(
    &mut self,
    draw_fn: &mut dyn FnMut(&Context) -> Result<(), Status>
) -> Result<(), Status>
[src]

Draw on the surface using cairo

pub fn rows_mut(&mut self) -> RowsMut[src]

Trait Implementations

impl<T: Clone> Clone for ImageSurface<T>[src]

impl<T: Debug> Debug for ImageSurface<T>[src]

Auto 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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,