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:
authorCampbell Barton <ideasman42@gmail.com>2019-04-22 02:19:45 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-22 12:48:16 +0300
commit620b960d3d8cfd90b9f0df6ba3671c33eccb8309 (patch)
tree64f69db4bf9d44f0a32d1c92b0714bf2dc98ff2d /source/blender/editors/sculpt_paint/paint_image_2d.c
parentbba60bb564cf5a16cfcac744d4ba82cf8eba3da9 (diff)
Cleanup: style, use braces for editors
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_image_2d.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_2d.c225
1 files changed, 150 insertions, 75 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 5390f18304a..78832bbbd8f 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -158,14 +158,18 @@ static void brush_painter_2d_require_imbuf(BrushPainter *painter,
Brush *brush = painter->brush;
if ((painter->cache.use_float != use_float)) {
- if (painter->cache.ibuf)
+ if (painter->cache.ibuf) {
IMB_freeImBuf(painter->cache.ibuf);
- if (painter->cache.curve_mask)
+ }
+ if (painter->cache.curve_mask) {
MEM_freeN(painter->cache.curve_mask);
- if (painter->cache.tex_mask)
+ }
+ if (painter->cache.tex_mask) {
MEM_freeN(painter->cache.tex_mask);
- if (painter->cache.tex_mask_old)
+ }
+ if (painter->cache.tex_mask_old) {
MEM_freeN(painter->cache.tex_mask_old);
+ }
painter->cache.ibuf = NULL;
painter->cache.curve_mask = NULL;
painter->cache.tex_mask = NULL;
@@ -182,16 +186,21 @@ static void brush_painter_2d_require_imbuf(BrushPainter *painter,
static void brush_painter_2d_free(BrushPainter *painter)
{
- if (painter->cache.ibuf)
+ if (painter->cache.ibuf) {
IMB_freeImBuf(painter->cache.ibuf);
- if (painter->cache.texibuf)
+ }
+ if (painter->cache.texibuf) {
IMB_freeImBuf(painter->cache.texibuf);
- if (painter->cache.curve_mask)
+ }
+ if (painter->cache.curve_mask) {
MEM_freeN(painter->cache.curve_mask);
- if (painter->cache.tex_mask)
+ }
+ if (painter->cache.tex_mask) {
MEM_freeN(painter->cache.tex_mask);
- if (painter->cache.tex_mask_old)
+ }
+ if (painter->cache.tex_mask_old) {
MEM_freeN(painter->cache.tex_mask_old);
+ }
MEM_freeN(painter);
}
@@ -297,9 +306,10 @@ static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter,
int destx, desty, srcx, srcy, w, h, x1, y1, x2, y2;
/* create brush image buffer if it didn't exist yet */
- if (!cache->tex_mask)
+ if (!cache->tex_mask) {
cache->tex_mask = MEM_mallocN(sizeof(unsigned short) * diameter * diameter,
"brush_painter_mask");
+ }
/* create new texture image buffer with coordinates relative to old */
tex_mask_old = cache->tex_mask_old;
@@ -334,21 +344,27 @@ static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter,
y2 = min_ii(desty + h, diameter);
/* blend existing texture in new position */
- if ((x1 < x2) && (y1 < y2))
+ if ((x1 < x2) && (y1 < y2)) {
brush_painter_mask_imbuf_update(painter, tex_mask_old, x1, y1, x2, y2, srcx, srcy, diameter);
+ }
- if (tex_mask_old)
+ if (tex_mask_old) {
MEM_freeN(tex_mask_old);
+ }
/* sample texture in new areas */
- if ((0 < x1) && (0 < diameter))
+ if ((0 < x1) && (0 < diameter)) {
brush_painter_mask_imbuf_update(painter, NULL, 0, 0, x1, diameter, 0, 0, diameter);
- if ((x2 < diameter) && (0 < diameter))
+ }
+ if ((x2 < diameter) && (0 < diameter)) {
brush_painter_mask_imbuf_update(painter, NULL, x2, 0, diameter, diameter, 0, 0, diameter);
- if ((x1 < x2) && (0 < y1))
+ }
+ if ((x1 < x2) && (0 < y1)) {
brush_painter_mask_imbuf_update(painter, NULL, x1, 0, x2, y1, 0, 0, diameter);
- if ((x1 < x2) && (y2 < diameter))
+ }
+ if ((x1 < x2) && (y2 < diameter)) {
brush_painter_mask_imbuf_update(painter, NULL, x1, y2, x2, diameter, 0, 0, diameter);
+ }
/* through with sampling, now update sizes */
cache->tex_mask_old_w = diameter;
@@ -556,8 +572,9 @@ static void brush_painter_imbuf_update(
crgba[2] = ot[2];
crgba[3] = ot[3];
}
- else
+ else {
rgba_float_to_uchar(crgba, rgba);
+ }
/* write to new texture buffer */
t[0] = crgba[0];
@@ -588,8 +605,9 @@ static void brush_painter_imbuf_partial_update(BrushPainter *painter,
/* create brush image buffer if it didn't exist yet */
imbflag = (cache->use_float) ? IB_rectfloat : IB_rect;
- if (!cache->ibuf)
+ if (!cache->ibuf) {
cache->ibuf = IMB_allocImBuf(diameter, diameter, 32, imbflag);
+ }
ibuf = cache->ibuf;
/* create new texture image buffer with coordinates relative to old */
@@ -617,21 +635,27 @@ static void brush_painter_imbuf_partial_update(BrushPainter *painter,
y2 = min_ii(desty + h, ibuf->y);
/* blend existing texture in new position */
- if ((x1 < x2) && (y1 < y2))
+ if ((x1 < x2) && (y1 < y2)) {
brush_painter_imbuf_update(painter, oldtexibuf, x1, y1, x2, y2, srcx, srcy);
+ }
- if (oldtexibuf)
+ if (oldtexibuf) {
IMB_freeImBuf(oldtexibuf);
+ }
/* sample texture in new areas */
- if ((0 < x1) && (0 < ibuf->y))
+ if ((0 < x1) && (0 < ibuf->y)) {
brush_painter_imbuf_update(painter, NULL, 0, 0, x1, ibuf->y, 0, 0);
- if ((x2 < ibuf->x) && (0 < ibuf->y))
+ }
+ if ((x2 < ibuf->x) && (0 < ibuf->y)) {
brush_painter_imbuf_update(painter, NULL, x2, 0, ibuf->x, ibuf->y, 0, 0);
- if ((x1 < x2) && (0 < y1))
+ }
+ if ((x1 < x2) && (0 < y1)) {
brush_painter_imbuf_update(painter, NULL, x1, 0, x2, y1, 0, 0);
- if ((x1 < x2) && (y2 < ibuf->y))
+ }
+ if ((x1 < x2) && (y2 < ibuf->y)) {
brush_painter_imbuf_update(painter, NULL, x1, y2, x2, ibuf->y, 0, 0);
+ }
}
static void brush_painter_2d_tex_mapping(ImagePaintState *s,
@@ -716,10 +740,12 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s,
if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) {
tex_rotation += ups->brush_rotation;
}
- else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM)
+ else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) {
do_random = true;
- else if (!((brush->flag & BRUSH_ANCHORED) || update_color))
+ }
+ else if (!((brush->flag & BRUSH_ANCHORED) || update_color)) {
do_partial_update = true;
+ }
brush_painter_2d_tex_mapping(s,
diameter,
@@ -765,10 +791,12 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s,
brush->mask_mtex.brush_map_mode,
&painter->mask_mapping);
- if (do_partial_update_mask)
+ if (do_partial_update_mask) {
brush_painter_mask_imbuf_partial_update(painter, pos, diameter);
- else
+ }
+ else {
cache->tex_mask = brush_painter_mask_ibuf_new(painter, diameter);
+ }
cache->last_mask_rotation = mask_rotation;
}
}
@@ -835,11 +863,13 @@ static void paint_2d_ibuf_rgb_set(
{
if (is_torus) {
x %= ibuf->x;
- if (x < 0)
+ if (x < 0) {
x += ibuf->x;
+ }
y %= ibuf->y;
- if (y < 0)
+ if (y < 0) {
y += ibuf->y;
+ }
}
if (ibuf->rect_float) {
@@ -865,13 +895,15 @@ static void paint_2d_ibuf_tile_convert(ImBuf *ibuf, int *x, int *y, short tile)
{
if (tile & PAINT_TILE_X) {
*x %= ibuf->x;
- if (*x < 0)
+ if (*x < 0) {
*x += ibuf->x;
+ }
}
if (tile & PAINT_TILE_Y) {
*y %= ibuf->y;
- if (*y < 0)
+ if (*y < 0) {
*y += ibuf->y;
+ }
}
}
@@ -879,15 +911,17 @@ static float paint_2d_ibuf_add_if(ImBuf *ibuf, int x, int y, float *outrgb, shor
{
float inrgb[4];
- if (tile)
+ if (tile) {
paint_2d_ibuf_tile_convert(ibuf, &x, &y, tile);
+ }
/* need to also do clipping here always since tiled coordinates
* are not always within bounds */
if (x < ibuf->x && x >= 0 && y < ibuf->y && y >= 0) {
paint_2d_ibuf_rgb_get(ibuf, x, y, inrgb);
}
- else
+ else {
return 0;
+ }
mul_v4_fl(inrgb, w);
add_v4_v4(outrgb, inrgb);
@@ -917,8 +951,9 @@ static void paint_2d_lift_soften(
if (!tile) {
IMB_rectclip(ibuf, ibufb, &in_off[0], &in_off[1], &out_off[0], &out_off[1], &dim[0], &dim[1]);
- if ((dim[0] == 0) || (dim[1] == 0))
+ if ((dim[0] == 0) || (dim[1] == 0)) {
return;
+ }
}
/* find offset inside mask buffers to sample them */
@@ -933,10 +968,12 @@ static void paint_2d_lift_soften(
count = 0.0;
if (tile) {
paint_2d_ibuf_tile_convert(ibuf, &xi, &yi, tile);
- if (xi < ibuf->x && xi >= 0 && yi < ibuf->y && yi >= 0)
+ if (xi < ibuf->x && xi >= 0 && yi < ibuf->y && yi >= 0) {
paint_2d_ibuf_rgb_get(ibuf, xi, yi, rgba);
- else
+ }
+ else {
zero_v4(rgba);
+ }
}
else {
/* coordinates have been clipped properly here, it should be safe to do this */
@@ -974,12 +1011,14 @@ static void paint_2d_lift_soften(
blend_color_add_float(outrgb, rgba, outrgb);
outrgb[3] = alpha;
}
- else
+ else {
copy_v4_v4(outrgb, rgba);
+ }
}
}
- else
+ else {
copy_v4_v4(outrgb, rgba);
+ }
/* write into brush buffer */
xo = out_off[0] + x;
yo = out_off[1] + y;
@@ -1015,19 +1054,23 @@ static int paint_2d_torus_split_region(ImagePaintRegion region[4],
/* convert destination and source coordinates to be within image */
if (tile & PAINT_TILE_X) {
destx = destx % dbuf->x;
- if (destx < 0)
+ if (destx < 0) {
destx += dbuf->x;
+ }
srcx = srcx % sbuf->x;
- if (srcx < 0)
+ if (srcx < 0) {
srcx += sbuf->x;
+ }
}
if (tile & PAINT_TILE_Y) {
desty = desty % dbuf->y;
- if (desty < 0)
+ if (desty < 0) {
desty += dbuf->y;
+ }
srcy = srcy % sbuf->y;
- if (srcy < 0)
+ if (srcy < 0) {
srcy += sbuf->y;
+ }
}
/* clip width of blending area to destination imbuf, to avoid writing the
* same pixel twice */
@@ -1039,13 +1082,15 @@ static int paint_2d_torus_split_region(ImagePaintRegion region[4],
paint_2d_set_region(&region[tot++], destx, desty, srcx, srcy, w, h);
/* do 3 other rects if needed */
- if ((tile & PAINT_TILE_X) && w < origw)
+ if ((tile & PAINT_TILE_X) && w < origw) {
paint_2d_set_region(
&region[tot++], (destx + w) % dbuf->x, desty, (srcx + w) % sbuf->x, srcy, origw - w, h);
- if ((tile & PAINT_TILE_Y) && h < origh)
+ }
+ if ((tile & PAINT_TILE_Y) && h < origh) {
paint_2d_set_region(
&region[tot++], destx, (desty + h) % dbuf->y, srcx, (srcy + h) % sbuf->y, w, origh - h);
- if ((tile & PAINT_TILE_X) && (tile & PAINT_TILE_Y) && (w < origw) && (h < origh))
+ }
+ if ((tile & PAINT_TILE_X) && (tile & PAINT_TILE_Y) && (w < origw) && (h < origh)) {
paint_2d_set_region(&region[tot++],
(destx + w) % dbuf->x,
(desty + h) % dbuf->y,
@@ -1053,6 +1098,7 @@ static int paint_2d_torus_split_region(ImagePaintRegion region[4],
(srcy + h) % sbuf->y,
origw - w,
origh - h);
+ }
return tot;
}
@@ -1065,7 +1111,7 @@ static void paint_2d_lift_smear(ImBuf *ibuf, ImBuf *ibufb, int *pos, short tile)
paint_2d_set_region(region, 0, 0, pos[0], pos[1], ibufb->x, ibufb->y);
tot = paint_2d_torus_split_region(region, ibufb, ibuf, tile);
- for (a = 0; a < tot; a++)
+ for (a = 0; a < tot; a++) {
IMB_rectblend(ibufb,
ibufb,
ibuf,
@@ -1083,6 +1129,7 @@ static void paint_2d_lift_smear(ImBuf *ibuf, ImBuf *ibufb, int *pos, short tile)
region[a].height,
IMB_BLEND_COPY,
false);
+ }
}
static ImBuf *paint_2d_lift_clone(ImBuf *ibuf, ImBuf *ibufb, int *pos)
@@ -1161,11 +1208,13 @@ static void paint_2d_do_making_brush(ImagePaintState *s,
int origx = region->destx - tx * IMAPAINT_TILE_SIZE;
int origy = region->desty - ty * IMAPAINT_TILE_SIZE;
- if (s->canvas->rect_float)
+ if (s->canvas->rect_float) {
tmpbuf.rect_float = image_undo_find_tile(
undo_tiles, s->image, s->canvas, tx, ty, &mask, false);
- else
+ }
+ else {
tmpbuf.rect = image_undo_find_tile(undo_tiles, s->image, s->canvas, tx, ty, &mask, false);
+ }
IMB_rectblend(s->canvas,
&tmpbuf,
@@ -1244,8 +1293,9 @@ static int paint_2d_op(void *state,
blend = IMB_BLEND_INTERPOLATE;
}
else if (s->tool == PAINT_TOOL_SMEAR) {
- if (lastpos[0] == pos[0] && lastpos[1] == pos[1])
+ if (lastpos[0] == pos[0] && lastpos[1] == pos[1]) {
return 0;
+ }
paint_2d_convert_brushco(ibufb, lastpos, blastpos);
paint_2d_lift_smear(s->canvas, ibufb, blastpos, tile);
@@ -1337,8 +1387,9 @@ static int paint_2d_op(void *state,
}
}
- if (clonebuf)
+ if (clonebuf) {
IMB_freeImBuf(clonebuf);
+ }
return 1;
}
@@ -1359,8 +1410,9 @@ static int paint_2d_canvas_set(ImagePaintState *s, Image *ima)
s->warnmultifile = ima->id.name + 2;
return 0;
}
- else if (!ibuf || !(ibuf->rect || ibuf->rect_float))
+ else if (!ibuf || !(ibuf->rect || ibuf->rect_float)) {
return 0;
+ }
s->image = ima;
s->canvas = ibuf;
@@ -1382,8 +1434,9 @@ static int paint_2d_canvas_set(ImagePaintState *s, Image *ima)
if (s->canvas->rect_float && !s->clonecanvas->rect_float) {
IMB_float_from_rect(s->clonecanvas);
}
- else if (!s->canvas->rect_float && !s->clonecanvas->rect)
+ else if (!s->canvas->rect_float && !s->clonecanvas->rect) {
IMB_rect_from_float(s->clonecanvas);
+ }
}
/* set masking */
@@ -1419,12 +1472,14 @@ void paint_2d_stroke(void *ps,
ImBuf *ibuf = BKE_image_acquire_ibuf(s->image, s->sima ? &s->sima->iuser : NULL, NULL);
const bool is_data = (ibuf && ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA);
- if (!ibuf)
+ if (!ibuf) {
return;
+ }
s->blend = s->brush->blend;
- if (eraser)
+ if (eraser) {
s->blend = IMB_BLEND_ERASE_ALPHA;
+ }
UI_view2d_region_to_view(s->v2d, mval[0], mval[1], &newuv[0], &newuv[1]);
UI_view2d_region_to_view(s->v2d, prev_mval[0], prev_mval[1], &olduv[0], &olduv[1]);
@@ -1463,8 +1518,9 @@ void paint_2d_stroke(void *ps,
painter->cache.curve_mask,
painter->cache.tex_mask,
olduv,
- newuv))
+ newuv)) {
s->need_redraw = true;
+ }
BKE_image_release_ibuf(s->image, ibuf, NULL);
}
@@ -1490,10 +1546,12 @@ void *paint_2d_new_stroke(bContext *C, wmOperator *op, int mode)
s->symmetry = settings->imapaint.paint.symmetry_flags;
if (!paint_2d_canvas_set(s, s->image)) {
- if (s->warnmultifile)
+ if (s->warnmultifile) {
BKE_report(op->reports, RPT_WARNING, "Image requires 4 color channels to paint");
- if (s->warnpackedfile)
+ }
+ if (s->warnpackedfile) {
BKE_report(op->reports, RPT_WARNING, "Packed MultiLayer files cannot be painted");
+ }
MEM_freeN(s);
return NULL;
@@ -1530,18 +1588,21 @@ void paint_2d_redraw(const bContext *C, void *ps, bool final)
}
if (final) {
- if (s->image && !(s->sima && s->sima->lock))
+ if (s->image && !(s->sima && s->sima->lock)) {
GPU_free_image(s->image);
+ }
/* compositor listener deals with updating */
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, s->image);
DEG_id_tag_update(&s->image->id, 0);
}
else {
- if (!s->sima || !s->sima->lock)
+ if (!s->sima || !s->sima->lock) {
ED_region_tag_redraw(CTX_wm_region(C));
- else
+ }
+ else {
WM_event_add_notifier(C, NC_IMAGE | NA_PAINTING, s->image);
+ }
}
}
@@ -1566,8 +1627,9 @@ static void paint_2d_fill_add_pixel_byte(const int x_px,
{
size_t coordinate;
- if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0)
+ if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) {
return;
+ }
coordinate = ((size_t)y_px) * ibuf->x + x_px;
@@ -1594,8 +1656,9 @@ static void paint_2d_fill_add_pixel_float(const int x_px,
{
size_t coordinate;
- if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0)
+ if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) {
return;
+ }
coordinate = ((size_t)y_px) * ibuf->x + x_px;
@@ -1624,13 +1687,15 @@ void paint_2d_bucket_fill(
bool do_float;
- if (!ima)
+ if (!ima) {
return;
+ }
ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL);
- if (!ibuf)
+ if (!ibuf) {
return;
+ }
do_float = (ibuf->rect_float != NULL);
/* first check if our image is float. If it is not we should correct the color to
@@ -1742,14 +1807,18 @@ void paint_2d_bucket_fill(
paint_2d_fill_add_pixel_float(
x_px + 1, y_px + 1, ibuf, stack, touched, pixel_color, threshold_sq);
- if (x_px > maxx)
+ if (x_px > maxx) {
maxx = x_px;
- if (x_px < minx)
+ }
+ if (x_px < minx) {
minx = x_px;
- if (y_px > maxy)
+ }
+ if (y_px > maxy) {
maxy = y_px;
- if (x_px > miny)
+ }
+ if (x_px > miny) {
miny = y_px;
+ }
}
}
else {
@@ -1782,14 +1851,18 @@ void paint_2d_bucket_fill(
paint_2d_fill_add_pixel_byte(
x_px + 1, y_px + 1, ibuf, stack, touched, pixel_color, threshold_sq);
- if (x_px > maxx)
+ if (x_px > maxx) {
maxx = x_px;
- if (x_px < minx)
+ }
+ if (x_px < minx) {
minx = x_px;
- if (y_px > maxy)
+ }
+ if (y_px > maxy) {
maxy = y_px;
- if (x_px > miny)
+ }
+ if (x_px > miny) {
miny = y_px;
+ }
}
}
@@ -1822,13 +1895,15 @@ void paint_2d_gradient_fill(
bool do_float;
- if (!ima)
+ if (!ima) {
return;
+ }
ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL);
- if (!ibuf)
+ if (!ibuf) {
return;
+ }
UI_view2d_region_to_view(
s->v2d, mouse_final[0], mouse_final[1], &image_final[0], &image_final[1]);