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

Campbell Barton noreply at git.blender.org
Mon Jul 14 03:40:41 CEST 2014


Commit: 34b2c3771a136ca3d6937362ab3f8727af519f4d
Author: Campbell Barton
Date:   Mon Jul 14 11:39:25 2014 +1000
https://developer.blender.org/rB34b2c3771a136ca3d6937362ab3f8727af519f4d

Merge branch 'master' into soc-2013-paint

Conflicts:
	source/blender/bmesh/intern/bmesh_mods.c

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



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

diff --cc source/blender/blenlib/BLI_math_vector.h
index 1191301,942097e..6885a5a
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@@ -232,7 -231,6 +232,7 @@@ MINLINE bool equals_v3v3(const float a[
  MINLINE bool compare_v2v2(const float a[2], const float b[2], const float limit)  ATTR_WARN_UNUSED_RESULT;
  MINLINE bool compare_v3v3(const float a[3], const float b[3], const float limit)  ATTR_WARN_UNUSED_RESULT;
  MINLINE bool compare_len_v3v3(const float a[3], const float b[3], const float limit)  ATTR_WARN_UNUSED_RESULT;
- MINLINE bool compare_len_v3v3_squared(const float a[3], const float b[3], const float limit)  ATTR_WARN_UNUSED_RESULT;
++MINLINE bool compare_len_squared_v3v3(const float a[3], const float b[3], const float limit)  ATTR_WARN_UNUSED_RESULT;
  
  MINLINE bool compare_v4v4(const float a[4], const float b[4], const float limit)  ATTR_WARN_UNUSED_RESULT;
  MINLINE bool equals_v4v4(const float a[4], const float b[4])  ATTR_WARN_UNUSED_RESULT;
diff --cc source/blender/blenlib/intern/math_vector_inline.c
index 8d1f8f4,4a18987..b4530e6
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@@ -925,27 -931,15 +931,27 @@@ MINLINE bool compare_len_v3v3(const flo
  	y = v1[1] - v2[1];
  	z = v1[2] - v2[2];
  
- 	return ((x * x + y * y + z * z) < (limit * limit));
+ 	return ((x * x + y * y + z * z) <= (limit * limit));
  }
  
 +/* same as above but limit has been pre-squared */
- MINLINE bool compare_len_v3v3_squared(const float v1[3], const float v2[3], const float limit)
++MINLINE bool compare_len_squared_v3v3(const float v1[3], const float v2[3], const float limit)
 +{
 +	float x, y, z;
 +
 +	x = v1[0] - v2[0];
 +	y = v1[1] - v2[1];
 +	z = v1[2] - v2[2];
 +
- 	return ((x * x + y * y + z * z) < (limit));
++	return ((x * x + y * y + z * z) <= limit);
 +}
 +
  MINLINE bool compare_v4v4(const float v1[4], const float v2[4], const float limit)
  {
- 	if (fabsf(v1[0] - v2[0]) < limit)
- 		if (fabsf(v1[1] - v2[1]) < limit)
- 			if (fabsf(v1[2] - v2[2]) < limit)
- 				if (fabsf(v1[3] - v2[3]) < limit)
+ 	if (fabsf(v1[0] - v2[0]) <= limit)
+ 		if (fabsf(v1[1] - v2[1]) <= limit)
+ 			if (fabsf(v1[2] - v2[2]) <= limit)
+ 				if (fabsf(v1[3] - v2[3]) <= limit)
  					return true;
  
  	return false;
diff --cc source/blender/editors/sculpt_paint/paint_image_2d.c
index 31679b3,4f67fc9..e4171a5
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@@ -1304,320 -1153,3 +1304,320 @@@ void paint_2d_stroke_done(void *ps
  
  	MEM_freeN(s);
  }
 +
 +static void paint_2d_fill_add_pixel_byte(int i, int j, ImBuf *ibuf, GSQueue *stack, BLI_bitmap *touched, float color[4], float threshold)
 +{
 +	int coordinate = j * ibuf->x + i;
 +
 +	if (i >= ibuf->x || i < 0 || j >= ibuf->y || j < 0)
 +		return;
 +
 +	if (!BLI_BITMAP_TEST(touched, coordinate)) {
 +		float color_f[4];
 +		unsigned char *color_b = (unsigned char *)(ibuf->rect + coordinate);
 +		rgba_uchar_to_float(color_f, color_b);
 +
- 		if (compare_len_v3v3_squared(color_f, color, threshold)) {
++		if (compare_len_squared_v3v3(color_f, color, threshold)) {
 +			BLI_gsqueue_push(stack, &coordinate);
 +		}
 +		BLI_BITMAP_SET(touched, coordinate, true);
 +	}
 +}
 +
 +static void paint_2d_fill_add_pixel_float(int i, int j, ImBuf *ibuf, GSQueue *stack, BLI_bitmap *touched, const float color[4], float threshold)
 +{
 +	int coordinate = j * ibuf->x + i;
 +
 +	if (i >= ibuf->x || i < 0 || j >= ibuf->y || j < 0)
 +		return;
 +
 +	if (!BLI_BITMAP_TEST(touched, coordinate)) {
- 		if (compare_len_v3v3_squared(ibuf->rect_float + 4 * coordinate, color, threshold)) {
++		if (compare_len_squared_v3v3(ibuf->rect_float + 4 * coordinate, color, threshold)) {
 +			BLI_gsqueue_push(stack, &coordinate);
 +		}
 +		BLI_BITMAP_SET(touched, coordinate, true);
 +	}
 +}
 +
 +/* this function expects linear space color values */
 +void paint_2d_bucket_fill(const bContext *C, const float color[3], Brush *br, float mouse_init[2], void *ps)
 +{
 +	SpaceImage *sima = CTX_wm_space_image(C);
 +	Image *ima = sima->image;
 +
 +	ImagePaintState *s = ps;
 +
 +	ImBuf *ibuf;
 +	int i = 0, j = 0;
 +	unsigned int color_b;
 +	float color_f[4];
 +	float strength = br ? br->alpha : 1.0f;
 +
 +	bool do_float;
 +
 +	if (!ima)
 +		return;
 +
 +	ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL);
 +
 +	if (!ibuf)
 +		return;
 +
 +	do_float = (ibuf->rect_float != NULL);
 +	/* first check if our image is float. If it is not we should correct the color to
 +	 * be in gamma space. strictly speaking this is not correct, but blender does not paint
 +	 * byte images in linear space */
 +	if (!do_float) {
 +		linearrgb_to_srgb_uchar3((unsigned char *)&color_b, color);
 +		*(((char *)&color_b) + 3) = strength * 255;
 +	}
 +	else {
 +		copy_v3_v3(color_f, color);
 +		color_f[3] = strength;
 +	}
 +
 +	if (!mouse_init || !br) {
 +		/* first case, no image UV, fill the whole image */
 +		ED_imapaint_dirty_region(ima, ibuf, 0, 0, ibuf->x, ibuf->y);
 +
 +		if (do_float) {
 +			for (; i < ibuf->x; i++) {
 +				for (j = 0; j < ibuf->y; j++) {
 +					blend_color_mix_float(ibuf->rect_float + 4 * (j * ibuf->x + i),
 +					                      ibuf->rect_float + 4 * (j * ibuf->x + i), color_f);
 +				}
 +			}
 +		}
 +		else {
 +			for (; i < ibuf->x; i++) {
 +				for (j = 0; j < ibuf->y; j++) {
 +					blend_color_mix_byte((unsigned char *)(ibuf->rect + j * ibuf->x + i),
 +					                     (unsigned char *)(ibuf->rect + j * ibuf->x + i), (unsigned char *)&color_b);
 +				}
 +			}
 +		}
 +	}
 +	else {
 +		/* second case, start sweeping the neighboring pixels, looking for pixels whose
 +		 * value is within the brush fill threshold from the fill color */
 +		GSQueue *stack;
 +		BLI_bitmap *touched;
 +		int coordinate;
 +		int width = ibuf->x;
 +		float image_init[2];
 +		int minx = ibuf->x, miny = ibuf->y, maxx = 0, maxy = 0;
 +		float pixel_color[4];
 +		float threshold_sq = br->fill_threshold * br->fill_threshold;
 +
 +		UI_view2d_region_to_view(s->v2d, mouse_init[0], mouse_init[1], &image_init[0], &image_init[1]);
 +
 +		i = image_init[0] * ibuf->x;
 +		j = image_init[1] * ibuf->y;
 +
 +		if (i >= ibuf->x || i < 0 || j > ibuf->y || j < 0) {
 +			BKE_image_release_ibuf(ima, ibuf, NULL);
 +			return;
 +		}
 +
 +		/* change image invalidation method later */
 +		ED_imapaint_dirty_region(ima, ibuf, 0, 0, ibuf->x, ibuf->y);
 +
 +		stack = BLI_gsqueue_new(sizeof(int));
 +		touched = BLI_BITMAP_NEW(ibuf->x * ibuf->y, "bucket_fill_bitmap");
 +
 +		coordinate = (j * ibuf->x + i);
 +
 +		if (do_float) {
 +			copy_v4_v4(pixel_color, ibuf->rect_float + 4 * coordinate);
 +		}
 +		else {
 +			int pixel_color_b = *(ibuf->rect + coordinate);
 +			rgba_uchar_to_float(pixel_color, (unsigned char *)&pixel_color_b);
 +		}
 +
 +		BLI_gsqueue_push(stack, &coordinate);
 +		BLI_BITMAP_SET(touched, coordinate, true);
 +
 +		if (do_float) {
 +			while (!BLI_gsqueue_is_empty(stack)) {
 +				BLI_gsqueue_pop(stack, &coordinate);
 +
 +				IMB_blend_color_float(ibuf->rect_float + 4 * (coordinate),
 +				                      ibuf->rect_float + 4 * (coordinate),
 +				                      color_f, br->blend);
 +
 +				/* reconstruct the coordinates here */
 +				i = coordinate % width;
 +				j = coordinate / width;
 +
 +				paint_2d_fill_add_pixel_float(i - 1, j - 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_float(i - 1, j, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_float(i - 1, j + 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_float(i, j + 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_float(i, j - 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_float(i + 1, j - 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_float(i + 1, j, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_float(i + 1, j + 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +
 +				if (i > maxx)
 +					maxx = i;
 +				if (i < minx)
 +					minx = i;
 +				if (j > maxy)
 +					maxy = j;
 +				if (i > miny)
 +					miny = j;
 +			}
 +		}
 +		else {
 +			while (!BLI_gsqueue_is_empty(stack)) {
 +				BLI_gsqueue_pop(stack, &coordinate);
 +
 +				IMB_blend_color_byte((unsigned char *)(ibuf->rect + coordinate),
 +				                     (unsigned char *)(ibuf->rect + coordinate),
 +				                     (unsigned char *)&color_b, br->blend);
 +
 +				/* reconstruct the coordinates here */
 +				i = coordinate % width;
 +				j = coordinate / width;
 +
 +				paint_2d_fill_add_pixel_byte(i - 1, j - 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_byte(i - 1, j, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_byte(i - 1, j + 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_byte(i, j + 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_byte(i, j - 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_byte(i + 1, j - 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_byte(i + 1, j, ibuf, stack, touched, pixel_color, threshold_sq);
 +				paint_2d_fill_add_pixel_byte(i + 1, j + 1, ibuf, stack, touched, pixel_color, threshold_sq);
 +
 +				if (i > maxx)
 +					maxx = i;
 +				if (i < minx)
 +					minx = i;
 +				if (j > maxy)
 +					maxy = j;
 +				if (i > miny)
 +					miny = j;
 +			}
 +		}
 +
 +		MEM_freeN(touched);
 +		BLI_gsqueue_free(stack);
 +	}
 +
 +	imapaint_image_update(sima, ima, ibuf, false);
 +	ED_imapaint_clear_partial_redraw();
 +
 +	BKE_image_release_ibuf(ima, ibuf, NULL);
 +
 +	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
 +}
 +
 +void paint_2d_gradient_fill (const bContext *C, Brush *br, float mouse_init[2], float mouse_final[2], void *ps)
 +{
 +	SpaceImage *sima = CTX_wm_space_image(C);
 +	Image *ima = sima->image;
 +	ImagePaintState *s = ps;
 +
 +	ImBuf *ibuf;
 +	unsigned short i = 0, j = 0;
 +	unsigned int

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list