Home | History | Annotate | Download | only in src
      1 
      2 //
      3 // This file is auto-generated, please don't edit!
      4 //
      5 
      6 #define LOG_TAG "org.opencv.imgcodecs"
      7 
      8 #include "common.h"
      9 
     10 #include "opencv2/opencv_modules.hpp"
     11 #ifdef HAVE_OPENCV_IMGCODECS
     12 
     13 #include <string>
     14 
     15 #include "opencv2/imgcodecs.hpp"
     16 
     17 #include "../../imgcodecs/include/opencv2/imgcodecs/imgcodecs_c.h"
     18 #include "../../imgcodecs/include/opencv2/imgcodecs.hpp"
     19 
     20 using namespace cv;
     21 
     22 /// throw java exception
     23 static void throwJavaException(JNIEnv *env, const std::exception *e, const char *method) {
     24   std::string what = "unknown exception";
     25   jclass je = 0;
     26 
     27   if(e) {
     28     std::string exception_type = "std::exception";
     29 
     30     if(dynamic_cast<const cv::Exception*>(e)) {
     31       exception_type = "cv::Exception";
     32       je = env->FindClass("org/opencv/core/CvException");
     33     }
     34 
     35     what = exception_type + ": " + e->what();
     36   }
     37 
     38   if(!je) je = env->FindClass("java/lang/Exception");
     39   env->ThrowNew(je, what.c_str());
     40 
     41   LOGE("%s caught %s", method, what.c_str());
     42   (void)method;        // avoid "unused" warning
     43 }
     44 
     45 
     46 extern "C" {
     47 
     48 
     49 //
     50 //  Mat imread(String filename, int flags = IMREAD_COLOR)
     51 //
     52 
     53 JNIEXPORT jlong JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imread_10 (JNIEnv*, jclass, jstring, jint);
     54 
     55 JNIEXPORT jlong JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imread_10
     56   (JNIEnv* env, jclass , jstring filename, jint flags)
     57 {
     58     static const char method_name[] = "imgcodecs::imread_10()";
     59     try {
     60         LOGD("%s", method_name);
     61         const char* utf_filename = env->GetStringUTFChars(filename, 0); String n_filename( utf_filename ? utf_filename : "" ); env->ReleaseStringUTFChars(filename, utf_filename);
     62         ::Mat _retval_ = cv::imread( n_filename, (int)flags );
     63         return (jlong) new ::Mat(_retval_);
     64     } catch(const std::exception &e) {
     65         throwJavaException(env, &e, method_name);
     66     } catch (...) {
     67         throwJavaException(env, 0, method_name);
     68     }
     69     return 0;
     70 }
     71 
     72 
     73 
     74 JNIEXPORT jlong JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imread_11 (JNIEnv*, jclass, jstring);
     75 
     76 JNIEXPORT jlong JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imread_11
     77   (JNIEnv* env, jclass , jstring filename)
     78 {
     79     static const char method_name[] = "imgcodecs::imread_11()";
     80     try {
     81         LOGD("%s", method_name);
     82         const char* utf_filename = env->GetStringUTFChars(filename, 0); String n_filename( utf_filename ? utf_filename : "" ); env->ReleaseStringUTFChars(filename, utf_filename);
     83         ::Mat _retval_ = cv::imread( n_filename );
     84         return (jlong) new ::Mat(_retval_);
     85     } catch(const std::exception &e) {
     86         throwJavaException(env, &e, method_name);
     87     } catch (...) {
     88         throwJavaException(env, 0, method_name);
     89     }
     90     return 0;
     91 }
     92 
     93 
     94 
     95 //
     96 //  bool imreadmulti(String filename, vector_Mat mats, int flags = IMREAD_ANYCOLOR)
     97 //
     98 
     99 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imreadmulti_10 (JNIEnv*, jclass, jstring, jlong, jint);
    100 
    101 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imreadmulti_10
    102   (JNIEnv* env, jclass , jstring filename, jlong mats_mat_nativeObj, jint flags)
    103 {
    104     static const char method_name[] = "imgcodecs::imreadmulti_10()";
    105     try {
    106         LOGD("%s", method_name);
    107         std::vector<Mat> mats;
    108         Mat& mats_mat = *((Mat*)mats_mat_nativeObj);
    109         Mat_to_vector_Mat( mats_mat, mats );
    110         const char* utf_filename = env->GetStringUTFChars(filename, 0); String n_filename( utf_filename ? utf_filename : "" ); env->ReleaseStringUTFChars(filename, utf_filename);
    111         bool _retval_ = cv::imreadmulti( n_filename, mats, (int)flags );
    112         return _retval_;
    113     } catch(const std::exception &e) {
    114         throwJavaException(env, &e, method_name);
    115     } catch (...) {
    116         throwJavaException(env, 0, method_name);
    117     }
    118     return 0;
    119 }
    120 
    121 
    122 
    123 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imreadmulti_11 (JNIEnv*, jclass, jstring, jlong);
    124 
    125 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imreadmulti_11
    126   (JNIEnv* env, jclass , jstring filename, jlong mats_mat_nativeObj)
    127 {
    128     static const char method_name[] = "imgcodecs::imreadmulti_11()";
    129     try {
    130         LOGD("%s", method_name);
    131         std::vector<Mat> mats;
    132         Mat& mats_mat = *((Mat*)mats_mat_nativeObj);
    133         Mat_to_vector_Mat( mats_mat, mats );
    134         const char* utf_filename = env->GetStringUTFChars(filename, 0); String n_filename( utf_filename ? utf_filename : "" ); env->ReleaseStringUTFChars(filename, utf_filename);
    135         bool _retval_ = cv::imreadmulti( n_filename, mats );
    136         return _retval_;
    137     } catch(const std::exception &e) {
    138         throwJavaException(env, &e, method_name);
    139     } catch (...) {
    140         throwJavaException(env, 0, method_name);
    141     }
    142     return 0;
    143 }
    144 
    145 
    146 
    147 //
    148 //  bool imwrite(String filename, Mat img, vector_int params = std::vector<int>())
    149 //
    150 
    151 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imwrite_10 (JNIEnv*, jclass, jstring, jlong, jlong);
    152 
    153 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imwrite_10
    154   (JNIEnv* env, jclass , jstring filename, jlong img_nativeObj, jlong params_mat_nativeObj)
    155 {
    156     static const char method_name[] = "imgcodecs::imwrite_10()";
    157     try {
    158         LOGD("%s", method_name);
    159         std::vector<int> params;
    160         Mat& params_mat = *((Mat*)params_mat_nativeObj);
    161         Mat_to_vector_int( params_mat, params );
    162         const char* utf_filename = env->GetStringUTFChars(filename, 0); String n_filename( utf_filename ? utf_filename : "" ); env->ReleaseStringUTFChars(filename, utf_filename);
    163         Mat& img = *((Mat*)img_nativeObj);
    164         bool _retval_ = cv::imwrite( n_filename, img, params );
    165         return _retval_;
    166     } catch(const std::exception &e) {
    167         throwJavaException(env, &e, method_name);
    168     } catch (...) {
    169         throwJavaException(env, 0, method_name);
    170     }
    171     return 0;
    172 }
    173 
    174 
    175 
    176 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imwrite_11 (JNIEnv*, jclass, jstring, jlong);
    177 
    178 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imwrite_11
    179   (JNIEnv* env, jclass , jstring filename, jlong img_nativeObj)
    180 {
    181     static const char method_name[] = "imgcodecs::imwrite_11()";
    182     try {
    183         LOGD("%s", method_name);
    184         const char* utf_filename = env->GetStringUTFChars(filename, 0); String n_filename( utf_filename ? utf_filename : "" ); env->ReleaseStringUTFChars(filename, utf_filename);
    185         Mat& img = *((Mat*)img_nativeObj);
    186         bool _retval_ = cv::imwrite( n_filename, img );
    187         return _retval_;
    188     } catch(const std::exception &e) {
    189         throwJavaException(env, &e, method_name);
    190     } catch (...) {
    191         throwJavaException(env, 0, method_name);
    192     }
    193     return 0;
    194 }
    195 
    196 
    197 
    198 //
    199 //  Mat imdecode(Mat buf, int flags)
    200 //
    201 
    202 JNIEXPORT jlong JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imdecode_10 (JNIEnv*, jclass, jlong, jint);
    203 
    204 JNIEXPORT jlong JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imdecode_10
    205   (JNIEnv* env, jclass , jlong buf_nativeObj, jint flags)
    206 {
    207     static const char method_name[] = "imgcodecs::imdecode_10()";
    208     try {
    209         LOGD("%s", method_name);
    210         Mat& buf = *((Mat*)buf_nativeObj);
    211         ::Mat _retval_ = cv::imdecode( buf, (int)flags );
    212         return (jlong) new ::Mat(_retval_);
    213     } catch(const std::exception &e) {
    214         throwJavaException(env, &e, method_name);
    215     } catch (...) {
    216         throwJavaException(env, 0, method_name);
    217     }
    218     return 0;
    219 }
    220 
    221 
    222 
    223 //
    224 //  bool imencode(String ext, Mat img, vector_uchar& buf, vector_int params = std::vector<int>())
    225 //
    226 
    227 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imencode_10 (JNIEnv*, jclass, jstring, jlong, jlong, jlong);
    228 
    229 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imencode_10
    230   (JNIEnv* env, jclass , jstring ext, jlong img_nativeObj, jlong buf_mat_nativeObj, jlong params_mat_nativeObj)
    231 {
    232     static const char method_name[] = "imgcodecs::imencode_10()";
    233     try {
    234         LOGD("%s", method_name);
    235         std::vector<uchar> buf;
    236         Mat& buf_mat = *((Mat*)buf_mat_nativeObj);
    237         std::vector<int> params;
    238         Mat& params_mat = *((Mat*)params_mat_nativeObj);
    239         Mat_to_vector_int( params_mat, params );
    240         const char* utf_ext = env->GetStringUTFChars(ext, 0); String n_ext( utf_ext ? utf_ext : "" ); env->ReleaseStringUTFChars(ext, utf_ext);
    241         Mat& img = *((Mat*)img_nativeObj);
    242         bool _retval_ = cv::imencode( n_ext, img, buf, params );
    243         vector_uchar_to_Mat( buf, buf_mat );
    244         return _retval_;
    245     } catch(const std::exception &e) {
    246         throwJavaException(env, &e, method_name);
    247     } catch (...) {
    248         throwJavaException(env, 0, method_name);
    249     }
    250     return 0;
    251 }
    252 
    253 
    254 
    255 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imencode_11 (JNIEnv*, jclass, jstring, jlong, jlong);
    256 
    257 JNIEXPORT jboolean JNICALL Java_org_opencv_imgcodecs_Imgcodecs_imencode_11
    258   (JNIEnv* env, jclass , jstring ext, jlong img_nativeObj, jlong buf_mat_nativeObj)
    259 {
    260     static const char method_name[] = "imgcodecs::imencode_11()";
    261     try {
    262         LOGD("%s", method_name);
    263         std::vector<uchar> buf;
    264         Mat& buf_mat = *((Mat*)buf_mat_nativeObj);
    265         const char* utf_ext = env->GetStringUTFChars(ext, 0); String n_ext( utf_ext ? utf_ext : "" ); env->ReleaseStringUTFChars(ext, utf_ext);
    266         Mat& img = *((Mat*)img_nativeObj);
    267         bool _retval_ = cv::imencode( n_ext, img, buf );
    268         vector_uchar_to_Mat( buf, buf_mat );
    269         return _retval_;
    270     } catch(const std::exception &e) {
    271         throwJavaException(env, &e, method_name);
    272     } catch (...) {
    273         throwJavaException(env, 0, method_name);
    274     }
    275     return 0;
    276 }
    277 
    278 
    279 
    280 
    281 } // extern "C"
    282 
    283 #endif // HAVE_OPENCV_IMGCODECS
    284