[Bf-blender-cvs] [39db2d0] soc-2013-paint: Merge branch 'master' into soc-2013-paint
Antony Riakiotakis
noreply at git.blender.org
Wed Jun 18 21:16:06 CEST 2014
Commit: 39db2d010bab6303f242e756bab9f749489d85a0
Author: Antony Riakiotakis
Date: Wed Jun 18 22:14:57 2014 +0300
https://developer.blender.org/rB39db2d010bab6303f242e756bab9f749489d85a0
Merge branch 'master' into soc-2013-paint
Conflicts:
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/space_view3d/drawmesh.c
===================================================================
===================================================================
diff --cc source/blender/editors/sculpt_paint/paint_image_2d.c
index 4e1a7e0,667b487..bc08eb1
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@@ -1299,327 -1153,3 +1299,327 @@@ 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_GET(touched, coordinate)) {
++ if (!BLI_BITMAP_TEST(touched, coordinate)) {
+ float color_f[4];
+ unsigned char *color_b = (unsigned char *)(ibuf->rect + coordinate);
+ float luminance;
+ rgba_uchar_to_float(color_f, color_b);
+
+ sub_v3_v3(color_f, color);
+
+ luminance = (fabs(color_f[0]) + fabs(color_f[0]) + fabs(color_f[0]))/3.0;
+ if (luminance < threshold) {
+ BLI_gsqueue_push(stack, &coordinate);
+ }
- BLI_BITMAP_SET(touched, 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, 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_GET(touched, coordinate)) {
++ if (!BLI_BITMAP_TEST(touched, coordinate)) {
+ float color_f[4];
+ float luminance;
+ sub_v3_v3v3(color_f, ibuf->rect_float + 4 * coordinate, color);
+
+ luminance = (fabs(color_f[0]) + fabs(color_f[0]) + fabs(color_f[0]))/3.0;
+ if (luminance < threshold) {
+ BLI_gsqueue_push(stack, &coordinate);
+ }
- BLI_BITMAP_SET(touched, coordinate);
++ BLI_BITMAP_SET(touched, coordinate, true);
+ }
+}
+
+/* this function expects linear space color values */
+void paint_2d_bucket_fill (const bContext *C, 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.0;
+
+ 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 colour 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];
+
+ 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);
++ 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, br->fill_threshold);
+ paint_2d_fill_add_pixel_float(i - 1, j, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_float(i - 1, j + 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_float(i, j + 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_float(i, j - 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_float(i + 1, j - 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_float(i + 1, j, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_float(i + 1, j + 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+
+ 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, br->fill_threshold);
+ paint_2d_fill_add_pixel_byte(i - 1, j, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_byte(i - 1, j + 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_byte(i, j + 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_byte(i, j - 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_byte(i + 1, j - 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_byte(i + 1, j, ibuf, stack, touched, pixel_color, br->fill_threshold);
+ paint_2d_fill_add_pixel_byte(i + 1, j + 1, ibuf, stack, touched, pixel_color, br->fill_threshold);
+
+ 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 color_b;
+ float color_f[4];
+ float image_init[2], image_final[2];
+ float tangent[2];
+ float line_len_sq_inv, line_len;
+
+ bool do_float;
+
+ if (!ima)
+ return;
+
+ ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL);
+
+ if (!ibuf)
+ return;
+
+ UI_view2d_region_to_view(s->v2d, mouse_final[0], mouse_final[1], &image_final[0], &image_final[1]);
+ UI_view2d_region_to_view(s->v2d, mouse_init[0], mouse_init[1], &image_init[0], &image_init[1]);
+
+ image_final[0] *= ibuf->x;
+ image_final[1] *= ibuf->y;
+
+ image_init[0] *= ibuf->x;
+ image_init[1] *= ibuf->y;
+
+ /* some math to get needed gradient variables */
+ sub_v2_v2v2(tangent, image_final, image_init);
+ line_len = len_squared_v2(tangent);
+ line_len_sq_inv = 1.0/line_len;
+ line_len = sqrt(line_len);
+
+ do_float = (ibuf->rect_float != NULL);
+
+ /* this will be substituted by something else when selection is available */
+ 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++) {
+ float f;
+ float p[2] = {i - image_init[0], j - image_init[1]};
+
+ switch (br->gradient_fill_mode) {
+ case BRUSH_GRADIENT_LINEAR:
+ {
+ f = dot_v2v2(p, tangent)*line_len_sq_inv;
+ break;
+ }
+ case BRUSH_GRADIENT_RADIAL:
+ {
+ f = len_v2(p)/line_len;
+ break;
+ }
+ }
+ do_colorband(br->gradient, f, color_f);
+ /* convert to premultiplied */
+ mul_v3_fl(color_f, color_f[3]);
+ color_f[3] *= br->alpha;
+ IMB_blend_color_float(ibuf->rect_float + 4 * (j * ibuf->x + i),
+ ibuf->rect_float + 4 * (j * ibuf->x + i),
+ color_f, br->blend);
+ }
+ }
+ }
+ else {
+ for (; i < ibuf->x; i++) {
+ for (j = 0; j < ibuf->y; j++) {
+ float f;
+ float p[2] = {i - image_init[0], j - image_init[1]};
+
+ switch (br->gradient_fill_mode) {
+ case BRUSH_GRADIENT_LINEAR:
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list