30 uchar *p1, *_p1, *dest;
33 float af, rf, gf, bf, *p1f, *_p1f, *destf;
34 bool do_rect, do_float;
45 for (
y = ibuf2->
y;
y > 0;
y--) {
48 for (
x = ibuf2->
x;
x > 0;
x--) {
72 *(destf++) = 0.5f * af;
73 *(destf++) = 0.5f * bf;
74 *(destf++) = 0.5f * gf;
75 *(destf++) = 0.5f * rf;
79 _p1 += (ibuf1->
x << 2);
82 _p1f += (ibuf1->
x << 2);
91 if (ibuf1 ==
nullptr) {
103 if (ibuf2 ==
nullptr) {
114 uchar *p1, *p2, *_p1, *dest;
117 float af, rf, gf, bf, *p1f, *p2f, *_p1f, *destf;
131 for (
y = ibuf2->
y;
y > 0;
y--) {
134 p2 = _p1 + (ibuf1->
x << 2);
138 p2f = _p1f + (ibuf1->
x << 2);
140 for (
x = ibuf2->
x;
x > 0;
x--) {
164 *(destf++) = 0.5f * af;
165 *(destf++) = 0.5f * bf;
166 *(destf++) = 0.5f * gf;
167 *(destf++) = 0.5f * rf;
171 _p1 += (ibuf1->
x << 3);
174 _p1f += (ibuf1->
x << 3);
183 if (ibuf1 ==
nullptr) {
195 if (ibuf2 ==
nullptr) {
211 result[0] = color[0] * alpha;
212 result[1] = color[1] * alpha;
213 result[2] = color[2] * alpha;
219 if (color[3] <= 255) {
226 ushort alpha = color[3] / 256;
256 uchar *cp1, *cp2, *dest;
261 for (
y = ibuf2->
y;
y > 0;
y--) {
262 cp2 = cp1 + (ibuf1->
x << 2);
263 for (
x = ibuf2->
x;
x > 0;
x--) {
264 ushort p1i[8], p2i[8], desti[4];
271 desti[0] = (
uint(p1i[0]) + p2i[0] + p1i[4] + p2i[4]) >> 2;
272 desti[1] = (
uint(p1i[1]) + p2i[1] + p1i[5] + p2i[5]) >> 2;
273 desti[2] = (
uint(p1i[2]) + p2i[2] + p1i[6] + p2i[6]) >> 2;
274 desti[3] = (
uint(p1i[3]) + p2i[3] + p1i[7] + p2i[7]) >> 2;
290 float *p1f, *p2f, *destf;
294 for (
y = ibuf2->
y;
y > 0;
y--) {
295 p2f = p1f + (ibuf1->
x << 2);
296 for (
x = ibuf2->
x;
x > 0;
x--) {
297 destf[0] = 0.25f * (p1f[0] + p2f[0] + p1f[4] + p2f[4]);
298 destf[1] = 0.25f * (p1f[1] + p2f[1] + p1f[5] + p2f[5]);
299 destf[2] = 0.25f * (p1f[2] + p2f[2] + p1f[6] + p2f[6]);
300 destf[3] = 0.25f * (p1f[3] + p2f[3] + p1f[7] + p2f[7]);
317 if (ibuf1 ==
nullptr) {
332 if (ibuf2 ==
nullptr) {
344 *r_dst_byte =
nullptr;
347 if (*r_dst_byte ==
nullptr) {
351 *r_dst_float =
nullptr;
355 if (*r_dst_float ==
nullptr) {
394 memcpy(
ptr, &pix,
sizeof(*
ptr));
398 memcpy(
ptr, &pix,
sizeof(*
ptr));
407 static void op(
const T *src,
T *dst,
int ibufx,
int ibufy,
int newx,
int ,
bool threaded)
410 const float add = (ibufx - 0.01f) / newx;
411 const float inv_add = 1.0f /
add;
413 const int grain_size = threaded ? 32 : ibufy;
415 for (
const int y : range) {
416 const T *src_ptr = src + (
int64_t(
y) * ibufx);
421 for (
int x = 0;
x < newx;
x++) {
446 static void op(
const T *src,
T *dst,
int ibufx,
int ibufy,
int ,
int newy,
bool threaded)
449 const float add = (ibufy - 0.01f) / newy;
450 const float inv_add = 1.0f /
add;
452 const int grain_size = threaded ? 32 : ibufx;
454 for (
const int x : range) {
455 const T *src_ptr = src +
x;
456 T *dst_ptr = dst +
x;
460 for (
int y = 0;
y < newy;
y++) {
485 static void op(
const T *src,
T *dst,
int ibufx,
int ibufy,
int newx,
int ,
bool threaded)
488 const float add = (ibufx - 0.001f) / newx;
491 for (
int y = ibufy;
y > 0;
y--) {
492 for (
int x = newx;
x > 0;
x--) {
500 const int grain_size = threaded ? 32 : ibufy;
502 for (
const int y : range) {
505 const T *src_ptr = src + (
int64_t(
y) * ibufx);
514 for (
int x = 0;
x < newx;
x++) {
520 if (counter + 1 < ibufx) {
538 static void op(
const T *src,
T *dst,
int ibufx,
int ibufy,
int ,
int newy,
bool threaded)
541 const float add = (ibufy - 0.001f) / newy;
544 for (
int y = newy;
y > 0;
y--) {
545 memcpy(dst, src,
sizeof(
T) * ibufx);
550 const int grain_size = threaded ? 32 : ibufx;
552 for (
const int x : range) {
555 const T *src_ptr = src +
x;
556 T *dst_ptr = dst +
x;
562 src_ptr += ibufx * 2;
566 for (
int y = 0;
y < newy;
y++) {
572 if (counter + 1 < ibufy) {
597 if (dst_byte !=
nullptr) {
599 T::op(src, dst_byte, ibuf->
x, ibuf->
y, newx, newy, threaded);
601 if (dst_float !=
nullptr) {
607 T::op(src, (
float2 *)dst_float, ibuf->
x, ibuf->
y, newx, newy, threaded);
611 T::op(src, (
float3 *)dst_float, ibuf->
x, ibuf->
y, newx, newy, threaded);
615 T::op(src, (
float4 *)dst_float, ibuf->
x, ibuf->
y, newx, newy, threaded);
621 const ImBuf *ibuf,
int newx,
int newy,
uchar4 *dst_byte,
float *dst_float,
bool threaded)
628 const ImBuf *ibuf,
int newx,
int newy,
uchar4 *dst_byte,
float *dst_float,
bool threaded)
635 const ImBuf *ibuf,
int newx,
int newy,
uchar4 *dst_byte,
float *dst_float,
bool threaded)
642 const ImBuf *ibuf,
int newx,
int newy,
uchar4 *dst_byte,
float *dst_float,
bool threaded)
649 const ImBuf *ibuf,
int newx,
int newy,
uchar4 *dst_byte,
float *dst_float,
bool threaded);
654 uchar4 *dst_byte =
nullptr;
655 float *dst_float =
nullptr;
657 if (dst_byte ==
nullptr && dst_float ==
nullptr) {
662 func(ibuf, newx, newy, dst_byte, dst_float, threaded);
665 if (dst_byte !=
nullptr) {
669 if (dst_float !=
nullptr) {
679 if (newx != 0 && (newx < ibuf->
x)) {
682 if (newy != 0 && (newy < ibuf->
y)) {
685 if (newx != 0 && (newx > ibuf->
x)) {
688 if (newy != 0 && (newy > ibuf->
y)) {
698 constexpr int FRAC_BITS = 16;
699 int64_t stepx = ((
int64_t(ibufx) << FRAC_BITS) + newx / 2) / newx;
700 int64_t stepy = ((
int64_t(ibufy) << FRAC_BITS) + newy / 2) / newy;
702 dst += y_range.
first() * newx;
703 for (
const int y : y_range) {
705 const T *row = src + (posy >> FRAC_BITS) * ibufx;
707 for (
int x = 0;
x < newx;
x++, posx += stepx) {
708 *dst = row[posx >> FRAC_BITS];
716 const ImBuf *ibuf,
int newx,
int newy,
uchar4 *dst_byte,
float *dst_float,
bool threaded)
720 const int grain_size = threaded ? 64 : newy;
723 if (dst_byte !=
nullptr) {
728 if (dst_float !=
nullptr) {
749 const ImBuf *ibuf,
int newx,
int newy,
uchar4 *dst_byte,
float *dst_float,
bool threaded)
754 const int grain_size = threaded ? 32 : newy;
756 float factor_x = float(ibuf->
x) / newx;
757 float factor_y = float(ibuf->
y) / newy;
759 for (
const int y : y_range) {
760 float v = (float(
y) + 0.5f) * factor_y - 0.5f;
761 for (
int x = 0;
x < newx;
x++) {
762 float u = (float(
x) + 0.5f) * factor_x - 0.5f;
768 float *pixel = dst_float + ibuf->
channels * offset;
779 BLI_assert_msg(newx > 0 && newy > 0,
"Images must be at least 1 on both dimensions!");
780 if (ibuf ==
nullptr) {
783 if (newx == ibuf->
x && newy == ibuf->
y) {
804 BLI_assert_msg(newx > 0 && newy > 0,
"Images must be at least 1 on both dimensions!");
805 if (ibuf ==
nullptr) {
809 if (newx == ibuf->
x && newy == ibuf->
y) {
816 uchar4 *dst_byte =
nullptr;
817 float *dst_float =
nullptr;
819 if (dst_byte ==
nullptr && dst_float ==
nullptr) {
832 uchar4 *tmp_byte =
nullptr;
833 float *tmp_float =
nullptr;
835 if (tmp_byte ==
nullptr && tmp_float ==
nullptr) {
836 if (dst_byte !=
nullptr) {
839 if (dst_byte !=
nullptr) {
844 if (newx < ibuf->
x) {
854 if (tmp_byte !=
nullptr) {
858 if (tmp_float !=
nullptr) {
861 if (newy < ibuf->
y) {
868 if (tmp_byte !=
nullptr) {
871 if (tmp_float !=
nullptr) {
882 if (dst_byte !=
nullptr) {
886 if (dst_float !=
nullptr) {
#define BLI_assert_msg(a, msg)
Function declarations for filter.cc.
ImBuf * IMB_dupImBuf(const ImBuf *ibuf1)
void IMB_assign_float_buffer(ImBuf *ibuf, float *buffer_data, ImBufOwnership ownership)
bool IMB_alloc_byte_pixels(ImBuf *ibuf, bool initialize_pixels=true)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
void IMB_free_float_pixels(ImBuf *ibuf)
void IMB_free_byte_pixels(ImBuf *ibuf)
bool IMB_initImBuf(ImBuf *ibuf, unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
void IMB_assign_byte_buffer(ImBuf *ibuf, uint8_t *buffer_data, ImBufOwnership ownership)
@ IB_DO_NOT_TAKE_OWNERSHIP
@ IB_uninitialized_pixels
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v
constexpr int64_t first() const
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
MINLINE unsigned char unit_ushort_to_uchar(unsigned short val)
static void add(blender::Map< std::string, std::string > &messages, Message &msg)
uchar4 interpolate_bilinear_byte(const ImBuf *in, 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))
blender::VecBase< uint8_t, 4 > uchar4
VecBase< float, 4 > float4
VecBase< float, 2 > float2
VecBase< float, 3 > float3
MINLINE void straight_uchar_to_premul_ushort(ushort result[4], const uchar color[4])
static void alloc_scale_dst_buffers(const ImBuf *ibuf, uint newx, uint newy, uchar4 **r_dst_byte, float **r_dst_float)
ImBuf * IMB_onehalf(ImBuf *ibuf1)
static void scale_nearest(const T *src, T *dst, int ibufx, int ibufy, int newx, int newy, blender::IndexRange y_range)
ImBuf * IMB_scale_into_new(const ImBuf *ibuf, uint newx, uint newy, IMBScaleFilter filter, bool threaded)
bool IMB_scale(ImBuf *ibuf, uint newx, uint newy, IMBScaleFilter filter, bool threaded)
void(*)( const ImBuf *ibuf, int newx, int newy, uchar4 *dst_byte, float *dst_float, bool threaded) ScaleFunction
ImBuf * IMB_half_x(ImBuf *ibuf1)
static void scale_with_function(ImBuf *ibuf, int newx, int newy, ScaleFunction func, bool threaded)
ImBuf * IMB_half_y(ImBuf *ibuf1)
void imb_onehalf_no_alloc(ImBuf *ibuf2, ImBuf *ibuf1)
static void imb_scale_box(ImBuf *ibuf, uint newx, uint newy, bool threaded)
static void imb_half_x_no_alloc(ImBuf *ibuf2, ImBuf *ibuf1)
static void scale_up_y_func(const ImBuf *ibuf, int newx, int newy, uchar4 *dst_byte, float *dst_float, bool threaded)
MINLINE void premul_ushort_to_straight_uchar(uchar *result, const ushort color[4])
static void scale_down_y_func(const ImBuf *ibuf, int newx, int newy, uchar4 *dst_byte, float *dst_float, bool threaded)
static void store_pixel(float4 pix, uchar4 *ptr)
static void imb_half_y_no_alloc(ImBuf *ibuf2, ImBuf *ibuf1)
static void scale_bilinear_func(const ImBuf *ibuf, int newx, int newy, uchar4 *dst_byte, float *dst_float, bool threaded)
static void scale_nearest_func(const ImBuf *ibuf, int newx, int newy, uchar4 *dst_byte, float *dst_float, bool threaded)
static void scale_down_x_func(const ImBuf *ibuf, int newx, int newy, uchar4 *dst_byte, float *dst_float, bool threaded)
static void instantiate_pixel_op(T &, const ImBuf *ibuf, int newx, int newy, uchar4 *dst_byte, float *dst_float, bool threaded)
static void scale_up_x_func(const ImBuf *ibuf, int newx, int newy, uchar4 *dst_byte, float *dst_float, bool threaded)
static float4 load_pixel(const uchar4 *ptr)
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
static void op(const T *src, T *dst, int ibufx, int ibufy, int newx, int, bool threaded)
static void op(const T *src, T *dst, int ibufx, int ibufy, int, int newy, bool threaded)
static void op(const T *src, T *dst, int ibufx, int ibufy, int newx, int, bool threaded)
static void op(const T *src, T *dst, int ibufx, int ibufy, int, int newy, bool threaded)