@@ -382,6 +382,14 @@ namespace cv { namespace cuda { namespace device
382
382
template void Bayer2BGR_16u_gpu<3 >(PtrStepSzb src, PtrStepSzb dst, bool blue_last, bool start_with_green, cudaStream_t stream);
383
383
template void Bayer2BGR_16u_gpu<4 >(PtrStepSzb src, PtrStepSzb dst, bool blue_last, bool start_with_green, cudaStream_t stream);
384
384
385
+ template <typename D> __device__ __forceinline__ D toDstColor (const float3 & pix){
386
+ return toDst<D>(make_uchar3 (saturate_cast<uchar>(pix.x ), saturate_cast<uchar>(pix.y ), saturate_cast<uchar>(pix.z )));
387
+ }
388
+ template <> __device__ __forceinline__ float3 toDstColor<float3 >(const float3 & pix)
389
+ {
390
+ return pix;
391
+ }
392
+
385
393
// ////////////////////////////////////////////////////////////
386
394
// Bayer Demosaicing (Malvar, He, and Cutler)
387
395
//
@@ -507,16 +515,15 @@ namespace cv { namespace cuda { namespace device
507
515
alternate.y = (y + firstRed.y ) % 2 ;
508
516
509
517
// in BGR sequence;
510
- uchar3 pixelColor =
518
+ float3 pixelColor =
511
519
(alternate.y == 0 ) ?
512
520
((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 ) )) :
521
+ make_float3 ( PATTERN.y , PATTERN.x , C ) :
522
+ make_float3 ( PATTERN.w , C, PATTERN.z )) :
515
523
((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 )));
518
-
519
- dst (y, x) = toDst<DstType>(pixelColor);
524
+ make_float3 (PATTERN.z , C, PATTERN.w ) :
525
+ make_float3 (C, PATTERN.x , PATTERN.y ));
526
+ dst (y, x) = toDstColor<DstType>(pixelColor);
520
527
}
521
528
522
529
template <int cn>
@@ -545,6 +552,29 @@ namespace cv { namespace cuda { namespace device
545
552
template void MHCdemosaic<1 >(PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream);
546
553
template void MHCdemosaic<3 >(PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream);
547
554
template void MHCdemosaic<4 >(PtrStepSzb src, int2 sourceOffset, PtrStepSzb dst, int2 firstRed, cudaStream_t stream);
555
+
556
+ // Implement MHCdemosaic for float and with a result of 3 channels
557
+ void MHCdemosaic_float3 (PtrStepSzf src, int2 sourceOffset, PtrStepSzf dst, int2 firstRed, cudaStream_t stream)
558
+ {
559
+ typedef typename TypeVec<float , 3 >::vec_type dst_t ;
560
+
561
+ const dim3 block (32 , 8 );
562
+ const dim3 grid (divUp (src.cols , block.x ), divUp (src.rows , block.y ));
563
+
564
+ if (sourceOffset.x || sourceOffset.y ) {
565
+ cv::cudev::TextureOff<float > texSrc (src, sourceOffset.y , sourceOffset.x );
566
+ MHCdemosaic<dst_t , cv::cudev::TextureOffPtr<float >><<<grid, block, 0 , stream>>> ((PtrStepSz<dst_t >)dst, texSrc, firstRed);
567
+ }
568
+ else {
569
+ cv::cudev::Texture<float > texSrc (src);
570
+ MHCdemosaic<dst_t , cv::cudev::TexturePtr<float >><<<grid, block, 0 , stream>>> ((PtrStepSz<dst_t >)dst, texSrc, firstRed);
571
+ }
572
+
573
+ cudaSafeCall ( cudaGetLastError () );
574
+
575
+ if (stream == 0 )
576
+ cudaSafeCall ( cudaDeviceSynchronize () );
577
+ }
548
578
}}}
549
579
550
580
#endif /* CUDA_DISABLER */
0 commit comments