Commit d15fcdc7 authored by Davis King's avatar Davis King

Fixed a bug in the signed/unsigned comparison code in the assign_pixel function.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403975
parent 020006c2
......@@ -482,50 +482,47 @@ namespace dlib
// -----------------------------
template <typename T>
typename unsigned_type<T>::type make_unsigned (
const T& val
) { return static_cast<typename unsigned_type<T>::type>(val); }
inline float make_unsigned(const float& val) { return val; }
inline double make_unsigned(const double& val) { return val; }
inline long double make_unsigned(const long double& val) { return val; }
template <typename T, typename P>
typename enable_if_c<(sizeof(P) < sizeof(T)), bool>::type less_or_equal_to_max (
const P&
) { return true; }
typename enable_if_c<pixel_traits<T>::is_unsigned == pixel_traits<P>::is_unsigned, bool>::type less_or_equal_to_max (
const P& p
)
/*!
ensures
- returns true if p is <= max value of T
!*/
template <typename T, typename P>
typename enable_if_c<sizeof(P) == sizeof(T) && pixel_traits<T>::is_unsigned == pixel_traits<P>::is_unsigned, bool>::type less_or_equal_to_max (
const P& p
)
{
return p <= pixel_traits<T>::max();
}
template <typename T, typename P>
typename enable_if_c<sizeof(P) == sizeof(T) && pixel_traits<T>::is_unsigned && !pixel_traits<P>::is_unsigned, bool>::type less_or_equal_to_max (
typename enable_if_c<pixel_traits<T>::is_unsigned && !pixel_traits<P>::is_unsigned, bool>::type less_or_equal_to_max (
const P& p
)
{
if (p <= 0)
return true;
else if (static_cast<T>(p) <= pixel_traits<T>::max())
else if (make_unsigned(p) <= pixel_traits<T>::max())
return true;
else
return false;
}
template <typename T, typename P>
typename enable_if_c<sizeof(P) == sizeof(T) && !pixel_traits<T>::is_unsigned && pixel_traits<P>::is_unsigned, bool>::type less_or_equal_to_max (
const P& p
)
{
return p <= static_cast<P>(pixel_traits<T>::max());
}
template <typename T, typename P>
typename enable_if_c<(sizeof(P) > sizeof(T)), bool>::type less_or_equal_to_max (
typename enable_if_c<!pixel_traits<T>::is_unsigned && pixel_traits<P>::is_unsigned, bool>::type less_or_equal_to_max (
const P& p
)
{
return p <= static_cast<P>(pixel_traits<T>::max());
return p <= make_unsigned(pixel_traits<T>::max());
}
// -----------------------------
......
......@@ -122,7 +122,7 @@ namespace
DLIB_TEST(p_schar == std::numeric_limits<signed char>::max());
DLIB_TEST(p_int == (255+100+50)/3);
DLIB_TEST(p_float == (255+100+50)/3);
DLIB_TEST_MSG(p_float == (255+100+50)/3, p_float - (255+100+50)/3);
DLIB_TEST(p_gray == (255+100+50)/3);
DLIB_TEST(p_rgb.red == 255);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment