image: Do not guess bg color for opaque images
In theory this feature made sense to see a black square but in practice it seems mostly confusing. Closes #186 Part-of: <https://gitlab.gnome.org/GNOME/Incubator/loupe/-/merge_requests/235>
This commit is contained in:
parent
c1422cf728
commit
0c2bdbd736
1 changed files with 10 additions and 1 deletions
|
|
@ -1798,6 +1798,7 @@ impl LpImage {
|
|||
let default_color = Self::default_background_color();
|
||||
|
||||
gio::spawn_blocking(move || {
|
||||
let mut has_transparency = false;
|
||||
let mut bytes_iter = bytes.iter();
|
||||
// Number of transparent pixels
|
||||
let mut completely_transparent = 0;
|
||||
|
|
@ -1810,7 +1811,10 @@ impl LpImage {
|
|||
let Some(b) = bytes_iter.next() else { break 'img; };
|
||||
let Some(a) = bytes_iter.next() else { break 'img; };
|
||||
|
||||
// 70% transparency
|
||||
if *a < 255 {
|
||||
has_transparency = true;
|
||||
}
|
||||
|
||||
if *a == 0 {
|
||||
completely_transparent += 1;
|
||||
} else {
|
||||
|
|
@ -1835,6 +1839,11 @@ impl LpImage {
|
|||
}
|
||||
}
|
||||
|
||||
if !has_transparency {
|
||||
log::debug!("This image does not have transparency");
|
||||
return Some(default_color);
|
||||
}
|
||||
|
||||
let n_pixels = texture.width() * texture.height();
|
||||
|
||||
let part_bad_contrast = if completely_transparent < n_pixels {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue