Commit f4cb2dd8 authored by Thomas Manni's avatar Thomas Manni Committed by Michael Natterer

Bug 109161 - Improve Histogram with Luminance Channel

Add a luminance channel to GimpHistogram
parent 1d337877
......@@ -255,6 +255,7 @@ gimp_histogram_channel_get_type (void)
{ GIMP_HISTOGRAM_GREEN, "GIMP_HISTOGRAM_GREEN", "green" },
{ GIMP_HISTOGRAM_BLUE, "GIMP_HISTOGRAM_BLUE", "blue" },
{ GIMP_HISTOGRAM_ALPHA, "GIMP_HISTOGRAM_ALPHA", "alpha" },
{ GIMP_HISTOGRAM_LUMINANCE, "GIMP_HISTOGRAM_LUMINANCE", "luminance" },
{ GIMP_HISTOGRAM_RGB, "GIMP_HISTOGRAM_RGB", "rgb" },
{ 0, NULL, NULL }
};
......@@ -266,6 +267,7 @@ gimp_histogram_channel_get_type (void)
{ GIMP_HISTOGRAM_GREEN, NC_("histogram-channel", "Green"), NULL },
{ GIMP_HISTOGRAM_BLUE, NC_("histogram-channel", "Blue"), NULL },
{ GIMP_HISTOGRAM_ALPHA, NC_("histogram-channel", "Alpha"), NULL },
{ GIMP_HISTOGRAM_LUMINANCE, NC_("histogram-channel", "Luminance"), NULL },
{ GIMP_HISTOGRAM_RGB, NC_("histogram-channel", "RGB"), NULL },
{ 0, NULL, NULL }
};
......
......@@ -138,12 +138,13 @@ GType gimp_histogram_channel_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_HISTOGRAM_VALUE = 0, /*< desc="Value" >*/
GIMP_HISTOGRAM_RED = 1, /*< desc="Red" >*/
GIMP_HISTOGRAM_GREEN = 2, /*< desc="Green" >*/
GIMP_HISTOGRAM_BLUE = 3, /*< desc="Blue" >*/
GIMP_HISTOGRAM_ALPHA = 4, /*< desc="Alpha" >*/
GIMP_HISTOGRAM_RGB = 5 /*< desc="RGB", pdb-skip >*/
GIMP_HISTOGRAM_VALUE = 0, /*< desc="Value" >*/
GIMP_HISTOGRAM_RED = 1, /*< desc="Red" >*/
GIMP_HISTOGRAM_GREEN = 2, /*< desc="Green" >*/
GIMP_HISTOGRAM_BLUE = 3, /*< desc="Blue" >*/
GIMP_HISTOGRAM_ALPHA = 4, /*< desc="Alpha" >*/
GIMP_HISTOGRAM_LUMINANCE = 5, /*< desc="Luminance" >*/
GIMP_HISTOGRAM_RGB = 6 /*< desc="RGB", pdb-skip >*/
} GimpHistogramChannel;
......
......@@ -20,10 +20,12 @@
#include "config.h"
#include <string.h>
#include <cairo.h>
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpcolor/gimpcolor.h"
#include "core-types.h"
......@@ -88,7 +90,7 @@ gimp_histogram_class_init (GimpHistogramClass *klass)
g_object_class_install_property (object_class, PROP_N_CHANNELS,
g_param_spec_int ("n-channels", NULL, NULL,
0, 5, 0,
0, 6, 0,
GIMP_PARAM_READABLE));
g_object_class_install_property (object_class, PROP_N_BINS,
......@@ -333,6 +335,7 @@ gimp_histogram_calculate (GimpHistogram *histogram,
const gfloat *data = iter->data[0];
gint length = iter->length;
gfloat max;
gfloat luminance;
if (mask)
{
......@@ -377,9 +380,11 @@ gimp_histogram_calculate (GimpHistogram *histogram,
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;
}
......@@ -398,9 +403,11 @@ gimp_histogram_calculate (GimpHistogram *histogram,
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;
}
......@@ -441,9 +448,11 @@ gimp_histogram_calculate (GimpHistogram *histogram,
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;
}
break;
......@@ -460,9 +469,11 @@ gimp_histogram_calculate (GimpHistogram *histogram,
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;
}
break;
......@@ -515,8 +526,11 @@ gimp_histogram_get_maximum (GimpHistogram *histogram,
priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
/* the luminance channel is in slot 4 */
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
channel = 4;
if (! priv->values ||
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
......@@ -554,8 +568,11 @@ gimp_histogram_get_value (GimpHistogram *histogram,
priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
/* the luminance channel is in slot 4 */
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
channel = 4;
if (! priv->values ||
bin < 0 || bin >= priv->n_bins ||
......@@ -584,7 +601,7 @@ gimp_histogram_get_component (GimpHistogram *histogram,
{
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0.0);
if (histogram->priv->n_channels > 3)
if (histogram->priv->n_channels > 4)
component++;
return gimp_histogram_get_value (histogram, component, bin);
......@@ -595,7 +612,7 @@ gimp_histogram_n_channels (GimpHistogram *histogram)
{
g_return_val_if_fail (GIMP_IS_HISTOGRAM (histogram), 0);
return histogram->priv->n_channels - 1;
return histogram->priv->n_channels - 2;
}
gint
......@@ -621,8 +638,11 @@ gimp_histogram_get_count (GimpHistogram *histogram,
priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
/* the luminance channel is in slot 4 */
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
channel = 4;
if (channel == GIMP_HISTOGRAM_RGB)
return (gimp_histogram_get_count (histogram,
......@@ -662,12 +682,15 @@ gimp_histogram_get_mean (GimpHistogram *histogram,
priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
/* the luminance channel is in slot 4 */
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
channel = 4;
if (! priv->values ||
start > end ||
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 5) ||
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0.0;
......@@ -719,12 +742,15 @@ gimp_histogram_get_median (GimpHistogram *histogram,
priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
/* the luminance channel is in slot 4 */
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
channel = 4;
if (! priv->values ||
start > end ||
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 5) ||
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0.0;
......@@ -788,12 +814,15 @@ gimp_histogram_get_threshold (GimpHistogram *histogram,
priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
/* the luminance channel is in slot 4 */
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
channel = 4;
if (! priv->values ||
start > end ||
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 5) ||
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0;
......@@ -876,12 +905,15 @@ gimp_histogram_get_std_dev (GimpHistogram *histogram,
priv = histogram->priv;
/* the gray alpha channel is in slot 1 */
if (priv->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
if (priv->n_channels == 4 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
/* the luminance channel is in slot 4 */
else if (priv->n_channels == 5 && channel == GIMP_HISTOGRAM_LUMINANCE)
channel = 4;
if (! priv->values ||
start > end ||
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 4) ||
(channel == GIMP_HISTOGRAM_RGB && priv->n_channels < 5) ||
(channel != GIMP_HISTOGRAM_RGB && channel >= priv->n_channels))
return 0.0;
......@@ -922,14 +954,14 @@ gimp_histogram_alloc_values (GimpHistogram *histogram,
{
GimpHistogramPrivate *priv = histogram->priv;
if (n_components + 1 != priv->n_channels ||
if (n_components + 2 != priv->n_channels ||
n_bins != priv->n_bins)
{
gimp_histogram_clear_values (histogram);
if (n_components + 1 != priv->n_channels)
if (n_components + 2 != priv->n_channels)
{
priv->n_channels = n_components + 1;
priv->n_channels = n_components + 2;
g_object_notify (G_OBJECT (histogram), "n-channels");
}
......
......@@ -535,6 +535,9 @@ gimp_levels_config_input_from_color (GimpHistogramChannel channel,
case GIMP_HISTOGRAM_RGB:
return MIN (MIN (color->r, color->g), color->b);
case GIMP_HISTOGRAM_LUMINANCE:
return GIMP_RGB_LUMINANCE (color->r, color->g, color->b);
}
return 0.0;
......
......@@ -126,6 +126,7 @@ levels_invoker (GimpProcedure *procedure,
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
channel != GIMP_HISTOGRAM_LUMINANCE &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
......@@ -423,7 +424,8 @@ curves_spline_invoker (GimpProcedure *procedure,
! (num_points & 1) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = gimp_curves_config_new_spline_cruft (channel,
control_pts,
......@@ -470,7 +472,8 @@ curves_explicit_invoker (GimpProcedure *procedure,
(num_bytes == 256) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = gimp_curves_config_new_explicit_cruft (channel,
curve,
......
......@@ -224,7 +224,8 @@ drawable_curves_explicit_invoker (GimpProcedure *procedure,
(num_values <= 4096) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = gimp_curves_config_new_explicit (channel,
values,
......@@ -271,7 +272,8 @@ drawable_curves_spline_invoker (GimpProcedure *procedure,
! (num_points & 1) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = gimp_curves_config_new_spline (channel,
points,
......@@ -572,7 +574,8 @@ drawable_levels_invoker (GimpProcedure *procedure,
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = g_object_new (GIMP_TYPE_LEVELS_CONFIG,
"channel", channel,
......
......@@ -714,6 +714,7 @@ gimp_curves_tool_update_channel (GimpCurvesTool *tool)
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
case GIMP_HISTOGRAM_RGB:
case GIMP_HISTOGRAM_LUMINANCE:
gimp_curve_get_uchar (curve, sizeof (r), r);
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->xrange),
......@@ -837,6 +838,9 @@ curves_menu_sensitivity (gint value,
case GIMP_HISTOGRAM_RGB:
return FALSE;
case GIMP_HISTOGRAM_LUMINANCE:
return FALSE;
}
return FALSE;
......
......@@ -837,6 +837,7 @@ levels_update_input_bar (GimpLevelsTool *tool)
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
case GIMP_HISTOGRAM_RGB:
case GIMP_HISTOGRAM_LUMINANCE:
{
guchar v[256];
gint i;
......@@ -933,6 +934,9 @@ levels_menu_sensitivity (gint value,
case GIMP_HISTOGRAM_RGB:
return FALSE;
case GIMP_HISTOGRAM_LUMINANCE:
return FALSE;
}
return FALSE;
......
......@@ -289,6 +289,7 @@ gimp_color_bar_set_channel (GimpColorBar *bar,
switch (channel)
{
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_LUMINANCE:
case GIMP_HISTOGRAM_ALPHA:
case GIMP_HISTOGRAM_RGB:
gimp_rgb_set (&color, 1.0, 1.0, 1.0);
......
......@@ -460,6 +460,7 @@ gimp_histogram_editor_channel_valid (GimpHistogramEditor *editor,
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
case GIMP_HISTOGRAM_LUMINANCE:
case GIMP_HISTOGRAM_RGB:
return gimp_drawable_is_rgb (editor->drawable);
......
......@@ -58,7 +58,8 @@ typedef enum
GIMP_HISTOGRAM_RED,
GIMP_HISTOGRAM_GREEN,
GIMP_HISTOGRAM_BLUE,
GIMP_HISTOGRAM_ALPHA
GIMP_HISTOGRAM_ALPHA,
GIMP_HISTOGRAM_LUMINANCE
} GimpHistogramChannel;
......
......@@ -665,12 +665,13 @@ package Gimp::CodeGen::enums;
header => 'core/core-enums.h',
symbols => [ qw(GIMP_HISTOGRAM_VALUE GIMP_HISTOGRAM_RED
GIMP_HISTOGRAM_GREEN GIMP_HISTOGRAM_BLUE
GIMP_HISTOGRAM_ALPHA) ],
GIMP_HISTOGRAM_ALPHA GIMP_HISTOGRAM_LUMINANCE) ],
mapping => { GIMP_HISTOGRAM_VALUE => '0',
GIMP_HISTOGRAM_RED => '1',
GIMP_HISTOGRAM_GREEN => '2',
GIMP_HISTOGRAM_BLUE => '3',
GIMP_HISTOGRAM_ALPHA => '4' }
GIMP_HISTOGRAM_ALPHA => '4',
GIMP_HISTOGRAM_LUMINANCE => '5' }
},
GimpLayerModeEffects =>
{ contig => 1,
......
......@@ -81,6 +81,7 @@ sub levels {
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
channel != GIMP_HISTOGRAM_LUMINANCE &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
......@@ -353,7 +354,8 @@ sub curves_spline {
! (num_points & 1) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = gimp_curves_config_new_spline_cruft (channel,
control_pts,
......@@ -397,7 +399,8 @@ sub curves_explicit {
(num_bytes == 256) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = gimp_curves_config_new_explicit_cruft (channel,
curve,
......
......@@ -214,7 +214,8 @@ HELP
(num_values <= 4096) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = gimp_curves_config_new_explicit (channel,
values,
......@@ -271,7 +272,8 @@ HELP
! (num_points & 1) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = gimp_curves_config_new_spline (channel,
points,
......@@ -628,7 +630,8 @@ HELP
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
channel != GIMP_HISTOGRAM_LUMINANCE)
{
GObject *config = g_object_new (GIMP_TYPE_LEVELS_CONFIG,
"channel", channel,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment