summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jni/Android.mk3
-rw-r--r--jni/filters/brightness.c37
-rw-r--r--jni/filters/contrast.c46
-rw-r--r--jni/filters/filters.h2
-rw-r--r--jni/filters/hue.c46
5 files changed, 134 insertions, 0 deletions
diff --git a/jni/Android.mk b/jni/Android.mk
index 846c0f215..8453f76d1 100644
--- a/jni/Android.mk
+++ b/jni/Android.mk
@@ -27,6 +27,9 @@ LOCAL_MODULE := libjni_filtershow_filters
LOCAL_SRC_FILES := filters/bw.c \
filters/gradient.c \
filters/saturated.c \
+ filters/brightness.c \
+ filters/contrast.c \
+ filters/hue.c \
filters/vignette.c
LOCAL_CFLAGS += -ffast-math -O3 -funroll-loops
diff --git a/jni/filters/brightness.c b/jni/filters/brightness.c
new file mode 100644
index 000000000..88044a28c
--- /dev/null
+++ b/jni/filters/brightness.c
@@ -0,0 +1,37 @@
+/*
+ * 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"
+
+void JNIFUNCF(ImageFilterBrightness, nativeApplyFilter, jobject bitmap, jint width, jint height, jfloat bright)
+{
+ char* destination = 0;
+ AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
+ unsigned char * rgb = (unsigned char * )destination;
+ int i;
+ int len = width * height * 4;
+ int c = (int)(bright);
+ int m = (c>0)?(255+c):255;
+
+ for (i = 0; i < len; i+=4)
+ {
+ rgb[RED] = clamp((255*(rgb[RED]))/m+c);
+ rgb[GREEN] = clamp((255*(rgb[GREEN]))/m+c);
+ rgb[BLUE] = clamp((255*(rgb[BLUE]))/m+c);
+ }
+ AndroidBitmap_unlockPixels(env, bitmap);
+}
+
diff --git a/jni/filters/contrast.c b/jni/filters/contrast.c
new file mode 100644
index 000000000..45209c1fb
--- /dev/null
+++ b/jni/filters/contrast.c
@@ -0,0 +1,46 @@
+/*
+ * 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"
+
+unsigned char clamp(int c)
+{
+ int N = 255;
+ c &= ~(c >> 31);
+ c -= N;
+ c &= (c >> 31);
+ c += N;
+ return (unsigned char) c;
+}
+
+void JNIFUNCF(ImageFilterContrast, nativeApplyFilter, jobject bitmap, jint width, jint height, jfloat bright)
+{
+ char* destination = 0;
+ AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
+ unsigned char * rgb = (unsigned char * )destination;
+ int i;
+ int len = width * height * 4;
+ float m = (float)pow(2, bright/100.);
+ float c = 127-m*127;
+
+ for (i = 0; i < len; i+=4) {
+ rgb[RED] = clamp((int)(m*rgb[RED]+c));
+ rgb[GREEN] = clamp((int)(m*rgb[GREEN]+c));
+ rgb[BLUE] = clamp((int)(m*rgb[BLUE]+c));
+ }
+ AndroidBitmap_unlockPixels(env, bitmap);
+}
+
diff --git a/jni/filters/filters.h b/jni/filters/filters.h
index f8c4c5d08..5fe595b9e 100644
--- a/jni/filters/filters.h
+++ b/jni/filters/filters.h
@@ -43,4 +43,6 @@ typedef unsigned int Color;
#define ALPHA i+3
#define CLAMP(c) (MAX(0, MIN(255, c)))
+unsigned char __inline__ clamp(int c);
+
#endif // FILTERS_H
diff --git a/jni/filters/hue.c b/jni/filters/hue.c
new file mode 100644
index 000000000..a4aef936d
--- /dev/null
+++ b/jni/filters/hue.c
@@ -0,0 +1,46 @@
+/*
+ * 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"
+
+void JNIFUNCF(ImageFilterHue, nativeApplyFilter, jobject bitmap, jint width, jint height, jfloatArray matrix)
+{
+ char* destination = 0;
+ AndroidBitmap_lockPixels(env, bitmap, (void**) &destination);
+ unsigned char * rgb = (unsigned char * )destination;
+ int i;
+ int len = width * height * 4;
+ jfloat* mat = (*env)->GetFloatArrayElements(env, matrix,0);
+
+ for (i = 0; i < len; i+=4)
+ {
+ int r = rgb[RED];
+ int g = rgb[GREEN];
+ int b = rgb[BLUE];
+
+ float rf = r*mat[0] + g*mat[4] + b*mat[8] + mat[12];
+ float gf = r*mat[1] + g*mat[5] + b*mat[9] + mat[13];
+ float bf = r*mat[2] + g*mat[6] + b*mat[10] + mat[14];
+
+ rgb[RED] = clamp((int)rf);
+ rgb[GREEN] = clamp((int)gf);
+ rgb[BLUE] = clamp((int)bf);
+ }
+
+ (*env)->ReleaseFloatArrayElements(env, matrix, mat, 0);
+ AndroidBitmap_unlockPixels(env, bitmap);
+}
+