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

Webp preview workaround remove #923

Merged
merged 1 commit into from
Feb 26, 2023
Merged
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
21 changes: 1 addition & 20 deletions czkawka_gui/src/connect_things/connect_button_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,8 @@ fn generate_cache_for_results(vector_with_path: Vec<(String, String, TreePath)>)
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 {
if is_heic {
#[allow(clippy::never_loop)]
'czystka: loop {
#[cfg(feature = "heif")]
Expand All @@ -381,24 +380,6 @@ fn generate_cache_for_results(vector_with_path: Vec<(String, String, TreePath)>)
};
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;
}
} else {
Expand Down
56 changes: 18 additions & 38 deletions czkawka_gui/src/initialize_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,56 +575,33 @@ 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 {
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;
}
let mut pixbuf = if cfg!(feature = "heif") && is_heic {
#[cfg(feature = "heif")]
let image = 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;
}
} else {
panic!("");
};

#[cfg(feature = "heif")]
match get_pixbuf_from_dynamic_image(&image) {
Ok(t) => t,
Err(e) => {
Expand All @@ -639,6 +616,9 @@ fn show_preview(
break 'dir;
}
}

#[cfg(not(feature = "heif"))]
unreachable!()
} else {
match Pixbuf::from_file(file_name) {
Ok(pixbuf) => pixbuf,
Expand Down