From e4f998bbf493636cf93554fbb2a3d90186e65b5f Mon Sep 17 00:00:00 2001 From: John Hoford Date: Wed, 20 Feb 2013 17:50:42 -0800 Subject: add highlight filter Change-Id: I2e59e09fbc80172b9dfe27b3ce8ff2f1e24c5872 --- jni/Android.mk | 1 + jni/filters/contrast.c | 9 +++++++++ jni/filters/filters.h | 1 + jni/filters/highlight.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 jni/filters/highlight.c (limited to 'jni') 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 +#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); +} -- cgit v1.2.3