Skip to content

Commit

Permalink
Expose zune-jpeg's Exif chunk extraction (#2291)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnatsel committed Aug 26, 2024
1 parent 6d19ffa commit a804647
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/codecs/jpeg/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ impl<R: BufRead + Seek> ImageDecoder for JpegDecoder<R> {
Ok(decoder.icc_profile())
}

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())
}

fn read_image(self, buf: &mut [u8]) -> ImageResult<()> {
let advertised_len = self.total_bytes();
let actual_len = buf.len() as u64;
Expand Down
11 changes: 11 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 Expand Up @@ -710,6 +718,9 @@ impl<T: ?Sized + ImageDecoder> ImageDecoder for Box<T> {
fn icc_profile(&mut self) -> ImageResult<Option<Vec<u8>>> {
(**self).icc_profile()
}
fn exif_metadata(&mut self) -> ImageResult<Option<Vec<u8>>> {
(**self).exif_metadata()
}
fn total_bytes(&self) -> u64 {
(**self).total_bytes()
}
Expand Down

0 comments on commit a804647

Please sign in to comment.