diff options
-rw-r--r-- | jni/Android.mk | 1 | ||||
-rw-r--r-- | jni/filters/fx.c | 88 | ||||
-rw-r--r-- | res/drawable/filtershow_fx_0000_vintage.png | bin | 0 -> 11635 bytes | |||
-rw-r--r-- | res/drawable/filtershow_fx_0001_instant.png | bin | 0 -> 11179 bytes | |||
-rw-r--r-- | res/drawable/filtershow_fx_0002_bleach.png | bin | 0 -> 12263 bytes | |||
-rw-r--r-- | res/drawable/filtershow_fx_0003_blue_crush.png | bin | 0 -> 11417 bytes | |||
-rw-r--r-- | res/drawable/filtershow_fx_0004_bw_contrast.png | bin | 0 -> 4389 bytes | |||
-rw-r--r-- | res/drawable/filtershow_fx_0005_punch.png | bin | 0 -> 11338 bytes | |||
-rw-r--r-- | res/drawable/filtershow_fx_0006_x_process.png | bin | 0 -> 8548 bytes | |||
-rw-r--r-- | res/drawable/filtershow_fx_0007_washout.png | bin | 0 -> 5907 bytes | |||
-rw-r--r-- | res/drawable/filtershow_fx_0008_washout_color.png | bin | 0 -> 11387 bytes | |||
-rw-r--r-- | res/values/strings.xml | 18 | ||||
-rw-r--r-- | src/com/android/gallery3d/filtershow/FilterShowActivity.java | 38 | ||||
-rw-r--r-- | src/com/android/gallery3d/filtershow/filters/ImageFilterFx.java | 41 | ||||
-rw-r--r-- | src/com/android/gallery3d/filtershow/presets/ImagePresetFX.java | 29 |
15 files changed, 214 insertions, 1 deletions
diff --git a/jni/Android.mk b/jni/Android.mk index 92789c157..f2f714d50 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -36,6 +36,7 @@ LOCAL_SRC_FILES := filters/bw.c \ filters/geometry.c \ filters/vignette.c \ filters/redEyeMath.c \ + filters/fx.c \ filters/redeye.c LOCAL_CFLAGS += -ffast-math -O3 -funroll-loops diff --git a/jni/filters/fx.c b/jni/filters/fx.c new file mode 100644 index 000000000..24fa5e0d7 --- /dev/null +++ b/jni/filters/fx.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "filters.h" + +__inline__ int interp(unsigned char *src, int p , int *off ,float dr,float dg, float db){ + + float fr00 = (src[p+off[0]])*(1-dr)+(src[p+off[1]])*dr; + float fr01 = (src[p+off[2]])*(1-dr)+(src[p+off[3]])*dr; + float fr10 = (src[p+off[4]])*(1-dr)+(src[p+off[5]])*dr; + float fr11 = (src[p+off[6]])*(1-dr)+(src[p+off[7]])*dr; + float frb0 = fr00 * (1-db)+fr01*db; + float frb1 = fr10 * (1-db)+fr11*db; + float frbg = frb0 * (1-dg)+frb1*dg; + + return (int)frbg ; +} + +void JNIFUNCF(ImageFilterFx, nativeApplyFilter, jobject bitmap, jint width, jint height, jobject lutbitmap,jint lutwidth, jint lutheight ) +{ + char* destination = 0; + char* lut = 0; + AndroidBitmap_lockPixels(env, bitmap, (void**) &destination); + AndroidBitmap_lockPixels(env, lutbitmap, (void**) &lut); + unsigned char * rgb = (unsigned char * )destination; + unsigned char * lutrgb = (unsigned char * )lut; + int lutdim_r = lutheight; + int lutdim_g = lutheight;; + int lutdim_b = lutwidth/lutheight;; + int STEP = 4; + + int off[8] = { + 0, + STEP*1, + STEP*lutdim_r, + STEP*(lutdim_r + 1), + STEP*(lutdim_r*lutdim_b), + STEP*(lutdim_r*lutdim_b+1), + STEP*(lutdim_r*lutdim_b+lutdim_r), + STEP*(lutdim_r*lutdim_b+lutdim_r + 1) + }; + + float scale_R = (lutdim_r-1.f)/256.f; + float scale_G = (lutdim_g-1.f)/256.f; + float scale_B = (lutdim_b-1.f)/256.f; + + int i; + int len = width * height * STEP; + + for (i = 0; i < len; i+=STEP) + { + int r = rgb[RED]; + int g = rgb[GREEN]; + int b = rgb[BLUE]; + + float fb = b*scale_B; + float fg = g*scale_G; + float fr = r*scale_R; + int lut_b = (int)fb; + int lut_g = (int)fg; + int lut_r = (int)fr; + int p = lut_r+lut_b*lutdim_r+lut_g*lutdim_r*lutdim_b; + p*=STEP; + float dr = fr-lut_r; + float dg = fg-lut_g; + float db = fb-lut_b; + rgb[RED] = clamp(interp(lutrgb,p ,off,dr,dg,db)); + rgb[GREEN] = clamp(interp(lutrgb,p+1,off,dr,dg,db)); + rgb[BLUE] = clamp(interp(lutrgb,p+2,off,dr,dg,db)); + + } + + AndroidBitmap_unlockPixels(env, bitmap); + AndroidBitmap_unlockPixels(env, lutbitmap); +} diff --git a/res/drawable/filtershow_fx_0000_vintage.png b/res/drawable/filtershow_fx_0000_vintage.png Binary files differnew file mode 100644 index 000000000..6783bb607 --- /dev/null +++ b/res/drawable/filtershow_fx_0000_vintage.png diff --git a/res/drawable/filtershow_fx_0001_instant.png b/res/drawable/filtershow_fx_0001_instant.png Binary files differnew file mode 100644 index 000000000..1652a4b9f --- /dev/null +++ b/res/drawable/filtershow_fx_0001_instant.png diff --git a/res/drawable/filtershow_fx_0002_bleach.png b/res/drawable/filtershow_fx_0002_bleach.png Binary files differnew file mode 100644 index 000000000..afb8a82bc --- /dev/null +++ b/res/drawable/filtershow_fx_0002_bleach.png diff --git a/res/drawable/filtershow_fx_0003_blue_crush.png b/res/drawable/filtershow_fx_0003_blue_crush.png Binary files differnew file mode 100644 index 000000000..2b238e3f8 --- /dev/null +++ b/res/drawable/filtershow_fx_0003_blue_crush.png diff --git a/res/drawable/filtershow_fx_0004_bw_contrast.png b/res/drawable/filtershow_fx_0004_bw_contrast.png Binary files differnew file mode 100644 index 000000000..40eb397da --- /dev/null +++ b/res/drawable/filtershow_fx_0004_bw_contrast.png diff --git a/res/drawable/filtershow_fx_0005_punch.png b/res/drawable/filtershow_fx_0005_punch.png Binary files differnew file mode 100644 index 000000000..e7e080379 --- /dev/null +++ b/res/drawable/filtershow_fx_0005_punch.png diff --git a/res/drawable/filtershow_fx_0006_x_process.png b/res/drawable/filtershow_fx_0006_x_process.png Binary files differnew file mode 100644 index 000000000..5de9bb484 --- /dev/null +++ b/res/drawable/filtershow_fx_0006_x_process.png diff --git a/res/drawable/filtershow_fx_0007_washout.png b/res/drawable/filtershow_fx_0007_washout.png Binary files differnew file mode 100644 index 000000000..20dfb5e06 --- /dev/null +++ b/res/drawable/filtershow_fx_0007_washout.png diff --git a/res/drawable/filtershow_fx_0008_washout_color.png b/res/drawable/filtershow_fx_0008_washout_color.png Binary files differnew file mode 100644 index 000000000..bb6602bda --- /dev/null +++ b/res/drawable/filtershow_fx_0008_washout_color.png diff --git a/res/values/strings.xml b/res/values/strings.xml index 67ba40d7e..c6ef704d7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -323,6 +323,24 @@ <!-- String indicating camera flash is not used. [CHAR LIMIT=14] --> <string name="flash_off">No flash</string> + <!-- String for filter filtershow_fx_0000_vintage [CHAR LIMIT=14] --> + <string name="ffx_vintage">Vintage</string> + <!-- String for filter filtershow_fx_0001_instant [CHAR LIMIT=14] --> + <string name="ffx_instant">Instant</string> + <!-- String for filter filtershow_fx_0002_bleach [CHAR LIMIT=14] --> + <string name="ffx_bleach">Bleach</string> + <!-- String for filter filtershow_fx_0003_blue_crush [CHAR LIMIT=14] --> + <string name="ffx_blue_crush">Blue Crush</string> + <!-- String for filter filtershow_fx_0004_bw_contrast [CHAR LIMIT=14] --> + <string name="ffx_bw_contrast">BW Contrast</string> + <!-- String for filter filtershow_fx_0005_punch [CHAR LIMIT=14] --> + <string name="ffx_punch">Punch</string> + <!-- String for filter filtershow_fx_0006_x_process [CHAR LIMIT=14] --> + <string name="ffx_x_process">X Process</string> + <!-- String for filter filtershow_fx_0007_washout [CHAR LIMIT=14] --> + <string name="ffx_washout">Washout</string> + <!-- String for filter filtershow_fx_0008_washout_color [CHAR LIMIT=14] --> + <string name="ffx_washout_color">Washout Color</string> <!-- Toast message shown after we make some album(s) available offline [CHAR LIMIT=50] --> <plurals name="make_albums_available_offline"> 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)); + } + } + +} |