}
}
-void ConvertIntsToRGBA(const int* ints, int length, uint8_t* result) {
- for (int i = 0; i < length; ++i) {
- result[i] = static_cast<uint8_t>(ints[i]);
- }
-}
-
-void ConvertRGBAToInts(const uint8_t* rgba, int length, int* result) {
- for (int i = 0; i < length; ++i) {
- result[i] = rgba[i];
- }
-}
// GLFrame JNI implementation //////////////////////////////////////////////////////////////////////
jboolean Java_android_filterfw_core_GLFrame_allocate(JNIEnv* env,
jobject thiz,
jint* int_ptr = env->GetIntArrayElements(ints, NULL);
const int length = env->GetArrayLength(ints);
if (int_ptr) {
- // Convert ints to RGBA buffer
- uint8_t* rgba_buffer = new uint8_t[length];
- ConvertIntsToRGBA(int_ptr, length, rgba_buffer);
+ const bool success = frame->WriteData(reinterpret_cast<const uint8_t*>(int_ptr),
+ length * sizeof(jint));
env->ReleaseIntArrayElements(ints, int_ptr, JNI_ABORT);
-
- // Write RGBA buffer to frame
- const bool success = frame->WriteData(rgba_buffer, length);
-
- // Clean-up
- delete[] rgba_buffer;
return ToJBool(success);
}
}
jintArray Java_android_filterfw_core_GLFrame_getNativeInts(JNIEnv* env, jobject thiz) {
GLFrame* frame = ConvertFromJava<GLFrame>(env, thiz);
- if (frame && frame->Size() > 0) {
- // Create the result array
- jintArray result = env->NewIntArray(frame->Size());
- jint* int_array = env->GetIntArrayElements(result, NULL);
-
- // Read the frame pixels
- uint8_t* pixels = new uint8_t[frame->Size()];
- frame->CopyDataTo(pixels, frame->Size());
-
- // Convert them to integers
- ConvertRGBAToInts(pixels, frame->Size(), int_array);
-
- // Clean-up
- delete[] pixels;
- env->ReleaseIntArrayElements(result, int_array, 0);
+ if (frame && frame->Size() > 0 && (frame->Size() % sizeof(jint) == 0)) {
+ jintArray result = env->NewIntArray(frame->Size() / sizeof(jint));
+ jint* data = env->GetIntArrayElements(result, NULL);
+ frame->CopyDataTo(reinterpret_cast<uint8_t*>(data), frame->Size());
+ env->ReleaseIntArrayElements(result, data, 0);
return result;
- }
- return NULL;
+ }
+ return NULL;
}
jboolean Java_android_filterfw_core_GLFrame_setNativeFloats(JNIEnv* env,