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>2012-01-14 14:33:16 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-01-14 14:33:16 +0400
commitd14ac69c8c2340575cd453bd4cf473692de69f54 (patch)
tree749abed0ea2bdb0affdbcd70bcb0ee609d2d5ad9
parent0863575816d281d4a7ffad351a8213367b6a938d (diff)
ensure functions are not used within FTOCHAR macro since they run 2-3 times.
brushes were doing curve lookups within this macro for example.
-rw-r--r--source/blender/blenkernel/BKE_brush.h2
-rw-r--r--source/blender/blenkernel/intern/brush.c66
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c8
-rw-r--r--source/blender/blenlib/BLI_math_color.h4
-rw-r--r--source/blender/blenlib/intern/math_color.c4
-rw-r--r--source/blender/editors/sculpt_paint/paint_image.c24
6 files changed, 48 insertions, 60 deletions
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index b69eabbb371..687da70974c 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -67,7 +67,7 @@ float brush_curve_strength_clamp(struct Brush *br, float p, const float len);
float brush_curve_strength(struct Brush *br, float p, const float len); /* used for sculpt */
/* sampling */
-void brush_sample_tex(struct Brush *brush, float *xy, float *rgba, const int thread);
+void brush_sample_tex(struct Brush *brush, const float xy[2], float rgba[4], const int thread);
void brush_imbuf_new(struct Brush *brush, short flt, short texfalloff, int size,
struct ImBuf **imbuf, int use_color_correction);
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index daa41442ed5..b78b15c9a6a 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -487,7 +487,7 @@ int brush_clone_image_delete(Brush *brush)
}
/* Brush Sampling */
-void brush_sample_tex(Brush *brush, float *xy, float *rgba, const int thread)
+void brush_sample_tex(Brush *brush, const float xy[2], float rgba[4], const int thread)
{
MTex *mtex= &brush->mtex;
@@ -515,15 +515,16 @@ void brush_sample_tex(Brush *brush, float *xy, float *rgba, const int thread)
rgba[3]= 1.0f;
}
}
- else if (rgba)
+ else {
rgba[0]= rgba[1]= rgba[2]= rgba[3]= 1.0f;
+ }
}
-
+/* TODO, use define for 'texfall' arg */
void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
{
ImBuf *ibuf;
- float xy[2], dist, rgba[4], *dstf;
+ float xy[2], rgba[4], *dstf;
int x, y, rowbytes, xoff, yoff, imbflag;
const int radius= brush_size(brush);
char *dst, crgb[3];
@@ -554,28 +555,23 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf
xy[1] = y + yoff;
if (texfall == 0) {
- dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
-
copy_v3_v3(dstf, brush_rgb);
- dstf[3]= alpha*brush_curve_strength_clamp(brush, dist, radius);
+ dstf[3]= alpha*brush_curve_strength_clamp(brush, len_v2(xy), radius);
}
else if (texfall == 1) {
brush_sample_tex(brush, xy, dstf, 0);
}
else {
- dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
-
brush_sample_tex(brush, xy, rgba, 0);
mul_v3_v3v3(dstf, rgba, brush_rgb);
- dstf[3] = rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius);
+ dstf[3] = rgba[3]*alpha*brush_curve_strength_clamp(brush, len_v2(xy), radius);
}
}
}
}
else {
- crgb[0]= FTOCHAR(brush->rgb[0]);
- crgb[1]= FTOCHAR(brush->rgb[1]);
- crgb[2]= FTOCHAR(brush->rgb[2]);
+ float alpha_f; /* final float alpha to convert to char */
+ F3TOCHAR3(brush->rgb, crgb);
for (y=0; y < ibuf->y; y++) {
dst = (char*)ibuf->rect + y*rowbytes;
@@ -585,36 +581,38 @@ void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf
xy[1] = y + yoff;
if (texfall == 0) {
- dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
+ alpha_f = alpha * brush_curve_strength(brush, len_v2(xy), radius);
- dst[0]= crgb[0];
- dst[1]= crgb[1];
- dst[2]= crgb[2];
- dst[3]= FTOCHAR(alpha*brush_curve_strength(brush, dist, radius));
+ dst[0] = crgb[0];
+ dst[1] = crgb[1];
+ dst[2] = crgb[2];
+ dst[3] = FTOCHAR(alpha_f);
}
else if (texfall == 1) {
brush_sample_tex(brush, xy, rgba, 0);
- dst[0]= FTOCHAR(rgba[0]);
- dst[1]= FTOCHAR(rgba[1]);
- dst[2]= FTOCHAR(rgba[2]);
- dst[3]= FTOCHAR(rgba[3]);
+ dst[0] = FTOCHAR(rgba[0]);
+ dst[1] = FTOCHAR(rgba[1]);
+ dst[2] = FTOCHAR(rgba[2]);
+ dst[3] = FTOCHAR(rgba[3]);
}
else if (texfall == 2) {
- dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
-
brush_sample_tex(brush, xy, rgba, 0);
- dst[0] = FTOCHAR(rgba[0]*brush->rgb[0]);
- dst[1] = FTOCHAR(rgba[1]*brush->rgb[1]);
- dst[2] = FTOCHAR(rgba[2]*brush->rgb[2]);
- dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius));
- } else {
- dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
+ mul_v3_v3(rgba, brush->rgb);
+ alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
+ dst[0] = FTOCHAR(rgba[0]);
+ dst[1] = FTOCHAR(rgba[1]);
+ dst[2] = FTOCHAR(rgba[2]);
+ dst[3] = FTOCHAR(alpha_f);
+ }
+ else {
brush_sample_tex(brush, xy, rgba, 0);
- dst[0]= crgb[0];
- dst[1]= crgb[1];
- dst[2]= crgb[2];
- dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius));
+ alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
+
+ dst[0] = crgb[0];
+ dst[1] = crgb[1];
+ dst[2] = crgb[2];
+ dst[3] = FTOCHAR(alpha_f);
}
}
}
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index 108bfe3473b..f93aee80ab8 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -1620,8 +1620,8 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
}
else {
col[i*4+j].a = 255;
- col[i*4+j].r = FTOCHAR(pPoint[index].wetness);
- col[i*4+j].g = FTOCHAR(pPoint[index].wetness);
+ col[i*4+j].r =
+ col[i*4+j].g =
col[i*4+j].b = FTOCHAR(pPoint[index].wetness);
}
}
@@ -1671,8 +1671,8 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
for (; j<((mface[i].v4)?4:3); j++) {
int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
col[i*4+j].a = 255;
- col[i*4+j].r = FTOCHAR(pPoint[index].wetness);
- col[i*4+j].g = FTOCHAR(pPoint[index].wetness);
+ col[i*4+j].r =
+ col[i*4+j].g =
col[i*4+j].b = FTOCHAR(pPoint[index].wetness);
}
}
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 32c300944b4..2d8b0188165 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -99,8 +99,8 @@ void minmax_rgb(short c[3]);
void rgb_float_set_hue_float_offset(float * rgb, float hue_offset);
void rgb_byte_set_hue_float_offset(unsigned char * rgb, float hue_offset);
-void rgb_byte_to_float(const unsigned char *in, float *out);
-void rgb_float_to_byte(const float *in, unsigned char *out);
+void rgb_byte_to_float(const unsigned char in[3], float out[3]);
+void rgb_float_to_byte(const float in[3], unsigned char out[3]);
/***************** lift/gamma/gain / ASC-CDL conversion *****************/
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 3627b38a091..e9e700d355a 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -337,14 +337,14 @@ void cpack_to_rgb(unsigned int col, float *r, float *g, float *b)
*b /= 255.0f;
}
-void rgb_byte_to_float(const unsigned char *in, float *out)
+void rgb_byte_to_float(const unsigned char in[3], float out[3])
{
out[0]= ((float)in[0]) / 255.0f;
out[1]= ((float)in[1]) / 255.0f;
out[2]= ((float)in[2]) / 255.0f;
}
-void rgb_float_to_byte(const float *in, unsigned char *out)
+void rgb_float_to_byte(const float in[3], unsigned char out[3])
{
int r, g, b;
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 2b75b32a705..5acc690807e 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1784,16 +1784,7 @@ static void scale_tri(float insetCos[4][3], float *origCos[4], const float inset
}
#endif //PROJ_DEBUG_NOSEAMBLEED
-static float Vec2Lenf_nosqrt(const float *v1, const float *v2)
-{
- float x, y;
-
- x = v1[0]-v2[0];
- y = v1[1]-v2[1];
- return x*x+y*y;
-}
-
-static float Vec2Lenf_nosqrt_other(const float *v1, const float v2_1, const float v2_2)
+static float len_squared_v2v2_alt(const float *v1, const float v2_1, const float v2_2)
{
float x, y;
@@ -1802,7 +1793,7 @@ static float Vec2Lenf_nosqrt_other(const float *v1, const float v2_1, const floa
return x*x+y*y;
}
-/* note, use a squared value so we can use Vec2Lenf_nosqrt
+/* note, use a squared value so we can use len_squared_v2v2
* be sure that you have done a bounds check first or this may fail */
/* only give bucket_bounds as an arg because we need it elsewhere */
static int project_bucket_isect_circle(const float cent[2], const float radius_squared, rctf *bucket_bounds)
@@ -1826,21 +1817,21 @@ static int project_bucket_isect_circle(const float cent[2], const float radius_s
if (cent[0] < bucket_bounds->xmin) {
/* lower left out of radius test */
if (cent[1] < bucket_bounds->ymin) {
- return (Vec2Lenf_nosqrt_other(cent, bucket_bounds->xmin, bucket_bounds->ymin) < radius_squared) ? 1 : 0;
+ return (len_squared_v2v2_alt(cent, bucket_bounds->xmin, bucket_bounds->ymin) < radius_squared) ? 1 : 0;
}
/* top left test */
else if (cent[1] > bucket_bounds->ymax) {
- return (Vec2Lenf_nosqrt_other(cent, bucket_bounds->xmin, bucket_bounds->ymax) < radius_squared) ? 1 : 0;
+ return (len_squared_v2v2_alt(cent, bucket_bounds->xmin, bucket_bounds->ymax) < radius_squared) ? 1 : 0;
}
}
else if (cent[0] > bucket_bounds->xmax) {
/* lower right out of radius test */
if (cent[1] < bucket_bounds->ymin) {
- return (Vec2Lenf_nosqrt_other(cent, bucket_bounds->xmax, bucket_bounds->ymin) < radius_squared) ? 1 : 0;
+ return (len_squared_v2v2_alt(cent, bucket_bounds->xmax, bucket_bounds->ymin) < radius_squared) ? 1 : 0;
}
/* top right test */
else if (cent[1] > bucket_bounds->ymax) {
- return (Vec2Lenf_nosqrt_other(cent, bucket_bounds->xmax, bucket_bounds->ymax) < radius_squared) ? 1 : 0;
+ return (len_squared_v2v2_alt(cent, bucket_bounds->xmax, bucket_bounds->ymax) < radius_squared) ? 1 : 0;
}
}
@@ -3901,8 +3892,7 @@ static void *do_projectpaint_thread(void *ph_v)
projPixel = (ProjPixel *)node->link;
- /*dist = len_v2v2(projPixel->projCoSS, pos);*/ /* correct but uses a sqrtf */
- dist_nosqrt = Vec2Lenf_nosqrt(projPixel->projCoSS, pos);
+ dist_nosqrt = len_squared_v2v2(projPixel->projCoSS, pos);
/*if (dist < radius) {*/ /* correct but uses a sqrtf */
if (dist_nosqrt <= radius_squared) {