diff options
-rw-r--r-- | gallerycommon/src/com/android/gallery3d/common/ApiHelper.java | 3 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/CropImage.java | 22 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/DecodeUtils.java | 11 |
3 files changed, 31 insertions, 5 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java index 418e3cdd2..68aa50dda 100644 --- a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java +++ b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java @@ -151,6 +151,9 @@ public class ApiHelper { public static final boolean HAS_CAMERA_HDR = Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1; + public static final boolean HAS_OPTIONS_IN_MUTABLE = + Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; + public static final boolean CAN_START_PREVIEW_IN_JPEG_CALLBACK = Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; diff --git a/src/com/android/gallery3d/app/CropImage.java b/src/com/android/gallery3d/app/CropImage.java index 21ce98388..f9254eefe 100644 --- a/src/com/android/gallery3d/app/CropImage.java +++ b/src/com/android/gallery3d/app/CropImage.java @@ -392,10 +392,17 @@ public class CropImage extends AbstractGalleryActivity { } } - private void changeExifImageSizeTag(ExifData data, int width, int height) { - data.getIfdData(IfdId.TYPE_IFD_0).getTag(ExifTag.TIFF_TAG.TAG_IMAGE_WIDTH).setValue(width); - data.getIfdData(IfdId.TYPE_IFD_0).getTag(ExifTag.TIFF_TAG.TAG_IMAGE_HEIGHT).setValue( - height); + private void changeExifImageSizeTags(ExifData data, int width, int height) { + // FIXME: would the image size be too large for TYPE_UNSIGHED_SHORT? + ExifTag tag = new ExifTag(ExifTag.TIFF_TAG.TAG_IMAGE_WIDTH, + ExifTag.TYPE_UNSIGNED_SHORT, 1, IfdId.TYPE_IFD_0); + tag.setValue(new int[] {width}); + data.getIfdData(IfdId.TYPE_IFD_0).setTag(tag); + + tag = new ExifTag(ExifTag.TIFF_TAG.TAG_IMAGE_HEIGHT, + ExifTag.TYPE_UNSIGNED_SHORT, 1, IfdId.TYPE_IFD_0); + tag.setValue(new int[] {height}); + data.getIfdData(IfdId.TYPE_IFD_0).setTag(tag); } private Uri saveToMediaProvider(JobContext jc, Bitmap cropped) { @@ -426,6 +433,9 @@ public class CropImage extends AbstractGalleryActivity { if (pos >= 0) filename = filename.substring(0, pos); ExifData exifData = new ExifData(ByteOrder.BIG_ENDIAN); PicasaSource.extractExifValues(mMediaItem, exifData); + changeExifImageSizeTags(exifData, cropped.getWidth(), cropped.getHeight()); + // TODO: modify the Software tag to indicate which the image is revised by + // TODO: modify the DateTime tag File output = saveMedia(jc, cropped, DOWNLOAD_BUCKET, filename, exifData); if (output == null) return null; @@ -467,7 +477,9 @@ public class CropImage extends AbstractGalleryActivity { if (convertExtensionToCompressFormat(getFileExtension()) == CompressFormat.JPEG) { exifData = getExifData(oldPath.getAbsolutePath()); if (exifData != null) { - changeExifImageSizeTag(exifData, cropped.getWidth(), cropped.getHeight()); + // TODO: modify the Software tag to indicate which the image is revised by + // TODO: modify the DateTime tag + changeExifImageSizeTags(exifData, cropped.getWidth(), cropped.getHeight()); } } output = saveMedia(jc, cropped, directory, filename, exifData); diff --git a/src/com/android/gallery3d/data/DecodeUtils.java b/src/com/android/gallery3d/data/DecodeUtils.java index 773af74bb..4d3c99653 100644 --- a/src/com/android/gallery3d/data/DecodeUtils.java +++ b/src/com/android/gallery3d/data/DecodeUtils.java @@ -25,6 +25,7 @@ import android.graphics.BitmapRegionDecoder; import android.os.Build; import android.util.FloatMath; +import com.android.gallery3d.common.ApiHelper; import com.android.gallery3d.common.BitmapUtils; import com.android.gallery3d.common.Utils; import com.android.gallery3d.ui.Log; @@ -51,9 +52,15 @@ public class DecodeUtils { } } + @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB) + public static void setOptionsMutable(Options options) { + if (ApiHelper.HAS_OPTIONS_IN_MUTABLE) options.inMutable = true; + } + public static Bitmap decode(JobContext jc, FileDescriptor fd, Options options) { if (options == null) options = new Options(); jc.setCancelListener(new DecodeCanceller(options)); + setOptionsMutable(options); return ensureGLCompatibleBitmap( BitmapFactory.decodeFileDescriptor(fd, null, options)); } @@ -75,6 +82,7 @@ public class DecodeUtils { int length, Options options) { if (options == null) options = new Options(); jc.setCancelListener(new DecodeCanceller(options)); + setOptionsMutable(options); return ensureGLCompatibleBitmap( BitmapFactory.decodeByteArray(bytes, offset, length, options)); } @@ -135,6 +143,7 @@ public class DecodeUtils { } options.inJustDecodeBounds = false; + setOptionsMutable(options); Bitmap result = BitmapFactory.decodeFileDescriptor(fd, null, options); if (result == null) return null; @@ -170,6 +179,8 @@ public class DecodeUtils { options.inSampleSize = BitmapUtils.computeSampleSizeLarger( options.outWidth, options.outHeight, targetSize); options.inJustDecodeBounds = false; + setOptionsMutable(options); + return ensureGLCompatibleBitmap( BitmapFactory.decodeByteArray(data, 0, data.length, options)); } |