iliaa           Sun Nov 24 20:51:53 2002 EDT

  Modified files:              
    /php4/ext/gd        config.m4 
    /php4/ext/gd/libgd  gd.c gd.h gd_gd2.c gd_jpeg.c gd_png.c gd_wbmp.c 
                        gdft.c gdxpm.c 
  Log:
  Synchronized bundled gd library with the latest stable GD, 2.0.6
  Fixed a configuration problem with xpm.
  Fixed 2 possible memory leaks in fontFetch().
  
  
Index: php4/ext/gd/config.m4
diff -u php4/ext/gd/config.m4:1.123 php4/ext/gd/config.m4:1.124
--- php4/ext/gd/config.m4:1.123 Sun Nov 17 19:41:27 2002
+++ php4/ext/gd/config.m4       Sun Nov 24 20:51:52 2002
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.123 2002/11/18 00:41:27 sniper Exp $
+dnl $Id: config.m4,v 1.124 2002/11/25 01:51:52 iliaa Exp $
 dnl
 
 dnl
@@ -112,7 +112,7 @@
     fi
 
     for i in include include/X11; do
-      test -f $GD_XPM_DIR/$i/xpm.h && GD_XPM_INC=$GD_XPM_DIR/$i
+      test -f $GD_XPM_DIR/$i/xpm.h && GD_XPM_INC=$GD_XPM_DIR/include
     done
 
     if test -z "$GD_XPM_INC"; then
Index: php4/ext/gd/libgd/gd.c
diff -u php4/ext/gd/libgd/gd.c:1.27 php4/ext/gd/libgd/gd.c:1.28
--- php4/ext/gd/libgd/gd.c:1.27 Sun Nov 17 09:25:50 2002
+++ php4/ext/gd/libgd/gd.c      Sun Nov 24 20:51:52 2002
@@ -244,7 +244,7 @@
 #define RETURN_HWB(h, w, b) {HWB->H = h; HWB->W = w; HWB->B = b; return HWB;}
 #define RETURN_RGB(r, g, b) {RGB->R = r; RGB->G = g; RGB->B = b; return RGB;}
 #define HWB_UNDEFINED -1
-#define SETUP_RGB(s, r, g, b) {s.R = r/255.0f; s.G = g/255.0f; s.B = b/255.0f;}
+#define SETUP_RGB(s, r, g, b) {s.R = r/255.0; s.G = g/255.0; s.B = b/255.0;}
 
 #ifndef MIN
 #define MIN(a,b) ((a)<(b)?(a):(b))
@@ -315,14 +315,14 @@
 
   if ((HWB1.H == HWB_UNDEFINED) || (HWB2.H == HWB_UNDEFINED))
     {
-      diff = 0.0f;                     /* Undefined hues always match... */
+      diff = 0;                        /* Undefined hues always match... */
     }
   else
     {
-      diff = fabsf (HWB1.H - HWB2.H);
-      if (diff > 3.0f)
+      diff = abs (HWB1.H - HWB2.H);
+      if (diff > 3)
        {
-         diff = 6.0f - diff;   /* Remember, it's a colour circle */
+         diff = 6 - diff;      /* Remember, it's a colour circle */
        }
     }
 
@@ -375,8 +375,9 @@
     }
 
   return RGB;
+
 }
-#endif /* 0 */
+#endif
 
 int
 gdImageColorClosestHWB (gdImagePtr im, int r, int g, int b)
@@ -516,12 +517,12 @@
          op = c;               /* Save open slot */
          continue;             /* Color not in use */
        }
-    if (c == im->transparent)
-    {
-        /* don't ever resolve to the color that has
-         * been designated as the transparent color */
-        continue;
-    }
+      if (c == im->transparent)
+        {
+          /* don't ever resolve to the color that has
+           * been designated as the transparent color */
+          continue;
+       }
       rd = (long) (im->red[c] - r);
       gd = (long) (im->green[c] - g);
       bd = (long) (im->blue[c] - b);
@@ -873,10 +874,15 @@
   if (dy <= dx)
     {
       /* More-or-less horizontal. use wid for vertical stroke */
-      wid = (int)(thick * cos (atan2 (dy, dx)));
-      if (wid == 0)
-       wid = 1;
-
+      /* Doug Claar: watch out for NaN in atan2 (2.0.5) */
+      if ((dx == 0) && (dy == 0)) {
+        wid = 1;
+      } else {
+        wid = thick * cos (atan2 (dy, dx));
+        if (wid == 0) {
+          wid = 1;
+        }
+      }
       d = 2 * dy - dx;
       incr1 = 2 * dy;
       incr2 = 2 * (dy - dx);
@@ -942,7 +948,7 @@
   else
     {
       /* More-or-less vertical. use wid for horizontal stroke */
-      wid = (int)(thick * sin (atan2 (dy, dx)));
+      wid = thick * sin (atan2 (dy, dx));
       if (wid == 0)
        wid = 1;
 
@@ -1027,7 +1033,7 @@
   if (dy <= dx)
     {
       /* More-or-less horizontal. use wid for vertical stroke */
-      wid = (int)(thick * sin (atan2 (dy, dx)));
+      wid = thick * sin (atan2 (dy, dx));
       vert = 1;
 
       d = 2 * dy - dx;
@@ -1086,7 +1092,7 @@
   else
     {
       /* More-or-less vertical. use wid for horizontal stroke */
-      wid = (int)(thick * sin (atan2 (dy, dx)));
+      wid = thick * sin (atan2 (dy, dx));
       vert = 0;
 
       d = 2 * dx - dy;
@@ -1790,6 +1796,7 @@
       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)
@@ -1798,7 +1805,19 @@
              continue;
            }
          /* Have we established a mapping for this color? */
-         if (colorMap[c] == (-1))
+         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),
+                                            gdTrueColorGetBlue (c),
+                                          gdTrueColorGetAlpha (c));
+           }
+         else if (colorMap[c] == (-1))
            {
              /* If it's the same image, mapping is trivial */
              if (dst == src)
@@ -1815,8 +1834,13 @@
                                               src->blue[c], src->alpha[c]);
                }
              colorMap[c] = nc;
+              mapTo = colorMap[c];  
            }
-         gdImageSetPixel (dst, tox, toy, colorMap[c]);
+          else
+            {
+              mapTo = colorMap[c];  
+            }
+         gdImageSetPixel (dst, tox, toy, mapTo);
          tox++;
        }
       toy++;
@@ -1856,12 +1880,12 @@
            {
              dc = gdImageGetPixel (dst, tox, toy);
 
-             ncR = (int)( gdImageRed (src, c) * (pct / 100.0f)
-                        + gdImageRed (dst, dc) * ((100 - pct) / 100.0f));
-             ncG = (int)( gdImageGreen (src, c) * (pct / 100.0f)
-                        + gdImageGreen (dst, dc) * ((100 - pct) / 100.0f));
-             ncB = (int)( gdImageBlue (src, c) * (pct / 100.0f)
-                        + gdImageBlue (dst, dc) * ((100 - pct) / 100.0f));
+             ncR = gdImageRed (src, c) * (pct / 100.0)
+               + gdImageRed (dst, dc) * ((100 - pct) / 100.0);
+             ncG = gdImageGreen (src, c) * (pct / 100.0)
+               + gdImageGreen (dst, dc) * ((100 - pct) / 100.0);
+             ncB = gdImageBlue (src, c) * (pct / 100.0)
+               + gdImageBlue (dst, dc) * ((100 - pct) / 100.0);
 
              /* Find a reasonable color */
              nc = gdImageColorResolve (dst, ncR, ncG, ncB);
@@ -1906,19 +1930,19 @@
          else
            {
              dc = gdImageGetPixel (dst, tox, toy);
-             g = 0.29900f * dst->red[dc]
-               + 0.58700f * dst->green[dc]
-               + 0.11400f * dst->blue[dc];
-
-             ncR = (int)( gdImageRed (src, c) * (pct / 100.0f)
-                        + gdImageRed (dst, dc) * g * ((100 - pct) / 100.0f));
-
-             ncG = (int)( gdImageGreen (src, c) * (pct / 100.0f)
-                        + gdImageGreen (dst, dc) * g * ((100 - pct) / 100.0f));
-
-             ncB = (int)( gdImageBlue (src, c) * (pct / 100.0f)
-                        + gdImageBlue (dst, dc) * g * ((100 - pct) / 100.0f));
-
+             g = 0.29900 * dst->red[dc]
+               + 0.58700 * dst->green[dc]
+               + 0.11400 * dst->blue[dc];
+
+             ncR = gdImageRed (src, c) * (pct / 100.0)
+               + gdImageRed (dst, dc) * g *
+               ((100 - pct) / 100.0);
+             ncG = gdImageGreen (src, c) * (pct / 100.0)
+               + gdImageGreen (dst, dc) * g *
+               ((100 - pct) / 100.0);
+             ncB = gdImageBlue (src, c) * (pct / 100.0)
+               + gdImageBlue (dst, dc) * g *
+               ((100 - pct) / 100.0);
 
              /* First look for an exact match */
              nc = gdImageColorExact (dst, ncR, ncG, ncB);
@@ -2037,11 +2061,12 @@
                          else
                            {
                              /* Find or create the best match */
-                             mapTo = gdImageColorResolveAlpha (dst,
-                                                     gdTrueColorGetRed (c),
-                                                   gdTrueColorGetGreen (c),
-                                                    gdTrueColorGetBlue (c),
-                                                  gdTrueColorGetAlpha (c));
+                  /* 2.0.5: can't use gdTrueColorGetRed, etc with palette */
+                             nc = gdImageColorResolveAlpha (dst,
+                                                     gdImageRed (src, c),
+                                                   gdImageGreen (src, c),
+                                                    gdImageBlue (src, c),
+                                                  gdImageAlpha (src, c));
                            }
                          colorMap[c] = nc;
                        }
@@ -2088,37 +2113,36 @@
        {
          float sy1, sy2, sx1, sx2;
          float sx, sy;
-         float spixels = 0.0f;
-         float red = 0.0f, green = 0.0f, blue = 0.0f, alpha = 0.0f;
-         float alpha_factor, alpha_sum = 0.0f, contrib_sum = 0.0f;
-         sy1 = ((float)(y - dstY)) * (float)srcH /
-           (float)dstH;
-         sy2 = ((float)(y + 1 - dstY)) * (float) srcH /
+         float spixels = 0;
+         float red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0, alpha_sum = 0.0, 
+contrib_sum = 0.0, alpha_factor;
+         sy1 = ((float) y - (float) dstY) * (float) srcH /
+           (float) dstH;
+         sy2 = ((float) (y + 1) - (float) dstY) * (float) srcH /
            (float) dstH;
          sy = sy1;
          do
            {
              float yportion;
-             if (floorf(sy) == floorf(sy1))
+             if (floor (sy) == floor (sy1))
                {
-                 yportion = 1.0f - (sy - floorf(sy));
+                 yportion = 1.0 - (sy - floor (sy));
                  if (yportion > sy2 - sy1)
                    {
                      yportion = sy2 - sy1;
                    }
-                 sy = floorf(sy);
+                 sy = floor (sy);
                }
-             else if (sy == floorf(sy2))
+             else if (sy == floor (sy2))
                {
-                 yportion = sy2 - floorf(sy2);
+                 yportion = sy2 - floor (sy2);
                }
              else
                {
-                 yportion = 1.0f;
+                 yportion = 1.0;
                }
-             sx1 = ((float)(x - dstX)) * (float) srcW /
+             sx1 = ((float) x - (float) dstX) * (float) srcW /
                dstW;
-             sx2 = ((float)(x + 1 - dstX)) * (float) srcW /
+             sx2 = ((float) (x + 1) - (float) dstX) * (float) srcW /
                dstW;
              sx = sx1;
              do
@@ -2126,68 +2150,69 @@
                  float xportion;
                  float pcontribution;
                  int p;
-                 if (floorf(sx) == floorf(sx1))
+                 if (floor (sx) == floor (sx1))
                    {
-                     xportion = 1.0f - (sx - floorf(sx));
+                     xportion = 1.0 - (sx - floor (sx));
                      if (xportion > sx2 - sx1)
                        {
                          xportion = sx2 - sx1;
                        }
-                     sx = floorf(sx);
+                     sx = floor (sx);
                    }
-                 else if (sx == floorf(sx2))
+                 else if (sx == floor (sx2))
                    {
-                     xportion = sx2 - floorf(sx2);
+                     xportion = sx2 - floor (sx2);
                    }
                  else
                    {
-                     xportion = 1.0f;
+                     xportion = 1.0;
                    }
                  pcontribution = xportion * yportion;
                  p = gdImageGetTrueColorPixel (
                                                 src,
-                                                (int) sx + srcX,
-                                                (int) sy + srcY);
+                                                (int) sx,
+                                                (int) sy);
                  alpha_factor = ((gdAlphaMax - gdTrueColorGetAlpha(p))) * 
pcontribution;
-                 red += gdTrueColorGetRed (p) * alpha_factor;
-                 green += gdTrueColorGetGreen (p) * alpha_factor;
-                 blue += gdTrueColorGetBlue (p) * alpha_factor;
+                 green += gdTrueColorGetGreen (p) * pcontribution;             
+                 red += gdTrueColorGetRed (p) * alpha_factor;                  
+                 blue += gdTrueColorGetBlue (p) * pcontribution;               
+                 green += gdTrueColorGetGreen (p) * alpha_factor;              
                  alpha += gdTrueColorGetAlpha (p) * pcontribution;
                  alpha_sum += alpha_factor;
-                 contrib_sum += pcontribution;
+                 contrib_sum += pcontribution;                                 
                  spixels += xportion * yportion;
-                 sx += 1.0f;
+                 sx += 1.0;
                }
              while (sx < sx2);
-             sy += 1.0f;
+             sy += 1.0;
            }
          while (sy < sy2);
-         if (spixels != 0.0f)
+         if (spixels != 0.0)
            {
              red /= spixels;
              green /= spixels;
              blue /= spixels;
              alpha /= spixels;
            }
-          if ( alpha_sum != 0.0f)
+          if ( alpha_sum != 0.0)
             {
-              if( contrib_sum != 0.0f ) alpha_sum /= contrib_sum;
+              if( contrib_sum != 0.0 ) alpha_sum /= contrib_sum;
               red /= alpha_sum;
               green /= alpha_sum;
               blue /= alpha_sum;
             }
          /* Clamping to allow for rounding errors above */
-         if (red > 255.0f)
+         if (red > 255.0)
            {
-             red = 255.0f;
+             red = 255.0;
            }
-         if (green > 255.0f)
+         if (green > 255.0)
            {
-             green = 255.0f;
+             green = 255.0;
            }
-         if (blue > 255.0f)
+         if (blue > 255.0)
            {
-             blue = 255.0f;
+             blue = 255.0;
            }
          if (alpha > gdAlphaMax)
            {
@@ -2709,7 +2734,7 @@
   for (i = 0; (i < bytes); i++)
     {
       char h[3];
-      int b;
+      unsigned int b;
       /* Skip spaces, commas, CRs, 0x */
       while (1)
        {
Index: php4/ext/gd/libgd/gd.h
diff -u php4/ext/gd/libgd/gd.h:1.8 php4/ext/gd/libgd/gd.h:1.9
--- php4/ext/gd/libgd/gd.h:1.8  Wed Nov 13 15:02:58 2002
+++ php4/ext/gd/libgd/gd.h      Sun Nov 24 20:51:53 2002
@@ -298,6 +298,8 @@
        beats the exact same color with radically different
        transparency */
 int gdImageColorClosestAlpha(gdImagePtr im, int r, int g, int b, int a);
+/* An alternate method */
+int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b);
 /* Returns exact, 100% opaque matches only */
 int gdImageColorExact(gdImagePtr im, int r, int g, int b);
 /* Returns an exact match only, including alpha */
Index: php4/ext/gd/libgd/gd_gd2.c
diff -u php4/ext/gd/libgd/gd_gd2.c:1.4 php4/ext/gd/libgd/gd_gd2.c:1.5
--- php4/ext/gd/libgd/gd_gd2.c:1.4      Tue Nov 12 08:12:58 2002
+++ php4/ext/gd/libgd/gd_gd2.c  Sun Nov 24 20:51:53 2002
@@ -18,6 +18,10 @@
 #include "gd.h"
 #include "gdhelpers.h"
 
+/* 2.03: gd2 is no longer mandatory */
+/* JCE - test after including gd.h so that HAVE_LIBZ can be set in
+ * a config.h file included by gd.h */
+#ifdef HAVE_ZLIB
 #include <zlib.h>
 
 #define TRUE 1
@@ -763,7 +767,7 @@
       /* The zlib notes say output buffer size should be (input size) * 1.01 * 12 */
       /* - we'll use 1.02 to be paranoid. */
       /* */
-      compMax = (int)(cs * bytesPerPixel * cs * 1.02 + 12);
+      compMax = cs * bytesPerPixel * cs * 1.02 + 12;
 
       /* */
       /* Allocate the buffers.  */
@@ -922,3 +926,18 @@
   out->gd_free (out);
   return rv;
 }
+
+#else /* no HAVE_ZLIB */
+gdImagePtr
+gdImageCreateFromGd2 (FILE * inFile)
+{
+  fprintf(stderr,"GD2 support is not available - no libz\n");
+  return NULL;
+}
+gdImagePtr
+gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
+{
+  fprintf(stderr,"GD2 support is not available - no libz\n");
+  return NULL;
+}
+#endif /* HAVE_ZLIB */
Index: php4/ext/gd/libgd/gd_jpeg.c
diff -u php4/ext/gd/libgd/gd_jpeg.c:1.5 php4/ext/gd/libgd/gd_jpeg.c:1.6
--- php4/ext/gd/libgd/gd_jpeg.c:1.5     Mon Nov 18 07:31:39 2002
+++ php4/ext/gd/libgd/gd_jpeg.c Sun Nov 24 20:51:53 2002
@@ -281,9 +281,8 @@
   volatile JSAMPROW row = 0;
   volatile gdImagePtr im = 0;
   JSAMPROW rowptr[1];
-  JDIMENSION i, j;
+  int i, j, retval;
   JDIMENSION nrows;
-  int retval;
 
 #ifdef JPEG_DEBUG
   printf ("gd-jpeg: gd JPEG version %s\n", GD_JPEG_VERSION);
@@ -812,7 +811,7 @@
   /* Write any data remaining in the buffer */
   if (datacount > 0)
     {
-      if ((size_t)gdPutBuf (dest->buffer, datacount, dest->outfile) != datacount)
+      if (gdPutBuf (dest->buffer, datacount, dest->outfile) != datacount)
        ERREXIT (cinfo, JERR_FILE_WRITE);
     }
 }
Index: php4/ext/gd/libgd/gd_png.c
diff -u php4/ext/gd/libgd/gd_png.c:1.5 php4/ext/gd/libgd/gd_png.c:1.6
--- php4/ext/gd/libgd/gd_png.c:1.5      Mon Nov 18 07:31:39 2002
+++ php4/ext/gd/libgd/gd_png.c  Sun Nov 24 20:51:53 2002
@@ -7,7 +7,6 @@
 /* JCE: Arrange HAVE_LIBPNG so that it can be set in gd.h */
 #ifdef HAVE_LIBPNG
 
-
 #include "png.h"               /* includes zlib.h and setjmp.h */
 #include "gdhelpers.h"
 
@@ -128,7 +127,6 @@
   png_bytepp row_pointers = NULL;
   gdImagePtr im = NULL;
   int i, j, *open = NULL;
-  png_uint_32 ui, uj;
   volatile int transparent = -1;
   volatile int palette_allocated = FALSE;
 
@@ -228,7 +226,7 @@
              im->alpha[i] = gdAlphaMax - (trans[i] >> 1);
              if ((trans[i] == 0) && (firstZero))
                {
-                                         transparent = i;
+                 transparent = i;
                  firstZero = 0;
                }
            }
@@ -321,9 +319,9 @@
     }
 
   /* set the individual row_pointers to point at the correct offsets */
-  for (uj = 0; uj < height; ++uj)
+  for (j = 0; j < height; ++j)
     {
-      row_pointers[uj] = image_data + uj * rowbytes;
+      row_pointers[j] = image_data + j * rowbytes;
     }
 
   png_read_image (png_ptr, row_pointers);      /* read whole image... */
@@ -354,44 +352,44 @@
   switch (color_type)
     {
     case PNG_COLOR_TYPE_RGB:
-      for (uj = 0; uj < height; uj++)
+      for (j = 0; j < height; j++)
        {
          int boffset = 0;
-         for (ui = 0; ui < width; ui++)
+         for (i = 0; i < width; i++)
            {
-             register png_byte r = row_pointers[uj][boffset++];
-             register png_byte g = row_pointers[uj][boffset++];
-             register png_byte b = row_pointers[uj][boffset++];
-             im->tpixels[uj][ui] = gdTrueColor (r, g, b);
+             register png_byte r = row_pointers[j][boffset++];
+             register png_byte g = row_pointers[j][boffset++];
+             register png_byte b = row_pointers[j][boffset++];
+             im->tpixels[j][i] = gdTrueColor (r, g, b);
            }
        }
       break;
     case PNG_COLOR_TYPE_RGB_ALPHA:
-      for (uj = 0; uj < height; uj++)
+      for (j = 0; j < height; j++)
        {
          int boffset = 0;
-         for (ui = 0; ui < width; ui++)
+         for (i = 0; i < width; i++)
            {
-             register png_byte r = row_pointers[uj][boffset++];
-             register png_byte g = row_pointers[uj][boffset++];
-             register png_byte b = row_pointers[uj][boffset++];
+             register png_byte r = row_pointers[j][boffset++];
+             register png_byte g = row_pointers[j][boffset++];
+             register png_byte b = row_pointers[j][boffset++];
              /* gd has only 7 bits of alpha channel resolution, and
                 127 is transparent, 0 opaque. A moment of convenience, 
                 a lifetime of compatibility. */
              register png_byte a = gdAlphaMax -
-             (row_pointers[uj][boffset++] >> 1);
-             im->tpixels[uj][ui] = gdTrueColorAlpha (r, g, b, a);
+             (row_pointers[j][boffset++] >> 1);
+             im->tpixels[j][i] = gdTrueColorAlpha (r, g, b, a);
            }
        }
       break;
     default:
       /* Palette image, or something coerced to be one */
-      for (uj = 0; uj < height; ++uj)
+      for (j = 0; j < height; ++j)
        {
-         for (ui = 0; ui < width; ++ui)
+         for (i = 0; i < width; ++i)
            {
-             register png_byte idx = row_pointers[uj][ui];
-             im->pixels[uj][ui] = idx;
+             register png_byte idx = row_pointers[j][i];
+             im->pixels[j][i] = idx;
              open[idx] = 0;
            }
        }
@@ -597,7 +595,7 @@
            {
              trans_values[i] = 255 -
                ((im->alpha[i] << 1) +
-                (im->alpha[i] >> 7));
+                (im->alpha[i] >> 6));
            }
          png_set_tRNS (png_ptr, info_ptr, trans_values, 256, NULL);
 #endif
@@ -616,9 +614,10 @@
                {
                  if (im->alpha[i] != gdAlphaOpaque)
                    {
+                      /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */ 
                      trans_values[j] = 255 -
                        ((im->alpha[i] << 1) +
-                        (im->alpha[i] >> 7));
+                        (im->alpha[i] >> 6));
                      mapping[i] = j++;
                    }
                  else
@@ -699,7 +698,8 @@
                     127 maps to 255. We also have to invert to match
                     PNG's convention in which 255 is opaque. */
                  a = gdTrueColorGetAlpha (im->tpixels[j][i]);
-                 row_pointers[j][bo++] = 255 - ((a << 1) + (a >> 7));
+                  /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */ 
+                 row_pointers[j][bo++] = 255 - ((a << 1) + (a >> 6));
                }
            }
        }
Index: php4/ext/gd/libgd/gd_wbmp.c
diff -u php4/ext/gd/libgd/gd_wbmp.c:1.3 php4/ext/gd/libgd/gd_wbmp.c:1.4
--- php4/ext/gd/libgd/gd_wbmp.c:1.3     Tue Oct 29 18:08:01 2002
+++ php4/ext/gd/libgd/gd_wbmp.c Sun Nov 24 20:51:53 2002
@@ -70,7 +70,7 @@
 void
 gd_putout (int i, void *out)
 {
-  gdPutC ((unsigned char)i, (gdIOCtx *) out);
+  gdPutC (i, (gdIOCtx *) out);
 }
 
 
Index: php4/ext/gd/libgd/gdft.c
diff -u php4/ext/gd/libgd/gdft.c:1.15 php4/ext/gd/libgd/gdft.c:1.16
--- php4/ext/gd/libgd/gdft.c:1.15       Sat Nov 23 20:30:51 2002
+++ php4/ext/gd/libgd/gdft.c    Sun Nov 24 20:51:53 2002
@@ -32,12 +32,21 @@
 gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist,
                  double ptsize, double angle, int x, int y, char *string)
 {
+  /* 2.0.6: valid return */ 
   return gdImageStringFT (im, brect, fg, fontlist, ptsize,
                   angle, x, y, string);
 }
 
 #ifndef HAVE_LIBFREETYPE
 char *
+gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
+                double ptsize, double angle, int x, int y, char *string,
+                gdFTStringExtraPtr strex)
+{
+  return "libgd was not built with FreeType font support\n";
+}
+
+char *
 gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
                 double ptsize, double angle, int x, int y, char *string)
 {
@@ -402,6 +411,7 @@
                        }
                }
                gdFree(path);
+               path = NULL;
                if (font_found) {
                        break;
                }       
@@ -416,6 +426,9 @@
        if (!font_found) {
                gdPFree(a->fontlist);
                gdPFree(a);
+               if (fullname) {
+                       gdFree(fullname);
+               }
                *error = "Could not find/open font";
                return NULL;
        }
@@ -424,6 +437,9 @@
        if (err) {
                gdPFree(a->fontlist);
                gdPFree(a);
+               if (fullname) {
+                       gdFree(fullname);
+               }
                *error = "Could not read font";
                return NULL;
        }
@@ -466,6 +482,8 @@
                return NULL;
        }
 
+       /* 2.0.5: we should actually return this */
+       a->face->charmap = found;
        return (void *) a;
 }
 
@@ -563,7 +581,7 @@
 {
   unsigned char *pixel = NULL;
   int *tpixel = NULL;
-  int x, y, row, col, pc;
+  int x, y, row, col, pc, pcr;
 
   tweencolor_t *tc_elem;
   tweencolorkey_t tc_key;
@@ -577,6 +595,7 @@
     for (row = 0; row < bitmap.rows; row++)
       {
         pc = row * bitmap.pitch;
+        pcr = pc;
         y = pen_y + row;
         /* clip if out of bounds */
         if (y >= im->sy || y < 0)
@@ -595,17 +614,20 @@
             }
           else if (bitmap.pixel_mode == ft_pixel_mode_mono)
             {
-              level = ((bitmap.buffer[pc / 8]
-                              << (pc % 8)) & 128) ? gdAlphaOpaque :
-                gdAlphaTransparent;
+              /* 2.0.5: mode_mono fix from Giuliano Pochini */
+              level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07)))
+               ? gdAlphaTransparent :
+                gdAlphaOpaque;
             }  
           else 
            {
              return "Unsupported ft_pixel_mode";
            }
-          if (fg >= 0) {
+          if ((fg >= 0) && (im->trueColor)) {
             /* Consider alpha in the foreground color itself to be an
-              upper bound on how opaque things get */
+              upper bound on how opaque things get, when truecolor is
+              available. Without truecolor this results in far too many
+              color indexes. */ 
             level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax;
           }
           level = gdAlphaMax - level;  
@@ -633,7 +655,9 @@
     /* Non-truecolor case, restored to its more or less original form */ 
   for (row = 0; row < bitmap.rows; row++)
     {
+      int pcr;
       pc = row * bitmap.pitch;
+      pcr = pc;
       if(bitmap.pixel_mode==ft_pixel_mode_mono)
              pc *= 8;    /* pc is measured in bits for monochrome images */
 
@@ -660,6 +684,9 @@
            {
              tc_key.pixel = ((bitmap.buffer[pc / 8]
                               << (pc % 8)) & 128) ? NUMCOLORS : 0;
+              /* 2.0.5: mode_mono fix from Giuliano Pochini */
+              tc_key.pixel = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07)))
+               ? NUMCOLORS : 0;
            }
          else
            {
@@ -722,17 +749,19 @@
 
 /********************************************************************/
 /* gdImageStringFT -  render a utf8 string onto a gd image          */
+
 char *
 gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
-                 double ptsize, double angle, int x, int y, char *string)
+                double ptsize, double angle, int x, int y, char *string)
 {
-    return gdImageStringFTEx(im, brect, fg, fontlist, ptsize, angle, x, y, string, 
NULL);
+       return gdImageStringFTEx(im, brect, fg, fontlist,
+               ptsize, angle, x, y, string, 0);
 }
 
 char *
 gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
                 double ptsize, double angle, int x, int y, char *string,
-                gdFTStringExtra * strex)
+               gdFTStringExtraPtr strex)
 {
   FT_BBox bbox, glyph_bbox;
   FT_Matrix matrix;
@@ -754,10 +783,9 @@
   int render = (im && (im->trueColor || (fg <= 255 && fg >= -255)));
   FT_BitmapGlyph bm;
   int render_mode = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;
-
-  /* fine tuning */
+  /* Now tuneable thanks to Wez Furlong */
   double linespace = LINESPACE;
-
+  /* 2.0.6: put this declaration with the other declarations! */
   /*
    *   make a new tweenColorCache on every call
    *   because caching colormappings between calls
@@ -767,6 +795,11 @@
    */
   gdCache_head_t  *tc_cache;
 
+  if (strex) {
+    if ((strex->flags & gdFTEX_LINESPACE) == gdFTEX_LINESPACE) {
+      linespace = strex->linespacing;
+    }
+  }
   tc_cache = gdCacheCreate( TWEENCOLORCACHESIZE,
                tweenColorTest, tweenColorFetch, tweenColorRelease );
 
@@ -803,12 +836,6 @@
       return "Could not set character size";
     }
 
-    /* pull in supplied extended settings */
-    if (strex)      {
-        if ((strex->flags & gdFTEX_LINESPACE) == gdFTEX_LINESPACE)
-        linespace = strex->linespacing;
-    }
-
   matrix.xx = (FT_Fixed) (cos_a * (1 << 16));
   matrix.yx = (FT_Fixed) (sin_a * (1 << 16));
   matrix.xy = -matrix.yx;
@@ -853,8 +880,8 @@
       if (ch == '\r')
        {
          penf.x = 0;
-         x1 = (int)((penf.x * cos_a - penf.y * sin_a + 32.0) / 64.0);
-         y1 = (int)((penf.x * sin_a + penf.y * cos_a + 32.0) / 64.0);
+         x1 = (penf.x * cos_a - penf.y * sin_a + 32) / 64;
+         y1 = (penf.x * sin_a + penf.y * cos_a + 32) / 64;
          pen.x = pen.y = 0;
          previous = 0;         /* clear kerning flag */
          next++;
@@ -863,10 +890,10 @@
       /* newlines */
       if (ch == '\n')
        {
-         penf.y = penf.y - (int)(face->size->metrics.height * LINESPACE);
+         penf.y -= face->size->metrics.height * linespace;
          penf.y = (penf.y - 32) & -64;         /* round to next pixel row */
-         x1 = (int)((penf.x * cos_a - penf.y * sin_a + 32.0) / 64.0);
-         y1 = (int)((penf.x * sin_a + penf.y * cos_a + 32.0) / 64.0);
+         x1 = (penf.x * cos_a - penf.y * sin_a + 32) / 64;
+         y1 = (penf.x * sin_a + penf.y * cos_a + 32) / 64;
          pen.x = pen.y = 0;
          previous = 0;         /* clear kerning flag */
          next++;
@@ -929,10 +956,8 @@
              next++;
            }
        }
-
       /* set rotation transform */
       FT_Set_Transform(face, &matrix, NULL);
-
       /* Convert character code to glyph index */
       glyph_index = FT_Get_Char_Index (face, ch);
 
Index: php4/ext/gd/libgd/gdxpm.c
diff -u php4/ext/gd/libgd/gdxpm.c:1.2 php4/ext/gd/libgd/gdxpm.c:1.3
--- php4/ext/gd/libgd/gdxpm.c:1.2       Wed Oct 30 12:54:36 2002
+++ php4/ext/gd/libgd/gdxpm.c   Sun Nov 24 20:51:53 2002
@@ -7,21 +7,13 @@
  */
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include "gd.h"
 #include "gdhelpers.h"
 
-#ifndef HAVE_XPM
-gdImagePtr
-gdImageCreateFromXpm (char *filename)
-{
-  fprintf (stderr, "libgd was not built with xpm support\n");
-  return (NULL);
-}
-
-#else
+#ifdef HAVE_XPM
 
-#include "xpm.h"
-#include <string.h>
+#include <X11/xpm.h>
 
 gdImagePtr
 gdImageCreateFromXpm (char *filename)
@@ -46,8 +38,6 @@
 
   number = image.ncolors;
   colors = (int *) gdMalloc (sizeof (int) * number);
-  if (colors == NULL)
-    return (0);
   for (i = 0; i < number; i++)
     {
       switch (strlen (image.colorTable[i].c_color))
@@ -129,11 +119,9 @@
     }
 
   apixel = (char *) gdMalloc (image.cpp + 1);
-  if (apixel == NULL)
-    return (0);
   apixel[image.cpp] = '\0';
 
-  pointer = image.data;
+  pointer = (int *) image.data;
   for (i = 0; i < image.height; i++)
     {
       for (j = 0; j < image.width; j++)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to