Commit 318e76b7 authored by Maurits Rijk's avatar Maurits Rijk
Browse files

Extracted a few reusable routines from several plug-ins and introduced them....

Extracted a few reusable routines from several plug-ins and introduced them. The imagemap plug-in now uses the stock Gimp grid icon.
parent b80ed8a5
2003-09-13 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/imagemap/grid.xpm: removed
* plug-ins/imagemap/Makefile.am: removed grid.xpm from distribution
* plug-ins/imagemap/imap_stock.[ch]
* plug-ins/imagemap/imap_toolbar.c: use gimp stock icon for grid
2003-09-13 Maurits Rijk <lpeek.mrijk@consunet.nl>
* libgimp/gimpmiscui.[ch]
* libgimp/gimpmisc.[ch]: a few more reusable routines extracted from
several plug-ins.
* plug-ins/common/align_layers.c:
* plug-ins/common/apply_lens.c
* plug-ins/common/blinds.c
* plug-ins/common/blur.c
* plug-ins/common/bumpmap.c
* plug-ins/common/checkerboard.c
* plug-ins/common/cubism.c
* plug-ins/common/despeckle.c
* plug-ins/common/destripe.c
* plug-ins/common/edge.c
* plug-ins/common/emboss.c
* plug-ins/common/engrave.c
* plug-ins/common/gauss_iir.c
* plug-ins/common/gauss_rle.c
* plug-ins/common/glasstile.c
* plug-ins/common/grid.c
* plug-ins/common/illusion.c
* plug-ins/common/jpeg.c
* plug-ins/common/lic.c
* plug-ins/common/mapcolor.c
* plug-ins/common/nlfilt.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/oilify.c
* plug-ins/common/pixelize.c
* plug-ins/common/plasma.c
* plug-ins/common/polar.c
* plug-ins/common/randomize.c
* plug-ins/common/ripple.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/sel_gauss.c
* plug-ins/common/sharpen.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sobel.c
* plug-ins/common/sparkle.c
* plug-ins/common/struc.c
* plug-ins/common/threshold_alpha.c
* plug-ins/common/tileit.c
* plug-ins/common/unsharp.c
* plug-ins/common/vpropagate.c
* plug-ins/common/waves.c
* plug-ins/common/whirlpinch.c
* plug-ins/common/wind.c
* plug-ins/common/xpm.c: use new stuff from libgimp/gimpmiscui.[ch]
plus some minor cleanup like removing unused header files (for
example signal.h)
2003-09-13 Sven Neumann <sven@gimp.org>
 
* app/core/core-enums.[ch]
......@@ -49,6 +49,12 @@ struct _GimpPixelFetcher
gboolean shadow;
};
struct _GimpRgnIterator
{
GimpDrawable *drawable;
gint x1, y1, x2, y2;
GimpRunMode run_mode;
};
GimpPixelFetcher *
gimp_pixel_fetcher_new (GimpDrawable *drawable)
......@@ -258,34 +264,31 @@ gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
g_free (pf);
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
static void
gimp_get_color_guchar (GimpDrawable *drawable,
GimpRGB *color,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
switch (gimp_drawable_type (drawable->drawable_id))
{
case GIMP_RGB_IMAGE :
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
gimp_rgb_get_uchar (color, &bg[0], &bg[1], &bg[2]);
bg[3] = 255;
break;
case GIMP_RGBA_IMAGE:
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
gimp_rgb_get_uchar (color, &bg[0], &bg[1], &bg[2]);
bg[3] = transparent ? 0 : 255;
break;
case GIMP_GRAY_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[0] = gimp_rgb_intensity_uchar (color);
bg[1] = 255;
break;
case GIMP_GRAYA_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[0] = gimp_rgb_intensity_uchar (color);
bg[1] = transparent ? 0 : 255;
break;
......@@ -294,6 +297,116 @@ gimp_get_bg_guchar (GimpDrawable *drawable,
}
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
gimp_get_color_guchar (drawable, &background, transparent, bg);
}
void
gimp_get_fg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *fg)
{
GimpRGB foreground;
gimp_palette_get_foreground (&foreground);
gimp_get_color_guchar (drawable, &foreground, transparent, fg);
}
GimpRgnIterator*
gimp_rgn_iterator_new (GimpDrawable *drawable, GimpRunMode run_mode)
{
GimpRgnIterator *iter = g_new (GimpRgnIterator, 1);
iter->drawable = drawable;
iter->run_mode = run_mode;
gimp_drawable_mask_bounds (drawable->drawable_id, &iter->x1, &iter->y1,
&iter->x2, &iter->y2);
return iter;
}
void
gimp_rgn_iterator_free (GimpRgnIterator *iter)
{
g_free (iter);
}
static void
gimp_rgn_iterator_iter_single (GimpRgnIterator *iter, GimpPixelRgn *srcPR,
GimpRgnFuncSrc func, gpointer data)
{
gpointer pr;
gint total_area, area_so_far;
total_area = (iter->x2 - iter->x1) * (iter->y2 - iter->y1);
area_so_far = 0;
for (pr = gimp_pixel_rgns_register (1, srcPR);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
guchar *src = srcPR->data;
gint y;
for (y = srcPR->y; y < srcPR->y + srcPR->h; y++)
{
guchar *s = src;
gint x;
for (x = srcPR->x; x < srcPR->x + srcPR->w; x++)
{
func (x, y, s, srcPR->bpp, data);
s += srcPR->bpp;
}
src += srcPR->rowstride;
}
if (iter->run_mode != GIMP_RUN_NONINTERACTIVE)
{
area_so_far += srcPR->w * srcPR->h;
gimp_progress_update ((gdouble) area_so_far /
(gdouble) total_area);
}
}
}
void
gimp_rgn_iterator_src (GimpRgnIterator *iter, GimpRgnFuncSrc func,
gpointer data)
{
GimpPixelRgn srcPR;
gimp_pixel_rgn_init (&srcPR, iter->drawable, iter->x1, iter->y1,
iter->x2 - iter->x1, iter->y2 - iter->y1, FALSE, FALSE);
gimp_rgn_iterator_iter_single (iter, &srcPR, func, data);
}
void
gimp_rgn_iterator_dest (GimpRgnIterator *iter,
GimpRgnFuncDest func,
gpointer data)
{
GimpPixelRgn destPR;
gimp_pixel_rgn_init (&destPR, iter->drawable, iter->x1, iter->y1,
iter->x2 - iter->x1, iter->y2 - iter->y1, TRUE, TRUE);
gimp_rgn_iterator_iter_single (iter, &destPR, func, data);
/* update the processed region */
gimp_drawable_flush (iter->drawable);
gimp_drawable_merge_shadow (iter->drawable->drawable_id, TRUE);
gimp_drawable_update (iter->drawable->drawable_id, iter->x1, iter->y1,
iter->x2 - iter->x1, iter->y2 - iter->y1);
}
static void
gimp_rgn_render_row (guchar *src,
guchar *dest,
......
......@@ -39,7 +39,7 @@ enum
};
typedef struct _GimpPixelFetcher GimpPixelFetcher;
typedef struct _GimpRgnIterator GimpRgnIterator;
GimpPixelFetcher * gimp_pixel_fetcher_new (GimpDrawable *drawable);
void gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf);
......@@ -64,6 +64,9 @@ void gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf);
void gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg);
void gimp_get_fg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *fg);
typedef void (* GimpRgnFunc1) (const guchar *src,
......@@ -73,6 +76,22 @@ typedef void (* GimpRgnFunc2) (const guchar *src,
guchar *dest,
gint bpp,
gpointer data);
typedef void (* GimpRgnFuncSrc) (gint x,
gint y,
guchar *src,
gint bpp,
gpointer data);
typedef GimpRgnFuncSrc GimpRgnFuncDest;
GimpRgnIterator *gimp_rgn_iterator_new (GimpDrawable *drawable,
GimpRunMode run_mode);
void gimp_rgn_iterator_free (GimpRgnIterator *iter);
void gimp_rgn_iterator_src (GimpRgnIterator *iter,
GimpRgnFuncSrc func,
gpointer data);
void gimp_rgn_iterator_dest (GimpRgnIterator *iter,
GimpRgnFuncDest func,
gpointer data);
void gimp_rgn_iterate1 (GimpDrawable *drawable,
GimpRunMode run_mode,
......
......@@ -546,3 +546,34 @@ gimp_plug_in_get_path (const gchar *path_name,
return path;
}
GtkWidget*
gimp_parameter_settings_new (GtkWidget *parent,
guint rows,
guint columns)
{
GtkWidget *frame, *table;
frame = gtk_frame_new ( _("Parameter Settings"));
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start ( GTK_BOX (parent), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
if (rows && columns)
{
table = gtk_table_new (rows, columns, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
gtk_container_add (GTK_CONTAINER (frame), table);
}
else
{
table = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
gtk_container_add (GTK_CONTAINER (frame), table);
}
gtk_widget_show (table);
return table;
}
......@@ -98,6 +98,10 @@ gchar * gimp_plug_in_get_path (const gchar *path_name,
const gchar *dir_name);
GtkWidget *gimp_parameter_settings_new (GtkWidget *parent,
guint rows,
guint columns);
G_END_DECLS
#endif /* __GIMP_MISCUI_H__ */
......@@ -49,6 +49,12 @@ struct _GimpPixelFetcher
gboolean shadow;
};
struct _GimpRgnIterator
{
GimpDrawable *drawable;
gint x1, y1, x2, y2;
GimpRunMode run_mode;
};
GimpPixelFetcher *
gimp_pixel_fetcher_new (GimpDrawable *drawable)
......@@ -258,34 +264,31 @@ gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
g_free (pf);
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
static void
gimp_get_color_guchar (GimpDrawable *drawable,
GimpRGB *color,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
switch (gimp_drawable_type (drawable->drawable_id))
{
case GIMP_RGB_IMAGE :
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
gimp_rgb_get_uchar (color, &bg[0], &bg[1], &bg[2]);
bg[3] = 255;
break;
case GIMP_RGBA_IMAGE:
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
gimp_rgb_get_uchar (color, &bg[0], &bg[1], &bg[2]);
bg[3] = transparent ? 0 : 255;
break;
case GIMP_GRAY_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[0] = gimp_rgb_intensity_uchar (color);
bg[1] = 255;
break;
case GIMP_GRAYA_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[0] = gimp_rgb_intensity_uchar (color);
bg[1] = transparent ? 0 : 255;
break;
......@@ -294,6 +297,116 @@ gimp_get_bg_guchar (GimpDrawable *drawable,
}
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
gimp_get_color_guchar (drawable, &background, transparent, bg);
}
void
gimp_get_fg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *fg)
{
GimpRGB foreground;
gimp_palette_get_foreground (&foreground);
gimp_get_color_guchar (drawable, &foreground, transparent, fg);
}
GimpRgnIterator*
gimp_rgn_iterator_new (GimpDrawable *drawable, GimpRunMode run_mode)
{
GimpRgnIterator *iter = g_new (GimpRgnIterator, 1);
iter->drawable = drawable;
iter->run_mode = run_mode;
gimp_drawable_mask_bounds (drawable->drawable_id, &iter->x1, &iter->y1,
&iter->x2, &iter->y2);
return iter;
}
void
gimp_rgn_iterator_free (GimpRgnIterator *iter)
{
g_free (iter);
}
static void
gimp_rgn_iterator_iter_single (GimpRgnIterator *iter, GimpPixelRgn *srcPR,
GimpRgnFuncSrc func, gpointer data)
{
gpointer pr;
gint total_area, area_so_far;
total_area = (iter->x2 - iter->x1) * (iter->y2 - iter->y1);
area_so_far = 0;
for (pr = gimp_pixel_rgns_register (1, srcPR);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
guchar *src = srcPR->data;
gint y;
for (y = srcPR->y; y < srcPR->y + srcPR->h; y++)
{
guchar *s = src;
gint x;
for (x = srcPR->x; x < srcPR->x + srcPR->w; x++)
{
func (x, y, s, srcPR->bpp, data);
s += srcPR->bpp;
}
src += srcPR->rowstride;
}
if (iter->run_mode != GIMP_RUN_NONINTERACTIVE)
{
area_so_far += srcPR->w * srcPR->h;
gimp_progress_update ((gdouble) area_so_far /
(gdouble) total_area);
}
}
}
void
gimp_rgn_iterator_src (GimpRgnIterator *iter, GimpRgnFuncSrc func,
gpointer data)
{
GimpPixelRgn srcPR;
gimp_pixel_rgn_init (&srcPR, iter->drawable, iter->x1, iter->y1,
iter->x2 - iter->x1, iter->y2 - iter->y1, FALSE, FALSE);
gimp_rgn_iterator_iter_single (iter, &srcPR, func, data);
}
void
gimp_rgn_iterator_dest (GimpRgnIterator *iter,
GimpRgnFuncDest func,
gpointer data)
{
GimpPixelRgn destPR;
gimp_pixel_rgn_init (&destPR, iter->drawable, iter->x1, iter->y1,
iter->x2 - iter->x1, iter->y2 - iter->y1, TRUE, TRUE);
gimp_rgn_iterator_iter_single (iter, &destPR, func, data);
/* update the processed region */
gimp_drawable_flush (iter->drawable);
gimp_drawable_merge_shadow (iter->drawable->drawable_id, TRUE);
gimp_drawable_update (iter->drawable->drawable_id, iter->x1, iter->y1,
iter->x2 - iter->x1, iter->y2 - iter->y1);
}
static void
gimp_rgn_render_row (guchar *src,
guchar *dest,
......
......@@ -39,7 +39,7 @@ enum
};
typedef struct _GimpPixelFetcher GimpPixelFetcher;
typedef struct _GimpRgnIterator GimpRgnIterator;
GimpPixelFetcher * gimp_pixel_fetcher_new (GimpDrawable *drawable);
void gimp_pixel_fetcher_set_bg_color (GimpPixelFetcher *pf);
......@@ -64,6 +64,9 @@ void gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf);
void gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg);
void gimp_get_fg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *fg);
typedef void (* GimpRgnFunc1) (const guchar *src,
......@@ -73,6 +76,22 @@ typedef void (* GimpRgnFunc2) (const guchar *src,
guchar *dest,
gint bpp,
gpointer data);
typedef void (* GimpRgnFuncSrc) (gint x,
gint y,
guchar *src,
gint bpp,
gpointer data);
typedef GimpRgnFuncSrc GimpRgnFuncDest;
GimpRgnIterator *gimp_rgn_iterator_new (GimpDrawable *drawable,
GimpRunMode run_mode);
void gimp_rgn_iterator_free (GimpRgnIterator *iter);
void gimp_rgn_iterator_src (GimpRgnIterator *iter,
GimpRgnFuncSrc func,
gpointer data);
void gimp_rgn_iterator_dest (GimpRgnIterator *iter,
GimpRgnFuncDest func,
gpointer data);
void gimp_rgn_iterate1 (GimpDrawable *drawable,
GimpRunMode run_mode,
......
......@@ -49,6 +49,12 @@ struct _GimpPixelFetcher
gboolean shadow;
};
struct _GimpRgnIterator
{
GimpDrawable *drawable;
gint x1, y1, x2, y2;
GimpRunMode run_mode;
};
GimpPixelFetcher *
gimp_pixel_fetcher_new (GimpDrawable *drawable)
......@@ -258,34 +264,31 @@ gimp_pixel_fetcher_destroy (GimpPixelFetcher *pf)
g_free (pf);
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
static void
gimp_get_color_guchar (GimpDrawable *drawable,
GimpRGB *color,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
switch (gimp_drawable_type (drawable->drawable_id))
{
case GIMP_RGB_IMAGE :
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
gimp_rgb_get_uchar (color, &bg[0], &bg[1], &bg[2]);
bg[3] = 255;
break;
case GIMP_RGBA_IMAGE:
gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
gimp_rgb_get_uchar (color, &bg[0], &bg[1], &bg[2]);
bg[3] = transparent ? 0 : 255;
break;
case GIMP_GRAY_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[0] = gimp_rgb_intensity_uchar (color);
bg[1] = 255;
break;
case GIMP_GRAYA_IMAGE:
bg[0] = gimp_rgb_intensity_uchar (&background);
bg[0] = gimp_rgb_intensity_uchar (color);
bg[1] = transparent ? 0 : 255;
break;
......@@ -294,6 +297,116 @@ gimp_get_bg_guchar (GimpDrawable *drawable,
}
}
void
gimp_get_bg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *bg)
{
GimpRGB background;
gimp_palette_get_background (&background);
gimp_get_color_guchar (drawable, &background, transparent, bg);
}
void
gimp_get_fg_guchar (GimpDrawable *drawable,
gboolean transparent,
guchar *fg)
{
GimpRGB foreground;
gimp_palette_get_foreground (&foreground);
gimp_get_color_guchar (drawable, &foreground, transparent, fg);