@@ -95,6 +95,8 @@ pub enum AppData {
9595 Avi1 ,
9696 Icc ( IccChunk ) ,
9797 Exif ( Vec < u8 > ) ,
98+ Xmp ( Vec < u8 > ) ,
99+ Psir ( Vec < u8 > ) ,
98100}
99101
100102// http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe
@@ -623,21 +625,20 @@ pub fn parse_app<R: Read>(reader: &mut R, marker: Marker) -> Result<Option<AppDa
623625 }
624626 }
625627 }
626- // Exif Data
627628 APP ( 1 ) => {
628- if length >= 6 {
629- let mut buffer = [ 0u8 ; 6 ] ;
630- reader . read_exact ( & mut buffer ) ? ;
631- bytes_read = buffer . len ( ) ;
632-
633- // https://web.archive.org/web/20190624045241if_/http://www.cipa.jp:80/std/documents/e/DC-008-Translation-2019-E.pdf
634- // 4.5.4 Basic Structure of JPEG Compressed Data
635- if buffer == * b" Exif\x00 \x00 " {
636- let mut data = vec ! [ 0 ; length - bytes_read ] ;
637- reader . read_exact ( & mut data ) ? ;
638- bytes_read += data . len ( ) ;
639- result = Some ( AppData :: Exif ( data ) ) ;
640- }
629+ let mut buffer = vec ! [ 0u8 ; length ] ;
630+ reader . read_exact ( & mut buffer) ? ;
631+ bytes_read = buffer . len ( ) ;
632+
633+ // https://web.archive.org/web/20190624045241if_/http://www.cipa.jp:80/std/documents/e/DC-008-Translation-2019-E.pdf
634+ // 4.5.4 Basic Structure of JPEG Compressed Data
635+ if length >= 6 && buffer [ 0 .. 6 ] == * b"Exif \x00 \x00 " {
636+ result = Some ( AppData :: Exif ( buffer [ 6 .. ] . to_vec ( ) ) ) ;
637+ }
638+ // XMP packet
639+ // https://github.com/adobe/XMP-Toolkit-SDK/blob/main/docs/XMPSpecificationPart3.pdf
640+ else if length >= 29 && buffer [ 0 .. 29 ] == * b"http://ns.adobe.com/xap/1.0/ \0 " {
641+ result = Some ( AppData :: Xmp ( buffer [ 29 .. ] . to_vec ( ) ) ) ;
641642 }
642643 }
643644 APP ( 2 ) => {
@@ -660,6 +661,22 @@ pub fn parse_app<R: Read>(reader: &mut R, marker: Marker) -> Result<Option<AppDa
660661 }
661662 }
662663 }
664+ APP ( 13 ) => {
665+ if length >= 14 {
666+ let mut buffer = [ 0u8 ; 14 ] ;
667+ reader. read_exact ( & mut buffer) ?;
668+ bytes_read = buffer. len ( ) ;
669+
670+ // PSIR (Photoshop)
671+ // https://github.com/adobe/XMP-Toolkit-SDK/blob/main/docs/XMPSpecificationPart3.pdf
672+ if buffer[ 0 ..14 ] == * b"Photoshop 3.0\0 " {
673+ let mut data = vec ! [ 0 ; length - bytes_read] ;
674+ reader. read_exact ( & mut data) ?;
675+ bytes_read += data. len ( ) ;
676+ result = Some ( AppData :: Psir ( data) ) ;
677+ }
678+ }
679+ }
663680 APP ( 14 ) => {
664681 if length >= 12 {
665682 let mut buffer = [ 0u8 ; 12 ] ;
0 commit comments