hardcode the result of log (1.0 / 255.0) and avoid a useless call to

2007-03-30  Sven Neumann  <sven@gimp.org>

	* app/paint-funcs/paint-funcs.c: hardcode the result of
	log (1.0 / 255.0) and avoid a useless call to sqrt().

svn path=/trunk/; revision=22201
This commit is contained in:
Sven Neumann
2007-03-30 10:14:30 +00:00
committed by Sven Neumann
parent f51e694972
commit 05d6439d9d
2 changed files with 19 additions and 17 deletions

View File

@ -1,9 +1,13 @@
2007-03-30 Sven Neumann <sven@gimp.org>
* app/paint-funcs/paint-funcs.c: hardcode the result of
log (1.0 / 255.0) and avoid a useless call to sqrt().
2007-03-30 Sven Neumann <sven@gimp.org> 2007-03-30 Sven Neumann <sven@gimp.org>
* app/paint/gimpheal.c (gimp_heal_laplace_iteration) * app/paint/gimpheal.c (gimp_heal_laplace_iteration)
(gimp_heal_laplace_loop): compare square of errors instead of (gimp_heal_laplace_loop): compare square of errors instead of
calculating the square root. Rewritten loop to avoid code calculating the square root. Rewritten loop to avoid code duplication.
duplication.
2007-03-30 Sven Neumann <sven@gimp.org> 2007-03-30 Sven Neumann <sven@gimp.org>

View File

@ -42,6 +42,8 @@
#define RANDOM_SEED 314159265 #define RANDOM_SEED 314159265
#define EPSILON 0.0001 #define EPSILON 0.0001
#define LOG_1_255 -5.541263545 /* log (1.0 / 255.0) */
/* Layer modes information */ /* Layer modes information */
typedef struct _LayerMode LayerMode; typedef struct _LayerMode LayerMode;
@ -54,10 +56,9 @@ struct _LayerMode
}; };
static const LayerMode layer_modes[] = static const LayerMode layer_modes[] =
/* This must obviously be in the same /* This must be in the same order as the
* order as the corresponding values * corresponding values in GimpLayerModeEffects.
* in the GimpLayerModeEffects enumeration. */
*/
{ {
{ TRUE, TRUE, FALSE, }, /* GIMP_NORMAL_MODE */ { TRUE, TRUE, FALSE, }, /* GIMP_NORMAL_MODE */
{ TRUE, TRUE, FALSE, }, /* GIMP_DISSOLVE_MODE */ { TRUE, TRUE, FALSE, }, /* GIMP_DISSOLVE_MODE */
@ -126,7 +127,7 @@ static const guchar no_mask = OPAQUE_OPACITY;
/* Local function prototypes */ /* Local function prototypes */
static gint * make_curve (gdouble sigma, static gint * make_curve (gdouble sigma_square,
gint *length); gint *length);
static gdouble cubic (gdouble dx, static gdouble cubic (gdouble dx,
gint jm1, gint jm1,
@ -332,15 +333,15 @@ update_tile_rowhints (Tile *tile,
/* /*
* The equations: g(r) = exp (- r^2 / (2 * sigma^2)) * The equations: g(r) = exp (- r^2 / (2 * sigma^2))
* r = sqrt (x^2 + y ^2) * r = sqrt (x^2 + y^2)
*/ */
static gint * static gint *
make_curve (gdouble sigma, make_curve (gdouble sigma_square,
gint *length) gint *length)
{ {
const gdouble sigma2 = 2 * sigma * sigma; const gdouble sigma2 = 2 * sigma_square;
const gdouble l = sqrt (-sigma2 * log (1.0 / 255.0)); const gdouble l = sqrt (-sigma2 * LOG_1_255);
gint *curve; gint *curve;
gint i, n; gint i, n;
@ -357,7 +358,7 @@ make_curve (gdouble sigma,
for (i = 1; i <= *length; i++) for (i = 1; i <= *length; i++)
{ {
gint temp = (gint) (exp (- (i * i) / sigma2) * 255); gint temp = (gint) (exp (- SQR (i) / sigma2) * 255);
curve[-i] = temp; curve[-i] = temp;
curve[i] = temp; curve[i] = temp;
@ -2660,7 +2661,6 @@ gaussian_blur_region (PixelRegion *srcR,
gdouble radius_x, gdouble radius_x,
gdouble radius_y) gdouble radius_y)
{ {
gdouble std_dev;
glong width, height; glong width, height;
guint bytes; guint bytes;
guchar *src, *sp; guchar *src, *sp;
@ -2696,8 +2696,7 @@ gaussian_blur_region (PixelRegion *srcR,
if (radius_y != 0.0) if (radius_y != 0.0)
{ {
std_dev = sqrt (-(radius_y * radius_y) / (2 * log (1.0 / 255.0))); curve = make_curve (- SQR (radius_y) / (2 * LOG_1_255), &length);
curve = make_curve (std_dev, &length);
sum = g_new (gint, 2 * length + 1); sum = g_new (gint, 2 * length + 1);
sum[0] = 0; sum[0] = 0;
@ -2758,8 +2757,7 @@ gaussian_blur_region (PixelRegion *srcR,
if (radius_x != 0.0) if (radius_x != 0.0)
{ {
std_dev = sqrt (-(radius_x * radius_x) / (2 * log (1.0 / 255.0))); curve = make_curve (- SQR (radius_x) / (2 * LOG_1_255), &length);
curve = make_curve (std_dev, &length);
sum = g_new (gint, 2 * length + 1); sum = g_new (gint, 2 * length + 1);
sum[0] = 0; sum[0] = 0;