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

ported to GIMP data structures. There are still some TODOs, smooth_mask()

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

	* app/base/segmentator.[ch]: ported to GIMP data structures. There
	are still some TODOs, smooth_mask() isn't implemented yet.

	* app/core/Makefile.am
	* app/core/gimpdrawable-foreground-extract.[ch]: thin wrapper around
	the new segmentation algorithm.

	* tools/pdbgen/pdb/drawable.pdb: added a first draft of a PDB API
	for foreground extraction.

	* app/pdb/drawable_cmds.c
	* app/pdb/internal_procs.c
	* libgimp/gimpdrawable_pdb.[ch]: regenerated.
parent 9b9052b8
2005-07-10 Sven Neumann <sven@gimp.org>
* app/base/segmentator.[ch]: ported to GIMP data structures. There
are still some TODOs, smooth_mask() isn't implemented yet.
* app/core/Makefile.am
* app/core/gimpdrawable-foreground-extract.[ch]: thin wrapper around
the new segmentation algorithm.
* tools/pdbgen/pdb/drawable.pdb: added a first draft of a PDB API
for foreground extraction.
* app/pdb/drawable_cmds.c
* app/pdb/internal_procs.c
* libgimp/gimpdrawable_pdb.[ch]: regenerated.
2005-07-09 Michael Natterer <mitch@gimp.org>
* app/core/gimplayer.c: removed if(image) checks where the image
......
This diff is collapsed.
......@@ -40,12 +40,10 @@
#define DIMS 3
float * segmentate (guint *rgbs,
float *confidencematrix,
int xres,
int yres,
float limits[DIMS],
int smoothness);
void foreground_extract (TileManager *tiles,
TileManager *trimap,
gfloat limits[DIMS],
gint smoothness);
#endif /* __SEGMENTATOR_H__ */
This diff is collapsed.
......@@ -40,12 +40,10 @@
#define DIMS 3
float * segmentate (guint *rgbs,
float *confidencematrix,
int xres,
int yres,
float limits[DIMS],
int smoothness);
void foreground_extract (TileManager *tiles,
TileManager *trimap,
gfloat limits[DIMS],
gint smoothness);
#endif /* __SEGMENTATOR_H__ */
......@@ -92,6 +92,8 @@ libappcore_a_sources = \
gimpdrawable-desaturate.h \
gimpdrawable-equalize.c \
gimpdrawable-equalize.h \
gimpdrawable-foreground-extract.c\
gimpdrawable-foreground-extract.h\
gimpdrawable-histogram.c \
gimpdrawable-histogram.h \
gimpdrawable-invert.c \
......
/* 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 <glib-object.h>
#include "core-types.h"
#include "base/pixel-region.h"
#include "base/segmentator.h"
#include "base/tile-manager.h"
#include "gimpchannel.h"
#include "gimpdrawable.h"
#include "gimpdrawable-foreground-extract.h"
#include "gimpimage.h"
/* public functions */
void
gimp_drawable_foreground_extract (GimpDrawable *drawable,
GimpDrawable *mask)
{
GimpImage *gimage;
gfloat limits[DIMS] = { 0.66, 1.25, 2.5 };
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
g_return_if_fail (GIMP_IS_DRAWABLE (mask));
g_return_if_fail (gimp_drawable_bytes (mask) == 1);
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
foreground_extract (gimp_drawable_data (drawable),
gimp_drawable_data (mask),
limits, 3);
gimp_drawable_update (mask,
0, 0,
gimp_item_width (GIMP_ITEM (mask)),
gimp_item_height (GIMP_ITEM (mask)));
}
/* 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_DRAWABLE_FOREGROUND_EXTRACT_H__
#define __GIMP_DRAWABLE_FOREGROUND_EXTRACT_H__
void gimp_drawable_foreground_extract (GimpDrawable *drawable,
GimpDrawable *mask);
#endif /* __GIMP_DRAWABLE_FOREGROUND_EXTRACT_H__ */
......@@ -31,6 +31,7 @@
#include "base/tile.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimpdrawable-foreground-extract.h"
#include "core/gimpdrawable-offset.h"
#include "core/gimpdrawable-preview.h"
#include "core/gimpdrawable.h"
......@@ -74,6 +75,7 @@ static ProcRecord drawable_fill_proc;
static ProcRecord drawable_offset_proc;
static ProcRecord drawable_thumbnail_proc;
static ProcRecord drawable_sub_thumbnail_proc;
static ProcRecord drawable_foreground_extract_proc;
void
register_drawable_procs (Gimp *gimp)
......@@ -112,6 +114,7 @@ register_drawable_procs (Gimp *gimp)
procedural_db_register (gimp, &drawable_offset_proc);
procedural_db_register (gimp, &drawable_thumbnail_proc);
procedural_db_register (gimp, &drawable_sub_thumbnail_proc);
procedural_db_register (gimp, &drawable_foreground_extract_proc);
}
static Argument *
......@@ -2499,3 +2502,63 @@ static ProcRecord drawable_sub_thumbnail_proc =
drawable_sub_thumbnail_outargs,
{ { drawable_sub_thumbnail_invoker } }
};
static Argument *
drawable_foreground_extract_invoker (Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpDrawable *drawable;
GimpDrawable *mask;
drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int);
if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable))))
success = FALSE;
mask = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[1].value.pdb_int);
if (! (GIMP_IS_DRAWABLE (mask) && ! gimp_item_is_removed (GIMP_ITEM (mask))))
success = FALSE;
if (success)
{
success = gimp_item_is_attached (GIMP_ITEM (drawable));
if (success)
gimp_drawable_foreground_extract (drawable, mask);
}
return procedural_db_return_args (&drawable_foreground_extract_proc, success);
}
static ProcArg drawable_foreground_extract_inargs[] =
{
{
GIMP_PDB_DRAWABLE,
"drawable",
"The drawable"
},
{
GIMP_PDB_DRAWABLE,
"mask",
"Tri-Map"
}
};
static ProcRecord drawable_foreground_extract_proc =
{
"gimp_drawable_foreground_extract",
"Extract the foreground of a drawable using a given trimap.",
"Image Segmentation by Uniform Color Clustering, see http://www.inf.fu-berlin.de/inst/pubs/tr-b-05-07.pdf",
"Gerald Friedland <fland@inf.fu-berlin.de>, Kristian Jantz <jantz@inf.fu-berlin.de>, Sven Neumann <sven@gimp.org>",
"Gerald Friedland",
"2005",
NULL,
GIMP_INTERNAL,
2,
drawable_foreground_extract_inargs,
0,
NULL,
{ { drawable_foreground_extract_invoker } }
};
......@@ -75,7 +75,7 @@ void register_undo_procs (Gimp *gimp);
void register_unit_procs (Gimp *gimp);
void register_vectors_procs (Gimp *gimp);
/* 463 procedures registered total */
/* 464 procedures registered total */
void
internal_procs_init (Gimp *gimp,
......@@ -87,7 +87,7 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (_("Internal Procedures"), _("Brush"), 0.0);
register_brush_procs (gimp);
(* status_callback) (NULL, _("Brush UI"), 0.048);
(* status_callback) (NULL, _("Brush UI"), 0.047);
register_brush_select_procs (gimp);
(* status_callback) (NULL, _("Brushes"), 0.054);
......@@ -96,79 +96,79 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Channel"), 0.067);
register_channel_procs (gimp);
(* status_callback) (NULL, _("Color"), 0.089);
(* status_callback) (NULL, _("Color"), 0.088);
register_color_procs (gimp);
(* status_callback) (NULL, _("Context"), 0.123);
register_context_procs (gimp);
(* status_callback) (NULL, _("Convert"), 0.171);
(* status_callback) (NULL, _("Convert"), 0.17);
register_convert_procs (gimp);
(* status_callback) (NULL, _("Display procedures"), 0.177);
register_display_procs (gimp);
(* status_callback) (NULL, _("Drawable procedures"), 0.186);
(* status_callback) (NULL, _("Drawable procedures"), 0.185);
register_drawable_procs (gimp);
(* status_callback) (NULL, _("Transformation procedures"), 0.259);
(* status_callback) (NULL, _("Transformation procedures"), 0.261);
register_drawable_transform_procs (gimp);
(* status_callback) (NULL, _("Edit procedures"), 0.294);
(* status_callback) (NULL, _("Edit procedures"), 0.295);
register_edit_procs (gimp);
(* status_callback) (NULL, _("File Operations"), 0.313);
(* status_callback) (NULL, _("File Operations"), 0.315);
register_fileops_procs (gimp);
(* status_callback) (NULL, _("Floating selections"), 0.335);
(* status_callback) (NULL, _("Floating selections"), 0.336);
register_floating_sel_procs (gimp);
(* status_callback) (NULL, _("Font UI"), 0.348);
(* status_callback) (NULL, _("Font UI"), 0.349);
register_font_select_procs (gimp);
(* status_callback) (NULL, _("Fonts"), 0.354);
(* status_callback) (NULL, _("Fonts"), 0.356);
register_fonts_procs (gimp);
(* status_callback) (NULL, _("Gimprc procedures"), 0.359);
(* status_callback) (NULL, _("Gimprc procedures"), 0.36);
register_gimprc_procs (gimp);
(* status_callback) (NULL, _("Gradient"), 0.374);
(* status_callback) (NULL, _("Gradient"), 0.375);
register_gradient_procs (gimp);
(* status_callback) (NULL, _("Gradient UI"), 0.438);
(* status_callback) (NULL, _("Gradient UI"), 0.44);
register_gradient_select_procs (gimp);
(* status_callback) (NULL, _("Gradients"), 0.445);
(* status_callback) (NULL, _("Gradients"), 0.446);
register_gradients_procs (gimp);
(* status_callback) (NULL, _("Guide procedures"), 0.456);
(* status_callback) (NULL, _("Guide procedures"), 0.457);
register_guides_procs (gimp);
(* status_callback) (NULL, _("Help procedures"), 0.469);
(* status_callback) (NULL, _("Help procedures"), 0.47);
register_help_procs (gimp);
(* status_callback) (NULL, _("Image"), 0.471);
(* status_callback) (NULL, _("Image"), 0.472);
register_image_procs (gimp);
(* status_callback) (NULL, _("Layer"), 0.607);
(* status_callback) (NULL, _("Layer"), 0.608);
register_layer_procs (gimp);
(* status_callback) (NULL, _("Message procedures"), 0.665);
(* status_callback) (NULL, _("Message procedures"), 0.666);
register_message_procs (gimp);
(* status_callback) (NULL, _("Miscellaneous"), 0.672);
register_misc_procs (gimp);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.676);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.677);
register_paint_tools_procs (gimp);
(* status_callback) (NULL, _("Palette"), 0.708);
(* status_callback) (NULL, _("Palette"), 0.709);
register_palette_procs (gimp);
(* status_callback) (NULL, _("Palette UI"), 0.739);
register_palette_select_procs (gimp);
(* status_callback) (NULL, _("Palettes"), 0.745);
(* status_callback) (NULL, _("Palettes"), 0.746);
register_palettes_procs (gimp);
(* status_callback) (NULL, _("Parasite procedures"), 0.754);
......@@ -177,7 +177,7 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Paths"), 0.78);
register_paths_procs (gimp);
(* status_callback) (NULL, _("Pattern"), 0.814);
(* status_callback) (NULL, _("Pattern"), 0.815);
register_pattern_procs (gimp);
(* status_callback) (NULL, _("Pattern UI"), 0.819);
......@@ -204,13 +204,13 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Text procedures"), 0.929);
register_text_tool_procs (gimp);
(* status_callback) (NULL, _("Transform Tool procedures"), 0.937);
(* status_callback) (NULL, _("Transform Tool procedures"), 0.938);
register_transform_tools_procs (gimp);
(* status_callback) (NULL, _("Undo"), 0.95);
register_undo_procs (gimp);
(* status_callback) (NULL, _("Units"), 0.965);
(* status_callback) (NULL, _("Units"), 0.966);
register_unit_procs (gimp);
(* status_callback) (NULL, _("Paths"), 0.991);
......
......@@ -1298,3 +1298,38 @@ _gimp_drawable_sub_thumbnail (gint32 drawable_ID,
return success;
}
/**
* gimp_drawable_foreground_extract:
* @drawable_ID: The drawable.
* @mask_ID: Tri-Map.
*
* Extract the foreground of a drawable using a given trimap.
*
* Image Segmentation by Uniform Color Clustering, see
* http://www.inf.fu-berlin.de/inst/pubs/tr-b-05-07.pdf
*
* Returns: TRUE on success.
*
* Since: GIMP 2.4
*/
gboolean
gimp_drawable_foreground_extract (gint32 drawable_ID,
gint32 mask_ID)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp_drawable_foreground_extract",
&nreturn_vals,
GIMP_PDB_DRAWABLE, drawable_ID,
GIMP_PDB_DRAWABLE, mask_ID,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
......@@ -29,92 +29,94 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
gboolean gimp_drawable_delete (gint32 drawable_ID);
gboolean gimp_drawable_is_layer (gint32 drawable_ID);
gboolean gimp_drawable_is_layer_mask (gint32 drawable_ID);
gboolean gimp_drawable_is_channel (gint32 drawable_ID);
GimpImageType gimp_drawable_type (gint32 drawable_ID);
GimpImageType gimp_drawable_type_with_alpha (gint32 drawable_ID);
gboolean gimp_drawable_has_alpha (gint32 drawable_ID);
gboolean gimp_drawable_is_rgb (gint32 drawable_ID);
gboolean gimp_drawable_is_gray (gint32 drawable_ID);
gboolean gimp_drawable_is_indexed (gint32 drawable_ID);
gint gimp_drawable_bpp (gint32 drawable_ID);
gint gimp_drawable_width (gint32 drawable_ID);
gint gimp_drawable_height (gint32 drawable_ID);
gboolean gimp_drawable_offsets (gint32 drawable_ID,
gint *offset_x,
gint *offset_y);
gint32 gimp_drawable_get_image (gint32 drawable_ID);
gboolean gimp_drawable_delete (gint32 drawable_ID);
gboolean gimp_drawable_is_layer (gint32 drawable_ID);
gboolean gimp_drawable_is_layer_mask (gint32 drawable_ID);
gboolean gimp_drawable_is_channel (gint32 drawable_ID);
GimpImageType gimp_drawable_type (gint32 drawable_ID);
GimpImageType gimp_drawable_type_with_alpha (gint32 drawable_ID);
gboolean gimp_drawable_has_alpha (gint32 drawable_ID);
gboolean gimp_drawable_is_rgb (gint32 drawable_ID);
gboolean gimp_drawable_is_gray (gint32 drawable_ID);
gboolean gimp_drawable_is_indexed (gint32 drawable_ID);
gint gimp_drawable_bpp (gint32 drawable_ID);
gint gimp_drawable_width (gint32 drawable_ID);
gint gimp_drawable_height (gint32 drawable_ID);
gboolean gimp_drawable_offsets (gint32 drawable_ID,
gint *offset_x,
gint *offset_y);
gint32 gimp_drawable_get_image (gint32 drawable_ID);
#ifndef GIMP_DISABLE_DEPRECATED
gboolean gimp_drawable_set_image (gint32 drawable_ID,
gint32 image_ID);
gboolean gimp_drawable_set_image (gint32 drawable_ID,
gint32 image_ID);
#endif /* GIMP_DISABLE_DEPRECATED */
gchar* gimp_drawable_get_name (gint32 drawable_ID);
gboolean gimp_drawable_set_name (gint32 drawable_ID,
const gchar *name);
gboolean gimp_drawable_get_visible (gint32 drawable_ID);
gboolean gimp_drawable_set_visible (gint32 drawable_ID,
gboolean visible);
gboolean gimp_drawable_get_linked (gint32 drawable_ID);
gboolean gimp_drawable_set_linked (gint32 drawable_ID,
gboolean linked);
gint gimp_drawable_get_tattoo (gint32 drawable_ID);
gboolean gimp_drawable_set_tattoo (gint32 drawable_ID,
gint tattoo);
gboolean gimp_drawable_mask_bounds (gint32 drawable_ID,
gint *x1,
gint *y1,
gint *x2,
gint *y2);
gboolean gimp_drawable_mask_intersect (gint32 drawable_ID,
gint *x,
gint *y,
gint *width,
gint *height);
gboolean gimp_drawable_merge_shadow (gint32 drawable_ID,
gboolean undo);
gboolean gimp_drawable_update (gint32 drawable_ID,
gint x,
gint y,
gint width,
gint height);
guint8* gimp_drawable_get_pixel (gint32 drawable_ID,
gint x_coord,
gint y_coord,
gint *num_channels);
gboolean gimp_drawable_set_pixel (gint32 drawable_ID,
gint x_coord,
gint y_coord,
gint num_channels,
const guint8 *pixel);
gboolean gimp_drawable_fill (gint32 drawable_ID,
GimpFillType fill_type);
gboolean gimp_drawable_offset (gint32 drawable_ID,
gboolean wrap_around,
GimpOffsetType fill_type,
gint offset_x,
gint offset_y);
gboolean _gimp_drawable_thumbnail (gint32 drawable_ID,
gint width,
gint height,
gint *ret_width,
gint *ret_height,
gint *bpp,
gint *thumbnail_data_count,
guint8 **thumbnail_data);
gboolean _gimp_drawable_sub_thumbnail (gint32 drawable_ID,
gint src_x,
gint src_y,
gint src_width,
gint src_height,
gint dest_width,
gint dest_height,
gint *width,
gint *height,
gint *bpp,
gint *thumbnail_data_count,
guint8 **thumbnail_data);
gchar* gimp_drawable_get_name (gint32 drawable_ID);
gboolean gimp_drawable_set_name (gint32 drawable_ID,
const gchar *name);
gboolean gimp_drawable_get_visible (gint32 drawable_ID);
gboolean gimp_drawable_set_visible (gint32 drawable_ID,
gboolean visible);
gboolean gimp_drawable_get_linked (gint32 drawable_ID);
gboolean gimp_drawable_set_linked (gint32 drawable_ID,
gboolean linked);
gint gimp_drawable_get_tattoo (gint32 drawable_ID);
gboolean gimp_drawable_set_tattoo (gint32 drawable_ID,
gint tattoo);
gboolean gimp_drawable_mask_bounds (gint32 drawable_ID,
gint *x1,
gint *y1,
gint *x2,
gint *y2);
gboolean gimp_drawable_mask_intersect (gint32 drawable_ID,
gint *x,
gint *y,
gint *width,
gint *height);
gboolean gimp_drawable_merge_shadow (gint32 drawable_ID,
gboolean undo);
gboolean gimp_drawable_update (gint32 drawable_ID,
gint x,
gint y,
gint width,
gint height);
guint8* gimp_drawable_get_pixel (gint32 drawable_ID,
gint x_coord,
gint y_coord,
gint *num_channels);
gboolean gimp_drawable_set_pixel (gint32 drawable_ID,
gint x_coord,
gint y_coord,
gint num_channels,
const guint8 *pixel);
gboolean gimp_drawable_fill (gint32 drawable_ID,
GimpFillType fill_type);
gboolean gimp_drawable_offset (gint32 drawable_ID,
gboolean wrap_around,
GimpOffsetType fill_type,
gint offset_x,
gint offset_y);
gboolean _gimp_drawable_thumbnail (gint32 drawable_ID,
gint width,
gint height,
gint *ret_width,
gint *ret_height,
gint *bpp,
gint *thumbnail_data_count,
guint8 **thumbnail_data);
gboolean _gimp_drawable_sub_thumbnail (gint32 drawable_ID,
gint src_x,
gint src_y,
gint src_width,
gint src_height,
gint dest_width,
gint dest_height,
gint *width,
gint *height,
gint *bpp,
gint *thumbnail_data_count,
guint8 **thumbnail_data);
gboolean gimp_drawable_foreground_extract (gint32 drawable_ID,
gint32 mask_ID);
G_END_DECLS
......
......@@ -837,6 +837,37 @@ HELP
CODE
}
sub drawable_foreground_extract {
$blurb = 'Extract the foreground of a drawable using a given trimap.';
$help = <<'HELP';
Image Segmentation by Uniform Color Clustering, see
http://www.inf.fu-berlin.de/inst/pubs/tr-b-05-07.pdf
HELP
$author = 'Gerald Friedland <fland@inf.fu-berlin.de>, Kristian Jantz <jantz@inf.fu-berlin.de>, Sven Neumann <sven@gimp.org>';
$copyright = 'Gerald Friedland';
$date = '2005';
$since = '2.4';
@inargs = (
&drawable_arg,
{ name => 'mask', type => 'drawable', desc => 'Tri-Map' }
);
%invoke = ( headers => [ qw("core/gimpdrawable-foreground-extract.h") ],
code => <<'CODE'
{
success = gimp_item_is_attached (GIMP_ITEM (drawable));
if (success)
gimp_drawable_foreground_extract (drawable, mask);
}
CODE
);
}
@headers = qw("base/tile.h" "base/tile-manager.h" "base/temp-buf.h"
"config/gimpcoreconfig.h"
"core/gimp.h" "core/gimplayer.h" "core/gimplayermask.h"
......@@ -856,7 +887,8 @@ CODE
drawable_merge_shadow drawable_update
drawable_get_pixel drawable_set_pixel
drawable_fill drawable_offset
drawable_thumbnail drawable_sub_thumbnail);
drawable_thumbnail drawable_sub_thumbnail
drawable_foreground_extract);
%exports = (app => [@procs], lib => [@procs]);
$desc = 'Drawable procedures';
......
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