From edbb2d22791f04af6b775f5d46321f533c705781 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 15 Jul 2018 18:34:31 +0200 Subject: Fix Cycles incorrect resize and CMYK conversion of uint16/half images. --- intern/cycles/util/util_half.h | 2 +- intern/cycles/util/util_image.h | 62 +++++++++++++++++++++++++++++++++ intern/cycles/util/util_image_impl.h | 66 ++---------------------------------- 3 files changed, 65 insertions(+), 65 deletions(-) (limited to 'intern/cycles/util') diff --git a/intern/cycles/util/util_half.h b/intern/cycles/util/util_half.h index 58f3f903619..53b7f2472bd 100644 --- a/intern/cycles/util/util_half.h +++ b/intern/cycles/util/util_half.h @@ -42,7 +42,7 @@ public: half() : v(0) {} half(const unsigned short& i) : v(i) {} operator unsigned short() { return v; } - half & operator =(const unsigned short& i) { v = i; return *this; } + half& operator =(const unsigned short& i) { v = i; return *this; } private: unsigned short v; }; diff --git a/intern/cycles/util/util_image.h b/intern/cycles/util/util_image.h index 18876841b5b..85bdb0d8050 100644 --- a/intern/cycles/util/util_image.h +++ b/intern/cycles/util/util_image.h @@ -38,6 +38,68 @@ void util_image_resize_pixels(const vector& input_pixels, size_t *output_height, size_t *output_depth); +/* Cast input pixel from unknown storage to float. */ +template +inline float util_image_cast_to_float(T value); + +template<> +inline float util_image_cast_to_float(float value) +{ + return value; +} +template<> +inline float util_image_cast_to_float(uchar value) +{ + return (float)value / 255.0f; +} +template<> +inline float util_image_cast_to_float(uint16_t value) +{ + return (float)value / 65535.0f; +} +template<> +inline float util_image_cast_to_float(half value) +{ + return half_to_float(value); +} + +/* Cast float value to output pixel type. */ +template +inline T util_image_cast_from_float(float value); + +template<> +inline float util_image_cast_from_float(float value) +{ + return value; +} +template<> +inline uchar util_image_cast_from_float(float value) +{ + if(value < 0.0f) { + return 0; + } + else if(value > (1.0f - 0.5f / 255.0f)) { + return 255; + } + return (uchar)((255.0f * value) + 0.5f); +} +template<> +inline uint16_t util_image_cast_from_float(float value) +{ + if(value < 0.0f) { + return 0; + } + else if(value > (1.0f - 0.5f / 65535.0f)) { + return 65535; + } + return (uint16_t)((65535.0f * value) + 0.5f); +} +template<> +inline half util_image_cast_from_float(float value) +{ + return float_to_half(value); +} + CCL_NAMESPACE_END #endif /* __UTIL_IMAGE_H__ */ diff --git a/intern/cycles/util/util_image_impl.h b/intern/cycles/util/util_image_impl.h index fb953a43ab2..5bc1c727595 100644 --- a/intern/cycles/util/util_image_impl.h +++ b/intern/cycles/util/util_image_impl.h @@ -38,68 +38,6 @@ const T *util_image_read(const vector& pixels, return &pixels[index]; } -/* Cast input pixel from unknown storage to float. */ -template -inline float cast_to_float(T value); - -template<> -inline float cast_to_float(float value) -{ - return value; -} -template<> -inline float cast_to_float(uchar value) -{ - return (float)value / 255.0f; -} -template<> -inline float cast_to_float(uint16_t value) -{ - return (float)value / 65535.0f; -} -template<> -inline float cast_to_float(half value) -{ - return half_to_float(value); -} - -/* Cast float value to output pixel type. */ -template -inline T cast_from_float(float value); - -template<> -inline float cast_from_float(float value) -{ - return value; -} -template<> -inline uchar cast_from_float(float value) -{ - if(value < 0.0f) { - return 0; - } - else if(value > (1.0f - 0.5f / 255.0f)) { - return 255; - } - return (uchar)((255.0f * value) + 0.5f); -} -template<> -inline uint16_t cast_from_float(float value) -{ - if(value < 0.0f) { - return 0; - } - else if(value >(1.0f - 0.5f / 65535.0f)) { - return 65535; - } - return (uchar)((65535.0f * value) + 0.5f); -} -template<> -inline half cast_from_float(float value) -{ - return float_to_half(value); -} - template void util_image_downscale_sample(const vector& pixels, const size_t width, @@ -133,7 +71,7 @@ void util_image_downscale_sample(const vector& pixels, components, nx, ny, nz); for(size_t k = 0; k < components; ++k) { - accum[k] += cast_to_float(pixel[k]); + accum[k] += util_image_cast_to_float(pixel[k]); } ++count; } @@ -142,7 +80,7 @@ void util_image_downscale_sample(const vector& pixels, if(count != 0) { const float inv_count = 1.0f / (float)count; for(size_t k = 0; k < components; ++k) { - result[k] = cast_from_float(accum[k] * inv_count); + result[k] = util_image_cast_from_float(accum[k] * inv_count); } } else { -- cgit v1.2.3