Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
49e93747
Commit
49e93747
authored
Feb 12, 2015
by
Erik Karlsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added saturate_cast from int64 and uint64
parent
8368fb9e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
0 deletions
+12
-0
base.hpp
modules/core/include/opencv2/core/base.hpp
+12
-0
No files found.
modules/core/include/opencv2/core/base.hpp
View file @
49e93747
...
...
@@ -442,6 +442,10 @@ template<typename _Tp> static inline _Tp saturate_cast(int v) { return _Tp(
template
<
typename
_Tp
>
static
inline
_Tp
saturate_cast
(
float
v
)
{
return
_Tp
(
v
);
}
/** @overload */
template
<
typename
_Tp
>
static
inline
_Tp
saturate_cast
(
double
v
)
{
return
_Tp
(
v
);
}
/** @overload */
template
<
typename
_Tp
>
static
inline
_Tp
saturate_cast
(
int64
v
)
{
return
_Tp
(
v
);
}
/** @overload */
template
<
typename
_Tp
>
static
inline
_Tp
saturate_cast
(
uint64
v
)
{
return
_Tp
(
v
);
}
//! @cond IGNORED
...
...
@@ -452,6 +456,8 @@ template<> inline uchar saturate_cast<uchar>(short v) { return saturate_c
template
<>
inline
uchar
saturate_cast
<
uchar
>
(
unsigned
v
)
{
return
(
uchar
)
std
::
min
(
v
,
(
unsigned
)
UCHAR_MAX
);
}
template
<>
inline
uchar
saturate_cast
<
uchar
>
(
float
v
)
{
int
iv
=
cvRound
(
v
);
return
saturate_cast
<
uchar
>
(
iv
);
}
template
<>
inline
uchar
saturate_cast
<
uchar
>
(
double
v
)
{
int
iv
=
cvRound
(
v
);
return
saturate_cast
<
uchar
>
(
iv
);
}
template
<>
inline
uchar
saturate_cast
<
uchar
>
(
int64
v
)
{
return
(
uchar
)((
uint64
)
v
<=
(
uint64
)
UCHAR_MAX
?
v
:
v
>
0
?
UCHAR_MAX
:
0
);
}
template
<>
inline
uchar
saturate_cast
<
uchar
>
(
uint64
v
)
{
return
(
uchar
)
std
::
min
(
v
,
(
uint64
)
UCHAR_MAX
);
}
template
<>
inline
schar
saturate_cast
<
schar
>
(
uchar
v
)
{
return
(
schar
)
std
::
min
((
int
)
v
,
SCHAR_MAX
);
}
template
<>
inline
schar
saturate_cast
<
schar
>
(
ushort
v
)
{
return
(
schar
)
std
::
min
((
unsigned
)
v
,
(
unsigned
)
SCHAR_MAX
);
}
...
...
@@ -460,6 +466,8 @@ template<> inline schar saturate_cast<schar>(short v) { return saturate_c
template
<>
inline
schar
saturate_cast
<
schar
>
(
unsigned
v
)
{
return
(
schar
)
std
::
min
(
v
,
(
unsigned
)
SCHAR_MAX
);
}
template
<>
inline
schar
saturate_cast
<
schar
>
(
float
v
)
{
int
iv
=
cvRound
(
v
);
return
saturate_cast
<
schar
>
(
iv
);
}
template
<>
inline
schar
saturate_cast
<
schar
>
(
double
v
)
{
int
iv
=
cvRound
(
v
);
return
saturate_cast
<
schar
>
(
iv
);
}
template
<>
inline
schar
saturate_cast
<
schar
>
(
int64
v
)
{
return
(
schar
)((
uint64
)((
int64
)
v
-
SCHAR_MIN
)
<=
(
uint64
)
UCHAR_MAX
?
v
:
v
>
0
?
SCHAR_MAX
:
SCHAR_MIN
);
}
template
<>
inline
schar
saturate_cast
<
schar
>
(
uint64
v
)
{
return
(
schar
)
std
::
min
(
v
,
(
uint64
)
SCHAR_MAX
);
}
template
<>
inline
ushort
saturate_cast
<
ushort
>
(
schar
v
)
{
return
(
ushort
)
std
::
max
((
int
)
v
,
0
);
}
template
<>
inline
ushort
saturate_cast
<
ushort
>
(
short
v
)
{
return
(
ushort
)
std
::
max
((
int
)
v
,
0
);
}
...
...
@@ -467,12 +475,16 @@ template<> inline ushort saturate_cast<ushort>(int v) { return (ushort)((
template
<>
inline
ushort
saturate_cast
<
ushort
>
(
unsigned
v
)
{
return
(
ushort
)
std
::
min
(
v
,
(
unsigned
)
USHRT_MAX
);
}
template
<>
inline
ushort
saturate_cast
<
ushort
>
(
float
v
)
{
int
iv
=
cvRound
(
v
);
return
saturate_cast
<
ushort
>
(
iv
);
}
template
<>
inline
ushort
saturate_cast
<
ushort
>
(
double
v
)
{
int
iv
=
cvRound
(
v
);
return
saturate_cast
<
ushort
>
(
iv
);
}
template
<>
inline
ushort
saturate_cast
<
ushort
>
(
int64
v
)
{
return
(
ushort
)((
uint64
)
v
<=
(
uint64
)
USHRT_MAX
?
v
:
v
>
0
?
USHRT_MAX
:
0
);
}
template
<>
inline
ushort
saturate_cast
<
ushort
>
(
uint64
v
)
{
return
(
ushort
)
std
::
min
(
v
,
(
uint64
)
USHRT_MAX
);
}
template
<>
inline
short
saturate_cast
<
short
>
(
ushort
v
)
{
return
(
short
)
std
::
min
((
int
)
v
,
SHRT_MAX
);
}
template
<>
inline
short
saturate_cast
<
short
>
(
int
v
)
{
return
(
short
)((
unsigned
)(
v
-
SHRT_MIN
)
<=
(
unsigned
)
USHRT_MAX
?
v
:
v
>
0
?
SHRT_MAX
:
SHRT_MIN
);
}
template
<>
inline
short
saturate_cast
<
short
>
(
unsigned
v
)
{
return
(
short
)
std
::
min
(
v
,
(
unsigned
)
SHRT_MAX
);
}
template
<>
inline
short
saturate_cast
<
short
>
(
float
v
)
{
int
iv
=
cvRound
(
v
);
return
saturate_cast
<
short
>
(
iv
);
}
template
<>
inline
short
saturate_cast
<
short
>
(
double
v
)
{
int
iv
=
cvRound
(
v
);
return
saturate_cast
<
short
>
(
iv
);
}
template
<>
inline
short
saturate_cast
<
short
>
(
int64
v
)
{
return
(
short
)((
uint64
)((
int64
)
v
-
SHRT_MIN
)
<=
(
uint64
)
USHRT_MAX
?
v
:
v
>
0
?
SHRT_MAX
:
SHRT_MIN
);
}
template
<>
inline
short
saturate_cast
<
short
>
(
uint64
v
)
{
return
(
short
)
std
::
min
(
v
,
(
uint64
)
SHRT_MAX
);
}
template
<>
inline
int
saturate_cast
<
int
>
(
float
v
)
{
return
cvRound
(
v
);
}
template
<>
inline
int
saturate_cast
<
int
>
(
double
v
)
{
return
cvRound
(
v
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment