From 30fdcff7758b89086d191bb7d5d62d8c2d741601 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Sat, 27 Jul 2024 13:20:15 +0100 Subject: [PATCH] move exif_metadata to Decoder trait - way better user API this way --- src/codecs/jpeg/decoder.rs | 14 ++++++-------- src/image.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/codecs/jpeg/decoder.rs b/src/codecs/jpeg/decoder.rs index 01c8214607..c558df1ed5 100644 --- a/src/codecs/jpeg/decoder.rs +++ b/src/codecs/jpeg/decoder.rs @@ -52,14 +52,6 @@ impl JpegDecoder { phantom: PhantomData, }) } - - /// Returns the raw [Exif](https://en.wikipedia.org/wiki/Exif) chunk, if it is present. - /// A third-party crate such as [`kamadak-exif`](https://docs.rs/kamadak-exif/) is required to actually parse it. - pub fn exif_metadata(&mut self) -> ImageResult>> { - let mut decoder = zune_jpeg::JpegDecoder::new(&self.input); - decoder.decode_headers().map_err(ImageError::from_jpeg)?; - Ok(decoder.exif().cloned()) - } } impl ImageDecoder for JpegDecoder { @@ -108,6 +100,12 @@ impl ImageDecoder for JpegDecoder { fn read_image_boxed(self: Box, buf: &mut [u8]) -> ImageResult<()> { (*self).read_image(buf) } + + fn exif_metadata(&mut self) -> ImageResult>> { + let mut decoder = zune_jpeg::JpegDecoder::new(&self.input); + decoder.decode_headers().map_err(ImageError::from_jpeg)?; + Ok(decoder.exif().cloned()) + } } impl ColorType { diff --git a/src/image.rs b/src/image.rs index 5bdecd4c9a..f19ba9d39b 100644 --- a/src/image.rs +++ b/src/image.rs @@ -628,6 +628,14 @@ pub trait ImageDecoder { Ok(None) } + /// Returns the raw [Exif](https://en.wikipedia.org/wiki/Exif) chunk, if it is present. + /// A third-party crate such as [`kamadak-exif`](https://docs.rs/kamadak-exif/) is required to actually parse it. + /// + /// For formats that don't support embedded profiles this function should always return `Ok(None)`. + fn exif_metadata(&mut self) -> ImageResult>> { + Ok(None) + } + /// Returns the total number of bytes in the decoded image. /// /// This is the size of the buffer that must be passed to `read_image` or