Skip to content

Commit

Permalink
fmt and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Oct 22, 2024
1 parent 55557b8 commit 0c9fa19
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
10 changes: 4 additions & 6 deletions src/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,22 +999,20 @@ fn load_jxl(img_location: &Path, frame_sender: Sender<Frame>) -> 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<RgbaImage>{
pub fn rotate_rgbaimage(di: &RgbaImage, path: &Path) -> Result<RgbaImage> {
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.")
}
}
}
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());

Expand Down
19 changes: 5 additions & 14 deletions src/texture_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ pub struct TextureWrapperManager {

impl TextureWrapperManager {
pub fn set(&mut self, tex: Option<TexWrap>, gfx: &mut Graphics) {

let mut texture_taken: Option<TexWrap> = self.current_texture.take();
if let Some(texture) = &mut texture_taken {
let mut texture_taken: Option<TexWrap> = self.current_texture.take();
if let Some(texture) = &mut texture_taken {
texture.unregister_textures(gfx);
}

Expand Down Expand Up @@ -165,20 +164,12 @@ impl TexWrap {
) -> Option<Texture>,
) -> Option<TexWrap> {
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;

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 11 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub const SUPPORTED_EXTENSIONS: &[&str] = &[
"avcs",
#[cfg(feature = "heif")]
"hif",
];
];

fn is_pixel_fully_transparent(p: &Rgba<u8>) -> bool {
p.0 == [0, 0, 0, 0]
Expand Down Expand Up @@ -639,7 +639,11 @@ pub trait ImageExt {
unimplemented!()
}

fn to_texture_with_texwrap(&self, _: &mut Graphics, _settings: &PersistentSettings) -> Option<TexWrap> {
fn to_texture_with_texwrap(
&self,
_: &mut Graphics,
_settings: &PersistentSettings,
) -> Option<TexWrap> {
unimplemented!()
}

Expand All @@ -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<TexWrap> {
fn to_texture_with_texwrap(
&self,
gfx: &mut Graphics,
settings: &PersistentSettings,
) -> Option<TexWrap> {
TexWrap::from_rgbaimage(gfx, settings, self)
}

Expand Down

0 comments on commit 0c9fa19

Please sign in to comment.