decoder_jni_onload.cc (1458B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #include <jni.h> 7 8 #include "tools/jni/org/jpeg/jpegxl/wrapper/decoder_jni.h" 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 static char* kGetBasicInfoName = const_cast<char*>("nativeGetBasicInfo"); 15 static char* kGetBasicInfoSig = const_cast<char*>("([ILjava/nio/Buffer;)V"); 16 static char* kGetPixelsName = const_cast<char*>("nativeGetPixels"); 17 static char* kGetPixelsInfoSig = const_cast<char*>( 18 "([ILjava/nio/Buffer;Ljava/nio/Buffer;Ljava/nio/Buffer;)V"); 19 20 #define JXL_JNI_METHOD(NAME) \ 21 (reinterpret_cast<void*>( \ 22 Java_org_jpeg_jpegxl_wrapper_DecoderJni_native##NAME)) 23 24 static const JNINativeMethod kDecoderMethods[] = { 25 {kGetBasicInfoName, kGetBasicInfoSig, JXL_JNI_METHOD(GetBasicInfo)}, 26 {kGetPixelsName, kGetPixelsInfoSig, JXL_JNI_METHOD(GetPixels)}}; 27 28 static const size_t kNumDecoderMethods = 2; 29 30 #undef JXL_JNI_METHOD 31 32 JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { 33 JNIEnv* env; 34 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { 35 return -1; 36 } 37 38 jclass clazz = env->FindClass("org/jpeg/jpegxl/wrapper/DecoderJni"); 39 if (clazz == nullptr) { 40 return -1; 41 } 42 43 if (env->RegisterNatives(clazz, kDecoderMethods, kNumDecoderMethods) < 0) { 44 return -1; 45 } 46 47 return JNI_VERSION_1_6; 48 } 49 50 #ifdef __cplusplus 51 } 52 #endif