Commit 5d9d35a5 authored by robbycerantola's avatar robbycerantola

Merge branch 'fast_image' of https://github.com/robbycerantola/orbclient into fast_image

parents 3e214c62 a5d4820e
......@@ -3,7 +3,7 @@ extern crate time;
use orbclient::{Color, Window, Renderer, EventOption};
const TIMES:i32 = 10;
const TIMES:i32 = 100;
fn main() {
//let (width, height) = orbclient::get_display_size().unwrap();
......@@ -20,17 +20,18 @@ fn main() {
//create image data : a green square
let data = vec![Color::rgba(100,200,10,20);412500];
let data2 = vec![Color::rgba(200,100,10,20);412500];
let data3 = vec![Color::rgba(10,100,200,20);800];
//draw image benchmarking
println!("Benchmarking implementations to draw an image on window:");
let mut t = time::now();
for _i in 0..TIMES {
window.image(10,10,750,550, &data[..]);
window.image_legacy(10,10,750,550, &data[..]);
}
let mut t2 = time::now();
let dt = (t2-t)/TIMES;
println!(" image {:?}",dt );
println!("image_legacy {:?}",dt );
t = time::now();
......@@ -42,6 +43,17 @@ fn main() {
println!("image_fast {:?}",dt2);
println!("-------------------------");
println!("difference {:?}", dt-dt2);
t = time::now();
for _i in 0..TIMES {
window.image(0,0,800,1, &data3[..]);
}
t2 = time::now();
let dt3 = (t2-t)/TIMES;
println!("image wrapper {:?}",dt3);
window.sync();
'events: loop {
......
......@@ -294,8 +294,17 @@ pub trait Renderer {
}
/// Display an image
// TODO: Improve speed
fn image(&mut self, start_x: i32, start_y: i32, w: u32, h: u32, data: &[Color]) {
//check if image is inside window
if (w + start_x as u32) > self.width() {
self.image_legacy(start_x, start_y, w, h, data);
}else{
self.image_fast(start_x, start_y, w, h, data);
}
}
// TODO: Improve speed
fn image_legacy(&mut self, start_x: i32, start_y: i32, w: u32, h: u32, data: &[Color]) {
let mut i = 0;
for y in start_y..start_y + h as i32 {
for x in start_x..start_x + w as i32 {
......@@ -308,7 +317,7 @@ pub trait Renderer {
}
// 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]) {
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;
let window_len = self.data().len();
let data = self.data_mut();
......@@ -316,10 +325,10 @@ pub trait Renderer {
let start_x = start_x as usize;
let start_y = start_y as usize;
for i in 0..image_data.len() {
let y0 = i/w;
for i in 0..w * h as usize {
let y0 = i / w;
let y = y0 + start_y;
let x = start_x + i-(y0*w) ;
let x = start_x + i - (y0 * w);
let window_index = y * window_w + x;
if window_index < window_len {
let new = image_data[i].data;
......
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