summaryrefslogtreecommitdiffstats
path: root/jni
diff options
context:
space:
mode:
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 1843c77..e612486 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 6c1b976..b04e936 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 d518b63..14b69cd 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 0000000..fe9b88f
--- /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);
+}