209 if (*buf_p ==
nullptr) {
212 const int size_dst[2] = {
216 uint *src =
static_cast<uint *
>(*buf_p);
217 uint *dst = src + crop->
ymin * size_src[0] + crop->
xmin;
218 for (
int y = 0;
y < size_dst[1];
y++, src += size_dst[0], dst += size_src[0]) {
219 memmove(src, dst,
sizeof(
uint) * size_dst[0]);
226 if (*buf_p ==
nullptr) {
229 const int size_dst[2] = {
233 uint(*src)[4] =
static_cast<uint(*)[4]
>(*buf_p);
234 uint(*dst)[4] = src + crop->
ymin * size_src[0] + crop->
xmin;
235 for (
int y = 0;
y < size_dst[1];
y++, src += size_dst[0], dst += size_src[0]) {
236 memmove(src, dst,
sizeof(
uint[4]) * size_dst[0]);
238 *buf_p = (
void *)
MEM_reallocN(*buf_p,
sizeof(
uint[4]) * size_dst[0] * size_dst[1]);
243 const int size_src[2] = {
247 const int size_dst[2] = {
251 BLI_assert(size_dst[0] > 0 && size_dst[1] > 0);
255 if ((size_dst[0] == ibuf->
x) && (size_dst[1] == ibuf->
y)) {
263 ibuf->
x = size_dst[0];
264 ibuf->
y = size_dst[1];
272 if (*buf_p ==
nullptr) {
281 if (*buf_p ==
nullptr) {
291 if ((
size[0] == ibuf->
x) && (
size[1] == ibuf->
y)) {
318 if (dbuf ==
nullptr) {
343 tmp = dbuf->
x - *destx;
344 *width = std::min(*width, tmp);
345 tmp = dbuf->
y - *desty;
346 *height = std::min(*height, tmp);
349 tmp = sbuf->
x - *srcx;
350 *width = std::min(*width, tmp);
351 tmp = sbuf->
y - *srcy;
352 *height = std::min(*height, tmp);
355 if ((*height <= 0) || (*width <= 0)) {
375 if (dbuf ==
nullptr) {
417 tmp = dbuf->
x - *destx;
418 *width = std::min(*width, tmp);
419 tmp = dbuf->
y - *desty;
420 *height = std::min(*height, tmp);
423 tmp = obuf->
x - *origx;
424 *width = std::min(*width, tmp);
425 tmp = obuf->
y - *origy;
426 *height = std::min(*height, tmp);
430 tmp = sbuf->
x - *srcx;
431 *width = std::min(*width, tmp);
432 tmp = sbuf->
y - *srcy;
433 *height = std::min(*height, tmp);
436 if ((*height <= 0) || (*width <= 0)) {
493 uint *drect =
nullptr, *orect =
nullptr, *srect =
nullptr, *dr, *outr, *sr;
494 float *drectf =
nullptr, *orectf =
nullptr, *srectf =
nullptr, *drf, *orf, *srf;
495 const ushort *cmaskrect = curvemask, *cmr;
496 ushort *dmaskrect = dmask, *dmr;
497 const ushort *texmaskrect = texmask, *tmr;
498 int srcskip, destskip, origskip,
x;
502 if (dbuf ==
nullptr || obuf ==
nullptr) {
506 imb_rectclip3(dbuf, obuf, sbuf, &destx, &desty, &origx, &origy, &srcx, &srcy, &width, &height);
508 if (width == 0 || height == 0) {
533 dmaskrect += size_t(origy) * obuf->
x + origx;
549 cmaskrect += size_t(srcy) * sbuf->
x + srcx;
553 texmaskrect += size_t(srcy) * sbuf->
x + srcx;
564 for (; height > 0; height--) {
566 memcpy(drect, srect, width *
sizeof(
int));
572 memcpy(drectf, srectf,
sizeof(
float[4]) * width);
573 drectf += destskip * 4;
574 srectf += srcskip * 4;
580 for (; height > 0; height--) {
584 for (
x = width;
x > 0;
x--, dr++, sr++) {
585 ((
char *)dr)[0] = ((
char *)sr)[0];
586 ((
char *)dr)[1] = ((
char *)sr)[1];
587 ((
char *)dr)[2] = ((
char *)sr)[2];
596 for (
x = width;
x > 0;
x--, drf += 4, srf += 4) {
597 float map_alpha = (srf[3] == 0.0f) ? drf[3] : drf[3] / srf[3];
599 drf[0] = srf[0] * map_alpha;
600 drf[1] = srf[1] * map_alpha;
601 drf[2] = srf[2] * map_alpha;
603 drectf += destskip * 4;
604 srectf += srcskip * 4;
610 for (; height > 0; height--) {
614 for (
x = width;
x > 0;
x--, dr++, sr++) {
615 ((
char *)dr)[3] = ((
char *)sr)[3];
624 for (
x = width;
x > 0;
x--, drf += 4, srf += 4) {
627 drectf += destskip * 4;
628 srectf += srcskip * 4;
736 for (; height > 0; height--) {
750 for (
x = width;
x > 0;
x--, dr++, outr++, sr++, dmr++, cmr++) {
752 float mask_lim = mask_max * (*cmr);
755 mask_lim *= ((*tmr++) / 65535.0f);
758 if (src[3] && mask_lim) {
762 mask = *dmr + mask_lim;
765 mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
775 mask_src[0] = src[0];
776 mask_src[1] = src[1];
777 mask_src[2] = src[2];
780 mask_src[3] = src[3];
791 dmaskrect += origskip;
795 for (
x = width;
x > 0;
x--, dr++, outr++, sr++, cmr++) {
805 if (src[3] && (
mask > 0.0f)) {
808 mask_src[0] = src[0];
809 mask_src[1] = src[1];
810 mask_src[2] = src[2];
813 mask_src[3] = src[3];
825 cmaskrect += srcskip;
827 texmaskrect += srcskip;
832 for (
x = width;
x > 0;
x--, dr++, outr++, sr++) {
833 if (((
uchar *)sr)[3]) {
857 for (
x = width;
x > 0;
x--, drf += 4, orf += 4, srf += 4, dmr++, cmr++) {
858 float mask_lim = mask_max * (*cmr);
861 mask_lim *= ((*tmr++) / 65535.0f);
864 if (srf[3] && mask_lim) {
871 mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
885 func_float(drf, orf, mask_srf);
890 dmaskrect += origskip;
894 for (
x = width;
x > 0;
x--, drf += 4, orf += 4, srf += 4, cmr++) {
903 if (srf[3] && (
mask > 0.0f)) {
910 func_float(drf, orf, mask_srf);
916 cmaskrect += srcskip;
918 texmaskrect += srcskip;
923 for (
x = width;
x > 0;
x--, drf += 4, orf += 4, srf += 4) {
925 func_float(drf, orf, srf);
930 drectf += destskip * 4;
931 orectf += origskip * 4;
932 srectf += srcskip * 4;
966 desty + y_range.
first(),
968 origy + y_range.
first(),
970 srcy + y_range.
first(),
990 *rrect++ = *((
uint *)ccol);
1008 ImBuf *ibuf,
const float scene_linear_color[4],
int x1,
int y1,
int x2,
int y2)
1016 const int width = ibuf->
x;
1017 const int height = ibuf->
y;
1019 if ((!rect && !rectf) || scene_linear_color[3] == 0.0f) {
1024 CLAMP(x1, 0, width);
1025 CLAMP(x2, 0, width);
1026 CLAMP(y1, 0, height);
1027 CLAMP(y2, 0, height);
1035 if (x1 == x2 || y1 == y2) {
1038 const int x_span = x2 - x1;
1039 const int y_span = y2 - y1;
1042 const float a = scene_linear_color[3];
1044 const float ai = 1 - a;
1046 const float aich = ai / 255.0f;
1050 uchar chr = 0, chg = 0, chb = 0;
1051 float fr = 0, fg = 0,
fb = 0;
1074 for (
int j = 0; j < y_span; j++) {
1075 pixel = rect + (4 * (((size_t(y1) + size_t(j)) * size_t(width)) + size_t(x1)));
1076 for (
int i = 0;
i < x_span;
i++) {
1077 BLI_assert(pixel >= rect && pixel < rect + (4 * (
size_t(width) *
size_t(height))));
1086 pixel[0] = char((fr + (
float(pixel[0]) * aich)) * 255.0f);
1087 pixel[1] = char((fg + (
float(pixel[1]) * aich)) * 255.0f);
1088 pixel[2] = char((
fb + (
float(pixel[2]) * aich)) * 255.0f);
1089 pixel[3] = char((alphatest = (
int(pixel[3]) + alphaint)) < 255 ? alphatest : 255);
1099 for (
int j = 0; j < y_span; j++) {
1100 pixel = rectf + (4 * (((size_t(y1) + j) * size_t(width)) + size_t(x1)));
1101 for (
int i = 0;
i < x_span;
i++) {
1102 BLI_assert(pixel >= rectf && pixel < rectf + (4 * (
size_t(width) *
size_t(height))));
1104 pixel[0] = scene_linear_color[0];
1105 pixel[1] = scene_linear_color[1];
1106 pixel[2] = scene_linear_color[2];
1111 pixel[0] = (scene_linear_color[0] * a) + (pixel[0] * ai);
1112 pixel[1] = (scene_linear_color[1] * a) + (pixel[1] * ai);
1113 pixel[2] = (scene_linear_color[2] * a) + (pixel[2] * ai);
1114 pixel[3] = (alphatest = (pixel[3] + a)) < 1.0f ? alphatest : 1.0f;
1134 const uchar cvalue = value * 255;
MINLINE float min_ff(float a, float b)
MINLINE int divide_round_i(int a, int b)
MINLINE void blend_color_add_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_exclusion_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_linearburn_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_overlay_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_saturation_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_burn_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_erase_alpha_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void blend_color_color_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_linearlight_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_sub_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])
MINLINE void blend_color_hue_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])
MINLINE void blend_color_dodge_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_luminosity_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_pinlight_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])
MINLINE void blend_color_pinlight_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_erase_alpha_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_screen_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])
MINLINE void blend_color_add_alpha_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])
MINLINE void blend_color_linearburn_float(float dst[4], const float src1[4], const float 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_vividlight_float(float dst[4], const float src1[4], const float 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_mix_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_difference_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_burn_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_add_alpha_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void blend_color_color_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_overlay_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])
MINLINE void blend_color_hardlight_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_sub_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])
MINLINE void blend_color_softlight_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_add_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void blend_color_hue_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4])
MINLINE void blend_color_lighten_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4])
MINLINE void blend_color_exclusion_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[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_hardlight_float(float dst[4], const float src1[4], const float src2[4])
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_linearlight_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_softlight_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_interpolate_float(float dst[4], const float src1[4], const float src2[4], float t)
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
ATTR_WARN_UNUSED_RESULT const size_t num
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], const ColorSpace *colorspace)
BLI_INLINE void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3], const float scene_linear[3])
size_t IMB_get_pixel_count(const ImBuf *ibuf)
Get the length of the data of the given image buffer in pixels.
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
constexpr int64_t first() const
constexpr int64_t size() const
BLI_INLINE float fb(float length, float L)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
#define unit_float_to_uchar_clamp_v4(v1, v2)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
static void rect_realloc_16bytes(void **buf_p, const uint size[2])
void IMB_rectfill_alpha(ImBuf *ibuf, const float value)
static void rect_crop_4bytes(void **buf_p, const int size_src[2], const rcti *crop)
static void rect_crop_16bytes(void **buf_p, const int size_src[2], const rcti *crop)
void IMB_rectblend_threaded(ImBuf *dbuf, const ImBuf *obuf, const ImBuf *sbuf, ushort *dmask, const ushort *curvemask, const ushort *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)
void IMB_rect_crop(ImBuf *ibuf, const rcti *crop)
void IMB_rectblend(ImBuf *dbuf, const ImBuf *obuf, const ImBuf *sbuf, ushort *dmask, const ushort *curvemask, const ushort *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)
void(*)(uchar *dst, const uchar *src1, const uchar *src2) IMB_blend_func
void IMB_rectclip(ImBuf *dbuf, const ImBuf *sbuf, int *destx, int *desty, int *srcx, int *srcy, int *width, int *height)
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)
void IMB_blend_color_byte(uchar dst[4], const uchar src1[4], const uchar src2[4], IMB_BlendMode mode)
void IMB_blend_color_float(float dst[4], const float src1[4], const float src2[4], IMB_BlendMode mode)
void IMB_rectfill(ImBuf *drect, const float col[4])
void IMB_rectfill_area(ImBuf *ibuf, const float scene_linear_color[4], int x1, int y1, int x2, int y2)
void(*)(float *dst, const float *src1, const float *src2) IMB_blend_func_float
void IMB_rect_size_set(ImBuf *ibuf, const uint size[2])
static void rect_realloc_4bytes(void **buf_p, const uint size[2])
void IMB_rectcpy(ImBuf *dbuf, const ImBuf *sbuf, int destx, int desty, int srcx, int srcy, int width, int height)
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer