Implement create Vectors method in PacketCreator class.
- createInt16Vector - createInt32Vector - createInt64Vector - createFloat64Vector
This commit is contained in:
parent
f15da632de
commit
91cc9a18c3
|
@ -196,15 +196,15 @@ public class PacketCreator {
|
|||
}
|
||||
|
||||
public Packet createInt16Vector(short[] data) {
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
return Packet.create(nativeCreateInt16Vector(mediapipeGraph.getNativeHandle(), data));
|
||||
}
|
||||
|
||||
public Packet createInt32Vector(int[] data) {
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
return Packet.create(nativeCreateInt32Vector(mediapipeGraph.getNativeHandle(), data));
|
||||
}
|
||||
|
||||
public Packet createInt64Vector(long[] data) {
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
return Packet.create(nativeCreateInt64Vector(mediapipeGraph.getNativeHandle(), data));
|
||||
}
|
||||
|
||||
public Packet createFloat32Vector(float[] data) {
|
||||
|
@ -212,7 +212,7 @@ public class PacketCreator {
|
|||
}
|
||||
|
||||
public Packet createFloat64Vector(double[] data) {
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
return Packet.create(nativeCreateFloat64Vector(mediapipeGraph.getNativeHandle(), data));
|
||||
}
|
||||
|
||||
public Packet createInt32Array(int[] data) {
|
||||
|
@ -367,7 +367,11 @@ public class PacketCreator {
|
|||
private native long nativeCreateInt32Array(long context, int[] data);
|
||||
private native long nativeCreateFloat32Array(long context, float[] data);
|
||||
|
||||
private native long nativeCreateInt16Vector(long context, short[] data);
|
||||
private native long nativeCreateInt32Vector(long context, int[] data);
|
||||
private native long nativeCreateInt64Vector(long context, long[] data);
|
||||
private native long nativeCreateFloat32Vector(long context, float[] data);
|
||||
private native long nativeCreateFloat64Vector(long context, double[] data);
|
||||
|
||||
private native long nativeCreateStringFromByteArray(long context, byte[] data);
|
||||
private native long nativeCreateProto(long context, SerializedMessage data);
|
||||
|
|
|
@ -354,8 +354,6 @@ JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateGpuBuffer)(
|
|||
|
||||
#endif // !defined(MEDIAPIPE_DISABLE_GPU)
|
||||
|
||||
// TODO: Add vector creators.
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Array)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jfloatArray data) {
|
||||
jsize count = env->GetArrayLength(data);
|
||||
|
@ -376,6 +374,45 @@ JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Array)(
|
|||
return CreatePacketWithContext(context, packet);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt16Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jshortArray data) {
|
||||
jsize count = env->GetArrayLength(data);
|
||||
jshort* data_ref = env->GetShortArrayElements(data, nullptr);
|
||||
static_assert(std::is_same<int16_t, jshort>::value, "jshort must be int16_t");
|
||||
std::unique_ptr<std::vector<int16_t>> shorts =
|
||||
absl::make_unique<std::vector<int16_t>>(data_ref, data_ref + count);
|
||||
|
||||
env->ReleaseShortArrayElements(data, data_ref, JNI_ABORT);
|
||||
mediapipe::Packet packet = mediapipe::Adopt(shorts.release());
|
||||
return CreatePacketWithContext(context, packet);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt32Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jintArray data) {
|
||||
jsize count = env->GetArrayLength(data);
|
||||
jint* data_ref = env->GetIntArrayElements(data, nullptr);
|
||||
static_assert(std::is_same<int32_t, jint>::value, "jint must be int32_t");
|
||||
std::unique_ptr<std::vector<int32_t>> ints =
|
||||
absl::make_unique<std::vector<int32_t>>(data_ref, data_ref + count);
|
||||
|
||||
env->ReleaseIntArrayElements(data, data_ref, JNI_ABORT);
|
||||
mediapipe::Packet packet = mediapipe::Adopt(ints.release());
|
||||
return CreatePacketWithContext(context, packet);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt64Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jlongArray data) {
|
||||
jsize count = env->GetArrayLength(data);
|
||||
jlong* data_ref = env->GetLongArrayElements(data, nullptr);
|
||||
static_assert(std::is_same<int64_t, jlong>::value, "jlong must be int64_t");
|
||||
std::unique_ptr<std::vector<int64_t>> longs =
|
||||
absl::make_unique<std::vector<int64_t>>(data_ref, data_ref + count);
|
||||
|
||||
env->ReleaseLongArrayElements(data, data_ref, JNI_ABORT);
|
||||
mediapipe::Packet packet = mediapipe::Adopt(longs.release());
|
||||
return CreatePacketWithContext(context, packet);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jfloatArray data) {
|
||||
jsize count = env->GetArrayLength(data);
|
||||
|
@ -393,6 +430,19 @@ JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Vector)(
|
|||
return CreatePacketWithContext(context, packet);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat64Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jdoubleArray data) {
|
||||
jsize count = env->GetArrayLength(data);
|
||||
jdouble* data_ref = env->GetDoubleArrayElements(data, nullptr);
|
||||
static_assert(std::is_same<double, jdouble>::value, "jdouble must be double");
|
||||
std::unique_ptr<std::vector<double>> doubles =
|
||||
absl::make_unique<std::vector<double>>(data_ref, data_ref + count);
|
||||
|
||||
env->ReleaseDoubleArrayElements(data, data_ref, JNI_ABORT);
|
||||
mediapipe::Packet packet = mediapipe::Adopt(doubles.release());
|
||||
return CreatePacketWithContext(context, packet);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt32Array)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jintArray data) {
|
||||
jsize count = env->GetArrayLength(data);
|
||||
|
|
|
@ -104,9 +104,21 @@ JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateGpuBuffer)(
|
|||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Array)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jfloatArray data);
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt16Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jshortArray data);
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt32Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jintArray data);
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt64Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jlongArray data);
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jfloatArray data);
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat64Vector)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jdoubleArray data);
|
||||
|
||||
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt32Array)(
|
||||
JNIEnv* env, jobject thiz, jlong context, jintArray data);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user