summaryrefslogtreecommitdiffstats
path: root/jni
diff options
context:
space:
mode:
authorPuneet Lall <puneetl@google.com>2014-09-05 10:38:39 -0700
committerPuneet Lall <puneetl@google.com>2014-09-05 15:55:53 -0700
commit0ad7ab0b0a0d17a96438a503d0c918979b5d6480 (patch)
tree3c4d7b1b425fa1fff9ec7945e9bb4f4c4561f86b /jni
parentdf435d0e26b6fa5f0d8443b2d9098d61b54a9f00 (diff)
downloadandroid_packages_apps_Camera2-0ad7ab0b0a0d17a96438a503d0c918979b5d6480.tar.gz
android_packages_apps_Camera2-0ad7ab0b0a0d17a96438a503d0c918979b5d6480.tar.bz2
android_packages_apps_Camera2-0ad7ab0b0a0d17a96438a503d0c918979b5d6480.zip
Implemented rotation of zsl images
Bug: 17370310 Change-Id: Ida437d817482d19224d7afd2f06b00960480bd1c
Diffstat (limited to 'jni')
-rwxr-xr-xjni/Android.mk2
-rw-r--r--jni/jpegutilnative.cpp65
2 files changed, 66 insertions, 1 deletions
diff --git a/jni/Android.mk b/jni/Android.mk
index 0f95c9b9d..e12870500 100755
--- a/jni/Android.mk
+++ b/jni/Android.mk
@@ -19,7 +19,7 @@ include $(CLEAR_VARS)
LOCAL_CFLAGS := -std=c++11
LOCAL_NDK_STL_VARIANT := c++_static
-LOCAL_LDFLAGS := -llog -ldl
+LOCAL_LDFLAGS := -llog -ldl -ljnigraphics
LOCAL_SDK_VERSION := 9
LOCAL_MODULE := libjni_jpegutil
LOCAL_SRC_FILES := jpegutil.cpp jpegutilnative.cpp
diff --git a/jni/jpegutilnative.cpp b/jni/jpegutilnative.cpp
index cd5a2b384..7012b979f 100644
--- a/jni/jpegutilnative.cpp
+++ b/jni/jpegutilnative.cpp
@@ -57,3 +57,68 @@ extern "C" JNIEXPORT jint JNICALL
return jpegutil::compress(yP, cbP, crP, (unsigned char*)out, outBufCapacity,
flush, quality);
}
+
+/**
+ * Copies the Image.Plane specified by planeBuf, pStride, and rStride to the
+ * Bitmap.
+ *
+ * @param env the JNI environment
+ * @param clazz the java class
+ * @param width the width of the output image
+ * @param height the height of the output image
+ * @param planeBuf the native ByteBuffer containing the image plane data
+ * @param pStride the stride between adjacent pixels in the same row of planeBuf
+ * @param rStride the stride between adjacent rows in planeBuf
+ * @param rot90 the multiple of 90 degrees to rotate, one of {0, 1, 2, 3}.
+ */
+extern "C" JNIEXPORT void JNICALL
+ Java_com_android_camera_util_JpegUtilNative_copyImagePlaneToBitmap(
+ JNIEnv* env, jclass clazz, jint width, jint height, jobject planeBuf,
+ jint pStride, jint rStride, jobject outBitmap, jint rot90) {
+ jbyte* src = (jbyte*)env->GetDirectBufferAddress(planeBuf);
+
+ char* dst = 0;
+ AndroidBitmap_lockPixels(env, outBitmap, (void**) &dst);
+
+ if (rot90 == 0) {
+ // No rotation
+ for (int y = 0; y < height; y++) {
+ char* srcPtr = reinterpret_cast<char*>(&src[y * rStride]);
+ char* dstPtr = &dst[y * width];
+ for (int x = 0; x < width; x++) {
+ *dstPtr = *srcPtr;
+ srcPtr += pStride;
+ dstPtr++;
+ }
+ }
+ } else if (rot90 == 1) {
+ // 90-degree rotation
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int srcX = height - 1 - y;
+ int srcY = x;
+ dst[y * width + x] = src[srcX * pStride + rStride * srcY];
+ }
+ }
+ } else if (rot90 == 2) {
+ // 180-degree rotation
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int srcX = width - 1 - x;
+ int srcY = height - 1 - y;
+ dst[y * width + x] = src[srcX * pStride + rStride * srcY];
+ }
+ }
+ } else if (rot90 == 3) {
+ // 270-degree rotation
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int srcX = y;
+ int srcY = width - 1 - x;
+ dst[y * width + x] = src[srcX * pStride + rStride * srcY];
+ }
+ }
+ }
+
+ AndroidBitmap_unlockPixels(env, outBitmap);
+}