Esempio n. 1
0
/**** Radial Control ****/
struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary)
{
	ImBuf *im = MEM_callocN(sizeof(ImBuf), "radial control texture");
	unsigned int *texcache;
	int side = 128;
	int half = side / 2;
	int i, j;

	curvemapping_initialize(br->curve);
	texcache = BKE_brush_gen_texture_cache(br, half, secondary);
	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) {
			float magn = sqrtf(pow2f(i - half) + pow2f(j - half));
			im->rect_float[i * side + j] = BKE_brush_curve_strength_clamped(br, magn, half);
		}
	}

	/* Modulate curve with texture */
	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;
			}
		}

		MEM_freeN(texcache);
	}

	return im;
}
Esempio n. 2
0
/* 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 = -radius;
	int yoff = -radius;

	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);

			*m = (unsigned short)(65535.0f * BKE_brush_curve_strength_clamped(brush, len, radius));
		}
	}

	return mask;
}