Some more gegl code to have some playground for experimenting.

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

	Some more gegl code to have some playground for experimenting.

	* app/gegl/Makefile.am
	* app/gegl/gegl-types.h
	* app/gegl/gimpoperationdesaturate.[ch]: ported desaturate.

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

	* app/gegl/gimpoperationtilesink.h: fix name of parent class member.

	* app/core/gimpdrawable-desaturate.c: use the new operator, but
	keep the old code around (prepared for runtime switching).

	* app/core/gimpdrawable-invert.c: prepare for runtime switching
	here too.


svn path=/trunk/; revision=24514
This commit is contained in:
Michael Natterer
2008-01-03 18:54:58 +00:00
committed by Michael Natterer
parent 7e25f48a32
commit 697cc82af7
9 changed files with 359 additions and 93 deletions

View File

@ -1,3 +1,21 @@
2008-01-03 Michael Natterer <mitch@gimp.org>
Some more gegl code to have some playground for experimenting.
* app/gegl/Makefile.am
* app/gegl/gegl-types.h
* app/gegl/gimpoperationdesaturate.[ch]: ported desaturate.
* app/gegl/gimp-gegl.c: register it.
* app/gegl/gimpoperationtilesink.h: fix name of parent class member.
* app/core/gimpdrawable-desaturate.c: use the new operator, but
keep the old code around (prepared for runtime switching).
* app/core/gimpdrawable-invert.c: prepare for runtime switching
here too.
2008-01-03 Michael Natterer <mitch@gimp.org>
* app/gegl/gegl/gegl-operation-sink.h

View File

@ -18,7 +18,7 @@
#include "config.h"
#include <glib-object.h>
#include <gegl.h>
#include "libgimpcolor/gimpcolor.h"
@ -29,11 +29,14 @@
#include "gimpdrawable.h"
#include "gimpdrawable-desaturate.h"
#include "gimpimage.h"
#include "gimpdrawable-operation.h"
#include "gimp-intl.h"
static gboolean enable_gegl = TRUE;
static void desaturate_region_lightness (gpointer data,
PixelRegion *srcPR,
PixelRegion *destPR);
@ -51,52 +54,72 @@ void
gimp_drawable_desaturate (GimpDrawable *drawable,
GimpDesaturateMode mode)
{
PixelRegion srcPR, destPR;
PixelProcessorFunc function;
gint x, y;
gint width, height;
gboolean has_alpha;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_drawable_is_rgb (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
return;
switch (mode)
if (enable_gegl)
{
case GIMP_DESATURATE_LIGHTNESS:
function = (PixelProcessorFunc) desaturate_region_lightness;
break;
GeglNode *desaturate;
break;
case GIMP_DESATURATE_LUMINOSITY:
function = (PixelProcessorFunc) desaturate_region_luminosity;
break;
desaturate = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp-desaturate",
NULL);
case GIMP_DESATURATE_AVERAGE:
function = (PixelProcessorFunc) desaturate_region_average;
break;
gegl_node_set (desaturate,
"mode", mode,
NULL);
default:
g_return_if_reached ();
return;
gimp_drawable_apply_operation (drawable, desaturate, TRUE,
NULL, _("Desaturate"));
g_object_unref (desaturate);
}
else
{
PixelRegion srcPR, destPR;
PixelProcessorFunc function;
gint x, y;
gint width, height;
gboolean has_alpha;
has_alpha = gimp_drawable_has_alpha (drawable);
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
return;
pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
x, y, width, height, FALSE);
pixel_region_init (&destPR, gimp_drawable_get_shadow_tiles (drawable),
x, y, width, height, TRUE);
switch (mode)
{
case GIMP_DESATURATE_LIGHTNESS:
function = (PixelProcessorFunc) desaturate_region_lightness;
break;
pixel_regions_process_parallel (function, GINT_TO_POINTER (has_alpha),
2, &srcPR, &destPR);
break;
case GIMP_DESATURATE_LUMINOSITY:
function = (PixelProcessorFunc) desaturate_region_luminosity;
break;
gimp_drawable_merge_shadow (drawable, TRUE, _("Desaturate"));
case GIMP_DESATURATE_AVERAGE:
function = (PixelProcessorFunc) desaturate_region_average;
break;
gimp_drawable_update (drawable, x, y, width, height);
default:
g_return_if_reached ();
return;
}
has_alpha = gimp_drawable_has_alpha (drawable);
pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
x, y, width, height, FALSE);
pixel_region_init (&destPR, gimp_drawable_get_shadow_tiles (drawable),
x, y, width, height, TRUE);
pixel_regions_process_parallel (function, GINT_TO_POINTER (has_alpha),
2, &srcPR, &destPR);
gimp_drawable_merge_shadow (drawable, TRUE, _("Desaturate"));
gimp_drawable_update (drawable, x, y, width, height);
}
}
static void

View File

@ -16,52 +16,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define ENABLE_GEGL
#ifdef ENABLE_GEGL
#include "config.h"
#include <gegl.h>
#include "core-types.h"
#include "gimpdrawable.h"
#include "gimpdrawable-invert.h"
#include "gimpdrawable-operation.h"
#include "gimpprogress.h"
#include "gimp-intl.h"
void
gimp_drawable_invert (GimpDrawable *drawable,
GimpProgress *progress)
{
GeglNode *invert;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
invert = g_object_new (GEGL_TYPE_NODE,
"operation", "invert",
NULL);
gimp_drawable_apply_operation (drawable, invert, TRUE,
progress, _("Invert"));
g_object_unref (invert);
}
#else /* ENABLE_GEGL is not defined */
#include "config.h"
#include <glib-object.h>
#include "core-types.h"
#include "base/gimplut.h"
#include "base/lut-funcs.h"
#include "base/pixel-processor.h"
@ -69,41 +29,59 @@ gimp_drawable_invert (GimpDrawable *drawable,
#include "gimpdrawable.h"
#include "gimpdrawable-invert.h"
#include "gimpdrawable-operation.h"
#include "gimpprogress.h"
#include "gimp-intl.h"
static gboolean enable_gegl = TRUE;
void
gimp_drawable_invert (GimpDrawable *drawable,
GimpProgress *progress)
{
PixelRegion srcPR, destPR;
gint x, y, width, height;
GimpLut *lut;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
return;
if (enable_gegl)
{
GeglNode *invert;
lut = invert_lut_new (gimp_drawable_bytes (drawable));
invert = g_object_new (GEGL_TYPE_NODE,
"operation", "invert",
NULL);
pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
x, y, width, height, FALSE);
pixel_region_init (&destPR, gimp_drawable_get_shadow_tiles (drawable),
x, y, width, height, TRUE);
gimp_drawable_apply_operation (drawable, invert, TRUE,
progress, _("Invert"));
pixel_regions_process_parallel ((PixelProcessorFunc) gimp_lut_process,
lut, 2, &srcPR, &destPR);
g_object_unref (invert);
}
else
{
PixelRegion srcPR, destPR;
gint x, y, width, height;
GimpLut *lut;
gimp_lut_free (lut);
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
return;
gimp_drawable_merge_shadow (drawable, TRUE, _("Invert"));
lut = invert_lut_new (gimp_drawable_bytes (drawable));
gimp_drawable_update (drawable, x, y, width, height);
pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
x, y, width, height, FALSE);
pixel_region_init (&destPR, gimp_drawable_get_shadow_tiles (drawable),
x, y, width, height, TRUE);
pixel_regions_process_parallel ((PixelProcessorFunc) gimp_lut_process,
lut, 2, &srcPR, &destPR);
gimp_lut_free (lut);
gimp_drawable_merge_shadow (drawable, TRUE, _("Invert"));
gimp_drawable_update (drawable, x, y, width, height);
}
}
#endif

View File

@ -7,6 +7,8 @@ libappgegl_a_SOURCES = \
gimp-gegl.h \
gimp-gegl-utils.c \
gimp-gegl-utils.h \
gimpoperationdesaturate.c \
gimpoperationdesaturate.h \
gimpoperationtilesink.c \
gimpoperationtilesink.h \
gimpoperationtilesource.c \

View File

@ -25,6 +25,7 @@
#include "base/base-types.h"
typedef struct _GimpOperationDesaturate GimpOperationDesaturate;
typedef struct _GimpOperationTileSink GimpOperationTileSink;
typedef struct _GimpOperationTileSource GimpOperationTileSource;

View File

@ -27,6 +27,7 @@
#include "gegl-types.h"
#include "gimp-gegl.h"
#include "gimpoperationdesaturate.h"
#include "gimpoperationtilesink.h"
#include "gimpoperationtilesource.h"
@ -34,6 +35,7 @@
void
gimp_gegl_init (void)
{
g_type_class_ref (GIMP_TYPE_OPERATION_DESATURATE);
g_type_class_ref (GIMP_TYPE_OPERATION_TILE_SINK);
g_type_class_ref (GIMP_TYPE_OPERATION_TILE_SOURCE);
}

View File

@ -0,0 +1,189 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationdesaturate.c
* Copyright (C) 2007 Øyvind Kolås <pippin@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 "gimpoperationdesaturate.h"
enum
{
PROP_0,
PROP_MODE
};
static void gimp_operation_desaturate_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_operation_desaturate_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_operation_desaturate_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples);
G_DEFINE_TYPE (GimpOperationDesaturate, gimp_operation_desaturate,
GEGL_TYPE_OPERATION_POINT_FILTER)
#define parent_class gimp_operation_desaturate_parent_class
static void
gimp_operation_desaturate_class_init (GimpOperationDesaturateClass * 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_desaturate_set_property;
object_class->get_property = gimp_operation_desaturate_get_property;
point_class->process = gimp_operation_desaturate_process;
gegl_operation_class_set_name (operation_class, "gimp-desaturate");
g_object_class_install_property (object_class,
PROP_MODE,
g_param_spec_enum ("mode",
"Mode",
"The desaturate mode",
GIMP_TYPE_DESATURATE_MODE,
GIMP_DESATURATE_LIGHTNESS,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
gimp_operation_desaturate_init (GimpOperationDesaturate *self)
{
}
static void
gimp_operation_desaturate_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpOperationDesaturate *self = GIMP_OPERATION_DESATURATE (object);
switch (property_id)
{
case PROP_MODE:
g_value_set_enum (value, self->mode);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_operation_desaturate_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpOperationDesaturate *self = GIMP_OPERATION_DESATURATE (object);
switch (property_id)
{
case PROP_MODE:
self->mode = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gboolean
gimp_operation_desaturate_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples)
{
GimpOperationDesaturate *self = GIMP_OPERATION_DESATURATE (operation);
gfloat *src = in_buf;
gfloat *dest = out_buf;
glong sample;
for (sample = 0; sample < samples; sample++)
{
gfloat value = 0.0;
switch (self->mode)
{
case GIMP_DESATURATE_LIGHTNESS:
{
gfloat min, max;
#ifdef __GNUC__
#warning FIXME: cant use FOO_PIX but have no constants from babl???
#endif
max = MAX (src[RED_PIX], src[GREEN_PIX]);
max = MAX (max, src[BLUE_PIX]);
min = MIN (src[RED_PIX], src[GREEN_PIX]);
min = MIN (min, src[BLUE_PIX]);
value = (max + min) / 2;
}
break;
case GIMP_DESATURATE_LUMINOSITY:
value = GIMP_RGB_LUMINANCE (src[RED_PIX],
src[GREEN_PIX],
src[BLUE_PIX]);
break;
case GIMP_DESATURATE_AVERAGE:
value = (src[RED_PIX] + src[GREEN_PIX] + src[BLUE_PIX]) / 3;
break;
}
dest[RED_PIX] = value;
dest[GREEN_PIX] = value;
dest[BLUE_PIX] = value;
dest[ALPHA_PIX] = src[ALPHA_PIX];
src += 4;
dest += 4;
}
return TRUE;
}

View File

@ -0,0 +1,53 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationdesaturate.h
* Copyright (C) 2007 Øyvind Kolås <pippin@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_DESATURATE_H__
#define __GIMP_OPERATION_DESATURATE_H__
#include "gegl/gegl-operation-point-filter.h"
#define GIMP_TYPE_OPERATION_DESATURATE (gimp_operation_desaturate_get_type ())
#define GIMP_OPERATION_DESATURATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_DESATURATE, GimpOperationDesaturate))
#define GIMP_OPERATION_DESATURATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_DESATURATE, GimpOperationDesaturateClass))
#define GIMP_OPERATION_DESATURATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_DESATURATE, GimpOperationDesaturateClass))
typedef struct _GimpOperationDesaturateClass GimpOperationDesaturateClass;
struct _GimpOperationDesaturate
{
GeglOperationPointFilter parent_instance;
GimpDesaturateMode mode;
};
struct _GimpOperationDesaturateClass
{
GeglOperationPointFilterClass parent_class;
};
GType gimp_operation_desaturate_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_OPERATION_DESATURATE_H__ */

View File

@ -44,7 +44,7 @@ struct _GimpOperationTileSink
struct _GimpOperationTileSinkClass
{
GeglOperationSinkClass operation_sink_class;
GeglOperationSinkClass parent_class;
void (* data_written) (GimpOperationTileSink *sink,
const GeglRectangle *extent);