36 return float4(ptr[0], 0.0f, 1.0f);
40 return float4(ptr[0], 1.0f);
56 memcpy(
reinterpret_cast<void *
>(ptr), &pix,
sizeof(*ptr));
60 memcpy(
reinterpret_cast<void *
>(ptr), &pix,
sizeof(*ptr));
67template<
typename BufferT,
typename Fn>
73 if constexpr (std::is_same_v<BufferT, uchar>) {
74 fn(
reinterpret_cast<const uchar4 *
>(src_buffer),
reinterpret_cast<uchar4 *
>(dst_buffer));
78 fn(src_buffer, dst_buffer);
80 else if (channels == 2) {
81 const float2 *src =
reinterpret_cast<const float2 *
>(src_buffer);
82 fn(src,
reinterpret_cast<float2 *
>(dst_buffer));
84 else if (channels == 3) {
85 const float3 *src =
reinterpret_cast<const float3 *
>(src_buffer);
86 fn(src,
reinterpret_cast<float3 *
>(dst_buffer));
88 else if (channels == 4) {
89 const float4 *src =
reinterpret_cast<const float4 *
>(src_buffer);
90 fn(src,
reinterpret_cast<float4 *
>(dst_buffer));
95template<
typename BufferT>
104 const int newx = dst_size.x;
105 const int ibufx = src_size.x;
106 const int ibufy = src_size.y;
108 const float add = (ibufx - 0.01f) / newx;
109 const float inv_add = 1.0f / add;
111 const int grain_size = threaded ? 32 : ibufy;
113 for (
const int y : range) {
114 const T *src_ptr = src + (
int64_t(
y) * src_stride);
119 for (
int x = 0;
x < newx;
x++) {
142template<
typename BufferT>
150 const int newy = dst_size.y;
151 const int ibufx = src_size.x;
152 const int ibufy = src_size.y;
154 const float add = (ibufy - 0.01f) / newy;
155 const float inv_add = 1.0f / add;
157 const int grain_size = threaded ? 32 : ibufx;
159 for (
const int x : range) {
160 const T *src_ptr = src +
x;
161 T *dst_ptr = dst +
x;
165 for (
int y = 0;
y < newy;
y++) {
188template<
typename BufferT>
191 const int src_stride,
197 const int newx = dst_size.x;
198 const int ibufx = src_size.x;
199 const int ibufy = src_size.y;
201 const float add = (ibufx - 0.001f) / newx;
203 if (ibufx == 1) [[unlikely]] {
204 for (
int y = ibufy;
y > 0;
y--) {
205 for (
int x = newx;
x > 0;
x--) {
213 const int grain_size = threaded ? 32 : ibufy;
215 for (
const int y : range) {
216 float sample = -0.5f + add * 0.5f;
218 const T *src_ptr = src + (
int64_t(
y) * src_stride);
227 for (
int x = 0;
x < newx;
x++) {
233 if (counter + 1 < ibufx) {
249template<
typename BufferT>
257 const int newy = dst_size.y;
258 const int ibufx = src_size.x;
259 const int ibufy = src_size.y;
261 const float add = (ibufy - 0.001f) / newy;
263 if (ibufy == 1) [[unlikely]] {
264 for (
int y = newy;
y > 0;
y--) {
265 memcpy(
reinterpret_cast<void *
>(dst), src,
sizeof(
T) * ibufx);
270 const int grain_size = threaded ? 32 : ibufx;
272 for (
const int x : range) {
273 float sample = -0.5f + add * 0.5f;
275 const T *src_ptr = src +
x;
276 T *dst_ptr = dst +
x;
282 src_ptr += ibufx * 2;
286 for (
int y = 0;
y < newy;
y++) {
292 if (counter + 1 < ibufy) {
308template<
typename BufferT>
315 const int src_stride = 0)
317 const int stride = (src_stride != 0) ? src_stride : src_size.x;
319 int64_t(channels) * dst_size.x * src_size.y, __func__);
320 if (dst_size.x < src_size.x) {
326 int2(dst_size.x, src_size.y),
335 int2(dst_size.x, src_size.y),
339 if (dst_size.y < src_size.y) {
341 tmp_buffer,
int2(dst_size.x, src_size.y), channels, dst_buffer, dst_size, threaded);
345 tmp_buffer,
int2(dst_size.x, src_size.y), channels, dst_buffer, dst_size, threaded);
348 MEM_delete(tmp_buffer);
357 const int src_stride)
359 imb_scale_box(src_buffer, src_size, channels, dst_buffer, dst_size, threaded, src_stride);
368 const int src_stride)
370 imb_scale_box(src_buffer, src_size, channels, dst_buffer, dst_size, threaded, src_stride);
377 const int ibufx = src_size.x;
378 const int ibufy = src_size.y;
379 const int newx = dst_size.x;
380 const int newy = dst_size.y;
382 constexpr int FRAC_BITS = 16;
383 int64_t stepx = ((
int64_t(ibufx) << FRAC_BITS) + newx / 2) / newx;
384 int64_t stepy = ((
int64_t(ibufy) << FRAC_BITS) + newy / 2) / newy;
386 dst += y_range.
first() * newx;
387 for (
const int y : y_range) {
389 const T *row = src + (posy >> FRAC_BITS) * ibufx;
391 for (
int x = 0;
x < newx;
x++, posx += stepx) {
392 *dst = row[posx >> FRAC_BITS];
399template<
typename BufferT>
407 const int grain_size = threaded ? 64 : dst_size.y;
409 if constexpr (std::is_same_v<BufferT, uchar>) {
410 const uchar4 *src = reinterpret_cast<const uchar4 *>(src_buffer);
411 scale_nearest(src, reinterpret_cast<uchar4 *>(dst_buffer), src_size, dst_size, y_range);
415 scale_nearest(src_buffer, dst_buffer, src_size, dst_size, y_range);
417 else if (channels == 2) {
418 const float2 *src =
reinterpret_cast<const float2 *
>(src_buffer);
421 else if (channels == 3) {
422 const float3 *src =
reinterpret_cast<const float3 *
>(src_buffer);
425 else if (channels == 4) {
426 const float4 *src =
reinterpret_cast<const float4 *
>(src_buffer);
433template<
typename BufferT>
441 const int newx = dst_size.x;
442 const int newy = dst_size.y;
444 const int grain_size = threaded ? 32 : newy;
446 float factor_x =
float(src_size.x) / newx;
447 float factor_y =
float(src_size.y) / newy;
449 for (
const int y : y_range) {
450 float v = (
float(
y) + 0.5f) * factor_y - 0.5f;
451 for (
int x = 0;
x < newx;
x++) {
452 float u = (
float(
x) + 0.5f) * factor_x - 0.5f;
454 if constexpr (std::is_same_v<BufferT, uchar>) {
456 src_buffer, src_size.x, src_size.y, u,
v);
459 float *pixel = dst_buffer + channels * offset;
470 "Images must be at least 1 on both dimensions!");
471 if (ibuf ==
nullptr) {
475 if (src_size == new_size) {
483 size_t(ibuf->
channels) * new_size.x * new_size.y, __func__);
498 size_t(ibuf->
channels) * new_size.x * new_size.y, __func__);
513 size_t(ibuf->
channels) * new_size.x * new_size.y, __func__);
526 ibuf->
x = new_size.x;
527 ibuf->
y = new_size.y;
537 "Images must be at least 1 on both dimensions!");
538 if (ibuf ==
nullptr) {
543 if (src_size == new_size) {
561 if (dst_byte ==
nullptr && dst_float ==
nullptr) {
590 imb_scale_box(src, src_size, 4, dst_byte, new_size, threaded);
Function declarations for filter.cc.
Read Blender memory allocation and freeing.
#define BLI_assert_msg(a, msg)
constexpr int64_t first() const
constexpr IndexRange()=default
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
uchar4 interpolate_bilinear_byte(const uchar *buffer, int width, int height, float u, float v)
float4 interpolate_bilinear_fl(const float *buffer, int width, int height, float u, float v)
T max(const T &a, const T &b)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
static void scale_nearest_func(const BufferT *src_buffer, const int2 src_size, const int channels, BufferT *dst_buffer, const int2 dst_size, bool threaded)
VecBase< uint8_t, 4 > uchar4
static float4 load_pixel(const uchar4 *ptr)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void scale_bilinear(const BufferT *src_buffer, const int2 src_size, const int channels, BufferT *dst_buffer, const int2 dst_size, bool threaded)
static void scale_nearest(const T *src, T *dst, const int2 src_size, const int2 dst_size, IndexRange y_range)
ATTR_WARN_UNUSED_RESULT const BMVert * v
ImBuf * IMB_dupImBuf(const ImBuf *ibuf1)
static void to_static_pixel_type(const BufferT *src_buffer, const int channels, BufferT *dst_buffer, const Fn &fn)
VecBase< float, 4 > float4
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
static void scale_down_y_func(const BufferT *src_buffer, const int2 src_size, const int channels, BufferT *dst_buffer, const int2 dst_size, bool threaded)
static void store_pixel(float4 pix, uchar4 *ptr)
void IMB_scale_box(const float *src_buffer, int2 src_size, int channels, float *dst_buffer, int2 dst_size, bool threaded, int src_stride=0)
static void imb_scale_box(const BufferT *src_buffer, const int2 src_size, const int channels, BufferT *dst_buffer, const int2 dst_size, const bool threaded, const int src_stride=0)
static void scale_up_y_func(const BufferT *src_buffer, const int2 src_size, const int channels, BufferT *dst_buffer, const int2 dst_size, bool threaded)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
static void scale_down_x_func(const BufferT *src_buffer, const int2 src_size, const int src_stride, const int channels, BufferT *dst_buffer, const int2 dst_size, bool threaded)
void IMB_metadata_copy(ImBuf *ibuf_dst, const ImBuf *ibuf_src)
VecBase< float, 3 > float3
ImBuf * IMB_scale_into_new(const ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
bool IMB_scale(ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
static void scale_up_x_func(const BufferT *src_buffer, const int2 src_size, const int src_stride, const int channels, BufferT *dst_buffer, const int2 dst_size, bool threaded)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
const float * float_data() const
void assign_byte_data(uint8_t *data)
float * float_data_for_write()
void assign_float_data(float *data)