From 9ea20852baf8a2eeae2e4fc19f12a9f35b106b0c Mon Sep 17 00:00:00 2001 From: John Hoford Date: Tue, 9 Oct 2012 16:17:17 -0700 Subject: add filters bug:7234321 Change-Id: I4c9695c3ad90fcb7f4d67d40faa0a7da85f99030 --- .../gallery3d/filtershow/FilterShowActivity.java | 38 +++++++++++++++++++- .../filtershow/filters/ImageFilterFx.java | 41 ++++++++++++++++++++++ .../filtershow/presets/ImagePresetFX.java | 29 +++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java create mode 100644 src/com/android/gallery3d/filtershow/presets/ImagePresetFX.java (limited to 'src') diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index f2fb3da9d..1cd5fded6 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -6,9 +6,13 @@ import android.app.ActionBar; import android.app.Activity; import android.app.ProgressDialog; import android.content.ContentValues; +import android.content.Context; import android.content.Intent; import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.Color; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -33,6 +37,7 @@ import com.android.gallery3d.R; import com.android.gallery3d.filtershow.cache.ImageLoader; import com.android.gallery3d.filtershow.filters.ImageFilter; import com.android.gallery3d.filtershow.filters.ImageFilterBorder; +import com.android.gallery3d.filtershow.filters.ImageFilterFx; import com.android.gallery3d.filtershow.filters.ImageFilterParametricBorder; import com.android.gallery3d.filtershow.filters.ImageFilterRS; import com.android.gallery3d.filtershow.imageshow.ImageBorder; @@ -48,6 +53,7 @@ import com.android.gallery3d.filtershow.presets.ImagePresetBW; import com.android.gallery3d.filtershow.presets.ImagePresetBWBlue; import com.android.gallery3d.filtershow.presets.ImagePresetBWGreen; import com.android.gallery3d.filtershow.presets.ImagePresetBWRed; +import com.android.gallery3d.filtershow.presets.ImagePresetFX; import com.android.gallery3d.filtershow.presets.ImagePresetOld; import com.android.gallery3d.filtershow.presets.ImagePresetSaturated; import com.android.gallery3d.filtershow.presets.ImagePresetXProcessing; @@ -390,8 +396,38 @@ public class FilterShowActivity extends Activity implements OnItemClickListener, private void fillListImages(LinearLayout listFilters) { // TODO: use listview // TODO: load the filters straight from the filesystem - ImagePreset[] preset = new ImagePreset[9]; + ImagePreset[] preset = new ImagePreset[18]; int p = 0; + + int[]drawid = { + R.drawable.filtershow_fx_0000_vintage, + R.drawable.filtershow_fx_0001_instant, + R.drawable.filtershow_fx_0002_bleach, + R.drawable.filtershow_fx_0003_blue_crush, + R.drawable.filtershow_fx_0004_bw_contrast, + R.drawable.filtershow_fx_0005_punch, + R.drawable.filtershow_fx_0006_x_process, + R.drawable.filtershow_fx_0007_washout, + R.drawable.filtershow_fx_0008_washout_color + }; + + int[]fxNameid = { + R.string.ffx_vintage, + R.string.ffx_instant, + R.string.ffx_bleach, + R.string.ffx_blue_crush, + R.string.ffx_bw_contrast, + R.string.ffx_punch, + R.string.ffx_x_process, + R.string.ffx_washout, + R.string.ffx_washout_color, + }; + + for (int i = 0; i < drawid.length; i++) { + Bitmap b = BitmapFactory.decodeResource(getResources(),drawid[i]); + preset[p++] = new ImagePresetFX(b, getString(fxNameid[i])); + } + preset[p++] = new ImagePreset(); preset[p++] = new ImagePresetSaturated(); preset[p++] = new ImagePresetOld(); diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java new file mode 100644 index 000000000..00fd20cf5 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java @@ -0,0 +1,41 @@ + +package com.android.gallery3d.filtershow.filters; + +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.util.Log; + +import com.android.gallery3d.R; + +import java.util.Arrays; + +public class ImageFilterFx extends ImageFilter { + private static final String TAG = "ImageFilterFx"; + Bitmap fxBitmap; + + public ImageFilterFx(Bitmap fxBitmap) { + mName = "fx"; + this.fxBitmap = fxBitmap; + } + + @Override + public ImageFilter clone() throws CloneNotSupportedException { + ImageFilterFx filter = (ImageFilterFx) super.clone(); + filter.fxBitmap = this.fxBitmap; + return filter; + } + + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h,Bitmap fxBitmap, int fxw, int fxh); + + public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { + + int w = bitmap.getWidth(); + int h = bitmap.getHeight(); + + int fxw = fxBitmap.getWidth(); + int fxh = fxBitmap.getHeight(); + + nativeApplyFilter(bitmap, w, h, fxBitmap, fxw, fxh); + return bitmap; + } +} diff --git a/src/com/android/gallery3d/filtershow/presets/ImagePresetFX.java b/src/com/android/gallery3d/filtershow/presets/ImagePresetFX.java new file mode 100644 index 000000000..326471ef3 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/presets/ImagePresetFX.java @@ -0,0 +1,29 @@ + +package com.android.gallery3d.filtershow.presets; + +import android.graphics.Bitmap; + +import com.android.gallery3d.filtershow.filters.ImageFilterBWRed; +import com.android.gallery3d.filtershow.filters.ImageFilterFx; + +public class ImagePresetFX extends ImagePreset { + String name; + Bitmap fxBitmap; + + public String name() { + return name; + } + + public ImagePresetFX(Bitmap bitmap, String name) { + fxBitmap = bitmap; + this.name = name; + setup(); + } + + public void setup() { + if (fxBitmap != null) { + mFilters.add(new ImageFilterFx(fxBitmap)); + } + } + +} -- cgit v1.2.3