summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2012-10-05 15:55:56 -0700
committernicolasroard <nicolasroard@google.com>2012-10-05 15:55:56 -0700
commit10455d031ac898abf1367b3e2f69675c988374e0 (patch)
tree89226aeedf9461cd70aa74d3929586325cb55e5f /src
parent14dafd63b69f3908b7374a8c0c49762813a454f5 (diff)
downloadandroid_packages_apps_Snap-10455d031ac898abf1367b3e2f69675c988374e0.tar.gz
android_packages_apps_Snap-10455d031ac898abf1367b3e2f69675c988374e0.tar.bz2
android_packages_apps_Snap-10455d031ac898abf1367b3e2f69675c988374e0.zip
Add scale factor / quality parameters in filters
bug:7248352 Change-Id: I2e4ca86d681eba2e97ddc550f88d9f702ecba65d
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/cache/DelayedPresetCache.java7
-rw-r--r--src/com/android/gallery3d/filtershow/cache/DirectPresetCache.java27
-rw-r--r--src/com/android/gallery3d/filtershow/presets/ImagePreset.java31
3 files changed, 49 insertions, 16 deletions
diff --git a/src/com/android/gallery3d/filtershow/cache/DelayedPresetCache.java b/src/com/android/gallery3d/filtershow/cache/DelayedPresetCache.java
index 8acb539b6..361190b78 100644
--- a/src/com/android/gallery3d/filtershow/cache/DelayedPresetCache.java
+++ b/src/com/android/gallery3d/filtershow/cache/DelayedPresetCache.java
@@ -14,7 +14,7 @@ public class DelayedPresetCache extends DirectPresetCache implements Callback {
private final static int COMPUTE_PRESET = 1;
private Handler mProcessingHandler = null;
- private Handler mUIHandler = new Handler() {
+ private final Handler mUIHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
@@ -41,13 +41,14 @@ public class DelayedPresetCache extends DirectPresetCache implements Callback {
return false;
}
- public DelayedPresetCache(int size) {
- super(size);
+ public DelayedPresetCache(ImageLoader loader, int size) {
+ super(loader, size);
mHandlerThread = new HandlerThread("ImageProcessing", Process.THREAD_PRIORITY_BACKGROUND);
mHandlerThread.start();
mProcessingHandler = new Handler(mHandlerThread.getLooper(), this);
}
+ @Override
protected void willCompute(CachedPreset cache) {
if (cache == null) {
return;
diff --git a/src/com/android/gallery3d/filtershow/cache/DirectPresetCache.java b/src/com/android/gallery3d/filtershow/cache/DirectPresetCache.java
index 1ba835673..67bd49b1c 100644
--- a/src/com/android/gallery3d/filtershow/cache/DirectPresetCache.java
+++ b/src/com/android/gallery3d/filtershow/cache/DirectPresetCache.java
@@ -1,23 +1,23 @@
package com.android.gallery3d.filtershow.cache;
-import java.util.Vector;
-
import android.graphics.Bitmap;
-import android.util.Log;
import com.android.gallery3d.filtershow.imageshow.ImageShow;
import com.android.gallery3d.filtershow.presets.ImagePreset;
+import java.util.Vector;
+
public class DirectPresetCache implements Cache {
private static final String LOGTAG = "DirectPresetCache";
private Bitmap mOriginalBitmap = null;
- private Vector<ImageShow> mObservers = new Vector<ImageShow>();
- private Vector<CachedPreset> mCache = new Vector<CachedPreset>();
+ private final Vector<ImageShow> mObservers = new Vector<ImageShow>();
+ private final Vector<CachedPreset> mCache = new Vector<CachedPreset>();
private int mCacheSize = 1;
- private Bitmap.Config mBitmapConfig = Bitmap.Config.ARGB_8888;
+ private final Bitmap.Config mBitmapConfig = Bitmap.Config.ARGB_8888;
private long mGlobalAge = 0;
+ private ImageLoader mLoader = null;
protected class CachedPreset {
private Bitmap mBitmap = null;
@@ -34,10 +34,12 @@ public class DirectPresetCache implements Cache {
}
}
- public DirectPresetCache(int size) {
+ public DirectPresetCache(ImageLoader loader, int size) {
+ mLoader = loader;
mCacheSize = size;
}
+ @Override
public void setOriginalBitmap(Bitmap bitmap) {
mOriginalBitmap = bitmap;
notifyObservers();
@@ -50,6 +52,7 @@ public class DirectPresetCache implements Cache {
}
}
+ @Override
public void addObserver(ImageShow observer) {
if (!mObservers.contains(observer)) {
mObservers.add(observer);
@@ -66,6 +69,7 @@ public class DirectPresetCache implements Cache {
return null;
}
+ @Override
public Bitmap get(ImagePreset preset) {
// Log.v(LOGTAG, "get preset " + preset.name() + " : " + preset);
CachedPreset cache = getCachedPreset(preset);
@@ -77,6 +81,7 @@ public class DirectPresetCache implements Cache {
return null;
}
+ @Override
public void reset(ImagePreset preset) {
CachedPreset cache = getCachedPreset(preset);
if (cache != null && !cache.mBusy) {
@@ -120,10 +125,16 @@ public class DirectPresetCache implements Cache {
protected void compute(CachedPreset cache) {
cache.mBitmap = null;
cache.mBitmap = mOriginalBitmap.copy(mBitmapConfig, true);
- cache.mPreset.apply(cache.mBitmap);
+ float scaleFactor = (float) cache.mBitmap.getWidth() / (float) mLoader.getOriginalBounds().width();
+ if (scaleFactor < 1.0f) {
+ cache.mPreset.setIsHighQuality(false);
+ }
+ cache.mPreset.setScaleFactor(scaleFactor);
+ cache.mBitmap = cache.mPreset.apply(cache.mBitmap);
cache.mAge = mGlobalAge++;
}
+ @Override
public void prepare(ImagePreset preset) {
// Log.v(LOGTAG, "prepare preset " + preset.name() + " : " + preset);
CachedPreset cache = getCachedPreset(preset);
diff --git a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java
index 8dd81d4d0..c0c310374 100644
--- a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java
+++ b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java
@@ -32,6 +32,9 @@ public class ImagePreset {
protected boolean mVerticalFlip = false;
protected RectF mCrop = null;
+ private float mScaleFactor = 1.0f;
+ private boolean mIsHighQuality = false;
+
public ImagePreset() {
setup();
}
@@ -50,6 +53,9 @@ public class ImagePreset {
mStraightenRotate = source.mStraightenRotate;
mStraightenZoom = source.mStraightenZoom;
+
+ mScaleFactor = source.mScaleFactor;
+ mIsHighQuality = source.mIsHighQuality;
}
public void setStraightenRotation(float rotate, float zoom) {
@@ -57,7 +63,7 @@ public class ImagePreset {
mStraightenZoom = zoom;
}
- private Bitmap applyGeometry(Bitmap original) {
+ private Bitmap applyGeometry(Bitmap original, float scaleFactor, boolean highQuality) {
Bitmap bitmap = original;
if (mFullRotate != FullRotate.ZERO) {
@@ -67,7 +73,7 @@ public class ImagePreset {
if (mStraightenRotate != 0) {
// TODO: keep the instances around
ImageFilter straighten = new ImageFilterStraighten(mStraightenRotate, mStraightenZoom);
- straighten.apply(bitmap);
+ bitmap = straighten.apply(bitmap, scaleFactor, highQuality);
straighten = null;
}
@@ -154,7 +160,7 @@ public class ImagePreset {
public Bitmap apply(Bitmap original) {
// First we apply any transform -- 90 rotate, flip, straighten, crop
- Bitmap bitmap = applyGeometry(original);
+ Bitmap bitmap = applyGeometry(original, mScaleFactor, mIsHighQuality);
// TODO -- apply borders separately
ImageFilter borderFilter = null;
@@ -164,11 +170,11 @@ public class ImagePreset {
// TODO don't use the name as an id
borderFilter = filter;
} else {
- filter.apply(bitmap);
+ bitmap = filter.apply(bitmap, mScaleFactor, mIsHighQuality);
}
}
if (borderFilter != null) {
- borderFilter.apply(bitmap);
+ bitmap = borderFilter.apply(bitmap, mScaleFactor, mIsHighQuality);
}
if (mEndPoint != null) {
mEndPoint.updateFilteredImage(bitmap);
@@ -185,4 +191,19 @@ public class ImagePreset {
imageStateAdapter.notifyDataSetChanged();
}
+ public float getScaleFactor() {
+ return mScaleFactor;
+ }
+
+ public boolean isHighQuality() {
+ return mIsHighQuality;
+ }
+
+ public void setIsHighQuality(boolean value) {
+ mIsHighQuality = value;
+ }
+
+ public void setScaleFactor(float value) {
+ mScaleFactor = value;
+ }
}