Skip to main content

Surface

Struct Surface 

Source
pub struct Surface<'s, S: AsRef<[P]> + AsMut<[P]>, P: Copy + Clone + Sized + Default> { /* private fields */ }
Expand description

A Surface is a pixel buffer, a size, and some underlying data describing how to blit it to a given destination Surface.

§Type aliases

There are type aliases for surface of common buffer and pixel types. Consider using them!

use blittle::{Rgba8Surface, Size};

let _ = Rgba8Surface::new(Size::new(512, 512));

Sometimes, you will need to use a buffer that isn’t a vec or is an uncommon pixel type. In those cases, see below:

§Generics

A Surface has a lifetime and two generics: Surface<'s, S, P>.

  • The lifetime is only relevant if the buffer is a reference, e.g. &mut [[u8; 3]]
  • S is the type of underlying pixel buffer. This could be, for example, a vec, or a mutable slice.
  • P is the type of pixel. S must be a buffer with elements of type P.

So, Rgba8Surface is a type alias for: Surface<'s, Vec<[u8; 4]>, [u8; 4]>

use blittle::{Size, Surface};

let _ = Surface::<'_, Vec<[u8; 4]>, [u8; 4]>::new(Size::new(512, 512));

Implementations§

Source§

impl<'s> Surface<'s, &'s mut [Zrgb], Zrgb>

Source

pub fn from_softbuffer<D: HasDisplayHandle, W: HasWindowHandle>( buffer: &'s mut Buffer<'_, D, W>, ) -> Self

Available on crate feature softbuffer only.

Convert a softbuffer Buffer to a surface.

The underlying pixel buffer is a mutable reference to buffer.

Source§

impl<'s, S: AsRef<[Zrgb]> + AsMut<[Zrgb]>> Surface<'s, S, Zrgb>

Source

pub fn blit_to_softbuffer<D: HasDisplayHandle, W: HasWindowHandle>( &self, buffer: &'s mut Buffer<'_, D, W>, ) -> Result<(), Error>

Available on crate feature softbuffer only.

Blit to a softbuffer Buffer.

Source§

impl<P: Copy + Clone + Sized + Default> Surface<'_, Vec<P>, P>

Source

pub fn new(size: Size) -> Self

Available on crate feature std only.

Get a new surface.

The position defaults to (0, 0). The underlying pixel buffer is set to the pixel’s default value (i.e. [0, 0, 0]), length size.width * size.height.

Source

pub fn new_filled(size: Size, color: P) -> Self

Available on crate feature std only.

Get a new surface with color color.

The position defaults to (0, 0). The underlying pixel buffer is set to vec![color; size.width * size.height].

Source§

impl<'s, P: Copy + Clone + Sized + Default> Surface<'s, &'s mut [P], P>

Source

pub fn new(size: Size, buffer: &'s mut [P]) -> Result<Self, Error>

Get a new surface from a mutable slice.

The position defaults to (0, 0). The underlying pixel buffer is set to the pixel’s default value (i.e. [0, 0, 0]), length size.width * size.height.

Returns an error if size.width * size.height != buffer.len()

Source§

impl<S: AsRef<[P]> + AsMut<[P]>, P: Copy + Clone + Sized + Default> Surface<'_, S, P>

Source

pub fn blit<B: AsRef<[P]> + AsMut<[P]>>( &self, other: &mut Surface<'_, B, P>, ) -> Result<(), Error>

Blit onto other.

There are three constraints for blitting to other.

  1. other must have the same pixel type as self. For example, you can’t blit an Rgba8Surface onto an L8Surface. However, other can have a different buffer type. For example, you can blit Surface<'_, Vec<u8>, u8> onto Surface<'s, &'s mut[u8], u8>

  2. You must call Self::set_position before blitting. This is because Self::set_position not only sets the position, but also defines the region in which pixels in src actually overlap with dst. If you have called Self::set_position for one destination, and you are blitting to a different destination, you must call Self::set_position again.

  3. Having called Self::set_position, some pixels of src must overlap with dst.

For example, this returns an error:

use blittle::*;

let mut src = Rgb8Surface::new(Size::new(512, 512));
let mut dst = Rgb8Surface::new(Size::new(1920, 1080));
// This works. Some, or all, of src is within dst.
src.set_position(PositionI::new(100, 100), &dst).unwrap();
src.blit(&mut dst).unwrap();

// Set a new destination.
let mut dst = Rgb8Surface::new(Size::new(64, 64));
// The position of `src` is obsolete, and is out of bounds.
assert!(src.blit(&mut dst).is_err());
Source

pub fn fill(&mut self, color: P)

Fill the surface with color.

Source

pub const fn set_position<B: AsRef<[P]> + AsMut<[P]>>( &mut self, position: PositionI, destination: &Surface<'_, B, P>, ) -> Result<RectU, Error>

Set the top-left position of the surface, relative to the surface it will blit to destination.

destination must be of the same pixel type and can be of a different buffer type. For example, if self is of type Surface<'_, Vec<[u8; 4]>, [u8; 4]>>:

  • self can set its position relative to a Surface<'s, &'s mut [u8], [u8; 4]>>
  • self can’t set its position relative to a Surface<'_, Vec<[u8; 3]>, [u8; 3]>>

This will also set the region of pixels of self.buffer that otherlap with destination.buffer.

Returns an error if the clipped blitting area is not within destination.

Source

pub const fn get_position(&self) -> Option<PositionU>

Returns the top-left position of self relative to a destination surface, or None if Self::set_position hasn’t been called.

Source

pub const fn set_area( &mut self, area: Option<RectI>, ) -> Result<Option<RectU>, Error>

Set an area within the pixel buffer to blit.

You must call Self::set_position before calling this.

If area is None, then the entirety of this surface will blit (this is the default behavior).

If area is out of bounds of self’s underlying buffer, this will return an error. Otherwise, this returns a RectU describing the clipped area (i.e. which pixels within the area overlap with dst).

use blittle::*;

let mut src = Rgb8Surface::new(Size::new(512, 512));
let dst = Rgb8Surface::new(Size::new(1920, 1080));
// Set the position.
src.set_position(PositionI::new(0, 0), &dst).unwrap();
// Blit only the pixels in this region.
src.set_area(Some(RectI { position: PositionI::new(1, 3), size: Size::new(60, 80)})).unwrap();
// Reset the area. Now, all pixels will blit.
src.set_area(None).unwrap();
// Invalid area.
assert!(src.set_area(Some(RectI { position: PositionI::new(-2000, -2000), size: Size::new(60, 80)})).is_err());
Source

pub fn rows(&self) -> impl Iterator<Item = &[P]>

Iterate through the pixel buffer per-row, top to bottom.

Source

pub fn rows_mut(&mut self) -> impl Iterator<Item = &mut [P]>

Iterate through the pixel buffer per-row, top to bottom.

Source

pub fn get_pixel_checked(&self, position: PositionU) -> Result<P, Error>

Returns the color of the pixel at position.

Returns an error if position is out of bounds.

use blittle::*;

let src = Rgb8Surface::new(Size::new(64, 64));
// Get the pixel at this position.
let _ = src.get_pixel_checked(PositionU::new(3, 15));
// This position is out of bounds.
assert!(src.get_pixel_checked(PositionU::new(102, 15)).is_err());
Source

pub fn get_pixel_unchecked(&self, position: PositionU) -> P

Returns the color of the pixel at position.

use blittle::*;

let src = Rgb8Surface::new(Size::new(64, 64));
let _ = src.get_pixel_unchecked(PositionU::new(3, 15));
Source

pub fn set_pixel_checked( &mut self, position: PositionU, color: P, ) -> Result<(), Error>

Set the color of the pixel at position.

Returns an error if position is out of bounds.

use blittle::*;

let mut src = Rgb8Surface::new(Size::new(64, 64));
// Set the pixel at this position.
src.set_pixel_checked(PositionU::new(3, 15), [50, 0, 220]).unwrap();
// This pixel is out of bounds.
assert!(src.set_pixel_checked(PositionU::new(120, 15), [50, 0, 220]).is_err());
Source

pub fn set_pixel_unchecked(&mut self, position: PositionU, color: P)

Set the color of the pixel at position.

use blittle::*;

let mut src = Rgb8Surface::new(Size::new(64, 64));
src.set_pixel_unchecked(PositionU::new(3, 15), [50, 0, 220]);
Source

pub const fn get_index(&self, x: usize, y: usize) -> usize

Convert (x, y) coordinates into an index value within the underlying pixel buffer.

Source

pub const fn reset(&mut self)

Unset all internal data related to blitting to the destination surface.

This function can be a useful safeguard when blitting to multiple surfaces.

Source

pub const fn get_size(&self) -> Size

Returns the size of the surface.

Source

pub fn buffer(&self) -> &[P]

Returns the underlying pixel buffer.

Source

pub fn buffer_mut(&mut self) -> &mut [P]

Returns the underlying mutable pixel buffer.

Source§

impl<S: AsRef<[P]> + AsMut<[P]>, P: Copy + Clone + Sized + Default + Zeroable + Pod> Surface<'_, S, P>

Source

pub fn bytes(&self) -> &[u8]

Available on crate feature bytes only.

Returns the underlying mutable buffer as bytes.

Source

pub fn bytes_mut(&mut self) -> &mut [u8]

Available on crate feature bytes only.

Returns the underlying mutable buffer as bytes.

Trait Implementations§

Source§

impl<'s, S: Clone + AsRef<[P]> + AsMut<[P]>, P: Clone + Copy + Clone + Sized + Default> Clone for Surface<'s, S, P>

Source§

fn clone(&self) -> Surface<'s, S, P>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: AsRef<[[f32; 2]]> + AsMut<[[f32; 2]]>> From<&Surface<'_, S, [f32; 2]>> for Surface<'_, Vec<[f32; 4]>, [f32; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 2]]> + AsMut<[[f32; 2]]>> From<&Surface<'_, S, [f32; 2]>> for Surface<'_, Vec<[u8; 2]>, [u8; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 2]]> + AsMut<[[f32; 2]]>> From<&Surface<'_, S, [f32; 2]>> for Surface<'_, Vec<[u8; 3]>, [u8; 3]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 2]]> + AsMut<[[f32; 2]]>> From<&Surface<'_, S, [f32; 2]>> for Surface<'_, Vec<[u8; 4]>, [u8; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 2]]> + AsMut<[[f32; 2]]>> From<&Surface<'_, S, [f32; 2]>> for Surface<'_, Vec<Zrgb>, Zrgb>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, [f32; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 2]]> + AsMut<[[f32; 2]]>> From<&Surface<'_, S, [f32; 2]>> for Surface<'_, Vec<f32>, f32>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 2]]> + AsMut<[[f32; 2]]>> From<&Surface<'_, S, [f32; 2]>> for Surface<'_, Vec<u8>, u8>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 4]]> + AsMut<[[f32; 4]]>> From<&Surface<'_, S, [f32; 4]>> for Surface<'_, Vec<[f32; 2]>, [f32; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 4]]> + AsMut<[[f32; 4]]>> From<&Surface<'_, S, [f32; 4]>> for Surface<'_, Vec<[u8; 2]>, [u8; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 4]]> + AsMut<[[f32; 4]]>> From<&Surface<'_, S, [f32; 4]>> for Surface<'_, Vec<[u8; 3]>, [u8; 3]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 4]]> + AsMut<[[f32; 4]]>> From<&Surface<'_, S, [f32; 4]>> for Surface<'_, Vec<[u8; 4]>, [u8; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 4]]> + AsMut<[[f32; 4]]>> From<&Surface<'_, S, [f32; 4]>> for Surface<'_, Vec<Zrgb>, Zrgb>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, [f32; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 4]]> + AsMut<[[f32; 4]]>> From<&Surface<'_, S, [f32; 4]>> for Surface<'_, Vec<f32>, f32>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 4]]> + AsMut<[[f32; 4]]>> From<&Surface<'_, S, [f32; 4]>> for Surface<'_, Vec<u8>, u8>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [f32; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> From<&Surface<'_, S, [u8; 2]>> for Surface<'_, Vec<[f32; 2]>, [f32; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> From<&Surface<'_, S, [u8; 2]>> for Surface<'_, Vec<[f32; 4]>, [f32; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> From<&Surface<'_, S, [u8; 2]>> for Surface<'_, Vec<[u8; 3]>, [u8; 3]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> From<&Surface<'_, S, [u8; 2]>> for Surface<'_, Vec<[u8; 4]>, [u8; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> From<&Surface<'_, S, [u8; 2]>> for Surface<'_, Vec<Zrgb>, Zrgb>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, [u8; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> From<&Surface<'_, S, [u8; 2]>> for Surface<'_, Vec<f32>, f32>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> From<&Surface<'_, S, [u8; 2]>> for Surface<'_, Vec<u8>, u8>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 2]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 3]]> + AsMut<[[u8; 3]]>> From<&Surface<'_, S, [u8; 3]>> for Surface<'_, Vec<[f32; 2]>, [f32; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 3]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 3]]> + AsMut<[[u8; 3]]>> From<&Surface<'_, S, [u8; 3]>> for Surface<'_, Vec<[f32; 4]>, [f32; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 3]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 3]]> + AsMut<[[u8; 3]]>> From<&Surface<'_, S, [u8; 3]>> for Surface<'_, Vec<[u8; 2]>, [u8; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 3]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 3]]> + AsMut<[[u8; 3]]>> From<&Surface<'_, S, [u8; 3]>> for Surface<'_, Vec<[u8; 4]>, [u8; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 3]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 3]]> + AsMut<[[u8; 3]]>> From<&Surface<'_, S, [u8; 3]>> for Surface<'_, Vec<Zrgb>, Zrgb>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, [u8; 3]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 3]]> + AsMut<[[u8; 3]]>> From<&Surface<'_, S, [u8; 3]>> for Surface<'_, Vec<f32>, f32>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 3]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 3]]> + AsMut<[[u8; 3]]>> From<&Surface<'_, S, [u8; 3]>> for Surface<'_, Vec<u8>, u8>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 3]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 4]]> + AsMut<[[u8; 4]]>> From<&Surface<'_, S, [u8; 4]>> for Surface<'_, Vec<[f32; 2]>, [f32; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 4]]> + AsMut<[[u8; 4]]>> From<&Surface<'_, S, [u8; 4]>> for Surface<'_, Vec<[f32; 4]>, [f32; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 4]]> + AsMut<[[u8; 4]]>> From<&Surface<'_, S, [u8; 4]>> for Surface<'_, Vec<[u8; 2]>, [u8; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 4]]> + AsMut<[[u8; 4]]>> From<&Surface<'_, S, [u8; 4]>> for Surface<'_, Vec<[u8; 3]>, [u8; 3]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 4]]> + AsMut<[[u8; 4]]>> From<&Surface<'_, S, [u8; 4]>> for Surface<'_, Vec<Zrgb>, Zrgb>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, [u8; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 4]]> + AsMut<[[u8; 4]]>> From<&Surface<'_, S, [u8; 4]>> for Surface<'_, Vec<f32>, f32>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[u8; 4]]> + AsMut<[[u8; 4]]>> From<&Surface<'_, S, [u8; 4]>> for Surface<'_, Vec<u8>, u8>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, [u8; 4]>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[Zrgb]> + AsMut<[Zrgb]>> From<&Surface<'_, S, Zrgb>> for Surface<'_, Vec<[f32; 2]>, [f32; 2]>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, Zrgb>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[Zrgb]> + AsMut<[Zrgb]>> From<&Surface<'_, S, Zrgb>> for Surface<'_, Vec<[u8; 2]>, [u8; 2]>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, Zrgb>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[Zrgb]> + AsMut<[Zrgb]>> From<&Surface<'_, S, Zrgb>> for Surface<'_, Vec<[u8; 3]>, [u8; 3]>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, Zrgb>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[Zrgb]> + AsMut<[Zrgb]>> From<&Surface<'_, S, Zrgb>> for Surface<'_, Vec<[u8; 4]>, [u8; 4]>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, Zrgb>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[Zrgb]> + AsMut<[Zrgb]>> From<&Surface<'_, S, Zrgb>> for Surface<'_, Vec<f32>, f32>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, Zrgb>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[Zrgb]> + AsMut<[Zrgb]>> From<&Surface<'_, S, Zrgb>> for Surface<'_, Vec<u8>, u8>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, Zrgb>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[f32]> + AsMut<[f32]>> From<&Surface<'_, S, f32>> for Surface<'_, Vec<[f32; 2]>, [f32; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, f32>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[f32]> + AsMut<[f32]>> From<&Surface<'_, S, f32>> for Surface<'_, Vec<[f32; 4]>, [f32; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, f32>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[f32]> + AsMut<[f32]>> From<&Surface<'_, S, f32>> for Surface<'_, Vec<[u8; 2]>, [u8; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, f32>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[f32]> + AsMut<[f32]>> From<&Surface<'_, S, f32>> for Surface<'_, Vec<[u8; 3]>, [u8; 3]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, f32>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[f32]> + AsMut<[f32]>> From<&Surface<'_, S, f32>> for Surface<'_, Vec<[u8; 4]>, [u8; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, f32>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[f32]> + AsMut<[f32]>> From<&Surface<'_, S, f32>> for Surface<'_, Vec<Zrgb>, Zrgb>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, f32>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[f32]> + AsMut<[f32]>> From<&Surface<'_, S, f32>> for Surface<'_, Vec<u8>, u8>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, f32>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[u8]> + AsMut<[u8]>> From<&Surface<'_, S, u8>> for Surface<'_, Vec<[f32; 2]>, [f32; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, u8>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[u8]> + AsMut<[u8]>> From<&Surface<'_, S, u8>> for Surface<'_, Vec<[f32; 4]>, [f32; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, u8>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[u8]> + AsMut<[u8]>> From<&Surface<'_, S, u8>> for Surface<'_, Vec<[u8; 2]>, [u8; 2]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, u8>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[u8]> + AsMut<[u8]>> From<&Surface<'_, S, u8>> for Surface<'_, Vec<[u8; 3]>, [u8; 3]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, u8>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[u8]> + AsMut<[u8]>> From<&Surface<'_, S, u8>> for Surface<'_, Vec<[u8; 4]>, [u8; 4]>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, u8>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[u8]> + AsMut<[u8]>> From<&Surface<'_, S, u8>> for Surface<'_, Vec<Zrgb>, Zrgb>

Available on crate features std and softbuffer only.
Source§

fn from(value: &Surface<'_, S, u8>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[u8]> + AsMut<[u8]>> From<&Surface<'_, S, u8>> for Surface<'_, Vec<f32>, f32>

Available on crate feature std only.
Source§

fn from(value: &Surface<'_, S, u8>) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<[[f32; 2]]> + AsMut<[[f32; 2]]>> PixelConverter<[f32; 2]> for Surface<'_, S, [f32; 2]>

Source§

fn pixel_to_l8(pixel: &[f32; 2]) -> u8

Source§

fn pixel_to_la8(pixel: &[f32; 2]) -> [u8; 2]

Source§

fn pixel_to_l32(pixel: &[f32; 2]) -> f32

Source§

fn pixel_to_la32(pixel: &[f32; 2]) -> [f32; 2]

Source§

fn pixel_to_rgb8(pixel: &[f32; 2]) -> [u8; 3]

Source§

fn pixel_to_rgba8(pixel: &[f32; 2]) -> [u8; 4]

Source§

fn pixel_to_rgba32(pixel: &[f32; 2]) -> [f32; 4]

Source§

fn pixel_to_zrgb(pixel: &[f32; 2]) -> Zrgb

Available on crate feature softbuffer only.
Source§

impl<S: AsRef<[[f32; 4]]> + AsMut<[[f32; 4]]>> PixelConverter<[f32; 4]> for Surface<'_, S, [f32; 4]>

Source§

fn pixel_to_l8(pixel: &[f32; 4]) -> u8

Source§

fn pixel_to_la8(pixel: &[f32; 4]) -> [u8; 2]

Source§

fn pixel_to_l32(pixel: &[f32; 4]) -> f32

Source§

fn pixel_to_la32(pixel: &[f32; 4]) -> [f32; 2]

Source§

fn pixel_to_rgb8(pixel: &[f32; 4]) -> [u8; 3]

Source§

fn pixel_to_rgba8(pixel: &[f32; 4]) -> [u8; 4]

Source§

fn pixel_to_rgba32(pixel: &[f32; 4]) -> [f32; 4]

Source§

fn pixel_to_zrgb(pixel: &[f32; 4]) -> Zrgb

Available on crate feature softbuffer only.
Source§

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> PixelConverter<[u8; 2]> for Surface<'_, S, [u8; 2]>

Source§

fn pixel_to_l8(pixel: &[u8; 2]) -> u8

Source§

fn pixel_to_la8(pixel: &[u8; 2]) -> [u8; 2]

Source§

fn pixel_to_l32(pixel: &[u8; 2]) -> f32

Source§

fn pixel_to_la32(pixel: &[u8; 2]) -> [f32; 2]

Source§

fn pixel_to_rgb8(pixel: &[u8; 2]) -> [u8; 3]

Source§

fn pixel_to_rgba8(pixel: &[u8; 2]) -> [u8; 4]

Source§

fn pixel_to_rgba32(pixel: &[u8; 2]) -> [f32; 4]

Source§

fn pixel_to_zrgb(pixel: &[u8; 2]) -> Zrgb

Available on crate feature softbuffer only.
Source§

impl<S: AsRef<[[u8; 3]]> + AsMut<[[u8; 3]]>> PixelConverter<[u8; 3]> for Surface<'_, S, [u8; 3]>

Source§

fn pixel_to_l8(pixel: &[u8; 3]) -> u8

Source§

fn pixel_to_la8(pixel: &[u8; 3]) -> [u8; 2]

Source§

fn pixel_to_l32(pixel: &[u8; 3]) -> f32

Source§

fn pixel_to_la32(pixel: &[u8; 3]) -> [f32; 2]

Source§

fn pixel_to_rgb8(pixel: &[u8; 3]) -> [u8; 3]

Source§

fn pixel_to_rgba8(pixel: &[u8; 3]) -> [u8; 4]

Source§

fn pixel_to_rgba32(pixel: &[u8; 3]) -> [f32; 4]

Source§

fn pixel_to_zrgb(pixel: &[u8; 3]) -> Zrgb

Available on crate feature softbuffer only.
Source§

impl<S: AsRef<[[u8; 4]]> + AsMut<[[u8; 4]]>> PixelConverter<[u8; 4]> for Surface<'_, S, [u8; 4]>

Source§

fn pixel_to_l8(pixel: &[u8; 4]) -> u8

Source§

fn pixel_to_la8(pixel: &[u8; 4]) -> [u8; 2]

Source§

fn pixel_to_l32(pixel: &[u8; 4]) -> f32

Source§

fn pixel_to_la32(pixel: &[u8; 4]) -> [f32; 2]

Source§

fn pixel_to_rgb8(pixel: &[u8; 4]) -> [u8; 3]

Source§

fn pixel_to_rgba8(pixel: &[u8; 4]) -> [u8; 4]

Source§

fn pixel_to_rgba32(pixel: &[u8; 4]) -> [f32; 4]

Source§

fn pixel_to_zrgb(pixel: &[u8; 4]) -> Zrgb

Available on crate feature softbuffer only.
Source§

impl<S: AsRef<[Zrgb]> + AsMut<[Zrgb]>> PixelConverter<Zrgb> for Surface<'_, S, Zrgb>

Available on crate feature softbuffer only.
Source§

fn pixel_to_l8(pixel: &Zrgb) -> u8

Source§

fn pixel_to_la8(pixel: &Zrgb) -> [u8; 2]

Source§

fn pixel_to_l32(pixel: &Zrgb) -> f32

Source§

fn pixel_to_la32(pixel: &Zrgb) -> [f32; 2]

Source§

fn pixel_to_rgb8(pixel: &Zrgb) -> [u8; 3]

Source§

fn pixel_to_rgba8(pixel: &Zrgb) -> [u8; 4]

Source§

fn pixel_to_rgba32(pixel: &Zrgb) -> [f32; 4]

Source§

fn pixel_to_zrgb(pixel: &Zrgb) -> Zrgb

Source§

impl<S: AsRef<[f32]> + AsMut<[f32]>> PixelConverter<f32> for Surface<'_, S, f32>

Source§

fn pixel_to_l8(pixel: &f32) -> u8

Source§

fn pixel_to_la8(pixel: &f32) -> [u8; 2]

Source§

fn pixel_to_l32(pixel: &f32) -> f32

Source§

fn pixel_to_la32(pixel: &f32) -> [f32; 2]

Source§

fn pixel_to_rgb8(pixel: &f32) -> [u8; 3]

Source§

fn pixel_to_rgba8(pixel: &f32) -> [u8; 4]

Source§

fn pixel_to_rgba32(pixel: &f32) -> [f32; 4]

Source§

fn pixel_to_zrgb(pixel: &f32) -> Zrgb

Available on crate feature softbuffer only.
Source§

impl<S: AsRef<[u8]> + AsMut<[u8]>> PixelConverter<u8> for Surface<'_, S, u8>

Source§

fn pixel_to_l8(pixel: &u8) -> u8

Source§

fn pixel_to_la8(pixel: &u8) -> [u8; 2]

Source§

fn pixel_to_l32(pixel: &u8) -> f32

Source§

fn pixel_to_la32(pixel: &u8) -> [f32; 2]

Source§

fn pixel_to_rgb8(pixel: &u8) -> [u8; 3]

Source§

fn pixel_to_rgba8(pixel: &u8) -> [u8; 4]

Source§

fn pixel_to_rgba32(pixel: &u8) -> [f32; 4]

Source§

fn pixel_to_zrgb(pixel: &u8) -> Zrgb

Available on crate feature softbuffer only.
Source§

impl<S: AsRef<[[u8; 2]]> + AsMut<[[u8; 2]]>> Png<S, [u8; 2]> for Surface<'_, S, [u8; 2]>

Available on crate feature png only.
Source§

fn get_png_color_type() -> ColorType

Returns the expected .png color type.
Source§

fn write_png<Pa: AsRef<Path>>( surface: &Surface<'_, S, P>, path: Pa, ) -> Result<(), Error>

Write to a .png file. Read more
Source§

fn read_png<'s, B: BufRead + Seek>( png: B, ) -> Result<Surface<'s, Vec<P>, P>, Error>

Read from a .png file. Read more
Source§

impl<S: AsRef<[[u8; 3]]> + AsMut<[[u8; 3]]>> Png<S, [u8; 3]> for Surface<'_, S, [u8; 3]>

Available on crate feature png only.
Source§

fn get_png_color_type() -> ColorType

Returns the expected .png color type.
Source§

fn write_png<Pa: AsRef<Path>>( surface: &Surface<'_, S, P>, path: Pa, ) -> Result<(), Error>

Write to a .png file. Read more
Source§

fn read_png<'s, B: BufRead + Seek>( png: B, ) -> Result<Surface<'s, Vec<P>, P>, Error>

Read from a .png file. Read more
Source§

impl<S: AsRef<[[u8; 4]]> + AsMut<[[u8; 4]]>> Png<S, [u8; 4]> for Surface<'_, S, [u8; 4]>

Available on crate feature png only.
Source§

fn get_png_color_type() -> ColorType

Returns the expected .png color type.
Source§

fn write_png<Pa: AsRef<Path>>( surface: &Surface<'_, S, P>, path: Pa, ) -> Result<(), Error>

Write to a .png file. Read more
Source§

fn read_png<'s, B: BufRead + Seek>( png: B, ) -> Result<Surface<'s, Vec<P>, P>, Error>

Read from a .png file. Read more
Source§

impl<S: AsRef<[u8]> + AsMut<[u8]>> Png<S, u8> for Surface<'_, S, u8>

Available on crate feature png only.
Source§

fn get_png_color_type() -> ColorType

Returns the expected .png color type.
Source§

fn write_png<Pa: AsRef<Path>>( surface: &Surface<'_, S, P>, path: Pa, ) -> Result<(), Error>

Write to a .png file. Read more
Source§

fn read_png<'s, B: BufRead + Seek>( png: B, ) -> Result<Surface<'s, Vec<P>, P>, Error>

Read from a .png file. Read more

Auto Trait Implementations§

§

impl<'s, S, P> Freeze for Surface<'s, S, P>
where S: Freeze,

§

impl<'s, S, P> RefUnwindSafe for Surface<'s, S, P>

§

impl<'s, S, P> Send for Surface<'s, S, P>
where S: Send, P: Sync,

§

impl<'s, S, P> Sync for Surface<'s, S, P>
where S: Sync, P: Sync,

§

impl<'s, S, P> Unpin for Surface<'s, S, P>
where S: Unpin,

§

impl<'s, S, P> UnsafeUnpin for Surface<'s, S, P>
where S: UnsafeUnpin,

§

impl<'s, S, P> UnwindSafe for Surface<'s, S, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more