https://github.com/pistondevelopers/image_buffer
Provides a buffer type to ease the work with images and different color types.
https://github.com/pistondevelopers/image_buffer
Last synced: 9 months ago
JSON representation
Provides a buffer type to ease the work with images and different color types.
- Host: GitHub
- URL: https://github.com/pistondevelopers/image_buffer
- Owner: PistonDevelopers
- License: apache-2.0
- Created: 2017-01-14T09:36:23.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-19T08:40:38.000Z (over 9 years ago)
- Last Synced: 2025-09-13T13:33:30.915Z (9 months ago)
- Language: Rust
- Homepage:
- Size: 25.4 KB
- Stars: 2
- Watchers: 49
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# image_buffer [](https://travis-ci.org/PistonDevelopers/image_buffer)
## Image buffer abstraction
Provides an image buffer and various color types ([API Documentation](https://docs.rs/image_buffer)).
### Usage
```rust
//!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]);
}
}
```