summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
diff options
context:
space:
mode:
authorSascha Haeberling <haeberling@google.com>2012-10-23 22:34:21 -0700
committerSascha Haeberling <haeberling@google.com>2012-10-23 22:34:21 -0700
commitbbd30e0aab09feba5d3e038433895561ab255640 (patch)
tree0c8de6e2670da790686ad0f7e59b17aa36baac69 /src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
parent026dabdcb13bd0095a970af8e1a05741f801db50 (diff)
downloadandroid_packages_apps_Snap-bbd30e0aab09feba5d3e038433895561ab255640.tar.gz
android_packages_apps_Snap-bbd30e0aab09feba5d3e038433895561ab255640.tar.bz2
android_packages_apps_Snap-bbd30e0aab09feba5d3e038433895561ab255640.zip
Use XMP meta-data for correct tiny planets.
Bug: 7403766 Change-Id: Ie03d40d0396d352d6fe48c91b995a2f872c98a06
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java')
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java70
1 files changed, 59 insertions, 11 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
index 1dc173123..c996e9c03 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
@@ -17,7 +17,11 @@
package com.android.gallery3d.filtershow.filters;
import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import com.adobe.xmp.XMPException;
+import com.adobe.xmp.XMPMeta;
import com.android.gallery3d.filtershow.presets.ImagePreset;
/**
@@ -25,6 +29,20 @@ import com.android.gallery3d.filtershow.presets.ImagePreset;
*/
public class ImageFilterTinyPlanet extends ImageFilter {
private static final String TAG = ImageFilterTinyPlanet.class.getSimpleName();
+ public static final String GOOGLE_PANO_NAMESPACE = "http://ns.google.com/photos/1.0/panorama/";
+
+ public static final String CROPPED_AREA_IMAGE_WIDTH_PIXELS =
+ "CroppedAreaImageWidthPixels";
+ public static final String CROPPED_AREA_IMAGE_HEIGHT_PIXELS =
+ "CroppedAreaImageHeightPixels";
+ public static final String CROPPED_AREA_FULL_PANO_WIDTH_PIXELS =
+ "FullPanoWidthPixels";
+ public static final String CROPPED_AREA_FULL_PANO_HEIGHT_PIXELS =
+ "FullPanoHeightPixels";
+ public static final String CROPPED_AREA_LEFT =
+ "CroppedAreaLeftPixels";
+ public static final String CROPPED_AREA_TOP =
+ "CroppedAreaTopPixels";
public ImageFilterTinyPlanet() {
setFilterType(TYPE_TINYPLANET);
@@ -43,26 +61,56 @@ public class ImageFilterTinyPlanet extends ImageFilter {
@Override
public Bitmap apply(Bitmap bitmapIn, float scaleFactor, boolean highQuality) {
+ int w = bitmapIn.getWidth();
+ int h = bitmapIn.getHeight();
+ int outputSize = Math.min(w, h);
+
ImagePreset preset = getImagePreset();
if (preset != null) {
if (preset.isPanoramaSafe()) {
- // TODO(haeberling): Get XMPMeta object.
- Object xmp = preset.getImageLoader().getXmpObject();
+ try {
+ XMPMeta xmp = preset.getImageLoader().getXmpObject();
+ int croppedAreaWidth =
+ getInt(xmp, CROPPED_AREA_IMAGE_WIDTH_PIXELS);
+ int croppedAreaHeight =
+ getInt(xmp, CROPPED_AREA_IMAGE_HEIGHT_PIXELS);
+ int fullPanoWidth =
+ getInt(xmp, CROPPED_AREA_FULL_PANO_WIDTH_PIXELS);
+ int fullPanoHeight =
+ getInt(xmp, CROPPED_AREA_FULL_PANO_HEIGHT_PIXELS);
+ int left = getInt(xmp, CROPPED_AREA_LEFT);
+ int top = getInt(xmp, CROPPED_AREA_TOP);
+
+ Bitmap paddedBitmap = Bitmap.createBitmap(
+ fullPanoWidth, fullPanoHeight, Bitmap.Config.ARGB_8888);
+ Canvas paddedCanvas = new Canvas(paddedBitmap);
+
+ int right = left + croppedAreaWidth;
+ int bottom = top + croppedAreaHeight;
+ Rect destRect = new Rect(left, top, right, bottom);
+ paddedCanvas.drawBitmap(bitmapIn, null, destRect, null);
+ bitmapIn = paddedBitmap;
+ } catch (XMPException ex) {
+ // Do nothing, just use bitmapIn as is.
+ }
} else {
- // TODO(haeberling): What should we do for:
- // !preset.isPanoramaSafe()?
+ // Do nothing, just use bitmapIn as is, there is nothing else we
+ // can do.
}
}
- int w = bitmapIn.getWidth();
- int h = bitmapIn.getHeight();
- int outputSize = Math.min(w, h);
-
Bitmap mBitmapOut = Bitmap.createBitmap(
outputSize, outputSize, Bitmap.Config.ARGB_8888);
-
- // TODO(haeberling): Add the padding back in based on the meta-data.
- nativeApplyFilter(bitmapIn, w, h, mBitmapOut, outputSize, mParameter / 100f, 0f);
+ nativeApplyFilter(bitmapIn, bitmapIn.getWidth(), bitmapIn.getHeight(), mBitmapOut,
+ outputSize, mParameter / 100f, 0f);
return mBitmapOut;
}
+
+ private static int getInt(XMPMeta xmp, String key) throws XMPException {
+ if (xmp.doesPropertyExist(GOOGLE_PANO_NAMESPACE, key)) {
+ return xmp.getPropertyInteger(GOOGLE_PANO_NAMESPACE, key);
+ } else {
+ return 0;
+ }
+ }
}