2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2006-01-12 08:50:44 +08:00
|
|
|
* gimphistogram module Copyright (C) 1999 Jay Cox <jaycox@gimp.org>
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2005-02-15 01:45:35 +08:00
|
|
|
#include <string.h>
|
2015-11-02 15:53:50 +08:00
|
|
|
#include <cairo.h>
|
2012-04-17 03:01:39 +08:00
|
|
|
#include <gegl.h>
|
2015-11-02 15:53:50 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2000-12-19 22:43:54 +08:00
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2015-11-02 15:53:50 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2012-03-25 05:29:53 +08:00
|
|
|
#include "core-types.h"
|
|
|
|
|
2012-04-26 07:07:20 +08:00
|
|
|
#include "gegl/gimp-babl.h"
|
2018-05-24 22:21:21 +08:00
|
|
|
#include "gegl/gimp-gegl-loops.h"
|
2012-04-26 07:07:20 +08:00
|
|
|
|
2018-05-14 03:10:19 +08:00
|
|
|
#include "gimp-atomic.h"
|
2018-05-11 23:51:30 +08:00
|
|
|
#include "gimp-parallel.h"
|
|
|
|
#include "gimpasync.h"
|
2001-01-30 01:54:02 +08:00
|
|
|
#include "gimphistogram.h"
|
2018-05-27 22:14:17 +08:00
|
|
|
#include "gimpwaitable.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2005-02-14 09:33:14 +08:00
|
|
|
|
2018-05-14 03:10:19 +08:00
|
|
|
#define MIN_PARALLEL_SUB_SIZE 64
|
|
|
|
#define MIN_PARALLEL_SUB_AREA (MIN_PARALLEL_SUB_SIZE * MIN_PARALLEL_SUB_SIZE)
|
|
|
|
|
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_N_CHANNELS,
|
|
|
|
PROP_N_BINS,
|
|
|
|
PROP_VALUES
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GimpHistogramPrivate
|
2000-12-19 22:43:54 +08:00
|
|
|
{
|
2018-05-11 23:51:30 +08:00
|
|
|
gboolean linear;
|
|
|
|
gint n_channels;
|
|
|
|
gint n_bins;
|
|
|
|
gdouble *values;
|
|
|
|
GimpAsync *calculate_async;
|
2000-12-19 22:43:54 +08:00
|
|
|
};
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2018-05-14 03:10:19 +08:00
|
|
|
/* input */
|
2018-05-11 23:51:30 +08:00
|
|
|
GimpHistogram *histogram;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
GeglRectangle buffer_rect;
|
|
|
|
GeglBuffer *mask;
|
|
|
|
GeglRectangle mask_rect;
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
|
2018-05-14 03:10:19 +08:00
|
|
|
/* output */
|
2018-05-11 23:51:30 +08:00
|
|
|
gint n_components;
|
|
|
|
gint n_bins;
|
|
|
|
gdouble *values;
|
|
|
|
} CalculateContext;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2018-05-14 03:10:19 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GimpAsync *async;
|
|
|
|
CalculateContext *context;
|
|
|
|
|
|
|
|
const Babl *format;
|
|
|
|
GSList *values_list;
|
|
|
|
} CalculateData;
|
|
|
|
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
/* local function prototypes */
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
static void gimp_histogram_finalize (GObject *object);
|
|
|
|
static void gimp_histogram_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_histogram_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static gint64 gimp_histogram_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
|
|
|
|
|
|
|
static void gimp_histogram_set_values (GimpHistogram *histogram,
|
|
|
|
gint n_components,
|
|
|
|
gint n_bins,
|
|
|
|
gdouble *values);
|
|
|
|
|
|
|
|
static void gimp_histogram_calculate_internal (GimpAsync *async,
|
|
|
|
CalculateContext *context);
|
2018-05-14 03:10:19 +08:00
|
|
|
static void gimp_histogram_calculate_area (const GeglRectangle *area,
|
|
|
|
CalculateData *data);
|
2018-05-11 23:51:30 +08:00
|
|
|
static void gimp_histogram_calculate_async_callback (GimpAsync *async,
|
|
|
|
CalculateContext *context);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpHistogram, gimp_histogram, GIMP_TYPE_OBJECT)
|
|
|
|
|
|
|
|
#define parent_class gimp_histogram_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_histogram_class_init (GimpHistogramClass *klass)
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gimp_histogram_finalize;
|
|
|
|
object_class->set_property = gimp_histogram_set_property;
|
|
|
|
object_class->get_property = gimp_histogram_get_property;
|
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_histogram_get_memsize;
|
2003-01-15 21:40:44 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_N_CHANNELS,
|
|
|
|
g_param_spec_int ("n-channels", NULL, NULL,
|
2015-11-02 15:53:50 +08:00
|
|
|
0, 6, 0,
|
2013-06-12 03:23:32 +08:00
|
|
|
GIMP_PARAM_READABLE));
|
2008-02-05 05:41:57 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_N_BINS,
|
|
|
|
g_param_spec_int ("n-bins", NULL, NULL,
|
|
|
|
256, 1024, 1024,
|
|
|
|
GIMP_PARAM_READABLE));
|
|
|
|
|
|
|
|
/* this is just for notifications */
|
|
|
|
g_object_class_install_property (object_class, PROP_VALUES,
|
|
|
|
g_param_spec_boolean ("values", NULL, NULL,
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READABLE));
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GimpHistogramPrivate));
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
}
|
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
static void
|
|
|
|
gimp_histogram_init (GimpHistogram *histogram)
|
2008-02-05 05:41:57 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
histogram->priv = G_TYPE_INSTANCE_GET_PRIVATE (histogram,
|
|
|
|
GIMP_TYPE_HISTOGRAM,
|
|
|
|
GimpHistogramPrivate);
|
2008-02-05 05:41:57 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
histogram->priv->n_bins = 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_histogram_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpHistogram *histogram = GIMP_HISTOGRAM (object);
|
2008-02-05 05:41:57 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
gimp_histogram_clear_values (histogram);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2008-02-05 05:41:57 +08:00
|
|
|
}
|
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
static void
|
|
|
|
gimp_histogram_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
static void
|
|
|
|
gimp_histogram_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpHistogram *histogram = GIMP_HISTOGRAM (object);
|
2008-02-05 05:41:57 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
switch (property_id)
|
2008-02-05 05:41:57 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
case PROP_N_CHANNELS:
|
|
|
|
g_value_set_int (value, histogram->priv->n_channels);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_N_BINS:
|
|
|
|
g_value_set_int (value, histogram->priv->n_bins);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VALUES:
|
|
|
|
/* return a silly boolean */
|
|
|
|
g_value_set_boolean (value, histogram->priv->values != NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
2008-02-05 05:41:57 +08:00
|
|
|
}
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
static gint64
|
|
|
|
gimp_histogram_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size)
|
|
|
|
{
|
|
|
|
GimpHistogram *histogram = GIMP_HISTOGRAM (object);
|
|
|
|
gint64 memsize = 0;
|
|
|
|
|
|
|
|
if (histogram->priv->values)
|
|
|
|
memsize += (histogram->priv->n_channels *
|
|
|
|
histogram->priv->n_bins * sizeof (gdouble));
|
|
|
|
|
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GimpHistogram *
|
2016-12-27 00:32:17 +08:00
|
|
|
gimp_histogram_new (gboolean linear)
|
2013-06-12 03:23:32 +08:00
|
|
|
{
|
2013-06-12 07:02:25 +08:00
|
|
|
GimpHistogram *histogram = g_object_new (GIMP_TYPE_HISTOGRAM, NULL);
|
|
|
|
|
2016-12-27 00:32:17 +08:00
|
|
|
histogram->priv->linear = linear;
|
2013-06-12 07:02:25 +08:00
|
|
|
|
|
|
|
return histogram;
|
2013-06-12 03:23:32 +08:00
|
|
|
}
|
|
|
|
|
2008-07-22 17:29:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_histogram_duplicate:
|
|
|
|
* @histogram: a %GimpHistogram
|
|
|
|
*
|
|
|
|
* Creates a duplicate of @histogram. The duplicate has a reference
|
|
|
|
* count of 1 and contains the values from @histogram.
|
|
|
|
*
|
|
|
|
* Return value: a newly allocated %GimpHistogram
|
|
|
|
**/
|
|
|
|
GimpHistogram *
|
|
|
|
gimp_histogram_duplicate (GimpHistogram *histogram)
|
|
|
|
{
|
|
|
|
GimpHistogram *dup;
|
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), NULL);
|
2008-07-22 17:29:35 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
if (histogram->priv->calculate_async)
|
2018-05-27 22:14:17 +08:00
|
|
|
gimp_waitable_wait (GIMP_WAITABLE (histogram->priv->calculate_async));
|
2018-05-11 23:51:30 +08:00
|
|
|
|
2016-12-27 00:32:17 +08:00
|
|
|
dup = gimp_histogram_new (histogram->priv->linear);
|
2008-07-22 17:29:35 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
dup->priv->n_channels = histogram->priv->n_channels;
|
|
|
|
dup->priv->n_bins = histogram->priv->n_bins;
|
|
|
|
dup->priv->values = g_memdup (histogram->priv->values,
|
|
|
|
sizeof (gdouble) *
|
|
|
|
dup->priv->n_channels *
|
|
|
|
dup->priv->n_bins);
|
2008-07-22 17:29:35 +08:00
|
|
|
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
2012-04-17 03:01:39 +08:00
|
|
|
void
|
2012-04-17 04:36:28 +08:00
|
|
|
gimp_histogram_calculate (GimpHistogram *histogram,
|
2012-04-17 03:01:39 +08:00
|
|
|
GeglBuffer *buffer,
|
|
|
|
const GeglRectangle *buffer_rect,
|
|
|
|
GeglBuffer *mask,
|
|
|
|
const GeglRectangle *mask_rect)
|
|
|
|
{
|
2018-05-11 23:51:30 +08:00
|
|
|
CalculateContext context = {};
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
g_return_if_fail (GIMP_IS_HISTOGRAM (histogram));
|
2012-04-17 03:01:39 +08:00
|
|
|
g_return_if_fail (GEGL_IS_BUFFER (buffer));
|
|
|
|
g_return_if_fail (buffer_rect != NULL);
|
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
if (histogram->priv->calculate_async)
|
2018-05-27 22:14:17 +08:00
|
|
|
gimp_async_cancel_and_wait (histogram->priv->calculate_async);
|
2012-04-26 07:07:20 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
context.histogram = histogram;
|
|
|
|
context.buffer = buffer;
|
|
|
|
context.buffer_rect = *buffer_rect;
|
2012-04-17 03:01:39 +08:00
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
2018-05-11 23:51:30 +08:00
|
|
|
context.mask = mask;
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
if (mask_rect)
|
|
|
|
context.mask_rect = *mask_rect;
|
|
|
|
else
|
|
|
|
context.mask_rect = *gegl_buffer_get_extent (mask);
|
|
|
|
}
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
gimp_histogram_calculate_internal (NULL, &context);
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
gimp_histogram_set_values (histogram,
|
|
|
|
context.n_components, context.n_bins,
|
|
|
|
context.values);
|
|
|
|
}
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
GimpAsync *
|
|
|
|
gimp_histogram_calculate_async (GimpHistogram *histogram,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
const GeglRectangle *buffer_rect,
|
|
|
|
GeglBuffer *mask,
|
|
|
|
const GeglRectangle *mask_rect)
|
|
|
|
{
|
|
|
|
CalculateContext *context;
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), NULL);
|
|
|
|
g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
|
|
|
|
g_return_val_if_fail (buffer_rect != NULL, NULL);
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
if (histogram->priv->calculate_async)
|
2018-05-27 22:14:17 +08:00
|
|
|
gimp_async_cancel_and_wait (histogram->priv->calculate_async);
|
2015-11-02 15:53:50 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
context = g_slice_new0 (CalculateContext);
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
context->histogram = histogram;
|
|
|
|
context->buffer = gegl_buffer_new (buffer_rect,
|
|
|
|
gegl_buffer_get_format (buffer));
|
|
|
|
context->buffer_rect = *buffer_rect;
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-24 22:21:21 +08:00
|
|
|
gimp_gegl_buffer_copy (buffer, buffer_rect, GEGL_ABYSS_NONE,
|
|
|
|
context->buffer, NULL);
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
if (mask_rect)
|
|
|
|
context->mask_rect = *mask_rect;
|
|
|
|
else
|
|
|
|
context->mask_rect = *gegl_buffer_get_extent (mask);
|
2012-04-17 03:01:39 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
context->mask = gegl_buffer_new (&context->mask_rect,
|
|
|
|
gegl_buffer_get_format (mask));
|
2015-11-02 15:53:50 +08:00
|
|
|
|
2018-05-24 22:21:21 +08:00
|
|
|
gimp_gegl_buffer_copy (mask, &context->mask_rect, GEGL_ABYSS_NONE,
|
|
|
|
context->mask, NULL);
|
2012-04-17 03:01:39 +08:00
|
|
|
}
|
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
histogram->priv->calculate_async = gimp_parallel_run_async (
|
|
|
|
(GimpParallelRunAsyncFunc) gimp_histogram_calculate_internal,
|
|
|
|
context);
|
2013-06-12 03:23:32 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
gimp_async_add_callback (
|
|
|
|
histogram->priv->calculate_async,
|
|
|
|
(GimpAsyncCallback) gimp_histogram_calculate_async_callback,
|
|
|
|
context);
|
2013-06-12 03:23:32 +08:00
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
return histogram->priv->calculate_async;
|
2012-04-17 03:01:39 +08:00
|
|
|
}
|
|
|
|
|
2012-04-16 01:09:35 +08:00
|
|
|
void
|
|
|
|
gimp_histogram_clear_values (GimpHistogram *histogram)
|
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
g_return_if_fail (GIMP_IS_HISTOGRAM (histogram));
|
2012-04-16 01:09:35 +08:00
|
|
|
|
2018-05-12 20:56:16 +08:00
|
|
|
if (histogram->priv->calculate_async)
|
2018-05-27 22:14:17 +08:00
|
|
|
gimp_async_cancel_and_wait (histogram->priv->calculate_async);
|
2018-05-12 20:56:16 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
if (histogram->priv->values)
|
2012-04-17 04:36:28 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
g_free (histogram->priv->values);
|
|
|
|
histogram->priv->values = NULL;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (histogram), "values");
|
2012-04-17 04:36:28 +08:00
|
|
|
}
|
2012-04-16 01:09:35 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
if (histogram->priv->n_channels)
|
|
|
|
{
|
|
|
|
histogram->priv->n_channels = 0;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (histogram), "n-channels");
|
|
|
|
}
|
2012-04-16 01:09:35 +08:00
|
|
|
}
|
|
|
|
|
2005-02-15 01:45:35 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
#define HISTOGRAM_VALUE(c,i) (priv->values[(c) * priv->n_bins + (i)])
|
2005-02-15 01:45:35 +08:00
|
|
|
|
|
|
|
|
2002-09-08 01:27:32 +08:00
|
|
|
gdouble
|
2003-10-31 01:48:16 +08:00
|
|
|
gimp_histogram_get_maximum (GimpHistogram *histogram,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpHistogramChannel channel)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
GimpHistogramPrivate *priv;
|
|
|
|
gdouble max = 0.0;
|
|
|
|
gint x;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
priv = histogram->priv;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2004-01-13 21:35:58 +08:00
|
|
|
/* the gray alpha channel is in slot 1 */
|
2015-11-02 15:53:50 +08:00
|
|
|
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
|
2004-01-13 21:35:58 +08:00
|
|
|
channel = 1;
|
2015-11-02 15:53:50 +08:00
|
|
|
/* the luminance channel is in slot 4 */
|
|
|
|
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
|
|
|
|
channel = 4;
|
2004-01-13 21:35:58 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
if (! priv->values ||
|
|
|
|
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
|
2003-11-01 10:39:34 +08:00
|
|
|
return 0.0;
|
|
|
|
|
2004-07-07 00:33:30 +08:00
|
|
|
if (channel == GIMP_HISTOGRAM_RGB)
|
2013-06-11 06:58:47 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
for (x = 0; x < priv->n_bins; x++)
|
2013-06-11 06:58:47 +08:00
|
|
|
{
|
|
|
|
max = MAX (max, HISTOGRAM_VALUE (GIMP_HISTOGRAM_RED, x));
|
|
|
|
max = MAX (max, HISTOGRAM_VALUE (GIMP_HISTOGRAM_GREEN, x));
|
|
|
|
max = MAX (max, HISTOGRAM_VALUE (GIMP_HISTOGRAM_BLUE, x));
|
|
|
|
}
|
|
|
|
}
|
2004-07-07 00:33:30 +08:00
|
|
|
else
|
2013-06-11 06:58:47 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
for (x = 0; x < priv->n_bins; x++)
|
2013-06-11 06:58:47 +08:00
|
|
|
{
|
|
|
|
max = MAX (max, HISTOGRAM_VALUE (channel, x));
|
|
|
|
}
|
|
|
|
}
|
2002-09-08 01:27:32 +08:00
|
|
|
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdouble
|
2003-10-31 01:48:16 +08:00
|
|
|
gimp_histogram_get_value (GimpHistogram *histogram,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpHistogramChannel channel,
|
|
|
|
gint bin)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
GimpHistogramPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
|
|
|
|
|
|
|
|
priv = histogram->priv;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2004-01-13 21:35:58 +08:00
|
|
|
/* the gray alpha channel is in slot 1 */
|
2015-11-02 15:53:50 +08:00
|
|
|
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
|
2004-01-13 21:35:58 +08:00
|
|
|
channel = 1;
|
2015-11-02 15:53:50 +08:00
|
|
|
/* the luminance channel is in slot 4 */
|
|
|
|
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
|
|
|
|
channel = 4;
|
2004-01-13 21:35:58 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
if (! priv->values ||
|
|
|
|
bin < 0 || bin >= priv->n_bins ||
|
|
|
|
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
|
|
|
|
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
|
2004-07-07 00:33:30 +08:00
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
if (channel == GIMP_HISTOGRAM_RGB)
|
|
|
|
{
|
2005-02-15 01:45:35 +08:00
|
|
|
gdouble min = HISTOGRAM_VALUE (GIMP_HISTOGRAM_RED, bin);
|
2004-07-07 00:33:30 +08:00
|
|
|
|
2005-02-15 01:45:35 +08:00
|
|
|
min = MIN (min, HISTOGRAM_VALUE (GIMP_HISTOGRAM_GREEN, bin));
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2005-02-15 01:45:35 +08:00
|
|
|
return MIN (min, HISTOGRAM_VALUE (GIMP_HISTOGRAM_BLUE, bin));
|
2004-07-07 00:33:30 +08:00
|
|
|
}
|
|
|
|
else
|
2005-02-14 09:33:14 +08:00
|
|
|
{
|
2005-02-15 01:45:35 +08:00
|
|
|
return HISTOGRAM_VALUE (channel, bin);
|
2005-02-14 09:33:14 +08:00
|
|
|
}
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gdouble
|
2013-06-12 03:32:08 +08:00
|
|
|
gimp_histogram_get_component (GimpHistogram *histogram,
|
|
|
|
gint component,
|
|
|
|
gint bin)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2015-11-02 15:53:50 +08:00
|
|
|
if (histogram->priv->n_channels > 4)
|
2013-06-12 03:32:08 +08:00
|
|
|
component++;
|
2005-02-15 01:45:35 +08:00
|
|
|
|
2013-06-12 03:32:08 +08:00
|
|
|
return gimp_histogram_get_value (histogram, component, bin);
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
2004-01-13 19:51:45 +08:00
|
|
|
gimp_histogram_n_channels (GimpHistogram *histogram)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2015-11-02 15:53:50 +08:00
|
|
|
return histogram->priv->n_channels - 2;
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
|
|
|
|
2013-06-11 06:58:47 +08:00
|
|
|
gint
|
|
|
|
gimp_histogram_n_bins (GimpHistogram *histogram)
|
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0);
|
2013-06-11 06:58:47 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
return histogram->priv->n_bins;
|
2013-06-11 06:58:47 +08:00
|
|
|
}
|
|
|
|
|
2002-09-08 01:27:32 +08:00
|
|
|
gdouble
|
2003-10-31 01:48:16 +08:00
|
|
|
gimp_histogram_get_count (GimpHistogram *histogram,
|
|
|
|
GimpHistogramChannel channel,
|
2006-04-12 20:49:29 +08:00
|
|
|
gint start,
|
|
|
|
gint end)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
GimpHistogramPrivate *priv;
|
|
|
|
gint i;
|
|
|
|
gdouble count = 0.0;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
|
|
|
|
|
|
|
|
priv = histogram->priv;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2004-01-13 21:35:58 +08:00
|
|
|
/* the gray alpha channel is in slot 1 */
|
2015-11-02 15:53:50 +08:00
|
|
|
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
|
2004-01-13 21:35:58 +08:00
|
|
|
channel = 1;
|
2015-11-02 15:53:50 +08:00
|
|
|
/* the luminance channel is in slot 4 */
|
|
|
|
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
|
|
|
|
channel = 4;
|
2004-01-13 21:35:58 +08:00
|
|
|
|
2004-07-07 00:33:30 +08:00
|
|
|
if (channel == GIMP_HISTOGRAM_RGB)
|
|
|
|
return (gimp_histogram_get_count (histogram,
|
|
|
|
GIMP_HISTOGRAM_RED, start, end) +
|
2006-04-12 20:49:29 +08:00
|
|
|
gimp_histogram_get_count (histogram,
|
2004-07-07 00:33:30 +08:00
|
|
|
GIMP_HISTOGRAM_GREEN, start, end) +
|
2006-04-12 20:49:29 +08:00
|
|
|
gimp_histogram_get_count (histogram,
|
2004-07-07 00:33:30 +08:00
|
|
|
GIMP_HISTOGRAM_BLUE, start, end));
|
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
if (! priv->values ||
|
2004-07-07 00:33:30 +08:00
|
|
|
start > end ||
|
2013-06-12 03:23:32 +08:00
|
|
|
channel >= priv->n_channels)
|
2003-11-01 10:39:34 +08:00
|
|
|
return 0.0;
|
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
start = CLAMP (start, 0, priv->n_bins - 1);
|
|
|
|
end = CLAMP (end, 0, priv->n_bins - 1);
|
2004-07-07 00:33:30 +08:00
|
|
|
|
2002-09-08 01:27:32 +08:00
|
|
|
for (i = start; i <= end; i++)
|
2005-02-15 01:45:35 +08:00
|
|
|
count += HISTOGRAM_VALUE (channel, i);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdouble
|
2003-10-31 01:48:16 +08:00
|
|
|
gimp_histogram_get_mean (GimpHistogram *histogram,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpHistogramChannel channel,
|
|
|
|
gint start,
|
|
|
|
gint end)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
GimpHistogramPrivate *priv;
|
|
|
|
gint i;
|
|
|
|
gdouble mean = 0.0;
|
|
|
|
gdouble count;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
priv = histogram->priv;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2004-01-13 21:35:58 +08:00
|
|
|
/* the gray alpha channel is in slot 1 */
|
2015-11-02 15:53:50 +08:00
|
|
|
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
|
2004-01-13 21:35:58 +08:00
|
|
|
channel = 1;
|
2015-11-02 15:53:50 +08:00
|
|
|
/* the luminance channel is in slot 4 */
|
|
|
|
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
|
|
|
|
channel = 4;
|
2004-01-13 21:35:58 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
if (! priv->values ||
|
2004-07-07 00:33:30 +08:00
|
|
|
start > end ||
|
2015-11-02 15:53:50 +08:00
|
|
|
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 5) ||
|
2013-06-12 03:23:32 +08:00
|
|
|
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
|
2003-11-01 10:39:34 +08:00
|
|
|
return 0.0;
|
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
start = CLAMP (start, 0, priv->n_bins - 1);
|
|
|
|
end = CLAMP (end, 0, priv->n_bins - 1);
|
2004-07-07 00:33:30 +08:00
|
|
|
|
|
|
|
if (channel == GIMP_HISTOGRAM_RGB)
|
|
|
|
{
|
|
|
|
for (i = start; i <= end; i++)
|
2013-06-12 08:01:24 +08:00
|
|
|
{
|
|
|
|
gdouble factor = (gdouble) i / (gdouble) (priv->n_bins - 1);
|
|
|
|
|
|
|
|
mean += (factor * HISTOGRAM_VALUE (GIMP_HISTOGRAM_RED, i) +
|
|
|
|
factor * HISTOGRAM_VALUE (GIMP_HISTOGRAM_GREEN, i) +
|
|
|
|
factor * HISTOGRAM_VALUE (GIMP_HISTOGRAM_BLUE, i));
|
|
|
|
}
|
2004-07-07 00:33:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = start; i <= end; i++)
|
2013-06-12 08:01:24 +08:00
|
|
|
{
|
|
|
|
gdouble factor = (gdouble) i / (gdouble) (priv->n_bins - 1);
|
|
|
|
|
|
|
|
mean += factor * HISTOGRAM_VALUE (channel, i);
|
|
|
|
}
|
2004-07-07 00:33:30 +08:00
|
|
|
}
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2003-10-31 01:48:16 +08:00
|
|
|
count = gimp_histogram_get_count (histogram, channel, start, end);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
|
|
|
if (count > 0.0)
|
|
|
|
return mean / count;
|
|
|
|
|
|
|
|
return mean;
|
|
|
|
}
|
|
|
|
|
2013-06-12 08:01:24 +08:00
|
|
|
gdouble
|
2003-10-31 01:48:16 +08:00
|
|
|
gimp_histogram_get_median (GimpHistogram *histogram,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpHistogramChannel channel,
|
|
|
|
gint start,
|
|
|
|
gint end)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
GimpHistogramPrivate *priv;
|
|
|
|
gint i;
|
|
|
|
gdouble sum = 0.0;
|
|
|
|
gdouble count;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 08:01:24 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), -1.0);
|
2013-06-12 03:23:32 +08:00
|
|
|
|
|
|
|
priv = histogram->priv;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2004-01-13 21:35:58 +08:00
|
|
|
/* the gray alpha channel is in slot 1 */
|
2015-11-02 15:53:50 +08:00
|
|
|
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
|
2004-01-13 21:35:58 +08:00
|
|
|
channel = 1;
|
2015-11-02 15:53:50 +08:00
|
|
|
/* the luminance channel is in slot 4 */
|
|
|
|
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
|
|
|
|
channel = 4;
|
2004-01-13 21:35:58 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
if (! priv->values ||
|
2004-07-07 00:33:30 +08:00
|
|
|
start > end ||
|
2015-11-02 15:53:50 +08:00
|
|
|
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 5) ||
|
2013-06-12 03:23:32 +08:00
|
|
|
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
|
2013-06-12 08:01:24 +08:00
|
|
|
return 0.0;
|
2003-11-01 10:39:34 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
start = CLAMP (start, 0, priv->n_bins - 1);
|
|
|
|
end = CLAMP (end, 0, priv->n_bins - 1);
|
2004-07-07 00:33:30 +08:00
|
|
|
|
2003-10-31 01:48:16 +08:00
|
|
|
count = gimp_histogram_get_count (histogram, channel, start, end);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2004-07-07 00:33:30 +08:00
|
|
|
if (channel == GIMP_HISTOGRAM_RGB)
|
2013-06-11 06:58:47 +08:00
|
|
|
{
|
|
|
|
for (i = start; i <= end; i++)
|
|
|
|
{
|
|
|
|
sum += (HISTOGRAM_VALUE (GIMP_HISTOGRAM_RED, i) +
|
|
|
|
HISTOGRAM_VALUE (GIMP_HISTOGRAM_GREEN, i) +
|
|
|
|
HISTOGRAM_VALUE (GIMP_HISTOGRAM_BLUE, i));
|
|
|
|
|
|
|
|
if (sum * 2 > count)
|
2013-06-12 08:01:24 +08:00
|
|
|
return ((gdouble) i / (gdouble) (priv->n_bins - 1));
|
2013-06-11 06:58:47 +08:00
|
|
|
}
|
|
|
|
}
|
2004-07-07 00:33:30 +08:00
|
|
|
else
|
2013-06-11 06:58:47 +08:00
|
|
|
{
|
|
|
|
for (i = start; i <= end; i++)
|
|
|
|
{
|
|
|
|
sum += HISTOGRAM_VALUE (channel, i);
|
2004-07-07 00:33:30 +08:00
|
|
|
|
2013-06-11 06:58:47 +08:00
|
|
|
if (sum * 2 > count)
|
2013-06-12 08:01:24 +08:00
|
|
|
return ((gdouble) i / (gdouble) (priv->n_bins - 1));
|
2013-06-11 06:58:47 +08:00
|
|
|
}
|
|
|
|
}
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 08:01:24 +08:00
|
|
|
return -1.0;
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
|
|
|
|
2006-04-21 17:40:27 +08:00
|
|
|
/*
|
|
|
|
* adapted from GNU ocrad 0.14 : page_image_io.cc : otsu_th
|
|
|
|
*
|
|
|
|
* N. Otsu, "A threshold selection method from gray-level histograms,"
|
|
|
|
* IEEE Trans. Systems, Man, and Cybernetics, vol. 9, no. 1, pp. 62-66, 1979.
|
|
|
|
*/
|
|
|
|
gdouble
|
|
|
|
gimp_histogram_get_threshold (GimpHistogram *histogram,
|
|
|
|
GimpHistogramChannel channel,
|
|
|
|
gint start,
|
|
|
|
gint end)
|
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
GimpHistogramPrivate *priv;
|
|
|
|
gint i;
|
|
|
|
gint maxval;
|
|
|
|
gdouble *hist = NULL;
|
|
|
|
gdouble *chist = NULL;
|
|
|
|
gdouble *cmom = NULL;
|
|
|
|
gdouble hist_max = 0.0;
|
|
|
|
gdouble chist_max = 0.0;
|
|
|
|
gdouble cmom_max = 0.0;
|
|
|
|
gdouble bvar_max = 0.0;
|
|
|
|
gint threshold = 127;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), -1);
|
|
|
|
|
|
|
|
priv = histogram->priv;
|
2006-04-21 17:40:27 +08:00
|
|
|
|
|
|
|
/* the gray alpha channel is in slot 1 */
|
2015-11-02 15:53:50 +08:00
|
|
|
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
|
2006-04-21 17:40:27 +08:00
|
|
|
channel = 1;
|
2015-11-02 15:53:50 +08:00
|
|
|
/* the luminance channel is in slot 4 */
|
|
|
|
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
|
|
|
|
channel = 4;
|
2006-04-21 17:40:27 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
if (! priv->values ||
|
2006-04-21 17:40:27 +08:00
|
|
|
start > end ||
|
2015-11-02 15:53:50 +08:00
|
|
|
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 5) ||
|
2013-06-12 03:23:32 +08:00
|
|
|
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
|
2006-04-21 17:40:27 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
start = CLAMP (start, 0, priv->n_bins - 1);
|
|
|
|
end = CLAMP (end, 0, priv->n_bins - 1);
|
2006-04-21 17:40:27 +08:00
|
|
|
|
|
|
|
maxval = end - start;
|
|
|
|
|
|
|
|
hist = g_newa (gdouble, maxval + 1);
|
|
|
|
chist = g_newa (gdouble, maxval + 1);
|
|
|
|
cmom = g_newa (gdouble, maxval + 1);
|
|
|
|
|
|
|
|
if (channel == GIMP_HISTOGRAM_RGB)
|
|
|
|
{
|
|
|
|
for (i = start; i <= end; i++)
|
|
|
|
hist[i - start] = (HISTOGRAM_VALUE (GIMP_HISTOGRAM_RED, i) +
|
|
|
|
HISTOGRAM_VALUE (GIMP_HISTOGRAM_GREEN, i) +
|
|
|
|
HISTOGRAM_VALUE (GIMP_HISTOGRAM_BLUE, i));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = start; i <= end; i++)
|
|
|
|
hist[i - start] = HISTOGRAM_VALUE (channel, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
hist_max = hist[0];
|
|
|
|
chist[0] = hist[0];
|
|
|
|
cmom[0] = 0;
|
|
|
|
|
2011-10-13 13:13:09 +08:00
|
|
|
for (i = 1; i <= maxval; i++)
|
2006-04-21 17:40:27 +08:00
|
|
|
{
|
|
|
|
if (hist[i] > hist_max)
|
2016-11-25 12:51:03 +08:00
|
|
|
hist_max = hist[i];
|
2006-04-21 17:40:27 +08:00
|
|
|
|
|
|
|
chist[i] = chist[i-1] + hist[i];
|
|
|
|
cmom[i] = cmom[i-1] + i * hist[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
chist_max = chist[maxval];
|
|
|
|
cmom_max = cmom[maxval];
|
|
|
|
bvar_max = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < maxval; ++i)
|
2013-06-11 06:58:47 +08:00
|
|
|
{
|
|
|
|
if (chist[i] > 0 && chist[i] < chist_max)
|
|
|
|
{
|
|
|
|
gdouble bvar;
|
|
|
|
|
|
|
|
bvar = (gdouble) cmom[i] / chist[i];
|
|
|
|
bvar -= (cmom_max - cmom[i]) / (chist_max - chist[i]);
|
|
|
|
bvar *= bvar;
|
|
|
|
bvar *= chist[i];
|
|
|
|
bvar *= chist_max - chist[i];
|
|
|
|
|
|
|
|
if (bvar > bvar_max)
|
|
|
|
{
|
|
|
|
bvar_max = bvar;
|
|
|
|
threshold = start + i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-04-21 17:40:27 +08:00
|
|
|
|
|
|
|
return threshold;
|
|
|
|
}
|
|
|
|
|
2002-09-08 01:27:32 +08:00
|
|
|
gdouble
|
2003-10-31 01:48:16 +08:00
|
|
|
gimp_histogram_get_std_dev (GimpHistogram *histogram,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpHistogramChannel channel,
|
|
|
|
gint start,
|
|
|
|
gint end)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
GimpHistogramPrivate *priv;
|
|
|
|
gint i;
|
|
|
|
gdouble dev = 0.0;
|
|
|
|
gdouble count;
|
|
|
|
gdouble mean;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
priv = histogram->priv;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2004-01-13 21:35:58 +08:00
|
|
|
/* the gray alpha channel is in slot 1 */
|
2015-11-02 15:53:50 +08:00
|
|
|
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
|
2004-01-13 21:35:58 +08:00
|
|
|
channel = 1;
|
2015-11-02 15:53:50 +08:00
|
|
|
/* the luminance channel is in slot 4 */
|
|
|
|
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
|
|
|
|
channel = 4;
|
2004-01-13 21:35:58 +08:00
|
|
|
|
2013-06-12 03:23:32 +08:00
|
|
|
if (! priv->values ||
|
2004-07-07 00:33:30 +08:00
|
|
|
start > end ||
|
2015-11-02 15:53:50 +08:00
|
|
|
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 5) ||
|
2013-06-12 03:23:32 +08:00
|
|
|
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
|
2003-11-01 10:39:34 +08:00
|
|
|
return 0.0;
|
|
|
|
|
2002-09-08 01:27:32 +08:00
|
|
|
mean = gimp_histogram_get_mean (histogram, channel, start, end);
|
2003-10-31 01:48:16 +08:00
|
|
|
count = gimp_histogram_get_count (histogram, channel, start, end);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
|
|
|
if (count == 0.0)
|
|
|
|
count = 1.0;
|
|
|
|
|
|
|
|
for (i = start; i <= end; i++)
|
2007-08-13 18:34:35 +08:00
|
|
|
{
|
|
|
|
gdouble value;
|
|
|
|
|
|
|
|
if (channel == GIMP_HISTOGRAM_RGB)
|
|
|
|
{
|
|
|
|
value = (HISTOGRAM_VALUE (GIMP_HISTOGRAM_RED, i) +
|
|
|
|
HISTOGRAM_VALUE (GIMP_HISTOGRAM_GREEN, i) +
|
|
|
|
HISTOGRAM_VALUE (GIMP_HISTOGRAM_BLUE, i));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = gimp_histogram_get_value (histogram, channel, i);
|
|
|
|
}
|
|
|
|
|
2013-06-12 08:01:24 +08:00
|
|
|
dev += value * SQR (((gdouble) i / (gdouble) (priv->n_bins - 1)) - mean);
|
2007-08-13 18:34:35 +08:00
|
|
|
}
|
2002-09-08 01:27:32 +08:00
|
|
|
|
|
|
|
return sqrt (dev / count);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2018-05-11 23:51:30 +08:00
|
|
|
static void
|
|
|
|
gimp_histogram_set_values (GimpHistogram *histogram,
|
|
|
|
gint n_components,
|
|
|
|
gint n_bins,
|
|
|
|
gdouble *values)
|
|
|
|
{
|
|
|
|
GimpHistogramPrivate *priv = histogram->priv;
|
|
|
|
gboolean notify_n_channels = FALSE;
|
|
|
|
gboolean notify_n_bins = FALSE;
|
|
|
|
|
|
|
|
if (n_components + 2 != priv->n_channels)
|
|
|
|
{
|
|
|
|
priv->n_channels = n_components + 2;
|
|
|
|
|
|
|
|
notify_n_channels = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_bins != priv->n_bins)
|
|
|
|
{
|
|
|
|
priv->n_bins = n_bins;
|
|
|
|
|
|
|
|
notify_n_bins = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (values != priv->values)
|
|
|
|
{
|
|
|
|
if (priv->values)
|
|
|
|
g_free (priv->values);
|
|
|
|
|
|
|
|
priv->values = values;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notify_n_channels)
|
|
|
|
g_object_notify (G_OBJECT (histogram), "n-channels");
|
|
|
|
|
|
|
|
if (notify_n_bins)
|
|
|
|
g_object_notify (G_OBJECT (histogram), "n-bins");
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (histogram), "values");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_histogram_calculate_internal (GimpAsync *async,
|
|
|
|
CalculateContext *context)
|
|
|
|
{
|
2018-05-14 03:10:19 +08:00
|
|
|
CalculateData data;
|
2018-05-11 23:51:30 +08:00
|
|
|
GimpHistogramPrivate *priv;
|
|
|
|
const Babl *format;
|
|
|
|
|
|
|
|
priv = context->histogram->priv;
|
|
|
|
|
|
|
|
format = gegl_buffer_get_format (context->buffer);
|
|
|
|
|
|
|
|
if (babl_format_get_type (format, 0) == babl_type ("u8"))
|
2018-05-14 03:10:19 +08:00
|
|
|
context->n_bins = 256;
|
2018-05-11 23:51:30 +08:00
|
|
|
else
|
2018-05-14 03:10:19 +08:00
|
|
|
context->n_bins = 1024;
|
2018-05-11 23:51:30 +08:00
|
|
|
|
|
|
|
if (babl_format_is_palette (format))
|
|
|
|
{
|
|
|
|
if (babl_format_has_alpha (format))
|
|
|
|
{
|
|
|
|
if (priv->linear)
|
|
|
|
format = babl_format ("RGB float");
|
|
|
|
else
|
|
|
|
format = babl_format ("R'G'B' float");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (priv->linear)
|
|
|
|
format = babl_format ("RGBA float");
|
|
|
|
else
|
|
|
|
format = babl_format ("R'G'B'A float");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const Babl *model = babl_format_get_model (format);
|
|
|
|
|
|
|
|
if (model == babl_model ("Y") ||
|
|
|
|
model == babl_model ("Y'"))
|
|
|
|
{
|
|
|
|
if (priv->linear)
|
|
|
|
format = babl_format ("Y float");
|
|
|
|
else
|
|
|
|
format = babl_format ("Y' float");
|
|
|
|
}
|
|
|
|
else if (model == babl_model ("YA") ||
|
|
|
|
model == babl_model ("Y'A"))
|
|
|
|
{
|
|
|
|
if (priv->linear)
|
|
|
|
format = babl_format ("YA float");
|
|
|
|
else
|
|
|
|
format = babl_format ("Y'A float");
|
|
|
|
}
|
|
|
|
else if (model == babl_model ("RGB") ||
|
|
|
|
model == babl_model ("R'G'B'"))
|
|
|
|
{
|
|
|
|
if (priv->linear)
|
|
|
|
format = babl_format ("RGB float");
|
|
|
|
else
|
|
|
|
format = babl_format ("R'G'B' float");
|
|
|
|
}
|
|
|
|
else if (model == babl_model ("RGBA") ||
|
|
|
|
model == babl_model ("R'G'B'A"))
|
|
|
|
{
|
|
|
|
if (priv->linear)
|
|
|
|
format = babl_format ("RGBA float");
|
|
|
|
else
|
|
|
|
format = babl_format ("R'G'B'A float");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (async)
|
|
|
|
gimp_async_abort (async);
|
|
|
|
|
|
|
|
g_return_if_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 03:10:19 +08:00
|
|
|
context->n_components = babl_format_get_n_components (format);
|
|
|
|
|
|
|
|
data.async = async;
|
|
|
|
data.context = context;
|
|
|
|
data.format = format;
|
|
|
|
data.values_list = NULL;
|
2018-05-11 23:51:30 +08:00
|
|
|
|
2018-05-14 03:10:19 +08:00
|
|
|
gimp_parallel_distribute_area (
|
|
|
|
&context->buffer_rect, MIN_PARALLEL_SUB_AREA,
|
|
|
|
(GimpParallelDistributeAreaFunc) gimp_histogram_calculate_area,
|
|
|
|
&data);
|
|
|
|
|
|
|
|
if (! async || ! gimp_async_is_canceled (async))
|
2018-05-11 23:51:30 +08:00
|
|
|
{
|
2018-05-14 03:10:19 +08:00
|
|
|
gdouble *total_values = NULL;
|
|
|
|
gint n_values = (context->n_components + 2) * context->n_bins;
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
for (iter = data.values_list; iter; iter = g_slist_next (iter))
|
|
|
|
{
|
|
|
|
gdouble *values = iter->data;
|
|
|
|
|
|
|
|
if (! total_values)
|
|
|
|
{
|
|
|
|
total_values = values;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_values; i++)
|
|
|
|
total_values[i] += values[i];
|
|
|
|
|
|
|
|
g_free (values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (data.values_list);
|
|
|
|
|
|
|
|
context->values = total_values;
|
|
|
|
|
|
|
|
if (async)
|
|
|
|
gimp_async_finish (async, NULL);
|
2018-05-11 23:51:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-14 03:10:19 +08:00
|
|
|
g_slist_free_full (data.values_list, g_free);
|
|
|
|
|
|
|
|
if (async)
|
|
|
|
gimp_async_abort (async);
|
2018-05-11 23:51:30 +08:00
|
|
|
}
|
2018-05-14 03:10:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_histogram_calculate_area (const GeglRectangle *area,
|
|
|
|
CalculateData *data)
|
|
|
|
{
|
|
|
|
GimpAsync *async;
|
|
|
|
CalculateContext *context;
|
|
|
|
GeglBufferIterator *iter;
|
|
|
|
gdouble *values;
|
|
|
|
gint n_components;
|
|
|
|
gint n_bins;
|
|
|
|
gfloat n_bins_1f;
|
|
|
|
gfloat temp;
|
|
|
|
|
|
|
|
async = data->async;
|
|
|
|
context = data->context;
|
|
|
|
|
|
|
|
n_bins = context->n_bins;
|
|
|
|
n_components = context->n_components;
|
2018-05-11 23:51:30 +08:00
|
|
|
|
2018-05-14 03:10:19 +08:00
|
|
|
values = g_new0 (gdouble, (n_components + 2) * n_bins);
|
|
|
|
gimp_atomic_slist_push_head (&data->values_list, values);
|
|
|
|
|
|
|
|
iter = gegl_buffer_iterator_new (context->buffer, area, 0,
|
|
|
|
data->format,
|
2018-05-11 23:51:30 +08:00
|
|
|
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
|
|
|
|
|
|
|
|
if (context->mask)
|
2018-05-14 03:10:19 +08:00
|
|
|
{
|
|
|
|
GeglRectangle mask_area = *area;
|
|
|
|
|
|
|
|
mask_area.x += context->mask_rect.x - context->buffer_rect.x;
|
|
|
|
mask_area.y += context->mask_rect.y - context->buffer_rect.y;
|
|
|
|
|
|
|
|
gegl_buffer_iterator_add (iter, context->mask, &mask_area, 0,
|
|
|
|
babl_format ("Y float"),
|
|
|
|
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
|
|
|
|
}
|
2018-05-11 23:51:30 +08:00
|
|
|
|
|
|
|
n_bins_1f = n_bins - 1;
|
|
|
|
|
|
|
|
#define VALUE(c,i) (*(temp = (i) * n_bins_1f, \
|
|
|
|
&values[(c) * n_bins + \
|
|
|
|
SIGNED_ROUND (SAFE_CLAMP (temp, \
|
|
|
|
0.0f, \
|
|
|
|
n_bins_1f))]))
|
|
|
|
|
|
|
|
#define CHECK_CANCELED(length) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
2018-05-14 03:10:19 +08:00
|
|
|
if ((length) % 128 == 0 && async && gimp_async_is_canceled (async)) \
|
2018-05-11 23:51:30 +08:00
|
|
|
{ \
|
|
|
|
gegl_buffer_iterator_stop (iter); \
|
|
|
|
\
|
2018-05-14 03:10:19 +08:00
|
|
|
return; \
|
2018-05-11 23:51:30 +08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
G_STMT_END
|
|
|
|
|
|
|
|
while (gegl_buffer_iterator_next (iter))
|
|
|
|
{
|
|
|
|
const gfloat *data = iter->data[0];
|
|
|
|
gint length = iter->length;
|
|
|
|
gfloat max;
|
|
|
|
gfloat luminance;
|
|
|
|
|
|
|
|
CHECK_CANCELED (0);
|
|
|
|
|
|
|
|
if (context->mask)
|
|
|
|
{
|
|
|
|
const gfloat *mask_data = iter->data[1];
|
|
|
|
|
|
|
|
switch (n_components)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
const gdouble masked = *mask_data;
|
|
|
|
|
|
|
|
VALUE (0, data[0]) += masked;
|
|
|
|
|
|
|
|
data += n_components;
|
|
|
|
mask_data += 1;
|
|
|
|
|
|
|
|
CHECK_CANCELED (length);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
const gdouble masked = *mask_data;
|
|
|
|
const gdouble weight = data[1];
|
|
|
|
|
|
|
|
VALUE (0, data[0]) += weight * masked;
|
|
|
|
VALUE (1, data[1]) += masked;
|
|
|
|
|
|
|
|
data += n_components;
|
|
|
|
mask_data += 1;
|
|
|
|
|
|
|
|
CHECK_CANCELED (length);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* calculate separate value values */
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
const gdouble masked = *mask_data;
|
|
|
|
|
|
|
|
VALUE (1, data[0]) += masked;
|
|
|
|
VALUE (2, data[1]) += masked;
|
|
|
|
VALUE (3, data[2]) += masked;
|
|
|
|
|
|
|
|
max = MAX (data[0], data[1]);
|
|
|
|
max = MAX (data[2], max);
|
|
|
|
VALUE (0, max) += masked;
|
|
|
|
|
|
|
|
luminance = GIMP_RGB_LUMINANCE (data[0], data[1], data[2]);
|
|
|
|
VALUE (4, luminance) += masked;
|
|
|
|
|
|
|
|
data += n_components;
|
|
|
|
mask_data += 1;
|
|
|
|
|
|
|
|
CHECK_CANCELED (length);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: /* calculate separate value values */
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
const gdouble masked = *mask_data;
|
|
|
|
const gdouble weight = data[3];
|
|
|
|
|
|
|
|
VALUE (1, data[0]) += weight * masked;
|
|
|
|
VALUE (2, data[1]) += weight * masked;
|
|
|
|
VALUE (3, data[2]) += weight * masked;
|
|
|
|
VALUE (4, data[3]) += masked;
|
|
|
|
|
|
|
|
max = MAX (data[0], data[1]);
|
|
|
|
max = MAX (data[2], max);
|
|
|
|
VALUE (0, max) += weight * masked;
|
|
|
|
|
|
|
|
luminance = GIMP_RGB_LUMINANCE (data[0], data[1], data[2]);
|
|
|
|
VALUE (5, luminance) += weight * masked;
|
|
|
|
|
|
|
|
data += n_components;
|
|
|
|
mask_data += 1;
|
|
|
|
|
|
|
|
CHECK_CANCELED (length);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* no mask */
|
|
|
|
{
|
|
|
|
switch (n_components)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
VALUE (0, data[0]) += 1.0;
|
|
|
|
|
|
|
|
data += n_components;
|
|
|
|
|
|
|
|
CHECK_CANCELED (length);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
const gdouble weight = data[1];
|
|
|
|
|
|
|
|
VALUE (0, data[0]) += weight;
|
|
|
|
VALUE (1, data[1]) += 1.0;
|
|
|
|
|
|
|
|
data += n_components;
|
|
|
|
|
|
|
|
CHECK_CANCELED (length);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* calculate separate value values */
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
VALUE (1, data[0]) += 1.0;
|
|
|
|
VALUE (2, data[1]) += 1.0;
|
|
|
|
VALUE (3, data[2]) += 1.0;
|
|
|
|
|
|
|
|
max = MAX (data[0], data[1]);
|
|
|
|
max = MAX (data[2], max);
|
|
|
|
VALUE (0, max) += 1.0;
|
|
|
|
|
|
|
|
luminance = GIMP_RGB_LUMINANCE (data[0], data[1], data[2]);
|
|
|
|
VALUE (4, luminance) += 1.0;
|
|
|
|
|
|
|
|
data += n_components;
|
|
|
|
|
|
|
|
CHECK_CANCELED (length);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: /* calculate separate value values */
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
const gdouble weight = data[3];
|
|
|
|
|
|
|
|
VALUE (1, data[0]) += weight;
|
|
|
|
VALUE (2, data[1]) += weight;
|
|
|
|
VALUE (3, data[2]) += weight;
|
|
|
|
VALUE (4, data[3]) += 1.0;
|
|
|
|
|
|
|
|
max = MAX (data[0], data[1]);
|
|
|
|
max = MAX (data[2], max);
|
|
|
|
VALUE (0, max) += weight;
|
|
|
|
|
|
|
|
luminance = GIMP_RGB_LUMINANCE (data[0], data[1], data[2]);
|
|
|
|
VALUE (5, luminance) += weight;
|
|
|
|
|
|
|
|
data += n_components;
|
|
|
|
|
|
|
|
CHECK_CANCELED (length);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef VALUE
|
|
|
|
#undef CHECK_CANCELED
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_histogram_calculate_async_callback (GimpAsync *async,
|
|
|
|
CalculateContext *context)
|
|
|
|
{
|
|
|
|
context->histogram->priv->calculate_async = NULL;
|
|
|
|
|
|
|
|
if (gimp_async_is_finished (async))
|
|
|
|
{
|
|
|
|
gimp_histogram_set_values (context->histogram,
|
|
|
|
context->n_components, context->n_bins,
|
|
|
|
context->values);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (context->buffer);
|
|
|
|
if (context->mask)
|
|
|
|
g_object_unref (context->mask);
|
|
|
|
|
|
|
|
g_slice_free (CalculateContext, context);
|
|
|
|
}
|