This commit is contained in:
faineance 2015-03-14 21:08:55 +00:00
commit cf64ee3733

View file

@ -1,7 +1,6 @@
use std::vec::from_elem;
use std::path::posix::{Path};
use std::io::File;
use std::path::Path;
use std::fs::File;
pub struct RGB {
r: u8
,g: u8
@ -9,23 +8,23 @@ pub struct RGB {
}
pub struct PPM {
height: uint
,width: uint
,data: ~[u8]
height: usize
,width: usize
,data: [u8]
}
impl PPM {
pub fn new(height: uint, width: uint) -> PPM {
pub fn new(height: usize, width: usize) -> PPM {
let size = 3 * height * width;
let buffer = from_elem(size, 0u8);
PPM{height: height, width: width, data: buffer}
}
fn buffer_size(&self) -> uint {
fn buffer_size(&self) -> usize {
3 * self.height * self.width
}
fn get_offset(&self, x: uint, y: uint) -> Option<uint> {
fn get_offset(&self, x: usize, y: usize) -> Option<usize> {
let offset = (y * self.width * 3) + (x * 3);
if(offset < self.buffer_size()){
Some(offset)
@ -34,19 +33,19 @@ impl PPM {
}
}
pub fn get_pixel(&self, x: uint, y: uint) -> Option<RGB> {
pub fn get_pixel(&self, x: usize, y: usize) -> Option<RGB> {
match self.get_offset(x, y) {
Some(offset) => {
let r = self.data[offset];
let g = self.data[offset + 1];
let b = self.data[offset + 2];
Some(RGB{r, g, b})
Some(RGB{r: r, g: g, b: b})
},
None => None
}
}
pub fn set_pixel(&mut self, x: uint, y: uint, color: RGB) -> bool {
pub fn set_pixel(&mut self, x: usize, y: usize, color: RGB) -> bool {
match self.get_offset(x, y) {
Some(offset) => {
self.data[offset] = color.r;