23 #ifndef __CUDA_VECTOR_TEMPLATES_H__
24 #define __CUDA_VECTOR_TEMPLATES_H__
31 #include <type_traits>
61 template<>
inline __host__ __device__
uchar make_vec( uint8_t x, uint8_t y, uint8_t z, uint8_t w ) {
return x; }
62 template<>
inline __host__ __device__ uchar3
make_vec( uint8_t x, uint8_t y, uint8_t z, uint8_t w ) {
return make_uchar3(x,y,z); }
63 template<>
inline __host__ __device__ uchar4
make_vec( uint8_t x, uint8_t y, uint8_t z, uint8_t w ) {
return make_uchar4(x,y,z,w); }
65 template<>
inline __host__ __device__
float make_vec(
float x,
float y,
float z,
float w ) {
return x; }
66 template<>
inline __host__ __device__ float3
make_vec(
float x,
float y,
float z,
float w ) {
return make_float3(x,y,z); }
67 template<>
inline __host__ __device__ float4
make_vec(
float x,
float y,
float z,
float w ) {
return make_float4(x,y,z,w); }
71 template<
typename T>
inline __host__ __device__ T
cast_vec(
const uchar3& a ) { static_assert(
cuda_assert_false<T>::value,
"invalid vector type - supported types are uchar3, uchar4, float3, float4"); }
72 template<
typename T>
inline __host__ __device__ T
cast_vec(
const uchar4& a ) { static_assert(
cuda_assert_false<T>::value,
"invalid vector type - supported types are uchar3, uchar4, float3, float4"); }
73 template<
typename T>
inline __host__ __device__ T
cast_vec(
const float3& a ) { static_assert(
cuda_assert_false<T>::value,
"invalid vector type - supported types are uchar3, uchar4, float3, float4"); }
74 template<
typename T>
inline __host__ __device__ T
cast_vec(
const float4& a ) { static_assert(
cuda_assert_false<T>::value,
"invalid vector type - supported types are uchar3, uchar4, float3, float4"); }
77 template<>
inline __host__ __device__ uchar4
cast_vec(
const uchar3& a ) {
return make_uchar4(a); }
78 template<>
inline __host__ __device__ float3
cast_vec(
const uchar3& a ) {
return make_float3(a); }
79 template<>
inline __host__ __device__ float4
cast_vec(
const uchar3& a ) {
return make_float4(a); }
82 template<>
inline __host__ __device__ uchar4
cast_vec(
const uchar4& a ) {
return make_uchar4(a); }
83 template<>
inline __host__ __device__ float3
cast_vec(
const uchar4& a ) {
return make_float3(a); }
84 template<>
inline __host__ __device__ float4
cast_vec(
const uchar4& a ) {
return make_float4(a); }
87 template<>
inline __host__ __device__ uchar4
cast_vec(
const float3& a ) {
return make_uchar4(a); }
88 template<>
inline __host__ __device__ float3
cast_vec(
const float3& a ) {
return make_float3(a); }
89 template<>
inline __host__ __device__ float4
cast_vec(
const float3& a ) {
return make_float4(a); }
92 template<>
inline __host__ __device__ uchar4
cast_vec(
const float4& a ) {
return make_uchar4(a); }
93 template<>
inline __host__ __device__ float3
cast_vec(
const float4& a ) {
return make_float3(a); }
94 template<>
inline __host__ __device__ float4
cast_vec(
const float4& a ) {
return make_float4(a); }
100 template<>
inline __host__ __device__ uint8_t
alpha( uchar3 vec, uint8_t default_alpha ) {
return default_alpha; }
101 template<>
inline __host__ __device__ uint8_t
alpha( uchar4 vec, uint8_t default_alpha ) {
return vec.w; }
103 template<>
inline __host__ __device__
float alpha( float3 vec,
float default_alpha ) {
return default_alpha; }
104 template<>
inline __host__ __device__
float alpha( float4 vec,
float default_alpha ) {
return vec.w; }