Commit 89900621 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/gegl/Makefile.am app/gegl/gegl-types.h app/gegl/gimpcurvesconfig.[ch]

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

	* app/gegl/Makefile.am
	* app/gegl/gegl-types.h
	* app/gegl/gimpcurvesconfig.[ch]
	* app/gegl/gimpoperationcurves.[ch]: add curves operation and its
	config object. Hack around badly to be able to use GimpCurve from
	app/core.

	* app/gegl/gimp-gegl.c: register the curves operation.

	* app/tools/gimpcurvestool.[ch]: added get_operation() implemenetation
	and use the new config object instead of keeping around 5 curves.


svn path=/trunk/; revision=24683
parent 5d07620d
2008-01-23 Michael Natterer <mitch@gimp.org>
* app/gegl/Makefile.am
* app/gegl/gegl-types.h
* app/gegl/gimpcurvesconfig.[ch]
* app/gegl/gimpoperationcurves.[ch]: add curves operation and its
config object. Hack around badly to be able to use GimpCurve from
app/core.
* app/gegl/gimp-gegl.c: register the curves operation.
* app/tools/gimpcurvestool.[ch]: added get_operation() implemenetation
and use the new config object instead of keeping around 5 curves.
2008-01-23 Michael Natterer <mitch@gimp.org>
* app/gegl/gimpoperationlevels.[ch]
......
......@@ -10,6 +10,8 @@ libappgegl_a_SOURCES = \
\
gimpcolorizeconfig.c \
gimpcolorizeconfig.h \
gimpcurvesconfig.c \
gimpcurvesconfig.h \
gimphuesaturationconfig.c \
gimphuesaturationconfig.h \
gimplevelsconfig.c \
......@@ -19,6 +21,8 @@ libappgegl_a_SOURCES = \
gimpoperationcolorbalance.h \
gimpoperationcolorize.c \
gimpoperationcolorize.h \
gimpoperationcurves.c \
gimpoperationcurves.h \
gimpoperationdesaturate.c \
gimpoperationdesaturate.h \
gimpoperationhuesaturation.c \
......@@ -41,4 +45,5 @@ INCLUDES = \
-I$(top_builddir)/app \
-I$(top_srcdir)/app \
$(GEGL_CFLAGS) \
$(GDK_PIXBUF_CFLAGS) \
-I$(includedir)
......@@ -30,6 +30,7 @@
typedef struct _GimpOperationColorBalance GimpOperationColorBalance;
typedef struct _GimpOperationColorize GimpOperationColorize;
typedef struct _GimpOperationCurves GimpOperationCurves;
typedef struct _GimpOperationDesaturate GimpOperationDesaturate;
typedef struct _GimpOperationHueSaturation GimpOperationHueSaturation;
typedef struct _GimpOperationLevels GimpOperationLevels;
......@@ -42,6 +43,7 @@ typedef struct _GimpOperationTileSource GimpOperationTileSource;
/* operation config objects */
typedef struct _GimpColorizeConfig GimpColorizeConfig;
typedef struct _GimpCurvesConfig GimpCurvesConfig;
typedef struct _GimpHueSaturationConfig GimpHueSaturationConfig;
typedef struct _GimpLevelsConfig GimpLevelsConfig;
......
......@@ -28,6 +28,7 @@
#include "gimp-gegl.h"
#include "gimpoperationcolorbalance.h"
#include "gimpoperationcolorize.h"
#include "gimpoperationcurves.h"
#include "gimpoperationdesaturate.h"
#include "gimpoperationhuesaturation.h"
#include "gimpoperationlevels.h"
......@@ -42,6 +43,7 @@ gimp_gegl_init (void)
{
g_type_class_ref (GIMP_TYPE_OPERATION_COLOR_BALANCE);
g_type_class_ref (GIMP_TYPE_OPERATION_COLORIZE);
g_type_class_ref (GIMP_TYPE_OPERATION_CURVES);
g_type_class_ref (GIMP_TYPE_OPERATION_DESATURATE);
g_type_class_ref (GIMP_TYPE_OPERATION_HUE_SATURATION);
g_type_class_ref (GIMP_TYPE_OPERATION_LEVELS);
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcurvesconfig.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 "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "gegl-types.h"
#include "base/gimphistogram.h"
/* temp cruft */
#include "base/curves.h"
#include "gimpcurvesconfig.h"
enum
{
PROP_0,
PROP_CHANNEL,
PROP_CURVE
};
static void gimp_curves_config_finalize (GObject *object);
static void gimp_curves_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_curves_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (GimpCurvesConfig, gimp_curves_config, G_TYPE_OBJECT)
#define parent_class gimp_curves_config_parent_class
static void
gimp_curves_config_class_init (GimpCurvesConfigClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gimp_curves_config_finalize;
object_class->set_property = gimp_curves_config_set_property;
object_class->get_property = gimp_curves_config_get_property;
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_CURVE,
g_param_spec_object ("curve",
"Curve",
"Curve",
GIMP_TYPE_CURVE,
G_PARAM_READWRITE));
}
static void
gimp_curves_config_init (GimpCurvesConfig *self)
{
GimpHistogramChannel channel;
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
self->curve[channel] = GIMP_CURVE (gimp_curve_new ("curves config"));
}
gimp_curves_config_reset (self);
}
static void
gimp_curves_config_finalize (GObject *object)
{
GimpCurvesConfig *self = GIMP_CURVES_CONFIG (object);
GimpHistogramChannel channel;
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
if (self->curve[channel])
{
g_object_unref (self->curve[channel]);
self->curve[channel] = NULL;
}
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_curves_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpCurvesConfig *self = GIMP_CURVES_CONFIG (object);
switch (property_id)
{
case PROP_CHANNEL:
g_value_set_enum (value, self->channel);
break;
case PROP_CURVE:
g_value_set_object (value, self->curve[self->channel]);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_curves_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpCurvesConfig *self = GIMP_CURVES_CONFIG (object);
switch (property_id)
{
case PROP_CHANNEL:
self->channel = g_value_get_enum (value);
break;
case PROP_CURVE:
if (self->curve[self->channel])
g_object_unref (self->curve[self->channel]);
self->curve[self->channel] = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/* public functions */
void
gimp_curves_config_reset (GimpCurvesConfig *config)
{
GimpHistogramChannel channel;
g_return_if_fail (GIMP_IS_CURVES_CONFIG (config));
config->channel = GIMP_HISTOGRAM_VALUE;
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
gimp_curve_reset (config->curve[channel], FALSE);
}
}
void
gimp_curves_config_reset_channel (GimpCurvesConfig *config,
GimpHistogramChannel channel)
{
g_return_if_fail (GIMP_IS_CURVES_CONFIG (config));
gimp_curve_reset (config->curve[channel], FALSE);
}
/* temp cruft */
void
gimp_curves_config_to_cruft (GimpCurvesConfig *config,
Curves *cruft,
gboolean is_color)
{
GimpHistogramChannel channel;
g_return_if_fail (GIMP_IS_CURVES_CONFIG (config));
g_return_if_fail (cruft != NULL);
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
gimp_curve_get_uchar (config->curve[channel], cruft->curve[channel]);
}
if (! is_color)
{
gimp_curve_get_uchar (config->curve[GIMP_HISTOGRAM_ALPHA], cruft->curve[1]);
}
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcurvesconfig.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_CURVES_CONFIG_H__
#define __GIMP_CURVES_CONFIG_H__
#include <gdk-pixbuf/gdk-pixbuf.h> /* eek */
#include "core/core-types.h" /* eek */
#include "core/gimpcurve.h" /* eek */
#define GIMP_TYPE_CURVES_CONFIG (gimp_curves_config_get_type ())
#define GIMP_CURVES_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CURVES_CONFIG, GimpCurvesConfig))
#define GIMP_CURVES_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CURVES_CONFIG, GimpCurvesConfigClass))
#define GIMP_IS_CURVES_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CURVES_CONFIG))
#define GIMP_IS_CURVES_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CURVES_CONFIG))
#define GIMP_CURVES_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CURVES_CONFIG, GimpCurvesConfigClass))
typedef struct _GimpCurvesConfigClass GimpCurvesConfigClass;
struct _GimpCurvesConfig
{
GObject parent_instance;
GimpHistogramChannel channel;
GimpCurve *curve[5];
};
struct _GimpCurvesConfigClass
{
GObjectClass parent_class;
};
GType gimp_curves_config_get_type (void) G_GNUC_CONST;
void gimp_curves_config_reset (GimpCurvesConfig *config);
void gimp_curves_config_reset_channel (GimpCurvesConfig *config,
GimpHistogramChannel channel);
/* temp cruft */
void gimp_curves_config_to_cruft (GimpCurvesConfig *config,
Curves *cruft,
gboolean is_color);
#endif /* __GIMP_CURVES_CONFIG_H__ */
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationcurves.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 "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "gegl-types.h"
#include "gimpcurvesconfig.h"
#include "gimpoperationcurves.h"
enum
{
PROP_0,
PROP_CONFIG
};
static void gimp_operation_curves_finalize (GObject *object);
static void gimp_operation_curves_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_operation_curves_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_operation_curves_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples);
G_DEFINE_TYPE (GimpOperationCurves, gimp_operation_curves,
GEGL_TYPE_OPERATION_POINT_FILTER)
#define parent_class gimp_operation_curves_parent_class
static void
gimp_operation_curves_class_init (GimpOperationCurvesClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
GeglOperationPointFilterClass *point_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
object_class->finalize = gimp_operation_curves_finalize;
object_class->set_property = gimp_operation_curves_set_property;
object_class->get_property = gimp_operation_curves_get_property;
point_class->process = gimp_operation_curves_process;
gegl_operation_class_set_name (operation_class, "gimp-curves");
g_object_class_install_property (object_class, PROP_CONFIG,
g_param_spec_object ("config",
"Config",
"The config object",
GIMP_TYPE_CURVES_CONFIG,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
gimp_operation_curves_init (GimpOperationCurves *self)
{
}
static void
gimp_operation_curves_finalize (GObject *object)
{
GimpOperationCurves *self = GIMP_OPERATION_CURVES (object);
if (self->config)
{
g_object_unref (self->config);
self->config = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_operation_curves_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpOperationCurves *self = GIMP_OPERATION_CURVES (object);
switch (property_id)
{
case PROP_CONFIG:
g_value_set_object (value, self->config);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_operation_curves_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpOperationCurves *self = GIMP_OPERATION_CURVES (object);
switch (property_id)
{
case PROP_CONFIG:
if (self->config)
g_object_unref (self->config);
self->config = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static inline gdouble
gimp_operation_curves_map (gdouble value,
GimpCurve *curve)
{
if (value < 0.0)
{
value = curve->curve[0] / 255.0;
}
else if (value >= 1.0)
{
value = curve->curve[255] / 255.0;
}
else /* interpolate the curve */
{
gint index = floor (value * 255.0);
gdouble f = value * 255.0 - index;
value = ((1.0 - f) * curve->curve[index ] +
f * curve->curve[index + 1] ) / 255.0;
}
return value;
}
static gboolean
gimp_operation_curves_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples)
{
GimpOperationCurves *self = GIMP_OPERATION_CURVES (operation);
GimpCurvesConfig *config = self->config;
gfloat *src = in_buf;
gfloat *dest = out_buf;
glong sample;
if (! config)
return FALSE;
for (sample = 0; sample < samples; sample++)
{
gint channel;
for (channel = 0; channel < 4; channel++)
{
gdouble value;
value = gimp_operation_curves_map (src[channel],
config->curve[channel + 1]);
/* don't apply the overall curve to the alpha channel */
if (channel != ALPHA_PIX)
value = gimp_operation_curves_map (value,
config->curve[0]);
dest[channel] = value;
}
src += 4;
dest += 4;
}
return TRUE;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationcurves.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_OPERATION_CURVES_H__
#define __GIMP_OPERATION_CURVES_H__
#include <gegl-plugin.h>
#include <operation/gegl-operation-point-filter.h>
#define GIMP_TYPE_OPERATION_CURVES (gimp_operation_curves_get_type ())
#define GIMP_OPERATION_CURVES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_CURVES, GimpOperationCurves))
#define GIMP_OPERATION_CURVES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_CURVES, GimpOperationCurvesClass))
#define GIMP_IS_OPERATION_CURVES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OPERATION_CURVES))
#define GIMP_IS_OPERATION_CURVES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_OPERATION_CURVES))
#define GIMP_OPERATION_CURVES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_CURVES, GimpOperationCurvesClass))
typedef struct _GimpOperationCurvesClass GimpOperationCurvesClass;
struct _GimpOperationCurves
{
GeglOperationPointFilter parent_instance;
GimpCurvesConfig *config;
};
struct _GimpOperationCurvesClass
{
GeglOperationPointFilterClass parent_class;
};
GType gimp_operation_curves_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_OPERATION_CURVES_H__ */
......@@ -36,6 +36,9 @@
#include "base/gimphistogram.h"
#include "base/gimplut.h"
#include "gegl/gimpcurvesconfig.h"
#include "gegl/gimpoperationcurves.h"
#include "core/gimp.h"
#include "core/gimpcurve.h"
#include "core/gimpdrawable.h"
......@@ -62,52 +65,53 @@
/* local function prototypes */
static void gimp_curves_tool_finalize (GObject *object);
static gboolean gimp_curves_tool_initialize (GimpTool *tool,