diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-05-13 02:13:38 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-05-13 02:13:38 +0400 |
commit | 145289ad958e43b3f4f8475c581fca2180f6be88 (patch) | |
tree | 5f6d6081166a3459fb5beacd9fa99f62d33000fb /source/blender/editors | |
parent | a88f910b9a21e284a2d742213f7c01ed13ddd751 (diff) |
code cleanup: minor improvements to float/vector usage.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/mesh/editmesh_bvh.c | 9 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 73 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 2 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.c | 4 |
4 files changed, 47 insertions, 41 deletions
diff --git a/source/blender/editors/mesh/editmesh_bvh.c b/source/blender/editors/mesh/editmesh_bvh.c index 6d740812f27..16948a2372d 100644 --- a/source/blender/editors/mesh/editmesh_bvh.c +++ b/source/blender/editors/mesh/editmesh_bvh.c @@ -201,12 +201,13 @@ void BMBVH_FreeBVH(BMBVHTree *tree) } /* taken from bvhutils.c */ -static float ray_tri_intersection(const BVHTreeRay *ray, const float UNUSED(m_dist), float *v0, - float *v1, float *v2, float *uv, float UNUSED(e)) +static float ray_tri_intersection(const BVHTreeRay *ray, const float UNUSED(m_dist), + const float v0[3], const float v1[3], const float v2[3], + float r_uv[2], float UNUSED(e)) { float dist; - if (isect_ray_tri_v3((float *)ray->origin, (float *)ray->direction, v0, v1, v2, &dist, uv)) { + if (isect_ray_tri_v3((float *)ray->origin, (float *)ray->direction, v0, v1, v2, &dist, r_uv)) { return dist; } @@ -343,7 +344,7 @@ BMVert *BMBVH_FindClosestVert(BMBVHTree *tree, float *co, float maxdist) /* UNUSED */ #if 0 -static short winding(float *v1, float *v2, float *v3) +static short winding(const float v1[3], const float v2[3], const float v3[3]) /* is v3 to the right of (v1 - v2) ? With exception: v3 == v1 || v3 == v2 */ { double inp; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index c46c153aa70..ead85486ec0 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -3769,7 +3769,7 @@ static void do_projectpaint_smear_f(ProjPaintState *ps, ProjPixel *projPixel, fl BLI_linklist_prepend_arena(smearPixels_f, (void *)projPixel, smearArena); } -static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, float *rgba, float alpha, float mask) +static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, const float rgba[4], float alpha, float mask) { unsigned char rgba_ub[4]; @@ -3793,7 +3793,7 @@ static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, float } } -static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel, float *rgba, float alpha, float mask, int use_color_correction) +static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel, float rgba[4], float alpha, float mask, int use_color_correction) { if (ps->is_texbrush) { /* rgba already holds a texture result here from higher level function */ @@ -4190,9 +4190,10 @@ static void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, s /* Image Paint Operations */ -static void imapaint_ibuf_get_set_rgb(ImBuf *ibuf, int x, int y, short torus, short set, float *rgb) +/* keep these functions in sync */ +static void imapaint_ibuf_rgb_get(ImBuf *ibuf, int x, int y, const short is_torus, float r_rgb[3]) { - if (torus) { + if (is_torus) { x %= ibuf->x; if (x < 0) x += ibuf->x; y %= ibuf->y; @@ -4201,23 +4202,29 @@ static void imapaint_ibuf_get_set_rgb(ImBuf *ibuf, int x, int y, short torus, sh if (ibuf->rect_float) { float *rrgbf = ibuf->rect_float + (ibuf->x * y + x) * 4; - - if (set) { - IMAPAINT_FLOAT_RGB_COPY(rrgbf, rgb); - } - else { - IMAPAINT_FLOAT_RGB_COPY(rgb, rrgbf); - } + IMAPAINT_FLOAT_RGB_COPY(r_rgb, rrgbf); } else { char *rrgb = (char *)ibuf->rect + (ibuf->x * y + x) * 4; + IMAPAINT_CHAR_RGB_TO_FLOAT(r_rgb, rrgb) + } +} +static void imapaint_ibuf_rgb_set(ImBuf *ibuf, int x, int y, const short is_torus, const float rgb[3]) +{ + if (is_torus) { + x %= ibuf->x; + if (x < 0) x += ibuf->x; + y %= ibuf->y; + if (y < 0) y += ibuf->y; + } - if (set) { - IMAPAINT_FLOAT_RGB_TO_CHAR(rrgb, rgb) - } - else { - IMAPAINT_CHAR_RGB_TO_FLOAT(rgb, rrgb) - } + if (ibuf->rect_float) { + float *rrgbf = ibuf->rect_float + (ibuf->x * y + x) * 4; + IMAPAINT_FLOAT_RGB_COPY(rrgbf, rgb); + } + else { + char *rrgb = (char *)ibuf->rect + (ibuf->x * y + x) * 4; + IMAPAINT_FLOAT_RGB_TO_CHAR(rrgb, rgb) } } @@ -4227,10 +4234,10 @@ static int imapaint_ibuf_add_if(ImBuf *ibuf, unsigned int x, unsigned int y, flo // XXX: signed unsigned mismatch if ((x >= (unsigned int)(ibuf->x)) || (y >= (unsigned int)(ibuf->y))) { - if (torus) imapaint_ibuf_get_set_rgb(ibuf, x, y, 1, 0, inrgb); + if (torus) imapaint_ibuf_rgb_get(ibuf, x, y, 1, inrgb); else return 0; } - else imapaint_ibuf_get_set_rgb(ibuf, x, y, 0, 0, inrgb); + else imapaint_ibuf_rgb_get(ibuf, x, y, 0, inrgb); outrgb[0] += inrgb[0]; outrgb[1] += inrgb[1]; @@ -4239,7 +4246,7 @@ static int imapaint_ibuf_add_if(ImBuf *ibuf, unsigned int x, unsigned int y, flo return 1; } -static void imapaint_lift_soften(ImBuf *ibuf, ImBuf *ibufb, int *pos, short torus) +static void imapaint_lift_soften(ImBuf *ibuf, ImBuf *ibufb, int *pos, const short is_torus) { int x, y, count, xi, yi, xo, yo; int out_off[2], in_off[2], dim[2]; @@ -4251,7 +4258,7 @@ static void imapaint_lift_soften(ImBuf *ibuf, ImBuf *ibufb, int *pos, short toru in_off[1] = pos[1]; out_off[0] = out_off[1] = 0; - if (!torus) { + if (!is_torus) { IMB_rectclip(ibuf, ibufb, &in_off[0], &in_off[1], &out_off[0], &out_off[1], &dim[0], &dim[1]); @@ -4266,27 +4273,25 @@ static void imapaint_lift_soften(ImBuf *ibuf, ImBuf *ibufb, int *pos, short toru yi = in_off[1] + y; count = 1; - imapaint_ibuf_get_set_rgb(ibuf, xi, yi, torus, 0, outrgb); + imapaint_ibuf_rgb_get(ibuf, xi, yi, is_torus, outrgb); - count += imapaint_ibuf_add_if(ibuf, xi - 1, yi - 1, outrgb, torus); - count += imapaint_ibuf_add_if(ibuf, xi - 1, yi, outrgb, torus); - count += imapaint_ibuf_add_if(ibuf, xi - 1, yi + 1, outrgb, torus); + count += imapaint_ibuf_add_if(ibuf, xi - 1, yi - 1, outrgb, is_torus); + count += imapaint_ibuf_add_if(ibuf, xi - 1, yi, outrgb, is_torus); + count += imapaint_ibuf_add_if(ibuf, xi - 1, yi + 1, outrgb, is_torus); - count += imapaint_ibuf_add_if(ibuf, xi, yi - 1, outrgb, torus); - count += imapaint_ibuf_add_if(ibuf, xi, yi + 1, outrgb, torus); + count += imapaint_ibuf_add_if(ibuf, xi, yi - 1, outrgb, is_torus); + count += imapaint_ibuf_add_if(ibuf, xi, yi + 1, outrgb, is_torus); - count += imapaint_ibuf_add_if(ibuf, xi + 1, yi - 1, outrgb, torus); - count += imapaint_ibuf_add_if(ibuf, xi + 1, yi, outrgb, torus); - count += imapaint_ibuf_add_if(ibuf, xi + 1, yi + 1, outrgb, torus); + count += imapaint_ibuf_add_if(ibuf, xi + 1, yi - 1, outrgb, is_torus); + count += imapaint_ibuf_add_if(ibuf, xi + 1, yi, outrgb, is_torus); + count += imapaint_ibuf_add_if(ibuf, xi + 1, yi + 1, outrgb, is_torus); - outrgb[0] /= count; - outrgb[1] /= count; - outrgb[2] /= count; + mul_v3_fl(outrgb, 1.0f / (float)count); /* write into brush buffer */ xo = out_off[0] + x; yo = out_off[1] + y; - imapaint_ibuf_get_set_rgb(ibufb, xo, yo, 0, 1, outrgb); + imapaint_ibuf_rgb_set(ibufb, xo, yo, 0, outrgb); } } } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index c01da3a816f..3b74ae54810 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -844,7 +844,7 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x } /* whats _dl mean? */ -static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float *vert_nor, +static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float vert_nor[3], const float mval[2], const float brush_size_pressure) { Brush *brush = paint_brush(&vp->paint); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index ae7d02e1cfb..8b472fd987f 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -260,7 +260,7 @@ void projectFloatView(TransInfo *t, const float vec[3], float adr[2]) zero_v2(adr); } -void applyAspectRatio(TransInfo *t, float *vec) +void applyAspectRatio(TransInfo *t, float vec[2]) { if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) { SpaceImage *sima= t->sa->spacedata.first; @@ -293,7 +293,7 @@ void applyAspectRatio(TransInfo *t, float *vec) } } -void removeAspectRatio(TransInfo *t, float *vec) +void removeAspectRatio(TransInfo *t, float vec[2]) { if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) { SpaceImage *sima= t->sa->spacedata.first; |