Skip to content

Commit

Permalink
move exif_metadata to Decoder trait - way better user API this way
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnatsel committed Jul 27, 2024
1 parent 2dd3f1a commit 30fdcff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/codecs/jpeg/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ impl<R: BufRead + Seek> JpegDecoder<R> {
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<Option<Vec<u8>>> {
let mut decoder = zune_jpeg::JpegDecoder::new(&self.input);
decoder.decode_headers().map_err(ImageError::from_jpeg)?;
Ok(decoder.exif().cloned())
}
}

impl<R: BufRead + Seek> ImageDecoder for JpegDecoder<R> {
Expand Down Expand Up @@ -108,6 +100,12 @@ impl<R: BufRead + Seek> ImageDecoder for JpegDecoder<R> {
fn read_image_boxed(self: Box<Self>, buf: &mut [u8]) -> ImageResult<()> {
(*self).read_image(buf)
}

fn exif_metadata(&mut self) -> ImageResult<Option<Vec<u8>>> {
let mut decoder = zune_jpeg::JpegDecoder::new(&self.input);
decoder.decode_headers().map_err(ImageError::from_jpeg)?;
Ok(decoder.exif().cloned())
}
}

impl ColorType {
Expand Down
8 changes: 8 additions & 0 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<Vec<u8>>> {
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
Expand Down

0 comments on commit 30fdcff

Please sign in to comment.