Loading media/java/android/media/ExifInterface.java +58 −34 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ import libcore.io.Streams; /** * This is a class for reading and writing Exif tags in a JPEG file or a RAW image file. * <p> * Supported formats are: JPEG, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW and RAF. * Supported formats are: JPEG, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW, RAF and HEIF. * <p> * Attribute mutation is supported for JPEG image files. */ Loading Loading @@ -2524,9 +2524,6 @@ public class ExifInterface { private void getHeifAttributes(ByteOrderedDataInputStream in) throws IOException { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { if (mSeekableFileDescriptor != null) { retriever.setDataSource(mSeekableFileDescriptor); } else { retriever.setDataSource(new MediaDataSource() { long mPosition; Loading Loading @@ -2562,8 +2559,11 @@ public class ExifInterface { return -1; } }); } String exifOffsetStr = retriever.extractMetadata( MediaMetadataRetriever.METADATA_KEY_EXIF_OFFSET); String exifLengthStr = retriever.extractMetadata( MediaMetadataRetriever.METADATA_KEY_EXIF_LENGTH); String hasImage = retriever.extractMetadata( MediaMetadataRetriever.METADATA_KEY_HAS_IMAGE); String hasVideo = retriever.extractMetadata( Loading Loading @@ -2622,6 +2622,30 @@ public class ExifInterface { ExifAttribute.createUShort(orientation, mExifByteOrder)); } if (exifOffsetStr != null && exifLengthStr != null) { int offset = Integer.parseInt(exifOffsetStr); int length = Integer.parseInt(exifLengthStr); if (length <= 6) { throw new IOException("Invalid exif length"); } in.seek(offset); byte[] identifier = new byte[6]; if (in.read(identifier) != 6) { throw new IOException("Can't read identifier"); } offset += 6; length -= 6; if (!Arrays.equals(identifier, IDENTIFIER_EXIF_APP1)) { throw new IOException("Invalid identifier"); } byte[] bytes = new byte[length]; if (in.read(bytes) != length) { throw new IOException("Can't read exif"); } readExifSegment(bytes, IFD_TYPE_PRIMARY); } if (DEBUG) { Log.d(TAG, "Heif meta: " + width + "x" + height + ", rotation " + rotation); } Loading media/java/android/media/MediaMetadataRetriever.java +9 −0 Original line number Diff line number Diff line Loading @@ -890,5 +890,14 @@ public class MediaMetadataRetriever */ public static final int METADATA_KEY_VIDEO_FRAME_COUNT = 32; /** * @hide */ public static final int METADATA_KEY_EXIF_OFFSET = 33; /** * @hide */ public static final int METADATA_KEY_EXIF_LENGTH = 34; // Add more here... } Loading
media/java/android/media/ExifInterface.java +58 −34 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ import libcore.io.Streams; /** * This is a class for reading and writing Exif tags in a JPEG file or a RAW image file. * <p> * Supported formats are: JPEG, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW and RAF. * Supported formats are: JPEG, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW, RAF and HEIF. * <p> * Attribute mutation is supported for JPEG image files. */ Loading Loading @@ -2524,9 +2524,6 @@ public class ExifInterface { private void getHeifAttributes(ByteOrderedDataInputStream in) throws IOException { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { if (mSeekableFileDescriptor != null) { retriever.setDataSource(mSeekableFileDescriptor); } else { retriever.setDataSource(new MediaDataSource() { long mPosition; Loading Loading @@ -2562,8 +2559,11 @@ public class ExifInterface { return -1; } }); } String exifOffsetStr = retriever.extractMetadata( MediaMetadataRetriever.METADATA_KEY_EXIF_OFFSET); String exifLengthStr = retriever.extractMetadata( MediaMetadataRetriever.METADATA_KEY_EXIF_LENGTH); String hasImage = retriever.extractMetadata( MediaMetadataRetriever.METADATA_KEY_HAS_IMAGE); String hasVideo = retriever.extractMetadata( Loading Loading @@ -2622,6 +2622,30 @@ public class ExifInterface { ExifAttribute.createUShort(orientation, mExifByteOrder)); } if (exifOffsetStr != null && exifLengthStr != null) { int offset = Integer.parseInt(exifOffsetStr); int length = Integer.parseInt(exifLengthStr); if (length <= 6) { throw new IOException("Invalid exif length"); } in.seek(offset); byte[] identifier = new byte[6]; if (in.read(identifier) != 6) { throw new IOException("Can't read identifier"); } offset += 6; length -= 6; if (!Arrays.equals(identifier, IDENTIFIER_EXIF_APP1)) { throw new IOException("Invalid identifier"); } byte[] bytes = new byte[length]; if (in.read(bytes) != length) { throw new IOException("Can't read exif"); } readExifSegment(bytes, IFD_TYPE_PRIMARY); } if (DEBUG) { Log.d(TAG, "Heif meta: " + width + "x" + height + ", rotation " + rotation); } Loading
media/java/android/media/MediaMetadataRetriever.java +9 −0 Original line number Diff line number Diff line Loading @@ -890,5 +890,14 @@ public class MediaMetadataRetriever */ public static final int METADATA_KEY_VIDEO_FRAME_COUNT = 32; /** * @hide */ public static final int METADATA_KEY_EXIF_OFFSET = 33; /** * @hide */ public static final int METADATA_KEY_EXIF_LENGTH = 34; // Add more here... }