Skip to main content

Pixfmt

Struct Pixfmt 

Source
pub struct Pixfmt<T> { /* private fields */ }
Expand description

Pixel Format Wrapper around raw pixel component data

Implementations§

Source§

impl<T> Pixfmt<T>
where Pixfmt<T>: PixelDraw,

Source

pub fn new(width: usize, height: usize) -> Self

Create new Pixel Format of width * height * bpp

Allocates memory of width * height * bpp

Source

pub fn size(&self) -> usize

Size of Rendering Buffer in bytes; width * height * bpp

Source

pub fn clear(&mut self)

Clear the Image

All color components are set to 255, including alpha if present

use agg::{Source,Pixfmt,Rgb8,Rgba8};

// Pixfmt with Rgb8, not Alpha Component
let mut pix = Pixfmt::<Rgb8>::new(2,2);
pix.clear();
let empty = Rgba8 { r:255, g:255, b:255, a:255};
assert_eq!(pix.get((0,0)), empty);
assert_eq!(pix.get((0,1)), empty);
assert_eq!(pix.get((1,0)), empty);
assert_eq!(pix.get((1,1)), empty);

// Pixfmt with Rgba8, including Alpha Component
let mut pix = Pixfmt::<Rgb8>::new(2,2);
pix.clear();
let empty = Rgba8 { r:255, g:255, b:255, a:255};
assert_eq!(pix.get((0,0)), empty);
assert_eq!(pix.get((0,1)), empty);
assert_eq!(pix.get((1,0)), empty);
assert_eq!(pix.get((1,1)), empty);
Source

pub fn copy_pixel<C: Color>(&mut self, x: usize, y: usize, c: C)

Copies the Color c to pixel at (x,y)

Locations outside of the region are igorned

use agg::{Source,Pixfmt,Rgba8};

let mut pix = Pixfmt::<Rgba8>::new(1,2);
let black = Rgba8::black();
pix.copy_pixel(0,1, black);
assert_eq!(pix.get((0,0)), Rgba8{r:0, g:0, b:0, a:0});
assert_eq!(pix.get((0,1)), black);

pix.copy_pixel(10,10, black); // Ignored, outside of range
Source

pub fn copy_hline<C: Color>(&mut self, x: usize, y: usize, n: usize, c: C)

Copies the Color c to pixels from (x,y) to (x+n-1,y)

Locations outside of the region are ignored

use agg::{Source,Pixfmt,Rgb8,Rgba8};

let mut pix = Pixfmt::<Rgb8>::new(10,1);
let black = Rgba8::black();
pix.copy_hline(0,0,10, black);
assert_eq!(pix.get((0,0)), black);
assert_eq!(pix.get((1,0)), black);
assert_eq!(pix.get((9,0)), black);

pix.copy_hline(1,1,10, black); // Ignored, outside of range
Source

pub fn copy_vline<C: Color>(&mut self, x: usize, y: usize, n: usize, c: C)

Copies the Color c to pixels from (x,y) to (x,y+n-1)

Locations outside of the region are ignored

use agg::{Source,Pixfmt,Rgba8,Rgba32};

let mut pix = Pixfmt::<Rgba32>::new(1,10);
let black  = Rgba32::new(0.,0.,0.,1.);
pix.copy_vline(0,0,10, black);

let black8 = Rgba8::from_trait(black); // pix.get() returns Rgba8
assert_eq!(pix.get((0,0)), black8);
assert_eq!(pix.get((0,1)), black8);
assert_eq!(pix.get((0,9)), black8);

pix.copy_vline(1,1,10, black); // Ignored, outside of range
Source

pub fn line_sp_aa(&mut self, x1: f64, y1: f64, x2: f64, y2: f64, c: Rgb8)

👎Deprecated since 0.1.0:

please use path_storage and friends instead

Draw a line from (x1,y1) to (x2,y2) of color c

Uses Xiaolin Wu’s line drawing algorithm which include Anti-Aliasing

Source

pub fn line_sp(&mut self, x1: f64, y1: f64, x2: f64, y2: f64, c: Rgb8)

👎Deprecated since 0.1.0:

please use path_storage and friends instead

Draw a line from (x1,y1) to (x2,y2) of color c using a subpixel algorithm

Line is Aliased (not-anti-aliased)

Source

pub fn line(&mut self, x1: f64, y1: f64, x2: f64, y2: f64, c: Rgb8)

👎Deprecated since 0.1.0:

please use path_storage and friends instead

Draw a line from (x1,y1) to (x2,y2) of color c

Uses Bresenham’s line drawing algorithm

Source§

impl Pixfmt<Gray8>

Source

pub fn raw(&self, id: (usize, usize)) -> Gray8

Source§

impl Pixfmt<Rgb8>

Source

pub fn raw(&self, id: (usize, usize)) -> Rgb8

Trait Implementations§

Source§

impl<T: Debug> Debug for Pixfmt<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Pixel for Pixfmt<Gray8>

Source§

fn height(&self) -> usize

Height of rendering buffer in pixels

Source§

fn width(&self) -> usize

Width of rendering buffer in pixels

Source§

fn set<C: Color>(&mut self, id: (usize, usize), c: C)

Source§

fn cover_mask() -> u64

Source§

fn bpp() -> usize

Source§

fn blend_pix<C: Color>(&mut self, id: (usize, usize), c: C, cover: u64)

Source§

impl Pixel for Pixfmt<Rgb8>

Source§

fn height(&self) -> usize

Height of rendering buffer in pixels

Source§

fn width(&self) -> usize

Width of rendering buffer in pixels

Source§

fn set<C: Color>(&mut self, id: (usize, usize), c: C)

Source§

fn bpp() -> usize

Source§

fn cover_mask() -> u64

Source§

fn blend_pix<C: Color>(&mut self, id: (usize, usize), c: C, cover: u64)

Source§

impl Pixel for Pixfmt<Rgba32>

Source§

fn height(&self) -> usize

Height of rendering buffer in pixels

Source§

fn width(&self) -> usize

Width of rendering buffer in pixels

Source§

fn set<C: Color>(&mut self, id: (usize, usize), c: C)

Source§

fn bpp() -> usize

Source§

fn cover_mask() -> u64

Source§

fn blend_pix<C: Color>(&mut self, _id: (usize, usize), _c: C, _cover: u64)

Source§

impl Pixel for Pixfmt<Rgba8>

Source§

fn height(&self) -> usize

Height of rendering buffer in pixels

Source§

fn width(&self) -> usize

Width of rendering buffer in pixels

Source§

fn bpp() -> usize

Source§

fn cover_mask() -> u64

Source§

fn set<C: Color>(&mut self, id: (usize, usize), c: C)

Source§

fn blend_pix<C: Color>(&mut self, id: (usize, usize), c: C, cover: u64)

Source§

impl Pixel for Pixfmt<Rgba8pre>

Source§

fn height(&self) -> usize

Height of rendering buffer in pixels

Source§

fn width(&self) -> usize

Width of rendering buffer in pixels

Source§

fn set<C: Color>(&mut self, id: (usize, usize), c: C)

Source§

fn bpp() -> usize

Source§

fn cover_mask() -> u64

Source§

fn blend_pix<C: Color>(&mut self, id: (usize, usize), c: C, cover: u64)

Source§

impl<T> PixelData for Pixfmt<T>

Access Pixeldata from a Pixfmt

Source§

fn pixeldata(&self) -> &[u8]

Source§

impl<T> PixelDraw for Pixfmt<T>
where Pixfmt<T>: Pixel,

Source§

fn fill<C: Color>(&mut self, color: C)

Fill the data with the specified color
Source§

fn copy_or_blend_pix<C: Color>(&mut self, id: (usize, usize), color: C)

Copy or blend a pixel at id with color Read more
Source§

fn copy_or_blend_pix_with_cover<C: Color>( &mut self, id: (usize, usize), color: C, cover: u64, )

Copy or blend a pixel at id with color and a cover Read more
Source§

fn blend_hline<C: Color>( &mut self, x: i64, y: i64, len: i64, color: C, cover: u64, )

Copy or Blend a single color from (x,y) to (x+len-1,y) with cover
Source§

fn blend_solid_hspan<C: Color>( &mut self, x: i64, y: i64, len: i64, color: C, covers: &[u64], )

Blend a single color from (x,y) to (x+len-1,y) with collection of covers
Source§

fn blend_vline<C: Color>(&mut self, x: i64, y: i64, len: i64, c: C, cover: u64)

Copy or Blend a single color from (x,y) to (x,y+len-1) with cover
Source§

fn blend_solid_vspan<C: Color>( &mut self, x: i64, y: i64, len: i64, c: C, covers: &[u64], )

Blend a single color from (x,y) to (x,y+len-1) with collection of covers
Source§

fn blend_color_hspan<C: Color>( &mut self, x: i64, y: i64, len: i64, colors: &[C], covers: &[u64], cover: u64, )

Blend a collection of colors from (x,y) to (x+len-1,y) with either a collection of covers or a single cover Read more
Source§

fn blend_color_vspan<C: Color>( &mut self, x: i64, y: i64, len: i64, colors: &[C], covers: &[u64], cover: u64, )

Blend a collection of colors from (x,y) to (x,y+len-1) with either a collection of covers or a single cover Read more
Source§

impl Source for Pixfmt<Rgb8>

Source§

fn get(&self, id: (usize, usize)) -> Rgba8

Source§

impl Source for Pixfmt<Rgba32>

Source§

fn get(&self, id: (usize, usize)) -> Rgba8

Source§

impl Source for Pixfmt<Rgba8>

Source§

fn get(&self, id: (usize, usize)) -> Rgba8

Source§

impl Source for Pixfmt<Rgba8pre>

Source§

fn get(&self, id: (usize, usize)) -> Rgba8

Auto Trait Implementations§

§

impl<T> Freeze for Pixfmt<T>

§

impl<T> RefUnwindSafe for Pixfmt<T>
where T: RefUnwindSafe,

§

impl<T> Send for Pixfmt<T>
where T: Send,

§

impl<T> Sync for Pixfmt<T>
where T: Sync,

§

impl<T> Unpin for Pixfmt<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Pixfmt<T>

§

impl<T> UnwindSafe for Pixfmt<T>
where T: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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