mirror of https://github.com/GNOME/gimp.git
Fixed small bug in gimp_bilinear routines and use them instead of plug-in's own implementations
This commit is contained in:
parent
3f201df9b6
commit
82243555b0
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,12 @@
|
|||
2002-11-20 Maurits Rijk <lpeek.mrijk@consunet.nl>
|
||||
|
||||
* plug-ins/common/whirlpinch.c
|
||||
* plug-ins/common/waves.c
|
||||
* plug-ins/common/polar.c
|
||||
* plug-ins/common/warp.c
|
||||
* plug-ins/common/displace.c: replaced all implementations of bilinear
|
||||
func by call to gimp_bilinear_8/16
|
||||
|
||||
2002-11-20 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/config/gimprc.c: made object properties from the gimprc
|
||||
|
@ -139,6 +148,12 @@
|
|||
GRand * object was used and g_rand_* functions were
|
||||
preferred. This fixes bug #67386 in HEAD.
|
||||
|
||||
2002-11-19 Maurits Rijk <lpeek.mrijk@consunet.nl>
|
||||
|
||||
* libgimpcolor/gimpbilinear.c (gimp_bilinear): fixed bug that could
|
||||
happen with negative values of parameter x or y. Same bug in
|
||||
gimp_bilinear_8, gimp_bilinear_16 and gimp_bilinear_32.
|
||||
|
||||
2002-11-19 Maurits Rijk <lpeek.mrijk@consunet.nl>
|
||||
|
||||
* plug-ins/gimpressionist/brush.c
|
||||
|
|
|
@ -33,23 +33,22 @@ gimp_bilinear (gdouble x,
|
|||
gdouble y,
|
||||
gdouble *values)
|
||||
{
|
||||
gdouble xx, yy;
|
||||
gdouble m0, m1;
|
||||
|
||||
g_assert (values != NULL);
|
||||
|
||||
xx = fmod (x, 1.0);
|
||||
yy = fmod (y, 1.0);
|
||||
x = fmod (x, 1.0);
|
||||
y = fmod (y, 1.0);
|
||||
|
||||
if (x < 0.0)
|
||||
x += 1.0;
|
||||
if (y < 0.0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (1.0 - xx) * values[0] + xx * values[1];
|
||||
m1 = (1.0 - xx) * values[2] + xx * values[3];
|
||||
m0 = (1.0 - x) * values[0] + x * values[1];
|
||||
m1 = (1.0 - x) * values[2] + x * values[3];
|
||||
|
||||
return (1.0 - yy) * m0 + yy * m1;
|
||||
return (1.0 - y) * m0 + y * m1;
|
||||
}
|
||||
|
||||
guchar
|
||||
|
@ -57,23 +56,22 @@ gimp_bilinear_8 (gdouble x,
|
|||
gdouble y,
|
||||
guchar *values)
|
||||
{
|
||||
gdouble xx, yy;
|
||||
gdouble m0, m1;
|
||||
|
||||
g_assert (values != NULL);
|
||||
|
||||
xx = fmod (x, 1.0);
|
||||
yy = fmod (y, 1.0);
|
||||
x = fmod (x, 1.0);
|
||||
y = fmod (y, 1.0);
|
||||
|
||||
if (x < 0.0)
|
||||
x += 1.0;
|
||||
if (y < 0.0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (1.0 - xx) * values[0] + xx * values[1];
|
||||
m1 = (1.0 - xx) * values[2] + xx * values[3];
|
||||
m0 = (1.0 - x) * values[0] + x * values[1];
|
||||
m1 = (1.0 - x) * values[2] + x * values[3];
|
||||
|
||||
return (guchar) ((1.0 - yy) * m0 + yy * m1);
|
||||
return (guchar) ((1.0 - y) * m0 + y * m1);
|
||||
}
|
||||
|
||||
guint16
|
||||
|
@ -81,23 +79,22 @@ gimp_bilinear_16 (gdouble x,
|
|||
gdouble y,
|
||||
guint16 *values)
|
||||
{
|
||||
gdouble xx, yy;
|
||||
gdouble m0, m1;
|
||||
|
||||
g_assert (values != NULL);
|
||||
|
||||
xx = fmod (x, 1.0);
|
||||
yy = fmod (y, 1.0);
|
||||
x = fmod (x, 1.0);
|
||||
y = fmod (y, 1.0);
|
||||
|
||||
if (x < 0.0)
|
||||
x += 1.0;
|
||||
if (y < 0.0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (1.0 - xx) * values[0] + xx * values[1];
|
||||
m1 = (1.0 - xx) * values[2] + xx * values[3];
|
||||
m0 = (1.0 - x) * values[0] + x * values[1];
|
||||
m1 = (1.0 - x) * values[2] + x * values[3];
|
||||
|
||||
return (guint16) ((1.0 - yy) * m0 + yy * m1);
|
||||
return (guint16) ((1.0 - y) * m0 + y * m1);
|
||||
}
|
||||
|
||||
guint32
|
||||
|
@ -105,23 +102,22 @@ gimp_bilinear_32 (gdouble x,
|
|||
gdouble y,
|
||||
guint32 *values)
|
||||
{
|
||||
gdouble xx, yy;
|
||||
gdouble m0, m1;
|
||||
|
||||
g_assert (values != NULL);
|
||||
|
||||
xx = fmod (x, 1.0);
|
||||
yy = fmod (y, 1.0);
|
||||
x = fmod (x, 1.0);
|
||||
y = fmod (y, 1.0);
|
||||
|
||||
if (x < 0.0)
|
||||
x += 1.0;
|
||||
if (y < 0.0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (1.0 - xx) * values[0] + xx * values[1];
|
||||
m1 = (1.0 - xx) * values[2] + xx * values[3];
|
||||
m0 = (1.0 - x) * values[0] + x * values[1];
|
||||
m1 = (1.0 - x) * values[2] + x * values[3];
|
||||
|
||||
return (guint32) ((1.0 - yy) * m0 + yy * m1);
|
||||
return (guint32) ((1.0 - y) * m0 + y * m1);
|
||||
}
|
||||
|
||||
GimpRGB
|
||||
|
|
|
@ -104,9 +104,6 @@ static GimpTile *displace_pixel (GimpDrawable *drawable,
|
|||
gint *row,
|
||||
gint *col,
|
||||
guchar *pixel);
|
||||
static guchar bilinear (gdouble x,
|
||||
gdouble y,
|
||||
guchar *v);
|
||||
|
||||
static gint displace_map_constrain (gint32 image_id,
|
||||
gint32 drawable_id,
|
||||
|
@ -623,7 +620,7 @@ displace (GimpDrawable *drawable)
|
|||
values[1] = pixel[1][k];
|
||||
values[2] = pixel[2][k];
|
||||
values[3] = pixel[3][k];
|
||||
val = bilinear(needx, needy, values);
|
||||
val = gimp_bilinear_8 (needx, needy, values);
|
||||
|
||||
*dest++ = val;
|
||||
} /* for */
|
||||
|
@ -748,28 +745,6 @@ displace_pixel (GimpDrawable *drawable,
|
|||
return tile;
|
||||
}
|
||||
|
||||
|
||||
static guchar
|
||||
bilinear (gdouble x,
|
||||
gdouble y,
|
||||
guchar *v)
|
||||
{
|
||||
gdouble m0, m1;
|
||||
|
||||
x = fmod(x, 1.0);
|
||||
y = fmod(y, 1.0);
|
||||
|
||||
if (x < 0)
|
||||
x += 1.0;
|
||||
if (y < 0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (gdouble) v[0] + x * ((gdouble) v[1] - v[0]);
|
||||
m1 = (gdouble) v[2] + x * ((gdouble) v[3] - v[2]);
|
||||
|
||||
return (guchar) (m0 + y * (m1 - m0));
|
||||
}
|
||||
|
||||
/* Displace interface functions */
|
||||
|
||||
static gint
|
||||
|
@ -784,11 +759,8 @@ displace_map_constrain (gint32 image_id,
|
|||
if (drawable_id == -1)
|
||||
return TRUE;
|
||||
|
||||
if (gimp_drawable_width (drawable_id) == drawable->width &&
|
||||
gimp_drawable_height (drawable_id) == drawable->height)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
return (gimp_drawable_width (drawable_id) == drawable->width &&
|
||||
gimp_drawable_height (drawable_id) == drawable->height);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -134,7 +134,6 @@ static void run (gchar *name,
|
|||
static void polarize(void);
|
||||
static int calc_undistorted_coords(double wx, double wy,
|
||||
double *x, double *y);
|
||||
static guchar bilinear(double x, double y, guchar *values);
|
||||
|
||||
static pixel_fetcher_t *pixel_fetcher_new (GimpDrawable *drawable);
|
||||
static void pixel_fetcher_set_bg_color (pixel_fetcher_t *pf);
|
||||
|
@ -431,7 +430,7 @@ polarize (void)
|
|||
values[2] = pixel[2][b];
|
||||
values[3] = pixel[3][b];
|
||||
|
||||
d[b] = bilinear (cx, cy, values);
|
||||
d[b] = gimp_bilinear_8 (cx, cy, values);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -692,28 +691,6 @@ calc_undistorted_coords (gdouble wx,
|
|||
return inside;
|
||||
}
|
||||
|
||||
static guchar
|
||||
bilinear (gdouble x,
|
||||
gdouble y,
|
||||
guchar *values)
|
||||
{
|
||||
gdouble m0, m1;
|
||||
|
||||
x = fmod (x, 1.0);
|
||||
y = fmod (y, 1.0);
|
||||
|
||||
if (x < 0.0)
|
||||
x += 1.0;
|
||||
|
||||
if (y < 0.0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (double) values[0] + x * ((double) values[1] - values[0]);
|
||||
m1 = (double) values[2] + x * ((double) values[3] - values[2]);
|
||||
|
||||
return (guchar) (m0 + y * (m1 - m0));
|
||||
}
|
||||
|
||||
static pixel_fetcher_t *
|
||||
pixel_fetcher_new (GimpDrawable *drawable)
|
||||
{
|
||||
|
|
|
@ -165,14 +165,6 @@ static GimpTile *warp_pixel (GimpDrawable *drawable,
|
|||
gint *col,
|
||||
guchar *pixel);
|
||||
|
||||
static guchar bilinear (gdouble x,
|
||||
gdouble y,
|
||||
guchar *v);
|
||||
|
||||
static gint bilinear16 (gdouble x,
|
||||
gdouble y,
|
||||
gint *v);
|
||||
|
||||
static gint warp_map_constrain (gint32 image_id,
|
||||
gint32 drawable_id,
|
||||
gpointer data);
|
||||
|
@ -1324,7 +1316,7 @@ warp_one (GimpDrawable *draw,
|
|||
gint substep; /* loop variable counting displacement vector substeps */
|
||||
|
||||
guchar values[4];
|
||||
gint ivalues[4];
|
||||
guint32 ivalues[4];
|
||||
guchar val;
|
||||
|
||||
gint k;
|
||||
|
@ -1455,7 +1447,7 @@ warp_one (GimpDrawable *draw,
|
|||
ivalues[1] = 256*pixel[1][0] + pixel[1][1];
|
||||
ivalues[2] = 256*pixel[2][0] + pixel[2][1];
|
||||
ivalues[3] = 256*pixel[3][0] + pixel[3][1];
|
||||
xval = bilinear16(needx, needy, ivalues);
|
||||
xval = gimp_bilinear_32(needx, needy, ivalues);
|
||||
|
||||
/* get 4 neighboring DY values from DiffY drawable for linear interpolation */
|
||||
ytile = warp_pixel (map_y, ytile, width, height, x1, y1, x2, y2, xi, yi, &yrow, &ycol, pixel[0]);
|
||||
|
@ -1467,7 +1459,7 @@ warp_one (GimpDrawable *draw,
|
|||
ivalues[1] = 256*pixel[1][0] + pixel[1][1];
|
||||
ivalues[2] = 256*pixel[2][0] + pixel[2][1];
|
||||
ivalues[3] = 256*pixel[3][0] + pixel[3][1];
|
||||
yval = bilinear16(needx, needy, ivalues);
|
||||
yval = gimp_bilinear_32(needx, needy, ivalues);
|
||||
|
||||
dx += dscalefac * (xval-32768); /* move displacement vector to this new value */
|
||||
dy += dscalefac * (yval-32768);
|
||||
|
@ -1511,7 +1503,7 @@ warp_one (GimpDrawable *draw,
|
|||
values[1] = pixel[1][k];
|
||||
values[2] = pixel[2][k];
|
||||
values[3] = pixel[3][k];
|
||||
val = bilinear(needx, needy, values);
|
||||
val = gimp_bilinear_8(needx, needy, values);
|
||||
|
||||
*dest++ = val;
|
||||
} /* for k */
|
||||
|
@ -1650,49 +1642,6 @@ warp_pixel (GimpDrawable *drawable,
|
|||
return tile;
|
||||
}
|
||||
|
||||
static guchar
|
||||
bilinear (gdouble x,
|
||||
gdouble y,
|
||||
guchar *v)
|
||||
{
|
||||
gdouble m0, m1;
|
||||
|
||||
x = fmod(x, 1.0);
|
||||
y = fmod(y, 1.0);
|
||||
|
||||
if (x < 0)
|
||||
x += 1.0;
|
||||
if (y < 0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (gdouble) v[0] + x * ((gdouble) v[1] - v[0]);
|
||||
m1 = (gdouble) v[2] + x * ((gdouble) v[3] - v[2]);
|
||||
|
||||
return (guchar) (m0 + y * (m1 - m0));
|
||||
} /* bilinear */
|
||||
|
||||
static gint
|
||||
bilinear16 (gdouble x,
|
||||
gdouble y,
|
||||
gint *v)
|
||||
{
|
||||
gdouble m0, m1;
|
||||
|
||||
x = fmod(x, 1.0);
|
||||
y = fmod(y, 1.0);
|
||||
|
||||
if (x < 0)
|
||||
x += 1.0;
|
||||
if (y < 0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (gdouble) v[0] + x * ((gdouble) v[1] - v[0]);
|
||||
m1 = (gdouble) v[2] + x * ((gdouble) v[3] - v[2]);
|
||||
|
||||
return (gint) (m0 + y * (m1 - m0));
|
||||
} /* bilinear16 */
|
||||
|
||||
|
||||
/* Warp interface functions */
|
||||
|
||||
static gint
|
||||
|
@ -1707,11 +1656,8 @@ warp_map_constrain (gint32 image_id,
|
|||
if (drawable_id == -1)
|
||||
return TRUE;
|
||||
|
||||
if (gimp_drawable_width (drawable_id) == drawable->width &&
|
||||
gimp_drawable_height (drawable_id) == drawable->height)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
return (gimp_drawable_width (drawable_id) == drawable->width &&
|
||||
gimp_drawable_height (drawable_id) == drawable->height);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -107,10 +107,6 @@ static void wave (guchar *src,
|
|||
gint reflective,
|
||||
gint verbose);
|
||||
|
||||
static guchar bilinear (gdouble x,
|
||||
gdouble y,
|
||||
guchar *v);
|
||||
|
||||
#define WITHIN(a, b, c) ((((a) <= (b)) && ((b) <= (c))) ? TRUE : FALSE)
|
||||
|
||||
GimpPlugInInfo PLUG_IN_INFO =
|
||||
|
@ -317,7 +313,6 @@ static gint
|
|||
pluginCoreIA (piArgs *argp,
|
||||
gint32 drawable)
|
||||
{
|
||||
gint r=-1; /* default to error return */
|
||||
GtkWidget *dlg;
|
||||
GtkWidget *main_vbox;
|
||||
GtkWidget *frame;
|
||||
|
@ -432,14 +427,7 @@ pluginCoreIA (piArgs *argp,
|
|||
gtk_main ();
|
||||
gdk_flush ();
|
||||
|
||||
if (run_flag)
|
||||
{
|
||||
return pluginCore (argp, drawable);
|
||||
}
|
||||
else
|
||||
{
|
||||
return r;
|
||||
}
|
||||
return (run_flag) ? pluginCore (argp, drawable) : -1;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -790,7 +778,7 @@ wave (guchar *src,
|
|||
else
|
||||
values[3] = 0;
|
||||
|
||||
val = bilinear (needx, needy, values);
|
||||
val = gimp_bilinear_8 (needx, needy, values);
|
||||
|
||||
*dest++ = val;
|
||||
}
|
||||
|
@ -802,23 +790,3 @@ wave (guchar *src,
|
|||
if (verbose)
|
||||
gimp_progress_update (1.0);
|
||||
}
|
||||
|
||||
static guchar
|
||||
bilinear (gdouble x,
|
||||
gdouble y,
|
||||
guchar *v)
|
||||
{
|
||||
gdouble m0, m1;
|
||||
x = fmod (x, 1.0);
|
||||
y = fmod (y, 1.0);
|
||||
|
||||
if (x < 0)
|
||||
x += 1.0;
|
||||
if (y < 0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (1.0 - x) * v[0] + x * v[1];
|
||||
m1 = (1.0 - x) * v[2] + x * v[3];
|
||||
|
||||
return (guchar) ((1.0 - y) * m0 + y * m1);
|
||||
}
|
||||
|
|
|
@ -120,7 +120,6 @@ static void whirl_pinch (void);
|
|||
static int calc_undistorted_coords (double wx, double wy,
|
||||
double whirl, double pinch,
|
||||
double *x, double *y);
|
||||
static guchar bilinear (double x, double y, guchar *values);
|
||||
|
||||
static pixel_fetcher_t *pixel_fetcher_new (GimpDrawable *drawable);
|
||||
static void pixel_fetcher_set_bg_color (pixel_fetcher_t *pf);
|
||||
|
@ -434,7 +433,7 @@ whirl_pinch (void)
|
|||
values[2] = pixel[2][i];
|
||||
values[3] = pixel[3][i];
|
||||
|
||||
*top_p++ = bilinear (cx, cy, values);
|
||||
*top_p++ = gimp_bilinear_8 (cx, cy, values);
|
||||
}
|
||||
|
||||
/* Bottom */
|
||||
|
@ -464,7 +463,7 @@ whirl_pinch (void)
|
|||
values[2] = pixel[2][i];
|
||||
values[3] = pixel[3][i];
|
||||
|
||||
*bot_p++ = bilinear (cx, cy, values);
|
||||
*bot_p++ = gimp_bilinear_8 (cx, cy, values);
|
||||
}
|
||||
|
||||
bot_p -= 2 * img_bpp; /* We move backwards! */
|
||||
|
@ -581,28 +580,6 @@ calc_undistorted_coords (gdouble wx,
|
|||
return inside;
|
||||
}
|
||||
|
||||
static guchar
|
||||
bilinear (gdouble x,
|
||||
gdouble y,
|
||||
guchar *values)
|
||||
{
|
||||
gdouble m0, m1;
|
||||
|
||||
x = fmod (x, 1.0);
|
||||
y = fmod (y, 1.0);
|
||||
|
||||
if (x < 0.0)
|
||||
x += 1.0;
|
||||
|
||||
if (y < 0.0)
|
||||
y += 1.0;
|
||||
|
||||
m0 = (double) values[0] + x * ((double) values[1] - values[0]);
|
||||
m1 = (double) values[2] + x * ((double) values[3] - values[2]);
|
||||
|
||||
return (guchar) (m0 + y * (m1 - m0));
|
||||
}
|
||||
|
||||
static pixel_fetcher_t *
|
||||
pixel_fetcher_new (GimpDrawable *drawable)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue