summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jni/Android.mk2
-rw-r--r--jni/filters/filters.h3
-rw-r--r--jni/filters/hsv.c144
-rw-r--r--jni/filters/shadows.c39
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java6
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java61
-rw-r--r--src/com/android/gallery3d/filtershow/ui/ControlPoint.java2
7 files changed, 253 insertions, 4 deletions
diff --git a/jni/Android.mk b/jni/Android.mk
index 38fa453b9..f6c3c81d1 100644
--- a/jni/Android.mk
+++ b/jni/Android.mk
@@ -30,6 +30,8 @@ LOCAL_SRC_FILES := filters/bw.c \
filters/exposure.c \
filters/contrast.c \
filters/hue.c \
+ filters/shadows.c \
+ filters/hsv.c \
filters/vignette.c
LOCAL_CFLAGS += -ffast-math -O3 -funroll-loops
diff --git a/jni/filters/filters.h b/jni/filters/filters.h
index 44a442290..954d02ddd 100644
--- a/jni/filters/filters.h
+++ b/jni/filters/filters.h
@@ -45,4 +45,7 @@ typedef unsigned int Color;
__inline__ unsigned char clamp(int c);
+extern void rgb2hsv( unsigned char *rgb,int rgbOff,unsigned short *hsv,int hsvOff);
+extern void hsv2rgb(unsigned short *hsv,int hsvOff,unsigned char *rgb,int rgbOff);
+
#endif // FILTERS_H
diff --git a/jni/filters/hsv.c b/jni/filters/hsv.c
new file mode 100644
index 000000000..af438f87a
--- /dev/null
+++ b/jni/filters/hsv.c
@@ -0,0 +1,144 @@
+/*
+ * 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 <math.h>
+#include "filters.h"
+
+void rgb2hsv( unsigned char *rgb,int rgbOff,unsigned short *hsv,int hsvOff)
+{
+ int iMin,iMax,chroma;
+ int ABITS = 4;
+ int HSCALE = 256;
+
+ int k1=255 << ABITS;
+ int k2=HSCALE << ABITS;
+
+ int ri = rgb[rgbOff+0];
+ int gi = rgb[rgbOff+1];
+ int bi = rgb[rgbOff+2];
+ short rv,rs,rh;
+
+ if (ri > gi) {
+ iMax = MAX (ri, bi);
+ iMin = MIN (gi, bi);
+ } else {
+ iMax = MAX (gi, bi);
+ iMin = MIN (ri, bi);
+ }
+
+ chroma = iMax - iMin;
+ // set value
+ rv = (short)( iMax << ABITS);
+
+ // set saturation
+ if (rv == 0)
+ rs = 0;
+ else
+ rs = (short)((k1*chroma)/iMax);
+
+ // set hue
+ if (rs == 0)
+ rh = 0;
+ else {
+ if ( ri == iMax ) {
+ rh = (short)( (k2*(6*chroma+gi - bi))/(6*chroma));
+ if (rh >= k2) rh -= k2;
+ } else if (gi == iMax)
+ rh = (short)( (k2*(2*chroma+bi - ri ))/(6*chroma));
+ else // (bi == iMax )
+ rh = (short)( (k2*(4*chroma+ri - gi ))/(6*chroma));
+ }
+ hsv[hsvOff+0] = rv;
+ hsv[hsvOff+1] = rs;
+ hsv[hsvOff+2] = rh;
+ }
+
+ void hsv2rgb(unsigned short *hsv,int hsvOff, unsigned char *rgb,int rgbOff)
+ {
+ int ABITS = 4;
+ int HSCALE = 256;
+ int m;
+ int H,X,ih,is,iv;
+ int k1=255<<ABITS;
+ int k2=HSCALE<<ABITS;
+ int k3=1<<(ABITS-1);
+ int rr=0;
+ int rg=0;
+ int rb=0;
+ short cv = hsv[hsvOff+0];
+ short cs = hsv[hsvOff+1];
+ short ch = hsv[hsvOff+2];
+
+ // set chroma and min component value m
+ //chroma = ( cv * cs )/k1;
+ //m = cv - chroma;
+ m = ((int)cv*(k1 - (int)cs ))/k1;
+
+ // chroma == 0 <-> cs == 0 --> m=cv
+ if (cs == 0) {
+ rb = ( rg = ( rr =( cv >> ABITS) ));
+ } else {
+ ih=(int)ch;
+ is=(int)cs;
+ iv=(int)cv;
+
+ H = (6*ih)/k2;
+ X = ((iv*is)/k2)*(k2- abs(6*ih- 2*(H>>1)*k2 - k2)) ;
+
+ // removing additional bits --> unit8
+ X=( (X+iv*(k1 - is ))/k1 + k3 ) >> ABITS;
+ m=m >> ABITS;
+
+ // ( chroma + m ) --> cv ;
+ cv=(short) (cv >> ABITS);
+ switch (H) {
+ case 0:
+ rr = cv;
+ rg = X;
+ rb = m;
+ break;
+ case 1:
+ rr = X;
+ rg = cv;
+ rb = m;
+ break;
+ case 2:
+ rr = m;
+ rg = cv;
+ rb = X;
+ break;
+ case 3:
+ rr = m;
+ rg = X;
+ rb = cv;
+ break;
+ case 4:
+ rr = X;
+ rg = m;
+ rb = cv;
+ break;
+ case 5:
+ rr = cv;
+ rg = m ;
+ rb = X;
+ break;
+ }
+ }
+ rgb[rgbOff+0] = rr;
+ rgb[rgbOff+1] = rg;
+ rgb[rgbOff+2] = rb;
+ }
+
diff --git a/jni/filters/shadows.c b/jni/filters/shadows.c
new file mode 100644
index 000000000..da3e33cf9
--- /dev/null
+++ b/jni/filters/shadows.c
@@ -0,0 +1,39 @@
+/*
+ * 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 <math.h>
+#include "filters.h"
+
+ void JNIFUNCF(ImageFilterShadows, nativeApplyFilter, jobject bitmap, jint width, jint height, jshortArray vlut)
+ {
+ char* destination = 0;
+ AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
+ unsigned char * rgb = (unsigned char * )destination;
+ int i;
+ int len = width * height * 4;
+ short* lut = (*env)->GetShortArrayElements(env, vlut,0);
+ unsigned short * hsv = (unsigned short *)malloc(3*sizeof(short));
+ for (i = 0; i < len; i+=4)
+ {
+ rgb2hsv(rgb,i,hsv,0);
+ hsv[0] = lut[hsv[0]];
+ hsv2rgb(hsv,0, rgb,i);
+ }
+
+ (*env)->ReleaseShortArrayElements(env, vlut, lut, 0);
+ free(lut);
+ AndroidBitmap_unlockPixels(env, bitmap);
+ }
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index b50ab94d6..694f51290 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -783,14 +783,14 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
mImageShow.setVisibility(View.VISIBLE);
mImageShow.setShowControls(true);
ImagePreset preset = mImageShow.getImagePreset();
- ImageFilter filter = preset.getFilter("Hue");
+ ImageFilter filter = preset.getFilter("Shadows");
if (filter == null) {
- ImageFilterHue contrast = new ImageFilterHue();
+ ImageFilterShadows contrast = new ImageFilterShadows();
ImagePreset copy = new ImagePreset(preset);
copy.add(contrast);
copy.setHistoryName(contrast.getName());
copy.setIsFx(false);
- filter = copy.getFilter("Hue");
+ filter = copy.getFilter("Shadows");
mImageShow.setImagePreset(copy);
}
mImageShow.setCurrentFilter(filter);
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java
new file mode 100644
index 000000000..39c95064b
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java
@@ -0,0 +1,61 @@
+
+package com.android.gallery3d.filtershow.filters;
+
+import android.graphics.Bitmap;
+
+import com.android.gallery3d.filtershow.ui.ControlPoint;
+import com.android.gallery3d.filtershow.ui.Spline;
+
+public class ImageFilterShadows extends ImageFilter {
+ private final float SHADOW = .1f;
+ private final float MID = .5f;
+ private final float HIGHLIGHT = .9f;
+
+ private float []baseX = {0f,SHADOW,MID,HIGHLIGHT,1f};
+ private float []baseY = {0f,SHADOW,MID,HIGHLIGHT,1f};
+
+ public ImageFilterShadows() {
+ mName = "Shadows";
+
+ }
+ short [] calcMap(){
+ Spline sp = new Spline();
+ for (int i = 0; i < baseX.length; i++) {
+ sp.addPoint(baseX[i], baseY[i]);
+ }
+ int max = 4080;
+ int w = 40800;
+ float []px = new float[w+1];
+ float []py = new float[w+1];
+ short []vlut = new short[4080+1];
+ for (int i = 0; i < px.length; i++) {
+ float t = i/(float)(w);
+
+ ControlPoint p = sp.getPoint(t);
+ px[i] = p.x;
+ py[i] = p.y;
+ }
+ for (int i = 0; i < py.length; i++) {
+ short x = (short)Math.min(4080,Math.max(0,((int)(px[i]*max))));
+ short y = (short)Math.min(4082,Math.max(0,((int)(py[i]*max))));
+ vlut[x] = y;
+ }
+ return vlut;
+ }
+ @Override
+ public ImageFilter clone() throws CloneNotSupportedException {
+ ImageFilterShadows filter = (ImageFilterShadows) super.clone();
+ return filter;
+ }
+
+ native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, short []valMap);
+
+ public void apply(Bitmap bitmap) {
+ int w = bitmap.getWidth();
+ int h = bitmap.getHeight();
+ float p = mParameter;
+ baseY[1] = (float)(SHADOW*Math.pow(4, mParameter/100.));
+
+ nativeApplyFilter(bitmap, w, h, calcMap());
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/ui/ControlPoint.java b/src/com/android/gallery3d/filtershow/ui/ControlPoint.java
index 6daa96182..68b799a9e 100644
--- a/src/com/android/gallery3d/filtershow/ui/ControlPoint.java
+++ b/src/com/android/gallery3d/filtershow/ui/ControlPoint.java
@@ -1,7 +1,7 @@
package com.android.gallery3d.filtershow.ui;
-class ControlPoint implements Comparable {
+public class ControlPoint implements Comparable {
public ControlPoint(float px, float py) {
x = px;
y = py;