inline the repeat functions.

2004-06-13  Sven Neumann  <sven@gimp.org>

	* app/core/gimpdrawable-blend.c (gradient_render_pixel): inline
	the repeat functions.

	* app/core/gimpgradient.c: inline the curve functions.
This commit is contained in:
Sven Neumann
2004-06-13 01:17:57 +00:00
committed by Sven Neumann
parent 4e235080ce
commit c28d70ce00
3 changed files with 59 additions and 88 deletions

View File

@ -1,3 +1,10 @@
2004-06-13 Sven Neumann <sven@gimp.org>
* app/core/gimpdrawable-blend.c (gradient_render_pixel): inline
the repeat functions.
* app/core/gimpgradient.c: inline the curve functions.
2004-06-13 Jakub Steiner <jimmac@ximian.com> 2004-06-13 Jakub Steiner <jimmac@ximian.com>
* cursors/gimp-tool-cursors.xcf * cursors/gimp-tool-cursors.xcf

View File

@ -44,9 +44,6 @@
#include "gimp-intl.h" #include "gimp-intl.h"
typedef gdouble (* BlendRepeatFunc) (gdouble val);
typedef struct typedef struct
{ {
GimpGradient *gradient; GimpGradient *gradient;
@ -58,7 +55,7 @@ typedef struct
GimpRGB fg, bg; GimpRGB fg, bg;
gdouble dist; gdouble dist;
gdouble vec[2]; gdouble vec[2];
BlendRepeatFunc repeat_func; GimpRepeatMode repeat
} RenderBlendData; } RenderBlendData;
typedef struct typedef struct
@ -116,10 +113,6 @@ static gdouble gradient_calc_shapeburst_spherical_factor (gdouble x,
static gdouble gradient_calc_shapeburst_dimpled_factor (gdouble x, static gdouble gradient_calc_shapeburst_dimpled_factor (gdouble x,
gdouble y); gdouble y);
static gdouble gradient_repeat_none (gdouble val);
static gdouble gradient_repeat_sawtooth (gdouble val);
static gdouble gradient_repeat_triangular (gdouble val);
static void gradient_precalc_shapeburst (GimpImage *gimage, static void gradient_precalc_shapeburst (GimpImage *gimage,
GimpDrawable *drawable, GimpDrawable *drawable,
PixelRegion *PR, PixelRegion *PR,
@ -143,7 +136,7 @@ static void gradient_fill_region (GimpImage *gimage,
GimpBlendMode blend_mode, GimpBlendMode blend_mode,
GimpGradientType gradient_type, GimpGradientType gradient_type,
gdouble offset, gdouble offset,
GimpRepeatMode repeat, GimpRepeatMode repeat,
gboolean reverse, gboolean reverse,
gboolean supersample, gboolean supersample,
gint max_depth, gint max_depth,
@ -576,37 +569,6 @@ gradient_calc_shapeburst_dimpled_factor (gdouble x,
return value; return value;
} }
static gdouble
gradient_repeat_none (gdouble val)
{
return CLAMP (val, 0.0, 1.0);
}
static gdouble
gradient_repeat_sawtooth (gdouble val)
{
return val - floor (val);
}
static gdouble
gradient_repeat_triangular (gdouble val)
{
guint ival;
if (val < 0.0)
val = -val;
ival = (guint) val;
val = val - floor (val);
if (ival & 1)
return 1.0 - val;
else
return val;
}
static void static void
gradient_precalc_shapeburst (GimpImage *gimage, gradient_precalc_shapeburst (GimpImage *gimage,
GimpDrawable *drawable, GimpDrawable *drawable,
@ -699,11 +661,9 @@ gradient_render_pixel (double x,
GimpRGB *color, GimpRGB *color,
gpointer render_data) gpointer render_data)
{ {
RenderBlendData *rbd; RenderBlendData *rbd = render_data;
gdouble factor; gdouble factor;
rbd = render_data;
/* Calculate blending factor */ /* Calculate blending factor */
switch (rbd->gradient_type) switch (rbd->gradient_type)
@ -767,7 +727,31 @@ gradient_render_pixel (double x,
/* Adjust for repeat */ /* Adjust for repeat */
factor = rbd->repeat_func (factor); switch (rbd->repeat)
{
case GIMP_REPEAT_NONE:
factor = CLAMP (factor, 0.0, 1.0);
break;
case GIMP_REPEAT_SAWTOOTH:
factor = factor - floor (factor);
break;
case GIMP_REPEAT_TRIANGULAR:
{
guint ifactor;
if (factor < 0.0)
factor = -factor;
ifactor = (guint) factor;
factor = factor - floor (factor);
if (ifactor & 1)
factor = 1.0 - factor;
}
break;
}
/* Blend the colors */ /* Blend the colors */
@ -802,11 +786,9 @@ gradient_put_pixel (gint x,
GimpRGB *color, GimpRGB *color,
gpointer put_pixel_data) gpointer put_pixel_data)
{ {
PutPixelData *ppd; PutPixelData *ppd = put_pixel_data;
guchar *data; guchar *data;
ppd = put_pixel_data;
/* Paint */ /* Paint */
data = ppd->row_data + ppd->bytes * x; data = ppd->row_data + ppd->bytes * x;
@ -1008,27 +990,6 @@ gradient_fill_region (GimpImage *gimage,
break; break;
} }
/* Set repeat function */
switch (repeat)
{
case GIMP_REPEAT_NONE:
rbd.repeat_func = gradient_repeat_none;
break;
case GIMP_REPEAT_SAWTOOTH:
rbd.repeat_func = gradient_repeat_sawtooth;
break;
case GIMP_REPEAT_TRIANGULAR:
rbd.repeat_func = gradient_repeat_triangular;
break;
default:
g_assert_not_reached ();
break;
}
/* Initialize render data */ /* Initialize render data */
rbd.offset = offset; rbd.offset = offset;
@ -1036,6 +997,7 @@ gradient_fill_region (GimpImage *gimage,
rbd.sy = sy; rbd.sy = sy;
rbd.blend_mode = blend_mode; rbd.blend_mode = blend_mode;
rbd.gradient_type = gradient_type; rbd.gradient_type = gradient_type;
rbd.repeat = repeat;
if (dither) if (dither)
dither_rand = g_rand_new (); dither_rand = g_rand_new ();
@ -1162,10 +1124,12 @@ gradient_fill_region (GimpImage *gimage,
} }
} }
progress += PR->w * PR->h; if (progress_callback)
if (progress_callback) {
(* progress_callback) (0, max_progress, progress, progress_data); progress += PR->w * PR->h;
} (* progress_callback) (0, max_progress, progress, progress_data);
}
}
} }
if (dither) if (dither)

View File

@ -72,16 +72,16 @@ static gchar * gimp_gradient_get_extension (GimpData *data);
static GimpData * gimp_gradient_duplicate (GimpData *data, static GimpData * gimp_gradient_duplicate (GimpData *data,
gboolean stingy_memory_use); gboolean stingy_memory_use);
static gdouble gimp_gradient_calc_linear_factor (gdouble middle, static inline gdouble gimp_gradient_calc_linear_factor (gdouble middle,
gdouble pos); gdouble pos);
static gdouble gimp_gradient_calc_curved_factor (gdouble middle, static inline gdouble gimp_gradient_calc_curved_factor (gdouble middle,
gdouble pos); gdouble pos);
static gdouble gimp_gradient_calc_sine_factor (gdouble middle, static inline gdouble gimp_gradient_calc_sine_factor (gdouble middle,
gdouble pos); gdouble pos);
static gdouble gimp_gradient_calc_sphere_increasing_factor (gdouble middle, static inline gdouble gimp_gradient_calc_sphere_increasing_factor (gdouble middle,
gdouble pos); gdouble pos);
static gdouble gimp_gradient_calc_sphere_decreasing_factor (gdouble middle, static inline gdouble gimp_gradient_calc_sphere_decreasing_factor (gdouble middle,
gdouble pos); gdouble pos);
static GimpDataClass *parent_class = NULL; static GimpDataClass *parent_class = NULL;
@ -822,7 +822,7 @@ gimp_gradient_get_segment_at (GimpGradient *gradient,
return NULL; return NULL;
} }
static gdouble static inline gdouble
gimp_gradient_calc_linear_factor (gdouble middle, gimp_gradient_calc_linear_factor (gdouble middle,
gdouble pos) gdouble pos)
{ {
@ -845,17 +845,17 @@ gimp_gradient_calc_linear_factor (gdouble middle,
} }
} }
static gdouble static inline gdouble
gimp_gradient_calc_curved_factor (gdouble middle, gimp_gradient_calc_curved_factor (gdouble middle,
gdouble pos) gdouble pos)
{ {
if (middle < EPSILON) if (middle < EPSILON)
middle = EPSILON; middle = EPSILON;
return pow(pos, log (0.5) / log (middle)); return pow (pos, log (0.5) / log (middle));
} }
static gdouble static inline gdouble
gimp_gradient_calc_sine_factor (gdouble middle, gimp_gradient_calc_sine_factor (gdouble middle,
gdouble pos) gdouble pos)
{ {
@ -864,7 +864,7 @@ gimp_gradient_calc_sine_factor (gdouble middle,
return (sin ((-G_PI / 2.0) + G_PI * pos) + 1.0) / 2.0; return (sin ((-G_PI / 2.0) + G_PI * pos) + 1.0) / 2.0;
} }
static gdouble static inline gdouble
gimp_gradient_calc_sphere_increasing_factor (gdouble middle, gimp_gradient_calc_sphere_increasing_factor (gdouble middle,
gdouble pos) gdouble pos)
{ {
@ -873,7 +873,7 @@ gimp_gradient_calc_sphere_increasing_factor (gdouble middle,
return sqrt (1.0 - pos * pos); /* Works for convex increasing and concave decreasing */ return sqrt (1.0 - pos * pos); /* Works for convex increasing and concave decreasing */
} }
static gdouble static inline gdouble
gimp_gradient_calc_sphere_decreasing_factor (gdouble middle, gimp_gradient_calc_sphere_decreasing_factor (gdouble middle,
gdouble pos) gdouble pos)
{ {