]> git.pld-linux.org Git - packages/gd.git/blob - gd-fixes.patch
- fix for gdTiled-related SEGV (uninitialized variable) (gdTiled-segv patch)
[packages/gd.git] / gd-fixes.patch
1 diff -Nur gd-2.0.1.orig/gd.c gd-2.0.1/gd.c
2 --- gd-2.0.1.orig/gd.c  Sat Aug 10 23:19:14 2002
3 +++ gd-2.0.1/gd.c       Sat Aug 10 23:39:35 2002
4 @@ -473,6 +473,12 @@
5           op = c;               /* Save open slot */
6           continue;             /* Color not in use */
7         }
8 +      if (c == im->transparent)
9 +        {
10 +         /* don't ever resolve to the color that has
11 +          * been designated as the transparent color */
12 +         continue;
13 +        }
14        rd = (long) (im->red[c] - r);
15        gd = (long) (im->green[c] - g);
16        bd = (long) (im->blue[c] - b);
17 @@ -1928,7 +1934,7 @@
18                           else
19                             {
20                               /* Find or create the best match */
21 -                             mapTo = gdImageColorResolveAlpha (dst,
22 +                             nc = gdImageColorResolveAlpha (dst,
23                                                       gdTrueColorGetRed (c),
24                                                     gdTrueColorGetGreen (c),
25                                                      gdTrueColorGetBlue (c),
26 @@ -1978,7 +1984,7 @@
27      {
28        for (x = dstX; (x < dstX + dstW); x++)
29         {
30 -         int pd = gdImageGetPixel (dst, x, y);
31 +       /*  int pd = gdImageGetPixel (dst, x, y);  -- not used */
32           float sy1, sy2, sx1, sx2;
33           float sx, sy;
34           float spixels = 0;
35 diff -Nur gd-2.0.1.orig/gd_gd2.c gd-2.0.1/gd_gd2.c
36 --- gd-2.0.1.orig/gd_gd2.c      Tue Apr  3 22:44:41 2001
37 +++ gd-2.0.1/gd_gd2.c   Sat Aug 10 23:48:23 2002
38 @@ -635,10 +635,10 @@
39                     {
40                       if (im->trueColor)
41                         {
42 -                         ch = chunkBuf[chunkPos++] << 24 +
43 -                           chunkBuf[chunkPos++] << 16 +
44 -                           chunkBuf[chunkPos++] << 8 +
45 -                           chunkBuf[chunkPos++];
46 +                         ch = chunkBuf[chunkPos++] << 24;
47 +                         ch += chunkBuf[chunkPos++] << 16;
48 +                         ch += chunkBuf[chunkPos++] << 8;
49 +                         ch += chunkBuf[chunkPos++];
50                         }
51                       else
52                         {
53 diff -Nur gd-2.0.1.orig/gd_topal.c gd-2.0.1/gd_topal.c
54 --- gd-2.0.1.orig/gd_topal.c    Tue Apr  3 22:44:42 2001
55 +++ gd-2.0.1/gd_topal.c Sat Aug 10 23:55:17 2002
56 @@ -1035,6 +1035,8 @@
57               xx2 = inc2;
58               for (ic2 = BOX_C2_ELEMS - 1; ic2 >= 0; ic2--)
59                 {
60 +                 dist3 = dist2;
61 +                 xx3 = inc3;
62                   for (ic3 = BOX_C3_ELEMS - 1; ic3 >= 0; ic3--)
63                     {
64                       if (dist3 < *bptr)
65 diff -Nur gd-2.0.1.orig/gdft.c gd-2.0.1/gdft.c
66 --- gd-2.0.1.orig/gdft.c        Tue Apr  3 22:44:42 2001
67 +++ gd-2.0.1/gdft.c     Sun Aug 11 00:19:56 2002
68 @@ -349,7 +349,6 @@
69    fontsearchpath = getenv ("GDFONTPATH");
70    if (!fontsearchpath)
71      fontsearchpath = DEFAULT_FONTPATH;
72 -  path = strdup (fontsearchpath);
73    fontlist = strdup (a->fontlist);
74  
75    /*
76 @@ -358,7 +357,8 @@
77    for (name = gd_strtok_r (fontlist, LISTSEPARATOR, &strtok_ptr); name;
78         name = gd_strtok_r (0, LISTSEPARATOR, &strtok_ptr))
79      {
80 -
81 +      /* make a fresh copy each time - strtok corrupts it. */
82 +      path = strdup (fontsearchpath);
83        /*
84         * Allocate an oversized buffer that is guaranteed to be
85         * big enough for all paths to be tested.
86 @@ -384,11 +384,23 @@
87               font_found++;
88               break;
89             }
90 +         sprintf (fullname, "%s/%s.pfa", dir, name);
91 +         if (access (fullname, R_OK) == 0)
92 +           {
93 +             font_found++;
94 +             break;
95 +           }
96 +         sprintf (fullname, "%s/%s.pfb", dir, name);
97 +         if (access (fullname, R_OK) == 0)
98 +           {
99 +             font_found++;
100 +             break;
101 +           }
102         }
103        if (font_found)
104         break;
105 +      gdFree (path);
106      }
107 -  gdFree (path);
108    gdFree (fontlist);
109    if (!font_found)
110      {
111 @@ -497,7 +509,10 @@
112    /* if fg is specified by a negative color idx, then don't antialias */
113    if (fg < 0)
114      {
115 -      a->tweencolor = -fg;
116 +      if ((pixel + pixel) >= NUMCOLORS)
117 +       a->tweencolor = -fg;
118 +      else
119 +       a->tweencolor = bg;
120      }
121    else
122      {
123 @@ -534,7 +549,7 @@
124  
125  /* draw_bitmap - transfers glyph bitmap to GD image */
126  static char *
127 -gdft_draw_bitmap (gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
128 +gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
129  {
130    unsigned char *pixel;
131    int *tpixel;
132 @@ -543,21 +558,15 @@
133    tweencolor_t *tc_elem;
134    tweencolorkey_t tc_key;
135  
136 -  /* initialize tweenColorCache on first call */
137 -  static gdCache_head_t *tc_cache;
138 -
139 -  if (!tc_cache)
140 -    {
141 -      tc_cache = gdCacheCreate (TWEENCOLORCACHESIZE,
142 -                       tweenColorTest, tweenColorFetch, tweenColorRelease);
143 -    }
144 -
145    /* copy to image, mapping colors */
146    tc_key.fgcolor = fg;
147    tc_key.im = im;
148    for (row = 0; row < bitmap.rows; row++)
149      {
150        pc = row * bitmap.pitch;
151 +      if(bitmap.pixel_mode==ft_pixel_mode_mono)
152 +       pc *= 8;    /* pc is measured in bits for monochrome images */
153 +
154        y = pen_y + row;
155  
156        /* clip if out of bounds */
157 @@ -608,11 +617,11 @@
158                   /* use fg color directly */
159                   if (im->trueColor)
160                     {
161 -                     *tpixel = fg;
162 +                     *tpixel = abs( fg );
163                     }
164                   else
165                     {
166 -                     *pixel = fg;
167 +                     *pixel = abs( fg );
168                     }
169                 }
170               else
171 @@ -643,8 +652,29 @@
172    return (char *) NULL;
173  }
174  
175 +static int
176 +gdroundupdown (FT_F26Dot6 v1, int updown)
177 +{
178 +  return (!updown)
179 +    ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6)
180 +    : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6);
181 +}
182 +
183  extern int any2eucjp (char *, char *, unsigned int);
184  
185 +/* Persistent font cache until explicitly cleared */
186 +/*     Fonts can be used across multiple images */
187 +static gdCache_head_t *fontCache;
188 +static FT_Library library;
189 +
190 +void
191 +gdFreeFontCache() {
192 +  if (fontCache) {
193 +    gdCacheDelete(fontCache);
194 +    FT_Done_FreeType(library);
195 +  }
196 +}
197 +               
198  /********************************************************************/
199  /* gdImageStringFT -  render a utf8 string onto a gd image          */
200  
201 @@ -671,15 +701,26 @@
202    char *tmpstr = 0;
203    int render = (im && (im->trueColor || (fg <= 255 && fg >= -255)));
204    FT_BitmapGlyph bm;
205 +  int render_mode = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;
206  
207 -/***** initialize font library and font cache on first call ******/
208 -  static gdCache_head_t *fontCache;
209 -  static FT_Library library;
210 +  /*
211 +   *   make a new tweenColorCache on every call
212 +   *   because caching colormappings between calls
213 +   *   is not safe. If the im-pointer points to a
214 +   *   brand new image, the cache gives out bogus
215 +   *   colorindexes.          -- 27.06.2001 <krisku@arrak.fi>
216 +   */
217 +  gdCache_head_t  *tc_cache;
218 +
219 +  tc_cache = gdCacheCreate( TWEENCOLORCACHESIZE,
220 +             tweenColorTest, tweenColorFetch, tweenColorRelease );
221  
222 +/***** initialize font library and font cache on first call ******/
223    if (!fontCache)
224      {
225        if (FT_Init_FreeType (&library))
226         {
227 +         gdCacheDelete( tc_cache );
228           return "Failure to initialize font library";
229         }
230        fontCache = gdCacheCreate (FONTCACHESIZE,
231 @@ -693,6 +734,7 @@
232    font = (font_t *) gdCacheGet (fontCache, &fontkey);
233    if (!font)
234      {
235 +      gdCacheDelete( tc_cache );
236        return fontCache->error;
237      }
238    face = font->face;           /* shortcut */
239 @@ -701,6 +743,7 @@
240    if (FT_Set_Char_Size (face, 0, (FT_F26Dot6) (ptsize * 64),
241                         GD_RESOLUTION, GD_RESOLUTION))
242      {
243 +      gdCacheDelete( tc_cache );
244        return "Could not set character size";
245      }
246  
247 @@ -715,6 +758,10 @@
248  
249    use_kerning = FT_HAS_KERNING (face);
250    previous = 0;
251 +  if (fg < 0)
252 +    {
253 +      render_mode |= FT_LOAD_MONOCHROME;
254 +    }
255  
256  #ifndef JISX0208
257    if (font->have_char_map_sjis)
258 @@ -821,6 +868,9 @@
259             }
260         }
261  
262 +      /* set rotation transform */
263 +      FT_Set_Transform(face, &matrix, NULL);
264 +
265        /* Convert character code to glyph index */
266        glyph_index = FT_Get_Char_Index (face, ch);
267  
268 @@ -833,50 +883,60 @@
269         }
270  
271        /* load glyph image into the slot (erase previous one) */
272 -      err = FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT);
273 +      err = FT_Load_Glyph (face, glyph_index, render_mode);
274        if (err)
275 -       return "Problem loading glyph";
276 +       {
277 +         gdCacheDelete( tc_cache );
278 +         return "Problem loading glyph";
279 +       }
280  
281        /* transform glyph image */
282        FT_Get_Glyph (slot, &image);
283        if (brect)
284         {                       /* only if need brect */
285           FT_Glyph_Get_CBox (image, ft_glyph_bbox_gridfit, &glyph_bbox);
286 -         if (!i)
287 -           {                   /* if first character, init BB corner values */
288 -             bbox.xMin = bbox.yMin = (1 << 30) - 1;
289 -             bbox.xMax = bbox.yMax = -bbox.xMin;
290 -           }
291           glyph_bbox.xMin += penf.x;
292           glyph_bbox.yMin += penf.y;
293           glyph_bbox.xMax += penf.x;
294           glyph_bbox.yMax += penf.y;
295 -         if (bbox.xMin > glyph_bbox.xMin)
296 -           bbox.xMin = glyph_bbox.xMin;
297 -         if (bbox.yMin > glyph_bbox.yMin)
298 -           bbox.yMin = glyph_bbox.yMin;
299 -         if (bbox.xMax < glyph_bbox.xMax)
300 -           bbox.xMax = glyph_bbox.xMax;
301 -         if (bbox.yMax < glyph_bbox.yMax)
302 -           bbox.yMax = glyph_bbox.yMax;
303 +         if (ch == ' ')   /* special case for trailing space */
304 +           glyph_bbox.xMax += slot->metrics.horiAdvance;
305 +         if (!i)
306 +           {                   /* if first character, init BB corner values */
307 +             bbox.xMin = glyph_bbox.xMin;
308 +             bbox.yMin = glyph_bbox.yMin;
309 +             bbox.xMax = glyph_bbox.xMax;
310 +             bbox.yMax = glyph_bbox.yMax;
311 +           }
312 +         else
313 +           {
314 +             if (bbox.xMin > glyph_bbox.xMin)
315 +               bbox.xMin = glyph_bbox.xMin;
316 +             if (bbox.yMin > glyph_bbox.yMin)
317 +               bbox.yMin = glyph_bbox.yMin;
318 +             if (bbox.xMax < glyph_bbox.xMax)
319 +               bbox.xMax = glyph_bbox.xMax;
320 +             if (bbox.yMax < glyph_bbox.yMax)
321 +               bbox.yMax = glyph_bbox.yMax;
322 +           }
323           i++;
324         }
325  
326 -      /* transform glyph image */
327 -      FT_Glyph_Transform (image, &matrix, 0);
328 -
329        if (render)
330         {
331           if (image->format != ft_glyph_format_bitmap)
332             {
333               err = FT_Glyph_To_Bitmap (&image, ft_render_mode_normal, 0, 1);
334               if (err)
335 -               return "Problem rendering glyph";
336 +               {
337 +                 gdCacheDelete( tc_cache );
338 +                 return "Problem rendering glyph";
339 +               }
340             }
341  
342           /* now, draw to our target surface */
343           bm = (FT_BitmapGlyph) image;
344 -         gdft_draw_bitmap (im, fg, bm->bitmap,
345 +         gdft_draw_bitmap (tc_cache, im, fg, bm->bitmap,
346                             x + x1 + ((pen.x + 31) >> 6) + bm->left,
347                             y - y1 + ((pen.y + 31) >> 6) - bm->top);
348         }
349 @@ -922,15 +982,8 @@
350  
351    if (tmpstr)
352      gdFree (tmpstr);
353 +  gdCacheDelete (tc_cache);
354    return (char *) NULL;
355  }
356  
357 -int
358 -gdroundupdown (FT_F26Dot6 v1, int updown)
359 -{
360 -  return (!updown)
361 -    ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6)
362 -    : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6);
363 -}
364 -
365  #endif /* HAVE_LIBFREETYPE */
This page took 0.095175 seconds and 4 git commands to generate.