Commit a5abd453 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

added gimp_scan_convert_render_value(), a variant of

2005-07-29  Sven Neumann  <sven@gimp.org>

	* app/core/gimpscanconvert.[ch]: added
	gimp_scan_convert_render_value(), a variant of
	gimp_scan_convert_render() that allows to pass the foreground value.

	* app/tools/gimpfreeselecttool.[ch]: added a virtual "select" method.

	* app/tools/Makefile.am
	* app/tools/gimp-tools.c
	* app/tools/gimpforegroundselecttool.[ch]: added a rough first
	version of foreground selection tool based on the SIOX algorithm.
	Work in progress...

	* app/widgets/gimphelp-ids.h: added help-id for the new tool.
parent 81b81e33
2005-07-29 Sven Neumann <sven@gimp.org>
* app/core/gimpscanconvert.[ch]: added
gimp_scan_convert_render_value(), a variant of
gimp_scan_convert_render() that allows to pass the foreground value.
* app/tools/gimpfreeselecttool.[ch]: added a virtual "select" method.
* app/tools/Makefile.am
* app/tools/gimp-tools.c
* app/tools/gimpforegroundselecttool.[ch]: added a rough first
version of foreground selection tool based on the SIOX algorithm.
Work in progress...
* app/widgets/gimphelp-ids.h: added help-id for the new tool.
2005-07-29 Sven Neumann <sven@gimp.org>
* app/tools/gimpfreeselecttool.c: minor cleanup.
......
......@@ -57,10 +57,18 @@ struct _GimpScanConvert
gint rowstride;
gint x0, x1;
gboolean antialias;
gboolean value;
};
/* private functions */
static void gimp_scan_convert_render_internal (GimpScanConvert *sc,
TileManager *tile_manager,
gint off_x,
gint off_y,
gboolean antialias,
guchar value);
static void gimp_scan_convert_finish (GimpScanConvert *sc);
static void gimp_scan_convert_close_add_points (GimpScanConvert *sc);
......@@ -201,8 +209,8 @@ gimp_scan_convert_add_polyline (GimpScanConvert *sc,
GimpVector2 *points,
gboolean closed)
{
GimpVector2 prev;
gint i;
GimpVector2 prev = { 0.0, 0.0, };
gint i;
g_return_if_fail (sc != NULL);
g_return_if_fail (points != NULL);
......@@ -437,12 +445,38 @@ gimp_scan_convert_render (GimpScanConvert *sc,
gint off_y,
gboolean antialias)
{
PixelRegion maskPR;
gpointer pr;
g_return_if_fail (sc != NULL);
g_return_if_fail (tile_manager != NULL);
gimp_scan_convert_render_internal (sc,
tile_manager, off_x, off_y, antialias, 0);
}
void
gimp_scan_convert_render_value (GimpScanConvert *sc,
TileManager *tile_manager,
gint off_x,
gint off_y,
guchar value)
{
g_return_if_fail (sc != NULL);
g_return_if_fail (tile_manager != NULL);
gimp_scan_convert_render_internal (sc,
tile_manager, off_x, off_y, FALSE, value);
}
static void
gimp_scan_convert_render_internal (GimpScanConvert *sc,
TileManager *tile_manager,
gint off_x,
gint off_y,
gboolean antialias,
guchar value)
{
PixelRegion maskPR;
gpointer pr;
gimp_scan_convert_finish (sc);
if (!sc->svp)
......@@ -456,15 +490,16 @@ gimp_scan_convert_render (GimpScanConvert *sc,
g_return_if_fail (maskPR.bytes == 1);
sc->antialias = antialias;
sc->value = value;
for (pr = pixel_regions_register (1, &maskPR);
pr != NULL;
pr = pixel_regions_process (pr))
{
sc->buf = maskPR.data;
sc->buf = maskPR.data;
sc->rowstride = maskPR.rowstride;
sc->x0 = off_x + maskPR.x;
sc->x1 = off_x + maskPR.x + maskPR.w;
sc->x0 = off_x + maskPR.x;
sc->x1 = off_x + maskPR.x + maskPR.w;
art_svp_render_aa (sc->svp,
sc->x0,
......@@ -476,7 +511,6 @@ gimp_scan_convert_render (GimpScanConvert *sc,
}
}
/* private function to convert the vpath to a svp when not using
* gimp_scan_convert_stroke
*/
......@@ -560,7 +594,7 @@ gimp_scan_convert_render_callback (gpointer user_data,
#define VALUE_TO_PIXEL(x) (sc->antialias ? \
((x) >> 16) : \
(((x) & (1 << 23) ? 255 : 0)))
(((x) & (1 << 23) ? sc->value : 0)))
if (n_steps > 0)
{
......
......@@ -72,15 +72,20 @@ void gimp_scan_convert_stroke (GimpScanConvert *sc,
GArray *dash_info);
/* This is a more low level version. Expects a tile manager of depth 1.
/* These are more low level version. Expects a tile manager of depth 1.
*
* You cannot add additional polygons after this command.
*/
void gimp_scan_convert_render (GimpScanConvert *scan_converter,
void gimp_scan_convert_render (GimpScanConvert *scan_converter,
TileManager *tile_manager,
gint off_x,
gint off_y,
gboolean antialias);
void gimp_scan_convert_render_value (GimpScanConvert *sc,
TileManager *tile_manager,
gint off_x,
gint off_y,
guchar value);
#endif /* __GIMP_SCAN_CONVERT_H__ */
......@@ -68,6 +68,8 @@ libapptools_a_sources = \
gimpfliptool.h \
gimpfreeselecttool.c \
gimpfreeselecttool.h \
gimpforegroundselecttool.c \
gimpforegroundselecttool.h \
gimpfuzzyselecttool.c \
gimpfuzzyselecttool.h \
gimphistogramoptions.c \
......
......@@ -59,6 +59,7 @@
#include "gimperasertool.h"
#include "gimpfliptool.h"
#include "gimpfreeselecttool.h"
#include "gimpforegroundselecttool.h"
#include "gimpfuzzyselecttool.h"
#include "gimphuesaturationtool.h"
#include "gimpinktool.h"
......@@ -163,6 +164,7 @@ gimp_tools_init (Gimp *gimp)
/* selection tools */
gimp_foreground_select_tool_register,
gimp_iscissors_tool_register,
gimp_by_color_select_tool_register,
gimp_fuzzy_select_tool_register,
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "core/gimpchannel.h"
#include "core/gimpchannel-select.h"
#include "core/gimpdrawable-foreground-extract.h"
#include "core/gimpimage.h"
#include "core/gimpscanconvert.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimphelp-ids.h"
#include "display/gimpdisplay.h"
#include "gimpforegroundselecttool.h"
#include "gimpselectionoptions.h"
#include "gimptoolcontrol.h"
#include "gimp-intl.h"
static void gimp_foreground_select_tool_class_init (GimpForegroundSelectToolClass *klass);
static void gimp_foreground_select_tool_init (GimpForegroundSelectTool *fg_select);
static void gimp_foreground_select_tool_finalize (GObject *object);
static void gimp_foreground_select_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_foreground_select_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_foreground_select_tool_motion (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_foreground_select_tool_draw (GimpDrawTool *draw_tool);
static void gimp_foreground_select_tool_select (GimpFreeSelectTool *free_sel,
GimpImage *gimage);
static GimpFreeSelectToolClass *parent_class = NULL;
/* public functions */
void
gimp_foreground_select_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
(* callback) (GIMP_TYPE_FOREGROUND_SELECT_TOOL,
GIMP_TYPE_SELECTION_OPTIONS,
gimp_selection_options_gui,
0,
"gimp-foreground-select-tool",
_("Foreground Select"),
_("Extract foreground"),
N_("_Foreground Select"), NULL,
NULL, GIMP_HELP_TOOL_FOREGROUND_SELECT,
GIMP_STOCK_TOOL_FUZZY_SELECT,
data);
}
GType
gimp_foreground_select_tool_get_type (void)
{
static GType tool_type = 0;
if (! tool_type)
{
static const GTypeInfo tool_info =
{
sizeof (GimpForegroundSelectToolClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_foreground_select_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpForegroundSelectTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_foreground_select_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_FREE_SELECT_TOOL,
"GimpForegroundSelectTool",
&tool_info, 0);
}
return tool_type;
}
/* private functions */
static void
gimp_foreground_select_tool_class_init (GimpForegroundSelectToolClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
GimpFreeSelectToolClass *free_select_tool_class = GIMP_FREE_SELECT_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_foreground_select_tool_finalize;
tool_class->button_press = gimp_foreground_select_tool_button_press;
tool_class->button_release = gimp_foreground_select_tool_button_release;
tool_class->motion = gimp_foreground_select_tool_motion;
draw_tool_class->draw = gimp_foreground_select_tool_draw;
free_select_tool_class->select = gimp_foreground_select_tool_select;
}
static void
gimp_foreground_select_tool_init (GimpForegroundSelectTool *fg_select)
{
GimpTool *tool = GIMP_TOOL (fg_select);
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_FREE_SELECT);
fg_select->mask = NULL;
}
static void
gimp_foreground_select_tool_finalize (GObject *object)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (object);
if (fg_select->mask)
{
g_object_unref (fg_select->mask);
fg_select->mask = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_foreground_select_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
{
GIMP_TOOL_CLASS (parent_class)->button_press (tool,
coords, time, state, gdisp);
}
static void
gimp_foreground_select_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
{
GIMP_TOOL_CLASS (parent_class)->button_release (tool,
coords, time, state, gdisp);
}
static void
gimp_foreground_select_tool_motion (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
{
GIMP_TOOL_CLASS (parent_class)->motion (tool,
coords, time, state, gdisp);
}
static void
gimp_foreground_select_tool_draw (GimpDrawTool *draw_tool)
{
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
}
static void
gimp_foreground_select_tool_select (GimpFreeSelectTool *free_sel,
GimpImage *gimage)
{
GimpTool *tool = GIMP_TOOL (free_sel);
GimpDrawable *drawable = gimp_image_active_drawable (gimage);
GimpScanConvert *scan_convert;
GimpChannel *mask;
GimpSelectionOptions *options;
if (! drawable)
return;
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
gimp_set_busy (gimage->gimp);
scan_convert = gimp_scan_convert_new ();
gimp_scan_convert_add_polyline (scan_convert,
free_sel->num_points, free_sel->points, TRUE);
mask = gimp_channel_new (gimage,
gimp_image_get_width (gimage),
gimp_image_get_height (gimage),
"foreground-extraction", NULL);
gimp_scan_convert_render_value (scan_convert,
gimp_drawable_data (GIMP_DRAWABLE (mask)),
0, 0, 127);
gimp_scan_convert_free (scan_convert);
gimp_drawable_foreground_extract (drawable, mask);
gimp_channel_select_channel (gimp_image_get_mask (gimage),
tool->tool_info->blurb,
mask, 0, 0,
GIMP_SELECTION_TOOL (tool)->op,
options->feather,
options->feather_radius,
options->feather_radius);
g_object_unref (mask);
gimp_unset_busy (gimage->gimp);
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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_FOREGROUND_SELECT_TOOL_H__
#define __GIMP_FOREGROUND_SELECT_TOOL_H__
#include "gimpfreeselecttool.h"
#define GIMP_TYPE_FOREGROUND_SELECT_TOOL (gimp_foreground_select_tool_get_type ())
#define GIMP_FOREGROUND_SELECT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_FOREGROUND_SELECT_TOOL, GimpForegroundSelectTool))
#define GIMP_FOREGROUND_SELECT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_FOREGROUND_SELECT_TOOL, GimpForegroundSelectToolClass))
#define GIMP_IS_FOREGROUND_SELECT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_FOREGROUND_SELECT_TOOL))
#define GIMP_IS_FOREGROUND_SELECT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_FOREGROUND_SELECT_TOOL))
#define GIMP_FOREGROUND_SELECT_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_FOREGROUND_SELECT_TOOL, GimpForegroundSelectToolClass))
typedef struct _GimpForegroundSelectTool GimpForegroundSelectTool;
typedef struct _GimpForegroundSelectToolClass GimpForegroundSelectToolClass;
struct _GimpForegroundSelectTool
{
GimpFreeSelectTool parent_instance;
GimpChannel *mask;
};
struct _GimpForegroundSelectToolClass
{
GimpFreeSelectToolClass parent_class;
};
void gimp_foreground_select_tool_register (GimpToolRegisterCallback callback,
gpointer data);
GType gimp_foreground_select_tool_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_FOREGROUND_SELECT_TOOL_H__ */
......@@ -66,6 +66,9 @@ static void gimp_free_select_tool_motion (GimpTool *tool,
static void gimp_free_select_tool_draw (GimpDrawTool *draw_tool);
static void gimp_free_select_tool_select (GimpFreeSelectTool *free_sel,
GimpImage *gimage);
static void gimp_free_select_tool_add_point (GimpFreeSelectTool *free_sel,
gdouble x,
gdouble y);
......@@ -142,6 +145,8 @@ gimp_free_select_tool_class_init (GimpFreeSelectToolClass *klass)
tool_class->motion = gimp_free_select_tool_motion;
draw_tool_class->draw = gimp_free_select_tool_draw;
klass->select = gimp_free_select_tool_select;
}
static void
......@@ -219,22 +224,19 @@ gimp_free_select_tool_button_release (GimpTool *tool,
{
/* If there is a floating selection, anchor it */
if (gimp_image_floating_sel (gdisp->gimage))
floating_sel_anchor (gimp_image_floating_sel (gdisp->gimage));
{
floating_sel_anchor (gimp_image_floating_sel (gdisp->gimage));
}
/* Otherwise, clear the selection mask */
else
gimp_channel_clear (gimp_image_get_mask (gdisp->gimage), NULL, TRUE);
{
gimp_channel_clear (gimp_image_get_mask (gdisp->gimage), NULL, TRUE);
}
}
else
{
gimp_channel_select_polygon (gimp_image_get_mask (gdisp->gimage),
tool->tool_info->blurb,
free_sel->num_points,
free_sel->points,
GIMP_SELECTION_TOOL (tool)->op,
options->antialias,
options->feather,
options->feather_radius,
options->feather_radius);
GIMP_FREE_SELECT_TOOL_GET_CLASS (free_sel)->select (free_sel,
gdisp->gimage);
}
gimp_image_flush (gdisp->gimage);
......@@ -299,6 +301,26 @@ gimp_free_select_tool_draw (GimpDrawTool *draw_tool)
}
}
static void
gimp_free_select_tool_select (GimpFreeSelectTool *free_sel,
GimpImage *gimage)
{
GimpTool *tool = GIMP_TOOL (free_sel);
GimpSelectionOptions *options;
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
gimp_channel_select_polygon (gimp_image_get_mask (gimage),
tool->tool_info->blurb,
free_sel->num_points,
free_sel->points,
GIMP_SELECTION_TOOL (tool)->op,
options->antialias,
options->feather,
options->feather_radius,
options->feather_radius);
}
static void
gimp_free_select_tool_add_point (GimpFreeSelectTool *free_sel,
gdouble x,
......
......@@ -48,6 +48,11 @@ struct _GimpFreeSelectTool
struct _GimpFreeSelectToolClass
{
GimpSelectionToolClass parent_class;
/* virtual function */
void (* select) (GimpFreeSelectTool *free_select_tool,
GimpImage *gimage);
};
......
......@@ -241,6 +241,7 @@
#define GIMP_HELP_TOOL_ERASER "gimp-tool-eraser"
#define GIMP_HELP_TOOL_FLIP "gimp-tool-flip"
#define GIMP_HELP_TOOL_FREE_SELECT "gimp-tool-free-select"
#define GIMP_HELP_TOOL_FOREGROUND_SELECT "gimp-tool-foreground-select"
#define GIMP_HELP_TOOL_FUZZY_SELECT "gimp-tool-fuzzy-select"
#define GIMP_HELP_TOOL_HUE_SATURATION "gimp-tool-hue-saturation"
#define GIMP_HELP_TOOL_INK "gimp-tool-ink"
......
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