extern "C" JNIEXPORT jint JNICALL Java_com_almalence_plugins_processing_objectremoval_AlmaCLRShot_ConvertFromJpeg ( JNIEnv* env, jobject thiz, jintArray in, jintArray in_len, jint nFrames, jint sx, jint sy ) { int *jpeg_length; unsigned char * *jpeg; int isFoundinInput; jpeg = (unsigned char**)env->GetIntArrayElements(in, NULL); jpeg_length = (int*)env->GetIntArrayElements(in_len, NULL); isFoundinInput = DecodeAndRotateMultipleJpegs(inputFrame, jpeg, jpeg_length, sx, sy, nFrames, 0, 0, 0, true); env->ReleaseIntArrayElements(in, (jint*)jpeg, JNI_ABORT); env->ReleaseIntArrayElements(in_len, (jint*)jpeg_length, JNI_ABORT); return isFoundinInput; }
extern "C" JNIEXPORT jstring JNICALL Java_com_almalence_plugins_processing_bestshot_AlmaShotBestShot_ConvertFromJpeg ( JNIEnv* env, jobject thiz, jintArray in, jintArray in_len, jint nFrames, jint sx, jint sy ) { int i; int *jpeg_length; unsigned char * *jpeg; char status[1024]; Uint8 *inp[4]; int x, y; int x0_out, y0_out, w_out, h_out; jpeg = (unsigned char**)env->GetIntArrayElements(in, NULL); jpeg_length = (int*)env->GetIntArrayElements(in_len, NULL); DecodeAndRotateMultipleJpegs(yuv, jpeg, jpeg_length, sx, sy, nFrames, 0, 0, 0, false); env->ReleaseIntArrayElements(in, (jint*)jpeg, JNI_ABORT); env->ReleaseIntArrayElements(in_len, (jint*)jpeg_length, JNI_ABORT); sprintf (status, "frames total: %d\n", (int)nFrames); return env->NewStringUTF(status); }
// this is a very common operation - use ImageConversion jni interface instead (? - need to avoid global yuv array then?) extern "C" JNIEXPORT jstring JNICALL Java_com_almalence_plugins_processing_simple_AlmaShotDRO_ConvertFromJpeg ( JNIEnv* env, jobject thiz, jintArray in, jintArray in_len, jint nFrames, jint sx, jint sy ) { int i; int *jpeg_length; unsigned char * *jpeg; char status[1024]; Uint8 *inp[4]; int x, y; int x0_out, y0_out, w_out, h_out; jbyteArray infrms[MAX_FRAMES]; jpeg = (unsigned char**)env->GetIntArrayElements(in, NULL); jpeg_length = (int*)env->GetIntArrayElements(in_len, NULL); DecodeAndRotateMultipleJpegs(yuv, jpeg, jpeg_length, sx, sy, nFrames, 0, 0, 0, true); /* // dump jpeg data { FILE *f; char str[256]; for (i=0; i<nFrames; ++i) { sprintf(str, "/sdcard/DCIM/nightDump_%d.jpg", i); f = fopen(str,"wb"); fwrite(jpeg[i], jpeg_length[i], 1, f); fclose(f); } } */ env->ReleaseIntArrayElements(in, (jint*)jpeg, JNI_ABORT); env->ReleaseIntArrayElements(in_len, (jint*)jpeg_length, JNI_ABORT); //sprintf (status, "frames total: %d\nsize0: %d\nsize1: %d\nsize2: %d\n", (int)nFrames, jpeg_length[0], jpeg_length[1], jpeg_length[2]); sprintf (status, "frames total: %d\n", (int)nFrames); return env->NewStringUTF(status); }
extern "C" JNIEXPORT jint JNICALL Java_com_almalence_plugins_processing_sequence_AlmaCLRShot_ConvertFromJpeg ( JNIEnv* env, jobject thiz, jintArray in, jintArray in_len, jint nFrames, jint sx, jint sy ) { int i; int *jpeg_length; unsigned char * *jpeg; char status[1024]; int isFoundinInput = MAX_MOV_FRAMES; int x, y; int x0_out, y0_out, w_out, h_out; /* // pre-allocate uncompressed yuv buffers for (i=0; i<nFrames; ++i) { inputFrame[i] = (unsigned char*)malloc(sx*sy+2*((sx+1)/2)*((sy+1)/2)); if (inputFrame[i]==NULL) { for (;i>=0;--i) { free(inputFrame[i]); inputFrame[i] = NULL; } LOGD("not enough memory"); return -1; } } jpeg = (unsigned char**)env->GetIntArrayElements(in, NULL); jpeg_length = (int*)env->GetIntArrayElements(in_len, NULL); #pragma omp parallel for num_threads(10) for (i=0; i<nFrames; ++i) { // decode from jpeg if(decodeFromJpeg(jpeg[i], jpeg_length[i], i, sx, sy) == 0) { isFoundinInput = i; LOGD("JPEG buffer error found in %d frame\n", (int)i); } // release compressed memory free (jpeg[i]); } */ jpeg = (unsigned char**)env->GetIntArrayElements(in, NULL); jpeg_length = (int*)env->GetIntArrayElements(in_len, NULL); isFoundinInput = DecodeAndRotateMultipleJpegs(inputFrame, jpeg, jpeg_length, sx, sy, nFrames, 0, 0, 0, true); env->ReleaseIntArrayElements(in, (jint*)jpeg, JNI_ABORT); env->ReleaseIntArrayElements(in_len, (jint*)jpeg_length, JNI_ABORT); return isFoundinInput; }
extern "C" JNIEXPORT jint JNICALL Java_com_almalence_plugins_processing_groupshot_AlmaShotSeamless_ConvertAndDetectFacesFromJpegs ( JNIEnv* env, jobject thiz, jintArray in, jintArray in_len, jint nFrames, jint sx, jint sy, jint fd_sx, jint fd_sy, jboolean needRotation, jboolean cameraMirrored, jint rotationDegree ) { int i; int *jpeg_length; unsigned char * *jpeg; char status[1024]; int isFoundinInput; int x, y; int x0_out, y0_out, w_out, h_out; jpeg = (unsigned char**)env->GetIntArrayElements(in, NULL); jpeg_length = (int*)env->GetIntArrayElements(in_len, NULL); isFoundinInput = DecodeAndRotateMultipleJpegs(inputFrame, jpeg, jpeg_length, sx, sy, nFrames, needRotation, cameraMirrored, rotationDegree); // prepare down-scaled gray frames for face detection analisys and detect faces #pragma omp parallel for for (i=0; i<nFrames; ++i) { unsigned char * grayFrame = (unsigned char *)malloc(fd_sx*fd_sy); if (grayFrame == NULL) isFoundinInput = i; else { void *inst; if(rotationDegree == 0 || rotationDegree == 180) NV21_to_Gray_scaled(inputFrame[i], sx, sy, 0, 0, sx, sy, fd_sx, fd_sy, grayFrame); else NV21_to_Gray_scaled(inputFrame[i], sy, sx, 0, 0, sy, sx, fd_sx, fd_sy, grayFrame); FaceDetector_initialize(&inst, fd_sx, fd_sy, MAX_FACE_DETECTED); fd_nFaces[i] = FaceDetector_detect(inst, grayFrame); if (fd_nFaces[i] > MAX_FACE_DETECTED) fd_nFaces[i] = MAX_FACE_DETECTED; for (int f=0; f<fd_nFaces[i]; ++f) FaceDetector_get_face(inst, &fd_confid[i][f], &fd_midx[i][f], &fd_midy[i][f], &fd_eyedist[i][f]); FaceDetector_destroy(inst); free(grayFrame); } } env->ReleaseIntArrayElements(in, (jint*)jpeg, JNI_ABORT); env->ReleaseIntArrayElements(in_len, (jint*)jpeg_length, JNI_ABORT); LOGD("frames total: %d\n", (int)nFrames); return isFoundinInput; }