diff options
author | Jack Yoo <jyoo@codeaurora.org> | 2016-04-06 16:07:22 -0700 |
---|---|---|
committer | Jack Yoo <jyoo@codeaurora.org> | 2016-06-01 11:17:18 -0700 |
commit | a02710a35bfd859dbaae3557d4f278d5b1a80ab6 (patch) | |
tree | 45e1b74fbfe736a6feac9b181444d847cba2f7c4 /jni | |
parent | 77f78793bd93f0003c7e310592414f1fc93236e5 (diff) | |
download | android_packages_apps_Snap-a02710a35bfd859dbaae3557d4f278d5b1a80ab6.tar.gz android_packages_apps_Snap-a02710a35bfd859dbaae3557d4f278d5b1a80ab6.tar.bz2 android_packages_apps_Snap-a02710a35bfd859dbaae3557d4f278d5b1a80ab6.zip |
SnapdragonCamera: FrameProcessor
Introducing Frameprocessor with beautifiation.
Change-Id: Ie6d8f4157a7d0c1a21e6f347457e84685e397286
CRs-Fixed: 1023183
Diffstat (limited to 'jni')
-rw-r--r-- | jni/Android.mk | 10 | ||||
-rw-r--r-- | jni/image_util_jni.cpp | 153 |
2 files changed, 163 insertions, 0 deletions
diff --git a/jni/Android.mk b/jni/Android.mk index c94a8075d..de2abb6b8 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -63,3 +63,13 @@ LOCAL_ARM_MODE := arm include $(BUILD_SHARED_LIBRARY) +# ImageUtilForCamera2 with beautification +include $(CLEAR_VARS) +LOCAL_LDFLAGS := -llog +LOCAL_SDK_VERSION := 9 +LOCAL_MODULE := libjni_imageutil +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := image_util_jni.cpp +LOCAL_CFLAGS += -ffast-math -O3 -funroll-loops +include $(BUILD_SHARED_LIBRARY) + diff --git a/jni/image_util_jni.cpp b/jni/image_util_jni.cpp new file mode 100644 index 000000000..2297f9164 --- /dev/null +++ b/jni/image_util_jni.cpp @@ -0,0 +1,153 @@ +/* +Copyright (c) 2016, The Linux Foundation. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <jni.h> +#include <assert.h> +#include <stdlib.h> + +#ifdef __ANDROID__ +#include "android/log.h" +#define printf(...) __android_log_print( ANDROID_LOG_ERROR, "ImageUtil", __VA_ARGS__ ) +#endif + +#ifdef __cplusplus +extern "C" { +#endif +JNIEXPORT jint JNICALL Java_com_android_camera_imageprocessor_FrameProcessor_nativeRotateNV21 + (JNIEnv* env, jobject thiz, jobjectArray inBuf, + jint imageWidth, jint imageHeight, jint degree, jobjectArray outBuf); +JNIEXPORT jint JNICALL Java_com_android_camera_imageprocessor_FrameProcessor_nativeNV21toRgb( + JNIEnv *env, jobject thiz, jobjectArray yvuBuf, jobjectArray rgbBuf, jint width, jint height); +#ifdef __cplusplus +} +#endif + +typedef unsigned char uint8_t; + +void rotateBufAndMerge(uint8_t *in_buf, jint imageWidth, jint imageHeight, jint degree, uint8_t *out_buf) +{ + if(degree == 90) { + int i = 0; + for (int x = 0; x < imageWidth; x++) { + for (int y = imageHeight - 1; y >= 0; y--) { + int offset = y * imageWidth + x; + out_buf[i] = in_buf[offset]; + i++; + } + } + i = imageWidth * imageHeight; + for (int x = 0; x < imageWidth; x += 2) { + for (int y = imageHeight / 2 - 1; y >= 0; y--) { + int offset = imageWidth*imageHeight + y * imageWidth + x; + out_buf[i] = in_buf[offset]; + i++; + out_buf[i] = in_buf[offset + 1]; + i++; + } + } + } else if(degree == 270) { + int i = 0; + for (int x = imageWidth - 1; x >= 0; x--) { + for (int y = 0; y < imageHeight; y++) { + int offset = y * imageWidth + x; + out_buf[i] = in_buf[offset]; + i++; + } + } + i = imageWidth * imageHeight; + for (int x = imageWidth - 2; x >= 0; x-=2) { + for (int y = 0; y < imageHeight/2; y++) { + int offset = imageWidth*imageHeight + y * imageWidth + x; + out_buf[i] = in_buf[offset]; + i++; + out_buf[i] = in_buf[offset + 1]; + i++; + } + } + } else if(degree == 180) { + int i = 0; + for (int y = imageHeight - 1; y >= 0; y--) { + for (int x = imageWidth - 1; x >= 0 ; x--) { + int offset = y * imageWidth + x; + out_buf[i] = in_buf[offset]; + i++; + } + } + i = imageWidth * imageHeight; + for (int y = imageHeight/2 - 1; y >= 0; y--) { + for (int x = imageWidth - 2; x >= 0 ; x-=2) { + int offset = imageWidth*imageHeight + y * imageWidth + x; + out_buf[i] = in_buf[offset]; + i++; + out_buf[i] = in_buf[offset + 1]; + i++; + } + } + } +} + +jint JNICALL Java_com_android_camera_imageprocessor_FrameProcessor_nativeRotateNV21( + JNIEnv* env, jobject thiz, jobjectArray inBuf, + jint imageWidth, jint imageHeight, jint degree, jobjectArray outBuf) +{ + uint8_t *in_buf = (uint8_t *)env->GetDirectBufferAddress(inBuf); + uint8_t *out_buf = (uint8_t *)env->GetDirectBufferAddress(outBuf); + rotateBufAndMerge(in_buf, imageWidth, imageHeight, degree, out_buf); + + return 0; +} + +jint JNICALL Java_com_android_camera_imageprocessor_FrameProcessor_nativeNV21toRgb( + JNIEnv* env, jobject thiz, jobjectArray yvuBuf, jobjectArray rgbBuf, jint width, jint height) +{ + uint8_t *in_buf = (uint8_t *)env->GetDirectBufferAddress(yvuBuf); + uint8_t *rgb_buf = (uint8_t *)env->GetDirectBufferAddress(rgbBuf); + int ysize = width * height; + int y_value; + int i, v, u, r, g, b; + for(int x=0; x < width; x++) { + for(int y=0; y < height; y++) { + y_value = (in_buf[y*width+x] & 0xFF); + i = ysize + (x/2*2) + ((y/2) * width); + v = (in_buf[i] & 0xFF) - 128; + u = (in_buf[i + 1] & 0xFF) - 128; + r = (int)(1.164f * y_value + 1.596f * v); + g = (int)(1.164f * y_value - 0.813f * v - 0.391f * u); + b = (int)(1.164f * y_value + 2.018f * u); + r = r > 255 ? 255 : r < 0 ? 0 : r; + g = g > 255 ? 255 : g < 0 ? 0 : g; + b = b > 255 ? 255 : b < 0 ? 0 : b; + rgb_buf[(y*width + x) * 4 + 3] = (uint8_t)(0xFF); + rgb_buf[(y*width + x) * 4 + 2] = (uint8_t)(b & 0xFF); + rgb_buf[(y*width + x) * 4 + 1] = (uint8_t)(g & 0xFF); + rgb_buf[(y*width + x) * 4 + 0] = (uint8_t)(r & 0xFF); + } + } + return 0; +}
\ No newline at end of file |