3dphotoshoot
diff src/android/camera.c @ 9:d1b456d08713
texture matrix and video size from JNI
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 25 May 2015 05:27:26 +0300 |
parents | 9fc7d52f578d |
children | ac80210d5fbe |
line diff
1.1 --- a/src/android/camera.c Mon May 25 04:14:38 2015 +0300 1.2 +++ b/src/android/camera.c Mon May 25 05:27:26 2015 +0300 1.3 @@ -1,4 +1,5 @@ 1.4 #include <stdio.h> 1.5 +#include <string.h> 1.6 #include <assert.h> 1.7 #include <jni.h> 1.8 #include "opengl.h" 1.9 @@ -9,6 +10,9 @@ 1.10 static JNIEnv *jni; 1.11 static jclass activity_class; 1.12 static unsigned int tex; 1.13 +static float tex_matrix[16]; 1.14 +static const float identity_matrix[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; 1.15 +static jfloatArray jtex_matrix; 1.16 static int capturing; 1.17 1.18 int cam_init(void *platform_data) 1.19 @@ -20,6 +24,8 @@ 1.20 jni = pdata->jni; 1.21 activity_class = pdata->activity_class; 1.22 1.23 + jtex_matrix = (*jni)->NewFloatArray(jni, 16); 1.24 + 1.25 // create the camera texture 1.26 assert(glGetError() == GL_NO_ERROR); 1.27 glGenTextures(1, &tex); 1.28 @@ -37,6 +43,10 @@ 1.29 cam_stop_video(); 1.30 glDeleteTextures(1, &tex); 1.31 tex = 0; 1.32 + 1.33 + if(jni) { 1.34 + (*jni)->DeleteGlobalRef(jni, jtex_matrix); 1.35 + } 1.36 } 1.37 1.38 unsigned int cam_texture(void) 1.39 @@ -44,9 +54,9 @@ 1.40 return tex; 1.41 } 1.42 1.43 -void cam_texture_size(int *w, int *h) 1.44 +const float *cam_texture_matrix(void) 1.45 { 1.46 - /* TODO */ 1.47 + return tex_matrix; 1.48 } 1.49 1.50 int cam_start_video(void) 1.51 @@ -104,7 +114,9 @@ 1.52 1.53 int cam_update(void) 1.54 { 1.55 + static int texmat_fail_warned; 1.56 jmethodID method; 1.57 + float *ptr; 1.58 1.59 if(!jvm) { 1.60 fprintf(stderr, "failed to update camera\n"); 1.61 @@ -114,11 +126,23 @@ 1.62 return 0; 1.63 } 1.64 1.65 - if(!(method = (*jni)->GetStaticMethodID(jni, activity_class, "update", "()V"))) { 1.66 + if(!(method = (*jni)->GetStaticMethodID(jni, activity_class, "update", "([F)V"))) { 1.67 fprintf(stderr, "failed to find static method: update\n"); 1.68 return -1; 1.69 } 1.70 - (*jni)->CallStaticVoidMethod(jni, activity_class, method); 1.71 + (*jni)->CallStaticVoidMethod(jni, activity_class, method, jtex_matrix); 1.72 + 1.73 + if(!(ptr = (*jni)->GetFloatArrayElements(jni, jtex_matrix, 0))) { 1.74 + if(!texmat_fail_warned) { 1.75 + fprintf(stderr, "failed to get texture matrix\n"); 1.76 + texmat_fail_warned = 1; 1.77 + } 1.78 + memcpy(tex_matrix, identity_matrix, sizeof identity_matrix); 1.79 + } else { 1.80 + memcpy(tex_matrix, ptr, 16 * sizeof *ptr); 1.81 + (*jni)->ReleaseFloatArrayElements(jni, jtex_matrix, ptr, JNI_ABORT); 1.82 + } 1.83 + 1.84 return 0; 1.85 } 1.86 1.87 @@ -127,6 +151,22 @@ 1.88 return capturing; // XXX is it better to do this properly through JNI? 1.89 } 1.90 1.91 +int cam_video_size(int *xsz, int *ysz) 1.92 +{ 1.93 + jfieldID jwidth, jheight; 1.94 + 1.95 + if(!(jwidth = (*jni)->GetStaticFieldID(jni, activity_class, "preview_width", "I")) || 1.96 + !(jheight = (*jni)->GetStaticFieldID(jni, activity_class, "preview_height", "I"))) { 1.97 + fprintf(stderr, "failed to retrieve preview width/height fields\n"); 1.98 + *xsz = *ysz = 0; 1.99 + return -1; 1.100 + } 1.101 + 1.102 + *xsz = (*jni)->GetStaticIntField(jni, activity_class, jwidth); 1.103 + *ysz = (*jni)->GetStaticIntField(jni, activity_class, jheight); 1.104 + return 0; 1.105 +} 1.106 + 1.107 int cam_take_picture(void) 1.108 { 1.109 return -1; // TODO