@@ -390,6 +390,17 @@ namespace cv { namespace cuda { namespace device
390390 //
391391 // ported to CUDA
392392
393+ template <typename Depth> __device__
394+ typename TypeVec<Depth, 3 >::vec_type make_3 (Depth x, Depth y, Depth z);
395+
396+ template <> __device__ TypeVec<uchar, 3 >::vec_type make_3<uchar>(uchar x, uchar y, uchar z) {
397+ return make_uchar3 (x, y, z);
398+ }
399+
400+ template <> __device__ TypeVec<ushort, 3 >::vec_type make_3<ushort>(ushort x, ushort y, ushort z) {
401+ return make_ushort3 (x, y, z);
402+ }
403+
393404 template <typename DstType, class Ptr2D >
394405 __global__ void MHCdemosaic (PtrStepSz<DstType> dst, Ptr2D src, const int2 firstRed)
395406 {
@@ -506,34 +517,36 @@ namespace cv { namespace cuda { namespace device
506517 alternate.x = (x + firstRed.x ) % 2 ;
507518 alternate.y = (y + firstRed.y ) % 2 ;
508519
509- // in BGR sequence;
510- uchar3 pixelColor =
520+ typedef typename VecTraits<DstType>::elem_type SrcElemType;
521+ typedef typename TypeVec<SrcElemType, 3 >::vec_type SrcType;
522+
523+ SrcType pixelColor =
511524 (alternate.y == 0 ) ?
512525 ((alternate.x == 0 ) ?
513- make_uchar3 (saturate_cast<uchar >(PATTERN.y ), saturate_cast<uchar >(PATTERN.x ), saturate_cast<uchar >(C)) :
514- make_uchar3 (saturate_cast<uchar >(PATTERN.w ), saturate_cast<uchar >(C), saturate_cast<uchar >(PATTERN.z ))) :
526+ make_3<SrcElemType> (saturate_cast<SrcElemType >(PATTERN.y ), saturate_cast<SrcElemType >(PATTERN.x ), saturate_cast<SrcElemType >(C)) :
527+ make_3<SrcElemType> (saturate_cast<SrcElemType >(PATTERN.w ), saturate_cast<SrcElemType >(C), saturate_cast<SrcElemType >(PATTERN.z ))) :
515528 ((alternate.x == 0 ) ?
516- make_uchar3 (saturate_cast<uchar >(PATTERN.z ), saturate_cast<uchar >(C), saturate_cast<uchar >(PATTERN.w )) :
517- make_uchar3 (saturate_cast<uchar >(C), saturate_cast<uchar >(PATTERN.x ), saturate_cast<uchar >(PATTERN.y )));
529+ make_3<SrcElemType> (saturate_cast<SrcElemType >(PATTERN.z ), saturate_cast<SrcElemType >(C), saturate_cast<SrcElemType >(PATTERN.w )) :
530+ make_3<SrcElemType> (saturate_cast<SrcElemType >(C), saturate_cast<SrcElemType >(PATTERN.x ), saturate_cast<SrcElemType >(PATTERN.y )));
518531
519532 dst (y, x) = toDst<DstType>(pixelColor);
520533 }
521534
522- template <int cn>
523- void MHCdemosaic (PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream)
535+ template <int cn, typename Depth >
536+ void MHCdemosaic (PtrStepSz<Depth> src, int2 sourceOffset, PtrStepSz<Depth> dst, int2 firstRed, cudaStream_t stream)
524537 {
525- typedef typename TypeVec<uchar , cn>::vec_type dst_t ;
538+ typedef typename TypeVec<Depth , cn>::vec_type dst_t ;
526539
527540 const dim3 block (32 , 8 );
528541 const dim3 grid (divUp (src.cols , block.x ), divUp (src.rows , block.y ));
529542
530543 if (sourceOffset.x || sourceOffset.y ) {
531- cv::cudev::TextureOff<uchar > texSrc (src, sourceOffset.y , sourceOffset.x );
532- MHCdemosaic<dst_t , cv::cudev::TextureOffPtr<uchar >><<<grid, block, 0 , stream>>> ((PtrStepSz<dst_t >)dst, texSrc, firstRed);
544+ cv::cudev::TextureOff<Depth > texSrc (src, sourceOffset.y , sourceOffset.x );
545+ MHCdemosaic<dst_t , cv::cudev::TextureOffPtr<Depth >><<<grid, block, 0 , stream>>> ((PtrStepSz<dst_t >)dst, texSrc, firstRed);
533546 }
534547 else {
535- cv::cudev::Texture<uchar > texSrc (src);
536- MHCdemosaic<dst_t , cv::cudev::TexturePtr<uchar >><<<grid, block, 0 , stream>>> ((PtrStepSz<dst_t >)dst, texSrc, firstRed);
548+ cv::cudev::Texture<Depth > texSrc (src);
549+ MHCdemosaic<dst_t , cv::cudev::TexturePtr<Depth >><<<grid, block, 0 , stream>>> ((PtrStepSz<dst_t >)dst, texSrc, firstRed);
537550 }
538551
539552 cudaSafeCall ( cudaGetLastError () );
@@ -542,9 +555,12 @@ namespace cv { namespace cuda { namespace device
542555 cudaSafeCall ( cudaDeviceSynchronize () );
543556 }
544557
545- template void MHCdemosaic<1 >(PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream);
546- template void MHCdemosaic<3 >(PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream);
547- template void MHCdemosaic<4 >(PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream);
558+ template void MHCdemosaic<1 , uchar>(PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream);
559+ template void MHCdemosaic<3 , uchar>(PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream);
560+ template void MHCdemosaic<4 , uchar>(PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream);
561+ template void MHCdemosaic<1 , ushort>(PtrStepSz<ushort> src, int2 sourceOffset, PtrStepSz<ushort> dst, int2 firstRed, cudaStream_t stream);
562+ template void MHCdemosaic<3 , ushort>(PtrStepSz<ushort> src, int2 sourceOffset, PtrStepSz<ushort> dst, int2 firstRed, cudaStream_t stream);
563+ template void MHCdemosaic<4 , ushort>(PtrStepSz<ushort> src, int2 sourceOffset, PtrStepSz<ushort> dst, int2 firstRed, cudaStream_t stream);
548564}}}
549565
550566#endif /* CUDA_DISABLER */
0 commit comments