@@ -382,6 +382,15 @@ 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 DstType> __device__ __forceinline__ DstType toDstColor (const float3 & pix){
386
+ typedef typename VecTraits<DstType>::elem_type SrcElemType;
387
+ return toDst<D>(make_3<SrcElemType>(saturate_cast<SrcElemType>(pix.x ), saturate_cast<SrcElemType>(pix.y ), saturate_cast<SrcElemType>(pix.z )));
388
+ }
389
+ template <> __device__ __forceinline__ float3 toDstColor<float3 >(const float3 & pix)
390
+ {
391
+ return pix;
392
+ }
393
+
385
394
// ////////////////////////////////////////////////////////////
386
395
// Bayer Demosaicing (Malvar, He, and Cutler)
387
396
//
@@ -517,19 +526,15 @@ namespace cv { namespace cuda { namespace device
517
526
alternate.x = (x + firstRed.x ) % 2 ;
518
527
alternate.y = (y + firstRed.y ) % 2 ;
519
528
520
- typedef typename VecTraits<DstType>::elem_type SrcElemType;
521
- typedef typename TypeVec<SrcElemType, 3 >::vec_type SrcType;
522
-
523
- SrcType pixelColor =
529
+ float3 pixelColor =
524
530
(alternate.y == 0 ) ?
525
531
((alternate.x == 0 ) ?
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 ) )) :
532
+ make_float3 ( PATTERN.y , PATTERN.x , C ) :
533
+ make_float3 ( PATTERN.w , C, PATTERN.z )) :
528
534
((alternate.x == 0 ) ?
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 )));
531
-
532
- dst (y, x) = toDst<DstType>(pixelColor);
535
+ make_float3 (PATTERN.z , C, PATTERN.w ) :
536
+ make_float3 (C, PATTERN.x , PATTERN.y ));
537
+ dst (y, x) = toDstColor<DstType>(pixelColor);
533
538
}
534
539
535
540
template <int cn, typename Depth>
@@ -561,6 +566,29 @@ namespace cv { namespace cuda { namespace device
561
566
template void MHCdemosaic<1 , ushort >(PtrStepSz<ushort > src, int2 sourceOffset, PtrStepSz<ushort > dst, int2 firstRed, cudaStream_t stream);
562
567
template void MHCdemosaic<3 , ushort >(PtrStepSz<ushort > src, int2 sourceOffset, PtrStepSz<ushort > dst, int2 firstRed, cudaStream_t stream);
563
568
template void MHCdemosaic<4 , ushort >(PtrStepSz<ushort > src, int2 sourceOffset, PtrStepSz<ushort > dst, int2 firstRed, cudaStream_t stream);
569
+
570
+ // Implement MHCdemosaic for float and with a result of 3 channels
571
+ void MHCdemosaic_float3 (PtrStepSzf src, int2 sourceOffset, PtrStepSzf dst, int2 firstRed, cudaStream_t stream)
572
+ {
573
+ typedef typename TypeVec<float , 3 >::vec_type dst_t ;
574
+
575
+ const dim3 block (32 , 8 );
576
+ const dim3 grid (divUp (src.cols , block.x ), divUp (src.rows , block.y ));
577
+
578
+ if (sourceOffset.x || sourceOffset.y ) {
579
+ cv::cudev::TextureOff<float > texSrc (src, sourceOffset.y , sourceOffset.x );
580
+ MHCdemosaic<dst_t , cv::cudev::TextureOffPtr<float >><<<grid, block, 0 , stream>>> ((PtrStepSz<dst_t >)dst, texSrc, firstRed);
581
+ }
582
+ else {
583
+ cv::cudev::Texture<float > texSrc (src);
584
+ MHCdemosaic<dst_t , cv::cudev::TexturePtr<float >><<<grid, block, 0 , stream>>> ((PtrStepSz<dst_t >)dst, texSrc, firstRed);
585
+ }
586
+
587
+ cudaSafeCall ( cudaGetLastError () );
588
+
589
+ if (stream == 0 )
590
+ cudaSafeCall ( cudaDeviceSynchronize () );
591
+ }
564
592
}}}
565
593
566
594
#endif /* CUDA_DISABLER */
0 commit comments