Hello community,

here is the log from the commit of package mgp for openSUSE:Factory checked in 
at 2016-05-23 16:39:04
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/mgp (Old)
 and      /work/SRC/openSUSE:Factory/.mgp.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "mgp"

Changes:
--------
--- /work/SRC/openSUSE:Factory/mgp/mgp.changes  2012-11-14 09:14:39.000000000 
+0100
+++ /work/SRC/openSUSE:Factory/.mgp.new/mgp.changes     2016-05-23 
16:39:06.000000000 +0200
@@ -1,0 +2,9 @@
+Thu May 19 19:45:51 CEST 2016 - ti...@suse.de
+
+- Implement the alpha channel support for fix the rendering bug
+  of images with transparent color (boo#980768):
+   mgp-alpha-channel.diff
+  Refresh mgp-bilinear-zoom.diff for a workaround of transparent
+  bug, too
+
+-------------------------------------------------------------------

New:
----
  mgp-alpha-channel.diff

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ mgp.spec ++++++
--- /var/tmp/diff_new_pack.98Dzc8/_old  2016-05-23 16:39:07.000000000 +0200
+++ /var/tmp/diff_new_pack.98Dzc8/_new  2016-05-23 16:39:07.000000000 +0200
@@ -1,7 +1,7 @@
 #
 # spec file for package mgp
 #
-# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -56,6 +56,7 @@
 Patch13:        magicpoint-%{version}-warnings.patch
 Patch14:        mgp-bilinear-zoom.diff
 Patch15:        mgp-imlib2-segfault-fix.diff
+Patch16:        mgp-alpha-channel.diff
 BuildRoot:      %{_tmppath}/%{name}-%{version}-build
 
 %description
@@ -83,6 +84,7 @@
 %patch13
 %patch14 -p1
 %patch15 -p1
+%patch16 -p1
 cp %{SOURCE1} .
 rm -rf sample/CVS
 

++++++ mgp-alpha-channel.diff ++++++
---
 draw.c        |   41 ++++++++++++++++++++++++++++--
 image/image.h |    1 
 image/new.c   |    4 ++
 image/zoom.c  |   78 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 4 files changed, 113 insertions(+), 11 deletions(-)

--- a/draw.c
+++ b/draw.c
@@ -1980,6 +1980,7 @@ obj_image_trans(image, x, y)
        int trans;
        u_int bw, bh, bx, by;
        int inithist;
+       byte *alpha = NULL;
 
        if (!COMPLEX_BGIMAGE) {
                if (back_color[caching] != xcol.pixel) {
@@ -1995,10 +1996,25 @@ obj_image_trans(image, x, y)
                        image->rgb.blue[image->trans] = xcol.blue;
                        break;
                case ITRUE:
-                       d = image->trans;
-                       n = RGB_TO_TRUE(xcol.red, xcol.green, xcol.blue);
                        pl = image->pixlen;
                        p = image->data;
+                       if (image->alpha) {
+                               alpha = image->alpha;
+                               for (j = 0; j < image->height; j++) {
+                                       for (i = 0; i < image->width; i++, p += 
pl) {
+                                               byte a = *alpha++ - 255;
+                                               if (!a)
+                                                       continue;
+                                               n = RGB_TO_TRUE(xcol.red * a / 
255,
+                                                               xcol.green * a 
/ 255,
+                                                               xcol.blue * a / 
255);
+                                               valToMem(n, p, pl);
+                                       }
+                               }
+                               break;
+                       }
+                       d = image->trans;
+                       n = RGB_TO_TRUE(xcol.red, xcol.green, xcol.blue);
                        for (j = 0; j < image->height; j++) {
                                for (i = 0; i < image->width; i++, p += pl) {
                                        if (memToVal(p, pl) == d)
@@ -2024,6 +2040,8 @@ obj_image_trans(image, x, y)
        }
        pl = image->pixlen;
        p = image->data + image->width * j * pl;
+       if (image->type == ITRUE && image->alpha)
+               alpha = image->alpha + image->width * j;
        bpl = bgpixmap[bgindex].image->pixlen;
        pd = -1;
        n = 0;  /* for lint */
@@ -2040,6 +2058,23 @@ obj_image_trans(image, x, y)
                                b = bgpixmap[bgindex].image->data + 
                                        bgpixmap[bgindex].image->width * by * 
bpl;
                        }
+                       if (alpha) {
+                               byte a = *alpha++;
+                               int n, v;
+                               if (a == 255)
+                                       continue;
+                               n = memToVal(p, pl);
+                               d = memToVal(b, bpl);
+                               v = RGB_TO_TRUE((TRUE_RED(n) * a +
+                                                TRUE_RED(d) * (255 - a)) / 255,
+                                               (TRUE_GREEN(n) * a +
+                                                TRUE_RED(d) * (255 - a)) / 255,
+                                               (TRUE_BLUE(n) * a +
+                                                TRUE_BLUE(d) * (255 - a)) / 
255);
+                               valToMem(v, p, pl);
+                               continue;
+                       }
+
                        if (memToVal(p, pl) != trans)
                                continue;
                        d = memToVal(b, bpl);
@@ -2099,7 +2134,7 @@ obj_draw_image(target, x, y, obj, page)
                }
                freeImage(timage);
        }
-       if (image->trans >= 0)
+       if (image->trans >= 0 || image->alpha)
                image = obj_image_trans(image, x, y);
        obj->data.image.image = image;  /* to free later */
        ximageinfo= imageToXImage(display, screen, visual, depth, image,
--- a/image/image.h
+++ b/image/image.h
@@ -90,6 +90,7 @@ typedef struct {
   unsigned int  depth;  /* depth of image in bits if IRGB type */
   unsigned int  pixlen; /* length of pixel if IRGB type */
   byte         *data;   /* data rounded to full byte for each row */
+  byte         *alpha;  /* optional alpha channel */
   int          trans;  /* transparent index in rgb */
 } Image;
 
--- a/image/new.c
+++ b/image/new.c
@@ -119,6 +119,7 @@ Image *newBitImage(width, height)
   linelen= (width / 8) + (width % 8 ? 1 : 0); /* thanx jo...@amcc.com */
   image->data= (unsigned char *)lcalloc(linelen * height);
   image->trans = -1;
+  image->alpha = NULL;
   return(image);
 }
 
@@ -141,6 +142,7 @@ Image *newRGBImage(width, height, depth)
   image->pixlen= pixlen;
   image->data= (unsigned char *)lmalloc(width * height * pixlen);
   image->trans = -1;
+  image->alpha = NULL;
   return(image);
 }
 
@@ -157,6 +159,7 @@ Image *newTrueImage(width, height)
   image->depth= 24;
   image->pixlen= 3;
   image->data= (unsigned char *)lmalloc(width * height * 3);
+  image->alpha = NULL;
   image->trans = -1;
   return(image);
 }
@@ -171,6 +174,7 @@ void freeImageData(image)
   if (!TRUEP(image))
     freeRGBMapData(&(image->rgb));
   lfree(image->data);
+  lfree(image->alpha);
 }
 
 void freeImage(image)
--- a/image/zoom.c
+++ b/image/zoom.c
@@ -58,6 +58,7 @@ static void resize_image(oimage, image)
   int i, j;
   byte *line1, *line2;
   byte *destptr;
+  byte *adest = NULL;
   unsigned int srclinelen;
   unsigned int pixlen;
   Pixel v[4];
@@ -68,6 +69,12 @@ static void resize_image(oimage, image)
   pixlen= oimage->pixlen;
   srclinelen= oimage->width * pixlen;
   destptr = image->data;
+  if (oimage->trans != -1 || oimage->alpha) {
+    image->trans = -1;
+    lfree(image->alpha);
+    image->alpha = lmalloc(image->width * image->height);
+    adest = image->alpha;
+  }
   cy = 0;
   xstep = (double)oimage->width / (double)image->width;
   ystep = (double)oimage->height / (double)image->height;
@@ -84,6 +91,8 @@ static void resize_image(oimage, image)
     line2 = oimage->data + srclinelen * y2;
     cx = 0;
     for (i = image->width; i > 0; i--) {
+      byte a[4];
+      memset(a, 0xff, 4);
       x1 = cx;
       if (x1 >= maxx) {
        x1 = x2 = maxx;
@@ -93,9 +102,25 @@ static void resize_image(oimage, image)
        xoff = cx - x1;
       }
       v[0] = memToVal(line1 + pixlen * x1, pixlen);
+      if (v[0] == oimage->trans) {
+       v[0] = 0;
+       a[0] = 0;
+      }
       v[1] = memToVal(line1 + pixlen * x2, pixlen);
+      if (v[1] == oimage->trans) {
+       v[1] = 0;
+       a[1] = 0;
+      }
       v[2] = memToVal(line2 + pixlen * x1, pixlen);
+      if (v[2] == oimage->trans) {
+       v[2] = 0;
+       a[2] = 0;
+      }
       v[3] = memToVal(line2 + pixlen * x2, pixlen);
+      if (v[3] == oimage->trans) {
+       v[3] = 0;
+       a[3] = 0;
+      }
       r = (TRUE_RED(v[0]) * (1 - xoff) +
           TRUE_RED(v[1]) * xoff) * (1 - yoff) +
        (TRUE_RED(v[2]) * (1 - xoff) +
@@ -111,6 +136,21 @@ static void resize_image(oimage, image)
       v[0] = rgb8_to_true(r, g, b);
       valToMem(v[0], destptr, pixlen);
       destptr += pixlen;
+
+      if (adest) {
+       if (oimage->alpha) {
+         byte *alpha1 = oimage->alpha + oimage->width * y1;
+         byte *alpha2 = oimage->alpha + oimage->width * y2;
+         a[0] = alpha1[x1];
+         a[1] = alpha1[x2];
+         a[2] = alpha2[x1];
+         a[3] = alpha2[x2];
+       }
+
+       *adest++ = (a[0] * (1 - xoff) + a[1] * xoff) * (1 - yoff) +
+         (a[2] * (1 - xoff) + a[3] * xoff) * yoff;
+      }
+
       cx += xstep;
     }
     cy += ystep;
@@ -125,6 +165,7 @@ static Image *reduced_image(oimage, widt
 {
   Image *dest;
   byte *destptr;
+  byte *adest = NULL;
   unsigned int srclinelen;
   unsigned int i, j;
   unsigned int factorx = oimage->width / width;
@@ -145,23 +186,41 @@ static Image *reduced_image(oimage, widt
 
   dest = newTrueImage(width, height);
   destptr = dest->data;
+  if (oimage->trans) {
+    dest->alpha = (unsigned char *)lmalloc(width * height);
+    adest = dest->alpha;
+  }
 
   srclinelen = oimage->width * oimage->pixlen;
 
   for (j = 0; j < oimage->height; j += factory) {
     for (i = 0; i < oimage->width; i += factorx) {
-      unsigned int r, g, b, div, x, y;
+      unsigned int r, g, b, a, div, x, y;
       Pixel v;
 
-      r = g = b= 0;
+      r = g = b = a = 0;
       div = 0;
       for (y = 0; y < factory && j + y < oimage->height; y++) {
        byte *src = oimage->data + srclinelen * (j + y);
+       byte *asrc = NULL;
+       if (oimage->alpha)
+         asrc = oimage->alpha + oimage->width * (j + y);
        for (x = 0; x < factorx && i + x < oimage->width; x++) {
          v = memToVal(src + pixlen * (i + x), pixlen);
-         r += TRUE_RED(v);
-         g += TRUE_GREEN(v);
-         b += TRUE_BLUE(v);
+         if (asrc) {
+           if (*asrc) {
+             r += TRUE_RED(v);
+             g += TRUE_GREEN(v);
+             g += TRUE_BLUE(v);
+           }
+           a += *asrc;
+           asrc++;
+         } else if (v != oimage->trans) {
+           r += TRUE_RED(v);
+           g += TRUE_GREEN(v);
+           b += TRUE_BLUE(v);
+           a += 0xff;
+         }
          div++;
        }
       }
@@ -171,6 +230,8 @@ static Image *reduced_image(oimage, widt
       v = rgb8_to_true(r, g, b);
       valToMem(v, destptr, pixlen);
       destptr += pixlen;
+      if (adest)
+       *adest++ = a / div;
     }
   }
   return dest;
@@ -287,7 +348,7 @@ Image *zoom(oimage, xzoom, yzoom, verbos
   case ITRUE:
     if (!RGBP(oimage)) {
       Image *tmpimage = NULL;
-      if (smooth_scaling && oimage->transparent == -1 &&
+      if (smooth_scaling &&
          (oimage->width / xwidth > 1 || oimage->height / ywidth > 1)) {
        tmpimage = reduced_image(oimage, xwidth, ywidth);
        if (tmpimage->width == xwidth && tmpimage->height == ywidth) {
@@ -296,7 +357,7 @@ Image *zoom(oimage, xzoom, yzoom, verbos
        }
       }
       image= newTrueImage(xwidth, ywidth);
-      if (smooth_scaling && oimage->transparent == -1) {
+      if (smooth_scaling) {
        resize_image(tmpimage ? tmpimage : oimage, image);
        if (tmpimage)
          freeImage(tmpimage);
@@ -333,7 +394,8 @@ Image *zoom(oimage, xzoom, yzoom, verbos
 
   if (image) {
       image->title= dupString(buf);
-      image->trans = oimage->trans;
+      if (!image->alpha)
+       image->trans = oimage->trans;
   }
   lfree((byte *)xindex);
   lfree((byte *)yindex);
++++++ mgp-bilinear-zoom.diff ++++++
--- /var/tmp/diff_new_pack.98Dzc8/_old  2016-05-23 16:39:07.000000000 +0200
+++ /var/tmp/diff_new_pack.98Dzc8/_new  2016-05-23 16:39:07.000000000 +0200
@@ -167,7 +167,7 @@
 -    if (!RGBP(oimage))
 +    if (!RGBP(oimage)) {
 +      Image *tmpimage = NULL;
-+      if (smooth_scaling &&
++      if (smooth_scaling && oimage->transparent == -1 &&
 +        (oimage->width / xwidth > 1 || oimage->height / ywidth > 1)) {
 +      tmpimage = reduced_image(oimage, xwidth, ywidth);
 +      if (tmpimage->width == xwidth && tmpimage->height == ywidth) {
@@ -176,7 +176,7 @@
 +      }
 +      }
        image= newTrueImage(xwidth, ywidth);
-+      if (smooth_scaling) {
++      if (smooth_scaling && oimage->transparent == -1) {
 +      resize_image(tmpimage ? tmpimage : oimage, image);
 +      if (tmpimage)
 +        freeImage(tmpimage);


Reply via email to