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

app/gegl/Makefile.am app/gegl/gegl-types.h gimpish threshold operator

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

	* app/gegl/Makefile.am
	* app/gegl/gegl-types.h
	* app/gegl/gimpoperationthreshold.[ch]: gimpish threshold operator
	which has "low" and "high" properties.

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

	* app/gegl/gimpoperationdesaturate.[ch]: fix copyright.

	* app/tools/gimpthresholdtool.[ch]: use the new operator.


svn path=/trunk/; revision=24515
parent 697cc82a
2008-01-03 Michael Natterer <mitch@gimp.org>
* app/gegl/Makefile.am
* app/gegl/gegl-types.h
* app/gegl/gimpoperationthreshold.[ch]: gimpish threshold operator
which has "low" and "high" properties.
* app/gegl/gimp-gegl.c: register it.
* app/gegl/gimpoperationdesaturate.[ch]: fix copyright.
* app/tools/gimpthresholdtool.[ch]: use the new operator.
2008-01-03 Michael Natterer <mitch@gimp.org>
Some more gegl code to have some playground for experimenting.
......
......@@ -9,6 +9,8 @@ libappgegl_a_SOURCES = \
gimp-gegl-utils.h \
gimpoperationdesaturate.c \
gimpoperationdesaturate.h \
gimpoperationthreshold.c \
gimpoperationthreshold.h \
gimpoperationtilesink.c \
gimpoperationtilesink.h \
gimpoperationtilesource.c \
......
......@@ -26,6 +26,7 @@
typedef struct _GimpOperationDesaturate GimpOperationDesaturate;
typedef struct _GimpOperationThreshold GimpOperationThreshold;
typedef struct _GimpOperationTileSink GimpOperationTileSink;
typedef struct _GimpOperationTileSource GimpOperationTileSource;
......
......@@ -28,6 +28,7 @@
#include "gimp-gegl.h"
#include "gimpoperationdesaturate.h"
#include "gimpoperationthreshold.h"
#include "gimpoperationtilesink.h"
#include "gimpoperationtilesource.h"
......@@ -36,6 +37,7 @@ void
gimp_gegl_init (void)
{
g_type_class_ref (GIMP_TYPE_OPERATION_DESATURATE);
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);
}
......@@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationdesaturate.c
* Copyright (C) 2007 Øyvind Kolås <pippin@gimp.org>
* 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
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationdesaturate.h
* Copyright (C) 2007 Øyvind Kolås <pippin@gimp.org>
* 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
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationthreshold.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 "gimpoperationthreshold.h"
enum
{
PROP_0,
PROP_LOW,
PROP_HIGH
};
static void gimp_operation_threshold_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_operation_threshold_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_operation_threshold_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples);
G_DEFINE_TYPE (GimpOperationThreshold, gimp_operation_threshold,
GEGL_TYPE_OPERATION_POINT_FILTER)
#define parent_class gimp_operation_threshold_parent_class
static void
gimp_operation_threshold_class_init (GimpOperationThresholdClass * 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_threshold_set_property;
object_class->get_property = gimp_operation_threshold_get_property;
point_class->process = gimp_operation_threshold_process;
gegl_operation_class_set_name (operation_class, "gimp-threshold");
g_object_class_install_property (object_class,
PROP_LOW,
g_param_spec_float ("low",
"Low",
"Low threshold",
0.0, 1.0, 0.5,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_HIGH,
g_param_spec_float ("high",
"High",
"High threshold",
0.0, 1.0, 1.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
gimp_operation_threshold_init (GimpOperationThreshold *self)
{
}
static void
gimp_operation_threshold_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpOperationThreshold *self = GIMP_OPERATION_THRESHOLD (object);
switch (property_id)
{
case PROP_LOW:
g_value_set_float (value, self->low);
break;
case PROP_HIGH:
g_value_set_float (value, self->high);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_operation_threshold_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpOperationThreshold *self = GIMP_OPERATION_THRESHOLD (object);
switch (property_id)
{
case PROP_LOW:
self->low = g_value_get_float (value);
break;
case PROP_HIGH:
self->high = g_value_get_float (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gboolean
gimp_operation_threshold_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples)
{
GimpOperationThreshold *self = GIMP_OPERATION_THRESHOLD (operation);
gfloat *src = in_buf;
gfloat *dest = out_buf;
glong sample;
for (sample = 0; sample < samples; sample++)
{
gfloat value;
value = MAX (src[RED_PIX], src[GREEN_PIX]);
value = MAX (value, src[BLUE_PIX]);
value = (value >= self->low && value <= self->high) ? 1.0 : 0.0;
dest[RED_PIX] = value;
dest[GREEN_PIX] = value;
dest[BLUE_PIX] = value;
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
*
* gimpoperationthreshold.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_THRESHOLD_H__
#define __GIMP_OPERATION_THRESHOLD_H__
#include "gegl/gegl-operation-point-filter.h"
#define GIMP_TYPE_OPERATION_THRESHOLD (gimp_operation_threshold_get_type ())
#define GIMP_OPERATION_THRESHOLD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_THRESHOLD, GimpOperationThreshold))
#define GIMP_OPERATION_THRESHOLD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_THRESHOLD, GimpOperationThresholdClass))
#define GIMP_OPERATION_THRESHOLD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_THRESHOLD, GimpOperationThresholdClass))
typedef struct _GimpOperationThresholdClass GimpOperationThresholdClass;
struct _GimpOperationThreshold
{
GeglOperationPointFilter parent_instance;
gfloat low;
gfloat high;
};
struct _GimpOperationThresholdClass
{
GeglOperationPointFilterClass parent_class;
};
GType gimp_operation_threshold_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_OPERATION_THRESHOLD_H__ */
......@@ -47,22 +47,23 @@
/* local function prototypes */
static void gimp_threshold_tool_finalize (GObject *object);
static void gimp_threshold_tool_finalize (GObject *object);
static gboolean gimp_threshold_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static gboolean gimp_threshold_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static void gimp_threshold_tool_map (GimpImageMapTool *im_tool);
static void gimp_threshold_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_threshold_tool_reset (GimpImageMapTool *im_tool);
static GeglNode * gimp_threshold_tool_get_operation (GimpImageMapTool *im_tool);
static void gimp_threshold_tool_map (GimpImageMapTool *im_tool);
static void gimp_threshold_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_threshold_tool_reset (GimpImageMapTool *im_tool);
static void gimp_threshold_tool_histogram_range (GimpHistogramView *view,
gint start,
gint end,
GimpThresholdTool *t_tool);
static void gimp_threshold_tool_auto_clicked (GtkWidget *button,
GimpThresholdTool *t_tool);
static void gimp_threshold_tool_histogram_range (GimpHistogramView *view,
gint start,
gint end,
GimpThresholdTool *t_tool);
static void gimp_threshold_tool_auto_clicked (GtkWidget *button,
GimpThresholdTool *t_tool);
G_DEFINE_TYPE (GimpThresholdTool, gimp_threshold_tool,
......@@ -95,15 +96,16 @@ gimp_threshold_tool_class_init (GimpThresholdToolClass *klass)
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
object_class->finalize = gimp_threshold_tool_finalize;
object_class->finalize = gimp_threshold_tool_finalize;
tool_class->initialize = gimp_threshold_tool_initialize;
tool_class->initialize = gimp_threshold_tool_initialize;
im_tool_class->shell_desc = _("Apply Threshold");
im_tool_class->shell_desc = _("Apply Threshold");
im_tool_class->map = gimp_threshold_tool_map;
im_tool_class->dialog = gimp_threshold_tool_dialog;
im_tool_class->reset = gimp_threshold_tool_reset;
im_tool_class->get_operation = gimp_threshold_tool_get_operation;
im_tool_class->map = gimp_threshold_tool_map;
im_tool_class->dialog = gimp_threshold_tool_dialog;
im_tool_class->reset = gimp_threshold_tool_reset;
}
static void
......@@ -121,6 +123,12 @@ gimp_threshold_tool_finalize (GObject *object)
{
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (object);
if (t_tool->t_node)
{
g_object_unref (t_tool->t_node);
t_tool->t_node = NULL;
}
g_slice_free (Threshold, t_tool->threshold);
if (t_tool->hist)
......@@ -178,11 +186,34 @@ gimp_threshold_tool_initialize (GimpTool *tool,
return TRUE;
}
static GeglNode *
gimp_threshold_tool_get_operation (GimpImageMapTool *im_tool)
{
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (im_tool);
if (! t_tool->t_node)
{
t_tool->t_node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp-threshold",
NULL);
}
return t_tool->t_node;
}
static void
gimp_threshold_tool_map (GimpImageMapTool *image_map_tool)
{
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
if (t_tool->t_node)
{
gegl_node_set (t_tool->t_node,
"low", t_tool->threshold->low_threshold / 255.0,
"high", t_tool->threshold->high_threshold / 255.0,
NULL);
}
gimp_image_map_apply (image_map_tool->image_map,
(GimpImageMapApplyFunc) threshold,
t_tool->threshold);
......
......@@ -39,6 +39,7 @@ struct _GimpThresholdTool
GimpImageMapTool parent_instance;
Threshold *threshold;
GeglNode *t_node;
/* dialog */
GimpHistogram *hist;
......
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