filters/geometry.c \
filters/vignette.c \
filters/redEyeMath.c \
+ filters/fx.c \
filters/redeye.c
LOCAL_CFLAGS += -ffast-math -O3 -funroll-loops
--- /dev/null
+/*
+ * 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);
+}
<!-- 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">
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;
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;
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;
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();
--- /dev/null
+
+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;
+ }
+}
--- /dev/null
+
+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));
+ }
+ }
+
+}