SnapdraongCamera:Fix HEIF exif
Exif information is not aligned in
heif images, need to check byte by
byte to avoid lossing exif.
Change-Id: I1c67d399d28494067722ea59aea61994349860c4
CRs-Fixed: 2583399
diff --git a/gallerycommon/src/com/android/gallery3d/exif/CountedDataInputStream.java b/gallerycommon/src/com/android/gallery3d/exif/CountedDataInputStream.java
old mode 100644
new mode 100755
index c8300ad..7fddae9
--- a/gallerycommon/src/com/android/gallery3d/exif/CountedDataInputStream.java
+++ b/gallerycommon/src/com/android/gallery3d/exif/CountedDataInputStream.java
@@ -106,6 +106,12 @@
return readShort() & 0xffff;
}
+ public byte readByte() throws IOException {
+ readOrThrow(mByteArray, 0 ,1);
+ mByteBuffer.rewind();
+ return mByteBuffer.get(0);
+ }
+
public int readInt() throws IOException {
readOrThrow(mByteArray, 0 , 4);
mByteBuffer.rewind();
diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java b/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java
index ec653e9..9d60101 100755
--- a/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java
+++ b/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java
@@ -140,6 +140,8 @@
protected static final int OFFSET_SIZE = 2;
private static final Charset US_ASCII = Charset.forName("US-ASCII");
+ private static final byte APP1_UP = (byte)0xFF;
+ private static final byte APP1_DOWN = (byte)0xE1;
protected static final int DEFAULT_IFD0_OFFSET = 8;
@@ -784,26 +786,29 @@
}
marker = dataStream.readShort();
}
-
-
} else{
dataStream.skip(6);
if (dataStream.readInt() == HEIC_HEADER) {
while(true){
try{
- short marker = dataStream.readShort();
- if (marker == JpegHeader.APP1) {
- int header = 0;
- short headerTail = 0;
- int length = dataStream.readUnsignedShort();
- header = dataStream.readInt();
- headerTail = dataStream.readShort();
- if (header == EXIF_HEADER && headerTail == EXIF_HEADER_TAIL) {
- mTiffStartPosition = dataStream.getReadByteCount();
- mApp1End = length;
- mOffsetToApp1EndFromSOF = mTiffStartPosition + mApp1End;
- return true;
+ byte marker = dataStream.readByte();
+ if(marker == APP1_UP){
+ dataStream.mark(8);
+ marker = dataStream.readByte();
+ if (marker == APP1_DOWN){
+ int header = 0;
+ short headerTail = 0;
+ int length = dataStream.readUnsignedShort();
+ header = dataStream.readInt();
+ headerTail = dataStream.readShort();
+ if (header == EXIF_HEADER && headerTail == EXIF_HEADER_TAIL) {
+ mTiffStartPosition = dataStream.getReadByteCount();
+ mApp1End = length;
+ mOffsetToApp1EndFromSOF = mTiffStartPosition + mApp1End;
+ return true;
+ }
}
+ dataStream.reset();
}
}catch (Exception e){
break;