210 if (*buf_p ==
nullptr) {
213 const int size_dst[2] = {
217 uint *src =
static_cast<uint *
>(*buf_p);
218 uint *dst = src + crop->
ymin * size_src[0] + crop->
xmin;
219 for (
int y = 0;
y < size_dst[1];
y++, src += size_dst[0], dst += size_src[0]) {
220 memmove(src, dst,
sizeof(
uint) * size_dst[0]);
227 if (*buf_p ==
nullptr) {
230 const int size_dst[2] = {
234 uint(*src)[4] =
static_cast<uint(*)[4]
>(*buf_p);
235 uint(*dst)[4] = src + crop->
ymin * size_src[0] + crop->
xmin;
236 for (
int y = 0;
y < size_dst[1];
y++, src += size_dst[0], dst += size_src[0]) {
237 memmove(src, dst,
sizeof(
uint[4]) * size_dst[0]);
239 *buf_p = (
void *)
MEM_reallocN(*buf_p,
sizeof(
uint[4]) * size_dst[0] * size_dst[1]);
244 const int size_src[2] = {
248 const int size_dst[2] = {
252 BLI_assert(size_dst[0] > 0 && size_dst[1] > 0);
256 if ((size_dst[0] == ibuf->
x) && (size_dst[1] == ibuf->
y)) {
264 ibuf->
x = size_dst[0];
265 ibuf->
y = size_dst[1];
273 if (*buf_p ==
nullptr) {
282 if (*buf_p ==
nullptr) {
292 if ((
size[0] == ibuf->
x) && (
size[1] == ibuf->
y)) {
319 if (dbuf ==
nullptr) {
344 tmp = dbuf->
x - *destx;
345 *width = std::min(*width, tmp);
346 tmp = dbuf->
y - *desty;
347 *height = std::min(*height, tmp);
350 tmp = sbuf->
x - *srcx;
351 *width = std::min(*width, tmp);
352 tmp = sbuf->
y - *srcy;
353 *height = std::min(*height, tmp);
356 if ((*height <= 0) || (*width <= 0)) {
376 if (dbuf ==
nullptr) {
418 tmp = dbuf->
x - *destx;
419 *width = std::min(*width, tmp);
420 tmp = dbuf->
y - *desty;
421 *height = std::min(*height, tmp);
424 tmp = obuf->
x - *origx;
425 *width = std::min(*width, tmp);
426 tmp = obuf->
y - *origy;
427 *height = std::min(*height, tmp);
431 tmp = sbuf->
x - *srcx;
432 *width = std::min(*width, tmp);
433 tmp = sbuf->
y - *srcy;
434 *height = std::min(*height, tmp);
437 if ((*height <= 0) || (*width <= 0)) {
494 uint *drect =
nullptr, *orect =
nullptr, *srect =
nullptr, *dr, *outr, *sr;
495 float *drectf =
nullptr, *orectf =
nullptr, *srectf =
nullptr, *drf, *orf, *srf;
496 const ushort *cmaskrect = curvemask, *cmr;
497 ushort *dmaskrect = dmask, *dmr;
498 const ushort *texmaskrect = texmask, *tmr;
499 int srcskip, destskip, origskip,
x;
503 if (dbuf ==
nullptr || obuf ==
nullptr) {
507 imb_rectclip3(dbuf, obuf, sbuf, &destx, &desty, &origx, &origy, &srcx, &srcy, &width, &height);
509 if (width == 0 || height == 0) {
534 dmaskrect += size_t(origy) * obuf->
x + origx;
550 cmaskrect += size_t(srcy) * sbuf->
x + srcx;
554 texmaskrect += size_t(srcy) * sbuf->
x + srcx;
565 for (; height > 0; height--) {
567 memcpy(drect, srect, width *
sizeof(
int));
573 memcpy(drectf, srectf,
sizeof(
float[4]) * width);
574 drectf += destskip * 4;
575 srectf += srcskip * 4;
581 for (; height > 0; height--) {
585 for (
x = width;
x > 0;
x--, dr++, sr++) {
586 ((
char *)dr)[0] = ((
char *)sr)[0];
587 ((
char *)dr)[1] = ((
char *)sr)[1];
588 ((
char *)dr)[2] = ((
char *)sr)[2];
597 for (
x = width;
x > 0;
x--, drf += 4, srf += 4) {
598 float map_alpha = (srf[3] == 0.0f) ? drf[3] : drf[3] / srf[3];
600 drf[0] = srf[0] * map_alpha;
601 drf[1] = srf[1] * map_alpha;
602 drf[2] = srf[2] * map_alpha;
604 drectf += destskip * 4;
605 srectf += srcskip * 4;
611 for (; height > 0; height--) {
615 for (
x = width;
x > 0;
x--, dr++, sr++) {
616 ((
char *)dr)[3] = ((
char *)sr)[3];
625 for (
x = width;
x > 0;
x--, drf += 4, srf += 4) {
628 drectf += destskip * 4;
629 srectf += srcskip * 4;
737 for (; height > 0; height--) {
751 for (
x = width;
x > 0;
x--, dr++, outr++, sr++, dmr++, cmr++) {
753 float mask_lim = mask_max * (*cmr);
756 mask_lim *= ((*tmr++) / 65535.0f);
759 if (src[3] && mask_lim) {
763 mask = *dmr + mask_lim;
766 mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
776 mask_src[0] = src[0];
777 mask_src[1] = src[1];
778 mask_src[2] = src[2];
781 mask_src[3] = src[3];
792 dmaskrect += origskip;
796 for (
x = width;
x > 0;
x--, dr++, outr++, sr++, cmr++) {
798 float mask = mask_max * float(*cmr);
801 mask *= (float(*tmr++) / 65535.0f);
806 if (src[3] && (
mask > 0.0f)) {
809 mask_src[0] = src[0];
810 mask_src[1] = src[1];
811 mask_src[2] = src[2];
814 mask_src[3] = src[3];
826 cmaskrect += srcskip;
828 texmaskrect += srcskip;
833 for (
x = width;
x > 0;
x--, dr++, outr++, sr++) {
834 if (((
uchar *)sr)[3]) {
858 for (
x = width;
x > 0;
x--, drf += 4, orf += 4, srf += 4, dmr++, cmr++) {
859 float mask_lim = mask_max * (*cmr);
862 mask_lim *= ((*tmr++) / 65535.0f);
865 if (srf[3] && mask_lim) {
872 mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
886 func_float(drf, orf, mask_srf);
891 dmaskrect += origskip;
895 for (
x = width;
x > 0;
x--, drf += 4, orf += 4, srf += 4, cmr++) {
896 float mask = mask_max * float(*cmr);
899 mask *= (float(*tmr++) / 65535.0f);
904 if (srf[3] && (
mask > 0.0f)) {
911 func_float(drf, orf, mask_srf);
917 cmaskrect += srcskip;
919 texmaskrect += srcskip;
924 for (
x = width;
x > 0;
x--, drf += 4, orf += 4, srf += 4) {
926 func_float(drf, orf, srf);
931 drectf += destskip * 4;
932 orectf += origskip * 4;
933 srectf += srcskip * 4;
967 desty + y_range.
first(),
969 origy + y_range.
first(),
971 srcy + y_range.
first(),
987 ccol[0] = int(
col[0] * 255);
988 ccol[1] = int(
col[1] * 255);
989 ccol[2] = int(
col[2] * 255);
990 ccol[3] = int(
col[3] * 255);
994 *rrect++ = *((
uint *)ccol);
1012 const ImBuf *ibuf,
const float col[4],
int x1,
int y1,
int x2,
int y2)
1021 int width = ibuf->
x;
1022 int height = ibuf->
y;
1023 CLAMP(x1, 0, width);
1024 CLAMP(x2, 0, width);
1025 CLAMP(y1, 0, height);
1026 CLAMP(y2, 0, height);
1034 if (x1 == x2 || y1 == y2) {
1038 const uchar col_char[4] = {
1041 for (
int y = y1;
y < y2;
y++) {
1042 for (
int x = x1;
x < x2;
x++) {
1043 size_t offset = size_t(ibuf->
x) *
y * 4 + 4 *
x;
1047 memcpy(rrect, col_char,
sizeof(
uchar[4]));
1052 memcpy(rrectf,
col,
sizeof(
float[4]));
1069 if ((!rect && !rectf) || (!
col) ||
col[3] == 0.0f) {
1074 CLAMP(x1, 0, width);
1075 CLAMP(x2, 0, width);
1076 CLAMP(y1, 0, height);
1077 CLAMP(y2, 0, height);
1085 if (x1 == x2 || y1 == y2) {
1088 const int x_span = x2 - x1;
1089 const int y_span = y2 - y1;
1092 const float a =
col[3];
1094 const float ai = 1 - a;
1096 const float aich = ai / 255.0f;
1100 uchar chr = 0, chg = 0, chb = 0;
1101 float fr = 0, fg = 0,
fb = 0;
1115 for (
int j = 0; j < y_span; j++) {
1116 pixel = rect + (4 * (((size_t(y1) + size_t(j)) * size_t(width)) + size_t(x1)));
1117 for (
int i = 0;
i < x_span;
i++) {
1118 BLI_assert(pixel >= rect && pixel < rect + (4 * (
size_t(width) *
size_t(height))));
1127 pixel[0] = char((fr + (
float(pixel[0]) * aich)) * 255.0f);
1128 pixel[1] = char((fg + (
float(pixel[1]) * aich)) * 255.0f);
1129 pixel[2] = char((
fb + (
float(pixel[2]) * aich)) * 255.0f);
1130 pixel[3] = char((alphatest = (
int(pixel[3]) + alphaint)) < 255 ? alphatest : 255);
1149 for (
int j = 0; j < y_span; j++) {
1150 pixel = rectf + (4 * (((size_t(y1) + j) * size_t(width)) + size_t(x1)));
1151 for (
int i = 0;
i < x_span;
i++) {
1152 BLI_assert(pixel >= rectf && pixel < rectf + (4 * (
size_t(width) *
size_t(height))));
1154 pixel[0] = col_conv[0];
1155 pixel[1] = col_conv[1];
1156 pixel[2] = col_conv[2];
1161 pixel[0] = (col_conv[0] * a) + (pixel[0] * ai);
1162 pixel[1] = (col_conv[1] * a) + (pixel[1] * ai);
1163 pixel[2] = (col_conv[2] * a) + (pixel[2] * ai);
1164 pixel[3] = (alphatest = (pixel[3] + a)) < 1.0f ? alphatest : 1.0f;
1207 const uchar cvalue = value * 255;
blender::ocio::Display ColorManagedDisplay
MINLINE float min_ff(float a, float b)
MINLINE int divide_round_i(int a, int b)
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
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 copy_v4_v4(float r[4], const float a[4])
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
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_display_to_scene_linear_v3(float pixel[3], const ColorManagedDisplay *display)
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.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
constexpr int64_t first() const
constexpr int64_t size() const
#define MEM_reallocN(vmemh, len)
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)
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_rectfill_area_replace(const ImBuf *ibuf, const float col[4], int x1, int y1, int x2, int y2)
void buf_rectfill_area(uchar *rect, float *rectf, int width, int height, const float col[4], const ColorManagedDisplay *display, int x1, int y1, int x2, int y2)
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(*)(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)
void IMB_rectfill_area(ImBuf *ibuf, const float col[4], int x1, int y1, int x2, int y2, const ColorManagedDisplay *display)
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer