summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ta Chen <weita@google.com>2011-07-08 13:02:45 +0800
committerWei-Ta Chen <weita@google.com>2011-07-08 17:02:39 +0800
commit81f844f803ea2feeb61eb9270fbdd5592620d42e (patch)
tree42de94b54101dfee03b9032c4de56d182420cd1a
parentbb7b3116ed24463fb73a6e5a3fc258423d69eeab (diff)
downloadpackages_apps_LegacyCamera-81f844f803ea2feeb61eb9270fbdd5592620d42e.zip
packages_apps_LegacyCamera-81f844f803ea2feeb61eb9270fbdd5592620d42e.tar.gz
packages_apps_LegacyCamera-81f844f803ea2feeb61eb9270fbdd5592620d42e.tar.bz2
Check in Mosaic.java - the Java interface to JNI.
Change-Id: Id3a84177aa6978499c5a8b1cff78b44759989119
-rw-r--r--jni/feature_mos_jni.cpp28
-rw-r--r--src/com/android/camera/panorama/Mosaic.java139
2 files changed, 147 insertions, 20 deletions
diff --git a/jni/feature_mos_jni.cpp b/jni/feature_mos_jni.cpp
index 680a913..22ac5ba 100644
--- a/jni/feature_mos_jni.cpp
+++ b/jni/feature_mos_jni.cpp
@@ -71,11 +71,6 @@ bool high_res = false;
bool quarter_res[NR] = {false,false};
float thresh_still[NR] = {5.0f,0.0f};
-JNIEXPORT jstring JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_StringFromJNI( JNIEnv* env, jobject thiz )
-{
- return (env)->NewStringUTF(buffer);
-}
-
/* return current time in milliseconds*/
#ifndef now_ms
@@ -243,7 +238,7 @@ void YUV420toYVU24(ImageType yvu24, ImageType yuv420sp, int width, int height)
}
}
-JNIEXPORT jboolean JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_SetSourceImageDimensions(JNIEnv* env, jobject thiz, jint width, jint height)
+JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_setSourceImageDimensions(JNIEnv* env, jobject thiz, jint width, jint height)
{
tWidth[HR] = width;
tHeight[HR] = height;
@@ -258,11 +253,10 @@ JNIEXPORT jboolean JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_SetSourceImageDimen
{
tImage[HR][i] = ImageUtils::allocateImage(tWidth[HR], tHeight[HR], ImageUtils::IMAGE_TYPE_NUM_CHANNELS);
}
- return 1;
}
-JNIEXPORT jfloatArray JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_SetSourceImage(JNIEnv* env, jobject thiz, jbyteArray photo_data)
+JNIEXPORT jfloatArray JNICALL Java_com_android_camera_panorama_Mosaic_setSourceImage(JNIEnv* env, jobject thiz, jbyteArray photo_data)
{
double t0, t1, time_c;
t0 = now_ms();
@@ -311,25 +305,20 @@ JNIEXPORT jfloatArray JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_SetSourceImage(J
return bytes;
}
-JNIEXPORT jboolean JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_SetBlendingType(JNIEnv* env, jobject thiz, jint type)
+JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_setBlendingType(JNIEnv* env, jobject thiz, jint type)
{
blendingType = int(type);
-
- return 1;
}
-JNIEXPORT jboolean JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_Reset(JNIEnv* env, jobject thiz, jint type)
+JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_reset(JNIEnv* env, jobject thiz)
{
frame_number_HR = 0;
frame_number_LR = 0;
- blendingType = int(type);
Init(LR,MAX_FRAMES_LR);
-
- return 1;
}
-JNIEXPORT jboolean JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_CreateMosaic(JNIEnv* env, jobject thiz, jboolean value)
+JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_createMosaic(JNIEnv* env, jobject thiz, jboolean value)
{
high_res = bool(value);
@@ -349,10 +338,9 @@ JNIEXPORT jboolean JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_CreateMosaic(JNIEnv
{
Finalize(LR);
}
-
- return 1;
}
-JNIEXPORT jintArray JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_GetFinalMosaic(JNIEnv* env, jobject thiz)
+
+JNIEXPORT jintArray JNICALL Java_com_android_camera_panorama_Mosaic_getFinalMosaic(JNIEnv* env, jobject thiz)
{
int y,x;
int width = mosaicWidth;
@@ -394,7 +382,7 @@ JNIEXPORT jintArray JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_GetFinalMosaic(JNI
return bytes;
}
-JNIEXPORT jbyteArray JNICALL Java_sri_ics_vt_SmartPhone_Mosaic_GetFinalMosaicNV21(JNIEnv* env, jobject thiz)
+JNIEXPORT jbyteArray JNICALL Java_com_android_camera_panorama_Mosaic_getFinalMosaicNV21(JNIEnv* env, jobject thiz)
{
int y,x;
int width;
diff --git a/src/com/android/camera/panorama/Mosaic.java b/src/com/android/camera/panorama/Mosaic.java
new file mode 100644
index 0000000..2407729
--- /dev/null
+++ b/src/com/android/camera/panorama/Mosaic.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+package com.android.camera.panorama;
+
+/**
+ * The Java interface to JNI calls regarding mosaic stitching.
+ *
+ * A high-level usage is:
+ *
+ * Mosaic mosaic = new Mosaic();
+ * mosaic.setSourceImageDimensions(width, height);
+ * mosaic.reset(blendType);
+ *
+ * while ((pixels = hasNextImage()) != null) {
+ * mosaic.setSourceImage(pixels);
+ * }
+ *
+ * mosaic.createMosaic(highRes);
+ * byte[] result = mosaic.getFinalMosaic();
+ *
+ */
+public class Mosaic {
+ /**
+ * In this mode, the images are stitched together in the same spatial arrangement as acquired
+ * i.e. if the user follows a curvy trajectory, the image boundary of the resulting mosaic will
+ * be curved in the same manner. This mode is useful if the user wants to capture a mosaic as
+ * if "painting" the scene using the smart-phone device and does not want any corrective warps
+ * to distort the captured images.
+ */
+ public static final int BLENDTYPE_FULL = 0;
+
+ /**
+ * This mode is the same as BLENDTYPE_FULL except that the resulting mosaic is rotated
+ * to balance the first and last images to be approximately at the same vertical offset in the
+ * output mosaic. This is useful when acquiring a mosaic by a typical panning-like motion to
+ * remove a one-sided curve in the mosaic (typically due to the camera not staying horizontal
+ * during the video capture) and convert it to a more symmetrical "smiley-face" like output.
+ */
+ public static final int BLENDTYPE_PAN = 1;
+
+ /**
+ * This mode compensates for typical "smiley-face" like output in longer mosaics and creates
+ * a rectangular mosaic with minimal black borders (by unwrapping the mosaic onto an imaginary
+ * cylinder). If the user follows a curved trajectory (instead of a perfect panning trajectory),
+ * the resulting mosaic here may suffer from some image distortions in trying to map the
+ * trajectory to a cylinder.
+ */
+ public static final int BLENDTYPE_CYLINDERPAN = 2;
+
+ /**
+ * This mode is basically BLENDTYPE_CYLINDERPAN plus doing a rectangle cropping before returning
+ * the mosaic. The mode is useful for making the resulting mosaic have a rectangle shape.
+ */
+ public static final int BLENDTYPE_HORIZONTAL =3;
+
+ static {
+ System.loadLibrary("jni_mosaic");
+ }
+
+ /**
+ * Allocate memory for the image frames at the given resolution.
+ *
+ * @param width width of the input frames in pixels
+ * @param height height of the input frames in pixels
+ */
+ public native void setSourceImageDimensions(int width, int height);
+
+ /**
+ * Pass the input image frame to the native layer. Each time the a new
+ * source image t is set, the transformation matrix from the first source
+ * image to t is computed and returned.
+ *
+ * @param pixels source image of NV21 format.
+ * @return Float array of length 10; first 9 entries correspond to the 3x3
+ * transformation matrix between the first frame and the passed frame,
+ * and the last entry is the number of the passed frame,
+ * where the counting starts from 1.
+ */
+ public native float[] setSourceImage(byte[] pixels);
+
+ /**
+ * Set the type of blending.
+ *
+ * @param type the blending type defined in the class. {BLENDTYPE_FULL,
+ * BLENDTYPE_PAN, BLENDTYPE_CYLINDERPAN, BLENDTYPE_HORIZONTAL}
+ */
+ public native void setBlendingType(int type);
+
+ /**
+ * Tell the native layer to create the final mosaic after all the input frame
+ * data have been collected.
+ * The case of generating high-resolution mosaic may take dozens of seconds to finish.
+ *
+ * @param value True means generating a high-resolution mosaic -
+ * which is based on the original images set in setSourceImage().
+ * False means generating a low-resolution version -
+ * which is based on 1/4 downscaled images from the original images.
+ */
+ public native void createMosaic(boolean value);
+
+ /**
+ * Get the data for the created mosaic.
+ *
+ * @return Returns an integer array which contains the final mosaic in the ARGB_8888 format.
+ * The first MosaicWidth*MosaicHeight values contain the image data, followed by 2
+ * integers corresponding to the values MosaicWidth and MosaicHeight respectively.
+ */
+ public native int[] getFinalMosaic();
+
+ /**
+ * Get the data for the created mosaic.
+ *
+ * @return Returns a byte array which contains the final mosaic in the NV21 format.
+ * The first MosaicWidth*MosaicHeight*1.5 values contain the image data, followed by
+ * 8 bytes which pack the MosaicWidth and MosaicHeight integers into 4 bytes each
+ * respectively.
+ */
+ public native byte[] getFinalMosaicNV21();
+
+ /**
+ * Reset the state of the frame arrays which maintain the captured frame data.
+ * Also re-initializes the native mosaic object to make it ready for capturing a new mosaic.
+ */
+ public native void reset();
+}