50 void init(
const float3x3 &transform_matrix,
const bool has_source_crop)
55 init_destination_region(transform_matrix, has_source_crop);
59 void init_destination_region(
const float3x3 &transform_matrix,
const bool has_source_crop)
61 if (!has_source_crop) {
76 for (
int i = 0; i < 4; i++) {
77 int2 src_co = src_coords[i];
104 return image->byte_data_for_write() + (size_t(
y) *
image->x +
x) *
image->channels;
108 return image->float_data_for_write() + (size_t(
y) *
image->x +
x) *
image->channels;
124template<eIMBInterpolationFilterMode Filter,
typename T,
int NumChannels,
bool WrapUV>
127 if constexpr (WrapUV) {
150 if constexpr (WrapUV) {
163 source->
float_data(), r_sample, source->
x, source->
y, NumChannels, u,
v);
168 source->
float_data(), r_sample, source->
x, source->
y, NumChannels, u,
v);
172 source->
float_data(), r_sample, source->
x, source->
y, NumChannels, u,
v);
181 source->
float_data(), r_sample, source->
x, source->
y, NumChannels, u,
v);
224 if constexpr (SrcChannels == 4) {
227 else if constexpr (SrcChannels == 3) {
230 else if constexpr (SrcChannels == 2) {
233 else if constexpr (SrcChannels == 1) {
266 const float inv_count = 1.0f / (sub_count_x * sub_count_y);
270 for (
int yi : y_range) {
277 for (
int sub_y = 0; sub_y < sub_count_y; sub_y++) {
278 for (
int sub_x = 0; sub_x < sub_count_x; sub_x++) {
279 float2 delta = (sub_x + 0.5f) * sub_step_x + (sub_y + 0.5f) * sub_step_y;
280 float2 sub_uv = uv + delta;
286 WrapUV>(ctx.
src, sub_uv.x, sub_uv.y, sub_sample);
303 for (
int yi : y_range) {
319template<eIMBInterpolationFilterMode Filter,
typename T,
int SrcChannels>
338template<eIMBInterpolationFilterMode Filter>
348 else if (channels == 3) {
351 else if (channels == 2) {
354 else if (channels == 1) {
374 cov =
fabsf(ipos.x - pos.x);
380 cov =
fabsf(ipos.y - pos.y);
400 for (
int line_idx = 0; line_idx < 4; line_idx++) {
409 bool is_steep =
length == abs_delta.y;
414 constexpr float NO_ROTATION = 1.0e-6f;
415 constexpr float NO_AA_CONTRIB = 1.0e-2f;
417 if ((abs_delta.x < NO_ROTATION) && (
fabsf(ptA.x -
roundf(ptA.x)) < NO_AA_CONTRIB)) {
422 if ((abs_delta.y < NO_ROTATION) && (
fabsf(ptA.y -
roundf(ptA.y)) < NO_AA_CONTRIB)) {
430 for (
int i = 0; i <
length; i++) {
431 float2 pos = ptA + i * delta;
433 if (ipos.x >= 0 && ipos.x < ctx.
dst->
x && ipos.y >= 0 && ipos.y < ctx.
dst->
y) {
435 size_t idx = (size_t(ipos.y) * ctx.
dst->
x + ipos.x) * 4;
444 for (
int i = 0; i <
length; i++) {
445 float2 pos = ptA + i * delta;
447 if (ipos.x >= 0 && ipos.x < ctx.
dst->
x && ipos.y >= 0 && ipos.y < ctx.
dst->
y) {
449 size_t idx = (size_t(ipos.y) * ctx.
dst->
x + ipos.x) * 4;
465 const rctf *src_crop)
468 "No source crop rect given, but crop source is requested. Or source crop rect "
469 "was given, but crop source was not requested.");
480 ctx.
init(transform_matrix, crop);
483 if (filter == IMB_FILTER_NEAREST) {
484 transform_scanlines_filter<IMB_FILTER_NEAREST>(ctx, y_range);
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
constexpr int64_t first() const
constexpr IndexRange()=default
MatBase< C, R > inverse(MatBase< C, R >) RET
float length(VecOp< float, D >) RET
float4 interpolate_bilinear_fl(const ImBuf *in, float u, float v)
uchar4 interpolate_nearest_border_byte(const ImBuf *in, float u, float v)
uchar4 interpolate_bilinear_byte(const ImBuf *in, float u, float v)
uchar4 interpolate_cubic_mitchell_byte(const ImBuf *in, float u, float v)
uchar4 interpolate_cubic_bspline_byte(const ImBuf *in, float u, float v)
T clamp(const T &a, const T &min, const T &max)
void interpolate_nearest_border_fl(const float *buffer, float *output, int width, int height, int components, float u, float v)
T length(const VecBase< T, Size > &a)
float4 interpolate_cubic_bspline_fl(const float *buffer, int width, int height, float u, float v)
CartesianBasis invert(const CartesianBasis &basis)
float4 interpolate_bilinear_fl(const float *buffer, int width, int height, float u, float v)
BLI_INLINE void interpolate_bilinear_wrapmode_fl(const float *buffer, float *output, int width, int height, int components, float u, float v, InterpWrapMode wrap_x, InterpWrapMode wrap_y)
float4 interpolate_cubic_mitchell_fl(const float *buffer, int width, int height, float u, float v)
T max(const T &a, const T &b)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
void BLI_rcti_init_minmax(struct rcti *rect)
MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2])
void IMB_transform(const ImBuf *src, ImBuf *dst, eIMBTransformMode mode, eIMBInterpolationFilterMode filter, const float3x3 &transform_matrix, const rctf *src_crop)
Transform source image buffer onto destination image buffer using a transform matrix.
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
MINLINE void add_v4_v4(float r[4], const float a[4])
eIMBInterpolationFilterMode
@ IMB_FILTER_CUBIC_BSPLINE
@ IMB_FILTER_CUBIC_MITCHELL
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
MatBase< float, 3, 3 > float3x3
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4])
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4])
eIMBTransformMode
Transform modes to use for IMB_transform function.
@ IMB_TRANSFORM_MODE_REGULAR
Do not crop or repeat.
@ IMB_TRANSFORM_MODE_WRAP_REPEAT
Wrap repeat the source buffer. Only supported in with nearest filtering.
@ IMB_TRANSFORM_MODE_CROP_SRC
Crop the source buffer.
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
const float * float_data() const
float * float_data_for_write()
IndexRange dst_region_y_range
void init(const float3x3 &transform_matrix, const bool has_source_crop)
IndexRange dst_region_x_range