GObject * gimp_curves_config_new_explicit (gint32 channel, const gdouble *samples, gint n_samples) { GimpCurvesConfig *config; GimpCurve *curve; 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); config = g_object_new (GIMP_TYPE_CURVES_CONFIG, NULL); curve = config->curve[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 < n_samples; i++) gimp_curve_set_curve (curve, (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 (gint32 channel, const gdouble *points, gint n_points) { GimpCurvesConfig *config; GimpCurve *curve; 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); config = g_object_new (GIMP_TYPE_CURVES_CONFIG, NULL); curve = config->curve[channel]; gimp_data_freeze (GIMP_DATA (curve)); gimp_curve_set_curve_type (curve, GIMP_CURVE_SMOOTH); gimp_curve_set_n_samples (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, (gdouble) points[i * 2], (gdouble) points[i * 2 + 1]); gimp_data_thaw (GIMP_DATA (curve)); return G_OBJECT (config); }
void gradient_editor_load_right_cmd_callback (GtkAction *action, gint value, gpointer data) { GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data); GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data); GimpGradient *gradient; GimpGradientSegment *seg; GimpRGB color; GimpGradientColor color_type = GIMP_GRADIENT_COLOR_FIXED; gradient = GIMP_GRADIENT (data_editor->data); switch (value) { case GRADIENT_EDITOR_COLOR_NEIGHBOR_ENDPOINT: if (editor->control_sel_r->next != NULL) seg = editor->control_sel_r->next; else seg = gimp_gradient_segment_get_first (editor->control_sel_r); color = seg->left_color; color_type = seg->left_color_type; break; case GRADIENT_EDITOR_COLOR_OTHER_ENDPOINT: color = editor->control_sel_l->left_color; color_type = editor->control_sel_l->left_color_type; break; case GRADIENT_EDITOR_COLOR_FOREGROUND: gimp_context_get_foreground (data_editor->context, &color); break; case GRADIENT_EDITOR_COLOR_BACKGROUND: gimp_context_get_background (data_editor->context, &color); break; default: /* Load a color */ color = editor->saved_colors[value - GRADIENT_EDITOR_COLOR_FIRST_CUSTOM]; break; } gimp_data_freeze (GIMP_DATA (gradient)); gimp_gradient_segment_range_blend (gradient, editor->control_sel_l, editor->control_sel_r, &editor->control_sel_l->left_color, &color, TRUE, TRUE); gimp_gradient_segment_set_right_color_type (gradient, editor->control_sel_l, color_type); gimp_data_thaw (GIMP_DATA (gradient)); }
static void gimp_curve_data_copy (GimpData *data, GimpData *src_data) { gimp_data_freeze (data); gimp_config_copy (GIMP_CONFIG (src_data), GIMP_CONFIG (data), 0); gimp_data_thaw (data); }
static void gimp_brush_editor_update_brush (GtkAdjustment *adjustment, GimpBrushEditor *editor) { GimpBrushGenerated *brush; gdouble radius; gint spikes; gdouble hardness; gdouble ratio; gdouble angle; gdouble spacing; if (! GIMP_IS_BRUSH_GENERATED (GIMP_DATA_EDITOR (editor)->data)) return; brush = GIMP_BRUSH_GENERATED (GIMP_DATA_EDITOR (editor)->data); radius = gtk_adjustment_get_value (editor->radius_data); spikes = ROUND (gtk_adjustment_get_value (editor->spikes_data)); hardness = gtk_adjustment_get_value (editor->hardness_data); ratio = gtk_adjustment_get_value (editor->aspect_ratio_data); angle = gtk_adjustment_get_value (editor->angle_data); spacing = gtk_adjustment_get_value (editor->spacing_data); if (radius != gimp_brush_generated_get_radius (brush) || spikes != gimp_brush_generated_get_spikes (brush) || hardness != gimp_brush_generated_get_hardness (brush) || ratio != gimp_brush_generated_get_aspect_ratio (brush) || angle != gimp_brush_generated_get_angle (brush) || spacing != gimp_brush_get_spacing (GIMP_BRUSH (brush))) { g_signal_handlers_block_by_func (brush, gimp_brush_editor_notify_brush, editor); gimp_data_freeze (GIMP_DATA (brush)); g_object_freeze_notify (G_OBJECT (brush)); gimp_brush_generated_set_radius (brush, radius); gimp_brush_generated_set_spikes (brush, spikes); gimp_brush_generated_set_hardness (brush, hardness); gimp_brush_generated_set_aspect_ratio (brush, ratio); gimp_brush_generated_set_angle (brush, angle); gimp_brush_set_spacing (GIMP_BRUSH (brush), spacing); g_object_thaw_notify (G_OBJECT (brush)); gimp_data_thaw (GIMP_DATA (brush)); g_signal_handlers_unblock_by_func (brush, gimp_brush_editor_notify_brush, editor); } }
void gimp_drawable_curves_spline (GimpDrawable *drawable, GimpProgress *progress, gint32 channel, const guint8 *points, gint n_points) { GimpCurvesConfig *config; GimpCurve *curve; gint i; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (! gimp_drawable_is_indexed (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_if_fail (channel >= GIMP_HISTOGRAM_VALUE && channel <= GIMP_HISTOGRAM_ALPHA); if (channel == GIMP_HISTOGRAM_ALPHA) g_return_if_fail (gimp_drawable_has_alpha (drawable)); if (gimp_drawable_is_gray (drawable)) g_return_if_fail (channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA); config = g_object_new (GIMP_TYPE_CURVES_CONFIG, NULL); curve = config->curve[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); n_points = MIN (n_points / 2, curve->n_points); 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); gimp_data_thaw (GIMP_DATA (curve)); gimp_drawable_curves (drawable, progress, config); g_object_unref (config); }
void gimp_drawable_curves_explicit (GimpDrawable *drawable, GimpProgress *progress, gint32 channel, const guint8 *points, gint n_points) { GimpCurvesConfig *config; GimpCurve *curve; gint i; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (! gimp_drawable_is_indexed (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_if_fail (channel >= GIMP_HISTOGRAM_VALUE && channel <= GIMP_HISTOGRAM_ALPHA); if (channel == GIMP_HISTOGRAM_ALPHA) g_return_if_fail (gimp_drawable_has_alpha (drawable)); if (gimp_drawable_is_gray (drawable)) g_return_if_fail (channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA); config = g_object_new (GIMP_TYPE_CURVES_CONFIG, NULL); curve = config->curve[channel]; gimp_data_freeze (GIMP_DATA (curve)); gimp_curve_set_curve_type (curve, GIMP_CURVE_FREE); for (i = 0; i < 256; i++) gimp_curve_set_curve (curve, (gdouble) i / 255.0, (gdouble) points[i] / 255.0); gimp_data_thaw (GIMP_DATA (curve)); gimp_drawable_curves (drawable, progress, config); g_object_unref (config); }
void gradient_editor_right_color_type_cmd_callback (GtkAction *action, GtkAction *current, gpointer data) { GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data); GimpGradient *gradient; gint value; gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data); value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)); if (gradient && value >= 0) { GimpGradientColor color_type = value; GimpRGB color; gimp_gradient_get_color_at (gradient, GIMP_DATA_EDITOR (editor)->context, editor->control_sel_r, editor->control_sel_r->right, FALSE, &color); gimp_data_freeze (GIMP_DATA (gradient)); gimp_gradient_segment_set_right_color_type (gradient, editor->control_sel_r, color_type); if (color_type == GIMP_GRADIENT_COLOR_FIXED) gimp_gradient_segment_set_right_color (gradient, editor->control_sel_r, &color); gimp_data_thaw (GIMP_DATA (gradient)); } }
gboolean gimp_curves_config_load_cruft (GimpCurvesConfig *config, gpointer fp, GError **error) { FILE *file = fp; gint i, j; gint fields; gchar buf[50]; gint index[5][GIMP_CURVE_N_CRUFT_POINTS]; gint value[5][GIMP_CURVE_N_CRUFT_POINTS]; g_return_val_if_fail (GIMP_IS_CURVES_CONFIG (config), FALSE); g_return_val_if_fail (file != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (! fgets (buf, sizeof (buf), file) || strcmp (buf, "# GIMP Curves File\n") != 0) { g_set_error_literal (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE, _("not a GIMP Curves file")); return FALSE; } for (i = 0; i < 5; i++) { for (j = 0; j < GIMP_CURVE_N_CRUFT_POINTS; j++) { fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]); if (fields != 2) { /* FIXME: should have a helpful error message here */ g_printerr ("fields != 2"); g_set_error_literal (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE, _("parse error")); return FALSE; } } } g_object_freeze_notify (G_OBJECT (config)); for (i = 0; i < 5; i++) { GimpCurve *curve = config->curve[i]; gimp_data_freeze (GIMP_DATA (curve)); gimp_curve_set_curve_type (curve, GIMP_CURVE_SMOOTH); gimp_curve_reset (curve, FALSE); for (j = 0; j < GIMP_CURVE_N_CRUFT_POINTS; j++) { if (index[i][j] < 0 || value[i][j] < 0) gimp_curve_set_point (curve, j, -1.0, -1.0); else gimp_curve_set_point (curve, j, (gdouble) index[i][j] / 255.0, (gdouble) value[i][j] / 255.0); } gimp_data_thaw (GIMP_DATA (curve)); } g_object_thaw_notify (G_OBJECT (config)); return TRUE; }
gboolean gimp_curves_config_load_cruft (GimpCurvesConfig *config, GInputStream *input, GError **error) { GDataInputStream *data_input; gint index[5][GIMP_CURVE_N_CRUFT_POINTS]; gint value[5][GIMP_CURVE_N_CRUFT_POINTS]; gchar *line; gsize line_len; gint i, j; g_return_val_if_fail (GIMP_IS_CURVES_CONFIG (config), FALSE); g_return_val_if_fail (G_IS_INPUT_STREAM (input), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); data_input = g_data_input_stream_new (input); line_len = 64; line = g_data_input_stream_read_line (data_input, &line_len, NULL, error); if (! line) return FALSE; if (strcmp (line, "# GIMP Curves File") != 0) { g_set_error_literal (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE, _("not a GIMP Curves file")); g_object_unref (data_input); g_free (line); return FALSE; } for (i = 0; i < 5; i++) { for (j = 0; j < GIMP_CURVE_N_CRUFT_POINTS; j++) { gchar *x_str = NULL; gchar *y_str = NULL; if (! (x_str = g_data_input_stream_read_upto (data_input, " ", -1, NULL, NULL, error)) || ! g_data_input_stream_read_byte (data_input, NULL, error) || ! (y_str = g_data_input_stream_read_upto (data_input, " ", -1, NULL, NULL, error)) || ! g_data_input_stream_read_byte (data_input, NULL, error)) { g_free (x_str); g_free (y_str); g_object_unref (data_input); return FALSE; } if (sscanf (x_str, "%d", &index[i][j]) != 1 || sscanf (y_str, "%d", &value[i][j]) != 1) { g_set_error_literal (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE, _("Parse error, didn't find 2 integers")); g_free (x_str); g_free (y_str); g_object_unref (data_input); return FALSE; } g_free (x_str); g_free (y_str); } } g_object_unref (data_input); g_object_freeze_notify (G_OBJECT (config)); for (i = 0; i < 5; i++) { GimpCurve *curve = config->curve[i]; 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); for (j = 0; j < GIMP_CURVE_N_CRUFT_POINTS; j++) { if (index[i][j] < 0 || value[i][j] < 0) gimp_curve_set_point (curve, j, -1.0, -1.0); else gimp_curve_set_point (curve, j, (gdouble) index[i][j] / 255.0, (gdouble) value[i][j] / 255.0); } gimp_data_thaw (GIMP_DATA (curve)); } g_object_thaw_notify (G_OBJECT (config)); return TRUE; }