summaryrefslogtreecommitdiffstats
path: root/jni
diff options
context:
space:
mode:
authorJohn Hoford <hoford@google.com>2013-02-20 17:50:42 -0800
committerJohn Hoford <hoford@google.com>2013-02-21 11:24:47 -0800
commite4f998bbf493636cf93554fbb2a3d90186e65b5f (patch)
tree2126b95fb350eda463063af24fdd1b566037de6e /jni
parent4c54808f10fa647c4dc8f95551eb369172535d50 (diff)
downloadandroid_packages_apps_Snap-e4f998bbf493636cf93554fbb2a3d90186e65b5f.tar.gz
android_packages_apps_Snap-e4f998bbf493636cf93554fbb2a3d90186e65b5f.tar.bz2
android_packages_apps_Snap-e4f998bbf493636cf93554fbb2a3d90186e65b5f.zip
add highlight filter
Change-Id: I2e59e09fbc80172b9dfe27b3ce8ff2f1e24c5872
Diffstat (limited to 'jni')
-rw-r--r--jni/Android.mk1
-rw-r--r--jni/filters/contrast.c9
-rw-r--r--jni/filters/filters.h1
-rw-r--r--jni/filters/highlight.c40
4 files changed, 51 insertions, 0 deletions
diff --git a/jni/Android.mk b/jni/Android.mk
index 1843c77ea..e612486e1 100644
--- a/jni/Android.mk
+++ b/jni/Android.mk
@@ -32,6 +32,7 @@ LOCAL_SRC_FILES := filters/gradient.c \
filters/contrast.c \
filters/hue.c \
filters/shadows.c \
+ filters/highlight.c \
filters/hsv.c \
filters/vibrance.c \
filters/geometry.c \
diff --git a/jni/filters/contrast.c b/jni/filters/contrast.c
index 6c1b976cf..b04e9364e 100644
--- a/jni/filters/contrast.c
+++ b/jni/filters/contrast.c
@@ -27,6 +27,15 @@ unsigned char clamp(int c)
return (unsigned char) c;
}
+int clampMax(int c,int max)
+{
+ c &= ~(c >> 31);
+ c -= max;
+ c &= (c >> 31);
+ c += max;
+ return c;
+}
+
void JNIFUNCF(ImageFilterContrast, nativeApplyFilter, jobject bitmap, jint width, jint height, jfloat bright)
{
char* destination = 0;
diff --git a/jni/filters/filters.h b/jni/filters/filters.h
index d518b6398..14b69cdd4 100644
--- a/jni/filters/filters.h
+++ b/jni/filters/filters.h
@@ -44,6 +44,7 @@ typedef unsigned int Color;
#define CLAMP(c) (MAX(0, MIN(255, c)))
__inline__ unsigned char clamp(int c);
+__inline__ int clampMax(int c,int max);
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);
diff --git a/jni/filters/highlight.c b/jni/filters/highlight.c
new file mode 100644
index 000000000..fe9b88f94
--- /dev/null
+++ b/jni/filters/highlight.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2013 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(ImageFilterHighlights, nativeApplyFilter, jobject bitmap,
+ jint width, jint height, jfloatArray luminanceMap){
+ char* destination = 0;
+ AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
+ unsigned char * rgb = (unsigned char * )destination;
+ int i;
+ int len = width * height * 4;
+ jfloat* lum = (*env)->GetFloatArrayElements(env, luminanceMap,0);
+ unsigned short * hsv = (unsigned short *)malloc(3*sizeof(short));
+
+ for (i = 0; i < len; i+=4)
+ {
+ rgb2hsv(rgb,i,hsv,0);
+ int v = clampMax(hsv[0],4080);
+ hsv[0] = (unsigned short) clampMax(lum[((255*v)/4080)]*4080,4080);
+ hsv2rgb(hsv,0, rgb,i);
+ }
+
+ free(hsv);
+ AndroidBitmap_unlockPixels(env, bitmap);
+}