Java API: fix in Mat::put methods, general improvements
authorAndrey Pavlenko <no@email>
Mon, 18 Jul 2011 07:18:35 +0000 (07:18 +0000)
committerAndrey Pavlenko <no@email>
Mon, 18 Jul 2011 07:18:35 +0000 (07:18 +0000)
modules/java/src/cpp/Mat.cpp

index 0f860b4..9ffab28 100644 (file)
@@ -79,11 +79,12 @@ JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nClone
 \r
 // unlike other nPut()-s this one (with double[]) should convert input values to correct type\r
 #define PUT_ITEM(T, R, C) for(int ch=0; ch<me->channels() && count>0; ch++,count--) *((T*)me->ptr(R, C)+ch) = cv::saturate_cast<T>(*(src+ch))\r
+\r
 JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutD\r
        (JNIEnv* env, jclass cls, jlong self, jint row, jint col, jint count, jdoubleArray vals)\r
 {\r
        cv::Mat* me = (cv::Mat*) self;\r
-       if(! self) return 0;  // no native object behind\r
+       if(!me || !me->data) return 0;  // no native object behind\r
        if(me->rows<=row || me->cols<=col) return 0; // indexes out of range\r
 \r
        int rest = ((me->rows - row) * me->cols - col) * me->channels();\r
@@ -135,6 +136,7 @@ template<typename T> static int mat_put(cv::Mat* m, int row, int col, int count,
        if(! m) return 0;\r
        if(! buff) return 0;\r
 \r
+       count *= sizeof(T);\r
        int rest = ((m->rows - row) * m->cols - col) * m->channels() * sizeof(T);\r
        if(count>rest) count = rest;\r
        int res = count;\r
@@ -183,7 +185,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutS
 {\r
        cv::Mat* me = (cv::Mat*) self;\r
        if(! self) return 0; // no native object behind\r
-       if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type\r
+       if(me->depth() != CV_16U && me->depth() != CV_16S) return 0; // incompatible type\r
        if(me->rows<=row || me->cols<=col) return 0; // indexes out of range\r
        \r
        char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);\r
@@ -197,7 +199,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutI
 {\r
        cv::Mat* me = (cv::Mat*) self;\r
        if(! self) return 0; // no native object behind\r
-       if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type\r
+       if(me->depth() != CV_32S) return 0; // incompatible type\r
        if(me->rows<=row || me->cols<=col) return 0; // indexes out of range\r
        \r
        char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);\r
@@ -211,7 +213,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutF
 {\r
        cv::Mat* me = (cv::Mat*) self;\r
        if(! self) return 0; // no native object behind\r
-       if(me->depth() != CV_8U && me->depth() != CV_8S) return 0; // incompatible type\r
+       if(me->depth() != CV_32F) return 0; // incompatible type\r
        if(me->rows<=row || me->cols<=col) return 0; // indexes out of range\r
        \r
        char* values = (char*)env->GetPrimitiveArrayCritical(vals, 0);\r
@@ -231,7 +233,7 @@ template<typename T> int mat_get(cv::Mat* m, int row, int col, int count, char*
        if(! m) return 0;\r
        if(! buff) return 0;\r
 \r
-       count *= sizeof(T);//This change is required, checked TODO: recheck for non-continious case\r
+       count *= sizeof(T);\r
        int rest = ((m->rows - row) * m->cols - col) * m->channels() * sizeof(T);\r
        if(count>rest) count = rest;\r
        int res = count;\r