Blender
V5.0
intern
cycles
util
cycles/util/image.h
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2
*
3
* SPDX-License-Identifier: Apache-2.0 */
4
5
#pragma once
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
14
CCL_NAMESPACE_BEGIN
15
16
using
OIIO::AutoStride;
17
using
OIIO::ImageInput;
18
using
OIIO::ImageOutput;
19
using
OIIO::ImageSpec;
20
21
template
<
typename
T>
22
void
util_image_resize_pixels
(
const
vector<T>
&input_pixels,
23
const
size_t
input_width,
24
const
size_t
input_height,
25
const
size_t
components,
26
vector<T>
*output_pixels,
27
size_t
*output_width,
28
size_t
*output_height);
29
30
/* Cast input pixel from unknown storage to float. */
31
template
<
typename
T>
inline
float
util_image_cast_to_float
(
T
value);
32
33
template
<>
inline
float
util_image_cast_to_float
(
const
float
value)
34
{
35
return
value;
36
}
37
template
<>
inline
float
util_image_cast_to_float
(
const
uchar
value)
38
{
39
return
(
float
)value / 255.0f;
40
}
41
template
<>
inline
float
util_image_cast_to_float
(
const
uint16_t value)
42
{
43
return
(
float
)value / 65535.0f;
44
}
45
template
<>
inline
float
util_image_cast_to_float
(
half
value)
46
{
47
return
half_to_float_image
(value);
48
}
49
50
/* Cast float value to output pixel type. */
51
template
<
typename
T>
inline
T
util_image_cast_from_float
(
const
float
value);
52
53
template
<>
inline
float
util_image_cast_from_float
(
const
float
value)
54
{
55
return
value;
56
}
57
template
<>
inline
uchar
util_image_cast_from_float
(
const
float
value)
58
{
59
if
(value < 0.0f) {
60
return
0;
61
}
62
if
(value > (1.0f - 0.5f / 255.0f)) {
63
return
255;
64
}
65
return
(
uchar
)((255.0f * value) + 0.5f);
// NOLINT
66
}
67
template
<>
inline
uint16_t
util_image_cast_from_float
(
const
float
value)
68
{
69
if
(value < 0.0f) {
70
return
0;
71
}
72
if
(value > (1.0f - 0.5f / 65535.0f)) {
73
return
65535;
74
}
75
return
(uint16_t)((65535.0f * value) + 0.5f);
// NOLINT
76
}
77
template
<>
inline
half
util_image_cast_from_float
(
const
float
value)
78
{
79
return
float_to_half_image
(value);
80
}
81
82
/* Multiply image pixels in native data format. */
83
template
<
typename
T>
inline
T
util_image_multiply_native
(
T
a,
T
b
);
84
85
template
<>
inline
float
util_image_multiply_native
(
const
float
a,
const
float
b
)
86
{
87
return
a *
b
;
88
}
89
template
<>
inline
uchar
util_image_multiply_native
(
const
uchar
a,
const
uchar
b
)
90
{
91
return
((uint32_t)a * (uint32_t)
b
) / 255;
92
}
93
template
<>
inline
uint16_t
util_image_multiply_native
(
const
uint16_t a,
const
uint16_t
b
)
94
{
95
return
((uint32_t)a * (uint32_t)
b
) / 65535;
96
}
97
template
<>
inline
half
util_image_multiply_native
(
half
a,
half
b
)
98
{
99
return
float_to_half_image
(
half_to_float_image
(a) *
half_to_float_image
(
b
));
100
}
101
102
CCL_NAMESPACE_END
103
104
#include "
util/image_impl.h
"
// IWYU pragma: export
uchar
unsigned char uchar
Definition
BLI_sys_types.h:67
half
Definition
half.h:41
vector
Definition
cycles/util/vector.h:20
b
b
Definition
compositor_morphological_distance_infos.hh:24
util_image_cast_from_float
T util_image_cast_from_float(const float value)
util_image_multiply_native
T util_image_multiply_native(T a, T b)
util_image_cast_to_float
float util_image_cast_to_float(T value)
util_image_resize_pixels
void util_image_resize_pixels(const vector< T > &input_pixels, const size_t input_width, const size_t input_height, const size_t components, vector< T > *output_pixels, size_t *output_width, size_t *output_height)
vector.h
CCL_NAMESPACE_END
#define CCL_NAMESPACE_END
Definition
device/cuda/compat.h:10
half.h
float_to_half_image
ccl_device_inline half float_to_half_image(const float f)
Definition
half.h:70
half_to_float_image
ccl_device_inline float half_to_float_image(half h)
Definition
half.h:98
image_impl.h
T
#define T
Definition
mball_tessellate.cc:274
CCL_NAMESPACE_BEGIN
Definition
python.cpp:37
Generated on
for Blender by
doxygen
1.16.1