code cleanup: function naming, use BKE_*type* prefix.
[blender.git] / source / blender / blenkernel / intern / brush.c
index 9e706c48430f04c03ccc5a842b96c2f0e97e0ece..a1e8a11e9ff67a87e6f26c350c3f9446dbe201f3 100644 (file)
@@ -67,7 +67,7 @@
 #include "RE_render_ext.h" /* externtex */
 #include "RE_shader_ext.h"
 
-static void brush_set_defaults(Brush *brush)
+static void brush_defaults(Brush *brush)
 {
        brush->blend = 0;
        brush->flag = 0;
@@ -75,6 +75,7 @@ static void brush_set_defaults(Brush *brush)
        brush->ob_mode = OB_MODE_ALL_PAINT;
 
        /* BRUSH SCULPT TOOL SETTINGS */
+       brush->weight= 1.0f; /* weight of brush 0 - 1.0 */
        brush->size= 35; /* radius of the brush in pixels */
        brush->alpha= 0.5f; /* brush strength/intensity probably variable should be renamed? */
        brush->autosmooth_factor= 0.0f;
@@ -121,30 +122,30 @@ static void brush_set_defaults(Brush *brush)
 
 /* Datablock add/copy/free/make_local */
 
-Brush *add_brush(const char *name)
+Brush *BKE_brush_add(const char *name)
 {
        Brush *brush;
 
-       brush= alloc_libblock(&G.main->brush, ID_BR, name);
+       brush= BKE_libblock_alloc(&G.main->brush, ID_BR, name);
 
        /* enable fake user by default */
        brush->id.flag |= LIB_FAKEUSER;
 
-       brush_set_defaults(brush);
+       brush_defaults(brush);
 
        brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */
 
         /* the default alpha falloff curve */
-       brush_curve_preset(brush, CURVE_PRESET_SMOOTH);
+       BKE_brush_curve_preset(brush, CURVE_PRESET_SMOOTH);
 
        return brush;
 }
 
-Brush *copy_brush(Brush *brush)
+Brush *BKE_brush_copy(Brush *brush)
 {
        Brush *brushn;
        
-       brushn= copy_libblock(&brush->id);
+       brushn= BKE_libblock_copy(&brush->id);
 
        if (brush->mtex.tex)
                id_us_plus((ID*)brush->mtex.tex);
@@ -166,7 +167,7 @@ Brush *copy_brush(Brush *brush)
 }
 
 /* not brush itself */
-void free_brush(Brush *brush)
+void BKE_brush_free(Brush *brush)
 {
        if (brush->mtex.tex)
                brush->mtex.tex->id.us--;
@@ -185,7 +186,7 @@ static void extern_local_brush(Brush *brush)
        id_lib_extern((ID *)brush->clone.image);
 }
 
-void make_local_brush(Brush *brush)
+void BKE_brush_make_local(Brush *brush)
 {
 
        /* - only lib users: do nothing
@@ -197,23 +198,23 @@ void make_local_brush(Brush *brush)
        Scene *scene;
        int is_local= FALSE, is_lib= FALSE;
 
-       if(brush->id.lib==NULL) return;
+       if (brush->id.lib==NULL) return;
 
-       if(brush->clone.image) {
+       if (brush->clone.image) {
                /* special case: ima always local immediately. Clone image should only
-                  have one user anyway. */
+                * have one user anyway. */
                id_clear_lib_data(bmain, &brush->clone.image->id);
                extern_local_brush(brush);
        }
 
-       for(scene= bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene=scene->id.next) {
-               if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
-                       if(scene->id.lib) is_lib= TRUE;
+       for (scene= bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene=scene->id.next) {
+               if (paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
+                       if (scene->id.lib) is_lib= TRUE;
                        else is_local= TRUE;
                }
        }
 
-       if(is_local && is_lib == FALSE) {
+       if (is_local && is_lib == FALSE) {
                id_clear_lib_data(bmain, &brush->id);
                extern_local_brush(brush);
 
@@ -223,17 +224,17 @@ void make_local_brush(Brush *brush)
                        brush->id.us++;
                }
        }
-       else if(is_local && is_lib) {
-               Brush *brush_new= copy_brush(brush);
+       else if (is_local && is_lib) {
+               Brush *brush_new= BKE_brush_copy(brush);
                brush_new->id.us= 1; /* only keep fake user */
                brush_new->id.flag |= LIB_FAKEUSER;
 
                /* Remap paths of new ID using old library as base. */
                BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id);
                
-               for(scene= bmain->scene.first; scene; scene=scene->id.next) {
-                       if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
-                               if(scene->id.lib==NULL) {
+               for (scene= bmain->scene.first; scene; scene=scene->id.next) {
+                       if (paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
+                               if (scene->id.lib==NULL) {
                                        paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new);
                                }
                        }
@@ -241,20 +242,20 @@ void make_local_brush(Brush *brush)
        }
 }
 
-void brush_debug_print_state(Brush *br)
+void BKE_brush_debug_print_state(Brush *br)
 {
        /* create a fake brush and set it to the defaults */
        Brush def= {{NULL}};
-       brush_set_defaults(&def);
+       brush_defaults(&def);
        
 #define BR_TEST(field, t)                                      \
-       if(br->field != def.field)                              \
+       if (br->field != def.field)                             \
                printf("br->" #field " = %" #t ";\n", br->field)
 
 #define BR_TEST_FLAG(_f)                               \
-       if((br->flag & _f) && !(def.flag & _f))         \
+       if ((br->flag & _f) && !(def.flag & _f))                \
                printf("br->flag |= " #_f ";\n");       \
-       else if(!(br->flag & _f) && (def.flag & _f))    \
+       else if (!(br->flag & _f) && (def.flag & _f))   \
                printf("br->flag &= ~" #_f ";\n")
        
 
@@ -328,18 +329,16 @@ void brush_debug_print_state(Brush *br)
 #undef BR_TEST_FLAG
 }
 
-void brush_reset_sculpt(Brush *br)
+void BKE_brush_sculpt_reset(Brush *br)
 {
        /* enable this to see any non-default
-          settings used by a brush:
+        * settings used by a brush: */
+       // BKE_brush_debug_print_state(br);
 
-       brush_debug_print_state(br);
-       */
+       brush_defaults(br);
+       BKE_brush_curve_preset(br, CURVE_PRESET_SMOOTH);
 
-       brush_set_defaults(br);
-       brush_curve_preset(br, CURVE_PRESET_SMOOTH);
-
-       switch(br->sculpt_tool) {
+       switch (br->sculpt_tool) {
        case SCULPT_TOOL_CLAY:
                br->flag |= BRUSH_FRONTFACE;
                break;
@@ -410,11 +409,11 @@ void brush_reset_sculpt(Brush *br)
 }
 
 /* Library Operations */
-void brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset)
+void BKE_brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset)
 {
        CurveMap *cm = NULL;
 
-       if(!b->curve)
+       if (!b->curve)
                b->curve = curvemapping_add(1, 0, 0, 1, 1);
 
        cm = b->curve->cm;
@@ -425,20 +424,20 @@ void brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset)
        curvemapping_changed(b->curve, 0);
 }
 
-int brush_texture_set_nr(Brush *brush, int nr)
+int BKE_brush_texture_set_nr(Brush *brush, int nr)
 {
        ID *idtest, *id=NULL;
 
        id= (ID *)brush->mtex.tex;
 
        idtest= (ID*)BLI_findlink(&G.main->tex, nr-1);
-       if(idtest==NULL) { /* new tex */
-               if(id) idtest= (ID *)copy_texture((Tex *)id);
+       if (idtest==NULL) { /* new tex */
+               if (id) idtest= (ID *)BKE_texture_copy((Tex *)id);
                else idtest= (ID *)add_texture("Tex");
                idtest->us--;
        }
-       if(idtest!=id) {
-               brush_texture_delete(brush);
+       if (idtest!=id) {
+               BKE_brush_texture_delete(brush);
 
                brush->mtex.tex= (Tex*)idtest;
                id_us_plus(idtest);
@@ -449,21 +448,21 @@ int brush_texture_set_nr(Brush *brush, int nr)
        return 0;
 }
 
-int brush_texture_delete(Brush *brush)
+int BKE_brush_texture_delete(Brush *brush)
 {
-       if(brush->mtex.tex)
+       if (brush->mtex.tex)
                brush->mtex.tex->id.us--;
 
        return 1;
 }
 
-int brush_clone_image_set_nr(Brush *brush, int nr)
+int BKE_brush_clone_image_set_nr(Brush *brush, int nr)
 {
-       if(brush && nr > 0) {
+       if (brush && nr > 0) {
                Image *ima= (Image*)BLI_findlink(&G.main->image, nr-1);
 
-               if(ima) {
-                       brush_clone_image_delete(brush);
+               if (ima) {
+                       BKE_brush_clone_image_delete(brush);
                        brush->clone.image= ima;
                        id_us_plus(&ima->id);
                        brush->clone.offset[0]= brush->clone.offset[1]= 0.0f;
@@ -475,7 +474,7 @@ int brush_clone_image_set_nr(Brush *brush, int nr)
        return 0;
 }
 
-int brush_clone_image_delete(Brush *brush)
+int BKE_brush_clone_image_delete(Brush *brush)
 {
        if (brush && brush->clone.image) {
                brush->clone.image->id.us--;
@@ -487,14 +486,14 @@ int brush_clone_image_delete(Brush *brush)
 }
 
 /* Brush Sampling */
-void brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread)
+void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread)
 {
        MTex *mtex= &brush->mtex;
 
        if (mtex && mtex->tex) {
                float co[3], tin, tr, tg, tb, ta;
                int hasrgb;
-               const int radius= brush_size(scene, brush);
+               const int radius= BKE_brush_size_get(scene, brush);
 
                co[0]= xy[0]/radius;
                co[1]= xy[1]/radius;
@@ -521,14 +520,14 @@ void brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float
 }
 
 /* TODO, use define for 'texfall' arg */
-void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
+void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
 {
        ImBuf *ibuf;
        float xy[2], rgba[4], *dstf;
        int x, y, rowbytes, xoff, yoff, imbflag;
-       const int radius= brush_size(scene, brush);
+       const int radius= BKE_brush_size_get(scene, brush);
        unsigned char *dst, crgb[3];
-       const float alpha= brush_alpha(scene, brush);
+       const float alpha= BKE_brush_alpha_get(scene, brush);
        float brush_rgb[3];
     
        imbflag= (flt)? IB_rectfloat: IB_rect;
@@ -556,15 +555,15 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
 
                                if (texfall == 0) {
                                        copy_v3_v3(dstf, brush_rgb);
-                                       dstf[3]= alpha*brush_curve_strength_clamp(brush, len_v2(xy), radius);
+                                       dstf[3]= alpha*BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
                                }
                                else if (texfall == 1) {
-                                       brush_sample_tex(scene, brush, xy, dstf, 0);
+                                       BKE_brush_sample_tex(scene, brush, xy, dstf, 0);
                                }
                                else {
-                                       brush_sample_tex(scene, brush, xy, rgba, 0);
+                                       BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
                                        mul_v3_v3v3(dstf, rgba, brush_rgb);
-                                       dstf[3] = rgba[3]*alpha*brush_curve_strength_clamp(brush, len_v2(xy), radius);
+                                       dstf[3] = rgba[3]*alpha*BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
                                }
                        }
                }
@@ -581,7 +580,7 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
                                xy[1] = y + yoff;
 
                                if (texfall == 0) {
-                                       alpha_f = alpha * brush_curve_strength(brush, len_v2(xy), radius);
+                                       alpha_f = alpha * BKE_brush_curve_strength(brush, len_v2(xy), radius);
 
                                        dst[0] = crgb[0];
                                        dst[1] = crgb[1];
@@ -589,21 +588,21 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
                                        dst[3] = FTOCHAR(alpha_f);
                                }
                                else if (texfall == 1) {
-                                       brush_sample_tex(scene, brush, xy, rgba, 0);
+                                       BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
                                        rgba_float_to_uchar(dst, rgba);
                                }
                                else if (texfall == 2) {
-                                       brush_sample_tex(scene, brush, xy, rgba, 0);
+                                       BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
                                        mul_v3_v3(rgba, brush->rgb);
-                                       alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
+                                       alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
 
                                        rgb_float_to_uchar(dst, rgba);
 
                                        dst[3] = FTOCHAR(alpha_f);
                                }
                                else {
-                                       brush_sample_tex(scene, brush, xy, rgba, 0);
-                                       alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
+                                       BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+                                       alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
 
                                        dst[0] = crgb[0];
                                        dst[1] = crgb[1];
@@ -632,7 +631,7 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
 // In anycase, a better solution is needed to prevent
 // inconsistency.
 
-void brush_set_size(Scene *scene, Brush *brush, int size)
+void BKE_brush_size_set(Scene *scene, Brush *brush, int size)
 {
        UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 
@@ -642,14 +641,14 @@ void brush_set_size(Scene *scene, Brush *brush, int size)
                brush->size= size;
 }
 
-int brush_size(const Scene *scene, Brush *brush)
+int BKE_brush_size_get(const Scene *scene, Brush *brush)
 {
        UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 
        return (ups->flag & UNIFIED_PAINT_SIZE) ? ups->size : brush->size;
 }
 
-int brush_use_locked_size(const Scene *scene, Brush *brush)
+int BKE_brush_use_locked_size(const Scene *scene, Brush *brush)
 {
        const short us_flag = scene->toolsettings->unified_paint_settings.flag;
 
@@ -658,7 +657,7 @@ int brush_use_locked_size(const Scene *scene, Brush *brush)
                (brush->flag & BRUSH_LOCK_SIZE);
 }
 
-int brush_use_size_pressure(const Scene *scene, Brush *brush)
+int BKE_brush_use_size_pressure(const Scene *scene, Brush *brush)
 {
        const short us_flag = scene->toolsettings->unified_paint_settings.flag;
 
@@ -667,7 +666,7 @@ int brush_use_size_pressure(const Scene *scene, Brush *brush)
                (brush->flag & BRUSH_SIZE_PRESSURE);
 }
 
-int brush_use_alpha_pressure(const Scene *scene, Brush *brush)
+int BKE_brush_use_alpha_pressure(const Scene *scene, Brush *brush)
 {
        const short us_flag = scene->toolsettings->unified_paint_settings.flag;
 
@@ -676,7 +675,7 @@ int brush_use_alpha_pressure(const Scene *scene, Brush *brush)
                (brush->flag & BRUSH_ALPHA_PRESSURE);
 }
 
-void brush_set_unprojected_radius(Scene *scene, Brush *brush, float unprojected_radius)
+void BKE_brush_unprojected_radius_set(Scene *scene, Brush *brush, float unprojected_radius)
 {
        UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 
@@ -686,7 +685,7 @@ void brush_set_unprojected_radius(Scene *scene, Brush *brush, float unprojected_
                brush->unprojected_radius= unprojected_radius;
 }
 
-float brush_unprojected_radius(const Scene *scene, Brush *brush)
+float BKE_brush_unprojected_radius_get(const Scene *scene, Brush *brush)
 {
        UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 
@@ -695,7 +694,7 @@ float brush_unprojected_radius(const Scene *scene, Brush *brush)
                brush->unprojected_radius;
 }
 
-static void brush_set_alpha(Scene *scene, Brush *brush, float alpha)
+static void brush_alpha_set(Scene *scene, Brush *brush, float alpha)
 {
        UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 
@@ -705,35 +704,52 @@ static void brush_set_alpha(Scene *scene, Brush *brush, float alpha)
                brush->alpha= alpha;
 }
 
-float brush_alpha(const Scene *scene, Brush *brush)
+float BKE_brush_alpha_get(const Scene *scene, Brush *brush)
 {
        UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 
        return (ups->flag & UNIFIED_PAINT_ALPHA) ? ups->alpha : brush->alpha;
 }
 
+float BKE_brush_weight_get(const Scene *scene, Brush *brush)
+{
+       UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
+
+       return (ups->flag & UNIFIED_PAINT_WEIGHT) ? ups->weight : brush->weight;
+}
+
+void BKE_brush_weight_set(const Scene *scene, Brush *brush, float value)
+{
+       UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
+
+       if(ups->flag & UNIFIED_PAINT_WEIGHT)
+               ups->weight = value;
+       else
+               brush->weight = value;
+}
+
 /* scale unprojected radius to reflect a change in the brush's 2D size */
-void brush_scale_unprojected_radius(float *unprojected_radius,
-                                                                       int new_brush_size,
-                                                                       int old_brush_size)
+void BKE_brush_scale_unprojected_radius(float *unprojected_radius,
+                                        int new_brush_size,
+                                        int old_brush_size)
 {
        float scale = new_brush_size;
        /* avoid division by zero */
-       if(old_brush_size != 0)
+       if (old_brush_size != 0)
                scale /= (float)old_brush_size;
        (*unprojected_radius) *= scale;
 }
 
 /* scale brush size to reflect a change in the brush's unprojected radius */
-void brush_scale_size(int *brush_size,
-                                         float new_unprojected_radius,
-                                         float old_unprojected_radius)
+void BKE_brush_scale_size(int *BKE_brush_size_get,
+                          float new_unprojected_radius,
+                          float old_unprojected_radius)
 {
        float scale = new_unprojected_radius;
        /* avoid division by zero */
-       if(old_unprojected_radius != 0)
+       if (old_unprojected_radius != 0)
                scale /= new_unprojected_radius;
-       (*brush_size)= (int)((float)(*brush_size) * scale);
+       (*BKE_brush_size_get)= (int)((float)(*BKE_brush_size_get) * scale);
 }
 
 /* Brush Painting */
@@ -741,7 +757,7 @@ void brush_scale_size(int *brush_size,
 typedef struct BrushPainterCache {
        short enabled;
 
-       int size;                       /* size override, if 0 uses 2*brush_size(brush) */
+       int size;                       /* size override, if 0 uses 2*BKE_brush_size_get(brush) */
        short flt;                      /* need float imbuf? */
        short texonly;          /* no alpha, color or fallof, only texture in imbuf */
 
@@ -779,7 +795,7 @@ struct BrushPainter {
        BrushPainterCache cache;
 };
 
-BrushPainter *brush_painter_new(Scene *scene, Brush *brush)
+BrushPainter *BKE_brush_painter_new(Scene *scene, Brush *brush)
 {
        BrushPainter *painter= MEM_callocN(sizeof(BrushPainter), "BrushPainter");
 
@@ -788,15 +804,15 @@ BrushPainter *brush_painter_new(Scene *scene, Brush *brush)
        painter->firsttouch= 1;
        painter->cache.lastsize= -1; /* force ibuf create in refresh */
 
-       painter->startsize = brush_size(scene, brush);
-       painter->startalpha = brush_alpha(scene, brush);
+       painter->startsize = BKE_brush_size_get(scene, brush);
+       painter->startalpha = BKE_brush_alpha_get(scene, brush);
        painter->startjitter = brush->jitter;
        painter->startspacing = brush->spacing;
 
        return painter;
 }
 
-void brush_painter_require_imbuf(BrushPainter *painter, short flt, short texonly, int size)
+void BKE_brush_painter_require_imbuf(BrushPainter *painter, short flt, short texonly, int size)
 {
        if ((painter->cache.flt != flt) || (painter->cache.size != size) ||
                ((painter->cache.texonly != texonly) && texonly)) {
@@ -818,12 +834,12 @@ void brush_painter_require_imbuf(BrushPainter *painter, short flt, short texonly
        painter->cache.enabled= 1;
 }
 
-void brush_painter_free(BrushPainter *painter)
+void BKE_brush_painter_free(BrushPainter *painter)
 {
        Brush *brush = painter->brush;
 
-       brush_set_size(painter->scene, brush, painter->startsize);
-       brush_set_alpha(painter->scene, brush, painter->startalpha);
+       BKE_brush_size_set(painter->scene, brush, painter->startsize);
+       brush_alpha_set(painter->scene, brush, painter->startalpha);
        brush->jitter = painter->startjitter;
        brush->spacing = painter->startspacing;
 
@@ -843,7 +859,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf,
        float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4];
        unsigned char *b, *m, *t, *ot= NULL;
        int dotexold, origx= x, origy= y;
-       const int radius= brush_size(painter->scene, brush);
+       const int radius= BKE_brush_size_get(painter->scene, brush);
 
        xoff = -radius + 0.5f;
        yoff = -radius + 0.5f;
@@ -857,8 +873,8 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf,
        dotexold = (oldtexibuf != NULL);
 
        /* not sure if it's actually needed or it's a mistake in coords/sizes
-          calculation in brush_painter_fixed_tex_partial_update(), but without this
-          limitation memory gets corrupted at fast strokes with quite big spacing (sergey) */
+        * calculation in brush_painter_fixed_tex_partial_update(), but without this
+        * limitation memory gets corrupted at fast strokes with quite big spacing (sergey) */
        w = MIN2(w, ibuf->x);
        h = MIN2(h, ibuf->y);
 
@@ -881,7 +897,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf,
                                        xy[0] = x + xoff;
                                        xy[1] = y + yoff;
 
-                                       brush_sample_tex(scene, brush, xy, tf, 0);
+                                       BKE_brush_sample_tex(scene, brush, xy, tf, 0);
                                }
 
                                bf[0] = tf[0]*mf[0];
@@ -912,7 +928,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf,
                                        xy[0] = x + xoff;
                                        xy[1] = y + yoff;
 
-                                       brush_sample_tex(scene, brush, xy, rgba, 0);
+                                       BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
                                        rgba_float_to_uchar(t, rgba);
                                }
 
@@ -932,7 +948,7 @@ static void brush_painter_fixed_tex_partial_update(BrushPainter *painter, const
        BrushPainterCache *cache= &painter->cache;
        ImBuf *oldtexibuf, *ibuf;
        int imbflag, destx, desty, srcx, srcy, w, h, x1, y1, x2, y2;
-       const int diameter= 2*brush_size(scene, brush);
+       const int diameter= 2*BKE_brush_size_get(scene, brush);
 
        imbflag= (cache->flt)? IB_rectfloat: IB_rect;
        if (!cache->ibuf)
@@ -988,8 +1004,8 @@ static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2
        MTex *mtex= &brush->mtex;
        int size;
        short flt;
-       const int diameter= 2*brush_size(scene, brush);
-       const float alpha= brush_alpha(scene, brush);
+       const int diameter= 2*BKE_brush_size_get(scene, brush);
+       const float alpha= BKE_brush_alpha_get(scene, brush);
 
        if (diameter != cache->lastsize ||
                alpha != cache->lastalpha ||
@@ -1008,11 +1024,11 @@ static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2
                size= (cache->size)? cache->size: diameter;
 
                if (brush->flag & BRUSH_FIXED_TEX) {
-                       brush_imbuf_new(scene, brush, flt, 3, size, &cache->maskibuf, use_color_correction);
+                       BKE_brush_imbuf_new(scene, brush, flt, 3, size, &cache->maskibuf, use_color_correction);
                        brush_painter_fixed_tex_partial_update(painter, pos);
                }
                else
-                       brush_imbuf_new(scene, brush, flt, 2, size, &cache->ibuf, use_color_correction);
+                       BKE_brush_imbuf_new(scene, brush, flt, 2, size, &cache->ibuf, use_color_correction);
 
                cache->lastsize= diameter;
                cache->lastalpha= alpha;
@@ -1027,34 +1043,34 @@ static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2
        }
 }
 
-void brush_painter_break_stroke(BrushPainter *painter)
+void BKE_brush_painter_break_stroke(BrushPainter *painter)
 {
        painter->firsttouch= 1;
 }
 
-static void brush_apply_pressure(BrushPainter *painter, Brush *brush, float pressure)
+static void brush_pressure_apply(BrushPainter *painter, Brush *brush, float pressure)
 {
-       if (brush_use_alpha_pressure(painter->scene, brush)) 
-               brush_set_alpha(painter->scene, brush, MAX2(0.0f, painter->startalpha*pressure));
-       if (brush_use_size_pressure(painter->scene, brush))
-               brush_set_size(painter->scene, brush, MAX2(1.0f, painter->startsize*pressure));
+       if (BKE_brush_use_alpha_pressure(painter->scene, brush))
+               brush_alpha_set(painter->scene, brush, MAX2(0.0f, painter->startalpha*pressure));
+       if (BKE_brush_use_size_pressure(painter->scene, brush))
+               BKE_brush_size_set(painter->scene, brush, MAX2(1.0f, painter->startsize*pressure));
        if (brush->flag & BRUSH_JITTER_PRESSURE)
                brush->jitter = MAX2(0.0f, painter->startjitter*pressure);
        if (brush->flag & BRUSH_SPACING_PRESSURE)
                brush->spacing = MAX2(1.0f, painter->startspacing*(1.5f-pressure));
 }
 
-void brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2])
+void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2])
 {
        int use_jitter= brush->jitter != 0;
 
        /* jitter-ed brush gives weird and unpredictable result for this
-          kinds of stroke, so manyally disable jitter usage (sergey) */
+        * kinds of stroke, so manyally disable jitter usage (sergey) */
        use_jitter &= (brush->flag & (BRUSH_RESTORE_MESH|BRUSH_ANCHORED)) == 0;
 
        if (use_jitter) {
                float rand_pos[2];
-               const int radius= brush_size(scene, brush);
+               const int radius= BKE_brush_size_get(scene, brush);
                const int diameter= 2*radius;
 
                // find random position within a circle of diameter 1
@@ -1071,15 +1087,15 @@ void brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], floa
        }
 }
 
-int brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2], double time, float pressure,
-                        void *user, int use_color_correction)
+int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2], double time, float pressure,
+                            void *user, int use_color_correction)
 {
        Scene *scene= painter->scene;
        Brush *brush= painter->brush;
        int totpaintops= 0;
 
        if (pressure == 0.0f) {
-               if(painter->lastpressure) // XXX - hack, operator misses
+               if (painter->lastpressure) // XXX - hack, operator misses
                        pressure= painter->lastpressure;
                else
                        pressure = 1.0f;        /* zero pressure == not using tablet */
@@ -1089,7 +1105,7 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2
                painter->startpaintpos[0]= pos[0];
                painter->startpaintpos[1]= pos[1];
 
-               brush_apply_pressure(painter, brush, pressure);
+               brush_pressure_apply(painter, brush, pressure);
                if (painter->cache.enabled)
                        brush_painter_refresh_cache(painter, pos, use_color_correction);
                totpaintops += func(user, painter->cache.ibuf, pos, pos);
@@ -1136,11 +1152,11 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2
        else {
                float startdistance, spacing, step, paintpos[2], dmousepos[2], finalpos[2];
                float t, len, press;
-               const int radius= brush_size(scene, brush);
+               const int radius= BKE_brush_size_get(scene, brush);
 
                /* compute brush spacing adapted to brush radius, spacing may depend
-                  on pressure, so update it */
-               brush_apply_pressure(painter, brush, painter->lastpressure);
+                * on pressure, so update it */
+               brush_pressure_apply(painter, brush, painter->lastpressure);
                spacing= MAX2(1.0f, radius)*brush->spacing*0.01f;
 
                /* setup starting distance, direction vector and accumulated distance */
@@ -1158,10 +1174,10 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2
 
                                t = step/len;
                                press= (1.0f-t)*painter->lastpressure + t*pressure;
-                               brush_apply_pressure(painter, brush, press);
+                               brush_pressure_apply(painter, brush, press);
                                spacing= MAX2(1.0f, radius)*brush->spacing*0.01f;
 
-                               brush_jitter_pos(scene, brush, paintpos, finalpos);
+                               BKE_brush_jitter_pos(scene, brush, paintpos, finalpos);
 
                                if (painter->cache.enabled)
                                        brush_painter_refresh_cache(painter, finalpos, use_color_correction);
@@ -1174,8 +1190,9 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2
                                painter->accumdistance -= spacing;
                                startdistance -= spacing;
                        }
-               } else {
-                       brush_jitter_pos(scene, brush, pos, finalpos);
+               }
+               else {
+                       BKE_brush_jitter_pos(scene, brush, pos, finalpos);
 
                        if (painter->cache.enabled)
                                brush_painter_refresh_cache(painter, finalpos, use_color_correction);
@@ -1188,8 +1205,8 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2
                }
 
                /* do airbrush paint ops, based on the number of paint ops left over
-                  from regular painting. this is a temporary solution until we have
-                  accurate time stamps for mouse move events */
+                * from regular painting. this is a temporary solution until we have
+                * accurate time stamps for mouse move events */
                if (brush->flag & BRUSH_AIRBRUSH) {
                        double curtime= time;
                        double painttime= brush->rate*totpaintops;
@@ -1201,9 +1218,9 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2
                                painter->accumtime -= painttime;
 
                        while (painter->accumtime >= (double)brush->rate) {
-                               brush_apply_pressure(painter, brush, pressure);
+                               brush_pressure_apply(painter, brush, pressure);
 
-                               brush_jitter_pos(scene, brush, pos, finalpos);
+                               BKE_brush_jitter_pos(scene, brush, pos, finalpos);
 
                                if (painter->cache.enabled)
                                        brush_painter_refresh_cache(painter, finalpos, use_color_correction);
@@ -1221,8 +1238,8 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2
        painter->lastmousepos[1]= pos[1];
        painter->lastpressure= pressure;
 
-       brush_set_alpha(scene, brush, painter->startalpha);
-       brush_set_size(scene, brush, painter->startsize);
+       brush_alpha_set(scene, brush, painter->startalpha);
+       BKE_brush_size_set(scene, brush, painter->startsize);
        brush->jitter = painter->startjitter;
        brush->spacing = painter->startspacing;
 
@@ -1230,21 +1247,21 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2
 }
 
 /* Uses the brush curve control to find a strength value between 0 and 1 */
-float brush_curve_strength_clamp(Brush *br, float p, const float len)
+float BKE_brush_curve_strength_clamp(Brush *br, float p, const float len)
 {
-       if(p >= len)    return 0;
+       if (p >= len)   return 0;
        else                    p= p/len;
 
        p= curvemapping_evaluateF(br->curve, 0, p);
-       if(p < 0.0f)            p= 0.0f;
-       else if(p > 1.0f)       p= 1.0f;
+       if (p < 0.0f)           p= 0.0f;
+       else if (p > 1.0f)      p= 1.0f;
        return p;
 }
 /* same as above but can return negative values if the curve enables
  * used for sculpt only */
-float brush_curve_strength(Brush *br, float p, const float len)
+float BKE_brush_curve_strength(Brush *br, float p, const float len)
 {
-       if(p >= len)
+       if (p >= len)
                p= 1.0f;
        else
                p= p/len;
@@ -1253,7 +1270,7 @@ float brush_curve_strength(Brush *br, float p, const float len)
 }
 
 /* TODO: should probably be unified with BrushPainter stuff? */
-unsigned int *brush_gen_texture_cache(Brush *br, int half_side)
+unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side)
 {
        unsigned int *texcache = NULL;
        MTex *mtex = &br->mtex;
@@ -1261,7 +1278,7 @@ unsigned int *brush_gen_texture_cache(Brush *br, int half_side)
        int hasrgb, ix, iy;
        int side = half_side * 2;
        
-       if(mtex->tex) {
+       if (mtex->tex) {
                float x, y, step = 2.0 / side, co[3];
 
                texcache = MEM_callocN(sizeof(int) * side * side, "Brush texture cache");
@@ -1282,7 +1299,7 @@ unsigned int *brush_gen_texture_cache(Brush *br, int half_side)
                                 * intensity, so calculate one (formula from do_material_tex).
                                 * if the texture didn't give an RGB value, copy the intensity across
                                 */
-                               if(hasrgb & TEX_RGB)
+                               if (hasrgb & TEX_RGB)
                                        texres.tin = (0.35f * texres.tr + 0.45f *
                                                                  texres.tg + 0.2f * texres.tb);
 
@@ -1299,7 +1316,7 @@ unsigned int *brush_gen_texture_cache(Brush *br, int half_side)
 }
 
 /**** Radial Control ****/
-struct ImBuf *brush_gen_radial_control_imbuf(Brush *br)
+struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br)
 {
        ImBuf *im = MEM_callocN(sizeof(ImBuf), "radial control texture");
        unsigned int *texcache;
@@ -1307,21 +1324,21 @@ struct ImBuf *brush_gen_radial_control_imbuf(Brush *br)
        int half = side / 2;
        int i, j;
 
-       texcache = brush_gen_texture_cache(br, half);
+       texcache = BKE_brush_gen_texture_cache(br, half);
        im->rect_float = MEM_callocN(sizeof(float) * side * side, "radial control rect");
        im->x = im->y = side;
 
-       for(i=0; i<side; ++i) {
-               for(j=0; j<side; ++j) {
+       for (i=0; i<side; ++i) {
+               for (j=0; j<side; ++j) {
                        float magn= sqrt(pow(i - half, 2) + pow(j - half, 2));
-                       im->rect_float[i*side + j]= brush_curve_strength_clamp(br, magn, half);
+                       im->rect_float[i*side + j]= BKE_brush_curve_strength_clamp(br, magn, half);
                }
        }
 
        /* Modulate curve with texture */
-       if(texcache) {
-               for(i=0; i<side; ++i) {
-                       for(j=0; j<side; ++j) {
+       if (texcache) {
+               for (i=0; i<side; ++i) {
+                       for (j=0; j<side; ++j) {
                                const int col= texcache[i*side+j];
                                im->rect_float[i*side+j]*= (((char*)&col)[0]+((char*)&col)[1]+((char*)&col)[2])/3.0f/255.0f;
                        }