Commit 27319afd authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

add properties, some cleanup.

2008-01-07  Michael Natterer  <mitch@gimp.org>

	* app/gegl/gimpoperationlevels.[ch]: add properties, some cleanup.

	* app/tools/gimplevelstool.c: use gegl_node_set() instead of
	accessing the operation directly.


svn path=/trunk/; revision=24566
parent 1c804c8d
2008-01-07 Michael Natterer <mitch@gimp.org>
* app/gegl/gimpoperationlevels.[ch]: add properties, some cleanup.
* app/tools/gimplevelstool.c: use gegl_node_set() instead of
accessing the operation directly.
2008-01-07 Michael Natterer <mitch@gimp.org>
* app/gegl/Makefile.am
......
......@@ -37,9 +37,12 @@
enum
{
PROP_0,
PROP_HUE,
PROP_SATURATION,
PROP_LIGHTNESS
PROP_CHANNEL,
PROP_GAMMA,
PROP_LOW_INPUT,
PROP_HIGH_INPUT,
PROP_LOW_OUTPUT,
PROP_HIGH_OUTPUT
};
......@@ -77,11 +80,74 @@ gimp_operation_levels_class_init (GimpOperationLevelsClass * klass)
point_class->process = gimp_operation_levels_process;
gegl_operation_class_set_name (operation_class, "gimp-levels");
g_object_class_install_property (object_class, PROP_CHANNEL,
g_param_spec_enum ("channel",
"Channel",
"The affected channel",
GIMP_TYPE_HISTOGRAM_CHANNEL,
GIMP_HISTOGRAM_VALUE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_GAMMA,
g_param_spec_float ("gamma",
"Gamma",
"Gamma",
0.1, 10.0, 1.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_LOW_INPUT,
g_param_spec_float ("low-input",
"Low Input",
"Low Input",
0.0, 1.0, 0.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_HIGH_INPUT,
g_param_spec_float ("high-input",
"High Input",
"High Input",
0.0, 1.0, 1.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_LOW_OUTPUT,
g_param_spec_float ("low-output",
"Low Output",
"Low Output",
0.0, 1.0, 0.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_HIGH_OUTPUT,
g_param_spec_float ("high-output",
"High Output",
"High Output",
0.0, 1.0, 1.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
gimp_operation_levels_init (GimpOperationLevels *self)
{
GimpHistogramChannel channel;
self->channel = GIMP_HISTOGRAM_VALUE;
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
self->gamma[channel] = 1.0;
self->low_input[channel] = 0.0;
self->high_input[channel] = 1.0;
self->low_output[channel] = 0.0;
self->high_output[channel] = 1.0;
}
}
static void
......@@ -90,10 +156,34 @@ gimp_operation_levels_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
/* GimpOperationLevels *self = GIMP_OPERATION_LEVELS (object); */
GimpOperationLevels *self = GIMP_OPERATION_LEVELS (object);
switch (property_id)
{
case PROP_CHANNEL:
g_value_set_enum (value, self->channel);
break;
case PROP_GAMMA:
g_value_set_float (value, self->gamma[self->channel]);
break;
case PROP_LOW_INPUT:
g_value_set_float (value, self->low_input[self->channel]);
break;
case PROP_HIGH_INPUT:
g_value_set_float (value, self->high_input[self->channel]);
break;
case PROP_LOW_OUTPUT:
g_value_set_float (value, self->low_output[self->channel]);
break;
case PROP_HIGH_OUTPUT:
g_value_set_float (value, self->high_output[self->channel]);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -106,10 +196,34 @@ gimp_operation_levels_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
/* GimpOperationLevels *self = GIMP_OPERATION_LEVELS (object); */
GimpOperationLevels *self = GIMP_OPERATION_LEVELS (object);
switch (property_id)
{
case PROP_CHANNEL:
self->channel = g_value_get_enum (value);
break;
case PROP_GAMMA:
self->gamma[self->channel] = g_value_get_float (value);
break;
case PROP_LOW_INPUT:
self->low_input[self->channel] = g_value_get_float (value);
break;
case PROP_HIGH_INPUT:
self->high_input[self->channel] = g_value_get_float (value);
break;
case PROP_LOW_OUTPUT:
self->low_output[self->channel] = g_value_get_float (value);
break;
case PROP_HIGH_OUTPUT:
self->high_output[self->channel] = g_value_get_float (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -118,21 +232,17 @@ gimp_operation_levels_set_property (GObject *object,
static inline gfloat
gimp_operation_levels_map (gfloat value,
gfloat gamma,
gfloat low_input,
gfloat high_input,
gfloat gamma,
gfloat low_output,
gfloat high_output)
{
/* determine input intensity */
if (high_input != low_input)
{
value = (value - low_input) / (high_input - low_input);
}
value = (value - low_input) / (high_input - low_input);
else
{
value = (value - low_input);
}
value = (value - low_input);
if (gamma != 0.0)
{
......@@ -171,18 +281,18 @@ gimp_operation_levels_process (GeglOperation *operation,
gfloat value;
value = gimp_operation_levels_map (src[channel],
self->gamma[channel + 1],
self->low_input[channel + 1],
self->high_input[channel + 1],
self->gamma[channel + 1],
self->low_output[channel + 1],
self->high_output[channel + 1]);
/* don't apply the overall curve to the alpha channel */
if (channel != 3)
value = gimp_operation_levels_map (value,
self->gamma[0],
self->low_input[0],
self->high_input[0],
self->gamma[0],
self->low_output[0],
self->high_output[0]);
......
......@@ -40,6 +40,8 @@ struct _GimpOperationLevels
{
GeglOperationPointFilter parent_instance;
GimpHistogramChannel channel;
gfloat gamma[5];
gfloat low_input[5];
......
......@@ -37,8 +37,6 @@
#include "base/gimplut.h"
#include "base/levels.h"
#include "gegl/gimpoperationlevels.h"
#include "core/gimpdrawable.h"
#include "core/gimpdrawable-histogram.h"
#include "core/gimpimage.h"
......@@ -270,28 +268,25 @@ gimp_levels_tool_map (GimpImageMapTool *image_map_tool)
if (image_map_tool->operation)
{
GimpOperationLevels *levels;
Levels *l;
Levels *levels = tool->levels;
GimpHistogramChannel channel;
g_object_get (image_map_tool->operation, "gegl-operation", &levels, NULL);
l = tool->levels;
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
levels->gamma[channel] = l->gamma[channel];
levels->low_input[channel] = l->low_input[channel] / 255.0;
levels->high_input[channel] = l->high_input[channel] / 255.0;
gegl_node_set (image_map_tool->operation,
"channel", channel,
NULL);
levels->low_output[channel] = l->low_output[channel] / 255.0;
levels->high_output[channel] = l->high_output[channel] / 255.0;
gegl_node_set (image_map_tool->operation,
"gamma", levels->gamma[channel],
"low-input", levels->low_input[channel] / 255.0,
"high-input", levels->high_input[channel] / 255.0,
"low-output", levels->low_output[channel] / 255.0,
"high-output", levels->high_output[channel] / 255.0,
NULL);
}
g_object_unref (levels);
}
gimp_lut_setup (tool->lut,
......
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