Merge "SnapdragonGallery: update min birghtness value" into android-snapdragonGallery.lnx.2.0
diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java b/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java
old mode 100644
new mode 100755
index 5621c23..ec653e9
--- a/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java
+++ b/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java
@@ -143,6 +143,9 @@
 
     protected static final int DEFAULT_IFD0_OFFSET = 8;
 
+    //HEIC header
+    protected static final int HEIC_HEADER = 0x68656963;
+
     private final CountedDataInputStream mTiffStream;
     private final int mOptions;
     private int mIfdStartOffset = 0;
@@ -753,37 +756,66 @@
     private boolean seekTiffData(InputStream inputStream) throws IOException,
             ExifInvalidFormatException {
         CountedDataInputStream dataStream = new CountedDataInputStream(inputStream);
-        if (dataStream.readShort() != JpegHeader.SOI) {
-            throw new ExifInvalidFormatException("Invalid JPEG format");
-        }
-
-        short marker = dataStream.readShort();
-        while (marker != JpegHeader.EOI
-                && !JpegHeader.isSofMarker(marker)) {
-            int length = dataStream.readUnsignedShort();
-            // Some invalid formatted image contains multiple APP1,
-            // try to find the one with Exif data.
-            if (marker == JpegHeader.APP1) {
-                int header = 0;
-                short headerTail = 0;
-                if (length >= 8) {
-                    header = dataStream.readInt();
-                    headerTail = dataStream.readShort();
-                    length -= 6;
-                    if (header == EXIF_HEADER && headerTail == EXIF_HEADER_TAIL) {
-                        mTiffStartPosition = dataStream.getReadByteCount();
-                        mApp1End = length;
-                        mOffsetToApp1EndFromSOF = mTiffStartPosition + mApp1End;
-                        return true;
+        if (dataStream.readShort() == JpegHeader.SOI) {
+            short marker = dataStream.readShort();
+            while (marker != JpegHeader.EOI
+                    && !JpegHeader.isSofMarker(marker)) {
+                int length = dataStream.readUnsignedShort();
+                // Some invalid formatted image contains multiple APP1,
+                // try to find the one with Exif data.
+                if (marker == JpegHeader.APP1) {
+                    int header = 0;
+                    short headerTail = 0;
+                    if (length >= 8) {
+                        header = dataStream.readInt();
+                        headerTail = dataStream.readShort();
+                        length -= 6;
+                        if (header == EXIF_HEADER && headerTail == EXIF_HEADER_TAIL) {
+                            mTiffStartPosition = dataStream.getReadByteCount();
+                            mApp1End = length;
+                            mOffsetToApp1EndFromSOF = mTiffStartPosition + mApp1End;
+                            return true;
+                        }
                     }
                 }
+                if (length < 2 || (length - 2) != dataStream.skip(length - 2)) {
+                    Log.w(TAG, "Invalid JPEG format.");
+                    return false;
+                }
+                marker = dataStream.readShort();
             }
-            if (length < 2 || (length - 2) != dataStream.skip(length - 2)) {
-                Log.w(TAG, "Invalid JPEG format.");
+
+
+        } 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;
+                            }
+                        }
+                    }catch (Exception e){
+                        break;
+                    }
+                }
                 return false;
+            } else {
+                throw new ExifInvalidFormatException("Invalid JPEG format");
             }
-            marker = dataStream.readShort();
+
         }
+
         return false;
     }
 
diff --git a/src/com/android/gallery3d/data/LocalImage.java b/src/com/android/gallery3d/data/LocalImage.java
index 2743a3e..1b5c88b 100755
--- a/src/com/android/gallery3d/data/LocalImage.java
+++ b/src/com/android/gallery3d/data/LocalImage.java
@@ -356,7 +356,8 @@
     public MediaDetails getDetails() {
         MediaDetails details = super.getDetails();
         details.addDetail(MediaDetails.INDEX_ORIENTATION, Integer.valueOf(rotation));
-        if (MIME_TYPE_JPEG.equals(mimeType)) {
+        if (MIME_TYPE_JPEG.equals(mimeType) || MIME_TYPE_HEIF.equals(mimeType) ||
+                MIME_TYPE_HEIC.equals(mimeType)) {
             // ExifInterface returns incorrect values for photos in other format.
             // For example, the width and height of an webp images is always '0'.
             MediaDetails.extractExifInfo(details, filePath);
diff --git a/src/com/android/gallery3d/data/MediaDetails.java b/src/com/android/gallery3d/data/MediaDetails.java
old mode 100644
new mode 100755
index 2a501c7..359eeeb
--- a/src/com/android/gallery3d/data/MediaDetails.java
+++ b/src/com/android/gallery3d/data/MediaDetails.java
@@ -166,5 +166,12 @@
                     focalTag.getValueAsRational(0).toDouble());
             details.setUnit(MediaDetails.INDEX_FOCAL_LENGTH, R.string.unit_mm);
         }
+        ExifTag latitudeTag = exif.getTag(ExifInterface.TAG_GPS_LATITUDE);
+        ExifTag longitudeTag = exif.getTag(ExifInterface.TAG_GPS_LONGITUDE);
+        if (latitudeTag != null && longitudeTag != null) {
+            double latitude = latitudeTag.getValueAsRational(0).toDouble();
+            double longitude = longitudeTag.getValueAsRational(0).toDouble();
+            details.addDetail(MediaDetails.INDEX_LOCATION, new double[] {latitude, longitude});
+        }
     }
 }
diff --git a/src/com/android/gallery3d/data/MediaItem.java b/src/com/android/gallery3d/data/MediaItem.java
old mode 100644
new mode 100755
index c27667c..da58136
--- a/src/com/android/gallery3d/data/MediaItem.java
+++ b/src/com/android/gallery3d/data/MediaItem.java
@@ -37,6 +37,8 @@
     public static final int IMAGE_ERROR = -1;
 
     public static final String MIME_TYPE_JPEG = "image/jpeg";
+    public static final String MIME_TYPE_HEIF = "image/heif";
+    public static final String MIME_TYPE_HEIC = "image/heic";
     public static final String MIME_TYPE_GIF = "image/gif";
 
     private static final int BYTESBUFFE_POOL_SIZE = 4;
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
old mode 100644
new mode 100755
index 95f8fd2..9f6af5a
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
@@ -34,7 +34,7 @@
     }
 
     public FilterRepresentation getDefaultRepresentation() {
-        FilterRepresentation representation = new FilterBasicRepresentation("Sharpen", 0, 0, 100);
+        FilterRepresentation representation = new FilterBasicRepresentation("Sharpen", -100, 0, 100);
         representation.setSerializationName(SERIALIZATION_NAME);
         representation.setShowParameterValue(true);
         representation.setFilterClass(ImageFilterSharpen.class);