Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/cycles/util/util_image.h')
-rw-r--r--intern/cycles/util/util_image.h62
1 files changed, 62 insertions, 0 deletions
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<T>& input_pixels,
size_t *output_height,
size_t *output_depth);
+/* Cast input pixel from unknown storage to float. */
+template<typename T>
+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<typename T>
+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__ */