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.
This commit is contained in:
Michael Natterer
2014-06-17 21:10:33 +02:00
parent a5fe6c244f
commit f5e4f01c52
6 changed files with 57 additions and 51 deletions

View File

@ -361,9 +361,9 @@ gimp_curves_config_curve_dirty (GimpCurve *curve,
/* public functions */ /* public functions */
GObject * GObject *
gimp_curves_config_new_spline (gint32 channel, gimp_curves_config_new_spline_cruft (gint32 channel,
const guint8 *points, const guint8 *points,
gint n_points) gint n_points)
{ {
GimpCurvesConfig *config; GimpCurvesConfig *config;
GimpCurve *curve; GimpCurve *curve;
@ -371,6 +371,8 @@ gimp_curves_config_new_spline (gint32 channel,
g_return_val_if_fail (channel >= GIMP_HISTOGRAM_VALUE && g_return_val_if_fail (channel >= GIMP_HISTOGRAM_VALUE &&
channel <= GIMP_HISTOGRAM_ALPHA, NULL); 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); 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)); gimp_data_freeze (GIMP_DATA (curve));
/* FIXME: create a curves object with the right number of points */ gimp_curve_set_curve_type (curve, GIMP_CURVE_SMOOTH);
/* unset the last point */ gimp_curve_set_n_samples (curve, n_points);
gimp_curve_set_point (curve, curve->n_points - 1, -1, -1);
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++) for (i = 0; i < n_points; i++)
gimp_curve_set_point (curve, i, gimp_curve_set_point (curve, i,
@ -395,9 +397,9 @@ gimp_curves_config_new_spline (gint32 channel,
} }
GObject * GObject *
gimp_curves_config_new_explicit (gint32 channel, gimp_curves_config_new_explicit_cruft (gint32 channel,
const guint8 *points, const guint8 *samples,
gint n_points) gint n_samples)
{ {
GimpCurvesConfig *config; GimpCurvesConfig *config;
GimpCurve *curve; GimpCurve *curve;
@ -405,6 +407,8 @@ gimp_curves_config_new_explicit (gint32 channel,
g_return_val_if_fail (channel >= GIMP_HISTOGRAM_VALUE && g_return_val_if_fail (channel >= GIMP_HISTOGRAM_VALUE &&
channel <= GIMP_HISTOGRAM_ALPHA, NULL); 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); 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_data_freeze (GIMP_DATA (curve));
gimp_curve_set_curve_type (curve, GIMP_CURVE_FREE); 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, gimp_curve_set_curve (curve,
(gdouble) i / 255.0, (gdouble) i / 255.0,
(gdouble) points[i] / 255.0); (gdouble) samples[i] / 255.0);
gimp_data_thaw (GIMP_DATA (curve)); gimp_data_thaw (GIMP_DATA (curve));
@ -485,6 +490,7 @@ gimp_curves_config_load_cruft (GimpCurvesConfig *config,
gimp_data_freeze (GIMP_DATA (curve)); gimp_data_freeze (GIMP_DATA (curve));
gimp_curve_set_curve_type (curve, GIMP_CURVE_SMOOTH); 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); gimp_curve_reset (curve, FALSE);

View File

@ -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, GObject * gimp_curves_config_new_spline_cruft (gint32 channel,
const guint8 *points, const guint8 *points,
gint n_points); gint n_points);
GObject * gimp_curves_config_new_explicit (gint32 channel, GObject * gimp_curves_config_new_explicit_cruft (gint32 channel,
const guint8 *points, const guint8 *points,
gint n_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, gboolean gimp_curves_config_load_cruft (GimpCurvesConfig *config,
gpointer fp, gpointer fp,
GError **error); GError **error);
gboolean gimp_curves_config_save_cruft (GimpCurvesConfig *config, gboolean gimp_curves_config_save_cruft (GimpCurvesConfig *config,
gpointer fp, gpointer fp,
GError **error); GError **error);
#endif /* __GIMP_CURVES_CONFIG_H__ */ #endif /* __GIMP_CURVES_CONFIG_H__ */

View File

@ -425,9 +425,9 @@ curves_spline_invoker (GimpProcedure *procedure,
(! gimp_drawable_is_gray (drawable) || (! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{ {
GObject *config = gimp_curves_config_new_spline (channel, GObject *config = gimp_curves_config_new_spline_cruft (channel,
control_pts, control_pts,
num_points); num_points / 2);
gimp_drawable_apply_operation_by_name (drawable, progress, gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Curves"), C_("undo-type", "Curves"),
@ -472,9 +472,9 @@ curves_explicit_invoker (GimpProcedure *procedure,
(! gimp_drawable_is_gray (drawable) || (! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{ {
GObject *config = gimp_curves_config_new_explicit (channel, GObject *config = gimp_curves_config_new_explicit_cruft (channel,
curve, curve,
num_bytes); num_bytes);
gimp_drawable_apply_operation_by_name (drawable, progress, gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Curves"), C_("undo-type", "Curves"),

View File

@ -228,9 +228,9 @@ drawable_curves_explicit_invoker (GimpProcedure *procedure,
(! gimp_drawable_is_gray (drawable) || (! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{ {
GObject *config = gimp_curves_config_new_explicit (channel, GObject *config = gimp_curves_config_new_explicit_cruft (channel,
curve, curve,
num_bytes); num_bytes);
gimp_drawable_apply_operation_by_name (drawable, progress, gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Curves"), C_("undo-type", "Curves"),
@ -275,9 +275,9 @@ drawable_curves_spline_invoker (GimpProcedure *procedure,
(! gimp_drawable_is_gray (drawable) || (! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{ {
GObject *config = gimp_curves_config_new_spline (channel, GObject *config = gimp_curves_config_new_spline_cruft (channel,
control_pts, control_pts,
num_points); num_points / 2);
gimp_drawable_apply_operation_by_name (drawable, progress, gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Curves"), C_("undo-type", "Curves"),

View File

@ -366,9 +366,9 @@ HELP
(! gimp_drawable_is_gray (drawable) || (! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{ {
GObject *config = gimp_curves_config_new_spline (channel, GObject *config = gimp_curves_config_new_spline_cruft (channel,
control_pts, control_pts,
num_points); num_points / 2);
gimp_drawable_apply_operation_by_name (drawable, progress, gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Curves"), C_("undo-type", "Curves"),
@ -421,9 +421,9 @@ HELP
(! gimp_drawable_is_gray (drawable) || (! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{ {
GObject *config = gimp_curves_config_new_explicit (channel, GObject *config = gimp_curves_config_new_explicit_cruft (channel,
curve, curve,
num_bytes); num_bytes);
gimp_drawable_apply_operation_by_name (drawable, progress, gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Curves"), C_("undo-type", "Curves"),

View File

@ -216,9 +216,9 @@ HELP
(! gimp_drawable_is_gray (drawable) || (! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{ {
GObject *config = gimp_curves_config_new_explicit (channel, GObject *config = gimp_curves_config_new_explicit_cruft (channel,
curve, curve,
num_bytes); num_bytes);
gimp_drawable_apply_operation_by_name (drawable, progress, gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Curves"), C_("undo-type", "Curves"),
@ -273,9 +273,9 @@ HELP
(! gimp_drawable_is_gray (drawable) || (! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)) channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{ {
GObject *config = gimp_curves_config_new_spline (channel, GObject *config = gimp_curves_config_new_spline_cruft (channel,
control_pts, control_pts,
num_points); num_points / 2);
gimp_drawable_apply_operation_by_name (drawable, progress, gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Curves"), C_("undo-type", "Curves"),