revent a division by zero when both layers have an opacity of 0
authorStephane Delcroix <stephane@delcroix.org>
Fri, 20 Mar 2009 14:22:03 +0000 (15:22 +0100)
committerStephane Delcroix <stephane@delcroix.org>
Fri, 20 Mar 2009 14:22:03 +0000 (15:22 +0100)
io-xcf.c

index 68ea51c..3413420 100644 (file)
--- a/io-xcf.c
+++ b/io-xcf.c
@@ -296,6 +296,9 @@ intersect_tile (guchar* ptr, int im_width, int im_height, int *ox, int *oy, int
 
 void blend (guchar* rgba0, guchar* rgba1)
 {
+       if (rgba0[3] == 0 && rgba1[3] == 0)
+               return;
+
        guchar k = 0xff * rgba1[3] / (0xff - (0xff-rgba0[3])*(0xff-rgba1[3])/0xff);
        rgba0[0] = ((0xff - k) * rgba0[0] + k * rgba1[0]) / 0xff;
        rgba0[1] = ((0xff - k) * rgba0[1] + k * rgba1[1]) / 0xff;