Round when converting to 8 bits (#3429)

This commit is contained in:
Flössie
2016-09-21 21:54:46 +02:00
parent 309b823f93
commit 1e7b8035c4
5 changed files with 21 additions and 21 deletions

View File

@@ -103,27 +103,27 @@ public:
template<>
inline void ImageDatas::convertTo(unsigned short src, unsigned char& dst) const
{
dst = src / 257;
dst = (src + 128) / 257;
}
template<>
inline void ImageDatas::convertTo(unsigned char src, int& dst) const
{
dst = static_cast<int>(src) * 257;
dst = src * 257;
}
template<>
inline void ImageDatas::convertTo(unsigned char src, unsigned short& dst) const
{
dst = static_cast<unsigned short>(src) * 257;
dst = src * 257;
}
template<>
inline void ImageDatas::convertTo(float src, unsigned char& dst) const
{
dst = static_cast<unsigned short>(src) / 257;
dst = (static_cast<int>(src) + 128) / 257;
}
template<>
inline void ImageDatas::convertTo(unsigned char src, float& dst) const
{
dst = static_cast<unsigned short>(src) * 257;
dst = src * 257;
}
// --------------------------------------------------------------------