From 0c9fa19553bbd2df732d3c45c860d91765e17793 Mon Sep 17 00:00:00 2001 From: Johann Woelper Date: Tue, 22 Oct 2024 21:55:24 +0200 Subject: [PATCH] fmt and cleanup --- src/image_loader.rs | 10 ++++------ src/main.rs | 16 ++++++++-------- src/texture_wrapper.rs | 19 +++++-------------- src/ui.rs | 7 ++++--- src/utils.rs | 14 +++++++++++--- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/image_loader.rs b/src/image_loader.rs index bd5566fd..28500c34 100644 --- a/src/image_loader.rs +++ b/src/image_loader.rs @@ -999,22 +999,20 @@ fn load_jxl(img_location: &Path, frame_sender: Sender) -> Result<()> { } #[allow(unused)] -pub fn rotate_dynimage(di: &mut DynamicImage, path: &Path) -> Result<()>{ +pub fn rotate_dynimage(di: &mut DynamicImage, path: &Path) -> Result<()> { let mut decoder = ImageReader::open(path)?.into_decoder()?; di.apply_orientation(decoder.orientation()?); Ok(()) } - - -pub fn rotate_rgbaimage(di: &RgbaImage, path: &Path) -> Result{ +pub fn rotate_rgbaimage(di: &RgbaImage, path: &Path) -> Result { let mut decoder = ImageReader::open(path)?.into_decoder()?; let orientation = decoder.orientation()?; if orientation != image::metadata::Orientation::NoTransforms { - let mut dynimage = DynamicImage::ImageRgba8(di.clone()); + let mut dynimage = DynamicImage::ImageRgba8(di.clone()); dynimage.apply_orientation(orientation); Ok(dynimage.to_rgba8()) } else { bail!("This image needs no rotation.") } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index a8fe52d7..a1001c7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -935,15 +935,17 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O if tex.width() as u32 == img.width() && tex.height() as u32 == img.height() { img.update_texture_with_texwrap(gfx, tex); } else { - state - .current_texture - .set(img.to_texture_with_texwrap(gfx, &state.persistent_settings), gfx); + state.current_texture.set( + img.to_texture_with_texwrap(gfx, &state.persistent_settings), + gfx, + ); } } else { debug!("Setting texture"); - state - .current_texture - .set(img.to_texture_with_texwrap(gfx, &state.persistent_settings), gfx); + state.current_texture.set( + img.to_texture_with_texwrap(gfx, &state.persistent_settings), + gfx, + ); } match &state.persistent_settings.current_channel { @@ -1056,8 +1058,6 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O info_ui(ctx, state, gfx); } - - state.pointer_over_ui = ctx.is_pointer_over_area(); // ("using pointer {}", ctx.is_using_pointer()); diff --git a/src/texture_wrapper.rs b/src/texture_wrapper.rs index bc3e9194..32f02606 100644 --- a/src/texture_wrapper.rs +++ b/src/texture_wrapper.rs @@ -29,9 +29,8 @@ pub struct TextureWrapperManager { impl TextureWrapperManager { pub fn set(&mut self, tex: Option, gfx: &mut Graphics) { - - let mut texture_taken: Option = self.current_texture.take(); - if let Some(texture) = &mut texture_taken { + let mut texture_taken: Option = self.current_texture.take(); + if let Some(texture) = &mut texture_taken { texture.unregister_textures(gfx); } @@ -165,20 +164,12 @@ impl TexWrap { ) -> Option, ) -> Option { const MAX_PIXEL_COUNT: usize = 8192 * 8192; - - let im_w = image.width(); - let im_h = image.height(); - - if im_w<1{ + let (im_w, im_h) = image.dimensions(); + if im_w < 1 || im_h < 1 { error!("Image width smaller than 1!"); return None; } - if im_h<1{ - error!("Image height smaller than 1!"); - return None; - } - let im_pixel_count = (im_w * im_h) as usize; let allow_mipmap = im_pixel_count < MAX_PIXEL_COUNT; @@ -323,7 +314,7 @@ impl TexWrap { let y = ya.max(0).min(self.height() as i32 - 1); //Div by zero possible, never allow zero sized textures! - let x_idx = x / self.col_translation as i32; + let x_idx = x / self.col_translation as i32; let y_idx = y / self.row_translation as i32; let tex_idx = (y_idx * self.col_count as i32 + x_idx).min(self.texture_array.len() as i32 - 1); diff --git a/src/ui.rs b/src/ui.rs index c9e26de7..e1bc0c08 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -2392,9 +2392,10 @@ pub fn main_menu(ui: &mut Ui, state: &mut OculanteState, app: &mut App, gfx: &mu ); } ColorChannel::Rgba => { - state - .current_texture - .set(img.to_texture_with_texwrap(gfx, &state.persistent_settings), gfx); + state.current_texture.set( + img.to_texture_with_texwrap(gfx, &state.persistent_settings), + gfx, + ); } _ => { state.current_texture.set( diff --git a/src/utils.rs b/src/utils.rs index f4a90c50..4bc6b670 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -87,7 +87,7 @@ pub const SUPPORTED_EXTENSIONS: &[&str] = &[ "avcs", #[cfg(feature = "heif")] "hif", - ]; +]; fn is_pixel_fully_transparent(p: &Rgba) -> bool { p.0 == [0, 0, 0, 0] @@ -639,7 +639,11 @@ pub trait ImageExt { unimplemented!() } - fn to_texture_with_texwrap(&self, _: &mut Graphics, _settings: &PersistentSettings) -> Option { + fn to_texture_with_texwrap( + &self, + _: &mut Graphics, + _settings: &PersistentSettings, + ) -> Option { unimplemented!() } @@ -666,7 +670,11 @@ impl ImageExt for RgbaImage { Vector2::new(self.width() as f32, self.height() as f32) } - fn to_texture_with_texwrap(&self, gfx: &mut Graphics, settings: &PersistentSettings) -> Option { + fn to_texture_with_texwrap( + &self, + gfx: &mut Graphics, + settings: &PersistentSettings, + ) -> Option { TexWrap::from_rgbaimage(gfx, settings, self) }