Unverified Commit 498d7a46 authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub

Merge pull request #46 from robbycerantola/image_opaque

Image opaque
parents 30a4f469 8c36b0cf
......@@ -54,11 +54,19 @@ fn main() {
t = time::now();
for _i in 0..TIMES {
window.image(30,30,750,550, &data3[..]);
window.image_parallel(30,30,750,550, &data3[..]);
}
t2 = time::now();
let dt3 = (t2-t)/TIMES;
println!("image_parallel {:?}",dt3);
t = time::now();
for _i in 0..TIMES {
window.image_opaque(40,40,750,550, &data4[..]);
}
t2 = time::now();
let dt3 = (t2-t)/TIMES;
println!("image_opaque {:?}",dt3);
//println!("difference {:?}", dt-dt3);
println!("-------------------------");
......
......@@ -320,7 +320,7 @@ pub trait Renderer {
///Display an image overwriting a portion of window starting at given line : very quick!!
fn image_over (&mut self, start: i32, image_data: &[Color]) {
let start = start as usize * self.width() as usize;
let window_data = self.data_mut();
let stop = cmp::min(start + image_data.len(), window_data.len());
......@@ -329,6 +329,36 @@ pub trait Renderer {
window_data[start..stop].copy_from_slice(&image_data[..end]);
}
///Display an image using non transparent method
fn image_opaque (&mut self, start_x: i32, start_y: i32, w: u32, h: u32, image_data: &[Color]) {
let w = w as usize;
let mut h = h as usize;
let width = self.width() as usize;
let height = self.height() as usize;
let start_x = start_x as usize;
let start_y =start_y as usize;
//check boundaries
if h + start_y > height {
h = height - start_y;
}
let window_data = self.data_mut();
let offset = start_y * width + start_x;
//copy image slices to window line by line
for l in 0..h {
let start = offset + l * width;
let mut stop = start + w;
let begin = l * w;
let mut end = begin + w;
//check boundaries
if start_x + w > width {
stop = (start_y + l +1) * width - 1;
end = begin + stop - start;
}
window_data[start..stop]
.copy_from_slice(&image_data[begin..end]);
}
}
// Speed improved, but image has to be all inside of window boundary
fn image_fast (&mut self, start_x: i32, start_y: i32, w: u32, h: u32, image_data: &[Color]) {
let window_w = self.width() as usize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment