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;
GimpChannel *selection;
GimpHistogram *hist;
GimpHistogram *histogram;
GeglNode *equalize;
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));
selection = gimp_image_get_mask (image);
hist = gimp_histogram_new (FALSE);
gimp_drawable_calculate_histogram (drawable, hist);
histogram = gimp_histogram_new (FALSE);
gimp_drawable_calculate_histogram (drawable, histogram, FALSE);
equalize = gegl_node_new_child (NULL,
"operation", "gimp:equalize",
"histogram", hist,
"histogram", histogram,
NULL);
if (! mask_only)
@ -67,5 +67,5 @@ gimp_drawable_equalize (GimpDrawable *drawable,
gimp_selection_resume (GIMP_SELECTION (selection));
g_object_unref (equalize);
g_object_unref (hist);
g_object_unref (histogram);
}

View File

@ -19,14 +19,17 @@
#include "config.h"
#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "core-types.h"
#include "gegl/gimp-gegl-nodes.h"
#include "gegl/gimptilehandlervalidate.h"
#include "gimpchannel.h"
#include "gimpdrawable-filters.h"
#include "gimpdrawable-histogram.h"
#include "gimphistogram.h"
#include "gimpimage.h"
@ -34,7 +37,8 @@
void
gimp_drawable_calculate_histogram (GimpDrawable *drawable,
GimpHistogram *histogram)
GimpHistogram *histogram,
gboolean with_filters)
{
GimpImage *image;
GimpChannel *mask;
@ -53,14 +57,21 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable,
if (FALSE)
{
GeglNode *node = gegl_node_new ();
GeglNode *buffer_source;
GeglNode *source;
GeglNode *histogram_sink;
GeglProcessor *processor;
buffer_source =
gimp_gegl_add_buffer_source (node,
gimp_drawable_get_buffer (drawable),
0, 0);
if (with_filters)
{
source = gimp_drawable_get_source_node (drawable);
}
else
{
source =
gimp_gegl_add_buffer_source (node,
gimp_drawable_get_buffer (drawable),
0, 0);
}
histogram_sink =
gegl_node_new_child (node,
@ -68,7 +79,7 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable,
"histogram", histogram,
NULL);
gegl_node_connect_to (buffer_source, "output",
gegl_node_connect_to (source, "output",
histogram_sink, "input");
if (! gimp_channel_is_empty (mask))
@ -99,14 +110,50 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable,
}
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))
{
gint off_x, off_y;
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
gimp_histogram_calculate (histogram,
gimp_drawable_get_buffer (drawable),
gimp_histogram_calculate (histogram, buffer,
GEGL_RECTANGLE (x, y, width, height),
gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)),
GEGL_RECTANGLE (x + off_x, y + off_y,
@ -114,10 +161,11 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable,
}
else
{
gimp_histogram_calculate (histogram,
gimp_drawable_get_buffer (drawable),
gimp_histogram_calculate (histogram, buffer,
GEGL_RECTANGLE (x, y, width, height),
NULL, NULL);
}
g_object_unref (buffer);
}
}

View File

@ -22,7 +22,8 @@
void gimp_drawable_calculate_histogram (GimpDrawable *drawable,
GimpHistogram *histogram);
GimpHistogram *histogram,
gboolean with_filters);
#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);
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_drawable_is_rgb (drawable));

View File

@ -647,7 +647,7 @@ histogram_invoker (GimpProcedure *procedure,
linear = FALSE;
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);

View File

@ -418,7 +418,7 @@ drawable_histogram_invoker (GimpProcedure *procedure,
linear = FALSE;
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);

View File

@ -195,7 +195,7 @@ gimp_curves_tool_initialize (GimpTool *tool,
}
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),
histogram);
g_object_unref (histogram);

View File

@ -191,7 +191,7 @@ gimp_levels_tool_initialize (GimpTool *tool,
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),
l_tool->histogram);

View File

@ -142,7 +142,7 @@ gimp_threshold_tool_initialize (GimpTool *tool,
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,
t_tool->histogram);

View File

@ -133,12 +133,7 @@ gimp_histogram_editor_init (GimpHistogramEditor *editor)
N_("Percentile:")
};
editor->drawable = NULL;
editor->histogram = NULL;
editor->bg_histogram = NULL;
editor->valid = FALSE;
editor->idle_id = 0;
editor->box = gimp_histogram_box_new ();
editor->box = gimp_histogram_box_new ();
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,
editor->histogram);
editor->histogram,
TRUE);
}
else
{

View File

@ -606,7 +606,7 @@ HELP
linear = FALSE;
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);

View File

@ -464,7 +464,7 @@ HELP
linear = FALSE;
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);