From f5e4f01c52eec511bad4f48f562ba8eb868154ab Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 17 Jun 2014 21:10:33 +0200 Subject: [PATCH] app: make gimp_curves_config_new_spline,explicit() handle variable #points Also, append _cruft to the function name because they take guint8* arrays, will add proper ones next. --- app/operations/gimpcurvesconfig.c | 32 +++++++++++++++++------------ app/operations/gimpcurvesconfig.h | 28 ++++++++++++------------- app/pdb/color-cmds.c | 12 +++++------ app/pdb/drawable-color-cmds.c | 12 +++++------ tools/pdbgen/pdb/color.pdb | 12 +++++------ tools/pdbgen/pdb/drawable_color.pdb | 12 +++++------ 6 files changed, 57 insertions(+), 51 deletions(-) diff --git a/app/operations/gimpcurvesconfig.c b/app/operations/gimpcurvesconfig.c index c1a68478e7..a6a8f72f2f 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 (gint32 channel, - const guint8 *points, - gint n_points) +gimp_curves_config_new_spline_cruft (gint32 channel, + const guint8 *points, + gint n_points) { GimpCurvesConfig *config; GimpCurve *curve; @@ -371,6 +371,8 @@ gimp_curves_config_new_spline (gint32 channel, 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); config = g_object_new (GIMP_TYPE_CURVES_CONFIG, NULL); @@ -378,11 +380,11 @@ gimp_curves_config_new_spline (gint32 channel, gimp_data_freeze (GIMP_DATA (curve)); - /* FIXME: create a curves object with the right number of points */ - /* unset the last point */ - gimp_curve_set_point (curve, curve->n_points - 1, -1, -1); + gimp_curve_set_curve_type (curve, GIMP_CURVE_SMOOTH); + gimp_curve_set_n_samples (curve, n_points); - n_points = MIN (n_points / 2, curve->n_points); + /* unset the last point */ + gimp_curve_set_point (curve, curve->n_points - 1, -1.0, -1.0); for (i = 0; i < n_points; i++) gimp_curve_set_point (curve, i, @@ -395,9 +397,9 @@ gimp_curves_config_new_spline (gint32 channel, } GObject * -gimp_curves_config_new_explicit (gint32 channel, - const guint8 *points, - gint n_points) +gimp_curves_config_new_explicit_cruft (gint32 channel, + const guint8 *samples, + gint n_samples) { GimpCurvesConfig *config; GimpCurve *curve; @@ -405,6 +407,8 @@ gimp_curves_config_new_explicit (gint32 channel, 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); config = g_object_new (GIMP_TYPE_CURVES_CONFIG, NULL); @@ -413,11 +417,12 @@ gimp_curves_config_new_explicit (gint32 channel, gimp_data_freeze (GIMP_DATA (curve)); gimp_curve_set_curve_type (curve, GIMP_CURVE_FREE); + gimp_curve_set_n_samples (curve, n_samples); - for (i = 0; i < 256; i++) + for (i = 0; i < n_samples; i++) gimp_curve_set_curve (curve, - (gdouble) i / 255.0, - (gdouble) points[i] / 255.0); + (gdouble) i / 255.0, + (gdouble) samples[i] / 255.0); gimp_data_thaw (GIMP_DATA (curve)); @@ -485,6 +490,7 @@ gimp_curves_config_load_cruft (GimpCurvesConfig *config, gimp_data_freeze (GIMP_DATA (curve)); gimp_curve_set_curve_type (curve, GIMP_CURVE_SMOOTH); + gimp_curve_set_n_points (curve, GIMP_CURVE_N_CRUFT_POINTS); gimp_curve_reset (curve, FALSE); diff --git a/app/operations/gimpcurvesconfig.h b/app/operations/gimpcurvesconfig.h index 1bcf96dfbc..4fc7f7f9c9 100644 --- a/app/operations/gimpcurvesconfig.h +++ b/app/operations/gimpcurvesconfig.h @@ -50,23 +50,23 @@ struct _GimpCurvesConfigClass }; -GType gimp_curves_config_get_type (void) G_GNUC_CONST; +GType gimp_curves_config_get_type (void) G_GNUC_CONST; -GObject * gimp_curves_config_new_spline (gint32 channel, - const guint8 *points, - gint n_points); -GObject * gimp_curves_config_new_explicit (gint32 channel, - const guint8 *points, - gint n_points); +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); -void gimp_curves_config_reset_channel (GimpCurvesConfig *config); +void gimp_curves_config_reset_channel (GimpCurvesConfig *config); -gboolean gimp_curves_config_load_cruft (GimpCurvesConfig *config, - gpointer fp, - GError **error); -gboolean gimp_curves_config_save_cruft (GimpCurvesConfig *config, - gpointer fp, - GError **error); +gboolean gimp_curves_config_load_cruft (GimpCurvesConfig *config, + gpointer fp, + GError **error); +gboolean gimp_curves_config_save_cruft (GimpCurvesConfig *config, + gpointer fp, + GError **error); #endif /* __GIMP_CURVES_CONFIG_H__ */ diff --git a/app/pdb/color-cmds.c b/app/pdb/color-cmds.c index a91d3c3412..03fbb2c315 100644 --- a/app/pdb/color-cmds.c +++ b/app/pdb/color-cmds.c @@ -425,9 +425,9 @@ curves_spline_invoker (GimpProcedure *procedure, (! gimp_drawable_is_gray (drawable) || channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) { - GObject *config = gimp_curves_config_new_spline (channel, - control_pts, - num_points); + GObject *config = gimp_curves_config_new_spline_cruft (channel, + control_pts, + num_points / 2); gimp_drawable_apply_operation_by_name (drawable, progress, C_("undo-type", "Curves"), @@ -472,9 +472,9 @@ curves_explicit_invoker (GimpProcedure *procedure, (! gimp_drawable_is_gray (drawable) || channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) { - GObject *config = gimp_curves_config_new_explicit (channel, - curve, - num_bytes); + GObject *config = gimp_curves_config_new_explicit_cruft (channel, + curve, + num_bytes); gimp_drawable_apply_operation_by_name (drawable, progress, C_("undo-type", "Curves"), diff --git a/app/pdb/drawable-color-cmds.c b/app/pdb/drawable-color-cmds.c index 09d13adfb7..cc799296aa 100644 --- a/app/pdb/drawable-color-cmds.c +++ b/app/pdb/drawable-color-cmds.c @@ -228,9 +228,9 @@ drawable_curves_explicit_invoker (GimpProcedure *procedure, (! gimp_drawable_is_gray (drawable) || channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) { - GObject *config = gimp_curves_config_new_explicit (channel, - curve, - num_bytes); + GObject *config = gimp_curves_config_new_explicit_cruft (channel, + curve, + num_bytes); gimp_drawable_apply_operation_by_name (drawable, progress, C_("undo-type", "Curves"), @@ -275,9 +275,9 @@ drawable_curves_spline_invoker (GimpProcedure *procedure, (! gimp_drawable_is_gray (drawable) || channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) { - GObject *config = gimp_curves_config_new_spline (channel, - control_pts, - num_points); + GObject *config = gimp_curves_config_new_spline_cruft (channel, + control_pts, + num_points / 2); gimp_drawable_apply_operation_by_name (drawable, progress, C_("undo-type", "Curves"), diff --git a/tools/pdbgen/pdb/color.pdb b/tools/pdbgen/pdb/color.pdb index 2840ca0d9a..e5142ca244 100644 --- a/tools/pdbgen/pdb/color.pdb +++ b/tools/pdbgen/pdb/color.pdb @@ -366,9 +366,9 @@ HELP (! gimp_drawable_is_gray (drawable) || channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) { - GObject *config = gimp_curves_config_new_spline (channel, - control_pts, - num_points); + GObject *config = gimp_curves_config_new_spline_cruft (channel, + control_pts, + num_points / 2); gimp_drawable_apply_operation_by_name (drawable, progress, C_("undo-type", "Curves"), @@ -421,9 +421,9 @@ HELP (! gimp_drawable_is_gray (drawable) || channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) { - GObject *config = gimp_curves_config_new_explicit (channel, - curve, - num_bytes); + GObject *config = gimp_curves_config_new_explicit_cruft (channel, + curve, + num_bytes); gimp_drawable_apply_operation_by_name (drawable, progress, C_("undo-type", "Curves"), diff --git a/tools/pdbgen/pdb/drawable_color.pdb b/tools/pdbgen/pdb/drawable_color.pdb index 029c642c74..3544d8cdc7 100644 --- a/tools/pdbgen/pdb/drawable_color.pdb +++ b/tools/pdbgen/pdb/drawable_color.pdb @@ -216,9 +216,9 @@ HELP (! gimp_drawable_is_gray (drawable) || channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) { - GObject *config = gimp_curves_config_new_explicit (channel, - curve, - num_bytes); + GObject *config = gimp_curves_config_new_explicit_cruft (channel, + curve, + num_bytes); gimp_drawable_apply_operation_by_name (drawable, progress, C_("undo-type", "Curves"), @@ -273,9 +273,9 @@ HELP (! gimp_drawable_is_gray (drawable) || channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) { - GObject *config = gimp_curves_config_new_spline (channel, - control_pts, - num_points); + GObject *config = gimp_curves_config_new_spline_cruft (channel, + control_pts, + num_points / 2); gimp_drawable_apply_operation_by_name (drawable, progress, C_("undo-type", "Curves"),