From c821cb148959a6b7203e485686eaabfc1318155a Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 15 Aug 2014 14:10:15 +0400 Subject: [PATCH] fix BGR->BGR5x5 color convertion (cherry picked from commit 62f27b28edb6406b6cf8f2c16370187ce8c24e30) --- .../gpu/device/detail/color_detail.hpp | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/modules/gpu/include/opencv2/gpu/device/detail/color_detail.hpp b/modules/gpu/include/opencv2/gpu/device/detail/color_detail.hpp index 5b422849bd..f938b90801 100644 --- a/modules/gpu/include/opencv2/gpu/device/detail/color_detail.hpp +++ b/modules/gpu/include/opencv2/gpu/device/detail/color_detail.hpp @@ -160,16 +160,12 @@ namespace cv { namespace gpu { namespace device template struct RGB2RGB5x5Converter; template struct RGB2RGB5x5Converter<6, bidx> { - static __device__ __forceinline__ ushort cvt(const uchar3& src) + template + static __device__ __forceinline__ ushort cvt(const T& src) { - return (ushort)(((&src.x)[bidx] >> 3) | ((src.y & ~3) << 3) | (((&src.x)[bidx^2] & ~7) << 8)); - } - - static __device__ __forceinline__ ushort cvt(uint src) - { - uint b = 0xffu & (src >> (bidx * 8)); - uint g = 0xffu & (src >> 8); - uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); + uint b = bidx == 0 ? src.x : src.z; + uint g = src.y; + uint r = bidx == 0 ? src.z : src.x; return (ushort)((b >> 3) | ((g & ~3) << 3) | ((r & ~7) << 8)); } }; @@ -178,22 +174,25 @@ namespace cv { namespace gpu { namespace device { static __device__ __forceinline__ ushort cvt(const uchar3& src) { - return (ushort)(((&src.x)[bidx] >> 3) | ((src.y & ~7) << 2) | (((&src.x)[bidx^2] & ~7) << 7)); + uint b = bidx == 0 ? src.x : src.z; + uint g = src.y; + uint r = bidx == 0 ? src.z : src.x; + return (ushort)((b >> 3) | ((g & ~7) << 2) | ((r & ~7) << 7)); } - static __device__ __forceinline__ ushort cvt(uint src) + static __device__ __forceinline__ ushort cvt(const uchar4& src) { - uint b = 0xffu & (src >> (bidx * 8)); - uint g = 0xffu & (src >> 8); - uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); - uint a = 0xffu & (src >> 24); + uint b = bidx == 0 ? src.x : src.z; + uint g = src.y; + uint r = bidx == 0 ? src.z : src.x; + uint a = src.w; return (ushort)((b >> 3) | ((g & ~7) << 2) | ((r & ~7) << 7) | (a * 0x8000)); } }; template struct RGB2RGB5x5; - template struct RGB2RGB5x5<3, bidx,green_bits> : unary_function + template struct RGB2RGB5x5<3, bidx, green_bits> : unary_function { __device__ __forceinline__ ushort operator()(const uchar3& src) const { @@ -204,9 +203,9 @@ namespace cv { namespace gpu { namespace device __host__ __device__ __forceinline__ RGB2RGB5x5(const RGB2RGB5x5&) {} }; - template struct RGB2RGB5x5<4, bidx,green_bits> : unary_function + template struct RGB2RGB5x5<4, bidx, green_bits> : unary_function { - __device__ __forceinline__ ushort operator()(uint src) const + __device__ __forceinline__ ushort operator()(const uchar4& src) const { return RGB2RGB5x5Converter::cvt(src); }