metadata: Report if image can be transparent

This feature was not implemented before and would always return true,
triggering a line detection for the background color in large JPEG
images.

Part-of: <https://gitlab.gnome.org/GNOME/loupe/-/merge_requests/442>
This commit is contained in:
Sophie Herold 2024-08-05 19:01:23 +02:00
parent daadbda4ee
commit 1ea4a3ad5d
2 changed files with 7 additions and 5 deletions

View file

@ -69,7 +69,7 @@ impl Glycin {
let frame = image.next_frame().await?;
let mut metadata: Metadata = Metadata::default();
metadata.set_frame_info(frame.details().clone());
metadata.set_frame_metadata(&frame);
updater.send(DecoderUpdate::Metadata(Box::new(metadata)));
tiles.set_original_dimensions((frame.width() as u32, frame.height() as u32));

View file

@ -25,6 +25,7 @@ mod file;
mod gps;
pub use file::FileInfo;
use glycin::{Frame, MemoryFormat};
use glycin::{FrameDetails, ImageInfoDetails};
pub use gps::GPSLocation;
@ -39,6 +40,7 @@ pub struct Metadata {
file_info: Option<FileInfo>,
image_info: Option<glycin::ImageInfoDetails>,
frame_info: Option<FrameDetails>,
memory_format: Option<MemoryFormat>,
}
impl std::fmt::Debug for Metadata {
@ -80,8 +82,9 @@ impl Metadata {
self.image_info = Some(image_info);
}
pub fn set_frame_info(&mut self, frame_info: FrameDetails) {
self.frame_info = Some(frame_info);
pub fn set_frame_metadata(&mut self, frame: &Frame) {
self.frame_info = Some(frame.details().clone());
self.memory_format = Some(frame.memory_format());
}
pub fn set_file_info(&mut self, file_info: FileInfo) {
@ -144,8 +147,7 @@ impl Metadata {
}
pub fn is_potentially_transparent(&self) -> bool {
// TODO: Implement again
true
self.memory_format.is_some_and(|x| x.has_alpha())
}
pub fn transformations_applied(&self) -> bool {