[gimp/soc-2011-warp] gimpoperationwarp: implement erase and smooth behavior
- From: Michael Murà <mmure src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2011-warp] gimpoperationwarp: implement erase and smooth behavior
- Date: Sat, 2 Jul 2011 12:01:41 +0000 (UTC)
commit ae702511f2803f1300997a8ccdb48cfd2d722cfe
Author: Michael Murà <batolettre gmail com>
Date: Sat Jul 2 14:00:51 2011 +0200
gimpoperationwarp: implement erase and smooth behavior
app/gegl/gimp-gegl-enums.c | 4 ++++
app/gegl/gimp-gegl-enums.h | 4 +++-
app/gegl/gimpoperationwarp.c | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-enums.c b/app/gegl/gimp-gegl-enums.c
index 944c030..2cbbefe 100644
--- a/app/gegl/gimp-gegl-enums.c
+++ b/app/gegl/gimp-gegl-enums.c
@@ -48,6 +48,8 @@ gimp_warp_behavior_get_type (void)
{ GIMP_WARP_BEHAVIOR_SHRINK, "GIMP_WARP_BEHAVIOR_SHRINK", "shrink" },
{ GIMP_WARP_BEHAVIOR_SWIRL_CW, "GIMP_WARP_BEHAVIOR_SWIRL_CW", "swirl-cw" },
{ GIMP_WARP_BEHAVIOR_SWIRL_CCW, "GIMP_WARP_BEHAVIOR_SWIRL_CCW", "swirl-ccw" },
+ { GIMP_WARP_BEHAVIOR_ERASE, "GIMP_WARP_BEHAVIOR_ERASE", "erase" },
+ { GIMP_WARP_BEHAVIOR_SMOOTH, "GIMP_WARP_BEHAVIOR_SMOOTH", "smooth" },
{ 0, NULL, NULL }
};
@@ -58,6 +60,8 @@ gimp_warp_behavior_get_type (void)
{ GIMP_WARP_BEHAVIOR_SHRINK, NC_("warp-behavior", "Shrink area"), NULL },
{ GIMP_WARP_BEHAVIOR_SWIRL_CW, NC_("warp-behavior", "Swirl clockwise"), NULL },
{ GIMP_WARP_BEHAVIOR_SWIRL_CCW, NC_("warp-behavior", "Swirl counter-clockwise"), NULL },
+ { GIMP_WARP_BEHAVIOR_ERASE, NC_("warp-behavior", "Erase warping"), NULL },
+ { GIMP_WARP_BEHAVIOR_SMOOTH, NC_("warp-behavior", "Smooth warping"), NULL },
{ 0, NULL, NULL }
};
diff --git a/app/gegl/gimp-gegl-enums.h b/app/gegl/gimp-gegl-enums.h
index cd53d5e..9f455ef 100644
--- a/app/gegl/gimp-gegl-enums.h
+++ b/app/gegl/gimp-gegl-enums.h
@@ -41,7 +41,9 @@ typedef enum
GIMP_WARP_BEHAVIOR_GROW, /*< desc="Grow area" >*/
GIMP_WARP_BEHAVIOR_SHRINK, /*< desc="Shrink area" >*/
GIMP_WARP_BEHAVIOR_SWIRL_CW, /*< desc="Swirl clockwise" >*/
- GIMP_WARP_BEHAVIOR_SWIRL_CCW /*< desc="Swirl counter-clockwise" >*/
+ GIMP_WARP_BEHAVIOR_SWIRL_CCW, /*< desc="Swirl counter-clockwise" >*/
+ GIMP_WARP_BEHAVIOR_ERASE, /*< desc="Erase warping" >*/
+ GIMP_WARP_BEHAVIOR_SMOOTH /*< desc="Smooth warping" >*/
} GimpWarpBehavior;
#endif /* __GIMP_GEGL_ENUMS_H__ */
diff --git a/app/gegl/gimpoperationwarp.c b/app/gegl/gimpoperationwarp.c
index 7f8d5c1..e19c2da 100644
--- a/app/gegl/gimpoperationwarp.c
+++ b/app/gegl/gimpoperationwarp.c
@@ -252,6 +252,7 @@ gimp_operation_warp_stamp (GimpOperationWarp *ow,
GeglBufferIterator *it;
Babl *format;
gdouble influence;
+ gdouble x_mean, y_mean;
gint x_iter, y_iter;
GeglRectangle area = {x - ow->size / 2.0,
y - ow->size / 2.0,
@@ -267,6 +268,32 @@ gimp_operation_warp_stamp (GimpOperationWarp *ow,
return;
}
+ /* If needed, compute the mean deformation */
+ if (ow->behavior == GIMP_WARP_BEHAVIOR_SMOOTH)
+ {
+ gint pixel_count = 0;
+ x_mean = y_mean = 0.0;
+
+ it = gegl_buffer_iterator_new (ow->buffer, &area, format, GEGL_BUFFER_READ);
+
+ while (gegl_buffer_iterator_next (it))
+ {
+ gint n_pixels = it->length;
+ gfloat *coords = it->data[0];
+
+ while (n_pixels--)
+ {
+ x_mean += coords[0];
+ y_mean += coords[1];
+ coords += 2;
+ }
+ pixel_count += it->roi->width * it->roi->height;
+ }
+ x_mean /= pixel_count;
+ y_mean /= pixel_count;
+ }
+
+
format = babl_format_n (babl_type ("float"), 2);
it = gegl_buffer_iterator_new (ow->buffer, &area, format, GEGL_BUFFER_READWRITE);
@@ -308,6 +335,14 @@ gimp_operation_warp_stamp (GimpOperationWarp *ow,
coords[0] -= influence * (y_iter - y) / ow->size;
coords[1] += influence * (x_iter - x) / ow->size;
break;
+ case GIMP_WARP_BEHAVIOR_ERASE:
+ coords[0] *= 1.0 - MIN (influence, 1.0);
+ coords[1] *= 1.0 - MIN (influence, 1.0);
+ break;
+ case GIMP_WARP_BEHAVIOR_SMOOTH:
+ coords[0] -= influence * (coords[0] - x_mean);
+ coords[1] -= influence * (coords[1] - y_mean);
+ break;
}
coords += 2;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]