Blender  V3.3
cycles/util/image.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __UTIL_IMAGE_H__
5 # define __UTIL_IMAGE_H__
6 
7 /* OpenImageIO is used for all image file reading and writing. */
8 
9 # include <OpenImageIO/imageio.h>
10 
11 # include "util/half.h"
12 # include "util/vector.h"
13 
15 
16 OIIO_NAMESPACE_USING
17 
18 template<typename T>
19 void util_image_resize_pixels(const vector<T> &input_pixels,
20  const size_t input_width,
21  const size_t input_height,
22  const size_t input_depth,
23  const size_t components,
24  vector<T> *output_pixels,
25  size_t *output_width,
26  size_t *output_height,
27  size_t *output_depth);
28 
29 /* Cast input pixel from unknown storage to float. */
30 template<typename T> inline float util_image_cast_to_float(T value);
31 
32 template<> inline float util_image_cast_to_float(float value)
33 {
34  return value;
35 }
36 template<> inline float util_image_cast_to_float(uchar value)
37 {
38  return (float)value / 255.0f;
39 }
40 template<> inline float util_image_cast_to_float(uint16_t value)
41 {
42  return (float)value / 65535.0f;
43 }
44 template<> inline float util_image_cast_to_float(half value)
45 {
46  return half_to_float_image(value);
47 }
48 
49 /* Cast float value to output pixel type. */
50 template<typename T> inline T util_image_cast_from_float(float value);
51 
52 template<> inline float util_image_cast_from_float(float value)
53 {
54  return value;
55 }
56 template<> inline uchar util_image_cast_from_float(float value)
57 {
58  if (value < 0.0f) {
59  return 0;
60  }
61  else if (value > (1.0f - 0.5f / 255.0f)) {
62  return 255;
63  }
64  return (uchar)((255.0f * value) + 0.5f);
65 }
66 template<> inline uint16_t util_image_cast_from_float(float value)
67 {
68  if (value < 0.0f) {
69  return 0;
70  }
71  else if (value > (1.0f - 0.5f / 65535.0f)) {
72  return 65535;
73  }
74  return (uint16_t)((65535.0f * value) + 0.5f);
75 }
76 template<> inline half util_image_cast_from_float(float value)
77 {
78  return float_to_half_image(value);
79 }
80 
81 /* Multiply image pixels in native data format. */
82 template<typename T> inline T util_image_multiply_native(T a, T b);
83 
84 template<> inline float util_image_multiply_native(float a, float b)
85 {
86  return a * b;
87 }
89 {
90  return ((uint32_t)a * (uint32_t)b) / 255;
91 }
93 {
94  return ((uint32_t)a * (uint32_t)b) / 65535;
95 }
97 {
99 }
100 
102 
103 #endif /* __UTIL_IMAGE_H__ */
104 
105 #include "util/image_impl.h"
unsigned char uchar
Definition: BLI_sys_types.h:70
Definition: half.h:41
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
T util_image_multiply_native(T a, T b)
float util_image_cast_to_float(T value)
T util_image_cast_from_float(float value)
CCL_NAMESPACE_BEGIN OIIO_NAMESPACE_USING void util_image_resize_pixels(const vector< T > &input_pixels, const size_t input_width, const size_t input_height, const size_t input_depth, const size_t components, vector< T > *output_pixels, size_t *output_width, size_t *output_height, size_t *output_depth)
ccl_device_inline half float_to_half_image(float f)
Definition: half.h:74
ccl_device_inline float half_to_float_image(half h)
Definition: half.h:102
#define T
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
unsigned short uint16_t
Definition: stdint.h:79
unsigned int uint32_t
Definition: stdint.h:80