Struct glitter::image_data::Pixels
[−]
[src]
pub struct Pixels { /* fields omitted */ }
A (heap-allocated) 2D image composed of a list of pixels.
Example
// Draw a red circle with a 50px radius in a 100px * 100px black image. extern crate glitter; let width = 100; let height = 100; let radius = 50.0; let (center_x, center_y) = (width as f32/2.0, height as f32/2.0); let mut pixels = glitter::Pixels::new(width, height); for x in 0..width { for y in 0..height { let dx = center_x - x as f32; let dy = center_y - y as f32; let distance = (dx*dx + dy*dy).sqrt(); let color = if distance < radius { // The point is within the circle, so it should be red glitter::Pixel::rgb(0xFF0000) } else { // The point is outside the circle, so it should be black glitter::Pixel::rgb(0x000000) }; pixels[y][x] = color; } }
Methods
impl Pixels
[src]
pub fn new(width: usize, height: usize) -> Self
[src]
Create a new image with the desired width and height. Pixels
are initialized with Pixel::default()
.
Trait Implementations
impl Clone for Pixels
[src]
fn clone(&self) -> Pixels
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Index<usize> for Pixels
[src]
type Output = [Pixel]
The returned type after indexing.
fn index(&self, row: usize) -> &[Pixel]
[src]
Performs the indexing (container[index]
) operation.
impl IndexMut<usize> for Pixels
[src]
fn index_mut(&mut self, row: usize) -> &mut [Pixel]
[src]
Performs the mutable indexing (container[index]
) operation.
impl Image2d for Pixels
[src]
fn width(&self) -> usize
[src]
Get the width of the image, in texels.
fn height(&self) -> usize
[src]
Get the height of the image, in texels.
fn format(&self) -> ImageFormat
[src]
Get the format of the image data that is returned by the texel_bytes
method. Read more
fn texel_bytes(&self) -> &[u8]
[src]
Get the raw texel data of the image data, as a u8
slice.
impl<'a, I, P> From<I> for Pixels where
I: GenericImage<Pixel = P>,
P: Pixel<Subpixel = u8>,
[src]
I: GenericImage<Pixel = P>,
P: Pixel<Subpixel = u8>,