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:
authorJeroen Bakker <jeroen@blender.org>2022-10-12 09:47:12 +0300
committerJeroen Bakker <jeroen@blender.org>2022-10-12 09:56:14 +0300
commit872a45f42bc5a582fac59e9cd24239ee25821bff (patch)
tree578aebfda4bcd28075fb3565ede2118ae9ed62ff /source/blender/imbuf/intern
parent78634b1fd1fb76f101cd36e05fc80d00cd4c6f07 (diff)
ImageEngine: Clamp image data to fit half float range.
When image data exceeds half float ranges values are set to +/- infinity that could lead to artifacts later on in the pipeline. Color management for example. This patch adds a utility function `IMB_gpu_clamp_half_float` that clamps full float values to fit within the range of half floats. This fixes T98575 and T101601.
Diffstat (limited to 'source/blender/imbuf/intern')
-rw-r--r--source/blender/imbuf/intern/util_gpu.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/source/blender/imbuf/intern/util_gpu.c b/source/blender/imbuf/intern/util_gpu.c
index 6f1275e1812..dd509677d8d 100644
--- a/source/blender/imbuf/intern/util_gpu.c
+++ b/source/blender/imbuf/intern/util_gpu.c
@@ -370,3 +370,19 @@ eGPUTextureFormat IMB_gpu_get_texture_format(const ImBuf *ibuf,
return gpu_texture_format;
}
+
+void IMB_gpu_clamp_half_float(ImBuf *image_buffer)
+{
+ const float half_min = -65504;
+ const float half_max = 65504;
+ if (!image_buffer->rect_float) {
+ return;
+ }
+
+ int rect_float_len = image_buffer->x * image_buffer->y *
+ (image_buffer->channels == 0 ? 4 : image_buffer->channels);
+
+ for (int i = 0; i < rect_float_len; i++) {
+ image_buffer->rect_float[i] = clamp_f(image_buffer->rect_float[i], half_min, half_max);
+ }
+}