43
#ifndef OPENCV_CUDA_SATURATE_CAST_HPP
44
#define OPENCV_CUDA_SATURATE_CAST_HPP
54
namespace
cv
{
namespace
cuda {
namespace
device
56
template<
typename
_Tp> __device__ __forceinline__ _Tp
saturate_cast(uchar v) {
return
_Tp(v); }
57
template<
typename
_Tp> __device__ __forceinline__ _Tp
saturate_cast(schar v) {
return
_Tp(v); }
58
template<
typename
_Tp> __device__ __forceinline__ _Tp
saturate_cast(ushort v) {
return
_Tp(v); }
59
template<
typename
_Tp> __device__ __forceinline__ _Tp
saturate_cast(
short
v) {
return
_Tp(v); }
60
template<
typename
_Tp> __device__ __forceinline__ _Tp
saturate_cast(uint v) {
return
_Tp(v); }
61
template<
typename
_Tp> __device__ __forceinline__ _Tp
saturate_cast(
int
v) {
return
_Tp(v); }
62
template<
typename
_Tp> __device__ __forceinline__ _Tp
saturate_cast(
float
v) {
return
_Tp(v); }
63
template<
typename
_Tp> __device__ __forceinline__ _Tp
saturate_cast(
double
v) {
return
_Tp(v); }
65
template<> __device__ __forceinline__ uchar saturate_cast<uchar>(schar v)
69
asm(
"cvt.sat.u8.s8 %0, %1;"
:
"=r"(res) :
"r"(vi));
72
template<> __device__ __forceinline__ uchar saturate_cast<uchar>(
short
v)
75
asm(
"cvt.sat.u8.s16 %0, %1;"
:
"=r"(res) :
"h"(v));
78
template<> __device__ __forceinline__ uchar saturate_cast<uchar>(ushort v)
81
asm(
"cvt.sat.u8.u16 %0, %1;"
:
"=r"(res) :
"h"(v));
84
template<> __device__ __forceinline__ uchar saturate_cast<uchar>(
int
v)
87
asm(
"cvt.sat.u8.s32 %0, %1;"
:
"=r"(res) :
"r"(v));
90
template<> __device__ __forceinline__ uchar saturate_cast<uchar>(uint v)
93
asm(
"cvt.sat.u8.u32 %0, %1;"
:
"=r"(res) :
"r"(v));
96
template<> __device__ __forceinline__ uchar saturate_cast<uchar>(
float
v)
99
asm(
"cvt.rni.sat.u8.f32 %0, %1;"
:
"=r"(res) :
"f"(v));
102
template<> __device__ __forceinline__ uchar saturate_cast<uchar>(
double
v)
104
#if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130
106
asm(
"cvt.rni.sat.u8.f64 %0, %1;"
:
"=r"(res) :
"d"(v));
109
return
saturate_cast<uchar>((
float)v);
113
template<> __device__ __forceinline__ schar saturate_cast<schar>(uchar v)
117
asm(
"cvt.sat.s8.u8 %0, %1;"
:
"=r"(res) :
"r"(vi));
120
template<> __device__ __forceinline__ schar saturate_cast<schar>(
short
v)
123
asm(
"cvt.sat.s8.s16 %0, %1;"
:
"=r"(res) :
"h"(v));
126
template<> __device__ __forceinline__ schar saturate_cast<schar>(ushort v)
129
asm(
"cvt.sat.s8.u16 %0, %1;"
:
"=r"(res) :
"h"(v));
132
template<> __device__ __forceinline__ schar saturate_cast<schar>(
int
v)
135
asm(
"cvt.sat.s8.s32 %0, %1;"
:
"=r"(res) :
"r"(v));
138
template<> __device__ __forceinline__ schar saturate_cast<schar>(uint v)
141
asm(
"cvt.sat.s8.u32 %0, %1;"
:
"=r"(res) :
"r"(v));
144
template<> __device__ __forceinline__ schar saturate_cast<schar>(
float
v)
147
asm(
"cvt.rni.sat.s8.f32 %0, %1;"
:
"=r"(res) :
"f"(v));
150
template<> __device__ __forceinline__ schar saturate_cast<schar>(
double
v)
152
#if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130
154
asm(
"cvt.rni.sat.s8.f64 %0, %1;"
:
"=r"(res) :
"d"(v));
157
return
saturate_cast<schar>((
float)v);
161
template<> __device__ __forceinline__ ushort saturate_cast<ushort>(schar v)
165
asm(
"cvt.sat.u16.s8 %0, %1;"
:
"=h"(res) :
"r"(vi));
168
template<> __device__ __forceinline__ ushort saturate_cast<ushort>(
short
v)
171
asm(
"cvt.sat.u16.s16 %0, %1;"
:
"=h"(res) :
"h"(v));
174
template<> __device__ __forceinline__ ushort saturate_cast<ushort>(
int
v)
177
asm(
"cvt.sat.u16.s32 %0, %1;"
:
"=h"(res) :
"r"(v));
180
template<> __device__ __forceinline__ ushort saturate_cast<ushort>(uint v)
183
asm(
"cvt.sat.u16.u32 %0, %1;"
:
"=h"(res) :
"r"(v));
186
template<> __device__ __forceinline__ ushort saturate_cast<ushort>(
float
v)
189
asm(
"cvt.rni.sat.u16.f32 %0, %1;"
:
"=h"(res) :
"f"(v));
192
template<> __device__ __forceinline__ ushort saturate_cast<ushort>(
double
v)
194
#if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130
196
asm(
"cvt.rni.sat.u16.f64 %0, %1;"
:
"=h"(res) :
"d"(v));
199
return
saturate_cast<ushort>((
float)v);
203
template<> __device__ __forceinline__
short
saturate_cast<short>(ushort v)
206
asm(
"cvt.sat.s16.u16 %0, %1;"
:
"=h"(res) :
"h"(v));
209
template<> __device__ __forceinline__
short
saturate_cast<short>(
int
v)
212
asm(
"cvt.sat.s16.s32 %0, %1;"
:
"=h"(res) :
"r"(v));
215
template<> __device__ __forceinline__
short
saturate_cast<short>(uint v)
218
asm(
"cvt.sat.s16.u32 %0, %1;"
:
"=h"(res) :
"r"(v));
221
template<> __device__ __forceinline__
short
saturate_cast<short>(
float
v)
224
asm(
"cvt.rni.sat.s16.f32 %0, %1;"
:
"=h"(res) :
"f"(v));
227
template<> __device__ __forceinline__
short
saturate_cast<short>(
double
v)
229
#if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130
231
asm(
"cvt.rni.sat.s16.f64 %0, %1;"
:
"=h"(res) :
"d"(v));
234
return
saturate_cast<short>((
float)v);
238
template<> __device__ __forceinline__
int
saturate_cast<int>(uint v)
241
asm(
"cvt.sat.s32.u32 %0, %1;"
:
"=r"(res) :
"r"(v));
244
template<> __device__ __forceinline__
int
saturate_cast<int>(
float
v)
246
return
__float2int_rn(v);
248
template<> __device__ __forceinline__
int
saturate_cast<int>(
double
v)
250
#if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130
251
return
__double2int_rn(v);
253
return
saturate_cast<int>((
float)v);
257
template<> __device__ __forceinline__ uint saturate_cast<uint>(schar v)
261
asm(
"cvt.sat.u32.s8 %0, %1;"
:
"=r"(res) :
"r"(vi));
264
template<> __device__ __forceinline__ uint saturate_cast<uint>(
short
v)
267
asm(
"cvt.sat.u32.s16 %0, %1;"
:
"=r"(res) :
"h"(v));
270
template<> __device__ __forceinline__ uint saturate_cast<uint>(
int
v)
273
asm(
"cvt.sat.u32.s32 %0, %1;"
:
"=r"(res) :
"r"(v));
276
template<> __device__ __forceinline__ uint saturate_cast<uint>(
float
v)
278
return
__float2uint_rn(v);
280
template<> __device__ __forceinline__ uint saturate_cast<uint>(
double
v)
282
#if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130
283
return
__double2uint_rn(v);
285
return
saturate_cast<uint>((
float)v);
static _Tp saturate_cast(uchar v)
Template function for accurate conversion from one primitive type to another.
Definition:
saturate.hpp:80
"black box" representation of the file storage associated with a file on disk.
Definition:
aruco.hpp:75