From cb034284be3f33921952dd28acd6c0fa951b3e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Wed, 14 Sep 2016 21:36:44 +0200 Subject: [PATCH] Use full range in `ImageDatas::convertTo<>` (#3429) Kudos to @mmmtok for finding and fixing! --- rtengine/iimage.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/rtengine/iimage.h b/rtengine/iimage.h index 1f82ea3e6..2eded8208 100644 --- a/rtengine/iimage.h +++ b/rtengine/iimage.h @@ -58,10 +58,10 @@ enum TypeInterpolation { TI_Nearest, TI_Bilinear }; class ImageDatas : virtual public ImageDimensions { public: - template - void convertTo (S srcValue, D &dstValue) + template + void convertTo(S src, D& dst) const { - dstValue = static_cast(srcValue); + dst = src; } // parameters that will never be used, replaced by the subclasses r, g and b parameters! @@ -100,30 +100,30 @@ public: }; -template <> -inline void ImageDatas::convertTo (const unsigned short srcValue, unsigned char &dstValue) +template<> +inline void ImageDatas::convertTo(unsigned short src, unsigned char& dst) const { - dstValue = (unsigned char)(srcValue >> 8); + dst = src / 257; } -template <> -inline void ImageDatas::convertTo (const unsigned char srcValue, int &dstValue) +template<> +inline void ImageDatas::convertTo(unsigned char src, int& dst) const { - dstValue = (int)(srcValue) << 8; + dst = static_cast(src) * 257; } -template <> -inline void ImageDatas::convertTo (const unsigned char srcValue, unsigned short &dstValue) +template<> +inline void ImageDatas::convertTo(unsigned char src, unsigned short& dst) const { - dstValue = (unsigned short)(srcValue) << 8; + dst = static_cast(src) * 257; } -template <> -inline void ImageDatas::convertTo (const float srcValue, unsigned char &dstValue) +template<> +inline void ImageDatas::convertTo(float src, unsigned char& dst) const { - dstValue = (unsigned char)( (unsigned short)(srcValue) >> 8 ); + dst = static_cast(src) / 257; } -template <> -inline void ImageDatas::convertTo (const unsigned char srcValue, float &dstValue) +template<> +inline void ImageDatas::convertTo(unsigned char src, float& dst) const { - dstValue = float( (unsigned short)(srcValue) << 8 ); + dst = static_cast(src) * 257; } // --------------------------------------------------------------------