Commit 5784e3ee authored by Maurits Rijk's avatar Maurits Rijk

HIGified, fixed indendation, speed improvement (around 70 %).

parent 0cc32e99
2004-05-18 Maurits Rijk <m.rijk@chello.nl>
* plug-ins/common/sel_gauss.c: HIGified, fixed indendation, speed
improvement (around 70 %).
2004-05-18 Sven Neumann <sven@gimp.org> 2004-05-18 Sven Neumann <sven@gimp.org>
* plug-ins/common/blur.c * plug-ins/common/blur.c
......
...@@ -19,12 +19,6 @@ ...@@ -19,12 +19,6 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
*
* Changelog:
*
* v0.1 990202, TVO
* First release
*
* To do: * To do:
* - support for horizontal or vertical only blur * - support for horizontal or vertical only blur
* - use memory more efficiently, smaller regions at a time * - use memory more efficiently, smaller regions at a time
...@@ -36,9 +30,6 @@ ...@@ -36,9 +30,6 @@
*/ */
#include "config.h" #include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libgimp/gimp.h> #include <libgimp/gimp.h>
...@@ -221,7 +212,6 @@ static gint ...@@ -221,7 +212,6 @@ static gint
sel_gauss_dialog (void) sel_gauss_dialog (void)
{ {
GtkWidget *dlg; GtkWidget *dlg;
GtkWidget *frame;
GtkWidget *table; GtkWidget *table;
GtkWidget *spinbutton; GtkWidget *spinbutton;
GtkObject *adj; GtkObject *adj;
...@@ -238,17 +228,12 @@ sel_gauss_dialog (void) ...@@ -238,17 +228,12 @@ sel_gauss_dialog (void)
NULL); NULL);
/* parameter settings */
frame = gtk_frame_new (_("Parameter Settings"));
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame,
TRUE, TRUE, 0);
table = gtk_table_new (2, 3, FALSE); table = gtk_table_new (2, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4); gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2); gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 4); gtk_container_set_border_width (GTK_CONTAINER (table), 12);
gtk_container_add (GTK_CONTAINER (frame), table); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), table,
TRUE, TRUE, 0);
spinbutton = gimp_spin_button_new (&adj, spinbutton = gimp_spin_button_new (&adj,
bvals.radius, 0.0, G_MAXINT, 1.0, 5.0, bvals.radius, 0.0, G_MAXINT, 1.0, 5.0,
...@@ -270,7 +255,6 @@ sel_gauss_dialog (void) ...@@ -270,7 +255,6 @@ sel_gauss_dialog (void)
&bvals.maxdelta); &bvals.maxdelta);
gtk_widget_show (table); gtk_widget_show (table);
gtk_widget_show (frame);
gtk_widget_show (dlg); gtk_widget_show (dlg);
run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK); run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
...@@ -290,14 +274,14 @@ init_matrix (gdouble radius, ...@@ -290,14 +274,14 @@ init_matrix (gdouble radius,
/* This formula isn't really correct, but it'll do */ /* This formula isn't really correct, but it'll do */
sd = radius / 3.329042969; sd = radius / 3.329042969;
c1 = 1.0 / sqrt(2.0 * G_PI * sd); c1 = 1.0 / sqrt (2.0 * G_PI * sd);
c2 = -2.0 * (sd * sd); c2 = -2.0 * (sd * sd);
for (dy=0; dy<num; dy++) for (dy = 0; dy < num; dy++)
{ {
for (dx=dy; dx<num; dx++) for (dx = dy; dx < num; dx++)
{ {
mat[dx][dy] = c1 * exp(((dx*dx)+ (dy*dy))/ c2); mat[dx][dy] = c1 * exp ((dx * dx + dy * dy)/ c2);
mat[dy][dx] = mat[dx][dy]; mat[dy][dx] = mat[dx][dy];
} }
} }
...@@ -316,53 +300,70 @@ matrixmult (guchar *src, ...@@ -316,53 +300,70 @@ matrixmult (guchar *src,
{ {
gint i, j, b, nb, x, y; gint i, j, b, nb, x, y;
gint six, dix, tmp; gint six, dix, tmp;
gdouble sum, fact, d, alpha=1.0; gint rowstride;
gdouble sum, fact, d, alpha = 1.0;
guchar *src_b, *src_db;
gdouble *m;
gint offset;
nb = bytes - (has_alpha?1:0); nb = bytes - (has_alpha ? 1 : 0);
rowstride = width * bytes;
for (y = 0; y< height; y++) for (y = 0; y < height; y++)
{ {
for (x = 0; x< width; x++) for (x = 0; x < width; x++)
{ {
dix = (bytes*((width*y)+x)); dix = bytes * (width * y + x);
if (has_alpha) if (has_alpha)
dest[dix+nb] = src[dix+nb]; dest[dix + nb] = src[dix + nb];
for (b=0; b<nb; b++)
for (b = 0; b < nb; b++)
{ {
sum = 0.0; sum = 0.0;
fact = 0.0; fact = 0.0;
for (i= 1-numrad; i<numrad; i++) src_db = src + dix + b;
offset = rowstride * (y - numrad) + bytes * (x - numrad);
for (i = 1 - numrad; i < numrad; i++)
{ {
if (((x+i)< 0) || ((x+i)>= width)) offset += bytes;
if (x + i < 0 || x + i >= width)
continue; continue;
for (j= 1-numrad; j<numrad; j++)
six = offset;
m = mat[ABS(i)];
src_b = src + six + b;
for (j = 1 - numrad; j < numrad; j++)
{ {
if (((y+j)<0)||((y+j)>=height)) src_b += rowstride;
six += rowstride;
if (y + j < 0 || y + j >= height)
continue; continue;
six = (bytes*((width*(y+j))+x+i));
if (has_alpha) tmp = *src_db - *src_b;
{ if (tmp > maxdelta || tmp < -maxdelta)
if (!src[six+nb])
continue;
alpha = (double)src[six+nb] / 255.0;
}
tmp = src[dix+b] - src[six+b];
if ((tmp>maxdelta)||
(tmp<-maxdelta))
continue; continue;
d = mat[ABS(i)][ABS(j)];
d = m[ABS(j)];
if (has_alpha) if (has_alpha)
{ {
if (!src[six + nb])
continue;
alpha = (double) src[six + nb] / 255.0;
d *= alpha; d *= alpha;
} }
sum += d * src[six+b]; sum += d * *src_b;
fact += d; fact += d;
} }
} }
if (fact == 0.0) if (fact == 0.0)
dest[dix+b] = src[dix+b]; dest[dix + b] = *src_db;
else else
dest[dix+b] = sum/fact; dest[dix + b] = sum / fact;
} }
} }
......
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