static void gimp_histogram_editor_frozen_update (GimpHistogramEditor *editor, const GParamSpec *pspec) { GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view; if (gimp_viewable_preview_is_frozen (GIMP_VIEWABLE (editor->drawable))) { /* Only do the background histogram if the histogram is visible. * This is a workaround for the fact that recalculating the * histogram is expensive and that it is only validated when it * is shown. So don't slow down painting by doing something that * is not even seen by the user. */ if (! editor->bg_histogram && GTK_WIDGET_DRAWABLE (editor)) { if (gimp_histogram_editor_validate (editor)) editor->bg_histogram = gimp_histogram_duplicate (editor->histogram); gimp_histogram_view_set_background (view, editor->bg_histogram); } } else if (editor->bg_histogram) { gimp_histogram_unref (editor->bg_histogram); editor->bg_histogram = NULL; gimp_histogram_view_set_background (view, NULL); } }
static void gimp_histogram_editor_set_image (GimpImageEditor *image_editor, GimpImage *image) { GimpHistogramEditor *editor = GIMP_HISTOGRAM_EDITOR (image_editor); GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view; if (image_editor->image) { if (editor->idle_id) { g_source_remove (editor->idle_id); editor->idle_id = 0; } g_signal_handlers_disconnect_by_func (image_editor->image, gimp_histogram_editor_layer_changed, editor); g_signal_handlers_disconnect_by_func (image_editor->image, gimp_histogram_editor_menu_update, editor); if (editor->histogram) { gimp_histogram_unref (editor->histogram); editor->histogram = NULL; gimp_histogram_view_set_histogram (view, NULL); } if (editor->bg_histogram) { gimp_histogram_unref (editor->bg_histogram); editor->bg_histogram = NULL; gimp_histogram_view_set_background (view, NULL); } } GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, image); if (image) { editor->histogram = gimp_histogram_new (); gimp_histogram_view_set_histogram (view, editor->histogram); g_signal_connect_object (image, "mode-changed", G_CALLBACK (gimp_histogram_editor_menu_update), editor, G_CONNECT_SWAPPED); g_signal_connect_object (image, "active-layer-changed", G_CALLBACK (gimp_histogram_editor_layer_changed), editor, 0); g_signal_connect_object (image, "mask-changed", G_CALLBACK (gimp_histogram_editor_update), editor, G_CONNECT_SWAPPED); } gimp_histogram_editor_layer_changed (image, editor); }
static gboolean gimp_curves_tool_initialize (GimpTool *tool, GimpDisplay *display, GError **error) { GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpHistogram *histogram; if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) { return FALSE; } /* always pick colors */ gimp_color_tool_enable (GIMP_COLOR_TOOL (tool), GIMP_COLOR_TOOL_GET_OPTIONS (tool)); gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (c_tool->channel_menu), curves_menu_sensitivity, drawable, NULL); histogram = gimp_histogram_new (TRUE); gimp_drawable_calculate_histogram (drawable, histogram); gimp_histogram_view_set_background (GIMP_HISTOGRAM_VIEW (c_tool->graph), histogram); g_object_unref (histogram); if (gimp_drawable_get_precision (drawable) == GIMP_PRECISION_U8) { gimp_curve_view_set_range_x (GIMP_CURVE_VIEW (c_tool->graph), 0, 255); gimp_curve_view_set_range_y (GIMP_CURVE_VIEW (c_tool->graph), 0, 255); } else { gimp_curve_view_set_range_x (GIMP_CURVE_VIEW (c_tool->graph), 0.0, 1.0); gimp_curve_view_set_range_y (GIMP_CURVE_VIEW (c_tool->graph), 0.0, 1.0); } return TRUE; }
static gboolean gimp_curves_tool_initialize (GimpTool *tool, GimpDisplay *display, GError **error) { GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool); GimpDrawable *drawable = gimp_image_get_active_drawable (display->image); GimpHistogram *histogram; if (! drawable) return FALSE; if (gimp_drawable_is_indexed (drawable)) { g_set_error (error, 0, 0, _("Curves does not operate on indexed layers.")); return FALSE; } gimp_config_reset (GIMP_CONFIG (c_tool->config)); GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); /* always pick colors */ gimp_color_tool_enable (GIMP_COLOR_TOOL (tool), GIMP_COLOR_TOOL_GET_OPTIONS (tool)); gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (c_tool->channel_menu), curves_menu_sensitivity, drawable, NULL); histogram = gimp_histogram_new (); gimp_drawable_calculate_histogram (drawable, histogram); gimp_histogram_view_set_background (GIMP_HISTOGRAM_VIEW (c_tool->graph), histogram); gimp_histogram_unref (histogram); return TRUE; }
static void gimp_histogram_editor_layer_changed (GimpImage *image, GimpHistogramEditor *editor) { if (editor->drawable) { if (editor->bg_histogram) { GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view; gimp_histogram_unref (editor->bg_histogram); editor->bg_histogram = NULL; gimp_histogram_view_set_background (view, NULL); } g_signal_handlers_disconnect_by_func (editor->drawable, gimp_histogram_editor_name_update, editor); g_signal_handlers_disconnect_by_func (editor->drawable, gimp_histogram_editor_menu_update, editor); g_signal_handlers_disconnect_by_func (editor->drawable, gimp_histogram_editor_update, editor); g_signal_handlers_disconnect_by_func (editor->drawable, gimp_histogram_editor_frozen_update, editor); editor->drawable = NULL; } if (image) editor->drawable = (GimpDrawable *) gimp_image_get_active_layer (image); gimp_histogram_editor_menu_update (editor); if (editor->drawable) { g_signal_connect_object (editor->drawable, "notify::frozen", G_CALLBACK (gimp_histogram_editor_frozen_update), editor, G_CONNECT_SWAPPED); g_signal_connect_object (editor->drawable, "update", G_CALLBACK (gimp_histogram_editor_update), editor, G_CONNECT_SWAPPED); g_signal_connect_object (editor->drawable, "alpha-changed", G_CALLBACK (gimp_histogram_editor_menu_update), editor, G_CONNECT_SWAPPED); g_signal_connect_object (editor->drawable, "name-changed", G_CALLBACK (gimp_histogram_editor_name_update), editor, G_CONNECT_SWAPPED); gimp_histogram_editor_update (editor); } else if (editor->histogram) { editor->valid = FALSE; gtk_widget_queue_draw (GTK_WIDGET (editor->box)); } gimp_histogram_editor_info_update (editor); gimp_histogram_editor_name_update (editor); }