fix alpha multiplication routine to perhaps work correctly, reported by

2002-04-09  Havoc Pennington  <hp@pobox.com>

	* src/theme.c (multiply_alpha): fix alpha multiplication routine
	to perhaps work correctly, reported by tigert. Also, be sure
	we always copy the image if necessary before modifying the
	alpha channel.
This commit is contained in:
Havoc Pennington 2002-04-10 04:00:32 +00:00 committed by Havoc Pennington
parent fa0592ebc7
commit 38ff6a49c4
2 changed files with 27 additions and 8 deletions

View File

@ -1,3 +1,10 @@
2002-04-09 Havoc Pennington <hp@pobox.com>
* src/theme.c (multiply_alpha): fix alpha multiplication routine
to perhaps work correctly, reported by tigert. Also, be sure
we always copy the image if necessary before modifying the
alpha channel.
2002-04-05 Havoc Pennington <hp@pobox.com> 2002-04-05 Havoc Pennington <hp@pobox.com>
* src/stack.c: remove the unused tab stuff * src/stack.c: remove the unused tab stuff

View File

@ -2460,7 +2460,8 @@ get_gc_for_primitive (GtkWidget *widget,
static GdkPixbuf* static GdkPixbuf*
multiply_alpha (GdkPixbuf *pixbuf, multiply_alpha (GdkPixbuf *pixbuf,
guchar alpha) guchar alpha,
gboolean force_copy)
{ {
GdkPixbuf *new_pixbuf; GdkPixbuf *new_pixbuf;
guchar *pixels; guchar *pixels;
@ -2469,7 +2470,7 @@ multiply_alpha (GdkPixbuf *pixbuf,
int row; int row;
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
if (alpha == 255) if (alpha == 255)
return pixbuf; return pixbuf;
@ -2479,7 +2480,15 @@ multiply_alpha (GdkPixbuf *pixbuf,
g_object_unref (G_OBJECT (pixbuf)); g_object_unref (G_OBJECT (pixbuf));
pixbuf = new_pixbuf; pixbuf = new_pixbuf;
} }
else if (force_copy)
{
new_pixbuf = gdk_pixbuf_copy (pixbuf);
g_object_unref (G_OBJECT (pixbuf));
pixbuf = new_pixbuf;
}
g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
pixels = gdk_pixbuf_get_pixels (pixbuf); pixels = gdk_pixbuf_get_pixels (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf);
height = gdk_pixbuf_get_height (pixbuf); height = gdk_pixbuf_get_height (pixbuf);
@ -2502,8 +2511,9 @@ multiply_alpha (GdkPixbuf *pixbuf,
* then it should be modified to contain "alpha"; if the * then it should be modified to contain "alpha"; if the
* pixbuf contains 0, it should remain 0. * pixbuf contains 0, it should remain 0.
*/ */
*p = (*p * alpha) / 65025; /* (*p / 255) * (alpha / 255); */ /* ((*p / 255.0) * (alpha / 255.0)) * 255; */
*p = (guchar) (((int) *p * (int) alpha) / (int) 255);
++p; /* skip A */ ++p; /* skip A */
} }
@ -2597,8 +2607,9 @@ scale_and_alpha_pixbuf (GdkPixbuf *src,
if (pixbuf) if (pixbuf)
pixbuf = multiply_alpha (pixbuf, pixbuf = multiply_alpha (pixbuf,
ALPHA_TO_UCHAR (alpha)); ALPHA_TO_UCHAR (alpha),
pixbuf == src);
return pixbuf; return pixbuf;
} }
@ -2672,7 +2683,8 @@ draw_op_as_pixbuf (const MetaDrawOp *op,
widget, width, height); widget, width, height);
pixbuf = multiply_alpha (pixbuf, pixbuf = multiply_alpha (pixbuf,
ALPHA_TO_UCHAR (op->data.gradient.alpha)); ALPHA_TO_UCHAR (op->data.gradient.alpha),
FALSE);
} }
break; break;