[gthumb] pass the curve type to gth_curve_new



commit 81f99e0c05f1999183ac42f093b13a495487c70d
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Jan 7 12:30:00 2015 +0100

    pass the curve type to gth_curve_new
    
    this allows to remove duplicated code

 extensions/file_tools/gth-curve-editor.c     |    2 +-
 extensions/file_tools/gth-curve.c            |   74 ++++++++++++--------------
 extensions/file_tools/gth-curve.h            |    8 ++-
 extensions/file_tools/gth-file-tool-curves.c |    2 +-
 4 files changed, 42 insertions(+), 44 deletions(-)
---
diff --git a/extensions/file_tools/gth-curve-editor.c b/extensions/file_tools/gth-curve-editor.c
index ce5cabc..2e4edeb 100644
--- a/extensions/file_tools/gth-curve-editor.c
+++ b/extensions/file_tools/gth-curve-editor.c
@@ -867,7 +867,7 @@ gth_curve_editor_init (GthCurveEditor *self)
        self->priv->scale_type = GTH_HISTOGRAM_SCALE_LINEAR;
 
        for (c = 0; c < GTH_HISTOGRAM_N_CHANNELS; c++) {
-               self->priv->curve[c] = gth_bezier_new (NULL);
+               self->priv->curve[c] = gth_curve_new (GTH_TYPE_BEZIER, NULL);
                gth_curve_editor_reset_channel (self, c);
        }
 
diff --git a/extensions/file_tools/gth-curve.c b/extensions/file_tools/gth-curve.c
index 0789b27..ba15388 100644
--- a/extensions/file_tools/gth-curve.c
+++ b/extensions/file_tools/gth-curve.c
@@ -30,6 +30,41 @@
 G_DEFINE_TYPE (GthCurve, gth_curve, G_TYPE_OBJECT)
 
 
+GthCurve *
+gth_curve_new (GType            curve_type,
+              GthPoints        *points)
+{
+       GthCurve *curve;
+
+       curve = g_object_new (curve_type, NULL);
+       gth_curve_set_points (curve, points);
+
+       return curve;
+}
+
+
+GthCurve *
+gth_curve_new_for_points (GType                 curve_type,
+                         int            n_points,
+                         ...)
+{
+       GthCurve  *curve;
+       va_list    args;
+       int        i;
+       GthPoints  points;
+
+       curve = g_object_new (curve_type, NULL);
+
+       va_start (args, n_points);
+       gth_points_init (&points, 0);
+       gth_points_set_pointv (&points, args, n_points);
+       gth_curve_set_points (curve, &points);
+       va_end (args);
+
+       return curve;
+}
+
+
 void
 gth_curve_set_points (GthCurve *curve,
                      GthPoints *points)
@@ -322,19 +357,6 @@ gth_spline_init (GthSpline *spline)
 }
 
 
-GthCurve *
-gth_spline_new (GthPoints *points)
-{
-       GthSpline *spline;
-       int        i;
-
-       spline = g_object_new (GTH_TYPE_SPLINE, NULL);
-       gth_curve_set_points (GTH_CURVE (spline), points);
-
-       return GTH_CURVE (spline);
-}
-
-
 /* -- GthCSpline (https://en.wikipedia.org/wiki/Cubic_Hermite_spline) -- */
 
 
@@ -547,19 +569,6 @@ gth_cspline_init (GthCSpline *spline)
 }
 
 
-GthCurve *
-gth_cspline_new (GthPoints *points)
-{
-       GthCSpline *spline;
-       int         i;
-
-       spline = g_object_new (GTH_TYPE_CSPLINE, NULL);
-       gth_curve_set_points (GTH_CURVE (spline), points);
-
-       return GTH_CURVE (spline);
-}
-
-
 /* -- GthBezier -- */
 
 
@@ -726,16 +735,3 @@ gth_bezier_init (GthBezier *spline)
        spline->k = NULL;
        spline->linear = TRUE;
 }
-
-
-GthCurve *
-gth_bezier_new (GthPoints *points)
-{
-       GthBezier *spline;
-       int        i;
-
-       spline = g_object_new (GTH_TYPE_BEZIER, NULL);
-       gth_curve_set_points (GTH_CURVE (spline), points);
-
-       return GTH_CURVE (spline);
-}
diff --git a/extensions/file_tools/gth-curve.h b/extensions/file_tools/gth-curve.h
index 8b90d27..0b62a54 100644
--- a/extensions/file_tools/gth-curve.h
+++ b/extensions/file_tools/gth-curve.h
@@ -55,6 +55,11 @@ typedef struct {
 } GthCurveClass;
 
 GType          gth_curve_get_type              (void);
+GthCurve *      gth_curve_new                  (GType           curve_type,
+                                                GthPoints      *points);
+GthCurve *      gth_curve_new_for_points        (GType          curve_type,
+                                                int             n_points,
+                                                ...);
 void           gth_curve_set_points            (GthCurve       *curve,
                                                 GthPoints      *points);
 GthPoints *    gth_curve_get_points            (GthCurve       *curve);
@@ -82,7 +87,6 @@ typedef struct {
 typedef GthCurveClass GthSplineClass;
 
 GType          gth_spline_get_type             (void);
-GthCurve *     gth_spline_new                  (GthPoints      *points);
 
 
 /* -- GthCSpline -- */
@@ -103,7 +107,6 @@ typedef struct {
 typedef GthCurveClass GthCSplineClass;
 
 GType          gth_cspline_get_type            (void);
-GthCurve *     gth_cspline_new                 (GthPoints      *points);
 
 
 /* -- GthBezier -- */
@@ -125,7 +128,6 @@ typedef struct {
 typedef GthCurveClass GthBezierClass;
 
 GType          gth_bezier_get_type             (void);
-GthCurve *     gth_bezier_new                  (GthPoints      *points);
 
 
 G_END_DECLS
diff --git a/extensions/file_tools/gth-file-tool-curves.c b/extensions/file_tools/gth-file-tool-curves.c
index 6b5bd86..8b6bdd0 100644
--- a/extensions/file_tools/gth-file-tool-curves.c
+++ b/extensions/file_tools/gth-file-tool-curves.c
@@ -227,7 +227,7 @@ task_data_new (GthPoints *points)
        task_data = g_new (TaskData, 1);
        for (c = 0; c < GTH_HISTOGRAM_N_CHANNELS; c++) {
                task_data->value_map[c] = NULL;
-               task_data->curve[c] = gth_bezier_new (&points[c]);
+               task_data->curve[c] = gth_curve_new (GTH_TYPE_BEZIER, points + c);
        }
 
        return task_data;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]