fixed bug in cv::LUT (multi-channel source array and single-channel table)
authorVladislav Vinogradov <no@email>
Tue, 10 May 2011 06:11:03 +0000 (06:11 +0000)
committerVladislav Vinogradov <no@email>
Tue, 10 May 2011 06:11:03 +0000 (06:11 +0000)
added missing cudaSafeCall

modules/core/src/convert.cpp
modules/gpu/src/matrix_operations.cpp

index f7da74b..dcc89e8 100644 (file)
@@ -930,11 +930,11 @@ namespace cv
 {
 
 template<typename T> static void
-LUT8u_( const uchar* src, const T* lut, T* dst, int len, int cn )
+LUT8u_( const uchar* src, const T* lut, T* dst, int len, int cn, int lutcn )
 {
-    if( cn == 1 )
+    if( lutcn == 1 )
     {
-        for( int i = 0; i < len; i++ )
+        for( int i = 0; i < len*cn; i++ )
             dst[i] = lut[src[i]];
     }
     else
@@ -945,42 +945,42 @@ LUT8u_( const uchar* src, const T* lut, T* dst, int len, int cn )
     }
 }
 
-static void LUT8u_8u( const uchar* src, const uchar* lut, uchar* dst, int len, int cn )
+static void LUT8u_8u( const uchar* src, const uchar* lut, uchar* dst, int len, int cn, int lutcn )
 {
-    LUT8u_( src, lut, dst, len, cn );
+    LUT8u_( src, lut, dst, len, cn, lutcn );
 }
 
-static void LUT8u_8s( const uchar* src, const schar* lut, schar* dst, int len, int cn )
+static void LUT8u_8s( const uchar* src, const schar* lut, schar* dst, int len, int cn, int lutcn )
 {
-    LUT8u_( src, lut, dst, len, cn );
+    LUT8u_( src, lut, dst, len, cn, lutcn );
 }
 
-static void LUT8u_16u( const uchar* src, const ushort* lut, ushort* dst, int len, int cn )
+static void LUT8u_16u( const uchar* src, const ushort* lut, ushort* dst, int len, int cn, int lutcn )
 {
-    LUT8u_( src, lut, dst, len, cn );
+    LUT8u_( src, lut, dst, len, cn, lutcn );
 }
 
-static void LUT8u_16s( const uchar* src, const short* lut, short* dst, int len, int cn )
+static void LUT8u_16s( const uchar* src, const short* lut, short* dst, int len, int cn, int lutcn )
 {
-    LUT8u_( src, lut, dst, len, cn );
+    LUT8u_( src, lut, dst, len, cn, lutcn );
 }
 
-static void LUT8u_32s( const uchar* src, const int* lut, int* dst, int len, int cn )
+static void LUT8u_32s( const uchar* src, const int* lut, int* dst, int len, int cn, int lutcn )
 {
-    LUT8u_( src, lut, dst, len, cn );
+    LUT8u_( src, lut, dst, len, cn, lutcn );
 }
 
-static void LUT8u_32f( const uchar* src, const float* lut, float* dst, int len, int cn )
+static void LUT8u_32f( const uchar* src, const float* lut, float* dst, int len, int cn, int lutcn )
 {
-    LUT8u_( src, lut, dst, len, cn );
+    LUT8u_( src, lut, dst, len, cn, lutcn );
 }
 
-static void LUT8u_64f( const uchar* src, const double* lut, double* dst, int len, int cn )
+static void LUT8u_64f( const uchar* src, const double* lut, double* dst, int len, int cn, int lutcn )
 {
-    LUT8u_( src, lut, dst, len, cn );
+    LUT8u_( src, lut, dst, len, cn, lutcn );
 }    
     
-typedef void (*LUTFunc)( const uchar* src, const uchar* lut, uchar* dst, int len, int cn );
+typedef void (*LUTFunc)( const uchar* src, const uchar* lut, uchar* dst, int len, int cn, int lutcn );
     
 static LUTFunc lutTab[] =
 {
@@ -995,8 +995,9 @@ void cv::LUT( const InputArray& _src, const InputArray& _lut, OutputArray _dst,
     Mat src = _src.getMat(), lut = _lut.getMat();
     CV_Assert( interpolation == 0 );
     int cn = src.channels();
+    int lutcn = lut.channels();
 
-    CV_Assert( (lut.channels() == cn || lut.channels() == 1) &&
+    CV_Assert( (lutcn == cn || lutcn == 1) &&
         lut.total() == 256 && lut.isContinuous() &&
         (src.depth() == CV_8U || src.depth() == CV_8S) );
     _dst.create( src.dims, src.size, CV_MAKETYPE(lut.depth(), cn));
@@ -1011,7 +1012,7 @@ void cv::LUT( const InputArray& _src, const InputArray& _lut, OutputArray _dst,
     int len = (int)it.size;
     
     for( size_t i = 0; i < it.nplanes; i++, ++it )
-        func(ptrs[0], lut.data, ptrs[1], len, cn);
+        func(ptrs[0], lut.data, ptrs[1], len, cn, lutcn);
 }
 
 
index 2a79167..6467ee7 100644 (file)
@@ -590,7 +590,7 @@ void cv::gpu::ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m)
 bool cv::gpu::CudaMem::canMapHostMemory()\r
 {\r
     cudaDeviceProp prop;\r
-    cudaGetDeviceProperties(&prop, getDevice());\r
+    cudaSafeCall( cudaGetDeviceProperties(&prop, getDevice()) );\r
     return (prop.canMapHostMemory != 0) ? true : false;\r
 }\r
 \r
@@ -625,7 +625,7 @@ void cv::gpu::CudaMem::create(int _rows, int _cols, int _type, int _alloc_type)
         if (_alloc_type == ALLOC_ZEROCOPY)\r
         {\r
             cudaDeviceProp prop;\r
-            cudaGetDeviceProperties(&prop, getDevice());\r
+            cudaSafeCall( cudaGetDeviceProperties(&prop, getDevice()) );\r
             step = alignUp(step, prop.textureAlignment);\r
         }\r
         int64 _nettosize = (int64)step*rows;\r