image.rs 1.65 KB
Newer Older
robbycerantola's avatar
robbycerantola committed
1 2 3
extern crate orbclient;
extern crate time;

robbycerantola's avatar
robbycerantola committed
4 5 6
use orbclient::{Color, Window, Renderer, EventOption};

const TIMES:i32 = 10;
robbycerantola's avatar
robbycerantola committed
7 8 9 10 11 12 13 14

fn main() {
    let (width, height) = orbclient::get_display_size().unwrap();

    let mut window = Window::new((width as i32)/4,
                                 (height as i32)/4,
                                 width/2,
                                 height/2,
robbycerantola's avatar
robbycerantola committed
15
                                 "IMAGE BENCHMARK")
robbycerantola's avatar
robbycerantola committed
16 17
                         .unwrap();

robbycerantola's avatar
robbycerantola committed
18
    window.set(Color::rgb(255,255,255));
robbycerantola's avatar
robbycerantola committed
19 20
    
    //create image data : a green square
robbycerantola's avatar
robbycerantola committed
21 22
    let data = vec![Color::rgba(100,200,10,20);200000];
    let data2 = vec![Color::rgba(200,100,10,20);200000];
robbycerantola's avatar
robbycerantola committed
23

robbycerantola's avatar
robbycerantola committed
24 25
    //draw image benchmarking 
    println!("Benchmarking implementations to draw an image on window:");
robbycerantola's avatar
robbycerantola committed
26 27
    let mut t = time::now();
    
robbycerantola's avatar
robbycerantola committed
28 29
    for _i in 0..TIMES {
        window.image(10,10,500,400, &data[..]);
robbycerantola's avatar
robbycerantola committed
30
    }
robbycerantola's avatar
robbycerantola committed
31 32 33 34
    let mut t2 = time::now();
    let dt = (t2-t)/TIMES;
    println!("     image {:?}",dt );

robbycerantola's avatar
robbycerantola committed
35
    t = time::now();
robbycerantola's avatar
robbycerantola committed
36
    
robbycerantola's avatar
robbycerantola committed
37 38
    for _i in 0..TIMES {
        window.image_fast(40,40,500,400, &data2[..]);
robbycerantola's avatar
robbycerantola committed
39
    }
robbycerantola's avatar
robbycerantola committed
40 41 42 43 44
    t2 = time::now();
    let dt2 = (t2-t)/TIMES;
    println!("image_fast {:?}",dt2);
    println!("-------------------------");
    println!("difference {:?}", dt-dt2);
robbycerantola's avatar
robbycerantola committed
45 46 47 48 49 50 51 52 53 54 55 56
    window.sync();

    'events: loop {
        for event in window.events() {
            match event.to_option() {
                EventOption::Quit(_quit_event) => break 'events,
                EventOption::Mouse(evt) => println!("At position {:?} pixel color is : {:?}",(evt.x,evt.y), window.getpixel(evt.x,evt.y )),
                event_option => println!("{:?}", event_option)
            }
        }
    }
}