[gimp] app: add back gimp_curves_config_new_spline,explicit()



commit 847606d1775a26f37ff7f1bdad27b8c826bea0fb
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jun 17 22:23:41 2014 +0200

    app: add back gimp_curves_config_new_spline,explicit()
    
    but as versions using gdouble instead of guint8. Use the new functions
    from the just renamed _cruft() variants.

 app/operations/gimpcurvesconfig.c |   77 ++++++++++++++++++++++++++++++++-----
 app/operations/gimpcurvesconfig.h |   11 ++++-
 2 files changed, 76 insertions(+), 12 deletions(-)
---
diff --git a/app/operations/gimpcurvesconfig.c b/app/operations/gimpcurvesconfig.c
index a6a8f72..ee90364 100644
--- a/app/operations/gimpcurvesconfig.c
+++ b/app/operations/gimpcurvesconfig.c
@@ -361,9 +361,9 @@ gimp_curves_config_curve_dirty (GimpCurve        *curve,
 /*  public functions  */
 
 GObject *
-gimp_curves_config_new_spline_cruft (gint32        channel,
-                                     const guint8 *points,
-                                     gint          n_points)
+gimp_curves_config_new_spline (gint32         channel,
+                               const gdouble *points,
+                               gint           n_points)
 {
   GimpCurvesConfig *config;
   GimpCurve        *curve;
@@ -388,8 +388,8 @@ gimp_curves_config_new_spline_cruft (gint32        channel,
 
   for (i = 0; i < n_points; i++)
     gimp_curve_set_point (curve, i,
-                          (gdouble) points[i * 2]     / 255.0,
-                          (gdouble) points[i * 2 + 1] / 255.0);
+                          (gdouble) points[i * 2],
+                          (gdouble) points[i * 2 + 1]);
 
   gimp_data_thaw (GIMP_DATA (curve));
 
@@ -397,9 +397,9 @@ gimp_curves_config_new_spline_cruft (gint32        channel,
 }
 
 GObject *
-gimp_curves_config_new_explicit_cruft (gint32        channel,
-                                       const guint8 *samples,
-                                       gint          n_samples)
+gimp_curves_config_new_explicit (gint32         channel,
+                                 const gdouble *samples,
+                                 gint           n_samples)
 {
   GimpCurvesConfig *config;
   GimpCurve        *curve;
@@ -421,14 +421,71 @@ gimp_curves_config_new_explicit_cruft (gint32        channel,
 
   for (i = 0; i < n_samples; i++)
     gimp_curve_set_curve (curve,
-                          (gdouble) i          / 255.0,
-                          (gdouble) samples[i] / 255.0);
+                          (gdouble) i / (gdouble) (n_samples - 1),
+                          (gdouble) samples[i]);
 
   gimp_data_thaw (GIMP_DATA (curve));
 
   return G_OBJECT (config);
 }
 
+GObject *
+gimp_curves_config_new_spline_cruft (gint32        channel,
+                                     const guint8 *points,
+                                     gint          n_points)
+{
+  GObject *config;
+  gdouble *d_points;
+  gint     i;
+
+  g_return_val_if_fail (channel >= GIMP_HISTOGRAM_VALUE &&
+                        channel <= GIMP_HISTOGRAM_ALPHA, NULL);
+  g_return_val_if_fail (points != NULL, NULL);
+  g_return_val_if_fail (n_points >= 2 && n_points <= 1024, NULL);
+
+  d_points = g_new (gdouble, 2 * n_points);
+
+  for (i = 0; i < n_points; i++)
+    {
+      d_points[i * 2]     = (gdouble) points[i * 2]     / 255.0;
+      d_points[i * 2 + 1] = (gdouble) points[i * 2 + 1] / 255.0;
+    }
+
+  config = gimp_curves_config_new_spline (channel, d_points, n_points);
+
+  g_free (d_points);
+
+  return config;
+}
+
+GObject *
+gimp_curves_config_new_explicit_cruft (gint32        channel,
+                                       const guint8 *samples,
+                                       gint          n_samples)
+{
+  GObject *config;
+  gdouble *d_samples;
+  gint     i;
+
+  g_return_val_if_fail (channel >= GIMP_HISTOGRAM_VALUE &&
+                        channel <= GIMP_HISTOGRAM_ALPHA, NULL);
+  g_return_val_if_fail (samples != NULL, NULL);
+  g_return_val_if_fail (n_samples >= 2 && n_samples <= 4096, NULL);
+
+  d_samples = g_new (gdouble, n_samples);
+
+  for (i = 0; i < n_samples; i++)
+    {
+      d_samples[i] = (gdouble) samples[i] / 255.0;
+    }
+
+  config = gimp_curves_config_new_explicit (channel, d_samples, n_samples);
+
+  g_free (d_samples);
+
+  return config;
+}
+
 void
 gimp_curves_config_reset_channel (GimpCurvesConfig *config)
 {
diff --git a/app/operations/gimpcurvesconfig.h b/app/operations/gimpcurvesconfig.h
index 4fc7f7f..4859dad 100644
--- a/app/operations/gimpcurvesconfig.h
+++ b/app/operations/gimpcurvesconfig.h
@@ -52,12 +52,19 @@ struct _GimpCurvesConfigClass
 
 GType      gimp_curves_config_get_type            (void) G_GNUC_CONST;
 
+GObject  * gimp_curves_config_new_spline          (gint32             channel,
+                                                   const gdouble     *points,
+                                                   gint               n_points);
+GObject *  gimp_curves_config_new_explicit        (gint32             channel,
+                                                   const gdouble     *samples,
+                                                   gint               n_samples);
+
 GObject  * gimp_curves_config_new_spline_cruft    (gint32             channel,
                                                    const guint8      *points,
                                                    gint               n_points);
 GObject *  gimp_curves_config_new_explicit_cruft  (gint32             channel,
-                                                   const guint8      *points,
-                                                   gint               n_points);
+                                                   const guint8      *samples,
+                                                   gint               n_samples);
 
 void       gimp_curves_config_reset_channel       (GimpCurvesConfig  *config);
 


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