208 if (*buf_p ==
nullptr) {
211 const int size_dst[2] = {
215 uint *src =
static_cast<uint *
>(*buf_p);
216 uint *dst = src + crop->
ymin * size_src[0] + crop->
xmin;
217 for (
int y = 0; y < size_dst[1]; y++, src += size_dst[0], dst += size_src[0]) {
218 memmove(src, dst,
sizeof(
uint) * size_dst[0]);
225 if (*buf_p ==
nullptr) {
228 const int size_dst[2] = {
232 uint(*src)[4] =
static_cast<uint(*)[4]
>(*buf_p);
233 uint(*dst)[4] = src + crop->
ymin * size_src[0] + crop->
xmin;
234 for (
int y = 0; y < size_dst[1]; y++, src += size_dst[0], dst += size_src[0]) {
235 memmove(src, dst,
sizeof(
uint[4]) * size_dst[0]);
237 *buf_p = (
void *)
MEM_reallocN(*buf_p,
sizeof(
uint[4]) * size_dst[0] * size_dst[1]);
242 const int size_src[2] = {
246 const int size_dst[2] = {
250 BLI_assert(size_dst[0] > 0 && size_dst[1] > 0);
254 if ((size_dst[0] == ibuf->
x) && (size_dst[1] == ibuf->
y)) {
262 ibuf->
x = size_dst[0];
263 ibuf->
y = size_dst[1];
271 if (*buf_p ==
nullptr) {
280 if (*buf_p ==
nullptr) {
290 if ((size[0] == ibuf->
x) && (size[1] == ibuf->
y)) {
317 if (dbuf ==
nullptr) {
342 tmp = dbuf->
x - *destx;
346 tmp = dbuf->
y - *desty;
352 tmp = sbuf->
x - *srcx;
356 tmp = sbuf->
y - *srcy;
362 if ((*height <= 0) || (*width <= 0)) {
382 if (dbuf ==
nullptr) {
424 tmp = dbuf->
x - *destx;
428 tmp = dbuf->
y - *desty;
434 tmp = obuf->
x - *origx;
438 tmp = obuf->
y - *origy;
445 tmp = sbuf->
x - *srcx;
449 tmp = sbuf->
y - *srcy;
455 if ((*height <= 0) || (*width <= 0)) {
512 uint *drect =
nullptr, *orect =
nullptr, *srect =
nullptr, *dr, *outr, *sr;
513 float *drectf =
nullptr, *orectf =
nullptr, *srectf =
nullptr, *drf, *orf, *srf;
514 const ushort *cmaskrect = curvemask, *cmr;
515 ushort *dmaskrect = dmask, *dmr;
516 const ushort *texmaskrect = texmask, *tmr;
517 int srcskip, destskip, origskip,
x;
521 if (dbuf ==
nullptr || obuf ==
nullptr) {
525 imb_rectclip3(dbuf, obuf, sbuf, &destx, &desty, &origx, &origy, &srcx, &srcy, &width, &height);
527 if (width == 0 || height == 0) {
552 dmaskrect += size_t(origy) * obuf->
x + origx;
568 cmaskrect += size_t(srcy) * sbuf->
x + srcx;
572 texmaskrect += size_t(srcy) * sbuf->
x + srcx;
583 for (; height > 0; height--) {
585 memcpy(drect, srect, width *
sizeof(
int));
591 memcpy(drectf, srectf,
sizeof(
float[4]) * width);
592 drectf += destskip * 4;
593 srectf += srcskip * 4;
599 for (; height > 0; height--) {
603 for (x = width; x > 0; x--, dr++, sr++) {
604 ((
char *)dr)[0] = ((
char *)sr)[0];
605 ((
char *)dr)[1] = ((
char *)sr)[1];
606 ((
char *)dr)[2] = ((
char *)sr)[2];
615 for (x = width; x > 0; x--, drf += 4, srf += 4) {
616 float map_alpha = (srf[3] == 0.0f) ? drf[3] : drf[3] / srf[3];
618 drf[0] = srf[0] * map_alpha;
619 drf[1] = srf[1] * map_alpha;
620 drf[2] = srf[2] * map_alpha;
622 drectf += destskip * 4;
623 srectf += srcskip * 4;
629 for (; height > 0; height--) {
633 for (x = width; x > 0; x--, dr++, sr++) {
634 ((
char *)dr)[3] = ((
char *)sr)[3];
643 for (x = width; x > 0; x--, drf += 4, srf += 4) {
646 drectf += destskip * 4;
647 srectf += srcskip * 4;
755 for (; height > 0; height--) {
769 for (x = width; x > 0; x--, dr++, outr++, sr++, dmr++, cmr++) {
771 float mask_lim = mask_max * (*cmr);
774 mask_lim *= ((*tmr++) / 65535.0f);
777 if (src[3] && mask_lim) {
781 mask = *dmr + mask_lim;
784 mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
787 mask =
min_ff(mask, 65535.0);
794 mask_src[0] = src[0];
795 mask_src[1] = src[1];
796 mask_src[2] = src[2];
799 mask_src[3] = src[3];
801 (
uchar *)dr, (
uchar *)outr, mask_src, mask / 65535.0f);
810 dmaskrect += origskip;
814 for (x = width; x > 0; x--, dr++, outr++, sr++, cmr++) {
819 mask *= (
float(*tmr++) / 65535.0f);
822 mask =
min_ff(mask, 65535.0);
824 if (src[3] && (mask > 0.0f)) {
827 mask_src[0] = src[0];
828 mask_src[1] = src[1];
829 mask_src[2] = src[2];
832 mask_src[3] = src[3];
834 (
uchar *)dr, (
uchar *)outr, mask_src, mask / 65535.0f);
844 cmaskrect += srcskip;
846 texmaskrect += srcskip;
851 for (x = width; x > 0; x--, dr++, outr++, sr++) {
852 if (((
uchar *)sr)[3]) {
876 for (x = width; x > 0; x--, drf += 4, orf += 4, srf += 4, dmr++, cmr++) {
877 float mask_lim = mask_max * (*cmr);
880 mask_lim *= ((*tmr++) / 65535.0f);
883 if (srf[3] && mask_lim) {
887 mask =
min_ff(*dmr + mask_lim, 65535.0);
890 mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
893 mask =
min_ff(mask, 65535.0);
904 func_float(drf, orf, mask_srf);
909 dmaskrect += origskip;
913 for (x = width; x > 0; x--, drf += 4, orf += 4, srf += 4, cmr++) {
917 mask *= (
float(*tmr++) / 65535.0f);
920 mask =
min_ff(mask, 65535.0);
922 if (srf[3] && (mask > 0.0f)) {
929 func_float(drf, orf, mask_srf);
935 cmaskrect += srcskip;
937 texmaskrect += srcskip;
942 for (x = width; x > 0; x--, drf += 4, orf += 4, srf += 4) {
944 func_float(drf, orf, srf);
949 drectf += destskip * 4;
950 orectf += origskip * 4;
951 srectf += srcskip * 4;
971 const int num_scanlines = 1;
981 data->desty + scanline,
983 data->origy + scanline,
985 data->srcy + scanline,
1010 if (
size_t(width) * height < 64 * 64) {
1035 data.curvemask = curvemask;
1036 data.texmask = texmask;
1037 data.mask_max = mask_max;
1046 data.accumulate = accumulate;
1059 ccol[0] =
int(
col[0] * 255);
1060 ccol[1] =
int(
col[1] * 255);
1061 ccol[2] =
int(
col[2] * 255);
1062 ccol[3] =
int(
col[3] * 255);
1064 num = drect->
x * drect->
y;
1065 for (; num > 0; num--) {
1066 *rrect++ = *((
uint *)ccol);
1073 num = drect->
x * drect->
y;
1074 for (; num > 0; num--) {
1084 const ImBuf *ibuf,
const float col[4],
int x1,
int y1,
int x2,
int y2)
1093 int width = ibuf->
x;
1094 int height = ibuf->
y;
1095 CLAMP(x1, 0, width);
1096 CLAMP(x2, 0, width);
1097 CLAMP(y1, 0, height);
1098 CLAMP(y2, 0, height);
1106 if (x1 == x2 || y1 == y2) {
1110 const uchar col_char[4] = {
1113 for (
int y = y1; y < y2; y++) {
1114 for (
int x = x1; x < x2; x++) {
1115 size_t offset = size_t(ibuf->
x) * y * 4 + 4 *
x;
1119 memcpy(rrect, col_char,
sizeof(
uchar[4]));
1124 memcpy(rrectf,
col,
sizeof(
float[4]));
1145 if ((!rect && !rectf) || (!
col) ||
col[3] == 0.0f) {
1150 CLAMP(x1, 0, width);
1151 CLAMP(x2, 0, width);
1152 CLAMP(y1, 0, height);
1153 CLAMP(y2, 0, height);
1161 if (x1 == x2 || y1 == y2) {
1171 uchar chr = 0, chg = 0, chb = 0;
1172 float fr = 0, fg = 0,
fb = 0;
1186 for (j = 0; j < y2 - y1; j++) {
1187 for (i = 0; i < x2 - x1; i++) {
1188 pixel = rect + 4 * (((y1 + j) * width) + (x1 + i));
1189 if (pixel >= rect && pixel < rect + (4 * (width * height))) {
1198 pixel[0] = char((fr + (
float(pixel[0]) * aich)) * 255.0f);
1199 pixel[1] = char((fg + (
float(pixel[1]) * aich)) * 255.0f);
1200 pixel[2] = char((
fb + (
float(pixel[2]) * aich)) * 255.0f);
1201 pixel[3] = char((alphatest = (
int(pixel[3]) + alphaint)) < 255 ? alphatest : 255);
1220 for (j = 0; j < y2 - y1; j++) {
1221 for (i = 0; i < x2 - x1; i++) {
1222 pixel = rectf + 4 * (((y1 + j) * width) + (x1 + i));
1224 pixel[0] = col_conv[0];
1225 pixel[1] = col_conv[1];
1226 pixel[2] = col_conv[2];
1231 pixel[0] = (col_conv[0] * a) + (pixel[0] * ai);
1232 pixel[1] = (col_conv[1] * a) + (pixel[1] * ai);
1233 pixel[2] = (col_conv[2] * a) + (pixel[2] * ai);
1234 pixel[3] = (alphatest = (pixel[3] + a)) < 1.0f ? alphatest : 1.0f;
1265 for (i = ibuf->
x * ibuf->
y; i > 0; i--, fbuf += 4) {
1271 const uchar cvalue = value * 255;
1273 for (i = ibuf->
x * ibuf->
y; i > 0; i--, cbuf += 4) {
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)
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], ColorManagedDisplay *display)
void IMB_processor_apply_threaded_scanlines(int total_scanlines, ScanlineThreadFunc do_thread, void *custom_data)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
BLI_INLINE float fb(float length, float L)
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
#define unit_float_to_uchar_clamp(val)
ccl_device_inline float4 mask(const int4 mask, const float4 a)
static void rect_realloc_16bytes(void **buf_p, const uint size[2])
void IMB_rectfill_alpha(ImBuf *ibuf, const float value)
void buf_rectfill_area(uchar *rect, float *rectf, int width, int height, const float col[4], ColorManagedDisplay *display, int x1, int y1, int x2, int y2)
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 IMB_rectfill_area(ImBuf *ibuf, const float col[4], int x1, int y1, int x2, int y2, ColorManagedDisplay *display)
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)
static void rectblend_thread_do(void *data_v, int scanline)
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)
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer