image_buffer 0.2.0

Provides a buffer type to ease the work with images and different color types.
Documentation
  • Coverage
  • 87.23%
    41 out of 47 items documented1 out of 1 items with examples
  • Size
  • Source code size: 53.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 16.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • PistonDevelopers/image_buffer
    2 0 2
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nwin

image_buffer Build Status

Image buffer abstraction

Provides an image buffer and various color types (API Documentation).

Usage

//!An example of generating Julia fractals.
extern crate num;
extern crate image_buffer;

use num::complex::Complex;

fn main() {
    let max_iterations = 256u16;

    let imgx = 800;
    let imgy = 800;

    let scalex = 4.0 / imgx as f32;
    let scaley = 4.0 / imgy as f32;

    // Create a new ImgBuf with width: imgx and height: imgy
    let mut imgbuf = image_buffer::ImageBuffer::new(imgx, imgy);

    // Iterate over the coordiantes and pixels of the image
    for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
        let cy = y as f32 * scaley - 2.0;
        let cx = x as f32 * scalex - 2.0;

        let mut z = Complex::new(cx, cy);
        let c = Complex::new(-0.4, 0.6);

        let mut i = 0;

        for t in (0..max_iterations) {
            if z.norm() > 2.0 {
                break
            }
            z = z * z + c;
            i = t;
        }

        // Create an 8bit pixel of type Luma and value i
        // and assign in to the pixel at position (x, y)
        *pixel = image::Gray([i as u8]);

    }
}