]> git.pld-linux.org Git - packages/php4.git/blame - php4-gd.patch
- release 9 (imap rebuild)
[packages/php4.git] / php4-gd.patch
CommitLineData
23005b3f
AM
1diff -urN php-4.4.8.org/ext/gd/config.m4 php-4.4.8/ext/gd/config.m4
2--- php-4.4.8.org/ext/gd/config.m4 2007-03-10 14:06:37.000000000 +0100
84aee732 3+++ php-4.4.8/ext/gd/config.m4 2008-01-22 22:38:05.833815388 +0100
23005b3f 4@@ -259,12 +259,13 @@
fa2ea656
AM
5 PHP_CHECK_LIBRARY(gd, gdCacheCreate, [AC_DEFINE(HAVE_GD_CACHE_CREATE, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ])
6 PHP_CHECK_LIBRARY(gd, gdFontCacheShutdown, [AC_DEFINE(HAVE_GD_FONTCACHESHUTDOWN,1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ])
7 PHP_CHECK_LIBRARY(gd, gdFreeFontCache, [AC_DEFINE(HAVE_GD_FREEFONTCACHE, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ])
8+ PHP_CHECK_LIBRARY(gd, gdFontCacheMutexSetup, [AC_DEFINE(HAVE_GD_FONTMUTEX, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ])
9 PHP_CHECK_LIBRARY(gd, gdNewDynamicCtxEx, [AC_DEFINE(HAVE_GD_DYNAMIC_CTX_EX, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ])
10 ])
11
23005b3f
AM
12 dnl
13 dnl Main GD configure
14-dnl
15+dnl
16
17 if test "$PHP_GD" = "yes"; then
18 GD_MODULE_TYPE=builtin
84aee732 19@@ -310,6 +311,7 @@
fa2ea656
AM
20 AC_DEFINE(HAVE_GD_GIF_CREATE, 1, [ ])
21 AC_DEFINE(HAVE_GD_IMAGEELLIPSE, 1, [ ])
22 AC_DEFINE(HAVE_GD_FONTCACHESHUTDOWN,1, [ ])
23+ AC_DEFINE(HAVE_GD_FONTMUTEX, 1, [ ])
24 AC_DEFINE(HAVE_GD_DYNAMIC_CTX_EX, 1, [ ])
25 AC_DEFINE(HAVE_GD_GIF_CTX, 1, [ ])
26
23005b3f
AM
27diff -urN php-4.4.8.org/ext/gd/CREDITS php-4.4.8/ext/gd/CREDITS
28--- php-4.4.8.org/ext/gd/CREDITS 2003-03-01 02:16:00.000000000 +0100
84aee732 29+++ php-4.4.8/ext/gd/CREDITS 2008-01-22 22:38:05.837148890 +0100
23005b3f
AM
30@@ -1,2 +1,2 @@
31 GD imaging
32-Rasmus Lerdorf, Stig Bakken, Jim Winstead, Jouni Ahto, Ilia Alshanetsky, Pierre-Alain Joye
33+Rasmus Lerdorf, Stig Bakken, Jim Winstead, Jouni Ahto, Ilia Alshanetsky, Pierre-Alain Joye, Marcus Boerger
34diff -urN php-4.4.8.org/ext/gd/gd.c php-4.4.8/ext/gd/gd.c
35--- php-4.4.8.org/ext/gd/gd.c 2007-12-31 08:22:47.000000000 +0100
84aee732 36+++ php-4.4.8/ext/gd/gd.c 2008-01-22 22:38:05.837148890 +0100
23005b3f
AM
37@@ -1,8 +1,8 @@
38 /*
39 +----------------------------------------------------------------------+
40- | PHP Version 4 |
41+ | PHP Version 5 |
42 +----------------------------------------------------------------------+
43- | Copyright (c) 1997-2008 The PHP Group |
44+ | Copyright (c) 1997-2007 The PHP Group |
45 +----------------------------------------------------------------------+
46 | This source file is subject to version 3.01 of the PHP license, |
47 | that is bundled with this package in the file LICENSE, and is |
48@@ -13,14 +13,14 @@
49 | license@php.net so we can mail you a copy immediately. |
50 +----------------------------------------------------------------------+
51 | Authors: Rasmus Lerdorf <rasmus@php.net> |
52- | Stig Bakken <ssb@fast.no> |
53+ | Stig Bakken <ssb@php.net> |
54 | Jim Winstead <jimw@php.net> |
55 +----------------------------------------------------------------------+
56 */
57
58-/* $Id$ */
59+/* $Id$ */
60
61-/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
62+/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
63 Cold Spring Harbor Labs. */
64
65 /* Note that there is no code from the gd package in this file */
66@@ -29,7 +29,13 @@
67 #include "config.h"
68 #endif
69
70+#ifdef HAVE_GD_PNG
71+/* needs to be first */
72+#include <png.h>
73+#endif
74+
75 #include "php.h"
76+#include "php_ini.h"
77 #include "ext/standard/head.h"
78 #include <math.h>
79 #include "SAPI.h"
80@@ -46,6 +52,9 @@
81 #ifdef PHP_WIN32
82 # include <io.h>
83 # include <fcntl.h>
84+#include <windows.h>
85+#include <Winuser.h>
86+#include <Wingdi.h>
87 #endif
88
89 #if HAVE_LIBGD
fd438bd3
AM
90@@ -64,10 +73,20 @@
91 #include <gdfontmb.h> /* 3 Medium bold font */
92 #include <gdfontl.h> /* 4 Large font */
93 #include <gdfontg.h> /* 5 Giant font */
94+#if HAVE_GD_BUNDLED
95 #ifdef HAVE_GD_WBMP
23005b3f
AM
96 #include "libgd/wbmp.h"
97 #endif
fd438bd3 98+#endif
23005b3f
AM
99 #ifdef ENABLE_GD_TTF
100+# ifdef HAVE_LIBFREETYPE
101+# include <ft2build.h>
102+# include FT_FREETYPE_H
103+# else
104+# ifdef HAVE_LIBTTF
105+# include <freetype.h>
106+# endif
107+# endif
108 # include "gdttf.h"
109 #endif
110
fd438bd3 111@@ -112,6 +131,40 @@
23005b3f
AM
112 #define gdNewDynamicCtxEx(len, data, val) gdNewDynamicCtx(len, data)
113 #endif
114
115+/* Section Filters Declarations */
116+/* IMPORTANT NOTE FOR NEW FILTER
117+ * Do not forget to update:
118+ * IMAGE_FILTER_MAX: define the last filter index
119+ * IMAGE_FILTER_MAX_ARGS: define the biggest amout of arguments
120+ * image_filter array in PHP_FUNCTION(imagefilter)
121+ * */
122+#if HAVE_GD_BUNDLED
123+#define IMAGE_FILTER_NEGATE 0
124+#define IMAGE_FILTER_GRAYSCALE 1
125+#define IMAGE_FILTER_BRIGHTNESS 2
126+#define IMAGE_FILTER_CONTRAST 3
127+#define IMAGE_FILTER_COLORIZE 4
128+#define IMAGE_FILTER_EDGEDETECT 5
129+#define IMAGE_FILTER_EMBOSS 6
130+#define IMAGE_FILTER_GAUSSIAN_BLUR 7
131+#define IMAGE_FILTER_SELECTIVE_BLUR 8
132+#define IMAGE_FILTER_MEAN_REMOVAL 9
133+#define IMAGE_FILTER_SMOOTH 10
134+#define IMAGE_FILTER_MAX 10
135+#define IMAGE_FILTER_MAX_ARGS 5
136+static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS);
137+static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS);
138+static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS);
139+static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS);
140+static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS);
141+static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS);
142+static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS);
143+static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS);
144+static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS);
145+static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS);
146+static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS);
147+#endif
148+/* End Section filters declarations */
149 static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC);
150 static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)());
151 static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)());
fd438bd3 152@@ -121,7 +174,7 @@
23005b3f
AM
153
154 /* {{{ gd_functions[]
155 */
156-function_entry gd_functions[] = {
157+zend_function_entry gd_functions[] = {
158 PHP_FE(gd_info, NULL)
159 PHP_FE(imagearc, NULL)
160 PHP_FE(imageellipse, NULL)
fd438bd3 161@@ -167,6 +220,11 @@
23005b3f
AM
162 PHP_FE(imagecopyresampled, NULL)
163 #endif
164
165+#ifdef PHP_WIN32
166+ PHP_FE(imagegrabwindow, NULL)
167+ PHP_FE(imagegrabscreen, NULL)
168+#endif
169+
170 #ifdef HAVE_GD_BUNDLED
171 PHP_FE(imagerotate, NULL)
172 PHP_FE(imageantialias, NULL)
fd438bd3 173@@ -277,6 +335,12 @@
23005b3f
AM
174 #if HAVE_GD_BUNDLED
175 PHP_FE(imagelayereffect, NULL)
176 PHP_FE(imagecolormatch, NULL)
177+ PHP_FE(imagexbm, NULL)
178+#endif
179+/* gd filters */
180+#ifdef HAVE_GD_BUNDLED
181+ PHP_FE(imagefilter, NULL)
182+ PHP_FE(imageconvolution, NULL)
183 #endif
184
185 {NULL, NULL, NULL}
fd438bd3 186@@ -288,9 +352,13 @@
23005b3f
AM
187 "gd",
188 gd_functions,
189 PHP_MINIT(gd),
190+#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
191 PHP_MSHUTDOWN(gd),
192+#else
fd438bd3
AM
193+ NULL,
194+#endif
23005b3f
AM
195 NULL,
196-#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
23005b3f
AM
197+#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
198 PHP_RSHUTDOWN(gd),
199 #else
200 NULL,
fd438bd3 201@@ -304,6 +372,12 @@
23005b3f
AM
202 ZEND_GET_MODULE(gd)
203 #endif
204
205+/* {{{ PHP_INI_BEGIN */
206+PHP_INI_BEGIN()
207+ PHP_INI_ENTRY("gd.jpeg_ignore_warning", "0", PHP_INI_ALL, NULL)
208+PHP_INI_END()
209+/* }}} */
210+
211 /* {{{ php_free_gd_image
212 */
213 static void php_free_gd_image(zend_rsrc_list_entry *rsrc TSRMLS_DC)
fd438bd3 214@@ -326,15 +400,21 @@
23005b3f
AM
215 }
216 /* }}} */
217
218+
219 /* {{{ PHP_MSHUTDOWN_FUNCTION
220 */
221+#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
222 PHP_MSHUTDOWN_FUNCTION(gd)
223 {
fa2ea656
AM
224 #if HAVE_LIBT1
225 T1_CloseLib();
226 #endif
23005b3f
AM
227+#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
228+ gdFontCacheMutexShutdown();
fa2ea656
AM
229+#endif
230 return SUCCESS;
231 }
23005b3f 232+#endif
fa2ea656 233 /* }}} */
23005b3f
AM
234
235
fd438bd3 236@@ -344,6 +424,10 @@
fa2ea656
AM
237 {
238 le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
239 le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
23005b3f
AM
240+
241+#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
242+ gdFontCacheMutexSetup();
fa2ea656
AM
243+#endif
244 #if HAVE_LIBT1
245 T1_SetBitmapPad(8);
246 T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
fd438bd3 247@@ -352,6 +436,8 @@
23005b3f
AM
248 le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number);
249 #endif
fa2ea656 250
23005b3f
AM
251+ REGISTER_INI_ENTRIES();
252+
253 REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT);
254 REGISTER_LONG_CONSTANT("IMG_JPG", 2, CONST_CS | CONST_PERSISTENT);
255 REGISTER_LONG_CONSTANT("IMG_JPEG", 2, CONST_CS | CONST_PERSISTENT);
fd438bd3 256@@ -387,16 +473,58 @@
23005b3f
AM
257 REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT);
258 REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT);
259 REGISTER_LONG_CONSTANT("GD_BUNDLED", 1, CONST_CS | CONST_PERSISTENT);
260+
261+ /* Section Filters */
262+ REGISTER_LONG_CONSTANT("IMG_FILTER_NEGATE", IMAGE_FILTER_NEGATE, CONST_CS | CONST_PERSISTENT);
263+ REGISTER_LONG_CONSTANT("IMG_FILTER_GRAYSCALE", IMAGE_FILTER_GRAYSCALE, CONST_CS | CONST_PERSISTENT);
264+ REGISTER_LONG_CONSTANT("IMG_FILTER_BRIGHTNESS", IMAGE_FILTER_BRIGHTNESS, CONST_CS | CONST_PERSISTENT);
265+ REGISTER_LONG_CONSTANT("IMG_FILTER_CONTRAST", IMAGE_FILTER_CONTRAST, CONST_CS | CONST_PERSISTENT);
266+ REGISTER_LONG_CONSTANT("IMG_FILTER_COLORIZE", IMAGE_FILTER_COLORIZE, CONST_CS | CONST_PERSISTENT);
267+ REGISTER_LONG_CONSTANT("IMG_FILTER_EDGEDETECT", IMAGE_FILTER_EDGEDETECT, CONST_CS | CONST_PERSISTENT);
268+ REGISTER_LONG_CONSTANT("IMG_FILTER_GAUSSIAN_BLUR", IMAGE_FILTER_GAUSSIAN_BLUR, CONST_CS | CONST_PERSISTENT);
269+ REGISTER_LONG_CONSTANT("IMG_FILTER_SELECTIVE_BLUR", IMAGE_FILTER_SELECTIVE_BLUR, CONST_CS | CONST_PERSISTENT);
270+ REGISTER_LONG_CONSTANT("IMG_FILTER_EMBOSS", IMAGE_FILTER_EMBOSS, CONST_CS | CONST_PERSISTENT);
271+ REGISTER_LONG_CONSTANT("IMG_FILTER_MEAN_REMOVAL", IMAGE_FILTER_MEAN_REMOVAL, CONST_CS | CONST_PERSISTENT);
272+ REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT);
273+ /* End Section Filters */
274 #else
275 REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
276 #endif
fa2ea656 277+
23005b3f
AM
278+#ifdef GD_VERSION_STRING
279+ REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
280+#endif
fa2ea656 281+
23005b3f
AM
282+#if defined(GD_MAJOR_VERSION) && defined(GD_MINOR_VERSION) && defined(GD_RELEASE_VERSION) && defined(GD_EXTRA_VERSION)
283+ REGISTER_LONG_CONSTANT("GD_MAJOR_VERSION", GD_MAJOR_VERSION, CONST_CS | CONST_PERSISTENT);
284+ REGISTER_LONG_CONSTANT("GD_MINOR_VERSION", GD_MINOR_VERSION, CONST_CS | CONST_PERSISTENT);
285+ REGISTER_LONG_CONSTANT("GD_RELEASE_VERSION", GD_RELEASE_VERSION, CONST_CS | CONST_PERSISTENT);
286+ REGISTER_STRING_CONSTANT("GD_EXTRA_VERSION", GD_EXTRA_VERSION, CONST_CS | CONST_PERSISTENT);
287+#endif
fa2ea656 288+
fa2ea656 289+
23005b3f 290+#ifdef HAVE_GD_PNG
fa2ea656 291+
23005b3f
AM
292+/*
293+ * cannot include #include "png.h"
294+ * /usr/include/pngconf.h:310:2: error: #error png.h already includes setjmp.h with some additional fixup.
295+ * as error, use the values for now...
296+ */
297+ REGISTER_LONG_CONSTANT("PNG_NO_FILTER", 0x00, CONST_CS | CONST_PERSISTENT);
298+ REGISTER_LONG_CONSTANT("PNG_FILTER_NONE", 0x08, CONST_CS | CONST_PERSISTENT);
299+ REGISTER_LONG_CONSTANT("PNG_FILTER_SUB", 0x10, CONST_CS | CONST_PERSISTENT);
300+ REGISTER_LONG_CONSTANT("PNG_FILTER_UP", 0x20, CONST_CS | CONST_PERSISTENT);
301+ REGISTER_LONG_CONSTANT("PNG_FILTER_AVG", 0x40, CONST_CS | CONST_PERSISTENT);
302+ REGISTER_LONG_CONSTANT("PNG_FILTER_PAETH", 0x80, CONST_CS | CONST_PERSISTENT);
303+ REGISTER_LONG_CONSTANT("PNG_ALL_FILTERS", 0x08 | 0x10 | 0x20 | 0x40 | 0x80, CONST_CS | CONST_PERSISTENT);
304+#endif
305 return SUCCESS;
fa2ea656 306 }
23005b3f 307 /* }}} */
fa2ea656 308
23005b3f 309 /* {{{ PHP_RSHUTDOWN_FUNCTION
fa2ea656 310 */
23005b3f
AM
311-#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
312+#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
313 PHP_RSHUTDOWN_FUNCTION(gd)
314 {
315 #if HAVE_GD_FONTCACHESHUTDOWN
fd438bd3 316@@ -410,7 +538,7 @@
23005b3f
AM
317 /* }}} */
318
319 #if HAVE_GD_BUNDLED
320-#define PHP_GD_VERSION_STRING "bundled (2.0.28 compatible)"
321+#define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)"
322 #elif HAVE_LIBGD20
323 #define PHP_GD_VERSION_STRING "2.0 or higher"
324 #elif HAVE_GDIMAGECOLORRESOLVE
fd438bd3 325@@ -436,8 +564,24 @@
23005b3f
AM
326 php_info_print_table_row(2, "FreeType Support", "enabled");
327 #if HAVE_LIBFREETYPE
328 php_info_print_table_row(2, "FreeType Linkage", "with freetype");
329+ {
330+ char tmp[256];
331+#ifdef FREETYPE_PATCH
332+ snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
333+#elif defined(FREETYPE_MAJOR)
334+ snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR);
335+#else
336+ snprintf(tmp, sizeof(tmp), "1.x");
337+#endif
338+ php_info_print_table_row(2, "FreeType Version", tmp);
339+ }
340 #elif HAVE_LIBTTF
341 php_info_print_table_row(2, "FreeType Linkage", "with TTF library");
342+ {
343+ char tmp[256];
344+ snprintf(tmp, sizeof(tmp), "%d.%d", TT_FREETYPE_MAJOR, TT_FREETYPE_MINOR);
345+ php_info_print_table_row(2, "FreeType Version", tmp);
346+ }
347 #else
348 php_info_print_table_row(2, "FreeType Linkage", "with unknown library");
349 #endif
fd438bd3 350@@ -464,6 +608,9 @@
23005b3f
AM
351 #ifdef HAVE_GD_WBMP
352 php_info_print_table_row(2, "WBMP Support", "enabled");
353 #endif
354+#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
355+ php_info_print_table_row(2, "XPM Support", "enabled");
356+#endif
357 #ifdef HAVE_GD_XBM
358 php_info_print_table_row(2, "XBM Support", "enabled");
359 #endif
fd438bd3 360@@ -530,6 +677,11 @@
23005b3f
AM
361 #else
362 add_assoc_bool(return_value, "WBMP Support", 0);
363 #endif
364+#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
365+ add_assoc_bool(return_value, "XPM Support", 1);
366+#else
367+ add_assoc_bool(return_value, "XPM Support", 0);
368+#endif
369 #ifdef HAVE_GD_XBM
370 add_assoc_bool(return_value, "XBM Support", 1);
371 #else
fd438bd3 372@@ -548,6 +700,7 @@
23005b3f
AM
373 {
374 return le_gd;
375 }
376+/* }}} */
fa2ea656 377
23005b3f 378 #ifndef HAVE_GDIMAGECOLORRESOLVE
fa2ea656 379
fd438bd3 380@@ -763,13 +916,19 @@
23005b3f
AM
381 convert_to_long_ex(x_size);
382 convert_to_long_ex(y_size);
fa2ea656 383
23005b3f
AM
384- if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0) {
385+ if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 ||
386+ Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX
387+ ) {
388 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
389 RETURN_FALSE;
fa2ea656 390 }
23005b3f
AM
391
392 im = gdImageCreateTrueColor(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
393
394+ if (!im) {
395+ RETURN_FALSE;
396+ }
fa2ea656 397+
23005b3f 398 ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
fa2ea656 399 }
23005b3f 400 /* }}} */
fd438bd3 401@@ -836,15 +995,19 @@
23005b3f
AM
402 result = gdImageColorMatch(im1, im2);
403 switch (result) {
404 case -1:
405- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image1 must be TrueColor" );
406+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 must be TrueColor" );
407 RETURN_FALSE;
408 break;
409 case -2:
410- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image2 must be Palette" );
411+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must be Palette" );
412 RETURN_FALSE;
413 break;
414 case -3:
415- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image1 and Image2 must be the same size" );
416+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 and Image2 must be the same size" );
417+ RETURN_FALSE;
418+ break;
419+ case -4:
420+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must have at least one color" );
421 RETURN_FALSE;
422 break;
423 }
fd438bd3 424@@ -977,6 +1140,7 @@
fa2ea656 425
23005b3f 426 RETURN_TRUE;
fa2ea656 427 }
23005b3f
AM
428+/* }}} */
429 #endif
fa2ea656 430
23005b3f 431 #if HAVE_GD_BUNDLED
fd438bd3 432@@ -1008,6 +1172,7 @@
23005b3f
AM
433 zval *IM;
434 long red, green, blue, alpha;
435 gdImagePtr im;
436+ int ct = (-1);
fa2ea656 437
23005b3f
AM
438 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
439 RETURN_FALSE;
fd438bd3 440@@ -1015,7 +1180,12 @@
fa2ea656 441
23005b3f
AM
442 ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
443
444- RETURN_LONG(gdImageColorAllocateAlpha(im, red, green, blue, alpha));
445+ ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha);
446+ if (ct < 0) {
447+ RETURN_FALSE;
448+ }
fa2ea656 449+
23005b3f
AM
450+ RETURN_LONG((long)ct);
451 }
452 /* }}} */
fa2ea656 453
fd438bd3 454@@ -1125,28 +1295,173 @@
23005b3f
AM
455 /* }}} */
456 #endif
457
458+#ifdef PHP_WIN32
459+/* {{{ proto resource imagegrabwindow(int window_handle [, int client_area])
460+ Grab a window or its client area using a windows handle (HWND property in COM instance) */
461+PHP_FUNCTION(imagegrabwindow)
462+{
463+ HWND window;
464+ long client_area = 0;
465+ RECT rc = {0};
466+ RECT rc_win = {0};
467+ int Width, Height;
468+ HDC hdc;
469+ HDC memDC;
470+ HBITMAP memBM;
471+ HBITMAP hOld;
472+ HINSTANCE handle;
473+ long lwindow_handle;
474+ typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
475+ tPrintWindow pPrintWindow = 0;
476+ gdImagePtr im;
477+
478+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &lwindow_handle, &client_area) == FAILURE) {
479+ RETURN_FALSE;
480+ }
481+
482+ window = (HWND) lwindow_handle;
fa2ea656 483+
23005b3f
AM
484+ if (!IsWindow(window)) {
485+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid window handle");
486+ RETURN_FALSE;
487+ }
488+
489+ hdc = GetDC(0);
490+
491+ if (client_area) {
492+ GetClientRect(window, &rc);
493+ Width = rc.right;
494+ Height = rc.bottom;
495+ } else {
496+ GetWindowRect(window, &rc);
497+ Width = rc.right - rc.left;
498+ Height = rc.bottom - rc.top;
499+ }
500+
501+ Width = (Width/4)*4;
502+
503+ memDC = CreateCompatibleDC(hdc);
504+ memBM = CreateCompatibleBitmap(hdc, Width, Height);
505+ hOld = (HBITMAP) SelectObject (memDC, memBM);
506+
507+
508+ handle = LoadLibrary("User32.dll");
509+ if ( handle == 0 ) {
510+ goto clean;
511+ }
512+ pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow");
513+
514+ if ( pPrintWindow ) {
515+ pPrintWindow(window, memDC, (UINT) client_area);
516+ } else {
517+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows API too old");
518+ RETURN_FALSE;
519+ goto clean;
520+ }
521+
522+ FreeLibrary(handle);
523+
524+ im = gdImageCreateTrueColor(Width, Height);
525+ if (im) {
526+ int x,y;
527+ for (y=0; y <= Height; y++) {
528+ for (x=0; x <= Width; x++) {
529+ int c = GetPixel(memDC, x,y);
530+ gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
fa2ea656
AM
531+ }
532+ }
23005b3f
AM
533+ }
534+
535+clean:
536+ SelectObject(memDC,hOld);
537+ DeleteObject(memBM);
538+ DeleteDC(memDC);
539+ ReleaseDC( 0, hdc );
540+
541+ if (!im) {
542+ RETURN_FALSE;
543+ } else {
544+ ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
545+ }
546+}
547+/* }}} */
548+
549+/* {{{ proto resource imagegrabscreen()
550+ Grab a screenshot */
551+PHP_FUNCTION(imagegrabscreen)
552+{
553+ HWND window = GetDesktopWindow();
554+ RECT rc = {0};
555+ int Width, Height;
556+ HDC hdc;
557+ HDC memDC;
558+ HBITMAP memBM;
559+ HBITMAP hOld;
560+ HINSTANCE handle;
561+ long lwindow_handle;
562+ typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
563+ tPrintWindow pPrintWindow = 0;
564+ gdImagePtr im;
565+ hdc = GetDC(0);
566+
567+ if (!hdc) {
568+ RETURN_FALSE;
569+ }
570+
571+ GetWindowRect(window, &rc);
572+ Width = rc.right - rc.left;
573+ Height = rc.bottom - rc.top;
fa2ea656 574+
23005b3f
AM
575+ Width = (Width/4)*4;
576+
577+ memDC = CreateCompatibleDC(hdc);
578+ memBM = CreateCompatibleBitmap(hdc, Width, Height);
579+ hOld = (HBITMAP) SelectObject (memDC, memBM);
580+ BitBlt( memDC, 0, 0, Width, Height , hdc, rc.left, rc.top , SRCCOPY );
581+
582+ im = gdImageCreateTrueColor(Width, Height);
583+ if (im) {
584+ int x,y;
585+ for (y=0; y <= Height; y++) {
586+ for (x=0; x <= Width; x++) {
587+ int c = GetPixel(memDC, x,y);
588+ gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
fa2ea656
AM
589+ }
590+ }
fa2ea656
AM
591+ }
592+
23005b3f
AM
593+ SelectObject(memDC,hOld);
594+ DeleteObject(memBM);
595+ DeleteDC(memDC);
596+ ReleaseDC( 0, hdc );
fa2ea656 597+
23005b3f
AM
598+ if (!im) {
599+ RETURN_FALSE;
600+ } else {
601+ ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
602+ }
fa2ea656 603+}
23005b3f
AM
604+/* }}} */
605+#endif /* PHP_WIN32 */
606+
607 #ifdef HAVE_GD_BUNDLED
608-/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor)
609+/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor [, int ignoretransparent])
610 Rotate an image using a custom angle */
611 PHP_FUNCTION(imagerotate)
612 {
613- zval **SIM, **ANGLE, **BGDCOLOR;
614+ zval *SIM;
615 gdImagePtr im_dst, im_src;
616 double degrees;
617 long color;
618+ long ignoretransparent = 0;
fa2ea656 619
23005b3f
AM
620- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &SIM, &ANGLE, &BGDCOLOR) == FAILURE) {
621- ZEND_WRONG_PARAM_COUNT();
622+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdl|l", &SIM, &degrees, &color, &ignoretransparent) == FAILURE) {
623+ RETURN_FALSE;
fa2ea656
AM
624 }
625
23005b3f
AM
626- ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
627-
628- convert_to_long_ex(BGDCOLOR);
629- color = Z_LVAL_PP(BGDCOLOR);
630+ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
fa2ea656 631
23005b3f
AM
632- convert_to_double_ex(ANGLE);
633- degrees = Z_DVAL_PP(ANGLE);
634- im_dst = gdImageRotate(im_src, degrees, color);
635+ im_dst = gdImageRotate(im_src, degrees, color, ignoretransparent);
636
637 if (im_dst != NULL) {
638 ZEND_REGISTER_RESOURCE(return_value, im_dst, le_gd);
fd438bd3 639@@ -1215,13 +1530,19 @@
23005b3f
AM
640 convert_to_long_ex(x_size);
641 convert_to_long_ex(y_size);
642
643- if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0) {
644+ if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 ||
645+ Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX
646+ ) {
647 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
648 RETURN_FALSE;
fa2ea656 649 }
fa2ea656 650
23005b3f 651 im = gdImageCreate(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
fa2ea656 652
23005b3f
AM
653+ if (!im) {
654+ RETURN_FALSE;
fa2ea656
AM
655+ }
656+
23005b3f
AM
657 ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
658 }
659 /* }}} */
fd438bd3 660@@ -1323,6 +1644,11 @@
23005b3f
AM
661 im = (*ioctx_func_p)(io_ctx);
662 if (!im) {
663 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed data is not in '%s' format", tn);
664+#if HAVE_LIBGD204
665+ io_ctx->gd_free(io_ctx);
666+#else
667+ io_ctx->free(io_ctx);
668+#endif
669 return NULL;
fa2ea656
AM
670 }
671
fd438bd3 672@@ -1350,6 +1676,11 @@
fa2ea656 673 }
fa2ea656 674
23005b3f
AM
675 convert_to_string_ex(data);
676+ if (Z_STRLEN_PP(data) < 8) {
677+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string or invalid image");
678+ RETURN_FALSE;
679+ }
fa2ea656 680+
23005b3f 681 memcpy(sig, Z_STRVAL_PP(data), 8);
fa2ea656 682
23005b3f 683 imtype = _php_image_type(sig);
fd438bd3 684@@ -1401,7 +1732,7 @@
23005b3f 685 break;
fa2ea656 686
23005b3f
AM
687 default:
688- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format.");
689+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format");
690 RETURN_FALSE;
fa2ea656
AM
691 }
692
fd438bd3 693@@ -1425,6 +1756,9 @@
23005b3f
AM
694 php_stream *stream;
695 FILE * fp = NULL;
696 int argc=ZEND_NUM_ARGS();
697+#ifdef HAVE_GD_JPG
698+ long ignore_warning;
699+#endif
fa2ea656 700
23005b3f
AM
701 if ((image_type == PHP_GDIMG_TYPE_GD2PART && argc != 5) ||
702 (image_type != PHP_GDIMG_TYPE_GD2PART && argc != 1) ||
fd438bd3 703@@ -1436,6 +1770,10 @@
fa2ea656 704
23005b3f
AM
705 if (argc == 5 && image_type == PHP_GDIMG_TYPE_GD2PART) {
706 multi_convert_to_long_ex(4, srcx, srcy, width, height);
707+ if (Z_LVAL_PP(width) < 1 || Z_LVAL_PP(height) < 1) {
708+ php_error_docref(NULL TSRMLS_CC, E_WARNING,"Zero width or height not allowed");
709+ RETURN_FALSE;
710+ }
fa2ea656
AM
711 }
712
23005b3f 713 fn = Z_STRVAL_PP(file);
fd438bd3 714@@ -1471,6 +1809,7 @@
23005b3f
AM
715
716 io_ctx = gdNewDynamicCtxEx(buff_size, buff, 0);
717 if (!io_ctx) {
718+ pefree(buff, 1);
719 php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context");
720 goto out_err;
fa2ea656 721 }
fd438bd3 722@@ -1485,7 +1824,7 @@
23005b3f
AM
723 #else
724 io_ctx->free(io_ctx);
725 #endif
fa2ea656 726-
23005b3f
AM
727+ pefree(buff, 1);
728 #endif
fa2ea656 729 }
23005b3f 730 else {
fd438bd3 731@@ -1505,6 +1844,18 @@
23005b3f
AM
732 im = gdImageCreateFromXpm(fn);
733 break;
734 #endif
fa2ea656 735+
23005b3f
AM
736+#ifdef HAVE_GD_JPG
737+ case PHP_GDIMG_TYPE_JPG:
738+ ignore_warning = INI_INT("gd.jpeg_ignore_warning");
739+#ifdef HAVE_GD_BUNDLED
740+ im = gdImageCreateFromJpeg(fp, ignore_warning);
741+#else
742+ im = gdImageCreateFromJpeg(fp);
743+#endif
744+ break;
745+#endif
fa2ea656 746+
23005b3f
AM
747 default:
748 im = (*func_p)(fp);
749 break;
fd438bd3 750@@ -1685,6 +2036,14 @@
23005b3f
AM
751 (*func_p)(im, fp);
752 break;
753 #endif
754+#ifdef HAVE_GD_GD2
755+ case PHP_GDIMG_TYPE_GD2:
756+ if (q == -1) {
757+ q = 128;
fa2ea656 758+ }
23005b3f
AM
759+ (*func_p)(im, fp, q, t);
760+ break;
761+#endif
762 default:
763 if (q == -1) {
764 q = 128;
fd438bd3 765@@ -1737,6 +2096,14 @@
23005b3f
AM
766 (*func_p)(im, tmp);
767 break;
768 #endif
769+#ifdef HAVE_GD_GD2
770+ case PHP_GDIMG_TYPE_GD2:
771+ if (q == -1) {
772+ q = 128;
fa2ea656 773+ }
23005b3f
AM
774+ (*func_p)(im, tmp, q, t);
775+ break;
776+#endif
777 default:
778 (*func_p)(im, tmp);
779 break;
fd438bd3 780@@ -1762,6 +2129,16 @@
fa2ea656 781 }
23005b3f 782 /* }}} */
fa2ea656 783
23005b3f
AM
784+/* {{{ proto int imagexbm(int im, string filename [, int foreground])
785+ Output XBM image to browser or file */
786+#if HAVE_GD_BUNDLED
787+PHP_FUNCTION(imagexbm)
788+{
789+ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx);
790+}
791+#endif
792+/* }}} */
fa2ea656 793+
23005b3f
AM
794 #ifdef HAVE_GD_GIF_CREATE
795 /* {{{ proto bool imagegif(resource im [, string filename])
796 Output GIF image to browser or file */
fd438bd3 797@@ -1782,7 +2159,7 @@
23005b3f
AM
798 PHP_FUNCTION(imagepng)
799 {
800 #ifdef USE_GD_IOCTX
801- _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtx);
802+ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtxEx);
803 #else
804 _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng);
805 #endif
fd438bd3 806@@ -1862,6 +2239,7 @@
23005b3f
AM
807 {
808 zval **IM, **red, **green, **blue;
809 gdImagePtr im;
810+ int ct = (-1);
fa2ea656 811
23005b3f
AM
812 if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
813 ZEND_WRONG_PARAM_COUNT();
fd438bd3 814@@ -1872,8 +2250,11 @@
23005b3f
AM
815 convert_to_long_ex(red);
816 convert_to_long_ex(green);
817 convert_to_long_ex(blue);
818-
819- RETURN_LONG(gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
820+ ct = gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue));
821+ if (ct < 0) {
822+ RETURN_FALSE;
823+ }
824+ RETURN_LONG(ct);
fa2ea656 825 }
23005b3f 826 /* }}} */
fa2ea656 827
fd438bd3 828@@ -2508,7 +2889,7 @@
23005b3f 829 static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
fa2ea656 830 {
23005b3f
AM
831 zval **IM, **POINTS, **NPOINTS, **COL;
832- pval **var = NULL;
833+ zval **var = NULL;
834 gdImagePtr im;
835 gdPointPtr points;
836 int npoints, col, nelem, i;
fd438bd3 837@@ -2716,7 +3097,7 @@
23005b3f 838 ch = (int)((unsigned char)*(Z_STRVAL_PP(C)));
fa2ea656 839 } else {
23005b3f
AM
840 str = (unsigned char *) estrndup(Z_STRVAL_PP(C), Z_STRLEN_PP(C));
841- l = strlen(str);
842+ l = strlen((char *)str);
fa2ea656 843 }
fa2ea656 844
23005b3f 845 y = Z_LVAL_PP(Y);
fd438bd3 846@@ -3083,7 +3464,7 @@
23005b3f
AM
847 {
848 char tmp_font_path[MAXPATHLEN];
fa2ea656 849
23005b3f
AM
850- if (VCWD_REALPATH(fontname, tmp_font_path)) {
851+ if (VCWD_REALPATH((char *)fontname, tmp_font_path)) {
852 fontname = (unsigned char *) fontname;
853 } else {
854 fontname = NULL;
fd438bd3 855@@ -3093,16 +3474,18 @@
23005b3f
AM
856 fontname = (unsigned char *) fontname;
857 #endif
fa2ea656 858
23005b3f
AM
859+ PHP_GD_CHECK_OPEN_BASEDIR((char *)fontname, "Invalid font filename");
860+
861 #ifdef USE_GD_IMGSTRTTF
862 # if HAVE_GD_STRINGFTEX
863 if (extended) {
864- error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
865+ error = gdImageStringFTEx(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str, &strex);
866 }
867 else
868 # endif
869
870 # if HAVE_GD_STRINGFT
871- error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);
872+ error = gdImageStringFT(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str);
873 # elif HAVE_GD_STRINGTTF
874 error = gdImageStringTTF(im, brect, col, fontname, ptsize, angle, x, y, str);
875 # endif
fd438bd3 876@@ -3155,6 +3538,9 @@
23005b3f
AM
877 {
878 zval **file;
879 int f_ind, *font;
880+#ifdef PHP_WIN32
881+ struct stat st;
882+#endif
fa2ea656 883
23005b3f
AM
884 if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
885 ZEND_WRONG_PARAM_COUNT();
fd438bd3 886@@ -3162,24 +3548,18 @@
fa2ea656 887
23005b3f 888 convert_to_string_ex(file);
fa2ea656 889
23005b3f
AM
890+#ifdef PHP_WIN32
891+ if (VCWD_STAT(Z_STRVAL_PP(file), &st) < 0) {
892+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Font file not found (%s)", Z_STRVAL_PP(file));
893+ RETURN_FALSE;
fa2ea656 894+ }
23005b3f 895+#endif
fa2ea656 896+
23005b3f
AM
897 f_ind = T1_AddFont(Z_STRVAL_PP(file));
898
899 if (f_ind < 0) {
900- switch (f_ind) {
901- case -1:
902- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't find the font file");
903- RETURN_FALSE;
904- break;
905- case -2:
906- case -3:
907- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memory allocation fault in t1lib");
908- RETURN_FALSE;
909- break;
910- default:
911- php_error_docref(NULL TSRMLS_CC, E_WARNING, "An unknown error occurred in t1lib");
912- RETURN_FALSE;
913- break;
914- }
915+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind));
916+ RETURN_FALSE;
fa2ea656
AM
917 }
918
23005b3f 919 if (T1_LoadFont(f_ind)) {
fd438bd3 920@@ -3317,6 +3697,11 @@
fa2ea656 921
23005b3f 922 T1_DeleteAllSizes(*f_ind);
fa2ea656 923
23005b3f
AM
924+ if (Z_DVAL_PP(ext) <= 0) {
925+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter %F out of range (must be > 0)", Z_DVAL_PP(ext));
926+ RETURN_FALSE;
fa2ea656
AM
927+ }
928+
23005b3f
AM
929 if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) {
930 RETURN_FALSE;
fa2ea656 931 }
fd438bd3 932@@ -3348,7 +3733,7 @@
fa2ea656 933 }
23005b3f 934 /* }}} */
fa2ea656 935
23005b3f
AM
936-/* {{{ proto array imagepstext(resource image, string text, resource font, int size, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias])
937+/* {{{ proto array imagepstext(resource image, string text, resource font, int size, int foreground, int background, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias])
938 Rasterize a string over an image */
939 PHP_FUNCTION(imagepstext)
fa2ea656 940 {
fd438bd3 941@@ -3371,11 +3756,6 @@
23005b3f
AM
942 T1_TMATRIX *transform = NULL;
943 char *str;
944 int str_len;
945- int argc = ZEND_NUM_ARGS();
946-
947- if (argc != 8 && argc != 12) {
948- ZEND_WRONG_PARAM_COUNT();
949- }
fa2ea656 950
23005b3f
AM
951 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrlllll|lldl", &img, &str, &str_len, &fnt, &size, &_fg, &_bg, &x, &y, &space, &width, &angle, &aa_steps) == FAILURE) {
952 return;
fd438bd3 953@@ -3455,7 +3835,7 @@
fa2ea656 954
23005b3f
AM
955 if (!str_path) {
956 if (T1_errno) {
957- php_error_docref(NULL TSRMLS_CC, E_WARNING, "libt1 returned error %d", T1_errno);
958+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
959 }
960 RETURN_FALSE;
961 }
fd438bd3 962@@ -3476,7 +3856,7 @@
23005b3f 963 str_img = T1_AASetString(*f_ind, str, str_len, space, T1_KERNING, size, transform);
fa2ea656 964 }
23005b3f
AM
965 if (T1_errno) {
966- php_error_docref(NULL TSRMLS_CC, E_WARNING, "libt1 returned error %d", T1_errno);
967+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
968 RETURN_FALSE;
fa2ea656
AM
969 }
970
fd438bd3 971@@ -3719,7 +4099,10 @@
23005b3f
AM
972 int int_threshold;
973 int x, y;
974 float x_ratio, y_ratio;
fa2ea656 975-
23005b3f
AM
976+#ifdef HAVE_GD_JPG
977+ long ignore_warning;
978+#endif
979+
980 if (argc != 5 || zend_get_parameters_ex(argc, &f_org, &f_dest, &height, &width, &threshold) == FAILURE) {
981 ZEND_WRONG_PARAM_COUNT();
fa2ea656 982 }
fd438bd3 983@@ -3775,7 +4158,12 @@
fa2ea656 984
23005b3f
AM
985 #ifdef HAVE_GD_JPG
986 case PHP_GDIMG_TYPE_JPG:
987+ ignore_warning = INI_INT("gd.jpeg_ignore_warning");
988+#ifdef HAVE_GD_BUNDLED
989+ im_org = gdImageCreateFromJpeg(org, ignore_warning);
990+#else
991 im_org = gdImageCreateFromJpeg(org);
992+#endif
993 if (im_org == NULL) {
994 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid JPEG file", fn_dest);
995 RETURN_FALSE;
fd438bd3 996@@ -3886,7 +4274,282 @@
23005b3f
AM
997 /* }}} */
998 #endif /* HAVE_GD_WBMP */
fa2ea656 999
23005b3f 1000+#endif /* HAVE_LIBGD */
fa2ea656 1001+
23005b3f
AM
1002+/* Section Filters */
1003 #ifdef HAVE_GD_BUNDLED
fa2ea656 1004+
23005b3f
AM
1005+#define PHP_GD_SINGLE_RES \
1006+ zval **SIM; \
1007+ gdImagePtr im_src; \
1008+ if (zend_get_parameters_ex(1, &SIM) == FAILURE) { \
1009+ RETURN_FALSE; \
1010+ } \
1011+ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); \
1012+ if (im_src == NULL) { \
1013+ RETURN_FALSE; \
1014+ }
fa2ea656 1015+
23005b3f
AM
1016+static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
1017+{
1018+ PHP_GD_SINGLE_RES
fa2ea656 1019+
23005b3f
AM
1020+ if (gdImageNegate(im_src) == 1) {
1021+ RETURN_TRUE;
1022+ }
fa2ea656 1023+
23005b3f 1024+ RETURN_FALSE;
fa2ea656
AM
1025+}
1026+
23005b3f
AM
1027+static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
1028+{
1029+ PHP_GD_SINGLE_RES
fa2ea656 1030+
23005b3f
AM
1031+ if (gdImageGrayScale(im_src) == 1) {
1032+ RETURN_TRUE;
1033+ }
fa2ea656 1034+
23005b3f
AM
1035+ RETURN_FALSE;
1036+}
fa2ea656 1037+
23005b3f 1038+static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
fa2ea656 1039+{
23005b3f
AM
1040+ zval *SIM;
1041+ gdImagePtr im_src;
1042+ long brightness, tmp;
fa2ea656 1043+
23005b3f
AM
1044+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &SIM, &tmp, &brightness) == FAILURE) {
1045+ RETURN_FALSE;
fa2ea656
AM
1046+ }
1047+
23005b3f 1048+ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
fa2ea656 1049+
23005b3f
AM
1050+ if (im_src == NULL) {
1051+ RETURN_FALSE;
1052+ }
fa2ea656 1053+
23005b3f
AM
1054+ if (gdImageBrightness(im_src, (int)brightness) == 1) {
1055+ RETURN_TRUE;
fa2ea656 1056+ }
23005b3f
AM
1057+
1058+ RETURN_FALSE;
fa2ea656
AM
1059+}
1060+
23005b3f 1061+static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
fa2ea656 1062+{
23005b3f
AM
1063+ zval *SIM;
1064+ gdImagePtr im_src;
1065+ long contrast, tmp;
fa2ea656 1066+
23005b3f
AM
1067+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &SIM, &tmp, &contrast) == FAILURE) {
1068+ RETURN_FALSE;
fa2ea656
AM
1069+ }
1070+
23005b3f 1071+ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
fa2ea656 1072+
23005b3f
AM
1073+ if (im_src == NULL) {
1074+ RETURN_FALSE;
fa2ea656 1075+ }
23005b3f
AM
1076+
1077+ if (gdImageContrast(im_src, (int)contrast) == 1) {
1078+ RETURN_TRUE;
1079+ }
1080+
1081+ RETURN_FALSE;
fa2ea656
AM
1082+}
1083+
23005b3f 1084+static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
fa2ea656 1085+{
23005b3f
AM
1086+ zval *SIM;
1087+ gdImagePtr im_src;
1088+ long r,g,b,tmp;
1089+ long a = 0;
fa2ea656 1090+
23005b3f
AM
1091+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &SIM, &tmp, &r, &g, &b, &a) == FAILURE) {
1092+ RETURN_FALSE;
fa2ea656
AM
1093+ }
1094+
23005b3f 1095+ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
fa2ea656 1096+
23005b3f
AM
1097+ if (im_src == NULL) {
1098+ RETURN_FALSE;
1099+ }
fa2ea656 1100+
23005b3f
AM
1101+ if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) {
1102+ RETURN_TRUE;
1103+ }
fa2ea656 1104+
23005b3f
AM
1105+ RETURN_FALSE;
1106+}
fa2ea656 1107+
23005b3f
AM
1108+static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS)
1109+{
1110+ PHP_GD_SINGLE_RES
fa2ea656 1111+
23005b3f
AM
1112+ if (gdImageEdgeDetectQuick(im_src) == 1) {
1113+ RETURN_TRUE;
fa2ea656 1114+ }
fa2ea656 1115+
23005b3f
AM
1116+ RETURN_FALSE;
1117+}
fa2ea656 1118+
23005b3f 1119+static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
fa2ea656 1120+{
23005b3f 1121+ PHP_GD_SINGLE_RES
fa2ea656 1122+
23005b3f
AM
1123+ if (gdImageEmboss(im_src) == 1) {
1124+ RETURN_TRUE;
fa2ea656
AM
1125+ }
1126+
23005b3f
AM
1127+ RETURN_FALSE;
1128+}
1129+
1130+static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
1131+{
1132+ PHP_GD_SINGLE_RES
fa2ea656 1133+
23005b3f
AM
1134+ if (gdImageGaussianBlur(im_src) == 1) {
1135+ RETURN_TRUE;
1136+ }
fa2ea656 1137+
23005b3f
AM
1138+ RETURN_FALSE;
1139+}
fa2ea656 1140+
23005b3f
AM
1141+static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
1142+{
1143+ PHP_GD_SINGLE_RES
fa2ea656 1144+
23005b3f
AM
1145+ if (gdImageSelectiveBlur(im_src) == 1) {
1146+ RETURN_TRUE;
1147+ }
fa2ea656 1148+
23005b3f
AM
1149+ RETURN_FALSE;
1150+}
fa2ea656 1151+
23005b3f
AM
1152+static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
1153+{
1154+ PHP_GD_SINGLE_RES
fa2ea656 1155+
23005b3f
AM
1156+ if (gdImageMeanRemoval(im_src) == 1) {
1157+ RETURN_TRUE;
fa2ea656 1158+ }
fa2ea656 1159+
23005b3f
AM
1160+ RETURN_FALSE;
1161+}
fa2ea656 1162+
23005b3f 1163+static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
fa2ea656 1164+{
23005b3f
AM
1165+ zval *SIM;
1166+ long tmp;
1167+ gdImagePtr im_src;
1168+ double weight;
fa2ea656 1169+
23005b3f
AM
1170+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
1171+ RETURN_FALSE;
fa2ea656
AM
1172+ }
1173+
23005b3f 1174+ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
fa2ea656 1175+
23005b3f
AM
1176+ if (im_src == NULL) {
1177+ RETURN_FALSE;
1178+ }
fa2ea656 1179+
23005b3f
AM
1180+ if (gdImageSmooth(im_src, (float)weight)==1) {
1181+ RETURN_TRUE;
1182+ }
fa2ea656 1183+
23005b3f
AM
1184+ RETURN_FALSE;
1185+}
fa2ea656 1186+
23005b3f
AM
1187+/* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] )
1188+ Applies Filter an image using a custom angle */
1189+PHP_FUNCTION(imagefilter)
fa2ea656 1190+{
23005b3f
AM
1191+ zval *tmp;
1192+
1193+ typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS);
1194+ long filtertype;
1195+ image_filter filters[] =
1196+ {
1197+ php_image_filter_negate ,
1198+ php_image_filter_grayscale,
1199+ php_image_filter_brightness,
1200+ php_image_filter_contrast,
1201+ php_image_filter_colorize,
1202+ php_image_filter_edgedetect,
1203+ php_image_filter_emboss,
1204+ php_image_filter_gaussian_blur,
1205+ php_image_filter_selective_blur,
1206+ php_image_filter_mean_removal,
1207+ php_image_filter_smooth
1208+ };
1209+
1210+ if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 6) {
1211+ WRONG_PARAM_COUNT;
1212+ } else if (zend_parse_parameters(2 TSRMLS_CC, "rl", &tmp, &filtertype) == FAILURE) {
1213+ return;
fa2ea656
AM
1214+ }
1215+
23005b3f
AM
1216+ if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
1217+ filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
fa2ea656 1218+ }
fa2ea656 1219+}
23005b3f 1220+/* }}} */
fa2ea656 1221+
23005b3f
AM
1222+/* {{{ proto resource imageconvolution(resource src_im, array matrix3x3, double div, double offset)
1223+ Apply a 3x3 convolution matrix, using coefficient div and offset */
1224+PHP_FUNCTION(imageconvolution)
fa2ea656 1225+{
23005b3f
AM
1226+ zval *SIM, *hash_matrix;
1227+ zval **var = NULL, **var2 = NULL;
1228+ gdImagePtr im_src = NULL;
1229+ double div, offset;
1230+ int nelem, i, j, res;
1231+ float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}};
fa2ea656 1232+
23005b3f
AM
1233+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "radd", &SIM, &hash_matrix, &div, &offset) == FAILURE) {
1234+ RETURN_FALSE;
fa2ea656
AM
1235+ }
1236+
23005b3f 1237+ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
fa2ea656 1238+
23005b3f
AM
1239+ nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
1240+ if (nelem != 3) {
1241+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
1242+ RETURN_FALSE;
fa2ea656
AM
1243+ }
1244+
23005b3f
AM
1245+ for (i=0; i<3; i++) {
1246+ if (zend_hash_index_find(Z_ARRVAL_P(hash_matrix), (i), (void **) &var) == SUCCESS && Z_TYPE_PP(var) == IS_ARRAY) {
1247+ if (Z_TYPE_PP(var) != IS_ARRAY || zend_hash_num_elements(Z_ARRVAL_PP(var)) != 3 ) {
1248+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
1249+ RETURN_FALSE;
fa2ea656
AM
1250+ }
1251+
fa2ea656 1252+ for (j=0; j<3; j++) {
23005b3f
AM
1253+ if (zend_hash_index_find(Z_ARRVAL_PP(var), (j), (void **) &var2) == SUCCESS) {
1254+ SEPARATE_ZVAL(var2);
1255+ convert_to_double(*var2);
1256+ matrix[i][j] = Z_DVAL_PP(var2);
1257+ } else {
1258+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have a 3x3 matrix");
1259+ RETURN_FALSE;
fa2ea656
AM
1260+ }
1261+ }
fa2ea656
AM
1262+ }
1263+ }
23005b3f 1264+ res = gdImageConvolution(im_src, matrix, div, offset);
fa2ea656 1265+
23005b3f
AM
1266+ if (res) {
1267+ RETURN_TRUE;
1268+ } else {
1269+ RETURN_FALSE;
1270+ }
fa2ea656 1271+}
23005b3f 1272+/* }}} */
fa2ea656 1273+
23005b3f 1274+/* End section: Filters */
fa2ea656 1275+
23005b3f
AM
1276 /* {{{ proto bool imageantialias(resource im, bool on)
1277 Should antialiased functions used or not*/
1278 PHP_FUNCTION(imageantialias)
fd438bd3 1279@@ -3908,8 +4571,6 @@
23005b3f
AM
1280 /* }}} */
1281 #endif
fa2ea656 1282
23005b3f
AM
1283-#endif /* HAVE_LIBGD */
1284-
1285 /*
1286 * Local variables:
1287 * tab-width: 4
1288diff -urN php-4.4.8.org/ext/gd/gdcache.c php-4.4.8/ext/gd/gdcache.c
1289--- php-4.4.8.org/ext/gd/gdcache.c 2005-01-09 22:05:31.000000000 +0100
84aee732 1290+++ php-4.4.8/ext/gd/gdcache.c 2008-01-22 22:38:05.863816915 +0100
23005b3f 1291@@ -1,8 +1,8 @@
fa2ea656 1292-/*
23005b3f 1293- * $Id$
fa2ea656 1294+/*
23005b3f 1295+ * $Id$
fa2ea656
AM
1296 *
1297- * Caches of pointers to user structs in which the least-recently-used
1298- * element is replaced in the event of a cache miss after the cache has
1299+ * Caches of pointers to user structs in which the least-recently-used
1300+ * element is replaced in the event of a cache miss after the cache has
1301 * reached a given size.
1302 *
23005b3f
AM
1303 * John Ellson (ellson@lucent.com) Oct 31, 1997
1304@@ -17,17 +17,17 @@
fa2ea656
AM
1305 * The head structure has a pointer to the most-recently-used
1306 * element, and elements are moved to this position in the list each
1307 * time they are used. The head also contains pointers to three
1308- * user defined functions:
23005b3f
AM
1309- * - a function to test if a cached userdata matches some keydata
1310- * - a function to provide a new userdata struct to the cache
fa2ea656 1311+ * user defined functions:
23005b3f
AM
1312+ * - a function to test if a cached userdata matches some keydata
1313+ * - a function to provide a new userdata struct to the cache
fa2ea656 1314 * if there has been a cache miss.
23005b3f 1315 * - a function to release a userdata struct when it is
fa2ea656
AM
1316 * no longer being managed by the cache
1317 *
1318 * In the event of a cache miss the cache is allowed to grow up to
1319 * a specified maximum size. After the maximum size is reached then
1320- * the least-recently-used element is discarded to make room for the
1321- * new. The most-recently-returned value is always left at the
1322+ * the least-recently-used element is discarded to make room for the
1323+ * new. The most-recently-returned value is always left at the
1324 * beginning of the list after retrieval.
1325 *
1326 * In the current implementation the cache is traversed by a linear
23005b3f
AM
1327@@ -59,9 +59,9 @@
1328 int size,
1329 gdCacheTestFn_t gdCacheTest,
1330 gdCacheFetchFn_t gdCacheFetch,
1331- gdCacheReleaseFn_t gdCacheRelease )
1332+ gdCacheReleaseFn_t gdCacheRelease )
1333 {
1334- gdCache_head_t *head;
1335+ gdCache_head_t *head;
1336
1337 head = (gdCache_head_t *)pemalloc(sizeof(gdCache_head_t), 1);
1338 head->mru = NULL;
1339diff -urN php-4.4.8.org/ext/gd/gdcache.h php-4.4.8/ext/gd/gdcache.h
1340--- php-4.4.8.org/ext/gd/gdcache.h 2003-03-05 17:04:20.000000000 +0100
84aee732 1341+++ php-4.4.8/ext/gd/gdcache.h 2008-01-22 22:38:05.863816915 +0100
fa2ea656
AM
1342@@ -1,8 +1,8 @@
1343-/*
23005b3f 1344- * $Id$
fa2ea656 1345+/*
23005b3f 1346+ * $Id$
fa2ea656
AM
1347 *
1348- * Caches of pointers to user structs in which the least-recently-used
1349- * element is replaced in the event of a cache miss after the cache has
1350+ * Caches of pointers to user structs in which the least-recently-used
1351+ * element is replaced in the event of a cache miss after the cache has
1352 * reached a given size.
1353 *
23005b3f 1354 * John Ellson (ellson@lucent.com) Oct 31, 1997
fa2ea656
AM
1355@@ -17,17 +17,17 @@
1356 * The head structure has a pointer to the most-recently-used
1357 * element, and elements are moved to this position in the list each
1358 * time they are used. The head also contains pointers to three
1359- * user defined functions:
1360- * - a function to test if a cached userdata matches some keydata
1361- * - a function to provide a new userdata struct to the cache
1362+ * user defined functions:
1363+ * - a function to test if a cached userdata matches some keydata
1364+ * - a function to provide a new userdata struct to the cache
1365 * if there has been a cache miss.
1366 * - a function to release a userdata struct when it is
1367 * no longer being managed by the cache
1368 *
1369 * In the event of a cache miss the cache is allowed to grow up to
1370 * a specified maximum size. After the maximum size is reached then
1371- * the least-recently-used element is discarded to make room for the
1372- * new. The most-recently-returned value is always left at the
1373+ * the least-recently-used element is discarded to make room for the
1374+ * new. The most-recently-returned value is always left at the
1375 * beginning of the list after retrieval.
1376 *
1377 * In the current implementation the cache is traversed by a linear
23005b3f
AM
1378diff -urN php-4.4.8.org/ext/gd/gd_ctx.c php-4.4.8/ext/gd/gd_ctx.c
1379--- php-4.4.8.org/ext/gd/gd_ctx.c 2007-12-31 08:22:47.000000000 +0100
84aee732 1380+++ php-4.4.8/ext/gd/gd_ctx.c 2008-01-22 22:38:05.863816915 +0100
23005b3f
AM
1381@@ -1,13 +1,13 @@
1382 /*
1383 +----------------------------------------------------------------------+
1384- | PHP Version 4 |
1385+ | PHP Version 5 |
1386 +----------------------------------------------------------------------+
1387- | Copyright (c) 1997-2008 The PHP Group |
1388+ | Copyright (c) 1997-2007 The PHP Group |
1389 +----------------------------------------------------------------------+
1390 | This source file is subject to version 3.01 of the PHP license, |
1391 | that is bundled with this package in the file LICENSE, and is |
1392 | available through the world-wide-web at the following url: |
1393- | http://www.php.net/license/3_0.txt. |
1394+ | http://www.php.net/license/3_01.txt |
1395 | If you did not receive a copy of the PHP license and are unable to |
1396 | obtain it through the world-wide-web, please send a note to |
1397 | license@php.net so we can mail you a copy immediately. |
1398@@ -15,11 +15,13 @@
1399 | Authors: Stanislav Malyshev <stas@php.net> |
1400 +----------------------------------------------------------------------+
1401 */
1402-#include "php_gd.h"
fa2ea656 1403
23005b3f
AM
1404+/* $Id$ */
1405+
1406+#include "php_gd.h"
fa2ea656 1407
23005b3f
AM
1408 #define CTX_PUTC(c,ctx) ctx->putC(ctx, c)
1409-
1410+
1411 static void _php_image_output_putc(struct gdIOCtx *ctx, int c)
fa2ea656 1412 {
23005b3f
AM
1413 /* without the following downcast, the write will fail
1414@@ -43,20 +45,29 @@
1415 efree(ctx);
1416 }
1417 }
1418-
1419-static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
1420+
1421+/* {{{ _php_image_output_ctx */
1422+static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
fa2ea656 1423 {
23005b3f
AM
1424- zval **imgind, **file, **quality;
1425+ zval **imgind, **file, **quality, **basefilter;
1426 gdImagePtr im;
1427 char *fn = NULL;
1428 FILE *fp = NULL;
1429 int argc = ZEND_NUM_ARGS();
1430 int q = -1, i;
1431+ int f = -1;
1432 gdIOCtx *ctx;
1433
1434- /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
1435-
1436- if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE)
1437+ /* The third (quality) parameter for Wbmp stands for the threshold when called from image2wbmp().
1438+ * The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called
1439+ * from imagey<type>().
1440+ */
1441+
1442+ if (argc < 2 && image_type == PHP_GDIMG_TYPE_XBM) {
1443+ WRONG_PARAM_COUNT;
1444+ }
1445+
1446+ if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc, &imgind, &file, &quality, &basefilter) == FAILURE)
1447 {
1448 WRONG_PARAM_COUNT;
1449 }
1450@@ -64,20 +75,27 @@
1451 ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", phpi_get_le_gd());
1452
1453 if (argc > 1) {
1454- convert_to_string_ex(file);
1455+ if (argc >= 2 && Z_TYPE_PP(file) != IS_NULL) {
1456+ convert_to_string_ex(file);
1457+ }
1458 fn = Z_STRVAL_PP(file);
1459- if (argc == 3) {
1460+ if (argc >= 3) {
1461 convert_to_long_ex(quality);
1462- q = Z_LVAL_PP(quality);
1463+ q = Z_LVAL_PP(quality);/* or colorindex for foreground of BW images (defaults to black) */
1464+ if (argc == 4) {
1465+ convert_to_long_ex(basefilter);
1466+ f = Z_LVAL_PP(basefilter);
1467+ }
1468 }
1469 }
1470
1471- if ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))) {
1472+ if (argc > 1 && (Z_TYPE_PP(file) != IS_NULL && ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))))) {
1473+
1474 PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
1475
1476 fp = VCWD_FOPEN(fn, "wb");
1477 if (!fp) {
1478- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn);
1479+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing: %s", fn, strerror(errno));
1480 RETURN_FALSE;
1481 }
1482
1483@@ -90,7 +108,7 @@
1484 ctx->gd_free = _php_image_output_ctxfree;
fa2ea656 1485 #else
23005b3f
AM
1486 ctx->free = _php_image_output_ctxfree;
1487-#endif
fa2ea656 1488+#endif
fa2ea656 1489
23005b3f
AM
1490 #if APACHE && defined(CHARSET_EBCDIC)
1491 /* XXX this is unlikely to work any more thies@thieso.net */
1492@@ -107,27 +125,48 @@
1493 case PHP_GDIMG_TYPE_JPG:
1494 (*func_p)(im, ctx, q);
1495 break;
1496+ case PHP_GDIMG_TYPE_PNG:
1497+ (*func_p)(im, ctx, q, f);
1498+ break;
1499+ case PHP_GDIMG_TYPE_XBM:
1500 case PHP_GDIMG_TYPE_WBM:
1501- for(i=0; i < gdImageColorsTotal(im); i++) {
1502- if(gdImageRed(im, i) == 0) break;
1503- }
1504- (*func_p)(im, i, ctx);
1505+ if (argc < 3) {
1506+ for(i=0; i < gdImageColorsTotal(im); i++) {
1507+ if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
1508+ }
1509+ q = i;
1510+ }
1511+ if (image_type == PHP_GDIMG_TYPE_XBM) {
1512+ (*func_p)(im, fn, q, ctx);
1513+ } else {
1514+ (*func_p)(im, q, ctx);
1515+ }
1516 break;
1517 default:
1518 (*func_p)(im, ctx);
1519 break;
1520 }
fa2ea656 1521
23005b3f
AM
1522-#if HAVE_LIBGD204
1523+#if HAVE_LIBGD204
1524 ctx->gd_free(ctx);
1525 #else
1526 ctx->free(ctx);
1527-#endif
1528+#endif
fa2ea656 1529
23005b3f
AM
1530 if(fp) {
1531 fflush(fp);
1532 fclose(fp);
1533 }
1534-
1535+
1536 RETURN_TRUE;
fa2ea656 1537 }
23005b3f
AM
1538+/* }}} */
1539+
1540+/*
1541+ * Local variables:
1542+ * tab-width: 4
1543+ * c-basic-offset: 4
1544+ * End:
1545+ * vim600: sw=4 ts=4 fdm=marker
1546+ * vim<600: sw=4 ts=4
1547+ */
1548diff -urN php-4.4.8.org/ext/gd/gd.dsp php-4.4.8/ext/gd/gd.dsp
1549--- php-4.4.8.org/ext/gd/gd.dsp 2007-05-03 04:55:11.000000000 +0200
84aee732 1550+++ php-4.4.8/ext/gd/gd.dsp 2008-01-22 22:38:05.887151436 +0100
23005b3f
AM
1551@@ -54,9 +54,9 @@
1552 # ADD BASE BSC32 /nologo\r
1553 # ADD BSC32 /nologo\r
1554 LINK32=link.exe\r
1555-# ADD BASE LINK32 php4ts.lib libjpeg.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd2.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"\r
1556+# ADD BASE LINK32 php5ts.lib libjpeg.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd2.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"\r
1557 # SUBTRACT BASE LINK32 /pdb:none\r
1558-# ADD LINK32 php4ts.lib freetype2.lib libjpeg.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd2.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\zlib\Release"\r
1559+# ADD LINK32 php5ts.lib freetype2.lib libjpeg.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd2.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\zlib\Release"\r
1560 # SUBTRACT LINK32 /pdb:none\r
1561 \r
1562 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1563@@ -84,9 +84,9 @@
1564 # ADD BASE BSC32 /nologo\r
1565 # ADD BSC32 /nologo\r
1566 LINK32=link.exe\r
1567-# ADD BASE LINK32 php4ts_debug.lib libjpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd2.dll" /libpath:"..\..\Debug_TS"\r
1568+# ADD BASE LINK32 php5ts_debug.lib libjpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd2.dll" /libpath:"..\..\Debug_TS"\r
1569 # SUBTRACT BASE LINK32 /pdb:none\r
1570-# ADD LINK32 php4ts_debug.lib libpng.lib zlib.lib libjpeg.lib freetype2.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /nodefaultlib:"MSVCRT" /out:"..\..\Debug_TS/php_gd2.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\zlib\Debug"\r
1571+# ADD LINK32 php5ts_debug.lib libpng.lib zlib.lib libjpeg.lib freetype2.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd2.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\zlib\Debug"\r
1572 # SUBTRACT LINK32 /pdb:none\r
1573 \r
1574 !ENDIF \r
1575@@ -144,7 +144,6 @@
1576 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1577 \r
1578 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1579-# ADD CPP /FR\r
1580 \r
1581 !ENDIF \r
1582 \r
1583@@ -160,7 +159,6 @@
1584 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1585 \r
1586 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1587-# ADD CPP /FR\r
1588 \r
1589 !ENDIF \r
1590 \r
1591@@ -176,7 +174,6 @@
1592 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1593 \r
1594 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1595-# ADD CPP /FR\r
1596 \r
1597 !ENDIF \r
1598 \r
1599@@ -192,7 +189,6 @@
1600 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1601 \r
1602 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1603-# ADD CPP /FR\r
1604 \r
1605 !ENDIF \r
1606 \r
1607@@ -208,7 +204,6 @@
1608 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1609 \r
1610 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1611-# ADD CPP /FR\r
1612 \r
1613 !ENDIF \r
1614 \r
1615@@ -216,18 +211,6 @@
1616 # Begin Source File\r
1617 \r
1618 SOURCE=.\libgd\gd_gif_in.c\r
1619-\r
1620-!IF "$(CFG)" == "gd - Win32 Release_TS GD2"\r
1621-\r
1622-# PROP Intermediate_Dir "Release_TS_bundled"\r
1623-\r
1624-!ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1625-\r
1626-# PROP Intermediate_Dir "Debug_TS_bundled"\r
1627-# ADD CPP /FR\r
1628-\r
1629-!ENDIF \r
1630-\r
1631 # End Source File\r
1632 # Begin Source File\r
1633 \r
1634@@ -244,7 +227,6 @@
1635 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1636 \r
1637 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1638-# ADD CPP /FR\r
1639 \r
1640 !ENDIF \r
1641 \r
1642@@ -260,7 +242,6 @@
1643 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1644 \r
1645 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1646-# ADD CPP /FR\r
1647 \r
1648 !ENDIF \r
1649 \r
1650@@ -276,7 +257,6 @@
1651 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1652 \r
1653 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1654-# ADD CPP /FR\r
1655 \r
1656 !ENDIF \r
1657 \r
1658@@ -292,7 +272,6 @@
1659 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1660 \r
1661 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1662-# ADD CPP /FR\r
1663 \r
1664 !ENDIF \r
1665 \r
1666@@ -308,7 +287,6 @@
1667 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1668 \r
1669 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1670-# ADD CPP /FR\r
1671 \r
1672 !ENDIF \r
1673 \r
1674@@ -324,17 +302,12 @@
1675 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1676 \r
1677 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1678-# ADD CPP /FR\r
1679 \r
1680 !ENDIF \r
1681 \r
1682 # End Source File\r
1683 # Begin Source File\r
1684 \r
1685-SOURCE=.\libgd\gd_security.c\r
1686-# End Source File\r
1687-# Begin Source File\r
1688-\r
1689 SOURCE=.\libgd\gd_ss.c\r
1690 \r
1691 !IF "$(CFG)" == "gd - Win32 Release_TS GD2"\r
1692@@ -344,7 +317,6 @@
1693 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1694 \r
1695 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1696-# ADD CPP /FR\r
1697 \r
1698 !ENDIF \r
1699 \r
1700@@ -360,7 +332,6 @@
1701 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1702 \r
1703 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1704-# ADD CPP /FR\r
1705 \r
1706 !ENDIF \r
1707 \r
1708@@ -376,7 +347,6 @@
1709 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1710 \r
1711 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1712-# ADD CPP /FR\r
1713 \r
1714 !ENDIF \r
1715 \r
1716@@ -392,7 +362,6 @@
1717 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1718 \r
1719 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1720-# ADD CPP /FR\r
1721 \r
1722 !ENDIF \r
1723 \r
1724@@ -408,7 +377,6 @@
1725 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1726 \r
1727 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1728-# ADD CPP /FR\r
1729 \r
1730 !ENDIF \r
1731 \r
1732@@ -424,7 +392,6 @@
1733 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1734 \r
1735 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1736-# ADD CPP /FR\r
1737 \r
1738 !ENDIF \r
1739 \r
1740@@ -440,7 +407,6 @@
1741 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1742 \r
1743 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1744-# ADD CPP /FR\r
1745 \r
1746 !ENDIF \r
1747 \r
1748@@ -456,7 +422,6 @@
1749 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1750 \r
1751 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1752-# ADD CPP /FR\r
1753 \r
1754 !ENDIF \r
1755 \r
1756@@ -472,7 +437,6 @@
1757 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1758 \r
1759 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1760-# ADD CPP /FR\r
1761 \r
1762 !ENDIF \r
1763 \r
1764@@ -488,7 +452,6 @@
1765 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1766 \r
1767 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1768-# ADD CPP /FR\r
1769 \r
1770 !ENDIF \r
1771 \r
1772@@ -504,7 +467,6 @@
1773 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1774 \r
1775 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1776-# ADD CPP /FR\r
1777 \r
1778 !ENDIF \r
1779 \r
1780@@ -520,7 +482,6 @@
1781 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1782 \r
1783 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1784-# ADD CPP /FR\r
1785 \r
1786 !ENDIF \r
1787 \r
1788@@ -536,7 +497,6 @@
1789 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1790 \r
1791 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1792-# ADD CPP /FR\r
1793 \r
1794 !ENDIF \r
1795 \r
1796@@ -552,7 +512,6 @@
1797 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1798 \r
1799 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1800-# ADD CPP /FR\r
1801 \r
1802 !ENDIF \r
1803 \r
1804@@ -568,7 +527,6 @@
1805 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1806 \r
1807 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1808-# ADD CPP /FR\r
1809 \r
1810 !ENDIF \r
1811 \r
1812@@ -584,7 +542,6 @@
1813 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"\r
1814 \r
1815 # PROP Intermediate_Dir "Debug_TS_bundled"\r
1816-# ADD CPP /FR\r
1817 \r
1818 !ENDIF \r
1819 \r
1820diff -urN php-4.4.8.org/ext/gd/gdttf.c php-4.4.8/ext/gd/gdttf.c
1821--- php-4.4.8.org/ext/gd/gdttf.c 2005-01-09 22:05:31.000000000 +0100
84aee732 1822+++ php-4.4.8/ext/gd/gdttf.c 2008-01-22 22:38:05.887151436 +0100
23005b3f
AM
1823@@ -2,7 +2,7 @@
1824 /* */
1825 /* John Ellson ellson@lucent.com */
1826
1827-/* $Id$ */
1828+/* $Id$ */
fa2ea656 1829
23005b3f 1830 #include "php.h"
fa2ea656 1831
23005b3f
AM
1832@@ -28,11 +28,11 @@
1833 /* number of fonts cached before least recently used is replaced */
1834 #define FONTCACHESIZE 6
1835
1836-/* number of character glyphs cached per font before
1837+/* number of character glyphs cached per font before
1838 least-recently-used is replaced */
1839 #define GLYPHCACHESIZE 120
1840
1841-/* number of bitmaps cached per glyph before
1842+/* number of bitmaps cached per glyph before
1843 least-recently-used is replaced */
1844 #define BITMAPCACHESIZE 8
1845
1846@@ -42,15 +42,15 @@
1847 /* ptsize below which anti-aliasing is ineffective */
1848 #define MINANTIALIASPTSIZE 0
1849
1850-/* display resolution - (Not really. This has to be 72 or hinting is wrong) */
1851+/* display resolution - (Not really. This has to be 72 or hinting is wrong) */
1852 #define RESOLUTION 72
1853
1854 /* Number of colors used for anti-aliasing */
1855 #undef NUMCOLORS
1856 #define NUMCOLORS 4
1857
1858-/* Line separation as a factor of font height.
1859- No space between if LINESPACE = 1.00
1860+/* Line separation as a factor of font height.
1861+ No space between if LINESPACE = 1.00
1862 Line separation will be rounded up to next pixel row*/
fa2ea656 1863 #define LINESPACE 1.05
fa2ea656 1864
23005b3f
AM
1865@@ -125,7 +125,7 @@
1866 glyph_t *glyph;
1867 } bitmapkey_t;
1868
1869-typedef struct {
1870+typedef struct {
1871 unsigned char pixel; /* key */
1872 unsigned char bgcolor; /* key */
1873 int fgcolor; /* key */ /* -ve means no antialias */
1874@@ -138,7 +138,7 @@
1875 unsigned char bgcolor; /* key */
1876 int fgcolor; /* key */ /* -ve means no antialias */
1877 gdImagePtr im; /* key */
1878-} tweencolorkey_t;
fa2ea656
AM
1879+} tweencolorkey_t;
1880
23005b3f
AM
1881 /* forward declarations so that glyphCache can be initialized by font code */
1882 static int glyphTest ( void *element, void *key );
1883@@ -196,7 +196,7 @@
1884 *
1885 *---------------------------------------------------------------------------
1886 */
1887-
1888+
1889 #ifndef CHARSET_EBCDIC
1890 #define ASC(ch) (ch)
1891 #else /*CHARSET_EBCDIC*/
1892@@ -205,17 +205,16 @@
fa2ea656
AM
1893
1894 #define Tcl_UniChar int
1895 #define TCL_UTF_MAX 3
1896-static int
23005b3f
AM
1897-gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr)
1898+static int gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr)
fa2ea656
AM
1899 /* str is the UTF8 next character pointer */
1900 /* chPtr is the int for the result */
1901 {
23005b3f
AM
1902- int byte;
1903-
fa2ea656
AM
1904+ int byte;
1905+
23005b3f
AM
1906 /* HTML4.0 entities in decimal form, e.g. &#197; */
1907- byte = *((unsigned char *) str);
fa2ea656 1908+ byte = *((unsigned char *) str);
23005b3f
AM
1909 if (byte == '&') {
1910- int i, n=0;
fa2ea656 1911+ int i, n = 0;
fa2ea656 1912
23005b3f
AM
1913 byte = *((unsigned char *) (str+1));
1914 if (byte == '#') {
1915@@ -223,9 +222,9 @@
1916 byte = *((unsigned char *) (str+i));
1917 if (byte >= '0' && byte <= '9') {
1918 n = (n * 10) + (byte - '0');
1919- }
1920- else
1921+ } else {
1922 break;
1923+ }
1924 }
1925 if (byte == ';') {
1926 *chPtr = (Tcl_UniChar) n;
1927@@ -233,105 +232,91 @@
1928 }
1929 }
1930 }
1931-
1932- /*
1933- * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones.
1934- */
1935-
1936- byte = ASC(*((unsigned char *) str));
1937- if (byte < 0xC0) {
1938- /*
1939- * Handles properly formed UTF-8 characters between 0x01 and 0x7F.
1940- * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
1941- * characters representing themselves.
1942- */
1943
1944- *chPtr = (Tcl_UniChar) byte;
1945- return 1;
1946- } else if (byte < 0xE0) {
1947- if ((ASC(str[1]) & 0xC0) == 0x80) {
1948- /*
1949- * Two-byte-character lead-byte followed by a trail-byte.
1950- */
1951-
1952- *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F));
1953- return 2;
fa2ea656 1954- }
23005b3f
AM
1955- /*
1956- * A two-byte-character lead-byte not followed by trail-byte
1957- * represents itself.
1958- */
1959-
1960- *chPtr = (Tcl_UniChar) byte;
1961- return 1;
1962- } else if (byte < 0xF0) {
1963- if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) {
1964- /*
1965- * Three-byte-character lead byte followed by two trail bytes.
1966- */
1967-
1968- *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12)
1969- | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F));
1970- return 3;
1971- }
1972- /*
1973- * A three-byte-character lead-byte not followed by two trail-bytes
1974- * represents itself.
1975- */
fa2ea656
AM
1976+ /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */
1977
23005b3f
AM
1978- *chPtr = (Tcl_UniChar) byte;
1979- return 1;
fa2ea656 1980- }
23005b3f 1981+ byte = ASC(*((unsigned char *) str));
fa2ea656 1982+ if (byte < 0xC0) {
23005b3f
AM
1983+ /*
1984+ * Handles properly formed UTF-8 characters between 0x01 and 0x7F.
1985+ * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
1986+ * characters representing themselves.
fa2ea656
AM
1987+ */
1988+
1989+ *chPtr = (Tcl_UniChar) byte;
1990+ return 1;
1991+ } else if (byte < 0xE0) {
23005b3f 1992+ if ((ASC(str[1]) & 0xC0) == 0x80) {
fa2ea656
AM
1993+ /* Two-byte-character lead-byte followed by a trail-byte. */
1994+
23005b3f 1995+ *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F));
fa2ea656
AM
1996+ return 2;
1997+ }
1998+ /*
1999+ * A two-byte-character lead-byte not followed by trail-byte
2000+ * represents itself.
2001+ */
2002+
2003+ *chPtr = (Tcl_UniChar) byte;
2004+ return 1;
2005+ } else if (byte < 0xF0) {
23005b3f
AM
2006+ if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) {
2007+ /* Three-byte-character lead byte followed by two trail bytes. */
fa2ea656 2008+
23005b3f 2009+ *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F));
fa2ea656
AM
2010+ return 3;
2011+ }
2012+ /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */
2013+
2014+ *chPtr = (Tcl_UniChar) byte;
2015+ return 1;
2016+ }
2017 #if TCL_UTF_MAX > 3
23005b3f
AM
2018- else {
2019- int ch, total, trail;
fa2ea656
AM
2020+ else {
2021+ int ch, total, trail;
23005b3f
AM
2022
2023- total = totalBytes[byte];
2024- trail = total - 1;
2025- if (trail > 0) {
2026- ch = byte & (0x3F >> trail);
2027- do {
2028- str++;
2029- if ((ASC(*str) & 0xC0) != 0x80) {
2030- *chPtr = byte;
2031- return 1;
2032- }
2033- ch <<= 6;
2034- ch |= (ASC(*str) & 0x3F);
2035- trail--;
2036- } while (trail > 0);
2037- *chPtr = ch;
2038- return total;
fa2ea656
AM
2039+ total = totalBytes[byte];
2040+ trail = total - 1;
fa2ea656
AM
2041+ if (trail > 0) {
2042+ ch = byte & (0x3F >> trail);
2043+ do {
2044+ str++;
23005b3f 2045+ if ((ASC(*str) & 0xC0) != 0x80) {
fa2ea656
AM
2046+ *chPtr = byte;
2047+ return 1;
2048+ }
2049+ ch <<= 6;
23005b3f 2050+ ch |= (ASC(*str) & 0x3F);
fa2ea656
AM
2051+ trail--;
2052+ } while (trail > 0);
2053+ *chPtr = ch;
2054+ return total;
2055+ }
2056 }
2057- }
2058 #endif
2059
23005b3f
AM
2060- *chPtr = (Tcl_UniChar) byte;
2061- return 1;
fa2ea656
AM
2062+ *chPtr = (Tcl_UniChar) byte;
2063+ return 1;
2064 }
2065
2066 /********************************************************************/
2067 /* font cache functions */
2068
2069-static int
23005b3f
AM
2070-fontTest ( void *element, void *key )
2071+static int fontTest ( void *element, void *key )
fa2ea656 2072 {
23005b3f
AM
2073- font_t *a=(font_t *)element;
2074- fontkey_t *b=(fontkey_t *)key;
2075+ font_t *a = (font_t *)element;
2076+ fontkey_t *b = (fontkey_t *)key;
fa2ea656 2077
23005b3f
AM
2078- return ( strcmp(a->fontname, b->fontname) == 0
2079- && a->ptsize == b->ptsize
2080- && a->angle == b->angle);
2081+ return (strcmp(a->fontname, b->fontname) == 0 && a->ptsize == b->ptsize && a->angle == b->angle);
fa2ea656
AM
2082 }
2083
23005b3f
AM
2084-static void *
2085-fontFetch ( char **error, void *key )
2086+static void * fontFetch ( char **error, void *key )
2087 {
2088- TT_Error err;
2089- font_t *a;
2090- fontkey_t *b=(fontkey_t *)key;
2091- int i, n, map_found;
2092- short platform, encoding;
2093+ TT_Error err;
2094+ font_t *a;
2095+ fontkey_t *b = (fontkey_t *)key;
2096+ int i, n, map_found;
2097+ short platform, encoding;
2098 TSRMLS_FETCH();
fa2ea656 2099
23005b3f
AM
2100 a = (font_t *)pemalloc(sizeof(font_t), 1);
2101@@ -354,8 +339,7 @@
2102 if ((err = TT_Open_Face(*b->engine, a->fontname, &a->face))) {
2103 if (err == TT_Err_Could_Not_Open_File) {
2104 *error = "Could not find/open font";
2105- }
2106- else {
2107+ } else {
2108 *error = "Could not read font";
2109 }
2110 pefree(a, 1);
2111@@ -370,7 +354,7 @@
2112 pefree(a, 1);
2113 return NULL;
fa2ea656 2114 }
23005b3f 2115-
fa2ea656 2116+
23005b3f
AM
2117 if (TT_Set_Instance_Resolutions(a->instance, RESOLUTION, RESOLUTION)) {
2118 *error = "Could not set device resolutions";
2119 pefree(a, 1);
2120@@ -384,12 +368,12 @@
fa2ea656 2121 }
23005b3f
AM
2122
2123 TT_Get_Instance_Metrics(a->instance, &a->imetrics);
2124-
fa2ea656 2125+
23005b3f
AM
2126 /* First, look for a Unicode charmap */
2127 n = TT_Get_CharMap_Count(a->face);
2128
2129 for (i = 0; i < n; i++) {
2130- TT_Get_CharMap_ID(a->face, i, &platform, &encoding);
2131+ TT_Get_CharMap_ID(a->face, i, &platform, &encoding);
2132 if ((platform == 3 && encoding == 1) /* Windows Unicode */
2133 || (platform == 2 && encoding == 1)
2134 || (platform == 0)) { /* ?? Unicode */
2135@@ -407,7 +391,7 @@
2136 }
2137 }
2138
2139- if (! map_found) {
2140+ if (!map_found) {
2141 *error = "Unable to find a CharMap that I can handle";
2142 pefree(a, 1);
2143 return NULL;
2144@@ -418,16 +402,14 @@
2145 a->matrix.xy = - a->matrix.yx;
2146 a->matrix.yy = a->matrix.xx;
2147
2148- a->glyphCache = gdCacheCreate( GLYPHCACHESIZE,
2149- glyphTest, glyphFetch, glyphRelease);
2150+ a->glyphCache = gdCacheCreate(GLYPHCACHESIZE, glyphTest, glyphFetch, glyphRelease);
2151
2152 return (void *)a;
2153 }
2154
2155-static void
2156-fontRelease( void *element )
2157+static void fontRelease( void *element )
fa2ea656 2158 {
23005b3f
AM
2159- font_t *a=(font_t *)element;
2160+ font_t *a = (font_t *)element;
2161
2162 gdCacheDelete(a->glyphCache);
2163 TT_Done_Instance(a->instance);
2164@@ -439,26 +421,22 @@
2165 /********************************************************************/
2166 /* glyph cache functions */
2167
2168-static int
2169-glyphTest ( void *element, void *key )
2170+static int glyphTest ( void *element, void *key )
2171 {
2172- glyph_t *a=(glyph_t *)element;
2173- glyphkey_t *b=(glyphkey_t *)key;
2174+ glyph_t *a = (glyph_t *)element;
2175+ glyphkey_t *b = (glyphkey_t *)key;
2176+
2177+ return (a->character == b->character && a->hinting == b->hinting && a->gray_render == b->gray_render);
2178+}
2179
2180- return (a->character == b->character
2181- && a->hinting == b->hinting
2182- && a->gray_render == b->gray_render);
2183-}
fa2ea656 2184-
23005b3f
AM
2185-static void *
2186-glyphFetch ( char **error, void *key )
2187-{
2188- glyph_t *a;
2189- glyphkey_t *b=(glyphkey_t *)key;
2190- short glyph_code;
2191- int flags, err;
2192- int crect[8], xmin, xmax, ymin, ymax;
2193- double cos_a, sin_a;
2194+static void * glyphFetch ( char **error, void *key )
2195+{
2196+ glyph_t *a;
2197+ glyphkey_t *b = (glyphkey_t *)key;
2198+ short glyph_code;
2199+ int flags, err;
2200+ int crect[8], xmin, xmax, ymin, ymax;
2201+ double cos_a, sin_a;
2202
2203 a = (glyph_t *)pemalloc(sizeof(glyph_t), 1);
2204 a->character = b->character;
2205@@ -523,38 +501,34 @@
2206 a->Bit.flow = TT_Flow_Up;
2207 if (a->gray_render) {
2208 a->Bit.cols = a->Bit.width; /* 1 byte per pixel */
2209- }
2210- else {
2211+ } else {
2212 a->Bit.cols = (a->Bit.width + 7) / 8; /* 1 bit per pixel */
fa2ea656 2213 }
23005b3f
AM
2214 a->Bit.cols = (a->Bit.cols + 3) & ~3; /* pad to 32 bits */
2215 a->Bit.size = a->Bit.rows * a->Bit.cols; /* # of bytes in buffer */
2216 a->Bit.bitmap = NULL;
fa2ea656 2217
23005b3f
AM
2218- a->bitmapCache = gdCacheCreate( BITMAPCACHESIZE,
2219- bitmapTest, bitmapFetch, bitmapRelease);
2220+ a->bitmapCache = gdCacheCreate(BITMAPCACHESIZE, bitmapTest, bitmapFetch, bitmapRelease);
fa2ea656 2221
23005b3f 2222 return (void *)a;
fa2ea656
AM
2223 }
2224
23005b3f
AM
2225-static void
2226-glyphRelease( void *element )
2227+static void glyphRelease( void *element )
fa2ea656 2228 {
23005b3f
AM
2229- glyph_t *a=(glyph_t *)element;
2230+ glyph_t *a = (glyph_t *)element;
fa2ea656 2231
23005b3f
AM
2232 gdCacheDelete(a->bitmapCache);
2233- TT_Done_Glyph( a->glyph );
2234- pefree ((char *)element, 1);
2235+ TT_Done_Glyph(a->glyph);
2236+ pefree((char *)element, 1);
fa2ea656
AM
2237 }
2238
23005b3f
AM
2239 /********************************************************************/
2240 /* bitmap cache functions */
fa2ea656 2241
23005b3f
AM
2242-static int
2243-bitmapTest ( void *element, void *key )
2244+static int bitmapTest ( void *element, void *key )
fa2ea656 2245 {
23005b3f
AM
2246- bitmap_t *a=(bitmap_t *)element;
2247- bitmapkey_t *b=(bitmapkey_t *)key;
2248+ bitmap_t *a = (bitmap_t *)element;
2249+ bitmapkey_t *b = (bitmapkey_t *)key;
fa2ea656 2250
23005b3f
AM
2251 if (a->xoffset == b->xoffset && a->yoffset == b->yoffset) {
2252 b->glyph->Bit.bitmap = a->bitmap;
2253@@ -563,11 +537,10 @@
2254 return FALSE;
2255 }
fa2ea656 2256
23005b3f
AM
2257-static void *
2258-bitmapFetch ( char **error, void *key )
2259+static void * bitmapFetch ( char **error, void *key )
2260 {
2261- bitmap_t *a;
2262- bitmapkey_t *b=(bitmapkey_t *)key;
2263+ bitmap_t *a;
2264+ bitmapkey_t *b = (bitmapkey_t *)key;
2265
2266 a = (bitmap_t *)pemalloc(sizeof(bitmap_t), 1);
2267 a->xoffset = b->xoffset;
2268@@ -577,56 +550,47 @@
2269 memset(a->bitmap, 0, b->glyph->Bit.size);
2270 /* render glyph */
2271 if (b->glyph->gray_render) {
2272- TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit,
2273- a->xoffset, a->yoffset);
fa2ea656 2274- }
23005b3f
AM
2275- else {
2276- TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit,
2277- a->xoffset, a->yoffset);
2278+ TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset);
2279+ } else {
2280+ TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset);
2281 }
2282 return (void *)a;
fa2ea656
AM
2283 }
2284
23005b3f
AM
2285-static void
2286-bitmapRelease( void *element )
2287+static void bitmapRelease( void *element )
fa2ea656 2288 {
23005b3f
AM
2289- bitmap_t *a=(bitmap_t *)element;
2290+ bitmap_t *a = (bitmap_t *)element;
fa2ea656 2291
23005b3f
AM
2292- pefree (a->bitmap, 1);
2293- pefree ((char *)element, 1);
2294+ pefree(a->bitmap, 1);
2295+ pefree((char *)element, 1);
2296 }
fa2ea656 2297
23005b3f
AM
2298 /********************************************************************/
2299 /* tweencolor cache functions */
fa2ea656 2300
23005b3f
AM
2301-static int
2302-tweenColorTest (void *element, void *key)
2303-{
2304- tweencolor_t *a=(tweencolor_t *)element;
2305- tweencolorkey_t *b=(tweencolorkey_t *)key;
2306-
2307- return (a->pixel == b->pixel
2308- && a->bgcolor == b->bgcolor
2309- && a->fgcolor == b->fgcolor
2310- && a->im == b->im);
2311-}
2312+static int tweenColorTest (void *element, void *key)
2313+{
2314+ tweencolor_t *a = (tweencolor_t *)element;
2315+ tweencolorkey_t *b = (tweencolorkey_t *)key;
fa2ea656 2316+
23005b3f 2317+ return (a->pixel == b->pixel && a->bgcolor == b->bgcolor && a->fgcolor == b->fgcolor && a->im == b->im);
aeb33d2f 2318+}
fa2ea656 2319
23005b3f
AM
2320-static void *
2321-tweenColorFetch (char **error, void *key)
2322+static void * tweenColorFetch (char **error, void *key)
fa2ea656 2323 {
23005b3f
AM
2324- tweencolor_t *a;
2325- tweencolorkey_t *b=(tweencolorkey_t *)key;
2326+ tweencolor_t *a;
2327+ tweencolorkey_t *b = (tweencolorkey_t *)key;
2328 int pixel, npixel, bg, fg;
2329 gdImagePtr im;
2330-
2331- a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1);
aeb33d2f 2332+
23005b3f
AM
2333+ a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1);
2334 pixel = a->pixel = b->pixel;
2335 bg = a->bgcolor = b->bgcolor;
2336 fg = a->fgcolor = b->fgcolor;
2337 im = b->im;
fa2ea656 2338
23005b3f
AM
2339 /* if fg is specified by a negative color idx, then don't antialias */
2340- if (fg <0) {
2341+ if (fg < 0) {
2342 a->tweencolor = -fg;
2343 } else {
2344 npixel = NUMCOLORS - pixel;
2345@@ -635,20 +599,19 @@
2346 (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS,
2347 (pixel * im->blue [fg] + npixel * im->blue [bg]) / NUMCOLORS);
2348 }
2349- *error = NULL;
2350- return (void *)a;
2351-}
2352-
2353-static void
2354-tweenColorRelease(void *element)
2355-{
2356- pefree((char *)element, 1);
2357-}
2358+ *error = NULL;
2359+ return (void *)a;
2360+}
fa2ea656 2361+
23005b3f
AM
2362+static void tweenColorRelease(void *element)
2363+{
2364+ pefree((char *)element, 1);
2365+}
fa2ea656 2366
23005b3f
AM
2367 /********************************************************************/
2368 /* gdttfchar - render one character onto a gd image */
fa2ea656 2369
23005b3f
AM
2370-static int OneTime=0;
2371+static int OneTime = 0;
2372 static gdCache_head_t *tweenColorCache;
fa2ea656 2373
23005b3f
AM
2374 char *
2375@@ -656,38 +619,37 @@
2376 int x, int y, /* string start pos in pixels */
2377 TT_F26Dot6 x1, TT_F26Dot6 y1, /* char start offset (*64) from x,y */
2378 TT_F26Dot6 *advance,
2379- TT_BBox **bbox,
2380+ TT_BBox **bbox,
2381 char **next)
2382 {
2383- int pc, ch, len;
2384+ int pc, ch, len;
2385 int row, col;
2386- int x2, y2; /* char start pos in pixels */
2387+ int x2, y2; /* char start pos in pixels */
2388 int x3, y3; /* current pixel pos */
2389 unsigned char *pixel;
2390
2391- glyph_t *glyph;
2392- glyphkey_t glyphkey;
2393- bitmapkey_t bitmapkey;
2394+ glyph_t *glyph;
2395+ glyphkey_t glyphkey;
2396+ bitmapkey_t bitmapkey;
2397 tweencolor_t *tweencolor;
2398 tweencolorkey_t tweencolorkey;
2399
2400 /****** set up tweenColorCache on first call ************/
2401- if (! OneTime) {
2402- tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE,
2403- tweenColorTest, tweenColorFetch, tweenColorRelease);
2404+ if (!OneTime) {
2405+ tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE, tweenColorTest, tweenColorFetch, tweenColorRelease);
2406 OneTime++;
2407 }
2408 /**************/
2409
2410 if (font->have_char_map_Unicode) { /* use UTF-8 mapping from ASCII */
2411- len = gdTcl_UtfToUniChar(*next, &ch);
2412- *next += len;
2413+ len = gdTcl_UtfToUniChar(*next, &ch);
2414+ *next += len;
2415 } else {
2416- /*
2417- * Big 5 mapping:
2418- * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref:
2419- * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs
2420- */
2421+ /*
2422+ * Big 5 mapping:
2423+ * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref:
2424+ * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs
2425+ */
2426 ch = (**next) & 255; /* don't extend sign */
2427 (*next)++;
2428 if (ch >= 161 /* first code of JIS-8 pair */
2429@@ -700,18 +662,20 @@
2430 glyphkey.character = ch;
2431 glyphkey.hinting = 1;
2432 /* if fg is specified by a negative color idx, then don't antialias */
2433- glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg <0))?FALSE:TRUE;
2434- glyphkey.font = font;
2435- glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey);
2436- if (! glyph)
2437+ glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg < 0)) ? FALSE : TRUE;
2438+ glyphkey.font = font;
2439+ glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey);
2440+ if (!glyph) {
2441 return font->glyphCache->error;
2442+ }
2443
2444 *bbox = &glyph->metrics.bbox;
2445 *advance = glyph->metrics.advance;
2446
2447 /* if null *im, or invalid color, then assume user just wants brect */
2448- if (!im || fg > 255 || fg < -255)
2449+ if (!im || fg > 255 || fg < -255) {
2450 return (char *)NULL;
2451+ }
2452
2453 /* render (via cache) a bitmap for the current fractional offset */
2454 bitmapkey.xoffset = ((x1+32) & 63) - 32 - ((glyph->xmin+32) & -64);
2455@@ -720,30 +684,32 @@
2456 gdCacheGet(glyph->bitmapCache, &bitmapkey);
2457
2458 /* copy to gif, mapping colors */
2459- x2 = x + (((glyph->xmin+32) & -64) + ((x1+32) & -64)) / 64;
2460- y2 = y - (((glyph->ymin+32) & -64) + ((y1+32) & -64)) / 64;
2461+ x2 = x + (((glyph->xmin+32) & -64) + ((x1+32) & -64)) / 64;
2462+ y2 = y - (((glyph->ymin+32) & -64) + ((y1+32) & -64)) / 64;
2463 tweencolorkey.fgcolor = fg;
2464 tweencolorkey.im = im;
2465 for (row = 0; row < glyph->Bit.rows; row++) {
2466- if (glyph->gray_render)
2467+ if (glyph->gray_render) {
2468 pc = row * glyph->Bit.cols;
2469- else
2470+ } else {
2471 pc = row * glyph->Bit.cols * 8;
fa2ea656 2472+ }
23005b3f
AM
2473 y3 = y2 - row;
2474- if (y3 >= im->sy || y3 < 0) continue;
2475+ if (y3 >= im->sy || y3 < 0) {
2476+ continue;
fa2ea656 2477+ }
23005b3f
AM
2478 for (col = 0; col < glyph->Bit.width; col++, pc++) {
2479 if (glyph->gray_render) {
2480- tweencolorkey.pixel =
2481- *((unsigned char *)(glyph->Bit.bitmap) + pc);
2482+ tweencolorkey.pixel = *((unsigned char *)(glyph->Bit.bitmap) + pc);
2483 } else {
2484- tweencolorkey.pixel =
2485- (((*((unsigned char *)(glyph->Bit.bitmap) + pc/8))
2486- <<(pc%8))&128)?4:0;
2487+ tweencolorkey.pixel = (((*((unsigned char *)(glyph->Bit.bitmap) + pc/8)) << (pc%8))&128)?4:0;
2488 }
2489 /* if not background */
2490 if (tweencolorkey.pixel > 0) {
2491 x3 = x2 + col;
2492- if (x3 >= im->sx || x3 < 0) continue;
2493+ if (x3 >= im->sx || x3 < 0) {
2494+ continue;
2495+ }
2496 #if HAVE_LIBGD20
2497 if (im->trueColor) {
2498 pixel = &im->tpixels[y3][x3];
2499@@ -757,8 +723,7 @@
fa2ea656 2500 #endif
23005b3f
AM
2501 }
2502 tweencolorkey.bgcolor = *pixel;
2503- tweencolor = (tweencolor_t *)gdCacheGet(
2504- tweenColorCache, &tweencolorkey);
2505+ tweencolor = (tweencolor_t *)gdCacheGet(tweenColorCache, &tweencolorkey);
2506 *pixel = tweencolor->tweencolor;
2507 }
2508 }
2509@@ -769,29 +734,26 @@
2510 /********************************************************************/
2511 /* gdttf - render a utf8 string onto a gd image */
2512
2513-char *
2514-gdttf(gdImage *im, int *brect, int fg, char *fontname,
2515- double ptsize, double angle, int x, int y, char *str)
2516+char * gdttf(gdImage *im, int *brect, int fg, char *fontname, double ptsize, double angle, int x, int y, char *str)
2517 {
2518- TT_F26Dot6 ur_x=0, ur_y=0, ll_x=0, ll_y=0;
2519+ TT_F26Dot6 ur_x = 0, ur_y = 0, ll_x = 0, ll_y = 0;
2520 TT_F26Dot6 advance_x, advance_y, advance, x1, y1;
2521 TT_BBox *bbox;
2522 double sin_a, cos_a;
2523- int i=0, ch;
2524+ int i=0, ch;
2525 font_t *font;
2526 fontkey_t fontkey;
2527 char *error, *next;
2528
2529 /****** initialize font engine on first call ************/
2530- static gdCache_head_t *fontCache;
2531+ static gdCache_head_t *fontCache;
2532 static TT_Engine engine;
2533
2534- if (! fontCache) {
2535+ if (!fontCache) {
2536 if (TT_Init_FreeType(&engine)) {
2537 return "Failure to initialize font engine";
2538 }
2539- fontCache = gdCacheCreate( FONTCACHESIZE,
2540- fontTest, fontFetch, fontRelease);
2541+ fontCache = gdCacheCreate(FONTCACHESIZE, fontTest, fontFetch, fontRelease);
2542 }
2543 /**************/
2544
2545@@ -801,15 +763,15 @@
2546 fontkey.angle = angle;
2547 fontkey.engine = &engine;
2548 font = (font_t *)gdCacheGet(fontCache, &fontkey);
2549- if (! font) {
2550+ if (!font) {
2551 return fontCache->error;
2552 }
2553 sin_a = font->sin_a;
2554 cos_a = font->cos_a;
2555 advance_x = advance_y = 0;
2556
2557- next=str;
2558- while (*next) {
2559+ next = str;
2560+ while (*next) {
2561 ch = *next;
fa2ea656 2562
23005b3f
AM
2563 /* carriage returns */
2564@@ -820,8 +782,8 @@
2565 }
2566 /* newlines */
2567 if (ch == '\n') {
2568- advance_y -= (TT_F26Dot6)(font->imetrics.y_ppem * LINESPACE * 64);
2569- advance_y = (advance_y-32) & -64; /* round to next pixel row */
2570+ advance_y -= (TT_F26Dot6)(font->imetrics.y_ppem * LINESPACE * 64);
2571+ advance_y = (advance_y-32) & -64; /* round to next pixel row */
2572 next++;
2573 continue;
2574 }
2575@@ -829,20 +791,24 @@
2576 x1 = (TT_F26Dot6)(advance_x * cos_a - advance_y * sin_a);
2577 y1 = (TT_F26Dot6)(advance_x * sin_a + advance_y * cos_a);
fa2ea656 2578
23005b3f
AM
2579- if ((error=gdttfchar(im, fg, font, x, y, x1, y1, &advance, &bbox, &next)))
2580+ if ((error = gdttfchar(im, fg, font, x, y, x1, y1, &advance, &bbox, &next))) {
2581 return error;
2582+ }
fa2ea656 2583
23005b3f
AM
2584- if (! i++) { /* if first character, init BB corner values */
2585+ if (!i++) { /* if first character, init BB corner values */
2586 ll_x = bbox->xMin;
2587 ll_y = bbox->yMin;
2588 ur_x = bbox->xMax;
2589 ur_y = bbox->yMax;
2590- }
2591- else {
2592- if (! advance_x) ll_x = MIN(bbox->xMin, ll_x);
2593+ } else {
2594+ if (!advance_x) {
2595+ ll_x = MIN(bbox->xMin, ll_x);
2596+ }
2597 ll_y = MIN(advance_y + bbox->yMin, ll_y);
2598 ur_x = MAX(advance_x + bbox->xMax, ur_x);
2599- if (! advance_y) ur_y = MAX(bbox->yMax, ur_y);
2600+ if (!advance_y) {
2601+ ur_y = MAX(bbox->yMax, ur_y);
2602+ }
2603 }
2604 advance_x += advance;
2605 }
2606@@ -859,7 +825,7 @@
fa2ea656 2607
23005b3f
AM
2608 /* scale, round and offset brect */
2609 i = 0;
2610- while (i<8) {
2611+ while (i < 8) {
2612 brect[i] = x + (brect[i] + 32) / 64;
2613 i++;
2614 brect[i] = y - (brect[i] + 32) / 64;
2615@@ -868,7 +834,7 @@
2616
2617 return (char *)NULL;
2618 }
2619-
fa2ea656 2620+
23005b3f
AM
2621 #endif /* HAVE_LIBTTF */
2622
2623 /*
84aee732
AM
2624diff -urN php-4.4.8.org/ext/gd/libgd/gd_arc_f_buggy.c php-4.4.8/ext/gd/libgd/gd_arc_f_buggy.c
2625--- php-4.4.8.org/ext/gd/libgd/gd_arc_f_buggy.c 2003-03-05 17:04:20.000000000 +0100
2626+++ php-4.4.8/ext/gd/libgd/gd_arc_f_buggy.c 2005-08-18 14:54:43.000000000 +0200
2627@@ -1,6 +1,6 @@
2628 /* This is potentially great stuff, but fails against the test
2629- program at the end. This would probably be much more
2630- efficent than the implementation currently in gd.c if the
2631+ program at the end. This would probably be much more
2632+ efficent than the implementation currently in gd.c if the
2633 errors in the output were corrected. TBB */
2634
2635 #if 0
2636@@ -698,7 +698,7 @@
2637 #define WIDTH 500
2638 #define HEIGHT 300
2639
2640-int
2641+int
2642 main (int argc, char *argv[])
2643 {
2644 gdImagePtr im = gdImageCreate (WIDTH, HEIGHT);
2645@@ -726,12 +726,12 @@
2646 out = fopen ("test/arctest.png", "wb");
2647 if (!out)
2648 {
2649- php_gd_error("Can't create test/arctest.png\n");
2650+ php_gd_error("Can't create test/arctest.png");
2651 exit (1);
2652 }
2653 gdImagePng (im, out);
2654 fclose (out);
2655- php_gd_error("Test image written to test/arctest.png\n");
2656+ php_gd_error("Test image written to test/arctest.png");
2657 /* Destroy it */
2658 gdImageDestroy (im);
2659
2660diff -urN php-4.4.8.org/ext/gd/libgd/gd.c php-4.4.8/ext/gd/libgd/gd.c
2661--- php-4.4.8.org/ext/gd/libgd/gd.c 2007-10-20 17:29:04.000000000 +0200
2662+++ php-4.4.8/ext/gd/libgd/gd.c 2007-11-05 00:56:00.000000000 +0100
2663@@ -1,4 +1,4 @@
2664-#include <stdio.h>
2665+
2666 #include <math.h>
2667 #include <string.h>
2668 #include <stdlib.h>
2669@@ -90,18 +90,16 @@
2670 static void gdImageBrushApply(gdImagePtr im, int x, int y);
2671 static void gdImageTileApply(gdImagePtr im, int x, int y);
2672 static void gdImageAntiAliasedApply(gdImagePtr im, int x, int y);
2673-static int gdFullAlphaBlend(int dst, int src);
2674 static int gdLayerOverlay(int dst, int src);
2675-static int gdAlphaBlendColor(int b1, int b2, int a1, int a2);
2676 static int gdAlphaOverlayColor(int src, int dst, int max);
2677 int gdImageGetTrueColorPixel(gdImagePtr im, int x, int y);
2678
2679-void php_gd_error_ex(int type, const char *format, ...)
2680+void php_gd_error_ex(int type, const char *format, ...)
2681 {
2682 va_list args;
2683-
2684+
2685 TSRMLS_FETCH();
2686-
2687+
2688 va_start(args, format);
2689 php_verror(NULL, "", type, format, args TSRMLS_CC);
2690 va_end(args);
2691@@ -110,9 +108,9 @@
2692 void php_gd_error(const char *format, ...)
2693 {
2694 va_list args;
2695-
2696+
2697 TSRMLS_FETCH();
2698-
2699+
2700 va_start(args, format);
2701 php_verror(NULL, "", E_WARNING, format, args TSRMLS_CC);
2702 va_end(args);
2703@@ -122,11 +120,20 @@
2704 {
2705 int i;
2706 gdImagePtr im;
2707- im = (gdImage *) gdMalloc(sizeof(gdImage));
2708- memset(im, 0, sizeof(gdImage));
2709+
2710+ if (overflow2(sx, sy)) {
2711+ return NULL;
2712+ }
2713+
2714+ if (overflow2(sizeof(unsigned char *), sy)) {
2715+ return NULL;
2716+ }
2717+
2718+ im = (gdImage *) gdCalloc(1, sizeof(gdImage));
2719+
2720 /* Row-major ever since gd 1.3 */
2721- im->pixels = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0);
2722- im->AA_opacity = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0);
2723+ im->pixels = (unsigned char **) gdMalloc(sizeof(unsigned char *) * sy);
2724+ im->AA_opacity = (unsigned char **) gdMalloc(sizeof(unsigned char *) * sy);
2725 im->polyInts = 0;
2726 im->polyAllocated = 0;
2727 im->brush = 0;
2728@@ -164,10 +171,23 @@
2729 {
2730 int i;
2731 gdImagePtr im;
2732+
2733+ if (overflow2(sx, sy)) {
2734+ return NULL;
2735+ }
2736+
2737+ if (overflow2(sizeof(unsigned char *), sy)) {
2738+ return NULL;
2739+ }
2740+
2741+ if (overflow2(sizeof(int), sx)) {
2742+ return NULL;
2743+ }
2744+
2745 im = (gdImage *) gdMalloc(sizeof(gdImage));
2746 memset(im, 0, sizeof(gdImage));
2747- im->tpixels = (int **) safe_emalloc(sizeof(int *), sy, 0);
2748- im->AA_opacity = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0);
2749+ im->tpixels = (int **) gdMalloc(sizeof(int *) * sy);
2750+ im->AA_opacity = (unsigned char **) gdMalloc(sizeof(unsigned char *) * sy);
2751 im->polyInts = 0;
2752 im->polyAllocated = 0;
2753 im->brush = 0;
2754@@ -267,8 +287,8 @@
2755 }
2756
2757 /* This code is taken from http://www.acm.org/jgt/papers/SmithLyons96/hwb_rgb.html, an article
2758- * on colour conversion to/from RBG and HWB colour systems.
2759- * It has been modified to return the converted value as a * parameter.
2760+ * on colour conversion to/from RBG and HWB colour systems.
2761+ * It has been modified to return the converted value as a * parameter.
2762 */
2763
2764 #define RETURN_HWB(h, w, b) {HWB->H = h; HWB->W = w; HWB->B = b; return HWB;}
2765@@ -287,8 +307,8 @@
2766
2767
2768 /*
2769- * Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. Pure
2770- * red always maps to 6 in this implementation. Therefore UNDEFINED can be
2771+ * Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. Pure
2772+ * red always maps to 6 in this implementation. Therefore UNDEFINED can be
2773 * defined as 0 in situations where only unsigned numbers are desired.
2774 */
2775 typedef struct
2776@@ -305,8 +325,8 @@
2777 static HWBType * RGB_to_HWB (RGBType RGB, HWBType * HWB)
2778 {
2779 /*
2780- * RGB are each on [0, 1]. W and B are returned on [0, 1] and H is
2781- * returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B.
2782+ * RGB are each on [0, 1]. W and B are returned on [0, 1] and H is
2783+ * returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B.
2784 */
2785
2786 float R = RGB.R, G = RGB.G, B = RGB.B, w, v, b, f;
2787@@ -320,7 +340,7 @@
2788 }
2789 f = (R == w) ? G - B : ((G == w) ? B - R : R - G);
2790 i = (R == w) ? 3 : ((G == w) ? 5 : 1);
2791-
2792+
2793 RETURN_HWB(i - f / (v - w), w, b);
2794 }
2795
2796@@ -363,9 +383,9 @@
2797 */
2798 static RGBType * HWB_to_RGB (HWBType HWB, RGBType * RGB)
2799 {
2800- /*
2801- * H is given on [0, 6] or UNDEFINED. W and B are given on [0, 1].
2802- * RGB are each returned on [0, 1].
2803+ /*
2804+ * H is given on [0, 6] or UNDEFINED. W and B are given on [0, 1].
2805+ * RGB are each returned on [0, 1].
2806 */
2807
2808 float h = HWB.H, w = HWB.W, b = HWB.B, v, n, f;
2809@@ -478,7 +498,7 @@
2810 im->blue[ct] = b;
2811 im->alpha[ct] = a;
2812 im->open[ct] = 0;
2813-
2814+
2815 return ct;
2816 }
2817
2818@@ -629,7 +649,7 @@
2819 * Given the end points of a line, and a bounding rectangle (which we
2820 * know to be from (0,0) to (SX,SY)), adjust the endpoints to be on
2821 * the edges of the rectangle if the line should be drawn at all,
2822- * otherwise return a failure code
2823+ * otherwise return a failure code
2824 */
2825
2826 /* this does "one-dimensional" clipping: note that the second time it
2827@@ -637,7 +657,7 @@
2828 * - the comments ignore this (if you can understand it when it's
2829 * looking at the X parameters, it should become clear what happens on
2830 * the second call!) The code is simplified from that in the article,
2831- * as we know that gd images always start at (0,0)
2832+ * as we know that gd images always start at (0,0)
2833 */
2834
2835 static int clip_1d(int *x0, int *y0, int *x1, int *y1, int maxdim) {
2836@@ -664,7 +684,7 @@
2837 }
2838 m = (*y1 - *y0)/(double)(*x1 - *x0); /* calculate the slope of the line */
2839 *y0 += (int)(m * (maxdim - *x0)); /* adjust so point is on the right boundary */
2840- *x0 = maxdim;
2841+ *x0 = maxdim;
2842 /* now, perhaps, adjust the end of the line */
2843 if (*x1 < 0) {
2844 *y1 -= (int)(m * *x1);
2845@@ -737,7 +757,7 @@
2846 im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color);
2847 break;
2848 case gdEffectNormal:
2849- im->tpixels[y][x] = gdFullAlphaBlend(im->tpixels[y][x], color);
2850+ im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color);
2851 break;
2852 case gdEffectOverlay :
2853 im->tpixels[y][x] = gdLayerOverlay(im->tpixels[y][x], color);
2854@@ -756,7 +776,7 @@
2855 int p = gdImageGetPixel(im, x, y);
2856
2857 if (!im->trueColor) {
2858- return gdTrueColorAlpha(im->red[p], im->green[p], im->blue[p], (im->transparent == p) ? gdAlphaTransparent : gdAlphaOpaque);
2859+ return gdTrueColorAlpha(im->red[p], im->green[p], im->blue[p], (im->transparent == p) ? gdAlphaTransparent : im->alpha[p]);
2860 } else {
2861 return p;
2862 }
2863@@ -780,7 +800,7 @@
2864 x1 = x - hx;
2865 x2 = x1 + gdImageSX(im->brush);
2866 srcy = 0;
2867-
2868+
2869 if (im->trueColor) {
2870 if (im->brush->trueColor) {
2871 for (ly = y1; ly < y2; ly++) {
2872@@ -823,8 +843,8 @@
2873 if (p != gdImageGetTransparent(im->brush)) {
2874 /* Truecolor brush. Very slow on a palette destination. */
2875 if (im->brush->trueColor) {
2876- gdImageSetPixel(im, lx, ly, gdImageColorResolveAlpha(im, gdTrueColorGetRed(p),
2877- gdTrueColorGetGreen(p),
2878+ gdImageSetPixel(im, lx, ly, gdImageColorResolveAlpha(im, gdTrueColorGetRed(p),
2879+ gdTrueColorGetGreen(p),
2880 gdTrueColorGetBlue(p),
2881 gdTrueColorGetAlpha(p)));
2882 } else {
2883@@ -849,7 +869,9 @@
2884 srcy = y % gdImageSY(im->tile);
2885 if (im->trueColor) {
2886 p = gdImageGetTrueColorPixel(im->tile, srcx, srcy);
2887- gdImageSetPixel(im, x, y, p);
2888+ if (p != gdImageGetTransparent (im->tile)) {
2889+ gdImageSetPixel(im, x, y, p);
2890+ }
2891 } else {
2892 p = gdImageGetPixel(im->tile, srcx, srcy);
2893 /* Allow for transparency */
2894@@ -903,8 +925,8 @@
2895 float p_dist, p_alpha;
2896 unsigned char opacity;
2897
2898- /*
2899- * Find the perpendicular distance from point C (px, py) to the line
2900+ /*
2901+ * Find the perpendicular distance from point C (px, py) to the line
2902 * segment AB that is being drawn. (Adapted from an algorithm from the
2903 * comp.graphics.algorithms FAQ.)
2904 */
2905@@ -918,7 +940,7 @@
2906 int By_Cy = im->AAL_y2 - py;
2907
2908 /* 2.0.13: bounds check! AA_opacity is just as capable of
2909- * overflowing as the main pixel array. Arne Jorgensen.
2910+ * overflowing as the main pixel array. Arne Jorgensen.
2911 * 2.0.14: typo fixed. 2.0.15: moved down below declarations
2912 * to satisfy non-C++ compilers.
2913 */
2914@@ -931,12 +953,12 @@
2915 LBC_2 = (Bx_Cx * Bx_Cx) + (By_Cy * By_Cy);
2916
2917 if (((im->AAL_LAB_2 + LAC_2) >= LBC_2) && ((im->AAL_LAB_2 + LBC_2) >= LAC_2)) {
2918- /* The two angles are acute. The point lies inside the portion of the
2919+ /* The two angles are acute. The point lies inside the portion of the
2920 * plane spanned by the line segment.
2921 */
2922 p_dist = fabs ((float) ((Ay_Cy * im->AAL_Bx_Ax) - (Ax_Cx * im->AAL_By_Ay)) / im->AAL_LAB);
2923 } else {
2924- /* The point is past an end of the line segment. It's length from the
2925+ /* The point is past an end of the line segment. It's length from the
2926 * segment is the shorter of the lengths from the endpoints, but call
2927 * the distance -1, so as not to compute the alpha nor draw the pixel.
2928 */
2929@@ -1017,6 +1039,43 @@
2930 }
2931 }
2932
2933+static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col)
2934+{
2935+ if (im->thick > 1) {
2936+ int thickhalf = im->thick >> 1;
2937+ gdImageFilledRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col);
2938+ } else {
2939+ if (x2 < x1) {
2940+ int t = x2;
2941+ x2 = x1;
2942+ x1 = t;
2943+ }
2944+
2945+ for (;x1 <= x2; x1++) {
2946+ gdImageSetPixel(im, x1, y, col);
2947+ }
2948+ }
2949+ return;
2950+}
2951+
2952+static void gdImageVLine(gdImagePtr im, int x, int y1, int y2, int col)
2953+{
2954+ if (im->thick > 1) {
2955+ int thickhalf = im->thick >> 1;
2956+ gdImageFilledRectangle(im, x - thickhalf, y1, x + im->thick - thickhalf - 1, y2, col);
2957+ } else {
2958+ if (y2 < y1) {
2959+ int t = y1;
2960+ y1 = y2;
2961+ y2 = t;
2962+ }
2963+
2964+ for (;y1 <= y2; y1++) {
2965+ gdImageSetPixel(im, x, y1, col);
2966+ }
2967+ }
2968+ return;
2969+}
2970
2971 /* Bresenham as presented in Foley & Van Dam */
2972 void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
2973@@ -1026,39 +1085,47 @@
2974 int w, wstart;
2975 int thick = im->thick;
2976
2977+ if (color == gdAntiAliased)
2978+ {
2979+ /*
2980+ gdAntiAliased passed as color: use the much faster, much cheaper
2981+ and equally attractive gdImageAALine implementation. That
2982+ clips too, so don't clip twice.
2983+ */
2984+ gdImageAALine(im, x1, y1, x2, y2, im->AA_color);
2985+ return;
2986+ }
2987+
2988 /* 2.0.10: Nick Atty: clip to edges of drawing rectangle, return if no points need to be drawn */
2989 if (!clip_1d(&x1,&y1,&x2,&y2,gdImageSX(im)) || !clip_1d(&y1,&x1,&y2,&x2,gdImageSY(im))) {
2990 return;
2991 }
2992
2993- /* gdAntiAliased passed as color: set anti-aliased line (AAL) global vars. */
2994- if (color == gdAntiAliased) {
2995- im->AAL_x1 = x1;
2996- im->AAL_y1 = y1;
2997- im->AAL_x2 = x2;
2998- im->AAL_y2 = y2;
2999-
3000- /* Compute what we can for point-to-line distance calculation later. */
3001- im->AAL_Bx_Ax = x2 - x1;
3002- im->AAL_By_Ay = y2 - y1;
3003- im->AAL_LAB_2 = (im->AAL_Bx_Ax * im->AAL_Bx_Ax) + (im->AAL_By_Ay * im->AAL_By_Ay);
3004- im->AAL_LAB = sqrt (im->AAL_LAB_2);
3005+ dx = abs (x2 - x1);
3006+ dy = abs (y2 - y1);
3007
3008- /* For AA, we must draw pixels outside the width of the line. Keep in
3009- * mind that this will be curtailed by cos/sin of theta later.
3010- */
3011- thick += 4;
3012+ if (dx == 0) {
3013+ gdImageVLine(im, x1, y1, y2, color);
3014+ return;
3015+ } else if (dy == 0) {
3016+ gdImageHLine(im, y1, x1, x2, color);
3017+ return;
3018 }
3019-
3020- dx = abs(x2 - x1);
3021- dy = abs(y2 - y1);
3022+
3023 if (dy <= dx) {
3024 /* More-or-less horizontal. use wid for vertical stroke */
3025 /* Doug Claar: watch out for NaN in atan2 (2.0.5) */
3026 if ((dx == 0) && (dy == 0)) {
3027 wid = 1;
3028 } else {
3029- wid = (int)(thick * cos (atan2 (dy, dx)));
3030+ /* 2.0.12: Michael Schwartz: divide rather than multiply;
3031+TBB: but watch out for /0! */
3032+ double ac = cos (atan2 (dy, dx));
3033+ if (ac != 0) {
3034+ wid = thick / ac;
3035+ } else {
3036+ wid = 1;
3037+ }
3038 if (wid == 0) {
3039 wid = 1;
3040 }
3041@@ -1115,16 +1182,17 @@
3042 }
3043 } else {
3044 /* More-or-less vertical. use wid for horizontal stroke */
3045- /* 2.0.12: Michael Schwartz: divide rather than multiply;
3046- TBB: but watch out for /0! */
3047- double as = sin(atan2(dy, dx));
3048+ /* 2.0.12: Michael Schwartz: divide rather than multiply;
3049+ TBB: but watch out for /0! */
3050+ double as = sin (atan2 (dy, dx));
3051 if (as != 0) {
3052- if (!(wid = thick / as)) {
3053- wid = 1;
3054- }
3055+ wid = thick / as;
3056 } else {
3057 wid = 1;
3058 }
3059+ if (wid == 0) {
3060+ wid = 1;
3061+ }
3062
3063 d = 2 * dx - dy;
3064 incr1 = 2 * dx;
3065@@ -1177,11 +1245,6 @@
3066 }
3067 }
3068 }
3069-
3070- /* If this is the only line we are drawing, go ahead and blend. */
3071- if (color == gdAntiAliased && !im->AA_polygon) {
3072- gdImageAABlend(im);
3073- }
3074 }
3075
3076
3077@@ -1207,7 +1270,7 @@
3078 BLEND_COLOR(t, dg, g, dg);
3079 BLEND_COLOR(t, db, b, db);
3080 im->tpixels[y][x]=gdTrueColorAlpha(dr, dg, db, gdAlphaOpaque);
3081-}
3082+}
3083
3084 /*
3085 * Added on 2003/12 by Pierre-Alain Joye (pajoye@pearfr.org)
3086@@ -1586,9 +1649,9 @@
3087
3088 /* s and e are integers modulo 360 (degrees), with 0 degrees
3089 being the rightmost extreme and degrees changing clockwise.
3090- cx and cy are the center in pixels; w and h are the horizontal
3091+ cx and cy are the center in pixels; w and h are the horizontal
3092 and vertical diameter in pixels. Nice interface, but slow.
3093- See gd_arc_f_buggy.c for a better version that doesn't
3094+ See gd_arc_f_buggy.c for a better version that doesn't
3095 seem to be bug-free yet. */
3096
3097 void gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
3098@@ -1607,29 +1670,30 @@
3099 int lx = 0, ly = 0;
3100 int fx = 0, fy = 0;
3101
3102- if ((s % 360) == (e % 360)) {
3103+
3104+ if ((s % 360) == (e % 360)) {
3105 s = 0; e = 360;
3106- } else {
3107- if (s > 360) {
3108- s = s % 360;
3109- }
3110+ } else {
3111+ if (s > 360) {
3112+ s = s % 360;
3113+ }
3114
3115- if (e > 360) {
3116- e = e % 360;
3117- }
3118+ if (e > 360) {
3119+ e = e % 360;
3120+ }
3121
3122- while (s < 0) {
3123- s += 360;
3124- }
3125+ while (s < 0) {
3126+ s += 360;
3127+ }
3128
3129- while (e < s) {
3130- e += 360;
3131- }
3132+ while (e < s) {
3133+ e += 360;
3134+ }
3135
3136- if (s == e) {
3137+ if (s == e) {
3138 s = 0; e = 360;
3139- }
3140- }
3141+ }
3142+ }
3143
3144 for (i = s; i <= e; i++) {
3145 int x, y;
3146@@ -1787,17 +1851,15 @@
3147 int lastBorder;
3148 /* Seek left */
3149 int leftLimit = -1, rightLimit;
3150- int i, restoreAlphaBleding=0;
3151+ int i, restoreAlphaBlending = 0;
3152
3153 if (border < 0) {
3154 /* Refuse to fill to a non-solid border */
3155 return;
3156 }
3157
3158- if (im->alphaBlendingFlag) {
3159- restoreAlphaBleding = 1;
3160- im->alphaBlendingFlag = 0;
3161- }
3162+ restoreAlphaBlending = im->alphaBlendingFlag;
3163+ im->alphaBlendingFlag = 0;
3164
3165 if (x >= im->sx) {
3166 x = im->sx - 1;
3167@@ -1814,9 +1876,7 @@
3168 leftLimit = i;
3169 }
3170 if (leftLimit == -1) {
3171- if (restoreAlphaBleding) {
3172- im->alphaBlendingFlag = 1;
3173- }
3174+ im->alphaBlendingFlag = restoreAlphaBlending;
3175 return;
3176 }
3177 /* Seek right */
3178@@ -1844,6 +1904,7 @@
3179 }
3180 }
3181 }
3182+
3183 /* Below */
3184 if (y < ((im->sy) - 1)) {
3185 lastBorder = 1;
3186@@ -1860,12 +1921,9 @@
3187 }
3188 }
3189 }
3190- if (restoreAlphaBleding) {
3191- im->alphaBlendingFlag = 1;
3192- }
3193+ im->alphaBlendingFlag = restoreAlphaBlending;
3194 }
3195
3196-
3197 /*
3198 * set the pixel at (x,y) and its 4-connected neighbors
3199 * with the same pixel value to the new pixel value nc (new color).
3200@@ -1888,25 +1946,31 @@
3201 #define FILL_POP(Y, XL, XR, DY) \
3202 {sp--; Y = sp->y+(DY = sp->dy); XL = sp->xl; XR = sp->xr;}
3203
3204-void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc);
3205+static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc);
3206
3207 void gdImageFill(gdImagePtr im, int x, int y, int nc)
3208 {
3209 int l, x1, x2, dy;
3210 int oc; /* old pixel value */
3211 int wx2,wy2;
3212+
3213 int alphablending_bak;
3214+
3215 /* stack of filled segments */
3216 /* struct seg stack[FILL_MAX],*sp = stack;; */
3217- struct seg *stack;
3218+ struct seg *stack = NULL;
3219 struct seg *sp;
3220
3221+ if (!im->trueColor && nc > (im->colorsTotal -1)) {
3222+ return;
3223+ }
3224+
3225 alphablending_bak = im->alphaBlendingFlag;
3226 im->alphaBlendingFlag = 0;
3227
3228 if (nc==gdTiled){
3229 _gdImageFillTiled(im,x,y,nc);
3230- im->alphaBlendingFlag = alphablending_bak;
3231+ im->alphaBlendingFlag = alphablending_bak;
3232 return;
3233 }
3234
3235@@ -1916,8 +1980,31 @@
3236 im->alphaBlendingFlag = alphablending_bak;
3237 return;
3238 }
3239-
3240- stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1);
3241+
3242+ /* Do not use the 4 neighbors implementation with
3243+ * small images
3244+ */
3245+ if (im->sx < 4) {
3246+ int ix = x, iy = y, c;
3247+ do {
3248+ c = gdImageGetPixel(im, ix, iy);
3249+ if (c != oc) {
3250+ goto done;
3251+ }
3252+ gdImageSetPixel(im, ix, iy, nc);
3253+ } while(ix++ < (im->sx -1));
3254+ ix = x; iy = y + 1;
3255+ do {
3256+ c = gdImageGetPixel(im, ix, iy);
3257+ if (c != oc) {
3258+ goto done;
3259+ }
3260+ gdImageSetPixel(im, ix, iy, nc);
3261+ } while(ix++ < (im->sx -1));
3262+ goto done;
3263+ }
3264+
3265+ stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1);
3266 sp = stack;
3267
3268 /* required! */
3269@@ -1954,22 +2041,25 @@
3270 l = x;
3271 } while (x<=x2);
3272 }
3273+
3274 efree(stack);
3275+
3276+done:
3277 im->alphaBlendingFlag = alphablending_bak;
3278 }
3279
3280-void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
3281+static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
3282 {
3283- int i,l, x1, x2, dy;
3284+ int i, l, x1, x2, dy;
3285 int oc; /* old pixel value */
3286 int tiled;
3287 int wx2,wy2;
3288 /* stack of filled segments */
3289 struct seg *stack;
3290 struct seg *sp;
3291+ char **pts;
3292
3293- int **pts;
3294- if(!im->tile){
3295+ if (!im->tile) {
3296 return;
3297 }
3298
3299@@ -1977,30 +2067,26 @@
3300 tiled = nc==gdTiled;
3301
3302 nc = gdImageTileGet(im,x,y);
3303- pts = (int **) ecalloc(sizeof(int *) * im->sy, sizeof(int));
3304
3305- for (i=0; i<im->sy;i++) {
3306- pts[i] = (int *) ecalloc(im->sx, sizeof(int));
3307+ pts = (char **) ecalloc(im->sy + 1, sizeof(char *));
3308+ for (i = 0; i < im->sy + 1; i++) {
3309+ pts[i] = (char *) ecalloc(im->sx + 1, sizeof(char));
3310 }
3311
3312- stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1);
3313+ stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1);
3314 sp = stack;
3315
3316 oc = gdImageGetPixel(im, x, y);
3317
3318- /* required! */
3319+/* required! */
3320 FILL_PUSH(y,x,x,1);
3321 /* seed segment (popped 1st) */
3322 FILL_PUSH(y+1, x, x, -1);
3323 while (sp>stack) {
3324 FILL_POP(y, x1, x2, dy);
3325 for (x=x1; x>=0 && (!pts[y][x] && gdImageGetPixel(im,x,y)==oc); x--) {
3326- if (pts[y][x]){
3327- /* we should never be here */
3328- break;
3329- }
3330 nc = gdImageTileGet(im,x,y);
3331- pts[y][x]=1;
3332+ pts[y][x] = 1;
3333 gdImageSetPixel(im,x, y, nc);
3334 }
3335 if (x>=x1) {
3336@@ -2014,13 +2100,9 @@
3337 }
3338 x = x1+1;
3339 do {
3340- for (; x<=wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc) ; x++) {
3341- if (pts[y][x]){
3342- /* we should never be here */
3343- break;
3344- }
3345+ for(; x<wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc); x++) {
3346 nc = gdImageTileGet(im,x,y);
3347- pts[y][x]=1;
3348+ pts[y][x] = 1;
3349 gdImageSetPixel(im, x, y, nc);
3350 }
3351 FILL_PUSH(y, l, x-1, dy);
3352@@ -2028,13 +2110,15 @@
3353 if (x>x2+1) {
3354 FILL_PUSH(y, x2+1, x-1, -dy);
3355 }
3356-skip: for (x++; x<=x2 && (pts[y][x] || gdImageGetPixel(im,x, y)!=oc); x++);
3357+skip: for(x++; x<=x2 && (pts[y][x] || gdImageGetPixel(im,x, y)!=oc); x++);
3358 l = x;
3359 } while (x<=x2);
3360 }
3361- for (i=0; i<im->sy;i++) {
3362+
3363+ for(i = 0; i < im->sy + 1; i++) {
3364 efree(pts[i]);
3365 }
3366+
3367 efree(pts);
3368 efree(stack);
3369 }
3370@@ -2048,6 +2132,11 @@
3371 int half1 = 1;
3372 int t;
3373
3374+ if (x1 == x2 && y1 == y2 && thick == 1) {
3375+ gdImageSetPixel(im, x1, y1, color);
3376+ return;
3377+ }
3378+
3379 if (y2 < y1) {
3380 t=y1;
3381 y1 = y2;
3382@@ -2110,16 +2199,15 @@
3383 gdImageLine(im, x1v, y1v, x1v, y2v, color);
3384 gdImageLine(im, x2v, y1v, x2v, y2v, color);
3385 }
3386-
3387 }
3388
3389 void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
3390 {
3391 int x, y;
3392-
3393+
3394 /* Nick Atty: limit the points at the edge. Note that this also
3395 * nicely kills any plotting for rectangles completely outside the
3396- * window as it makes the tests in the for loops fail
3397+ * window as it makes the tests in the for loops fail
3398 */
3399 if (x1 < 0) {
3400 x1 = 0;
3401@@ -2133,15 +2221,15 @@
3402 if (y1 > gdImageSY(im)) {
3403 y1 = gdImageSY(im);
3404 }
3405- if (y2 < y1) {
3406- int t;
3407- t=y1;
3408- y1 = y2;
3409- y2 = t;
3410-
3411- t = x1;
3412+ if (x1 > x2) {
3413+ x = x1;
3414 x1 = x2;
3415- x2 = t;
3416+ x2 = x;
3417+ }
3418+ if (y1 > y2) {
3419+ y = y1;
3420+ y1 = y2;
3421+ y2 = y;
3422 }
3423
3424 for (y = y1; (y <= y2); y++) {
3425@@ -2162,9 +2250,9 @@
3426 if (dst->trueColor) {
3427 /* 2.0: much easier when the destination is truecolor. */
3428 /* 2.0.10: needs a transparent-index check that is still valid if
3429- * the source is not truecolor. Thanks to Frank Warmerdam.
3430+ * the source is not truecolor. Thanks to Frank Warmerdam.
3431 */
3432-
3433+
3434 if (src->trueColor) {
3435 for (y = 0; (y < h); y++) {
3436 for (x = 0; (x < w); x++) {
3437@@ -2178,7 +2266,7 @@
3438 for (x = 0; (x < w); x++) {
3439 int c = gdImageGetPixel (src, srcX + x, srcY + y);
3440 if (c != src->transparent) {
3441- gdImageSetPixel (dst, dstX + x, dstY + y, gdTrueColor(src->red[c], src->green[c], src->blue[c]));
3442+ gdImageSetPixel(dst, dstX + x, dstY + y, gdTrueColorAlpha(src->red[c], src->green[c], src->blue[c], src->alpha[c]));
3443 }
3444 }
3445 }
3446@@ -2225,7 +2313,7 @@
3447 /* Have we established a mapping for this color? */
3448 if (src->trueColor) {
3449 /* 2.05: remap to the palette available in the destination image. This is slow and
3450- * works badly, but it beats crashing! Thanks to Padhrig McCarthy.
3451+ * works badly, but it beats crashing! Thanks to Padhrig McCarthy.
3452 */
3453 mapTo = gdImageColorResolveAlpha (dst, gdTrueColorGetRed (c), gdTrueColorGetGreen (c), gdTrueColorGetBlue (c), gdTrueColorGetAlpha (c));
3454 } else if (colorMap[c] == (-1)) {
3455@@ -2237,9 +2325,9 @@
3456 nc = gdImageColorResolveAlpha (dst, src->red[c], src->green[c], src->blue[c], src->alpha[c]);
3457 }
3458 colorMap[c] = nc;
3459- mapTo = colorMap[c];
3460+ mapTo = colorMap[c];
3461 } else {
3462- mapTo = colorMap[c];
3463+ mapTo = colorMap[c];
3464 }
3465 gdImageSetPixel (dst, tox, toy, mapTo);
3466 tox++;
3467@@ -2257,7 +2345,7 @@
3468 int tox, toy;
3469 int ncR, ncG, ncB;
3470 toy = dstY;
3471-
3472+
3473 for (y = srcY; y < (srcY + h); y++) {
3474 tox = dstX;
3475 for (x = srcX; x < (srcX + w); x++) {
3476@@ -2304,15 +2392,17 @@
3477 for (x = srcX; (x < (srcX + w)); x++) {
3478 int nc;
3479 c = gdImageGetPixel (src, x, y);
3480+
3481 /* Added 7/24/95: support transparent copies */
3482 if (gdImageGetTransparent(src) == c) {
3483 tox++;
3484 continue;
3485 }
3486- /*
3487- * If it's the same image, mapping is NOT trivial since we
3488- * merge with greyscale target, but if pct is 100, the grey
3489- * value is not used, so it becomes trivial. pjw 2.0.12.
3490+
3491+ /*
3492+ * If it's the same image, mapping is NOT trivial since we
3493+ * merge with greyscale target, but if pct is 100, the grey
3494+ * value is not used, so it becomes trivial. pjw 2.0.12.
3495 */
3496 if (dst == src && pct == 100) {
3497 nc = c;
3498@@ -2320,9 +2410,10 @@
3499 dc = gdImageGetPixel(dst, tox, toy);
3500 g = (0.29900f * gdImageRed(dst, dc)) + (0.58700f * gdImageGreen(dst, dc)) + (0.11400f * gdImageBlue(dst, dc));
3501
3502- ncR = (int)(gdImageRed (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3503- ncG = (int)(gdImageGreen (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3504- ncB = (int)(gdImageBlue (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3505+ ncR = (int)(gdImageRed (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3506+ ncG = (int)(gdImageGreen (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3507+ ncB = (int)(gdImageBlue (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3508+
3509
3510 /* First look for an exact match */
3511 nc = gdImageColorExact(dst, ncR, ncG, ncB);
3512@@ -2354,10 +2445,18 @@
3513 int *stx, *sty;
3514 /* We only need to use floating point to determine the correct stretch vector for one line's worth. */
3515 double accum;
3516- stx = (int *) safe_emalloc(sizeof(int), srcW, 0);
3517- sty = (int *) safe_emalloc(sizeof(int), srcH, 0);
3518- accum = 0;
3519
3520+ if (overflow2(sizeof(int), srcW)) {
3521+ return;
3522+ }
3523+ if (overflow2(sizeof(int), srcH)) {
3524+ return;
3525+ }
3526+
3527+ stx = (int *) gdMalloc (sizeof (int) * srcW);
3528+ sty = (int *) gdMalloc (sizeof (int) * srcH);
3529+ accum = 0;
3530+
3531 /* Fixed by Mao Morimoto 2.0.16 */
3532 for (i = 0; (i < srcW); i++) {
3533 stx[i] = dstW * (i+1) / srcW - dstW * i / srcW ;
3534@@ -2387,7 +2486,7 @@
3535 /* 2.0.21, TK: not tox++ */
3536 tox += stx[x - srcX];
3537 continue;
3538- }
3539+ }
3540 } else {
3541 /* TK: old code follows */
3542 mapTo = gdImageGetTrueColorPixel (src, x, y);
3543@@ -2397,7 +2496,7 @@
3544 tox += stx[x - srcX];
3545 continue;
3546 }
3547- }
3548+ }
3549 } else {
3550 c = gdImageGetPixel (src, x, y);
3551 /* Added 7/24/95: support transparent copies */
3552@@ -2451,6 +2550,7 @@
3553 {
3554 int x, y;
3555 double sy1, sy2, sx1, sx2;
3556+
3557 if (!dst->trueColor) {
3558 gdImageCopyResized (dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
3559 return;
3560@@ -2497,7 +2597,7 @@
3561 }
3562 pcontribution = xportion * yportion;
3563 p = gdImageGetTrueColorPixel(src, (int) sx + srcX, (int) sy + srcY);
3564-
3565+
3566 alpha_factor = ((gdAlphaMax - gdTrueColorGetAlpha(p))) * pcontribution;
3567 red += gdTrueColorGetRed (p) * alpha_factor;
3568 green += gdTrueColorGetGreen (p) * alpha_factor;
3569@@ -2509,12 +2609,12 @@
3570 sx += 1.0f;
3571 }
3572 while (sx < sx2);
3573-
3574+
3575 sy += 1.0f;
3576 }
3577-
3578+
3579 while (sy < sy2);
3580-
3581+
3582 if (spixels != 0.0f) {
3583 red /= spixels;
3584 green /= spixels;
3585@@ -2524,7 +2624,7 @@
3586 if ( alpha_sum != 0.0f) {
3587 if( contrib_sum != 0.0f) {
3588 alpha_sum /= contrib_sum;
3589- }
3590+ }
3591 red /= alpha_sum;
3592 green /= alpha_sum;
3593 blue /= alpha_sum;
3594@@ -2549,7 +2649,7 @@
3595
3596
3597 /*
3598- * Rotate function Added on 2003/12
3599+ * Rotate function Added on 2003/12
3600 * by Pierre-Alain Joye (pajoye@pearfr.org)
3601 **/
3602 /* Begin rotate function */
3603@@ -2558,7 +2658,7 @@
3604 #endif /* ROTATE_PI */
3605
3606 #define ROTATE_DEG2RAD 3.1415926535897932384626433832795/180
3607-void gdImageSkewX (gdImagePtr dst, gdImagePtr src, int uRow, int iOffset, double dWeight, int clrBack)
3608+void gdImageSkewX (gdImagePtr dst, gdImagePtr src, int uRow, int iOffset, double dWeight, int clrBack, int ignoretransparent)
3609 {
3610 typedef int (*FuncPtr)(gdImagePtr, int, int);
3611 int i, r, g, b, a, clrBackR, clrBackG, clrBackB, clrBackA;
3612@@ -2623,10 +2723,14 @@
3613 a = 127;
3614 }
3615
3616- pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3617+ if (ignoretransparent && pxlSrc == dst->transparent) {
3618+ pxlSrc = dst->transparent;
3619+ } else {
3620+ pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3621
3622- if (pxlSrc == -1) {
3623- pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3624+ if (pxlSrc == -1) {
3625+ pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3626+ }
3627 }
3628
3629 if ((i + iOffset >= 0) && (i + iOffset < dst->sx)) {
3630@@ -2651,7 +2755,7 @@
3631 }
3632 }
3633
3634-void gdImageSkewY (gdImagePtr dst, gdImagePtr src, int uCol, int iOffset, double dWeight, int clrBack)
3635+void gdImageSkewY (gdImagePtr dst, gdImagePtr src, int uCol, int iOffset, double dWeight, int clrBack, int ignoretransparent)
3636 {
3637 typedef int (*FuncPtr)(gdImagePtr, int, int);
3638 int i, iYPos=0, r, g, b, a;
3639@@ -2710,10 +2814,14 @@
3640 a = 127;
3641 }
3642
3643- pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3644+ if (ignoretransparent && pxlSrc == dst->transparent) {
3645+ pxlSrc = dst->transparent;
3646+ } else {
3647+ pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3648
3649- if (pxlSrc == -1) {
3650- pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3651+ if (pxlSrc == -1) {
3652+ pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3653+ }
3654 }
3655
3656 if ((iYPos >= 0) && (iYPos < dst->sy)) {
3657@@ -2735,10 +2843,10 @@
3658 }
3659
3660 /* Rotates an image by 90 degrees (counter clockwise) */
3661-gdImagePtr gdImageRotate90 (gdImagePtr src)
3662+gdImagePtr gdImageRotate90 (gdImagePtr src, int ignoretransparent)
3663 {
3664 int uY, uX;
3665- int c, r,g,b,a;
3666+ int c,r,g,b,a;
3667 gdImagePtr dst;
3668 typedef int (*FuncPtr)(gdImagePtr, int, int);
3669 FuncPtr f;
3670@@ -2749,8 +2857,12 @@
3671 f = gdImageGetPixel;
3672 }
3673 dst = gdImageCreateTrueColor(src->sy, src->sx);
3674+ dst->transparent = src->transparent;
3675
3676 if (dst != NULL) {
3677+ int old_blendmode = dst->alphaBlendingFlag;
3678+ dst->alphaBlendingFlag = 0;
3679+
3680 gdImagePaletteCopy (dst, src);
3681
3682 for (uY = 0; uY<src->sy; uY++) {
3683@@ -2763,16 +2875,21 @@
3684 a = gdImageAlpha(src,c);
3685 c = gdTrueColorAlpha(r, g, b, a);
3686 }
3687- gdImageSetPixel(dst, uY, (dst->sy - uX - 1), c);
3688+ if (ignoretransparent && c == dst->transparent) {
3689+ gdImageSetPixel(dst, uY, (dst->sy - uX - 1), dst->transparent);
3690+ } else {
3691+ gdImageSetPixel(dst, uY, (dst->sy - uX - 1), c);
3692+ }
3693 }
3694 }
3695+ dst->alphaBlendingFlag = old_blendmode;
3696 }
3697
3698 return dst;
3699 }
3700
3701 /* Rotates an image by 180 degrees (counter clockwise) */
3702-gdImagePtr gdImageRotate180 (gdImagePtr src)
3703+gdImagePtr gdImageRotate180 (gdImagePtr src, int ignoretransparent)
3704 {
3705 int uY, uX;
3706 int c,r,g,b,a;
3707@@ -2786,8 +2903,12 @@
3708 f = gdImageGetPixel;
3709 }
3710 dst = gdImageCreateTrueColor(src->sx, src->sy);
3711+ dst->transparent = src->transparent;
3712
3713 if (dst != NULL) {
3714+ int old_blendmode = dst->alphaBlendingFlag;
3715+ dst->alphaBlendingFlag = 0;
3716+
3717 gdImagePaletteCopy (dst, src);
3718
3719 for (uY = 0; uY<src->sy; uY++) {
3720@@ -2800,16 +2921,22 @@
3721 a = gdImageAlpha(src,c);
3722 c = gdTrueColorAlpha(r, g, b, a);
3723 }
3724- gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), c);
3725+
3726+ if (ignoretransparent && c == dst->transparent) {
3727+ gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), dst->transparent);
3728+ } else {
3729+ gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), c);
3730+ }
3731 }
3732 }
3733+ dst->alphaBlendingFlag = old_blendmode;
3734 }
3735
3736 return dst;
3737 }
3738
3739 /* Rotates an image by 270 degrees (counter clockwise) */
3740-gdImagePtr gdImageRotate270 ( gdImagePtr src )
3741+gdImagePtr gdImageRotate270 (gdImagePtr src, int ignoretransparent)
3742 {
3743 int uY, uX;
3744 int c,r,g,b,a;
3745@@ -2822,9 +2949,13 @@
3746 } else {
3747 f = gdImageGetPixel;
3748 }
3749- dst = gdImageCreateTrueColor(src->sy, src->sx);
3750+ dst = gdImageCreateTrueColor (src->sy, src->sx);
3751+ dst->transparent = src->transparent;
3752
3753 if (dst != NULL) {
3754+ int old_blendmode = dst->alphaBlendingFlag;
3755+ dst->alphaBlendingFlag = 0;
3756+
3757 gdImagePaletteCopy (dst, src);
3758
3759 for (uY = 0; uY<src->sy; uY++) {
3760@@ -2837,15 +2968,21 @@
3761 a = gdImageAlpha(src,c);
3762 c = gdTrueColorAlpha(r, g, b, a);
3763 }
3764- gdImageSetPixel(dst, (dst->sx - uY - 1), uX, c);
3765+
3766+ if (ignoretransparent && c == dst->transparent) {
3767+ gdImageSetPixel(dst, (dst->sx - uY - 1), uX, dst->transparent);
3768+ } else {
3769+ gdImageSetPixel(dst, (dst->sx - uY - 1), uX, c);
3770+ }
3771 }
3772 }
3773+ dst->alphaBlendingFlag = old_blendmode;
3774 }
3775
3776 return dst;
3777 }
3778
3779-gdImagePtr gdImageRotate45 (gdImagePtr src, double dAngle, int clrBack)
3780+gdImagePtr gdImageRotate45 (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent)
3781 {
3782 typedef int (*FuncPtr)(gdImagePtr, int, int);
3783 gdImagePtr dst1,dst2,dst3;
3784@@ -2869,8 +3006,8 @@
3785 } else {
3786 f = gdImageGetPixel;
3787 }
3788- dst1 = gdImageCreateTrueColor(newx, newy);
3789
3790+ dst1 = gdImageCreateTrueColor(newx, newy);
3791 /******* Perform 1st shear (horizontal) ******/
3792 if (dst1 == NULL) {
3793 return NULL;
3794@@ -2885,6 +3022,15 @@
3795
3796 gdImagePaletteCopy (dst1, src);
3797
3798+ if (ignoretransparent) {
3799+ if (gdImageTrueColor(src)) {
3800+ dst1->transparent = src->transparent;
3801+ } else {
3802+
3803+ dst1->transparent = gdTrueColorAlpha(gdImageRed(src, src->transparent), gdImageBlue(src, src->transparent), gdImageGreen(src, src->transparent), 127);
3804+ }
3805+ }
3806+
3807 dRadAngle = dAngle * ROTATE_DEG2RAD; /* Angle in radians */
3808 dSinE = sin (dRadAngle);
3809 dTan = tan (dRadAngle / 2.0);
3810@@ -2897,7 +3043,7 @@
3811 }
3812
3813 iShear = (int)floor(dShear);
3814- gdImageSkewX(dst1, src, u, iShear, (dShear - iShear), clrBack);
3815+ gdImageSkewX(dst1, src, u, iShear, (dShear - iShear), clrBack, ignoretransparent);
3816 }
3817
3818 /*
3819@@ -2933,10 +3079,13 @@
3820 return NULL;
3821 }
3822 dst2->alphaBlendingFlag = gdEffectReplace;
3823+ if (ignoretransparent) {
3824+ dst2->transparent = dst1->transparent;
3825+ }
3826
3827 for (u = 0; u < dst2->sx; u++, dOffset -= dSinE) {
3828 iShear = (int)floor (dOffset);
3829- gdImageSkewY(dst2, dst1, u, iShear, (dOffset - (double)iShear), clrBack);
3830+ gdImageSkewY(dst2, dst1, u, iShear, (dOffset - (double)iShear), clrBack, ignoretransparent);
3831 }
3832
3833 /* 3rd shear */
3834@@ -2955,6 +3104,12 @@
3835 gdImageDestroy(dst2);
3836 return NULL;
3837 }
3838+
3839+ dst3->alphaBlendingFlag = gdEffectReplace;
3840+ if (ignoretransparent) {
3841+ dst3->transparent = dst2->transparent;
3842+ }
3843+
3844 if (dSinE >= 0.0) {
3845 dOffset = (double)(src->sx - 1) * dSinE * -dTan;
3846 } else {
3847@@ -2962,8 +3117,8 @@
3848 }
3849
3850 for (u = 0; u < dst3->sy; u++, dOffset += dTan) {
3851- int iShear = (int)floor(dOffset);
3852- gdImageSkewX(dst3, dst2, u, iShear, (dOffset - iShear), clrBack);
3853+ int iShear = (int)floor(dOffset);
3854+ gdImageSkewX(dst3, dst2, u, iShear, (dOffset - iShear), clrBack, ignoretransparent);
3855 }
3856
3857 gdImageDestroy(dst2);
3858@@ -2971,11 +3126,11 @@
3859 return dst3;
3860 }
3861
3862-gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack)
3863+gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent)
3864 {
3865 gdImagePtr pMidImg;
3866 gdImagePtr rotatedImg;
3867- int r,g,b,a;
3868+
3869 if (src == NULL) {
3870 return NULL;
3871 }
3872@@ -2993,41 +3148,33 @@
3873 }
3874
3875 if (dAngle == 90.00) {
3876- return gdImageRotate90(src);
3877+ return gdImageRotate90(src, ignoretransparent);
3878 }
3879 if (dAngle == 180.00) {
3880- return gdImageRotate180(src);
3881+ return gdImageRotate180(src, ignoretransparent);
3882 }
3883 if(dAngle == 270.00) {
3884- return gdImageRotate270 ( src);
3885+ return gdImageRotate270 (src, ignoretransparent);
3886 }
3887
3888 if ((dAngle > 45.0) && (dAngle <= 135.0)) {
3889- pMidImg = gdImageRotate90 (src);
3890+ pMidImg = gdImageRotate90 (src, ignoretransparent);
3891 dAngle -= 90.0;
3892 } else if ((dAngle > 135.0) && (dAngle <= 225.0)) {
3893- pMidImg = gdImageRotate180 (src);
3894+ pMidImg = gdImageRotate180 (src, ignoretransparent);
3895 dAngle -= 180.0;
3896 } else if ((dAngle > 225.0) && (dAngle <= 315.0)) {
3897- pMidImg = gdImageRotate270 (src);
3898+ pMidImg = gdImageRotate270 (src, ignoretransparent);
3899 dAngle -= 270.0;
3900 } else {
3901- return gdImageRotate45 (src, dAngle, clrBack);
3902+ return gdImageRotate45 (src, dAngle, clrBack, ignoretransparent);
3903 }
3904
3905 if (pMidImg == NULL) {
3906 return NULL;
3907 }
3908
3909- if(!src->trueColor) {
3910- r = gdImageRed(src, clrBack);
3911- g = gdImageGreen(src, clrBack);
3912- b = gdImageBlue(src, clrBack);
3913- a = gdImageAlpha(src, clrBack);
3914- clrBack = gdTrueColorAlpha(r,g,b,a);
3915- }
3916-
3917- rotatedImg = gdImageRotate45 (pMidImg, dAngle, clrBack);
3918+ rotatedImg = gdImageRotate45 (pMidImg, dAngle, clrBack, ignoretransparent);
3919 gdImageDestroy(pMidImg);
3920
3921 return rotatedImg;
3922@@ -3098,20 +3245,27 @@
3923 return;
3924 }
3925
3926+ if (overflow2(sizeof(int), n)) {
3927+ return;
3928+ }
3929+
3930 if (c == gdAntiAliased) {
3931 fill_color = im->AA_color;
3932 } else {
3933 fill_color = c;
3934 }
3935-
3936+
3937 if (!im->polyAllocated) {
3938- im->polyInts = (int *) safe_emalloc(sizeof(int), n, 0);
3939+ im->polyInts = (int *) gdMalloc(sizeof(int) * n);
3940 im->polyAllocated = n;
3941 }
3942 if (im->polyAllocated < n) {
3943 while (im->polyAllocated < n) {
3944 im->polyAllocated *= 2;
3945 }
3946+ if (overflow2(sizeof(int), im->polyAllocated)) {
3947+ return;
3948+ }
3949 im->polyInts = (int *) gdRealloc(im->polyInts, sizeof(int) * im->polyAllocated);
3950 }
3951 miny = p[0].y;
3952@@ -3131,7 +3285,7 @@
3953 }
3954 if (maxy >= gdImageSY(im)) {
3955 maxy = gdImageSY(im) - 1;
3956- }
3957+ }
3958
3959 /* Fix in 1.3: count a vertex only once */
3960 for (y = miny; y <= maxy; y++) {
3961@@ -3193,7 +3347,7 @@
3962 if (im->style) {
3963 gdFree(im->style);
3964 }
3965- im->style = (int *) safe_emalloc(sizeof(int), noOfPixels, 0);
3966+ im->style = (int *) gdMalloc(sizeof(int) * noOfPixels);
3967 memcpy(im->style, style, sizeof(int) * noOfPixels);
3968 im->styleLength = noOfPixels;
3969 im->stylePos = 0;
3970@@ -3323,9 +3477,9 @@
3971 }
3972
3973 int
3974-gdAlphaBlend (int dst, int src)
3975+gdAlphaBlendOld (int dst, int src)
3976 {
3977- /* 2.0.12: TBB: alpha in the destination should be a
3978+ /* 2.0.12: TBB: alpha in the destination should be a
3979 * component of the result. Thanks to Frank Warmerdam for
3980 * pointing out the issue.
3981 */
3982@@ -3345,6 +3499,51 @@
3983 gdTrueColorGetBlue (dst)) / gdAlphaMax));
3984 }
3985
3986+int gdAlphaBlend (int dst, int src) {
3987+ int src_alpha = gdTrueColorGetAlpha(src);
3988+ int dst_alpha, alpha, red, green, blue;
3989+ int src_weight, dst_weight, tot_weight;
3990+
3991+/* -------------------------------------------------------------------- */
3992+/* Simple cases we want to handle fast. */
3993+/* -------------------------------------------------------------------- */
3994+ if( src_alpha == gdAlphaOpaque )
3995+ return src;
3996+
3997+ dst_alpha = gdTrueColorGetAlpha(dst);
3998+ if( src_alpha == gdAlphaTransparent )
3999+ return dst;
4000+ if( dst_alpha == gdAlphaTransparent )
4001+ return src;
4002+
4003+/* -------------------------------------------------------------------- */
4004+/* What will the source and destination alphas be? Note that */
4005+/* the destination weighting is substantially reduced as the */
4006+/* overlay becomes quite opaque. */
4007+/* -------------------------------------------------------------------- */
4008+ src_weight = gdAlphaTransparent - src_alpha;
4009+ dst_weight = (gdAlphaTransparent - dst_alpha) * src_alpha / gdAlphaMax;
4010+ tot_weight = src_weight + dst_weight;
4011+
4012+/* -------------------------------------------------------------------- */
4013+/* What red, green and blue result values will we use? */
4014+/* -------------------------------------------------------------------- */
4015+ alpha = src_alpha * dst_alpha / gdAlphaMax;
4016+
4017+ red = (gdTrueColorGetRed(src) * src_weight
4018+ + gdTrueColorGetRed(dst) * dst_weight) / tot_weight;
4019+ green = (gdTrueColorGetGreen(src) * src_weight
4020+ + gdTrueColorGetGreen(dst) * dst_weight) / tot_weight;
4021+ blue = (gdTrueColorGetBlue(src) * src_weight
4022+ + gdTrueColorGetBlue(dst) * dst_weight) / tot_weight;
4023+
4024+/* -------------------------------------------------------------------- */
4025+/* Return merged result. */
4026+/* -------------------------------------------------------------------- */
4027+ return ((alpha << 24) + (red << 16) + (green << 8) + blue);
4028+
4029+}
4030+
4031 void gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg)
4032 {
4033 im->alphaBlendingFlag = alphaBlendingArg;
4034@@ -3362,44 +3561,6 @@
4035 im->saveAlphaFlag = saveAlphaArg;
4036 }
4037
4038-static int gdFullAlphaBlend (int dst, int src)
4039-{
4040- int a1, a2;
4041- a1 = gdAlphaTransparent - gdTrueColorGetAlpha(src);
4042- a2 = gdAlphaTransparent - gdTrueColorGetAlpha(dst);
4043-
4044- return ( ((gdAlphaTransparent - ((a1+a2)-(a1*a2/gdAlphaMax))) << 24) +
4045- (gdAlphaBlendColor( gdTrueColorGetRed(src), gdTrueColorGetRed(dst), a1, a2 ) << 16) +
4046- (gdAlphaBlendColor( gdTrueColorGetGreen(src), gdTrueColorGetGreen(dst), a1, a2 ) << 8) +
4047- (gdAlphaBlendColor( gdTrueColorGetBlue(src), gdTrueColorGetBlue(dst), a1, a2 ))
4048- );
4049-}
4050-
4051-static int gdAlphaBlendColor( int b1, int b2, int a1, int a2 )
4052-{
4053- int c;
4054- int w;
4055-
4056- /* deal with special cases */
4057-
4058- if( (gdAlphaMax == a1) || (0 == a2) ) {
4059- /* the back pixel can't be seen */
4060- return b1;
4061- } else if(0 == a1) {
4062- /* the front pixel can't be seen */
4063- return b2;
4064- } else if(gdAlphaMax == a2) {
4065- /* the back pixel is opaque */
4066- return ( a1 * b1 + ( gdAlphaMax - a1 ) * b2 ) / gdAlphaMax;
4067- }
4068-
4069- /* the general case */
4070- w = ( a1 * ( gdAlphaMax - a2 ) / ( gdAlphaMax - a1 * a2 / gdAlphaMax ) * b1 + \
4071- a2 * ( gdAlphaMax - a1 ) / ( gdAlphaMax - a1 * a2 / gdAlphaMax ) * b2 ) / gdAlphaMax;
4072- c = (a2 * b2 + ( gdAlphaMax - a2 ) * w ) / gdAlphaMax;
4073- return ( a1 * b1 + ( gdAlphaMax - a1 ) * c ) / gdAlphaMax;
4074-}
4075-
4076 static int gdLayerOverlay (int dst, int src)
4077 {
4078 int a1, a2;
4079@@ -3415,12 +3576,12 @@
4080 static int gdAlphaOverlayColor (int src, int dst, int max )
4081 {
4082 /* this function implements the algorithm
4083- *
4084+ *
4085 * for dst[rgb] < 0.5,
4086 * c[rgb] = 2.src[rgb].dst[rgb]
4087 * and for dst[rgb] > 0.5,
4088 * c[rgb] = -2.src[rgb].dst[rgb] + 2.dst[rgb] + 2.src[rgb] - 1
4089- *
4090+ *
4091 */
4092
4093 dst = dst << 1;
4094@@ -3472,3 +3633,457 @@
4095 *x2P = im->cx2;
4096 *y2P = im->cy2;
4097 }
4098+
4099+
4100+/* Filters function added on 2003/12
4101+ * by Pierre-Alain Joye (pajoye@pearfr.org)
4102+ **/
4103+/* Begin filters function */
4104+#ifndef HAVE_GET_TRUE_COLOR
4105+#define GET_PIXEL_FUNCTION(src)(src->trueColor?gdImageGetTrueColorPixel:gdImageGetPixel)
4106+#endif
4107+
4108+/* invert src image */
4109+int gdImageNegate(gdImagePtr src)
4110+{
4111+ int x, y;
4112+ int r,g,b,a;
4113+ int new_pxl, pxl;
4114+ typedef int (*FuncPtr)(gdImagePtr, int, int);
4115+ FuncPtr f;
4116+
4117+ if (src==NULL) {
4118+ return 0;
4119+ }
4120+
4121+ f = GET_PIXEL_FUNCTION(src);
4122+
4123+ for (y=0; y<src->sy; ++y) {
4124+ for (x=0; x<src->sx; ++x) {
4125+ pxl = f (src, x, y);
4126+ r = gdImageRed(src, pxl);
4127+ g = gdImageGreen(src, pxl);
4128+ b = gdImageBlue(src, pxl);
4129+ a = gdImageAlpha(src, pxl);
4130+
4131+ new_pxl = gdImageColorAllocateAlpha(src, 255-r, 255-g, 255-b, a);
4132+ if (new_pxl == -1) {
4133+ new_pxl = gdImageColorClosestAlpha(src, 255-r, 255-g, 255-b, a);
4134+ }
4135+ gdImageSetPixel (src, x, y, new_pxl);
4136+ }
4137+ }
4138+ return 1;
4139+}
4140+
4141+/* Convert the image src to a grayscale image */
4142+int gdImageGrayScale(gdImagePtr src)
4143+{
4144+ int x, y;
4145+ int r,g,b,a;
4146+ int new_pxl, pxl;
4147+ typedef int (*FuncPtr)(gdImagePtr, int, int);
4148+ FuncPtr f;
4149+ f = GET_PIXEL_FUNCTION(src);
4150+
4151+ if (src==NULL) {
4152+ return 0;
4153+ }
4154+
4155+ for (y=0; y<src->sy; ++y) {
4156+ for (x=0; x<src->sx; ++x) {
4157+ pxl = f (src, x, y);
4158+ r = gdImageRed(src, pxl);
4159+ g = gdImageGreen(src, pxl);
4160+ b = gdImageBlue(src, pxl);
4161+ a = gdImageAlpha(src, pxl);
4162+ r = g = b = (int) (.299 * r + .587 * g + .114 * b);
4163+
4164+ new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a);
4165+ if (new_pxl == -1) {
4166+ new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
4167+ }
4168+ gdImageSetPixel (src, x, y, new_pxl);
4169+ }
4170+ }
4171+ return 1;
4172+}
4173+
4174+/* Set the brightness level <level> for the image src */
4175+int gdImageBrightness(gdImagePtr src, int brightness)
4176+{
4177+ int x, y;
4178+ int r,g,b,a;
4179+ int new_pxl, pxl;
4180+ typedef int (*FuncPtr)(gdImagePtr, int, int);
4181+ FuncPtr f;
4182+ f = GET_PIXEL_FUNCTION(src);
4183+
4184+ if (src==NULL || (brightness < -255 || brightness>255)) {
4185+ return 0;
4186+ }
4187+
4188+ if (brightness==0) {
4189+ return 1;
4190+ }
4191+
4192+ for (y=0; y<src->sy; ++y) {
4193+ for (x=0; x<src->sx; ++x) {
4194+ pxl = f (src, x, y);
4195+
4196+ r = gdImageRed(src, pxl);
4197+ g = gdImageGreen(src, pxl);
4198+ b = gdImageBlue(src, pxl);
4199+ a = gdImageAlpha(src, pxl);
4200+
4201+ r = r + brightness;
4202+ g = g + brightness;
4203+ b = b + brightness;
4204+
4205+ r = (r > 255)? 255 : ((r < 0)? 0:r);
4206+ g = (g > 255)? 255 : ((g < 0)? 0:g);
4207+ b = (b > 255)? 255 : ((b < 0)? 0:b);
4208+
4209+ new_pxl = gdImageColorAllocateAlpha(src, (int)r, (int)g, (int)b, a);
4210+ if (new_pxl == -1) {
4211+ new_pxl = gdImageColorClosestAlpha(src, (int)r, (int)g, (int)b, a);
4212+ }
4213+ gdImageSetPixel (src, x, y, new_pxl);
4214+ }
4215+ }
4216+ return 1;
4217+}
4218+
4219+
4220+int gdImageContrast(gdImagePtr src, double contrast)
4221+{
4222+ int x, y;
4223+ int r,g,b,a;
4224+ double rf,gf,bf;
4225+ int new_pxl, pxl;
4226+ typedef int (*FuncPtr)(gdImagePtr, int, int);
4227+
4228+ FuncPtr f;
4229+ f = GET_PIXEL_FUNCTION(src);
4230+
4231+ if (src==NULL) {
4232+ return 0;
4233+ }
4234+
4235+ contrast = (double)(100.0-contrast)/100.0;
4236+ contrast = contrast*contrast;
4237+
4238+ for (y=0; y<src->sy; ++y) {
4239+ for (x=0; x<src->sx; ++x) {
4240+ pxl = f(src, x, y);
4241+
4242+ r = gdImageRed(src, pxl);
4243+ g = gdImageGreen(src, pxl);
4244+ b = gdImageBlue(src, pxl);
4245+ a = gdImageAlpha(src, pxl);
4246+
4247+ rf = (double)r/255.0;
4248+ rf = rf-0.5;
4249+ rf = rf*contrast;
4250+ rf = rf+0.5;
4251+ rf = rf*255.0;
4252+
4253+ bf = (double)b/255.0;
4254+ bf = bf-0.5;
4255+ bf = bf*contrast;
4256+ bf = bf+0.5;
4257+ bf = bf*255.0;
4258+
4259+ gf = (double)g/255.0;
4260+ gf = gf-0.5;
4261+ gf = gf*contrast;
4262+ gf = gf+0.5;
4263+ gf = gf*255.0;
4264+
4265+ rf = (rf > 255.0)? 255.0 : ((rf < 0.0)? 0.0:rf);
4266+ gf = (gf > 255.0)? 255.0 : ((gf < 0.0)? 0.0:gf);
4267+ bf = (bf > 255.0)? 255.0 : ((bf < 0.0)? 0.0:bf);
4268+
4269+ new_pxl = gdImageColorAllocateAlpha(src, (int)rf, (int)gf, (int)bf, a);
4270+ if (new_pxl == -1) {
4271+ new_pxl = gdImageColorClosestAlpha(src, (int)rf, (int)gf, (int)bf, a);
4272+ }
4273+ gdImageSetPixel (src, x, y, new_pxl);
4274+ }
4275+ }
4276+ return 1;
4277+}
4278+
4279+
4280+int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha)
4281+{
4282+ int x, y;
4283+ int new_pxl, pxl;
4284+ typedef int (*FuncPtr)(gdImagePtr, int, int);
4285+ FuncPtr f;
4286+
4287+ if (src == NULL) {
4288+ return 0;
4289+ }
4290+
4291+ f = GET_PIXEL_FUNCTION(src);
4292+
4293+ for (y=0; y<src->sy; ++y) {
4294+ for (x=0; x<src->sx; ++x) {
4295+ int r,g,b,a;
4296+
4297+ pxl = f(src, x, y);
4298+ r = gdImageRed(src, pxl);
4299+ g = gdImageGreen(src, pxl);
4300+ b = gdImageBlue(src, pxl);
4301+ a = gdImageAlpha(src, pxl);
4302+
4303+ r = r + red;
4304+ g = g + green;
4305+ b = b + blue;
4306+ a = a + alpha;
4307+
4308+ r = (r > 255)? 255 : ((r < 0)? 0 : r);
4309+ g = (g > 255)? 255 : ((g < 0)? 0 : g);
4310+ b = (b > 255)? 255 : ((b < 0)? 0 : b);
4311+ a = (a > 127)? 127 : ((a < 0)? 0 : a);
4312+
4313+ new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a);
4314+ if (new_pxl == -1) {
4315+ new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
4316+ }
4317+ gdImageSetPixel (src, x, y, new_pxl);
4318+ }
4319+ }
4320+ return 1;
4321+}
4322+
4323+int gdImageConvolution(gdImagePtr src, float filter[3][3], float filter_div, float offset)
4324+{
4325+ int x, y, i, j, new_a;
4326+ float new_r, new_g, new_b;
4327+ int new_pxl, pxl=0;
4328+ gdImagePtr srcback;
4329+ typedef int (*FuncPtr)(gdImagePtr, int, int);
4330+ FuncPtr f;
4331+
4332+ if (src==NULL) {
4333+ return 0;
4334+ }
4335+
4336+ /* We need the orinal image with each safe neoghb. pixel */
4337+ srcback = gdImageCreateTrueColor (src->sx, src->sy);
4338+ gdImageCopy(srcback, src,0,0,0,0,src->sx,src->sy);
4339+
4340+ if (srcback==NULL) {
4341+ return 0;
4342+ }
4343+
4344+ f = GET_PIXEL_FUNCTION(src);
4345+
4346+ for ( y=0; y<src->sy; y++) {
4347+ for(x=0; x<src->sx; x++) {
4348+ new_r = new_g = new_b = 0;
4349+ new_a = gdImageAlpha(srcback, pxl);
4350+
4351+ for (j=0; j<3; j++) {
4352+ int yv = MIN(MAX(y - 1 + j, 0), src->sy - 1);
4353+ for (i=0; i<3; i++) {
4354+ pxl = f(srcback, MIN(MAX(x - 1 + i, 0), src->sx - 1), yv);
4355+ new_r += (float)gdImageRed(srcback, pxl) * filter[j][i];
4356+ new_g += (float)gdImageGreen(srcback, pxl) * filter[j][i];
4357+ new_b += (float)gdImageBlue(srcback, pxl) * filter[j][i];
4358+ }
4359+ }
4360+
4361+ new_r = (new_r/filter_div)+offset;
4362+ new_g = (new_g/filter_div)+offset;
4363+ new_b = (new_b/filter_div)+offset;
4364+
4365+ new_r = (new_r > 255.0f)? 255.0f : ((new_r < 0.0f)? 0.0f:new_r);
4366+ new_g = (new_g > 255.0f)? 255.0f : ((new_g < 0.0f)? 0.0f:new_g);
4367+ new_b = (new_b > 255.0f)? 255.0f : ((new_b < 0.0f)? 0.0f:new_b);
4368+
4369+ new_pxl = gdImageColorAllocateAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
4370+ if (new_pxl == -1) {
4371+ new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
4372+ }
4373+ gdImageSetPixel (src, x, y, new_pxl);
4374+ }
4375+ }
4376+ gdImageDestroy(srcback);
4377+ return 1;
4378+}
4379+
4380+int gdImageSelectiveBlur( gdImagePtr src)
4381+{
4382+ int x, y, i, j;
4383+ float new_r, new_g, new_b;
4384+ int new_pxl, cpxl, pxl, new_a=0;
4385+ float flt_r [3][3];
4386+ float flt_g [3][3];
4387+ float flt_b [3][3];
4388+ float flt_r_sum, flt_g_sum, flt_b_sum;
4389+
4390+ gdImagePtr srcback;
4391+ typedef int (*FuncPtr)(gdImagePtr, int, int);
4392+ FuncPtr f;
4393+
4394+ if (src==NULL) {
4395+ return 0;
4396+ }
4397+
4398+ /* We need the orinal image with each safe neoghb. pixel */
4399+ srcback = gdImageCreateTrueColor (src->sx, src->sy);
4400+ gdImageCopy(srcback, src,0,0,0,0,src->sx,src->sy);
4401+
4402+ if (srcback==NULL) {
4403+ return 0;
4404+ }
4405+
4406+ f = GET_PIXEL_FUNCTION(src);
4407+
4408+ for(y = 0; y<src->sy; y++) {
4409+ for (x=0; x<src->sx; x++) {
4410+ flt_r_sum = flt_g_sum = flt_b_sum = 0.0;
4411+ cpxl = f(src, x, y);
4412+
4413+ for (j=0; j<3; j++) {
4414+ for (i=0; i<3; i++) {
4415+ if ((j == 1) && (i == 1)) {
4416+ flt_r[1][1] = flt_g[1][1] = flt_b[1][1] = 0.5;
4417+ } else {
4418+ pxl = f(src, x-(3>>1)+i, y-(3>>1)+j);
4419+ new_a = gdImageAlpha(srcback, pxl);
4420+
4421+ new_r = ((float)gdImageRed(srcback, cpxl)) - ((float)gdImageRed (srcback, pxl));
4422+
4423+ if (new_r < 0.0f) {
4424+ new_r = -new_r;
4425+ }
4426+ if (new_r != 0) {
4427+ flt_r[j][i] = 1.0f/new_r;
4428+ } else {
4429+ flt_r[j][i] = 1.0f;
4430+ }
4431+
4432+ new_g = ((float)gdImageGreen(srcback, cpxl)) - ((float)gdImageGreen(srcback, pxl));
4433+
4434+ if (new_g < 0.0f) {
4435+ new_g = -new_g;
4436+ }
4437+ if (new_g != 0) {
4438+ flt_g[j][i] = 1.0f/new_g;
4439+ } else {
4440+ flt_g[j][i] = 1.0f;
4441+ }
4442+
4443+ new_b = ((float)gdImageBlue(srcback, cpxl)) - ((float)gdImageBlue(srcback, pxl));
4444+
4445+ if (new_b < 0.0f) {
4446+ new_b = -new_b;
4447+ }
4448+ if (new_b != 0) {
4449+ flt_b[j][i] = 1.0f/new_b;
4450+ } else {
4451+ flt_b[j][i] = 1.0f;
4452+ }
4453+ }
4454+
4455+ flt_r_sum += flt_r[j][i];
4456+ flt_g_sum += flt_g[j][i];
4457+ flt_b_sum += flt_b [j][i];
4458+ }
4459+ }
4460+
4461+ for (j=0; j<3; j++) {
4462+ for (i=0; i<3; i++) {
4463+ if (flt_r_sum != 0.0) {
4464+ flt_r[j][i] /= flt_r_sum;
4465+ }
4466+ if (flt_g_sum != 0.0) {
4467+ flt_g[j][i] /= flt_g_sum;
4468+ }
4469+ if (flt_b_sum != 0.0) {
4470+ flt_b [j][i] /= flt_b_sum;
4471+ }
4472+ }
4473+ }
4474+
4475+ new_r = new_g = new_b = 0.0;
4476+
4477+ for (j=0; j<3; j++) {
4478+ for (i=0; i<3; i++) {
4479+ pxl = f(src, x-(3>>1)+i, y-(3>>1)+j);
4480+ new_r += (float)gdImageRed(srcback, pxl) * flt_r[j][i];
4481+ new_g += (float)gdImageGreen(srcback, pxl) * flt_g[j][i];
4482+ new_b += (float)gdImageBlue(srcback, pxl) * flt_b[j][i];
4483+ }
4484+ }
4485+
4486+ new_r = (new_r > 255.0f)? 255.0f : ((new_r < 0.0f)? 0.0f:new_r);
4487+ new_g = (new_g > 255.0f)? 255.0f : ((new_g < 0.0f)? 0.0f:new_g);
4488+ new_b = (new_b > 255.0f)? 255.0f : ((new_b < 0.0f)? 0.0f:new_b);
4489+ new_pxl = gdImageColorAllocateAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
4490+ if (new_pxl == -1) {
4491+ new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
4492+ }
4493+ gdImageSetPixel (src, x, y, new_pxl);
4494+ }
4495+ }
4496+ gdImageDestroy(srcback);
4497+ return 1;
4498+}
4499+
4500+int gdImageEdgeDetectQuick(gdImagePtr src)
4501+{
4502+ float filter[3][3] = {{-1.0,0.0,-1.0},
4503+ {0.0,4.0,0.0},
4504+ {-1.0,0.0,-1.0}};
4505+
4506+ return gdImageConvolution(src, filter, 1, 127);
4507+}
4508+
4509+int gdImageGaussianBlur(gdImagePtr im)
4510+{
4511+ float filter[3][3] = {{1.0,2.0,1.0},
4512+ {2.0,4.0,2.0},
4513+ {1.0,2.0,1.0}};
4514+
4515+ return gdImageConvolution(im, filter, 16, 0);
4516+}
4517+
4518+int gdImageEmboss(gdImagePtr im)
4519+{
4520+/*
4521+ float filter[3][3] = {{1.0,1.0,1.0},
4522+ {0.0,0.0,0.0},
4523+ {-1.0,-1.0,-1.0}};
4524+*/
4525+ float filter[3][3] = {{ 1.5, 0.0, 0.0},
4526+ { 0.0, 0.0, 0.0},
4527+ { 0.0, 0.0,-1.5}};
4528+
4529+ return gdImageConvolution(im, filter, 1, 127);
4530+}
4531+
4532+int gdImageMeanRemoval(gdImagePtr im)
4533+{
4534+ float filter[3][3] = {{-1.0,-1.0,-1.0},
4535+ {-1.0,9.0,-1.0},
4536+ {-1.0,-1.0,-1.0}};
4537+
4538+ return gdImageConvolution(im, filter, 1, 0);
4539+}
4540+
4541+int gdImageSmooth(gdImagePtr im, float weight)
4542+{
4543+ float filter[3][3] = {{1.0,1.0,1.0},
4544+ {1.0,0.0,1.0},
4545+ {1.0,1.0,1.0}};
4546+
4547+ filter[1][1] = weight;
4548+
4549+ return gdImageConvolution(im, filter, weight+8, 0);
4550+}
4551+/* End filters function */
4552diff -urN php-4.4.8.org/ext/gd/libgd/gdcache.c php-4.4.8/ext/gd/libgd/gdcache.c
4553--- php-4.4.8.org/ext/gd/libgd/gdcache.c 2003-04-05 19:24:16.000000000 +0200
4554+++ php-4.4.8/ext/gd/libgd/gdcache.c 2003-12-28 21:11:08.000000000 +0100
4555@@ -11,11 +11,11 @@
4556
4557 #ifdef NEED_CACHE
4558
4559-/*
4560+/*
4561 * gdcache.c
4562 *
4563- * Caches of pointers to user structs in which the least-recently-used
4564- * element is replaced in the event of a cache miss after the cache has
4565+ * Caches of pointers to user structs in which the least-recently-used
4566+ * element is replaced in the event of a cache miss after the cache has
4567 * reached a given size.
4568 *
4569 * John Ellson (ellson@graphviz.org) Oct 31, 1997
4570@@ -30,17 +30,17 @@
4571 * The head structure has a pointer to the most-recently-used
4572 * element, and elements are moved to this position in the list each
4573 * time they are used. The head also contains pointers to three
4574- * user defined functions:
4575- * - a function to test if a cached userdata matches some keydata
4576- * - a function to provide a new userdata struct to the cache
4577+ * user defined functions:
4578+ * - a function to test if a cached userdata matches some keydata
4579+ * - a function to provide a new userdata struct to the cache
4580 * if there has been a cache miss.
4581 * - a function to release a userdata struct when it is
4582 * no longer being managed by the cache
4583 *
4584 * In the event of a cache miss the cache is allowed to grow up to
4585 * a specified maximum size. After the maximum size is reached then
4586- * the least-recently-used element is discarded to make room for the
4587- * new. The most-recently-returned value is always left at the
4588+ * the least-recently-used element is discarded to make room for the
4589+ * new. The most-recently-returned value is always left at the
4590 * beginning of the list after retrieval.
4591 *
4592 * In the current implementation the cache is traversed by a linear
4593diff -urN php-4.4.8.org/ext/gd/libgd/gdcache.h php-4.4.8/ext/gd/libgd/gdcache.h
4594--- php-4.4.8.org/ext/gd/libgd/gdcache.h 2003-04-05 19:24:16.000000000 +0200
4595+++ php-4.4.8/ext/gd/libgd/gdcache.h 2003-12-28 21:11:08.000000000 +0100
4596@@ -1,8 +1,8 @@
4597-/*
4598+/*
4599 * gdcache.h
4600 *
4601- * Caches of pointers to user structs in which the least-recently-used
4602- * element is replaced in the event of a cache miss after the cache has
4603+ * Caches of pointers to user structs in which the least-recently-used
4604+ * element is replaced in the event of a cache miss after the cache has
4605 * reached a given size.
4606 *
4607 * John Ellson (ellson@graphviz.org) Oct 31, 1997
4608@@ -17,17 +17,17 @@
4609 * The head structure has a pointer to the most-recently-used
4610 * element, and elements are moved to this position in the list each
4611 * time they are used. The head also contains pointers to three
4612- * user defined functions:
4613- * - a function to test if a cached userdata matches some keydata
4614- * - a function to provide a new userdata struct to the cache
4615+ * user defined functions:
4616+ * - a function to test if a cached userdata matches some keydata
4617+ * - a function to provide a new userdata struct to the cache
4618 * if there has been a cache miss.
4619 * - a function to release a userdata struct when it is
4620 * no longer being managed by the cache
4621 *
4622 * In the event of a cache miss the cache is allowed to grow up to
4623 * a specified maximum size. After the maximum size is reached then
4624- * the least-recently-used element is discarded to make room for the
4625- * new. The most-recently-returned value is always left at the
4626+ * the least-recently-used element is discarded to make room for the
4627+ * new. The most-recently-returned value is always left at the
4628 * beginning of the list after retrieval.
4629 *
4630 * In the current implementation the cache is traversed by a linear
4631diff -urN php-4.4.8.org/ext/gd/libgd/gdfontg.c php-4.4.8/ext/gd/libgd/gdfontg.c
4632--- php-4.4.8.org/ext/gd/libgd/gdfontg.c 2004-03-29 20:21:00.000000000 +0200
4633+++ php-4.4.8/ext/gd/libgd/gdfontg.c 2006-09-16 21:07:45.000000000 +0200
4634@@ -13,7 +13,7 @@
4635
4636 #include "gdfontg.h"
4637
4638-char gdFontGiantData[] =
4639+static const char gdFontGiantData[] =
4640 {
4641 /* Char 0 */
4642 0, 0, 0, 0, 0, 0, 0, 0, 0,
4643@@ -4376,7 +4376,7 @@
4644 0,
4645 9,
4646 15,
4647- gdFontGiantData
4648+ (char*)gdFontGiantData
4649 };
4650
4651 gdFontPtr gdFontGiant = &gdFontGiantRep;
4652diff -urN php-4.4.8.org/ext/gd/libgd/gdfontl.c php-4.4.8/ext/gd/libgd/gdfontl.c
4653--- php-4.4.8.org/ext/gd/libgd/gdfontl.c 2004-03-29 20:21:00.000000000 +0200
4654+++ php-4.4.8/ext/gd/libgd/gdfontl.c 2006-09-16 21:07:45.000000000 +0200
4655@@ -14,7 +14,7 @@
4656
4657 #include "gdfontl.h"
4658
4659-char gdFontLargeData[] =
4660+static const char gdFontLargeData[] =
4661 {
4662 /* Char 0 */
4663 0, 0, 0, 0, 0, 0, 0, 0,
4664@@ -4633,7 +4633,7 @@
4665 0,
4666 8,
4667 16,
4668- gdFontLargeData
4669+ (char*)gdFontLargeData
4670 };
4671
4672 gdFontPtr gdFontLarge = &gdFontLargeRep;
4673diff -urN php-4.4.8.org/ext/gd/libgd/gdfontmb.c php-4.4.8/ext/gd/libgd/gdfontmb.c
4674--- php-4.4.8.org/ext/gd/libgd/gdfontmb.c 2004-03-29 20:21:00.000000000 +0200
4675+++ php-4.4.8/ext/gd/libgd/gdfontmb.c 2006-09-16 21:07:46.000000000 +0200
4676@@ -12,7 +12,7 @@
4677
4678 #include "gdfontmb.h"
4679
4680-char gdFontMediumBoldData[] =
4681+static const char gdFontMediumBoldData[] =
4682 {
4683 /* Char 0 */
4684 0, 0, 0, 0, 0, 0, 0,
4685@@ -3863,7 +3863,7 @@
4686 0,
4687 7,
4688 13,
4689- gdFontMediumBoldData
4690+ (char*)gdFontMediumBoldData
4691 };
4692
4693 gdFontPtr gdFontMediumBold = &gdFontMediumBoldRep;
4694diff -urN php-4.4.8.org/ext/gd/libgd/gdfonts.c php-4.4.8/ext/gd/libgd/gdfonts.c
4695--- php-4.4.8.org/ext/gd/libgd/gdfonts.c 2004-03-29 20:21:00.000000000 +0200
4696+++ php-4.4.8/ext/gd/libgd/gdfonts.c 2006-09-16 21:07:46.000000000 +0200
4697@@ -12,7 +12,7 @@
4698
4699 #include "gdfonts.h"
4700
4701-char gdFontSmallData[] =
4702+static const char gdFontSmallData[] =
4703 {
4704 /* Char 0 */
4705 0, 0, 0, 0, 0, 0,
4706@@ -3863,7 +3863,7 @@
4707 0,
4708 6,
4709 13,
4710- gdFontSmallData
4711+ (char*)gdFontSmallData
4712 };
4713
4714 gdFontPtr gdFontSmall = &gdFontSmallRep;
4715diff -urN php-4.4.8.org/ext/gd/libgd/gdfontt.c php-4.4.8/ext/gd/libgd/gdfontt.c
4716--- php-4.4.8.org/ext/gd/libgd/gdfontt.c 2004-03-29 20:21:00.000000000 +0200
4717+++ php-4.4.8/ext/gd/libgd/gdfontt.c 2006-09-16 21:07:46.000000000 +0200
4718@@ -13,7 +13,7 @@
4719
4720 #include "gdfontt.h"
4721
4722-char gdFontTinyData[] =
4723+static const char gdFontTinyData[] =
4724 {
4725 /* Char 0 */
4726 0, 0, 0, 0, 0,
4727@@ -2584,7 +2584,7 @@
4728 0,
4729 5,
4730 8,
4731- gdFontTinyData
4732+ (char*)gdFontTinyData
4733 };
4734
4735 gdFontPtr gdFontTiny = &gdFontTinyRep;
4736diff -urN php-4.4.8.org/ext/gd/libgd/gdft.c php-4.4.8/ext/gd/libgd/gdft.c
4737--- php-4.4.8.org/ext/gd/libgd/gdft.c 2007-03-10 13:51:07.000000000 +0100
4738+++ php-4.4.8/ext/gd/libgd/gdft.c 2007-04-23 17:17:47.000000000 +0200
4739@@ -16,7 +16,9 @@
4740 #include <unistd.h>
4741 #else
4742 #include <io.h>
4743-#define R_OK 04 /* Needed in Windows */
4744+#ifndef R_OK
4745+# define R_OK 04 /* Needed in Windows */
4746+#endif
4747 #endif
4748
4749 #ifdef WIN32
4750@@ -37,9 +39,8 @@
4751 gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist,
4752 double ptsize, double angle, int x, int y, char *string)
4753 {
4754- /* 2.0.6: valid return */
4755- return gdImageStringFT (im, brect, fg, fontlist, ptsize,
4756- angle, x, y, string);
4757+ /* 2.0.6: valid return */
4758+ return gdImageStringFT (im, brect, fg, fontlist, ptsize, angle, x, y, string);
4759 }
4760
4761 #ifndef HAVE_LIBFREETYPE
4762@@ -48,14 +49,14 @@
4763 double ptsize, double angle, int x, int y, char *string,
4764 gdFTStringExtraPtr strex)
4765 {
4766- return "libgd was not built with FreeType font support\n";
4767+ return "libgd was not built with FreeType font support\n";
4768 }
4769
4770 char *
4771 gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
4772 double ptsize, double angle, int x, int y, char *string)
4773 {
4774- return "libgd was not built with FreeType font support\n";
4775+ return "libgd was not built with FreeType font support\n";
4776 }
4777 #else
4778
4779@@ -71,8 +72,8 @@
4780 #define TWEENCOLORCACHESIZE 32
4781
4782 /*
4783- * Line separation as a factor of font height.
4784- * No space between if LINESPACE = 1.00
4785+ * Line separation as a factor of font height.
4786+ * No space between if LINESPACE = 1.00
4787 * Line separation will be rounded up to next pixel row.
4788 */
4789 #define LINESPACE 1.05
4790@@ -115,40 +116,35 @@
4791
4792 typedef struct
4793 {
4794- char *fontlist; /* key */
4795- FT_Library *library;
4796- FT_Face face;
4797- FT_Bool have_char_map_unicode, have_char_map_big5, have_char_map_sjis,
4798- have_char_map_apple_roman;
4799- gdCache_head_t *glyphCache;
4800-}
4801-font_t;
4802+ char *fontlist; /* key */
4803+ FT_Library *library;
4804+ FT_Face face;
4805+ FT_Bool have_char_map_unicode, have_char_map_big5, have_char_map_sjis, have_char_map_apple_roman;
4806+ gdCache_head_t *glyphCache;
4807+} font_t;
4808
4809 typedef struct
4810- {
4811- char *fontlist; /* key */
4812- FT_Library *library;
4813- }
4814-fontkey_t;
4815+{
4816+ char *fontlist; /* key */
4817+ FT_Library *library;
4818+} fontkey_t;
4819
4820 typedef struct
4821- {
4822- int pixel; /* key */
4823- int bgcolor; /* key */
4824- int fgcolor; /* key *//* -ve means no antialias */
4825- gdImagePtr im; /* key */
4826- int tweencolor;
4827- }
4828-tweencolor_t;
4829+{
4830+ int pixel; /* key */
4831+ int bgcolor; /* key */
4832+ int fgcolor; /* key *//* -ve means no antialias */
4833+ gdImagePtr im; /* key */
4834+ int tweencolor;
4835+} tweencolor_t;
4836
4837 typedef struct
4838- {
4839- int pixel; /* key */
4840- int bgcolor; /* key */
4841- int fgcolor; /* key *//* -ve means no antialias */
4842- gdImagePtr im; /* key */
4843- }
4844-tweencolorkey_t;
4845+{
4846+ int pixel; /* key */
4847+ int bgcolor; /* key */
4848+ int fgcolor; /* key *//* -ve means no antialias */
4849+ gdImagePtr im; /* key */
4850+} tweencolorkey_t;
4851
4852 /********************************************************************
4853 * gdTcl_UtfToUniChar is borrowed from Tcl ...
4854@@ -208,160 +204,141 @@
4855
4856 #define Tcl_UniChar int
4857 #define TCL_UTF_MAX 3
4858-static int
4859-gdTcl_UtfToUniChar (char *str, Tcl_UniChar * chPtr)
4860+static int gdTcl_UtfToUniChar (char *str, Tcl_UniChar * chPtr)
4861 /* str is the UTF8 next character pointer */
4862 /* chPtr is the int for the result */
4863 {
4864- int byte;
4865+ int byte;
4866+
4867+ /* HTML4.0 entities in decimal form, e.g. &#197; */
4868+ byte = *((unsigned char *) str);
4869+ if (byte == '&') {
4870+ int i, n = 0;
4871+
4872+ byte = *((unsigned char *) (str + 1));
4873+ if (byte == '#') {
4874+ byte = *((unsigned char *) (str + 2));
4875+ if (byte == 'x' || byte == 'X') {
4876+ for (i = 3; i < 8; i++) {
4877+ byte = *((unsigned char *) (str + i));
4878+ if (byte >= 'A' && byte <= 'F')
4879+ byte = byte - 'A' + 10;
4880+ else if (byte >= 'a' && byte <= 'f')
4881+ byte = byte - 'a' + 10;
4882+ else if (byte >= '0' && byte <= '9')
4883+ byte = byte - '0';
4884+ else
4885+ break;
4886+ n = (n * 16) + byte;
4887+ }
4888+ } else {
4889+ for (i = 2; i < 8; i++) {
4890+ byte = *((unsigned char *) (str + i));
4891+ if (byte >= '0' && byte <= '9') {
4892+ n = (n * 10) + (byte - '0');
4893+ } else {
4894+ break;
4895+ }
4896+ }
4897+ }
4898+ if (byte == ';') {
4899+ *chPtr = (Tcl_UniChar) n;
4900+ return ++i;
4901+ }
4902+ }
4903+ }
4904
4905- /* HTML4.0 entities in decimal form, e.g. &#197; */
4906- byte = *((unsigned char *) str);
4907- if (byte == '&')
4908- {
4909- int i, n = 0;
4910-
4911- byte = *((unsigned char *) (str + 1));
4912- if (byte == '#')
4913- {
4914- for (i = 2; i < 8; i++)
4915- {
4916- byte = *((unsigned char *) (str + i));
4917- if (byte >= '0' && byte <= '9')
4918- {
4919- n = (n * 10) + (byte - '0');
4920- }
4921- else
4922- break;
4923- }
4924- if (byte == ';')
4925- {
4926- *chPtr = (Tcl_UniChar) n;
4927- return ++i;
4928- }
4929- }
4930- }
4931-
4932- /*
4933- * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones.
4934- */
4935+ /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */
4936
4937- byte = *((unsigned char *) str);
4938+ byte = *((unsigned char *) str);
4939 #ifdef JISX0208
4940- if (0xA1 <= byte && byte <= 0xFE)
4941- {
4942- int ku, ten;
4943-
4944- ku = (byte & 0x7F) - 0x20;
4945- ten = (str[1] & 0x7F) - 0x20;
4946- if ((ku < 1 || ku > 92) || (ten < 1 || ten > 94))
4947- {
4948- *chPtr = (Tcl_UniChar) byte;
4949- return 1;
4950- }
4951-
4952- *chPtr = (Tcl_UniChar) UnicodeTbl[ku - 1][ten - 1];
4953- return 2;
4954- }
4955- else
4956+ if (0xA1 <= byte && byte <= 0xFE) {
4957+ int ku, ten;
4958+
4959+ ku = (byte & 0x7F) - 0x20;
4960+ ten = (str[1] & 0x7F) - 0x20;
4961+ if ((ku < 1 || ku > 92) || (ten < 1 || ten > 94)) {
4962+ *chPtr = (Tcl_UniChar) byte;
4963+ return 1;
4964+ }
4965+
4966+ *chPtr = (Tcl_UniChar) UnicodeTbl[ku - 1][ten - 1];
4967+ return 2;
4968+ } else
4969 #endif /* JISX0208 */
4970- if (byte < 0xC0)
4971- {
4972- /*
4973- * Handles properly formed UTF-8 characters between
4974- * 0x01 and 0x7F. Also treats \0 and naked trail
4975- * bytes 0x80 to 0xBF as valid characters representing
4976- * themselves.
4977- */
4978-
4979- *chPtr = (Tcl_UniChar) byte;
4980- return 1;
4981- }
4982- else if (byte < 0xE0)
4983- {
4984- if ((str[1] & 0xC0) == 0x80)
4985- {
4986- /*
4987- * Two-byte-character lead-byte followed
4988- * by a trail-byte.
4989- */
4990-
4991- *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6)
4992- | (str[1] & 0x3F));
4993- return 2;
4994- }
4995- /*
4996- * A two-byte-character lead-byte not followed by trail-byte
4997- * represents itself.
4998- */
4999-
5000- *chPtr = (Tcl_UniChar) byte;
5001- return 1;
5002- }
5003- else if (byte < 0xF0)
5004- {
5005- if (((str[1] & 0xC0) == 0x80) && ((str[2] & 0xC0) == 0x80))
5006- {
5007- /*
5008- * Three-byte-character lead byte followed by
5009- * two trail bytes.
5010- */
5011-
5012- *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12)
5013- | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F));
5014- return 3;
5015- }
5016- /*
5017- * A three-byte-character lead-byte not followed by
5018- * two trail-bytes represents itself.
5019- */
5020-
5021- *chPtr = (Tcl_UniChar) byte;
5022- return 1;
5023- }
5024+ if (byte < 0xC0) {
5025+ /* Handles properly formed UTF-8 characters between
5026+ * 0x01 and 0x7F. Also treats \0 and naked trail
5027+ * bytes 0x80 to 0xBF as valid characters representing
5028+ * themselves.
5029+ */
5030+
5031+ *chPtr = (Tcl_UniChar) byte;
5032+ return 1;
5033+ } else if (byte < 0xE0) {
5034+ if ((str[1] & 0xC0) == 0x80) {
5035+ /* Two-byte-character lead-byte followed by a trail-byte. */
5036+
5037+ *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (str[1] & 0x3F));
5038+ return 2;
5039+ }
5040+ /*
5041+ * A two-byte-character lead-byte not followed by trail-byte
5042+ * represents itself.
5043+ */
5044+
5045+ *chPtr = (Tcl_UniChar) byte;
5046+ return 1;
5047+ } else if (byte < 0xF0) {
5048+ if (((str[1] & 0xC0) == 0x80) && ((str[2] & 0xC0) == 0x80)) {
5049+ /* Three-byte-character lead byte followed by two trail bytes. */
5050+
5051+ *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F));
5052+ return 3;
5053+ }
5054+ /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */
5055+
5056+ *chPtr = (Tcl_UniChar) byte;
5057+ return 1;
5058+ }
5059 #if TCL_UTF_MAX > 3
5060- else
5061- {
5062- int ch, total, trail;
5063-
5064- total = totalBytes[byte];
5065- trail = total - 1;
5066- if (trail > 0)
5067- {
5068- ch = byte & (0x3F >> trail);
5069- do
5070- {
5071- str++;
5072- if ((*str & 0xC0) != 0x80)
5073- {
5074- *chPtr = byte;
5075- return 1;
5076- }
5077- ch <<= 6;
5078- ch |= (*str & 0x3F);
5079- trail--;
5080- }
5081- while (trail > 0);
5082- *chPtr = ch;
5083- return total;
5084+ else {
5085+ int ch, total, trail;
5086+
5087+ total = totalBytes[byte];
5088+ trail = total - 1;
5089+
5090+ if (trail > 0) {
5091+ ch = byte & (0x3F >> trail);
5092+ do {
5093+ str++;
5094+ if ((*str & 0xC0) != 0x80) {
5095+ *chPtr = byte;
5096+ return 1;
5097+ }
5098+ ch <<= 6;
5099+ ch |= (*str & 0x3F);
5100+ trail--;
5101+ } while (trail > 0);
5102+ *chPtr = ch;
5103+ return total;
5104+ }
5105 }
5106- }
5107 #endif
5108
5109- *chPtr = (Tcl_UniChar) byte;
5110- return 1;
5111+ *chPtr = (Tcl_UniChar) byte;
5112+ return 1;
5113 }
5114
5115 /********************************************************************/
5116 /* font cache functions */
5117
5118-static int
5119-fontTest (void *element, void *key)
5120+static int fontTest (void *element, void *key)
5121 {
5122- font_t *a = (font_t *) element;
5123- fontkey_t *b = (fontkey_t *) key;
5124+ font_t *a = (font_t *) element;
5125+ fontkey_t *b = (fontkey_t *) key;
5126
5127- return (strcmp (a->fontlist, b->fontlist) == 0);
5128+ return (strcmp (a->fontlist, b->fontlist) == 0);
5129 }
5130
5131 static void *fontFetch (char **error, void *key)
5132@@ -389,7 +366,7 @@
5133 fontsearchpath = getenv ("GDFONTPATH");
5134 if (!fontsearchpath) {
5135 fontsearchpath = DEFAULT_FONTPATH;
5136- }
5137+ }
5138 fontlist = gdEstrdup(a->fontlist);
5139
5140 /*
5141@@ -399,8 +376,12 @@
5142 /* make a fresh copy each time - strtok corrupts it. */
5143 path = gdEstrdup (fontsearchpath);
5144
5145- /* if name is an absolute filename then test directly */
5146+ /* if name is an absolute filename then test directly */
5147+#ifdef NETWARE
5148+ if (*name == '/' || (name[0] != 0 && strstr(name, ":/"))) {
5149+#else
5150 if (*name == '/' || (name[0] != 0 && name[1] == ':' && (name[2] == '/' || name[2] == '\\'))) {
5151+#endif
5152 snprintf(fullname, sizeof(fullname) - 1, "%s", name);
5153 if (access(fullname, R_OK) == 0) {
5154 font_found++;
5155@@ -437,15 +418,15 @@
5156 path = NULL;
5157 if (font_found) {
5158 break;
5159- }
5160+ }
5161 }
5162-
5163+
5164 if (path) {
5165 gdFree(path);
5166 }
5167-
5168+
5169 gdFree(fontlist);
5170-
5171+
5172 if (!font_found) {
5173 gdPFree(a->fontlist);
5174 gdPFree(a);
5175@@ -556,257 +537,234 @@
5176 * does the work so that text can be alpha blended across a complex
5177 * background (TBB; and for real in 2.0.2).
5178 */
5179-static void *
5180-tweenColorFetch (char **error, void *key)
5181+static void * tweenColorFetch (char **error, void *key)
5182 {
5183- tweencolor_t *a;
5184- tweencolorkey_t *b = (tweencolorkey_t *) key;
5185- int pixel, npixel, bg, fg;
5186- gdImagePtr im;
5187-
5188- a = (tweencolor_t *) gdMalloc (sizeof (tweencolor_t));
5189- pixel = a->pixel = b->pixel;
5190- bg = a->bgcolor = b->bgcolor;
5191- fg = a->fgcolor = b->fgcolor;
5192- im = b->im;
5193-
5194- /* if fg is specified by a negative color idx, then don't antialias */
5195- if (fg < 0)
5196- {
5197- if ((pixel + pixel) >= NUMCOLORS)
5198- a->tweencolor = -fg;
5199- else
5200- a->tweencolor = bg;
5201- }
5202- else
5203- {
5204- npixel = NUMCOLORS - pixel;
5205- if (im->trueColor)
5206- {
5207- /* 2.0.1: use gdImageSetPixel to do the alpha blending work,
5208- or to just store the alpha level. All we have to do here
5209- is incorporate our knowledge of the percentage of this
5210- pixel that is really "lit" by pushing the alpha value
5211- up toward transparency in edge regions. */
5212- a->tweencolor = gdTrueColorAlpha (
5213- gdTrueColorGetRed (fg),
5214- gdTrueColorGetGreen (fg),
5215- gdTrueColorGetBlue (fg),
5216- gdAlphaMax - (gdTrueColorGetAlpha (fg) * pixel / NUMCOLORS));
5217- }
5218- else
5219- {
5220- a->tweencolor = gdImageColorResolve (im,
5221- (pixel * im->red[fg] + npixel * im->red[bg]) / NUMCOLORS,
5222- (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS,
5223- (pixel * im->blue[fg] + npixel * im->blue[bg]) / NUMCOLORS);
5224- }
5225- }
5226- return (void *) a;
5227+ tweencolor_t *a;
5228+ tweencolorkey_t *b = (tweencolorkey_t *) key;
5229+ int pixel, npixel, bg, fg;
5230+ gdImagePtr im;
5231+
5232+ a = (tweencolor_t *) gdMalloc (sizeof (tweencolor_t));
5233+ pixel = a->pixel = b->pixel;
5234+ bg = a->bgcolor = b->bgcolor;
5235+ fg = a->fgcolor = b->fgcolor;
5236+ im = a->im = b->im;
5237+
5238+ /* if fg is specified by a negative color idx, then don't antialias */
5239+ if (fg < 0) {
5240+ if ((pixel + pixel) >= NUMCOLORS) {
5241+ a->tweencolor = -fg;
5242+ } else {
5243+ a->tweencolor = bg;
5244+ }
5245+ } else {
5246+ npixel = NUMCOLORS - pixel;
5247+ if (im->trueColor) {
5248+ /* 2.0.1: use gdImageSetPixel to do the alpha blending work,
5249+ * or to just store the alpha level. All we have to do here
5250+ * is incorporate our knowledge of the percentage of this
5251+ * pixel that is really "lit" by pushing the alpha value
5252+ * up toward transparency in edge regions.
5253+ */
5254+ a->tweencolor = gdTrueColorAlpha(
5255+ gdTrueColorGetRed(fg),
5256+ gdTrueColorGetGreen(fg),
5257+ gdTrueColorGetBlue(fg),
5258+ gdAlphaMax - (gdTrueColorGetAlpha (fg) * pixel / NUMCOLORS));
5259+ } else {
5260+ a->tweencolor = gdImageColorResolve(im,
5261+ (pixel * im->red[fg] + npixel * im->red[bg]) / NUMCOLORS,
5262+ (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS,
5263+ (pixel * im->blue[fg] + npixel * im->blue[bg]) / NUMCOLORS);
5264+ }
5265+ }
5266+ return (void *) a;
5267 }
5268
5269-static void
5270-tweenColorRelease (void *element)
5271+static void tweenColorRelease (void *element)
5272 {
5273- gdFree ((char *) element);
5274+ gdFree((char *) element);
5275 }
5276
5277 /* draw_bitmap - transfers glyph bitmap to GD image */
5278-static char *
5279-gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
5280+static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
5281 {
5282- unsigned char *pixel = NULL;
5283- int *tpixel = NULL;
5284- int x, y, row, col, pc, pcr;
5285-
5286- tweencolor_t *tc_elem;
5287- tweencolorkey_t tc_key;
5288-
5289- /* copy to image, mapping colors */
5290- tc_key.fgcolor = fg;
5291- tc_key.im = im;
5292- /* Truecolor version; does not require the cache */
5293- if (im->trueColor)
5294- {
5295- for (row = 0; row < bitmap.rows; row++)
5296- {
5297- pc = row * bitmap.pitch;
5298- pcr = pc;
5299- y = pen_y + row;
5300- /* clip if out of bounds */
5301- /* 2.0.16: clipping rectangle, not image bounds */
5302- if ((y > im->cy2) || (y < im->cy1))
5303- continue;
5304- for (col = 0; col < bitmap.width; col++, pc++)
5305- {
5306- int level;
5307- if (bitmap.pixel_mode == ft_pixel_mode_grays)
5308- {
5309- /*
5310- * Scale to 128 levels of alpha for gd use.
5311- * alpha 0 is opacity, so be sure to invert at the end
5312- */
5313- level = (bitmap.buffer[pc] * gdAlphaMax /
5314- (bitmap.num_grays - 1));
5315- }
5316- else if (bitmap.pixel_mode == ft_pixel_mode_mono)
5317- {
5318- /* 2.0.5: mode_mono fix from Giuliano Pochini */
5319- level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07)))
5320- ? gdAlphaTransparent :
5321- gdAlphaOpaque;
5322- }
5323- else
5324- {
5325- return "Unsupported ft_pixel_mode";
5326- }
5327- if ((fg >= 0) && (im->trueColor)) {
5328- /* Consider alpha in the foreground color itself to be an
5329- upper bound on how opaque things get, when truecolor is
5330- available. Without truecolor this results in far too many
5331- color indexes. */
5332- level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax;
5333- }
5334- level = gdAlphaMax - level;
5335- x = pen_x + col;
5336- /* clip if out of bounds */
5337- /* 2.0.16: clip to clipping rectangle, Matt McNabb */
5338- if ((x > im->cx2) || (x < im->cx1))
5339- continue;
5340- /* get pixel location in gd buffer */
5341- tpixel = &im->tpixels[y][x];
5342- if (fg < 0) {
5343- if (level < (gdAlphaMax / 2)) {
5344- *tpixel = -fg;
5345- }
5346- } else {
5347- if (im->alphaBlendingFlag) {
5348- *tpixel = gdAlphaBlend(*tpixel, (level << 24) + (fg & 0xFFFFFF));
5349- } else {
5350- *tpixel = (level << 24) + (fg & 0xFFFFFF);
5351- }
5352- }
5353- }
5354- }
5355- return (char *) NULL;
5356- }
5357- /* Non-truecolor case, restored to its more or less original form */
5358- for (row = 0; row < bitmap.rows; row++)
5359- {
5360- int pcr;
5361- pc = row * bitmap.pitch;
5362- pcr = pc;
5363- if(bitmap.pixel_mode==ft_pixel_mode_mono)
5364- pc *= 8; /* pc is measured in bits for monochrome images */
5365-
5366- y = pen_y + row;
5367-
5368- /* clip if out of bounds */
5369- if (y >= im->sy || y < 0)
5370- continue;
5371-
5372- for (col = 0; col < bitmap.width; col++, pc++)
5373- {
5374- if (bitmap.pixel_mode == ft_pixel_mode_grays)
5375- {
5376- /*
5377- * Round to NUMCOLORS levels of antialiasing for
5378- * index color images since only 256 colors are
5379- * available.
5380- */
5381- tc_key.pixel = ((bitmap.buffer[pc] * NUMCOLORS)
5382- + bitmap.num_grays / 2)
5383- / (bitmap.num_grays - 1);
5384- }
5385- else if (bitmap.pixel_mode == ft_pixel_mode_mono)
5386- {
5387- tc_key.pixel = ((bitmap.buffer[pc / 8]
5388- << (pc % 8)) & 128) ? NUMCOLORS : 0;
5389- /* 2.0.5: mode_mono fix from Giuliano Pochini */
5390- tc_key.pixel = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07)))
5391- ? NUMCOLORS : 0;
5392- }
5393- else
5394- {
5395- return "Unsupported ft_pixel_mode";
5396- }
5397- if (tc_key.pixel > 0) /* if not background */
5398- {
5399- x = pen_x + col;
5400-
5401- /* clip if out of bounds */
5402- if (x >= im->sx || x < 0)
5403- continue;
5404- /* get pixel location in gd buffer */
5405- pixel = &im->pixels[y][x];
5406- if (tc_key.pixel == NUMCOLORS)
5407- {
5408- /* use fg color directly. gd 2.0.2: watch out for
5409- negative indexes (thanks to David Marwood). */
5410- *pixel = (fg < 0) ? -fg : fg;
5411- }
5412- else
5413- {
5414- /* find antialised color */
5415-
5416- tc_key.bgcolor = *pixel;
5417- gdMutexLock(gdFontCacheMutex);
5418- tc_elem = (tweencolor_t *) gdCacheGet (tc_cache, &tc_key);
5419- *pixel = tc_elem->tweencolor;
5420- gdMutexUnlock(gdFontCacheMutex);
5421+ unsigned char *pixel = NULL;
5422+ int *tpixel = NULL;
5423+ int x, y, row, col, pc, pcr;
5424+
5425+ tweencolor_t *tc_elem;
5426+ tweencolorkey_t tc_key;
5427+
5428+ /* copy to image, mapping colors */
5429+ tc_key.fgcolor = fg;
5430+ tc_key.im = im;
5431+ /* Truecolor version; does not require the cache */
5432+ if (im->trueColor) {
5433+ for (row = 0; row < bitmap.rows; row++) {
5434+ pc = row * bitmap.pitch;
5435+ pcr = pc;
5436+ y = pen_y + row;
5437+ /* clip if out of bounds */
5438+ /* 2.0.16: clipping rectangle, not image bounds */
5439+ if ((y > im->cy2) || (y < im->cy1)) {
5440+ continue;
5441+ }
5442+ for (col = 0; col < bitmap.width; col++, pc++) {
5443+ int level;
5444+ if (bitmap.pixel_mode == ft_pixel_mode_grays) {
5445+ /* Scale to 128 levels of alpha for gd use.
5446+ * alpha 0 is opacity, so be sure to invert at the end
5447+ */
5448+ level = (bitmap.buffer[pc] * gdAlphaMax / (bitmap.num_grays - 1));
5449+ } else if (bitmap.pixel_mode == ft_pixel_mode_mono) {
5450+ /* 2.0.5: mode_mono fix from Giuliano Pochini */
5451+ level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) ? gdAlphaTransparent : gdAlphaOpaque;
5452+ } else {
5453+ return "Unsupported ft_pixel_mode";
5454+ }
5455+ if ((fg >= 0) && (im->trueColor)) {
5456+ /* Consider alpha in the foreground color itself to be an
5457+ * upper bound on how opaque things get, when truecolor is
5458+ * available. Without truecolor this results in far too many
5459+ * color indexes.
5460+ */
5461+ level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax;
5462+ }
5463+ level = gdAlphaMax - level;
5464+ x = pen_x + col;
5465+ /* clip if out of bounds */
5466+ /* 2.0.16: clip to clipping rectangle, Matt McNabb */
5467+ if ((x > im->cx2) || (x < im->cx1)) {
5468+ continue;
5469+ }
5470+ /* get pixel location in gd buffer */
5471+ tpixel = &im->tpixels[y][x];
5472+ if (fg < 0) {
5473+ if (level < (gdAlphaMax / 2)) {
5474+ *tpixel = -fg;
5475+ }
5476+ } else {
5477+ if (im->alphaBlendingFlag) {
5478+ *tpixel = gdAlphaBlend(*tpixel, (level << 24) + (fg & 0xFFFFFF));
5479+ } else {
5480+ *tpixel = (level << 24) + (fg & 0xFFFFFF);
5481+ }
5482+ }
5483+ }
5484+ }
5485+ return (char *) NULL;
5486+ }
5487+ /* Non-truecolor case, restored to its more or less original form */
5488+ for (row = 0; row < bitmap.rows; row++) {
5489+ int pcr;
5490+ pc = row * bitmap.pitch;
5491+ pcr = pc;
5492+ if (bitmap.pixel_mode==ft_pixel_mode_mono) {
5493+ pc *= 8; /* pc is measured in bits for monochrome images */
5494+ }
5495+ y = pen_y + row;
5496+
5497+ /* clip if out of bounds */
5498+ if (y >= im->sy || y < 0) {
5499+ continue;
5500+ }
5501+
5502+ for (col = 0; col < bitmap.width; col++, pc++) {
5503+ if (bitmap.pixel_mode == ft_pixel_mode_grays) {
5504+ /*
5505+ * Round to NUMCOLORS levels of antialiasing for
5506+ * index color images since only 256 colors are
5507+ * available.
5508+ */
5509+ tc_key.pixel = ((bitmap.buffer[pc] * NUMCOLORS) + bitmap.num_grays / 2) / (bitmap.num_grays - 1);
5510+ } else if (bitmap.pixel_mode == ft_pixel_mode_mono) {
5511+ tc_key.pixel = ((bitmap.buffer[pc / 8] << (pc % 8)) & 128) ? NUMCOLORS : 0;
5512+ /* 2.0.5: mode_mono fix from Giuliano Pochini */
5513+ tc_key.pixel = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) ? NUMCOLORS : 0;
5514+ } else {
5515+ return "Unsupported ft_pixel_mode";
5516+ }
5517+ if (tc_key.pixel > 0) { /* if not background */
5518+ x = pen_x + col;
5519+
5520+ /* clip if out of bounds */
5521+ if (x >= im->sx || x < 0) {
5522+ continue;
5523+ }
5524+ /* get pixel location in gd buffer */
5525+ pixel = &im->pixels[y][x];
5526+ if (tc_key.pixel == NUMCOLORS) {
5527+ /* use fg color directly. gd 2.0.2: watch out for
5528+ * negative indexes (thanks to David Marwood).
5529+ */
5530+ *pixel = (fg < 0) ? -fg : fg;
5531+ } else {
5532+ /* find antialised color */
5533+ tc_key.bgcolor = *pixel;
5534+ tc_elem = (tweencolor_t *) gdCacheGet(tc_cache, &tc_key);
5535+ *pixel = tc_elem->tweencolor;
5536+ }
5537+ }
5538 }
5539- }
5540 }
5541- }
5542- return (char *) NULL;
5543+ return (char *) NULL;
5544 }
5545
5546 static int
5547 gdroundupdown (FT_F26Dot6 v1, int updown)
5548 {
5549- return (!updown)
5550- ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6)
5551- : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6);
5552+ return (!updown) ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6) : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6);
5553 }
5554
5555 void gdFontCacheShutdown()
5556 {
5557+ gdMutexLock(gdFontCacheMutex);
5558+
5559 if (fontCache) {
5560- gdMutexLock(gdFontCacheMutex);
5561 gdCacheDelete(fontCache);
5562 fontCache = NULL;
5563- gdMutexUnlock(gdFontCacheMutex);
5564- gdMutexShutdown(gdFontCacheMutex);
5565 FT_Done_FreeType(library);
5566 }
5567+
5568+ gdMutexUnlock(gdFontCacheMutex);
5569 }
5570
5571 void gdFreeFontCache()
5572 {
5573 gdFontCacheShutdown();
5574 }
5575-
5576+
5577+void gdFontCacheMutexSetup()
5578+{
5579+ gdMutexSetup(gdFontCacheMutex);
5580+}
5581+
5582+void gdFontCacheMutexShutdown()
5583+{
5584+ gdMutexShutdown(gdFontCacheMutex);
5585+}
5586+
5587 int gdFontCacheSetup(void)
5588 {
5589 if (fontCache) {
5590 /* Already set up */
5591 return 0;
5592 }
5593- gdMutexSetup(gdFontCacheMutex);
5594 if (FT_Init_FreeType(&library)) {
5595- gdMutexShutdown(gdFontCacheMutex);
5596 return -1;
5597 }
5598 fontCache = gdCacheCreate (FONTCACHESIZE, fontTest, fontFetch, fontRelease);
5599 return 0;
5600 }
5601
5602+
5603 /********************************************************************/
5604 /* gdImageStringFT - render a utf8 string onto a gd image */
5605
5606 char *
5607-gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
5608- double ptsize, double angle, int x, int y, char *string)
5609+gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
5610+ double ptsize, double angle, int x, int y, char *string)
5611 {
5612 return gdImageStringFTEx(im, brect, fg, fontlist, ptsize, angle, x, y, string, 0);
5613 }
5614@@ -856,15 +814,16 @@
5615
5616 /***** initialize font library and font cache on first call ******/
5617
5618+ gdMutexLock(gdFontCacheMutex);
5619 if (!fontCache) {
5620 if (gdFontCacheSetup() != 0) {
5621 gdCacheDelete(tc_cache);
5622+ gdMutexUnlock(gdFontCacheMutex);
5623 return "Failure to initialize font library";
5624 }
5625 }
5626 /*****/
5627-
5628- gdMutexLock(gdFontCacheMutex);
5629+
5630 /* get the font (via font cache) */
5631 fontkey.fontlist = fontlist;
5632 fontkey.library = &library;
5633@@ -961,6 +920,7 @@
5634
5635 while (*next) {
5636 ch = *next;
5637+
5638 /* carriage returns */
5639 if (ch == '\r') {
5640 penf.x = 0;
5641@@ -991,8 +951,9 @@
5642 /* I do not know the significance of the constant 0xf000.
5643 * It was determined by inspection of the character codes
5644 * stored in Microsoft font symbol.
5645+ * Added by Pierre (pajoye@php.net):
5646+ * Convert to the Symbol glyph range only for a Symbol family member
5647 */
5648- /* Convert to the Symbol glyph range only for a Symbol family member */
5649 len = gdTcl_UtfToUniChar (next, &ch);
5650 ch |= 0xf000;
5651 next += len;
5652@@ -1008,7 +969,7 @@
5653 next += len;
5654 }
5655 break;
5656- case gdFTEX_Shift_JIS:
5657+ case gdFTEX_Shift_JIS:
5658 if (font->have_char_map_sjis) {
5659 unsigned char c;
5660 int jiscode;
5661@@ -1063,7 +1024,7 @@
5662 FT_Set_Transform(face, &matrix, NULL);
5663 /* Convert character code to glyph index */
5664 glyph_index = FT_Get_Char_Index(face, ch);
5665-
5666+
5667 /* retrieve kerning distance and move pen position */
5668 if (use_kerning && previous && glyph_index) {
5669 FT_Get_Kerning(face, previous, glyph_index, ft_kerning_default, &delta);
5670diff -urN php-4.4.8.org/ext/gd/libgd/gd_gd2.c php-4.4.8/ext/gd/libgd/gd_gd2.c
5671--- php-4.4.8.org/ext/gd/libgd/gd_gd2.c 2004-03-29 20:21:00.000000000 +0200
5672+++ php-4.4.8/ext/gd/libgd/gd_gd2.c 2006-08-08 13:56:36.000000000 +0200
5673@@ -26,7 +26,7 @@
5674 /* 2.11: not part of the API, as the save routine can figure it out
5675 * from im->trueColor, and the load routine doesn't need to tell
5676 * the end user the saved format. NOTE: adding 2 is assumed
5677- * to result in the correct format value for truecolor!
5678+ * to result in the correct format value for truecolor!
5679 */
5680 #define GD2_FMT_TRUECOLOR_RAW 3
5681 #define GD2_FMT_TRUECOLOR_COMPRESSED 4
5682@@ -43,8 +43,7 @@
5683 {
5684 int offset;
5685 int size;
5686-}
5687-t_chunk_info;
5688+} t_chunk_info;
5689
5690 extern int _gdGetColors(gdIOCtx * in, gdImagePtr im, int gd2xFlag);
5691 extern void _gdPutColors(gdImagePtr im, gdIOCtx * out);
5692@@ -61,7 +60,7 @@
5693 int sidx;
5694 int nc;
5695
5696- GD2_DBG(php_gd_error("Reading gd2 header info\n"));
5697+ GD2_DBG(php_gd_error("Reading gd2 header info"));
5698
5699 for (i = 0; i < 4; i++) {
5700 ch = gdGetC(in);
5701@@ -72,11 +71,11 @@
5702 }
5703 id[4] = 0;
5704
5705- GD2_DBG(php_gd_error("Got file code: %s\n", id));
5706+ GD2_DBG(php_gd_error("Got file code: %s", id));
5707
5708 /* Equiv. of 'magick'. */
5709 if (strcmp(id, GD2_ID) != 0) {
5710- GD2_DBG(php_gd_error("Not a valid gd2 file\n"));
5711+ GD2_DBG(php_gd_error("Not a valid gd2 file"));
5712 goto fail1;
5713 }
5714
5715@@ -84,32 +83,32 @@
5716 if (gdGetWord(vers, in) != 1) {
5717 goto fail1;
5718 }
5719- GD2_DBG(php_gd_error("Version: %d\n", *vers));
5720+ GD2_DBG(php_gd_error("Version: %d", *vers));
5721
5722 if ((*vers != 1) && (*vers != 2)) {
5723- GD2_DBG(php_gd_error("Bad version: %d\n", *vers));
5724+ GD2_DBG(php_gd_error("Bad version: %d", *vers));
5725 goto fail1;
5726 }
5727
5728 /* Image Size */
5729 if (!gdGetWord(sx, in)) {
5730- GD2_DBG(php_gd_error("Could not get x-size\n"));
5731+ GD2_DBG(php_gd_error("Could not get x-size"));
5732 goto fail1;
5733 }
5734 if (!gdGetWord(sy, in)) {
5735- GD2_DBG(php_gd_error("Could not get y-size\n"));
5736+ GD2_DBG(php_gd_error("Could not get y-size"));
5737 goto fail1;
5738 }
5739- GD2_DBG(php_gd_error("Image is %dx%d\n", *sx, *sy));
5740+ GD2_DBG(php_gd_error("Image is %dx%d", *sx, *sy));
5741
5742 /* Chunk Size (pixels, not bytes!) */
5743 if (gdGetWord(cs, in) != 1) {
5744 goto fail1;
5745 }
5746- GD2_DBG(php_gd_error("ChunkSize: %d\n", *cs));
5747+ GD2_DBG(php_gd_error("ChunkSize: %d", *cs));
5748
5749 if ((*cs < GD2_CHUNKSIZE_MIN) || (*cs > GD2_CHUNKSIZE_MAX)) {
5750- GD2_DBG(php_gd_error("Bad chunk size: %d\n", *cs));
5751+ GD2_DBG(php_gd_error("Bad chunk size: %d", *cs));
5752 goto fail1;
5753 }
5754
5755@@ -117,10 +116,10 @@
5756 if (gdGetWord(fmt, in) != 1) {
5757 goto fail1;
5758 }
5759- GD2_DBG(php_gd_error("Format: %d\n", *fmt));
5760+ GD2_DBG(php_gd_error("Format: %d", *fmt));
5761
5762 if ((*fmt != GD2_FMT_RAW) && (*fmt != GD2_FMT_COMPRESSED) && (*fmt != GD2_FMT_TRUECOLOR_RAW) && (*fmt != GD2_FMT_TRUECOLOR_COMPRESSED)) {
5763- GD2_DBG(php_gd_error("Bad data format: %d\n", *fmt));
5764+ GD2_DBG(php_gd_error("Bad data format: %d", *fmt));
5765 goto fail1;
5766 }
5767
5768@@ -128,17 +127,17 @@
5769 if (gdGetWord(ncx, in) != 1) {
5770 goto fail1;
5771 }
5772- GD2_DBG(php_gd_error("%d Chunks Wide\n", *ncx));
5773+ GD2_DBG(php_gd_error("%d Chunks Wide", *ncx));
5774
5775 /* # of chunks high */
5776 if (gdGetWord(ncy, in) != 1) {
5777 goto fail1;
5778 }
5779- GD2_DBG(php_gd_error("%d Chunks vertically\n", *ncy));
5780+ GD2_DBG(php_gd_error("%d Chunks vertically", *ncy));
5781
5782 if (gd2_compressed(*fmt)) {
5783 nc = (*ncx) * (*ncy);
5784- GD2_DBG(php_gd_error("Reading %d chunk index entries\n", nc));
5785+ GD2_DBG(php_gd_error("Reading %d chunk index entries", nc));
5786 sidx = sizeof(t_chunk_info) * nc;
5787 if (sidx <= 0) {
5788 goto fail1;
5789@@ -155,7 +154,7 @@
5790 *chunkIdx = cidx;
5791 }
5792
5793- GD2_DBG(php_gd_error("gd2 header complete\n"));
5794+ GD2_DBG(php_gd_error("gd2 header complete"));
5795
5796 return 1;
5797
5798@@ -168,7 +167,7 @@
5799 gdImagePtr im;
5800
5801 if (_gd2GetHeader (in, sx, sy, cs, vers, fmt, ncx, ncy, cidx) != 1) {
5802- GD2_DBG(php_gd_error("Bad GD2 header\n"));
5803+ GD2_DBG(php_gd_error("Bad GD2 header"));
5804 goto fail1;
5805 }
5806
5807@@ -178,15 +177,15 @@
5808 im = gdImageCreate(*sx, *sy);
5809 }
5810 if (im == NULL) {
5811- GD2_DBG(php_gd_error("Could not create gdImage\n"));
5812+ GD2_DBG(php_gd_error("Could not create gdImage"));
5813 goto fail1;
5814 }
5815
5816 if (!_gdGetColors(in, im, (*vers) == 2)) {
5817- GD2_DBG(php_gd_error("Could not read color palette\n"));
5818+ GD2_DBG(php_gd_error("Could not read color palette"));
5819 goto fail2;
5820 }
5821- GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal));
5822+ GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal));
5823
5824 return im;
5825
5826@@ -203,25 +202,25 @@
5827 int zerr;
5828
5829 if (gdTell(in) != offset) {
5830- GD2_DBG(php_gd_error("Positioning in file to %d\n", offset));
5831+ GD2_DBG(php_gd_error("Positioning in file to %d", offset));
5832 gdSeek(in, offset);
5833 } else {
5834- GD2_DBG(php_gd_error("Already Positioned in file to %d\n", offset));
5835+ GD2_DBG(php_gd_error("Already Positioned in file to %d", offset));
5836 }
5837
5838 /* Read and uncompress an entire chunk. */
5839- GD2_DBG(php_gd_error("Reading file\n"));
5840+ GD2_DBG(php_gd_error("Reading file"));
5841 if (gdGetBuf(compBuf, compSize, in) != compSize) {
5842 return FALSE;
5843 }
5844- GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes\n", compSize, (int)*chunkLen));
5845+ GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes", compSize, (int)*chunkLen));
5846 zerr = uncompress((unsigned char *) chunkBuf, chunkLen, (unsigned char *) compBuf, compSize);
5847 if (zerr != Z_OK) {
5848- GD2_DBG(php_gd_error("Error %d from uncompress\n", zerr));
5849+ GD2_DBG(php_gd_error("Error %d from uncompress", zerr));
5850 return FALSE;
5851 }
5852- GD2_DBG(php_gd_error("Got chunk\n"));
5853-
5854+ GD2_DBG(php_gd_error("Got chunk"));
5855+
5856 return TRUE;
5857 }
5858
5859@@ -291,8 +290,8 @@
5860 }
5861 chunkBuf = gdCalloc(chunkMax, 1);
5862 compBuf = gdCalloc(compMax, 1);
5863-
5864- GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes\n", compMax));
5865+
5866+ GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes", compMax));
5867 }
5868
5869 /* Read the data... */
5870@@ -304,13 +303,13 @@
5871 yhi = im->sy;
5872 }
5873
5874- GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d\n", chunkNum, cx, cy, ylo, yhi));
5875+ GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d", chunkNum, cx, cy, ylo, yhi));
5876
5877 if (gd2_compressed(fmt)) {
5878 chunkLen = chunkMax;
5879
5880 if (!_gd2ReadChunk(chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *) chunkBuf, &chunkLen, in)) {
5881- GD2_DBG(php_gd_error("Error reading comproessed chunk\n"));
5882+ GD2_DBG(php_gd_error("Error reading comproessed chunk"));
5883 goto fail2;
5884 }
5885
5886@@ -357,7 +356,7 @@
5887 }
5888 }
5889
5890- GD2_DBG(php_gd_error("Freeing memory\n"));
5891+ GD2_DBG(php_gd_error("Freeing memory"));
5892
5893 if (chunkBuf) {
5894 gdFree(chunkBuf);
5895@@ -369,7 +368,7 @@
5896 gdFree(chunkIdx);
5897 }
5898
5899- GD2_DBG(php_gd_error("Done\n"));
5900+ GD2_DBG(php_gd_error("Done"));
5901
5902 return im;
5903
5904@@ -398,7 +397,7 @@
5905 return im;
5906 }
5907
5908-gdImagePtr gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h)
5909+gdImagePtr gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h)
5910 {
5911 gdImagePtr im;
5912 gdIOCtx *in = gdNewFileCtx(inFile);
5913@@ -431,6 +430,10 @@
5914
5915 gdImagePtr im;
5916
5917+ if (w<1 || h <1) {
5918+ return 0;
5919+ }
5920+
5921 /* The next few lines are basically copied from gd2CreateFromFile
5922 * we change the file size, so don't want to use the code directly.
5923 * but we do need to know the file size.
5924@@ -439,7 +442,7 @@
5925 goto fail1;
5926 }
5927
5928- GD2_DBG(php_gd_error("File size is %dx%d\n", fsx, fsy));
5929+ GD2_DBG(php_gd_error("File size is %dx%d", fsx, fsy));
5930
5931 /* This is the difference - make a file based on size of chunks. */
5932 if (gd2_truecolor(fmt)) {
5933@@ -454,7 +457,7 @@
5934 if (!_gdGetColors(in, im, vers == 2)) {
5935 goto fail2;
5936 }
5937- GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal));
5938+ GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal));
5939
5940 /* Process the header info */
5941 nc = ncx * ncy;
5942@@ -477,7 +480,7 @@
5943 if (chunkMax <= 0) {
5944 goto fail2;
5945 }
5946-
5947+
5948 chunkBuf = gdCalloc(chunkMax, 1);
5949 compBuf = gdCalloc(compMax, 1);
5950 }
5951@@ -503,7 +506,7 @@
5952
5953 /* Remember file position of image data. */
5954 dstart = gdTell(in);
5955- GD2_DBG(php_gd_error("Data starts at %d\n", dstart));
5956+ GD2_DBG(php_gd_error("Data starts at %d", dstart));
5957
5958 /* Loop through the chunks. */
5959 for (cy = scy; (cy <= ecy); cy++) {
5960@@ -521,10 +524,10 @@
5961 xhi = fsx;
5962 }
5963
5964- GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d\n", cx, cy, ylo, yhi));
5965+ GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d", cx, cy, ylo, yhi));
5966
5967 if (!gd2_compressed(fmt)) {
5968- GD2_DBG(php_gd_error("Using raw format data\n"));
5969+ GD2_DBG(php_gd_error("Using raw format data"));
5970 if (im->trueColor) {
5971 dpos = (cy * (cs * fsx) * 4 + cx * cs * (yhi - ylo) * 4) + dstart;
5972 } else {
5973@@ -533,29 +536,29 @@
5974
5975 /* gd 2.0.11: gdSeek returns TRUE on success, not 0. Longstanding bug. 01/16/03 */
5976 if (!gdSeek(in, dpos)) {
5977- php_gd_error_ex(E_WARNING, "Error from seek: %d\n", errno);
5978+ php_gd_error_ex(E_WARNING, "Error from seek: %d", errno);
5979 goto fail2;
5980 }
5981- GD2_DBG(php_gd_error("Reading (%d, %d) from position %d\n", cx, cy, dpos - dstart));
5982+ GD2_DBG(php_gd_error("Reading (%d, %d) from position %d", cx, cy, dpos - dstart));
5983 } else {
5984 chunkNum = cx + cy * ncx;
5985
5986 chunkLen = chunkMax;
5987- if (!_gd2ReadChunk (chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, chunkBuf, &chunkLen, in)) {
5988- php_gd_error("Error reading comproessed chunk\n");
5989+ if (!_gd2ReadChunk (chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *)chunkBuf, &chunkLen, in)) {
5990+ php_gd_error("Error reading comproessed chunk");
5991 goto fail2;
5992 }
5993 chunkPos = 0;
5994- GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d\n", cx, cy, chunkNum));
5995+ GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d", cx, cy, chunkNum));
5996 }
5997
5998- GD2_DBG(php_gd_error(" into (%d, %d) - (%d, %d)\n", xlo, ylo, xhi, yhi));
5999+ GD2_DBG(php_gd_error(" into (%d, %d) - (%d, %d)", xlo, ylo, xhi, yhi));
6000
6001 for (y = ylo; (y < yhi); y++) {
6002 for (x = xlo; x < xhi; x++) {
6003 if (!gd2_compressed(fmt)) {
6004 if (im->trueColor) {
6005- if (!gdGetInt(&ch, in)) {
6006+ if (!gdGetInt((int *)&ch, in)) {
6007 ch = 0;
6008 }
6009 } else {
6010@@ -577,11 +580,11 @@
6011
6012 /* Only use a point that is in the image. */
6013 if ((x >= srcx) && (x < (srcx + w)) && (x < fsx) && (x >= 0) && (y >= srcy) && (y < (srcy + h)) && (y < fsy) && (y >= 0)) {
6014- if (im->trueColor) {
6015+ if (im->trueColor) {
6016 im->tpixels[y - srcy][x - srcx] = ch;
6017 } else {
6018 im->pixels[y - srcy][x - srcx] = ch;
6019- }
6020+ }
6021 }
6022 }
6023 }
6024@@ -597,7 +600,7 @@
6025 if (chunkIdx) {
6026 gdFree(chunkIdx);
6027 }
6028-
6029+
6030 return im;
6031
6032 fail2:
6033@@ -653,7 +656,7 @@
6034 int compMax = 0;
6035
6036 /* Force fmt to a valid value since we don't return anything. */
6037- if ((fmt != GD2_FMT_RAW) && (fmt != GD2_FMT_COMPRESSED)) {
6038+ if ((fmt != GD2_FMT_RAW) && (fmt != GD2_FMT_COMPRESSED)) {
6039 fmt = im->trueColor ? GD2_FMT_TRUECOLOR_COMPRESSED : GD2_FMT_COMPRESSED;
6040 }
6041 if (im->trueColor) {
6042@@ -693,16 +696,16 @@
6043 chunkData = safe_emalloc(cs * bytesPerPixel, cs, 0);
6044 memset(chunkData, 0, cs * bytesPerPixel * cs);
6045 if (compMax <= 0) {
6046- goto fail;
6047+ goto fail;
6048 }
6049 compData = gdCalloc(compMax, 1);
6050
6051 /* Save the file position of chunk index, and allocate enough space for
6052- * each chunk_info block .
6053+ * each chunk_info block .
6054 */
6055 idxPos = gdTell(out);
6056 idxSize = ncx * ncy * sizeof(t_chunk_info);
6057- GD2_DBG(php_gd_error("Index size is %d\n", idxSize));
6058+ GD2_DBG(php_gd_error("Index size is %d", idxSize));
6059 gdSeek(out, idxPos + idxSize);
6060
6061 chunkIdx = safe_emalloc(idxSize, sizeof(t_chunk_info), 0);
6062@@ -711,8 +714,8 @@
6063
6064 _gdPutColors (im, out);
6065
6066- GD2_DBG(php_gd_error("Size: %dx%d\n", im->sx, im->sy));
6067- GD2_DBG(php_gd_error("Chunks: %dx%d\n", ncx, ncy));
6068+ GD2_DBG(php_gd_error("Size: %dx%d", im->sx, im->sy));
6069+ GD2_DBG(php_gd_error("Chunks: %dx%d", ncx, ncy));
6070
6071 for (cy = 0; (cy < ncy); cy++) {
6072 for (cx = 0; (cx < ncx); cx++) {
6073@@ -722,7 +725,7 @@
6074 yhi = im->sy;
6075 }
6076
6077- GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d\n", cx, cy, ylo, yhi));
6078+ GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d", cx, cy, ylo, yhi));
6079 chunkLen = 0;
6080 for (y = ylo; (y < yhi); y++) {
6081 GD2_DBG(php_gd_error("y=%d: ",y));
6082@@ -747,7 +750,7 @@
6083 }
6084 } else {
6085 for (x = xlo; x < xhi; x++) {
6086- GD2_DBG(php_gd_error("%d, ",x));
6087+ GD2_DBG(php_gd_error("%d, ",x));
6088
6089 if (im->trueColor) {
6090 gdPutInt(im->tpixels[y][x], out);
6091@@ -756,21 +759,21 @@
6092 }
6093 }
6094 }
6095- GD2_DBG(php_gd_error("y=%d done.\n",y));
6096+ GD2_DBG(php_gd_error("y=%d done.",y));
6097 }
6098
6099 if (gd2_compressed(fmt)) {
6100 compLen = compMax;
6101 if (compress((unsigned char *) &compData[0], &compLen, (unsigned char *) &chunkData[0], chunkLen) != Z_OK) {
6102- php_gd_error("Error from compressing\n");
6103+ php_gd_error("Error from compressing");
6104 } else {
6105 chunkIdx[chunkNum].offset = gdTell(out);
6106 chunkIdx[chunkNum++].size = compLen;
6107- GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
6108+ GD2_DBG(php_gd_error("Chunk %d size %d offset %d", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
6109
6110 if (gdPutBuf (compData, compLen, out) <= 0) {
6111 /* Any alternate suggestions for handling this? */
6112- php_gd_error_ex(E_WARNING, "Error %d on write\n", errno);
6113+ php_gd_error_ex(E_WARNING, "Error %d on write", errno);
6114 }
6115 }
6116 }
6117@@ -779,29 +782,29 @@
6118
6119 if (gd2_compressed(fmt)) {
6120 /* Save the position, write the index, restore position (paranoia). */
6121- GD2_DBG(php_gd_error("Seeking %d to write index\n", idxPos));
6122+ GD2_DBG(php_gd_error("Seeking %d to write index", idxPos));
6123 posSave = gdTell(out);
6124 gdSeek(out, idxPos);
6125- GD2_DBG(php_gd_error("Writing index\n"));
6126+ GD2_DBG(php_gd_error("Writing index"));
6127 for (x = 0; x < chunkNum; x++) {
6128- GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", x, chunkIdx[x].size, chunkIdx[x].offset));
6129+ GD2_DBG(php_gd_error("Chunk %d size %d offset %d", x, chunkIdx[x].size, chunkIdx[x].offset));
6130 gdPutInt(chunkIdx[x].offset, out);
6131 gdPutInt(chunkIdx[x].size, out);
6132 }
6133 gdSeek(out, posSave);
6134 }
6135 fail:
6136- GD2_DBG(php_gd_error("Freeing memory\n"));
6137+ GD2_DBG(php_gd_error("Freeing memory"));
6138 if (chunkData) {
6139 gdFree(chunkData);
6140 }
6141- if (compData) {
6142+ if (compData) {
6143 gdFree(compData);
6144 }
6145 if (chunkIdx) {
6146 gdFree(chunkIdx);
6147 }
6148- GD2_DBG(php_gd_error("Done\n"));
6149+ GD2_DBG(php_gd_error("Done"));
6150 }
6151
6152 void gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt)
6153@@ -809,7 +812,7 @@
6154 gdIOCtx *out = gdNewFileCtx(outFile);
6155
6156 _gdImageGd2(im, out, cs, fmt);
6157-
6158+
6159 out->gd_free(out);
6160 }
6161
6162@@ -821,6 +824,6 @@
6163 _gdImageGd2(im, out, cs, fmt);
6164 rv = gdDPExtractData(out, size);
6165 out->gd_free(out);
6166-
6167+
6168 return rv;
6169 }
6170diff -urN php-4.4.8.org/ext/gd/libgd/gd_gd.c php-4.4.8/ext/gd/libgd/gd_gd.c
6171--- php-4.4.8.org/ext/gd/libgd/gd_gd.c 2004-03-29 20:21:00.000000000 +0200
6172+++ php-4.4.8/ext/gd/libgd/gd_gd.c 2007-08-09 16:21:38.000000000 +0200
6173@@ -1,4 +1,3 @@
6174-
6175 #include <stdio.h>
6176 #include <math.h>
6177 #include <string.h>
6178@@ -58,7 +57,7 @@
6179 }
6180
6181 GD2_DBG(printf("Pallette had %d colours (T=%d)\n", im->colorsTotal, im->transparent));
6182-
6183+
6184 if (im->trueColor) {
6185 return TRUE;
6186 }
6187@@ -123,6 +122,9 @@
6188 } else {
6189 im = gdImageCreate(*sx, *sy);
6190 }
6191+ if(!im) {
6192+ goto fail1;
6193+ }
6194 if (!_gdGetColors(in, im, gd2xFlag)) {
6195 goto fail2;
6196 }
6197@@ -225,7 +227,7 @@
6198
6199 static void _gdPutHeader (gdImagePtr im, gdIOCtx * out)
6200 {
6201- /* 65535 indicates this is a gd 2.x .gd file.
6202+ /* 65535 indicates this is a gd 2.x .gd file.
6203 * 2.0.12: 65534 indicates truecolor.
6204 */
6205 if (im->trueColor) {
6206diff -urN php-4.4.8.org/ext/gd/libgd/gd_gif_in.c php-4.4.8/ext/gd/libgd/gd_gif_in.c
6207--- php-4.4.8.org/ext/gd/libgd/gd_gif_in.c 2007-06-08 07:31:02.000000000 +0200
6208+++ php-4.4.8/ext/gd/libgd/gd_gif_in.c 2007-06-07 23:07:33.000000000 +0200
6209@@ -17,9 +17,9 @@
6210
6211 static int set_verbose(void)
6212 {
6213- verbose = !!getenv("GIF_VERBOSE");
6214- verbose_set = 1;
6215- return(verbose);
6216+ verbose = !!getenv("GIF_VERBOSE");
6217+ verbose_set = 1;
6218+ return(verbose);
6219 }
6220
6221 #else
6222@@ -44,270 +44,313 @@
6223 #define LOCALCOLORMAP 0x80
6224 #define BitSet(byte, bit) (((byte) & (bit)) == (bit))
6225
6226-#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) != 0)
6227+#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) > 0)
6228
6229 #define LM_to_uint(a,b) (((b)<<8)|(a))
6230
6231 /* We may eventually want to use this information, but def it out for now */
6232 #if 0
6233 static struct {
6234- unsigned int Width;
6235- unsigned int Height;
6236- unsigned char ColorMap[3][MAXCOLORMAPSIZE];
6237- unsigned int BitPixel;
6238- unsigned int ColorResolution;
6239- unsigned int Background;
6240- unsigned int AspectRatio;
6241+ unsigned int Width;
6242+ unsigned int Height;
6243+ unsigned char ColorMap[3][MAXCOLORMAPSIZE];
6244+ unsigned int BitPixel;
6245+ unsigned int ColorResolution;
6246+ unsigned int Background;
6247+ unsigned int AspectRatio;
6248 } GifScreen;
6249 #endif
6250
6251+#if 0
6252 static struct {
6253- int transparent;
6254- int delayTime;
6255- int inputFlag;
6256- int disposal;
6257+ int transparent;
6258+ int delayTime;
6259+ int inputFlag;
6260+ int disposal;
6261 } Gif89 = { -1, -1, -1, 0 };
6262+#endif
6263
6264-static int ReadColorMap (gdIOCtx *fd, int number, unsigned char (*buffer)[256]);
6265-static int DoExtension (gdIOCtx *fd, int label, int *Transparent);
6266-static int GetDataBlock (gdIOCtx *fd, unsigned char *buf);
6267-static int GetCode (gdIOCtx *fd, int code_size, int flag);
6268-static int LWZReadByte (gdIOCtx *fd, int flag, int input_code_size);
6269+#define STACK_SIZE ((1<<(MAX_LWZ_BITS))*2)
6270
6271-static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace); /*1.4//, int ignore); */
6272+typedef struct {
6273+ unsigned char buf[280];
6274+ int curbit, lastbit, done, last_byte;
6275+} CODE_STATIC_DATA;
6276+
6277+typedef struct {
6278+ int fresh;
6279+ int code_size, set_code_size;
6280+ int max_code, max_code_size;
6281+ int firstcode, oldcode;
6282+ int clear_code, end_code;
6283+ int table[2][(1<< MAX_LWZ_BITS)];
6284+ int stack[STACK_SIZE], *sp;
6285+ CODE_STATIC_DATA scd;
6286+} LZW_STATIC_DATA;
6287
6288-int ZeroDataBlock;
6289+static int ReadColorMap (gdIOCtx *fd, int number, unsigned char (*buffer)[256]);
6290+static int DoExtension (gdIOCtx *fd, int label, int *Transparent, int *ZeroDataBlockP);
6291+static int GetDataBlock (gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP);
6292+static int GetCode (gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP);
6293+static int LWZReadByte (gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, int *ZeroDataBlockP);
6294+
6295+static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace, int *ZeroDataBlockP); /*1.4//, int ignore); */
6296
6297-gdImagePtr gdImageCreateFromGifSource(gdSourcePtr inSource)
6298+gdImagePtr gdImageCreateFromGifSource(gdSourcePtr inSource) /* {{{ */
6299 {
6300- gdIOCtx *in = gdNewSSCtx(inSource, NULL);
6301- gdImagePtr im;
6302+ gdIOCtx *in = gdNewSSCtx(inSource, NULL);
6303+ gdImagePtr im;
6304
6305- im = gdImageCreateFromGifCtx(in);
6306+ im = gdImageCreateFromGifCtx(in);
6307
6308- in->gd_free(in);
6309+ in->gd_free(in);
6310
6311- return im;
6312+ return im;
6313 }
6314+/* }}} */
6315
6316-gdImagePtr
6317-gdImageCreateFromGif(FILE *fdFile)
6318+gdImagePtr gdImageCreateFromGif(FILE *fdFile) /* {{{ */
6319 {
6320- gdIOCtx *fd = gdNewFileCtx(fdFile);
6321- gdImagePtr im = 0;
6322+ gdIOCtx *fd = gdNewFileCtx(fdFile);
6323+ gdImagePtr im = 0;
6324
6325- im = gdImageCreateFromGifCtx(fd);
6326+ im = gdImageCreateFromGifCtx(fd);
6327
6328- fd->gd_free(fd);
6329+ fd->gd_free(fd);
6330
6331- return im;
6332+ return im;
6333 }
6334+/* }}} */
6335
6336-gdImagePtr
6337-gdImageCreateFromGifCtx(gdIOCtxPtr fd)
6338+gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */
6339 {
6340-/* 1.4 int imageNumber; */
6341- int BitPixel;
6342- int ColorResolution;
6343- int Background;
6344- int AspectRatio;
6345- int Transparent = (-1);
6346- unsigned char buf[16];
6347- unsigned char c;
6348- unsigned char ColorMap[3][MAXCOLORMAPSIZE];
6349- unsigned char localColorMap[3][MAXCOLORMAPSIZE];
6350- int imw, imh;
6351- int useGlobalColormap;
6352- int bitPixel;
6353- int i;
6354- /*1.4//int imageCount = 0; */
6355- char version[4];
6356-
6357- gdImagePtr im = 0;
6358- ZeroDataBlock = FALSE;
6359+ int BitPixel;
6360+#if 0
6361+ int ColorResolution;
6362+ int Background;
6363+ int AspectRatio;
6364+#endif
6365+ int Transparent = (-1);
6366+ unsigned char buf[16];
6367+ unsigned char c;
6368+ unsigned char ColorMap[3][MAXCOLORMAPSIZE];
6369+ unsigned char localColorMap[3][MAXCOLORMAPSIZE];
6370+ int imw, imh, screen_width, screen_height;
6371+ int gif87a, useGlobalColormap;
6372+ int bitPixel;
6373+ int i;
6374+ /*1.4//int imageCount = 0; */
6375+
6376+ int ZeroDataBlock = FALSE;
6377+ int haveGlobalColormap;
6378+ gdImagePtr im = 0;
6379
6380- /*1.4//imageNumber = 1; */
6381- if (! ReadOK(fd,buf,6)) {
6382+ /*1.4//imageNumber = 1; */
6383+ if (! ReadOK(fd,buf,6)) {
6384 return 0;
6385 }
6386- if (strncmp((char *)buf,"GIF",3) != 0) {
6387+ if (strncmp((char *)buf,"GIF",3) != 0) {
6388 return 0;
6389 }
6390- strncpy(version, (char *)buf + 3, 3);
6391- version[3] = '\0';
6392
6393- if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) {
6394+ if (memcmp((char *)buf+3, "87a", 3) == 0) {
6395+ gif87a = 1;
6396+ } else if (memcmp((char *)buf+3, "89a", 3) == 0) {
6397+ gif87a = 0;
6398+ } else {
6399 return 0;
6400 }
6401- if (! ReadOK(fd,buf,7)) {
6402+
6403+ if (! ReadOK(fd,buf,7)) {
6404 return 0;
6405 }
6406- BitPixel = 2<<(buf[4]&0x07);
6407- ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
6408- Background = buf[5];
6409- AspectRatio = buf[6];
6410
6411- imw = LM_to_uint(buf[0],buf[1]);
6412- imh = LM_to_uint(buf[2],buf[3]);
6413+ BitPixel = 2<<(buf[4]&0x07);
6414+#if 0
6415+ ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
6416+ Background = buf[5];
6417+ AspectRatio = buf[6];
6418+#endif
6419+ screen_width = imw = LM_to_uint(buf[0],buf[1]);
6420+ screen_height = imh = LM_to_uint(buf[2],buf[3]);
6421
6422- if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */
6423- if (ReadColorMap(fd, BitPixel, ColorMap)) {
6424+ haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */
6425+ if (haveGlobalColormap) {
6426+ if (ReadColorMap(fd, BitPixel, ColorMap)) {
6427 return 0;
6428 }
6429- }
6430- for (;;) {
6431- if (! ReadOK(fd,&c,1)) {
6432- return 0;
6433- }
6434- if (c == ';') { /* GIF terminator */
6435+ }
6436+
6437+ for (;;) {
6438+ int top, left;
6439+ int width, height;
6440+
6441+ if (! ReadOK(fd,&c,1)) {
6442+ return 0;
6443+ }
6444+ if (c == ';') { /* GIF terminator */
6445 goto terminated;
6446- }
6447+ }
6448+
6449+ if (c == '!') { /* Extension */
6450+ if (! ReadOK(fd,&c,1)) {
6451+ return 0;
6452+ }
6453+ DoExtension(fd, c, &Transparent, &ZeroDataBlock);
6454+ continue;
6455+ }
6456
6457- if (c == '!') { /* Extension */
6458- if (! ReadOK(fd,&c,1)) {
6459- return 0;
6460- }
6461- DoExtension(fd, c, &Transparent);
6462- continue;
6463- }
6464-
6465- if (c != ',') { /* Not a valid start character */
6466- continue;
6467- }
6468-
6469- /*1.4//++imageCount; */
6470-
6471- if (! ReadOK(fd,buf,9)) {
6472- return 0;
6473- }
6474-
6475- useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
6476-
6477- bitPixel = 1<<((buf[8]&0x07)+1);
6478-
6479- if (!useGlobalColormap) {
6480- if (ReadColorMap(fd, bitPixel, localColorMap)) {
6481- return 0;
6482- }
6483- }
6484-
6485- if (!(im = gdImageCreate(imw, imh))) {
6486- return 0;
6487- }
6488- im->interlace = BitSet(buf[8], INTERLACE);
6489- if (! useGlobalColormap) {
6490- ReadImage(im, fd, imw, imh, localColorMap,
6491- BitSet(buf[8], INTERLACE));
6492- /*1.4//imageCount != imageNumber); */
6493- } else {
6494- ReadImage(im, fd, imw, imh,
6495- ColorMap,
6496- BitSet(buf[8], INTERLACE));
6497- /*1.4//imageCount != imageNumber); */
6498- }
6499- if (Transparent != (-1)) {
6500- gdImageColorTransparent(im, Transparent);
6501- }
6502- goto terminated;
6503- }
6504+ if (c != ',') { /* Not a valid start character */
6505+ continue;
6506+ }
6507
6508-terminated:
6509- /* Terminator before any image was declared! */
6510- if (!im) {
6511- return 0;
6512- }
6513+ /*1.4//++imageCount; */
6514
6515- if (!im->colorsTotal) {
6516- gdImageDestroy(im);
6517+ if (! ReadOK(fd,buf,9)) {
6518 return 0;
6519 }
6520
6521- /* Check for open colors at the end, so
6522- we can reduce colorsTotal and ultimately
6523- BitsPerPixel */
6524- for (i=((im->colorsTotal-1)); (i>=0); i--) {
6525+ useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
6526+
6527+ bitPixel = 1<<((buf[8]&0x07)+1);
6528+ left = LM_to_uint(buf[0], buf[1]);
6529+ top = LM_to_uint(buf[2], buf[3]);
6530+ width = LM_to_uint(buf[4], buf[5]);
6531+ height = LM_to_uint(buf[6], buf[7]);
6532+
6533+ if (left + width > screen_width || top + height > screen_height) {
6534+ if (VERBOSE) {
6535+ printf("Frame is not confined to screen dimension.\n");
6536+ }
6537+ return 0;
6538+ }
6539+
6540+ if (!(im = gdImageCreate(width, height))) {
6541+ return 0;
6542+ }
6543+ im->interlace = BitSet(buf[8], INTERLACE);
6544+ if (!useGlobalColormap) {
6545+ if (ReadColorMap(fd, bitPixel, localColorMap)) {
6546+ gdImageDestroy(im);
6547+ return 0;
6548+ }
6549+ ReadImage(im, fd, width, height, localColorMap,
6550+ BitSet(buf[8], INTERLACE), &ZeroDataBlock);
6551+ } else {
6552+ if (!haveGlobalColormap) {
6553+ gdImageDestroy(im);
6554+ return 0;
6555+ }
6556+ ReadImage(im, fd, width, height,
6557+ ColorMap,
6558+ BitSet(buf[8], INTERLACE), &ZeroDataBlock);
6559+ }
6560+ if (Transparent != (-1)) {
6561+ gdImageColorTransparent(im, Transparent);
6562+ }
6563+ goto terminated;
6564+ }
6565+
6566+terminated:
6567+ /* Terminator before any image was declared! */
6568+ if (!im) {
6569+ return 0;
6570+ }
6571+ if (!im->colorsTotal) {
6572+ gdImageDestroy(im);
6573+ return 0;
6574+ }
6575+ /* Check for open colors at the end, so
6576+ we can reduce colorsTotal and ultimately
6577+ BitsPerPixel */
6578+ for (i=((im->colorsTotal-1)); (i>=0); i--) {
6579 if (im->open[i]) {
6580- im->colorsTotal--;
6581- } else {
6582- break;
6583- }
6584- }
6585- return im;
6586+ im->colorsTotal--;
6587+ } else {
6588+ break;
6589+ }
6590+ }
6591+ return im;
6592 }
6593+/* }}} */
6594
6595-static int
6596-ReadColorMap(gdIOCtx *fd, int number, unsigned char (*buffer)[256])
6597+static int ReadColorMap(gdIOCtx *fd, int number, unsigned char (*buffer)[256]) /* {{{ */
6598 {
6599- int i;
6600- unsigned char rgb[3];
6601+ int i;
6602+ unsigned char rgb[3];
6603
6604
6605- for (i = 0; i < number; ++i) {
6606- if (! ReadOK(fd, rgb, sizeof(rgb))) {
6607- return TRUE;
6608- }
6609- buffer[CM_RED][i] = rgb[0] ;
6610- buffer[CM_GREEN][i] = rgb[1] ;
6611- buffer[CM_BLUE][i] = rgb[2] ;
6612- }
6613+ for (i = 0; i < number; ++i) {
6614+ if (! ReadOK(fd, rgb, sizeof(rgb))) {
6615+ return TRUE;
6616+ }
6617+ buffer[CM_RED][i] = rgb[0] ;
6618+ buffer[CM_GREEN][i] = rgb[1] ;
6619+ buffer[CM_BLUE][i] = rgb[2] ;
6620+ }
6621
6622
6623- return FALSE;
6624+ return FALSE;
6625 }
6626+/* }}} */
6627
6628 static int
6629-DoExtension(gdIOCtx *fd, int label, int *Transparent)
6630+DoExtension(gdIOCtx *fd, int label, int *Transparent, int *ZeroDataBlockP)
6631 {
6632- static unsigned char buf[256];
6633+ unsigned char buf[256];
6634+
6635+ switch (label) {
6636+ case 0xf9: /* Graphic Control Extension */
6637+ memset(buf, 0, 4); /* initialize a few bytes in the case the next function fails */
6638+ (void) GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP);
6639+#if 0
6640+ Gif89.disposal = (buf[0] >> 2) & 0x7;
6641+ Gif89.inputFlag = (buf[0] >> 1) & 0x1;
6642+ Gif89.delayTime = LM_to_uint(buf[1],buf[2]);
6643+#endif
6644+ if ((buf[0] & 0x1) != 0)
6645+ *Transparent = buf[3];
6646
6647- switch (label) {
6648- case 0xf9: /* Graphic Control Extension */
6649- (void) GetDataBlock(fd, (unsigned char*) buf);
6650- Gif89.disposal = (buf[0] >> 2) & 0x7;
6651- Gif89.inputFlag = (buf[0] >> 1) & 0x1;
6652- Gif89.delayTime = LM_to_uint(buf[1],buf[2]);
6653- if ((buf[0] & 0x1) != 0)
6654- *Transparent = buf[3];
6655-
6656- while (GetDataBlock(fd, (unsigned char*) buf) > 0)
6657- ;
6658- return FALSE;
6659- default:
6660- break;
6661- }
6662- while (GetDataBlock(fd, (unsigned char*) buf) > 0)
6663- ;
6664+ while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0);
6665+ return FALSE;
6666+ default:
6667+ break;
6668+ }
6669+ while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0)
6670+ ;
6671
6672- return FALSE;
6673+ return FALSE;
6674 }
6675+/* }}} */
6676
6677 static int
6678-GetDataBlock_(gdIOCtx *fd, unsigned char *buf)
6679+GetDataBlock_(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP)
6680 {
6681- unsigned char count;
6682+ unsigned char count;
6683
6684- if (! ReadOK(fd,&count,1)) {
6685- return -1;
6686- }
6687+ if (! ReadOK(fd,&count,1)) {
6688+ return -1;
6689+ }
6690
6691- ZeroDataBlock = count == 0;
6692+ *ZeroDataBlockP = count == 0;
6693
6694- if ((count != 0) && (! ReadOK(fd, buf, count))) {
6695- return -1;
6696- }
6697+ if ((count != 0) && (! ReadOK(fd, buf, count))) {
6698+ return -1;
6699+ }
6700
6701- return count;
6702+ return count;
6703 }
6704+/* }}} */
6705
6706 static int
6707-GetDataBlock(gdIOCtx *fd, unsigned char *buf)
6708+GetDataBlock(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP)
6709 {
6710 int rv;
6711 int i;
6712- char *tmp = NULL;
6713-
6714- rv = GetDataBlock_(fd,buf);
6715+
6716+ rv = GetDataBlock_(fd,buf, ZeroDataBlockP);
6717 if (VERBOSE) {
6718+ char *tmp = NULL;
6719 if (rv > 0) {
6720 tmp = safe_emalloc(3 * rv, sizeof(char), 1);
6721 for (i=0;i<rv;i++) {
6722@@ -321,281 +364,275 @@
6723 }
6724 return(rv);
6725 }
6726+/* }}} */
6727
6728 static int
6729-GetCode_(gdIOCtx *fd, int code_size, int flag)
6730+GetCode_(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP)
6731 {
6732- static unsigned char buf[280];
6733- static int curbit, lastbit, done, last_byte;
6734- int i, j, ret;
6735- unsigned char count;
6736-
6737- if (flag) {
6738- curbit = 0;
6739- lastbit = 0;
6740- done = FALSE;
6741- return 0;
6742- }
6743-
6744- if ( (curbit+code_size) >= lastbit) {
6745- if (done) {
6746- if (curbit >= lastbit) {
6747- /* Oh well */
6748- }
6749- return -1;
6750- }
6751- buf[0] = buf[last_byte-2];
6752- buf[1] = buf[last_byte-1];
6753-
6754- if ((count = GetDataBlock(fd, &buf[2])) <= 0)
6755- done = TRUE;
6756-
6757- last_byte = 2 + count;
6758- curbit = (curbit - lastbit) + 16;
6759- lastbit = (2+count)*8 ;
6760- }
6761-
6762- ret = 0;
6763- for (i = curbit, j = 0; j < code_size; ++i, ++j)
6764- ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
6765+ int i, j, ret;
6766+ unsigned char count;
6767+
6768+ if (flag) {
6769+ scd->curbit = 0;
6770+ scd->lastbit = 0;
6771+ scd->last_byte = 0;
6772+ scd->done = FALSE;
6773+ return 0;
6774+ }
6775+
6776+ if ( (scd->curbit + code_size) >= scd->lastbit) {
6777+ if (scd->done) {
6778+ if (scd->curbit >= scd->lastbit) {
6779+ /* Oh well */
6780+ }
6781+ return -1;
6782+ }
6783+ scd->buf[0] = scd->buf[scd->last_byte-2];
6784+ scd->buf[1] = scd->buf[scd->last_byte-1];
6785+
6786+ if ((count = GetDataBlock(fd, &scd->buf[2], ZeroDataBlockP)) <= 0)
6787+ scd->done = TRUE;
6788+
6789+ scd->last_byte = 2 + count;
6790+ scd->curbit = (scd->curbit - scd->lastbit) + 16;
6791+ scd->lastbit = (2+count)*8 ;
6792+ }
6793
6794- curbit += code_size;
6795- return ret;
6796+ ret = 0;
6797+ for (i = scd->curbit, j = 0; j < code_size; ++i, ++j)
6798+ ret |= ((scd->buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
6799+
6800+ scd->curbit += code_size;
6801+ return ret;
6802 }
6803
6804 static int
6805-GetCode(gdIOCtx *fd, int code_size, int flag)
6806+GetCode(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP)
6807 {
6808- int rv;
6809+ int rv;
6810
6811- rv = GetCode_(fd,code_size,flag);
6812- if (VERBOSE) php_gd_error_ex(E_NOTICE, "[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
6813- return(rv);
6814+ rv = GetCode_(fd, scd, code_size,flag, ZeroDataBlockP);
6815+ if (VERBOSE) printf("[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
6816+ return(rv);
6817 }
6818+/* }}} */
6819
6820-#define STACK_SIZE ((1<<(MAX_LWZ_BITS))*2)
6821 static int
6822-LWZReadByte_(gdIOCtx *fd, int flag, int input_code_size)
6823+LWZReadByte_(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, int *ZeroDataBlockP)
6824 {
6825- static int fresh = FALSE;
6826- int code, incode;
6827- static int code_size, set_code_size;
6828- static int max_code, max_code_size;
6829- static int firstcode, oldcode;
6830- static int clear_code, end_code;
6831- static int table[2][(1<< MAX_LWZ_BITS)];
6832- static int stack[STACK_SIZE], *sp;
6833- register int i;
6834-
6835- if (flag) {
6836- set_code_size = input_code_size;
6837- code_size = set_code_size+1;
6838- clear_code = 1 << set_code_size ;
6839- end_code = clear_code + 1;
6840- max_code_size = 2*clear_code;
6841- max_code = clear_code+2;
6842-
6843- GetCode(fd, 0, TRUE);
6844-
6845- fresh = TRUE;
6846-
6847- for (i = 0; i < clear_code; ++i) {
6848- table[0][i] = 0;
6849- table[1][i] = i;
6850- }
6851- for (; i < (1<<MAX_LWZ_BITS); ++i)
6852- table[0][i] = table[1][0] = 0;
6853-
6854- sp = stack;
6855-
6856- return 0;
6857- } else if (fresh) {
6858- fresh = FALSE;
6859- do {
6860- firstcode = oldcode =
6861- GetCode(fd, code_size, FALSE);
6862- } while (firstcode == clear_code);
6863- return firstcode;
6864- }
6865-
6866- if (sp > stack)
6867- return *--sp;
6868-
6869- while ((code = GetCode(fd, code_size, FALSE)) >= 0) {
6870- if (code == clear_code) {
6871- for (i = 0; i < clear_code; ++i) {
6872- table[0][i] = 0;
6873- table[1][i] = i;
6874- }
6875- for (; i < (1<<MAX_LWZ_BITS); ++i)
6876- table[0][i] = table[1][i] = 0;
6877- code_size = set_code_size+1;
6878- max_code_size = 2*clear_code;
6879- max_code = clear_code+2;
6880- sp = stack;
6881- firstcode = oldcode =
6882- GetCode(fd, code_size, FALSE);
6883- return firstcode;
6884- } else if (code == end_code) {
6885- int count;
6886- unsigned char buf[260];
6887-
6888- if (ZeroDataBlock)
6889- return -2;
6890-
6891- while ((count = GetDataBlock(fd, buf)) > 0)
6892- ;
6893-
6894- if (count != 0)
6895- return -2;
6896- }
6897-
6898- incode = code;
6899-
6900- if (sp == (stack + STACK_SIZE)) {
6901- /* Bad compressed data stream */
6902- return -1;
6903- }
6904-
6905- if (code >= max_code) {
6906- *sp++ = firstcode;
6907- code = oldcode;
6908- }
6909-
6910- while (code >= clear_code) {
6911- if (sp == (stack + STACK_SIZE)) {
6912- /* Bad compressed data stream */
6913- return -1;
6914- }
6915- *sp++ = table[1][code];
6916- if (code == table[0][code]) {
6917- /* Oh well */
6918- }
6919- code = table[0][code];
6920- }
6921-
6922- *sp++ = firstcode = table[1][code];
6923-
6924- if ((code = max_code) <(1<<MAX_LWZ_BITS)) {
6925- table[0][code] = oldcode;
6926- table[1][code] = firstcode;
6927- ++max_code;
6928- if ((max_code >= max_code_size) &&
6929- (max_code_size < (1<<MAX_LWZ_BITS))) {
6930- max_code_size *= 2;
6931- ++code_size;
6932- }
6933- }
6934-
6935- oldcode = incode;
6936-
6937- if (sp > stack)
6938- return *--sp;
6939- }
6940- return code;
6941+ int code, incode, i;
6942+
6943+ if (flag) {
6944+ sd->set_code_size = input_code_size;
6945+ sd->code_size = sd->set_code_size+1;
6946+ sd->clear_code = 1 << sd->set_code_size ;
6947+ sd->end_code = sd->clear_code + 1;
6948+ sd->max_code_size = 2*sd->clear_code;
6949+ sd->max_code = sd->clear_code+2;
6950+
6951+ GetCode(fd, &sd->scd, 0, TRUE, ZeroDataBlockP);
6952+
6953+ sd->fresh = TRUE;
6954+
6955+ for (i = 0; i < sd->clear_code; ++i) {
6956+ sd->table[0][i] = 0;
6957+ sd->table[1][i] = i;
6958+ }
6959+ for (; i < (1<<MAX_LWZ_BITS); ++i)
6960+ sd->table[0][i] = sd->table[1][0] = 0;
6961+
6962+ sd->sp = sd->stack;
6963+
6964+ return 0;
6965+ } else if (sd->fresh) {
6966+ sd->fresh = FALSE;
6967+ do {
6968+ sd->firstcode = sd->oldcode =
6969+ GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
6970+ } while (sd->firstcode == sd->clear_code);
6971+ return sd->firstcode;
6972+ }
6973+
6974+ if (sd->sp > sd->stack)
6975+ return *--sd->sp;
6976+
6977+ while ((code = GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP)) >= 0) {
6978+ if (code == sd->clear_code) {
6979+ for (i = 0; i < sd->clear_code; ++i) {
6980+ sd->table[0][i] = 0;
6981+ sd->table[1][i] = i;
6982+ }
6983+ for (; i < (1<<MAX_LWZ_BITS); ++i)
6984+ sd->table[0][i] = sd->table[1][i] = 0;
6985+ sd->code_size = sd->set_code_size+1;
6986+ sd->max_code_size = 2*sd->clear_code;
6987+ sd->max_code = sd->clear_code+2;
6988+ sd->sp = sd->stack;
6989+ sd->firstcode = sd->oldcode =
6990+ GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
6991+ return sd->firstcode;
6992+ } else if (code == sd->end_code) {
6993+ int count;
6994+ unsigned char buf[260];
6995+
6996+ if (*ZeroDataBlockP)
6997+ return -2;
6998+
6999+ while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0)
7000+ ;
7001+
7002+ if (count != 0)
7003+ return -2;
7004+ }
7005+
7006+ incode = code;
7007+
7008+ if (sd->sp == (sd->stack + STACK_SIZE)) {
7009+ /* Bad compressed data stream */
7010+ return -1;
7011+ }
7012+
7013+ if (code >= sd->max_code) {
7014+ *sd->sp++ = sd->firstcode;
7015+ code = sd->oldcode;
7016+ }
7017+
7018+ while (code >= sd->clear_code) {
7019+ if (sd->sp == (sd->stack + STACK_SIZE)) {
7020+ /* Bad compressed data stream */
7021+ return -1;
7022+ }
7023+ *sd->sp++ = sd->table[1][code];
7024+ if (code == sd->table[0][code]) {
7025+ /* Oh well */
7026+ }
7027+ code = sd->table[0][code];
7028+ }
7029+
7030+ *sd->sp++ = sd->firstcode = sd->table[1][code];
7031+
7032+ if ((code = sd->max_code) <(1<<MAX_LWZ_BITS)) {
7033+ sd->table[0][code] = sd->oldcode;
7034+ sd->table[1][code] = sd->firstcode;
7035+ ++sd->max_code;
7036+ if ((sd->max_code >= sd->max_code_size) &&
7037+ (sd->max_code_size < (1<<MAX_LWZ_BITS))) {
7038+ sd->max_code_size *= 2;
7039+ ++sd->code_size;
7040+ }
7041+ }
7042+
7043+ sd->oldcode = incode;
7044+
7045+ if (sd->sp > sd->stack)
7046+ return *--sd->sp;
7047+ }
7048+ return code;
7049 }
7050+/* }}} */
7051
7052 static int
7053-LWZReadByte(gdIOCtx *fd, int flag, int input_code_size)
7054+LWZReadByte(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, int *ZeroDataBlockP)
7055 {
7056- int rv;
7057+ int rv;
7058
7059- rv = LWZReadByte_(fd,flag,input_code_size);
7060- if (VERBOSE) php_gd_error_ex(E_NOTICE, "[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
7061- return(rv);
7062+ rv = LWZReadByte_(fd, sd, flag, input_code_size, ZeroDataBlockP);
7063+ if (VERBOSE) printf("[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
7064+ return(rv);
7065 }
7066+/* }}} */
7067
7068 static void
7069-ReadImage(gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace) /*1.4//, int ignore) */
7070+ReadImage(gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace, int *ZeroDataBlockP) /*1.4//, int ignore) */
7071 {
7072- unsigned char c;
7073- int v;
7074- int xpos = 0, ypos = 0, pass = 0;
7075- int i;
7076-
7077- /*
7078- ** Initialize the Compression routines
7079- */
7080- if (! ReadOK(fd,&c,1)) {
7081- return;
7082- }
7083-
7084- if (c > MAX_LWZ_BITS) {
7085- return;
7086- }
7087-
7088-
7089- /* Stash the color map into the image */
7090- for (i=0; (i<gdMaxColors); i++) {
7091- im->red[i] = cmap[CM_RED][i];
7092- im->green[i] = cmap[CM_GREEN][i];
7093- im->blue[i] = cmap[CM_BLUE][i];
7094- im->open[i] = 1;
7095- }
7096- /* Many (perhaps most) of these colors will remain marked open. */
7097- im->colorsTotal = gdMaxColors;
7098-
7099- if (LWZReadByte(fd, TRUE, c) < 0) {
7100- return;
7101- }
7102-
7103- /*
7104- ** If this is an "uninteresting picture" ignore it.
7105- ** REMOVED For 1.4
7106- */
7107- /*if (ignore) { */
7108- /* while (LWZReadByte(fd, FALSE, c) >= 0) */
7109- /* ; */
7110- /* return; */
7111- /*} */
7112-
7113- while ((v = LWZReadByte(fd,FALSE,c)) >= 0 ) {
7114- if (v >= gdMaxColors) {
7115- v = 0;
7116+ unsigned char c;
7117+ int v;
7118+ int xpos = 0, ypos = 0, pass = 0;
7119+ int i;
7120+ LZW_STATIC_DATA sd;
7121+
7122+
7123+ /*
7124+ ** Initialize the Compression routines
7125+ */
7126+ if (! ReadOK(fd,&c,1)) {
7127+ return;
7128+ }
7129+
7130+ if (c > MAX_LWZ_BITS) {
7131+ return;
7132+ }
7133+
7134+ /* Stash the color map into the image */
7135+ for (i=0; (i<gdMaxColors); i++) {
7136+ im->red[i] = cmap[CM_RED][i];
7137+ im->green[i] = cmap[CM_GREEN][i];
7138+ im->blue[i] = cmap[CM_BLUE][i];
7139+ im->open[i] = 1;
7140+ }
7141+ /* Many (perhaps most) of these colors will remain marked open. */
7142+ im->colorsTotal = gdMaxColors;
7143+ if (LWZReadByte(fd, &sd, TRUE, c, ZeroDataBlockP) < 0) {
7144+ return;
7145+ }
7146+
7147+ /*
7148+ ** If this is an "uninteresting picture" ignore it.
7149+ ** REMOVED For 1.4
7150+ */
7151+ /*if (ignore) { */
7152+ /* while (LWZReadByte(fd, &sd, FALSE, c) >= 0) */
7153+ /* ; */
7154+ /* return; */
7155+ /*} */
7156+
7157+ while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0) {
7158+ if (v >= gdMaxColors) {
7159+ v = 0;
7160+ }
7161+ /* This how we recognize which colors are actually used. */
7162+ if (im->open[v]) {
7163+ im->open[v] = 0;
7164+ }
7165+ gdImageSetPixel(im, xpos, ypos, v);
7166+ ++xpos;
7167+ if (xpos == len) {
7168+ xpos = 0;
7169+ if (interlace) {
7170+ switch (pass) {
7171+ case 0:
7172+ case 1:
7173+ ypos += 8; break;
7174+ case 2:
7175+ ypos += 4; break;
7176+ case 3:
7177+ ypos += 2; break;
7178 }
7179- /* This how we recognize which colors are actually used. */
7180- if (im->open[v]) {
7181- im->open[v] = 0;
7182- }
7183- gdImageSetPixel(im, xpos, ypos, v);
7184- ++xpos;
7185- if (xpos == len) {
7186- xpos = 0;
7187- if (interlace) {
7188- switch (pass) {
7189- case 0:
7190- case 1:
7191- ypos += 8; break;
7192- case 2:
7193- ypos += 4; break;
7194- case 3:
7195- ypos += 2; break;
7196- }
7197-
7198- if (ypos >= height) {
7199- ++pass;
7200- switch (pass) {
7201- case 1:
7202- ypos = 4; break;
7203- case 2:
7204- ypos = 2; break;
7205- case 3:
7206- ypos = 1; break;
7207- default:
7208- goto fini;
7209- }
7210- }
7211- } else {
7212- ++ypos;
7213- }
7214- }
7215- if (ypos >= height)
7216- break;
7217- }
7218+
7219+ if (ypos >= height) {
7220+ ++pass;
7221+ switch (pass) {
7222+ case 1:
7223+ ypos = 4; break;
7224+ case 2:
7225+ ypos = 2; break;
7226+ case 3:
7227+ ypos = 1; break;
7228+ default:
7229+ goto fini;
7230+ }
7231+ }
7232+ } else {
7233+ ++ypos;
7234+ }
7235+ }
7236+ if (ypos >= height)
7237+ break;
7238+ }
7239
7240 fini:
7241- if (LWZReadByte(fd,FALSE,c)>=0) {
7242- /* Ignore extra */
7243- }
7244+ if (LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP) >=0) {
7245+ /* Ignore extra */
7246+ }
7247 }
7248-
7249+/* }}} */
7250diff -urN php-4.4.8.org/ext/gd/libgd/gd_gif_out.c php-4.4.8/ext/gd/libgd/gd_gif_out.c
7251--- php-4.4.8.org/ext/gd/libgd/gd_gif_out.c 2004-07-23 01:09:24.000000000 +0200
7252+++ php-4.4.8/ext/gd/libgd/gd_gif_out.c 2006-07-26 12:03:09.000000000 +0200
7253@@ -133,7 +133,7 @@
7254 BitsPerPixel = colorstobpp(tim->colorsTotal);
7255 /* All set, let's do it. */
7256 GIFEncode(
7257- out, tim->sx, tim->sy, interlace, 0, transparent, BitsPerPixel,
7258+ out, tim->sx, tim->sy, tim->interlace, 0, tim->transparent, BitsPerPixel,
7259 tim->red, tim->green, tim->blue, tim);
7260 if (pim) {
7261 /* Destroy palette based temporary image. */
7262@@ -264,10 +264,12 @@
7263 int ColorMapSize;
7264 int InitCodeSize;
7265 int i;
7266- GifCtx ctx;
7267+ GifCtx ctx;
7268+
7269+ memset(&ctx, 0, sizeof(ctx));
7270 ctx.Interlace = GInterlace;
7271- ctx.in_count = 1;
7272- memset(&ctx, 0, sizeof(ctx));
7273+ ctx.in_count = 1;
7274+
7275 ColorMapSize = 1 << BitsPerPixel;
7276
7277 RWidth = ctx.Width = GWidth;
7278diff -urN php-4.4.8.org/ext/gd/libgd/gd.h php-4.4.8/ext/gd/libgd/gd.h
7279--- php-4.4.8.org/ext/gd/libgd/gd.h 2004-07-23 01:09:24.000000000 +0200
7280+++ php-4.4.8/ext/gd/libgd/gd.h 2007-09-12 01:34:25.000000000 +0200
7281@@ -5,14 +5,30 @@
7282 extern "C" {
7283 #endif
7284
7285-#ifndef WIN32
7286-/* default fontpath for unix systems */
7287-#define DEFAULT_FONTPATH "/usr/X11R6/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/truetype:/usr/X11R6/lib/X11/fonts/TTF:/usr/share/fonts/TrueType:/usr/share/fonts/truetype:/usr/openwin/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/Type1:."
7288-#define PATHSEPARATOR ":"
7289-#else
7290+#ifdef HAVE_CONFIG_H
7291+#include "config.h"
7292+#endif
7293+
7294+#include "php_compat.h"
7295+
7296+#define GD_MAJOR_VERSION 2
7297+#define GD_MINOR_VERSION 0
7298+#define GD_RELEASE_VERSION 35
7299+#define GD_EXTRA_VERSION ""
7300+#define GD_VERSION_STRING "2.0.35"
7301+
7302+#ifdef NETWARE
7303+/* default fontpath for netware systems */
7304+#define DEFAULT_FONTPATH "sys:/java/nwgfx/lib/x11/fonts/ttf;."
7305+#define PATHSEPARATOR ";"
7306+#elif defined(WIN32)
7307 /* default fontpath for windows systems */
7308 #define DEFAULT_FONTPATH "c:\\winnt\\fonts;c:\\windows\\fonts;."
7309 #define PATHSEPARATOR ";"
7310+#else
7311+/* default fontpath for unix systems */
7312+#define DEFAULT_FONTPATH "/usr/X11R6/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/truetype:/usr/X11R6/lib/X11/fonts/TTF:/usr/share/fonts/TrueType:/usr/share/fonts/truetype:/usr/openwin/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/Type1:."
7313+#define PATHSEPARATOR ":"
7314 #endif
7315
7316 /* gd.h: declarations file for the graphic-draw module.
7317@@ -231,8 +247,8 @@
7318 gdImagePtr gdImageCreateFromPngCtx(gdIOCtxPtr in);
7319 gdImagePtr gdImageCreateFromWBMP(FILE *inFile);
7320 gdImagePtr gdImageCreateFromWBMPCtx(gdIOCtx *infile);
7321-gdImagePtr gdImageCreateFromJpeg(FILE *infile);
7322-gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile);
7323+gdImagePtr gdImageCreateFromJpeg(FILE *infile, int ignore_warning);
7324+gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile, int ignore_warning);
7325
7326 /* A custom data source. */
7327 /* The source function must return -1 on error, otherwise the number
7328@@ -295,6 +311,14 @@
7329 void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
7330 void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
7331
7332+/*
7333+ * The following functions are required to be called prior to the
7334+ * use of any sort of threads in a module load / shutdown function
7335+ * respectively.
7336+ */
7337+void gdFontCacheMutexSetup();
7338+void gdFontCacheMutexShutdown();
7339+
7340 /* 2.0.16: for thread-safe use of gdImageStringFT and friends,
7341 * call this before allowing any thread to call gdImageStringFT.
7342 * Otherwise it is invoked by the first thread to invoke
7343@@ -438,8 +462,8 @@
7344 * compression (smallest files) but takes a long time to compress, and
7345 * -1 selects the default compiled into the zlib library.
7346 */
7347-void gdImagePngEx(gdImagePtr im, FILE * out, int level);
7348-void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level);
7349+void gdImagePngEx(gdImagePtr im, FILE * out, int level, int basefilter);
7350+void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level, int basefilter);
7351
7352 void gdImageWBMP(gdImagePtr image, int fg, FILE *out);
7353 void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out);
7354@@ -483,7 +507,7 @@
7355
7356 /* Best to free this memory with gdFree(), not free() */
7357 void* gdImageGdPtr(gdImagePtr im, int *size);
7358-void *gdImagePngPtrEx(gdImagePtr im, int *size, int level);
7359+void *gdImagePngPtrEx(gdImagePtr im, int *size, int level, int basefilter);
7360
7361 /* Best to free this memory with gdFree(), not free() */
7362 void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size);
7363@@ -534,11 +558,11 @@
7364 substituted automatically. */
7365 void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
7366
7367-gdImagePtr gdImageRotate90(gdImagePtr src);
7368-gdImagePtr gdImageRotate180(gdImagePtr src);
7369-gdImagePtr gdImageRotate270(gdImagePtr src);
7370-gdImagePtr gdImageRotate45(gdImagePtr src, double dAngle, int clrBack);
7371-gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack);
7372+gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent);
7373+gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
7374+gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
7375+gdImagePtr gdImageRotate45(gdImagePtr src, double dAngle, int clrBack, int ignoretransparent);
7376+gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent);
7377
7378 void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
7379 void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
7380@@ -619,7 +643,7 @@
7381 int gdImageContrast(gdImagePtr src, double contrast);
7382
7383 /* Simply adds or substracts respectively red, green or blue to a pixel */
7384-int gdImageColor(gdImagePtr src, int red, int green, int blue);
7385+int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha);
7386
7387 /* Image convolution by a 3x3 custom matrix */
7388 int gdImageConvolution(gdImagePtr src, float ft[3][3], float filter_div, float offset);
7389diff -urN php-4.4.8.org/ext/gd/libgd/gdhelpers.h php-4.4.8/ext/gd/libgd/gdhelpers.h
7390--- php-4.4.8.org/ext/gd/libgd/gdhelpers.h 2007-03-10 14:06:37.000000000 +0100
7391+++ php-4.4.8/ext/gd/libgd/gdhelpers.h 2007-03-10 13:18:36.000000000 +0100
7392@@ -1,4 +1,4 @@
7393-#ifndef GDHELPERS_H
7394+#ifndef GDHELPERS_H
7395 #define GDHELPERS_H 1
7396
7397 #include <sys/types.h>
7398diff -urN php-4.4.8.org/ext/gd/libgd/gd_io.c php-4.4.8/ext/gd/libgd/gd_io.c
7399--- php-4.4.8.org/ext/gd/libgd/gd_io.c 2003-12-25 23:33:03.000000000 +0100
7400+++ php-4.4.8/ext/gd/libgd/gd_io.c 2005-08-18 14:54:43.000000000 +0200
7401@@ -23,153 +23,124 @@
7402 #define IO_DBG(s)
7403
7404
7405+#define GD_IO_EOF_CHK(r) \
7406+ if (r == EOF) { \
7407+ return 0; \
7408+ } \
7409+
7410 /*
7411 * Write out a word to the I/O context pointer
7412 */
7413-void
7414-Putword (int w, gdIOCtx * ctx)
7415+void Putword (int w, gdIOCtx * ctx)
7416 {
7417- unsigned char buf[2];
7418- buf[0] = w & 0xff;
7419- buf[1] = (w / 256) & 0xff;
7420- (ctx->putBuf) (ctx, (char *) buf, 2);
7421+ unsigned char buf[2];
7422+
7423+ buf[0] = w & 0xff;
7424+ buf[1] = (w / 256) & 0xff;
7425+ (ctx->putBuf) (ctx, (char *) buf, 2);
7426 }
7427
7428-void
7429-Putchar (int c, gdIOCtx * ctx)
7430+void Putchar (int c, gdIOCtx * ctx)
7431 {
7432- (ctx->putC) (ctx, c & 0xff);
7433+ (ctx->putC) (ctx, c & 0xff);
7434 }
7435
7436-void
7437-gdPutC (const unsigned char c, gdIOCtx * ctx)
7438+void gdPutC (const unsigned char c, gdIOCtx * ctx)
7439 {
7440- (ctx->putC) (ctx, c);
7441+ (ctx->putC) (ctx, c);
7442 }
7443
7444-void
7445-gdPutWord (int w, gdIOCtx * ctx)
7446+void gdPutWord (int w, gdIOCtx * ctx)
7447 {
7448- IO_DBG (printf ("Putting word...\n"));
7449- (ctx->putC) (ctx, (unsigned char) (w >> 8));
7450- (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
7451- IO_DBG (printf ("put.\n"));
7452+ IO_DBG (php_gd_error("Putting word..."));
7453+ (ctx->putC) (ctx, (unsigned char) (w >> 8));
7454+ (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
7455+ IO_DBG (php_gd_error("put."));
7456 }
7457
7458-void
7459-gdPutInt (int w, gdIOCtx * ctx)
7460+void gdPutInt (int w, gdIOCtx * ctx)
7461 {
7462- IO_DBG (printf ("Putting int...\n"));
7463- (ctx->putC) (ctx, (unsigned char) (w >> 24));
7464- (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF));
7465- (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF));
7466- (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
7467- IO_DBG (printf ("put.\n"));
7468+ IO_DBG (php_gd_error("Putting int..."));
7469+ (ctx->putC) (ctx, (unsigned char) (w >> 24));
7470+ (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF));
7471+ (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF));
7472+ (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
7473+ IO_DBG (php_gd_error("put."));
7474 }
7475
7476-int
7477-gdGetC (gdIOCtx * ctx)
7478+int gdGetC (gdIOCtx * ctx)
7479 {
7480- return ((ctx->getC) (ctx));
7481+ return ((ctx->getC) (ctx));
7482 }
7483
7484-
7485-
7486-int
7487-gdGetByte (int *result, gdIOCtx * ctx)
7488+int gdGetByte (int *result, gdIOCtx * ctx)
7489 {
7490- int r;
7491- r = (ctx->getC) (ctx);
7492- if (r == EOF)
7493- {
7494- return 0;
7495- }
7496- *result = r;
7497- return 1;
7498+ int r;
7499+ r = (ctx->getC) (ctx);
7500+ GD_IO_EOF_CHK(r);
7501+ *result = r;
7502+ return 1;
7503 }
7504
7505-int
7506-gdGetWord (int *result, gdIOCtx * ctx)
7507+int gdGetWord (int *result, gdIOCtx * ctx)
7508 {
7509- int r;
7510- r = (ctx->getC) (ctx);
7511- if (r == EOF)
7512- {
7513- return 0;
7514- }
7515- *result = r << 8;
7516- r = (ctx->getC) (ctx);
7517- if (r == EOF)
7518- {
7519- return 0;
7520- }
7521- *result += r;
7522- return 1;
7523+ int r;
7524+ r = (ctx->getC) (ctx);
7525+ GD_IO_EOF_CHK(r);
7526+ *result = r << 8;
7527+ r = (ctx->getC) (ctx);
7528+ GD_IO_EOF_CHK(r);
7529+ *result += r;
7530+ return 1;
7531 }
7532
7533
7534-int
7535-gdGetInt (int *result, gdIOCtx * ctx)
7536+int gdGetInt (int *result, gdIOCtx * ctx)
7537 {
7538- int r;
7539- r = (ctx->getC) (ctx);
7540- if (r == EOF)
7541- {
7542- return 0;
7543- }
7544- *result = r << 24;
7545+ int r;
7546+ r = (ctx->getC) (ctx);
7547+ GD_IO_EOF_CHK(r);
7548+ *result = r << 24;
7549
7550- r = (ctx->getC) (ctx);
7551- if (r == EOF)
7552- {
7553- return 0;
7554- }
7555- *result += r << 16;
7556+ r = (ctx->getC) (ctx);
7557+ GD_IO_EOF_CHK(r);
7558+ *result += r << 16;
7559
7560- r = (ctx->getC) (ctx);
7561- if (r == EOF)
7562- {
7563- return 0;
7564- }
7565- *result += r << 8;
7566+ r = (ctx->getC) (ctx);
7567+ if (r == EOF) {
7568+ return 0;
7569+ }
7570+ *result += r << 8;
7571
7572- r = (ctx->getC) (ctx);
7573- if (r == EOF)
7574- {
7575- return 0;
7576- }
7577- *result += r;
7578+ r = (ctx->getC) (ctx);
7579+ GD_IO_EOF_CHK(r);
7580+ *result += r;
7581
7582- return 1;
7583+ return 1;
7584 }
7585
7586-int
7587-gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
7588+int gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
7589 {
7590- IO_DBG (printf ("Putting buf...\n"));
7591- return (ctx->putBuf) (ctx, buf, size);
7592- IO_DBG (printf ("put.\n"));
7593+ IO_DBG (php_gd_error("Putting buf..."));
7594+ return (ctx->putBuf) (ctx, buf, size);
7595+ IO_DBG (php_gd_error("put."));
7596 }
7597
7598-int
7599-gdGetBuf (void *buf, int size, gdIOCtx * ctx)
7600+int gdGetBuf (void *buf, int size, gdIOCtx * ctx)
7601 {
7602- return (ctx->getBuf) (ctx, buf, size);
7603+ return (ctx->getBuf) (ctx, buf, size);
7604 }
7605
7606-
7607-int
7608-gdSeek (gdIOCtx * ctx, const int pos)
7609+int gdSeek (gdIOCtx * ctx, const int pos)
7610 {
7611- IO_DBG (printf ("Seeking...\n"));
7612- return ((ctx->seek) (ctx, pos));
7613- IO_DBG (printf ("Done.\n"));
7614+ IO_DBG (php_gd_error("Seeking..."));
7615+ return ((ctx->seek) (ctx, pos));
7616+ IO_DBG (php_gd_error("Done."));
7617 }
7618
7619-long
7620-gdTell (gdIOCtx * ctx)
7621+long gdTell (gdIOCtx * ctx)
7622 {
7623- IO_DBG (printf ("Telling...\n"));
7624- return ((ctx->tell) (ctx));
7625- IO_DBG (printf ("told.\n"));
7626+ IO_DBG (php_gd_error("Telling..."));
7627+ return ((ctx->tell) (ctx));
7628+ IO_DBG (php_gd_error ("told."));
7629 }
7630diff -urN php-4.4.8.org/ext/gd/libgd/gd_io_dp.c php-4.4.8/ext/gd/libgd/gd_io_dp.c
7631--- php-4.4.8.org/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:21:00.000000000 +0200
7632+++ php-4.4.8/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:20:33.000000000 +0200
7633@@ -27,26 +27,23 @@
7634
7635 /* this is used for creating images in main memory */
7636 typedef struct dpStruct
7637- {
7638- void *data;
7639- int logicalSize;
7640- int realSize;
7641- int dataGood;
7642- int pos;
7643- int freeOK;
7644- }
7645-dynamicPtr;
7646+{
7647+ void *data;
7648+ int logicalSize;
7649+ int realSize;
7650+ int dataGood;
7651+ int pos;
7652+ int freeOK;
7653+} dynamicPtr;
7654
7655 typedef struct dpIOCtx
7656- {
7657- gdIOCtx ctx;
7658- dynamicPtr *dp;
7659- }
7660-dpIOCtx;
7661+{
7662+ gdIOCtx ctx;
7663+ dynamicPtr *dp;
7664+} dpIOCtx;
7665
7666 typedef struct dpIOCtx *dpIOCtxPtr;
7667
7668-
7669 /* these functions operate on in-memory dynamic pointers */
7670 static int allocDynamic (dynamicPtr * dp, int initialSize, void *data);
7671 static int appendDynamic (dynamicPtr * dp, const void *src, int size);
7672@@ -65,166 +62,136 @@
7673 static long dynamicTell (struct gdIOCtx *);
7674
7675 /* return data as a dynamic pointer */
7676-gdIOCtx *
7677-gdNewDynamicCtx (int initialSize, void *data)
7678+gdIOCtx * gdNewDynamicCtx (int initialSize, void *data)
7679 {
7680- return gdNewDynamicCtxEx(initialSize, data, 1);
7681+ return gdNewDynamicCtxEx(initialSize, data, 1);
7682 }
7683-
7684+
7685 gdIOCtx * gdNewDynamicCtxEx (int initialSize, void *data, int freeOKFlag)
7686 {
7687- dpIOCtx *ctx;
7688- dynamicPtr *dp;
7689+ dpIOCtx *ctx;
7690+ dynamicPtr *dp;
7691
7692- ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx));
7693- if (ctx == NULL)
7694- {
7695- return NULL;
7696- }
7697+ ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx));
7698
7699- dp = newDynamic (initialSize, data, freeOKFlag);
7700- if (!dp)
7701- {
7702- gdFree (ctx);
7703- return NULL;
7704- };
7705+ dp = newDynamic(initialSize, data, freeOKFlag);
7706
7707- ctx->dp = dp;
7708+ ctx->dp = dp;
7709
7710- ctx->ctx.getC = dynamicGetchar;
7711- ctx->ctx.putC = dynamicPutchar;
7712+ ctx->ctx.getC = dynamicGetchar;
7713+ ctx->ctx.putC = dynamicPutchar;
7714
7715- ctx->ctx.getBuf = dynamicGetbuf;
7716- ctx->ctx.putBuf = dynamicPutbuf;
7717+ ctx->ctx.getBuf = dynamicGetbuf;
7718+ ctx->ctx.putBuf = dynamicPutbuf;
7719
7720- ctx->ctx.seek = dynamicSeek;
7721- ctx->ctx.tell = dynamicTell;
7722+ ctx->ctx.seek = dynamicSeek;
7723+ ctx->ctx.tell = dynamicTell;
7724
7725- ctx->ctx.gd_free = gdFreeDynamicCtx;
7726+ ctx->ctx.gd_free = gdFreeDynamicCtx;
7727
7728- return (gdIOCtx *) ctx;
7729+ return (gdIOCtx *) ctx;
7730 }
7731
7732-void *
7733-gdDPExtractData (struct gdIOCtx *ctx, int *size)
7734+void * gdDPExtractData (struct gdIOCtx *ctx, int *size)
7735 {
7736- dynamicPtr *dp;
7737- dpIOCtx *dctx;
7738- void *data;
7739+ dynamicPtr *dp;
7740+ dpIOCtx *dctx;
7741+ void *data;
7742
7743- dctx = (dpIOCtx *) ctx;
7744- dp = dctx->dp;
7745+ dctx = (dpIOCtx *) ctx;
7746+ dp = dctx->dp;
7747
7748- /* clean up the data block and return it */
7749- if (dp->dataGood)
7750- {
7751- trimDynamic (dp);
7752- *size = dp->logicalSize;
7753- data = dp->data;
7754- }
7755- else
7756- {
7757- *size = 0;
7758- data = NULL;
7759- if (dp->data != NULL && dp->freeOK)
7760- {
7761- gdFree (dp->data);
7762+ /* clean up the data block and return it */
7763+ if (dp->dataGood) {
7764+ trimDynamic (dp);
7765+ *size = dp->logicalSize;
7766+ data = dp->data;
7767+ } else {
7768+ *size = 0;
7769+ data = NULL;
7770+ if (dp->data != NULL && dp->freeOK) {
7771+ gdFree(dp->data);
7772+ }
7773 }
7774- }
7775
7776- dp->data = NULL;
7777- dp->realSize = 0;
7778- dp->logicalSize = 0;
7779+ dp->data = NULL;
7780+ dp->realSize = 0;
7781+ dp->logicalSize = 0;
7782
7783- return data;
7784+ return data;
7785 }
7786
7787-static
7788-void
7789-gdFreeDynamicCtx (struct gdIOCtx *ctx)
7790+static void gdFreeDynamicCtx (struct gdIOCtx *ctx)
7791 {
7792- dynamicPtr *dp;
7793- dpIOCtx *dctx;
7794-
7795- dctx = (dpIOCtx *) ctx;
7796- dp = dctx->dp;
7797+ dynamicPtr *dp;
7798+ dpIOCtx *dctx;
7799
7800- gdFree (ctx);
7801+ dctx = (dpIOCtx *) ctx;
7802+ dp = dctx->dp;
7803
7804- dp->realSize = 0;
7805- dp->logicalSize = 0;
7806+ gdFree(ctx);
7807
7808- gdFree (dp);
7809+ dp->realSize = 0;
7810+ dp->logicalSize = 0;
7811
7812+ gdFree(dp);
7813 }
7814
7815-static long
7816-dynamicTell (struct gdIOCtx *ctx)
7817+static long dynamicTell (struct gdIOCtx *ctx)
7818 {
7819- dpIOCtx *dctx;
7820+ dpIOCtx *dctx;
7821
7822- dctx = (dpIOCtx *) ctx;
7823- return (dctx->dp->pos);
7824+ dctx = (dpIOCtx *) ctx;
7825+
7826+ return (dctx->dp->pos);
7827 }
7828
7829-static int
7830-dynamicSeek (struct gdIOCtx *ctx, const int pos)
7831+static int dynamicSeek (struct gdIOCtx *ctx, const int pos)
7832 {
7833- int bytesNeeded;
7834- dynamicPtr *dp;
7835- dpIOCtx *dctx;
7836+ int bytesNeeded;
7837+ dynamicPtr *dp;
7838+ dpIOCtx *dctx;
7839
7840- dctx = (dpIOCtx *) ctx;
7841- dp = dctx->dp;
7842+ dctx = (dpIOCtx *) ctx;
7843+ dp = dctx->dp;
7844
7845- if (!dp->dataGood)
7846- return FALSE;
7847+ if (!dp->dataGood) {
7848+ return FALSE;
7849+ }
7850
7851- bytesNeeded = pos;
7852- if (bytesNeeded > dp->realSize)
7853- {
7854- /* 2.0.21 */
7855- if (!dp->freeOK) {
7856- return FALSE;
7857- }
7858- if (!gdReallocDynamic (dp, dp->realSize * 2))
7859- {
7860- dp->dataGood = FALSE;
7861- return FALSE;
7862+ bytesNeeded = pos;
7863+ if (bytesNeeded > dp->realSize) {
7864+ /* 2.0.21 */
7865+ if (!dp->freeOK) {
7866+ return FALSE;
7867+ }
7868+ gdReallocDynamic (dp, dp->realSize * 2);
7869 }
7870- }
7871
7872- /* if we get here, we can be sure that we have enough bytes
7873- to copy safely */
7874+ /* if we get here, we can be sure that we have enough bytes to copy safely */
7875
7876- /* Extend the logical size if we seek beyond EOF. */
7877- if (pos > dp->logicalSize)
7878- {
7879- dp->logicalSize = pos;
7880- };
7881+ /* Extend the logical size if we seek beyond EOF. */
7882+ if (pos > dp->logicalSize) {
7883+ dp->logicalSize = pos;
7884+ }
7885
7886- dp->pos = pos;
7887+ dp->pos = pos;
7888
7889- return TRUE;
7890+ return TRUE;
7891 }
7892
7893 /* return data as a dynamic pointer */
7894 static dynamicPtr * newDynamic (int initialSize, void *data, int freeOKFlag)
7895 {
7896- dynamicPtr *dp;
7897- dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr));
7898- if (dp == NULL)
7899- {
7900- return NULL;
7901- }
7902+ dynamicPtr *dp;
7903+ dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr));
7904
7905- if (!allocDynamic (dp, initialSize, data))
7906- return NULL;
7907+ allocDynamic (dp, initialSize, data);
7908
7909- dp->pos = 0;
7910- dp->freeOK = freeOKFlag;
7911+ dp->pos = 0;
7912+ dp->freeOK = freeOKFlag;
7913
7914- return dp;
7915+ return dp;
7916 }
7917
7918 static int
7919@@ -246,64 +213,53 @@
7920
7921 }
7922
7923-static void
7924-dynamicPutchar (struct gdIOCtx *ctx, int a)
7925+static void dynamicPutchar (struct gdIOCtx *ctx, int a)
7926 {
7927- unsigned char b;
7928- dpIOCtxPtr dctx;
7929+ unsigned char b;
7930+ dpIOCtxPtr dctx;
7931
7932- b = a;
7933- dctx = (dpIOCtxPtr) ctx;
7934+ b = a;
7935+ dctx = (dpIOCtxPtr) ctx;
7936
7937- appendDynamic (dctx->dp, &b, 1);
7938+ appendDynamic(dctx->dp, &b, 1);
7939 }
7940
7941-static int
7942-dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len)
7943+static int dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len)
7944 {
7945- int rlen, remain;
7946- dpIOCtxPtr dctx;
7947- dynamicPtr *dp;
7948+ int rlen, remain;
7949+ dpIOCtxPtr dctx;
7950+ dynamicPtr *dp;
7951
7952- dctx = (dpIOCtxPtr) ctx;
7953- dp = dctx->dp;
7954+ dctx = (dpIOCtxPtr) ctx;
7955+ dp = dctx->dp;
7956
7957- remain = dp->logicalSize - dp->pos;
7958- if (remain >= len)
7959- {
7960- rlen = len;
7961- }
7962- else
7963- {
7964- if (remain == 0)
7965- {
7966- return EOF;
7967+ remain = dp->logicalSize - dp->pos;
7968+ if (remain >= len) {
7969+ rlen = len;
7970+ } else {
7971+ if (remain == 0) {
7972+ return EOF;
7973+ }
7974+ rlen = remain;
7975 }
7976- rlen = remain;
7977- }
7978
7979- memcpy (buf, (void *) ((char *) dp->data + dp->pos), rlen);
7980- dp->pos += rlen;
7981+ memcpy(buf, (void *) ((char *) dp->data + dp->pos), rlen);
7982+ dp->pos += rlen;
7983
7984- return rlen;
7985+ return rlen;
7986 }
7987
7988-static int
7989-dynamicGetchar (gdIOCtxPtr ctx)
7990+static int dynamicGetchar (gdIOCtxPtr ctx)
7991 {
7992- unsigned char b;
7993- int rv;
7994-
7995- rv = dynamicGetbuf (ctx, &b, 1);
7996+ unsigned char b;
7997+ int rv;
7998
7999- if (rv != 1)
8000- {
8001- return EOF;
8002- }
8003- else
8004- {
8005- return b; /* (b & 0xff); */
8006- }
8007+ rv = dynamicGetbuf (ctx, &b, 1);
8008+ if (rv != 1) {
8009+ return EOF;
8010+ } else {
8011+ return b; /* (b & 0xff); */
8012+ }
8013 }
8014
8015 /* *********************************************************************
8016@@ -316,114 +272,89 @@
8017 allocDynamic (dynamicPtr * dp, int initialSize, void *data)
8018 {
8019
8020- if (data == NULL)
8021- {
8022- dp->logicalSize = 0;
8023- dp->dataGood = FALSE;
8024- dp->data = gdMalloc (initialSize);
8025- }
8026- else
8027- {
8028- dp->logicalSize = initialSize;
8029- dp->dataGood = TRUE;
8030- dp->data = data;
8031- }
8032+ if (data == NULL) {
8033+ dp->logicalSize = 0;
8034+ dp->dataGood = FALSE;
8035+ dp->data = gdMalloc(initialSize);
8036+ } else {
8037+ dp->logicalSize = initialSize;
8038+ dp->dataGood = TRUE;
8039+ dp->data = data;
8040+ }
8041
8042- if (dp->data != NULL)
8043- {
8044- dp->realSize = initialSize;
8045- dp->dataGood = TRUE;
8046- dp->pos = 0;
8047- return TRUE;
8048- }
8049- else
8050- {
8051- dp->realSize = 0;
8052- return FALSE;
8053- }
8054+ dp->realSize = initialSize;
8055+ dp->dataGood = TRUE;
8056+ dp->pos = 0;
8057+
8058+ return TRUE;
8059 }
8060
8061 /* append bytes to the end of a dynamic pointer */
8062-static int
8063-appendDynamic (dynamicPtr * dp, const void *src, int size)
8064+static int appendDynamic (dynamicPtr * dp, const void *src, int size)
8065 {
8066- int bytesNeeded;
8067- char *tmp;
8068+ int bytesNeeded;
8069+ char *tmp;
8070
8071- if (!dp->dataGood)
8072- return FALSE;
8073+ if (!dp->dataGood) {
8074+ return FALSE;
8075+ }
8076
8077-/* bytesNeeded = dp->logicalSize + size; */
8078- bytesNeeded = dp->pos + size;
8079+ /* bytesNeeded = dp->logicalSize + size; */
8080+ bytesNeeded = dp->pos + size;
8081
8082- if (bytesNeeded > dp->realSize)
8083- {
8084+ if (bytesNeeded > dp->realSize) {
8085 /* 2.0.21 */
8086 if (!dp->freeOK) {
8087 return FALSE;
8088 }
8089- if (!gdReallocDynamic (dp, bytesNeeded * 2))
8090- {
8091- dp->dataGood = FALSE;
8092- return FALSE;
8093+ gdReallocDynamic(dp, bytesNeeded * 2);
8094 }
8095- }
8096
8097- /* if we get here, we can be sure that we have enough bytes
8098- to copy safely */
8099- /*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */
8100-
8101- tmp = (char *) dp->data;
8102- memcpy ((void *) (tmp + (dp->pos)), src, size);
8103- dp->pos += size;
8104+ /* if we get here, we can be sure that we have enough bytes to copy safely */
8105+ /*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */
8106
8107- if (dp->pos > dp->logicalSize)
8108- {
8109- dp->logicalSize = dp->pos;
8110- };
8111+ tmp = (char *) dp->data;
8112+ memcpy((void *) (tmp + (dp->pos)), src, size);
8113+ dp->pos += size;
8114+
8115+ if (dp->pos > dp->logicalSize) {
8116+ dp->logicalSize = dp->pos;
8117+ }
8118
8119- return TRUE;
8120+ return TRUE;
8121 }
8122
8123 /* grow (or shrink) dynamic pointer */
8124-static int
8125-gdReallocDynamic (dynamicPtr * dp, int required)
8126+static int gdReallocDynamic (dynamicPtr * dp, int required)
8127 {
8128- void *newPtr;
8129+ void *newPtr;
8130
8131- /* First try gdRealloc(). If that doesn't work, make a new
8132- memory block and copy. */
8133- if ((newPtr = gdRealloc (dp->data, required)))
8134- {
8135- dp->realSize = required;
8136- dp->data = newPtr;
8137- return TRUE;
8138- }
8139+ /* First try gdRealloc(). If that doesn't work, make a new memory block and copy. */
8140+ if ((newPtr = gdRealloc(dp->data, required))) {
8141+ dp->realSize = required;
8142+ dp->data = newPtr;
8143+ return TRUE;
8144+ }
8145
8146- /* create a new pointer */
8147- newPtr = gdMalloc (required);
8148- if (!newPtr)
8149- {
8150- dp->dataGood = FALSE;
8151- return FALSE;
8152- }
8153+ /* create a new pointer */
8154+ newPtr = gdMalloc(required);
8155+
8156+ /* copy the old data into it */
8157+ memcpy(newPtr, dp->data, dp->logicalSize);
8158+ gdFree(dp->data);
8159+ dp->data = newPtr;
8160
8161- /* copy the old data into it */
8162- memcpy (newPtr, dp->data, dp->logicalSize);
8163- gdFree (dp->data);
8164- dp->data = newPtr;
8165+ dp->realSize = required;
8166
8167- dp->realSize = required;
8168- return TRUE;
8169+ return TRUE;
8170 }
8171
8172 /* trim pointer so that its real and logical sizes match */
8173-static int
8174-trimDynamic (dynamicPtr * dp)
8175+static int trimDynamic (dynamicPtr * dp)
8176 {
8177- /* 2.0.21: we don't reallocate memory we don't own */
8178- if (!dp->freeOK) {
8179- return FALSE;
8180- }
8181- return gdReallocDynamic (dp, dp->logicalSize);
8182+ /* 2.0.21: we don't reallocate memory we don't own */
8183+ if (!dp->freeOK) {
8184+ return FALSE;
8185+ }
8186+ return gdReallocDynamic(dp, dp->logicalSize);
8187 }
8188diff -urN php-4.4.8.org/ext/gd/libgd/gd_io_file.c php-4.4.8/ext/gd/libgd/gd_io_file.c
8189--- php-4.4.8.org/ext/gd/libgd/gd_io_file.c 2003-12-25 23:33:03.000000000 +0100
8190+++ php-4.4.8/ext/gd/libgd/gd_io_file.c 2003-12-25 23:12:12.000000000 +0100
8191@@ -29,11 +29,10 @@
8192 /* this is used for creating images in main memory */
8193
8194 typedef struct fileIOCtx
8195- {
8196- gdIOCtx ctx;
8197- FILE *f;
8198- }
8199-fileIOCtx;
8200+{
8201+ gdIOCtx ctx;
8202+ FILE *f;
8203+} fileIOCtx;
8204
8205 gdIOCtx *newFileCtx (FILE * f);
8206
8207@@ -47,97 +46,83 @@
8208 static void gdFreeFileCtx (gdIOCtx * ctx);
8209
8210 /* return data as a dynamic pointer */
8211-gdIOCtx *
8212-gdNewFileCtx (FILE * f)
8213+gdIOCtx * gdNewFileCtx (FILE * f)
8214 {
8215- fileIOCtx *ctx;
8216+ fileIOCtx *ctx;
8217
8218- ctx = (fileIOCtx *) gdMalloc (sizeof (fileIOCtx));
8219- if (ctx == NULL)
8220- {
8221- return NULL;
8222- }
8223+ ctx = (fileIOCtx *) gdMalloc(sizeof (fileIOCtx));
8224
8225- ctx->f = f;
8226+ ctx->f = f;
8227
8228- ctx->ctx.getC = fileGetchar;
8229- ctx->ctx.putC = filePutchar;
8230+ ctx->ctx.getC = fileGetchar;
8231+ ctx->ctx.putC = filePutchar;
8232
8233- ctx->ctx.getBuf = fileGetbuf;
8234- ctx->ctx.putBuf = filePutbuf;
8235+ ctx->ctx.getBuf = fileGetbuf;
8236+ ctx->ctx.putBuf = filePutbuf;
8237
8238- ctx->ctx.tell = fileTell;
8239- ctx->ctx.seek = fileSeek;
8240+ ctx->ctx.tell = fileTell;
8241+ ctx->ctx.seek = fileSeek;
8242
8243- ctx->ctx.gd_free = gdFreeFileCtx;
8244+ ctx->ctx.gd_free = gdFreeFileCtx;
8245
8246- return (gdIOCtx *) ctx;
8247+ return (gdIOCtx *) ctx;
8248 }
8249
8250-static
8251-void
8252-gdFreeFileCtx (gdIOCtx * ctx)
8253+static void gdFreeFileCtx (gdIOCtx * ctx)
8254 {
8255- gdFree (ctx);
8256+ gdFree(ctx);
8257 }
8258
8259
8260-static int
8261-filePutbuf (gdIOCtx * ctx, const void *buf, int size)
8262+static int filePutbuf (gdIOCtx * ctx, const void *buf, int size)
8263 {
8264- fileIOCtx *fctx;
8265- fctx = (fileIOCtx *) ctx;
8266+ fileIOCtx *fctx;
8267+ fctx = (fileIOCtx *) ctx;
8268
8269- return fwrite (buf, 1, size, fctx->f);
8270+ return fwrite(buf, 1, size, fctx->f);
8271
8272 }
8273
8274-static int
8275-fileGetbuf (gdIOCtx * ctx, void *buf, int size)
8276+static int fileGetbuf (gdIOCtx * ctx, void *buf, int size)
8277 {
8278- fileIOCtx *fctx;
8279- fctx = (fileIOCtx *) ctx;
8280-
8281- return (fread (buf, 1, size, fctx->f));
8282+ fileIOCtx *fctx;
8283+ fctx = (fileIOCtx *) ctx;
8284
8285+ return fread(buf, 1, size, fctx->f);
8286 }
8287
8288-static void
8289-filePutchar (gdIOCtx * ctx, int a)
8290+static void filePutchar (gdIOCtx * ctx, int a)
8291 {
8292- unsigned char b;
8293- fileIOCtx *fctx;
8294- fctx = (fileIOCtx *) ctx;
8295+ unsigned char b;
8296+ fileIOCtx *fctx;
8297+ fctx = (fileIOCtx *) ctx;
8298
8299- b = a;
8300+ b = a;
8301
8302- putc (b, fctx->f);
8303+ putc (b, fctx->f);
8304 }
8305
8306-static int
8307-fileGetchar (gdIOCtx * ctx)
8308+static int fileGetchar (gdIOCtx * ctx)
8309 {
8310- fileIOCtx *fctx;
8311- fctx = (fileIOCtx *) ctx;
8312+ fileIOCtx *fctx;
8313+ fctx = (fileIOCtx *) ctx;
8314
8315- return getc (fctx->f);
8316+ return getc (fctx->f);
8317 }
8318
8319
8320-static int
8321-fileSeek (struct gdIOCtx *ctx, const int pos)
8322+static int fileSeek (struct gdIOCtx *ctx, const int pos)
8323 {
8324- fileIOCtx *fctx;
8325- fctx = (fileIOCtx *) ctx;
8326+ fileIOCtx *fctx;
8327+ fctx = (fileIOCtx *) ctx;
8328
8329- return (fseek (fctx->f, pos, SEEK_SET) == 0);
8330+ return (fseek (fctx->f, pos, SEEK_SET) == 0);
8331 }
8332
8333-static long
8334-fileTell (struct gdIOCtx *ctx)
8335+static long fileTell (struct gdIOCtx *ctx)
8336 {
8337- fileIOCtx *fctx;
8338- fctx = (fileIOCtx *) ctx;
8339+ fileIOCtx *fctx;
8340+ fctx = (fileIOCtx *) ctx;
8341
8342- return ftell (fctx->f);
8343+ return ftell (fctx->f);
8344 }
8345diff -urN php-4.4.8.org/ext/gd/libgd/gd_io.h php-4.4.8/ext/gd/libgd/gd_io.h
8346--- php-4.4.8.org/ext/gd/libgd/gd_io.h 2003-04-05 19:24:16.000000000 +0200
8347+++ php-4.4.8/ext/gd/libgd/gd_io.h 2003-12-28 21:11:08.000000000 +0100
8348@@ -6,18 +6,18 @@
8349 #ifdef VMS
8350 #define Putchar gdPutchar
8351 #endif
8352-
8353+
8354 typedef struct gdIOCtx {
8355 int (*getC)(struct gdIOCtx*);
8356 int (*getBuf)(struct gdIOCtx*, void*, int);
8357
8358- void (*putC)(struct gdIOCtx*, int);
8359+ void (*putC)(struct gdIOCtx*, int);
8360 int (*putBuf)(struct gdIOCtx*, const void*, int);
8361
8362 int (*seek)(struct gdIOCtx*, const int);
8363 long (*tell)(struct gdIOCtx*);
8364
8365- void (*gd_free)(struct gdIOCtx*);
8366+ void (*gd_free)(struct gdIOCtx*);
8367
8368 } gdIOCtx;
8369
8370diff -urN php-4.4.8.org/ext/gd/libgd/gd_io_ss.c php-4.4.8/ext/gd/libgd/gd_io_ss.c
8371--- php-4.4.8.org/ext/gd/libgd/gd_io_ss.c 2002-10-30 00:08:01.000000000 +0100
8372+++ php-4.4.8/ext/gd/libgd/gd_io_ss.c 2003-12-28 21:11:08.000000000 +0100
8373@@ -12,7 +12,7 @@
8374 * used internally until it settles down a bit.
8375 *
8376 * This module just layers the Source/Sink interface on top of the IOCtx; no
8377- * support is provided for tell/seek, so GD2 writing is not possible, and
8378+ * support is provided for tell/seek, so GD2 writing is not possible, and
8379 * retrieving parts of GD2 files is also not possible.
8380 *
8381 * A new SS context does not need to be created with both a Source and a Sink.
8382@@ -30,12 +30,11 @@
8383 /* this is used for creating images in main memory */
8384
8385 typedef struct ssIOCtx
8386- {
8387- gdIOCtx ctx;
8388- gdSourcePtr src;
8389- gdSinkPtr snk;
8390- }
8391-ssIOCtx;
8392+{
8393+ gdIOCtx ctx;
8394+ gdSourcePtr src;
8395+ gdSinkPtr snk;
8396+} ssIOCtx;
8397
8398 typedef struct ssIOCtx *ssIOCtxPtr;
8399
8400@@ -48,118 +47,92 @@
8401 static void gdFreeSsCtx (gdIOCtx * ctx);
8402
8403 /* return data as a dynamic pointer */
8404-gdIOCtx *
8405-gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk)
8406+gdIOCtx * gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk)
8407 {
8408- ssIOCtxPtr ctx;
8409+ ssIOCtxPtr ctx;
8410
8411- ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx));
8412- if (ctx == NULL)
8413- {
8414- return NULL;
8415- }
8416+ ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx));
8417
8418- ctx->src = src;
8419- ctx->snk = snk;
8420+ ctx->src = src;
8421+ ctx->snk = snk;
8422
8423- ctx->ctx.getC = sourceGetchar;
8424- ctx->ctx.getBuf = sourceGetbuf;
8425+ ctx->ctx.getC = sourceGetchar;
8426+ ctx->ctx.getBuf = sourceGetbuf;
8427
8428- ctx->ctx.putC = sinkPutchar;
8429- ctx->ctx.putBuf = sinkPutbuf;
8430+ ctx->ctx.putC = sinkPutchar;
8431+ ctx->ctx.putBuf = sinkPutbuf;
8432
8433- ctx->ctx.tell = NULL;
8434- ctx->ctx.seek = NULL;
8435+ ctx->ctx.tell = NULL;
8436+ ctx->ctx.seek = NULL;
8437
8438- ctx->ctx.gd_free = gdFreeSsCtx;
8439+ ctx->ctx.gd_free = gdFreeSsCtx;
8440
8441- return (gdIOCtx *) ctx;
8442+ return (gdIOCtx *) ctx;
8443 }
8444
8445-static
8446-void
8447-gdFreeSsCtx (gdIOCtx * ctx)
8448+static void gdFreeSsCtx (gdIOCtx * ctx)
8449 {
8450- gdFree (ctx);
8451+ gdFree(ctx);
8452 }
8453
8454
8455-static int
8456-sourceGetbuf (gdIOCtx * ctx, void *buf, int size)
8457+static int sourceGetbuf (gdIOCtx * ctx, void *buf, int size)
8458 {
8459- ssIOCtx *lctx;
8460- int res;
8461-
8462- lctx = (ssIOCtx *) ctx;
8463+ ssIOCtx *lctx;
8464+ int res;
8465
8466- res = ((lctx->src->source) (lctx->src->context, buf, size));
8467+ lctx = (ssIOCtx *) ctx;
8468
8469-/*
8470- ** Translate the return values from the Source object:
8471- ** 0 is EOF, -1 is error
8472- */
8473+ res = ((lctx->src->source) (lctx->src->context, buf, size));
8474
8475- if (res == 0)
8476- {
8477- return EOF;
8478- }
8479- else if (res < 0)
8480- {
8481- return 0;
8482- }
8483- else
8484- {
8485- return res;
8486- };
8487+ /*
8488+ * Translate the return values from the Source object:
8489+ * 0 is EOF, -1 is error
8490+ */
8491
8492+ if (res == 0) {
8493+ return EOF;
8494+ } else if (res < 0) {
8495+ return 0;
8496+ } else {
8497+ return res;
8498+ }
8499 }
8500
8501-static int
8502-sourceGetchar (gdIOCtx * ctx)
8503+static int sourceGetchar (gdIOCtx * ctx)
8504 {
8505- int res;
8506- unsigned char buf;
8507+ int res;
8508+ unsigned char buf;
8509
8510- res = sourceGetbuf (ctx, &buf, 1);
8511-
8512- if (res == 1)
8513- {
8514- return buf;
8515- }
8516- else
8517- {
8518- return EOF;
8519- };
8520+ res = sourceGetbuf (ctx, &buf, 1);
8521
8522+ if (res == 1) {
8523+ return buf;
8524+ } else {
8525+ return EOF;
8526+ }
8527 }
8528
8529-static int
8530-sinkPutbuf (gdIOCtx * ctx, const void *buf, int size)
8531+static int sinkPutbuf (gdIOCtx * ctx, const void *buf, int size)
8532 {
8533- ssIOCtxPtr lctx;
8534- int res;
8535-
8536- lctx = (ssIOCtx *) ctx;
8537+ ssIOCtxPtr lctx;
8538+ int res;
8539
8540- res = (lctx->snk->sink) (lctx->snk->context, buf, size);
8541+ lctx = (ssIOCtx *) ctx;
8542
8543- if (res <= 0)
8544- {
8545- return 0;
8546- }
8547- else
8548- {
8549- return res;
8550- };
8551+ res = (lctx->snk->sink) (lctx->snk->context, buf, size);
8552
8553+ if (res <= 0) {
8554+ return 0;
8555+ } else {
8556+ return res;
8557+ }
8558 }
8559
8560-static void
8561-sinkPutchar (gdIOCtx * ctx, int a)
8562+static void sinkPutchar (gdIOCtx * ctx, int a)
8563 {
8564- unsigned char b;
8565-
8566- b = a;
8567- sinkPutbuf (ctx, &b, 1);
8568+ unsigned char b;
8569
8570+ b = a;
8571+ sinkPutbuf (ctx, &b, 1);
8572 }
8573diff -urN php-4.4.8.org/ext/gd/libgd/gd_jpeg.c php-4.4.8/ext/gd/libgd/gd_jpeg.c
8574--- php-4.4.8.org/ext/gd/libgd/gd_jpeg.c 2004-03-29 20:21:00.000000000 +0200
8575+++ php-4.4.8/ext/gd/libgd/gd_jpeg.c 2006-02-05 16:53:58.000000000 +0100
8576@@ -1,7 +1,7 @@
8577 /*
8578 * gd_jpeg.c: Read and write JPEG (JFIF) format image files using the
8579 * gd graphics library (http://www.boutell.com/gd/).
8580- *
8581+ *
8582 * This software is based in part on the work of the Independent JPEG
8583 * Group. For more information on the IJG JPEG software (and JPEG
8584 * documentation, etc.), see ftp://ftp.uu.net/graphics/jpeg/.
8585@@ -18,13 +18,9 @@
8586 * major CGI brain damage
8587 *
8588 * 2.0.10: more efficient gdImageCreateFromJpegCtx, thanks to
8589- * Christian Aberger
8590+ * Christian Aberger
8591 */
8592
8593-#if PHP_WIN32 && !defined(ssize_t)
8594-typedef int ssize_t;
8595-#endif
8596-
8597 #include <stdio.h>
8598 #include <stdlib.h>
8599 #include <setjmp.h>
8600@@ -47,8 +43,44 @@
8601 typedef struct _jmpbuf_wrapper
8602 {
8603 jmp_buf jmpbuf;
8604+ int ignore_warning;
8605 } jmpbuf_wrapper;
8606
8607+static long php_jpeg_emit_message(j_common_ptr jpeg_info, int level)
8608+{
8609+ char message[JMSG_LENGTH_MAX];
8610+ jmpbuf_wrapper *jmpbufw;
8611+ int ignore_warning = 0;
8612+
8613+ jmpbufw = (jmpbuf_wrapper *) jpeg_info->client_data;
8614+
8615+ if (jmpbufw != 0) {
8616+ ignore_warning = jmpbufw->ignore_warning;
8617+ }
8618+
8619+ (jpeg_info->err->format_message)(jpeg_info,message);
8620+
8621+ /* It is a warning message */
8622+ if (level < 0) {
8623+ /* display only the 1st warning, as would do a default libjpeg
8624+ * unless strace_level >= 3
8625+ */
8626+ if ((jpeg_info->err->num_warnings == 0) || (jpeg_info->err->trace_level >= 3)) {
8627+ php_gd_error_ex(ignore_warning ? E_NOTICE : E_WARNING, "gd-jpeg, libjpeg: recoverable error: %s\n", message);
8628+ }
8629+
8630+ jpeg_info->err->num_warnings++;
8631+ } else {
8632+ /* strace msg, Show it if trace_level >= level. */
8633+ if (jpeg_info->err->trace_level >= level) {
8634+ php_gd_error_ex(E_NOTICE, "gd-jpeg, libjpeg: strace message: %s\n", message);
8635+ }
8636+ }
8637+ return 1;
8638+}
8639+
8640+
8641+
8642 /* Called by the IJG JPEG library upon encountering a fatal error */
8643 static void fatal_jpeg_error (j_common_ptr cinfo)
8644 {
8645@@ -174,7 +206,7 @@
8646
8647 nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
8648 if (nlines != 1) {
8649- php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1\n", nlines);
8650+ php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
8651 }
8652 }
8653 } else {
8654@@ -201,7 +233,7 @@
8655
8656 nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
8657 if (nlines != 1) {
8658- php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1\n", nlines);
8659+ php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
8660 }
8661 }
8662 }
8663@@ -211,21 +243,21 @@
8664 gdFree (row);
8665 }
8666
8667-gdImagePtr gdImageCreateFromJpeg (FILE * inFile)
8668+gdImagePtr gdImageCreateFromJpeg (FILE * inFile, int ignore_warning)
8669 {
8670 gdImagePtr im;
8671 gdIOCtx *in = gdNewFileCtx(inFile);
8672- im = gdImageCreateFromJpegCtx(in);
8673+ im = gdImageCreateFromJpegCtx(in, ignore_warning);
8674 in->gd_free (in);
8675
8676 return im;
8677 }
8678
8679-gdImagePtr gdImageCreateFromJpegPtr (int size, void *data)
8680+gdImagePtr gdImageCreateFromJpegPtr (int size, void *data, int ignore_warning)
8681 {
8682 gdImagePtr im;
8683 gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
8684- im = gdImageCreateFromJpegCtx(in);
8685+ im = gdImageCreateFromJpegCtx(in, ignore_warning);
8686 in->gd_free(in);
8687
8688 return im;
8689@@ -235,11 +267,12 @@
8690
8691 static int CMYKToRGB(int c, int m, int y, int k, int inverted);
8692
8693-/*
8694+
8695+/*
8696 * Create a gd-format image from the JPEG-format INFILE. Returns the
8697 * image, or NULL upon error.
8698 */
8699-gdImagePtr gdImageCreateFromJpegCtx (gdIOCtx * infile)
8700+gdImagePtr gdImageCreateFromJpegCtx (gdIOCtx * infile, int ignore_warning)
8701 {
8702 struct jpeg_decompress_struct cinfo;
8703 struct jpeg_error_mgr jerr;
8704@@ -257,8 +290,13 @@
8705 memset (&cinfo, 0, sizeof (cinfo));
8706 memset (&jerr, 0, sizeof (jerr));
8707
8708+ jmpbufw.ignore_warning = ignore_warning;
8709+
8710 cinfo.err = jpeg_std_error (&jerr);
8711 cinfo.client_data = &jmpbufw;
8712+
8713+ cinfo.err->emit_message = (void (*)(j_common_ptr,int)) php_jpeg_emit_message;
8714+
8715 if (setjmp (jmpbufw.jmpbuf) != 0) {
8716 /* we're here courtesy of longjmp */
8717 if (row) {
8718@@ -280,7 +318,7 @@
8719 jpeg_save_markers(&cinfo, JPEG_APP0 + 14, 256);
8720
8721 retval = jpeg_read_header (&cinfo, TRUE);
8722- if (retval != JPEG_HEADER_OK) {
8723+ if (retval != JPEG_HEADER_OK) {
8724 php_gd_error_ex(E_WARNING, "gd-jpeg: warning: jpeg_read_header returned %d, expected %d", retval, JPEG_HEADER_OK);
8725 }
8726
8727@@ -316,9 +354,9 @@
8728 * latest libjpeg, replaced by something else. Unfortunately
8729 * there is still no right way to find out if the file was
8730 * progressive or not; just declare your intent before you
8731- * write one by calling gdImageInterlace(im, 1) yourself.
8732+ * write one by calling gdImageInterlace(im, 1) yourself.
8733 * After all, we're not really supposed to rework JPEGs and
8734- * write them out again anyway. Lossy compression, remember?
8735+ * write them out again anyway. Lossy compression, remember?
8736 */
8737 #if 0
8738 gdImageInterlace (im, cinfo.progressive_mode != 0);
8739@@ -390,12 +428,12 @@
8740 if (jpeg_finish_decompress (&cinfo) != TRUE) {
8741 php_gd_error("gd-jpeg: warning: jpeg_finish_decompress reports suspended data source");
8742 }
8743-
8744- /* Thanks to Truxton Fulton */
8745- if (cinfo.err->num_warnings > 0) {
8746- goto error;
8747+ if (!ignore_warning) {
8748+ if (cinfo.err->num_warnings > 0) {
8749+ goto error;
8750+ }
8751 }
8752-
8753+
8754 jpeg_destroy_decompress (&cinfo);
8755 gdFree (row);
8756
8757@@ -524,7 +562,7 @@
8758 int got = gdGetBuf(src->buffer + nbytes, INPUT_BUF_SIZE - nbytes, src->infile);
8759
8760 if (got == EOF || got == 0) {
8761- /* EOF or error. If we got any data, don't worry about it. If we didn't, then this is unexpected. */
8762+ /* EOF or error. If we got any data, don't worry about it. If we didn't, then this is unexpected. */
8763 if (!nbytes) {
8764 nbytes = -1;
8765 }
8766@@ -532,7 +570,7 @@
8767 }
8768 nbytes += got;
8769 }
8770-
8771+
8772 if (nbytes <= 0) {
8773 if (src->start_of_file) { /* Treat empty input file as fatal error */
8774 ERREXIT (cinfo, JERR_INPUT_EMPTY);
8775@@ -634,7 +672,7 @@
8776 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (my_source_mgr));
8777 src = (my_src_ptr) cinfo->src;
8778 src->buffer = (unsigned char *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, INPUT_BUF_SIZE * sizeof (unsigned char));
8779-
8780+
8781 }
8782
8783 src = (my_src_ptr) cinfo->src;
8784diff -urN php-4.4.8.org/ext/gd/libgd/gdkanji.c php-4.4.8/ext/gd/libgd/gdkanji.c
8785--- php-4.4.8.org/ext/gd/libgd/gdkanji.c 2003-04-05 19:24:16.000000000 +0200
8786+++ php-4.4.8/ext/gd/libgd/gdkanji.c 2003-12-28 21:11:08.000000000 +0100
8787@@ -75,7 +75,7 @@
8788 va_list args;
8789 char *tmp;
8790 TSRMLS_FETCH();
8791-
8792+
8793 va_start(args, format);
8794 vspprintf(&tmp, 0, format, args);
8795 va_end(args);
8796diff -urN php-4.4.8.org/ext/gd/libgd/gd_png.c php-4.4.8/ext/gd/libgd/gd_png.c
8797--- php-4.4.8.org/ext/gd/libgd/gd_png.c 2007-05-17 00:54:11.000000000 +0200
8798+++ php-4.4.8/ext/gd/libgd/gd_png.c 2007-05-17 00:19:08.000000000 +0200
8799@@ -23,7 +23,7 @@
8800 out all fprintf() statements to disable that).
8801
8802 GD 2.0 supports RGBA truecolor and will read and write truecolor PNGs.
8803- GD 2.0 supports 8 bits of color resolution per channel and
8804+ GD 2.0 supports 8 bits of color resolution per channel and
8805 7 bits of alpha channel resolution. Images with more than 8 bits
8806 per channel are reduced to 8 bits. Images with an alpha channel are
8807 only able to resolve down to '1/128th opaque' instead of '1/256th',
8808@@ -58,11 +58,11 @@
8809 * been defined.
8810 */
8811
8812- php_gd_error_ex(E_ERROR, "gd-png: fatal libpng error: %s\n", msg);
8813+ php_gd_error_ex(E_WARNING, "gd-png: fatal libpng error: %s", msg);
8814
8815 jmpbuf_ptr = png_get_error_ptr (png_ptr);
8816 if (jmpbuf_ptr == NULL) { /* we are completely hosed now */
8817- php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
8818+ php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.");
8819 }
8820
8821 longjmp (jmpbuf_ptr->jmpbuf, 1);
8822@@ -130,12 +130,15 @@
8823
8824 /* Make sure the signature can't match by dumb luck -- TBB */
8825 /* GRR: isn't sizeof(infile) equal to the size of the pointer? */
8826- memset (infile, 0, sizeof(infile));
8827+ memset (sig, 0, sizeof(sig));
8828
8829 /* first do a quick check that the file really is a PNG image; could
8830- * have used slightly more general png_sig_cmp() function instead
8831+ * have used slightly more general png_sig_cmp() function instead
8832 */
8833- gdGetBuf(sig, 8, infile);
8834+ if (gdGetBuf(sig, 8, infile) < 8) {
8835+ return NULL;
8836+ }
8837+
8838 if (!png_check_sig (sig, 8)) { /* bad signature */
8839 return NULL;
8840 }
8841@@ -146,13 +149,13 @@
8842 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
8843 #endif
8844 if (png_ptr == NULL) {
8845- php_gd_error("gd-png error: cannot allocate libpng main struct\n");
8846+ php_gd_error("gd-png error: cannot allocate libpng main struct");
8847 return NULL;
8848 }
8849
8850 info_ptr = png_create_info_struct(png_ptr);
8851 if (info_ptr == NULL) {
8852- php_gd_error("gd-png error: cannot allocate libpng info struct\n");
8853+ php_gd_error("gd-png error: cannot allocate libpng info struct");
8854 png_destroy_read_struct (&png_ptr, NULL, NULL);
8855
8856 return NULL;
8857@@ -160,7 +163,7 @@
8858
8859 /* we could create a second info struct here (end_info), but it's only
8860 * useful if we want to keep pre- and post-IDAT chunk info separated
8861- * (mainly for PNG-aware image editors and converters)
8862+ * (mainly for PNG-aware image editors and converters)
8863 */
8864
8865 /* setjmp() must be called in every non-callback function that calls a
8866@@ -168,7 +171,7 @@
8867 */
8868 #ifndef PNG_SETJMP_NOT_SUPPORTED
8869 if (setjmp(gdPngJmpbufStruct.jmpbuf)) {
8870- php_gd_error("gd-png error: setjmp returns error condition\n");
8871+ php_gd_error("gd-png error: setjmp returns error condition");
8872 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
8873
8874 return NULL;
8875@@ -187,7 +190,7 @@
8876 im = gdImageCreate((int) width, (int) height);
8877 }
8878 if (im == NULL) {
8879- php_gd_error("gd-png error: cannot allocate gdImage struct\n");
8880+ php_gd_error("gd-png error: cannot allocate gdImage struct");
8881 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
8882 gdFree(image_data);
8883 gdFree(row_pointers);
8884@@ -201,15 +204,32 @@
8885 png_set_packing (png_ptr); /* expand to 1 byte per pixel */
8886 }
8887
8888+ /* setjmp() must be called in every non-callback function that calls a
8889+ * PNG-reading libpng function
8890+ */
8891+#ifndef PNG_SETJMP_NOT_SUPPORTED
8892+ if (setjmp(gdPngJmpbufStruct.jmpbuf)) {
8893+ php_gd_error("gd-png error: setjmp returns error condition");
8894+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
8895+ gdFree(image_data);
8896+ gdFree(row_pointers);
8897+ if (im) {
8898+ gdImageDestroy(im);
8899+ }
8900+ return NULL;
8901+ }
8902+#endif
8903+
8904+
8905 switch (color_type) {
8906 case PNG_COLOR_TYPE_PALETTE:
8907 png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
8908 #ifdef DEBUG
8909- php_gd_error("gd-png color_type is palette, colors: %d\n", num_palette);
8910+ php_gd_error("gd-png color_type is palette, colors: %d", num_palette);
8911 #endif /* DEBUG */
8912 if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) {
8913 /* gd 2.0: we support this rather thoroughly now. Grab the
8914- * first fully transparent entry, if any, as the value of
8915+ * first fully transparent entry, if any, as the value of
8916 * the simple-transparency index, mostly for backwards
8917 * binary compatibility. The alpha channel is where it's
8918 * really at these days.
8919@@ -228,8 +248,8 @@
8920 case PNG_COLOR_TYPE_GRAY:
8921 case PNG_COLOR_TYPE_GRAY_ALPHA:
8922 /* create a fake palette and check for single-shade transparency */
8923- if ((palette = (png_colorp) safe_emalloc(256, sizeof(png_color), 0)) == NULL) {
8924- php_gd_error("gd-png error: cannot allocate gray palette\n");
8925+ if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL) {
8926+ php_gd_error("gd-png error: cannot allocate gray palette");
8927 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
8928
8929 return NULL;
8930@@ -263,7 +283,7 @@
8931 * custom 16-bit code to handle the case where there are gdFree
8932 * palette entries. This error will be extremely rare in
8933 * general, though. (Quite possibly there is only one such
8934- * image in existence.)
8935+ * image in existence.)
8936 */
8937 }
8938 break;
8939@@ -272,16 +292,16 @@
8940 case PNG_COLOR_TYPE_RGB_ALPHA:
8941 /* gd 2.0: we now support truecolor. See the comment above
8942 * for a rare situation in which the transparent pixel may not
8943- * work properly with 16-bit channels.
8944+ * work properly with 16-bit channels.
8945 */
8946 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
8947 png_get_tRNS(png_ptr, info_ptr, NULL, NULL, &trans_color_rgb);
8948 if (bit_depth == 16) { /* png_set_strip_16() not yet in effect */
8949- transparent = gdTrueColor(trans_color_rgb->red >> 8,
8950+ transparent = gdTrueColor(trans_color_rgb->red >> 8,
8951 trans_color_rgb->green >> 8,
8952 trans_color_rgb->blue >> 8);
8953 } else {
8954- transparent = gdTrueColor(trans_color_rgb->red,
8955+ transparent = gdTrueColor(trans_color_rgb->red,
8956 trans_color_rgb->green,
8957 trans_color_rgb->blue);
8958 }
8959@@ -295,7 +315,7 @@
8960 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
8961 image_data = (png_bytep) safe_emalloc(rowbytes, height, 0);
8962
8963- row_pointers = (png_bytepp) safe_emalloc(height, sizeof (png_bytep), 0);
8964+ row_pointers = (png_bytepp) safe_emalloc(height, sizeof(png_bytep), 0);
8965
8966 /* set the individual row_pointers to point at the correct offsets */
8967 for (h = 0; h < height; ++h) {
8968@@ -349,7 +369,7 @@
8969 register png_byte b = row_pointers[h][boffset++];
8970
8971 /* gd has only 7 bits of alpha channel resolution, and
8972- * 127 is transparent, 0 opaque. A moment of convenience,
8973+ * 127 is transparent, 0 opaque. A moment of convenience,
8974 * a lifetime of compatibility.
8975 */
8976
8977@@ -373,7 +393,7 @@
8978 if (!im->trueColor) {
8979 for (i = num_palette; i < gdMaxColors; ++i) {
8980 if (!open[i]) {
8981- php_gd_error("gd-png warning: image data references out-of-range color index (%d)\n", i);
8982+ php_gd_error("gd-png warning: image data references out-of-range color index (%d)", i);
8983 }
8984 }
8985 }
8986@@ -388,17 +408,17 @@
8987 return im;
8988 }
8989
8990-void gdImagePngEx (gdImagePtr im, FILE * outFile, int level)
8991+void gdImagePngEx (gdImagePtr im, FILE * outFile, int level, int basefilter)
8992 {
8993 gdIOCtx *out = gdNewFileCtx(outFile);
8994- gdImagePngCtxEx(im, out, level);
8995+ gdImagePngCtxEx(im, out, level, basefilter);
8996 out->gd_free(out);
8997 }
8998
8999 void gdImagePng (gdImagePtr im, FILE * outFile)
9000 {
9001 gdIOCtx *out = gdNewFileCtx(outFile);
9002- gdImagePngCtxEx(im, out, -1);
9003+ gdImagePngCtxEx(im, out, -1, -1);
9004 out->gd_free(out);
9005 }
9006
9007@@ -406,18 +426,18 @@
9008 {
9009 void *rv;
9010 gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
9011- gdImagePngCtxEx(im, out, -1);
9012+ gdImagePngCtxEx(im, out, -1, -1);
9013 rv = gdDPExtractData(out, size);
9014 out->gd_free(out);
9015
9016 return rv;
9017 }
9018
9019-void * gdImagePngPtrEx (gdImagePtr im, int *size, int level)
9020+void * gdImagePngPtrEx (gdImagePtr im, int *size, int level, int basefilter)
9021 {
9022 void *rv;
9023 gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
9024- gdImagePngCtxEx(im, out, level);
9025+ gdImagePngCtxEx(im, out, level, basefilter);
9026 rv = gdDPExtractData(out, size);
9027 out->gd_free(out);
9028 return rv;
9029@@ -425,14 +445,14 @@
9030
9031 void gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
9032 {
9033- gdImagePngCtxEx(im, outfile, -1);
9034+ gdImagePngCtxEx(im, outfile, -1, -1);
9035 }
9036
9037 /* This routine is based in part on code from Dale Lutz (Safe Software Inc.)
9038 * and in part on demo code from Chapter 15 of "PNG: The Definitive Guide"
9039 * (http://www.cdrom.com/pub/png/pngbook.html).
9040 */
9041-void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level)
9042+void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilter)
9043 {
9044 int i, j, bit_depth = 0, interlace_type;
9045 int width = im->sx;
9046@@ -454,13 +474,13 @@
9047 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
9048 #endif
9049 if (png_ptr == NULL) {
9050- php_gd_error("gd-png error: cannot allocate libpng main struct\n");
9051+ php_gd_error("gd-png error: cannot allocate libpng main struct");
9052 return;
9053 }
9054
9055 info_ptr = png_create_info_struct(png_ptr);
9056 if (info_ptr == NULL) {
9057- php_gd_error("gd-png error: cannot allocate libpng info struct\n");
9058+ php_gd_error("gd-png error: cannot allocate libpng info struct");
9059 png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
9060
9061 return;
9062@@ -468,7 +488,7 @@
9063
9064 #ifndef PNG_SETJMP_NOT_SUPPORTED
9065 if (setjmp (gdPngJmpbufStruct.jmpbuf)) {
9066- php_gd_error("gd-png error: setjmp returns error condition\n");
9067+ php_gd_error("gd-png error: setjmp returns error condition");
9068 png_destroy_write_struct (&png_ptr, &info_ptr);
9069
9070 return;
9071@@ -483,14 +503,17 @@
9072 * gd is intentionally imperfect and doesn't spend a lot of time
9073 * fussing with such things.
9074 */
9075-
9076+
9077 /* png_set_filter(png_ptr, 0, PNG_FILTER_NONE); */
9078
9079 /* 2.0.12: this is finally a parameter */
9080 png_set_compression_level(png_ptr, level);
9081+ if (basefilter >= 0) {
9082+ png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, basefilter);
9083+ }
9084
9085 /* can set this to a smaller value without compromising compression if all
9086- * image data is 16K or less; will save some decoder memory [min == 8]
9087+ * image data is 16K or less; will save some decoder memory [min == 8]
9088 */
9089
9090 /* png_set_compression_window_bits(png_ptr, 15); */
9091@@ -519,13 +542,13 @@
9092 bit_depth = 1;
9093 } else if (colors <= 4) {
9094 bit_depth = 2;
9095- } else if (colors <= 16) {
9096+ } else if (colors <= 16) {
9097 bit_depth = 4;
9098 } else {
9099 bit_depth = 8;
9100 }
9101 }
9102-
9103+
9104 interlace_type = im->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
9105
9106 if (im->trueColor) {
9107@@ -552,9 +575,9 @@
9108 if (!im->trueColor) {
9109 /* Oy veh. Remap the PNG palette to put the entries with interesting alpha channel
9110 * values first. This minimizes the size of the tRNS chunk and thus the size
9111- * of the PNG file as a whole.
9112+ * of the PNG file as a whole.
9113 */
9114-
9115+
9116 int tc = 0;
9117 int i;
9118 int j;
9119@@ -585,7 +608,7 @@
9120 for (i = 0; i < im->colorsTotal; i++) {
9121 if (!im->open[i]) {
9122 if (im->alpha[i] != gdAlphaOpaque) {
9123- /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
9124+ /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
9125 trans_values[j] = 255 - ((im->alpha[i] << 1) + (im->alpha[i] >> 6));
9126 mapping[i] = j++;
9127 } else {
9128@@ -665,7 +688,7 @@
9129 * PNG's convention in which 255 is opaque.
9130 */
9131 a = gdTrueColorGetAlpha(thisPixel);
9132- /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
9133+ /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
9134 *pOutputRow++ = 255 - ((a << 1) + (a >> 6));
9135 }
9136 }
9137@@ -677,12 +700,12 @@
9138 for (j = 0; j < height; ++j) {
9139 gdFree(row_pointers[j]);
9140 }
9141-
9142+
9143 gdFree(row_pointers);
9144 } else {
9145 if (remap) {
9146 png_bytep *row_pointers;
9147- row_pointers = safe_emalloc(sizeof(png_bytep), height, 0);
9148+ row_pointers = safe_emalloc(height, sizeof(png_bytep), 0);
9149 for (j = 0; j < height; ++j) {
9150 row_pointers[j] = (png_bytep) gdMalloc(width);
9151 for (i = 0; i < width; ++i) {
9152diff -urN php-4.4.8.org/ext/gd/libgd/gd_security.c php-4.4.8/ext/gd/libgd/gd_security.c
9153--- php-4.4.8.org/ext/gd/libgd/gd_security.c 2007-03-10 14:06:37.000000000 +0100
9154+++ php-4.4.8/ext/gd/libgd/gd_security.c 2007-10-23 03:58:08.000000000 +0200
9155@@ -19,12 +19,10 @@
9156
9157 int overflow2(int a, int b)
9158 {
9159- if(a < 0 || b < 0) {
9160- php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative, failing operation gracefully\n");
9161+ if(a <= 0 || b <= 0) {
9162+ php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
9163 return 1;
9164 }
9165- if(b == 0)
9166- return 0;
9167 if(a > INT_MAX / b) {
9168 php_gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
9169 return 1;
9170diff -urN php-4.4.8.org/ext/gd/libgd/gd_ss.c php-4.4.8/ext/gd/libgd/gd_ss.c
9171--- php-4.4.8.org/ext/gd/libgd/gd_ss.c 2003-03-05 17:04:20.000000000 +0100
9172+++ php-4.4.8/ext/gd/libgd/gd_ss.c 2005-08-18 14:54:44.000000000 +0200
9173@@ -17,37 +17,33 @@
9174 #define GD_SS_DBG(s)
9175
9176 #ifdef HAVE_LIBPNG
9177-void
9178-gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
9179+void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
9180 {
9181- gdIOCtx *out = gdNewSSCtx (NULL, outSink);
9182- gdImagePngCtx (im, out);
9183- out->gd_free (out);
9184+ gdIOCtx *out = gdNewSSCtx(NULL, outSink);
9185+ gdImagePngCtx(im, out);
9186+ out->gd_free(out);
9187 }
9188
9189-gdImagePtr
9190-gdImageCreateFromPngSource (gdSourcePtr inSource)
9191+gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
9192 {
9193- gdIOCtx *in = gdNewSSCtx (inSource, NULL);
9194- gdImagePtr im;
9195+ gdIOCtx *in = gdNewSSCtx(inSource, NULL);
9196+ gdImagePtr im;
9197
9198- im = gdImageCreateFromPngCtx (in);
9199+ im = gdImageCreateFromPngCtx(in);
9200
9201- in->gd_free (in);
9202+ in->gd_free(in);
9203
9204- return im;
9205+ return im;
9206 }
9207 #else /* no HAVE_LIBPNG */
9208-void
9209-gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
9210+void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
9211 {
9212- php_gd_error("PNG support is not available\n");
9213+ php_gd_error("PNG support is not available");
9214 }
9215-gdImagePtr
9216-gdImageCreateFromPngSource (gdSourcePtr inSource)
9217+gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
9218 {
9219- php_gd_error("PNG support is not available\n");
9220- return NULL;
9221+ php_gd_error("PNG support is not available");
9222+ return NULL;
9223 }
9224 #endif /* HAVE_LIBPNG */
9225
9226diff -urN php-4.4.8.org/ext/gd/libgd/gdtables.c php-4.4.8/ext/gd/libgd/gdtables.c
9227--- php-4.4.8.org/ext/gd/libgd/gdtables.c 2002-04-13 04:03:09.000000000 +0200
9228+++ php-4.4.8/ext/gd/libgd/gdtables.c 2006-09-15 17:11:54.000000000 +0200
9229@@ -1,5 +1,11 @@
9230
9231-int gdCosT[] =
9232+#ifdef HAVE_CONFIG_H
9233+#include "config.h"
9234+#endif
9235+
9236+#include "php_compat.h"
9237+
9238+const int gdCosT[] =
9239 {
9240 1024,
9241 1023,
9242@@ -363,7 +369,7 @@
9243 1023
9244 };
9245
9246-int gdSinT[] =
9247+const int gdSinT[] =
9248 {
9249 0,
9250 17,
9251diff -urN php-4.4.8.org/ext/gd/libgd/gdtest.c php-4.4.8/ext/gd/libgd/gdtest.c
9252--- php-4.4.8.org/ext/gd/libgd/gdtest.c 2002-10-30 00:08:01.000000000 +0100
9253+++ php-4.4.8/ext/gd/libgd/gdtest.c 2007-02-24 03:17:24.000000000 +0100
9254@@ -56,7 +56,7 @@
9255 /* */
9256 /* Send to PNG File then Ptr */
9257 /* */
9258- sprintf (of, "%s.png", argv[1]);
9259+ snprintf (of, sizeof(of), "%s.png", argv[1]);
9260 out = fopen (of, "wb");
9261 gdImagePng (im, out);
9262 fclose (out);
9263@@ -88,7 +88,7 @@
9264 /* */
9265 /* Send to GD2 File then Ptr */
9266 /* */
9267- sprintf (of, "%s.gd2", argv[1]);
9268+ snprintf (of, sizeof(of), "%s.gd2", argv[1]);
9269 out = fopen (of, "wb");
9270 gdImageGd2 (im, out, 128, 2);
9271 fclose (out);
9272@@ -123,7 +123,7 @@
9273 /* */
9274 /* Send to GD File then Ptr */
9275 /* */
9276- sprintf (of, "%s.gd", argv[1]);
9277+ snprintf (of, sizeof(of), "%s.gd", argv[1]);
9278 out = fopen (of, "wb");
9279 gdImageGd (im, out);
9280 fclose (out);
9281@@ -180,7 +180,7 @@
9282 ** Test gdImagePngToSink'
9283 * */
9284
9285- sprintf (of, "%s.snk", argv[1]);
9286+ snprintf (of, sizeof(of), "%s.snk", argv[1]);
9287 out = fopen (of, "wb");
9288 imgsnk.sink = fwriteWrapper;
9289 imgsnk.context = out;
9290diff -urN php-4.4.8.org/ext/gd/libgd/gd_topal.c php-4.4.8/ext/gd/libgd/gd_topal.c
9291--- php-4.4.8.org/ext/gd/libgd/gd_topal.c 2004-08-12 01:25:54.000000000 +0200
9292+++ php-4.4.8/ext/gd/libgd/gd_topal.c 2007-04-04 02:30:18.000000000 +0200
9293@@ -772,6 +772,7 @@
9294 nim->green[icolor] = 255;
9295 nim->blue[icolor] = 255;
9296 }
9297+ nim->open[icolor] = 0;
9298 #endif
9299 }
9300
9301@@ -2086,6 +2087,9 @@
9302 if( (im1->sx != im2->sx) || (im1->sy != im2->sy) ) {
9303 return -3; /* the images are meant to be the same dimensions */
9304 }
9305+ if (im2->colorsTotal<1) {
9306+ return -4; /* At least 1 color must be allocated */
9307+ }
9308
9309 buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0);
9310 memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal );
9311diff -urN php-4.4.8.org/ext/gd/libgd/gd_wbmp.c php-4.4.8/ext/gd/libgd/gd_wbmp.c
9312--- php-4.4.8.org/ext/gd/libgd/gd_wbmp.c 2004-03-29 20:21:00.000000000 +0200
9313+++ php-4.4.8/ext/gd/libgd/gd_wbmp.c 2005-08-18 14:54:44.000000000 +0200
9314@@ -1,10 +1,8 @@
9315-
9316-
9317 /*
9318 WBMP: Wireless Bitmap Type 0: B/W, Uncompressed Bitmap
9319- Specification of the WBMP format can be found in the file:
9320+ Specification of the WBMP format can be found in the file:
9321 SPEC-WAESpec-19990524.pdf
9322- You can download the WAP specification on: http://www.wapforum.com/
9323+ You can download the WAP specification on: http://www.wapforum.com/
9324
9325 gd_wbmp.c
9326
9327@@ -16,7 +14,7 @@
9328 (wbmp library included, but you can find the latest distribution
9329 at http://www.vandenbrande.com/wbmp)
9330
9331- Implemented: gdImageCreateFromWBMPCtx, gdImageCreateFromWBMP
9332+ Implemented: gdImageCreateFromWBMPCtx, gdImageCreateFromWBMP
9333
9334 ---------------------------------------------------------------------------
9335
9336@@ -34,7 +32,7 @@
9337 ** implied warranty.
9338
9339 ---------------------------------------------------------------------------
9340- Parts od this code are inspired by 'pbmtowbmp.c' and 'wbmptopbm.c' by
9341+ Parts od this code are inspired by 'pbmtowbmp.c' and 'wbmptopbm.c' by
9342 Terje Sannum <terje@looplab.com>.
9343 **
9344 ** Permission to use, copy, modify, and distribute this software and its
9345@@ -67,10 +65,9 @@
9346 ** Wrapper around gdPutC for use with writewbmp
9347 **
9348 */
9349-void
9350-gd_putout (int i, void *out)
9351+void gd_putout (int i, void *out)
9352 {
9353- gdPutC (i, (gdIOCtx *) out);
9354+ gdPutC(i, (gdIOCtx *) out);
9355 }
9356
9357
9358@@ -79,10 +76,9 @@
9359 ** Wrapper around gdGetC for use with readwbmp
9360 **
9361 */
9362-int
9363-gd_getin (void *in)
9364+int gd_getin (void *in)
9365 {
9366- return (gdGetC ((gdIOCtx *) in));
9367+ return (gdGetC((gdIOCtx *) in));
9368 }
9369
9370
9371@@ -91,105 +87,93 @@
9372 ** Write the image as a wbmp file
9373 ** Parameters are:
9374 ** image: gd image structure;
9375- ** fg: the index of the foreground color. any other value will be
9376+ ** fg: the index of the foreground color. any other value will be
9377 ** considered as background and will not be written
9378 ** out: the stream where to write
9379 */
9380-void
9381-gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
9382+void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
9383 {
9384+ int x, y, pos;
9385+ Wbmp *wbmp;
9386
9387- int x, y, pos;
9388- Wbmp *wbmp;
9389+ /* create the WBMP */
9390+ if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) {
9391+ php_gd_error("Could not create WBMP");
9392+ }
9393
9394+ /* fill up the WBMP structure */
9395+ pos = 0;
9396+ for (y = 0; y < gdImageSY(image); y++) {
9397+ for (x = 0; x < gdImageSX(image); x++) {
9398+ if (gdImageGetPixel (image, x, y) == fg) {
9399+ wbmp->bitmap[pos] = WBMP_BLACK;
9400+ }
9401+ pos++;
9402+ }
9403+ }
9404
9405- /* create the WBMP */
9406- if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL)
9407- php_gd_error("Could not create WBMP\n");
9408-
9409- /* fill up the WBMP structure */
9410- pos = 0;
9411- for (y = 0; y < gdImageSY (image); y++)
9412- {
9413- for (x = 0; x < gdImageSX (image); x++)
9414- {
9415- if (gdImageGetPixel (image, x, y) == fg)
9416- {
9417- wbmp->bitmap[pos] = WBMP_BLACK;
9418- }
9419- pos++;
9420- }
9421- }
9422-
9423- /* write the WBMP to a gd file descriptor */
9424- if (writewbmp (wbmp, &gd_putout, out))
9425- php_gd_error("Could not save WBMP\n");
9426- /* des submitted this bugfix: gdFree the memory. */
9427- freewbmp (wbmp);
9428+ /* write the WBMP to a gd file descriptor */
9429+ if (writewbmp (wbmp, &gd_putout, out)) {
9430+ php_gd_error("Could not save WBMP");
9431+ }
9432+ /* des submitted this bugfix: gdFree the memory. */
9433+ freewbmp(wbmp);
9434 }
9435
9436-
9437 /* gdImageCreateFromWBMPCtx
9438 ** ------------------------
9439 ** Create a gdImage from a WBMP file input from an gdIOCtx
9440 */
9441-gdImagePtr
9442-gdImageCreateFromWBMPCtx (gdIOCtx * infile)
9443+gdImagePtr gdImageCreateFromWBMPCtx (gdIOCtx * infile)
9444 {
9445- /* FILE *wbmp_file; */
9446- Wbmp *wbmp;
9447- gdImagePtr im = NULL;
9448- int black, white;
9449- int col, row, pos;
9450-
9451- if (readwbmp (&gd_getin, infile, &wbmp))
9452- return (NULL);
9453-
9454- if (!(im = gdImageCreate (wbmp->width, wbmp->height)))
9455- {
9456- freewbmp (wbmp);
9457- return (NULL);
9458- }
9459-
9460- /* create the background color */
9461- white = gdImageColorAllocate (im, 255, 255, 255);
9462- /* create foreground color */
9463- black = gdImageColorAllocate (im, 0, 0, 0);
9464-
9465- /* fill in image (in a wbmp 1 = white/ 0 = black) */
9466- pos = 0;
9467- for (row = 0; row < wbmp->height; row++)
9468- {
9469- for (col = 0; col < wbmp->width; col++)
9470- {
9471- if (wbmp->bitmap[pos++] == WBMP_WHITE)
9472- {
9473- gdImageSetPixel (im, col, row, white);
9474- }
9475- else
9476- {
9477- gdImageSetPixel (im, col, row, black);
9478- }
9479+ /* FILE *wbmp_file; */
9480+ Wbmp *wbmp;
9481+ gdImagePtr im = NULL;
9482+ int black, white;
9483+ int col, row, pos;
9484+
9485+ if (readwbmp (&gd_getin, infile, &wbmp)) {
9486+ return NULL;
9487 }
9488- }
9489
9490- freewbmp (wbmp);
9491+ if (!(im = gdImageCreate (wbmp->width, wbmp->height))) {
9492+ freewbmp (wbmp);
9493+ return NULL;
9494+ }
9495
9496- return (im);
9497-}
9498+ /* create the background color */
9499+ white = gdImageColorAllocate(im, 255, 255, 255);
9500+ /* create foreground color */
9501+ black = gdImageColorAllocate(im, 0, 0, 0);
9502+
9503+ /* fill in image (in a wbmp 1 = white/ 0 = black) */
9504+ pos = 0;
9505+ for (row = 0; row < wbmp->height; row++) {
9506+ for (col = 0; col < wbmp->width; col++) {
9507+ if (wbmp->bitmap[pos++] == WBMP_WHITE) {
9508+ gdImageSetPixel(im, col, row, white);
9509+ } else {
9510+ gdImageSetPixel(im, col, row, black);
9511+ }
9512+ }
9513+ }
9514
9515+ freewbmp(wbmp);
9516+
9517+ return im;
9518+}
9519
9520 /* gdImageCreateFromWBMP
9521 ** ---------------------
9522 */
9523-gdImagePtr
9524-gdImageCreateFromWBMP (FILE * inFile)
9525+gdImagePtr gdImageCreateFromWBMP (FILE * inFile)
9526 {
9527- gdImagePtr im;
9528- gdIOCtx *in = gdNewFileCtx (inFile);
9529- im = gdImageCreateFromWBMPCtx (in);
9530- in->gd_free (in);
9531- return (im);
9532+ gdImagePtr im;
9533+ gdIOCtx *in = gdNewFileCtx(inFile);
9534+ im = gdImageCreateFromWBMPCtx(in);
9535+ in->gd_free(in);
9536+
9537+ return im;
9538 }
9539
9540 gdImagePtr gdImageCreateFromWBMPPtr (int size, void *data)
9541@@ -204,24 +188,23 @@
9542 /* gdImageWBMP
9543 ** -----------
9544 */
9545-void
9546-gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
9547+void gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
9548 {
9549- gdIOCtx *out = gdNewFileCtx (outFile);
9550- gdImageWBMPCtx (im, fg, out);
9551- out->gd_free (out);
9552+ gdIOCtx *out = gdNewFileCtx(outFile);
9553+ gdImageWBMPCtx(im, fg, out);
9554+ out->gd_free(out);
9555 }
9556
9557 /* gdImageWBMPPtr
9558 ** --------------
9559 */
9560-void *
9561-gdImageWBMPPtr (gdImagePtr im, int *size, int fg)
9562+void * gdImageWBMPPtr (gdImagePtr im, int *size, int fg)
9563 {
9564- void *rv;
9565- gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
9566- gdImageWBMPCtx (im, fg, out);
9567- rv = gdDPExtractData (out, size);
9568- out->gd_free (out);
9569- return rv;
9570+ void *rv;
9571+ gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
9572+ gdImageWBMPCtx(im, fg, out);
9573+ rv = gdDPExtractData(out, size);
9574+ out->gd_free(out);
9575+
9576+ return rv;
9577 }
9578diff -urN php-4.4.8.org/ext/gd/libgd/gdxpm.c php-4.4.8/ext/gd/libgd/gdxpm.c
9579--- php-4.4.8.org/ext/gd/libgd/gdxpm.c 2003-06-04 01:42:49.000000000 +0200
9580+++ php-4.4.8/ext/gd/libgd/gdxpm.c 2005-08-18 14:54:44.000000000 +0200
9581@@ -1,8 +1,8 @@
9582
9583-/*
9584+/*
9585 add ability to load xpm files to gd, requires the xpm
9586 library.
9587- Caolan.McNamara@ul.ie
9588+ Caolan.McNamara@ul.ie
9589 http://www.csn.ul.ie/~caolan
9590 */
9591 #include <stdio.h>
9592@@ -15,123 +15,125 @@
9593
9594 #include <X11/xpm.h>
9595
9596-gdImagePtr
9597-gdImageCreateFromXpm (char *filename)
9598+gdImagePtr gdImageCreateFromXpm (char *filename)
9599 {
9600- XpmInfo info;
9601- XpmImage image;
9602- int i, j, k, number;
9603- char buf[5];
9604- gdImagePtr im = 0;
9605- char *apixel;
9606- int *pointer;
9607- int red = 0, green = 0, blue = 0;
9608- int *colors;
9609- int ret;
9610-
9611- ret = XpmReadFileToXpmImage (filename, &image, &info);
9612- if (ret != XpmSuccess)
9613- return 0;
9614-
9615- if (!(im = gdImageCreate (image.width, image.height)))
9616- return 0;
9617-
9618- number = image.ncolors;
9619- colors = (int *) safe_emalloc(number, sizeof(int), 0);
9620- for (i = 0; i < number; i++)
9621- {
9622- switch (strlen (image.colorTable[i].c_color))
9623- {
9624- case 4:
9625- buf[1] = '\0';
9626- buf[0] = image.colorTable[i].c_color[1];
9627- red = strtol (buf, NULL, 16);
9628-
9629- buf[0] = image.colorTable[i].c_color[3];
9630- green = strtol (buf, NULL, 16);
9631-
9632- buf[0] = image.colorTable[i].c_color[5];
9633- blue = strtol (buf, NULL, 16);
9634- break;
9635- case 7:
9636- buf[2] = '\0';
9637- buf[0] = image.colorTable[i].c_color[1];
9638- buf[1] = image.colorTable[i].c_color[2];
9639- red = strtol (buf, NULL, 16);
9640-
9641- buf[0] = image.colorTable[i].c_color[3];
9642- buf[1] = image.colorTable[i].c_color[4];
9643- green = strtol (buf, NULL, 16);
9644-
9645- buf[0] = image.colorTable[i].c_color[5];
9646- buf[1] = image.colorTable[i].c_color[6];
9647- blue = strtol (buf, NULL, 16);
9648- break;
9649- case 10:
9650- buf[3] = '\0';
9651- buf[0] = image.colorTable[i].c_color[1];
9652- buf[1] = image.colorTable[i].c_color[2];
9653- buf[2] = image.colorTable[i].c_color[3];
9654- red = strtol (buf, NULL, 16);
9655- red /= 64;
9656-
9657- buf[0] = image.colorTable[i].c_color[4];
9658- buf[1] = image.colorTable[i].c_color[5];
9659- buf[2] = image.colorTable[i].c_color[6];
9660- green = strtol (buf, NULL, 16);
9661- green /= 64;
9662-
9663- buf[0] = image.colorTable[i].c_color[7];
9664- buf[1] = image.colorTable[i].c_color[8];
9665- buf[2] = image.colorTable[i].c_color[9];
9666- blue = strtol (buf, NULL, 16);
9667- blue /= 64;
9668- break;
9669- case 13:
9670- buf[4] = '\0';
9671- buf[0] = image.colorTable[i].c_color[1];
9672- buf[1] = image.colorTable[i].c_color[2];
9673- buf[2] = image.colorTable[i].c_color[3];
9674- buf[3] = image.colorTable[i].c_color[4];
9675- red = strtol (buf, NULL, 16);
9676- red /= 256;
9677-
9678- buf[0] = image.colorTable[i].c_color[5];
9679- buf[1] = image.colorTable[i].c_color[6];
9680- buf[2] = image.colorTable[i].c_color[7];
9681- buf[3] = image.colorTable[i].c_color[8];
9682- green = strtol (buf, NULL, 16);
9683- green /= 256;
9684-
9685- buf[0] = image.colorTable[i].c_color[9];
9686- buf[1] = image.colorTable[i].c_color[10];
9687- buf[2] = image.colorTable[i].c_color[11];
9688- buf[3] = image.colorTable[i].c_color[12];
9689- blue = strtol (buf, NULL, 16);
9690- blue /= 256;
9691- break;
9692+ XpmInfo info;
9693+ XpmImage image;
9694+ int i, j, k, number;
9695+ char buf[5];
9696+ gdImagePtr im = 0;
9697+ char *apixel;
9698+ int *pointer;
9699+ int red = 0, green = 0, blue = 0;
9700+ int *colors;
9701+ int ret;
9702+
9703+ ret = XpmReadFileToXpmImage(filename, &image, &info);
9704+ if (ret != XpmSuccess) {
9705+ return 0;
9706 }
9707
9708+ if (!(im = gdImageCreate(image.width, image.height))) {
9709+ return 0;
9710+ }
9711
9712- colors[i] = gdImageColorResolve (im, red, green, blue);
9713- if (colors[i] == -1)
9714- php_gd_error("ARRRGH\n");
9715- }
9716-
9717- apixel = (char *) gdMalloc (image.cpp + 1);
9718- apixel[image.cpp] = '\0';
9719-
9720- pointer = (int *) image.data;
9721- for (i = 0; i < image.height; i++)
9722- {
9723- for (j = 0; j < image.width; j++)
9724- {
9725- k = *pointer++;
9726- gdImageSetPixel (im, j, i, colors[k]);
9727+ number = image.ncolors;
9728+ colors = (int *) safe_emalloc(number, sizeof(int), 0);
9729+ for (i = 0; i < number; i++) {
9730+ switch (strlen (image.colorTable[i].c_color)) {
9731+ case 4:
9732+ buf[1] = '\0';
9733+ buf[0] = image.colorTable[i].c_color[1];
9734+ red = strtol(buf, NULL, 16);
9735+
9736+ buf[0] = image.colorTable[i].c_color[2];
9737+ green = strtol(buf, NULL, 16);
9738+
9739+ buf[0] = image.colorTable[i].c_color[3];
9740+ blue = strtol(buf, NULL, 16);
9741+ break;
9742+
9743+ case 7:
9744+ buf[2] = '\0';
9745+ buf[0] = image.colorTable[i].c_color[1];
9746+ buf[1] = image.colorTable[i].c_color[2];
9747+ red = strtol(buf, NULL, 16);
9748+
9749+ buf[0] = image.colorTable[i].c_color[3];
9750+ buf[1] = image.colorTable[i].c_color[4];
9751+ green = strtol(buf, NULL, 16);
9752+
9753+ buf[0] = image.colorTable[i].c_color[5];
9754+ buf[1] = image.colorTable[i].c_color[6];
9755+ blue = strtol(buf, NULL, 16);
9756+ break;
9757+
9758+ case 10:
9759+ buf[3] = '\0';
9760+ buf[0] = image.colorTable[i].c_color[1];
9761+ buf[1] = image.colorTable[i].c_color[2];
9762+ buf[2] = image.colorTable[i].c_color[3];
9763+ red = strtol(buf, NULL, 16);
9764+ red /= 64;
9765+
9766+ buf[0] = image.colorTable[i].c_color[4];
9767+ buf[1] = image.colorTable[i].c_color[5];
9768+ buf[2] = image.colorTable[i].c_color[6];
9769+ green = strtol(buf, NULL, 16);
9770+ green /= 64;
9771+
9772+ buf[0] = image.colorTable[i].c_color[7];
9773+ buf[1] = image.colorTable[i].c_color[8];
9774+ buf[2] = image.colorTable[i].c_color[9];
9775+ blue = strtol(buf, NULL, 16);
9776+ blue /= 64;
9777+ break;
9778+
9779+ case 13:
9780+ buf[4] = '\0';
9781+ buf[0] = image.colorTable[i].c_color[1];
9782+ buf[1] = image.colorTable[i].c_color[2];
9783+ buf[2] = image.colorTable[i].c_color[3];
9784+ buf[3] = image.colorTable[i].c_color[4];
9785+ red = strtol(buf, NULL, 16);
9786+ red /= 256;
9787+
9788+ buf[0] = image.colorTable[i].c_color[5];
9789+ buf[1] = image.colorTable[i].c_color[6];
9790+ buf[2] = image.colorTable[i].c_color[7];
9791+ buf[3] = image.colorTable[i].c_color[8];
9792+ green = strtol(buf, NULL, 16);
9793+ green /= 256;
9794+
9795+ buf[0] = image.colorTable[i].c_color[9];
9796+ buf[1] = image.colorTable[i].c_color[10];
9797+ buf[2] = image.colorTable[i].c_color[11];
9798+ buf[3] = image.colorTable[i].c_color[12];
9799+ blue = strtol(buf, NULL, 16);
9800+ blue /= 256;
9801+ break;
9802+ }
9803+
9804+
9805+ colors[i] = gdImageColorResolve(im, red, green, blue);
9806+ if (colors[i] == -1) {
9807+ php_gd_error("ARRRGH");
9808+ }
9809 }
9810- }
9811- gdFree (apixel);
9812- gdFree (colors);
9813- return (im);
9814+
9815+ apixel = (char *) gdMalloc(image.cpp + 1);
9816+ apixel[image.cpp] = '\0';
9817+
9818+ pointer = (int *) image.data;
9819+ for (i = 0; i < image.height; i++) {
9820+ for (j = 0; j < image.width; j++) {
9821+ k = *pointer++;
9822+ gdImageSetPixel(im, j, i, colors[k]);
9823+ }
9824+ }
9825+
9826+ gdFree(apixel);
9827+ gdFree(colors);
9828+ return im;
9829 }
9830 #endif
9831diff -urN php-4.4.8.org/ext/gd/libgd/testac.c php-4.4.8/ext/gd/libgd/testac.c
9832--- php-4.4.8.org/ext/gd/libgd/testac.c 2002-04-13 04:03:09.000000000 +0200
9833+++ php-4.4.8/ext/gd/libgd/testac.c 2003-12-28 21:11:08.000000000 +0100
9834@@ -33,7 +33,7 @@
9835 }
9836 /* Load original PNG, which should contain alpha channel
9837 information. We will use it in two ways: preserving it
9838- literally, for use with compatible browsers, and
9839+ literally, for use with compatible browsers, and
9840 compositing it ourselves against a background of our
9841 choosing (alpha blending). We'll change its size
9842 and try creating palette versions of it. */
9843@@ -80,7 +80,7 @@
9844 /* Create output image. */
9845 im_out = gdImageCreateTrueColor ((int) (gdImageSX (im_in) * scale),
9846 (int) (gdImageSY (im_in) * scale));
9847- /*
9848+ /*
9849 Request alpha blending. This causes future
9850 drawing operations to perform alpha channel blending
9851 with the background, resulting in an opaque image.
9852@@ -111,7 +111,7 @@
9853
9854 /* If this image is the result of alpha channel blending,
9855 it will not contain an interesting alpha channel itself.
9856- Save a little file size by not saving the alpha channel.
9857+ Save a little file size by not saving the alpha channel.
9858 Otherwise the file would typically be slightly larger. */
9859 gdImageSaveAlpha (im_out, !blending);
9860
9861diff -urN php-4.4.8.org/ext/gd/libgd/wbmp.c php-4.4.8/ext/gd/libgd/wbmp.c
9862--- php-4.4.8.org/ext/gd/libgd/wbmp.c 2007-03-10 14:06:37.000000000 +0100
9863+++ php-4.4.8/ext/gd/libgd/wbmp.c 2007-03-10 13:18:36.000000000 +0100
9864@@ -28,7 +28,7 @@
9865
9866 /* getmbi
9867 ** ------
9868- ** Get a multibyte integer from a generic getin function
9869+ ** Get a multibyte integer from a generic getin function
9870 ** 'getin' can be getc, with in = NULL
9871 ** you can find getin as a function just above the main function
9872 ** This way you gain a lot of flexibilty about how this package
9873@@ -125,7 +125,7 @@
9874 return NULL;
9875 }
9876
9877- if ((wbmp->bitmap = (int *) safe_emalloc(sizeof(int), (width * height), 0)) == NULL)
9878+ if ((wbmp->bitmap = (int *) safe_emalloc(sizeof(int), width * height, 0)) == NULL)
9879 {
9880 gdFree (wbmp);
9881 return (NULL);
9882@@ -192,7 +192,7 @@
9883 return (-1);
9884 }
9885
9886- if ((wbmp->bitmap = (int *) safe_emalloc(sizeof(int), (wbmp->width * wbmp->height), 0)) == NULL)
9887+ if ((wbmp->bitmap = (int *) safe_emalloc((size_t)wbmp->width * wbmp->height, sizeof(int), 0)) == NULL)
9888 {
9889 gdFree (wbmp);
9890 return (-1);
9891@@ -240,7 +240,7 @@
9892 ** Why not just giving a filedescriptor to this function?
9893 ** Well, the incentive to write this function was the complete
9894 ** integration in gd library from www.boutell.com. They use
9895- ** their own io functions, so the passing of a function seemed to be
9896+ ** their own io functions, so the passing of a function seemed to be
9897 ** a logic(?) decision ...
9898 **
9899 */
9900@@ -335,7 +335,7 @@
9901 return (putc (c, (FILE *) out));
9902 }
9903
9904-/* getin from file descriptor
9905+/* getin from file descriptor
9906 ** --------------------------
9907 */
9908 int
9909diff -urN php-4.4.8.org/ext/gd/libgd/wbmp.h php-4.4.8/ext/gd/libgd/wbmp.h
9910--- php-4.4.8.org/ext/gd/libgd/wbmp.h 2002-04-13 04:03:09.000000000 +0200
9911+++ php-4.4.8/ext/gd/libgd/wbmp.h 2005-10-09 14:06:27.000000000 +0200
9912@@ -8,17 +8,22 @@
9913 ** (c) 2000 Johan Van den Brande <johan@vandenbrande.com>
9914 **
9915 ** Header file
9916-*/
9917+*/
9918 #ifndef __WBMP_H
9919 #define __WBMP_H 1
9920
9921+#ifdef HAVE_CONFIG_H
9922+#include "config.h"
9923+#endif
9924+
9925+#include "php_compat.h"
9926
9927 /* WBMP struct
9928 ** -----------
9929 ** A Wireless bitmap structure
9930 **
9931 */
9932-
9933+
9934 typedef struct Wbmp_
9935 {
9936 int type; /* type of the wbmp */
9937@@ -26,22 +31,22 @@
9938 int height; /* height of the image */
9939 int *bitmap; /* pointer to data: 0 = WHITE , 1 = BLACK */
9940 } Wbmp;
9941-
9942+
9943 #define WBMP_WHITE 1
9944 #define WBMP_BLACK 0
9945-
9946+
9947
9948 /* Proto's
9949 ** -------
9950 **
9951 */
9952-void putmbi( int i, void (*putout)(int c, void *out), void *out);
9953+void putmbi( int i, void (*putout)(int c, void *out), void *out);
9954 int getmbi ( int (*getin)(void *in), void *in );
9955 int skipheader( int (*getin)(void *in), void *in );
9956 Wbmp *createwbmp( int width, int height, int color );
9957 int readwbmp( int (*getin)(void *in), void *in, Wbmp **wbmp );
9958 int writewbmp( Wbmp *wbmp, void (*putout)( int c, void *out), void *out);
9959 void freewbmp( Wbmp *wbmp );
9960-void printwbmp( Wbmp *wbmp );
9961+void printwbmp( Wbmp *wbmp );
9962
9963 #endif
9964diff -urN php-4.4.8.org/ext/gd/libgd/webpng.c php-4.4.8/ext/gd/libgd/webpng.c
9965--- php-4.4.8.org/ext/gd/libgd/webpng.c 2002-04-21 15:48:22.000000000 +0200
9966+++ php-4.4.8/ext/gd/libgd/webpng.c 2007-02-24 03:17:24.000000000 +0100
9967@@ -193,7 +193,7 @@
9968 maxy = gdImageSY(im);
9969
9970 printf("alpha channel information:\n");
9971-
9972+
9973 if (im->trueColor) {
9974 for (y = 0; y < maxy; y++) {
9975 for (x = 0; x < maxx; x++) {
9976@@ -215,9 +215,9 @@
9977 }
9978 else
9979 printf("NOT a true color image\n");
9980- no = 0;
9981+ no = 0;
9982 printf("%d alpha channels\n", nalpha);
9983-
9984+
9985 }
9986 else
9987 {
9988@@ -252,7 +252,7 @@
9989 /* Open a temporary file. */
9990
9991 /* "temp.tmp" is not good temporary filename. */
9992- sprintf (outFn, "webpng.tmp%d", getpid ());
9993+ snprintf (outFn, sizeof(outFn), "webpng.tmp%d", getpid ());
9994 out = fopen (outFn, "wb");
9995
9996 if (!out)
9997diff -urN php-4.4.8.org/ext/gd/libgd/xbm.c php-4.4.8/ext/gd/libgd/xbm.c
9998--- php-4.4.8.org/ext/gd/libgd/xbm.c 2007-12-31 08:22:47.000000000 +0100
9999+++ php-4.4.8/ext/gd/libgd/xbm.c 2007-08-09 14:08:29.000000000 +0200
10000@@ -1,8 +1,8 @@
10001 /*
10002 +----------------------------------------------------------------------+
10003- | PHP Version 4 |
10004+ | PHP Version 5 |
10005 +----------------------------------------------------------------------+
10006- | Copyright (c) 1997-2008 The PHP Group |
10007+ | Copyright (c) 1997-2007 The PHP Group |
10008 +----------------------------------------------------------------------+
10009 | This source file is subject to version 3.01 of the PHP license, |
10010 | that is bundled with this package in the file LICENSE, and is |
10011@@ -16,7 +16,7 @@
10012 +----------------------------------------------------------------------+
10013 */
10014
10015-/* $Id$ */
10016+/* $Id$ */
10017
10018 #include <stdio.h>
10019 #include <math.h>
10020@@ -29,8 +29,8 @@
10021
10022 #define MAX_XBM_LINE_SIZE 255
10023
10024-gdImagePtr
10025-gdImageCreateFromXbm (FILE * fd)
10026+/* {{{ gdImagePtr gdImageCreateFromXbm */
10027+gdImagePtr gdImageCreateFromXbm(FILE * fd)
10028 {
10029 char fline[MAX_XBM_LINE_SIZE];
10030 char iname[MAX_XBM_LINE_SIZE];
10031@@ -46,7 +46,7 @@
10032 int ch;
10033 char h[8];
10034 unsigned int b;
10035-
10036+
10037 rewind(fd);
10038 while (fgets(fline, MAX_XBM_LINE_SIZE, fd)) {
10039 fline[MAX_XBM_LINE_SIZE-1] = '\0';
10040@@ -59,7 +59,7 @@
10041 } else {
10042 type++;
10043 }
10044-
10045+
10046 if (!strcmp("width", type)) {
10047 width = (unsigned int) value;
10048 }
10049@@ -96,7 +96,9 @@
10050 return 0;
10051 }
10052
10053- im = gdImageCreate(width, height);
10054+ if(!(im = gdImageCreate(width, height))) {
10055+ return 0;
10056+ }
10057 gdImageColorAllocate(im, 255, 255, 255);
10058 gdImageColorAllocate(im, 0, 0, 0);
10059 h[2] = '\0';
10060@@ -147,7 +149,93 @@
10061 }
10062 }
10063
10064- php_gd_error("EOF before image was complete\n");
10065+ php_gd_error("EOF before image was complete");
10066 gdImageDestroy(im);
10067 return 0;
10068 }
10069+/* }}} */
10070+
10071+/* {{{ gdCtxPrintf */
10072+void gdCtxPrintf(gdIOCtx * out, const char *format, ...)
10073+{
10074+ char *buf;
10075+ int len;
10076+ va_list args;
10077+
10078+ va_start(args, format);
10079+ len = vspprintf(&buf, 0, format, args);
10080+ va_end(args);
10081+ out->putBuf(out, buf, len);
10082+ efree(buf);
10083+}
10084+/* }}} */
10085+
10086+/* {{{ gdImageXbmCtx */
10087+void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out)
10088+{
10089+ int x, y, c, b, sx, sy, p;
10090+ char *name, *f;
10091+ size_t i, l;
10092+
10093+ name = file_name;
10094+ if ((f = strrchr(name, '/')) != NULL) name = f+1;
10095+ if ((f = strrchr(name, '\\')) != NULL) name = f+1;
10096+ name = estrdup(name);
10097+ if ((f = strrchr(name, '.')) != NULL && !strcasecmp(f, ".XBM")) *f = '\0';
10098+ if ((l = strlen(name)) == 0) {
10099+ efree(name);
10100+ name = estrdup("image");
10101+ } else {
10102+ for (i=0; i<l; i++) {
10103+ /* only in C-locale isalnum() would work */
10104+ if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) {
10105+ name[i] = '_';
10106+ }
10107+ }
10108+ }
10109+
10110+ gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image));
10111+ gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image));
10112+ gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name);
10113+
10114+ efree(name);
10115+
10116+ b = 1;
10117+ p = 0;
10118+ c = 0;
10119+ sx = gdImageSX(image);
10120+ sy = gdImageSY(image);
10121+ for (y = 0; y < sy; y++) {
10122+ for (x = 0; x < sx; x++) {
10123+ if (gdImageGetPixel(image, x, y) == fg) {
10124+ c |= b;
10125+ }
10126+ if ((b == 128) || (x == sx && y == sy)) {
10127+ b = 1;
10128+ if (p) {
10129+ gdCtxPrintf(out, ", ");
10130+ if (!(p%12)) {
10131+ gdCtxPrintf(out, "\n ");
10132+ p = 12;
10133+ }
10134+ }
10135+ p++;
10136+ gdCtxPrintf(out, "0x%02X", c);
10137+ c = 0;
10138+ } else {
10139+ b <<= 1;
10140+ }
10141+ }
10142+ }
10143+ gdCtxPrintf(out, "};\n");
10144+}
10145+/* }}} */
10146+
10147+/*
10148+ * Local variables:
10149+ * tab-width: 4
10150+ * c-basic-offset: 4
10151+ * End:
10152+ * vim600: sw=4 ts=4 fdm=marker
10153+ * vim<600: sw=4 ts=4
10154+ */
23005b3f
AM
10155diff -urN php-4.4.8.org/ext/gd/php_gd.h php-4.4.8/ext/gd/php_gd.h
10156--- php-4.4.8.org/ext/gd/php_gd.h 2007-12-31 08:22:47.000000000 +0100
84aee732 10157+++ php-4.4.8/ext/gd/php_gd.h 2008-01-22 22:38:05.897151947 +0100
23005b3f 10158@@ -1,8 +1,8 @@
fa2ea656
AM
10159 /*
10160 +----------------------------------------------------------------------+
10161- | PHP Version 4 |
10162+ | PHP Version 5 |
10163 +----------------------------------------------------------------------+
23005b3f
AM
10164- | Copyright (c) 1997-2008 The PHP Group |
10165+ | Copyright (c) 1997-2007 The PHP Group |
fa2ea656 10166 +----------------------------------------------------------------------+
23005b3f
AM
10167 | This source file is subject to version 3.01 of the PHP license, |
10168 | that is bundled with this package in the file LICENSE, and is |
10169@@ -13,11 +13,11 @@
10170 | license@php.net so we can mail you a copy immediately. |
fa2ea656 10171 +----------------------------------------------------------------------+
23005b3f
AM
10172 | Authors: Rasmus Lerdorf <rasmus@php.net> |
10173- | Stig Bakken <ssb@fast.no> |
10174+ | Stig Bakken <ssb@php.net> |
10175 +----------------------------------------------------------------------+
10176 */
fa2ea656
AM
10177
10178-/* $Id$ */
10179+/* $Id$ */
10180
23005b3f
AM
10181 #ifndef PHP_GD_H
10182 #define PHP_GD_H
10183@@ -32,7 +32,7 @@
10184
10185 /* open_basedir and safe_mode checks */
10186 #define PHP_GD_CHECK_OPEN_BASEDIR(filename, errormsg) \
10187- if (!filename || filename == empty_string || php_check_open_basedir(filename TSRMLS_CC) || \
10188+ if (!filename || php_check_open_basedir(filename TSRMLS_CC) || \
10189 (PG(safe_mode) && !php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR)) \
10190 ) { \
10191 php_error_docref(NULL TSRMLS_CC, E_WARNING, errormsg); \
10192@@ -66,7 +66,9 @@
10193 /* gd.c functions */
10194 PHP_MINFO_FUNCTION(gd);
10195 PHP_MINIT_FUNCTION(gd);
10196+#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
10197 PHP_MSHUTDOWN_FUNCTION(gd);
10198+#endif
10199 #if HAVE_LIBGD20 && HAVE_GD_STRINGFT
10200 PHP_RSHUTDOWN_FUNCTION(gd);
10201 #endif
10202@@ -112,6 +114,11 @@
10203 PHP_FUNCTION(imagecopyresampled);
10204 #endif
fa2ea656 10205
23005b3f
AM
10206+#ifdef PHP_WIN32
10207+PHP_FUNCTION(imagegrabwindow);
10208+PHP_FUNCTION(imagegrabscreen);
10209+#endif
fa2ea656 10210+
23005b3f
AM
10211 #ifdef HAVE_GD_BUNDLED
10212 PHP_FUNCTION(imagerotate);
10213 PHP_FUNCTION(imageantialias);
10214@@ -184,6 +191,8 @@
10215 PHP_FUNCTION(imagelayereffect);
10216 PHP_FUNCTION(imagecolormatch);
10217 PHP_FUNCTION(imagefilter);
10218+PHP_FUNCTION(imageconvolution);
10219+PHP_FUNCTION(imagexbm);
10220 #endif
fa2ea656 10221
23005b3f 10222 PHP_GD_API int phpi_get_le_gd(void);
This page took 1.237811 seconds and 4 git commands to generate.