gimpbilinear and alpha
Hello,
the gimp_bilinear_rgba () function (libgimpcolor/gimpbilinear.c)
handles alpha channel as if Gimp used premultiplied alpha.
Since all Gimp core uses separated alpha, I suggest the
attached patch (against CVS HEAD). This patch itself seems
to fix alpha handling in two plug-ins using gimp_bilinear_rgba ():
#72876 Incorrect RGBA resampling in Map Object plug-in
#105796 Incorrect RGBA resampling in Lighting Effects plug-in
(this one may be not fully fixed)
Beside that all the remaining functions in gimpbilinear
operate on individual channels (colors) and not pixels.
Plug-in authors using them hardly can handle alpha blending
correctly. IMHO functions operating on whole pixels are
needed more than the existing ones (though they are also
useful).
Regards,
Yeti
--- gimp.orig/libgimpcolor/gimpbilinear.c 2002-11-20 22:29:15.000000000 +0100
+++ gimp/libgimpcolor/gimpbilinear.c 2003-02-07 16:34:55.000000000 +0100
@@ -173,6 +173,7 @@
{
gdouble m0, m1;
gdouble ix, iy;
+ gdouble a0, a1, a2, a3, alpha;
GimpRGB v;
g_assert (values != NULL);
@@ -188,33 +189,41 @@
ix = 1.0 - x;
iy = 1.0 - y;
- /* Red */
+ a0 = values[0].a;
+ a1 = values[1].a;
+ a2 = values[2].a;
+ a3 = values[3].a;
- m0 = ix * values[0].r + x * values[1].r;
- m1 = ix * values[2].r + x * values[3].r;
+ /* Alpha */
- v.r = iy * m0 + y * m1;
+ m0 = ix * a0 + x * a1;
+ m1 = ix * a2 + x * a3;
- /* Green */
+ alpha = v.a = iy * m0 + y * m1;
- m0 = ix * values[0].g + x * values[1].g;
- m1 = ix * values[2].g + x * values[3].g;
+ if (alpha > 0)
+ {
+ /* Red */
- v.g = iy * m0 + y * m1;
+ m0 = ix * a0 * values[0].r + x * a1 * values[1].r;
+ m1 = ix * a2 * values[2].r + x * a3 * values[3].r;
- /* Blue */
+ v.r = (iy * m0 + y * m1)/alpha;
- m0 = ix * values[0].b + x * values[1].b;
- m1 = ix * values[2].b + x * values[3].b;
+ /* Green */
- v.b = iy * m0 + y * m1;
+ m0 = ix * a0 * values[0].g + x * a1 * values[1].g;
+ m1 = ix * a2 * values[2].g + x * a3 * values[3].g;
- /* Alpha */
+ v.g = (iy * m0 + y * m1)/alpha;
+
+ /* Blue */
- m0 = ix * values[0].a + x * values[1].a;
- m1 = ix * values[2].a + x * values[3].a;
+ m0 = ix * a0 * values[0].b + x * a1 * values[1].b;
+ m1 = ix * a2 * values[2].b + x * a3 * values[3].b;
- v.a = iy * m0 + y * m1;
+ v.b = (iy * m0 + y * m1)/alpha;
+ }
return v;
}