From 2985c713e66e51e19034cd9e595f0192abacbc2c Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 28 Sep 2010 09:10:25 +0000 Subject: [PATCH] fixed short and float reading/writing in gpu::cvtColor --- modules/gpu/src/cuda/color.cu | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/modules/gpu/src/cuda/color.cu b/modules/gpu/src/cuda/color.cu index d8c03aa30d..274bb67c09 100644 --- a/modules/gpu/src/cuda/color.cu +++ b/modules/gpu/src/cuda/color.cu @@ -52,35 +52,26 @@ using namespace cv::gpu; namespace imgproc { template struct TypeVec {}; - template<> struct TypeVec { typedef uchar1 vec_t; }; - template<> struct TypeVec { typedef uchar2 vec_t; }; template<> struct TypeVec { typedef uchar3 vec_t; }; template<> struct TypeVec { typedef uchar4 vec_t; }; - template<> struct TypeVec { typedef ushort1 vec_t; }; - template<> struct TypeVec { typedef ushort2 vec_t; }; template<> struct TypeVec { typedef ushort3 vec_t; }; template<> struct TypeVec { typedef ushort4 vec_t; }; - template<> struct TypeVec { typedef float1 vec_t; }; - template<> struct TypeVec { typedef float2 vec_t; }; template<> struct TypeVec { typedef float3 vec_t; }; template<> struct TypeVec { typedef float4 vec_t; }; template struct ColorChannel {}; - template<> struct ColorChannel { typedef float worktype_f; static __device__ unsigned char max() { return UCHAR_MAX; } static __device__ unsigned char half() { return (unsigned char)(max()/2 + 1); } }; - template<> struct ColorChannel { typedef float worktype_f; static __device__ unsigned short max() { return USHRT_MAX; } static __device__ unsigned short half() { return (unsigned short)(max()/2 + 1); } }; - template<> struct ColorChannel { typedef float worktype_f; @@ -124,7 +115,7 @@ namespace imgproc if (y < rows && x < cols) { - src_t src = *(const src_t*)(src_ + y * src_step + x * SRCCN); + src_t src = *(const src_t*)(src_ + y * src_step + x * SRCCN * sizeof(T)); dst_t dst; dst.x = ((const T*)(&src))[bidx]; @@ -132,7 +123,7 @@ namespace imgproc dst.z = ((const T*)(&src))[bidx ^ 2]; setAlpha(dst, getAlpha(src)); - *(dst_t*)(dst_ + y * dst_step + x * DSTCN) = dst; + *(dst_t*)(dst_ + y * dst_step + x * DSTCN * sizeof(T)) = dst; } } } @@ -817,12 +808,12 @@ namespace imgproc if (y < rows && x < cols) { - src_t src = *(const src_t*)(src_ + y * src_step + x * SRCCN); + src_t src = *(const src_t*)(src_ + y * src_step + x * SRCCN * sizeof(T)); dst_t dst; RGB2YCrCbConverter::cvt(((const T*)(&src)), dst, bidx); - *(dst_t*)(dst_ + y * dst_step + x * 3) = dst; + *(dst_t*)(dst_ + y * dst_step + x * 3 * sizeof(T)) = dst; } } @@ -865,13 +856,13 @@ namespace imgproc if (y < rows && x < cols) { - src_t src = *(const src_t*)(src_ + y * src_step + x * 3); + src_t src = *(const src_t*)(src_ + y * src_step + x * 3 * sizeof(T)); dst_t dst; YCrCb2RGBConvertor::cvt(src, ((T*)(&dst)), bidx); setAlpha(dst, ColorChannel::max()); - *(dst_t*)(dst_ + y * dst_step + x * DSTCN) = dst; + *(dst_t*)(dst_ + y * dst_step + x * DSTCN * sizeof(T)) = dst; } } }