Use texture buffer to get the image across the thread barrier
This commit is contained in:
parent
70a8b41578
commit
0c9cf5ac24
|
@ -175,7 +175,7 @@ where
|
||||||
|
|
||||||
previous_sample = sample;
|
previous_sample = sample;
|
||||||
|
|
||||||
if progress % LINES_PER_SECOND == 0 {
|
if progress % PIXELS_PER_LINE == 0 {
|
||||||
if !progress_update((progress as f32) / (step * 10) as f32, img.clone()) {
|
if !progress_update((progress as f32) / (step * 10) as f32, img.clone()) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
47
src/ui.rs
47
src/ui.rs
|
@ -17,7 +17,7 @@ enum DecoderRunState {
|
||||||
|
|
||||||
struct DecoderJobState {
|
struct DecoderJobState {
|
||||||
progress: f32,
|
progress: f32,
|
||||||
image: Option<image::GrayImage>,
|
texture: Option<(egui::TextureId, egui::Vec2)>,
|
||||||
run_state: DecoderRunState,
|
run_state: DecoderRunState,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ impl Default for DecoderJobState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
progress: 0.0,
|
progress: 0.0,
|
||||||
image: None,
|
texture: None,
|
||||||
run_state: DecoderRunState::DONE,
|
run_state: DecoderRunState::DONE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,6 @@ pub struct DecoderApp {
|
||||||
input_path: String,
|
input_path: String,
|
||||||
output_path: String,
|
output_path: String,
|
||||||
decoding_state: Arc<Mutex<DecoderJobState>>,
|
decoding_state: Arc<Mutex<DecoderJobState>>,
|
||||||
texture: Option<(egui::TextureId, egui::Vec2)>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DecoderApp {
|
impl Default for DecoderApp {
|
||||||
|
@ -51,7 +50,6 @@ impl Default for DecoderApp {
|
||||||
input_path: "input.wav".to_owned(),
|
input_path: "input.wav".to_owned(),
|
||||||
output_path: "output.png".to_owned(),
|
output_path: "output.png".to_owned(),
|
||||||
decoding_state: Arc::new(Mutex::new(DecoderJobState::default())),
|
decoding_state: Arc::new(Mutex::new(DecoderJobState::default())),
|
||||||
texture: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +75,6 @@ impl epi::App for DecoderApp {
|
||||||
input_path,
|
input_path,
|
||||||
output_path,
|
output_path,
|
||||||
decoding_state,
|
decoding_state,
|
||||||
texture,
|
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -140,7 +137,22 @@ impl epi::App for DecoderApp {
|
||||||
let mut state = decoding_state.lock().unwrap();
|
let mut state = decoding_state.lock().unwrap();
|
||||||
|
|
||||||
state.progress = progress;
|
state.progress = progress;
|
||||||
state.image = Some(image);
|
//state.image = Some(image);
|
||||||
|
|
||||||
|
let image = image::DynamicImage::ImageLuma8(image);
|
||||||
|
let size = [image.width() as _, image.height() as _];
|
||||||
|
let pixels = image.into_rgba8();
|
||||||
|
let epi_img = epi::Image::from_rgba_unmultiplied(
|
||||||
|
size,
|
||||||
|
pixels.as_flat_samples().as_slice(),
|
||||||
|
);
|
||||||
|
let size = egui::Vec2::new(size[0] as f32, size[1] as f32);
|
||||||
|
|
||||||
|
if let Some((old_texture, _)) = state.texture {
|
||||||
|
frame.free_texture(old_texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
state.texture = Some((frame.alloc_texture(epi_img), size));
|
||||||
|
|
||||||
frame.request_repaint();
|
frame.request_repaint();
|
||||||
|
|
||||||
|
@ -168,27 +180,8 @@ impl epi::App for DecoderApp {
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
if let Some(image) = state.image.take() {
|
if let Some((texture, size)) = state.texture {
|
||||||
let image = image::DynamicImage::ImageLuma8(image);
|
ui.image(texture, size);
|
||||||
let size = [image.width() as _, image.height() as _];
|
|
||||||
let pixels = image.into_rgba8();
|
|
||||||
let epi_img = epi::Image::from_rgba_unmultiplied(
|
|
||||||
size,
|
|
||||||
pixels.as_flat_samples().as_slice(),
|
|
||||||
);
|
|
||||||
let size = egui::Vec2::new(size[0] as f32, size[1] as f32);
|
|
||||||
|
|
||||||
if let Some((old_texture, _)) = texture {
|
|
||||||
frame.free_texture(*old_texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
*texture = Some((frame.alloc_texture(epi_img), size));
|
|
||||||
|
|
||||||
state.image = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some((texture, size)) = texture {
|
|
||||||
ui.image(*texture, *size);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue