Fixes bug 50911. Details there.

files: plug-ins/common/sparkle.c
This commit is contained in:
Seth Burgess
2003-09-17 05:21:08 +00:00
parent 72c5bb6c73
commit d9996103cc
2 changed files with 354 additions and 329 deletions

View File

@ -1,3 +1,9 @@
2003-09-17 Seth Burgess <sjburges@gimp.org>
* plug-ins/common/sparkle.c: use the rowstride of a pixel region
because you never know when you're starting on a selection. Fixes
bug #50911.
2003-09-17 Simon Budig <simon@gimp.org> 2003-09-17 Simon Budig <simon@gimp.org>
* app/tools/gimpvectortool.c: Ok, since the obsolete undo * app/tools/gimpvectortool.c: Ok, since the obsolete undo

View File

@ -1,7 +1,9 @@
/* Sparkle --- image filter plug-in for The Gimp image manipulation program /* Sparkle --- image filter plug-in for The Gimp image manipulation program
* Copyright (C) 1996 by John Beale; ported to Gimp by Michael J. Hammel; * Copyright (C) 1996 by John Beale; ported to Gimp by Michael J. Hammel;
* It has been optimized a little, bugfixed and modified by Martin Weber * It has been optimized a little, bugfixed and modified by Martin Weber
* for additional functionality. * for additional functionality. Also bugfixed by Seth Burgess (9/17/03)
* to take rowstrides into account when selections are present (bug #50911).
* Attempted reformatting.
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -19,11 +21,11 @@
* *
* You can contact Michael at mjhammel@csn.net * You can contact Michael at mjhammel@csn.net
* You can contact Martin at martweb@gmx.net * You can contact Martin at martweb@gmx.net
* Note: set tabstops to 3 to make this more readable. * You can contact Seth at sjburges@gimp.org
*/ */
/* /*
* Sparkle 1.26 - simulate pixel bloom and diffraction effects * Sparkle 1.27 - simulate pixel bloom and diffraction effects
*/ */
#include "config.h" #include "config.h"
@ -184,12 +186,11 @@ query (void)
gimp_install_procedure ("plug_in_sparkle", gimp_install_procedure ("plug_in_sparkle",
"Simulates pixel bloom and diffraction effects", "Simulates pixel bloom and diffraction effects",
"No help yet", "Uses a percentage based luminoisty threhsold to find "
"John Beale, & (ported to GIMP v0.54) Michael J. Hammel & ted to GIMP v1.0) Spencer Kimball", "candidate pixels for adding some sparkles (spikes). ",
"John Beale, & (ported to GIMP v0.54) Michael J. Hammel & ted to GIMP v1.0) & Seth Burgess & Spencer Kimball",
"John Beale", "John Beale",
"Version 1.26, December 1998", "Version 1.27, September 2003",
/* don't translate '<Image>', it's a special
* keyword for the gtk toolkit */
N_("<Image>/Filters/Light Effects/_Sparkle..."), N_("<Image>/Filters/Light Effects/_Sparkle..."),
"RGB*, GRAY*", "RGB*, GRAY*",
GIMP_PLUGIN, GIMP_PLUGIN,
@ -359,7 +360,7 @@ sparkle_dialog (void)
NULL); NULL);
/* parameter settings */ /* parameter settings */
main_vbox = gimp_parameter_settings_new (GTK_DIALOG (dlg)->vbox, 1, 3); main_vbox = gimp_parameter_settings_new (GTK_DIALOG (dlg)->vbox, 0, 0);
table = gtk_table_new (9, 3, FALSE); table = gtk_table_new (9, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4); gtk_table_set_col_spacings (GTK_TABLE (table), 4);
@ -597,7 +598,6 @@ compute_lum_threshold (GimpDrawable *drawable,
guchar *data; guchar *data;
gint values[256]; gint values[256];
gint total, sum; gint total, sum;
gint size;
gint gray; gint gray;
gint has_alpha; gint has_alpha;
gint i; gint i;
@ -618,14 +618,18 @@ compute_lum_threshold (GimpDrawable *drawable,
pr != NULL; pr != NULL;
pr = gimp_pixel_rgns_process (pr)) pr = gimp_pixel_rgns_process (pr))
{ {
int sx, sy;
data = src_rgn.data; data = src_rgn.data;
size = src_rgn.w * src_rgn.h;
while (size--) for (sy = 0; sy<src_rgn.h; sy++)
{
for(sx = 0; sx<src_rgn.w; sx++)
{ {
values [compute_luminosity (data, gray, has_alpha)]++; values [compute_luminosity (data, gray, has_alpha)]++;
data += src_rgn.bpp; data += src_rgn.bpp;
} }
data+=src_rgn.rowstride-(src_rgn.w*src_rgn.bpp);
}
} }
total = (x2 - x1) * (y2 - y1); total = (x2 - x1) * (y2 - y1);
@ -640,7 +644,6 @@ compute_lum_threshold (GimpDrawable *drawable,
return i; return i;
} }
} }
return 0; return 0;
} }
@ -653,7 +656,7 @@ sparkle (GimpDrawable *drawable,
gdouble nfrac, length, inten, spike_angle; gdouble nfrac, length, inten, spike_angle;
gint cur_progress, max_progress; gint cur_progress, max_progress;
gint x1, y1, x2, y2; gint x1, y1, x2, y2;
gint size, lum, x, y, b; gint lum, x, y, b;
gint gray; gint gray;
gint has_alpha, alpha; gint has_alpha, alpha;
gpointer pr; gpointer pr;
@ -673,6 +676,7 @@ sparkle (GimpDrawable *drawable,
cur_progress = 0; cur_progress = 0;
max_progress = num_sparkles; max_progress = num_sparkles;
/* copy what is already there */
gimp_pixel_rgn_init (&src_rgn, drawable, gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE); x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable, gimp_pixel_rgn_init (&dest_rgn, drawable,
@ -682,12 +686,14 @@ sparkle (GimpDrawable *drawable,
pr != NULL; pr != NULL;
pr = gimp_pixel_rgns_process (pr)) pr = gimp_pixel_rgns_process (pr))
{ {
int sx, sy;
src = src_rgn.data; src = src_rgn.data;
dest = dest_rgn.data; dest = dest_rgn.data;
size = src_rgn.w * src_rgn.h; for (sy=0; sy<src_rgn.h; sy++)
{
while (size --) for (sx=0; sx<src_rgn.w; sx++)
{ {
if(has_alpha && src[alpha] == 0) if(has_alpha && src[alpha] == 0)
{ {
@ -706,9 +712,12 @@ sparkle (GimpDrawable *drawable,
src += src_rgn.bpp; src += src_rgn.bpp;
} }
src += src_rgn.rowstride- (src_rgn.bpp * src_rgn.w);
dest += dest_rgn.rowstride- (dest_rgn.bpp * dest_rgn.w);
}
} }
/* add effects to new image based on intensity of old pixels */ /* add effects to new image based on intensity of old pixels */
gimp_pixel_rgn_init (&src_rgn, drawable, gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE); x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable, gimp_pixel_rgn_init (&dest_rgn, drawable,
@ -719,8 +728,8 @@ sparkle (GimpDrawable *drawable,
pr = gimp_pixel_rgns_process (pr)) pr = gimp_pixel_rgns_process (pr))
{ {
src = src_rgn.data; src = src_rgn.data;
for (y = 0; y < src_rgn.h; y++) for (y = 0; y < src_rgn.h; y++)
{
for (x = 0; x < src_rgn.w; x++) for (x = 0; x < src_rgn.w; x++)
{ {
if (svals.border) if (svals.border)
@ -744,12 +753,14 @@ sparkle (GimpDrawable *drawable,
/* fspike im x,y intens rlength angle */ /* fspike im x,y intens rlength angle */
if (svals.spike_pts > 0) if (svals.spike_pts > 0)
{ {
gdouble random_1 = g_rand_double(gr);
/* major spikes */ /* major spikes */
if (svals.spike_angle == -1) if (svals.spike_angle == -1)
spike_angle = g_rand_double_range (gr, 0, 360.0); spike_angle = g_rand_double_range (gr, 0, 360.0);
else else
spike_angle = svals.spike_angle; spike_angle = svals.spike_angle;
if (g_rand_double (gr) <= svals.density)
if (random_1 <= svals.density)
{ {
fspike (&src_rgn, &dest_rgn, gray, x1, y1, x2, y2, fspike (&src_rgn, &dest_rgn, gray, x1, y1, x2, y2,
x + src_rgn.x, y + src_rgn.y, x + src_rgn.x, y + src_rgn.y,
@ -760,7 +771,8 @@ sparkle (GimpDrawable *drawable,
x + src_rgn.x, y + src_rgn.y, x + src_rgn.x, y + src_rgn.y,
tile_width, tile_height, tile_width, tile_height,
inten * 0.7, length * 0.7, inten * 0.7, length * 0.7,
((gdouble) spike_angle + 180.0 / svals.spike_pts), gr); ((gdouble)spike_angle+180.0/svals.spike_pts),
gr);
} }
} }
cur_progress ++; cur_progress ++;
@ -770,8 +782,9 @@ sparkle (GimpDrawable *drawable,
} }
src += src_rgn.bpp; src += src_rgn.bpp;
} }
src += src_rgn.rowstride - (src_rgn.w * src_rgn.bpp);
}
} }
gimp_progress_update (1.0); gimp_progress_update (1.0);
/* update the blurred region */ /* update the blurred region */
@ -846,13 +859,13 @@ rpnt (GimpDrawable *drawable,
new -= val * color[b] * (1.0 - svals.opacity); new -= val * color[b] * (1.0 - svals.opacity);
if (new < 0.0) if (new < 0.0)
new = 0.0; new = 0.0;
} }
} }
new *= 1.0 - val * svals.opacity; new *= 1.0 - val * svals.opacity;
new += val * color[b]; new += val * color[b];
if (new > 255) new = 255; if (new > 255)
new = 255;
if (svals.invers != FALSE) if (svals.invers != FALSE)
pixel[b] = 255 - new; pixel[b] = 255 - new;
@ -860,7 +873,6 @@ rpnt (GimpDrawable *drawable,
pixel[b] = new; pixel[b] = new;
} }
} }
return tile; return tile;
} }
@ -922,7 +934,7 @@ fspike (GimpPixelRgn *src_rgn,
for (i = 0; i < svals.spike_pts; i++) for (i = 0; i < svals.spike_pts; i++)
{ {
if (svals.colortype == NATURAL) if (svals.colortype == NATURAL)
gimp_pixel_rgn_get_pixel (dest_rgn, pixel, xr, yr); gimp_pixel_rgn_get_pixel (src_rgn, pixel, xr, yr);
color[0] = pixel[0]; color[0] = pixel[0];
color[1] = pixel[1]; color[1] = pixel[1];
@ -968,10 +980,18 @@ fspike (GimpPixelRgn *src_rgn,
if (in > 0.01) if (in > 0.01)
ok = TRUE; ok = TRUE;
tile = rpnt (dest_rgn->drawable, tile, x1, y1, x2, y2, xrt, yrt, tile_width, tile_height, &row, &col, bytes, in, color); tile = rpnt (dest_rgn->drawable, tile, x1, y1, x2, y2,
tile = rpnt (dest_rgn->drawable, tile, x1, y1, x2, y2, xrt + 1.0, yrt, tile_width, tile_height, &row, &col, bytes, in, color); xrt, yrt, tile_width, tile_height,
tile = rpnt (dest_rgn->drawable, tile, x1, y1, x2, y2, xrt + 1.0, yrt + 1.0, tile_width, tile_height, &row, &col, bytes, in, color); &row, &col, bytes, in, color);
tile = rpnt (dest_rgn->drawable, tile, x1, y1, x2, y2, xrt, yrt + 1.0, tile_width, tile_height, &row, &col, bytes, in, color); tile = rpnt (dest_rgn->drawable, tile, x1, y1, x2, y2,
xrt + 1.0, yrt, tile_width, tile_height,
&row, &col, bytes, in, color);
tile = rpnt (dest_rgn->drawable, tile, x1, y1, x2, y2,
xrt + 1.0, yrt + 1.0, tile_width, tile_height,
&row, &col, bytes, in, color);
tile = rpnt (dest_rgn->drawable, tile, x1, y1, x2, y2,
xrt, yrt + 1.0, tile_width, tile_height,
&row, &col, bytes, in, color);
xrt += dx; xrt += dx;
yrt += dy; yrt += dy;
@ -990,6 +1010,5 @@ sparkle_ok_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
sint.run = TRUE; sint.run = TRUE;
gtk_widget_destroy (GTK_WIDGET (data)); gtk_widget_destroy (GTK_WIDGET (data));
} }