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

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

	* app/gegl/Makefile.am
	* app/gegl/gegl-types.h
	* app/gegl/gimpoperationlevels.[ch]: new operator.

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

	* app/tools/gimplevelstool.c: use it,


svn path=/trunk/; revision=24565
This commit is contained in:
Michael Natterer
2008-01-07 20:37:25 +00:00
committed by Michael Natterer
parent 5da250fc8f
commit 1c804c8d43
7 changed files with 354 additions and 43 deletions

View File

@ -1,3 +1,13 @@
2008-01-07 Michael Natterer <mitch@gimp.org>
* app/gegl/Makefile.am
* app/gegl/gegl-types.h
* app/gegl/gimpoperationlevels.[ch]: new operator.
* app/gegl/gimp-gegl.c: register it.
* app/tools/gimplevelstool.c: use it,
2008-01-07 Michael Natterer <mitch@gimp.org>
* app/gegl/gimpoperationcolorize.c (process): add some comments

View File

@ -11,6 +11,8 @@ libappgegl_a_SOURCES = \
gimpoperationcolorize.h \
gimpoperationdesaturate.c \
gimpoperationdesaturate.h \
gimpoperationlevels.c \
gimpoperationlevels.h \
gimpoperationposterize.c \
gimpoperationposterize.h \
gimpoperationthreshold.c \

View File

@ -27,6 +27,7 @@
typedef struct _GimpOperationColorize GimpOperationColorize;
typedef struct _GimpOperationDesaturate GimpOperationDesaturate;
typedef struct _GimpOperationLevels GimpOperationLevels;
typedef struct _GimpOperationPosterize GimpOperationPosterize;
typedef struct _GimpOperationThreshold GimpOperationThreshold;
typedef struct _GimpOperationTileSink GimpOperationTileSink;

View File

@ -29,6 +29,7 @@
#include "gimp-gegl.h"
#include "gimpoperationcolorize.h"
#include "gimpoperationdesaturate.h"
#include "gimpoperationlevels.h"
#include "gimpoperationposterize.h"
#include "gimpoperationthreshold.h"
#include "gimpoperationtilesink.h"
@ -40,6 +41,7 @@ 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_LEVELS);
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);

View File

@ -0,0 +1,197 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationlevels.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 "gimpoperationlevels.h"
enum
{
PROP_0,
PROP_HUE,
PROP_SATURATION,
PROP_LIGHTNESS
};
static void gimp_operation_levels_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_operation_levels_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_operation_levels_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples);
G_DEFINE_TYPE (GimpOperationLevels, gimp_operation_levels,
GEGL_TYPE_OPERATION_POINT_FILTER)
#define parent_class gimp_operation_levels_parent_class
static void
gimp_operation_levels_class_init (GimpOperationLevelsClass * 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_levels_set_property;
object_class->get_property = gimp_operation_levels_get_property;
point_class->process = gimp_operation_levels_process;
gegl_operation_class_set_name (operation_class, "gimp-levels");
}
static void
gimp_operation_levels_init (GimpOperationLevels *self)
{
}
static void
gimp_operation_levels_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
/* GimpOperationLevels *self = GIMP_OPERATION_LEVELS (object); */
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_operation_levels_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
/* GimpOperationLevels *self = GIMP_OPERATION_LEVELS (object); */
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static inline gfloat
gimp_operation_levels_map (gfloat value,
gfloat low_input,
gfloat high_input,
gfloat gamma,
gfloat low_output,
gfloat high_output)
{
/* determine input intensity */
if (high_input != low_input)
{
value = (value - low_input) / (high_input - low_input);
}
else
{
value = (value - low_input);
}
if (gamma != 0.0)
{
if (value >= 0.0)
value = pow ( value, 1.0 / gamma);
else
value = -pow (-value, 1.0 / gamma);
}
/* determine the output intensity */
if (high_output >= low_output)
value = value * (high_output - low_output) + low_output;
else if (high_output < low_output)
value = low_output - value * (low_output - high_output);
return value;
}
static gboolean
gimp_operation_levels_process (GeglOperation *operation,
void *in_buf,
void *out_buf,
glong samples)
{
GimpOperationLevels *self = GIMP_OPERATION_LEVELS (operation);
gfloat *src = in_buf;
gfloat *dest = out_buf;
glong sample;
for (sample = 0; sample < samples; sample++)
{
gint channel;
for (channel = 0; channel < 4; channel++)
{
gfloat value;
value = gimp_operation_levels_map (src[channel],
self->low_input[channel + 1],
self->high_input[channel + 1],
self->gamma[channel + 1],
self->low_output[channel + 1],
self->high_output[channel + 1]);
/* don't apply the overall curve to the alpha channel */
if (channel != 3)
value = gimp_operation_levels_map (value,
self->low_input[0],
self->high_input[0],
self->gamma[0],
self->low_output[0],
self->high_output[0]);
dest[channel] = value;
}
src += 4;
dest += 4;
}
return TRUE;
}

View File

@ -0,0 +1,61 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationlevels.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_LEVELS_H__
#define __GIMP_OPERATION_LEVELS_H__
#include "gegl/gegl-operation-point-filter.h"
#define GIMP_TYPE_OPERATION_LEVELS (gimp_operation_levels_get_type ())
#define GIMP_OPERATION_LEVELS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_LEVELS, GimpOperationLevels))
#define GIMP_OPERATION_LEVELS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_LEVELS, GimpOperationLevelsClass))
#define GIMP_IS_OPERATION_LEVELS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OPERATION_LEVELS))
#define GIMP_IS_OPERATION_LEVELS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_OPERATION_LEVELS))
#define GIMP_OPERATION_LEVELS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_LEVELS, GimpOperationLevelsClass))
typedef struct _GimpOperationLevelsClass GimpOperationLevelsClass;
struct _GimpOperationLevels
{
GeglOperationPointFilter parent_instance;
gfloat gamma[5];
gfloat low_input[5];
gfloat high_input[5];
gfloat low_output[5];
gfloat high_output[5];
};
struct _GimpOperationLevelsClass
{
GeglOperationPointFilterClass parent_class;
};
GType gimp_operation_levels_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_OPERATION_LEVELS_H__ */

View File

@ -37,6 +37,8 @@
#include "base/gimplut.h"
#include "base/levels.h"
#include "gegl/gimpoperationlevels.h"
#include "core/gimpdrawable.h"
#include "core/gimpdrawable-histogram.h"
#include "core/gimpimage.h"
@ -68,56 +70,57 @@
/* local function prototypes */
static void gimp_levels_tool_finalize (GObject *object);
static void gimp_levels_tool_finalize (GObject *object);
static gboolean gimp_levels_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static gboolean gimp_levels_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static void gimp_levels_tool_color_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
GimpRGB *color,
gint color_index);
static void gimp_levels_tool_color_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
GimpRGB *color,
gint color_index);
static void gimp_levels_tool_map (GimpImageMapTool *image_map_tool);
static void gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_levels_tool_dialog_unmap (GtkWidget *dialog,
GimpLevelsTool *tool);
static void gimp_levels_tool_reset (GimpImageMapTool *image_map_tool);
static gboolean gimp_levels_tool_settings_load (GimpImageMapTool *image_mao_tool,
gpointer fp,
GError **error);
static gboolean gimp_levels_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp);
static GeglNode * gimp_levels_tool_get_operation (GimpImageMapTool *im_tool);
static void gimp_levels_tool_map (GimpImageMapTool *im_tool);
static void gimp_levels_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_levels_tool_dialog_unmap (GtkWidget *dialog,
GimpLevelsTool *tool);
static void gimp_levels_tool_reset (GimpImageMapTool *im_tool);
static gboolean gimp_levels_tool_settings_load (GimpImageMapTool *im_tool,
gpointer fp,
GError **error);
static gboolean gimp_levels_tool_settings_save (GimpImageMapTool *im_tool,
gpointer fp);
static void levels_update_adjustments (GimpLevelsTool *tool);
static void levels_update_input_bar (GimpLevelsTool *tool);
static void levels_update_adjustments (GimpLevelsTool *tool);
static void levels_update_input_bar (GimpLevelsTool *tool);
static void levels_channel_callback (GtkWidget *widget,
GimpLevelsTool *tool);
static void levels_channel_reset_callback (GtkWidget *widget,
GimpLevelsTool *tool);
static void levels_channel_callback (GtkWidget *widget,
GimpLevelsTool *tool);
static void levels_channel_reset_callback (GtkWidget *widget,
GimpLevelsTool *tool);
static gboolean levels_menu_sensitivity (gint value,
gpointer data);
static gboolean levels_menu_sensitivity (gint value,
gpointer data);
static void levels_stretch_callback (GtkWidget *widget,
GimpLevelsTool *tool);
static void levels_low_input_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_gamma_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_linear_gamma_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_high_input_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_low_output_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_high_output_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_input_picker_toggled (GtkWidget *widget,
GimpLevelsTool *tool);
static void levels_stretch_callback (GtkWidget *widget,
GimpLevelsTool *tool);
static void levels_low_input_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_gamma_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_linear_gamma_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_high_input_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_low_output_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_high_output_changed (GtkAdjustment *adjustment,
GimpLevelsTool *tool);
static void levels_input_picker_toggled (GtkWidget *widget,
GimpLevelsTool *tool);
G_DEFINE_TYPE (GimpLevelsTool, gimp_levels_tool, GIMP_TYPE_IMAGE_MAP_TOOL)
@ -163,6 +166,7 @@ gimp_levels_tool_class_init (GimpLevelsToolClass *klass)
im_tool_class->save_dialog_title = _("Save Levels");
im_tool_class->save_button_tip = _("Save levels settings to file");
im_tool_class->get_operation = gimp_levels_tool_get_operation;
im_tool_class->map = gimp_levels_tool_map;
im_tool_class->dialog = gimp_levels_tool_dialog;
im_tool_class->reset = gimp_levels_tool_reset;
@ -251,11 +255,45 @@ gimp_levels_tool_initialize (GimpTool *tool,
return TRUE;
}
static GeglNode *
gimp_levels_tool_get_operation (GimpImageMapTool *im_tool)
{
return g_object_new (GEGL_TYPE_NODE,
"operation", "gimp-levels",
NULL);
}
static void
gimp_levels_tool_map (GimpImageMapTool *image_map_tool)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
if (image_map_tool->operation)
{
GimpOperationLevels *levels;
Levels *l;
GimpHistogramChannel channel;
g_object_get (image_map_tool->operation, "gegl-operation", &levels, NULL);
l = tool->levels;
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
levels->gamma[channel] = l->gamma[channel];
levels->low_input[channel] = l->low_input[channel] / 255.0;
levels->high_input[channel] = l->high_input[channel] / 255.0;
levels->low_output[channel] = l->low_output[channel] / 255.0;
levels->high_output[channel] = l->high_output[channel] / 255.0;
}
g_object_unref (levels);
}
gimp_lut_setup (tool->lut,
(GimpLutFunc) levels_lut_func,
tool->levels,