Commit ef679e5d authored by Maurits Rijk's avatar Maurits Rijk
Browse files

More replacement of generic code by gimpmisc convenience funcs.

parent 4531ab27
2002-11-26 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/scatter_hsv.c
* plug-ins/common/colorify.c: use gimpmisc region iterator funcs.
2002-11-26 Michael Natterer <mitch@gimp.org>
 
* app/config/gimprc.[ch]: added "gboolean verbose" to GimpRc and
......
......@@ -89,6 +89,8 @@ static GimpRGB button_color[] =
{ 1.0, 1.0, 1.0, 1.0 },
};
static GimpRunMode run_mode;
GimpPlugInInfo PLUG_IN_INFO =
{
NULL,
......@@ -141,7 +143,6 @@ run (gchar *name,
gint *nreturn_vals,
GimpParam **return_vals)
{
GimpRunMode run_mode;
GimpPDBStatusType status;
static GimpParam values[1];
GimpDrawable *drawable;
......@@ -204,18 +205,24 @@ run (gchar *name,
values[0].data.d_status = status;
}
static void
colorify_func (guchar *src, guchar *dest, gint bpp, gpointer data)
{
gint lum = lum_red_lookup[src[0]] +
lum_green_lookup[src[1]] +
lum_blue_lookup[src[2]]; /* luminosity */
dest[0] = final_red_lookup[lum];
dest[1] = final_green_lookup[lum];
dest[2] = final_blue_lookup[lum];
if (bpp == 4)
dest[3] = src[3];
}
static void
colorify (GimpDrawable *drawable)
{
GimpPixelRgn src_rgn;
GimpPixelRgn dest_rgn;
gpointer pr;
gint progress = 0;
gint max_progress;
gint sel_x1, sel_x2, sel_y1, sel_y2;
gint sel_width, sel_height;
gint has_alpha;
gint x, y;
gint i;
for (i = 0; i < 256; i ++)
......@@ -228,67 +235,7 @@ colorify (GimpDrawable *drawable)
final_blue_lookup[i] = i * cvals.color.b;
}
gimp_drawable_mask_bounds (drawable->drawable_id,
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
sel_width = sel_x2 - sel_x1;
sel_height = sel_y2 - sel_y1;
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
max_progress = sel_width * sel_height;
if (max_progress <= 0)
return;
gimp_pixel_rgn_init (&src_rgn, drawable,
sel_x1, sel_y1, sel_width, sel_height, FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable,
sel_x1, sel_y1, sel_width, sel_height, TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
guchar *src = src_rgn.data;
guchar *dest = dest_rgn.data;
for (y = 0; y < src_rgn.h; y++)
{
guchar *s = src;
guchar *d = dest;
for (x = 0; x < src_rgn.w; x++)
{
gint lum = lum_red_lookup[s[0]] +
lum_green_lookup[s[1]] +
lum_blue_lookup[s[2]]; /* luminosity */
d[0] = final_red_lookup[lum];
d[1] = final_green_lookup[lum];
d[2] = final_blue_lookup[lum];
if (has_alpha)
d[3] = s[3];
s += src_rgn.bpp;
d += dest_rgn.bpp;
}
src += src_rgn.rowstride;
dest += dest_rgn.rowstride;
}
/* Update progress */
progress += src_rgn.w * src_rgn.h;
gimp_progress_update ((gdouble) progress / (gdouble) max_progress);
}
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id,
sel_x1, sel_y1, sel_width, sel_height);
gimp_rgn_iterate2 (drawable, run_mode, colorify_func, NULL);
}
static gboolean
......@@ -363,7 +310,7 @@ colorify_dialog (GimpRGB *color)
gtk_container_add (GTK_CONTAINER (button), color_area);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (predefined_color_callback),
color_area);
&button_color[i]);
gtk_widget_show (color_area);
gtk_table_attach (GTK_TABLE (table), button, i, i + 1, 1, 2,
......@@ -392,9 +339,6 @@ static void
predefined_color_callback (GtkWidget *widget,
gpointer data)
{
GimpRGB color;
gimp_color_area_get_color (GIMP_COLOR_AREA (data), &color);
gimp_color_button_set_color (GIMP_COLOR_BUTTON (custum_color_button),
&color);
(GimpRGB*) data);
}
......@@ -24,7 +24,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
......@@ -77,6 +76,8 @@ static void scatter_hsv_iscale_update (GtkAdjustment *adjustment,
static gint preview_width = PREVIEW_WIDTH;
static gint preview_height = PREVIEW_HEIGHT;
static GimpRunMode run_mode;
GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
......@@ -161,7 +162,6 @@ run (gchar *name,
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
GimpRunMode run_mode;
run_mode = param[0].data.d_int32;
drawable_id = param[2].data.d_int32;
......@@ -209,73 +209,38 @@ run (gchar *name,
values[0].data.d_status = status;
}
static void
scatter_hsv_func (guchar *src, guchar *dest, gint bpp, gpointer data)
{
guchar h, s, v;
h = src[0];
s = src[1];
v = src[2];
scatter_hsv_scatter (&h, &s, &v);
dest[0] = h;
dest[1] = s;
dest[2] = v;
if (bpp == 4)
dest[3] = src[3];
}
static GimpPDBStatusType
scatter_hsv (gint32 drawable_id)
{
GimpDrawable *drawable;
GimpPixelRgn src_rgn, dest_rgn;
guchar *src, *dest;
gpointer pr;
gint x, y, x1, x2, y1, y2;
gint gap, total, processed = 0;
drawable = gimp_drawable_get (drawable_id);
gap = (gimp_drawable_has_alpha (drawable_id)) ? 1 : 0;
gimp_drawable_mask_bounds (drawable_id, &x1, &y1, &x2, &y2);
total = (x2 - x1) * (y2 - y1);
if (total < 1)
return GIMP_PDB_EXECUTION_ERROR;
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
gimp_progress_init (_("Scatter HSV: Scattering..."));
pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
for (; pr != NULL; pr = gimp_pixel_rgns_process (pr))
{
int offset;
for (y = 0; y < src_rgn.h; y++)
{
src = src_rgn.data + y * src_rgn.rowstride;
dest = dest_rgn.data + y * dest_rgn.rowstride;
offset = 0;
for (x = 0; x < src_rgn.w; x++)
{
guchar h, s, v;
h = *(src + offset);
s = *(src + offset + 1);
v = *(src + offset + 2);
scatter_hsv_scatter (&h, &s, &v);
*(dest + offset ) = (guchar) h;
*(dest + offset + 1) = (guchar) s;
*(dest + offset + 2) = (guchar) v;
offset += 3;
if (gap)
{
*(dest + offset) = *(src + offset);
offset++;
}
/* the function */
if ((++processed % (total / PROGRESS_UPDATE_NUM + 1)) == 0)
gimp_progress_update ((double) processed /(double) total);
}
}
}
gimp_rgn_iterate2 (drawable, run_mode, scatter_hsv_func, NULL);
gimp_progress_update (1.0);
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
gimp_drawable_detach (drawable);
return GIMP_PDB_SUCCESS;
......
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