From 98cf80a9900bc5d1ec63e69b3d2a6c1f6792f236 Mon Sep 17 00:00:00 2001 From: Cullum Baldwin Date: Sat, 31 Oct 2015 01:27:35 -0700 Subject: Gallery2: fix thumbnail issue when using dual cam filter When using some dual cam filter, the thumbnail shown to user did not match final saved image because filter was not being correctly applied to preview thumbnail. Correctly apply filter to preview thumbnail so that it matches final saved image. Change-Id: Ib8b750c7681aac38bef76dd90cb831ca6ac5ab5b --- .../gallery3d/filtershow/tools/SaveImage.java | 46 +++++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/com/android/gallery3d/filtershow/tools/SaveImage.java b/src/com/android/gallery3d/filtershow/tools/SaveImage.java index f04466f1b..cbe0f91a3 100644 --- a/src/com/android/gallery3d/filtershow/tools/SaveImage.java +++ b/src/com/android/gallery3d/filtershow/tools/SaveImage.java @@ -359,12 +359,47 @@ public class SaveImage { Uri savedUri = mSelectedImageUri; if (mPreviewImage != null) { + Bitmap previewBmp; + // Check for Fusion + FilterDualCamFusionRepresentation fusionRep = + (FilterDualCamFusionRepresentation) preset.getFilterWithSerializationName( + FilterDualCamFusionRepresentation.SERIALIZATION_NAME); + boolean hasFusion = (fusionRep != null && fusionRep.hasUnderlay()); + if(hasFusion) { + // fusion. decode underlay image and get dest rect + Uri underLayUri = Uri.parse(fusionRep.getUnderlay()); + Bitmap underlay = ImageLoader.loadConstrainedBitmap(underLayUri, mContext, + Math.max(mPreviewImage.getWidth(), mPreviewImage.getHeight()), null, false); + RectF destRect = new RectF(); + Rect imageBounds = MasterImage.getImage().getImageBounds(); + Rect underlayBounds = MasterImage.getImage().getFusionBounds(); + float underlayScaleFactor = (float)underlay.getWidth() + / (float)underlayBounds.width(); + + destRect.left = (imageBounds.left - underlayBounds.left) * underlayScaleFactor; + destRect.right = (imageBounds.right - underlayBounds.left) * underlayScaleFactor; + destRect.top = (imageBounds.top - underlayBounds.top) * underlayScaleFactor; + destRect.bottom = (imageBounds.bottom - underlayBounds.top) * underlayScaleFactor; + + Canvas canvas = new Canvas(underlay); + Paint paint = new Paint(); + paint.reset(); + paint.setAntiAlias(true); + paint.setFilterBitmap(true); + paint.setDither(true); + + canvas.drawBitmap(mPreviewImage, null, destRect, paint); + previewBmp = underlay; + } else { + previewBmp = mPreviewImage; + } + if (flatten) { Object xmp = getPanoramaXMPData(newSourceUri, preset); ExifInterface exif = getExifData(newSourceUri); long time = System.currentTimeMillis(); updateExifData(exif, time); - if (putExifData(mDestinationFile, exif, mPreviewImage, quality)) { + if (putExifData(mDestinationFile, exif, previewBmp, quality)) { putPanoramaXMPData(mDestinationFile, xmp); ContentValues values = getContentValues(mContext, mSelectedImageUri, mDestinationFile, time); Object result = mContext.getContentResolver().insert( @@ -377,7 +412,7 @@ public class SaveImage { long time = System.currentTimeMillis(); updateExifData(exif, time); // If we succeed in writing the bitmap as a jpeg, return a uri. - if (putExifData(mDestinationFile, exif, mPreviewImage, quality)) { + if (putExifData(mDestinationFile, exif, previewBmp, quality)) { putPanoramaXMPData(mDestinationFile, xmp); // mDestinationFile will save the newSourceUri info in the XMP. if (!flatten) { @@ -390,6 +425,13 @@ public class SaveImage { mDestinationFile, time, false); } } + + if(hasFusion) { + // recycle bitmap + previewBmp.recycle(); + previewBmp = null; + } + if (mCallback != null) { mCallback.onPreviewSaved(savedUri); } -- cgit v1.2.3