Commit c29aefcc authored by Michael Natterer's avatar Michael Natterer 😴

app: fix coding style in the new smoothing code

parent efd6c905
......@@ -521,10 +521,12 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
gimp_paint_core_get_last_coords (paint_core, &last_coords);
gimp_paint_core_get_current_coords (paint_core, &current_coords);
if (paint_core->stroke_buffer) {
current_coords = gimp_paint_core_get_smoothed_coords(paint_core, paint_options, &current_coords);
gimp_paint_core_set_current_coords (paint_core, &current_coords);
}
if (paint_core->stroke_buffer)
{
current_coords = gimp_paint_core_get_smoothed_coords (paint_core,
paint_options, &current_coords);
gimp_paint_core_set_current_coords (paint_core, &current_coords);
}
/*Zero sized brushes are unfit for interpolate,
* so we just let paint core fail onits own
......
......@@ -258,7 +258,8 @@ gimp_ink_motion (GimpPaintCore *paint_core,
image = gimp_item_get_image (GIMP_ITEM (drawable));
modified_coords = gimp_paint_core_get_smoothed_coords(paint_core, paint_options, coords);
modified_coords = gimp_paint_core_get_smoothed_coords (paint_core,
paint_options, coords);
if (! ink->last_blob)
{
......@@ -280,12 +281,12 @@ gimp_ink_motion (GimpPaintCore *paint_core,
else
{
GimpBlob *blob = ink_pen_ellipse (options,
modified_coords.x,
modified_coords.y,
modified_coords.pressure,
modified_coords.xtilt,
modified_coords.ytilt,
modified_coords.velocity * 100);
modified_coords.x,
modified_coords.y,
modified_coords.pressure,
modified_coords.xtilt,
modified_coords.ytilt,
modified_coords.velocity * 100);
blob_union = gimp_blob_convex_union (ink->last_blob, blob);
......
......@@ -21,7 +21,6 @@
#include "gimppaintcore.h"
#include "gimpink-blob.h"
#include "gimppaintoptions.h"
#define GIMP_TYPE_INK (gimp_ink_get_type ())
......@@ -40,8 +39,8 @@ struct _GimpInk
GimpBlob *start_blob; /* starting blob (for undo) */
GimpBlob *cur_blob; /* current blob */
GimpBlob *last_blob; /* blob for last cursor position */
GimpBlob *cur_blob; /* current blob */
GimpBlob *last_blob; /* blob for last cursor position */
};
struct _GimpInkClass
......
......@@ -353,14 +353,14 @@ gimp_paint_core_start (GimpPaintCore *core,
item = GIMP_ITEM (drawable);
if (core->stroke_buffer != NULL)
{
g_array_free(core->stroke_buffer, TRUE);
core->stroke_buffer = NULL;
}
if (core->stroke_buffer)
{
g_array_free (core->stroke_buffer, TRUE);
core->stroke_buffer = NULL;
}
core->stroke_buffer = g_array_sized_new (TRUE, TRUE,
sizeof(GimpCoords),
sizeof (GimpCoords),
STROKE_BUFFER_INIT_SIZE);
core->cur_coords = *coords;
......@@ -430,10 +430,11 @@ gimp_paint_core_finish (GimpPaintCore *core,
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
if (core->stroke_buffer) {
g_array_free (core->stroke_buffer, TRUE);
core->stroke_buffer = NULL;
}
if (core->stroke_buffer)
{
g_array_free (core->stroke_buffer, TRUE);
core->stroke_buffer = NULL;
}
image = gimp_item_get_image (GIMP_ITEM (drawable));
......@@ -1250,39 +1251,41 @@ gimp_paint_core_validate_canvas_tiles (GimpPaintCore *core,
}
}
GimpCoords gimp_paint_core_get_smoothed_coords (GimpPaintCore *core,
GimpPaintOptions *paint_options,
const GimpCoords *original_coords)
GimpCoords
gimp_paint_core_get_smoothed_coords (GimpPaintCore *core,
GimpPaintOptions *paint_options,
const GimpCoords *original_coords)
{
GimpSmoothingOptions *smoothing_options = paint_options->smoothing_options;
GArray *history = core->stroke_buffer;
GArray *history = core->stroke_buffer;
if (smoothing_options->use_smoothing && smoothing_options->smoothing_quality > 0)
if (smoothing_options->use_smoothing &&
smoothing_options->smoothing_quality > 0)
{
int i;
guint length;
gint min_index;
GimpCoords result = *original_coords;
gdouble gaussian_weight = 0.0;
gdouble gaussian_weight2 = SQR (smoothing_options->smoothing_factor);
gdouble velocity_sum = 0.0;
gdouble scale_sum = 0.0;
gint i;
guint length;
gint min_index;
GimpCoords result = *original_coords;
gdouble gaussian_weight = 0.0;
gdouble gaussian_weight2 = SQR (smoothing_options->smoothing_factor);
gdouble velocity_sum = 0.0;
gdouble scale_sum = 0.0;
result.x = result.y = 0.0;
g_array_append_val (history, *original_coords);
length = MIN(smoothing_options->smoothing_quality, history->len);
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,
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)
......@@ -1295,7 +1298,8 @@ GimpCoords gimp_paint_core_get_smoothed_coords (GimpPaintCore *core,
scale_sum += rate;
result.x += rate * next_coords->x;
result.y += rate * next_coords->y;
}
}
if (scale_sum != 0.0)
{
result.x /= scale_sum;
......@@ -1304,5 +1308,6 @@ GimpCoords gimp_paint_core_get_smoothed_coords (GimpPaintCore *core,
return result;
}
return *original_coords;
return *original_coords;
}
......@@ -21,7 +21,6 @@
#include "libgimpmath/gimpvector.h"
#include "core/gimpobject.h"
#include "gimppaintoptions.h" /* GimpCircularQueue */
#define GIMP_TYPE_PAINT_CORE (gimp_paint_core_get_type ())
......
......@@ -36,6 +36,7 @@
#include "gimp-intl.h"
#define DEFAULT_BRUSH_SIZE 20.0
#define DEFAULT_BRUSH_ASPECT_RATIO 1.0
#define DEFAULT_BRUSH_ANGLE 0.0
......@@ -64,6 +65,7 @@
#define DEFAULT_SMOOTHING_QUALITY 20
#define DEFAULT_SMOOTHING_FACTOR 50
enum
{
PROP_0,
......@@ -255,16 +257,15 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_SMOOTHING_QUALITY,
"smoothing-quality", NULL,
1,
100,
DEFAULT_SMOOTHING_QUALITY,
1, 100, DEFAULT_SMOOTHING_QUALITY,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_SMOOTHING_FACTOR,
"smoothing-factor", NULL,
3.0, 1000.0, DEFAULT_SMOOTHING_FACTOR, /* Max velocity is set at 3.
* Allowing for smoothing factor to be
* less than velcoty results in numeric
* instablility */
3.0, 1000.0, DEFAULT_SMOOTHING_FACTOR,
/* Max velocity is set at 3.
* Allowing for smoothing factor to be
* less than velcoty results in numeric
* instablility */
GIMP_PARAM_STATIC_STRINGS);
}
......@@ -298,9 +299,9 @@ gimp_paint_options_finalize (GObject *object)
{
GimpPaintOptions *options = GIMP_PAINT_OPTIONS (object);
g_slice_free (GimpJitterOptions, options->jitter_options);
g_slice_free (GimpFadeOptions, options->fade_options);
g_slice_free (GimpGradientOptions, options->gradient_options);
g_slice_free (GimpJitterOptions, options->jitter_options);
g_slice_free (GimpFadeOptions, options->fade_options);
g_slice_free (GimpGradientOptions, options->gradient_options);
g_slice_free (GimpSmoothingOptions, options->smoothing_options);
G_OBJECT_CLASS (parent_class)->finalize (object);
......@@ -312,11 +313,11 @@ gimp_paint_options_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
GimpPaintOptions *options = GIMP_PAINT_OPTIONS (object);
GimpFadeOptions *fade_options = options->fade_options;
GimpJitterOptions *jitter_options = options->jitter_options;
GimpGradientOptions *gradient_options = options->gradient_options;
GimpSmoothingOptions *smoothing_options= options->smoothing_options;
GimpPaintOptions *options = GIMP_PAINT_OPTIONS (object);
GimpFadeOptions *fade_options = options->fade_options;
GimpJitterOptions *jitter_options = options->jitter_options;
GimpGradientOptions *gradient_options = options->gradient_options;
GimpSmoothingOptions *smoothing_options = options->smoothing_options;
switch (property_id)
{
......@@ -436,7 +437,7 @@ gimp_paint_options_get_property (GObject *object,
GimpFadeOptions *fade_options = options->fade_options;
GimpJitterOptions *jitter_options = options->jitter_options;
GimpGradientOptions *gradient_options = options->gradient_options;
GimpSmoothingOptions *smoothing_options= options->smoothing_options;
GimpSmoothingOptions *smoothing_options = options->smoothing_options;
switch (property_id)
{
......@@ -529,7 +530,7 @@ gimp_paint_options_get_property (GObject *object,
break;
case PROP_USE_SMOOTHING:
g_value_set_boolean(value, smoothing_options->use_smoothing);
g_value_set_boolean (value, smoothing_options->use_smoothing);
break;
case PROP_SMOOTHING_QUALITY:
......
......@@ -173,9 +173,9 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
gtk_widget_show (frame);
}
frame = smoothing_options_gui (options, tool_type);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
frame = smoothing_options_gui (options, tool_type);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
/* the "incremental" toggle */
if (tool_type == GIMP_TYPE_PENCIL_TOOL ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment