Trait retro_pixel::ReadableImage[][src]

pub trait ReadableImage<P>: Index<(usize, usize), Output = P> {
    fn width(&self) -> usize;
fn height(&self) -> usize;
fn pitch(&self) -> isize;
fn as_ptr(&self) -> *const P; fn get(&self, loc: (usize, usize)) -> Option<&P> { ... }
fn slice(&self, r: Range<(usize, usize)>) -> ImageSlice<P> { ... }
fn iter(&self) -> ImageRefIter<P> { ... }
fn to_vecimage(&self) -> VecImage<P>
    where
        Self: Sized,
        P: Default + Clone
, { ... }
fn upscale(&self, scale: usize) -> VecImage<P>
    where
        P: Copy + Default
, { ... } }

Trait for anything that can be read as if it was an image.

An image is here defined as being a height long series of "pixel" slices (each width in length) that are evenly spaced out by a particular pitch value (the offset from the start of one slice to the start of the next slice). The type of data held in a pixel often doesn't matter, most operations don't examine the data itself. Things that do examine the data use "where" bounds so that they are always appropriate to the pixel type.

Required Methods

Can't exceed isize::MAX

Can't exceed isize::MAX

Offset from the start of one row to the start of the next row.

Raw const pointer to the data.

Provided Methods

Performs an optional indexing by reference, gives None for out of bounds.

Grabs out a sub-slice of the data.

Panics

If either end of the requested portion is out of bounds.

use retro_pixel::*;
let vi: VecImage<u8> = VecImage::new(10,15);

let whole_slice = vi.slice( (0,0) .. (vi.width(),vi.height()) );
assert_eq!(whole_slice.width(), vi.width());
assert_eq!(whole_slice.height(), vi.height());
assert_eq!(whole_slice.pitch(), vi.pitch());
assert_eq!(whole_slice.as_ptr(), vi.as_ptr());

let partial_slice = whole_slice.slice( (3,3) .. (7,8) );
assert_eq!(partial_slice.width(), 4);
assert_eq!(partial_slice.height(), 5);
assert_eq!(partial_slice.pitch(), vi.pitch());
assert_eq!(partial_slice.as_ptr(), unsafe { vi.as_ptr().offset(3 + (3 * vi.pitch())) } );
Important traits for ImageRefIter<'a, P>

Lets you iterate any image by reference.

This is like to_owned, you get your own version of the data.

The actual ToOwned trait has some conflicts because we're not using normal references, so we just have this instead.

use retro_pixel::*;
let mut source: VecImage<u8> = VecImage::new(5,5);
let a = source.to_vecimage();
let b = source.slice((0,0)..(5,5)).to_vecimage();
let c = source.slice_mut((0,0)..(5,5)).to_vecimage();

assert_eq!(a, b);
assert_eq!(a, c);

Scales up into a new VecImage by the given amount.

use retro_pixel::*;
let mut source = VecImage::new(2,2);
source[(0,1)] = 5u8;

let scaled = source.upscale(2);

for (x,y,&p) in scaled.iter() {
  match (x,y) {
    (0,2) | (0,3) | (1,2) | (1,3) => assert_eq!(p, 5),
    _ => assert_eq!(p, 0),
  }
}

Implementors