-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split SliceOperation to a new module
- Loading branch information
1 parent
869f4ef
commit f8a46cc
Showing
5 changed files
with
70 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::sync::Arc; | ||
|
||
use goo_format::File as GooFile; | ||
use image::RgbaImage; | ||
use nalgebra::Vector2; | ||
use parking_lot::{Condvar, MappedMutexGuard, Mutex, MutexGuard}; | ||
use slicer::slicer::Progress as SliceProgress; | ||
|
||
#[derive(Clone)] | ||
pub struct SliceOperation { | ||
pub progress: SliceProgress, | ||
pub result: Arc<Mutex<Option<SliceResult>>>, | ||
|
||
pub preview_image: Arc<Mutex<Option<RgbaImage>>>, | ||
preview_condvar: Arc<Condvar>, | ||
} | ||
|
||
pub struct SliceResult { | ||
pub goo: GooFile, | ||
|
||
pub slice_preview_layer: usize, | ||
pub last_preview_layer: usize, | ||
pub preview_offset: Vector2<f32>, | ||
pub preview_scale: f32, | ||
} | ||
|
||
impl SliceOperation { | ||
pub fn new(progress: SliceProgress) -> Self { | ||
Self { | ||
progress, | ||
result: Arc::new(Mutex::new(None)), | ||
preview_image: Arc::new(Mutex::new(None)), | ||
preview_condvar: Arc::new(Condvar::new()), | ||
} | ||
} | ||
|
||
pub fn needs_preview_image(&self) -> bool { | ||
self.preview_image.lock().is_none() | ||
} | ||
|
||
pub fn add_preview_image(&self, image: RgbaImage) { | ||
self.preview_image.lock().replace(image); | ||
self.preview_condvar.notify_all(); | ||
} | ||
|
||
pub fn preview_image(&self) -> MappedMutexGuard<'_, RgbaImage> { | ||
let mut preview_image = self.preview_image.lock(); | ||
while preview_image.is_none() { | ||
self.preview_condvar.wait(&mut preview_image); | ||
} | ||
|
||
MutexGuard::map(preview_image, |image| image.as_mut().unwrap()) | ||
} | ||
|
||
pub fn add_result(&self, result: SliceResult) { | ||
self.result.lock().replace(result); | ||
} | ||
|
||
pub fn result(&self) -> MutexGuard<Option<SliceResult>> { | ||
self.result.lock() | ||
} | ||
} |