[gimp] app: Move smooth to painttool and clean up the rest
- From: Alexia Death <alexiade src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: Move smooth to painttool and clean up the rest
- Date: Wed, 14 Sep 2011 17:44:54 +0000 (UTC)
commit d32fa80d1d98156a2825bf1380d24b0fd186f649
Author: Alexia Death <alexiadeath gmail com>
Date: Wed Sep 14 20:42:52 2011 +0300
app: Move smooth to painttool and clean up the rest
app/paint/gimpairbrush.c | 2 +-
app/paint/gimpbrushcore.c | 4 +-
app/paint/gimpink.c | 8 +--
app/paint/gimppaintcore.c | 140 ++++++++++++++++++++++-----------------------
app/paint/gimppaintcore.h | 5 +-
app/tools/gimppainttool.c | 2 +
6 files changed, 81 insertions(+), 80 deletions(-)
---
diff --git a/app/paint/gimpairbrush.c b/app/paint/gimpairbrush.c
index 0af6359..ae71044 100644
--- a/app/paint/gimpairbrush.c
+++ b/app/paint/gimpairbrush.c
@@ -220,7 +220,7 @@ gimp_airbrush_timeout (gpointer data)
GimpAirbrush *airbrush = GIMP_AIRBRUSH (data);
GimpCoords coords;
- gimp_paint_core_get_current_coords (GIMP_PAINT_CORE (airbrush), airbrush->paint_options, &coords);
+ gimp_paint_core_get_current_coords (GIMP_PAINT_CORE (airbrush), &coords);
gimp_airbrush_paint (GIMP_PAINT_CORE (airbrush),
airbrush->drawable,
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index 6468c57..7185a6a 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -297,7 +297,7 @@ gimp_brush_core_pre_paint (GimpPaintCore *paint_core,
gdouble scale;
gimp_paint_core_get_last_coords (paint_core, &last_coords);
- gimp_paint_core_get_current_coords (paint_core, paint_options, ¤t_coords);
+ gimp_paint_core_get_current_coords (paint_core, ¤t_coords);
/* If we current point == last point, check if the brush
* wants to be painted in that case. (Direction dependent
@@ -475,7 +475,7 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
g_return_if_fail (GIMP_IS_BRUSH (core->brush));
gimp_paint_core_get_last_coords (paint_core, &last_coords);
- gimp_paint_core_get_current_coords (paint_core, paint_options, ¤t_coords);
+ gimp_paint_core_get_current_coords (paint_core, ¤t_coords);
/* Zero sized brushes are unfit for interpolate, so we just let
* paint core fail on its own
diff --git a/app/paint/gimpink.c b/app/paint/gimpink.c
index a83cc48..455549c 100644
--- a/app/paint/gimpink.c
+++ b/app/paint/gimpink.c
@@ -146,18 +146,16 @@ gimp_ink_paint (GimpPaintCore *paint_core,
{
GimpInk *ink = GIMP_INK (paint_core);
GimpCoords last_coords;
- GimpCoords current_coords = *coords;
gimp_paint_core_get_last_coords (paint_core, &last_coords);
- gimp_paint_core_get_current_coords (paint_core, paint_options, ¤t_coords);
switch (paint_state)
{
case GIMP_PAINT_STATE_INIT:
- if (current_coords.x == last_coords.x &&
- current_coords.y == last_coords.y)
+ if (coords->x == last_coords.x &&
+ coords->y == last_coords.y)
{
/* start with new blobs if we're not interpolating */
@@ -185,7 +183,7 @@ gimp_ink_paint (GimpPaintCore *paint_core,
break;
case GIMP_PAINT_STATE_MOTION:
- gimp_ink_motion (paint_core, drawable, paint_options, ¤t_coords, time);
+ gimp_ink_motion (paint_core, drawable, paint_options, coords, time);
break;
case GIMP_PAINT_STATE_FINISH:
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index 7aa39c2..18892b8 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -111,10 +111,6 @@ static void paint_mask_to_canvas_buf (GimpPaintCore *core,
gdouble paint_opacity);
static void canvas_tiles_to_canvas_buf (GimpPaintCore *core);
-static void gimp_paint_core_smooth_coords (GimpPaintCore *core,
- GimpPaintOptions *paint_options,
- GimpCoords *coords);
-
G_DEFINE_TYPE (GimpPaintCore, gimp_paint_core, GIMP_TYPE_OBJECT)
@@ -628,7 +624,6 @@ gimp_paint_core_set_current_coords (GimpPaintCore *core,
void
gimp_paint_core_get_current_coords (GimpPaintCore *core,
- GimpPaintOptions *paint_options,
GimpCoords *coords)
{
g_return_if_fail (GIMP_IS_PAINT_CORE (core));
@@ -636,9 +631,6 @@ gimp_paint_core_get_current_coords (GimpPaintCore *core,
*coords = core->cur_coords;
- gimp_paint_core_smooth_coords (core,
- paint_options,
- coords);
}
void
@@ -1104,6 +1096,75 @@ gimp_paint_core_replace (GimpPaintCore *core,
core->canvas_buf->height);
}
+/**
+ * Smooth and store coords in the stroke buffer
+ */
+
+void
+gimp_paint_core_smooth_coords (GimpPaintCore *core,
+ GimpPaintOptions *paint_options,
+ GimpCoords *coords)
+{
+ GimpSmoothingOptions *smoothing_options = paint_options->smoothing_options;
+ GArray *history = core->stroke_buffer;
+
+ if (core->stroke_buffer == NULL)
+ return; /* Paint core has not initalized yet */
+
+ if (smoothing_options->use_smoothing &&
+ smoothing_options->smoothing_quality > 0)
+ {
+ gint i;
+ guint length;
+ gint min_index;
+ gdouble gaussian_weight = 0.0;
+ gdouble gaussian_weight2 = SQR (smoothing_options->smoothing_factor);
+ gdouble velocity_sum = 0.0;
+ gdouble scale_sum = 0.0;
+
+ g_array_append_val (history, *coords);
+
+ if (history->len < 2)
+ return; /* Just dont bother, nothing to do */
+
+ coords->x = coords->y = 0.0;
+
+ length = MIN (smoothing_options->smoothing_quality, history->len);
+
+ min_index = history->len - length;
+
+ if (gaussian_weight2 != 0.0)
+ gaussian_weight = 1 / (sqrt (2 * G_PI) * smoothing_options->smoothing_factor);
+
+ for (i = history->len - 1; i >= min_index; i--)
+ {
+ gdouble rate = 0.0;
+ GimpCoords *next_coords = &g_array_index (history,
+ GimpCoords, i);
+
+ if (gaussian_weight2 != 0.0)
+ {
+ /* We use gaussian function with velocity as a window function */
+ velocity_sum += next_coords->velocity * 100;
+ rate = gaussian_weight * exp (-velocity_sum*velocity_sum / (2 * gaussian_weight2));
+ }
+
+ scale_sum += rate;
+ coords->x += rate * next_coords->x;
+ coords->y += rate * next_coords->y;
+ }
+
+ if (scale_sum != 0.0)
+ {
+ coords->x /= scale_sum;
+ coords->y /= scale_sum;
+ }
+
+ }
+
+}
+
+
static void
canvas_tiles_to_canvas_buf (GimpPaintCore *core)
{
@@ -1261,66 +1322,3 @@ gimp_paint_core_validate_canvas_tiles (GimpPaintCore *core,
}
}
-static void
-gimp_paint_core_smooth_coords (GimpPaintCore *core,
- GimpPaintOptions *paint_options,
- GimpCoords *coords)
-{
- GimpSmoothingOptions *smoothing_options = paint_options->smoothing_options;
- GArray *history = core->stroke_buffer;
-
- if (core->stroke_buffer == NULL)
- return; /* Paint core has not initalized yet */
-
- if (smoothing_options->use_smoothing &&
- smoothing_options->smoothing_quality > 0)
- {
- gint i;
- guint length;
- gint min_index;
- gdouble gaussian_weight = 0.0;
- gdouble gaussian_weight2 = SQR (smoothing_options->smoothing_factor);
- gdouble velocity_sum = 0.0;
- gdouble scale_sum = 0.0;
-
- g_array_append_val (history, *coords);
-
- if (history->len < 2)
- return; /* Just dont bother, nothing to do */
-
- coords->x = coords->y = 0.0;
-
- length = MIN (smoothing_options->smoothing_quality, history->len);
-
- min_index = history->len - length;
-
- if (gaussian_weight2 != 0.0)
- gaussian_weight = 1 / (sqrt (2 * G_PI) * smoothing_options->smoothing_factor);
-
- for (i = history->len - 1; i >= min_index; i--)
- {
- gdouble rate = 0.0;
- GimpCoords *next_coords = &g_array_index (history,
- GimpCoords, i);
-
- if (gaussian_weight2 != 0.0)
- {
- /* We use gaussian function with velocity as a window function */
- velocity_sum += next_coords->velocity * 100;
- rate = gaussian_weight * exp (-velocity_sum*velocity_sum / (2 * gaussian_weight2));
- }
-
- scale_sum += rate;
- coords->x += rate * next_coords->x;
- coords->y += rate * next_coords->y;
- }
-
- if (scale_sum != 0.0)
- {
- coords->x /= scale_sum;
- coords->y /= scale_sum;
- }
-
- }
-
-}
diff --git a/app/paint/gimppaintcore.h b/app/paint/gimppaintcore.h
index dae6d87..970edb8 100644
--- a/app/paint/gimppaintcore.h
+++ b/app/paint/gimppaintcore.h
@@ -139,7 +139,6 @@ void gimp_paint_core_interpolate (GimpPaintCore *core,
void gimp_paint_core_set_current_coords (GimpPaintCore *core,
const GimpCoords *coords);
void gimp_paint_core_get_current_coords (GimpPaintCore *core,
- GimpPaintOptions *paint_options,
GimpCoords *coords);
void gimp_paint_core_set_last_coords (GimpPaintCore *core,
@@ -203,5 +202,9 @@ void gimp_paint_core_validate_canvas_tiles (GimpPaintCore *core,
gint w,
gint h);
+void gimp_paint_core_smooth_coords (GimpPaintCore *core,
+ GimpPaintOptions *paint_options,
+ GimpCoords *coords);
+
#endif /* __GIMP_PAINT_CORE_H__ */
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index db0d54c..cb7f8d0 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -416,6 +416,8 @@ gimp_paint_tool_motion (GimpTool *tool,
curr_coords = *coords;
+ gimp_paint_core_smooth_coords (core, paint_options, &curr_coords);
+
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
curr_coords.x -= off_x;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]