[Bf-blender-cvs] [fe0d39d] soc-2013-paint: Merge branch 'master' into soc-2013-paint

Antony Riakiotakis noreply at git.blender.org
Sat May 10 00:41:41 CEST 2014


Commit: fe0d39da76da3b7da052df2b8ac2ae223b190a88
Author: Antony Riakiotakis
Date:   Fri May 9 23:44:03 2014 +0300
https://developer.blender.org/rBfe0d39da76da3b7da052df2b8ac2ae223b190a88

Merge branch 'master' into soc-2013-paint

Conflicts:
	source/blender/editors/sculpt_paint/paint_image_2d.c

===================================================================



===================================================================

diff --cc source/blender/editors/sculpt_paint/paint_image_2d.c
index 260a5ad,667b487..bf5275b
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@@ -218,148 -212,13 +218,148 @@@ static unsigned short *brush_painter_ma
  
  	for (y = 0; y < size; y++) {
  		for (x = 0; x < size; x++, m++) {
 +			float res;
 +			brush_imbuf_tex_co(&mask_mapping, x, y, texco);
 +			res = BKE_brush_sample_masktex(scene, brush, texco, thread, pool);
 +			*m = (unsigned short)(65535.0f * res);
 +		}
 +	}
 +
 +	return mask;
 +}
 +
 +/* update rectangular section of the brush image */
 +static void brush_painter_mask_imbuf_update(BrushPainter *painter, unsigned short *tex_mask_old,
 +									   int origx, int origy, int w, int h, int xt, int yt, int diameter)
 +{
 +	Scene *scene = painter->scene;
 +	Brush *brush = painter->brush;
 +	rctf tex_mapping = painter->mask_mapping;
 +	struct ImagePool *pool = painter->pool;
 +	unsigned short res;
 +
 +	bool use_texture_old = (tex_mask_old != NULL);
 +
 +	int x, y, thread = 0;
 +
 +	unsigned short *tex_mask = painter->cache.tex_mask;
 +	unsigned short *tex_mask_cur = painter->cache.tex_mask_old;
 +
 +	/* fill pixels */
 +	for (y = origy; y < h; y++) {
 +		for (x = origx; x < w; x++) {
 +			/* sample texture */
 +			float texco[3];
 +
 +			/* handle byte pixel */
 +			unsigned short *b = tex_mask + (y * diameter + x);
 +			unsigned short *t = tex_mask_cur + (y * diameter + x);
 +
 +			if (!use_texture_old) {
 +				brush_imbuf_tex_co(&tex_mapping, x, y, texco);
 +				res = (unsigned short)(65535.0f * BKE_brush_sample_masktex(scene, brush, texco, thread, pool));
 +			}
 +
 +			/* read from old texture buffer */
 +			if (use_texture_old) {
 +				res = *(tex_mask_old + ((y - origy + yt) * painter->cache.tex_mask_old_w + (x - origx + xt)));
 +			}
 +
 +			/* write to new texture mask */
 +			*t = res;
 +			/* write to mask image buffer */
 +			*b = res;
 +		}
 +	}
 +}
 +
 +
 +/* update the brush mask image by trying to reuse the cached texture result. this
 + * can be considerably faster for brushes that change size due to pressure or
 + * textures that stick to the surface where only part of the pixels are new */
 +static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter, const float pos[2], int diameter)
 +{
 +	BrushPainterCache *cache = &painter->cache;
 +	unsigned short *tex_mask_old;
 +	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)
 +		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;
 +	cache->tex_mask_old = MEM_mallocN(sizeof(unsigned short) * diameter * diameter, "brush_painter_mask");
 +
 +	if (tex_mask_old) {
 +		ImBuf maskibuf;
 +		ImBuf maskibuf_old;
 +		maskibuf.x = maskibuf.y = diameter;
 +		maskibuf_old.x = cache->tex_mask_old_w;
 +		maskibuf_old.y = cache->tex_mask_old_h;
 +
 +		srcx = srcy = 0;
 +		destx = (int)painter->lastpaintpos[0] - (int)pos[0];
 +		desty = (int)painter->lastpaintpos[1] - (int)pos[1];
 +		w = cache->tex_mask_old_w;
 +		h = cache->tex_mask_old_h;
 +
 +		/* hack, use temporary rects so that clipping works */
 +		IMB_rectclip(&maskibuf, &maskibuf_old, &destx, &desty, &srcx, &srcy, &w, &h);
 +	}
 +	else {
 +		srcx = srcy = 0;
 +		destx = desty = 0;
 +		w = h = 0;
 +	}
 +
- 	x1 = destx;
- 	y1 = desty;
++	x1 = min_ii(destx, diameter);
++	y1 = min_ii(desty, diameter);
 +	x2 = min_ii(destx + w, diameter);
 +	y2 = min_ii(desty + h, diameter);
 +
 +	/* blend existing texture in new position */
 +	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)
 +		MEM_freeN(tex_mask_old);
 +
 +	/* sample texture in new areas */
 +	if ((0 < x1) && (0 < diameter))
 +		brush_painter_mask_imbuf_update(painter, NULL, 0, 0, x1, diameter, 0, 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))
 +		brush_painter_mask_imbuf_update(painter, NULL, x1, 0, x2, y1, 0, 0, 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;
 +	cache->tex_mask_old_h = diameter;
 +}
 +
 +/* create a mask with the falloff strength */
 +static unsigned short *brush_painter_curve_mask_new(BrushPainter *painter, int diameter, float radius)
 +{
 +	Brush *brush = painter->brush;
 +
 +	int xoff = -diameter * 0.5f + 0.5f;
 +	int yoff = -diameter * 0.5f + 0.5f;
 +
 +	unsigned short *mask, *m;
 +	int x, y;
 +
 +	mask = MEM_mallocN(sizeof(unsigned short) * diameter * diameter, "brush_painter_mask");
 +	m = mask;
 +
 +	for (y = 0; y < diameter; y++) {
 +		for (x = 0; x < diameter; x++, m++) {
  			float xy[2] = {x + xoff, y + yoff};
  			float len = len_v2(xy);
 -			float strength = alpha;
 -
 -			strength *= BKE_brush_curve_strength_clamp(brush, len, radius);
  
 -			*m = (unsigned short)(65535.0f * strength);
 +			*m = (unsigned short)(65535.0f * BKE_brush_curve_strength_clamp(brush, len, radius));
  		}
  	}




More information about the Bf-blender-cvs mailing list