Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GPUImage-x/proj.android/GPUImage-x/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.novoda:bintray-release:0.3.4'
}
}
Expand Down
2 changes: 2 additions & 0 deletions GPUImage-x/proj.android/GPUImage-x/library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_library( GPUImage-x
src/main/cpp/source/SourceCamera.cpp
src/main/cpp/target/Target.cpp
src/main/cpp/target/TargetView.cpp
src/main/cpp/target/TargetRawDataOutput.cpp
src/main/cpp/filter/Filter.cpp
src/main/cpp/filter/FilterGroup.cpp
src/main/cpp/filter/BrightnessFilter.cpp
Expand Down Expand Up @@ -54,6 +55,7 @@ add_library( GPUImage-x
src/main/cpp/filter/CrosshatchFilter.cpp
src/main/cpp/filter/SphereRefractionFilter.cpp
src/main/cpp/filter/GlassSphereFilter.cpp
src/main/cpp/filter/CropFilter.cpp
)

find_library( log-lib
Expand Down
24 changes: 24 additions & 0 deletions GPUImage-x/proj.android/GPUImage-x/library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,35 @@ apply plugin: 'com.novoda.bintray-release'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"

buildTypes{
debug{
jniDebuggable true
jniDebuggable = true
}
}

defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "1.0"

externalNativeBuild {

// For ndk-build, instead use ndkBuild {}
cmake {

// Passes optional arguments to CMake.
arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang"

// Sets optional flags for the C compiler.
cFlags "-g", "-O0"

// Sets a flag to enable format macro constants for the C++ compiler.
cppFlags "-D__STDC_FORMAT_MACROS"
}
}
}
// buildTypes {
// release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void Framebuffer::_generateTexture() {
}

void Framebuffer::_generateFramebuffer() {

CHECK_GL(glGenFramebuffers(1, &_framebuffer));
CHECK_GL(glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer));
_generateTexture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,74 @@

#include <jni.h>
#include <string>
#include <android/log.h>
#include <android/bitmap.h>
#include "source/SourceImage.h"
#include "source/SourceCamera.h"
#include "target/TargetView.h"
#include "target/TargetRawDataOutput.h"
#include "filter/Filter.hpp"
#include "filter/CropFilter.hpp"
#include "Context.hpp"

USING_NS_GI

class TargetRawDataDelegate : public ITargetRawDataDelegate {
public:
TargetRawDataDelegate() :
_env (nullptr) ,
_objClazz(nullptr),
_callback(nullptr)
{

};

TargetRawDataDelegate( JNIEnv* env, jobject clazz, jmethodID callback) :
_env(env) ,
_objClazz(clazz),
_callback(callback)
{

}

virtual ~TargetRawDataDelegate()
{
__android_log_print (ANDROID_LOG_DEBUG, __FUNCTION__ , "dealloc");
if (_env != nullptr && _objClazz != nullptr) {
_env->DeleteGlobalRef(_objClazz);
_objClazz = nullptr;
}
_env = nullptr;
_callback = nullptr;
}

virtual void newFrameAvailableBlock(TargetRawDataOutput* output)
{
// __android_log_print (ANDROID_LOG_DEBUG, __FUNCTION__ , "callback");
if (!_env || !_objClazz || !_callback)
return;
int width,height;
GLubyte *bytes = output->getRawBytesForImage(width, height);
int bytesPerRow = output->getBytesPerRowInOutput();
int frameSize = bytesPerRow * height * sizeof(unsigned char);

jbyteArray jresult = NULL;
if (bytes) {
jbyte* by = (jbyte*)bytes;
jresult = _env->NewByteArray(frameSize);
_env->SetByteArrayRegion(jresult, 0, frameSize, by);
}

_env->CallVoidMethod(_objClazz, _callback, jresult, bytesPerRow);
_env->DeleteLocalRef(jresult);
}

public:
JNIEnv *_env;
jobject _objClazz;
jmethodID _callback;
};

extern "C"
jlong Java_com_jin_gpuimage_GPUImage_nativeSourceImageNew(
JNIEnv *env,
Expand Down Expand Up @@ -102,6 +161,21 @@ void Java_com_jin_gpuimage_GPUImage_nativeSourceCameraSetFrame(
env->ReleasePrimitiveArrayCritical(jdata, data, 0);
};

extern "C"
void Java_com_jin_gpuimage_GPUImage_nativeSourceCameraSetFrameTexture
(JNIEnv *env,
jclass,
jlong classId,
jint width,
jint height,
jintArray textures,
jint rotation)
{
GLuint* nativeTextures = (GLuint *)env->GetIntArrayElements(textures,0);
((SourceCamera*)classId)->setFrameTexture(width, height, nativeTextures, (RotationMode)rotation);
env->ReleaseIntArrayElements(textures, (jint*)nativeTextures, 0);
}

extern "C"
jlong Java_com_jin_gpuimage_GPUImage_nativeSourceAddTarget(
JNIEnv *env,
Expand All @@ -113,6 +187,7 @@ jlong Java_com_jin_gpuimage_GPUImage_nativeSourceAddTarget(
{
Source* source = (Source *) classId;
Target* target = isFilter ? dynamic_cast<Target*>((Filter*)targetClassId) : (Target*)targetClassId;

if (texID >= 0) {
return (uintptr_t) (source->addTarget(target, texID));
} else {
Expand Down Expand Up @@ -232,6 +307,50 @@ void Java_com_jin_gpuimage_GPUImage_nativeTargetViewSetFillMode(
((TargetView*)classId)->setFillMode((TargetView::FillMode)fillMode);
};

extern "C"
jlong Java_com_jin_gpuimage_GPUImage_nativeTargetRawDataOutputNew
(JNIEnv *env, jclass obj, jint width, jint height, jboolean setRBGA)
{
return (uintptr_t)(new TargetRawDataOutput(width, height, setRBGA));
}


extern "C"
void Java_com_jin_gpuimage_GPUImage_nativeTargetRawDataOutputFinalize
(JNIEnv *env, jclass obj, jlong classId)
{
((TargetRawDataOutput*)classId)->release();
}

extern "C"
void Java_com_jin_gpuimage_GPUImage_nativeTargetRawDataOutputNewFrameAvailableCallback
(JNIEnv *env, jclass, jlong classId, jobject callback)
{
if (callback == NULL) {
((TargetRawDataOutput*)classId)->setTargetRawDataDelegate(nullptr);
} else {
jobject objClazz = env->NewGlobalRef(callback);
jclass jclsProcess = env->GetObjectClass(objClazz);
if (jclsProcess == NULL) {
__android_log_print (ANDROID_LOG_ERROR, __FUNCTION__ , "Android GetObjectClass failed!!!");
env->DeleteGlobalRef(objClazz);
((TargetRawDataOutput*)classId)->setTargetRawDataDelegate(nullptr);
return;
}

jmethodID jMethod = env->GetMethodID(jclsProcess, "onNewFrameAvailable", "([BI)V");
if (jMethod == NULL) {
__android_log_print (ANDROID_LOG_ERROR, __FUNCTION__ , "Android GetObjectClass CallBack failed!!!");
env->DeleteGlobalRef(objClazz);
((TargetRawDataOutput*)classId)->setTargetRawDataDelegate(nullptr);
return;
}

std::shared_ptr<TargetRawDataDelegate> delegate = std::make_shared<TargetRawDataDelegate>(env, objClazz, jMethod);
((TargetRawDataOutput*)classId)->setTargetRawDataDelegate(delegate);
}
};

extern "C"
jlong Java_com_jin_gpuimage_GPUImage_nativeFilterCreate(
JNIEnv *env,
Expand Down Expand Up @@ -307,6 +426,31 @@ void Java_com_jin_gpuimage_GPUImage_nativeFilterSetPropertyString(

};

extern "C" jlong JNICALL Java_com_jin_gpuimage_GPUImage_nativeCropFilterCreate
(JNIEnv *env, jclass, jfloat left, jfloat top, jfloat right, jfloat bottom)
{
return (uintptr_t) CropFilter::create(RectF(left, top, right, bottom));
}

extern "C" void JNICALL Java_com_jin_gpuimage_GPUImage_nativeCropFilterDestroy
(JNIEnv *env, jclass, jlong classId)
{
((Filter*)classId)->release();
}

extern "C" void JNICALL Java_com_jin_gpuimage_GPUImage_nativeCropFilterFinalize
(JNIEnv *env, jclass, jlong classId)
{
((Filter*)classId)->releaseFramebuffer(false);
((Filter*)classId)->release();
}

extern "C" void JNICALL Java_com_jin_gpuimage_GPUImage_nativeCropFilterSetCropRegion
(JNIEnv *env, jclass, jlong classId, jfloat left, jfloat top, jfloat right, jfloat bottom)
{
((CropFilter*)classId)->setCropRegion(RectF(left, top, right, bottom));
}

extern "C"
void Java_com_jin_gpuimage_GPUImage_nativeContextInit(
JNIEnv *env,
Expand Down
Loading