cvs: gd /libgd ISSUES gd.c /libgd/tests bug00007.c

[email protected] ("Pierre-Alain Joye")
Newsgroups php.gd.cvs
Message-ID <cvspajoye1160343796@cvsserver>
pajoye		Sun Oct  8 21:43:16 2006 UTC

  Added files:                 
    /gd/libgd/tests	bug00007.c 

  Modified files:              
    /gd/libgd	gd.c ISSUES 
  Log:
  - #7, imagecopy doen't copy the alpha channel, palette to truecolor copy
  
  
http://cvs.php.net/viewvc.cgi/gd/libgd/gd.c?r1=1.33&r2=1.34&diff_format=u
Index: gd/libgd/gd.c
diff -u gd/libgd/gd.c:1.33 gd/libgd/gd.c:1.34
--- gd/libgd/gd.c:1.33	Thu Sep 28 08:16:30 2006
+++ gd/libgd/gd.c	Sun Oct  8 21:43:16 2006
@@ -1975,52 +1975,60 @@
   int tox, toy;
   int i;
   int colorMap[gdMaxColors];
-  if (dst->trueColor)
-    {
-      /* 2.0: much easier when the destination is truecolor. */
-      /* 2.0.10: needs a transparent-index check that is still valid if
-         the source is not truecolor. Thanks to Frank Warmerdam. */
-      for (y = 0; (y < h); y++)
-	{
-	  for (x = 0; (x < w); x++)
-	    {
-	      int p = gdImageGetPixel (src, srcX + x, srcY + y);
-	      if (p != src->transparent)
-		{
-		  int c = gdImageGetTrueColorPixel (src, srcX + x,
-						    srcY + y);
-		  gdImageSetPixel (dst, dstX + x, dstY + y, c);
-		}
-	    }
-	}
-      return;
-    }
+
+  if (dst->trueColor) {
+	  /* 2.0: much easier when the destination is truecolor. */
+	  /* 2.0.10: needs a transparent-index check that is still valid if
+	   *          * the source is not truecolor. Thanks to Frank Warmerdam.
+	   *                   */
+
+	  if (src->trueColor) {
+		  for (y = 0; (y < h); y++) {
+			  for (x = 0; (x < w); x++) {
+				  int c = gdImageGetTrueColorPixel (src, srcX + x, srcY + y);
+				  gdImageSetPixel (dst, dstX + x, dstY + y, c);
+			  }
+		  }
+	  } else {
+		  /* source is palette based */
+		  for (y = 0; (y < h); y++) {
+			  for (x = 0; (x < w); x++) {
+				  int c = gdImageGetPixel (src, srcX + x, srcY + y);
+				  if (c != src->transparent) {
+					  gdImageSetPixel(dst, dstX + x, dstY + y, gdTrueColorAlpha(src->red[c], src->green[c], src->blue[c], src->alpha[c]));
+				  }
+			  }
+		  }
+	  }
+	  return;
+  }
+
   for (i = 0; (i < gdMaxColors); i++)
-    {
-      colorMap[i] = (-1);
-    }
+  {
+	  colorMap[i] = (-1);
+  }
   toy = dstY;
   for (y = srcY; (y < (srcY + h)); y++)
-    {
-      tox = dstX;
-      for (x = srcX; (x < (srcX + w)); x++)
-	{
-	  int nc;
-	  int mapTo;
-	  c = gdImageGetPixel (src, x, y);
-	  /* Added 7/24/95: support transparent copies */
-	  if (gdImageGetTransparent (src) == c)
-	    {
-	      tox++;
-	      continue;
-	    }
-	  /* Have we established a mapping for this color? */
-	  if (src->trueColor)
-	    {
-	      /* 2.05: remap to the palette available in the
-	         destination image. This is slow and
-	         works badly, but it beats crashing! Thanks 
-	         to Padhrig McCarthy. */
+  {
+	  tox = dstX;
+	  for (x = srcX; (x < (srcX + w)); x++)
+	  {
+		  int nc;
+		  int mapTo;
+		  c = gdImageGetPixel (src, x, y);
+		  /* Added 7/24/95: support transparent copies */
+		  if (gdImageGetTransparent (src) == c)
+		  {
+			  tox++;
+			  continue;
+		  }
+		  /* Have we established a mapping for this color? */
+		  if (src->trueColor)
+		  {
+			  /* 2.05: remap to the palette available in the
+				 destination image. This is slow and
+				 works badly, but it beats crashing! Thanks 
+				 to Padhrig McCarthy. */
 	      mapTo = gdImageColorResolveAlpha (dst,
 						gdTrueColorGetRed (c),
 						gdTrueColorGetGreen (c),
http://cvs.php.net/viewvc.cgi/gd/libgd/ISSUES?r1=1.5&r2=1.6&diff_format=u
Index: gd/libgd/ISSUES
diff -u gd/libgd/ISSUES:1.5 gd/libgd/ISSUES:1.6
--- gd/libgd/ISSUES:1.5	Sun Oct  8 16:42:47 2006
+++ gd/libgd/ISSUES	Sun Oct  8 21:43:16 2006
@@ -9,3 +9,5 @@
 #4, TrueColor transparent color not used  with GIF output (palette)
 #5, Numerous security fixes in GIF loader. When the gif palette is broken, 
     the image size is invalid or NULL block at unexpected postions.
+#6, Add test for gdImagePng and transparent color
+#7, gdIimageCopy doen't use the alpha channel (palette to truecolor copy)

http://cvs.php.net/viewvc.cgi/gd/libgd/tests/bug00007.c?view=markup&rev=1.1
Index: gd/libgd/tests/bug00007.c
+++ gd/libgd/tests/bug00007.c
#include "gd.h"

int main()
{
 	gdImagePtr dst_tc, src;
	FILE *fp;
	int c0,c1,c3;

	src  = gdImageCreate(5,5);
	c0 = gdImageColorAllocate(src, 255,255,255);
	c1 = gdImageColorAllocateAlpha(src, 255,0,0,70);

	gdImageAlphaBlending(src, 0);
	gdImageFill(src, 0,0, c1);

	dst_tc  = gdImageCreateTrueColor(5,5);
	gdImageAlphaBlending(dst_tc, 0);

	gdImageCopy(dst_tc, src, 0,0, 0,0, gdImageSX(src), gdImageSY(src));
 	gdImagePng(dst_tc, fp);
	fclose(fp);

 	/* Destroy it */
 	gdImageDestroy(src);
 	gdImageDestroy(dst_tc);

 	return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.