app/gegl/Makefile.am app/gegl/gegl-types.h new config object.

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

	* app/gegl/Makefile.am
	* app/gegl/gegl-types.h
	* app/gegl/gimpcolorizeconfig.[ch]: new config object.

	* app/gegl/gimpoperationcolorize.[ch]: remove all properties and
	add a "config" property.

	* app/tools/gimpcolorizetool.[ch]: port to GimpColorizeConfig, use
	the old Colorize struct only in map().


svn path=/trunk/; revision=24647
This commit is contained in:
Michael Natterer 2008-01-18 14:44:27 +00:00 committed by Michael Natterer
parent a09925eae8
commit 30907dbd76
9 changed files with 325 additions and 85 deletions

View file

@ -1,3 +1,15 @@
2008-01-18 Michael Natterer <mitch@gimp.org>
* app/gegl/Makefile.am
* app/gegl/gegl-types.h
* app/gegl/gimpcolorizeconfig.[ch]: new config object.
* app/gegl/gimpoperationcolorize.[ch]: remove all properties and
add a "config" property.
* app/tools/gimpcolorizetool.[ch]: port to GimpColorizeConfig, use
the old Colorize struct only in map().
2008-01-18 Michael Natterer <mitch@gimp.org>
* app/gegl/gimplevelsconfig.[ch]: ported the stretch and pick

View file

@ -7,8 +7,12 @@ libappgegl_a_SOURCES = \
gimp-gegl.h \
gimp-gegl-utils.c \
gimp-gegl-utils.h \
\
gimpcolorizeconfig.c \
gimpcolorizeconfig.h \
gimplevelsconfig.c \
gimplevelsconfig.h \
\
gimpoperationcolorbalance.c \
gimpoperationcolorbalance.h \
gimpoperationcolorize.c \

View file

@ -41,6 +41,7 @@ typedef struct _GimpOperationTileSource GimpOperationTileSource;
/* operation config objects */
typedef struct _GimpColorizeConfig GimpColorizeConfig;
typedef struct _GimpLevelsConfig GimpLevelsConfig;

View file

@ -0,0 +1,147 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcolorizeconfig.c
* Copyright (C) 2007 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gegl.h>
#include "gegl-types.h"
#include "gimpcolorizeconfig.h"
enum
{
PROP_0,
PROP_HUE,
PROP_SATURATION,
PROP_LIGHTNESS
};
static void gimp_colorize_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_colorize_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (GimpColorizeConfig, gimp_colorize_config, G_TYPE_OBJECT)
#define parent_class gimp_colorize_config_parent_class
static void
gimp_colorize_config_class_init (GimpColorizeConfigClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = gimp_colorize_config_set_property;
object_class->get_property = gimp_colorize_config_get_property;
g_object_class_install_property (object_class, PROP_HUE,
g_param_spec_double ("hue",
"Hue",
"Hue",
0.0, 1.0, 0.5,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_SATURATION,
g_param_spec_double ("saturation",
"Saturation",
"Saturation",
0.0, 1.0, 0.5,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_LIGHTNESS,
g_param_spec_double ("lightness",
"Lightness",
"Lightness",
-1.0, 1.0, 0.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
gimp_colorize_config_init (GimpColorizeConfig *self)
{
}
static void
gimp_colorize_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpColorizeConfig *self = GIMP_COLORIZE_CONFIG (object);
switch (property_id)
{
case PROP_HUE:
g_value_set_double (value, self->hue);
break;
case PROP_SATURATION:
g_value_set_double (value, self->saturation);
break;
case PROP_LIGHTNESS:
g_value_set_double (value, self->lightness);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_colorize_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpColorizeConfig *self = GIMP_COLORIZE_CONFIG (object);
switch (property_id)
{
case PROP_HUE:
self->hue = g_value_get_double (value);
break;
case PROP_SATURATION:
self->saturation = g_value_get_double (value);
break;
case PROP_LIGHTNESS:
self->lightness = g_value_get_double (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}

View file

@ -0,0 +1,52 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcolorizeconfig.h
* Copyright (C) 2007 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_COLORIZE_CONFIG_H__
#define __GIMP_COLORIZE_CONFIG_H__
#define GIMP_TYPE_COLORIZE_CONFIG (gimp_colorize_config_get_type ())
#define GIMP_COLORIZE_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLORIZE_CONFIG, GimpColorizeConfig))
#define GIMP_COLORIZE_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLORIZE_CONFIG, GimpColorizeConfigClass))
#define GIMP_COLORIZE_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLORIZE_CONFIG, GimpColorizeConfigClass))
typedef struct _GimpColorizeConfigClass GimpColorizeConfigClass;
struct _GimpColorizeConfig
{
GObject parent_instance;
gdouble hue;
gdouble saturation;
gdouble lightness;
};
struct _GimpColorizeConfigClass
{
GObjectClass parent_class;
};
GType gimp_colorize_config_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_COLORIZE_CONFIG_H__ */

View file

@ -27,18 +27,18 @@
#include "gegl-types.h"
#include "gimpcolorizeconfig.h"
#include "gimpoperationcolorize.h"
enum
{
PROP_0,
PROP_HUE,
PROP_SATURATION,
PROP_LIGHTNESS
PROP_CONFIG
};
static void gimp_operation_colorize_finalize (GObject *object);
static void gimp_operation_colorize_get_property (GObject *object,
guint property_id,
GValue *value,
@ -67,6 +67,7 @@ gimp_operation_colorize_class_init (GimpOperationColorizeClass * klass)
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
GeglOperationPointFilterClass *point_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
object_class->finalize = gimp_operation_colorize_finalize;
object_class->set_property = gimp_operation_colorize_set_property;
object_class->get_property = gimp_operation_colorize_get_property;
@ -74,27 +75,11 @@ gimp_operation_colorize_class_init (GimpOperationColorizeClass * klass)
gegl_operation_class_set_name (operation_class, "gimp-colorize");
g_object_class_install_property (object_class, PROP_HUE,
g_param_spec_double ("hue",
"Hue",
"Hue",
0.0, 1.0, 0.5,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_SATURATION,
g_param_spec_double ("saturation",
"Saturation",
"Saturation",
0.0, 1.0, 0.5,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_LIGHTNESS,
g_param_spec_double ("lightness",
"Lightness",
"Lightness",
-1.0, 1.0, 0.0,
g_object_class_install_property (object_class, PROP_CONFIG,
g_param_spec_object ("config",
"Config",
"The config object",
GIMP_TYPE_COLORIZE_CONFIG,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
@ -104,6 +89,20 @@ gimp_operation_colorize_init (GimpOperationColorize *self)
{
}
static void
gimp_operation_colorize_finalize (GObject *object)
{
GimpOperationColorize *self = GIMP_OPERATION_COLORIZE (object);
if (self->config)
{
g_object_unref (self->config);
self->config = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_operation_colorize_get_property (GObject *object,
guint property_id,
@ -114,16 +113,8 @@ gimp_operation_colorize_get_property (GObject *object,
switch (property_id)
{
case PROP_HUE:
g_value_set_double (value, self->hue);
break;
case PROP_SATURATION:
g_value_set_double (value, self->saturation);
break;
case PROP_LIGHTNESS:
g_value_set_double (value, self->lightness);
case PROP_CONFIG:
g_value_set_object (value, self->config);
break;
default:
@ -142,16 +133,10 @@ gimp_operation_colorize_set_property (GObject *object,
switch (property_id)
{
case PROP_HUE:
self->hue = g_value_get_double (value);
break;
case PROP_SATURATION:
self->saturation = g_value_get_double (value);
break;
case PROP_LIGHTNESS:
self->lightness = g_value_get_double (value);
case PROP_CONFIG:
if (self->config)
g_object_unref (self->config);
self->config = g_value_dup_object (value);
break;
default:
@ -166,14 +151,15 @@ gimp_operation_colorize_process (GeglOperation *operation,
void *out_buf,
glong samples)
{
GimpOperationColorize *self = GIMP_OPERATION_COLORIZE (operation);
gfloat *src = in_buf;
gfloat *dest = out_buf;
GimpOperationColorize *self = GIMP_OPERATION_COLORIZE (operation);
GimpColorizeConfig *config = self->config;
gfloat *src = in_buf;
gfloat *dest = out_buf;
GimpHSL hsl;
glong sample;
hsl.h = self->hue;
hsl.s = self->saturation;
hsl.h = config->hue;
hsl.s = config->saturation;
for (sample = 0; sample < samples; sample++)
{
@ -182,15 +168,15 @@ gimp_operation_colorize_process (GeglOperation *operation,
src[GREEN_PIX],
src[BLUE_PIX]);
if (self->lightness > 0)
if (config->lightness > 0)
{
lum = lum * (1.0 - self->lightness);
lum = lum * (1.0 - config->lightness);
lum += 1.0 - (1.0 - self->lightness);
lum += 1.0 - (1.0 - config->lightness);
}
else if (self->lightness < 0)
else if (config->lightness < 0)
{
lum = lum * (self->lightness + 1.0);
lum = lum * (config->lightness + 1.0);
}
hsl.l = lum;

View file

@ -38,9 +38,7 @@ struct _GimpOperationColorize
{
GeglOperationPointFilter parent_instance;
gdouble hue;
gdouble saturation;
gdouble lightness;
GimpColorizeConfig *config;
};
struct _GimpOperationColorizeClass

View file

@ -27,6 +27,8 @@
#include "base/colorize.h"
#include "gegl/gimpcolorizeconfig.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
@ -126,6 +128,12 @@ gimp_colorize_tool_finalize (GObject *object)
g_slice_free (Colorize, col_tool->colorize);
if (col_tool->config)
{
g_object_unref (col_tool->config);
col_tool->config = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -147,7 +155,11 @@ gimp_colorize_tool_initialize (GimpTool *tool,
return FALSE;
}
colorize_init (col_tool->colorize);
g_object_set (col_tool->config,
"hue", 0.5,
"saturation", 0.5,
"lightness", 0.0,
NULL);
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
@ -161,23 +173,34 @@ gimp_colorize_tool_initialize (GimpTool *tool,
static GeglNode *
gimp_colorize_tool_get_operation (GimpImageMapTool *im_tool)
{
return g_object_new (GEGL_TYPE_NODE,
GimpColorizeTool *tool = GIMP_COLORIZE_TOOL (im_tool);
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp-colorize",
NULL);
tool->config = g_object_new (GIMP_TYPE_COLORIZE_CONFIG, NULL);
gegl_node_set (node,
"config", tool->config,
NULL);
return node;
}
static void
gimp_colorize_tool_map (GimpImageMapTool *image_map_tool)
{
GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (image_map_tool);
GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (image_map_tool);
GimpColorizeConfig *config = col_tool->config;
Colorize *colorize = col_tool->colorize;
gegl_node_set (image_map_tool->operation,
"hue", col_tool->colorize->hue / 360.0,
"saturation", col_tool->colorize->saturation / 100.0,
"lightness", col_tool->colorize->lightness / 100.0,
NULL);
colorize->hue = config->hue * 360.0;
colorize->saturation = config->saturation * 100.0;
colorize->lightness = config->lightness * 100.0;
colorize_calculate (col_tool->colorize);
colorize_calculate (colorize);
}
@ -235,7 +258,7 @@ gimp_colorize_tool_dialog (GimpImageMapTool *image_map_tool)
slider = GIMP_SCALE_ENTRY_SCALE (data);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_CONTINUOUS);
g_signal_connect (col_tool->saturation_data, "value-changed",
g_signal_connect (data, "value-changed",
G_CALLBACK (colorize_saturation_changed),
col_tool);
@ -259,7 +282,11 @@ gimp_colorize_tool_reset (GimpImageMapTool *image_map_tool)
{
GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (image_map_tool);
colorize_init (col_tool->colorize);
g_object_set (col_tool->config,
"hue", 0.5,
"saturation", 0.5,
"lightness", 0.0,
NULL);
colorize_update_sliders (col_tool);
}
@ -267,21 +294,25 @@ gimp_colorize_tool_reset (GimpImageMapTool *image_map_tool)
static void
colorize_update_sliders (GimpColorizeTool *col_tool)
{
gtk_adjustment_set_value (GTK_ADJUSTMENT (col_tool->hue_data),
col_tool->colorize->hue);
gtk_adjustment_set_value (GTK_ADJUSTMENT (col_tool->saturation_data),
col_tool->colorize->saturation);
gtk_adjustment_set_value (GTK_ADJUSTMENT (col_tool->lightness_data),
col_tool->colorize->lightness);
gtk_adjustment_set_value (col_tool->hue_data,
col_tool->config->hue * 360.0);
gtk_adjustment_set_value (col_tool->saturation_data,
col_tool->config->saturation * 100.0);
gtk_adjustment_set_value (col_tool->lightness_data,
col_tool->config->lightness * 100.0);
}
static void
colorize_hue_changed (GtkAdjustment *adjustment,
GimpColorizeTool *col_tool)
{
if (col_tool->colorize->hue != adjustment->value)
gdouble value = adjustment->value / 360.0;
if (col_tool->config->hue != value)
{
col_tool->colorize->hue = adjustment->value;
g_object_set (col_tool->config,
"hue", value,
NULL);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (col_tool));
}
@ -291,9 +322,13 @@ static void
colorize_saturation_changed (GtkAdjustment *adjustment,
GimpColorizeTool *col_tool)
{
if (col_tool->colorize->saturation != adjustment->value)
gdouble value = adjustment->value / 100.0;
if (col_tool->config->saturation != value)
{
col_tool->colorize->saturation = adjustment->value;
g_object_set (col_tool->config,
"saturation", value,
NULL);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (col_tool));
}
@ -303,9 +338,13 @@ static void
colorize_lightness_changed (GtkAdjustment *adjustment,
GimpColorizeTool *col_tool)
{
if (col_tool->colorize->lightness != adjustment->value)
gdouble value = adjustment->value / 100.0;
if (col_tool->config->lightness != value)
{
col_tool->colorize->lightness = adjustment->value;
g_object_set (col_tool->config,
"lightness", value,
NULL);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (col_tool));
}

View file

@ -36,14 +36,15 @@ typedef struct _GimpColorizeToolClass GimpColorizeToolClass;
struct _GimpColorizeTool
{
GimpImageMapTool parent_instance;
GimpImageMapTool parent_instance;
Colorize *colorize;
GimpColorizeConfig *config;
Colorize *colorize;
/* dialog */
GtkAdjustment *hue_data;
GtkAdjustment *saturation_data;
GtkAdjustment *lightness_data;
GtkAdjustment *hue_data;
GtkAdjustment *saturation_data;
GtkAdjustment *lightness_data;
};
struct _GimpColorizeToolClass