347 const int2 &dst_size,
348 const void *src_void,
349 const int2 &src_size,
351 const int2 &src_rect_pos,
352 const int2 &dst_rect_pos,
358 BLI_assert(src_rect_pos.x >= 0 && src_rect_pos.y >= 0);
359 BLI_assert(dst_rect_pos.x >= 0 && dst_rect_pos.y >= 0);
361 (src_rect_pos.y +
rect_size.y) <= src_size.y);
363 (dst_rect_pos.y +
rect_size.y) <= dst_size.y);
364 auto *dst =
static_cast<std::byte *
>(dst_void);
365 const auto *src =
static_cast<const std::byte *
>(src_void);
367 const int src_y = src_rect_pos.y + rect_y;
368 const int dst_y = dst_rect_pos.y + rect_y;
369 const std::byte *row_src = src + size_t(src_size.x) * stride * src_y;
370 std::byte *row_dst = dst + size_t(dst_size.x) * stride * dst_y;
371 std::copy_n(row_src +
size_t(src_rect_pos.x) * stride,
373 row_dst +
size_t(dst_rect_pos.x) * stride);
378 const int2 &src_size,
380 const int2 &src_rect_pos,
392 const int2 &src_size,
394 const int2 &src_rect_pos,
398 const int stride = (channels == 0 ? 4 : channels) *
sizeof(
float);
399 return static_cast<float *
>(
404 const int2 &src_size,
405 const int2 &src_rect_pos,
409 const int stride = 4 *
sizeof(
uchar);
410 return static_cast<uchar *
>(
415 const int2 &dst_size,
417 const int2 &src_size,
419 const int2 &src_rect_pos,
420 const int2 &dst_rect_pos,
424 const int stride = (channels == 0 ? 4 : channels) *
sizeof(
float);
426 dst, dst_size, src, src_size, stride, src_rect_pos, dst_rect_pos,
rect_size);
430 const int2 &dst_size,
432 const int2 &src_size,
433 const int2 &src_rect_pos,
434 const int2 &dst_rect_pos,
438 const int stride = 4 *
sizeof(
uchar);
440 dst, dst_size, src, src_size, stride, src_rect_pos, dst_rect_pos,
rect_size);
445 const int2 &src_rect_pos,
446 const int2 &dst_rect_pos,
472 const int2 src_size(ibuf->
x, ibuf->
y);
480 if (
const float *float_data = ibuf->
float_data()) {
492 if ((size[0] == ibuf->
x) && (size[1] == ibuf->
y)) {
522 if (dbuf ==
nullptr) {
547 tmp = dbuf->
x - *destx;
548 *width = std::min(*width, tmp);
549 tmp = dbuf->
y - *desty;
550 *height = std::min(*height, tmp);
553 tmp = sbuf->
x - *srcx;
554 *width = std::min(*width, tmp);
555 tmp = sbuf->
y - *srcy;
556 *height = std::min(*height, tmp);
559 if ((*height <= 0) || (*width <= 0)) {
579 if (dbuf ==
nullptr) {
621 tmp = dbuf->
x - *destx;
622 *width = std::min(*width, tmp);
623 tmp = dbuf->
y - *desty;
624 *height = std::min(*height, tmp);
627 tmp = obuf->
x - *origx;
628 *width = std::min(*width, tmp);
629 tmp = obuf->
y - *origy;
630 *height = std::min(*height, tmp);
634 tmp = sbuf->
x - *srcx;
635 *width = std::min(*width, tmp);
636 tmp = sbuf->
y - *srcy;
637 *height = std::min(*height, tmp);
640 if ((*height <= 0) || (*width <= 0)) {
651 float *dbuf_float_data,
669 uint *drect =
nullptr;
670 const uint *orect =
nullptr;
671 const uint *srect =
nullptr;
675 float *drectf =
nullptr;
676 const float *orectf =
nullptr;
677 const float *srectf =
nullptr;
681 const ushort *cmaskrect = curvemask, *cmr;
682 ushort *dmaskrect = dmask, *dmr;
683 const ushort *texmaskrect = texmask, *tmr;
684 int srcskip, destskip, origskip,
x;
688 if (dbuf ==
nullptr || obuf ==
nullptr) {
692 imb_rectclip3(dbuf, obuf, sbuf, &destx, &desty, &origx, &origy, &srcx, &srcy, &width, &height);
694 if (width == 0 || height == 0) {
704 const bool do_char = (sbuf && sbuf->
byte_data() && dbuf_byte_data && obuf->
byte_data());
708 drect =
reinterpret_cast<uint *
>(dbuf_byte_data) +
size_t(desty) * dbuf->
x + destx;
709 orect =
reinterpret_cast<const uint *
>(obuf->
byte_data()) + size_t(origy) * obuf->
x + origx;
712 drectf = dbuf_float_data + (size_t(desty) * dbuf->
x + destx) * 4;
713 orectf = obuf->
float_data() + (size_t(origy) * obuf->
x + origx) * 4;
717 dmaskrect += size_t(origy) * obuf->
x + origx;
725 srect =
reinterpret_cast<const uint *
>(sbuf->
byte_data()) + size_t(srcy) * sbuf->
x + srcx;
728 srectf = sbuf->
float_data() + (size_t(srcy) * sbuf->
x + srcx) * 4;
733 cmaskrect += size_t(srcy) * sbuf->
x + srcx;
737 texmaskrect += size_t(srcy) * sbuf->
x + srcx;
748 for (; height > 0; height--) {
752 for (
x = width;
x > 0;
x--, dr++, sr++) {
753 (
reinterpret_cast<char *
>(dr))[0] = (
reinterpret_cast<const char *
>(sr))[0];
754 (
reinterpret_cast<char *
>(dr))[1] = (
reinterpret_cast<const char *
>(sr))[1];
755 (
reinterpret_cast<char *
>(dr))[2] = (
reinterpret_cast<const char *
>(sr))[2];
764 for (
x = width;
x > 0;
x--, drf += 4, srf += 4) {
765 float map_alpha = (srf[3] == 0.0f) ? drf[3] : drf[3] / srf[3];
767 drf[0] = srf[0] * map_alpha;
768 drf[1] = srf[1] * map_alpha;
769 drf[2] = srf[2] * map_alpha;
771 drectf += destskip * 4;
772 srectf += srcskip * 4;
778 for (; height > 0; height--) {
782 for (
x = width;
x > 0;
x--, dr++, sr++) {
783 (
reinterpret_cast<char *
>(dr))[3] = (
reinterpret_cast<const char *
>(sr))[3];
792 for (
x = width;
x > 0;
x--, drf += 4, srf += 4) {
795 drectf += destskip * 4;
796 srectf += srcskip * 4;
904 for (; height > 0; height--) {
918 for (
x = width;
x > 0;
x--, dr++, outr++, sr++, dmr++, cmr++) {
919 const uchar *src =
reinterpret_cast<const uchar *
>(sr);
920 float mask_lim = mask_max * (*cmr);
923 mask_lim *= ((*tmr++) / 65535.0f);
926 if (src[3] && mask_lim) {
930 mask = *dmr + mask_lim;
933 mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
943 mask_src[0] = src[0];
944 mask_src[1] = src[1];
945 mask_src[2] = src[2];
948 mask_src[3] = src[3];
950 reinterpret_cast<const uchar *
>(outr),
956 func(
reinterpret_cast<uchar *
>(dr),
957 reinterpret_cast<const uchar *
>(outr),
963 dmaskrect += origskip;
967 for (
x = width;
x > 0;
x--, dr++, outr++, sr++, cmr++) {
968 const uchar *src =
reinterpret_cast<const uchar *
>(sr);
977 if (src[3] && (
mask > 0.0f)) {
980 mask_src[0] = src[0];
981 mask_src[1] = src[1];
982 mask_src[2] = src[2];
985 mask_src[3] = src[3];
987 reinterpret_cast<const uchar *
>(outr),
993 func(
reinterpret_cast<uchar *
>(dr),
994 reinterpret_cast<const uchar *
>(outr),
1001 cmaskrect += srcskip;
1003 texmaskrect += srcskip;
1008 for (
x = width;
x > 0;
x--, dr++, outr++, sr++) {
1009 if ((
reinterpret_cast<const uchar *
>(sr))[3]) {
1010 func(
reinterpret_cast<uchar *
>(dr),
1011 reinterpret_cast<const uchar *
>(outr),
1012 reinterpret_cast<const uchar *
>(sr));
1035 for (
x = width;
x > 0;
x--, drf += 4, orf += 4, srf += 4, dmr++, cmr++) {
1036 float mask_lim = mask_max * (*cmr);
1039 mask_lim *= ((*tmr++) / 65535.0f);
1042 if (srf[3] && mask_lim) {
1049 mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
1063 func_float(drf, orf, mask_srf);
1068 dmaskrect += origskip;
1072 for (
x = width;
x > 0;
x--, drf += 4, orf += 4, srf += 4, cmr++) {
1081 if (srf[3] && (
mask > 0.0f)) {
1088 func_float(drf, orf, mask_srf);
1094 cmaskrect += srcskip;
1096 texmaskrect += srcskip;
1101 for (
x = width;
x > 0;
x--, drf += 4, orf += 4, srf += 4) {
1103 func_float(drf, orf, srf);
1108 drectf += destskip * 4;
1109 orectf += origskip * 4;
1110 srectf += srcskip * 4;
1134 if (dbuf ==
nullptr || obuf ==
nullptr) {
1153 desty + y_range.
first(),
1155 origy + y_range.
first(),
1157 srcy + y_range.
first(),
1177 *rrect++ = *(
reinterpret_cast<uint *
>(ccol));
1195 ImBuf *ibuf,
const float scene_linear_color[4],
int x1,
int y1,
int x2,
int y2)
1203 const int width = ibuf->
x;
1204 const int height = ibuf->
y;
1206 if ((!rect && !rectf) || scene_linear_color[3] == 0.0f) {
1211 CLAMP(x1, 0, width);
1212 CLAMP(x2, 0, width);
1213 CLAMP(y1, 0, height);
1214 CLAMP(y2, 0, height);
1222 if (x1 == x2 || y1 == y2) {
1225 const int x_span = x2 - x1;
1226 const int y_span = y2 - y1;
1229 const float a = scene_linear_color[3];
1231 const float ai = 1 - a;
1233 const float aich = ai / 255.0f;
1237 uchar chr = 0, chg = 0, chb = 0;
1238 float fr = 0, fg = 0,
fb = 0;
1261 for (
int j = 0; j < y_span; j++) {
1262 pixel = rect + (4 * (((size_t(y1) + size_t(j)) * size_t(width)) + size_t(x1)));
1263 for (
int i = 0; i < x_span; i++) {
1264 BLI_assert(pixel >= rect && pixel < rect + (4 * (
size_t(width) *
size_t(height))));
1273 pixel[0] = char((fr + (
float(pixel[0]) * aich)) * 255.0f);
1274 pixel[1] = char((fg + (
float(pixel[1]) * aich)) * 255.0f);
1275 pixel[2] = char((
fb + (
float(pixel[2]) * aich)) * 255.0f);
1276 pixel[3] = char((alphatest = (
int(pixel[3]) + alphaint)) < 255 ? alphatest : 255);
1286 for (
int j = 0; j < y_span; j++) {
1287 pixel = rectf + (4 * (((size_t(y1) + j) * size_t(width)) + size_t(x1)));
1288 for (
int i = 0; i < x_span; i++) {
1289 BLI_assert(pixel >= rectf && pixel < rectf + (4 * (
size_t(width) *
size_t(height))));
1291 pixel[0] = scene_linear_color[0];
1292 pixel[1] = scene_linear_color[1];
1293 pixel[2] = scene_linear_color[2];
1298 pixel[0] = (scene_linear_color[0] * a) + (pixel[0] * ai);
1299 pixel[1] = (scene_linear_color[1] * a) + (pixel[1] * ai);
1300 pixel[2] = (scene_linear_color[2] * a) + (pixel[2] * ai);
1301 pixel[3] = (alphatest = (pixel[3] + a)) < 1.0f ? alphatest : 1.0f;
1321 const uchar cvalue = value * 255;
1322 uchar *cbuf = byte_data + 3;
Read Blender memory allocation and freeing.
constexpr int64_t first() const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr int64_t size() const
#define unit_float_to_uchar_clamp_v4(v1, v2)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
MINLINE float min_ff(float a, float b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static float * create_cropped_buffer(const float *src, const int2 &src_size, const int channels, const int2 &src_rect_pos, const int2 &rect_size)
MINLINE void blend_color_vividlight_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_luminosity_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_add_alpha_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
void IMB_rectfill_alpha(ImBuf *ibuf, float value)
MINLINE void blend_color_linearburn_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_linearlight_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
MINLINE void blend_color_mix_float(float dst[4], const float src1[4], const float src2[4])
static void imb_rectclip3(ImBuf *dbuf, const ImBuf *obuf, const ImBuf *sbuf, int *destx, int *desty, int *origx, int *origy, int *srcx, int *srcy, int *width, int *height)
MINLINE void blend_color_add_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void blend_color_saturation_float(float dst[4], const float src1[4], const float src2[4])
BLI_INLINE float fb(float length, float L)
static void * create_cropped_buffer_impl(const void *src_void, const int2 &src_size, const int stride, const int2 &src_rect_pos, const int2 &rect_size)
size_t IMB_get_pixel_count(const ImBuf *ibuf)
Get the length of the data of the given image buffer in pixels.
MINLINE void blend_color_erase_alpha_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
bool IMB_alloc_byte_pixels(ImBuf *ibuf, bool initialize_pixels=true)
void IMB_rect_size_set(ImBuf *ibuf, const uint size[2])
MINLINE void blend_color_sub_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
void IMB_rectfill(ImBuf *drect, const float col[4])
MINLINE void blend_color_mix_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void blend_color_darken_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void blend_color_pinlight_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_overlay_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_hardlight_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_hue_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_darken_float(float dst[4], const float src1[4], const float src2[4])
void(*)(uchar *dst, const uchar *src1, const uchar *src2) IMB_blend_func
void IMB_rectfill_area(ImBuf *ibuf, const float scene_linear_color[4], int x1, int y1, int x2, int y2)
MINLINE void blend_color_exclusion_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
void IMB_crop(ImBuf *ibuf, const int2 &rect_pos, const int2 &rect_size)
MINLINE void blend_color_sub_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_difference_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_luminosity_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_color_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_color_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_difference_float(float dst[4], const float src1[4], const float src2[4])
void IMB_rectblend(ImBuf *dbuf, uint8_t *dbuf_byte_data, float *dbuf_float_data, const ImBuf *obuf, const ImBuf *sbuf, unsigned short *dmask, const unsigned short *curvemask, const unsigned short *texmask, float mask_max, int destx, int desty, int origx, int origy, int srcx, int srcy, int width, int height, IMB_BlendMode mode, bool accumulate)
MINLINE void blend_color_interpolate_float(float dst[4], const float src1[4], const float src2[4], float t)
MINLINE void blend_color_add_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_erase_alpha_float(float dst[4], const float src1[4], const float src2[4])
MINLINE int divide_round_i(int a, int b)
VecBase< int32_t, 2 > int2
MINLINE void blend_color_overlay_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_hardlight_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], const ColorSpace *colorspace)
MINLINE void blend_color_exclusion_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_screen_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
static void copy_to_cropped_bufffer(void *dst_void, const int2 &dst_size, const void *src_void, const int2 &src_size, const int stride, const int2 &src_rect_pos, const int2 &dst_rect_pos, const int2 &rect_size)
void IMB_rectclip(ImBuf *dbuf, const ImBuf *sbuf, int *destx, int *desty, int *srcx, int *srcy, int *width, int *height)
MINLINE void blend_color_saturation_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_dodge_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
void IMB_blend_color_float(float dst[4], const float src1[4], const float src2[4], IMB_BlendMode mode)
ATTR_WARN_UNUSED_RESULT const size_t num
MINLINE void blend_color_hue_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_screen_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_mul_float(float dst[4], const float src1[4], const float src2[4])
void IMB_rectblend_threaded(ImBuf *dbuf, const ImBuf *obuf, const ImBuf *sbuf, unsigned short *dmask, const unsigned short *curvemask, const unsigned short *texmask, float mask_max, int destx, int desty, int origx, int origy, int srcx, int srcy, int width, int height, IMB_BlendMode mode, bool accumulate)
MINLINE void blend_color_burn_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_lighten_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_linearburn_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_vividlight_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
void IMB_blend_color_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4], IMB_BlendMode mode)
MINLINE void blend_color_lighten_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void blend_color_burn_float(float dst[4], const float src1[4], const float src2[4])
bool IMB_alloc_float_pixels(ImBuf *ibuf, unsigned int channels, bool initialize_pixels=true)
BLI_INLINE void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3], const float scene_linear[3])
MINLINE void blend_color_softlight_float(float dst[4], const float src1[4], const float src2[4])
void(*)(float *dst, const float *src1, const float *src2) IMB_blend_func_float
MINLINE void blend_color_interpolate_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4], float ft)
MINLINE void blend_color_pinlight_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_mul_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void blend_color_add_alpha_float(float dst[4], const float src1[4], const float src2[4])
void IMB_copy_rect(float *dst, const int2 &dst_size, const float *src, const int2 &src_size, int channels, const int2 &src_rect_pos, const int2 &dst_rect_pos, const int2 &rect_size)
MINLINE void blend_color_softlight_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_linearlight_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_dodge_float(float dst[4], const float src1[4], const float src2[4])
ccl_device_inline int rect_size(const int4 rect)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const ColorSpace * colorspace
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)