static gboolean gimp_threshold_tool_initialize (GimpTool *tool, GimpDisplay *display, GError **error) { GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (tool); GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (tool); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); gdouble low; gdouble high; gint n_bins; if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) { return FALSE; } g_clear_object (&t_tool->histogram_async); g_object_get (filter_tool->config, "low", &low, "high", &high, NULL); /* this is a hack to make sure that * 'gimp_histogram_n_bins (t_tool->histogram)' returns the correct value for * 'drawable' before the asynchronous calculation of its histogram is * finished. */ { GeglBuffer *temp; temp = gegl_buffer_new (GEGL_RECTANGLE (0, 0, 1, 1), gimp_drawable_get_format (drawable)); gimp_histogram_calculate (t_tool->histogram, temp, GEGL_RECTANGLE (0, 0, 1, 1), NULL, NULL); g_object_unref (temp); } n_bins = gimp_histogram_n_bins (t_tool->histogram); t_tool->histogram_async = gimp_drawable_calculate_histogram_async ( drawable, t_tool->histogram, FALSE); gimp_histogram_view_set_histogram (t_tool->histogram_box->view, t_tool->histogram); gimp_histogram_view_set_range (t_tool->histogram_box->view, low * (n_bins - 0.0001), high * (n_bins - 0.0001)); return TRUE; }
static gboolean gimp_histogram_editor_validate (GimpHistogramEditor *editor) { if (! editor->valid && editor->histogram) { if (editor->drawable) gimp_drawable_calculate_histogram (editor->drawable, editor->histogram); else gimp_histogram_calculate (editor->histogram, NULL, NULL); gimp_histogram_editor_info_update (editor); editor->valid = TRUE; } return editor->valid; }