Bug 785535 - Histogram not updating in real when filters are active

Add "gboolean with_filters" to gimp_drawable_calculate_histogram(),
which is passed as FALSE in almost all places, except the histogram
dockable where we want to see both the drawable's unmodified histogram
*and* the histogram after filters are applied.
This commit is contained in:
Michael Natterer 2017-08-05 17:15:31 +02:00
parent 572063765f
commit c41e8eca86
12 changed files with 77 additions and 32 deletions

View File

@ -39,7 +39,7 @@ gimp_drawable_equalize (GimpDrawable *drawable,
{ {
GimpImage *image; GimpImage *image;
GimpChannel *selection; GimpChannel *selection;
GimpHistogram *hist; GimpHistogram *histogram;
GeglNode *equalize; GeglNode *equalize;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
@ -48,12 +48,12 @@ gimp_drawable_equalize (GimpDrawable *drawable,
image = gimp_item_get_image (GIMP_ITEM (drawable)); image = gimp_item_get_image (GIMP_ITEM (drawable));
selection = gimp_image_get_mask (image); selection = gimp_image_get_mask (image);
hist = gimp_histogram_new (FALSE); histogram = gimp_histogram_new (FALSE);
gimp_drawable_calculate_histogram (drawable, hist); gimp_drawable_calculate_histogram (drawable, histogram, FALSE);
equalize = gegl_node_new_child (NULL, equalize = gegl_node_new_child (NULL,
"operation", "gimp:equalize", "operation", "gimp:equalize",
"histogram", hist, "histogram", histogram,
NULL); NULL);
if (! mask_only) if (! mask_only)
@ -67,5 +67,5 @@ gimp_drawable_equalize (GimpDrawable *drawable,
gimp_selection_resume (GIMP_SELECTION (selection)); gimp_selection_resume (GIMP_SELECTION (selection));
g_object_unref (equalize); g_object_unref (equalize);
g_object_unref (hist); g_object_unref (histogram);
} }

View File

@ -19,14 +19,17 @@
#include "config.h" #include "config.h"
#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h> #include <gegl.h>
#include "core-types.h" #include "core-types.h"
#include "gegl/gimp-gegl-nodes.h" #include "gegl/gimp-gegl-nodes.h"
#include "gegl/gimptilehandlervalidate.h"
#include "gimpchannel.h" #include "gimpchannel.h"
#include "gimpdrawable-filters.h"
#include "gimpdrawable-histogram.h" #include "gimpdrawable-histogram.h"
#include "gimphistogram.h" #include "gimphistogram.h"
#include "gimpimage.h" #include "gimpimage.h"
@ -34,7 +37,8 @@
void void
gimp_drawable_calculate_histogram (GimpDrawable *drawable, gimp_drawable_calculate_histogram (GimpDrawable *drawable,
GimpHistogram *histogram) GimpHistogram *histogram,
gboolean with_filters)
{ {
GimpImage *image; GimpImage *image;
GimpChannel *mask; GimpChannel *mask;
@ -53,14 +57,21 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable,
if (FALSE) if (FALSE)
{ {
GeglNode *node = gegl_node_new (); GeglNode *node = gegl_node_new ();
GeglNode *buffer_source; GeglNode *source;
GeglNode *histogram_sink; GeglNode *histogram_sink;
GeglProcessor *processor; GeglProcessor *processor;
buffer_source = if (with_filters)
gimp_gegl_add_buffer_source (node, {
gimp_drawable_get_buffer (drawable), source = gimp_drawable_get_source_node (drawable);
0, 0); }
else
{
source =
gimp_gegl_add_buffer_source (node,
gimp_drawable_get_buffer (drawable),
0, 0);
}
histogram_sink = histogram_sink =
gegl_node_new_child (node, gegl_node_new_child (node,
@ -68,7 +79,7 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable,
"histogram", histogram, "histogram", histogram,
NULL); NULL);
gegl_node_connect_to (buffer_source, "output", gegl_node_connect_to (source, "output",
histogram_sink, "input"); histogram_sink, "input");
if (! gimp_channel_is_empty (mask)) if (! gimp_channel_is_empty (mask))
@ -99,14 +110,50 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable,
} }
else else
{ {
GeglBuffer *buffer = gimp_drawable_get_buffer (drawable);
if (with_filters && gimp_drawable_has_filters (drawable))
{
GimpTileHandlerValidate *validate;
GeglNode *node;
node = gimp_drawable_get_source_node (drawable);
buffer = gegl_buffer_new (gegl_buffer_get_extent (buffer),
gegl_buffer_get_format (buffer));
validate =
GIMP_TILE_HANDLER_VALIDATE (gimp_tile_handler_validate_new (node));
gimp_tile_handler_validate_assign (validate, buffer);
g_object_unref (validate);
gimp_tile_handler_validate_invalidate (validate,
gegl_buffer_get_extent (buffer));
#if 0
/* this would keep the buffer updated across drawable or
* filter changes, but the histogram is created in one go
* and doesn't need the signal connection
*/
g_signal_connect_object (node, "invalidated",
G_CALLBACK (gimp_tile_handler_validate_invalidate),
validate, G_CONNECT_SWAPPED);
#endif
}
else
{
g_object_ref (buffer);
}
if (! gimp_channel_is_empty (mask)) if (! gimp_channel_is_empty (mask))
{ {
gint off_x, off_y; gint off_x, off_y;
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
gimp_histogram_calculate (histogram, gimp_histogram_calculate (histogram, buffer,
gimp_drawable_get_buffer (drawable),
GEGL_RECTANGLE (x, y, width, height), GEGL_RECTANGLE (x, y, width, height),
gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)), gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)),
GEGL_RECTANGLE (x + off_x, y + off_y, GEGL_RECTANGLE (x + off_x, y + off_y,
@ -114,10 +161,11 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable,
} }
else else
{ {
gimp_histogram_calculate (histogram, gimp_histogram_calculate (histogram, buffer,
gimp_drawable_get_buffer (drawable),
GEGL_RECTANGLE (x, y, width, height), GEGL_RECTANGLE (x, y, width, height),
NULL, NULL); NULL, NULL);
} }
g_object_unref (buffer);
} }
} }

View File

@ -22,7 +22,8 @@
void gimp_drawable_calculate_histogram (GimpDrawable *drawable, void gimp_drawable_calculate_histogram (GimpDrawable *drawable,
GimpHistogram *histogram); GimpHistogram *histogram,
gboolean with_filters);
#endif /* __GIMP_HISTOGRAM_H__ */ #endif /* __GIMP_HISTOGRAM_H__ */

View File

@ -54,7 +54,7 @@ gimp_drawable_levels_stretch (GimpDrawable *drawable,
config = g_object_new (GIMP_TYPE_LEVELS_CONFIG, NULL); config = g_object_new (GIMP_TYPE_LEVELS_CONFIG, NULL);
histogram = gimp_histogram_new (FALSE); histogram = gimp_histogram_new (FALSE);
gimp_drawable_calculate_histogram (drawable, histogram); gimp_drawable_calculate_histogram (drawable, histogram, FALSE);
gimp_levels_config_stretch (config, histogram, gimp_levels_config_stretch (config, histogram,
gimp_drawable_is_rgb (drawable)); gimp_drawable_is_rgb (drawable));

View File

@ -647,7 +647,7 @@ histogram_invoker (GimpProcedure *procedure,
linear = FALSE; linear = FALSE;
histogram = gimp_histogram_new (linear); histogram = gimp_histogram_new (linear);
gimp_drawable_calculate_histogram (drawable, histogram); gimp_drawable_calculate_histogram (drawable, histogram, FALSE);
n_bins = gimp_histogram_n_bins (histogram); n_bins = gimp_histogram_n_bins (histogram);

View File

@ -418,7 +418,7 @@ drawable_histogram_invoker (GimpProcedure *procedure,
linear = FALSE; linear = FALSE;
histogram = gimp_histogram_new (linear); histogram = gimp_histogram_new (linear);
gimp_drawable_calculate_histogram (drawable, histogram); gimp_drawable_calculate_histogram (drawable, histogram, FALSE);
n_bins = gimp_histogram_n_bins (histogram); n_bins = gimp_histogram_n_bins (histogram);

View File

@ -195,7 +195,7 @@ gimp_curves_tool_initialize (GimpTool *tool,
} }
histogram = gimp_histogram_new (FALSE); histogram = gimp_histogram_new (FALSE);
gimp_drawable_calculate_histogram (drawable, histogram); gimp_drawable_calculate_histogram (drawable, histogram, FALSE);
gimp_histogram_view_set_background (GIMP_HISTOGRAM_VIEW (c_tool->graph), gimp_histogram_view_set_background (GIMP_HISTOGRAM_VIEW (c_tool->graph),
histogram); histogram);
g_object_unref (histogram); g_object_unref (histogram);

View File

@ -191,7 +191,7 @@ gimp_levels_tool_initialize (GimpTool *tool,
return FALSE; return FALSE;
} }
gimp_drawable_calculate_histogram (drawable, l_tool->histogram); gimp_drawable_calculate_histogram (drawable, l_tool->histogram, FALSE);
gimp_histogram_view_set_histogram (GIMP_HISTOGRAM_VIEW (l_tool->histogram_view), gimp_histogram_view_set_histogram (GIMP_HISTOGRAM_VIEW (l_tool->histogram_view),
l_tool->histogram); l_tool->histogram);

View File

@ -142,7 +142,7 @@ gimp_threshold_tool_initialize (GimpTool *tool,
return FALSE; return FALSE;
} }
gimp_drawable_calculate_histogram (drawable, t_tool->histogram); gimp_drawable_calculate_histogram (drawable, t_tool->histogram, FALSE);
gimp_histogram_view_set_histogram (t_tool->histogram_box->view, gimp_histogram_view_set_histogram (t_tool->histogram_box->view,
t_tool->histogram); t_tool->histogram);

View File

@ -133,12 +133,7 @@ gimp_histogram_editor_init (GimpHistogramEditor *editor)
N_("Percentile:") N_("Percentile:")
}; };
editor->drawable = NULL; editor->box = gimp_histogram_box_new ();
editor->histogram = NULL;
editor->bg_histogram = NULL;
editor->valid = FALSE;
editor->idle_id = 0;
editor->box = gimp_histogram_box_new ();
gimp_editor_set_show_name (GIMP_EDITOR (editor), TRUE); gimp_editor_set_show_name (GIMP_EDITOR (editor), TRUE);
@ -481,7 +476,8 @@ gimp_histogram_editor_validate (GimpHistogramEditor *editor)
} }
gimp_drawable_calculate_histogram (editor->drawable, gimp_drawable_calculate_histogram (editor->drawable,
editor->histogram); editor->histogram,
TRUE);
} }
else else
{ {

View File

@ -606,7 +606,7 @@ HELP
linear = FALSE; linear = FALSE;
histogram = gimp_histogram_new (linear); histogram = gimp_histogram_new (linear);
gimp_drawable_calculate_histogram (drawable, histogram); gimp_drawable_calculate_histogram (drawable, histogram, FALSE);
n_bins = gimp_histogram_n_bins (histogram); n_bins = gimp_histogram_n_bins (histogram);

View File

@ -464,7 +464,7 @@ HELP
linear = FALSE; linear = FALSE;
histogram = gimp_histogram_new (linear); histogram = gimp_histogram_new (linear);
gimp_drawable_calculate_histogram (drawable, histogram); gimp_drawable_calculate_histogram (drawable, histogram, FALSE);
n_bins = gimp_histogram_n_bins (histogram); n_bins = gimp_histogram_n_bins (histogram);