libgimpcolor/gimpbilinear.[ch] applied a patch from David Necas

2003-03-02  Sven Neumann  <sven@gimp.org>

	* libgimpcolor/gimpbilinear.[ch]
	* libgimpcolor/gimpcolor.def: applied a patch from David Necas
	<yeti@physics.muni.cz> that adds gimp_bilinear_pixels_8(), a new
	function that computes the bilinear interpolation of four pixels.

2003-03-02  Sven Neumann  <sven@gimp.org>

	* libgimpcolor/libgimpcolor-sections.txt
	* libgimpcolor/tmpl/gimpbilinear.sgml: updated.
This commit is contained in:
Sven Neumann 2003-03-02 16:27:01 +00:00 committed by Sven Neumann
parent ec2ce1d269
commit 8d1d6f0770
7 changed files with 133 additions and 25 deletions

View File

@ -1,3 +1,10 @@
2003-03-02 Sven Neumann <sven@gimp.org>
* libgimpcolor/gimpbilinear.[ch]
* libgimpcolor/gimpcolor.def: applied a patch from David Necas
<yeti@physics.muni.cz> that adds gimp_bilinear_pixels_8(), a new
function that computes the bilinear interpolation of four pixels.
2003-03-02 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/guides.pdb

View File

@ -1,3 +1,8 @@
2003-03-02 Sven Neumann <sven@gimp.org>
* libgimpcolor/libgimpcolor-sections.txt
* libgimpcolor/tmpl/gimpbilinear.sgml: updated.
2003-02-26 Sven Neumann <sven@gimp.org>
* libgimpwidgets/tmpl/gimpcolorscales.sgml

View File

@ -78,4 +78,5 @@ gimp_bilinear_16
gimp_bilinear_32
gimp_bilinear_rgb
gimp_bilinear_rgba
gimp_bilinear_pixels_8
</SECTION>

View File

@ -80,3 +80,16 @@ GimpBilinear
@Returns:
<!-- ##### FUNCTION gimp_bilinear_pixels_8 ##### -->
<para>
</para>
@dest:
@x:
@y:
@bpp:
@has_alpha:
@values:

View File

@ -35,7 +35,7 @@ gimp_bilinear (gdouble x,
{
gdouble m0, m1;
g_assert (values != NULL);
g_return_val_if_fail (values != NULL, 0.0);
x = fmod (x, 1.0);
y = fmod (y, 1.0);
@ -58,7 +58,7 @@ gimp_bilinear_8 (gdouble x,
{
gdouble m0, m1;
g_assert (values != NULL);
g_return_val_if_fail (values != NULL, 0);
x = fmod (x, 1.0);
y = fmod (y, 1.0);
@ -81,7 +81,7 @@ gimp_bilinear_16 (gdouble x,
{
gdouble m0, m1;
g_assert (values != NULL);
g_return_val_if_fail (values != NULL, 0);
x = fmod (x, 1.0);
y = fmod (y, 1.0);
@ -104,7 +104,7 @@ gimp_bilinear_32 (gdouble x,
{
gdouble m0, m1;
g_assert (values != NULL);
g_return_val_if_fail (values != NULL, 0);
x = fmod (x, 1.0);
y = fmod (y, 1.0);
@ -129,7 +129,7 @@ gimp_bilinear_rgb (gdouble x,
gdouble ix, iy;
GimpRGB v;
g_assert (values != NULL);
g_return_val_if_fail (values != NULL, v);
x = fmod(x, 1.0);
y = fmod(y, 1.0);
@ -176,7 +176,7 @@ gimp_bilinear_rgba (gdouble x,
gdouble a0, a1, a2, a3, alpha;
GimpRGB v;
g_assert (values != NULL);
g_return_val_if_fail (values != NULL, v);
x = fmod (x, 1.0);
y = fmod (y, 1.0);
@ -227,3 +227,79 @@ gimp_bilinear_rgba (gdouble x,
return v;
}
/**
* gimp_bilinear_pixels_8:
* @dest: Pixel, where interpolation result is to be stored.
* @x: x-coordinate (0.0 to 1.0).
* @y: y-coordinate (0.0 to 1.0).
* @bpp: Bytes per pixel. @dest and each @values item is an array of
* @bpp bytes.
* @has_alpha: %TRUE if the last channel is an alpha channel.
* @values: Array of four pointers to pixels.
*
* Computes bilinear interpolation of four pixels.
*
* When @has_alpha is %FALSE, it's identical to gimp_bilinear_8() on
* each channel separately. When @has_alpha is %TRUE, it handles
* alpha channel correctly.
*
* The pixels in @values correspond to corner x, y coordinates in the
* following order: [0,0], [1,0], [0,1], [1,1].
**/
void
gimp_bilinear_pixels_8 (guchar *dest,
gdouble x,
gdouble y,
guint bpp,
gboolean has_alpha,
guchar **values)
{
guint i;
g_return_if_fail (dest != NULL);
g_return_if_fail (values != NULL);
x = fmod (x, 1.0);
y = fmod (y, 1.0);
if (x < 0.0)
x += 1.0;
if (y < 0.0)
y += 1.0;
if (has_alpha)
{
guint ai = bpp - 1;
gdouble alpha0 = values[0][ai];
gdouble alpha1 = values[1][ai];
gdouble alpha2 = values[2][ai];
gdouble alpha3 = values[3][ai];
gdouble alpha = ((1.0 - y) * ((1.0 - x) * alpha0 + x * alpha1)
+ y * ((1.0 - x) * alpha2 + x * alpha3));
dest[ai] = (guchar) alpha;
if (dest[ai])
{
for (i = 0; i < ai; i++)
{
gdouble m0 = ((1.0 - x) * values[0][i] * alpha0
+ x * values[1][i] * alpha1);
gdouble m1 = ((1.0 - x) * values[2][i] * alpha2
+ x * values[3][i] * alpha3);
dest[i] = (guchar) (((1.0 - y) * m0 + y * m1) / alpha);
}
}
}
else
{
for (i = 0; i < bpp; i++)
{
gdouble m0 = (1.0 - x) * values[0][i] + x * values[1][i];
gdouble m1 = (1.0 - x) * values[2][i] + x * values[3][i];
dest[i] = (guchar) ((1.0 - y) * m0 + y * m1);
}
}
}

View File

@ -28,25 +28,30 @@ G_BEGIN_DECLS
/* bilinear interpolation functions taken from LibGCK */
gdouble gimp_bilinear (gdouble x,
gdouble y,
gdouble *values);
guchar gimp_bilinear_8 (gdouble x,
gdouble y,
guchar *values);
guint16 gimp_bilinear_16 (gdouble x,
gdouble y,
guint16 *values);
guint32 gimp_bilinear_32 (gdouble x,
gdouble y,
guint32 *values);
GimpRGB gimp_bilinear_rgb (gdouble x,
gdouble y,
GimpRGB *values);
GimpRGB gimp_bilinear_rgba (gdouble x,
gdouble y,
GimpRGB *values);
gdouble gimp_bilinear (gdouble x,
gdouble y,
gdouble *values);
guchar gimp_bilinear_8 (gdouble x,
gdouble y,
guchar *values);
guint16 gimp_bilinear_16 (gdouble x,
gdouble y,
guint16 *values);
guint32 gimp_bilinear_32 (gdouble x,
gdouble y,
guint32 *values);
GimpRGB gimp_bilinear_rgb (gdouble x,
gdouble y,
GimpRGB *values);
GimpRGB gimp_bilinear_rgba (gdouble x,
gdouble y,
GimpRGB *values);
void gimp_bilinear_pixels_8 (guchar *dest,
gdouble x,
gdouble y,
guint bpp,
gboolean has_alpha,
guchar **values);
G_END_DECLS

View File

@ -6,6 +6,7 @@ EXPORTS
gimp_bilinear_8
gimp_bilinear_rgb
gimp_bilinear_rgba
gimp_bilinear_pixels_8
gimp_hls_to_rgb_int
gimp_hsl_to_rgb
gimp_hsv_clamp