Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_image_proj.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c276
1 files changed, 184 insertions, 92 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 6b4951d1ca4..5436c5912bc 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -627,8 +627,9 @@ static float VecZDepthPersp(
w_tmp[1] = w_tmp[1] * wtot_inv;
w_tmp[2] = w_tmp[2] * wtot_inv;
}
- else /* dummy values for zero area face */
+ else { /* dummy values for zero area face */
w_tmp[0] = w_tmp[1] = w_tmp[2] = 1.0f / 3.0f;
+ }
/* done mimicking barycentric_weights_v2() */
return (v1[2] * w_tmp[0]) + (v2[2] * w_tmp[1]) + (v3[2] * w_tmp[2]);
@@ -644,8 +645,9 @@ static int project_paint_PickFace(const ProjPaintState *ps, const float pt[2], f
float z_depth_best = FLT_MAX, z_depth;
bucket_index = project_bucket_offset_safe(ps, pt);
- if (bucket_index == -1)
+ if (bucket_index == -1) {
return -1;
+ }
/* we could return 0 for 1 face buckets, as long as this function assumes
* that the point its testing is only every originated from an existing face */
@@ -686,10 +688,12 @@ static void uvco_to_wrapped_pxco(const float uv[2], int ibuf_x, int ibuf_y, floa
*x = fmodf(uv[0], 1.0f);
*y = fmodf(uv[1], 1.0f);
- if (*x < 0.0f)
+ if (*x < 0.0f) {
*x += 1.0f;
- if (*y < 0.0f)
+ }
+ if (*y < 0.0f) {
*y += 1.0f;
+ }
*x = *x * ibuf_x - 0.5f;
*y = *y * ibuf_y - 0.5f;
@@ -713,8 +717,9 @@ static bool project_paint_PickColor(const ProjPaintState *ps,
tri_index = project_paint_PickFace(ps, pt, w);
- if (tri_index == -1)
+ if (tri_index == -1) {
return 0;
+ }
lt = &ps->mlooptri_eval[tri_index];
PS_LOOPTRI_ASSIGN_UV_3(lt_tri_uv, ps->poly_to_loop_uv, lt);
@@ -724,8 +729,9 @@ static bool project_paint_PickColor(const ProjPaintState *ps,
ima = project_paint_face_paint_image(ps, tri_index);
/** we must have got the imbuf before getting here. */
ibuf = BKE_image_get_first_ibuf(ima);
- if (!ibuf)
+ if (!ibuf) {
return 0;
+ }
if (interp) {
float x, y;
@@ -802,12 +808,14 @@ static int project_paint_occlude_ptv(const float pt[3],
const bool is_ortho)
{
/* if all are behind us, return false */
- if (v1[2] > pt[2] && v2[2] > pt[2] && v3[2] > pt[2])
+ if (v1[2] > pt[2] && v2[2] > pt[2] && v3[2] > pt[2]) {
return 0;
+ }
/* do a 2D point in try intersection */
- if (!isect_point_tri_v2(pt, v1, v2, v3))
+ if (!isect_point_tri_v2(pt, v1, v2, v3)) {
return 0;
+ }
/* From here on we know there IS an intersection */
/* if ALL of the verts are infront of us then we know it intersects ? */
@@ -818,12 +826,14 @@ static int project_paint_occlude_ptv(const float pt[3],
/* we intersect? - find the exact depth at the point of intersection */
/* Is this point is occluded by another face? */
if (is_ortho) {
- if (VecZDepthOrtho(pt, v1, v2, v3, w) < pt[2])
+ if (VecZDepthOrtho(pt, v1, v2, v3, w) < pt[2]) {
return 2;
+ }
}
else {
- if (VecZDepthPersp(pt, v1, v2, v3, w) < pt[2])
+ if (VecZDepthPersp(pt, v1, v2, v3, w) < pt[2]) {
return 2;
+ }
}
}
return -1;
@@ -843,8 +853,9 @@ static int project_paint_occlude_ptv_clip(const float pt[3],
float wco[3];
int ret = project_paint_occlude_ptv(pt, v1, v2, v3, w, is_ortho);
- if (ret <= 0)
+ if (ret <= 0) {
return ret;
+ }
if (ret == 1) { /* weights not calculated */
if (is_ortho) {
@@ -1009,15 +1020,19 @@ static bool cmp_uv(const float vec2a[2], const float vec2b[2])
float xb = fmodf(vec2b[0], 1.0f);
float yb = fmodf(vec2b[1], 1.0f);
- if (xa < 0.0f)
+ if (xa < 0.0f) {
xa += 1.0f;
- if (ya < 0.0f)
+ }
+ if (ya < 0.0f) {
ya += 1.0f;
+ }
- if (xb < 0.0f)
+ if (xb < 0.0f) {
xb += 1.0f;
- if (yb < 0.0f)
+ }
+ if (yb < 0.0f) {
yb += 1.0f;
+ }
return ((fabsf(xa - xb) < PROJ_GEOM_TOLERANCE) && (fabsf(ya - yb) < PROJ_GEOM_TOLERANCE)) ? 1 :
0;
@@ -1093,8 +1108,9 @@ static void project_face_winding_init(const ProjPaintState *ps, const int tri_in
const float *lt_tri_uv[3] = {PS_LOOPTRI_AS_UV_3(ps->poly_to_loop_uv, lt)};
float winding = cross_tri_v2(lt_tri_uv[0], lt_tri_uv[1], lt_tri_uv[2]);
- if (winding > 0)
+ if (winding > 0) {
ps->faceWindingFlags[tri_index] |= PROJ_FACE_WINDING_CW;
+ }
ps->faceWindingFlags[tri_index] |= PROJ_FACE_WINDING_INIT;
}
@@ -1149,8 +1165,9 @@ static bool check_seam(const ProjPaintState *ps,
*orig_fidx = (i1_fidx < i2_fidx && (i2_fidx - i1_fidx == 1)) ? i1_fidx : i2_fidx;
/* initialize face winding if needed */
- if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0)
+ if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) {
project_face_winding_init(ps, tri_index);
+ }
/* first test if they have the same image */
if ((orig_tpage == tpage) && cmp_uv(orig_lt_tri_uv[orig_i1_fidx], lt_tri_uv[i1_fidx]) &&
@@ -1415,8 +1432,9 @@ static void project_face_seams_init(const ProjPaintState *ps,
LinkNode *node;
/* initialize face winding if needed */
- if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0)
+ if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) {
project_face_winding_init(ps, tri_index);
+ }
do {
if (init_all || (ps->mloop_eval[lt->tri[fidx[0]]].v == vert_index) ||
@@ -1779,14 +1797,16 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty)
/* double check lock to avoid locking */
if (UNLIKELY(!pjIma->undoRect[tile_index])) {
- if (tinf->lock)
+ if (tinf->lock) {
BLI_spin_lock(tinf->lock);
+ }
if (LIKELY(!pjIma->undoRect[tile_index])) {
pjIma->undoRect[tile_index] = TILE_PENDING;
generate_tile = true;
}
- if (tinf->lock)
+ if (tinf->lock) {
BLI_spin_unlock(tinf->lock);
+ }
}
if (generate_tile) {
@@ -1819,11 +1839,13 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty)
pjIma->ibuf->userflags |= IB_BITMAPDIRTY;
/* tile ready, publish */
- if (tinf->lock)
+ if (tinf->lock) {
BLI_spin_lock(tinf->lock);
+ }
pjIma->undoRect[tile_index] = undorect;
- if (tinf->lock)
+ if (tinf->lock) {
BLI_spin_unlock(tinf->lock);
+ }
}
return tile_index;
@@ -1872,8 +1894,9 @@ static ProjPixel *project_paint_uvpixel_init(const ProjPaintState *ps,
tile_index = project_paint_undo_subtiles(tinf, x_tile, y_tile);
/* other thread may be initializing the tile so wait here */
- while (projima->undoRect[tile_index] == TILE_PENDING)
+ while (projima->undoRect[tile_index] == TILE_PENDING) {
;
+ }
BLI_assert(tile_index < (IMAPAINT_TILE_NUMBER(ibuf->x) * IMAPAINT_TILE_NUMBER(ibuf->y)));
BLI_assert(tile_offset < (IMAPAINT_TILE_SIZE * IMAPAINT_TILE_SIZE));
@@ -1902,10 +1925,12 @@ static ProjPixel *project_paint_uvpixel_init(const ProjPaintState *ps,
projPixel->y_px = y_px;
projPixel->mask = (unsigned short)(mask * 65535);
- if (ps->do_masking)
+ if (ps->do_masking) {
projPixel->mask_accum = projima->maskRect[tile_index] + tile_offset;
- else
+ }
+ else {
projPixel->mask_accum = NULL;
+ }
/* which bounding box cell are we in?, needed for undo */
projPixel->bb_cell_index = ((int)(((float)x_px / (float)ibuf->x) * PROJ_BOUNDBOX_DIV)) +
@@ -1995,10 +2020,12 @@ static ProjPixel *project_paint_uvpixel_init(const ProjPaintState *ps,
}
#ifdef PROJ_DEBUG_PAINT
- if (ibuf->rect_float)
+ if (ibuf->rect_float) {
projPixel->pixel.f_pt[0] = 0;
- else
+ }
+ else {
projPixel->pixel.ch_pt[0] = 0;
+ }
#endif
/* pointer arithmetic */
projPixel->image_index = projima - ps->projImages;
@@ -2091,8 +2118,9 @@ static bool line_clip_rect2f(const rctf *cliprect,
}
/* line inside rect */
- if (ok1 && ok2)
+ if (ok1 && ok2) {
return 1;
+ }
/* top/bottom */
if (line_isect_y(l1, l2, rect->ymin, &isect) && (isect >= cliprect->xmin) &&
@@ -2109,8 +2137,9 @@ static bool line_clip_rect2f(const rctf *cliprect,
}
}
- if (ok1 && ok2)
+ if (ok1 && ok2) {
return 1;
+ }
if (line_isect_y(l1, l2, rect->ymax, &isect) && (isect >= cliprect->xmin) &&
(isect <= cliprect->xmax)) {
@@ -2126,8 +2155,9 @@ static bool line_clip_rect2f(const rctf *cliprect,
}
}
- if (ok1 && ok2)
+ if (ok1 && ok2) {
return 1;
+ }
/* left/right */
if (line_isect_x(l1, l2, rect->xmin, &isect) && (isect >= cliprect->ymin) &&
@@ -2144,8 +2174,9 @@ static bool line_clip_rect2f(const rctf *cliprect,
}
}
- if (ok1 && ok2)
+ if (ok1 && ok2) {
return 1;
+ }
if (line_isect_x(l1, l2, rect->xmax, &isect) && (isect >= cliprect->ymin) &&
(isect <= cliprect->ymax)) {
@@ -2430,8 +2461,9 @@ static bool line_rect_clip(const rctf *rect,
}
}
- if (min == FLT_MAX)
+ if (min == FLT_MAX) {
return false;
+ }
tmp = (is_ortho) ? 1.0f : (l1[3] + min * (l2[3] - l1[3]));
@@ -2504,8 +2536,9 @@ static void project_bucket_clip_face(const bool is_ortho,
(*tot) = 0;
- if (cull)
+ if (cull) {
return;
+ }
if (inside_bucket_flag & ISECT_1) {
copy_v2_v2(bucket_bounds_uv[*tot], uv1co);
@@ -2515,8 +2548,9 @@ static void project_bucket_clip_face(const bool is_ortho,
flag = inside_bucket_flag & (ISECT_1 | ISECT_2);
if (flag && flag != (ISECT_1 | ISECT_2)) {
if (line_rect_clip(
- bucket_bounds, v1coSS, v2coSS, uv1co, uv2co, bucket_bounds_uv[*tot], is_ortho))
+ bucket_bounds, v1coSS, v2coSS, uv1co, uv2co, bucket_bounds_uv[*tot], is_ortho)) {
(*tot)++;
+ }
}
if (inside_bucket_flag & ISECT_2) {
@@ -2527,8 +2561,9 @@ static void project_bucket_clip_face(const bool is_ortho,
flag = inside_bucket_flag & (ISECT_2 | ISECT_3);
if (flag && flag != (ISECT_2 | ISECT_3)) {
if (line_rect_clip(
- bucket_bounds, v2coSS, v3coSS, uv2co, uv3co, bucket_bounds_uv[*tot], is_ortho))
+ bucket_bounds, v2coSS, v3coSS, uv2co, uv3co, bucket_bounds_uv[*tot], is_ortho)) {
(*tot)++;
+ }
}
if (inside_bucket_flag & ISECT_3) {
@@ -2539,8 +2574,9 @@ static void project_bucket_clip_face(const bool is_ortho,
flag = inside_bucket_flag & (ISECT_3 | ISECT_1);
if (flag && flag != (ISECT_3 | ISECT_1)) {
if (line_rect_clip(
- bucket_bounds, v3coSS, v1coSS, uv3co, uv1co, bucket_bounds_uv[*tot], is_ortho))
+ bucket_bounds, v3coSS, v1coSS, uv3co, uv1co, bucket_bounds_uv[*tot], is_ortho)) {
(*tot)++;
+ }
}
if ((*tot) < 3) {
@@ -2743,10 +2779,12 @@ static void project_bucket_clip_face(const bool is_ortho,
v1_clipSS[0] * v2_clipSS[0] + v1_clipSS[1] * v2_clipSS[1]);
}
- if (flip)
+ if (flip) {
qsort(isectVCosSS, *tot, sizeof(float) * 3, float_z_sort_flip);
- else
+ }
+ else {
qsort(isectVCosSS, *tot, sizeof(float) * 3, float_z_sort);
+ }
doubles = true;
while (doubles == true) {
@@ -2795,12 +2833,14 @@ static void project_bucket_clip_face(const bool is_ortho,
/* If there are ever any problems, */
float test_uv[4][2];
int i;
- if (is_ortho)
+ if (is_ortho) {
rect_to_uvspace_ortho(
bucket_bounds, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, test_uv, flip);
- else
+ }
+ else {
rect_to_uvspace_persp(
bucket_bounds, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, test_uv, flip);
+ }
printf("( [(%f,%f), (%f,%f), (%f,%f), (%f,%f)], ",
test_uv[0][0],
test_uv[0][1],
@@ -2886,12 +2926,14 @@ static void project_bucket_clip_face(const bool is_ortho,
static bool IsectPoly2Df(const float pt[2], float uv[][2], const int tot)
{
int i;
- if (line_point_side_v2(uv[tot - 1], uv[0], pt) < 0.0f)
+ if (line_point_side_v2(uv[tot - 1], uv[0], pt) < 0.0f) {
return 0;
+ }
for (i = 1; i < tot; i++) {
- if (line_point_side_v2(uv[i - 1], uv[i], pt) < 0.0f)
+ if (line_point_side_v2(uv[i - 1], uv[i], pt) < 0.0f) {
return 0;
+ }
}
return 1;
@@ -2902,8 +2944,9 @@ static bool IsectPoly2Df_twoside(const float pt[2], float uv[][2], const int tot
bool side = (line_point_side_v2(uv[tot - 1], uv[0], pt) > 0.0f);
for (i = 1; i < tot; i++) {
- if ((line_point_side_v2(uv[i - 1], uv[i], pt) > 0.0f) != side)
+ if ((line_point_side_v2(uv[i - 1], uv[i], pt) > 0.0f) != side) {
return 0;
+ }
}
return 1;
@@ -3067,12 +3110,14 @@ static void project_paint_face_init(const ProjPaintState *ps,
has_x_isect = has_isect = 1;
- if (is_ortho)
+ if (is_ortho) {
screen_px_from_ortho(
uv, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, pixelScreenCo, w);
- else
+ }
+ else {
screen_px_from_persp(
uv, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, pixelScreenCo, w);
+ }
/* a pity we need to get the worldspace pixel location here */
if (do_clip || do_3d_mapping) {
@@ -3488,8 +3533,9 @@ static void project_bucket_init(const ProjPaintState *ps,
}
}
- if (tmpibuf)
+ if (tmpibuf) {
IMB_freeImBuf(tmpibuf);
+ }
ps->bucketFlags[bucket_index] |= PROJ_BUCKET_INIT;
}
@@ -3834,8 +3880,9 @@ static void proj_paint_state_cavity_init(ProjPaintState *ps)
/* augment the diffe*/
cavities[a] = saacos(10.0f * dot_v3v3(no, edges[a])) * (float)M_1_PI;
}
- else
+ else {
cavities[a] = 0.0;
+ }
}
MEM_freeN(counter);
@@ -3871,8 +3918,9 @@ static void proj_paint_state_thread_init(ProjPaintState *ps, const bool reset_th
/* workaround for #35057, disable threading if diameter is less than is possible for
* optimum bucket number generation */
- if (reset_threads)
+ if (reset_threads) {
ps->thread_tot = 1;
+ }
if (ps->is_shared_user == false) {
if (ps->thread_tot > 1) {
@@ -4048,8 +4096,9 @@ static void proj_paint_layer_clone_init(ProjPaintState *ps, ProjPaintLayerClone
ps->poly_to_loop_uv_clone = MEM_mallocN(ps->totpoly_eval * sizeof(MLoopUV *),
"proj_paint_mtfaces");
- if (layer_num != -1)
+ if (layer_num != -1) {
mloopuv_clone_base = CustomData_get_layer_n(&ps->me_eval->ldata, CD_MLOOPUV, layer_num);
+ }
if (mloopuv_clone_base == NULL) {
/* get active instead */
@@ -4071,11 +4120,13 @@ static bool project_paint_clone_face_skip(ProjPaintState *ps,
if (ps->do_material_slots) {
lc->slot_clone = project_paint_face_clone_slot(ps, tri_index);
/* all faces should have a valid slot, reassert here */
- if (ELEM(lc->slot_clone, NULL, slot))
+ if (ELEM(lc->slot_clone, NULL, slot)) {
return true;
+ }
}
- else if (ps->clone_ima == ps->canvas_ima)
+ else if (ps->clone_ima == ps->canvas_ima) {
return true;
+ }
if (ps->do_material_slots) {
if (lc->slot_clone != lc->slot_last_clone) {
@@ -4242,8 +4293,9 @@ static void project_paint_prepare_all_faces(ProjPaintState *ps,
else {
if (slot != slot_last) {
if (!slot->uvname || !(mloopuv_base = CustomData_get_layer_named(
- &ps->me_eval->ldata, CD_MLOOPUV, slot->uvname)))
+ &ps->me_eval->ldata, CD_MLOOPUV, slot->uvname))) {
mloopuv_base = CustomData_get_layer(&ps->me_eval->ldata, CD_MLOOPUV);
+ }
slot_last = slot;
}
@@ -4398,17 +4450,19 @@ static void project_paint_begin(const bContext *C,
if (ps->do_layer_stencil || ps->do_stencil_brush) {
//int layer_num = CustomData_get_stencil_layer(&ps->me_eval->ldata, CD_MLOOPUV);
int layer_num = CustomData_get_stencil_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV);
- if (layer_num != -1)
+ if (layer_num != -1) {
ps->mloopuv_stencil_eval = CustomData_get_layer_n(
&ps->me_eval->ldata, CD_MLOOPUV, layer_num);
+ }
if (ps->mloopuv_stencil_eval == NULL) {
/* get active instead */
ps->mloopuv_stencil_eval = CustomData_get_layer(&ps->me_eval->ldata, CD_MLOOPUV);
}
- if (ps->do_stencil_brush)
+ if (ps->do_stencil_brush) {
mloopuv_base = ps->mloopuv_stencil_eval;
+ }
}
/* when using subsurf or multires, mface arrays are thrown away, we need to keep a copy */
@@ -4513,11 +4567,13 @@ static void project_paint_end(ProjPaintState *ps)
/* must be set for non-shared */
BLI_assert(ps->poly_to_loop_uv || ps->is_shared_user);
- if (ps->poly_to_loop_uv)
+ if (ps->poly_to_loop_uv) {
MEM_freeN((void *)ps->poly_to_loop_uv);
+ }
- if (ps->do_layer_clone)
+ if (ps->do_layer_clone) {
MEM_freeN((void *)ps->poly_to_loop_uv_clone);
+ }
if (ps->thread_tot > 1) {
BLI_spin_end(ps->tile_lock);
MEM_freeN((void *)ps->tile_lock);
@@ -4550,8 +4606,9 @@ static void project_paint_end(ProjPaintState *ps)
MEM_freeN(ps->blurkernel);
}
- if (ps->vertFlags)
+ if (ps->vertFlags) {
MEM_freeN(ps->vertFlags);
+ }
for (a = 0; a < ps->thread_tot; a++) {
BLI_memarena_free(ps->arena_mt[a]);
@@ -4591,8 +4648,9 @@ static bool partial_redraw_array_merge(ImagePaintPartialRedraw *pr,
pr->x2 = max_ii(pr->x2, pr_other->x2);
pr->y2 = max_ii(pr->y2, pr_other->y2);
- if (pr->x2 != -1)
+ if (pr->x2 != -1) {
touch = 1;
+ }
pr++;
pr_other++;
@@ -4678,8 +4736,9 @@ static bool project_bucket_iter_next(ProjPaintState *ps,
{
const int diameter = 2 * ps->brush_size;
- if (ps->thread_tot > 1)
+ if (ps->thread_tot > 1) {
BLI_thread_lock(LOCK_CUSTOM1);
+ }
//printf("%d %d\n", ps->context_bucket_x, ps->context_bucket_y);
@@ -4694,8 +4753,9 @@ static bool project_bucket_iter_next(ProjPaintState *ps,
*bucket_index = ps->context_bucket_x + (ps->context_bucket_y * ps->buckets_x);
ps->context_bucket_x++;
- if (ps->thread_tot > 1)
+ if (ps->thread_tot > 1) {
BLI_thread_unlock(LOCK_CUSTOM1);
+ }
return 1;
}
@@ -4703,8 +4763,9 @@ static bool project_bucket_iter_next(ProjPaintState *ps,
ps->context_bucket_x = ps->bucketMin[0];
}
- if (ps->thread_tot > 1)
+ if (ps->thread_tot > 1) {
BLI_thread_unlock(LOCK_CUSTOM1);
+ }
return 0;
}
@@ -4782,8 +4843,9 @@ static void do_projectpaint_smear(ProjPaintState *ps,
{
unsigned char rgba_ub[4];
- if (project_paint_PickColor(ps, co, NULL, rgba_ub, 1) == 0)
+ if (project_paint_PickColor(ps, co, NULL, rgba_ub, 1) == 0) {
return;
+ }
blend_color_interpolate_byte(
((ProjPixelClone *)projPixel)->clonepx.ch, projPixel->pixel.ch_pt, rgba_ub, mask);
@@ -4799,8 +4861,9 @@ static void do_projectpaint_smear_f(ProjPaintState *ps,
{
float rgba[4];
- if (project_paint_PickColor(ps, co, rgba, NULL, 1) == 0)
+ if (project_paint_PickColor(ps, co, rgba, NULL, 1) == 0) {
return;
+ }
blend_color_interpolate_float(
((ProjPixelClone *)projPixel)->clonepx.f, projPixel->pixel.f_pt, rgba, mask);
@@ -4855,8 +4918,9 @@ static void do_projectpaint_soften_f(ProjPaintState *ps,
blend_color_add_float(rgba, projPixel->pixel.f_pt, rgba);
rgba[3] = alpha;
}
- else
+ else {
return;
+ }
}
else {
blend_color_interpolate_float(rgba, projPixel->pixel.f_pt, rgba, mask);
@@ -4922,8 +4986,9 @@ static void do_projectpaint_soften(ProjPaintState *ps,
rgba[3] = alpha;
premul_float_to_straight_uchar(rgba_ub, rgba);
}
- else
+ else {
return;
+ }
}
else {
premul_float_to_straight_uchar(rgba_ub, rgba);
@@ -4983,8 +5048,9 @@ static void do_projectpaint_draw_f(ProjPaintState *ps,
copy_v3_v3(rgba, ps->paint_color_linear);
- if (ps->is_texbrush)
+ if (ps->is_texbrush) {
mul_v3_v3(rgba, texrgb);
+ }
mul_v3_fl(rgba, mask);
rgba[3] = mask;
@@ -5330,10 +5396,12 @@ static void *do_projectpaint_thread(void *ph_v)
float mask_accum = *projPixel->mask_accum;
float max_mask = brush_alpha * custom_mask * falloff * 65535.0f;
- if (brush->flag & BRUSH_ACCUMULATE)
+ if (brush->flag & BRUSH_ACCUMULATE) {
mask = mask_accum + max_mask;
- else
+ }
+ else {
mask = mask_accum + (max_mask - mask_accum * falloff);
+ }
mask = min_ff(mask, 65535.0f);
mask_short = (unsigned short)mask;
@@ -5372,37 +5440,47 @@ static void *do_projectpaint_thread(void *ph_v)
/* texrgb is not used for clone, smear or soften */
switch (tool) {
case PAINT_TOOL_CLONE:
- if (is_floatbuf)
+ if (is_floatbuf) {
do_projectpaint_clone_f(ps, projPixel, mask);
- else
+ }
+ else {
do_projectpaint_clone(ps, projPixel, mask);
+ }
break;
case PAINT_TOOL_SMEAR:
sub_v2_v2v2(co, projPixel->projCoSS, pos_ofs);
- if (is_floatbuf)
+ if (is_floatbuf) {
do_projectpaint_smear_f(ps, projPixel, mask, smearArena, &smearPixels_f, co);
- else
+ }
+ else {
do_projectpaint_smear(ps, projPixel, mask, smearArena, &smearPixels, co);
+ }
break;
case PAINT_TOOL_SOFTEN:
- if (is_floatbuf)
+ if (is_floatbuf) {
do_projectpaint_soften_f(ps, projPixel, mask, softenArena, &softenPixels_f);
- else
+ }
+ else {
do_projectpaint_soften(ps, projPixel, mask, softenArena, &softenPixels);
+ }
break;
case PAINT_TOOL_MASK:
- if (is_floatbuf)
+ if (is_floatbuf) {
do_projectpaint_mask_f(ps, projPixel, mask);
- else
+ }
+ else {
do_projectpaint_mask(ps, projPixel, mask);
+ }
break;
default:
- if (is_floatbuf)
+ if (is_floatbuf) {
do_projectpaint_draw_f(ps, projPixel, texrgb, mask);
- else
+ }
+ else {
do_projectpaint_draw(
ps, projPixel, texrgb, mask, ps->dither, projPixel->x_px, projPixel->y_px);
+ }
break;
}
@@ -5476,8 +5554,9 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po
return touch_any;
}
- if (ps->thread_tot > 1)
+ if (ps->thread_tot > 1) {
BLI_threadpool_init(&threads, do_projectpaint_thread, ps->thread_tot);
+ }
pool = BKE_image_pool_new();
@@ -5510,14 +5589,17 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po
handles[a].pool = pool;
- if (ps->thread_tot > 1)
+ if (ps->thread_tot > 1) {
BLI_threadpool_insert(&threads, &handles[a]);
+ }
}
- if (ps->thread_tot > 1) /* wait for everything to be done */
+ if (ps->thread_tot > 1) { /* wait for everything to be done */
BLI_threadpool_end(&threads);
- else
+ }
+ else {
do_projectpaint_thread(&handles[0]);
+ }
BKE_image_pool_free(pool);
@@ -5582,8 +5664,9 @@ static void paint_proj_stroke_ps(const bContext *UNUSED(C),
ps->brush_size = size;
ps->blend = brush->blend;
- if (eraser)
+ if (eraser) {
ps->blend = IMB_BLEND_ERASE_ALPHA;
+ }
/* handle gradient and inverted stroke color here */
if (ELEM(ps->tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) {
@@ -5723,8 +5806,9 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int
ps->do_backfacecull = ps->do_occlude = ps->do_mask_normal = 0;
}
- if (ps->tool == PAINT_TOOL_CLONE)
+ if (ps->tool == PAINT_TOOL_CLONE) {
ps->do_layer_clone = (settings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE) ? 1 : 0;
+ }
ps->do_stencil_brush = (ps->brush && ps->brush->imagepaint_tool == PAINT_TOOL_MASK);
/* deactivate stenciling for the stencil brush :) */
@@ -5827,8 +5911,9 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m
}
/* Don't allow brush size below 2 */
- if (BKE_brush_size_get(scene, ps_handle->brush) < 2)
+ if (BKE_brush_size_get(scene, ps_handle->brush) < 2) {
BKE_brush_size_set(scene, ps_handle->brush, 2 * U.pixelsize);
+ }
/* allocate and initialize spatial data structures */
@@ -6087,10 +6172,12 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
maxsize = GPU_max_texture_size();
- if (w > maxsize)
+ if (w > maxsize) {
w = maxsize;
- if (h > maxsize)
+ }
+ if (h > maxsize) {
h = maxsize;
+ }
ibuf = ED_view3d_draw_offscreen_imbuf(depsgraph,
scene,
@@ -6255,14 +6342,18 @@ bool BKE_paint_proj_mesh_data_check(
}
}
- if (!hasuvs)
+ if (!hasuvs) {
imapaint->missing_data |= IMAGEPAINT_MISSING_UVS;
- if (!hasmat)
+ }
+ if (!hasmat) {
imapaint->missing_data |= IMAGEPAINT_MISSING_MATERIAL;
- if (!hastex)
+ }
+ if (!hastex) {
imapaint->missing_data |= IMAGEPAINT_MISSING_TEX;
- if (!hasstencil)
+ }
+ if (!hasstencil) {
imapaint->missing_data |= IMAGEPAINT_MISSING_STENCIL;
+ }
if (uvs) {
*uvs = hasuvs;
@@ -6386,8 +6477,9 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
Material *ma;
Image *ima = NULL;
- if (!ob)
+ if (!ob) {
return false;
+ }
ma = give_current_material(ob, ob->actcol);