Home | History | Annotate | Download | only in cpp
      1 #define LOG_TAG "org.opencv.core.Mat"
      2 
      3 #include <stdexcept>
      4 #include <string>
      5 
      6 #include "common.h"
      7 #include "opencv2/core.hpp"
      8 
      9 using namespace cv;
     10 
     11 /// throw java exception
     12 static void throwJavaException(JNIEnv *env, const std::exception *e, const char *method) {
     13   std::string what = "unknown exception";
     14   jclass je = 0;
     15 
     16   if(e) {
     17     std::string exception_type = "std::exception";
     18 
     19     if(dynamic_cast<const cv::Exception*>(e)) {
     20       exception_type = "cv::Exception";
     21       je = env->FindClass("org/opencv/core/CvException");
     22     }
     23 
     24     what = exception_type + ": " + e->what();
     25   }
     26 
     27   if(!je) je = env->FindClass("java/lang/Exception");
     28   env->ThrowNew(je, what.c_str());
     29 
     30   LOGE("%s caught %s", method, what.c_str());
     31   (void)method;        // avoid "unused" warning
     32 }
     33 
     34 extern "C" {
     35 
     36 
     37 //
     38 //   MatXXX::MatXXX()
     39 //
     40 
     41 
     42 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__
     43   (JNIEnv*, jclass);
     44 
     45 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__
     46   (JNIEnv*, jclass)
     47 {
     48     LOGD("Mat::n_1Mat__()");
     49     return (jlong) new cv::Mat();
     50 }
     51 
     52 
     53 
     54 //
     55 //   Mat::Mat(int rows, int cols, int type)
     56 //
     57 
     58 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__III
     59   (JNIEnv* env, jclass, jint rows, jint cols, jint type);
     60 
     61 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__III
     62   (JNIEnv* env, jclass, jint rows, jint cols, jint type)
     63 {
     64     static const char method_name[] = "Mat::n_1Mat__III()";
     65     try {
     66         LOGD("%s", method_name);
     67         return (jlong) new Mat( rows, cols, type );
     68     } catch(const std::exception &e) {
     69         throwJavaException(env, &e, method_name);
     70     } catch (...) {
     71         throwJavaException(env, 0, method_name);
     72     }
     73 
     74     return 0;
     75 }
     76 
     77 
     78 
     79 //
     80 //   Mat::Mat(Size size, int type)
     81 //
     82 
     83 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDI
     84   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);
     85 
     86 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDI
     87   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)
     88 {
     89     static const char method_name[] = "Mat::n_1Mat__DDI()";
     90     try {
     91         LOGD("%s", method_name);
     92         Size size((int)size_width, (int)size_height);
     93         return (jlong) new Mat( size, type );
     94     } catch(const std::exception &e) {
     95         throwJavaException(env, &e, method_name);
     96     } catch (...) {
     97         throwJavaException(env, 0, method_name);
     98     }
     99 
    100     return 0;
    101 }
    102 
    103 
    104 
    105 //
    106 //   Mat::Mat(int rows, int cols, int type, Scalar s)
    107 //
    108 
    109 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIIDDDD
    110   (JNIEnv* env, jclass, jint rows, jint cols, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3);
    111 
    112 
    113 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__IIIDDDD
    114   (JNIEnv* env, jclass, jint rows, jint cols, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3)
    115 {
    116     static const char method_name[] = "Mat::n_1Mat__IIIDDDD()";
    117     try {
    118         LOGD("%s", method_name);
    119         Scalar s(s_val0, s_val1, s_val2, s_val3);
    120         return (jlong) new Mat( rows, cols, type, s );
    121     } catch(const std::exception &e) {
    122         throwJavaException(env, &e, method_name);
    123     } catch (...) {
    124         throwJavaException(env, 0, method_name);
    125     }
    126 
    127     return 0;
    128 }
    129 
    130 
    131 
    132 //
    133 //   Mat::Mat(Size size, int type, Scalar s)
    134 //
    135 
    136 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDIDDDD
    137   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3);
    138 
    139 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__DDIDDDD
    140   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3)
    141 {
    142     static const char method_name[] = "Mat::n_1Mat__DDIDDDD()";
    143     try {
    144         LOGD("%s", method_name);
    145         Size size((int)size_width, (int)size_height);
    146         Scalar s(s_val0, s_val1, s_val2, s_val3);
    147         return (jlong) new Mat( size, type, s );
    148     } catch(const std::exception &e) {
    149         throwJavaException(env, &e, method_name);
    150     } catch (...) {
    151         throwJavaException(env, 0, method_name);
    152     }
    153 
    154     return 0;
    155 }
    156 
    157 
    158 
    159 //
    160 //   Mat::Mat(Mat m, Range rowRange, Range colRange = Range::all())
    161 //
    162 
    163 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JIIII
    164   (JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end);
    165 
    166 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JIIII
    167   (JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end)
    168 {
    169     static const char method_name[] = "Mat::n_1Mat__JIIII()";
    170     try {
    171         LOGD("%s", method_name);
    172         Range rowRange(rowRange_start, rowRange_end);
    173         Range colRange(colRange_start, colRange_end);
    174         return (jlong) new Mat( (*(Mat*)m_nativeObj), rowRange, colRange );
    175     } catch(const std::exception &e) {
    176         throwJavaException(env, &e, method_name);
    177     } catch (...) {
    178         throwJavaException(env, 0, method_name);
    179     }
    180 
    181     return 0;
    182 }
    183 
    184 
    185 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JII
    186   (JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end);
    187 
    188 
    189 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1Mat__JII
    190   (JNIEnv* env, jclass, jlong m_nativeObj, jint rowRange_start, jint rowRange_end)
    191 {
    192     static const char method_name[] = "Mat::n_1Mat__JII()";
    193     try {
    194         LOGD("%s", method_name);
    195         Range rowRange(rowRange_start, rowRange_end);
    196         return (jlong) new Mat( (*(Mat*)m_nativeObj), rowRange );
    197     } catch(const std::exception &e) {
    198         throwJavaException(env, &e, method_name);
    199     } catch (...) {
    200         throwJavaException(env, 0, method_name);
    201     }
    202 
    203     return 0;
    204 }
    205 
    206 
    207 //
    208 //  Mat Mat::adjustROI(int dtop, int dbottom, int dleft, int dright)
    209 //
    210 
    211 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1adjustROI
    212   (JNIEnv* env, jclass, jlong self, jint dtop, jint dbottom, jint dleft, jint dright);
    213 
    214 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1adjustROI
    215   (JNIEnv* env, jclass, jlong self, jint dtop, jint dbottom, jint dleft, jint dright)
    216 {
    217     static const char method_name[] = "Mat::n_1adjustROI()";
    218     try {
    219         LOGD("%s", method_name);
    220         Mat* me = (Mat*) self; //TODO: check for NULL
    221         Mat _retval_ = me->adjustROI( dtop, dbottom, dleft, dright );
    222         return (jlong) new Mat(_retval_);
    223     } catch(const std::exception &e) {
    224         throwJavaException(env, &e, method_name);
    225     } catch (...) {
    226         throwJavaException(env, 0, method_name);
    227     }
    228 
    229     return 0;
    230 }
    231 
    232 
    233 
    234 //
    235 //  void Mat::assignTo(Mat m, int type = -1)
    236 //
    237 
    238 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJI
    239   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint type);
    240 
    241 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJI
    242   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint type)
    243 {
    244     static const char method_name[] = "Mat::n_1assignTo__JJI()";
    245     try {
    246         LOGD("%s", method_name);
    247         Mat* me = (Mat*) self; //TODO: check for NULL
    248         me->assignTo( (*(Mat*)m_nativeObj), type );
    249     } catch(const std::exception &e) {
    250         throwJavaException(env, &e, method_name);
    251     } catch (...) {
    252         throwJavaException(env, 0, method_name);
    253     }
    254 }
    255 
    256 
    257 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJ
    258   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
    259 
    260 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1assignTo__JJ
    261   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
    262 {
    263     static const char method_name[] = "Mat::n_1assignTo__JJ()";
    264     try {
    265         LOGD("%s", method_name);
    266         Mat* me = (Mat*) self; //TODO: check for NULL
    267         me->assignTo( (*(Mat*)m_nativeObj) );
    268     } catch(const std::exception &e) {
    269         throwJavaException(env, &e, method_name);
    270     } catch (...) {
    271         throwJavaException(env, 0, method_name);
    272     }
    273 }
    274 
    275 
    276 
    277 //
    278 //  int Mat::channels()
    279 //
    280 
    281 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1channels
    282   (JNIEnv* env, jclass, jlong self);
    283 
    284 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1channels
    285   (JNIEnv* env, jclass, jlong self)
    286 {
    287     static const char method_name[] = "Mat::n_1channels()";
    288     try {
    289         LOGD("%s", method_name);
    290         Mat* me = (Mat*) self; //TODO: check for NULL
    291         return me->channels(  );
    292     } catch(const std::exception &e) {
    293         throwJavaException(env, &e, method_name);
    294     } catch (...) {
    295         throwJavaException(env, 0, method_name);
    296     }
    297 
    298     return 0;
    299 }
    300 
    301 
    302 
    303 //
    304 //  int Mat::checkVector(int elemChannels, int depth = -1, bool requireContinuous = true)
    305 //
    306 
    307 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JIIZ
    308   (JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth, jboolean requireContinuous);
    309 
    310 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JIIZ
    311   (JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth, jboolean requireContinuous)
    312 {
    313     static const char method_name[] = "Mat::n_1checkVector__JIIZ()";
    314     try {
    315         LOGD("%s", method_name);
    316         Mat* me = (Mat*) self; //TODO: check for NULL
    317         return me->checkVector( elemChannels, depth, requireContinuous );
    318     } catch(const std::exception &e) {
    319         throwJavaException(env, &e, method_name);
    320     } catch (...) {
    321         throwJavaException(env, 0, method_name);
    322     }
    323 
    324     return 0;
    325 }
    326 
    327 
    328 
    329 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JII
    330   (JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth);
    331 
    332 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JII
    333   (JNIEnv* env, jclass, jlong self, jint elemChannels, jint depth)
    334 {
    335     static const char method_name[] = "Mat::n_1checkVector__JII()";
    336     try {
    337         LOGD("%s", method_name);
    338         Mat* me = (Mat*) self; //TODO: check for NULL
    339         return me->checkVector( elemChannels, depth );
    340     } catch(const std::exception &e) {
    341         throwJavaException(env, &e, method_name);
    342     } catch (...) {
    343         throwJavaException(env, 0, method_name);
    344     }
    345 
    346     return 0;
    347 }
    348 
    349 
    350 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JI
    351   (JNIEnv* env, jclass, jlong self, jint elemChannels);
    352 
    353 
    354 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1checkVector__JI
    355   (JNIEnv* env, jclass, jlong self, jint elemChannels)
    356 {
    357     static const char method_name[] = "Mat::n_1checkVector__JI()";
    358     try {
    359         LOGD("%s", method_name);
    360         Mat* me = (Mat*) self; //TODO: check for NULL
    361         return me->checkVector( elemChannels );
    362     } catch(const std::exception &e) {
    363         throwJavaException(env, &e, method_name);
    364     } catch (...) {
    365         throwJavaException(env, 0, method_name);
    366     }
    367 
    368     return 0;
    369 }
    370 
    371 
    372 
    373 //
    374 //  Mat Mat::clone()
    375 //
    376 
    377 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1clone
    378   (JNIEnv* env, jclass, jlong self);
    379 
    380 
    381 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1clone
    382   (JNIEnv* env, jclass, jlong self)
    383 {
    384     static const char method_name[] = "Mat::n_1clone()";
    385     try {
    386         LOGD("%s", method_name);
    387         Mat* me = (Mat*) self; //TODO: check for NULL
    388         Mat _retval_ = me->clone(  );
    389         return (jlong) new Mat(_retval_);
    390     } catch(const std::exception &e) {
    391         throwJavaException(env, &e, method_name);
    392     } catch (...) {
    393         throwJavaException(env, 0, method_name);
    394     }
    395 
    396     return 0;
    397 }
    398 
    399 
    400 
    401 //
    402 //  Mat Mat::col(int x)
    403 //
    404 
    405 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1col
    406   (JNIEnv* env, jclass, jlong self, jint x);
    407 
    408 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1col
    409   (JNIEnv* env, jclass, jlong self, jint x)
    410 {
    411     static const char method_name[] = "Mat::n_1col()";
    412     try {
    413         LOGD("%s", method_name);
    414         Mat* me = (Mat*) self; //TODO: check for NULL
    415         Mat _retval_ = me->col( x );
    416         return (jlong) new Mat(_retval_);
    417     } catch(const std::exception &e) {
    418         throwJavaException(env, &e, method_name);
    419     } catch (...) {
    420         throwJavaException(env, 0, method_name);
    421     }
    422 
    423     return 0;
    424 }
    425 
    426 
    427 
    428 //
    429 //  Mat Mat::colRange(int startcol, int endcol)
    430 //
    431 
    432 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1colRange
    433   (JNIEnv* env, jclass, jlong self, jint startcol, jint endcol);
    434 
    435 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1colRange
    436   (JNIEnv* env, jclass, jlong self, jint startcol, jint endcol)
    437 {
    438     static const char method_name[] = "Mat::n_1colRange()";
    439     try {
    440         LOGD("%s", method_name);
    441         Mat* me = (Mat*) self; //TODO: check for NULL
    442         Mat _retval_ = me->colRange( startcol, endcol );
    443         return (jlong) new Mat(_retval_);
    444     } catch(const std::exception &e) {
    445         throwJavaException(env, &e, method_name);
    446     } catch (...) {
    447         throwJavaException(env, 0, method_name);
    448     }
    449 
    450     return 0;
    451 }
    452 
    453 
    454 
    455 //
    456 //  int Mat::dims()
    457 //
    458 
    459 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1dims
    460   (JNIEnv* env, jclass, jlong self);
    461 
    462 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1dims
    463   (JNIEnv* env, jclass, jlong self)
    464 {
    465     static const char method_name[] = "Mat::n_1dims()";
    466     try {
    467         LOGD("%s", method_name);
    468         Mat* me = (Mat*) self; //TODO: check for NULL
    469         return me->dims;
    470     } catch(const cv::Exception& e) {
    471         throwJavaException(env, &e, method_name);
    472     } catch (...) {
    473         throwJavaException(env, 0, method_name);
    474     }
    475 
    476     return 0;
    477 }
    478 
    479 
    480 
    481 //
    482 //  int Mat::cols()
    483 //
    484 
    485 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1cols
    486   (JNIEnv* env, jclass, jlong self);
    487 
    488 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1cols
    489   (JNIEnv* env, jclass, jlong self)
    490 {
    491     static const char method_name[] = "Mat::n_1cols()";
    492     try {
    493         LOGD("%s", method_name);
    494         Mat* me = (Mat*) self; //TODO: check for NULL
    495         return me->cols;
    496     } catch(const std::exception &e) {
    497         throwJavaException(env, &e, method_name);
    498     } catch (...) {
    499         throwJavaException(env, 0, method_name);
    500     }
    501 
    502     return 0;
    503 }
    504 
    505 
    506 
    507 //
    508 //  void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta = 0)
    509 //
    510 
    511 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJIDD
    512   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha, jdouble beta);
    513 
    514 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJIDD
    515   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha, jdouble beta)
    516 {
    517     static const char method_name[] = "Mat::n_1convertTo__JJIDD()";
    518     try {
    519         LOGD("%s", method_name);
    520         Mat* me = (Mat*) self; //TODO: check for NULL
    521         Mat& m = *((Mat*)m_nativeObj);
    522         me->convertTo( m, rtype, alpha, beta );
    523     } catch(const std::exception &e) {
    524         throwJavaException(env, &e, method_name);
    525     } catch (...) {
    526         throwJavaException(env, 0, method_name);
    527     }
    528 }
    529 
    530 
    531 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJID
    532   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha);
    533 
    534 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJID
    535   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype, jdouble alpha)
    536 {
    537     static const char method_name[] = "Mat::n_1convertTo__JJID()";
    538     try {
    539         LOGD("%s", method_name);
    540         Mat* me = (Mat*) self; //TODO: check for NULL
    541         Mat& m = *((Mat*)m_nativeObj);
    542         me->convertTo( m, rtype, alpha );
    543     } catch(const std::exception &e) {
    544         throwJavaException(env, &e, method_name);
    545     } catch (...) {
    546         throwJavaException(env, 0, method_name);
    547     }
    548 }
    549 
    550 
    551 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJI
    552   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype);
    553 
    554 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1convertTo__JJI
    555   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jint rtype)
    556 {
    557     static const char method_name[] = "Mat::n_1convertTo__JJI()";
    558     try {
    559         LOGD("%s", method_name);
    560         Mat* me = (Mat*) self; //TODO: check for NULL
    561         Mat& m = *((Mat*)m_nativeObj);
    562         me->convertTo( m, rtype );
    563     } catch(const std::exception &e) {
    564         throwJavaException(env, &e, method_name);
    565     } catch (...) {
    566         throwJavaException(env, 0, method_name);
    567     }
    568 }
    569 
    570 
    571 
    572 //
    573 //  void Mat::copyTo(Mat& m)
    574 //
    575 
    576 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJ
    577   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
    578 
    579 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJ
    580   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
    581 {
    582     static const char method_name[] = "Mat::n_1copyTo__JJ()";
    583     try {
    584         LOGD("%s", method_name);
    585         Mat* me = (Mat*) self; //TODO: check for NULL
    586         Mat& m = *((Mat*)m_nativeObj);
    587         me->copyTo( m );
    588     } catch(const std::exception &e) {
    589         throwJavaException(env, &e, method_name);
    590     } catch (...) {
    591         throwJavaException(env, 0, method_name);
    592     }
    593 }
    594 
    595 
    596 
    597 //
    598 //  void Mat::copyTo(Mat& m, Mat mask)
    599 //
    600 
    601 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJJ
    602   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jlong mask_nativeObj);
    603 
    604 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1copyTo__JJJ
    605   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jlong mask_nativeObj)
    606 {
    607     static const char method_name[] = "Mat::n_1copyTo__JJJ()";
    608     try {
    609         LOGD("%s", method_name);
    610         Mat* me = (Mat*) self; //TODO: check for NULL
    611         Mat& m = *((Mat*)m_nativeObj);
    612         Mat& mask = *((Mat*)mask_nativeObj);
    613         me->copyTo( m, mask );
    614     } catch(const std::exception &e) {
    615         throwJavaException(env, &e, method_name);
    616     } catch (...) {
    617         throwJavaException(env, 0, method_name);
    618     }
    619 }
    620 
    621 
    622 
    623 //
    624 //  void Mat::create(int rows, int cols, int type)
    625 //
    626 
    627 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JIII
    628   (JNIEnv* env, jclass, jlong self, jint rows, jint cols, jint type);
    629 
    630 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JIII
    631   (JNIEnv* env, jclass, jlong self, jint rows, jint cols, jint type)
    632 {
    633     static const char method_name[] = "Mat::n_1create__JIII()";
    634     try {
    635         LOGD("%s", method_name);
    636         Mat* me = (Mat*) self; //TODO: check for NULL
    637         me->create( rows, cols, type );
    638     } catch(const std::exception &e) {
    639         throwJavaException(env, &e, method_name);
    640     } catch (...) {
    641         throwJavaException(env, 0, method_name);
    642     }
    643 }
    644 
    645 
    646 
    647 //
    648 //  void Mat::create(Size size, int type)
    649 //
    650 
    651 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JDDI
    652   (JNIEnv* env, jclass, jlong self, jdouble size_width, jdouble size_height, jint type);
    653 
    654 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1create__JDDI
    655   (JNIEnv* env, jclass, jlong self, jdouble size_width, jdouble size_height, jint type)
    656 {
    657     static const char method_name[] = "Mat::n_1create__JDDI()";
    658     try {
    659         LOGD("%s", method_name);
    660         Mat* me = (Mat*) self; //TODO: check for NULL
    661         Size size((int)size_width, (int)size_height);
    662         me->create( size, type );
    663     } catch(const std::exception &e) {
    664         throwJavaException(env, &e, method_name);
    665     } catch (...) {
    666         throwJavaException(env, 0, method_name);
    667     }
    668 }
    669 
    670 
    671 
    672 //
    673 //  Mat Mat::cross(Mat m)
    674 //
    675 
    676 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1cross
    677   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
    678 
    679 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1cross
    680   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
    681 {
    682     static const char method_name[] = "Mat::n_1cross()";
    683     try {
    684         LOGD("%s", method_name);
    685         Mat* me = (Mat*) self; //TODO: check for NULL
    686         Mat& m = *((Mat*)m_nativeObj);
    687         Mat _retval_ = me->cross( m );
    688         return (jlong) new Mat(_retval_);
    689     } catch(const std::exception &e) {
    690         throwJavaException(env, &e, method_name);
    691     } catch (...) {
    692         throwJavaException(env, 0, method_name);
    693     }
    694 
    695     return 0;
    696 }
    697 
    698 
    699 
    700 //
    701 //  long Mat::dataAddr()
    702 //
    703 
    704 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1dataAddr
    705   (JNIEnv*, jclass, jlong self);
    706 
    707 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1dataAddr
    708   (JNIEnv*, jclass, jlong self)
    709 {
    710     LOGD("Mat::n_1dataAddr()");
    711     Mat* me = (Mat*) self; //TODO: check for NULL
    712     return (jlong) me->data;
    713 }
    714 
    715 
    716 
    717 //
    718 //  int Mat::depth()
    719 //
    720 
    721 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1depth
    722   (JNIEnv* env, jclass, jlong self);
    723 
    724 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1depth
    725   (JNIEnv* env, jclass, jlong self)
    726 {
    727     static const char method_name[] = "Mat::n_1depth()";
    728     try {
    729         LOGD("%s", method_name);
    730         Mat* me = (Mat*) self; //TODO: check for NULL
    731         return me->depth(  );
    732     } catch(const std::exception &e) {
    733         throwJavaException(env, &e, method_name);
    734     } catch (...) {
    735         throwJavaException(env, 0, method_name);
    736     }
    737 
    738     return 0;
    739 }
    740 
    741 
    742 
    743 //
    744 //  Mat Mat::diag(int d = 0)
    745 //
    746 
    747 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__JI
    748   (JNIEnv* env, jclass, jlong self, jint d);
    749 
    750 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__JI
    751   (JNIEnv* env, jclass, jlong self, jint d)
    752 {
    753     static const char method_name[] = "Mat::n_1diag__JI()";
    754     try {
    755         LOGD("%s", method_name);
    756         Mat* me = (Mat*) self; //TODO: check for NULL
    757         Mat _retval_ = me->diag( d );
    758         return (jlong) new Mat(_retval_);
    759     } catch(const std::exception &e) {
    760         throwJavaException(env, &e, method_name);
    761     } catch (...) {
    762         throwJavaException(env, 0, method_name);
    763     }
    764 
    765     return 0;
    766 }
    767 
    768 
    769 
    770 
    771 //
    772 // static Mat Mat::diag(Mat d)
    773 //
    774 
    775 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__J
    776   (JNIEnv* env, jclass, jlong d_nativeObj);
    777 
    778 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1diag__J
    779   (JNIEnv* env, jclass, jlong d_nativeObj)
    780 {
    781     static const char method_name[] = "Mat::n_1diag__J()";
    782     try {
    783         LOGD("%s", method_name);
    784         Mat _retval_ = Mat::diag( (*(Mat*)d_nativeObj) );
    785         return (jlong) new Mat(_retval_);
    786     } catch(const std::exception &e) {
    787         throwJavaException(env, &e, method_name);
    788     } catch (...) {
    789         throwJavaException(env, 0, method_name);
    790     }
    791 
    792     return 0;
    793 }
    794 
    795 
    796 
    797 //
    798 //  double Mat::dot(Mat m)
    799 //
    800 
    801 JNIEXPORT jdouble JNICALL Java_org_opencv_core_Mat_n_1dot
    802   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
    803 
    804 JNIEXPORT jdouble JNICALL Java_org_opencv_core_Mat_n_1dot
    805   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
    806 {
    807     static const char method_name[] = "Mat::n_1dot()";
    808     try {
    809         LOGD("%s", method_name);
    810         Mat* me = (Mat*) self; //TODO: check for NULL
    811         Mat& m = *((Mat*)m_nativeObj);
    812         return me->dot( m );
    813     } catch(const std::exception &e) {
    814         throwJavaException(env, &e, method_name);
    815     } catch (...) {
    816         throwJavaException(env, 0, method_name);
    817     }
    818 
    819     return 0;
    820 }
    821 
    822 
    823 
    824 //
    825 //  size_t Mat::elemSize()
    826 //
    827 
    828 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize
    829   (JNIEnv* env, jclass, jlong self);
    830 
    831 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize
    832   (JNIEnv* env, jclass, jlong self)
    833 {
    834     static const char method_name[] = "Mat::n_1elemSize()";
    835     try {
    836         LOGD("%s", method_name);
    837         Mat* me = (Mat*) self; //TODO: check for NULL
    838         return me->elemSize(  );
    839     } catch(const std::exception &e) {
    840         throwJavaException(env, &e, method_name);
    841     } catch (...) {
    842         throwJavaException(env, 0, method_name);
    843     }
    844 
    845     return 0;
    846 }
    847 
    848 
    849 
    850 //
    851 //  size_t Mat::elemSize1()
    852 //
    853 
    854 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize1
    855   (JNIEnv* env, jclass, jlong self);
    856 
    857 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1elemSize1
    858   (JNIEnv* env, jclass, jlong self)
    859 {
    860     static const char method_name[] = "Mat::n_1elemSize1()";
    861     try {
    862         LOGD("%s", method_name);
    863         Mat* me = (Mat*) self; //TODO: check for NULL
    864         return me->elemSize1(  );
    865     } catch(const std::exception &e) {
    866         throwJavaException(env, &e, method_name);
    867     } catch (...) {
    868         throwJavaException(env, 0, method_name);
    869     }
    870 
    871     return 0;
    872 }
    873 
    874 
    875 
    876 //
    877 //  bool Mat::empty()
    878 //
    879 
    880 JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1empty
    881   (JNIEnv* env, jclass, jlong self);
    882 
    883 JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1empty
    884   (JNIEnv* env, jclass, jlong self)
    885 {
    886     static const char method_name[] = "Mat::n_1empty()";
    887     try {
    888         LOGD("%s", method_name);
    889         Mat* me = (Mat*) self; //TODO: check for NULL
    890         return me->empty(  );
    891     } catch(const std::exception &e) {
    892         throwJavaException(env, &e, method_name);
    893     } catch (...) {
    894         throwJavaException(env, 0, method_name);
    895     }
    896 
    897     return 0;
    898 }
    899 
    900 
    901 
    902 //
    903 // static Mat Mat::eye(int rows, int cols, int type)
    904 //
    905 
    906 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__III
    907   (JNIEnv* env, jclass, jint rows, jint cols, jint type);
    908 
    909 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__III
    910   (JNIEnv* env, jclass, jint rows, jint cols, jint type)
    911 {
    912     static const char method_name[] = "Mat::n_1eye__III()";
    913     try {
    914         LOGD("%s", method_name);
    915         Mat _retval_ = Mat::eye( rows, cols, type );
    916         return (jlong) new Mat(_retval_);
    917     } catch(const std::exception &e) {
    918         throwJavaException(env, &e, method_name);
    919     } catch (...) {
    920         throwJavaException(env, 0, method_name);
    921     }
    922 
    923     return 0;
    924 }
    925 
    926 
    927 
    928 //
    929 // static Mat Mat::eye(Size size, int type)
    930 //
    931 
    932 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__DDI
    933   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);
    934 
    935 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1eye__DDI
    936   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)
    937 {
    938     static const char method_name[] = "Mat::n_1eye__DDI()";
    939     try {
    940         LOGD("%s", method_name);
    941         Size size((int)size_width, (int)size_height);
    942         Mat _retval_ = Mat::eye( size, type );
    943         return (jlong) new Mat(_retval_);
    944     } catch(const std::exception &e) {
    945         throwJavaException(env, &e, method_name);
    946     } catch (...) {
    947         throwJavaException(env, 0, method_name);
    948     }
    949 
    950     return 0;
    951 }
    952 
    953 
    954 
    955 //
    956 //  Mat Mat::inv(int method = DECOMP_LU)
    957 //
    958 
    959 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__JI
    960   (JNIEnv* env, jclass, jlong self, jint method);
    961 
    962 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__JI
    963   (JNIEnv* env, jclass, jlong self, jint method)
    964 {
    965     static const char method_name[] = "Mat::n_1inv__JI()";
    966     try {
    967         LOGD("%s", method_name);
    968         Mat* me = (Mat*) self; //TODO: check for NULL
    969         Mat _retval_ = me->inv( method );
    970         return (jlong) new Mat(_retval_);
    971     } catch(const std::exception &e) {
    972         throwJavaException(env, &e, method_name);
    973     } catch (...) {
    974         throwJavaException(env, 0, method_name);
    975     }
    976 
    977     return 0;
    978 }
    979 
    980 
    981 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__J
    982   (JNIEnv* env, jclass, jlong self);
    983 
    984 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1inv__J
    985   (JNIEnv* env, jclass, jlong self)
    986 {
    987     static const char method_name[] = "Mat::n_1inv__J()";
    988     try {
    989         LOGD("%s", method_name);
    990         Mat* me = (Mat*) self; //TODO: check for NULL
    991         Mat _retval_ = me->inv(  );
    992         return (jlong) new Mat(_retval_);
    993     } catch(const std::exception &e) {
    994         throwJavaException(env, &e, method_name);
    995     } catch (...) {
    996         throwJavaException(env, 0, method_name);
    997     }
    998 
    999     return 0;
   1000 }
   1001 
   1002 
   1003 
   1004 //
   1005 //  bool Mat::isContinuous()
   1006 //
   1007 
   1008 JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isContinuous
   1009   (JNIEnv* env, jclass, jlong self);
   1010 
   1011 JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isContinuous
   1012   (JNIEnv* env, jclass, jlong self)
   1013 {
   1014     static const char method_name[] = "Mat::n_1isContinuous()";
   1015     try {
   1016         LOGD("%s", method_name);
   1017         Mat* me = (Mat*) self; //TODO: check for NULL
   1018         return me->isContinuous(  );
   1019     } catch(const std::exception &e) {
   1020         throwJavaException(env, &e, method_name);
   1021     } catch (...) {
   1022         throwJavaException(env, 0, method_name);
   1023     }
   1024 
   1025     return 0;
   1026 }
   1027 
   1028 
   1029 
   1030 //
   1031 //  bool Mat::isSubmatrix()
   1032 //
   1033 
   1034 JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isSubmatrix
   1035   (JNIEnv* env, jclass, jlong self);
   1036 
   1037 JNIEXPORT jboolean JNICALL Java_org_opencv_core_Mat_n_1isSubmatrix
   1038   (JNIEnv* env, jclass, jlong self)
   1039 {
   1040     static const char method_name[] = "Mat::n_1isSubmatrix()";
   1041     try {
   1042         LOGD("%s", method_name);
   1043         Mat* me = (Mat*) self; //TODO: check for NULL
   1044         return me->isSubmatrix(  );
   1045     } catch(const std::exception &e) {
   1046         throwJavaException(env, &e, method_name);
   1047     } catch (...) {
   1048         throwJavaException(env, 0, method_name);
   1049     }
   1050 
   1051     return 0;
   1052 }
   1053 
   1054 
   1055 
   1056 //
   1057 //  void Mat::locateROI(Size wholeSize, Point ofs)
   1058 //
   1059 
   1060 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_locateROI_10
   1061   (JNIEnv* env, jclass, jlong self, jdoubleArray wholeSize_out, jdoubleArray ofs_out);
   1062 
   1063 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_locateROI_10
   1064   (JNIEnv* env, jclass, jlong self, jdoubleArray wholeSize_out, jdoubleArray ofs_out)
   1065 {
   1066     static const char method_name[] = "core::locateROI_10()";
   1067     try {
   1068         LOGD("%s", method_name);
   1069         Mat* me = (Mat*) self; //TODO: check for NULL
   1070         Size wholeSize;
   1071         Point ofs;
   1072         me->locateROI( wholeSize, ofs );
   1073         jdouble tmp_wholeSize[2] = {wholeSize.width, wholeSize.height}; env->SetDoubleArrayRegion(wholeSize_out, 0, 2, tmp_wholeSize);  jdouble tmp_ofs[2] = {ofs.x, ofs.y}; env->SetDoubleArrayRegion(ofs_out, 0, 2, tmp_ofs);
   1074     } catch(const std::exception &e) {
   1075         throwJavaException(env, &e, method_name);
   1076     } catch (...) {
   1077         throwJavaException(env, 0, method_name);
   1078     }
   1079 }
   1080 
   1081 
   1082 
   1083 //
   1084 //  Mat Mat::mul(Mat m, double scale = 1)
   1085 //
   1086 
   1087 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJD
   1088   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jdouble scale);
   1089 
   1090 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJD
   1091   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj, jdouble scale)
   1092 {
   1093     static const char method_name[] = "Mat::n_1mul__JJD()";
   1094     try {
   1095         LOGD("%s", method_name);
   1096         Mat* me = (Mat*) self; //TODO: check for NULL
   1097         Mat& m = *((Mat*)m_nativeObj);
   1098         Mat _retval_ = me->mul( m, scale );
   1099         return (jlong) new Mat(_retval_);
   1100     } catch(const std::exception &e) {
   1101         throwJavaException(env, &e, method_name);
   1102     } catch (...) {
   1103         throwJavaException(env, 0, method_name);
   1104     }
   1105 
   1106     return 0;
   1107 }
   1108 
   1109 
   1110 
   1111 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJ
   1112   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
   1113 
   1114 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1mul__JJ
   1115   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
   1116 {
   1117     static const char method_name[] = "Mat::n_1mul__JJ()";
   1118     try {
   1119         LOGD("%s", method_name);
   1120         Mat* me = (Mat*) self; //TODO: check for NULL
   1121         Mat& m = *((Mat*)m_nativeObj);
   1122         Mat _retval_ = me->mul( m );
   1123         return (jlong) new Mat(_retval_);
   1124     } catch(const std::exception &e) {
   1125         throwJavaException(env, &e, method_name);
   1126     } catch (...) {
   1127         throwJavaException(env, 0, method_name);
   1128     }
   1129 
   1130     return 0;
   1131 }
   1132 
   1133 
   1134 
   1135 //
   1136 // static Mat Mat::ones(int rows, int cols, int type)
   1137 //
   1138 
   1139 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__III
   1140   (JNIEnv* env, jclass, jint rows, jint cols, jint type);
   1141 
   1142 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__III
   1143   (JNIEnv* env, jclass, jint rows, jint cols, jint type)
   1144 {
   1145     static const char method_name[] = "Mat::n_1ones__III()";
   1146     try {
   1147         LOGD("%s", method_name);
   1148         Mat _retval_ = Mat::ones( rows, cols, type );
   1149         return (jlong) new Mat(_retval_);
   1150     } catch(const std::exception &e) {
   1151         throwJavaException(env, &e, method_name);
   1152     } catch (...) {
   1153         throwJavaException(env, 0, method_name);
   1154     }
   1155 
   1156     return 0;
   1157 }
   1158 
   1159 
   1160 
   1161 //
   1162 // static Mat Mat::ones(Size size, int type)
   1163 //
   1164 
   1165 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__DDI
   1166   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);
   1167 
   1168 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1ones__DDI
   1169   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)
   1170 {
   1171     static const char method_name[] = "Mat::n_1ones__DDI()";
   1172     try {
   1173         LOGD("%s", method_name);
   1174         Size size((int)size_width, (int)size_height);
   1175         Mat _retval_ = Mat::ones( size, type );
   1176         return (jlong) new Mat(_retval_);
   1177     } catch(const std::exception &e) {
   1178         throwJavaException(env, &e, method_name);
   1179     } catch (...) {
   1180         throwJavaException(env, 0, method_name);
   1181     }
   1182 
   1183     return 0;
   1184 }
   1185 
   1186 
   1187 
   1188 //
   1189 //  void Mat::push_back(Mat m)
   1190 //
   1191 
   1192 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1push_1back
   1193   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj);
   1194 
   1195 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1push_1back
   1196   (JNIEnv* env, jclass, jlong self, jlong m_nativeObj)
   1197 {
   1198     static const char method_name[] = "Mat::n_1push_1back()";
   1199     try {
   1200         LOGD("%s", method_name);
   1201         Mat* me = (Mat*) self; //TODO: check for NULL
   1202         me->push_back( (*(Mat*)m_nativeObj) );
   1203     } catch(const std::exception &e) {
   1204         throwJavaException(env, &e, method_name);
   1205     } catch (...) {
   1206         throwJavaException(env, 0, method_name);
   1207     }
   1208 }
   1209 
   1210 
   1211 
   1212 //
   1213 //  void Mat::release()
   1214 //
   1215 
   1216 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1release
   1217   (JNIEnv* env, jclass, jlong self);
   1218 
   1219 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1release
   1220   (JNIEnv* env, jclass, jlong self)
   1221 {
   1222     static const char method_name[] = "Mat::n_1release()";
   1223     try {
   1224         LOGD("%s", method_name);
   1225         Mat* me = (Mat*) self; //TODO: check for NULL
   1226         me->release(  );
   1227     } catch(const std::exception &e) {
   1228         throwJavaException(env, &e, method_name);
   1229     } catch (...) {
   1230         throwJavaException(env, 0, method_name);
   1231     }
   1232 }
   1233 
   1234 
   1235 
   1236 //
   1237 //  Mat Mat::reshape(int cn, int rows = 0)
   1238 //
   1239 
   1240 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JII
   1241   (JNIEnv* env, jclass, jlong self, jint cn, jint rows);
   1242 
   1243 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JII
   1244   (JNIEnv* env, jclass, jlong self, jint cn, jint rows)
   1245 {
   1246     static const char method_name[] = "Mat::n_1reshape__JII()";
   1247     try {
   1248         LOGD("%s", method_name);
   1249         Mat* me = (Mat*) self; //TODO: check for NULL
   1250         Mat _retval_ = me->reshape( cn, rows );
   1251         return (jlong) new Mat(_retval_);
   1252     } catch(const std::exception &e) {
   1253         throwJavaException(env, &e, method_name);
   1254     } catch (...) {
   1255         throwJavaException(env, 0, method_name);
   1256     }
   1257 
   1258     return 0;
   1259 }
   1260 
   1261 
   1262 
   1263 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JI
   1264   (JNIEnv* env, jclass, jlong self, jint cn);
   1265 
   1266 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JI
   1267   (JNIEnv* env, jclass, jlong self, jint cn)
   1268 {
   1269     static const char method_name[] = "Mat::n_1reshape__JI()";
   1270     try {
   1271         LOGD("%s", method_name);
   1272         Mat* me = (Mat*) self; //TODO: check for NULL
   1273         Mat _retval_ = me->reshape( cn );
   1274         return (jlong) new Mat(_retval_);
   1275     } catch(const std::exception &e) {
   1276         throwJavaException(env, &e, method_name);
   1277     } catch (...) {
   1278         throwJavaException(env, 0, method_name);
   1279     }
   1280 
   1281     return 0;
   1282 }
   1283 
   1284 
   1285 
   1286 //
   1287 //  Mat Mat::row(int y)
   1288 //
   1289 
   1290 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1row
   1291   (JNIEnv* env, jclass, jlong self, jint y);
   1292 
   1293 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1row
   1294   (JNIEnv* env, jclass, jlong self, jint y)
   1295 {
   1296     static const char method_name[] = "Mat::n_1row()";
   1297     try {
   1298         LOGD("%s", method_name);
   1299         Mat* me = (Mat*) self; //TODO: check for NULL
   1300         Mat _retval_ = me->row( y );
   1301         return (jlong) new Mat(_retval_);
   1302     } catch(const std::exception &e) {
   1303         throwJavaException(env, &e, method_name);
   1304     } catch (...) {
   1305         throwJavaException(env, 0, method_name);
   1306     }
   1307 
   1308     return 0;
   1309 }
   1310 
   1311 
   1312 
   1313 //
   1314 //  Mat Mat::rowRange(int startrow, int endrow)
   1315 //
   1316 
   1317 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1rowRange
   1318   (JNIEnv* env, jclass, jlong self, jint startrow, jint endrow);
   1319 
   1320 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1rowRange
   1321   (JNIEnv* env, jclass, jlong self, jint startrow, jint endrow)
   1322 {
   1323     static const char method_name[] = "Mat::n_1rowRange()";
   1324     try {
   1325         LOGD("%s", method_name);
   1326         Mat* me = (Mat*) self; //TODO: check for NULL
   1327         Mat _retval_ = me->rowRange( startrow, endrow );
   1328         return (jlong) new Mat(_retval_);
   1329     } catch(const std::exception &e) {
   1330         throwJavaException(env, &e, method_name);
   1331     } catch (...) {
   1332         throwJavaException(env, 0, method_name);
   1333     }
   1334 
   1335     return 0;
   1336 }
   1337 
   1338 
   1339 
   1340 //
   1341 //  int Mat::rows()
   1342 //
   1343 
   1344 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1rows
   1345   (JNIEnv* env, jclass, jlong self);
   1346 
   1347 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1rows
   1348   (JNIEnv* env, jclass, jlong self)
   1349 {
   1350     static const char method_name[] = "Mat::n_1rows()";
   1351     try {
   1352         LOGD("%s", method_name);
   1353         Mat* me = (Mat*) self; //TODO: check for NULL
   1354         return me->rows;
   1355     } catch(const std::exception &e) {
   1356         throwJavaException(env, &e, method_name);
   1357     } catch (...) {
   1358         throwJavaException(env, 0, method_name);
   1359     }
   1360 
   1361     return 0;
   1362 }
   1363 
   1364 
   1365 
   1366 //
   1367 //  Mat Mat::operator =(Scalar s)
   1368 //
   1369 
   1370 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDD
   1371   (JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3);
   1372 
   1373 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDD
   1374   (JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3)
   1375 {
   1376     static const char method_name[] = "Mat::n_1setTo__JDDDD()";
   1377     try {
   1378         LOGD("%s", method_name);
   1379         Mat* me = (Mat*) self; //TODO: check for NULL
   1380         Scalar s(s_val0, s_val1, s_val2, s_val3);
   1381         Mat _retval_ = me->operator =( s );
   1382         return (jlong) new Mat(_retval_);
   1383     } catch(const std::exception &e) {
   1384         throwJavaException(env, &e, method_name);
   1385     } catch (...) {
   1386         throwJavaException(env, 0, method_name);
   1387     }
   1388 
   1389     return 0;
   1390 }
   1391 
   1392 
   1393 
   1394 //
   1395 //  Mat Mat::setTo(Scalar value, Mat mask = Mat())
   1396 //
   1397 
   1398 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDDJ
   1399   (JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3, jlong mask_nativeObj);
   1400 
   1401 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JDDDDJ
   1402   (JNIEnv* env, jclass, jlong self, jdouble s_val0, jdouble s_val1, jdouble s_val2, jdouble s_val3, jlong mask_nativeObj)
   1403 {
   1404     static const char method_name[] = "Mat::n_1setTo__JDDDDJ()";
   1405     try {
   1406         LOGD("%s", method_name);
   1407         Mat* me = (Mat*) self; //TODO: check for NULL
   1408         Scalar s(s_val0, s_val1, s_val2, s_val3);
   1409         Mat& mask = *((Mat*)mask_nativeObj);
   1410         Mat _retval_ = me->setTo( s, mask );
   1411         return (jlong) new Mat(_retval_);
   1412     } catch(const std::exception &e) {
   1413         throwJavaException(env, &e, method_name);
   1414     } catch (...) {
   1415         throwJavaException(env, 0, method_name);
   1416     }
   1417 
   1418     return 0;
   1419 }
   1420 
   1421 
   1422 
   1423 //
   1424 //  Mat Mat::setTo(Mat value, Mat mask = Mat())
   1425 //
   1426 
   1427 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJJ
   1428   (JNIEnv* env, jclass, jlong self, jlong value_nativeObj, jlong mask_nativeObj);
   1429 
   1430 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJJ
   1431   (JNIEnv* env, jclass, jlong self, jlong value_nativeObj, jlong mask_nativeObj)
   1432 {
   1433     static const char method_name[] = "Mat::n_1setTo__JJJ()";
   1434     try {
   1435         LOGD("%s", method_name);
   1436         Mat* me = (Mat*) self; //TODO: check for NULL
   1437         Mat& value = *((Mat*)value_nativeObj);
   1438         Mat& mask = *((Mat*)mask_nativeObj);
   1439         Mat _retval_ = me->setTo( value, mask );
   1440         return (jlong) new Mat(_retval_);
   1441     } catch(const std::exception &e) {
   1442         throwJavaException(env, &e, method_name);
   1443     } catch (...) {
   1444         throwJavaException(env, 0, method_name);
   1445     }
   1446 
   1447     return 0;
   1448 }
   1449 
   1450 
   1451 
   1452 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJ
   1453   (JNIEnv* env, jclass, jlong self, jlong value_nativeObj);
   1454 
   1455 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1setTo__JJ
   1456   (JNIEnv* env, jclass, jlong self, jlong value_nativeObj)
   1457 {
   1458     static const char method_name[] = "Mat::n_1setTo__JJ()";
   1459     try {
   1460         LOGD("%s", method_name);
   1461         Mat* me = (Mat*) self; //TODO: check for NULL
   1462         Mat& value = *((Mat*)value_nativeObj);
   1463         Mat _retval_ = me->setTo( value );
   1464         return (jlong) new Mat(_retval_);
   1465     } catch(const std::exception &e) {
   1466         throwJavaException(env, &e, method_name);
   1467     } catch (...) {
   1468         throwJavaException(env, 0, method_name);
   1469     }
   1470 
   1471     return 0;
   1472 }
   1473 
   1474 
   1475 
   1476 //
   1477 //  Size Mat::size()
   1478 //
   1479 
   1480 JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_n_1size
   1481   (JNIEnv* env, jclass, jlong self);
   1482 
   1483 JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_n_1size
   1484   (JNIEnv* env, jclass, jlong self)
   1485 {
   1486     static const char method_name[] = "Mat::n_1size()";
   1487     try {
   1488         LOGD("%s", method_name);
   1489         Mat* me = (Mat*) self; //TODO: check for NULL
   1490         Size _retval_ = me->size(  );
   1491         jdoubleArray _da_retval_ = env->NewDoubleArray(2);
   1492         jdouble _tmp_retval_[2] = {_retval_.width, _retval_.height};
   1493         env->SetDoubleArrayRegion(_da_retval_, 0, 2, _tmp_retval_);
   1494         return _da_retval_;
   1495     } catch(const std::exception &e) {
   1496         throwJavaException(env, &e, method_name);
   1497     } catch (...) {
   1498         throwJavaException(env, 0, method_name);
   1499     }
   1500 
   1501     return 0;
   1502 }
   1503 
   1504 
   1505 
   1506 //
   1507 //  size_t Mat::step1(int i = 0)
   1508 //
   1509 
   1510 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__JI
   1511   (JNIEnv* env, jclass, jlong self, jint i);
   1512 
   1513 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__JI
   1514   (JNIEnv* env, jclass, jlong self, jint i)
   1515 {
   1516     static const char method_name[] = "Mat::n_1step1__JI()";
   1517     try {
   1518         LOGD("%s", method_name);
   1519         Mat* me = (Mat*) self; //TODO: check for NULL
   1520         return me->step1( i );
   1521     } catch(const std::exception &e) {
   1522         throwJavaException(env, &e, method_name);
   1523     } catch (...) {
   1524         throwJavaException(env, 0, method_name);
   1525     }
   1526 
   1527     return 0;
   1528 }
   1529 
   1530 
   1531 
   1532 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__J
   1533   (JNIEnv* env, jclass, jlong self);
   1534 
   1535 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1step1__J
   1536   (JNIEnv* env, jclass, jlong self)
   1537 {
   1538     static const char method_name[] = "Mat::n_1step1__J()";
   1539     try {
   1540         LOGD("%s", method_name);
   1541         Mat* me = (Mat*) self; //TODO: check for NULL
   1542         return me->step1(  );
   1543     } catch(const std::exception &e) {
   1544         throwJavaException(env, &e, method_name);
   1545     } catch (...) {
   1546         throwJavaException(env, 0, method_name);
   1547     }
   1548 
   1549     return 0;
   1550 }
   1551 
   1552 //
   1553 //  Mat Mat::operator()(Range rowRange, Range colRange)
   1554 //
   1555 
   1556 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat_1rr
   1557   (JNIEnv* env, jclass, jlong self, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end);
   1558 
   1559 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat_1rr
   1560   (JNIEnv* env, jclass, jlong self, jint rowRange_start, jint rowRange_end, jint colRange_start, jint colRange_end)
   1561 {
   1562     static const char method_name[] = "Mat::n_1submat_1rr()";
   1563     try {
   1564         LOGD("%s", method_name);
   1565         Mat* me = (Mat*) self; //TODO: check for NULL
   1566         Range rowRange(rowRange_start, rowRange_end);
   1567         Range colRange(colRange_start, colRange_end);
   1568         Mat _retval_ = me->operator()( rowRange, colRange );
   1569         return (jlong) new Mat(_retval_);
   1570     } catch(const std::exception &e) {
   1571         throwJavaException(env, &e, method_name);
   1572     } catch (...) {
   1573         throwJavaException(env, 0, method_name);
   1574     }
   1575 
   1576     return 0;
   1577 }
   1578 
   1579 
   1580 
   1581 //
   1582 //  Mat Mat::operator()(Rect roi)
   1583 //
   1584 
   1585 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat
   1586   (JNIEnv* env, jclass, jlong self, jint roi_x, jint roi_y, jint roi_width, jint roi_height);
   1587 
   1588 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1submat
   1589   (JNIEnv* env, jclass, jlong self, jint roi_x, jint roi_y, jint roi_width, jint roi_height)
   1590 {
   1591     static const char method_name[] = "Mat::n_1submat()";
   1592     try {
   1593         LOGD("%s", method_name);
   1594         Mat* me = (Mat*) self; //TODO: check for NULL
   1595         Rect roi(roi_x, roi_y, roi_width, roi_height);
   1596         Mat _retval_ = me->operator()( roi );
   1597         return (jlong) new Mat(_retval_);
   1598     } catch(const std::exception &e) {
   1599         throwJavaException(env, &e, method_name);
   1600     } catch (...) {
   1601         throwJavaException(env, 0, method_name);
   1602     }
   1603 
   1604     return 0;
   1605 }
   1606 
   1607 
   1608 
   1609 //
   1610 //  Mat Mat::t()
   1611 //
   1612 
   1613 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1t
   1614   (JNIEnv* env, jclass, jlong self);
   1615 
   1616 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1t
   1617   (JNIEnv* env, jclass, jlong self)
   1618 {
   1619     static const char method_name[] = "Mat::n_1t()";
   1620     try {
   1621         LOGD("%s", method_name);
   1622         Mat* me = (Mat*) self; //TODO: check for NULL
   1623         Mat _retval_ = me->t(  );
   1624         return (jlong) new Mat(_retval_);
   1625     } catch(const std::exception &e) {
   1626         throwJavaException(env, &e, method_name);
   1627     } catch (...) {
   1628         throwJavaException(env, 0, method_name);
   1629     }
   1630 
   1631     return 0;
   1632 }
   1633 
   1634 
   1635 
   1636 //
   1637 //  size_t Mat::total()
   1638 //
   1639 
   1640 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1total
   1641   (JNIEnv* env, jclass, jlong self);
   1642 
   1643 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1total
   1644   (JNIEnv* env, jclass, jlong self)
   1645 {
   1646     static const char method_name[] = "Mat::n_1total()";
   1647     try {
   1648         LOGD("%s", method_name);
   1649         Mat* me = (Mat*) self; //TODO: check for NULL
   1650         return me->total(  );
   1651     } catch(const std::exception &e) {
   1652         throwJavaException(env, &e, method_name);
   1653     } catch (...) {
   1654         throwJavaException(env, 0, method_name);
   1655     }
   1656 
   1657     return 0;
   1658 }
   1659 
   1660 
   1661 
   1662 //
   1663 //  int Mat::type()
   1664 //
   1665 
   1666 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1type
   1667   (JNIEnv* env, jclass, jlong self);
   1668 
   1669 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1type
   1670   (JNIEnv* env, jclass, jlong self)
   1671 {
   1672     static const char method_name[] = "Mat::n_1type()";
   1673     try {
   1674         LOGD("%s", method_name);
   1675         Mat* me = (Mat*) self; //TODO: check for NULL
   1676         return me->type(  );
   1677     } catch(const std::exception &e) {
   1678         throwJavaException(env, &e, method_name);
   1679     } catch (...) {
   1680         throwJavaException(env, 0, method_name);
   1681     }
   1682 
   1683     return 0;
   1684 }
   1685 
   1686 
   1687 
   1688 //
   1689 // static Mat Mat::zeros(int rows, int cols, int type)
   1690 //
   1691 
   1692 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__III
   1693   (JNIEnv* env, jclass, jint rows, jint cols, jint type);
   1694 
   1695 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__III
   1696   (JNIEnv* env, jclass, jint rows, jint cols, jint type)
   1697 {
   1698     static const char method_name[] = "Mat::n_1zeros__III()";
   1699     try {
   1700         LOGD("%s", method_name);
   1701         Mat _retval_ = Mat::zeros( rows, cols, type );
   1702         return (jlong) new Mat(_retval_);
   1703     } catch(const std::exception &e) {
   1704         throwJavaException(env, &e, method_name);
   1705     } catch (...) {
   1706         throwJavaException(env, 0, method_name);
   1707     }
   1708 
   1709     return 0;
   1710 }
   1711 
   1712 
   1713 
   1714 //
   1715 // static Mat Mat::zeros(Size size, int type)
   1716 //
   1717 
   1718 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__DDI
   1719   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type);
   1720 
   1721 JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__DDI
   1722   (JNIEnv* env, jclass, jdouble size_width, jdouble size_height, jint type)
   1723 {
   1724     static const char method_name[] = "Mat::n_1zeros__DDI()";
   1725     try {
   1726         LOGD("%s", method_name);
   1727         Size size((int)size_width, (int)size_height);
   1728         Mat _retval_ = Mat::zeros( size, type );
   1729         return (jlong) new Mat(_retval_);
   1730     } catch(const std::exception &e) {
   1731         throwJavaException(env, &e, method_name);
   1732     } catch (...) {
   1733         throwJavaException(env, 0, method_name);
   1734     }
   1735 
   1736     return 0;
   1737 }
   1738 
   1739 
   1740 
   1741 //
   1742 //  native support for java finalize()
   1743 //  static void Mat::n_delete( __int64 self )
   1744 //
   1745 
   1746 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1delete
   1747   (JNIEnv*, jclass, jlong self);
   1748 
   1749 JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1delete
   1750   (JNIEnv*, jclass, jlong self)
   1751 {
   1752     delete (Mat*) self;
   1753 }
   1754 
   1755 // unlike other nPut()-s this one (with double[]) should convert input values to correct type
   1756 #define PUT_ITEM(T, R, C) { T*dst = (T*)me->ptr(R, C); for(int ch=0; ch<me->channels() && count>0; count--,ch++,src++,dst++) *dst = cv::saturate_cast<T>(*src); }
   1757 
   1758 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
   1759     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals);
   1760 
   1761 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutD
   1762     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals)
   1763 {
   1764     static const char method_name[] = "Mat::nPutD()";
   1765     try {
   1766         LOGD("%s", method_name);
   1767         cv::Mat* me = (cv::Mat*) self;
   1768         if(!me || !me->data) return 0;  // no native object behind
   1769         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   1770 
   1771         int rest = ((me->rows - row) * me->cols - col) * me->channels();
   1772         if(count>rest) count = rest;
   1773         int res = count;
   1774         double* values = (double*)env->GetPrimitiveArrayCritical(vals, 0);
   1775         double* src = values;
   1776         int r, c;
   1777         for(c=col; c<me->cols && count>0; c++)
   1778         {
   1779             switch(me->depth()) {
   1780                 case CV_8U:  PUT_ITEM(uchar,  row, c); break;
   1781                 case CV_8S:  PUT_ITEM(schar,  row, c); break;
   1782                 case CV_16U: PUT_ITEM(ushort, row, c); break;
   1783                 case CV_16S: PUT_ITEM(short,  row, c); break;
   1784                 case CV_32S: PUT_ITEM(int,    row, c); break;
   1785                 case CV_32F: PUT_ITEM(float,  row, c); break;
   1786                 case CV_64F: PUT_ITEM(double, row, c); break;
   1787             }
   1788         }
   1789 
   1790         for(r=row+1; r<me->rows && count>0; r++)
   1791             for(c=0; c<me->cols && count>0; c++)
   1792             {
   1793                 switch(me->depth()) {
   1794                     case CV_8U:  PUT_ITEM(uchar,  r, c); break;
   1795                     case CV_8S:  PUT_ITEM(schar,  r, c); break;
   1796                     case CV_16U: PUT_ITEM(ushort, r, c); break;
   1797                     case CV_16S: PUT_ITEM(short,  r, c); break;
   1798                     case CV_32S: PUT_ITEM(int,    r, c); break;
   1799                     case CV_32F: PUT_ITEM(float,  r, c); break;
   1800                     case CV_64F: PUT_ITEM(double, r, c); break;
   1801                 }
   1802             }
   1803 
   1804         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   1805         return res;
   1806     } catch(const std::exception &e) {
   1807         throwJavaException(env, &e, method_name);
   1808     } catch (...) {
   1809         throwJavaException(env, 0, method_name);
   1810     }
   1811 
   1812     return 0;
   1813 }
   1814 
   1815 
   1816 } // extern "C"
   1817 
   1818 template<typename T> static int mat_put(cv::Mat* m, int row, int col, int count, char* buff)
   1819 {
   1820     if(! m) return 0;
   1821     if(! buff) return 0;
   1822 
   1823     count *= sizeof(T);
   1824     int rest = ((m->rows - row) * m->cols - col) * (int)m->elemSize();
   1825     if(count>rest) count = rest;
   1826     int res = count;
   1827 
   1828     if( m->isContinuous() )
   1829     {
   1830         memcpy(m->ptr(row, col), buff, count);
   1831     } else {
   1832         // row by row
   1833         int num = (m->cols - col) * (int)m->elemSize(); // 1st partial row
   1834         if(count<num) num = count;
   1835         uchar* data = m->ptr(row++, col);
   1836         while(count>0){
   1837             memcpy(data, buff, num);
   1838             count -= num;
   1839             buff += num;
   1840             num = m->cols * (int)m->elemSize();
   1841             if(count<num) num = count;
   1842             data = m->ptr(row++, 0);
   1843         }
   1844     }
   1845     return res;
   1846 }
   1847 
   1848 
   1849 extern "C" {
   1850 
   1851 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutB
   1852     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals);
   1853 
   1854 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutB
   1855     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals)
   1856 {
   1857     static const char method_name[] = "Mat::nPutB()";
   1858     try {
   1859         LOGD("%s", method_name);
   1860         cv::Mat* me = (cv::Mat*) self;
   1861         if(! self) return 0; // no native object behind
   1862         if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
   1863         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   1864 
   1865         char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
   1866         int res = mat_put<char>(me, row, col, count, values);
   1867         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   1868         return res;
   1869     } catch(const std::exception &e) {
   1870         throwJavaException(env, &e, method_name);
   1871     } catch (...) {
   1872         throwJavaException(env, 0, method_name);
   1873     }
   1874 
   1875     return 0;
   1876 }
   1877 
   1878 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutS
   1879     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals);
   1880 
   1881 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutS
   1882     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals)
   1883 {
   1884     static const char method_name[] = "Mat::nPutS()";
   1885     try {
   1886         LOGD("%s", method_name);
   1887         cv::Mat* me = (cv::Mat*) self;
   1888         if(! self) return 0; // no native object behind
   1889         if(me->depth() != CV_16U && me->depth() != CV_16S) return 0; // incompatible type
   1890         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   1891 
   1892         char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
   1893         int res = mat_put<short>(me, row, col, count, values);
   1894         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   1895         return res;
   1896     } catch(const std::exception &e) {
   1897         throwJavaException(env, &e, method_name);
   1898     } catch (...) {
   1899         throwJavaException(env, 0, method_name);
   1900     }
   1901 
   1902     return 0;
   1903 }
   1904 
   1905 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutI
   1906     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals);
   1907 
   1908 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutI
   1909     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals)
   1910 {
   1911     static const char method_name[] = "Mat::nPutI()";
   1912     try {
   1913         LOGD("%s", method_name);
   1914         cv::Mat* me = (cv::Mat*) self;
   1915         if(! self) return 0; // no native object behind
   1916         if(me->depth() != CV_32S) return 0; // incompatible type
   1917         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   1918 
   1919         char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
   1920         int res = mat_put<int>(me, row, col, count, values);
   1921         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   1922         return res;
   1923     } catch(const std::exception &e) {
   1924         throwJavaException(env, &e, method_name);
   1925     } catch (...) {
   1926         throwJavaException(env, 0, method_name);
   1927     }
   1928 
   1929     return 0;
   1930 }
   1931 
   1932 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutF
   1933     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals);
   1934 
   1935 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nPutF
   1936     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals)
   1937 {
   1938     static const char method_name[] = "Mat::nPutF()";
   1939     try {
   1940         LOGD("%s", method_name);
   1941         cv::Mat* me = (cv::Mat*) self;
   1942         if(! self) return 0; // no native object behind
   1943         if(me->depth() != CV_32F) return 0; // incompatible type
   1944         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   1945 
   1946         char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
   1947         int res = mat_put<float>(me, row, col, count, values);
   1948         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   1949         return res;
   1950     } catch(const std::exception &e) {
   1951         throwJavaException(env, &e, method_name);
   1952     } catch (...) {
   1953         throwJavaException(env, 0, method_name);
   1954     }
   1955 
   1956     return 0;
   1957 }
   1958 
   1959 
   1960 } // extern "C"
   1961 
   1962 template<typename T> int mat_get(cv::Mat* m, int row, int col, int count, char* buff)
   1963 {
   1964     if(! m) return 0;
   1965     if(! buff) return 0;
   1966 
   1967     int bytesToCopy = count * sizeof(T);
   1968     int bytesRestInMat = ((m->rows - row) * m->cols - col) * (int)m->elemSize();
   1969     if(bytesToCopy > bytesRestInMat) bytesToCopy = bytesRestInMat;
   1970     int res = bytesToCopy;
   1971 
   1972     if( m->isContinuous() )
   1973     {
   1974         memcpy(buff, m->ptr(row, col), bytesToCopy);
   1975     } else {
   1976         // row by row
   1977         int bytesInRow = (m->cols - col) * (int)m->elemSize(); // 1st partial row
   1978         while(bytesToCopy > 0)
   1979         {
   1980             int len = std::min(bytesToCopy, bytesInRow);
   1981             memcpy(buff, m->ptr(row, col), len);
   1982             bytesToCopy -= len;
   1983             buff += len;
   1984             row++;
   1985             col = 0;
   1986             bytesInRow = m->cols * (int)m->elemSize();
   1987         }
   1988     }
   1989     return res;
   1990 }
   1991 
   1992 extern "C" {
   1993 
   1994 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetB
   1995     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals);
   1996 
   1997 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetB
   1998     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jbyteArray vals)
   1999 {
   2000     static const char method_name[] = "Mat::nGetB()";
   2001     try {
   2002         LOGD("%s", method_name);
   2003         cv::Mat* me = (cv::Mat*) self;
   2004         if(! self) return 0; // no native object behind
   2005         if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type
   2006         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   2007 
   2008         char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
   2009         int res = mat_get<char>(me, row, col, count, values);
   2010         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   2011         return res;
   2012     } catch(const std::exception &e) {
   2013         throwJavaException(env, &e, method_name);
   2014     } catch (...) {
   2015         throwJavaException(env, 0, method_name);
   2016     }
   2017 
   2018     return 0;
   2019 }
   2020 
   2021 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetS
   2022     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals);
   2023 
   2024 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetS
   2025     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jshortArray vals)
   2026 {
   2027     static const char method_name[] = "Mat::nGetS()";
   2028     try {
   2029         LOGD("%s", method_name);
   2030         cv::Mat* me = (cv::Mat*) self;
   2031         if(! self) return 0; // no native object behind
   2032         if(me->depth() != CV_16U && me->depth() != CV_16S) return 0; // incompatible type
   2033         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   2034 
   2035         char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
   2036         int res = mat_get<short>(me, row, col, count, values);
   2037         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   2038         return res;
   2039     } catch(const std::exception &e) {
   2040         throwJavaException(env, &e, method_name);
   2041     } catch (...) {
   2042         throwJavaException(env, 0, method_name);
   2043     }
   2044 
   2045     return 0;
   2046 }
   2047 
   2048 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetI
   2049     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals);
   2050 
   2051 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetI
   2052     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jintArray vals)
   2053 {
   2054     static const char method_name[] = "Mat::nGetI()";
   2055     try {
   2056         LOGD("%s", method_name);
   2057         cv::Mat* me = (cv::Mat*) self;
   2058         if(! self) return 0; // no native object behind
   2059         if(me->depth() != CV_32S) return 0; // incompatible type
   2060         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   2061 
   2062         char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
   2063         int res = mat_get<int>(me, row, col, count, values);
   2064         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   2065         return res;
   2066     } catch(const std::exception &e) {
   2067         throwJavaException(env, &e, method_name);
   2068     } catch (...) {
   2069         throwJavaException(env, 0, method_name);
   2070     }
   2071 
   2072     return 0;
   2073 }
   2074 
   2075 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetF
   2076     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals);
   2077 
   2078 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetF
   2079     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jfloatArray vals)
   2080 {
   2081     static const char method_name[] = "Mat::nGetF()";
   2082     try {
   2083         LOGD("%s", method_name);
   2084         cv::Mat* me = (cv::Mat*) self;
   2085         if(! self) return 0; // no native object behind
   2086         if(me->depth() != CV_32F) return 0; // incompatible type
   2087         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   2088 
   2089         char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
   2090         int res = mat_get<float>(me, row, col, count, values);
   2091         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   2092         return res;
   2093     } catch(const std::exception &e) {
   2094         throwJavaException(env, &e, method_name);
   2095     } catch (...) {
   2096         throwJavaException(env, 0, method_name);
   2097     }
   2098 
   2099     return 0;
   2100 }
   2101 
   2102 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetD
   2103     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals);
   2104 
   2105 JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_nGetD
   2106     (JNIEnv* env, jclass, jlong self, jint row, jint col, jint count, jdoubleArray vals)
   2107 {
   2108     static const char method_name[] = "Mat::nGetD()";
   2109     try {
   2110         LOGD("%s", method_name);
   2111         cv::Mat* me = (cv::Mat*) self;
   2112         if(! self) return 0; // no native object behind
   2113         if(me->depth() != CV_64F) return 0; // incompatible type
   2114         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   2115 
   2116         char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);
   2117         int res = mat_get<double>(me, row, col, count, values);
   2118         env->ReleasePrimitiveArrayCritical(vals, values, 0);
   2119         return res;
   2120     } catch(const std::exception &e) {
   2121         throwJavaException(env, &e, method_name);
   2122     } catch (...) {
   2123         throwJavaException(env, 0, method_name);
   2124     }
   2125 
   2126     return 0;
   2127 }
   2128 
   2129 JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nGet
   2130     (JNIEnv* env, jclass, jlong self, jint row, jint col);
   2131 
   2132 JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Mat_nGet
   2133     (JNIEnv* env, jclass, jlong self, jint row, jint col)
   2134 {
   2135     static const char method_name[] = "Mat::nGet()";
   2136     try {
   2137         LOGD("%s", method_name);
   2138         cv::Mat* me = (cv::Mat*) self;
   2139         if(! self) return 0; // no native object behind
   2140         if(me->rows<=row || me->cols<=col) return 0; // indexes out of range
   2141 
   2142         jdoubleArray res = env->NewDoubleArray(me->channels());
   2143         if(res){
   2144             jdouble buff[CV_CN_MAX];//me->channels()
   2145             int i;
   2146             switch(me->depth()){
   2147                 case CV_8U:  for(i=0; i<me->channels(); i++) buff[i] = *((unsigned char*) me->ptr(row, col) + i); break;
   2148                 case CV_8S:  for(i=0; i<me->channels(); i++) buff[i] = *((signed char*)   me->ptr(row, col) + i); break;
   2149                 case CV_16U: for(i=0; i<me->channels(); i++) buff[i] = *((unsigned short*)me->ptr(row, col) + i); break;
   2150                 case CV_16S: for(i=0; i<me->channels(); i++) buff[i] = *((signed short*)  me->ptr(row, col) + i); break;
   2151                 case CV_32S: for(i=0; i<me->channels(); i++) buff[i] = *((int*)           me->ptr(row, col) + i); break;
   2152                 case CV_32F: for(i=0; i<me->channels(); i++) buff[i] = *((float*)         me->ptr(row, col) + i); break;
   2153                 case CV_64F: for(i=0; i<me->channels(); i++) buff[i] = *((double*)        me->ptr(row, col) + i); break;
   2154             }
   2155             env->SetDoubleArrayRegion(res, 0, me->channels(), buff);
   2156         }
   2157         return res;
   2158     } catch(const std::exception &e) {
   2159         throwJavaException(env, &e, method_name);
   2160     } catch (...) {
   2161         throwJavaException(env, 0, method_name);
   2162     }
   2163 
   2164     return 0;
   2165 }
   2166 
   2167 JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump
   2168   (JNIEnv *env, jclass, jlong self);
   2169 
   2170 JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump
   2171   (JNIEnv *env, jclass, jlong self)
   2172 {
   2173     static const char method_name[] = "Mat::nDump()";
   2174     try {
   2175         LOGD("%s", method_name);
   2176         cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL
   2177         String s;
   2178         Ptr<Formatted> fmtd = Formatter::get()->format(*me);
   2179         for(const char* str = fmtd->next(); str; str = fmtd->next())
   2180         {
   2181             s = s + String(str);
   2182         }
   2183         return env->NewStringUTF(s.c_str());
   2184     } catch(const std::exception &e) {
   2185         throwJavaException(env, &e, method_name);
   2186     } catch (...) {
   2187         throwJavaException(env, 0, method_name);
   2188     }
   2189 
   2190     return 0;
   2191 }
   2192 
   2193 
   2194 } // extern "C"
   2195