Skip to content

Commit 5a9a85e

Browse files
mtdxccqm
authored and
cqm
committed
android jni filter导出获取属性方法
1 parent 211db49 commit 5a9a85e

File tree

3 files changed

+126
-28
lines changed

3 files changed

+126
-28
lines changed

src/android/java/gpupixel/src/main/java/com/pixpark/gpupixel/GPUPixelFilter.java

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,36 @@ public String GetFilterClassName() {
7171
return filterClassName;
7272
}
7373

74-
public final void SetProperty(final String property, final double value) {
75-
SetProperty(property, (float) value);
74+
public final boolean SetProperty(final String property, final double value) {
75+
return SetProperty(property, (float) value);
7676
}
7777

78-
public final void SetProperty(final String property, final float value) {
78+
public final boolean SetProperty(final String property, final float value) {
7979
if (mNativeClassID != 0) {
80-
nativeFilterSetPropertyFloat(mNativeClassID, property, value);
80+
return nativeFilterSetPropertyFloat(mNativeClassID, property, value);
8181
}
82+
return false;
8283
}
8384

84-
public final void SetProperty(final String property, final float[] array) {
85+
public final boolean SetProperty(final String property, final float[] array) {
8586
if (mNativeClassID != 0) {
86-
nativeFilterSetPropertyFloatArray(mNativeClassID, property, array);
87+
return nativeFilterSetPropertyFloatArray(mNativeClassID, property, array);
8788
}
89+
return false;
8890
}
8991

90-
public final void SetProperty(final String property, final int value) {
92+
public final boolean SetProperty(final String property, final int value) {
9193
if (mNativeClassID != 0) {
92-
nativeFilterSetPropertyInt(mNativeClassID, property, value);
94+
return nativeFilterSetPropertyInt(mNativeClassID, property, value);
9395
}
96+
return false;
9497
}
9598

96-
public final void SetProperty(final String property, final String value) {
99+
public final boolean SetProperty(final String property, final String value) {
97100
if (mNativeClassID != 0) {
98-
nativeFilterSetPropertyString(mNativeClassID, property, value);
101+
return nativeFilterSetPropertyString(mNativeClassID, property, value);
99102
}
103+
return false;
100104
}
101105

102106
@Override
@@ -128,11 +132,42 @@ protected void finalize() throws Throwable {
128132
private static native long nativeFilterCreate(String filterClassName);
129133
private static native void nativeFilterDestroy(long classId);
130134
private static native void nativeFilterFinalize(long classId);
131-
private static native void nativeFilterSetPropertyFloat(
135+
private static native boolean nativeFilterSetPropertyFloat(
132136
long classId, String property, float value);
133-
private static native void nativeFilterSetPropertyInt(long classId, String property, int value);
134-
private static native void nativeFilterSetPropertyString(
137+
private static native boolean nativeFilterSetPropertyInt(long classId, String property, int value);
138+
private static native boolean nativeFilterSetPropertyString(
135139
long classId, String property, String value);
136-
private static native void nativeFilterSetPropertyFloatArray(
140+
private static native boolean nativeFilterSetPropertyFloatArray(
137141
long classId, String property, float[] array);
142+
143+
private static native float nativeFilterGetPropertyFloat(long classId, String property);
144+
private static native int nativeFilterGetPropertyInt(long classId, String property);
145+
private static native String nativeFilterGetPropertyString(long classId, String property);
146+
147+
private static native boolean nativeFilterHasProperty(long classId, String property, String type);
148+
public final boolean HasProperty(final String property, final String type) {
149+
if (mNativeClassID != 0) {
150+
return nativeFilterHasProperty(mNativeClassID, property, type);
151+
}
152+
return false;
153+
}
154+
155+
public final int GetPropertyInt(final String property) {
156+
if (mNativeClassID == 0) {
157+
return 0;
158+
}
159+
return nativeFilterGetPropertyInt(mNativeClassID, property);
160+
}
161+
public final float GetPropertyFloat(final String property) {
162+
if (mNativeClassID == 0) {
163+
return 0;
164+
}
165+
return nativeFilterGetPropertyFloat(mNativeClassID, property);
166+
}
167+
public final String GetPropertyString(final String property) {
168+
if (mNativeClassID == 0) {
169+
return null;
170+
}
171+
return nativeFilterGetPropertyString(mNativeClassID, property);
172+
}
138173
}

src/android/jni/jni_filter.cc

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,70 +57,73 @@ extern "C" JNIEXPORT void JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativ
5757
};
5858

5959
// Set float property for filter
60-
extern "C" JNIEXPORT void JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterSetPropertyFloat(
60+
extern "C" JNIEXPORT bool JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterSetPropertyFloat(
6161
JNIEnv* env,
6262
jclass obj,
6363
jlong classId,
6464
jstring jProperty,
6565
jfloat value) {
6666
auto* ptr = reinterpret_cast<std::shared_ptr<Filter>*>(classId);
6767
if (!ptr || !*ptr) {
68-
return;
68+
return false;
6969
}
7070

7171
const char* property = env->GetStringUTFChars(jProperty, 0);
72-
(*ptr)->SetProperty(property, value);
72+
bool ret = (*ptr)->SetProperty(property, value);
7373
env->ReleaseStringUTFChars(jProperty, property);
74+
return ret;
7475
};
7576

7677
// Set int property for filter
77-
extern "C" JNIEXPORT void JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterSetPropertyInt(
78+
extern "C" JNIEXPORT bool JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterSetPropertyInt(
7879
JNIEnv* env,
7980
jclass obj,
8081
jlong classId,
8182
jstring jProperty,
8283
jint value) {
8384
auto* ptr = reinterpret_cast<std::shared_ptr<Filter>*>(classId);
8485
if (!ptr || !*ptr) {
85-
return;
86+
return false;
8687
}
8788

8889
const char* property = env->GetStringUTFChars(jProperty, 0);
89-
(*ptr)->SetProperty(property, value);
90+
bool ret = (*ptr)->SetProperty(property, value);
9091
env->ReleaseStringUTFChars(jProperty, property);
92+
return ret;
9193
};
9294

9395
// Set string property for filter
94-
extern "C" JNIEXPORT void JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterSetPropertyString(
96+
extern "C" JNIEXPORT bool JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterSetPropertyString(
9597
JNIEnv* env,
9698
jclass obj,
9799
jlong classId,
98100
jstring jProperty,
99101
jstring jValue) {
100102
auto* ptr = reinterpret_cast<std::shared_ptr<Filter>*>(classId);
101103
if (!ptr || !*ptr) {
102-
return;
104+
return false;
103105
}
104106

105107
const char* property = env->GetStringUTFChars(jProperty, 0);
106108
const char* value = env->GetStringUTFChars(jValue, 0);
107-
(*ptr)->SetProperty(property, value);
109+
bool ret = (*ptr)->SetProperty(property, value);
108110
env->ReleaseStringUTFChars(jProperty, property);
109111
env->ReleaseStringUTFChars(jValue, value);
112+
return ret;
110113
};
111114

112115
// Set float array property for filter
113-
extern "C" JNIEXPORT void JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterSetPropertyFloatArray(
116+
extern "C" JNIEXPORT bool JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterSetPropertyFloatArray(
114117
JNIEnv* env,
115118
jclass clazz,
116119
jlong class_id,
117120
jstring jProperty,
118121
jfloatArray jarray) {
119122
auto* ptr = reinterpret_cast<std::shared_ptr<Filter>*>(class_id);
120123
if (!ptr || !*ptr) {
121-
return;
124+
return false;
122125
}
123-
126+
124127
const char* property = env->GetStringUTFChars(jProperty, 0);
125128
jsize length = env->GetArrayLength(jarray);
126129

@@ -131,9 +134,69 @@ extern "C" JNIEXPORT void JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativ
131134
vector.push_back(c_array[i]);
132135
}
133136

134-
(*ptr)->SetProperty(property, vector);
137+
bool ret = (*ptr)->SetProperty(property, vector);
135138

136139
env->ReleaseStringUTFChars(jProperty, property);
137140
// Release Java array memory
138141
env->ReleaseFloatArrayElements(jarray, c_array, JNI_ABORT);
142+
return ret;
143+
}
144+
145+
extern "C" JNIEXPORT bool JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterHasProperty(
146+
JNIEnv* env,
147+
jclass clazz,
148+
jlong class_id,
149+
jstring jProperty,
150+
jstring jType) {
151+
auto* ptr = reinterpret_cast<std::shared_ptr<Filter>*>(class_id);
152+
if (!ptr || !*ptr) {
153+
return false;
154+
}
155+
auto prop = JavaToStdString(env, jProperty);
156+
auto type = JavaToStdString(env, jType);
157+
return (*ptr)->HasProperty(prop, type);
158+
}
159+
160+
extern "C" JNIEXPORT jstring JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterGetPropertyString(
161+
JNIEnv* env,
162+
jclass clazz,
163+
jlong class_id,
164+
jstring jProperty) {
165+
auto* ptr = reinterpret_cast<std::shared_ptr<Filter>*>(class_id);
166+
if (!ptr || !*ptr) {
167+
return nullptr;
168+
}
169+
std::string ret,prop = JavaToStdString(env, jProperty);
170+
(*ptr)->GetProperty(prop, ret);
171+
return JavaStringFromStdString(env, ret);
172+
}
173+
174+
extern "C" JNIEXPORT int JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterGetPropertyInt(
175+
JNIEnv* env,
176+
jclass clazz,
177+
jlong class_id,
178+
jstring jProperty) {
179+
int ret = 0;
180+
auto* ptr = reinterpret_cast<std::shared_ptr<Filter>*>(class_id);
181+
if (!ptr || !*ptr) {
182+
return ret;
183+
}
184+
auto prop = JavaToStdString(env, jProperty);
185+
(*ptr)->GetProperty(prop, ret);
186+
return ret;
187+
}
188+
189+
extern "C" JNIEXPORT float JNICALL Java_com_pixpark_gpupixel_GPUPixelFilter_nativeFilterGetPropertyFloat(
190+
JNIEnv* env,
191+
jclass clazz,
192+
jlong class_id,
193+
jstring jProperty) {
194+
float ret = 0;
195+
auto* ptr = reinterpret_cast<std::shared_ptr<Filter>*>(class_id);
196+
if (!ptr || !*ptr) {
197+
return ret;
198+
}
199+
auto prop = JavaToStdString(env, jProperty);
200+
(*ptr)->GetProperty(prop, ret);
201+
return ret;
139202
}

src/filter/filter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ Filter::Property* Filter::GetProperty(const std::string& name) {
492492

493493
bool Filter::HasProperty(const std::string& name, const std::string type) {
494494
Property* property = GetProperty(name);
495-
return property && property->type == type ? true : false;
495+
return property && (type.empty() || property->type == type);
496496
}
497497

498498
bool Filter::HasProperty(const std::string& name) {

0 commit comments

Comments
 (0)