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