diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2019-05-03 12:23:16 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-03 16:42:49 +0300 |
commit | dba4684f82a179a5c8abdae5940bc7c35e65a1a7 (patch) | |
tree | 6bf8add48d7ac5e20a97da89a34db010625750e7 /intern/cycles/util | |
parent | fadb6f34662fb60e1a48c2c053c500f017206f27 (diff) |
Cycles: add colorspace manager class and utilities based on OpenColorIO
This is the groundwork for supporting loading image textures with arbitrary
color spaces through OpenColorIO.
Initial patch by Lukas, completed by Brecht.
Differential Revision: https://developer.blender.org/D3491
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_color.h | 6 | ||||
-rw-r--r-- | intern/cycles/util/util_image.h | 1 | ||||
-rw-r--r-- | intern/cycles/util/util_map.h | 7 | ||||
-rw-r--r-- | intern/cycles/util/util_math.h | 19 |
4 files changed, 33 insertions, 0 deletions
diff --git a/intern/cycles/util/util_color.h b/intern/cycles/util/util_color.h index 85f241c6221..83410db13c6 100644 --- a/intern/cycles/util/util_color.h +++ b/intern/cycles/util/util_color.h @@ -236,6 +236,12 @@ ccl_device float3 color_linear_to_srgb_v3(float3 c) color_linear_to_srgb(c.x), color_linear_to_srgb(c.y), color_linear_to_srgb(c.z)); } +ccl_device float4 color_linear_to_srgb_v4(float4 c) +{ + return make_float4( + color_linear_to_srgb(c.x), color_linear_to_srgb(c.y), color_linear_to_srgb(c.z), c.w); +} + ccl_device float4 color_srgb_to_linear_v4(float4 c) { #ifdef __KERNEL_SSE2__ diff --git a/intern/cycles/util/util_image.h b/intern/cycles/util/util_image.h index 8962c09d098..27ec7ffb423 100644 --- a/intern/cycles/util/util_image.h +++ b/intern/cycles/util/util_image.h @@ -21,6 +21,7 @@ # include <OpenImageIO/imageio.h> +# include "util/util_half.h" # include "util/util_vector.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/util_map.h b/intern/cycles/util/util_map.h index 3c9288417cf..8385b08dd5a 100644 --- a/intern/cycles/util/util_map.h +++ b/intern/cycles/util/util_map.h @@ -26,6 +26,13 @@ using std::map; using std::pair; using std::unordered_map; +template<typename T> static void map_free_memory(T &data) +{ + /* Use swap() trick to actually free all internal memory. */ + T empty_data; + data.swap(empty_data); +} + CCL_NAMESPACE_END #endif /* __UTIL_MAP_H__ */ diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index 92cab29346a..40c5ebbab67 100644 --- a/intern/cycles/util/util_math.h +++ b/intern/cycles/util/util_math.h @@ -651,6 +651,25 @@ ccl_device_inline float2 map_to_sphere(const float3 co) return make_float2(u, v); } +/* Compares two floats. + * Returns true if their absolute difference is smaller than abs_diff (for numbers near zero) + * or their relative difference is less than ulp_diff ULPs. + * Based on https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ + */ + +ccl_device_inline float compare_floats(float a, float b, float abs_diff, int ulp_diff) +{ + if (fabsf(a - b) < abs_diff) { + return true; + } + + if ((a < 0.0f) != (b < 0.0f)) { + return false; + } + + return (abs(__float_as_int(a) - __float_as_int(b)) < ulp_diff); +} + CCL_NAMESPACE_END #endif /* __UTIL_MATH_H__ */ |