summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-03-12 14:30:33 -0700
committernicolasroard <nicolasroard@google.com>2013-03-12 14:30:33 -0700
commit3243862413deeda922d2a1f087b89ceb789882b5 (patch)
treef01739f6ddb492b3800f30e98f2b0a97815979dc /src
parentb22a84a9baa7e64b5f9c77244c1586385e38a241 (diff)
downloadandroid_packages_apps_Snap-3243862413deeda922d2a1f087b89ceb789882b5.tar.gz
android_packages_apps_Snap-3243862413deeda922d2a1f087b89ceb789882b5.tar.bz2
android_packages_apps_Snap-3243862413deeda922d2a1f087b89ceb789882b5.zip
Add loading resources helper functions to ImageFilterRS
Change-Id: I79b4996b5da0fa05536f2f53f770d01e9735b96c
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
index a06c2e022..978bc8bd1 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.filtershow.filters;
import android.app.Activity;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.support.v8.renderscript.*;
import android.util.Log;
import com.android.gallery3d.R;
@@ -119,12 +120,16 @@ public abstract class ImageFilterRS extends ImageFilter {
sOldBitmap = null;
}
- public Allocation convertRGBAtoA(Bitmap bitmap) {
+ private Allocation convertBitmap(Bitmap bitmap) {
+ return Allocation.createFromBitmap(mRS, bitmap,
+ Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
+ }
+
+ private Allocation convertRGBAtoA(Bitmap bitmap) {
Type.Builder tb_a8 = new Type.Builder(mRS, Element.U8(mRS));
ScriptC_grey greyConvert = new ScriptC_grey(mRS, mResources, R.raw.grey);
- Allocation bitmapTemp = Allocation.createFromBitmap(mRS, bitmap);
-
+ Allocation bitmapTemp = convertBitmap(bitmap);
if (bitmapTemp.getType().getElement().isCompatible(Element.U8(mRS))) {
return bitmapTemp;
}
@@ -137,6 +142,28 @@ public abstract class ImageFilterRS extends ImageFilter {
return bitmapAlloc;
}
+ public Allocation loadResourceAlpha(int resource) {
+ final BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inPreferredConfig = Bitmap.Config.ALPHA_8;
+ Bitmap bitmap = BitmapFactory.decodeResource(
+ mRS.getApplicationContext().getResources(),
+ resource, options);
+ Allocation ret = convertRGBAtoA(bitmap);
+ bitmap.recycle();
+ return ret;
+ }
+
+ public Allocation loadResource(int resource) {
+ final BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ Bitmap bitmap = BitmapFactory.decodeResource(
+ mRS.getApplicationContext().getResources(),
+ resource, options);
+ Allocation ret = convertBitmap(bitmap);
+ bitmap.recycle();
+ return ret;
+ }
+
public boolean isResourcesLoaded() {
return mResourcesLoaded;
}