diff --git a/src/main.rs b/src/main.rs index b6b17dc..8dfbfe9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,9 @@ extern crate rscam; -use std::{env, time::Instant}; +use std::{default, env, time::Instant}; use fltk::{ app::App, - enums::ColorDepth, + enums::{Align, ColorDepth}, frame::Frame, image::RgbImage, prelude::{GroupExt, WidgetBase, WidgetExt}, @@ -23,10 +23,12 @@ fn main() { let app = App::default(); let mut camera_window = Window::new(0, 0, 400, 400, "Camera Video Output Window"); let mut camera_frame = Frame::default_fill(); + camera_frame.set_align(Align::LeftTop); camera_window.end(); camera_window.show(); - let mut color_window = Window::new(0, 400, 400, 400, "Video Output Window"); + let mut color_window = Window::new(0, 450, 400, 400, "Video Output Window"); let mut color_frame = Frame::default_fill(); + color_frame.set_align(Align::LeftTop); color_window.end(); color_window.show(); // app.run().unwrap(); @@ -77,13 +79,16 @@ fn main() { println!("L8 Frame Draw use time: {:?}", duration); }) .unwrap(); - // 尝试将部分功能移出线程 - let fltk_l_image = - RgbImage::new(l_data.as_raw(), w, h, ColorDepth::L8).unwrap(); - camera_frame.set_image(Some(fltk_l_image)); - camera_frame.redraw(); - let duration = start.elapsed(); - println!("RGB8 Frame Draw use time: {:?}", duration); + crossbeam::scope(|_| { + let fltk_l_image = + RgbImage::new(l_data.as_raw(), w, h, ColorDepth::L8).unwrap(); + camera_frame.set_image(Some(fltk_l_image)); + camera_frame.set_size(w, h); + camera_frame.redraw(); + let duration = start.elapsed(); + println!("RGB8 Frame Draw use time: {:?}", duration); + }) + .unwrap(); } Err(e) => { eprintln!("捕获错误: {}", e);