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

app/gegl/Makefile.am app/gegl/gegl-types.h

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

	* app/gegl/Makefile.am
	* app/gegl/gegl-types.h
	* app/gegl/gimpoperationcolorize.[ch]
	* app/gegl/gimpoperationposterize.[ch]: new operators which still
	use a lot of gimp stuff they shouldn't use, but at least the
	infrastructure for improving them is there now.

	* app/gegl/gimp-gegl.c: register them.

	* app/tools/gimpcolorizetool.c
	* app/tools/gimpposterizetool.c: use them.


svn path=/trunk/; revision=24528
parent 2634bcac
2008-01-04 Michael Natterer <mitch@gimp.org>
* app/gegl/Makefile.am
* app/gegl/gegl-types.h
* app/gegl/gimpoperationcolorize.[ch]
* app/gegl/gimpoperationposterize.[ch]: new operators which still
use a lot of gimp stuff they shouldn't use, but at least the
infrastructure for improving them is there now.
* app/gegl/gimp-gegl.c: register them.
* app/tools/gimpcolorizetool.c
* app/tools/gimpposterizetool.c: use them.
2008-01-04 Michael Natterer <mitch@gimp.org>
* app/core/gimpimagemap.c (gimp_image_map_apply): switch tile
......
......@@ -7,8 +7,12 @@ libappgegl_a_SOURCES = \
gimp-gegl.h \
gimp-gegl-utils.c \
gimp-gegl-utils.h \
gimpoperationcolorize.c \
gimpoperationcolorize.h \
gimpoperationdesaturate.c \
gimpoperationdesaturate.h \
gimpoperationposterize.c \
gimpoperationposterize.h \
gimpoperationthreshold.c \
gimpoperationthreshold.h \
gimpoperationtilesink.c \
......
......@@ -25,7 +25,9 @@
#include "base/base-types.h"
typedef struct _GimpOperationColorize GimpOperationColorize;
typedef struct _GimpOperationDesaturate GimpOperationDesaturate;
typedef struct _GimpOperationPosterize GimpOperationPosterize;
typedef struct _GimpOperationThreshold GimpOperationThreshold;
typedef struct _GimpOperationTileSink GimpOperationTileSink;
typedef struct _GimpOperationTileSource GimpOperationTileSource;
......
......@@ -27,7 +27,9 @@
#include "gegl-types.h"
#include "gimp-gegl.h"
#include "gimpoperationcolorize.h"
#include "gimpoperationdesaturate.h"
#include "gimpoperationposterize.h"
#include "gimpoperationthreshold.h"
#include "gimpoperationtilesink.h"
#include "gimpoperationtilesource.h"
......@@ -36,7 +38,9 @@
void
gimp_gegl_init (void)
{
g_type_class_ref (GIMP_TYPE_OPERATION_COLORIZE);
g_type_class_ref (GIMP_TYPE_OPERATION_DESATURATE);
g_type_class_ref (GIMP_TYPE_OPERATION_POSTERIZE);
g_type_class_ref (GIMP_TYPE_OPERATION_THRESHOLD);
g_type_class_ref (GIMP_TYPE_OPERATION_TILE_SINK);
g_type_class_ref (GIMP_TYPE_OPERATION_TILE_SOURCE);
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationcolorize.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 <glib-object.h>
#include "libgimpcolor/gimpcolor.h"
#include "gegl/gegl-types.h"
#include <gegl/buffer/gegl-buffer.h>
#include "gegl-types.h"
#include "gimpoperationcolorize.h"
enum
{
PROP_0,
PROP_HUE,
PROP_SATURATION,
PROP_LIGHTNESS
};
static void gimp_operation_colorize_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_operation_colorize_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_operation_colorize_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples);
G_DEFINE_TYPE (GimpOperationColorize, gimp_operation_colorize,
GEGL_TYPE_OPERATION_POINT_FILTER)
#define parent_class gimp_operation_colorize_parent_class
static void
gimp_operation_colorize_class_init (GimpOperationColorizeClass * 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->set_property = gimp_operation_colorize_set_property;
object_class->get_property = gimp_operation_colorize_get_property;
point_class->process = gimp_operation_colorize_process;
gegl_operation_class_set_name (operation_class, "gimp-colorize");
g_object_class_install_property (object_class,
PROP_HUE,
g_param_spec_float ("hue",
"Hue",
"Hue",
0.0, 360.0, 180.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_SATURATION,
g_param_spec_float ("saturation",
"Saturation",
"Saturation",
0.0, 100.0, 50.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_LIGHTNESS,
g_param_spec_float ("lightness",
"Lightness",
"Lightness",
-100.0, 100.0, 0.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
gimp_operation_colorize_init (GimpOperationColorize *self)
{
}
static void
gimp_operation_colorize_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpOperationColorize *self = GIMP_OPERATION_COLORIZE (object);
switch (property_id)
{
case PROP_HUE:
g_value_set_float (value, self->hue);
break;
case PROP_SATURATION:
g_value_set_float (value, self->saturation);
break;
case PROP_LIGHTNESS:
g_value_set_float (value, self->lightness);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_operation_colorize_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpOperationColorize *self = GIMP_OPERATION_COLORIZE (object);
switch (property_id)
{
case PROP_HUE:
self->hue = g_value_get_float (value);
break;
case PROP_SATURATION:
self->saturation = g_value_get_float (value);
break;
case PROP_LIGHTNESS:
self->lightness = g_value_get_float (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gboolean
gimp_operation_colorize_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples)
{
GimpOperationColorize *self = GIMP_OPERATION_COLORIZE (operation);
gfloat *src = in_buf;
gfloat *dest = out_buf;
glong sample;
for (sample = 0; sample < samples; sample++)
{
GimpHSL hsl;
GimpRGB rgb;
gfloat lum = GIMP_RGB_LUMINANCE (src[RED_PIX],
src[GREEN_PIX],
src[BLUE_PIX]);
if (self->lightness > 0)
{
lum = lum * (100.0 - self->lightness) / 100.0;
lum += 1.0 - (100.0 - self->lightness) / 100.0;
}
else if (self->lightness < 0)
{
lum = lum * (self->lightness + 100.0) / 100.0;
}
hsl.h = self->hue / 360.0;
hsl.s = self->saturation / 100.0;
hsl.l = lum;
gimp_hsl_to_rgb (&hsl, &rgb);
dest[RED_PIX] = rgb.r;
dest[GREEN_PIX] = rgb.g;
dest[BLUE_PIX] = rgb.b;
dest[ALPHA_PIX] = src[ALPHA_PIX];
src += 4;
dest += 4;
}
return TRUE;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationcolorize.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_COLORIZE_H__
#define __GIMP_OPERATION_COLORIZE_H__
#include "gegl/gegl-operation-point-filter.h"
#define GIMP_TYPE_OPERATION_COLORIZE (gimp_operation_colorize_get_type ())
#define GIMP_OPERATION_COLORIZE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_COLORIZE, GimpOperationColorize))
#define GIMP_OPERATION_COLORIZE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_COLORIZE, GimpOperationColorizeClass))
#define GIMP_OPERATION_COLORIZE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_COLORIZE, GimpOperationColorizeClass))
typedef struct _GimpOperationColorizeClass GimpOperationColorizeClass;
struct _GimpOperationColorize
{
GeglOperationPointFilter parent_instance;
gfloat hue;
gfloat saturation;
gfloat lightness;
};
struct _GimpOperationColorizeClass
{
GeglOperationPointFilterClass parent_class;
};
GType gimp_operation_colorize_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_OPERATION_COLORIZE_H__ */
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationposterize.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 <glib-object.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "gegl/gegl-types.h"
#include <gegl/buffer/gegl-buffer.h>
#include "gegl-types.h"
#include "gimpoperationposterize.h"
enum
{
PROP_0,
PROP_LEVELS
};
static void gimp_operation_posterize_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_operation_posterize_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_operation_posterize_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples);
G_DEFINE_TYPE (GimpOperationPosterize, gimp_operation_posterize,
GEGL_TYPE_OPERATION_POINT_FILTER)
#define parent_class gimp_operation_posterize_parent_class
static void
gimp_operation_posterize_class_init (GimpOperationPosterizeClass * 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->set_property = gimp_operation_posterize_set_property;
object_class->get_property = gimp_operation_posterize_get_property;
point_class->process = gimp_operation_posterize_process;
gegl_operation_class_set_name (operation_class, "gimp-posterize");
g_object_class_install_property (object_class,
PROP_LEVELS,
g_param_spec_int ("levels",
"Levels",
"Posterize levels",
2, 256, 10,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
gimp_operation_posterize_init (GimpOperationPosterize *self)
{
}
static void
gimp_operation_posterize_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpOperationPosterize *self = GIMP_OPERATION_POSTERIZE (object);
switch (property_id)
{
case PROP_LEVELS:
g_value_set_int (value, self->levels);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_operation_posterize_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpOperationPosterize *self = GIMP_OPERATION_POSTERIZE (object);
switch (property_id)
{
case PROP_LEVELS:
self->levels = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gboolean
gimp_operation_posterize_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples)
{
GimpOperationPosterize *self = GIMP_OPERATION_POSTERIZE (operation);
gfloat *src = in_buf;
gfloat *dest = out_buf;
gfloat levels = self->levels - 1.0;
glong sample;
for (sample = 0; sample < samples; sample++)
{
dest[RED_PIX] = RINT (src[RED_PIX] * levels) / levels;
dest[GREEN_PIX] = RINT (src[GREEN_PIX] * levels) / levels;
dest[BLUE_PIX] = RINT (src[BLUE_PIX] * levels) / levels;
dest[ALPHA_PIX] = src[ALPHA_PIX];
src += 4;
dest += 4;
}
return TRUE;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationposterize.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_POSTERIZE_H__
#define __GIMP_OPERATION_POSTERIZE_H__
#include "gegl/gegl-operation-point-filter.h"
#define GIMP_TYPE_OPERATION_POSTERIZE (gimp_operation_posterize_get_type ())
#define GIMP_OPERATION_POSTERIZE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_POSTERIZE, GimpOperationPosterize))
#define GIMP_OPERATION_POSTERIZE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_POSTERIZE, GimpOperationPosterizeClass))
#define GIMP_OPERATION_POSTERIZE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_POSTERIZE, GimpOperationPosterizeClass))
typedef struct _GimpOperationPosterizeClass GimpOperationPosterizeClass;
struct _GimpOperationPosterize
{
GeglOperationPointFilter parent_instance;
gint levels;
};
struct _GimpOperationPosterizeClass
{
GeglOperationPointFilterClass parent_class;
};
GType gimp_operation_posterize_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_OPERATION_POSTERIZE_H__ */
......@@ -42,29 +42,28 @@
#define SLIDER_WIDTH 200
#define DA_WIDTH 40
#define DA_HEIGHT 20
/* local function prototypes */
static void gimp_colorize_tool_finalize (GObject *object);
static void gimp_colorize_tool_finalize (GObject *object);
static gboolean gimp_colorize_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static gboolean gimp_colorize_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static void gimp_colorize_tool_map (GimpImageMapTool *im_tool);
static void gimp_colorize_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_colorize_tool_reset (GimpImageMapTool *im_tool);
static GeglNode * gimp_colorize_tool_get_operation (GimpImageMapTool *im_tool);
static void gimp_colorize_tool_map (GimpImageMapTool *im_tool);
static void gimp_colorize_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_colorize_tool_reset (GimpImageMapTool *im_tool);
static void colorize_update_sliders (GimpColorizeTool *col_tool);
static void colorize_hue_changed (GtkAdjustment *adj,
GimpColorizeTool *col_tool);
static void colorize_saturation_changed (GtkAdjustment *adj,
GimpColorizeTool *col_tool);
static void colorize_lightness_changed (GtkAdjustment *adj,
GimpColorizeTool *col_tool);
static void colorize_update_sliders (GimpColorizeTool *col_tool);
static void colorize_hue_changed (GtkAdjustment *adj,
GimpColorizeTool *col_tool);
static void colorize_saturation_changed (GtkAdjustment *adj,
GimpColorizeTool *col_tool);
static void colorize_lightness_changed (GtkAdjustment *adj,
GimpColorizeTool *col_tool);
G_DEFINE_TYPE (GimpColorizeTool, gimp_colorize_tool, GIMP_TYPE_IMAGE_MAP_TOOL)
......@@ -95,15 +94,16 @@ gimp_colorize_tool_class_init (GimpColorizeToolClass *klass)
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
object_class->finalize = gimp_colorize_tool_finalize;
object_class->finalize = gimp_colorize_tool_finalize;
tool_class->initialize = gimp_colorize_tool_initialize;
tool_class->initialize = gimp_colorize_tool_initialize;
im_tool_class->shell_desc = _("Colorize the Image");
im_tool_class->shell_desc = _("Colorize the Image");
im_tool_class->map = gimp_colorize_tool_map;
im_tool_class->dialog = gimp_colorize_tool_dialog;
im_tool_class->reset = gimp_colorize_tool_reset;
im_tool_class->get_operation = gimp_colorize_tool_get_operation;
im_tool_class->map = gimp_colorize_tool_map;
im_tool_class->dialog = gimp_colorize_tool_dialog;
im_tool_class->reset = gimp_colorize_tool_reset;
}
static void
......@@ -143,7 +143,6 @@ gimp_colorize_tool_initialize (GimpTool *tool,
}
colorize_init (col_tool->colorize);
colorize_calculate (col_tool->colorize);
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
......@@ -154,11 +153,30 @@ gimp_colorize_tool_initialize (GimpTool *tool,
return TRUE;
}
static GeglNode *
gimp_colorize_tool_get_operation (GimpImageMapTool *im_tool)
{
return g_object_new (GEGL_TYPE_NODE,
"operation", "gimp-colorize",
NULL);
}
static void
gimp_colorize_tool_map (GimpImageMapTool *image_map_tool)
{
GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (image_map_tool);
if (image_map_tool->operation)
{
gegl_node_set (image_map_tool->operation,
"hue", col_tool->colorize->hue,
"saturation", col_tool->colorize->saturation,
"lightness", col_tool->colorize->lightness,
NULL);
}
colorize_calculate (col_tool->colorize);
gimp_image_map_apply (image_map_tool->image_map,
(GimpImageMapApplyFunc) colorize,
col_tool->colorize);
......@@ -244,7 +262,6 @@ gimp_colorize_tool_reset (GimpImageMapTool *image_map_tool)
GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (image_map_tool);
colorize_init (col_tool->colorize);
colorize_calculate (col_tool->colorize);
colorize_update_sliders (col_tool);
}
......@@ -267,7 +284,6 @@ colorize_hue_changed (GtkAdjustment *adjustment,
if (col_tool->colorize->hue != adjustment->value)
{
col_tool->colorize->hue = adjustment->value;
colorize_calculate (col_tool->colorize);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (col_tool));
}
......@@ -280,7 +296,6 @@ colorize_saturation_changed (GtkAdjustment *adjustment,
if (col_tool->colorize->saturation != adjustment->value)
{
col_tool->colorize->saturation = adjustment->value;
colorize_calculate (col_tool->colorize);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (col_tool));
}
......@@ -293,7 +308,6 @@ colorize_lightness_changed (GtkAdjustment *adjustment,
if (col_tool->colorize->lightness != adjustment->value)
{
col_tool->colorize->lightness = adjustment->value;
colorize_calculate (col_tool->colorize);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (col_tool));
}
......
......@@ -47,18 +47,19 @@
#define SLIDER_WIDTH 200
static void gimp_posterize_tool_finalize (GObject *object);
static void gimp_posterize_tool_finalize (GObject *object);
static gboolean gimp_posterize_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);