Use full range in ImageDatas::convertTo<> (#3429)

Kudos to @mmmtok for finding and fixing!
This commit is contained in:
Flössie
2016-09-14 21:36:44 +02:00
parent 298e91b1a0
commit cb034284be

View File

@@ -59,9 +59,9 @@ class ImageDatas : virtual public ImageDimensions
{ {
public: public:
template<class S, class D> template<class S, class D>
void convertTo (S srcValue, D &dstValue) void convertTo(S src, D& dst) const
{ {
dstValue = static_cast<D>(srcValue); dst = src;
} }
// parameters that will never be used, replaced by the subclasses r, g and b parameters! // parameters that will never be used, replaced by the subclasses r, g and b parameters!
@@ -101,29 +101,29 @@ public:
}; };
template<> template<>
inline void ImageDatas::convertTo<unsigned short, unsigned char> (const unsigned short srcValue, unsigned char &dstValue) inline void ImageDatas::convertTo(unsigned short src, unsigned char& dst) const
{ {
dstValue = (unsigned char)(srcValue >> 8); dst = src / 257;
} }
template<> template<>
inline void ImageDatas::convertTo<unsigned char, int> (const unsigned char srcValue, int &dstValue) inline void ImageDatas::convertTo(unsigned char src, int& dst) const
{ {
dstValue = (int)(srcValue) << 8; dst = static_cast<int>(src) * 257;
} }
template<> template<>
inline void ImageDatas::convertTo<unsigned char, unsigned short> (const unsigned char srcValue, unsigned short &dstValue) inline void ImageDatas::convertTo(unsigned char src, unsigned short& dst) const
{ {
dstValue = (unsigned short)(srcValue) << 8; dst = static_cast<unsigned short>(src) * 257;
} }
template<> template<>
inline void ImageDatas::convertTo<float, unsigned char> (const float srcValue, unsigned char &dstValue) inline void ImageDatas::convertTo(float src, unsigned char& dst) const
{ {
dstValue = (unsigned char)( (unsigned short)(srcValue) >> 8 ); dst = static_cast<unsigned short>(src) / 257;
} }
template<> template<>
inline void ImageDatas::convertTo<unsigned char, float> (const unsigned char srcValue, float &dstValue) inline void ImageDatas::convertTo(unsigned char src, float& dst) const
{ {
dstValue = float( (unsigned short)(srcValue) << 8 ); dst = static_cast<unsigned short>(src) * 257;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------