Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove preview workaround in gui for webp/heif #921

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 8 additions & 59 deletions czkawka_gui/src/connect_things/connect_button_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ use gtk4::prelude::*;
use gtk4::{Align, CheckButton, Image, ListStore, Orientation, ScrolledWindow, TreeIter, TreeModel, TreePath, TreeSelection, Widget};
use image::DynamicImage;

#[cfg(feature = "heif")]
use czkawka_core::common::get_dynamic_image_from_heic;
use czkawka_core::common::HEIC_EXTENSIONS;

use crate::flg;
use crate::gui_structs::gui_data::GuiData;
use crate::help_functions::{
Expand Down Expand Up @@ -355,62 +351,15 @@ fn generate_cache_for_results(vector_with_path: Vec<(String, String, TreePath)>)
let big_img = Image::new();

let mut pixbuf = get_pixbuf_from_dynamic_image(&DynamicImage::new_rgb8(1, 1)).unwrap();
let name_lowercase = name.to_lowercase();
let is_heic = HEIC_EXTENSIONS.iter().any(|extension| name_lowercase.ends_with(extension));
let is_webp = name.to_lowercase().ends_with(".webp");

if is_heic || is_webp {
#[allow(clippy::never_loop)]
'czystka: loop {
#[cfg(feature = "heif")]
if is_heic {
match get_dynamic_image_from_heic(&full_path) {
Ok(t) => {
match get_pixbuf_from_dynamic_image(&t) {
Ok(t) => {
pixbuf = t;
}
Err(e) => {
println!("Failed to open image {full_path}, reason {e}");
}
};
}
Err(e) => {
println!("Failed to open image {full_path}, reason {e}");
}
};
break 'czystka;
}
if is_webp {
match image::open(&full_path) {
Ok(t) => {
match get_pixbuf_from_dynamic_image(&t) {
Ok(t) => {
pixbuf = t;
}
Err(e) => {
println!("Failed to open image {full_path}, reason {e}");
}
};
}
Err(e) => {
println!("Failed to open image {full_path}, reason {e}");
}
};
break 'czystka;
}
break 'czystka;

match Pixbuf::from_file(&full_path) {
Ok(t) => {
pixbuf = t;
}
} else {
match Pixbuf::from_file(&full_path) {
Ok(t) => {
pixbuf = t;
}
Err(e) => {
println!("Failed to open image {full_path}, reason {e}");
}
};
}
Err(e) => {
println!("Failed to open image {full_path}, reason {e}");
}
};

#[allow(clippy::never_loop)]
loop {
Expand Down
87 changes: 13 additions & 74 deletions czkawka_gui/src/initialize_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use gtk4::gdk_pixbuf::InterpType;
use gtk4::prelude::*;
use gtk4::{CheckButton, Image, SelectionMode, TextView, TreeView};

#[cfg(feature = "heif")]
use czkawka_core::common::get_dynamic_image_from_heic;
use czkawka_core::common::{HEIC_EXTENSIONS, IMAGE_RS_EXTENSIONS, RAW_IMAGE_EXTENSIONS};
use czkawka_core::similar_images::SIMILAR_VALUES;
use czkawka_core::similar_videos::MAX_TOLERANCE;
Expand Down Expand Up @@ -574,85 +572,26 @@ fn show_preview(
}
}

let is_heic;
let is_webp;
if let Some(extension) = Path::new(&name).extension() {
let extension = format!(".{}", extension.to_string_lossy().to_lowercase());
is_heic = HEIC_EXTENSIONS.contains(&extension.as_str());
is_webp = ".webp" == extension;
if !RAW_IMAGE_EXTENSIONS.contains(&extension.as_str()) && !IMAGE_RS_EXTENSIONS.contains(&extension.as_str()) && !is_heic {
if !RAW_IMAGE_EXTENSIONS.contains(&extension.as_str()) && !IMAGE_RS_EXTENSIONS.contains(&extension.as_str()) && !HEIC_EXTENSIONS.contains(&extension.as_str()) {
break 'dir;
}
} else {
break 'dir;
}
let mut pixbuf = if is_heic || is_webp {
let image = if is_heic {
#[cfg(feature = "heif")]
match get_dynamic_image_from_heic(file_name) {
Ok(t) => t,
Err(e) => {
add_text_to_text_view(
text_view_errors,
flg!(
"preview_image_opening_failure",
generate_translation_hashmap(vec![("name", file_name.to_string()), ("reason", e.to_string())])
)
.as_str(),
);
break 'dir;
}
}

#[cfg(not(feature = "heif"))]
panic!("")
} else if is_webp {
match image::open(file_name) {
Ok(t) => t,
Err(e) => {
add_text_to_text_view(
text_view_errors,
flg!(
"preview_image_opening_failure",
generate_translation_hashmap(vec![("name", file_name.to_string()), ("reason", e.to_string())])
)
.as_str(),
);
break 'dir;
}
}
} else {
panic!("");
};

match get_pixbuf_from_dynamic_image(&image) {
Ok(t) => t,
Err(e) => {
add_text_to_text_view(
text_view_errors,
flg!(
"preview_image_opening_failure",
generate_translation_hashmap(vec![("name", file_name.to_string()), ("reason", e.to_string())])
)
.as_str(),
);
break 'dir;
}
}
} else {
match Pixbuf::from_file(file_name) {
Ok(pixbuf) => pixbuf,
Err(e) => {
add_text_to_text_view(
text_view_errors,
flg!(
"preview_image_opening_failure",
generate_translation_hashmap(vec![("name", file_name.to_string()), ("reason", e.to_string())])
)
.as_str(),
);
break 'dir;
}
let mut pixbuf = match Pixbuf::from_file(file_name) {
Ok(pixbuf) => pixbuf,
Err(e) => {
add_text_to_text_view(
text_view_errors,
flg!(
"preview_image_opening_failure",
generate_translation_hashmap(vec![("name", file_name.to_string()), ("reason", e.to_string())])
)
.as_str(),
);
break 'dir;
}
};

Expand Down
6 changes: 4 additions & 2 deletions instructions/Compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ If you only want the terminal version without a GUI, just skip all the packages

FFmpeg is not included here because it is not needed to build - it is dynamically loaded.

Webp and heif pixbuf are needed to show preview of image files with this extensions.

Support for heif images is optional and require to install libheif library.


Expand All @@ -18,7 +20,7 @@ Support for heif images is optional and require to install libheif library.
```shell
sudo apt install -y curl git build-essential # Needed by Rust update tool
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Download the latest stable Rust
sudo apt install -y libgtk-4-dev
sudo apt install -y libgtk-4-dev webp-pixbuf-loader heif-gdk-pixbuf
```

#### Fedora / CentOS / Rocky Linux
Expand All @@ -33,7 +35,7 @@ You need to install Rust via Homebrew, GTK Libraries and optionally heif library
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install rustup
rustup-init
brew install gtk4 adwaita-icon-theme librsvg libheif
brew install gtk4 adwaita-icon-theme librsvg libheif webp-pixbuf-loader
```

### Windows
Expand Down