Blender V4.3
BLI_math_interp.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
20#include "BLI_math_base.h"
21#include "BLI_math_base.hh"
23
24namespace blender::math {
25
37 const uchar *buffer, uchar *output, int width, int height, float u, float v)
38{
39 BLI_assert(buffer);
40 int x = int(u);
41 int y = int(v);
42
43 /* Outside image? */
44 if (x < 0 || x >= width || y < 0 || y >= height) {
45 output[0] = output[1] = output[2] = output[3] = 0;
46 return;
47 }
48
49 const uchar *data = buffer + (int64_t(width) * y + x) * 4;
50 output[0] = data[0];
51 output[1] = data[1];
52 output[2] = data[2];
53 output[3] = data[3];
54}
55
57 const uchar *buffer, int width, int height, float u, float v)
58{
59 uchar4 res;
60 interpolate_nearest_border_byte(buffer, res, width, height, u, v);
61 return res;
62}
63
65 const float *buffer, float *output, int width, int height, int components, float u, float v)
66{
67 BLI_assert(buffer);
68 int x = int(u);
69 int y = int(v);
70
71 /* Outside image? */
72 if (x < 0 || x >= width || y < 0 || y >= height) {
73 for (int i = 0; i < components; i++) {
74 output[i] = 0.0f;
75 }
76 return;
77 }
78
79 const float *data = buffer + (int64_t(width) * y + x) * components;
80 for (int i = 0; i < components; i++) {
81 output[i] = data[i];
82 }
83}
84
86 const float *buffer, int width, int height, float u, float v)
87{
88 float4 res;
89 interpolate_nearest_border_fl(buffer, res, width, height, 4, u, v);
90 return res;
91}
92
104 const uchar *buffer, uchar *output, int width, int height, float u, float v)
105{
106 BLI_assert(buffer);
107 const int x = math::clamp(int(u), 0, width - 1);
108 const int y = math::clamp(int(v), 0, height - 1);
109
110 const uchar *data = buffer + (int64_t(width) * y + x) * 4;
111 output[0] = data[0];
112 output[1] = data[1];
113 output[2] = data[2];
114 output[3] = data[3];
115}
116
117[[nodiscard]] inline uchar4 interpolate_nearest_byte(
118 const uchar *buffer, int width, int height, float u, float v)
119{
120 uchar4 res;
121 interpolate_nearest_byte(buffer, res, width, height, u, v);
122 return res;
123}
124
126 const float *buffer, float *output, int width, int height, int components, float u, float v)
127{
128 BLI_assert(buffer);
129 const int x = math::clamp(int(u), 0, width - 1);
130 const int y = math::clamp(int(v), 0, height - 1);
131
132 const float *data = buffer + (int64_t(width) * y + x) * components;
133 for (int i = 0; i < components; i++) {
134 output[i] = data[i];
135 }
136}
137
138[[nodiscard]] inline float4 interpolate_nearest_fl(
139 const float *buffer, int width, int height, float u, float v)
140{
141 float4 res;
142 interpolate_nearest_fl(buffer, res, width, height, 4, u, v);
143 return res;
144}
145
151 const uchar *buffer, uchar *output, int width, int height, float u, float v)
152{
153 BLI_assert(buffer);
154 u = floored_fmod(u, float(width));
155 v = floored_fmod(v, float(height));
156 int x = int(u);
157 int y = int(v);
158 BLI_assert(x >= 0 && y >= 0 && x < width && y < height);
159
160 const uchar *data = buffer + (int64_t(width) * y + x) * 4;
161 output[0] = data[0];
162 output[1] = data[1];
163 output[2] = data[2];
164 output[3] = data[3];
165}
166
168 const uchar *buffer, int width, int height, float u, float v)
169{
170 uchar4 res;
171 interpolate_nearest_wrap_byte(buffer, res, width, height, u, v);
172 return res;
173}
174
176 const float *buffer, float *output, int width, int height, int components, float u, float v)
177{
178 BLI_assert(buffer);
179 u = floored_fmod(u, float(width));
180 v = floored_fmod(v, float(height));
181 int x = int(u);
182 int y = int(v);
183 BLI_assert(x >= 0 && y >= 0 && x < width && y < height);
184
185 const float *data = buffer + (int64_t(width) * y + x) * components;
186 for (int i = 0; i < components; i++) {
187 output[i] = data[i];
188 }
189}
190
192 const float *buffer, int width, int height, float u, float v)
193{
194 float4 res;
195 interpolate_nearest_wrap_fl(buffer, res, width, height, 4, u, v);
196 return res;
197}
198
211 const uchar *buffer, int width, int height, float u, float v);
212
214 const float *buffer, int width, int height, float u, float v);
215
217 const float *buffer, float *output, int width, int height, int components, float u, float v);
218
231 const uchar *buffer, int width, int height, float u, float v);
232
233[[nodiscard]] float4 interpolate_bilinear_fl(
234 const float *buffer, int width, int height, float u, float v);
235
237 const float *buffer, float *output, int width, int height, int components, float u, float v);
238
245 const uchar *buffer, int width, int height, float u, float v);
246
248 const float *buffer, int width, int height, float u, float v);
249
250void interpolate_bilinear_wrap_fl(const float *buffer,
251 float *output,
252 int width,
253 int height,
254 int components,
255 float u,
256 float v,
257 bool wrap_x,
258 bool wrap_y);
259
273 const uchar *buffer, int width, int height, float u, float v);
274
276 const float *buffer, int width, int height, float u, float v);
277
279 const float *buffer, float *output, int width, int height, int components, float u, float v);
280
294 const uchar *buffer, int width, int height, float u, float v);
295
297 const float *buffer, int width, int height, float u, float v);
298
300 const float *buffer, float *output, int width, int height, int components, float u, float v);
301
302} // namespace blender::math
303
304#define EWA_MAXIDX 255
305extern const float EWA_WTS[EWA_MAXIDX + 1];
306
307using ewa_filter_read_pixel_cb = void (*)(void *userdata, int x, int y, float result[4]);
308
310 float A, float B, float C, float F, float *a, float *b, float *th, float *ecc);
311
316void BLI_ewa_filter(int width,
317 int height,
318 bool intpol,
319 bool use_alpha,
320 const float uv[2],
321 const float du[2],
322 const float dv[2],
323 ewa_filter_read_pixel_cb read_pixel_cb,
324 void *userdata,
325 float result[4]);
#define BLI_assert(a)
Definition BLI_assert.h:50
MINLINE float floored_fmod(float f, float n)
void(*)(void *userdata, int x, int y, float result[4]) ewa_filter_read_pixel_cb
#define EWA_MAXIDX
const float EWA_WTS[EWA_MAXIDX+1]
void BLI_ewa_filter(int width, int height, bool intpol, bool use_alpha, const float uv[2], const float du[2], const float dv[2], ewa_filter_read_pixel_cb read_pixel_cb, void *userdata, float result[4])
void BLI_ewa_imp2radangle(float A, float B, float C, float F, float *a, float *b, float *th, float *ecc)
unsigned char uchar
ATTR_WARN_UNUSED_RESULT const BMVert * v
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define B
uchar4 interpolate_cubic_mitchell_byte(const uchar *buffer, int width, int height, float u, float v)
void interpolate_nearest_wrap_fl(const float *buffer, float *output, int width, int height, int components, float u, float v)
uchar4 interpolate_bilinear_wrap_byte(const uchar *buffer, int width, int height, float u, float v)
uchar4 interpolate_bilinear_byte(const uchar *buffer, int width, int height, float u, float v)
T clamp(const T &a, const T &min, const T &max)
void interpolate_nearest_fl(const float *buffer, float *output, int width, int height, int components, float u, float v)
void interpolate_nearest_border_fl(const float *buffer, float *output, int width, int height, int components, float u, float v)
float4 interpolate_bilinear_border_fl(const float *buffer, int width, int height, float u, float v)
float4 interpolate_bilinear_wrap_fl(const float *buffer, int width, int height, float u, float v)
float4 interpolate_cubic_bspline_fl(const float *buffer, int width, int height, float u, float v)
void interpolate_nearest_byte(const uchar *buffer, uchar *output, int width, int height, float u, float v)
float4 interpolate_bilinear_fl(const float *buffer, int width, int height, float u, float v)
float4 interpolate_cubic_mitchell_fl(const float *buffer, int width, int height, float u, float v)
void interpolate_nearest_wrap_byte(const uchar *buffer, uchar *output, int width, int height, float u, float v)
uchar4 interpolate_cubic_bspline_byte(const uchar *buffer, int width, int height, float u, float v)
uchar4 interpolate_bilinear_border_byte(const uchar *buffer, int width, int height, float u, float v)
void interpolate_nearest_border_byte(const uchar *buffer, uchar *output, int width, int height, float u, float v)
__int64 int64_t
Definition stdint.h:89