diff options
| author | Sakarias Johansson <sakarias.johansson@goodbyekansas.com> | 2023-03-20 21:24:13 +0100 |
|---|---|---|
| committer | Sakarias Johansson <sakariasjohansson@hotmail.com> | 2023-03-20 21:33:38 +0100 |
| commit | 60139fe0629a2680160549b525c7cb18bb43be13 (patch) | |
| tree | c4edad604528b394edc8f1e7b9ab27b550734eb0 /racer-tracer/src/image_action | |
| parent | 7d32f05f6123dc12ab099cf337f9abe137750e43 (diff) | |
| download | racer-tracer-60139fe0629a2680160549b525c7cb18bb43be13.tar.gz racer-tracer-60139fe0629a2680160549b525c7cb18bb43be13.tar.xz racer-tracer-60139fe0629a2680160549b525c7cb18bb43be13.zip | |
🐛 Fix png action reset
When aborting during the render while the png action was selected it
would abort it and start another one.
Diffstat (limited to 'racer-tracer/src/image_action')
| -rw-r--r-- | racer-tracer/src/image_action/png.rs | 88 |
1 files changed, 47 insertions, 41 deletions
diff --git a/racer-tracer/src/image_action/png.rs b/racer-tracer/src/image_action/png.rs index c43e863..4887d3d 100644 --- a/racer-tracer/src/image_action/png.rs +++ b/racer-tracer/src/image_action/png.rs @@ -13,52 +13,58 @@ impl ImageAction for SavePng { fn action( &self, screen_buffer: &RwLock<Vec<u32>>, - _event: &SignalEvent, + event: &SignalEvent, config: &Config, ) -> Result<(), TracerError> { - screen_buffer - .read() - .map_err(|e| TracerError::FailedToAcquireLock(e.to_string())) - .map(|buf| { - // Convert ARGB8 to RGBA8 - buf.iter() - .map(|v| { - let a: u32 = (v >> 24) & 0xff; - let r: u32 = (v >> 16) & 0xff; - let g: u32 = (v >> 8) & 0xff; - let b: u32 = v & 0xff; + let status = event.status(); + event.reset(); + if status { + Ok(()) + } else { + screen_buffer + .read() + .map_err(|e| TracerError::FailedToAcquireLock(e.to_string())) + .map(|buf| { + // Convert ARGB8 to RGBA8 + buf.iter() + .map(|v| { + let a: u32 = (v >> 24) & 0xff; + let r: u32 = (v >> 16) & 0xff; + let g: u32 = (v >> 8) & 0xff; + let b: u32 = v & 0xff; - (r << 24) | (g << 16) | (b << 8) | a - }) - .flat_map(|val| val.to_be_bytes()) - .collect::<Vec<u8>>() - }) - .and_then(|buf| match &config.image_output_dir { - Some(image_dir) => { - println!("Saving image..."); - let mut sha = Sha256::new(); + (r << 24) | (g << 16) | (b << 8) | a + }) + .flat_map(|val| val.to_be_bytes()) + .collect::<Vec<u8>>() + }) + .and_then(|buf| match &config.image_output_dir { + Some(image_dir) => { + println!("Saving image..."); + let mut sha = Sha256::new(); - sha.update(buf.as_slice()); + sha.update(buf.as_slice()); - let mut file_path = PathBuf::from(image_dir); - file_path.push(format!("{:X}.png", sha.finalize())); + let mut file_path = PathBuf::from(image_dir); + file_path.push(format!("{:X}.png", sha.finalize())); - img::save_buffer( - file_path.as_path(), - buf.as_slice(), - config.screen.width as u32, - config.screen.height as u32, - img::ColorType::Rgba8, - ) - .map_err(|e| { - let error = e.to_string(); - TracerError::ImageSave(error) - }) - .map(|_| { - println!("Saved image to: {}", file_path.to_string_lossy()); - }) - } - None => Ok(()), - }) + img::save_buffer( + file_path.as_path(), + buf.as_slice(), + config.screen.width as u32, + config.screen.height as u32, + img::ColorType::Rgba8, + ) + .map_err(|e| { + let error = e.to_string(); + TracerError::ImageSave(error) + }) + .map(|_| { + println!("Saved image to: {}", file_path.to_string_lossy()); + }) + } + None => Ok(()), + }) + } } } |
