]>
Commit | Line | Data |
---|---|---|
23005b3f AM |
1 | diff -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 |
27 | diff -urN php-4.4.8.org/ext/gd/gd.c php-4.4.8/ext/gd/gd.c |
28 | --- php-4.4.8.org/ext/gd/gd.c 2007-12-31 08:22:47.000000000 +0100 | |
84aee732 | 29 | +++ php-4.4.8/ext/gd/gd.c 2008-01-22 22:38:05.837148890 +0100 |
23005b3f AM |
30 | @@ -29,7 +29,13 @@ |
31 | #include "config.h" | |
32 | #endif | |
33 | ||
34 | +#ifdef HAVE_GD_PNG | |
35 | +/* needs to be first */ | |
36 | +#include <png.h> | |
37 | +#endif | |
38 | + | |
39 | #include "php.h" | |
40 | +#include "php_ini.h" | |
41 | #include "ext/standard/head.h" | |
42 | #include <math.h> | |
43 | #include "SAPI.h" | |
44 | @@ -46,6 +52,9 @@ | |
45 | #ifdef PHP_WIN32 | |
46 | # include <io.h> | |
47 | # include <fcntl.h> | |
48 | +#include <windows.h> | |
49 | +#include <Winuser.h> | |
50 | +#include <Wingdi.h> | |
51 | #endif | |
52 | ||
53 | #if HAVE_LIBGD | |
fd438bd3 AM |
54 | @@ -64,10 +73,20 @@ |
55 | #include <gdfontmb.h> /* 3 Medium bold font */ | |
56 | #include <gdfontl.h> /* 4 Large font */ | |
57 | #include <gdfontg.h> /* 5 Giant font */ | |
58 | +#if HAVE_GD_BUNDLED | |
59 | #ifdef HAVE_GD_WBMP | |
23005b3f AM |
60 | #include "libgd/wbmp.h" |
61 | #endif | |
fd438bd3 | 62 | +#endif |
23005b3f AM |
63 | #ifdef ENABLE_GD_TTF |
64 | +# ifdef HAVE_LIBFREETYPE | |
65 | +# include <ft2build.h> | |
66 | +# include FT_FREETYPE_H | |
67 | +# else | |
68 | +# ifdef HAVE_LIBTTF | |
69 | +# include <freetype.h> | |
70 | +# endif | |
71 | +# endif | |
72 | # include "gdttf.h" | |
73 | #endif | |
74 | ||
fd438bd3 | 75 | @@ -112,6 +131,40 @@ |
23005b3f AM |
76 | #define gdNewDynamicCtxEx(len, data, val) gdNewDynamicCtx(len, data) |
77 | #endif | |
78 | ||
79 | +/* Section Filters Declarations */ | |
80 | +/* IMPORTANT NOTE FOR NEW FILTER | |
81 | + * Do not forget to update: | |
82 | + * IMAGE_FILTER_MAX: define the last filter index | |
83 | + * IMAGE_FILTER_MAX_ARGS: define the biggest amout of arguments | |
84 | + * image_filter array in PHP_FUNCTION(imagefilter) | |
85 | + * */ | |
86 | +#if HAVE_GD_BUNDLED | |
87 | +#define IMAGE_FILTER_NEGATE 0 | |
88 | +#define IMAGE_FILTER_GRAYSCALE 1 | |
89 | +#define IMAGE_FILTER_BRIGHTNESS 2 | |
90 | +#define IMAGE_FILTER_CONTRAST 3 | |
91 | +#define IMAGE_FILTER_COLORIZE 4 | |
92 | +#define IMAGE_FILTER_EDGEDETECT 5 | |
93 | +#define IMAGE_FILTER_EMBOSS 6 | |
94 | +#define IMAGE_FILTER_GAUSSIAN_BLUR 7 | |
95 | +#define IMAGE_FILTER_SELECTIVE_BLUR 8 | |
96 | +#define IMAGE_FILTER_MEAN_REMOVAL 9 | |
97 | +#define IMAGE_FILTER_SMOOTH 10 | |
98 | +#define IMAGE_FILTER_MAX 10 | |
99 | +#define IMAGE_FILTER_MAX_ARGS 5 | |
100 | +static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS); | |
101 | +static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS); | |
102 | +static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS); | |
103 | +static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS); | |
104 | +static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS); | |
105 | +static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS); | |
106 | +static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS); | |
107 | +static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS); | |
108 | +static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS); | |
109 | +static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS); | |
110 | +static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS); | |
111 | +#endif | |
112 | +/* End Section filters declarations */ | |
113 | static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC); | |
114 | static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)()); | |
115 | static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()); | |
fd438bd3 | 116 | @@ -121,7 +174,7 @@ |
23005b3f AM |
117 | |
118 | /* {{{ gd_functions[] | |
119 | */ | |
120 | -function_entry gd_functions[] = { | |
121 | +zend_function_entry gd_functions[] = { | |
122 | PHP_FE(gd_info, NULL) | |
123 | PHP_FE(imagearc, NULL) | |
124 | PHP_FE(imageellipse, NULL) | |
fd438bd3 | 125 | @@ -167,6 +220,11 @@ |
23005b3f AM |
126 | PHP_FE(imagecopyresampled, NULL) |
127 | #endif | |
128 | ||
129 | +#ifdef PHP_WIN32 | |
130 | + PHP_FE(imagegrabwindow, NULL) | |
131 | + PHP_FE(imagegrabscreen, NULL) | |
132 | +#endif | |
133 | + | |
134 | #ifdef HAVE_GD_BUNDLED | |
135 | PHP_FE(imagerotate, NULL) | |
136 | PHP_FE(imageantialias, NULL) | |
fd438bd3 | 137 | @@ -277,6 +335,12 @@ |
23005b3f AM |
138 | #if HAVE_GD_BUNDLED |
139 | PHP_FE(imagelayereffect, NULL) | |
140 | PHP_FE(imagecolormatch, NULL) | |
141 | + PHP_FE(imagexbm, NULL) | |
142 | +#endif | |
143 | +/* gd filters */ | |
144 | +#ifdef HAVE_GD_BUNDLED | |
145 | + PHP_FE(imagefilter, NULL) | |
146 | + PHP_FE(imageconvolution, NULL) | |
147 | #endif | |
148 | ||
149 | {NULL, NULL, NULL} | |
fd438bd3 | 150 | @@ -288,9 +352,13 @@ |
23005b3f AM |
151 | "gd", |
152 | gd_functions, | |
153 | PHP_MINIT(gd), | |
154 | +#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX | |
155 | PHP_MSHUTDOWN(gd), | |
156 | +#else | |
fd438bd3 AM |
157 | + NULL, |
158 | +#endif | |
23005b3f AM |
159 | NULL, |
160 | -#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE) | |
23005b3f AM |
161 | +#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)) |
162 | PHP_RSHUTDOWN(gd), | |
163 | #else | |
164 | NULL, | |
fd438bd3 | 165 | @@ -304,6 +372,12 @@ |
23005b3f AM |
166 | ZEND_GET_MODULE(gd) |
167 | #endif | |
168 | ||
169 | +/* {{{ PHP_INI_BEGIN */ | |
170 | +PHP_INI_BEGIN() | |
171 | + PHP_INI_ENTRY("gd.jpeg_ignore_warning", "0", PHP_INI_ALL, NULL) | |
172 | +PHP_INI_END() | |
173 | +/* }}} */ | |
174 | + | |
175 | /* {{{ php_free_gd_image | |
176 | */ | |
177 | static void php_free_gd_image(zend_rsrc_list_entry *rsrc TSRMLS_DC) | |
fd438bd3 | 178 | @@ -326,15 +400,21 @@ |
23005b3f AM |
179 | } |
180 | /* }}} */ | |
181 | ||
182 | + | |
183 | /* {{{ PHP_MSHUTDOWN_FUNCTION | |
184 | */ | |
185 | +#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX | |
186 | PHP_MSHUTDOWN_FUNCTION(gd) | |
187 | { | |
fa2ea656 AM |
188 | #if HAVE_LIBT1 |
189 | T1_CloseLib(); | |
190 | #endif | |
23005b3f AM |
191 | +#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE |
192 | + gdFontCacheMutexShutdown(); | |
fa2ea656 AM |
193 | +#endif |
194 | return SUCCESS; | |
195 | } | |
23005b3f | 196 | +#endif |
fa2ea656 | 197 | /* }}} */ |
23005b3f AM |
198 | |
199 | ||
fd438bd3 | 200 | @@ -344,6 +424,10 @@ |
fa2ea656 AM |
201 | { |
202 | le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number); | |
203 | le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number); | |
23005b3f AM |
204 | + |
205 | +#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE | |
206 | + gdFontCacheMutexSetup(); | |
fa2ea656 AM |
207 | +#endif |
208 | #if HAVE_LIBT1 | |
209 | T1_SetBitmapPad(8); | |
210 | T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE); | |
fd438bd3 | 211 | @@ -352,6 +436,8 @@ |
23005b3f AM |
212 | le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number); |
213 | #endif | |
fa2ea656 | 214 | |
23005b3f AM |
215 | + REGISTER_INI_ENTRIES(); |
216 | + | |
217 | REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT); | |
218 | REGISTER_LONG_CONSTANT("IMG_JPG", 2, CONST_CS | CONST_PERSISTENT); | |
219 | REGISTER_LONG_CONSTANT("IMG_JPEG", 2, CONST_CS | CONST_PERSISTENT); | |
fd438bd3 | 220 | @@ -387,16 +473,58 @@ |
23005b3f AM |
221 | REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT); |
222 | REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT); | |
223 | REGISTER_LONG_CONSTANT("GD_BUNDLED", 1, CONST_CS | CONST_PERSISTENT); | |
224 | + | |
225 | + /* Section Filters */ | |
226 | + REGISTER_LONG_CONSTANT("IMG_FILTER_NEGATE", IMAGE_FILTER_NEGATE, CONST_CS | CONST_PERSISTENT); | |
227 | + REGISTER_LONG_CONSTANT("IMG_FILTER_GRAYSCALE", IMAGE_FILTER_GRAYSCALE, CONST_CS | CONST_PERSISTENT); | |
228 | + REGISTER_LONG_CONSTANT("IMG_FILTER_BRIGHTNESS", IMAGE_FILTER_BRIGHTNESS, CONST_CS | CONST_PERSISTENT); | |
229 | + REGISTER_LONG_CONSTANT("IMG_FILTER_CONTRAST", IMAGE_FILTER_CONTRAST, CONST_CS | CONST_PERSISTENT); | |
230 | + REGISTER_LONG_CONSTANT("IMG_FILTER_COLORIZE", IMAGE_FILTER_COLORIZE, CONST_CS | CONST_PERSISTENT); | |
231 | + REGISTER_LONG_CONSTANT("IMG_FILTER_EDGEDETECT", IMAGE_FILTER_EDGEDETECT, CONST_CS | CONST_PERSISTENT); | |
232 | + REGISTER_LONG_CONSTANT("IMG_FILTER_GAUSSIAN_BLUR", IMAGE_FILTER_GAUSSIAN_BLUR, CONST_CS | CONST_PERSISTENT); | |
233 | + REGISTER_LONG_CONSTANT("IMG_FILTER_SELECTIVE_BLUR", IMAGE_FILTER_SELECTIVE_BLUR, CONST_CS | CONST_PERSISTENT); | |
234 | + REGISTER_LONG_CONSTANT("IMG_FILTER_EMBOSS", IMAGE_FILTER_EMBOSS, CONST_CS | CONST_PERSISTENT); | |
235 | + REGISTER_LONG_CONSTANT("IMG_FILTER_MEAN_REMOVAL", IMAGE_FILTER_MEAN_REMOVAL, CONST_CS | CONST_PERSISTENT); | |
236 | + REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT); | |
237 | + /* End Section Filters */ | |
238 | #else | |
239 | REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT); | |
240 | #endif | |
fa2ea656 | 241 | + |
23005b3f AM |
242 | +#ifdef GD_VERSION_STRING |
243 | + REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT); | |
244 | +#endif | |
fa2ea656 | 245 | + |
23005b3f AM |
246 | +#if defined(GD_MAJOR_VERSION) && defined(GD_MINOR_VERSION) && defined(GD_RELEASE_VERSION) && defined(GD_EXTRA_VERSION) |
247 | + REGISTER_LONG_CONSTANT("GD_MAJOR_VERSION", GD_MAJOR_VERSION, CONST_CS | CONST_PERSISTENT); | |
248 | + REGISTER_LONG_CONSTANT("GD_MINOR_VERSION", GD_MINOR_VERSION, CONST_CS | CONST_PERSISTENT); | |
249 | + REGISTER_LONG_CONSTANT("GD_RELEASE_VERSION", GD_RELEASE_VERSION, CONST_CS | CONST_PERSISTENT); | |
250 | + REGISTER_STRING_CONSTANT("GD_EXTRA_VERSION", GD_EXTRA_VERSION, CONST_CS | CONST_PERSISTENT); | |
251 | +#endif | |
fa2ea656 | 252 | + |
fa2ea656 | 253 | + |
23005b3f | 254 | +#ifdef HAVE_GD_PNG |
fa2ea656 | 255 | + |
23005b3f AM |
256 | +/* |
257 | + * cannot include #include "png.h" | |
258 | + * /usr/include/pngconf.h:310:2: error: #error png.h already includes setjmp.h with some additional fixup. | |
259 | + * as error, use the values for now... | |
260 | + */ | |
261 | + REGISTER_LONG_CONSTANT("PNG_NO_FILTER", 0x00, CONST_CS | CONST_PERSISTENT); | |
262 | + REGISTER_LONG_CONSTANT("PNG_FILTER_NONE", 0x08, CONST_CS | CONST_PERSISTENT); | |
263 | + REGISTER_LONG_CONSTANT("PNG_FILTER_SUB", 0x10, CONST_CS | CONST_PERSISTENT); | |
264 | + REGISTER_LONG_CONSTANT("PNG_FILTER_UP", 0x20, CONST_CS | CONST_PERSISTENT); | |
265 | + REGISTER_LONG_CONSTANT("PNG_FILTER_AVG", 0x40, CONST_CS | CONST_PERSISTENT); | |
266 | + REGISTER_LONG_CONSTANT("PNG_FILTER_PAETH", 0x80, CONST_CS | CONST_PERSISTENT); | |
267 | + REGISTER_LONG_CONSTANT("PNG_ALL_FILTERS", 0x08 | 0x10 | 0x20 | 0x40 | 0x80, CONST_CS | CONST_PERSISTENT); | |
268 | +#endif | |
269 | return SUCCESS; | |
fa2ea656 | 270 | } |
23005b3f | 271 | /* }}} */ |
fa2ea656 | 272 | |
23005b3f | 273 | /* {{{ PHP_RSHUTDOWN_FUNCTION |
fa2ea656 | 274 | */ |
23005b3f AM |
275 | -#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE) |
276 | +#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)) | |
277 | PHP_RSHUTDOWN_FUNCTION(gd) | |
278 | { | |
279 | #if HAVE_GD_FONTCACHESHUTDOWN | |
fd438bd3 | 280 | @@ -410,7 +538,7 @@ |
23005b3f AM |
281 | /* }}} */ |
282 | ||
283 | #if HAVE_GD_BUNDLED | |
284 | -#define PHP_GD_VERSION_STRING "bundled (2.0.28 compatible)" | |
285 | +#define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)" | |
286 | #elif HAVE_LIBGD20 | |
287 | #define PHP_GD_VERSION_STRING "2.0 or higher" | |
288 | #elif HAVE_GDIMAGECOLORRESOLVE | |
fd438bd3 | 289 | @@ -436,8 +564,24 @@ |
23005b3f AM |
290 | php_info_print_table_row(2, "FreeType Support", "enabled"); |
291 | #if HAVE_LIBFREETYPE | |
292 | php_info_print_table_row(2, "FreeType Linkage", "with freetype"); | |
293 | + { | |
294 | + char tmp[256]; | |
295 | +#ifdef FREETYPE_PATCH | |
296 | + snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH); | |
297 | +#elif defined(FREETYPE_MAJOR) | |
298 | + snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR); | |
299 | +#else | |
300 | + snprintf(tmp, sizeof(tmp), "1.x"); | |
301 | +#endif | |
302 | + php_info_print_table_row(2, "FreeType Version", tmp); | |
303 | + } | |
304 | #elif HAVE_LIBTTF | |
305 | php_info_print_table_row(2, "FreeType Linkage", "with TTF library"); | |
306 | + { | |
307 | + char tmp[256]; | |
308 | + snprintf(tmp, sizeof(tmp), "%d.%d", TT_FREETYPE_MAJOR, TT_FREETYPE_MINOR); | |
309 | + php_info_print_table_row(2, "FreeType Version", tmp); | |
310 | + } | |
311 | #else | |
312 | php_info_print_table_row(2, "FreeType Linkage", "with unknown library"); | |
313 | #endif | |
fd438bd3 | 314 | @@ -464,6 +608,9 @@ |
23005b3f AM |
315 | #ifdef HAVE_GD_WBMP |
316 | php_info_print_table_row(2, "WBMP Support", "enabled"); | |
317 | #endif | |
318 | +#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED) | |
319 | + php_info_print_table_row(2, "XPM Support", "enabled"); | |
320 | +#endif | |
321 | #ifdef HAVE_GD_XBM | |
322 | php_info_print_table_row(2, "XBM Support", "enabled"); | |
323 | #endif | |
fd438bd3 | 324 | @@ -530,6 +677,11 @@ |
23005b3f AM |
325 | #else |
326 | add_assoc_bool(return_value, "WBMP Support", 0); | |
327 | #endif | |
328 | +#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED) | |
329 | + add_assoc_bool(return_value, "XPM Support", 1); | |
330 | +#else | |
331 | + add_assoc_bool(return_value, "XPM Support", 0); | |
332 | +#endif | |
333 | #ifdef HAVE_GD_XBM | |
334 | add_assoc_bool(return_value, "XBM Support", 1); | |
335 | #else | |
fd438bd3 | 336 | @@ -548,6 +700,7 @@ |
23005b3f AM |
337 | { |
338 | return le_gd; | |
339 | } | |
340 | +/* }}} */ | |
fa2ea656 | 341 | |
23005b3f | 342 | #ifndef HAVE_GDIMAGECOLORRESOLVE |
fa2ea656 | 343 | |
fd438bd3 | 344 | @@ -763,13 +916,19 @@ |
23005b3f AM |
345 | convert_to_long_ex(x_size); |
346 | convert_to_long_ex(y_size); | |
fa2ea656 | 347 | |
23005b3f AM |
348 | - if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0) { |
349 | + if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 || | |
350 | + Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX | |
351 | + ) { | |
352 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions"); | |
353 | RETURN_FALSE; | |
fa2ea656 | 354 | } |
23005b3f AM |
355 | |
356 | im = gdImageCreateTrueColor(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size)); | |
357 | ||
358 | + if (!im) { | |
359 | + RETURN_FALSE; | |
360 | + } | |
fa2ea656 | 361 | + |
23005b3f | 362 | ZEND_REGISTER_RESOURCE(return_value, im, le_gd); |
fa2ea656 | 363 | } |
23005b3f | 364 | /* }}} */ |
fd438bd3 | 365 | @@ -836,15 +995,19 @@ |
23005b3f AM |
366 | result = gdImageColorMatch(im1, im2); |
367 | switch (result) { | |
368 | case -1: | |
369 | - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image1 must be TrueColor" ); | |
370 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 must be TrueColor" ); | |
371 | RETURN_FALSE; | |
372 | break; | |
373 | case -2: | |
374 | - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image2 must be Palette" ); | |
375 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must be Palette" ); | |
376 | RETURN_FALSE; | |
377 | break; | |
378 | case -3: | |
379 | - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image1 and Image2 must be the same size" ); | |
380 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 and Image2 must be the same size" ); | |
381 | + RETURN_FALSE; | |
382 | + break; | |
383 | + case -4: | |
384 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must have at least one color" ); | |
385 | RETURN_FALSE; | |
386 | break; | |
387 | } | |
fd438bd3 | 388 | @@ -977,6 +1140,7 @@ |
fa2ea656 | 389 | |
23005b3f | 390 | RETURN_TRUE; |
fa2ea656 | 391 | } |
23005b3f AM |
392 | +/* }}} */ |
393 | #endif | |
fa2ea656 | 394 | |
23005b3f | 395 | #if HAVE_GD_BUNDLED |
fd438bd3 | 396 | @@ -1008,6 +1172,7 @@ |
23005b3f AM |
397 | zval *IM; |
398 | long red, green, blue, alpha; | |
399 | gdImagePtr im; | |
400 | + int ct = (-1); | |
fa2ea656 | 401 | |
23005b3f AM |
402 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { |
403 | RETURN_FALSE; | |
fd438bd3 | 404 | @@ -1015,7 +1180,12 @@ |
fa2ea656 | 405 | |
23005b3f AM |
406 | ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); |
407 | ||
408 | - RETURN_LONG(gdImageColorAllocateAlpha(im, red, green, blue, alpha)); | |
409 | + ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha); | |
410 | + if (ct < 0) { | |
411 | + RETURN_FALSE; | |
412 | + } | |
fa2ea656 | 413 | + |
23005b3f AM |
414 | + RETURN_LONG((long)ct); |
415 | } | |
416 | /* }}} */ | |
fa2ea656 | 417 | |
fd438bd3 | 418 | @@ -1125,28 +1295,173 @@ |
23005b3f AM |
419 | /* }}} */ |
420 | #endif | |
421 | ||
422 | +#ifdef PHP_WIN32 | |
423 | +/* {{{ proto resource imagegrabwindow(int window_handle [, int client_area]) | |
424 | + Grab a window or its client area using a windows handle (HWND property in COM instance) */ | |
425 | +PHP_FUNCTION(imagegrabwindow) | |
426 | +{ | |
427 | + HWND window; | |
428 | + long client_area = 0; | |
429 | + RECT rc = {0}; | |
430 | + RECT rc_win = {0}; | |
431 | + int Width, Height; | |
432 | + HDC hdc; | |
433 | + HDC memDC; | |
434 | + HBITMAP memBM; | |
435 | + HBITMAP hOld; | |
436 | + HINSTANCE handle; | |
437 | + long lwindow_handle; | |
438 | + typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT); | |
439 | + tPrintWindow pPrintWindow = 0; | |
440 | + gdImagePtr im; | |
441 | + | |
442 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &lwindow_handle, &client_area) == FAILURE) { | |
443 | + RETURN_FALSE; | |
444 | + } | |
445 | + | |
446 | + window = (HWND) lwindow_handle; | |
fa2ea656 | 447 | + |
23005b3f AM |
448 | + if (!IsWindow(window)) { |
449 | + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid window handle"); | |
450 | + RETURN_FALSE; | |
451 | + } | |
452 | + | |
453 | + hdc = GetDC(0); | |
454 | + | |
455 | + if (client_area) { | |
456 | + GetClientRect(window, &rc); | |
457 | + Width = rc.right; | |
458 | + Height = rc.bottom; | |
459 | + } else { | |
460 | + GetWindowRect(window, &rc); | |
461 | + Width = rc.right - rc.left; | |
462 | + Height = rc.bottom - rc.top; | |
463 | + } | |
464 | + | |
465 | + Width = (Width/4)*4; | |
466 | + | |
467 | + memDC = CreateCompatibleDC(hdc); | |
468 | + memBM = CreateCompatibleBitmap(hdc, Width, Height); | |
469 | + hOld = (HBITMAP) SelectObject (memDC, memBM); | |
470 | + | |
471 | + | |
472 | + handle = LoadLibrary("User32.dll"); | |
473 | + if ( handle == 0 ) { | |
474 | + goto clean; | |
475 | + } | |
476 | + pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow"); | |
477 | + | |
478 | + if ( pPrintWindow ) { | |
479 | + pPrintWindow(window, memDC, (UINT) client_area); | |
480 | + } else { | |
481 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows API too old"); | |
482 | + RETURN_FALSE; | |
483 | + goto clean; | |
484 | + } | |
485 | + | |
486 | + FreeLibrary(handle); | |
487 | + | |
488 | + im = gdImageCreateTrueColor(Width, Height); | |
489 | + if (im) { | |
490 | + int x,y; | |
491 | + for (y=0; y <= Height; y++) { | |
492 | + for (x=0; x <= Width; x++) { | |
493 | + int c = GetPixel(memDC, x,y); | |
494 | + gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c))); | |
fa2ea656 AM |
495 | + } |
496 | + } | |
23005b3f AM |
497 | + } |
498 | + | |
499 | +clean: | |
500 | + SelectObject(memDC,hOld); | |
501 | + DeleteObject(memBM); | |
502 | + DeleteDC(memDC); | |
503 | + ReleaseDC( 0, hdc ); | |
504 | + | |
505 | + if (!im) { | |
506 | + RETURN_FALSE; | |
507 | + } else { | |
508 | + ZEND_REGISTER_RESOURCE(return_value, im, le_gd); | |
509 | + } | |
510 | +} | |
511 | +/* }}} */ | |
512 | + | |
513 | +/* {{{ proto resource imagegrabscreen() | |
514 | + Grab a screenshot */ | |
515 | +PHP_FUNCTION(imagegrabscreen) | |
516 | +{ | |
517 | + HWND window = GetDesktopWindow(); | |
518 | + RECT rc = {0}; | |
519 | + int Width, Height; | |
520 | + HDC hdc; | |
521 | + HDC memDC; | |
522 | + HBITMAP memBM; | |
523 | + HBITMAP hOld; | |
524 | + HINSTANCE handle; | |
525 | + long lwindow_handle; | |
526 | + typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT); | |
527 | + tPrintWindow pPrintWindow = 0; | |
528 | + gdImagePtr im; | |
529 | + hdc = GetDC(0); | |
530 | + | |
531 | + if (!hdc) { | |
532 | + RETURN_FALSE; | |
533 | + } | |
534 | + | |
535 | + GetWindowRect(window, &rc); | |
536 | + Width = rc.right - rc.left; | |
537 | + Height = rc.bottom - rc.top; | |
fa2ea656 | 538 | + |
23005b3f AM |
539 | + Width = (Width/4)*4; |
540 | + | |
541 | + memDC = CreateCompatibleDC(hdc); | |
542 | + memBM = CreateCompatibleBitmap(hdc, Width, Height); | |
543 | + hOld = (HBITMAP) SelectObject (memDC, memBM); | |
544 | + BitBlt( memDC, 0, 0, Width, Height , hdc, rc.left, rc.top , SRCCOPY ); | |
545 | + | |
546 | + im = gdImageCreateTrueColor(Width, Height); | |
547 | + if (im) { | |
548 | + int x,y; | |
549 | + for (y=0; y <= Height; y++) { | |
550 | + for (x=0; x <= Width; x++) { | |
551 | + int c = GetPixel(memDC, x,y); | |
552 | + gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c))); | |
fa2ea656 AM |
553 | + } |
554 | + } | |
fa2ea656 AM |
555 | + } |
556 | + | |
23005b3f AM |
557 | + SelectObject(memDC,hOld); |
558 | + DeleteObject(memBM); | |
559 | + DeleteDC(memDC); | |
560 | + ReleaseDC( 0, hdc ); | |
fa2ea656 | 561 | + |
23005b3f AM |
562 | + if (!im) { |
563 | + RETURN_FALSE; | |
564 | + } else { | |
565 | + ZEND_REGISTER_RESOURCE(return_value, im, le_gd); | |
566 | + } | |
fa2ea656 | 567 | +} |
23005b3f AM |
568 | +/* }}} */ |
569 | +#endif /* PHP_WIN32 */ | |
570 | + | |
571 | #ifdef HAVE_GD_BUNDLED | |
572 | -/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor) | |
573 | +/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor [, int ignoretransparent]) | |
574 | Rotate an image using a custom angle */ | |
575 | PHP_FUNCTION(imagerotate) | |
576 | { | |
577 | - zval **SIM, **ANGLE, **BGDCOLOR; | |
578 | + zval *SIM; | |
579 | gdImagePtr im_dst, im_src; | |
580 | double degrees; | |
581 | long color; | |
582 | + long ignoretransparent = 0; | |
fa2ea656 | 583 | |
23005b3f AM |
584 | - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &SIM, &ANGLE, &BGDCOLOR) == FAILURE) { |
585 | - ZEND_WRONG_PARAM_COUNT(); | |
586 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdl|l", &SIM, °rees, &color, &ignoretransparent) == FAILURE) { | |
587 | + RETURN_FALSE; | |
fa2ea656 AM |
588 | } |
589 | ||
23005b3f AM |
590 | - ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); |
591 | - | |
592 | - convert_to_long_ex(BGDCOLOR); | |
593 | - color = Z_LVAL_PP(BGDCOLOR); | |
594 | + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); | |
fa2ea656 | 595 | |
23005b3f AM |
596 | - convert_to_double_ex(ANGLE); |
597 | - degrees = Z_DVAL_PP(ANGLE); | |
598 | - im_dst = gdImageRotate(im_src, degrees, color); | |
599 | + im_dst = gdImageRotate(im_src, degrees, color, ignoretransparent); | |
600 | ||
601 | if (im_dst != NULL) { | |
602 | ZEND_REGISTER_RESOURCE(return_value, im_dst, le_gd); | |
fd438bd3 | 603 | @@ -1215,13 +1530,19 @@ |
23005b3f AM |
604 | convert_to_long_ex(x_size); |
605 | convert_to_long_ex(y_size); | |
606 | ||
607 | - if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0) { | |
608 | + if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 || | |
609 | + Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX | |
610 | + ) { | |
611 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions"); | |
612 | RETURN_FALSE; | |
fa2ea656 | 613 | } |
fa2ea656 | 614 | |
23005b3f | 615 | im = gdImageCreate(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size)); |
fa2ea656 | 616 | |
23005b3f AM |
617 | + if (!im) { |
618 | + RETURN_FALSE; | |
fa2ea656 AM |
619 | + } |
620 | + | |
23005b3f AM |
621 | ZEND_REGISTER_RESOURCE(return_value, im, le_gd); |
622 | } | |
623 | /* }}} */ | |
fd438bd3 | 624 | @@ -1323,6 +1644,11 @@ |
23005b3f AM |
625 | im = (*ioctx_func_p)(io_ctx); |
626 | if (!im) { | |
627 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed data is not in '%s' format", tn); | |
628 | +#if HAVE_LIBGD204 | |
629 | + io_ctx->gd_free(io_ctx); | |
630 | +#else | |
631 | + io_ctx->free(io_ctx); | |
632 | +#endif | |
633 | return NULL; | |
fa2ea656 AM |
634 | } |
635 | ||
fd438bd3 | 636 | @@ -1350,6 +1676,11 @@ |
fa2ea656 | 637 | } |
fa2ea656 | 638 | |
23005b3f AM |
639 | convert_to_string_ex(data); |
640 | + if (Z_STRLEN_PP(data) < 8) { | |
641 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string or invalid image"); | |
642 | + RETURN_FALSE; | |
643 | + } | |
fa2ea656 | 644 | + |
23005b3f | 645 | memcpy(sig, Z_STRVAL_PP(data), 8); |
fa2ea656 | 646 | |
23005b3f | 647 | imtype = _php_image_type(sig); |
fd438bd3 | 648 | @@ -1401,7 +1732,7 @@ |
23005b3f | 649 | break; |
fa2ea656 | 650 | |
23005b3f AM |
651 | default: |
652 | - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format."); | |
653 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format"); | |
654 | RETURN_FALSE; | |
fa2ea656 AM |
655 | } |
656 | ||
fd438bd3 | 657 | @@ -1425,6 +1756,9 @@ |
23005b3f AM |
658 | php_stream *stream; |
659 | FILE * fp = NULL; | |
660 | int argc=ZEND_NUM_ARGS(); | |
661 | +#ifdef HAVE_GD_JPG | |
662 | + long ignore_warning; | |
663 | +#endif | |
fa2ea656 | 664 | |
23005b3f AM |
665 | if ((image_type == PHP_GDIMG_TYPE_GD2PART && argc != 5) || |
666 | (image_type != PHP_GDIMG_TYPE_GD2PART && argc != 1) || | |
fd438bd3 | 667 | @@ -1436,6 +1770,10 @@ |
fa2ea656 | 668 | |
23005b3f AM |
669 | if (argc == 5 && image_type == PHP_GDIMG_TYPE_GD2PART) { |
670 | multi_convert_to_long_ex(4, srcx, srcy, width, height); | |
671 | + if (Z_LVAL_PP(width) < 1 || Z_LVAL_PP(height) < 1) { | |
672 | + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Zero width or height not allowed"); | |
673 | + RETURN_FALSE; | |
674 | + } | |
fa2ea656 AM |
675 | } |
676 | ||
23005b3f | 677 | fn = Z_STRVAL_PP(file); |
fd438bd3 | 678 | @@ -1471,6 +1809,7 @@ |
23005b3f AM |
679 | |
680 | io_ctx = gdNewDynamicCtxEx(buff_size, buff, 0); | |
681 | if (!io_ctx) { | |
682 | + pefree(buff, 1); | |
683 | php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context"); | |
684 | goto out_err; | |
fa2ea656 | 685 | } |
fd438bd3 | 686 | @@ -1485,7 +1824,7 @@ |
23005b3f AM |
687 | #else |
688 | io_ctx->free(io_ctx); | |
689 | #endif | |
fa2ea656 | 690 | - |
23005b3f AM |
691 | + pefree(buff, 1); |
692 | #endif | |
fa2ea656 | 693 | } |
23005b3f | 694 | else { |
fd438bd3 | 695 | @@ -1505,6 +1844,18 @@ |
23005b3f AM |
696 | im = gdImageCreateFromXpm(fn); |
697 | break; | |
698 | #endif | |
fa2ea656 | 699 | + |
23005b3f AM |
700 | +#ifdef HAVE_GD_JPG |
701 | + case PHP_GDIMG_TYPE_JPG: | |
702 | + ignore_warning = INI_INT("gd.jpeg_ignore_warning"); | |
703 | +#ifdef HAVE_GD_BUNDLED | |
704 | + im = gdImageCreateFromJpeg(fp, ignore_warning); | |
705 | +#else | |
706 | + im = gdImageCreateFromJpeg(fp); | |
707 | +#endif | |
708 | + break; | |
709 | +#endif | |
fa2ea656 | 710 | + |
23005b3f AM |
711 | default: |
712 | im = (*func_p)(fp); | |
713 | break; | |
fd438bd3 | 714 | @@ -1685,6 +2036,14 @@ |
23005b3f AM |
715 | (*func_p)(im, fp); |
716 | break; | |
717 | #endif | |
718 | +#ifdef HAVE_GD_GD2 | |
719 | + case PHP_GDIMG_TYPE_GD2: | |
720 | + if (q == -1) { | |
721 | + q = 128; | |
fa2ea656 | 722 | + } |
23005b3f AM |
723 | + (*func_p)(im, fp, q, t); |
724 | + break; | |
725 | +#endif | |
726 | default: | |
727 | if (q == -1) { | |
728 | q = 128; | |
fd438bd3 | 729 | @@ -1737,6 +2096,14 @@ |
23005b3f AM |
730 | (*func_p)(im, tmp); |
731 | break; | |
732 | #endif | |
733 | +#ifdef HAVE_GD_GD2 | |
734 | + case PHP_GDIMG_TYPE_GD2: | |
735 | + if (q == -1) { | |
736 | + q = 128; | |
fa2ea656 | 737 | + } |
23005b3f AM |
738 | + (*func_p)(im, tmp, q, t); |
739 | + break; | |
740 | +#endif | |
741 | default: | |
742 | (*func_p)(im, tmp); | |
743 | break; | |
fd438bd3 | 744 | @@ -1762,6 +2129,16 @@ |
fa2ea656 | 745 | } |
23005b3f | 746 | /* }}} */ |
fa2ea656 | 747 | |
23005b3f AM |
748 | +/* {{{ proto int imagexbm(int im, string filename [, int foreground]) |
749 | + Output XBM image to browser or file */ | |
750 | +#if HAVE_GD_BUNDLED | |
751 | +PHP_FUNCTION(imagexbm) | |
752 | +{ | |
753 | + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx); | |
754 | +} | |
755 | +#endif | |
756 | +/* }}} */ | |
fa2ea656 | 757 | + |
23005b3f AM |
758 | #ifdef HAVE_GD_GIF_CREATE |
759 | /* {{{ proto bool imagegif(resource im [, string filename]) | |
760 | Output GIF image to browser or file */ | |
fd438bd3 | 761 | @@ -1782,7 +2159,7 @@ |
23005b3f AM |
762 | PHP_FUNCTION(imagepng) |
763 | { | |
764 | #ifdef USE_GD_IOCTX | |
765 | - _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtx); | |
766 | + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtxEx); | |
767 | #else | |
768 | _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng); | |
769 | #endif | |
fd438bd3 | 770 | @@ -1862,6 +2239,7 @@ |
23005b3f AM |
771 | { |
772 | zval **IM, **red, **green, **blue; | |
773 | gdImagePtr im; | |
774 | + int ct = (-1); | |
fa2ea656 | 775 | |
23005b3f AM |
776 | if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { |
777 | ZEND_WRONG_PARAM_COUNT(); | |
fd438bd3 | 778 | @@ -1872,8 +2250,11 @@ |
23005b3f AM |
779 | convert_to_long_ex(red); |
780 | convert_to_long_ex(green); | |
781 | convert_to_long_ex(blue); | |
782 | - | |
783 | - RETURN_LONG(gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); | |
784 | + ct = gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)); | |
785 | + if (ct < 0) { | |
786 | + RETURN_FALSE; | |
787 | + } | |
788 | + RETURN_LONG(ct); | |
fa2ea656 | 789 | } |
23005b3f | 790 | /* }}} */ |
fa2ea656 | 791 | |
fd438bd3 | 792 | @@ -2508,7 +2889,7 @@ |
23005b3f | 793 | static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled) |
fa2ea656 | 794 | { |
23005b3f AM |
795 | zval **IM, **POINTS, **NPOINTS, **COL; |
796 | - pval **var = NULL; | |
797 | + zval **var = NULL; | |
798 | gdImagePtr im; | |
799 | gdPointPtr points; | |
800 | int npoints, col, nelem, i; | |
fd438bd3 | 801 | @@ -2716,7 +3097,7 @@ |
23005b3f | 802 | ch = (int)((unsigned char)*(Z_STRVAL_PP(C))); |
fa2ea656 | 803 | } else { |
23005b3f AM |
804 | str = (unsigned char *) estrndup(Z_STRVAL_PP(C), Z_STRLEN_PP(C)); |
805 | - l = strlen(str); | |
806 | + l = strlen((char *)str); | |
fa2ea656 | 807 | } |
fa2ea656 | 808 | |
23005b3f | 809 | y = Z_LVAL_PP(Y); |
fd438bd3 | 810 | @@ -3083,7 +3464,7 @@ |
23005b3f AM |
811 | { |
812 | char tmp_font_path[MAXPATHLEN]; | |
fa2ea656 | 813 | |
23005b3f AM |
814 | - if (VCWD_REALPATH(fontname, tmp_font_path)) { |
815 | + if (VCWD_REALPATH((char *)fontname, tmp_font_path)) { | |
816 | fontname = (unsigned char *) fontname; | |
817 | } else { | |
818 | fontname = NULL; | |
fd438bd3 | 819 | @@ -3093,16 +3474,18 @@ |
23005b3f AM |
820 | fontname = (unsigned char *) fontname; |
821 | #endif | |
fa2ea656 | 822 | |
23005b3f AM |
823 | + PHP_GD_CHECK_OPEN_BASEDIR((char *)fontname, "Invalid font filename"); |
824 | + | |
825 | #ifdef USE_GD_IMGSTRTTF | |
826 | # if HAVE_GD_STRINGFTEX | |
827 | if (extended) { | |
828 | - error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex); | |
829 | + error = gdImageStringFTEx(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str, &strex); | |
830 | } | |
831 | else | |
832 | # endif | |
833 | ||
834 | # if HAVE_GD_STRINGFT | |
835 | - error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str); | |
836 | + error = gdImageStringFT(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str); | |
837 | # elif HAVE_GD_STRINGTTF | |
838 | error = gdImageStringTTF(im, brect, col, fontname, ptsize, angle, x, y, str); | |
839 | # endif | |
fd438bd3 | 840 | @@ -3155,6 +3538,9 @@ |
23005b3f AM |
841 | { |
842 | zval **file; | |
843 | int f_ind, *font; | |
844 | +#ifdef PHP_WIN32 | |
845 | + struct stat st; | |
846 | +#endif | |
fa2ea656 | 847 | |
23005b3f AM |
848 | if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) { |
849 | ZEND_WRONG_PARAM_COUNT(); | |
fd438bd3 | 850 | @@ -3162,24 +3548,18 @@ |
fa2ea656 | 851 | |
23005b3f | 852 | convert_to_string_ex(file); |
fa2ea656 | 853 | |
23005b3f AM |
854 | +#ifdef PHP_WIN32 |
855 | + if (VCWD_STAT(Z_STRVAL_PP(file), &st) < 0) { | |
856 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Font file not found (%s)", Z_STRVAL_PP(file)); | |
857 | + RETURN_FALSE; | |
fa2ea656 | 858 | + } |
23005b3f | 859 | +#endif |
fa2ea656 | 860 | + |
23005b3f AM |
861 | f_ind = T1_AddFont(Z_STRVAL_PP(file)); |
862 | ||
863 | if (f_ind < 0) { | |
864 | - switch (f_ind) { | |
865 | - case -1: | |
866 | - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't find the font file"); | |
867 | - RETURN_FALSE; | |
868 | - break; | |
869 | - case -2: | |
870 | - case -3: | |
871 | - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memory allocation fault in t1lib"); | |
872 | - RETURN_FALSE; | |
873 | - break; | |
874 | - default: | |
875 | - php_error_docref(NULL TSRMLS_CC, E_WARNING, "An unknown error occurred in t1lib"); | |
876 | - RETURN_FALSE; | |
877 | - break; | |
878 | - } | |
879 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind)); | |
880 | + RETURN_FALSE; | |
fa2ea656 AM |
881 | } |
882 | ||
23005b3f | 883 | if (T1_LoadFont(f_ind)) { |
fd438bd3 | 884 | @@ -3317,6 +3697,11 @@ |
fa2ea656 | 885 | |
23005b3f | 886 | T1_DeleteAllSizes(*f_ind); |
fa2ea656 | 887 | |
23005b3f AM |
888 | + if (Z_DVAL_PP(ext) <= 0) { |
889 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter %F out of range (must be > 0)", Z_DVAL_PP(ext)); | |
890 | + RETURN_FALSE; | |
fa2ea656 AM |
891 | + } |
892 | + | |
23005b3f AM |
893 | if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) { |
894 | RETURN_FALSE; | |
fa2ea656 | 895 | } |
fd438bd3 | 896 | @@ -3348,7 +3733,7 @@ |
fa2ea656 | 897 | } |
23005b3f | 898 | /* }}} */ |
fa2ea656 | 899 | |
23005b3f AM |
900 | -/* {{{ proto array imagepstext(resource image, string text, resource font, int size, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias]) |
901 | +/* {{{ 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]) | |
902 | Rasterize a string over an image */ | |
903 | PHP_FUNCTION(imagepstext) | |
fa2ea656 | 904 | { |
fd438bd3 | 905 | @@ -3371,11 +3756,6 @@ |
23005b3f AM |
906 | T1_TMATRIX *transform = NULL; |
907 | char *str; | |
908 | int str_len; | |
909 | - int argc = ZEND_NUM_ARGS(); | |
910 | - | |
911 | - if (argc != 8 && argc != 12) { | |
912 | - ZEND_WRONG_PARAM_COUNT(); | |
913 | - } | |
fa2ea656 | 914 | |
23005b3f AM |
915 | 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) { |
916 | return; | |
fd438bd3 | 917 | @@ -3455,7 +3835,7 @@ |
fa2ea656 | 918 | |
23005b3f AM |
919 | if (!str_path) { |
920 | if (T1_errno) { | |
921 | - php_error_docref(NULL TSRMLS_CC, E_WARNING, "libt1 returned error %d", T1_errno); | |
922 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno)); | |
923 | } | |
924 | RETURN_FALSE; | |
925 | } | |
fd438bd3 | 926 | @@ -3476,7 +3856,7 @@ |
23005b3f | 927 | str_img = T1_AASetString(*f_ind, str, str_len, space, T1_KERNING, size, transform); |
fa2ea656 | 928 | } |
23005b3f AM |
929 | if (T1_errno) { |
930 | - php_error_docref(NULL TSRMLS_CC, E_WARNING, "libt1 returned error %d", T1_errno); | |
931 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno)); | |
932 | RETURN_FALSE; | |
fa2ea656 AM |
933 | } |
934 | ||
fd438bd3 | 935 | @@ -3719,7 +4099,10 @@ |
23005b3f AM |
936 | int int_threshold; |
937 | int x, y; | |
938 | float x_ratio, y_ratio; | |
fa2ea656 | 939 | - |
23005b3f AM |
940 | +#ifdef HAVE_GD_JPG |
941 | + long ignore_warning; | |
942 | +#endif | |
943 | + | |
944 | if (argc != 5 || zend_get_parameters_ex(argc, &f_org, &f_dest, &height, &width, &threshold) == FAILURE) { | |
945 | ZEND_WRONG_PARAM_COUNT(); | |
fa2ea656 | 946 | } |
fd438bd3 | 947 | @@ -3775,7 +4158,12 @@ |
fa2ea656 | 948 | |
23005b3f AM |
949 | #ifdef HAVE_GD_JPG |
950 | case PHP_GDIMG_TYPE_JPG: | |
951 | + ignore_warning = INI_INT("gd.jpeg_ignore_warning"); | |
952 | +#ifdef HAVE_GD_BUNDLED | |
953 | + im_org = gdImageCreateFromJpeg(org, ignore_warning); | |
954 | +#else | |
955 | im_org = gdImageCreateFromJpeg(org); | |
956 | +#endif | |
957 | if (im_org == NULL) { | |
958 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid JPEG file", fn_dest); | |
959 | RETURN_FALSE; | |
fd438bd3 | 960 | @@ -3886,7 +4274,282 @@ |
23005b3f AM |
961 | /* }}} */ |
962 | #endif /* HAVE_GD_WBMP */ | |
fa2ea656 | 963 | |
23005b3f | 964 | +#endif /* HAVE_LIBGD */ |
fa2ea656 | 965 | + |
23005b3f AM |
966 | +/* Section Filters */ |
967 | #ifdef HAVE_GD_BUNDLED | |
fa2ea656 | 968 | + |
23005b3f AM |
969 | +#define PHP_GD_SINGLE_RES \ |
970 | + zval **SIM; \ | |
971 | + gdImagePtr im_src; \ | |
972 | + if (zend_get_parameters_ex(1, &SIM) == FAILURE) { \ | |
973 | + RETURN_FALSE; \ | |
974 | + } \ | |
975 | + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); \ | |
976 | + if (im_src == NULL) { \ | |
977 | + RETURN_FALSE; \ | |
978 | + } | |
fa2ea656 | 979 | + |
23005b3f AM |
980 | +static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS) |
981 | +{ | |
982 | + PHP_GD_SINGLE_RES | |
fa2ea656 | 983 | + |
23005b3f AM |
984 | + if (gdImageNegate(im_src) == 1) { |
985 | + RETURN_TRUE; | |
986 | + } | |
fa2ea656 | 987 | + |
23005b3f | 988 | + RETURN_FALSE; |
fa2ea656 AM |
989 | +} |
990 | + | |
23005b3f AM |
991 | +static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS) |
992 | +{ | |
993 | + PHP_GD_SINGLE_RES | |
fa2ea656 | 994 | + |
23005b3f AM |
995 | + if (gdImageGrayScale(im_src) == 1) { |
996 | + RETURN_TRUE; | |
997 | + } | |
fa2ea656 | 998 | + |
23005b3f AM |
999 | + RETURN_FALSE; |
1000 | +} | |
fa2ea656 | 1001 | + |
23005b3f | 1002 | +static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS) |
fa2ea656 | 1003 | +{ |
23005b3f AM |
1004 | + zval *SIM; |
1005 | + gdImagePtr im_src; | |
1006 | + long brightness, tmp; | |
fa2ea656 | 1007 | + |
23005b3f AM |
1008 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &SIM, &tmp, &brightness) == FAILURE) { |
1009 | + RETURN_FALSE; | |
fa2ea656 AM |
1010 | + } |
1011 | + | |
23005b3f | 1012 | + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); |
fa2ea656 | 1013 | + |
23005b3f AM |
1014 | + if (im_src == NULL) { |
1015 | + RETURN_FALSE; | |
1016 | + } | |
fa2ea656 | 1017 | + |
23005b3f AM |
1018 | + if (gdImageBrightness(im_src, (int)brightness) == 1) { |
1019 | + RETURN_TRUE; | |
fa2ea656 | 1020 | + } |
23005b3f AM |
1021 | + |
1022 | + RETURN_FALSE; | |
fa2ea656 AM |
1023 | +} |
1024 | + | |
23005b3f | 1025 | +static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS) |
fa2ea656 | 1026 | +{ |
23005b3f AM |
1027 | + zval *SIM; |
1028 | + gdImagePtr im_src; | |
1029 | + long contrast, tmp; | |
fa2ea656 | 1030 | + |
23005b3f AM |
1031 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &SIM, &tmp, &contrast) == FAILURE) { |
1032 | + RETURN_FALSE; | |
fa2ea656 AM |
1033 | + } |
1034 | + | |
23005b3f | 1035 | + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); |
fa2ea656 | 1036 | + |
23005b3f AM |
1037 | + if (im_src == NULL) { |
1038 | + RETURN_FALSE; | |
fa2ea656 | 1039 | + } |
23005b3f AM |
1040 | + |
1041 | + if (gdImageContrast(im_src, (int)contrast) == 1) { | |
1042 | + RETURN_TRUE; | |
1043 | + } | |
1044 | + | |
1045 | + RETURN_FALSE; | |
fa2ea656 AM |
1046 | +} |
1047 | + | |
23005b3f | 1048 | +static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS) |
fa2ea656 | 1049 | +{ |
23005b3f AM |
1050 | + zval *SIM; |
1051 | + gdImagePtr im_src; | |
1052 | + long r,g,b,tmp; | |
1053 | + long a = 0; | |
fa2ea656 | 1054 | + |
23005b3f AM |
1055 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &SIM, &tmp, &r, &g, &b, &a) == FAILURE) { |
1056 | + RETURN_FALSE; | |
fa2ea656 AM |
1057 | + } |
1058 | + | |
23005b3f | 1059 | + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); |
fa2ea656 | 1060 | + |
23005b3f AM |
1061 | + if (im_src == NULL) { |
1062 | + RETURN_FALSE; | |
1063 | + } | |
fa2ea656 | 1064 | + |
23005b3f AM |
1065 | + if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) { |
1066 | + RETURN_TRUE; | |
1067 | + } | |
fa2ea656 | 1068 | + |
23005b3f AM |
1069 | + RETURN_FALSE; |
1070 | +} | |
fa2ea656 | 1071 | + |
23005b3f AM |
1072 | +static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS) |
1073 | +{ | |
1074 | + PHP_GD_SINGLE_RES | |
fa2ea656 | 1075 | + |
23005b3f AM |
1076 | + if (gdImageEdgeDetectQuick(im_src) == 1) { |
1077 | + RETURN_TRUE; | |
fa2ea656 | 1078 | + } |
fa2ea656 | 1079 | + |
23005b3f AM |
1080 | + RETURN_FALSE; |
1081 | +} | |
fa2ea656 | 1082 | + |
23005b3f | 1083 | +static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS) |
fa2ea656 | 1084 | +{ |
23005b3f | 1085 | + PHP_GD_SINGLE_RES |
fa2ea656 | 1086 | + |
23005b3f AM |
1087 | + if (gdImageEmboss(im_src) == 1) { |
1088 | + RETURN_TRUE; | |
fa2ea656 AM |
1089 | + } |
1090 | + | |
23005b3f AM |
1091 | + RETURN_FALSE; |
1092 | +} | |
1093 | + | |
1094 | +static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS) | |
1095 | +{ | |
1096 | + PHP_GD_SINGLE_RES | |
fa2ea656 | 1097 | + |
23005b3f AM |
1098 | + if (gdImageGaussianBlur(im_src) == 1) { |
1099 | + RETURN_TRUE; | |
1100 | + } | |
fa2ea656 | 1101 | + |
23005b3f AM |
1102 | + RETURN_FALSE; |
1103 | +} | |
fa2ea656 | 1104 | + |
23005b3f AM |
1105 | +static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS) |
1106 | +{ | |
1107 | + PHP_GD_SINGLE_RES | |
fa2ea656 | 1108 | + |
23005b3f AM |
1109 | + if (gdImageSelectiveBlur(im_src) == 1) { |
1110 | + RETURN_TRUE; | |
1111 | + } | |
fa2ea656 | 1112 | + |
23005b3f AM |
1113 | + RETURN_FALSE; |
1114 | +} | |
fa2ea656 | 1115 | + |
23005b3f AM |
1116 | +static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS) |
1117 | +{ | |
1118 | + PHP_GD_SINGLE_RES | |
fa2ea656 | 1119 | + |
23005b3f AM |
1120 | + if (gdImageMeanRemoval(im_src) == 1) { |
1121 | + RETURN_TRUE; | |
fa2ea656 | 1122 | + } |
fa2ea656 | 1123 | + |
23005b3f AM |
1124 | + RETURN_FALSE; |
1125 | +} | |
fa2ea656 | 1126 | + |
23005b3f | 1127 | +static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS) |
fa2ea656 | 1128 | +{ |
23005b3f AM |
1129 | + zval *SIM; |
1130 | + long tmp; | |
1131 | + gdImagePtr im_src; | |
1132 | + double weight; | |
fa2ea656 | 1133 | + |
23005b3f AM |
1134 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) { |
1135 | + RETURN_FALSE; | |
fa2ea656 AM |
1136 | + } |
1137 | + | |
23005b3f | 1138 | + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); |
fa2ea656 | 1139 | + |
23005b3f AM |
1140 | + if (im_src == NULL) { |
1141 | + RETURN_FALSE; | |
1142 | + } | |
fa2ea656 | 1143 | + |
23005b3f AM |
1144 | + if (gdImageSmooth(im_src, (float)weight)==1) { |
1145 | + RETURN_TRUE; | |
1146 | + } | |
fa2ea656 | 1147 | + |
23005b3f AM |
1148 | + RETURN_FALSE; |
1149 | +} | |
fa2ea656 | 1150 | + |
23005b3f AM |
1151 | +/* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] ) |
1152 | + Applies Filter an image using a custom angle */ | |
1153 | +PHP_FUNCTION(imagefilter) | |
fa2ea656 | 1154 | +{ |
23005b3f AM |
1155 | + zval *tmp; |
1156 | + | |
1157 | + typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS); | |
1158 | + long filtertype; | |
1159 | + image_filter filters[] = | |
1160 | + { | |
1161 | + php_image_filter_negate , | |
1162 | + php_image_filter_grayscale, | |
1163 | + php_image_filter_brightness, | |
1164 | + php_image_filter_contrast, | |
1165 | + php_image_filter_colorize, | |
1166 | + php_image_filter_edgedetect, | |
1167 | + php_image_filter_emboss, | |
1168 | + php_image_filter_gaussian_blur, | |
1169 | + php_image_filter_selective_blur, | |
1170 | + php_image_filter_mean_removal, | |
1171 | + php_image_filter_smooth | |
1172 | + }; | |
1173 | + | |
1174 | + if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 6) { | |
1175 | + WRONG_PARAM_COUNT; | |
1176 | + } else if (zend_parse_parameters(2 TSRMLS_CC, "rl", &tmp, &filtertype) == FAILURE) { | |
1177 | + return; | |
fa2ea656 AM |
1178 | + } |
1179 | + | |
23005b3f AM |
1180 | + if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) { |
1181 | + filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU); | |
fa2ea656 | 1182 | + } |
fa2ea656 | 1183 | +} |
23005b3f | 1184 | +/* }}} */ |
fa2ea656 | 1185 | + |
23005b3f AM |
1186 | +/* {{{ proto resource imageconvolution(resource src_im, array matrix3x3, double div, double offset) |
1187 | + Apply a 3x3 convolution matrix, using coefficient div and offset */ | |
1188 | +PHP_FUNCTION(imageconvolution) | |
fa2ea656 | 1189 | +{ |
23005b3f AM |
1190 | + zval *SIM, *hash_matrix; |
1191 | + zval **var = NULL, **var2 = NULL; | |
1192 | + gdImagePtr im_src = NULL; | |
1193 | + double div, offset; | |
1194 | + int nelem, i, j, res; | |
1195 | + float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}}; | |
fa2ea656 | 1196 | + |
23005b3f AM |
1197 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "radd", &SIM, &hash_matrix, &div, &offset) == FAILURE) { |
1198 | + RETURN_FALSE; | |
fa2ea656 AM |
1199 | + } |
1200 | + | |
23005b3f | 1201 | + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); |
fa2ea656 | 1202 | + |
23005b3f AM |
1203 | + nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix)); |
1204 | + if (nelem != 3) { | |
1205 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array"); | |
1206 | + RETURN_FALSE; | |
fa2ea656 AM |
1207 | + } |
1208 | + | |
23005b3f AM |
1209 | + for (i=0; i<3; i++) { |
1210 | + if (zend_hash_index_find(Z_ARRVAL_P(hash_matrix), (i), (void **) &var) == SUCCESS && Z_TYPE_PP(var) == IS_ARRAY) { | |
1211 | + if (Z_TYPE_PP(var) != IS_ARRAY || zend_hash_num_elements(Z_ARRVAL_PP(var)) != 3 ) { | |
1212 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array"); | |
1213 | + RETURN_FALSE; | |
fa2ea656 AM |
1214 | + } |
1215 | + | |
fa2ea656 | 1216 | + for (j=0; j<3; j++) { |
23005b3f AM |
1217 | + if (zend_hash_index_find(Z_ARRVAL_PP(var), (j), (void **) &var2) == SUCCESS) { |
1218 | + SEPARATE_ZVAL(var2); | |
1219 | + convert_to_double(*var2); | |
1220 | + matrix[i][j] = Z_DVAL_PP(var2); | |
1221 | + } else { | |
1222 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have a 3x3 matrix"); | |
1223 | + RETURN_FALSE; | |
fa2ea656 AM |
1224 | + } |
1225 | + } | |
fa2ea656 AM |
1226 | + } |
1227 | + } | |
23005b3f | 1228 | + res = gdImageConvolution(im_src, matrix, div, offset); |
fa2ea656 | 1229 | + |
23005b3f AM |
1230 | + if (res) { |
1231 | + RETURN_TRUE; | |
1232 | + } else { | |
1233 | + RETURN_FALSE; | |
1234 | + } | |
fa2ea656 | 1235 | +} |
23005b3f | 1236 | +/* }}} */ |
fa2ea656 | 1237 | + |
23005b3f | 1238 | +/* End section: Filters */ |
fa2ea656 | 1239 | + |
23005b3f AM |
1240 | /* {{{ proto bool imageantialias(resource im, bool on) |
1241 | Should antialiased functions used or not*/ | |
1242 | PHP_FUNCTION(imageantialias) | |
fd438bd3 | 1243 | @@ -3908,8 +4571,6 @@ |
23005b3f AM |
1244 | /* }}} */ |
1245 | #endif | |
fa2ea656 | 1246 | |
23005b3f AM |
1247 | -#endif /* HAVE_LIBGD */ |
1248 | - | |
1249 | /* | |
1250 | * Local variables: | |
1251 | * tab-width: 4 | |
1252 | diff -urN php-4.4.8.org/ext/gd/gdcache.c php-4.4.8/ext/gd/gdcache.c | |
1253 | --- php-4.4.8.org/ext/gd/gdcache.c 2005-01-09 22:05:31.000000000 +0100 | |
84aee732 | 1254 | +++ php-4.4.8/ext/gd/gdcache.c 2008-01-22 22:38:05.863816915 +0100 |
23005b3f AM |
1255 | @@ -59,9 +59,9 @@ |
1256 | int size, | |
1257 | gdCacheTestFn_t gdCacheTest, | |
1258 | gdCacheFetchFn_t gdCacheFetch, | |
1259 | - gdCacheReleaseFn_t gdCacheRelease ) | |
1260 | + gdCacheReleaseFn_t gdCacheRelease ) | |
1261 | { | |
1262 | - gdCache_head_t *head; | |
1263 | + gdCache_head_t *head; | |
1264 | ||
1265 | head = (gdCache_head_t *)pemalloc(sizeof(gdCache_head_t), 1); | |
1266 | head->mru = NULL; | |
23005b3f AM |
1267 | diff -urN php-4.4.8.org/ext/gd/gd_ctx.c php-4.4.8/ext/gd/gd_ctx.c |
1268 | --- php-4.4.8.org/ext/gd/gd_ctx.c 2007-12-31 08:22:47.000000000 +0100 | |
84aee732 | 1269 | +++ php-4.4.8/ext/gd/gd_ctx.c 2008-01-22 22:38:05.863816915 +0100 |
23005b3f AM |
1270 | @@ -15,11 +15,13 @@ |
1271 | | Authors: Stanislav Malyshev <stas@php.net> | | |
1272 | +----------------------------------------------------------------------+ | |
1273 | */ | |
1274 | -#include "php_gd.h" | |
fa2ea656 | 1275 | |
23005b3f AM |
1276 | +/* $Id$ */ |
1277 | + | |
1278 | +#include "php_gd.h" | |
fa2ea656 | 1279 | |
23005b3f AM |
1280 | #define CTX_PUTC(c,ctx) ctx->putC(ctx, c) |
1281 | - | |
1282 | + | |
1283 | static void _php_image_output_putc(struct gdIOCtx *ctx, int c) | |
fa2ea656 | 1284 | { |
23005b3f AM |
1285 | /* without the following downcast, the write will fail |
1286 | @@ -43,20 +45,29 @@ | |
1287 | efree(ctx); | |
1288 | } | |
1289 | } | |
1290 | - | |
1291 | -static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) | |
1292 | + | |
1293 | +/* {{{ _php_image_output_ctx */ | |
1294 | +static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) | |
fa2ea656 | 1295 | { |
23005b3f AM |
1296 | - zval **imgind, **file, **quality; |
1297 | + zval **imgind, **file, **quality, **basefilter; | |
1298 | gdImagePtr im; | |
1299 | char *fn = NULL; | |
1300 | FILE *fp = NULL; | |
1301 | int argc = ZEND_NUM_ARGS(); | |
1302 | int q = -1, i; | |
1303 | + int f = -1; | |
1304 | gdIOCtx *ctx; | |
1305 | ||
1306 | - /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */ | |
1307 | - | |
1308 | - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE) | |
1309 | + /* The third (quality) parameter for Wbmp stands for the threshold when called from image2wbmp(). | |
1310 | + * The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called | |
1311 | + * from imagey<type>(). | |
1312 | + */ | |
1313 | + | |
1314 | + if (argc < 2 && image_type == PHP_GDIMG_TYPE_XBM) { | |
1315 | + WRONG_PARAM_COUNT; | |
1316 | + } | |
1317 | + | |
1318 | + if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc, &imgind, &file, &quality, &basefilter) == FAILURE) | |
1319 | { | |
1320 | WRONG_PARAM_COUNT; | |
1321 | } | |
1322 | @@ -64,20 +75,27 @@ | |
1323 | ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", phpi_get_le_gd()); | |
1324 | ||
1325 | if (argc > 1) { | |
1326 | - convert_to_string_ex(file); | |
1327 | + if (argc >= 2 && Z_TYPE_PP(file) != IS_NULL) { | |
1328 | + convert_to_string_ex(file); | |
1329 | + } | |
1330 | fn = Z_STRVAL_PP(file); | |
1331 | - if (argc == 3) { | |
1332 | + if (argc >= 3) { | |
1333 | convert_to_long_ex(quality); | |
1334 | - q = Z_LVAL_PP(quality); | |
1335 | + q = Z_LVAL_PP(quality);/* or colorindex for foreground of BW images (defaults to black) */ | |
1336 | + if (argc == 4) { | |
1337 | + convert_to_long_ex(basefilter); | |
1338 | + f = Z_LVAL_PP(basefilter); | |
1339 | + } | |
1340 | } | |
1341 | } | |
1342 | ||
1343 | - if ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))) { | |
1344 | + if (argc > 1 && (Z_TYPE_PP(file) != IS_NULL && ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))))) { | |
1345 | + | |
1346 | PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename"); | |
1347 | ||
1348 | fp = VCWD_FOPEN(fn, "wb"); | |
1349 | if (!fp) { | |
1350 | - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn); | |
1351 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing: %s", fn, strerror(errno)); | |
1352 | RETURN_FALSE; | |
1353 | } | |
1354 | ||
1355 | @@ -90,7 +108,7 @@ | |
1356 | ctx->gd_free = _php_image_output_ctxfree; | |
fa2ea656 | 1357 | #else |
23005b3f AM |
1358 | ctx->free = _php_image_output_ctxfree; |
1359 | -#endif | |
fa2ea656 | 1360 | +#endif |
fa2ea656 | 1361 | |
23005b3f AM |
1362 | #if APACHE && defined(CHARSET_EBCDIC) |
1363 | /* XXX this is unlikely to work any more thies@thieso.net */ | |
1364 | @@ -107,27 +125,48 @@ | |
1365 | case PHP_GDIMG_TYPE_JPG: | |
1366 | (*func_p)(im, ctx, q); | |
1367 | break; | |
1368 | + case PHP_GDIMG_TYPE_PNG: | |
1369 | + (*func_p)(im, ctx, q, f); | |
1370 | + break; | |
1371 | + case PHP_GDIMG_TYPE_XBM: | |
1372 | case PHP_GDIMG_TYPE_WBM: | |
1373 | - for(i=0; i < gdImageColorsTotal(im); i++) { | |
1374 | - if(gdImageRed(im, i) == 0) break; | |
1375 | - } | |
1376 | - (*func_p)(im, i, ctx); | |
1377 | + if (argc < 3) { | |
1378 | + for(i=0; i < gdImageColorsTotal(im); i++) { | |
1379 | + if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break; | |
1380 | + } | |
1381 | + q = i; | |
1382 | + } | |
1383 | + if (image_type == PHP_GDIMG_TYPE_XBM) { | |
1384 | + (*func_p)(im, fn, q, ctx); | |
1385 | + } else { | |
1386 | + (*func_p)(im, q, ctx); | |
1387 | + } | |
1388 | break; | |
1389 | default: | |
1390 | (*func_p)(im, ctx); | |
1391 | break; | |
1392 | } | |
fa2ea656 | 1393 | |
23005b3f AM |
1394 | -#if HAVE_LIBGD204 |
1395 | +#if HAVE_LIBGD204 | |
1396 | ctx->gd_free(ctx); | |
1397 | #else | |
1398 | ctx->free(ctx); | |
1399 | -#endif | |
1400 | +#endif | |
fa2ea656 | 1401 | |
23005b3f AM |
1402 | if(fp) { |
1403 | fflush(fp); | |
1404 | fclose(fp); | |
1405 | } | |
1406 | - | |
1407 | + | |
1408 | RETURN_TRUE; | |
fa2ea656 | 1409 | } |
23005b3f AM |
1410 | +/* }}} */ |
1411 | + | |
1412 | +/* | |
1413 | + * Local variables: | |
1414 | + * tab-width: 4 | |
1415 | + * c-basic-offset: 4 | |
1416 | + * End: | |
1417 | + * vim600: sw=4 ts=4 fdm=marker | |
1418 | + * vim<600: sw=4 ts=4 | |
1419 | + */ | |
23005b3f AM |
1420 | diff -urN php-4.4.8.org/ext/gd/gdttf.c php-4.4.8/ext/gd/gdttf.c |
1421 | --- php-4.4.8.org/ext/gd/gdttf.c 2005-01-09 22:05:31.000000000 +0100 | |
84aee732 | 1422 | +++ php-4.4.8/ext/gd/gdttf.c 2008-01-22 22:38:05.887151436 +0100 |
23005b3f AM |
1423 | @@ -42,15 +42,15 @@ |
1424 | /* ptsize below which anti-aliasing is ineffective */ | |
1425 | #define MINANTIALIASPTSIZE 0 | |
1426 | ||
1427 | -/* display resolution - (Not really. This has to be 72 or hinting is wrong) */ | |
1428 | +/* display resolution - (Not really. This has to be 72 or hinting is wrong) */ | |
1429 | #define RESOLUTION 72 | |
1430 | ||
1431 | /* Number of colors used for anti-aliasing */ | |
1432 | #undef NUMCOLORS | |
1433 | #define NUMCOLORS 4 | |
1434 | ||
1435 | -/* Line separation as a factor of font height. | |
1436 | - No space between if LINESPACE = 1.00 | |
1437 | +/* Line separation as a factor of font height. | |
1438 | + No space between if LINESPACE = 1.00 | |
1439 | Line separation will be rounded up to next pixel row*/ | |
fa2ea656 | 1440 | #define LINESPACE 1.05 |
fa2ea656 | 1441 | |
23005b3f AM |
1442 | @@ -125,7 +125,7 @@ |
1443 | glyph_t *glyph; | |
1444 | } bitmapkey_t; | |
1445 | ||
1446 | -typedef struct { | |
1447 | +typedef struct { | |
1448 | unsigned char pixel; /* key */ | |
1449 | unsigned char bgcolor; /* key */ | |
1450 | int fgcolor; /* key */ /* -ve means no antialias */ | |
1451 | @@ -138,7 +138,7 @@ | |
1452 | unsigned char bgcolor; /* key */ | |
1453 | int fgcolor; /* key */ /* -ve means no antialias */ | |
1454 | gdImagePtr im; /* key */ | |
1455 | -} tweencolorkey_t; | |
fa2ea656 AM |
1456 | +} tweencolorkey_t; |
1457 | ||
23005b3f AM |
1458 | /* forward declarations so that glyphCache can be initialized by font code */ |
1459 | static int glyphTest ( void *element, void *key ); | |
1460 | @@ -196,7 +196,7 @@ | |
1461 | * | |
1462 | *--------------------------------------------------------------------------- | |
1463 | */ | |
1464 | - | |
1465 | + | |
1466 | #ifndef CHARSET_EBCDIC | |
1467 | #define ASC(ch) (ch) | |
1468 | #else /*CHARSET_EBCDIC*/ | |
1469 | @@ -205,17 +205,16 @@ | |
fa2ea656 AM |
1470 | |
1471 | #define Tcl_UniChar int | |
1472 | #define TCL_UTF_MAX 3 | |
1473 | -static int | |
23005b3f AM |
1474 | -gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr) |
1475 | +static int gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr) | |
fa2ea656 AM |
1476 | /* str is the UTF8 next character pointer */ |
1477 | /* chPtr is the int for the result */ | |
1478 | { | |
23005b3f AM |
1479 | - int byte; |
1480 | - | |
fa2ea656 AM |
1481 | + int byte; |
1482 | + | |
23005b3f AM |
1483 | /* HTML4.0 entities in decimal form, e.g. Å */ |
1484 | - byte = *((unsigned char *) str); | |
fa2ea656 | 1485 | + byte = *((unsigned char *) str); |
23005b3f AM |
1486 | if (byte == '&') { |
1487 | - int i, n=0; | |
fa2ea656 | 1488 | + int i, n = 0; |
fa2ea656 | 1489 | |
23005b3f AM |
1490 | byte = *((unsigned char *) (str+1)); |
1491 | if (byte == '#') { | |
1492 | @@ -223,9 +222,9 @@ | |
1493 | byte = *((unsigned char *) (str+i)); | |
1494 | if (byte >= '0' && byte <= '9') { | |
1495 | n = (n * 10) + (byte - '0'); | |
1496 | - } | |
1497 | - else | |
1498 | + } else { | |
1499 | break; | |
1500 | + } | |
1501 | } | |
1502 | if (byte == ';') { | |
1503 | *chPtr = (Tcl_UniChar) n; | |
1504 | @@ -233,105 +232,91 @@ | |
1505 | } | |
1506 | } | |
1507 | } | |
1508 | - | |
1509 | - /* | |
1510 | - * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. | |
1511 | - */ | |
1512 | - | |
1513 | - byte = ASC(*((unsigned char *) str)); | |
1514 | - if (byte < 0xC0) { | |
1515 | - /* | |
1516 | - * Handles properly formed UTF-8 characters between 0x01 and 0x7F. | |
1517 | - * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid | |
1518 | - * characters representing themselves. | |
1519 | - */ | |
1520 | ||
1521 | - *chPtr = (Tcl_UniChar) byte; | |
1522 | - return 1; | |
1523 | - } else if (byte < 0xE0) { | |
1524 | - if ((ASC(str[1]) & 0xC0) == 0x80) { | |
1525 | - /* | |
1526 | - * Two-byte-character lead-byte followed by a trail-byte. | |
1527 | - */ | |
1528 | - | |
1529 | - *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F)); | |
1530 | - return 2; | |
fa2ea656 | 1531 | - } |
23005b3f AM |
1532 | - /* |
1533 | - * A two-byte-character lead-byte not followed by trail-byte | |
1534 | - * represents itself. | |
1535 | - */ | |
1536 | - | |
1537 | - *chPtr = (Tcl_UniChar) byte; | |
1538 | - return 1; | |
1539 | - } else if (byte < 0xF0) { | |
1540 | - if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) { | |
1541 | - /* | |
1542 | - * Three-byte-character lead byte followed by two trail bytes. | |
1543 | - */ | |
1544 | - | |
1545 | - *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | |
1546 | - | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F)); | |
1547 | - return 3; | |
1548 | - } | |
1549 | - /* | |
1550 | - * A three-byte-character lead-byte not followed by two trail-bytes | |
1551 | - * represents itself. | |
1552 | - */ | |
fa2ea656 AM |
1553 | + /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */ |
1554 | ||
23005b3f AM |
1555 | - *chPtr = (Tcl_UniChar) byte; |
1556 | - return 1; | |
fa2ea656 | 1557 | - } |
23005b3f | 1558 | + byte = ASC(*((unsigned char *) str)); |
fa2ea656 | 1559 | + if (byte < 0xC0) { |
23005b3f AM |
1560 | + /* |
1561 | + * Handles properly formed UTF-8 characters between 0x01 and 0x7F. | |
1562 | + * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid | |
1563 | + * characters representing themselves. | |
fa2ea656 AM |
1564 | + */ |
1565 | + | |
1566 | + *chPtr = (Tcl_UniChar) byte; | |
1567 | + return 1; | |
1568 | + } else if (byte < 0xE0) { | |
23005b3f | 1569 | + if ((ASC(str[1]) & 0xC0) == 0x80) { |
fa2ea656 AM |
1570 | + /* Two-byte-character lead-byte followed by a trail-byte. */ |
1571 | + | |
23005b3f | 1572 | + *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F)); |
fa2ea656 AM |
1573 | + return 2; |
1574 | + } | |
1575 | + /* | |
1576 | + * A two-byte-character lead-byte not followed by trail-byte | |
1577 | + * represents itself. | |
1578 | + */ | |
1579 | + | |
1580 | + *chPtr = (Tcl_UniChar) byte; | |
1581 | + return 1; | |
1582 | + } else if (byte < 0xF0) { | |
23005b3f AM |
1583 | + if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) { |
1584 | + /* Three-byte-character lead byte followed by two trail bytes. */ | |
fa2ea656 | 1585 | + |
23005b3f | 1586 | + *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F)); |
fa2ea656 AM |
1587 | + return 3; |
1588 | + } | |
1589 | + /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */ | |
1590 | + | |
1591 | + *chPtr = (Tcl_UniChar) byte; | |
1592 | + return 1; | |
1593 | + } | |
1594 | #if TCL_UTF_MAX > 3 | |
23005b3f AM |
1595 | - else { |
1596 | - int ch, total, trail; | |
fa2ea656 AM |
1597 | + else { |
1598 | + int ch, total, trail; | |
23005b3f AM |
1599 | |
1600 | - total = totalBytes[byte]; | |
1601 | - trail = total - 1; | |
1602 | - if (trail > 0) { | |
1603 | - ch = byte & (0x3F >> trail); | |
1604 | - do { | |
1605 | - str++; | |
1606 | - if ((ASC(*str) & 0xC0) != 0x80) { | |
1607 | - *chPtr = byte; | |
1608 | - return 1; | |
1609 | - } | |
1610 | - ch <<= 6; | |
1611 | - ch |= (ASC(*str) & 0x3F); | |
1612 | - trail--; | |
1613 | - } while (trail > 0); | |
1614 | - *chPtr = ch; | |
1615 | - return total; | |
fa2ea656 AM |
1616 | + total = totalBytes[byte]; |
1617 | + trail = total - 1; | |
fa2ea656 AM |
1618 | + if (trail > 0) { |
1619 | + ch = byte & (0x3F >> trail); | |
1620 | + do { | |
1621 | + str++; | |
23005b3f | 1622 | + if ((ASC(*str) & 0xC0) != 0x80) { |
fa2ea656 AM |
1623 | + *chPtr = byte; |
1624 | + return 1; | |
1625 | + } | |
1626 | + ch <<= 6; | |
23005b3f | 1627 | + ch |= (ASC(*str) & 0x3F); |
fa2ea656 AM |
1628 | + trail--; |
1629 | + } while (trail > 0); | |
1630 | + *chPtr = ch; | |
1631 | + return total; | |
1632 | + } | |
1633 | } | |
1634 | - } | |
1635 | #endif | |
1636 | ||
23005b3f AM |
1637 | - *chPtr = (Tcl_UniChar) byte; |
1638 | - return 1; | |
fa2ea656 AM |
1639 | + *chPtr = (Tcl_UniChar) byte; |
1640 | + return 1; | |
1641 | } | |
1642 | ||
1643 | /********************************************************************/ | |
1644 | /* font cache functions */ | |
1645 | ||
1646 | -static int | |
23005b3f AM |
1647 | -fontTest ( void *element, void *key ) |
1648 | +static int fontTest ( void *element, void *key ) | |
fa2ea656 | 1649 | { |
23005b3f AM |
1650 | - font_t *a=(font_t *)element; |
1651 | - fontkey_t *b=(fontkey_t *)key; | |
1652 | + font_t *a = (font_t *)element; | |
1653 | + fontkey_t *b = (fontkey_t *)key; | |
fa2ea656 | 1654 | |
23005b3f AM |
1655 | - return ( strcmp(a->fontname, b->fontname) == 0 |
1656 | - && a->ptsize == b->ptsize | |
1657 | - && a->angle == b->angle); | |
1658 | + return (strcmp(a->fontname, b->fontname) == 0 && a->ptsize == b->ptsize && a->angle == b->angle); | |
fa2ea656 AM |
1659 | } |
1660 | ||
23005b3f AM |
1661 | -static void * |
1662 | -fontFetch ( char **error, void *key ) | |
1663 | +static void * fontFetch ( char **error, void *key ) | |
1664 | { | |
1665 | - TT_Error err; | |
1666 | - font_t *a; | |
1667 | - fontkey_t *b=(fontkey_t *)key; | |
1668 | - int i, n, map_found; | |
1669 | - short platform, encoding; | |
1670 | + TT_Error err; | |
1671 | + font_t *a; | |
1672 | + fontkey_t *b = (fontkey_t *)key; | |
1673 | + int i, n, map_found; | |
1674 | + short platform, encoding; | |
1675 | TSRMLS_FETCH(); | |
fa2ea656 | 1676 | |
23005b3f AM |
1677 | a = (font_t *)pemalloc(sizeof(font_t), 1); |
1678 | @@ -354,8 +339,7 @@ | |
1679 | if ((err = TT_Open_Face(*b->engine, a->fontname, &a->face))) { | |
1680 | if (err == TT_Err_Could_Not_Open_File) { | |
1681 | *error = "Could not find/open font"; | |
1682 | - } | |
1683 | - else { | |
1684 | + } else { | |
1685 | *error = "Could not read font"; | |
1686 | } | |
1687 | pefree(a, 1); | |
1688 | @@ -370,7 +354,7 @@ | |
1689 | pefree(a, 1); | |
1690 | return NULL; | |
fa2ea656 | 1691 | } |
23005b3f | 1692 | - |
fa2ea656 | 1693 | + |
23005b3f AM |
1694 | if (TT_Set_Instance_Resolutions(a->instance, RESOLUTION, RESOLUTION)) { |
1695 | *error = "Could not set device resolutions"; | |
1696 | pefree(a, 1); | |
1697 | @@ -384,12 +368,12 @@ | |
fa2ea656 | 1698 | } |
23005b3f AM |
1699 | |
1700 | TT_Get_Instance_Metrics(a->instance, &a->imetrics); | |
1701 | - | |
fa2ea656 | 1702 | + |
23005b3f AM |
1703 | /* First, look for a Unicode charmap */ |
1704 | n = TT_Get_CharMap_Count(a->face); | |
1705 | ||
1706 | for (i = 0; i < n; i++) { | |
1707 | - TT_Get_CharMap_ID(a->face, i, &platform, &encoding); | |
1708 | + TT_Get_CharMap_ID(a->face, i, &platform, &encoding); | |
1709 | if ((platform == 3 && encoding == 1) /* Windows Unicode */ | |
1710 | || (platform == 2 && encoding == 1) | |
1711 | || (platform == 0)) { /* ?? Unicode */ | |
1712 | @@ -407,7 +391,7 @@ | |
1713 | } | |
1714 | } | |
1715 | ||
1716 | - if (! map_found) { | |
1717 | + if (!map_found) { | |
1718 | *error = "Unable to find a CharMap that I can handle"; | |
1719 | pefree(a, 1); | |
1720 | return NULL; | |
1721 | @@ -418,16 +402,14 @@ | |
1722 | a->matrix.xy = - a->matrix.yx; | |
1723 | a->matrix.yy = a->matrix.xx; | |
1724 | ||
1725 | - a->glyphCache = gdCacheCreate( GLYPHCACHESIZE, | |
1726 | - glyphTest, glyphFetch, glyphRelease); | |
1727 | + a->glyphCache = gdCacheCreate(GLYPHCACHESIZE, glyphTest, glyphFetch, glyphRelease); | |
1728 | ||
1729 | return (void *)a; | |
1730 | } | |
1731 | ||
1732 | -static void | |
1733 | -fontRelease( void *element ) | |
1734 | +static void fontRelease( void *element ) | |
fa2ea656 | 1735 | { |
23005b3f AM |
1736 | - font_t *a=(font_t *)element; |
1737 | + font_t *a = (font_t *)element; | |
1738 | ||
1739 | gdCacheDelete(a->glyphCache); | |
1740 | TT_Done_Instance(a->instance); | |
1741 | @@ -439,26 +421,22 @@ | |
1742 | /********************************************************************/ | |
1743 | /* glyph cache functions */ | |
1744 | ||
1745 | -static int | |
1746 | -glyphTest ( void *element, void *key ) | |
1747 | +static int glyphTest ( void *element, void *key ) | |
1748 | { | |
1749 | - glyph_t *a=(glyph_t *)element; | |
1750 | - glyphkey_t *b=(glyphkey_t *)key; | |
1751 | + glyph_t *a = (glyph_t *)element; | |
1752 | + glyphkey_t *b = (glyphkey_t *)key; | |
1753 | + | |
1754 | + return (a->character == b->character && a->hinting == b->hinting && a->gray_render == b->gray_render); | |
1755 | +} | |
1756 | ||
1757 | - return (a->character == b->character | |
1758 | - && a->hinting == b->hinting | |
1759 | - && a->gray_render == b->gray_render); | |
1760 | -} | |
fa2ea656 | 1761 | - |
23005b3f AM |
1762 | -static void * |
1763 | -glyphFetch ( char **error, void *key ) | |
1764 | -{ | |
1765 | - glyph_t *a; | |
1766 | - glyphkey_t *b=(glyphkey_t *)key; | |
1767 | - short glyph_code; | |
1768 | - int flags, err; | |
1769 | - int crect[8], xmin, xmax, ymin, ymax; | |
1770 | - double cos_a, sin_a; | |
1771 | +static void * glyphFetch ( char **error, void *key ) | |
1772 | +{ | |
1773 | + glyph_t *a; | |
1774 | + glyphkey_t *b = (glyphkey_t *)key; | |
1775 | + short glyph_code; | |
1776 | + int flags, err; | |
1777 | + int crect[8], xmin, xmax, ymin, ymax; | |
1778 | + double cos_a, sin_a; | |
1779 | ||
1780 | a = (glyph_t *)pemalloc(sizeof(glyph_t), 1); | |
1781 | a->character = b->character; | |
1782 | @@ -523,38 +501,34 @@ | |
1783 | a->Bit.flow = TT_Flow_Up; | |
1784 | if (a->gray_render) { | |
1785 | a->Bit.cols = a->Bit.width; /* 1 byte per pixel */ | |
1786 | - } | |
1787 | - else { | |
1788 | + } else { | |
1789 | a->Bit.cols = (a->Bit.width + 7) / 8; /* 1 bit per pixel */ | |
fa2ea656 | 1790 | } |
23005b3f AM |
1791 | a->Bit.cols = (a->Bit.cols + 3) & ~3; /* pad to 32 bits */ |
1792 | a->Bit.size = a->Bit.rows * a->Bit.cols; /* # of bytes in buffer */ | |
1793 | a->Bit.bitmap = NULL; | |
fa2ea656 | 1794 | |
23005b3f AM |
1795 | - a->bitmapCache = gdCacheCreate( BITMAPCACHESIZE, |
1796 | - bitmapTest, bitmapFetch, bitmapRelease); | |
1797 | + a->bitmapCache = gdCacheCreate(BITMAPCACHESIZE, bitmapTest, bitmapFetch, bitmapRelease); | |
fa2ea656 | 1798 | |
23005b3f | 1799 | return (void *)a; |
fa2ea656 AM |
1800 | } |
1801 | ||
23005b3f AM |
1802 | -static void |
1803 | -glyphRelease( void *element ) | |
1804 | +static void glyphRelease( void *element ) | |
fa2ea656 | 1805 | { |
23005b3f AM |
1806 | - glyph_t *a=(glyph_t *)element; |
1807 | + glyph_t *a = (glyph_t *)element; | |
fa2ea656 | 1808 | |
23005b3f AM |
1809 | gdCacheDelete(a->bitmapCache); |
1810 | - TT_Done_Glyph( a->glyph ); | |
1811 | - pefree ((char *)element, 1); | |
1812 | + TT_Done_Glyph(a->glyph); | |
1813 | + pefree((char *)element, 1); | |
fa2ea656 AM |
1814 | } |
1815 | ||
23005b3f AM |
1816 | /********************************************************************/ |
1817 | /* bitmap cache functions */ | |
fa2ea656 | 1818 | |
23005b3f AM |
1819 | -static int |
1820 | -bitmapTest ( void *element, void *key ) | |
1821 | +static int bitmapTest ( void *element, void *key ) | |
fa2ea656 | 1822 | { |
23005b3f AM |
1823 | - bitmap_t *a=(bitmap_t *)element; |
1824 | - bitmapkey_t *b=(bitmapkey_t *)key; | |
1825 | + bitmap_t *a = (bitmap_t *)element; | |
1826 | + bitmapkey_t *b = (bitmapkey_t *)key; | |
fa2ea656 | 1827 | |
23005b3f AM |
1828 | if (a->xoffset == b->xoffset && a->yoffset == b->yoffset) { |
1829 | b->glyph->Bit.bitmap = a->bitmap; | |
1830 | @@ -563,11 +537,10 @@ | |
1831 | return FALSE; | |
1832 | } | |
fa2ea656 | 1833 | |
23005b3f AM |
1834 | -static void * |
1835 | -bitmapFetch ( char **error, void *key ) | |
1836 | +static void * bitmapFetch ( char **error, void *key ) | |
1837 | { | |
1838 | - bitmap_t *a; | |
1839 | - bitmapkey_t *b=(bitmapkey_t *)key; | |
1840 | + bitmap_t *a; | |
1841 | + bitmapkey_t *b = (bitmapkey_t *)key; | |
1842 | ||
1843 | a = (bitmap_t *)pemalloc(sizeof(bitmap_t), 1); | |
1844 | a->xoffset = b->xoffset; | |
1845 | @@ -577,56 +550,47 @@ | |
1846 | memset(a->bitmap, 0, b->glyph->Bit.size); | |
1847 | /* render glyph */ | |
1848 | if (b->glyph->gray_render) { | |
1849 | - TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit, | |
1850 | - a->xoffset, a->yoffset); | |
fa2ea656 | 1851 | - } |
23005b3f AM |
1852 | - else { |
1853 | - TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit, | |
1854 | - a->xoffset, a->yoffset); | |
1855 | + TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset); | |
1856 | + } else { | |
1857 | + TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset); | |
1858 | } | |
1859 | return (void *)a; | |
fa2ea656 AM |
1860 | } |
1861 | ||
23005b3f AM |
1862 | -static void |
1863 | -bitmapRelease( void *element ) | |
1864 | +static void bitmapRelease( void *element ) | |
fa2ea656 | 1865 | { |
23005b3f AM |
1866 | - bitmap_t *a=(bitmap_t *)element; |
1867 | + bitmap_t *a = (bitmap_t *)element; | |
fa2ea656 | 1868 | |
23005b3f AM |
1869 | - pefree (a->bitmap, 1); |
1870 | - pefree ((char *)element, 1); | |
1871 | + pefree(a->bitmap, 1); | |
1872 | + pefree((char *)element, 1); | |
1873 | } | |
fa2ea656 | 1874 | |
23005b3f AM |
1875 | /********************************************************************/ |
1876 | /* tweencolor cache functions */ | |
fa2ea656 | 1877 | |
23005b3f AM |
1878 | -static int |
1879 | -tweenColorTest (void *element, void *key) | |
1880 | -{ | |
1881 | - tweencolor_t *a=(tweencolor_t *)element; | |
1882 | - tweencolorkey_t *b=(tweencolorkey_t *)key; | |
1883 | - | |
1884 | - return (a->pixel == b->pixel | |
1885 | - && a->bgcolor == b->bgcolor | |
1886 | - && a->fgcolor == b->fgcolor | |
1887 | - && a->im == b->im); | |
1888 | -} | |
1889 | +static int tweenColorTest (void *element, void *key) | |
1890 | +{ | |
1891 | + tweencolor_t *a = (tweencolor_t *)element; | |
1892 | + tweencolorkey_t *b = (tweencolorkey_t *)key; | |
fa2ea656 | 1893 | + |
23005b3f | 1894 | + return (a->pixel == b->pixel && a->bgcolor == b->bgcolor && a->fgcolor == b->fgcolor && a->im == b->im); |
aeb33d2f | 1895 | +} |
fa2ea656 | 1896 | |
23005b3f AM |
1897 | -static void * |
1898 | -tweenColorFetch (char **error, void *key) | |
1899 | +static void * tweenColorFetch (char **error, void *key) | |
fa2ea656 | 1900 | { |
23005b3f AM |
1901 | - tweencolor_t *a; |
1902 | - tweencolorkey_t *b=(tweencolorkey_t *)key; | |
1903 | + tweencolor_t *a; | |
1904 | + tweencolorkey_t *b = (tweencolorkey_t *)key; | |
1905 | int pixel, npixel, bg, fg; | |
1906 | gdImagePtr im; | |
1907 | - | |
1908 | - a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1); | |
aeb33d2f | 1909 | + |
23005b3f AM |
1910 | + a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1); |
1911 | pixel = a->pixel = b->pixel; | |
1912 | bg = a->bgcolor = b->bgcolor; | |
1913 | fg = a->fgcolor = b->fgcolor; | |
1914 | im = b->im; | |
fa2ea656 | 1915 | |
23005b3f AM |
1916 | /* if fg is specified by a negative color idx, then don't antialias */ |
1917 | - if (fg <0) { | |
1918 | + if (fg < 0) { | |
1919 | a->tweencolor = -fg; | |
1920 | } else { | |
1921 | npixel = NUMCOLORS - pixel; | |
1922 | @@ -635,20 +599,19 @@ | |
1923 | (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS, | |
1924 | (pixel * im->blue [fg] + npixel * im->blue [bg]) / NUMCOLORS); | |
1925 | } | |
1926 | - *error = NULL; | |
1927 | - return (void *)a; | |
1928 | -} | |
1929 | - | |
1930 | -static void | |
1931 | -tweenColorRelease(void *element) | |
1932 | -{ | |
1933 | - pefree((char *)element, 1); | |
1934 | -} | |
1935 | + *error = NULL; | |
1936 | + return (void *)a; | |
1937 | +} | |
fa2ea656 | 1938 | + |
23005b3f AM |
1939 | +static void tweenColorRelease(void *element) |
1940 | +{ | |
1941 | + pefree((char *)element, 1); | |
1942 | +} | |
fa2ea656 | 1943 | |
23005b3f AM |
1944 | /********************************************************************/ |
1945 | /* gdttfchar - render one character onto a gd image */ | |
fa2ea656 | 1946 | |
23005b3f AM |
1947 | -static int OneTime=0; |
1948 | +static int OneTime = 0; | |
1949 | static gdCache_head_t *tweenColorCache; | |
fa2ea656 | 1950 | |
23005b3f AM |
1951 | char * |
1952 | @@ -656,38 +619,37 @@ | |
1953 | int x, int y, /* string start pos in pixels */ | |
1954 | TT_F26Dot6 x1, TT_F26Dot6 y1, /* char start offset (*64) from x,y */ | |
1955 | TT_F26Dot6 *advance, | |
1956 | - TT_BBox **bbox, | |
1957 | + TT_BBox **bbox, | |
1958 | char **next) | |
1959 | { | |
1960 | - int pc, ch, len; | |
1961 | + int pc, ch, len; | |
1962 | int row, col; | |
1963 | - int x2, y2; /* char start pos in pixels */ | |
1964 | + int x2, y2; /* char start pos in pixels */ | |
1965 | int x3, y3; /* current pixel pos */ | |
1966 | unsigned char *pixel; | |
1967 | ||
1968 | - glyph_t *glyph; | |
1969 | - glyphkey_t glyphkey; | |
1970 | - bitmapkey_t bitmapkey; | |
1971 | + glyph_t *glyph; | |
1972 | + glyphkey_t glyphkey; | |
1973 | + bitmapkey_t bitmapkey; | |
1974 | tweencolor_t *tweencolor; | |
1975 | tweencolorkey_t tweencolorkey; | |
1976 | ||
1977 | /****** set up tweenColorCache on first call ************/ | |
1978 | - if (! OneTime) { | |
1979 | - tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE, | |
1980 | - tweenColorTest, tweenColorFetch, tweenColorRelease); | |
1981 | + if (!OneTime) { | |
1982 | + tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE, tweenColorTest, tweenColorFetch, tweenColorRelease); | |
1983 | OneTime++; | |
1984 | } | |
1985 | /**************/ | |
1986 | ||
1987 | if (font->have_char_map_Unicode) { /* use UTF-8 mapping from ASCII */ | |
1988 | - len = gdTcl_UtfToUniChar(*next, &ch); | |
1989 | - *next += len; | |
1990 | + len = gdTcl_UtfToUniChar(*next, &ch); | |
1991 | + *next += len; | |
1992 | } else { | |
1993 | - /* | |
1994 | - * Big 5 mapping: | |
1995 | - * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref: | |
1996 | - * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs | |
1997 | - */ | |
1998 | + /* | |
1999 | + * Big 5 mapping: | |
2000 | + * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref: | |
2001 | + * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs | |
2002 | + */ | |
2003 | ch = (**next) & 255; /* don't extend sign */ | |
2004 | (*next)++; | |
2005 | if (ch >= 161 /* first code of JIS-8 pair */ | |
2006 | @@ -700,18 +662,20 @@ | |
2007 | glyphkey.character = ch; | |
2008 | glyphkey.hinting = 1; | |
2009 | /* if fg is specified by a negative color idx, then don't antialias */ | |
2010 | - glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg <0))?FALSE:TRUE; | |
2011 | - glyphkey.font = font; | |
2012 | - glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey); | |
2013 | - if (! glyph) | |
2014 | + glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg < 0)) ? FALSE : TRUE; | |
2015 | + glyphkey.font = font; | |
2016 | + glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey); | |
2017 | + if (!glyph) { | |
2018 | return font->glyphCache->error; | |
2019 | + } | |
2020 | ||
2021 | *bbox = &glyph->metrics.bbox; | |
2022 | *advance = glyph->metrics.advance; | |
2023 | ||
2024 | /* if null *im, or invalid color, then assume user just wants brect */ | |
2025 | - if (!im || fg > 255 || fg < -255) | |
2026 | + if (!im || fg > 255 || fg < -255) { | |
2027 | return (char *)NULL; | |
2028 | + } | |
2029 | ||
2030 | /* render (via cache) a bitmap for the current fractional offset */ | |
2031 | bitmapkey.xoffset = ((x1+32) & 63) - 32 - ((glyph->xmin+32) & -64); | |
2032 | @@ -720,30 +684,32 @@ | |
2033 | gdCacheGet(glyph->bitmapCache, &bitmapkey); | |
2034 | ||
2035 | /* copy to gif, mapping colors */ | |
2036 | - x2 = x + (((glyph->xmin+32) & -64) + ((x1+32) & -64)) / 64; | |
2037 | - y2 = y - (((glyph->ymin+32) & -64) + ((y1+32) & -64)) / 64; | |
2038 | + x2 = x + (((glyph->xmin+32) & -64) + ((x1+32) & -64)) / 64; | |
2039 | + y2 = y - (((glyph->ymin+32) & -64) + ((y1+32) & -64)) / 64; | |
2040 | tweencolorkey.fgcolor = fg; | |
2041 | tweencolorkey.im = im; | |
2042 | for (row = 0; row < glyph->Bit.rows; row++) { | |
2043 | - if (glyph->gray_render) | |
2044 | + if (glyph->gray_render) { | |
2045 | pc = row * glyph->Bit.cols; | |
2046 | - else | |
2047 | + } else { | |
2048 | pc = row * glyph->Bit.cols * 8; | |
fa2ea656 | 2049 | + } |
23005b3f AM |
2050 | y3 = y2 - row; |
2051 | - if (y3 >= im->sy || y3 < 0) continue; | |
2052 | + if (y3 >= im->sy || y3 < 0) { | |
2053 | + continue; | |
fa2ea656 | 2054 | + } |
23005b3f AM |
2055 | for (col = 0; col < glyph->Bit.width; col++, pc++) { |
2056 | if (glyph->gray_render) { | |
2057 | - tweencolorkey.pixel = | |
2058 | - *((unsigned char *)(glyph->Bit.bitmap) + pc); | |
2059 | + tweencolorkey.pixel = *((unsigned char *)(glyph->Bit.bitmap) + pc); | |
2060 | } else { | |
2061 | - tweencolorkey.pixel = | |
2062 | - (((*((unsigned char *)(glyph->Bit.bitmap) + pc/8)) | |
2063 | - <<(pc%8))&128)?4:0; | |
2064 | + tweencolorkey.pixel = (((*((unsigned char *)(glyph->Bit.bitmap) + pc/8)) << (pc%8))&128)?4:0; | |
2065 | } | |
2066 | /* if not background */ | |
2067 | if (tweencolorkey.pixel > 0) { | |
2068 | x3 = x2 + col; | |
2069 | - if (x3 >= im->sx || x3 < 0) continue; | |
2070 | + if (x3 >= im->sx || x3 < 0) { | |
2071 | + continue; | |
2072 | + } | |
2073 | #if HAVE_LIBGD20 | |
2074 | if (im->trueColor) { | |
2075 | pixel = &im->tpixels[y3][x3]; | |
2076 | @@ -757,8 +723,7 @@ | |
fa2ea656 | 2077 | #endif |
23005b3f AM |
2078 | } |
2079 | tweencolorkey.bgcolor = *pixel; | |
2080 | - tweencolor = (tweencolor_t *)gdCacheGet( | |
2081 | - tweenColorCache, &tweencolorkey); | |
2082 | + tweencolor = (tweencolor_t *)gdCacheGet(tweenColorCache, &tweencolorkey); | |
2083 | *pixel = tweencolor->tweencolor; | |
2084 | } | |
2085 | } | |
2086 | @@ -769,29 +734,26 @@ | |
2087 | /********************************************************************/ | |
2088 | /* gdttf - render a utf8 string onto a gd image */ | |
2089 | ||
2090 | -char * | |
2091 | -gdttf(gdImage *im, int *brect, int fg, char *fontname, | |
2092 | - double ptsize, double angle, int x, int y, char *str) | |
2093 | +char * gdttf(gdImage *im, int *brect, int fg, char *fontname, double ptsize, double angle, int x, int y, char *str) | |
2094 | { | |
2095 | - TT_F26Dot6 ur_x=0, ur_y=0, ll_x=0, ll_y=0; | |
2096 | + TT_F26Dot6 ur_x = 0, ur_y = 0, ll_x = 0, ll_y = 0; | |
2097 | TT_F26Dot6 advance_x, advance_y, advance, x1, y1; | |
2098 | TT_BBox *bbox; | |
2099 | double sin_a, cos_a; | |
2100 | - int i=0, ch; | |
2101 | + int i=0, ch; | |
2102 | font_t *font; | |
2103 | fontkey_t fontkey; | |
2104 | char *error, *next; | |
2105 | ||
2106 | /****** initialize font engine on first call ************/ | |
2107 | - static gdCache_head_t *fontCache; | |
2108 | + static gdCache_head_t *fontCache; | |
2109 | static TT_Engine engine; | |
2110 | ||
2111 | - if (! fontCache) { | |
2112 | + if (!fontCache) { | |
2113 | if (TT_Init_FreeType(&engine)) { | |
2114 | return "Failure to initialize font engine"; | |
2115 | } | |
2116 | - fontCache = gdCacheCreate( FONTCACHESIZE, | |
2117 | - fontTest, fontFetch, fontRelease); | |
2118 | + fontCache = gdCacheCreate(FONTCACHESIZE, fontTest, fontFetch, fontRelease); | |
2119 | } | |
2120 | /**************/ | |
2121 | ||
2122 | @@ -801,15 +763,15 @@ | |
2123 | fontkey.angle = angle; | |
2124 | fontkey.engine = &engine; | |
2125 | font = (font_t *)gdCacheGet(fontCache, &fontkey); | |
2126 | - if (! font) { | |
2127 | + if (!font) { | |
2128 | return fontCache->error; | |
2129 | } | |
2130 | sin_a = font->sin_a; | |
2131 | cos_a = font->cos_a; | |
2132 | advance_x = advance_y = 0; | |
2133 | ||
2134 | - next=str; | |
2135 | - while (*next) { | |
2136 | + next = str; | |
2137 | + while (*next) { | |
2138 | ch = *next; | |
fa2ea656 | 2139 | |
23005b3f AM |
2140 | /* carriage returns */ |
2141 | @@ -820,8 +782,8 @@ | |
2142 | } | |
2143 | /* newlines */ | |
2144 | if (ch == '\n') { | |
2145 | - advance_y -= (TT_F26Dot6)(font->imetrics.y_ppem * LINESPACE * 64); | |
2146 | - advance_y = (advance_y-32) & -64; /* round to next pixel row */ | |
2147 | + advance_y -= (TT_F26Dot6)(font->imetrics.y_ppem * LINESPACE * 64); | |
2148 | + advance_y = (advance_y-32) & -64; /* round to next pixel row */ | |
2149 | next++; | |
2150 | continue; | |
2151 | } | |
2152 | @@ -829,20 +791,24 @@ | |
2153 | x1 = (TT_F26Dot6)(advance_x * cos_a - advance_y * sin_a); | |
2154 | y1 = (TT_F26Dot6)(advance_x * sin_a + advance_y * cos_a); | |
fa2ea656 | 2155 | |
23005b3f AM |
2156 | - if ((error=gdttfchar(im, fg, font, x, y, x1, y1, &advance, &bbox, &next))) |
2157 | + if ((error = gdttfchar(im, fg, font, x, y, x1, y1, &advance, &bbox, &next))) { | |
2158 | return error; | |
2159 | + } | |
fa2ea656 | 2160 | |
23005b3f AM |
2161 | - if (! i++) { /* if first character, init BB corner values */ |
2162 | + if (!i++) { /* if first character, init BB corner values */ | |
2163 | ll_x = bbox->xMin; | |
2164 | ll_y = bbox->yMin; | |
2165 | ur_x = bbox->xMax; | |
2166 | ur_y = bbox->yMax; | |
2167 | - } | |
2168 | - else { | |
2169 | - if (! advance_x) ll_x = MIN(bbox->xMin, ll_x); | |
2170 | + } else { | |
2171 | + if (!advance_x) { | |
2172 | + ll_x = MIN(bbox->xMin, ll_x); | |
2173 | + } | |
2174 | ll_y = MIN(advance_y + bbox->yMin, ll_y); | |
2175 | ur_x = MAX(advance_x + bbox->xMax, ur_x); | |
2176 | - if (! advance_y) ur_y = MAX(bbox->yMax, ur_y); | |
2177 | + if (!advance_y) { | |
2178 | + ur_y = MAX(bbox->yMax, ur_y); | |
2179 | + } | |
2180 | } | |
2181 | advance_x += advance; | |
2182 | } | |
2183 | @@ -859,7 +825,7 @@ | |
fa2ea656 | 2184 | |
23005b3f AM |
2185 | /* scale, round and offset brect */ |
2186 | i = 0; | |
2187 | - while (i<8) { | |
2188 | + while (i < 8) { | |
2189 | brect[i] = x + (brect[i] + 32) / 64; | |
2190 | i++; | |
2191 | brect[i] = y - (brect[i] + 32) / 64; | |
2192 | @@ -868,7 +834,7 @@ | |
2193 | ||
2194 | return (char *)NULL; | |
2195 | } | |
2196 | - | |
fa2ea656 | 2197 | + |
23005b3f AM |
2198 | #endif /* HAVE_LIBTTF */ |
2199 | ||
2200 | /* | |
84aee732 AM |
2201 | diff -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 |
2202 | --- php-4.4.8.org/ext/gd/libgd/gd_arc_f_buggy.c 2003-03-05 17:04:20.000000000 +0100 | |
2203 | +++ php-4.4.8/ext/gd/libgd/gd_arc_f_buggy.c 2005-08-18 14:54:43.000000000 +0200 | |
84aee732 AM |
2204 | @@ -698,7 +698,7 @@ |
2205 | #define WIDTH 500 | |
2206 | #define HEIGHT 300 | |
2207 | ||
2208 | -int | |
2209 | +int | |
2210 | main (int argc, char *argv[]) | |
2211 | { | |
2212 | gdImagePtr im = gdImageCreate (WIDTH, HEIGHT); | |
2213 | @@ -726,12 +726,12 @@ | |
2214 | out = fopen ("test/arctest.png", "wb"); | |
2215 | if (!out) | |
2216 | { | |
2217 | - php_gd_error("Can't create test/arctest.png\n"); | |
2218 | + php_gd_error("Can't create test/arctest.png"); | |
2219 | exit (1); | |
2220 | } | |
2221 | gdImagePng (im, out); | |
2222 | fclose (out); | |
2223 | - php_gd_error("Test image written to test/arctest.png\n"); | |
2224 | + php_gd_error("Test image written to test/arctest.png"); | |
2225 | /* Destroy it */ | |
2226 | gdImageDestroy (im); | |
2227 | ||
2228 | diff -urN php-4.4.8.org/ext/gd/libgd/gd.c php-4.4.8/ext/gd/libgd/gd.c | |
2229 | --- php-4.4.8.org/ext/gd/libgd/gd.c 2007-10-20 17:29:04.000000000 +0200 | |
2230 | +++ php-4.4.8/ext/gd/libgd/gd.c 2007-11-05 00:56:00.000000000 +0100 | |
2231 | @@ -1,4 +1,4 @@ | |
2232 | -#include <stdio.h> | |
2233 | + | |
2234 | #include <math.h> | |
2235 | #include <string.h> | |
2236 | #include <stdlib.h> | |
2237 | @@ -90,18 +90,16 @@ | |
2238 | static void gdImageBrushApply(gdImagePtr im, int x, int y); | |
2239 | static void gdImageTileApply(gdImagePtr im, int x, int y); | |
2240 | static void gdImageAntiAliasedApply(gdImagePtr im, int x, int y); | |
2241 | -static int gdFullAlphaBlend(int dst, int src); | |
2242 | static int gdLayerOverlay(int dst, int src); | |
2243 | -static int gdAlphaBlendColor(int b1, int b2, int a1, int a2); | |
2244 | static int gdAlphaOverlayColor(int src, int dst, int max); | |
2245 | int gdImageGetTrueColorPixel(gdImagePtr im, int x, int y); | |
2246 | ||
2247 | -void php_gd_error_ex(int type, const char *format, ...) | |
2248 | +void php_gd_error_ex(int type, const char *format, ...) | |
2249 | { | |
2250 | va_list args; | |
2251 | - | |
2252 | + | |
2253 | TSRMLS_FETCH(); | |
2254 | - | |
2255 | + | |
2256 | va_start(args, format); | |
2257 | php_verror(NULL, "", type, format, args TSRMLS_CC); | |
2258 | va_end(args); | |
2259 | @@ -110,9 +108,9 @@ | |
2260 | void php_gd_error(const char *format, ...) | |
2261 | { | |
2262 | va_list args; | |
2263 | - | |
2264 | + | |
2265 | TSRMLS_FETCH(); | |
2266 | - | |
2267 | + | |
2268 | va_start(args, format); | |
2269 | php_verror(NULL, "", E_WARNING, format, args TSRMLS_CC); | |
2270 | va_end(args); | |
2271 | @@ -122,11 +120,20 @@ | |
2272 | { | |
2273 | int i; | |
2274 | gdImagePtr im; | |
2275 | - im = (gdImage *) gdMalloc(sizeof(gdImage)); | |
2276 | - memset(im, 0, sizeof(gdImage)); | |
2277 | + | |
2278 | + if (overflow2(sx, sy)) { | |
2279 | + return NULL; | |
2280 | + } | |
2281 | + | |
2282 | + if (overflow2(sizeof(unsigned char *), sy)) { | |
2283 | + return NULL; | |
2284 | + } | |
2285 | + | |
2286 | + im = (gdImage *) gdCalloc(1, sizeof(gdImage)); | |
2287 | + | |
2288 | /* Row-major ever since gd 1.3 */ | |
2289 | - im->pixels = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0); | |
2290 | - im->AA_opacity = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0); | |
2291 | + im->pixels = (unsigned char **) gdMalloc(sizeof(unsigned char *) * sy); | |
2292 | + im->AA_opacity = (unsigned char **) gdMalloc(sizeof(unsigned char *) * sy); | |
2293 | im->polyInts = 0; | |
2294 | im->polyAllocated = 0; | |
2295 | im->brush = 0; | |
2296 | @@ -164,10 +171,23 @@ | |
2297 | { | |
2298 | int i; | |
2299 | gdImagePtr im; | |
2300 | + | |
2301 | + if (overflow2(sx, sy)) { | |
2302 | + return NULL; | |
2303 | + } | |
2304 | + | |
2305 | + if (overflow2(sizeof(unsigned char *), sy)) { | |
2306 | + return NULL; | |
2307 | + } | |
2308 | + | |
2309 | + if (overflow2(sizeof(int), sx)) { | |
2310 | + return NULL; | |
2311 | + } | |
2312 | + | |
2313 | im = (gdImage *) gdMalloc(sizeof(gdImage)); | |
2314 | memset(im, 0, sizeof(gdImage)); | |
2315 | - im->tpixels = (int **) safe_emalloc(sizeof(int *), sy, 0); | |
2316 | - im->AA_opacity = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0); | |
2317 | + im->tpixels = (int **) gdMalloc(sizeof(int *) * sy); | |
2318 | + im->AA_opacity = (unsigned char **) gdMalloc(sizeof(unsigned char *) * sy); | |
2319 | im->polyInts = 0; | |
2320 | im->polyAllocated = 0; | |
2321 | im->brush = 0; | |
84aee732 AM |
2322 | @@ -305,8 +325,8 @@ |
2323 | static HWBType * RGB_to_HWB (RGBType RGB, HWBType * HWB) | |
2324 | { | |
2325 | /* | |
2326 | - * RGB are each on [0, 1]. W and B are returned on [0, 1] and H is | |
2327 | - * returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B. | |
2328 | + * RGB are each on [0, 1]. W and B are returned on [0, 1] and H is | |
2329 | + * returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B. | |
2330 | */ | |
2331 | ||
2332 | float R = RGB.R, G = RGB.G, B = RGB.B, w, v, b, f; | |
2333 | @@ -320,7 +340,7 @@ | |
2334 | } | |
2335 | f = (R == w) ? G - B : ((G == w) ? B - R : R - G); | |
2336 | i = (R == w) ? 3 : ((G == w) ? 5 : 1); | |
2337 | - | |
2338 | + | |
2339 | RETURN_HWB(i - f / (v - w), w, b); | |
2340 | } | |
2341 | ||
2342 | @@ -363,9 +383,9 @@ | |
2343 | */ | |
2344 | static RGBType * HWB_to_RGB (HWBType HWB, RGBType * RGB) | |
2345 | { | |
2346 | - /* | |
2347 | - * H is given on [0, 6] or UNDEFINED. W and B are given on [0, 1]. | |
2348 | - * RGB are each returned on [0, 1]. | |
2349 | + /* | |
2350 | + * H is given on [0, 6] or UNDEFINED. W and B are given on [0, 1]. | |
2351 | + * RGB are each returned on [0, 1]. | |
2352 | */ | |
2353 | ||
2354 | float h = HWB.H, w = HWB.W, b = HWB.B, v, n, f; | |
2355 | @@ -478,7 +498,7 @@ | |
2356 | im->blue[ct] = b; | |
2357 | im->alpha[ct] = a; | |
2358 | im->open[ct] = 0; | |
2359 | - | |
2360 | + | |
2361 | return ct; | |
2362 | } | |
2363 | ||
84aee732 AM |
2364 | @@ -664,7 +684,7 @@ |
2365 | } | |
2366 | m = (*y1 - *y0)/(double)(*x1 - *x0); /* calculate the slope of the line */ | |
2367 | *y0 += (int)(m * (maxdim - *x0)); /* adjust so point is on the right boundary */ | |
2368 | - *x0 = maxdim; | |
2369 | + *x0 = maxdim; | |
2370 | /* now, perhaps, adjust the end of the line */ | |
2371 | if (*x1 < 0) { | |
2372 | *y1 -= (int)(m * *x1); | |
2373 | @@ -737,7 +757,7 @@ | |
2374 | im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color); | |
2375 | break; | |
2376 | case gdEffectNormal: | |
2377 | - im->tpixels[y][x] = gdFullAlphaBlend(im->tpixels[y][x], color); | |
2378 | + im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color); | |
2379 | break; | |
2380 | case gdEffectOverlay : | |
2381 | im->tpixels[y][x] = gdLayerOverlay(im->tpixels[y][x], color); | |
2382 | @@ -756,7 +776,7 @@ | |
2383 | int p = gdImageGetPixel(im, x, y); | |
2384 | ||
2385 | if (!im->trueColor) { | |
2386 | - return gdTrueColorAlpha(im->red[p], im->green[p], im->blue[p], (im->transparent == p) ? gdAlphaTransparent : gdAlphaOpaque); | |
2387 | + return gdTrueColorAlpha(im->red[p], im->green[p], im->blue[p], (im->transparent == p) ? gdAlphaTransparent : im->alpha[p]); | |
2388 | } else { | |
2389 | return p; | |
2390 | } | |
2391 | @@ -780,7 +800,7 @@ | |
2392 | x1 = x - hx; | |
2393 | x2 = x1 + gdImageSX(im->brush); | |
2394 | srcy = 0; | |
2395 | - | |
2396 | + | |
2397 | if (im->trueColor) { | |
2398 | if (im->brush->trueColor) { | |
2399 | for (ly = y1; ly < y2; ly++) { | |
2400 | @@ -823,8 +843,8 @@ | |
2401 | if (p != gdImageGetTransparent(im->brush)) { | |
2402 | /* Truecolor brush. Very slow on a palette destination. */ | |
2403 | if (im->brush->trueColor) { | |
2404 | - gdImageSetPixel(im, lx, ly, gdImageColorResolveAlpha(im, gdTrueColorGetRed(p), | |
2405 | - gdTrueColorGetGreen(p), | |
2406 | + gdImageSetPixel(im, lx, ly, gdImageColorResolveAlpha(im, gdTrueColorGetRed(p), | |
2407 | + gdTrueColorGetGreen(p), | |
2408 | gdTrueColorGetBlue(p), | |
2409 | gdTrueColorGetAlpha(p))); | |
2410 | } else { | |
2411 | @@ -849,7 +869,9 @@ | |
2412 | srcy = y % gdImageSY(im->tile); | |
2413 | if (im->trueColor) { | |
2414 | p = gdImageGetTrueColorPixel(im->tile, srcx, srcy); | |
2415 | - gdImageSetPixel(im, x, y, p); | |
2416 | + if (p != gdImageGetTransparent (im->tile)) { | |
2417 | + gdImageSetPixel(im, x, y, p); | |
2418 | + } | |
2419 | } else { | |
2420 | p = gdImageGetPixel(im->tile, srcx, srcy); | |
2421 | /* Allow for transparency */ | |
2422 | @@ -903,8 +925,8 @@ | |
2423 | float p_dist, p_alpha; | |
2424 | unsigned char opacity; | |
2425 | ||
2426 | - /* | |
2427 | - * Find the perpendicular distance from point C (px, py) to the line | |
2428 | + /* | |
2429 | + * Find the perpendicular distance from point C (px, py) to the line | |
2430 | * segment AB that is being drawn. (Adapted from an algorithm from the | |
2431 | * comp.graphics.algorithms FAQ.) | |
2432 | */ | |
2433 | @@ -918,7 +940,7 @@ | |
2434 | int By_Cy = im->AAL_y2 - py; | |
2435 | ||
2436 | /* 2.0.13: bounds check! AA_opacity is just as capable of | |
2437 | - * overflowing as the main pixel array. Arne Jorgensen. | |
2438 | + * overflowing as the main pixel array. Arne Jorgensen. | |
2439 | * 2.0.14: typo fixed. 2.0.15: moved down below declarations | |
2440 | * to satisfy non-C++ compilers. | |
2441 | */ | |
2442 | @@ -931,12 +953,12 @@ | |
2443 | LBC_2 = (Bx_Cx * Bx_Cx) + (By_Cy * By_Cy); | |
2444 | ||
2445 | if (((im->AAL_LAB_2 + LAC_2) >= LBC_2) && ((im->AAL_LAB_2 + LBC_2) >= LAC_2)) { | |
2446 | - /* The two angles are acute. The point lies inside the portion of the | |
2447 | + /* The two angles are acute. The point lies inside the portion of the | |
2448 | * plane spanned by the line segment. | |
2449 | */ | |
2450 | p_dist = fabs ((float) ((Ay_Cy * im->AAL_Bx_Ax) - (Ax_Cx * im->AAL_By_Ay)) / im->AAL_LAB); | |
2451 | } else { | |
2452 | - /* The point is past an end of the line segment. It's length from the | |
2453 | + /* The point is past an end of the line segment. It's length from the | |
2454 | * segment is the shorter of the lengths from the endpoints, but call | |
2455 | * the distance -1, so as not to compute the alpha nor draw the pixel. | |
2456 | */ | |
2457 | @@ -1017,6 +1039,43 @@ | |
2458 | } | |
2459 | } | |
2460 | ||
2461 | +static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col) | |
2462 | +{ | |
2463 | + if (im->thick > 1) { | |
2464 | + int thickhalf = im->thick >> 1; | |
2465 | + gdImageFilledRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col); | |
2466 | + } else { | |
2467 | + if (x2 < x1) { | |
2468 | + int t = x2; | |
2469 | + x2 = x1; | |
2470 | + x1 = t; | |
2471 | + } | |
2472 | + | |
2473 | + for (;x1 <= x2; x1++) { | |
2474 | + gdImageSetPixel(im, x1, y, col); | |
2475 | + } | |
2476 | + } | |
2477 | + return; | |
2478 | +} | |
2479 | + | |
2480 | +static void gdImageVLine(gdImagePtr im, int x, int y1, int y2, int col) | |
2481 | +{ | |
2482 | + if (im->thick > 1) { | |
2483 | + int thickhalf = im->thick >> 1; | |
2484 | + gdImageFilledRectangle(im, x - thickhalf, y1, x + im->thick - thickhalf - 1, y2, col); | |
2485 | + } else { | |
2486 | + if (y2 < y1) { | |
2487 | + int t = y1; | |
2488 | + y1 = y2; | |
2489 | + y2 = t; | |
2490 | + } | |
2491 | + | |
2492 | + for (;y1 <= y2; y1++) { | |
2493 | + gdImageSetPixel(im, x, y1, col); | |
2494 | + } | |
2495 | + } | |
2496 | + return; | |
2497 | +} | |
2498 | ||
2499 | /* Bresenham as presented in Foley & Van Dam */ | |
2500 | void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color) | |
2501 | @@ -1026,39 +1085,47 @@ | |
2502 | int w, wstart; | |
2503 | int thick = im->thick; | |
2504 | ||
2505 | + if (color == gdAntiAliased) | |
2506 | + { | |
2507 | + /* | |
2508 | + gdAntiAliased passed as color: use the much faster, much cheaper | |
2509 | + and equally attractive gdImageAALine implementation. That | |
2510 | + clips too, so don't clip twice. | |
2511 | + */ | |
2512 | + gdImageAALine(im, x1, y1, x2, y2, im->AA_color); | |
2513 | + return; | |
2514 | + } | |
2515 | + | |
2516 | /* 2.0.10: Nick Atty: clip to edges of drawing rectangle, return if no points need to be drawn */ | |
2517 | if (!clip_1d(&x1,&y1,&x2,&y2,gdImageSX(im)) || !clip_1d(&y1,&x1,&y2,&x2,gdImageSY(im))) { | |
2518 | return; | |
2519 | } | |
2520 | ||
2521 | - /* gdAntiAliased passed as color: set anti-aliased line (AAL) global vars. */ | |
2522 | - if (color == gdAntiAliased) { | |
2523 | - im->AAL_x1 = x1; | |
2524 | - im->AAL_y1 = y1; | |
2525 | - im->AAL_x2 = x2; | |
2526 | - im->AAL_y2 = y2; | |
2527 | - | |
2528 | - /* Compute what we can for point-to-line distance calculation later. */ | |
2529 | - im->AAL_Bx_Ax = x2 - x1; | |
2530 | - im->AAL_By_Ay = y2 - y1; | |
2531 | - im->AAL_LAB_2 = (im->AAL_Bx_Ax * im->AAL_Bx_Ax) + (im->AAL_By_Ay * im->AAL_By_Ay); | |
2532 | - im->AAL_LAB = sqrt (im->AAL_LAB_2); | |
2533 | + dx = abs (x2 - x1); | |
2534 | + dy = abs (y2 - y1); | |
2535 | ||
2536 | - /* For AA, we must draw pixels outside the width of the line. Keep in | |
2537 | - * mind that this will be curtailed by cos/sin of theta later. | |
2538 | - */ | |
2539 | - thick += 4; | |
2540 | + if (dx == 0) { | |
2541 | + gdImageVLine(im, x1, y1, y2, color); | |
2542 | + return; | |
2543 | + } else if (dy == 0) { | |
2544 | + gdImageHLine(im, y1, x1, x2, color); | |
2545 | + return; | |
2546 | } | |
2547 | - | |
2548 | - dx = abs(x2 - x1); | |
2549 | - dy = abs(y2 - y1); | |
2550 | + | |
2551 | if (dy <= dx) { | |
2552 | /* More-or-less horizontal. use wid for vertical stroke */ | |
2553 | /* Doug Claar: watch out for NaN in atan2 (2.0.5) */ | |
2554 | if ((dx == 0) && (dy == 0)) { | |
2555 | wid = 1; | |
2556 | } else { | |
2557 | - wid = (int)(thick * cos (atan2 (dy, dx))); | |
2558 | + /* 2.0.12: Michael Schwartz: divide rather than multiply; | |
2559 | +TBB: but watch out for /0! */ | |
2560 | + double ac = cos (atan2 (dy, dx)); | |
2561 | + if (ac != 0) { | |
2562 | + wid = thick / ac; | |
2563 | + } else { | |
2564 | + wid = 1; | |
2565 | + } | |
2566 | if (wid == 0) { | |
2567 | wid = 1; | |
2568 | } | |
2569 | @@ -1115,16 +1182,17 @@ | |
2570 | } | |
2571 | } else { | |
2572 | /* More-or-less vertical. use wid for horizontal stroke */ | |
2573 | - /* 2.0.12: Michael Schwartz: divide rather than multiply; | |
2574 | - TBB: but watch out for /0! */ | |
2575 | - double as = sin(atan2(dy, dx)); | |
2576 | + /* 2.0.12: Michael Schwartz: divide rather than multiply; | |
2577 | + TBB: but watch out for /0! */ | |
2578 | + double as = sin (atan2 (dy, dx)); | |
2579 | if (as != 0) { | |
2580 | - if (!(wid = thick / as)) { | |
2581 | - wid = 1; | |
2582 | - } | |
2583 | + wid = thick / as; | |
2584 | } else { | |
2585 | wid = 1; | |
2586 | } | |
2587 | + if (wid == 0) { | |
2588 | + wid = 1; | |
2589 | + } | |
2590 | ||
2591 | d = 2 * dx - dy; | |
2592 | incr1 = 2 * dx; | |
2593 | @@ -1177,11 +1245,6 @@ | |
2594 | } | |
2595 | } | |
2596 | } | |
2597 | - | |
2598 | - /* If this is the only line we are drawing, go ahead and blend. */ | |
2599 | - if (color == gdAntiAliased && !im->AA_polygon) { | |
2600 | - gdImageAABlend(im); | |
2601 | - } | |
2602 | } | |
2603 | ||
2604 | ||
2605 | @@ -1207,7 +1270,7 @@ | |
2606 | BLEND_COLOR(t, dg, g, dg); | |
2607 | BLEND_COLOR(t, db, b, db); | |
2608 | im->tpixels[y][x]=gdTrueColorAlpha(dr, dg, db, gdAlphaOpaque); | |
2609 | -} | |
2610 | +} | |
2611 | ||
2612 | /* | |
2613 | * Added on 2003/12 by Pierre-Alain Joye (pajoye@pearfr.org) | |
2614 | @@ -1586,9 +1649,9 @@ | |
2615 | ||
2616 | /* s and e are integers modulo 360 (degrees), with 0 degrees | |
2617 | being the rightmost extreme and degrees changing clockwise. | |
2618 | - cx and cy are the center in pixels; w and h are the horizontal | |
2619 | + cx and cy are the center in pixels; w and h are the horizontal | |
2620 | and vertical diameter in pixels. Nice interface, but slow. | |
2621 | - See gd_arc_f_buggy.c for a better version that doesn't | |
2622 | + See gd_arc_f_buggy.c for a better version that doesn't | |
2623 | seem to be bug-free yet. */ | |
2624 | ||
2625 | void gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color) | |
2626 | @@ -1607,29 +1670,30 @@ | |
2627 | int lx = 0, ly = 0; | |
2628 | int fx = 0, fy = 0; | |
2629 | ||
2630 | - if ((s % 360) == (e % 360)) { | |
2631 | + | |
2632 | + if ((s % 360) == (e % 360)) { | |
2633 | s = 0; e = 360; | |
2634 | - } else { | |
2635 | - if (s > 360) { | |
2636 | - s = s % 360; | |
2637 | - } | |
2638 | + } else { | |
2639 | + if (s > 360) { | |
2640 | + s = s % 360; | |
2641 | + } | |
2642 | ||
2643 | - if (e > 360) { | |
2644 | - e = e % 360; | |
2645 | - } | |
2646 | + if (e > 360) { | |
2647 | + e = e % 360; | |
2648 | + } | |
2649 | ||
2650 | - while (s < 0) { | |
2651 | - s += 360; | |
2652 | - } | |
2653 | + while (s < 0) { | |
2654 | + s += 360; | |
2655 | + } | |
2656 | ||
2657 | - while (e < s) { | |
2658 | - e += 360; | |
2659 | - } | |
2660 | + while (e < s) { | |
2661 | + e += 360; | |
2662 | + } | |
2663 | ||
2664 | - if (s == e) { | |
2665 | + if (s == e) { | |
2666 | s = 0; e = 360; | |
2667 | - } | |
2668 | - } | |
2669 | + } | |
2670 | + } | |
2671 | ||
2672 | for (i = s; i <= e; i++) { | |
2673 | int x, y; | |
2674 | @@ -1787,17 +1851,15 @@ | |
2675 | int lastBorder; | |
2676 | /* Seek left */ | |
2677 | int leftLimit = -1, rightLimit; | |
2678 | - int i, restoreAlphaBleding=0; | |
2679 | + int i, restoreAlphaBlending = 0; | |
2680 | ||
2681 | if (border < 0) { | |
2682 | /* Refuse to fill to a non-solid border */ | |
2683 | return; | |
2684 | } | |
2685 | ||
2686 | - if (im->alphaBlendingFlag) { | |
2687 | - restoreAlphaBleding = 1; | |
2688 | - im->alphaBlendingFlag = 0; | |
2689 | - } | |
2690 | + restoreAlphaBlending = im->alphaBlendingFlag; | |
2691 | + im->alphaBlendingFlag = 0; | |
2692 | ||
2693 | if (x >= im->sx) { | |
2694 | x = im->sx - 1; | |
2695 | @@ -1814,9 +1876,7 @@ | |
2696 | leftLimit = i; | |
2697 | } | |
2698 | if (leftLimit == -1) { | |
2699 | - if (restoreAlphaBleding) { | |
2700 | - im->alphaBlendingFlag = 1; | |
2701 | - } | |
2702 | + im->alphaBlendingFlag = restoreAlphaBlending; | |
2703 | return; | |
2704 | } | |
2705 | /* Seek right */ | |
2706 | @@ -1844,6 +1904,7 @@ | |
2707 | } | |
2708 | } | |
2709 | } | |
2710 | + | |
2711 | /* Below */ | |
2712 | if (y < ((im->sy) - 1)) { | |
2713 | lastBorder = 1; | |
2714 | @@ -1860,12 +1921,9 @@ | |
2715 | } | |
2716 | } | |
2717 | } | |
2718 | - if (restoreAlphaBleding) { | |
2719 | - im->alphaBlendingFlag = 1; | |
2720 | - } | |
2721 | + im->alphaBlendingFlag = restoreAlphaBlending; | |
2722 | } | |
2723 | ||
2724 | - | |
2725 | /* | |
2726 | * set the pixel at (x,y) and its 4-connected neighbors | |
2727 | * with the same pixel value to the new pixel value nc (new color). | |
2728 | @@ -1888,25 +1946,31 @@ | |
2729 | #define FILL_POP(Y, XL, XR, DY) \ | |
2730 | {sp--; Y = sp->y+(DY = sp->dy); XL = sp->xl; XR = sp->xr;} | |
2731 | ||
2732 | -void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc); | |
2733 | +static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc); | |
2734 | ||
2735 | void gdImageFill(gdImagePtr im, int x, int y, int nc) | |
2736 | { | |
2737 | int l, x1, x2, dy; | |
2738 | int oc; /* old pixel value */ | |
2739 | int wx2,wy2; | |
2740 | + | |
2741 | int alphablending_bak; | |
2742 | + | |
2743 | /* stack of filled segments */ | |
2744 | /* struct seg stack[FILL_MAX],*sp = stack;; */ | |
2745 | - struct seg *stack; | |
2746 | + struct seg *stack = NULL; | |
2747 | struct seg *sp; | |
2748 | ||
2749 | + if (!im->trueColor && nc > (im->colorsTotal -1)) { | |
2750 | + return; | |
2751 | + } | |
2752 | + | |
2753 | alphablending_bak = im->alphaBlendingFlag; | |
2754 | im->alphaBlendingFlag = 0; | |
2755 | ||
2756 | if (nc==gdTiled){ | |
2757 | _gdImageFillTiled(im,x,y,nc); | |
2758 | - im->alphaBlendingFlag = alphablending_bak; | |
2759 | + im->alphaBlendingFlag = alphablending_bak; | |
2760 | return; | |
2761 | } | |
2762 | ||
2763 | @@ -1916,8 +1980,31 @@ | |
2764 | im->alphaBlendingFlag = alphablending_bak; | |
2765 | return; | |
2766 | } | |
2767 | - | |
2768 | - stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1); | |
2769 | + | |
2770 | + /* Do not use the 4 neighbors implementation with | |
2771 | + * small images | |
2772 | + */ | |
2773 | + if (im->sx < 4) { | |
2774 | + int ix = x, iy = y, c; | |
2775 | + do { | |
2776 | + c = gdImageGetPixel(im, ix, iy); | |
2777 | + if (c != oc) { | |
2778 | + goto done; | |
2779 | + } | |
2780 | + gdImageSetPixel(im, ix, iy, nc); | |
2781 | + } while(ix++ < (im->sx -1)); | |
2782 | + ix = x; iy = y + 1; | |
2783 | + do { | |
2784 | + c = gdImageGetPixel(im, ix, iy); | |
2785 | + if (c != oc) { | |
2786 | + goto done; | |
2787 | + } | |
2788 | + gdImageSetPixel(im, ix, iy, nc); | |
2789 | + } while(ix++ < (im->sx -1)); | |
2790 | + goto done; | |
2791 | + } | |
2792 | + | |
2793 | + stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1); | |
2794 | sp = stack; | |
2795 | ||
2796 | /* required! */ | |
2797 | @@ -1954,22 +2041,25 @@ | |
2798 | l = x; | |
2799 | } while (x<=x2); | |
2800 | } | |
2801 | + | |
2802 | efree(stack); | |
2803 | + | |
2804 | +done: | |
2805 | im->alphaBlendingFlag = alphablending_bak; | |
2806 | } | |
2807 | ||
2808 | -void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc) | |
2809 | +static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc) | |
2810 | { | |
2811 | - int i,l, x1, x2, dy; | |
2812 | + int i, l, x1, x2, dy; | |
2813 | int oc; /* old pixel value */ | |
2814 | int tiled; | |
2815 | int wx2,wy2; | |
2816 | /* stack of filled segments */ | |
2817 | struct seg *stack; | |
2818 | struct seg *sp; | |
2819 | + char **pts; | |
2820 | ||
2821 | - int **pts; | |
2822 | - if(!im->tile){ | |
2823 | + if (!im->tile) { | |
2824 | return; | |
2825 | } | |
2826 | ||
2827 | @@ -1977,30 +2067,26 @@ | |
2828 | tiled = nc==gdTiled; | |
2829 | ||
2830 | nc = gdImageTileGet(im,x,y); | |
2831 | - pts = (int **) ecalloc(sizeof(int *) * im->sy, sizeof(int)); | |
2832 | ||
2833 | - for (i=0; i<im->sy;i++) { | |
2834 | - pts[i] = (int *) ecalloc(im->sx, sizeof(int)); | |
2835 | + pts = (char **) ecalloc(im->sy + 1, sizeof(char *)); | |
2836 | + for (i = 0; i < im->sy + 1; i++) { | |
2837 | + pts[i] = (char *) ecalloc(im->sx + 1, sizeof(char)); | |
2838 | } | |
2839 | ||
2840 | - stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1); | |
2841 | + stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1); | |
2842 | sp = stack; | |
2843 | ||
2844 | oc = gdImageGetPixel(im, x, y); | |
2845 | ||
2846 | - /* required! */ | |
2847 | +/* required! */ | |
2848 | FILL_PUSH(y,x,x,1); | |
2849 | /* seed segment (popped 1st) */ | |
2850 | FILL_PUSH(y+1, x, x, -1); | |
2851 | while (sp>stack) { | |
2852 | FILL_POP(y, x1, x2, dy); | |
2853 | for (x=x1; x>=0 && (!pts[y][x] && gdImageGetPixel(im,x,y)==oc); x--) { | |
2854 | - if (pts[y][x]){ | |
2855 | - /* we should never be here */ | |
2856 | - break; | |
2857 | - } | |
2858 | nc = gdImageTileGet(im,x,y); | |
2859 | - pts[y][x]=1; | |
2860 | + pts[y][x] = 1; | |
2861 | gdImageSetPixel(im,x, y, nc); | |
2862 | } | |
2863 | if (x>=x1) { | |
2864 | @@ -2014,13 +2100,9 @@ | |
2865 | } | |
2866 | x = x1+1; | |
2867 | do { | |
2868 | - for (; x<=wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc) ; x++) { | |
2869 | - if (pts[y][x]){ | |
2870 | - /* we should never be here */ | |
2871 | - break; | |
2872 | - } | |
2873 | + for(; x<wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc); x++) { | |
2874 | nc = gdImageTileGet(im,x,y); | |
2875 | - pts[y][x]=1; | |
2876 | + pts[y][x] = 1; | |
2877 | gdImageSetPixel(im, x, y, nc); | |
2878 | } | |
2879 | FILL_PUSH(y, l, x-1, dy); | |
2880 | @@ -2028,13 +2110,15 @@ | |
2881 | if (x>x2+1) { | |
2882 | FILL_PUSH(y, x2+1, x-1, -dy); | |
2883 | } | |
2884 | -skip: for (x++; x<=x2 && (pts[y][x] || gdImageGetPixel(im,x, y)!=oc); x++); | |
2885 | +skip: for(x++; x<=x2 && (pts[y][x] || gdImageGetPixel(im,x, y)!=oc); x++); | |
2886 | l = x; | |
2887 | } while (x<=x2); | |
2888 | } | |
2889 | - for (i=0; i<im->sy;i++) { | |
2890 | + | |
2891 | + for(i = 0; i < im->sy + 1; i++) { | |
2892 | efree(pts[i]); | |
2893 | } | |
2894 | + | |
2895 | efree(pts); | |
2896 | efree(stack); | |
2897 | } | |
2898 | @@ -2048,6 +2132,11 @@ | |
2899 | int half1 = 1; | |
2900 | int t; | |
2901 | ||
2902 | + if (x1 == x2 && y1 == y2 && thick == 1) { | |
2903 | + gdImageSetPixel(im, x1, y1, color); | |
2904 | + return; | |
2905 | + } | |
2906 | + | |
2907 | if (y2 < y1) { | |
2908 | t=y1; | |
2909 | y1 = y2; | |
2910 | @@ -2110,16 +2199,15 @@ | |
2911 | gdImageLine(im, x1v, y1v, x1v, y2v, color); | |
2912 | gdImageLine(im, x2v, y1v, x2v, y2v, color); | |
2913 | } | |
2914 | - | |
2915 | } | |
2916 | ||
2917 | void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color) | |
2918 | { | |
2919 | int x, y; | |
2920 | - | |
2921 | + | |
2922 | /* Nick Atty: limit the points at the edge. Note that this also | |
2923 | * nicely kills any plotting for rectangles completely outside the | |
2924 | - * window as it makes the tests in the for loops fail | |
2925 | + * window as it makes the tests in the for loops fail | |
2926 | */ | |
2927 | if (x1 < 0) { | |
2928 | x1 = 0; | |
2929 | @@ -2133,15 +2221,15 @@ | |
2930 | if (y1 > gdImageSY(im)) { | |
2931 | y1 = gdImageSY(im); | |
2932 | } | |
2933 | - if (y2 < y1) { | |
2934 | - int t; | |
2935 | - t=y1; | |
2936 | - y1 = y2; | |
2937 | - y2 = t; | |
2938 | - | |
2939 | - t = x1; | |
2940 | + if (x1 > x2) { | |
2941 | + x = x1; | |
2942 | x1 = x2; | |
2943 | - x2 = t; | |
2944 | + x2 = x; | |
2945 | + } | |
2946 | + if (y1 > y2) { | |
2947 | + y = y1; | |
2948 | + y1 = y2; | |
2949 | + y2 = y; | |
2950 | } | |
2951 | ||
2952 | for (y = y1; (y <= y2); y++) { | |
2953 | @@ -2162,9 +2250,9 @@ | |
2954 | if (dst->trueColor) { | |
2955 | /* 2.0: much easier when the destination is truecolor. */ | |
2956 | /* 2.0.10: needs a transparent-index check that is still valid if | |
2957 | - * the source is not truecolor. Thanks to Frank Warmerdam. | |
2958 | + * the source is not truecolor. Thanks to Frank Warmerdam. | |
2959 | */ | |
2960 | - | |
2961 | + | |
2962 | if (src->trueColor) { | |
2963 | for (y = 0; (y < h); y++) { | |
2964 | for (x = 0; (x < w); x++) { | |
2965 | @@ -2178,7 +2266,7 @@ | |
2966 | for (x = 0; (x < w); x++) { | |
2967 | int c = gdImageGetPixel (src, srcX + x, srcY + y); | |
2968 | if (c != src->transparent) { | |
2969 | - gdImageSetPixel (dst, dstX + x, dstY + y, gdTrueColor(src->red[c], src->green[c], src->blue[c])); | |
2970 | + gdImageSetPixel(dst, dstX + x, dstY + y, gdTrueColorAlpha(src->red[c], src->green[c], src->blue[c], src->alpha[c])); | |
2971 | } | |
2972 | } | |
2973 | } | |
2974 | @@ -2225,7 +2313,7 @@ | |
2975 | /* Have we established a mapping for this color? */ | |
2976 | if (src->trueColor) { | |
2977 | /* 2.05: remap to the palette available in the destination image. This is slow and | |
2978 | - * works badly, but it beats crashing! Thanks to Padhrig McCarthy. | |
2979 | + * works badly, but it beats crashing! Thanks to Padhrig McCarthy. | |
2980 | */ | |
2981 | mapTo = gdImageColorResolveAlpha (dst, gdTrueColorGetRed (c), gdTrueColorGetGreen (c), gdTrueColorGetBlue (c), gdTrueColorGetAlpha (c)); | |
2982 | } else if (colorMap[c] == (-1)) { | |
2983 | @@ -2237,9 +2325,9 @@ | |
2984 | nc = gdImageColorResolveAlpha (dst, src->red[c], src->green[c], src->blue[c], src->alpha[c]); | |
2985 | } | |
2986 | colorMap[c] = nc; | |
2987 | - mapTo = colorMap[c]; | |
2988 | + mapTo = colorMap[c]; | |
2989 | } else { | |
2990 | - mapTo = colorMap[c]; | |
2991 | + mapTo = colorMap[c]; | |
2992 | } | |
2993 | gdImageSetPixel (dst, tox, toy, mapTo); | |
2994 | tox++; | |
2995 | @@ -2257,7 +2345,7 @@ | |
2996 | int tox, toy; | |
2997 | int ncR, ncG, ncB; | |
2998 | toy = dstY; | |
2999 | - | |
3000 | + | |
3001 | for (y = srcY; y < (srcY + h); y++) { | |
3002 | tox = dstX; | |
3003 | for (x = srcX; x < (srcX + w); x++) { | |
3004 | @@ -2304,15 +2392,17 @@ | |
3005 | for (x = srcX; (x < (srcX + w)); x++) { | |
3006 | int nc; | |
3007 | c = gdImageGetPixel (src, x, y); | |
3008 | + | |
3009 | /* Added 7/24/95: support transparent copies */ | |
3010 | if (gdImageGetTransparent(src) == c) { | |
3011 | tox++; | |
3012 | continue; | |
3013 | } | |
3014 | - /* | |
3015 | - * If it's the same image, mapping is NOT trivial since we | |
3016 | - * merge with greyscale target, but if pct is 100, the grey | |
3017 | - * value is not used, so it becomes trivial. pjw 2.0.12. | |
3018 | + | |
3019 | + /* | |
3020 | + * If it's the same image, mapping is NOT trivial since we | |
3021 | + * merge with greyscale target, but if pct is 100, the grey | |
3022 | + * value is not used, so it becomes trivial. pjw 2.0.12. | |
3023 | */ | |
3024 | if (dst == src && pct == 100) { | |
3025 | nc = c; | |
3026 | @@ -2320,9 +2410,10 @@ | |
3027 | dc = gdImageGetPixel(dst, tox, toy); | |
3028 | g = (0.29900f * gdImageRed(dst, dc)) + (0.58700f * gdImageGreen(dst, dc)) + (0.11400f * gdImageBlue(dst, dc)); | |
3029 | ||
3030 | - ncR = (int)(gdImageRed (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0)); | |
3031 | - ncG = (int)(gdImageGreen (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0)); | |
3032 | - ncB = (int)(gdImageBlue (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0)); | |
3033 | + ncR = (int)(gdImageRed (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0)); | |
3034 | + ncG = (int)(gdImageGreen (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0)); | |
3035 | + ncB = (int)(gdImageBlue (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0)); | |
3036 | + | |
3037 | ||
3038 | /* First look for an exact match */ | |
3039 | nc = gdImageColorExact(dst, ncR, ncG, ncB); | |
3040 | @@ -2354,10 +2445,18 @@ | |
3041 | int *stx, *sty; | |
3042 | /* We only need to use floating point to determine the correct stretch vector for one line's worth. */ | |
3043 | double accum; | |
3044 | - stx = (int *) safe_emalloc(sizeof(int), srcW, 0); | |
3045 | - sty = (int *) safe_emalloc(sizeof(int), srcH, 0); | |
3046 | - accum = 0; | |
3047 | ||
3048 | + if (overflow2(sizeof(int), srcW)) { | |
3049 | + return; | |
3050 | + } | |
3051 | + if (overflow2(sizeof(int), srcH)) { | |
3052 | + return; | |
3053 | + } | |
3054 | + | |
3055 | + stx = (int *) gdMalloc (sizeof (int) * srcW); | |
3056 | + sty = (int *) gdMalloc (sizeof (int) * srcH); | |
3057 | + accum = 0; | |
3058 | + | |
3059 | /* Fixed by Mao Morimoto 2.0.16 */ | |
3060 | for (i = 0; (i < srcW); i++) { | |
3061 | stx[i] = dstW * (i+1) / srcW - dstW * i / srcW ; | |
3062 | @@ -2387,7 +2486,7 @@ | |
3063 | /* 2.0.21, TK: not tox++ */ | |
3064 | tox += stx[x - srcX]; | |
3065 | continue; | |
3066 | - } | |
3067 | + } | |
3068 | } else { | |
3069 | /* TK: old code follows */ | |
3070 | mapTo = gdImageGetTrueColorPixel (src, x, y); | |
3071 | @@ -2397,7 +2496,7 @@ | |
3072 | tox += stx[x - srcX]; | |
3073 | continue; | |
3074 | } | |
3075 | - } | |
3076 | + } | |
3077 | } else { | |
3078 | c = gdImageGetPixel (src, x, y); | |
3079 | /* Added 7/24/95: support transparent copies */ | |
3080 | @@ -2451,6 +2550,7 @@ | |
3081 | { | |
3082 | int x, y; | |
3083 | double sy1, sy2, sx1, sx2; | |
3084 | + | |
3085 | if (!dst->trueColor) { | |
3086 | gdImageCopyResized (dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); | |
3087 | return; | |
3088 | @@ -2497,7 +2597,7 @@ | |
3089 | } | |
3090 | pcontribution = xportion * yportion; | |
3091 | p = gdImageGetTrueColorPixel(src, (int) sx + srcX, (int) sy + srcY); | |
3092 | - | |
3093 | + | |
3094 | alpha_factor = ((gdAlphaMax - gdTrueColorGetAlpha(p))) * pcontribution; | |
3095 | red += gdTrueColorGetRed (p) * alpha_factor; | |
3096 | green += gdTrueColorGetGreen (p) * alpha_factor; | |
3097 | @@ -2509,12 +2609,12 @@ | |
3098 | sx += 1.0f; | |
3099 | } | |
3100 | while (sx < sx2); | |
3101 | - | |
3102 | + | |
3103 | sy += 1.0f; | |
3104 | } | |
3105 | - | |
3106 | + | |
3107 | while (sy < sy2); | |
3108 | - | |
3109 | + | |
3110 | if (spixels != 0.0f) { | |
3111 | red /= spixels; | |
3112 | green /= spixels; | |
3113 | @@ -2524,7 +2624,7 @@ | |
3114 | if ( alpha_sum != 0.0f) { | |
3115 | if( contrib_sum != 0.0f) { | |
3116 | alpha_sum /= contrib_sum; | |
3117 | - } | |
3118 | + } | |
3119 | red /= alpha_sum; | |
3120 | green /= alpha_sum; | |
3121 | blue /= alpha_sum; | |
3122 | @@ -2549,7 +2649,7 @@ | |
3123 | ||
3124 | ||
3125 | /* | |
3126 | - * Rotate function Added on 2003/12 | |
3127 | + * Rotate function Added on 2003/12 | |
3128 | * by Pierre-Alain Joye (pajoye@pearfr.org) | |
3129 | **/ | |
3130 | /* Begin rotate function */ | |
3131 | @@ -2558,7 +2658,7 @@ | |
3132 | #endif /* ROTATE_PI */ | |
3133 | ||
3134 | #define ROTATE_DEG2RAD 3.1415926535897932384626433832795/180 | |
3135 | -void gdImageSkewX (gdImagePtr dst, gdImagePtr src, int uRow, int iOffset, double dWeight, int clrBack) | |
3136 | +void gdImageSkewX (gdImagePtr dst, gdImagePtr src, int uRow, int iOffset, double dWeight, int clrBack, int ignoretransparent) | |
3137 | { | |
3138 | typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3139 | int i, r, g, b, a, clrBackR, clrBackG, clrBackB, clrBackA; | |
3140 | @@ -2623,10 +2723,14 @@ | |
3141 | a = 127; | |
3142 | } | |
3143 | ||
3144 | - pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a); | |
3145 | + if (ignoretransparent && pxlSrc == dst->transparent) { | |
3146 | + pxlSrc = dst->transparent; | |
3147 | + } else { | |
3148 | + pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a); | |
3149 | ||
3150 | - if (pxlSrc == -1) { | |
3151 | - pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a); | |
3152 | + if (pxlSrc == -1) { | |
3153 | + pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a); | |
3154 | + } | |
3155 | } | |
3156 | ||
3157 | if ((i + iOffset >= 0) && (i + iOffset < dst->sx)) { | |
3158 | @@ -2651,7 +2755,7 @@ | |
3159 | } | |
3160 | } | |
3161 | ||
3162 | -void gdImageSkewY (gdImagePtr dst, gdImagePtr src, int uCol, int iOffset, double dWeight, int clrBack) | |
3163 | +void gdImageSkewY (gdImagePtr dst, gdImagePtr src, int uCol, int iOffset, double dWeight, int clrBack, int ignoretransparent) | |
3164 | { | |
3165 | typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3166 | int i, iYPos=0, r, g, b, a; | |
3167 | @@ -2710,10 +2814,14 @@ | |
3168 | a = 127; | |
3169 | } | |
3170 | ||
3171 | - pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a); | |
3172 | + if (ignoretransparent && pxlSrc == dst->transparent) { | |
3173 | + pxlSrc = dst->transparent; | |
3174 | + } else { | |
3175 | + pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a); | |
3176 | ||
3177 | - if (pxlSrc == -1) { | |
3178 | - pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a); | |
3179 | + if (pxlSrc == -1) { | |
3180 | + pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a); | |
3181 | + } | |
3182 | } | |
3183 | ||
3184 | if ((iYPos >= 0) && (iYPos < dst->sy)) { | |
3185 | @@ -2735,10 +2843,10 @@ | |
3186 | } | |
3187 | ||
3188 | /* Rotates an image by 90 degrees (counter clockwise) */ | |
3189 | -gdImagePtr gdImageRotate90 (gdImagePtr src) | |
3190 | +gdImagePtr gdImageRotate90 (gdImagePtr src, int ignoretransparent) | |
3191 | { | |
3192 | int uY, uX; | |
3193 | - int c, r,g,b,a; | |
3194 | + int c,r,g,b,a; | |
3195 | gdImagePtr dst; | |
3196 | typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3197 | FuncPtr f; | |
3198 | @@ -2749,8 +2857,12 @@ | |
3199 | f = gdImageGetPixel; | |
3200 | } | |
3201 | dst = gdImageCreateTrueColor(src->sy, src->sx); | |
3202 | + dst->transparent = src->transparent; | |
3203 | ||
3204 | if (dst != NULL) { | |
3205 | + int old_blendmode = dst->alphaBlendingFlag; | |
3206 | + dst->alphaBlendingFlag = 0; | |
3207 | + | |
3208 | gdImagePaletteCopy (dst, src); | |
3209 | ||
3210 | for (uY = 0; uY<src->sy; uY++) { | |
3211 | @@ -2763,16 +2875,21 @@ | |
3212 | a = gdImageAlpha(src,c); | |
3213 | c = gdTrueColorAlpha(r, g, b, a); | |
3214 | } | |
3215 | - gdImageSetPixel(dst, uY, (dst->sy - uX - 1), c); | |
3216 | + if (ignoretransparent && c == dst->transparent) { | |
3217 | + gdImageSetPixel(dst, uY, (dst->sy - uX - 1), dst->transparent); | |
3218 | + } else { | |
3219 | + gdImageSetPixel(dst, uY, (dst->sy - uX - 1), c); | |
3220 | + } | |
3221 | } | |
3222 | } | |
3223 | + dst->alphaBlendingFlag = old_blendmode; | |
3224 | } | |
3225 | ||
3226 | return dst; | |
3227 | } | |
3228 | ||
3229 | /* Rotates an image by 180 degrees (counter clockwise) */ | |
3230 | -gdImagePtr gdImageRotate180 (gdImagePtr src) | |
3231 | +gdImagePtr gdImageRotate180 (gdImagePtr src, int ignoretransparent) | |
3232 | { | |
3233 | int uY, uX; | |
3234 | int c,r,g,b,a; | |
3235 | @@ -2786,8 +2903,12 @@ | |
3236 | f = gdImageGetPixel; | |
3237 | } | |
3238 | dst = gdImageCreateTrueColor(src->sx, src->sy); | |
3239 | + dst->transparent = src->transparent; | |
3240 | ||
3241 | if (dst != NULL) { | |
3242 | + int old_blendmode = dst->alphaBlendingFlag; | |
3243 | + dst->alphaBlendingFlag = 0; | |
3244 | + | |
3245 | gdImagePaletteCopy (dst, src); | |
3246 | ||
3247 | for (uY = 0; uY<src->sy; uY++) { | |
3248 | @@ -2800,16 +2921,22 @@ | |
3249 | a = gdImageAlpha(src,c); | |
3250 | c = gdTrueColorAlpha(r, g, b, a); | |
3251 | } | |
3252 | - gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), c); | |
3253 | + | |
3254 | + if (ignoretransparent && c == dst->transparent) { | |
3255 | + gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), dst->transparent); | |
3256 | + } else { | |
3257 | + gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), c); | |
3258 | + } | |
3259 | } | |
3260 | } | |
3261 | + dst->alphaBlendingFlag = old_blendmode; | |
3262 | } | |
3263 | ||
3264 | return dst; | |
3265 | } | |
3266 | ||
3267 | /* Rotates an image by 270 degrees (counter clockwise) */ | |
3268 | -gdImagePtr gdImageRotate270 ( gdImagePtr src ) | |
3269 | +gdImagePtr gdImageRotate270 (gdImagePtr src, int ignoretransparent) | |
3270 | { | |
3271 | int uY, uX; | |
3272 | int c,r,g,b,a; | |
3273 | @@ -2822,9 +2949,13 @@ | |
3274 | } else { | |
3275 | f = gdImageGetPixel; | |
3276 | } | |
3277 | - dst = gdImageCreateTrueColor(src->sy, src->sx); | |
3278 | + dst = gdImageCreateTrueColor (src->sy, src->sx); | |
3279 | + dst->transparent = src->transparent; | |
3280 | ||
3281 | if (dst != NULL) { | |
3282 | + int old_blendmode = dst->alphaBlendingFlag; | |
3283 | + dst->alphaBlendingFlag = 0; | |
3284 | + | |
3285 | gdImagePaletteCopy (dst, src); | |
3286 | ||
3287 | for (uY = 0; uY<src->sy; uY++) { | |
3288 | @@ -2837,15 +2968,21 @@ | |
3289 | a = gdImageAlpha(src,c); | |
3290 | c = gdTrueColorAlpha(r, g, b, a); | |
3291 | } | |
3292 | - gdImageSetPixel(dst, (dst->sx - uY - 1), uX, c); | |
3293 | + | |
3294 | + if (ignoretransparent && c == dst->transparent) { | |
3295 | + gdImageSetPixel(dst, (dst->sx - uY - 1), uX, dst->transparent); | |
3296 | + } else { | |
3297 | + gdImageSetPixel(dst, (dst->sx - uY - 1), uX, c); | |
3298 | + } | |
3299 | } | |
3300 | } | |
3301 | + dst->alphaBlendingFlag = old_blendmode; | |
3302 | } | |
3303 | ||
3304 | return dst; | |
3305 | } | |
3306 | ||
3307 | -gdImagePtr gdImageRotate45 (gdImagePtr src, double dAngle, int clrBack) | |
3308 | +gdImagePtr gdImageRotate45 (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent) | |
3309 | { | |
3310 | typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3311 | gdImagePtr dst1,dst2,dst3; | |
3312 | @@ -2869,8 +3006,8 @@ | |
3313 | } else { | |
3314 | f = gdImageGetPixel; | |
3315 | } | |
3316 | - dst1 = gdImageCreateTrueColor(newx, newy); | |
3317 | ||
3318 | + dst1 = gdImageCreateTrueColor(newx, newy); | |
3319 | /******* Perform 1st shear (horizontal) ******/ | |
3320 | if (dst1 == NULL) { | |
3321 | return NULL; | |
3322 | @@ -2885,6 +3022,15 @@ | |
3323 | ||
3324 | gdImagePaletteCopy (dst1, src); | |
3325 | ||
3326 | + if (ignoretransparent) { | |
3327 | + if (gdImageTrueColor(src)) { | |
3328 | + dst1->transparent = src->transparent; | |
3329 | + } else { | |
3330 | + | |
3331 | + dst1->transparent = gdTrueColorAlpha(gdImageRed(src, src->transparent), gdImageBlue(src, src->transparent), gdImageGreen(src, src->transparent), 127); | |
3332 | + } | |
3333 | + } | |
3334 | + | |
3335 | dRadAngle = dAngle * ROTATE_DEG2RAD; /* Angle in radians */ | |
3336 | dSinE = sin (dRadAngle); | |
3337 | dTan = tan (dRadAngle / 2.0); | |
3338 | @@ -2897,7 +3043,7 @@ | |
3339 | } | |
3340 | ||
3341 | iShear = (int)floor(dShear); | |
3342 | - gdImageSkewX(dst1, src, u, iShear, (dShear - iShear), clrBack); | |
3343 | + gdImageSkewX(dst1, src, u, iShear, (dShear - iShear), clrBack, ignoretransparent); | |
3344 | } | |
3345 | ||
3346 | /* | |
3347 | @@ -2933,10 +3079,13 @@ | |
3348 | return NULL; | |
3349 | } | |
3350 | dst2->alphaBlendingFlag = gdEffectReplace; | |
3351 | + if (ignoretransparent) { | |
3352 | + dst2->transparent = dst1->transparent; | |
3353 | + } | |
3354 | ||
3355 | for (u = 0; u < dst2->sx; u++, dOffset -= dSinE) { | |
3356 | iShear = (int)floor (dOffset); | |
3357 | - gdImageSkewY(dst2, dst1, u, iShear, (dOffset - (double)iShear), clrBack); | |
3358 | + gdImageSkewY(dst2, dst1, u, iShear, (dOffset - (double)iShear), clrBack, ignoretransparent); | |
3359 | } | |
3360 | ||
3361 | /* 3rd shear */ | |
3362 | @@ -2955,6 +3104,12 @@ | |
3363 | gdImageDestroy(dst2); | |
3364 | return NULL; | |
3365 | } | |
3366 | + | |
3367 | + dst3->alphaBlendingFlag = gdEffectReplace; | |
3368 | + if (ignoretransparent) { | |
3369 | + dst3->transparent = dst2->transparent; | |
3370 | + } | |
3371 | + | |
3372 | if (dSinE >= 0.0) { | |
3373 | dOffset = (double)(src->sx - 1) * dSinE * -dTan; | |
3374 | } else { | |
3375 | @@ -2962,8 +3117,8 @@ | |
3376 | } | |
3377 | ||
3378 | for (u = 0; u < dst3->sy; u++, dOffset += dTan) { | |
3379 | - int iShear = (int)floor(dOffset); | |
3380 | - gdImageSkewX(dst3, dst2, u, iShear, (dOffset - iShear), clrBack); | |
3381 | + int iShear = (int)floor(dOffset); | |
3382 | + gdImageSkewX(dst3, dst2, u, iShear, (dOffset - iShear), clrBack, ignoretransparent); | |
3383 | } | |
3384 | ||
3385 | gdImageDestroy(dst2); | |
3386 | @@ -2971,11 +3126,11 @@ | |
3387 | return dst3; | |
3388 | } | |
3389 | ||
3390 | -gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack) | |
3391 | +gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent) | |
3392 | { | |
3393 | gdImagePtr pMidImg; | |
3394 | gdImagePtr rotatedImg; | |
3395 | - int r,g,b,a; | |
3396 | + | |
3397 | if (src == NULL) { | |
3398 | return NULL; | |
3399 | } | |
3400 | @@ -2993,41 +3148,33 @@ | |
3401 | } | |
3402 | ||
3403 | if (dAngle == 90.00) { | |
3404 | - return gdImageRotate90(src); | |
3405 | + return gdImageRotate90(src, ignoretransparent); | |
3406 | } | |
3407 | if (dAngle == 180.00) { | |
3408 | - return gdImageRotate180(src); | |
3409 | + return gdImageRotate180(src, ignoretransparent); | |
3410 | } | |
3411 | if(dAngle == 270.00) { | |
3412 | - return gdImageRotate270 ( src); | |
3413 | + return gdImageRotate270 (src, ignoretransparent); | |
3414 | } | |
3415 | ||
3416 | if ((dAngle > 45.0) && (dAngle <= 135.0)) { | |
3417 | - pMidImg = gdImageRotate90 (src); | |
3418 | + pMidImg = gdImageRotate90 (src, ignoretransparent); | |
3419 | dAngle -= 90.0; | |
3420 | } else if ((dAngle > 135.0) && (dAngle <= 225.0)) { | |
3421 | - pMidImg = gdImageRotate180 (src); | |
3422 | + pMidImg = gdImageRotate180 (src, ignoretransparent); | |
3423 | dAngle -= 180.0; | |
3424 | } else if ((dAngle > 225.0) && (dAngle <= 315.0)) { | |
3425 | - pMidImg = gdImageRotate270 (src); | |
3426 | + pMidImg = gdImageRotate270 (src, ignoretransparent); | |
3427 | dAngle -= 270.0; | |
3428 | } else { | |
3429 | - return gdImageRotate45 (src, dAngle, clrBack); | |
3430 | + return gdImageRotate45 (src, dAngle, clrBack, ignoretransparent); | |
3431 | } | |
3432 | ||
3433 | if (pMidImg == NULL) { | |
3434 | return NULL; | |
3435 | } | |
3436 | ||
3437 | - if(!src->trueColor) { | |
3438 | - r = gdImageRed(src, clrBack); | |
3439 | - g = gdImageGreen(src, clrBack); | |
3440 | - b = gdImageBlue(src, clrBack); | |
3441 | - a = gdImageAlpha(src, clrBack); | |
3442 | - clrBack = gdTrueColorAlpha(r,g,b,a); | |
3443 | - } | |
3444 | - | |
3445 | - rotatedImg = gdImageRotate45 (pMidImg, dAngle, clrBack); | |
3446 | + rotatedImg = gdImageRotate45 (pMidImg, dAngle, clrBack, ignoretransparent); | |
3447 | gdImageDestroy(pMidImg); | |
3448 | ||
3449 | return rotatedImg; | |
3450 | @@ -3098,20 +3245,27 @@ | |
3451 | return; | |
3452 | } | |
3453 | ||
3454 | + if (overflow2(sizeof(int), n)) { | |
3455 | + return; | |
3456 | + } | |
3457 | + | |
3458 | if (c == gdAntiAliased) { | |
3459 | fill_color = im->AA_color; | |
3460 | } else { | |
3461 | fill_color = c; | |
3462 | } | |
3463 | - | |
3464 | + | |
3465 | if (!im->polyAllocated) { | |
3466 | - im->polyInts = (int *) safe_emalloc(sizeof(int), n, 0); | |
3467 | + im->polyInts = (int *) gdMalloc(sizeof(int) * n); | |
3468 | im->polyAllocated = n; | |
3469 | } | |
3470 | if (im->polyAllocated < n) { | |
3471 | while (im->polyAllocated < n) { | |
3472 | im->polyAllocated *= 2; | |
3473 | } | |
3474 | + if (overflow2(sizeof(int), im->polyAllocated)) { | |
3475 | + return; | |
3476 | + } | |
3477 | im->polyInts = (int *) gdRealloc(im->polyInts, sizeof(int) * im->polyAllocated); | |
3478 | } | |
3479 | miny = p[0].y; | |
3480 | @@ -3131,7 +3285,7 @@ | |
3481 | } | |
3482 | if (maxy >= gdImageSY(im)) { | |
3483 | maxy = gdImageSY(im) - 1; | |
3484 | - } | |
3485 | + } | |
3486 | ||
3487 | /* Fix in 1.3: count a vertex only once */ | |
3488 | for (y = miny; y <= maxy; y++) { | |
3489 | @@ -3193,7 +3347,7 @@ | |
3490 | if (im->style) { | |
3491 | gdFree(im->style); | |
3492 | } | |
3493 | - im->style = (int *) safe_emalloc(sizeof(int), noOfPixels, 0); | |
3494 | + im->style = (int *) gdMalloc(sizeof(int) * noOfPixels); | |
3495 | memcpy(im->style, style, sizeof(int) * noOfPixels); | |
3496 | im->styleLength = noOfPixels; | |
3497 | im->stylePos = 0; | |
3498 | @@ -3323,9 +3477,9 @@ | |
3499 | } | |
3500 | ||
3501 | int | |
3502 | -gdAlphaBlend (int dst, int src) | |
3503 | +gdAlphaBlendOld (int dst, int src) | |
3504 | { | |
3505 | - /* 2.0.12: TBB: alpha in the destination should be a | |
3506 | + /* 2.0.12: TBB: alpha in the destination should be a | |
3507 | * component of the result. Thanks to Frank Warmerdam for | |
3508 | * pointing out the issue. | |
3509 | */ | |
3510 | @@ -3345,6 +3499,51 @@ | |
3511 | gdTrueColorGetBlue (dst)) / gdAlphaMax)); | |
3512 | } | |
3513 | ||
3514 | +int gdAlphaBlend (int dst, int src) { | |
3515 | + int src_alpha = gdTrueColorGetAlpha(src); | |
3516 | + int dst_alpha, alpha, red, green, blue; | |
3517 | + int src_weight, dst_weight, tot_weight; | |
3518 | + | |
3519 | +/* -------------------------------------------------------------------- */ | |
3520 | +/* Simple cases we want to handle fast. */ | |
3521 | +/* -------------------------------------------------------------------- */ | |
3522 | + if( src_alpha == gdAlphaOpaque ) | |
3523 | + return src; | |
3524 | + | |
3525 | + dst_alpha = gdTrueColorGetAlpha(dst); | |
3526 | + if( src_alpha == gdAlphaTransparent ) | |
3527 | + return dst; | |
3528 | + if( dst_alpha == gdAlphaTransparent ) | |
3529 | + return src; | |
3530 | + | |
3531 | +/* -------------------------------------------------------------------- */ | |
3532 | +/* What will the source and destination alphas be? Note that */ | |
3533 | +/* the destination weighting is substantially reduced as the */ | |
3534 | +/* overlay becomes quite opaque. */ | |
3535 | +/* -------------------------------------------------------------------- */ | |
3536 | + src_weight = gdAlphaTransparent - src_alpha; | |
3537 | + dst_weight = (gdAlphaTransparent - dst_alpha) * src_alpha / gdAlphaMax; | |
3538 | + tot_weight = src_weight + dst_weight; | |
3539 | + | |
3540 | +/* -------------------------------------------------------------------- */ | |
3541 | +/* What red, green and blue result values will we use? */ | |
3542 | +/* -------------------------------------------------------------------- */ | |
3543 | + alpha = src_alpha * dst_alpha / gdAlphaMax; | |
3544 | + | |
3545 | + red = (gdTrueColorGetRed(src) * src_weight | |
3546 | + + gdTrueColorGetRed(dst) * dst_weight) / tot_weight; | |
3547 | + green = (gdTrueColorGetGreen(src) * src_weight | |
3548 | + + gdTrueColorGetGreen(dst) * dst_weight) / tot_weight; | |
3549 | + blue = (gdTrueColorGetBlue(src) * src_weight | |
3550 | + + gdTrueColorGetBlue(dst) * dst_weight) / tot_weight; | |
3551 | + | |
3552 | +/* -------------------------------------------------------------------- */ | |
3553 | +/* Return merged result. */ | |
3554 | +/* -------------------------------------------------------------------- */ | |
3555 | + return ((alpha << 24) + (red << 16) + (green << 8) + blue); | |
3556 | + | |
3557 | +} | |
3558 | + | |
3559 | void gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg) | |
3560 | { | |
3561 | im->alphaBlendingFlag = alphaBlendingArg; | |
3562 | @@ -3362,44 +3561,6 @@ | |
3563 | im->saveAlphaFlag = saveAlphaArg; | |
3564 | } | |
3565 | ||
3566 | -static int gdFullAlphaBlend (int dst, int src) | |
3567 | -{ | |
3568 | - int a1, a2; | |
3569 | - a1 = gdAlphaTransparent - gdTrueColorGetAlpha(src); | |
3570 | - a2 = gdAlphaTransparent - gdTrueColorGetAlpha(dst); | |
3571 | - | |
3572 | - return ( ((gdAlphaTransparent - ((a1+a2)-(a1*a2/gdAlphaMax))) << 24) + | |
3573 | - (gdAlphaBlendColor( gdTrueColorGetRed(src), gdTrueColorGetRed(dst), a1, a2 ) << 16) + | |
3574 | - (gdAlphaBlendColor( gdTrueColorGetGreen(src), gdTrueColorGetGreen(dst), a1, a2 ) << 8) + | |
3575 | - (gdAlphaBlendColor( gdTrueColorGetBlue(src), gdTrueColorGetBlue(dst), a1, a2 )) | |
3576 | - ); | |
3577 | -} | |
3578 | - | |
3579 | -static int gdAlphaBlendColor( int b1, int b2, int a1, int a2 ) | |
3580 | -{ | |
3581 | - int c; | |
3582 | - int w; | |
3583 | - | |
3584 | - /* deal with special cases */ | |
3585 | - | |
3586 | - if( (gdAlphaMax == a1) || (0 == a2) ) { | |
3587 | - /* the back pixel can't be seen */ | |
3588 | - return b1; | |
3589 | - } else if(0 == a1) { | |
3590 | - /* the front pixel can't be seen */ | |
3591 | - return b2; | |
3592 | - } else if(gdAlphaMax == a2) { | |
3593 | - /* the back pixel is opaque */ | |
3594 | - return ( a1 * b1 + ( gdAlphaMax - a1 ) * b2 ) / gdAlphaMax; | |
3595 | - } | |
3596 | - | |
3597 | - /* the general case */ | |
3598 | - w = ( a1 * ( gdAlphaMax - a2 ) / ( gdAlphaMax - a1 * a2 / gdAlphaMax ) * b1 + \ | |
3599 | - a2 * ( gdAlphaMax - a1 ) / ( gdAlphaMax - a1 * a2 / gdAlphaMax ) * b2 ) / gdAlphaMax; | |
3600 | - c = (a2 * b2 + ( gdAlphaMax - a2 ) * w ) / gdAlphaMax; | |
3601 | - return ( a1 * b1 + ( gdAlphaMax - a1 ) * c ) / gdAlphaMax; | |
3602 | -} | |
3603 | - | |
3604 | static int gdLayerOverlay (int dst, int src) | |
3605 | { | |
3606 | int a1, a2; | |
3607 | @@ -3415,12 +3576,12 @@ | |
3608 | static int gdAlphaOverlayColor (int src, int dst, int max ) | |
3609 | { | |
3610 | /* this function implements the algorithm | |
3611 | - * | |
3612 | + * | |
3613 | * for dst[rgb] < 0.5, | |
3614 | * c[rgb] = 2.src[rgb].dst[rgb] | |
3615 | * and for dst[rgb] > 0.5, | |
3616 | * c[rgb] = -2.src[rgb].dst[rgb] + 2.dst[rgb] + 2.src[rgb] - 1 | |
3617 | - * | |
3618 | + * | |
3619 | */ | |
3620 | ||
3621 | dst = dst << 1; | |
3622 | @@ -3472,3 +3633,457 @@ | |
3623 | *x2P = im->cx2; | |
3624 | *y2P = im->cy2; | |
3625 | } | |
3626 | + | |
3627 | + | |
3628 | +/* Filters function added on 2003/12 | |
3629 | + * by Pierre-Alain Joye (pajoye@pearfr.org) | |
3630 | + **/ | |
3631 | +/* Begin filters function */ | |
3632 | +#ifndef HAVE_GET_TRUE_COLOR | |
3633 | +#define GET_PIXEL_FUNCTION(src)(src->trueColor?gdImageGetTrueColorPixel:gdImageGetPixel) | |
3634 | +#endif | |
3635 | + | |
3636 | +/* invert src image */ | |
3637 | +int gdImageNegate(gdImagePtr src) | |
3638 | +{ | |
3639 | + int x, y; | |
3640 | + int r,g,b,a; | |
3641 | + int new_pxl, pxl; | |
3642 | + typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3643 | + FuncPtr f; | |
3644 | + | |
3645 | + if (src==NULL) { | |
3646 | + return 0; | |
3647 | + } | |
3648 | + | |
3649 | + f = GET_PIXEL_FUNCTION(src); | |
3650 | + | |
3651 | + for (y=0; y<src->sy; ++y) { | |
3652 | + for (x=0; x<src->sx; ++x) { | |
3653 | + pxl = f (src, x, y); | |
3654 | + r = gdImageRed(src, pxl); | |
3655 | + g = gdImageGreen(src, pxl); | |
3656 | + b = gdImageBlue(src, pxl); | |
3657 | + a = gdImageAlpha(src, pxl); | |
3658 | + | |
3659 | + new_pxl = gdImageColorAllocateAlpha(src, 255-r, 255-g, 255-b, a); | |
3660 | + if (new_pxl == -1) { | |
3661 | + new_pxl = gdImageColorClosestAlpha(src, 255-r, 255-g, 255-b, a); | |
3662 | + } | |
3663 | + gdImageSetPixel (src, x, y, new_pxl); | |
3664 | + } | |
3665 | + } | |
3666 | + return 1; | |
3667 | +} | |
3668 | + | |
3669 | +/* Convert the image src to a grayscale image */ | |
3670 | +int gdImageGrayScale(gdImagePtr src) | |
3671 | +{ | |
3672 | + int x, y; | |
3673 | + int r,g,b,a; | |
3674 | + int new_pxl, pxl; | |
3675 | + typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3676 | + FuncPtr f; | |
3677 | + f = GET_PIXEL_FUNCTION(src); | |
3678 | + | |
3679 | + if (src==NULL) { | |
3680 | + return 0; | |
3681 | + } | |
3682 | + | |
3683 | + for (y=0; y<src->sy; ++y) { | |
3684 | + for (x=0; x<src->sx; ++x) { | |
3685 | + pxl = f (src, x, y); | |
3686 | + r = gdImageRed(src, pxl); | |
3687 | + g = gdImageGreen(src, pxl); | |
3688 | + b = gdImageBlue(src, pxl); | |
3689 | + a = gdImageAlpha(src, pxl); | |
3690 | + r = g = b = (int) (.299 * r + .587 * g + .114 * b); | |
3691 | + | |
3692 | + new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a); | |
3693 | + if (new_pxl == -1) { | |
3694 | + new_pxl = gdImageColorClosestAlpha(src, r, g, b, a); | |
3695 | + } | |
3696 | + gdImageSetPixel (src, x, y, new_pxl); | |
3697 | + } | |
3698 | + } | |
3699 | + return 1; | |
3700 | +} | |
3701 | + | |
3702 | +/* Set the brightness level <level> for the image src */ | |
3703 | +int gdImageBrightness(gdImagePtr src, int brightness) | |
3704 | +{ | |
3705 | + int x, y; | |
3706 | + int r,g,b,a; | |
3707 | + int new_pxl, pxl; | |
3708 | + typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3709 | + FuncPtr f; | |
3710 | + f = GET_PIXEL_FUNCTION(src); | |
3711 | + | |
3712 | + if (src==NULL || (brightness < -255 || brightness>255)) { | |
3713 | + return 0; | |
3714 | + } | |
3715 | + | |
3716 | + if (brightness==0) { | |
3717 | + return 1; | |
3718 | + } | |
3719 | + | |
3720 | + for (y=0; y<src->sy; ++y) { | |
3721 | + for (x=0; x<src->sx; ++x) { | |
3722 | + pxl = f (src, x, y); | |
3723 | + | |
3724 | + r = gdImageRed(src, pxl); | |
3725 | + g = gdImageGreen(src, pxl); | |
3726 | + b = gdImageBlue(src, pxl); | |
3727 | + a = gdImageAlpha(src, pxl); | |
3728 | + | |
3729 | + r = r + brightness; | |
3730 | + g = g + brightness; | |
3731 | + b = b + brightness; | |
3732 | + | |
3733 | + r = (r > 255)? 255 : ((r < 0)? 0:r); | |
3734 | + g = (g > 255)? 255 : ((g < 0)? 0:g); | |
3735 | + b = (b > 255)? 255 : ((b < 0)? 0:b); | |
3736 | + | |
3737 | + new_pxl = gdImageColorAllocateAlpha(src, (int)r, (int)g, (int)b, a); | |
3738 | + if (new_pxl == -1) { | |
3739 | + new_pxl = gdImageColorClosestAlpha(src, (int)r, (int)g, (int)b, a); | |
3740 | + } | |
3741 | + gdImageSetPixel (src, x, y, new_pxl); | |
3742 | + } | |
3743 | + } | |
3744 | + return 1; | |
3745 | +} | |
3746 | + | |
3747 | + | |
3748 | +int gdImageContrast(gdImagePtr src, double contrast) | |
3749 | +{ | |
3750 | + int x, y; | |
3751 | + int r,g,b,a; | |
3752 | + double rf,gf,bf; | |
3753 | + int new_pxl, pxl; | |
3754 | + typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3755 | + | |
3756 | + FuncPtr f; | |
3757 | + f = GET_PIXEL_FUNCTION(src); | |
3758 | + | |
3759 | + if (src==NULL) { | |
3760 | + return 0; | |
3761 | + } | |
3762 | + | |
3763 | + contrast = (double)(100.0-contrast)/100.0; | |
3764 | + contrast = contrast*contrast; | |
3765 | + | |
3766 | + for (y=0; y<src->sy; ++y) { | |
3767 | + for (x=0; x<src->sx; ++x) { | |
3768 | + pxl = f(src, x, y); | |
3769 | + | |
3770 | + r = gdImageRed(src, pxl); | |
3771 | + g = gdImageGreen(src, pxl); | |
3772 | + b = gdImageBlue(src, pxl); | |
3773 | + a = gdImageAlpha(src, pxl); | |
3774 | + | |
3775 | + rf = (double)r/255.0; | |
3776 | + rf = rf-0.5; | |
3777 | + rf = rf*contrast; | |
3778 | + rf = rf+0.5; | |
3779 | + rf = rf*255.0; | |
3780 | + | |
3781 | + bf = (double)b/255.0; | |
3782 | + bf = bf-0.5; | |
3783 | + bf = bf*contrast; | |
3784 | + bf = bf+0.5; | |
3785 | + bf = bf*255.0; | |
3786 | + | |
3787 | + gf = (double)g/255.0; | |
3788 | + gf = gf-0.5; | |
3789 | + gf = gf*contrast; | |
3790 | + gf = gf+0.5; | |
3791 | + gf = gf*255.0; | |
3792 | + | |
3793 | + rf = (rf > 255.0)? 255.0 : ((rf < 0.0)? 0.0:rf); | |
3794 | + gf = (gf > 255.0)? 255.0 : ((gf < 0.0)? 0.0:gf); | |
3795 | + bf = (bf > 255.0)? 255.0 : ((bf < 0.0)? 0.0:bf); | |
3796 | + | |
3797 | + new_pxl = gdImageColorAllocateAlpha(src, (int)rf, (int)gf, (int)bf, a); | |
3798 | + if (new_pxl == -1) { | |
3799 | + new_pxl = gdImageColorClosestAlpha(src, (int)rf, (int)gf, (int)bf, a); | |
3800 | + } | |
3801 | + gdImageSetPixel (src, x, y, new_pxl); | |
3802 | + } | |
3803 | + } | |
3804 | + return 1; | |
3805 | +} | |
3806 | + | |
3807 | + | |
3808 | +int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha) | |
3809 | +{ | |
3810 | + int x, y; | |
3811 | + int new_pxl, pxl; | |
3812 | + typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3813 | + FuncPtr f; | |
3814 | + | |
3815 | + if (src == NULL) { | |
3816 | + return 0; | |
3817 | + } | |
3818 | + | |
3819 | + f = GET_PIXEL_FUNCTION(src); | |
3820 | + | |
3821 | + for (y=0; y<src->sy; ++y) { | |
3822 | + for (x=0; x<src->sx; ++x) { | |
3823 | + int r,g,b,a; | |
3824 | + | |
3825 | + pxl = f(src, x, y); | |
3826 | + r = gdImageRed(src, pxl); | |
3827 | + g = gdImageGreen(src, pxl); | |
3828 | + b = gdImageBlue(src, pxl); | |
3829 | + a = gdImageAlpha(src, pxl); | |
3830 | + | |
3831 | + r = r + red; | |
3832 | + g = g + green; | |
3833 | + b = b + blue; | |
3834 | + a = a + alpha; | |
3835 | + | |
3836 | + r = (r > 255)? 255 : ((r < 0)? 0 : r); | |
3837 | + g = (g > 255)? 255 : ((g < 0)? 0 : g); | |
3838 | + b = (b > 255)? 255 : ((b < 0)? 0 : b); | |
3839 | + a = (a > 127)? 127 : ((a < 0)? 0 : a); | |
3840 | + | |
3841 | + new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a); | |
3842 | + if (new_pxl == -1) { | |
3843 | + new_pxl = gdImageColorClosestAlpha(src, r, g, b, a); | |
3844 | + } | |
3845 | + gdImageSetPixel (src, x, y, new_pxl); | |
3846 | + } | |
3847 | + } | |
3848 | + return 1; | |
3849 | +} | |
3850 | + | |
3851 | +int gdImageConvolution(gdImagePtr src, float filter[3][3], float filter_div, float offset) | |
3852 | +{ | |
3853 | + int x, y, i, j, new_a; | |
3854 | + float new_r, new_g, new_b; | |
3855 | + int new_pxl, pxl=0; | |
3856 | + gdImagePtr srcback; | |
3857 | + typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3858 | + FuncPtr f; | |
3859 | + | |
3860 | + if (src==NULL) { | |
3861 | + return 0; | |
3862 | + } | |
3863 | + | |
3864 | + /* We need the orinal image with each safe neoghb. pixel */ | |
3865 | + srcback = gdImageCreateTrueColor (src->sx, src->sy); | |
3866 | + gdImageCopy(srcback, src,0,0,0,0,src->sx,src->sy); | |
3867 | + | |
3868 | + if (srcback==NULL) { | |
3869 | + return 0; | |
3870 | + } | |
3871 | + | |
3872 | + f = GET_PIXEL_FUNCTION(src); | |
3873 | + | |
3874 | + for ( y=0; y<src->sy; y++) { | |
3875 | + for(x=0; x<src->sx; x++) { | |
3876 | + new_r = new_g = new_b = 0; | |
3877 | + new_a = gdImageAlpha(srcback, pxl); | |
3878 | + | |
3879 | + for (j=0; j<3; j++) { | |
3880 | + int yv = MIN(MAX(y - 1 + j, 0), src->sy - 1); | |
3881 | + for (i=0; i<3; i++) { | |
3882 | + pxl = f(srcback, MIN(MAX(x - 1 + i, 0), src->sx - 1), yv); | |
3883 | + new_r += (float)gdImageRed(srcback, pxl) * filter[j][i]; | |
3884 | + new_g += (float)gdImageGreen(srcback, pxl) * filter[j][i]; | |
3885 | + new_b += (float)gdImageBlue(srcback, pxl) * filter[j][i]; | |
3886 | + } | |
3887 | + } | |
3888 | + | |
3889 | + new_r = (new_r/filter_div)+offset; | |
3890 | + new_g = (new_g/filter_div)+offset; | |
3891 | + new_b = (new_b/filter_div)+offset; | |
3892 | + | |
3893 | + new_r = (new_r > 255.0f)? 255.0f : ((new_r < 0.0f)? 0.0f:new_r); | |
3894 | + new_g = (new_g > 255.0f)? 255.0f : ((new_g < 0.0f)? 0.0f:new_g); | |
3895 | + new_b = (new_b > 255.0f)? 255.0f : ((new_b < 0.0f)? 0.0f:new_b); | |
3896 | + | |
3897 | + new_pxl = gdImageColorAllocateAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a); | |
3898 | + if (new_pxl == -1) { | |
3899 | + new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a); | |
3900 | + } | |
3901 | + gdImageSetPixel (src, x, y, new_pxl); | |
3902 | + } | |
3903 | + } | |
3904 | + gdImageDestroy(srcback); | |
3905 | + return 1; | |
3906 | +} | |
3907 | + | |
3908 | +int gdImageSelectiveBlur( gdImagePtr src) | |
3909 | +{ | |
3910 | + int x, y, i, j; | |
3911 | + float new_r, new_g, new_b; | |
3912 | + int new_pxl, cpxl, pxl, new_a=0; | |
3913 | + float flt_r [3][3]; | |
3914 | + float flt_g [3][3]; | |
3915 | + float flt_b [3][3]; | |
3916 | + float flt_r_sum, flt_g_sum, flt_b_sum; | |
3917 | + | |
3918 | + gdImagePtr srcback; | |
3919 | + typedef int (*FuncPtr)(gdImagePtr, int, int); | |
3920 | + FuncPtr f; | |
3921 | + | |
3922 | + if (src==NULL) { | |
3923 | + return 0; | |
3924 | + } | |
3925 | + | |
3926 | + /* We need the orinal image with each safe neoghb. pixel */ | |
3927 | + srcback = gdImageCreateTrueColor (src->sx, src->sy); | |
3928 | + gdImageCopy(srcback, src,0,0,0,0,src->sx,src->sy); | |
3929 | + | |
3930 | + if (srcback==NULL) { | |
3931 | + return 0; | |
3932 | + } | |
3933 | + | |
3934 | + f = GET_PIXEL_FUNCTION(src); | |
3935 | + | |
3936 | + for(y = 0; y<src->sy; y++) { | |
3937 | + for (x=0; x<src->sx; x++) { | |
3938 | + flt_r_sum = flt_g_sum = flt_b_sum = 0.0; | |
3939 | + cpxl = f(src, x, y); | |
3940 | + | |
3941 | + for (j=0; j<3; j++) { | |
3942 | + for (i=0; i<3; i++) { | |
3943 | + if ((j == 1) && (i == 1)) { | |
3944 | + flt_r[1][1] = flt_g[1][1] = flt_b[1][1] = 0.5; | |
3945 | + } else { | |
3946 | + pxl = f(src, x-(3>>1)+i, y-(3>>1)+j); | |
3947 | + new_a = gdImageAlpha(srcback, pxl); | |
3948 | + | |
3949 | + new_r = ((float)gdImageRed(srcback, cpxl)) - ((float)gdImageRed (srcback, pxl)); | |
3950 | + | |
3951 | + if (new_r < 0.0f) { | |
3952 | + new_r = -new_r; | |
3953 | + } | |
3954 | + if (new_r != 0) { | |
3955 | + flt_r[j][i] = 1.0f/new_r; | |
3956 | + } else { | |
3957 | + flt_r[j][i] = 1.0f; | |
3958 | + } | |
3959 | + | |
3960 | + new_g = ((float)gdImageGreen(srcback, cpxl)) - ((float)gdImageGreen(srcback, pxl)); | |
3961 | + | |
3962 | + if (new_g < 0.0f) { | |
3963 | + new_g = -new_g; | |
3964 | + } | |
3965 | + if (new_g != 0) { | |
3966 | + flt_g[j][i] = 1.0f/new_g; | |
3967 | + } else { | |
3968 | + flt_g[j][i] = 1.0f; | |
3969 | + } | |
3970 | + | |
3971 | + new_b = ((float)gdImageBlue(srcback, cpxl)) - ((float)gdImageBlue(srcback, pxl)); | |
3972 | + | |
3973 | + if (new_b < 0.0f) { | |
3974 | + new_b = -new_b; | |
3975 | + } | |
3976 | + if (new_b != 0) { | |
3977 | + flt_b[j][i] = 1.0f/new_b; | |
3978 | + } else { | |
3979 | + flt_b[j][i] = 1.0f; | |
3980 | + } | |
3981 | + } | |
3982 | + | |
3983 | + flt_r_sum += flt_r[j][i]; | |
3984 | + flt_g_sum += flt_g[j][i]; | |
3985 | + flt_b_sum += flt_b [j][i]; | |
3986 | + } | |
3987 | + } | |
3988 | + | |
3989 | + for (j=0; j<3; j++) { | |
3990 | + for (i=0; i<3; i++) { | |
3991 | + if (flt_r_sum != 0.0) { | |
3992 | + flt_r[j][i] /= flt_r_sum; | |
3993 | + } | |
3994 | + if (flt_g_sum != 0.0) { | |
3995 | + flt_g[j][i] /= flt_g_sum; | |
3996 | + } | |
3997 | + if (flt_b_sum != 0.0) { | |
3998 | + flt_b [j][i] /= flt_b_sum; | |
3999 | + } | |
4000 | + } | |
4001 | + } | |
4002 | + | |
4003 | + new_r = new_g = new_b = 0.0; | |
4004 | + | |
4005 | + for (j=0; j<3; j++) { | |
4006 | + for (i=0; i<3; i++) { | |
4007 | + pxl = f(src, x-(3>>1)+i, y-(3>>1)+j); | |
4008 | + new_r += (float)gdImageRed(srcback, pxl) * flt_r[j][i]; | |
4009 | + new_g += (float)gdImageGreen(srcback, pxl) * flt_g[j][i]; | |
4010 | + new_b += (float)gdImageBlue(srcback, pxl) * flt_b[j][i]; | |
4011 | + } | |
4012 | + } | |
4013 | + | |
4014 | + new_r = (new_r > 255.0f)? 255.0f : ((new_r < 0.0f)? 0.0f:new_r); | |
4015 | + new_g = (new_g > 255.0f)? 255.0f : ((new_g < 0.0f)? 0.0f:new_g); | |
4016 | + new_b = (new_b > 255.0f)? 255.0f : ((new_b < 0.0f)? 0.0f:new_b); | |
4017 | + new_pxl = gdImageColorAllocateAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a); | |
4018 | + if (new_pxl == -1) { | |
4019 | + new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a); | |
4020 | + } | |
4021 | + gdImageSetPixel (src, x, y, new_pxl); | |
4022 | + } | |
4023 | + } | |
4024 | + gdImageDestroy(srcback); | |
4025 | + return 1; | |
4026 | +} | |
4027 | + | |
4028 | +int gdImageEdgeDetectQuick(gdImagePtr src) | |
4029 | +{ | |
4030 | + float filter[3][3] = {{-1.0,0.0,-1.0}, | |
4031 | + {0.0,4.0,0.0}, | |
4032 | + {-1.0,0.0,-1.0}}; | |
4033 | + | |
4034 | + return gdImageConvolution(src, filter, 1, 127); | |
4035 | +} | |
4036 | + | |
4037 | +int gdImageGaussianBlur(gdImagePtr im) | |
4038 | +{ | |
4039 | + float filter[3][3] = {{1.0,2.0,1.0}, | |
4040 | + {2.0,4.0,2.0}, | |
4041 | + {1.0,2.0,1.0}}; | |
4042 | + | |
4043 | + return gdImageConvolution(im, filter, 16, 0); | |
4044 | +} | |
4045 | + | |
4046 | +int gdImageEmboss(gdImagePtr im) | |
4047 | +{ | |
4048 | +/* | |
4049 | + float filter[3][3] = {{1.0,1.0,1.0}, | |
4050 | + {0.0,0.0,0.0}, | |
4051 | + {-1.0,-1.0,-1.0}}; | |
4052 | +*/ | |
4053 | + float filter[3][3] = {{ 1.5, 0.0, 0.0}, | |
4054 | + { 0.0, 0.0, 0.0}, | |
4055 | + { 0.0, 0.0,-1.5}}; | |
4056 | + | |
4057 | + return gdImageConvolution(im, filter, 1, 127); | |
4058 | +} | |
4059 | + | |
4060 | +int gdImageMeanRemoval(gdImagePtr im) | |
4061 | +{ | |
4062 | + float filter[3][3] = {{-1.0,-1.0,-1.0}, | |
4063 | + {-1.0,9.0,-1.0}, | |
4064 | + {-1.0,-1.0,-1.0}}; | |
4065 | + | |
4066 | + return gdImageConvolution(im, filter, 1, 0); | |
4067 | +} | |
4068 | + | |
4069 | +int gdImageSmooth(gdImagePtr im, float weight) | |
4070 | +{ | |
4071 | + float filter[3][3] = {{1.0,1.0,1.0}, | |
4072 | + {1.0,0.0,1.0}, | |
4073 | + {1.0,1.0,1.0}}; | |
4074 | + | |
4075 | + filter[1][1] = weight; | |
4076 | + | |
4077 | + return gdImageConvolution(im, filter, weight+8, 0); | |
4078 | +} | |
4079 | +/* End filters function */ | |
4080 | diff -urN php-4.4.8.org/ext/gd/libgd/gdcache.c php-4.4.8/ext/gd/libgd/gdcache.c | |
4081 | --- php-4.4.8.org/ext/gd/libgd/gdcache.c 2003-04-05 19:24:16.000000000 +0200 | |
4082 | +++ php-4.4.8/ext/gd/libgd/gdcache.c 2003-12-28 21:11:08.000000000 +0100 | |
4083 | @@ -11,11 +11,11 @@ | |
4084 | ||
4085 | #ifdef NEED_CACHE | |
4086 | ||
4087 | -/* | |
4088 | +/* | |
4089 | * gdcache.c | |
4090 | * | |
4091 | - * Caches of pointers to user structs in which the least-recently-used | |
4092 | - * element is replaced in the event of a cache miss after the cache has | |
4093 | + * Caches of pointers to user structs in which the least-recently-used | |
4094 | + * element is replaced in the event of a cache miss after the cache has | |
4095 | * reached a given size. | |
4096 | * | |
4097 | * John Ellson (ellson@graphviz.org) Oct 31, 1997 | |
4098 | @@ -30,17 +30,17 @@ | |
4099 | * The head structure has a pointer to the most-recently-used | |
4100 | * element, and elements are moved to this position in the list each | |
4101 | * time they are used. The head also contains pointers to three | |
4102 | - * user defined functions: | |
4103 | - * - a function to test if a cached userdata matches some keydata | |
4104 | - * - a function to provide a new userdata struct to the cache | |
4105 | + * user defined functions: | |
4106 | + * - a function to test if a cached userdata matches some keydata | |
4107 | + * - a function to provide a new userdata struct to the cache | |
4108 | * if there has been a cache miss. | |
4109 | * - a function to release a userdata struct when it is | |
4110 | * no longer being managed by the cache | |
4111 | * | |
4112 | * In the event of a cache miss the cache is allowed to grow up to | |
4113 | * a specified maximum size. After the maximum size is reached then | |
4114 | - * the least-recently-used element is discarded to make room for the | |
4115 | - * new. The most-recently-returned value is always left at the | |
4116 | + * the least-recently-used element is discarded to make room for the | |
4117 | + * new. The most-recently-returned value is always left at the | |
4118 | * beginning of the list after retrieval. | |
4119 | * | |
4120 | * In the current implementation the cache is traversed by a linear | |
4121 | diff -urN php-4.4.8.org/ext/gd/libgd/gdcache.h php-4.4.8/ext/gd/libgd/gdcache.h | |
4122 | --- php-4.4.8.org/ext/gd/libgd/gdcache.h 2003-04-05 19:24:16.000000000 +0200 | |
4123 | +++ php-4.4.8/ext/gd/libgd/gdcache.h 2003-12-28 21:11:08.000000000 +0100 | |
4124 | @@ -1,8 +1,8 @@ | |
4125 | -/* | |
4126 | +/* | |
4127 | * gdcache.h | |
4128 | * | |
4129 | - * Caches of pointers to user structs in which the least-recently-used | |
4130 | - * element is replaced in the event of a cache miss after the cache has | |
4131 | + * Caches of pointers to user structs in which the least-recently-used | |
4132 | + * element is replaced in the event of a cache miss after the cache has | |
4133 | * reached a given size. | |
4134 | * | |
4135 | * John Ellson (ellson@graphviz.org) Oct 31, 1997 | |
4136 | @@ -17,17 +17,17 @@ | |
4137 | * The head structure has a pointer to the most-recently-used | |
4138 | * element, and elements are moved to this position in the list each | |
4139 | * time they are used. The head also contains pointers to three | |
4140 | - * user defined functions: | |
4141 | - * - a function to test if a cached userdata matches some keydata | |
4142 | - * - a function to provide a new userdata struct to the cache | |
4143 | + * user defined functions: | |
4144 | + * - a function to test if a cached userdata matches some keydata | |
4145 | + * - a function to provide a new userdata struct to the cache | |
4146 | * if there has been a cache miss. | |
4147 | * - a function to release a userdata struct when it is | |
4148 | * no longer being managed by the cache | |
4149 | * | |
4150 | * In the event of a cache miss the cache is allowed to grow up to | |
4151 | * a specified maximum size. After the maximum size is reached then | |
4152 | - * the least-recently-used element is discarded to make room for the | |
4153 | - * new. The most-recently-returned value is always left at the | |
4154 | + * the least-recently-used element is discarded to make room for the | |
4155 | + * new. The most-recently-returned value is always left at the | |
4156 | * beginning of the list after retrieval. | |
4157 | * | |
4158 | * In the current implementation the cache is traversed by a linear | |
4159 | diff -urN php-4.4.8.org/ext/gd/libgd/gdfontg.c php-4.4.8/ext/gd/libgd/gdfontg.c | |
4160 | --- php-4.4.8.org/ext/gd/libgd/gdfontg.c 2004-03-29 20:21:00.000000000 +0200 | |
4161 | +++ php-4.4.8/ext/gd/libgd/gdfontg.c 2006-09-16 21:07:45.000000000 +0200 | |
4162 | @@ -13,7 +13,7 @@ | |
4163 | ||
4164 | #include "gdfontg.h" | |
4165 | ||
4166 | -char gdFontGiantData[] = | |
4167 | +static const char gdFontGiantData[] = | |
4168 | { | |
4169 | /* Char 0 */ | |
4170 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
4171 | @@ -4376,7 +4376,7 @@ | |
4172 | 0, | |
4173 | 9, | |
4174 | 15, | |
4175 | - gdFontGiantData | |
4176 | + (char*)gdFontGiantData | |
4177 | }; | |
4178 | ||
4179 | gdFontPtr gdFontGiant = &gdFontGiantRep; | |
4180 | diff -urN php-4.4.8.org/ext/gd/libgd/gdfontl.c php-4.4.8/ext/gd/libgd/gdfontl.c | |
4181 | --- php-4.4.8.org/ext/gd/libgd/gdfontl.c 2004-03-29 20:21:00.000000000 +0200 | |
4182 | +++ php-4.4.8/ext/gd/libgd/gdfontl.c 2006-09-16 21:07:45.000000000 +0200 | |
4183 | @@ -14,7 +14,7 @@ | |
4184 | ||
4185 | #include "gdfontl.h" | |
4186 | ||
4187 | -char gdFontLargeData[] = | |
4188 | +static const char gdFontLargeData[] = | |
4189 | { | |
4190 | /* Char 0 */ | |
4191 | 0, 0, 0, 0, 0, 0, 0, 0, | |
4192 | @@ -4633,7 +4633,7 @@ | |
4193 | 0, | |
4194 | 8, | |
4195 | 16, | |
4196 | - gdFontLargeData | |
4197 | + (char*)gdFontLargeData | |
4198 | }; | |
4199 | ||
4200 | gdFontPtr gdFontLarge = &gdFontLargeRep; | |
4201 | diff -urN php-4.4.8.org/ext/gd/libgd/gdfontmb.c php-4.4.8/ext/gd/libgd/gdfontmb.c | |
4202 | --- php-4.4.8.org/ext/gd/libgd/gdfontmb.c 2004-03-29 20:21:00.000000000 +0200 | |
4203 | +++ php-4.4.8/ext/gd/libgd/gdfontmb.c 2006-09-16 21:07:46.000000000 +0200 | |
4204 | @@ -12,7 +12,7 @@ | |
4205 | ||
4206 | #include "gdfontmb.h" | |
4207 | ||
4208 | -char gdFontMediumBoldData[] = | |
4209 | +static const char gdFontMediumBoldData[] = | |
4210 | { | |
4211 | /* Char 0 */ | |
4212 | 0, 0, 0, 0, 0, 0, 0, | |
4213 | @@ -3863,7 +3863,7 @@ | |
4214 | 0, | |
4215 | 7, | |
4216 | 13, | |
4217 | - gdFontMediumBoldData | |
4218 | + (char*)gdFontMediumBoldData | |
4219 | }; | |
4220 | ||
4221 | gdFontPtr gdFontMediumBold = &gdFontMediumBoldRep; | |
4222 | diff -urN php-4.4.8.org/ext/gd/libgd/gdfonts.c php-4.4.8/ext/gd/libgd/gdfonts.c | |
4223 | --- php-4.4.8.org/ext/gd/libgd/gdfonts.c 2004-03-29 20:21:00.000000000 +0200 | |
4224 | +++ php-4.4.8/ext/gd/libgd/gdfonts.c 2006-09-16 21:07:46.000000000 +0200 | |
4225 | @@ -12,7 +12,7 @@ | |
4226 | ||
4227 | #include "gdfonts.h" | |
4228 | ||
4229 | -char gdFontSmallData[] = | |
4230 | +static const char gdFontSmallData[] = | |
4231 | { | |
4232 | /* Char 0 */ | |
4233 | 0, 0, 0, 0, 0, 0, | |
4234 | @@ -3863,7 +3863,7 @@ | |
4235 | 0, | |
4236 | 6, | |
4237 | 13, | |
4238 | - gdFontSmallData | |
4239 | + (char*)gdFontSmallData | |
4240 | }; | |
4241 | ||
4242 | gdFontPtr gdFontSmall = &gdFontSmallRep; | |
4243 | diff -urN php-4.4.8.org/ext/gd/libgd/gdfontt.c php-4.4.8/ext/gd/libgd/gdfontt.c | |
4244 | --- php-4.4.8.org/ext/gd/libgd/gdfontt.c 2004-03-29 20:21:00.000000000 +0200 | |
4245 | +++ php-4.4.8/ext/gd/libgd/gdfontt.c 2006-09-16 21:07:46.000000000 +0200 | |
4246 | @@ -13,7 +13,7 @@ | |
4247 | ||
4248 | #include "gdfontt.h" | |
4249 | ||
4250 | -char gdFontTinyData[] = | |
4251 | +static const char gdFontTinyData[] = | |
4252 | { | |
4253 | /* Char 0 */ | |
4254 | 0, 0, 0, 0, 0, | |
4255 | @@ -2584,7 +2584,7 @@ | |
4256 | 0, | |
4257 | 5, | |
4258 | 8, | |
4259 | - gdFontTinyData | |
4260 | + (char*)gdFontTinyData | |
4261 | }; | |
4262 | ||
4263 | gdFontPtr gdFontTiny = &gdFontTinyRep; | |
4264 | diff -urN php-4.4.8.org/ext/gd/libgd/gdft.c php-4.4.8/ext/gd/libgd/gdft.c | |
4265 | --- php-4.4.8.org/ext/gd/libgd/gdft.c 2007-03-10 13:51:07.000000000 +0100 | |
4266 | +++ php-4.4.8/ext/gd/libgd/gdft.c 2007-04-23 17:17:47.000000000 +0200 | |
4267 | @@ -16,7 +16,9 @@ | |
4268 | #include <unistd.h> | |
4269 | #else | |
4270 | #include <io.h> | |
4271 | -#define R_OK 04 /* Needed in Windows */ | |
4272 | +#ifndef R_OK | |
4273 | +# define R_OK 04 /* Needed in Windows */ | |
4274 | +#endif | |
4275 | #endif | |
4276 | ||
4277 | #ifdef WIN32 | |
4278 | @@ -37,9 +39,8 @@ | |
4279 | gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist, | |
4280 | double ptsize, double angle, int x, int y, char *string) | |
4281 | { | |
4282 | - /* 2.0.6: valid return */ | |
4283 | - return gdImageStringFT (im, brect, fg, fontlist, ptsize, | |
4284 | - angle, x, y, string); | |
4285 | + /* 2.0.6: valid return */ | |
4286 | + return gdImageStringFT (im, brect, fg, fontlist, ptsize, angle, x, y, string); | |
4287 | } | |
4288 | ||
4289 | #ifndef HAVE_LIBFREETYPE | |
4290 | @@ -48,14 +49,14 @@ | |
4291 | double ptsize, double angle, int x, int y, char *string, | |
4292 | gdFTStringExtraPtr strex) | |
4293 | { | |
4294 | - return "libgd was not built with FreeType font support\n"; | |
4295 | + return "libgd was not built with FreeType font support\n"; | |
4296 | } | |
4297 | ||
4298 | char * | |
4299 | gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, | |
4300 | double ptsize, double angle, int x, int y, char *string) | |
4301 | { | |
4302 | - return "libgd was not built with FreeType font support\n"; | |
4303 | + return "libgd was not built with FreeType font support\n"; | |
4304 | } | |
4305 | #else | |
4306 | ||
4307 | @@ -71,8 +72,8 @@ | |
4308 | #define TWEENCOLORCACHESIZE 32 | |
4309 | ||
4310 | /* | |
4311 | - * Line separation as a factor of font height. | |
4312 | - * No space between if LINESPACE = 1.00 | |
4313 | + * Line separation as a factor of font height. | |
4314 | + * No space between if LINESPACE = 1.00 | |
4315 | * Line separation will be rounded up to next pixel row. | |
4316 | */ | |
4317 | #define LINESPACE 1.05 | |
4318 | @@ -115,40 +116,35 @@ | |
4319 | ||
4320 | typedef struct | |
4321 | { | |
4322 | - char *fontlist; /* key */ | |
4323 | - FT_Library *library; | |
4324 | - FT_Face face; | |
4325 | - FT_Bool have_char_map_unicode, have_char_map_big5, have_char_map_sjis, | |
4326 | - have_char_map_apple_roman; | |
4327 | - gdCache_head_t *glyphCache; | |
4328 | -} | |
4329 | -font_t; | |
4330 | + char *fontlist; /* key */ | |
4331 | + FT_Library *library; | |
4332 | + FT_Face face; | |
4333 | + FT_Bool have_char_map_unicode, have_char_map_big5, have_char_map_sjis, have_char_map_apple_roman; | |
4334 | + gdCache_head_t *glyphCache; | |
4335 | +} font_t; | |
4336 | ||
4337 | typedef struct | |
4338 | - { | |
4339 | - char *fontlist; /* key */ | |
4340 | - FT_Library *library; | |
4341 | - } | |
4342 | -fontkey_t; | |
4343 | +{ | |
4344 | + char *fontlist; /* key */ | |
4345 | + FT_Library *library; | |
4346 | +} fontkey_t; | |
4347 | ||
4348 | typedef struct | |
4349 | - { | |
4350 | - int pixel; /* key */ | |
4351 | - int bgcolor; /* key */ | |
4352 | - int fgcolor; /* key *//* -ve means no antialias */ | |
4353 | - gdImagePtr im; /* key */ | |
4354 | - int tweencolor; | |
4355 | - } | |
4356 | -tweencolor_t; | |
4357 | +{ | |
4358 | + int pixel; /* key */ | |
4359 | + int bgcolor; /* key */ | |
4360 | + int fgcolor; /* key *//* -ve means no antialias */ | |
4361 | + gdImagePtr im; /* key */ | |
4362 | + int tweencolor; | |
4363 | +} tweencolor_t; | |
4364 | ||
4365 | typedef struct | |
4366 | - { | |
4367 | - int pixel; /* key */ | |
4368 | - int bgcolor; /* key */ | |
4369 | - int fgcolor; /* key *//* -ve means no antialias */ | |
4370 | - gdImagePtr im; /* key */ | |
4371 | - } | |
4372 | -tweencolorkey_t; | |
4373 | +{ | |
4374 | + int pixel; /* key */ | |
4375 | + int bgcolor; /* key */ | |
4376 | + int fgcolor; /* key *//* -ve means no antialias */ | |
4377 | + gdImagePtr im; /* key */ | |
4378 | +} tweencolorkey_t; | |
4379 | ||
4380 | /******************************************************************** | |
4381 | * gdTcl_UtfToUniChar is borrowed from Tcl ... | |
4382 | @@ -208,160 +204,141 @@ | |
4383 | ||
4384 | #define Tcl_UniChar int | |
4385 | #define TCL_UTF_MAX 3 | |
4386 | -static int | |
4387 | -gdTcl_UtfToUniChar (char *str, Tcl_UniChar * chPtr) | |
4388 | +static int gdTcl_UtfToUniChar (char *str, Tcl_UniChar * chPtr) | |
4389 | /* str is the UTF8 next character pointer */ | |
4390 | /* chPtr is the int for the result */ | |
4391 | { | |
4392 | - int byte; | |
4393 | + int byte; | |
4394 | + | |
4395 | + /* HTML4.0 entities in decimal form, e.g. Å */ | |
4396 | + byte = *((unsigned char *) str); | |
4397 | + if (byte == '&') { | |
4398 | + int i, n = 0; | |
4399 | + | |
4400 | + byte = *((unsigned char *) (str + 1)); | |
4401 | + if (byte == '#') { | |
4402 | + byte = *((unsigned char *) (str + 2)); | |
4403 | + if (byte == 'x' || byte == 'X') { | |
4404 | + for (i = 3; i < 8; i++) { | |
4405 | + byte = *((unsigned char *) (str + i)); | |
4406 | + if (byte >= 'A' && byte <= 'F') | |
4407 | + byte = byte - 'A' + 10; | |
4408 | + else if (byte >= 'a' && byte <= 'f') | |
4409 | + byte = byte - 'a' + 10; | |
4410 | + else if (byte >= '0' && byte <= '9') | |
4411 | + byte = byte - '0'; | |
4412 | + else | |
4413 | + break; | |
4414 | + n = (n * 16) + byte; | |
4415 | + } | |
4416 | + } else { | |
4417 | + for (i = 2; i < 8; i++) { | |
4418 | + byte = *((unsigned char *) (str + i)); | |
4419 | + if (byte >= '0' && byte <= '9') { | |
4420 | + n = (n * 10) + (byte - '0'); | |
4421 | + } else { | |
4422 | + break; | |
4423 | + } | |
4424 | + } | |
4425 | + } | |
4426 | + if (byte == ';') { | |
4427 | + *chPtr = (Tcl_UniChar) n; | |
4428 | + return ++i; | |
4429 | + } | |
4430 | + } | |
4431 | + } | |
4432 | ||
4433 | - /* HTML4.0 entities in decimal form, e.g. Å */ | |
4434 | - byte = *((unsigned char *) str); | |
4435 | - if (byte == '&') | |
4436 | - { | |
4437 | - int i, n = 0; | |
4438 | - | |
4439 | - byte = *((unsigned char *) (str + 1)); | |
4440 | - if (byte == '#') | |
4441 | - { | |
4442 | - for (i = 2; i < 8; i++) | |
4443 | - { | |
4444 | - byte = *((unsigned char *) (str + i)); | |
4445 | - if (byte >= '0' && byte <= '9') | |
4446 | - { | |
4447 | - n = (n * 10) + (byte - '0'); | |
4448 | - } | |
4449 | - else | |
4450 | - break; | |
4451 | - } | |
4452 | - if (byte == ';') | |
4453 | - { | |
4454 | - *chPtr = (Tcl_UniChar) n; | |
4455 | - return ++i; | |
4456 | - } | |
4457 | - } | |
4458 | - } | |
4459 | - | |
4460 | - /* | |
4461 | - * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. | |
4462 | - */ | |
4463 | + /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */ | |
4464 | ||
4465 | - byte = *((unsigned char *) str); | |
4466 | + byte = *((unsigned char *) str); | |
4467 | #ifdef JISX0208 | |
4468 | - if (0xA1 <= byte && byte <= 0xFE) | |
4469 | - { | |
4470 | - int ku, ten; | |
4471 | - | |
4472 | - ku = (byte & 0x7F) - 0x20; | |
4473 | - ten = (str[1] & 0x7F) - 0x20; | |
4474 | - if ((ku < 1 || ku > 92) || (ten < 1 || ten > 94)) | |
4475 | - { | |
4476 | - *chPtr = (Tcl_UniChar) byte; | |
4477 | - return 1; | |
4478 | - } | |
4479 | - | |
4480 | - *chPtr = (Tcl_UniChar) UnicodeTbl[ku - 1][ten - 1]; | |
4481 | - return 2; | |
4482 | - } | |
4483 | - else | |
4484 | + if (0xA1 <= byte && byte <= 0xFE) { | |
4485 | + int ku, ten; | |
4486 | + | |
4487 | + ku = (byte & 0x7F) - 0x20; | |
4488 | + ten = (str[1] & 0x7F) - 0x20; | |
4489 | + if ((ku < 1 || ku > 92) || (ten < 1 || ten > 94)) { | |
4490 | + *chPtr = (Tcl_UniChar) byte; | |
4491 | + return 1; | |
4492 | + } | |
4493 | + | |
4494 | + *chPtr = (Tcl_UniChar) UnicodeTbl[ku - 1][ten - 1]; | |
4495 | + return 2; | |
4496 | + } else | |
4497 | #endif /* JISX0208 */ | |
4498 | - if (byte < 0xC0) | |
4499 | - { | |
4500 | - /* | |
4501 | - * Handles properly formed UTF-8 characters between | |
4502 | - * 0x01 and 0x7F. Also treats \0 and naked trail | |
4503 | - * bytes 0x80 to 0xBF as valid characters representing | |
4504 | - * themselves. | |
4505 | - */ | |
4506 | - | |
4507 | - *chPtr = (Tcl_UniChar) byte; | |
4508 | - return 1; | |
4509 | - } | |
4510 | - else if (byte < 0xE0) | |
4511 | - { | |
4512 | - if ((str[1] & 0xC0) == 0x80) | |
4513 | - { | |
4514 | - /* | |
4515 | - * Two-byte-character lead-byte followed | |
4516 | - * by a trail-byte. | |
4517 | - */ | |
4518 | - | |
4519 | - *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | |
4520 | - | (str[1] & 0x3F)); | |
4521 | - return 2; | |
4522 | - } | |
4523 | - /* | |
4524 | - * A two-byte-character lead-byte not followed by trail-byte | |
4525 | - * represents itself. | |
4526 | - */ | |
4527 | - | |
4528 | - *chPtr = (Tcl_UniChar) byte; | |
4529 | - return 1; | |
4530 | - } | |
4531 | - else if (byte < 0xF0) | |
4532 | - { | |
4533 | - if (((str[1] & 0xC0) == 0x80) && ((str[2] & 0xC0) == 0x80)) | |
4534 | - { | |
4535 | - /* | |
4536 | - * Three-byte-character lead byte followed by | |
4537 | - * two trail bytes. | |
4538 | - */ | |
4539 | - | |
4540 | - *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | |
4541 | - | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F)); | |
4542 | - return 3; | |
4543 | - } | |
4544 | - /* | |
4545 | - * A three-byte-character lead-byte not followed by | |
4546 | - * two trail-bytes represents itself. | |
4547 | - */ | |
4548 | - | |
4549 | - *chPtr = (Tcl_UniChar) byte; | |
4550 | - return 1; | |
4551 | - } | |
4552 | + if (byte < 0xC0) { | |
4553 | + /* Handles properly formed UTF-8 characters between | |
4554 | + * 0x01 and 0x7F. Also treats \0 and naked trail | |
4555 | + * bytes 0x80 to 0xBF as valid characters representing | |
4556 | + * themselves. | |
4557 | + */ | |
4558 | + | |
4559 | + *chPtr = (Tcl_UniChar) byte; | |
4560 | + return 1; | |
4561 | + } else if (byte < 0xE0) { | |
4562 | + if ((str[1] & 0xC0) == 0x80) { | |
4563 | + /* Two-byte-character lead-byte followed by a trail-byte. */ | |
4564 | + | |
4565 | + *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (str[1] & 0x3F)); | |
4566 | + return 2; | |
4567 | + } | |
4568 | + /* | |
4569 | + * A two-byte-character lead-byte not followed by trail-byte | |
4570 | + * represents itself. | |
4571 | + */ | |
4572 | + | |
4573 | + *chPtr = (Tcl_UniChar) byte; | |
4574 | + return 1; | |
4575 | + } else if (byte < 0xF0) { | |
4576 | + if (((str[1] & 0xC0) == 0x80) && ((str[2] & 0xC0) == 0x80)) { | |
4577 | + /* Three-byte-character lead byte followed by two trail bytes. */ | |
4578 | + | |
4579 | + *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F)); | |
4580 | + return 3; | |
4581 | + } | |
4582 | + /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */ | |
4583 | + | |
4584 | + *chPtr = (Tcl_UniChar) byte; | |
4585 | + return 1; | |
4586 | + } | |
4587 | #if TCL_UTF_MAX > 3 | |
4588 | - else | |
4589 | - { | |
4590 | - int ch, total, trail; | |
4591 | - | |
4592 | - total = totalBytes[byte]; | |
4593 | - trail = total - 1; | |
4594 | - if (trail > 0) | |
4595 | - { | |
4596 | - ch = byte & (0x3F >> trail); | |
4597 | - do | |
4598 | - { | |
4599 | - str++; | |
4600 | - if ((*str & 0xC0) != 0x80) | |
4601 | - { | |
4602 | - *chPtr = byte; | |
4603 | - return 1; | |
4604 | - } | |
4605 | - ch <<= 6; | |
4606 | - ch |= (*str & 0x3F); | |
4607 | - trail--; | |
4608 | - } | |
4609 | - while (trail > 0); | |
4610 | - *chPtr = ch; | |
4611 | - return total; | |
4612 | + else { | |
4613 | + int ch, total, trail; | |
4614 | + | |
4615 | + total = totalBytes[byte]; | |
4616 | + trail = total - 1; | |
4617 | + | |
4618 | + if (trail > 0) { | |
4619 | + ch = byte & (0x3F >> trail); | |
4620 | + do { | |
4621 | + str++; | |
4622 | + if ((*str & 0xC0) != 0x80) { | |
4623 | + *chPtr = byte; | |
4624 | + return 1; | |
4625 | + } | |
4626 | + ch <<= 6; | |
4627 | + ch |= (*str & 0x3F); | |
4628 | + trail--; | |
4629 | + } while (trail > 0); | |
4630 | + *chPtr = ch; | |
4631 | + return total; | |
4632 | + } | |
4633 | } | |
4634 | - } | |
4635 | #endif | |
4636 | ||
4637 | - *chPtr = (Tcl_UniChar) byte; | |
4638 | - return 1; | |
4639 | + *chPtr = (Tcl_UniChar) byte; | |
4640 | + return 1; | |
4641 | } | |
4642 | ||
4643 | /********************************************************************/ | |
4644 | /* font cache functions */ | |
4645 | ||
4646 | -static int | |
4647 | -fontTest (void *element, void *key) | |
4648 | +static int fontTest (void *element, void *key) | |
4649 | { | |
4650 | - font_t *a = (font_t *) element; | |
4651 | - fontkey_t *b = (fontkey_t *) key; | |
4652 | + font_t *a = (font_t *) element; | |
4653 | + fontkey_t *b = (fontkey_t *) key; | |
4654 | ||
4655 | - return (strcmp (a->fontlist, b->fontlist) == 0); | |
4656 | + return (strcmp (a->fontlist, b->fontlist) == 0); | |
4657 | } | |
4658 | ||
4659 | static void *fontFetch (char **error, void *key) | |
4660 | @@ -389,7 +366,7 @@ | |
4661 | fontsearchpath = getenv ("GDFONTPATH"); | |
4662 | if (!fontsearchpath) { | |
4663 | fontsearchpath = DEFAULT_FONTPATH; | |
4664 | - } | |
4665 | + } | |
4666 | fontlist = gdEstrdup(a->fontlist); | |
4667 | ||
4668 | /* | |
4669 | @@ -399,8 +376,12 @@ | |
4670 | /* make a fresh copy each time - strtok corrupts it. */ | |
4671 | path = gdEstrdup (fontsearchpath); | |
4672 | ||
4673 | - /* if name is an absolute filename then test directly */ | |
4674 | + /* if name is an absolute filename then test directly */ | |
4675 | +#ifdef NETWARE | |
4676 | + if (*name == '/' || (name[0] != 0 && strstr(name, ":/"))) { | |
4677 | +#else | |
4678 | if (*name == '/' || (name[0] != 0 && name[1] == ':' && (name[2] == '/' || name[2] == '\\'))) { | |
4679 | +#endif | |
4680 | snprintf(fullname, sizeof(fullname) - 1, "%s", name); | |
4681 | if (access(fullname, R_OK) == 0) { | |
4682 | font_found++; | |
4683 | @@ -437,15 +418,15 @@ | |
4684 | path = NULL; | |
4685 | if (font_found) { | |
4686 | break; | |
4687 | - } | |
4688 | + } | |
4689 | } | |
4690 | - | |
4691 | + | |
4692 | if (path) { | |
4693 | gdFree(path); | |
4694 | } | |
4695 | - | |
4696 | + | |
4697 | gdFree(fontlist); | |
4698 | - | |
4699 | + | |
4700 | if (!font_found) { | |
4701 | gdPFree(a->fontlist); | |
4702 | gdPFree(a); | |
4703 | @@ -556,257 +537,234 @@ | |
4704 | * does the work so that text can be alpha blended across a complex | |
4705 | * background (TBB; and for real in 2.0.2). | |
4706 | */ | |
4707 | -static void * | |
4708 | -tweenColorFetch (char **error, void *key) | |
4709 | +static void * tweenColorFetch (char **error, void *key) | |
4710 | { | |
4711 | - tweencolor_t *a; | |
4712 | - tweencolorkey_t *b = (tweencolorkey_t *) key; | |
4713 | - int pixel, npixel, bg, fg; | |
4714 | - gdImagePtr im; | |
4715 | - | |
4716 | - a = (tweencolor_t *) gdMalloc (sizeof (tweencolor_t)); | |
4717 | - pixel = a->pixel = b->pixel; | |
4718 | - bg = a->bgcolor = b->bgcolor; | |
4719 | - fg = a->fgcolor = b->fgcolor; | |
4720 | - im = b->im; | |
4721 | - | |
4722 | - /* if fg is specified by a negative color idx, then don't antialias */ | |
4723 | - if (fg < 0) | |
4724 | - { | |
4725 | - if ((pixel + pixel) >= NUMCOLORS) | |
4726 | - a->tweencolor = -fg; | |
4727 | - else | |
4728 | - a->tweencolor = bg; | |
4729 | - } | |
4730 | - else | |
4731 | - { | |
4732 | - npixel = NUMCOLORS - pixel; | |
4733 | - if (im->trueColor) | |
4734 | - { | |
4735 | - /* 2.0.1: use gdImageSetPixel to do the alpha blending work, | |
4736 | - or to just store the alpha level. All we have to do here | |
4737 | - is incorporate our knowledge of the percentage of this | |
4738 | - pixel that is really "lit" by pushing the alpha value | |
4739 | - up toward transparency in edge regions. */ | |
4740 | - a->tweencolor = gdTrueColorAlpha ( | |
4741 | - gdTrueColorGetRed (fg), | |
4742 | - gdTrueColorGetGreen (fg), | |
4743 | - gdTrueColorGetBlue (fg), | |
4744 | - gdAlphaMax - (gdTrueColorGetAlpha (fg) * pixel / NUMCOLORS)); | |
4745 | - } | |
4746 | - else | |
4747 | - { | |
4748 | - a->tweencolor = gdImageColorResolve (im, | |
4749 | - (pixel * im->red[fg] + npixel * im->red[bg]) / NUMCOLORS, | |
4750 | - (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS, | |
4751 | - (pixel * im->blue[fg] + npixel * im->blue[bg]) / NUMCOLORS); | |
4752 | - } | |
4753 | - } | |
4754 | - return (void *) a; | |
4755 | + tweencolor_t *a; | |
4756 | + tweencolorkey_t *b = (tweencolorkey_t *) key; | |
4757 | + int pixel, npixel, bg, fg; | |
4758 | + gdImagePtr im; | |
4759 | + | |
4760 | + a = (tweencolor_t *) gdMalloc (sizeof (tweencolor_t)); | |
4761 | + pixel = a->pixel = b->pixel; | |
4762 | + bg = a->bgcolor = b->bgcolor; | |
4763 | + fg = a->fgcolor = b->fgcolor; | |
4764 | + im = a->im = b->im; | |
4765 | + | |
4766 | + /* if fg is specified by a negative color idx, then don't antialias */ | |
4767 | + if (fg < 0) { | |
4768 | + if ((pixel + pixel) >= NUMCOLORS) { | |
4769 | + a->tweencolor = -fg; | |
4770 | + } else { | |
4771 | + a->tweencolor = bg; | |
4772 | + } | |
4773 | + } else { | |
4774 | + npixel = NUMCOLORS - pixel; | |
4775 | + if (im->trueColor) { | |
4776 | + /* 2.0.1: use gdImageSetPixel to do the alpha blending work, | |
4777 | + * or to just store the alpha level. All we have to do here | |
4778 | + * is incorporate our knowledge of the percentage of this | |
4779 | + * pixel that is really "lit" by pushing the alpha value | |
4780 | + * up toward transparency in edge regions. | |
4781 | + */ | |
4782 | + a->tweencolor = gdTrueColorAlpha( | |
4783 | + gdTrueColorGetRed(fg), | |
4784 | + gdTrueColorGetGreen(fg), | |
4785 | + gdTrueColorGetBlue(fg), | |
4786 | + gdAlphaMax - (gdTrueColorGetAlpha (fg) * pixel / NUMCOLORS)); | |
4787 | + } else { | |
4788 | + a->tweencolor = gdImageColorResolve(im, | |
4789 | + (pixel * im->red[fg] + npixel * im->red[bg]) / NUMCOLORS, | |
4790 | + (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS, | |
4791 | + (pixel * im->blue[fg] + npixel * im->blue[bg]) / NUMCOLORS); | |
4792 | + } | |
4793 | + } | |
4794 | + return (void *) a; | |
4795 | } | |
4796 | ||
4797 | -static void | |
4798 | -tweenColorRelease (void *element) | |
4799 | +static void tweenColorRelease (void *element) | |
4800 | { | |
4801 | - gdFree ((char *) element); | |
4802 | + gdFree((char *) element); | |
4803 | } | |
4804 | ||
4805 | /* draw_bitmap - transfers glyph bitmap to GD image */ | |
4806 | -static char * | |
4807 | -gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y) | |
4808 | +static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y) | |
4809 | { | |
4810 | - unsigned char *pixel = NULL; | |
4811 | - int *tpixel = NULL; | |
4812 | - int x, y, row, col, pc, pcr; | |
4813 | - | |
4814 | - tweencolor_t *tc_elem; | |
4815 | - tweencolorkey_t tc_key; | |
4816 | - | |
4817 | - /* copy to image, mapping colors */ | |
4818 | - tc_key.fgcolor = fg; | |
4819 | - tc_key.im = im; | |
4820 | - /* Truecolor version; does not require the cache */ | |
4821 | - if (im->trueColor) | |
4822 | - { | |
4823 | - for (row = 0; row < bitmap.rows; row++) | |
4824 | - { | |
4825 | - pc = row * bitmap.pitch; | |
4826 | - pcr = pc; | |
4827 | - y = pen_y + row; | |
4828 | - /* clip if out of bounds */ | |
4829 | - /* 2.0.16: clipping rectangle, not image bounds */ | |
4830 | - if ((y > im->cy2) || (y < im->cy1)) | |
4831 | - continue; | |
4832 | - for (col = 0; col < bitmap.width; col++, pc++) | |
4833 | - { | |
4834 | - int level; | |
4835 | - if (bitmap.pixel_mode == ft_pixel_mode_grays) | |
4836 | - { | |
4837 | - /* | |
4838 | - * Scale to 128 levels of alpha for gd use. | |
4839 | - * alpha 0 is opacity, so be sure to invert at the end | |
4840 | - */ | |
4841 | - level = (bitmap.buffer[pc] * gdAlphaMax / | |
4842 | - (bitmap.num_grays - 1)); | |
4843 | - } | |
4844 | - else if (bitmap.pixel_mode == ft_pixel_mode_mono) | |
4845 | - { | |
4846 | - /* 2.0.5: mode_mono fix from Giuliano Pochini */ | |
4847 | - level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) | |
4848 | - ? gdAlphaTransparent : | |
4849 | - gdAlphaOpaque; | |
4850 | - } | |
4851 | - else | |
4852 | - { | |
4853 | - return "Unsupported ft_pixel_mode"; | |
4854 | - } | |
4855 | - if ((fg >= 0) && (im->trueColor)) { | |
4856 | - /* Consider alpha in the foreground color itself to be an | |
4857 | - upper bound on how opaque things get, when truecolor is | |
4858 | - available. Without truecolor this results in far too many | |
4859 | - color indexes. */ | |
4860 | - level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax; | |
4861 | - } | |
4862 | - level = gdAlphaMax - level; | |
4863 | - x = pen_x + col; | |
4864 | - /* clip if out of bounds */ | |
4865 | - /* 2.0.16: clip to clipping rectangle, Matt McNabb */ | |
4866 | - if ((x > im->cx2) || (x < im->cx1)) | |
4867 | - continue; | |
4868 | - /* get pixel location in gd buffer */ | |
4869 | - tpixel = &im->tpixels[y][x]; | |
4870 | - if (fg < 0) { | |
4871 | - if (level < (gdAlphaMax / 2)) { | |
4872 | - *tpixel = -fg; | |
4873 | - } | |
4874 | - } else { | |
4875 | - if (im->alphaBlendingFlag) { | |
4876 | - *tpixel = gdAlphaBlend(*tpixel, (level << 24) + (fg & 0xFFFFFF)); | |
4877 | - } else { | |
4878 | - *tpixel = (level << 24) + (fg & 0xFFFFFF); | |
4879 | - } | |
4880 | - } | |
4881 | - } | |
4882 | - } | |
4883 | - return (char *) NULL; | |
4884 | - } | |
4885 | - /* Non-truecolor case, restored to its more or less original form */ | |
4886 | - for (row = 0; row < bitmap.rows; row++) | |
4887 | - { | |
4888 | - int pcr; | |
4889 | - pc = row * bitmap.pitch; | |
4890 | - pcr = pc; | |
4891 | - if(bitmap.pixel_mode==ft_pixel_mode_mono) | |
4892 | - pc *= 8; /* pc is measured in bits for monochrome images */ | |
4893 | - | |
4894 | - y = pen_y + row; | |
4895 | - | |
4896 | - /* clip if out of bounds */ | |
4897 | - if (y >= im->sy || y < 0) | |
4898 | - continue; | |
4899 | - | |
4900 | - for (col = 0; col < bitmap.width; col++, pc++) | |
4901 | - { | |
4902 | - if (bitmap.pixel_mode == ft_pixel_mode_grays) | |
4903 | - { | |
4904 | - /* | |
4905 | - * Round to NUMCOLORS levels of antialiasing for | |
4906 | - * index color images since only 256 colors are | |
4907 | - * available. | |
4908 | - */ | |
4909 | - tc_key.pixel = ((bitmap.buffer[pc] * NUMCOLORS) | |
4910 | - + bitmap.num_grays / 2) | |
4911 | - / (bitmap.num_grays - 1); | |
4912 | - } | |
4913 | - else if (bitmap.pixel_mode == ft_pixel_mode_mono) | |
4914 | - { | |
4915 | - tc_key.pixel = ((bitmap.buffer[pc / 8] | |
4916 | - << (pc % 8)) & 128) ? NUMCOLORS : 0; | |
4917 | - /* 2.0.5: mode_mono fix from Giuliano Pochini */ | |
4918 | - tc_key.pixel = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) | |
4919 | - ? NUMCOLORS : 0; | |
4920 | - } | |
4921 | - else | |
4922 | - { | |
4923 | - return "Unsupported ft_pixel_mode"; | |
4924 | - } | |
4925 | - if (tc_key.pixel > 0) /* if not background */ | |
4926 | - { | |
4927 | - x = pen_x + col; | |
4928 | - | |
4929 | - /* clip if out of bounds */ | |
4930 | - if (x >= im->sx || x < 0) | |
4931 | - continue; | |
4932 | - /* get pixel location in gd buffer */ | |
4933 | - pixel = &im->pixels[y][x]; | |
4934 | - if (tc_key.pixel == NUMCOLORS) | |
4935 | - { | |
4936 | - /* use fg color directly. gd 2.0.2: watch out for | |
4937 | - negative indexes (thanks to David Marwood). */ | |
4938 | - *pixel = (fg < 0) ? -fg : fg; | |
4939 | - } | |
4940 | - else | |
4941 | - { | |
4942 | - /* find antialised color */ | |
4943 | - | |
4944 | - tc_key.bgcolor = *pixel; | |
4945 | - gdMutexLock(gdFontCacheMutex); | |
4946 | - tc_elem = (tweencolor_t *) gdCacheGet (tc_cache, &tc_key); | |
4947 | - *pixel = tc_elem->tweencolor; | |
4948 | - gdMutexUnlock(gdFontCacheMutex); | |
4949 | + unsigned char *pixel = NULL; | |
4950 | + int *tpixel = NULL; | |
4951 | + int x, y, row, col, pc, pcr; | |
4952 | + | |
4953 | + tweencolor_t *tc_elem; | |
4954 | + tweencolorkey_t tc_key; | |
4955 | + | |
4956 | + /* copy to image, mapping colors */ | |
4957 | + tc_key.fgcolor = fg; | |
4958 | + tc_key.im = im; | |
4959 | + /* Truecolor version; does not require the cache */ | |
4960 | + if (im->trueColor) { | |
4961 | + for (row = 0; row < bitmap.rows; row++) { | |
4962 | + pc = row * bitmap.pitch; | |
4963 | + pcr = pc; | |
4964 | + y = pen_y + row; | |
4965 | + /* clip if out of bounds */ | |
4966 | + /* 2.0.16: clipping rectangle, not image bounds */ | |
4967 | + if ((y > im->cy2) || (y < im->cy1)) { | |
4968 | + continue; | |
4969 | + } | |
4970 | + for (col = 0; col < bitmap.width; col++, pc++) { | |
4971 | + int level; | |
4972 | + if (bitmap.pixel_mode == ft_pixel_mode_grays) { | |
4973 | + /* Scale to 128 levels of alpha for gd use. | |
4974 | + * alpha 0 is opacity, so be sure to invert at the end | |
4975 | + */ | |
4976 | + level = (bitmap.buffer[pc] * gdAlphaMax / (bitmap.num_grays - 1)); | |
4977 | + } else if (bitmap.pixel_mode == ft_pixel_mode_mono) { | |
4978 | + /* 2.0.5: mode_mono fix from Giuliano Pochini */ | |
4979 | + level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) ? gdAlphaTransparent : gdAlphaOpaque; | |
4980 | + } else { | |
4981 | + return "Unsupported ft_pixel_mode"; | |
4982 | + } | |
4983 | + if ((fg >= 0) && (im->trueColor)) { | |
4984 | + /* Consider alpha in the foreground color itself to be an | |
4985 | + * upper bound on how opaque things get, when truecolor is | |
4986 | + * available. Without truecolor this results in far too many | |
4987 | + * color indexes. | |
4988 | + */ | |
4989 | + level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax; | |
4990 | + } | |
4991 | + level = gdAlphaMax - level; | |
4992 | + x = pen_x + col; | |
4993 | + /* clip if out of bounds */ | |
4994 | + /* 2.0.16: clip to clipping rectangle, Matt McNabb */ | |
4995 | + if ((x > im->cx2) || (x < im->cx1)) { | |
4996 | + continue; | |
4997 | + } | |
4998 | + /* get pixel location in gd buffer */ | |
4999 | + tpixel = &im->tpixels[y][x]; | |
5000 | + if (fg < 0) { | |
5001 | + if (level < (gdAlphaMax / 2)) { | |
5002 | + *tpixel = -fg; | |
5003 | + } | |
5004 | + } else { | |
5005 | + if (im->alphaBlendingFlag) { | |
5006 | + *tpixel = gdAlphaBlend(*tpixel, (level << 24) + (fg & 0xFFFFFF)); | |
5007 | + } else { | |
5008 | + *tpixel = (level << 24) + (fg & 0xFFFFFF); | |
5009 | + } | |
5010 | + } | |
5011 | + } | |
5012 | + } | |
5013 | + return (char *) NULL; | |
5014 | + } | |
5015 | + /* Non-truecolor case, restored to its more or less original form */ | |
5016 | + for (row = 0; row < bitmap.rows; row++) { | |
5017 | + int pcr; | |
5018 | + pc = row * bitmap.pitch; | |
5019 | + pcr = pc; | |
5020 | + if (bitmap.pixel_mode==ft_pixel_mode_mono) { | |
5021 | + pc *= 8; /* pc is measured in bits for monochrome images */ | |
5022 | + } | |
5023 | + y = pen_y + row; | |
5024 | + | |
5025 | + /* clip if out of bounds */ | |
5026 | + if (y >= im->sy || y < 0) { | |
5027 | + continue; | |
5028 | + } | |
5029 | + | |
5030 | + for (col = 0; col < bitmap.width; col++, pc++) { | |
5031 | + if (bitmap.pixel_mode == ft_pixel_mode_grays) { | |
5032 | + /* | |
5033 | + * Round to NUMCOLORS levels of antialiasing for | |
5034 | + * index color images since only 256 colors are | |
5035 | + * available. | |
5036 | + */ | |
5037 | + tc_key.pixel = ((bitmap.buffer[pc] * NUMCOLORS) + bitmap.num_grays / 2) / (bitmap.num_grays - 1); | |
5038 | + } else if (bitmap.pixel_mode == ft_pixel_mode_mono) { | |
5039 | + tc_key.pixel = ((bitmap.buffer[pc / 8] << (pc % 8)) & 128) ? NUMCOLORS : 0; | |
5040 | + /* 2.0.5: mode_mono fix from Giuliano Pochini */ | |
5041 | + tc_key.pixel = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) ? NUMCOLORS : 0; | |
5042 | + } else { | |
5043 | + return "Unsupported ft_pixel_mode"; | |
5044 | + } | |
5045 | + if (tc_key.pixel > 0) { /* if not background */ | |
5046 | + x = pen_x + col; | |
5047 | + | |
5048 | + /* clip if out of bounds */ | |
5049 | + if (x >= im->sx || x < 0) { | |
5050 | + continue; | |
5051 | + } | |
5052 | + /* get pixel location in gd buffer */ | |
5053 | + pixel = &im->pixels[y][x]; | |
5054 | + if (tc_key.pixel == NUMCOLORS) { | |
5055 | + /* use fg color directly. gd 2.0.2: watch out for | |
5056 | + * negative indexes (thanks to David Marwood). | |
5057 | + */ | |
5058 | + *pixel = (fg < 0) ? -fg : fg; | |
5059 | + } else { | |
5060 | + /* find antialised color */ | |
5061 | + tc_key.bgcolor = *pixel; | |
5062 | + tc_elem = (tweencolor_t *) gdCacheGet(tc_cache, &tc_key); | |
5063 | + *pixel = tc_elem->tweencolor; | |
5064 | + } | |
5065 | + } | |
5066 | } | |
5067 | - } | |
5068 | } | |
5069 | - } | |
5070 | - return (char *) NULL; | |
5071 | + return (char *) NULL; | |
5072 | } | |
5073 | ||
5074 | static int | |
5075 | gdroundupdown (FT_F26Dot6 v1, int updown) | |
5076 | { | |
5077 | - return (!updown) | |
5078 | - ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6) | |
5079 | - : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6); | |
5080 | + return (!updown) ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6) : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6); | |
5081 | } | |
5082 | ||
5083 | void gdFontCacheShutdown() | |
5084 | { | |
5085 | + gdMutexLock(gdFontCacheMutex); | |
5086 | + | |
5087 | if (fontCache) { | |
5088 | - gdMutexLock(gdFontCacheMutex); | |
5089 | gdCacheDelete(fontCache); | |
5090 | fontCache = NULL; | |
5091 | - gdMutexUnlock(gdFontCacheMutex); | |
5092 | - gdMutexShutdown(gdFontCacheMutex); | |
5093 | FT_Done_FreeType(library); | |
5094 | } | |
5095 | + | |
5096 | + gdMutexUnlock(gdFontCacheMutex); | |
5097 | } | |
5098 | ||
5099 | void gdFreeFontCache() | |
5100 | { | |
5101 | gdFontCacheShutdown(); | |
5102 | } | |
5103 | - | |
5104 | + | |
5105 | +void gdFontCacheMutexSetup() | |
5106 | +{ | |
5107 | + gdMutexSetup(gdFontCacheMutex); | |
5108 | +} | |
5109 | + | |
5110 | +void gdFontCacheMutexShutdown() | |
5111 | +{ | |
5112 | + gdMutexShutdown(gdFontCacheMutex); | |
5113 | +} | |
5114 | + | |
5115 | int gdFontCacheSetup(void) | |
5116 | { | |
5117 | if (fontCache) { | |
5118 | /* Already set up */ | |
5119 | return 0; | |
5120 | } | |
5121 | - gdMutexSetup(gdFontCacheMutex); | |
5122 | if (FT_Init_FreeType(&library)) { | |
5123 | - gdMutexShutdown(gdFontCacheMutex); | |
5124 | return -1; | |
5125 | } | |
5126 | fontCache = gdCacheCreate (FONTCACHESIZE, fontTest, fontFetch, fontRelease); | |
5127 | return 0; | |
5128 | } | |
5129 | ||
5130 | + | |
5131 | /********************************************************************/ | |
5132 | /* gdImageStringFT - render a utf8 string onto a gd image */ | |
5133 | ||
5134 | char * | |
5135 | -gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, | |
5136 | - double ptsize, double angle, int x, int y, char *string) | |
5137 | +gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, | |
5138 | + double ptsize, double angle, int x, int y, char *string) | |
5139 | { | |
5140 | return gdImageStringFTEx(im, brect, fg, fontlist, ptsize, angle, x, y, string, 0); | |
5141 | } | |
5142 | @@ -856,15 +814,16 @@ | |
5143 | ||
5144 | /***** initialize font library and font cache on first call ******/ | |
5145 | ||
5146 | + gdMutexLock(gdFontCacheMutex); | |
5147 | if (!fontCache) { | |
5148 | if (gdFontCacheSetup() != 0) { | |
5149 | gdCacheDelete(tc_cache); | |
5150 | + gdMutexUnlock(gdFontCacheMutex); | |
5151 | return "Failure to initialize font library"; | |
5152 | } | |
5153 | } | |
5154 | /*****/ | |
5155 | - | |
5156 | - gdMutexLock(gdFontCacheMutex); | |
5157 | + | |
5158 | /* get the font (via font cache) */ | |
5159 | fontkey.fontlist = fontlist; | |
5160 | fontkey.library = &library; | |
5161 | @@ -961,6 +920,7 @@ | |
5162 | ||
5163 | while (*next) { | |
5164 | ch = *next; | |
5165 | + | |
5166 | /* carriage returns */ | |
5167 | if (ch == '\r') { | |
5168 | penf.x = 0; | |
5169 | @@ -991,8 +951,9 @@ | |
5170 | /* I do not know the significance of the constant 0xf000. | |
5171 | * It was determined by inspection of the character codes | |
5172 | * stored in Microsoft font symbol. | |
5173 | + * Added by Pierre (pajoye@php.net): | |
5174 | + * Convert to the Symbol glyph range only for a Symbol family member | |
5175 | */ | |
5176 | - /* Convert to the Symbol glyph range only for a Symbol family member */ | |
5177 | len = gdTcl_UtfToUniChar (next, &ch); | |
5178 | ch |= 0xf000; | |
5179 | next += len; | |
5180 | @@ -1008,7 +969,7 @@ | |
5181 | next += len; | |
5182 | } | |
5183 | break; | |
5184 | - case gdFTEX_Shift_JIS: | |
5185 | + case gdFTEX_Shift_JIS: | |
5186 | if (font->have_char_map_sjis) { | |
5187 | unsigned char c; | |
5188 | int jiscode; | |
5189 | @@ -1063,7 +1024,7 @@ | |
5190 | FT_Set_Transform(face, &matrix, NULL); | |
5191 | /* Convert character code to glyph index */ | |
5192 | glyph_index = FT_Get_Char_Index(face, ch); | |
5193 | - | |
5194 | + | |
5195 | /* retrieve kerning distance and move pen position */ | |
5196 | if (use_kerning && previous && glyph_index) { | |
5197 | FT_Get_Kerning(face, previous, glyph_index, ft_kerning_default, &delta); | |
5198 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_gd2.c php-4.4.8/ext/gd/libgd/gd_gd2.c | |
5199 | --- php-4.4.8.org/ext/gd/libgd/gd_gd2.c 2004-03-29 20:21:00.000000000 +0200 | |
5200 | +++ php-4.4.8/ext/gd/libgd/gd_gd2.c 2006-08-08 13:56:36.000000000 +0200 | |
5201 | @@ -26,7 +26,7 @@ | |
5202 | /* 2.11: not part of the API, as the save routine can figure it out | |
5203 | * from im->trueColor, and the load routine doesn't need to tell | |
5204 | * the end user the saved format. NOTE: adding 2 is assumed | |
5205 | - * to result in the correct format value for truecolor! | |
5206 | + * to result in the correct format value for truecolor! | |
5207 | */ | |
5208 | #define GD2_FMT_TRUECOLOR_RAW 3 | |
5209 | #define GD2_FMT_TRUECOLOR_COMPRESSED 4 | |
5210 | @@ -43,8 +43,7 @@ | |
5211 | { | |
5212 | int offset; | |
5213 | int size; | |
5214 | -} | |
5215 | -t_chunk_info; | |
5216 | +} t_chunk_info; | |
5217 | ||
5218 | extern int _gdGetColors(gdIOCtx * in, gdImagePtr im, int gd2xFlag); | |
5219 | extern void _gdPutColors(gdImagePtr im, gdIOCtx * out); | |
5220 | @@ -61,7 +60,7 @@ | |
5221 | int sidx; | |
5222 | int nc; | |
5223 | ||
5224 | - GD2_DBG(php_gd_error("Reading gd2 header info\n")); | |
5225 | + GD2_DBG(php_gd_error("Reading gd2 header info")); | |
5226 | ||
5227 | for (i = 0; i < 4; i++) { | |
5228 | ch = gdGetC(in); | |
5229 | @@ -72,11 +71,11 @@ | |
5230 | } | |
5231 | id[4] = 0; | |
5232 | ||
5233 | - GD2_DBG(php_gd_error("Got file code: %s\n", id)); | |
5234 | + GD2_DBG(php_gd_error("Got file code: %s", id)); | |
5235 | ||
5236 | /* Equiv. of 'magick'. */ | |
5237 | if (strcmp(id, GD2_ID) != 0) { | |
5238 | - GD2_DBG(php_gd_error("Not a valid gd2 file\n")); | |
5239 | + GD2_DBG(php_gd_error("Not a valid gd2 file")); | |
5240 | goto fail1; | |
5241 | } | |
5242 | ||
5243 | @@ -84,32 +83,32 @@ | |
5244 | if (gdGetWord(vers, in) != 1) { | |
5245 | goto fail1; | |
5246 | } | |
5247 | - GD2_DBG(php_gd_error("Version: %d\n", *vers)); | |
5248 | + GD2_DBG(php_gd_error("Version: %d", *vers)); | |
5249 | ||
5250 | if ((*vers != 1) && (*vers != 2)) { | |
5251 | - GD2_DBG(php_gd_error("Bad version: %d\n", *vers)); | |
5252 | + GD2_DBG(php_gd_error("Bad version: %d", *vers)); | |
5253 | goto fail1; | |
5254 | } | |
5255 | ||
5256 | /* Image Size */ | |
5257 | if (!gdGetWord(sx, in)) { | |
5258 | - GD2_DBG(php_gd_error("Could not get x-size\n")); | |
5259 | + GD2_DBG(php_gd_error("Could not get x-size")); | |
5260 | goto fail1; | |
5261 | } | |
5262 | if (!gdGetWord(sy, in)) { | |
5263 | - GD2_DBG(php_gd_error("Could not get y-size\n")); | |
5264 | + GD2_DBG(php_gd_error("Could not get y-size")); | |
5265 | goto fail1; | |
5266 | } | |
5267 | - GD2_DBG(php_gd_error("Image is %dx%d\n", *sx, *sy)); | |
5268 | + GD2_DBG(php_gd_error("Image is %dx%d", *sx, *sy)); | |
5269 | ||
5270 | /* Chunk Size (pixels, not bytes!) */ | |
5271 | if (gdGetWord(cs, in) != 1) { | |
5272 | goto fail1; | |
5273 | } | |
5274 | - GD2_DBG(php_gd_error("ChunkSize: %d\n", *cs)); | |
5275 | + GD2_DBG(php_gd_error("ChunkSize: %d", *cs)); | |
5276 | ||
5277 | if ((*cs < GD2_CHUNKSIZE_MIN) || (*cs > GD2_CHUNKSIZE_MAX)) { | |
5278 | - GD2_DBG(php_gd_error("Bad chunk size: %d\n", *cs)); | |
5279 | + GD2_DBG(php_gd_error("Bad chunk size: %d", *cs)); | |
5280 | goto fail1; | |
5281 | } | |
5282 | ||
5283 | @@ -117,10 +116,10 @@ | |
5284 | if (gdGetWord(fmt, in) != 1) { | |
5285 | goto fail1; | |
5286 | } | |
5287 | - GD2_DBG(php_gd_error("Format: %d\n", *fmt)); | |
5288 | + GD2_DBG(php_gd_error("Format: %d", *fmt)); | |
5289 | ||
5290 | if ((*fmt != GD2_FMT_RAW) && (*fmt != GD2_FMT_COMPRESSED) && (*fmt != GD2_FMT_TRUECOLOR_RAW) && (*fmt != GD2_FMT_TRUECOLOR_COMPRESSED)) { | |
5291 | - GD2_DBG(php_gd_error("Bad data format: %d\n", *fmt)); | |
5292 | + GD2_DBG(php_gd_error("Bad data format: %d", *fmt)); | |
5293 | goto fail1; | |
5294 | } | |
5295 | ||
5296 | @@ -128,17 +127,17 @@ | |
5297 | if (gdGetWord(ncx, in) != 1) { | |
5298 | goto fail1; | |
5299 | } | |
5300 | - GD2_DBG(php_gd_error("%d Chunks Wide\n", *ncx)); | |
5301 | + GD2_DBG(php_gd_error("%d Chunks Wide", *ncx)); | |
5302 | ||
5303 | /* # of chunks high */ | |
5304 | if (gdGetWord(ncy, in) != 1) { | |
5305 | goto fail1; | |
5306 | } | |
5307 | - GD2_DBG(php_gd_error("%d Chunks vertically\n", *ncy)); | |
5308 | + GD2_DBG(php_gd_error("%d Chunks vertically", *ncy)); | |
5309 | ||
5310 | if (gd2_compressed(*fmt)) { | |
5311 | nc = (*ncx) * (*ncy); | |
5312 | - GD2_DBG(php_gd_error("Reading %d chunk index entries\n", nc)); | |
5313 | + GD2_DBG(php_gd_error("Reading %d chunk index entries", nc)); | |
5314 | sidx = sizeof(t_chunk_info) * nc; | |
5315 | if (sidx <= 0) { | |
5316 | goto fail1; | |
5317 | @@ -155,7 +154,7 @@ | |
5318 | *chunkIdx = cidx; | |
5319 | } | |
5320 | ||
5321 | - GD2_DBG(php_gd_error("gd2 header complete\n")); | |
5322 | + GD2_DBG(php_gd_error("gd2 header complete")); | |
5323 | ||
5324 | return 1; | |
5325 | ||
5326 | @@ -168,7 +167,7 @@ | |
5327 | gdImagePtr im; | |
5328 | ||
5329 | if (_gd2GetHeader (in, sx, sy, cs, vers, fmt, ncx, ncy, cidx) != 1) { | |
5330 | - GD2_DBG(php_gd_error("Bad GD2 header\n")); | |
5331 | + GD2_DBG(php_gd_error("Bad GD2 header")); | |
5332 | goto fail1; | |
5333 | } | |
5334 | ||
5335 | @@ -178,15 +177,15 @@ | |
5336 | im = gdImageCreate(*sx, *sy); | |
5337 | } | |
5338 | if (im == NULL) { | |
5339 | - GD2_DBG(php_gd_error("Could not create gdImage\n")); | |
5340 | + GD2_DBG(php_gd_error("Could not create gdImage")); | |
5341 | goto fail1; | |
5342 | } | |
5343 | ||
5344 | if (!_gdGetColors(in, im, (*vers) == 2)) { | |
5345 | - GD2_DBG(php_gd_error("Could not read color palette\n")); | |
5346 | + GD2_DBG(php_gd_error("Could not read color palette")); | |
5347 | goto fail2; | |
5348 | } | |
5349 | - GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal)); | |
5350 | + GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal)); | |
5351 | ||
5352 | return im; | |
5353 | ||
5354 | @@ -203,25 +202,25 @@ | |
5355 | int zerr; | |
5356 | ||
5357 | if (gdTell(in) != offset) { | |
5358 | - GD2_DBG(php_gd_error("Positioning in file to %d\n", offset)); | |
5359 | + GD2_DBG(php_gd_error("Positioning in file to %d", offset)); | |
5360 | gdSeek(in, offset); | |
5361 | } else { | |
5362 | - GD2_DBG(php_gd_error("Already Positioned in file to %d\n", offset)); | |
5363 | + GD2_DBG(php_gd_error("Already Positioned in file to %d", offset)); | |
5364 | } | |
5365 | ||
5366 | /* Read and uncompress an entire chunk. */ | |
5367 | - GD2_DBG(php_gd_error("Reading file\n")); | |
5368 | + GD2_DBG(php_gd_error("Reading file")); | |
5369 | if (gdGetBuf(compBuf, compSize, in) != compSize) { | |
5370 | return FALSE; | |
5371 | } | |
5372 | - GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes\n", compSize, (int)*chunkLen)); | |
5373 | + GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes", compSize, (int)*chunkLen)); | |
5374 | zerr = uncompress((unsigned char *) chunkBuf, chunkLen, (unsigned char *) compBuf, compSize); | |
5375 | if (zerr != Z_OK) { | |
5376 | - GD2_DBG(php_gd_error("Error %d from uncompress\n", zerr)); | |
5377 | + GD2_DBG(php_gd_error("Error %d from uncompress", zerr)); | |
5378 | return FALSE; | |
5379 | } | |
5380 | - GD2_DBG(php_gd_error("Got chunk\n")); | |
5381 | - | |
5382 | + GD2_DBG(php_gd_error("Got chunk")); | |
5383 | + | |
5384 | return TRUE; | |
5385 | } | |
5386 | ||
5387 | @@ -291,8 +290,8 @@ | |
5388 | } | |
5389 | chunkBuf = gdCalloc(chunkMax, 1); | |
5390 | compBuf = gdCalloc(compMax, 1); | |
5391 | - | |
5392 | - GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes\n", compMax)); | |
5393 | + | |
5394 | + GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes", compMax)); | |
5395 | } | |
5396 | ||
5397 | /* Read the data... */ | |
5398 | @@ -304,13 +303,13 @@ | |
5399 | yhi = im->sy; | |
5400 | } | |
5401 | ||
5402 | - GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d\n", chunkNum, cx, cy, ylo, yhi)); | |
5403 | + GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d", chunkNum, cx, cy, ylo, yhi)); | |
5404 | ||
5405 | if (gd2_compressed(fmt)) { | |
5406 | chunkLen = chunkMax; | |
5407 | ||
5408 | if (!_gd2ReadChunk(chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *) chunkBuf, &chunkLen, in)) { | |
5409 | - GD2_DBG(php_gd_error("Error reading comproessed chunk\n")); | |
5410 | + GD2_DBG(php_gd_error("Error reading comproessed chunk")); | |
5411 | goto fail2; | |
5412 | } | |
5413 | ||
5414 | @@ -357,7 +356,7 @@ | |
5415 | } | |
5416 | } | |
5417 | ||
5418 | - GD2_DBG(php_gd_error("Freeing memory\n")); | |
5419 | + GD2_DBG(php_gd_error("Freeing memory")); | |
5420 | ||
5421 | if (chunkBuf) { | |
5422 | gdFree(chunkBuf); | |
5423 | @@ -369,7 +368,7 @@ | |
5424 | gdFree(chunkIdx); | |
5425 | } | |
5426 | ||
5427 | - GD2_DBG(php_gd_error("Done\n")); | |
5428 | + GD2_DBG(php_gd_error("Done")); | |
5429 | ||
5430 | return im; | |
5431 | ||
5432 | @@ -398,7 +397,7 @@ | |
5433 | return im; | |
5434 | } | |
5435 | ||
5436 | -gdImagePtr gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h) | |
5437 | +gdImagePtr gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h) | |
5438 | { | |
5439 | gdImagePtr im; | |
5440 | gdIOCtx *in = gdNewFileCtx(inFile); | |
5441 | @@ -431,6 +430,10 @@ | |
5442 | ||
5443 | gdImagePtr im; | |
5444 | ||
5445 | + if (w<1 || h <1) { | |
5446 | + return 0; | |
5447 | + } | |
5448 | + | |
5449 | /* The next few lines are basically copied from gd2CreateFromFile | |
5450 | * we change the file size, so don't want to use the code directly. | |
5451 | * but we do need to know the file size. | |
5452 | @@ -439,7 +442,7 @@ | |
5453 | goto fail1; | |
5454 | } | |
5455 | ||
5456 | - GD2_DBG(php_gd_error("File size is %dx%d\n", fsx, fsy)); | |
5457 | + GD2_DBG(php_gd_error("File size is %dx%d", fsx, fsy)); | |
5458 | ||
5459 | /* This is the difference - make a file based on size of chunks. */ | |
5460 | if (gd2_truecolor(fmt)) { | |
5461 | @@ -454,7 +457,7 @@ | |
5462 | if (!_gdGetColors(in, im, vers == 2)) { | |
5463 | goto fail2; | |
5464 | } | |
5465 | - GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal)); | |
5466 | + GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal)); | |
5467 | ||
5468 | /* Process the header info */ | |
5469 | nc = ncx * ncy; | |
5470 | @@ -477,7 +480,7 @@ | |
5471 | if (chunkMax <= 0) { | |
5472 | goto fail2; | |
5473 | } | |
5474 | - | |
5475 | + | |
5476 | chunkBuf = gdCalloc(chunkMax, 1); | |
5477 | compBuf = gdCalloc(compMax, 1); | |
5478 | } | |
5479 | @@ -503,7 +506,7 @@ | |
5480 | ||
5481 | /* Remember file position of image data. */ | |
5482 | dstart = gdTell(in); | |
5483 | - GD2_DBG(php_gd_error("Data starts at %d\n", dstart)); | |
5484 | + GD2_DBG(php_gd_error("Data starts at %d", dstart)); | |
5485 | ||
5486 | /* Loop through the chunks. */ | |
5487 | for (cy = scy; (cy <= ecy); cy++) { | |
5488 | @@ -521,10 +524,10 @@ | |
5489 | xhi = fsx; | |
5490 | } | |
5491 | ||
5492 | - GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d\n", cx, cy, ylo, yhi)); | |
5493 | + GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d", cx, cy, ylo, yhi)); | |
5494 | ||
5495 | if (!gd2_compressed(fmt)) { | |
5496 | - GD2_DBG(php_gd_error("Using raw format data\n")); | |
5497 | + GD2_DBG(php_gd_error("Using raw format data")); | |
5498 | if (im->trueColor) { | |
5499 | dpos = (cy * (cs * fsx) * 4 + cx * cs * (yhi - ylo) * 4) + dstart; | |
5500 | } else { | |
5501 | @@ -533,29 +536,29 @@ | |
5502 | ||
5503 | /* gd 2.0.11: gdSeek returns TRUE on success, not 0. Longstanding bug. 01/16/03 */ | |
5504 | if (!gdSeek(in, dpos)) { | |
5505 | - php_gd_error_ex(E_WARNING, "Error from seek: %d\n", errno); | |
5506 | + php_gd_error_ex(E_WARNING, "Error from seek: %d", errno); | |
5507 | goto fail2; | |
5508 | } | |
5509 | - GD2_DBG(php_gd_error("Reading (%d, %d) from position %d\n", cx, cy, dpos - dstart)); | |
5510 | + GD2_DBG(php_gd_error("Reading (%d, %d) from position %d", cx, cy, dpos - dstart)); | |
5511 | } else { | |
5512 | chunkNum = cx + cy * ncx; | |
5513 | ||
5514 | chunkLen = chunkMax; | |
5515 | - if (!_gd2ReadChunk (chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, chunkBuf, &chunkLen, in)) { | |
5516 | - php_gd_error("Error reading comproessed chunk\n"); | |
5517 | + if (!_gd2ReadChunk (chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *)chunkBuf, &chunkLen, in)) { | |
5518 | + php_gd_error("Error reading comproessed chunk"); | |
5519 | goto fail2; | |
5520 | } | |
5521 | chunkPos = 0; | |
5522 | - GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d\n", cx, cy, chunkNum)); | |
5523 | + GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d", cx, cy, chunkNum)); | |
5524 | } | |
5525 | ||
5526 | - GD2_DBG(php_gd_error(" into (%d, %d) - (%d, %d)\n", xlo, ylo, xhi, yhi)); | |
5527 | + GD2_DBG(php_gd_error(" into (%d, %d) - (%d, %d)", xlo, ylo, xhi, yhi)); | |
5528 | ||
5529 | for (y = ylo; (y < yhi); y++) { | |
5530 | for (x = xlo; x < xhi; x++) { | |
5531 | if (!gd2_compressed(fmt)) { | |
5532 | if (im->trueColor) { | |
5533 | - if (!gdGetInt(&ch, in)) { | |
5534 | + if (!gdGetInt((int *)&ch, in)) { | |
5535 | ch = 0; | |
5536 | } | |
5537 | } else { | |
5538 | @@ -577,11 +580,11 @@ | |
5539 | ||
5540 | /* Only use a point that is in the image. */ | |
5541 | if ((x >= srcx) && (x < (srcx + w)) && (x < fsx) && (x >= 0) && (y >= srcy) && (y < (srcy + h)) && (y < fsy) && (y >= 0)) { | |
5542 | - if (im->trueColor) { | |
5543 | + if (im->trueColor) { | |
5544 | im->tpixels[y - srcy][x - srcx] = ch; | |
5545 | } else { | |
5546 | im->pixels[y - srcy][x - srcx] = ch; | |
5547 | - } | |
5548 | + } | |
5549 | } | |
5550 | } | |
5551 | } | |
5552 | @@ -597,7 +600,7 @@ | |
5553 | if (chunkIdx) { | |
5554 | gdFree(chunkIdx); | |
5555 | } | |
5556 | - | |
5557 | + | |
5558 | return im; | |
5559 | ||
5560 | fail2: | |
5561 | @@ -653,7 +656,7 @@ | |
5562 | int compMax = 0; | |
5563 | ||
5564 | /* Force fmt to a valid value since we don't return anything. */ | |
5565 | - if ((fmt != GD2_FMT_RAW) && (fmt != GD2_FMT_COMPRESSED)) { | |
5566 | + if ((fmt != GD2_FMT_RAW) && (fmt != GD2_FMT_COMPRESSED)) { | |
5567 | fmt = im->trueColor ? GD2_FMT_TRUECOLOR_COMPRESSED : GD2_FMT_COMPRESSED; | |
5568 | } | |
5569 | if (im->trueColor) { | |
5570 | @@ -693,16 +696,16 @@ | |
5571 | chunkData = safe_emalloc(cs * bytesPerPixel, cs, 0); | |
5572 | memset(chunkData, 0, cs * bytesPerPixel * cs); | |
5573 | if (compMax <= 0) { | |
5574 | - goto fail; | |
5575 | + goto fail; | |
5576 | } | |
5577 | compData = gdCalloc(compMax, 1); | |
5578 | ||
5579 | /* Save the file position of chunk index, and allocate enough space for | |
5580 | - * each chunk_info block . | |
5581 | + * each chunk_info block . | |
5582 | */ | |
5583 | idxPos = gdTell(out); | |
5584 | idxSize = ncx * ncy * sizeof(t_chunk_info); | |
5585 | - GD2_DBG(php_gd_error("Index size is %d\n", idxSize)); | |
5586 | + GD2_DBG(php_gd_error("Index size is %d", idxSize)); | |
5587 | gdSeek(out, idxPos + idxSize); | |
5588 | ||
5589 | chunkIdx = safe_emalloc(idxSize, sizeof(t_chunk_info), 0); | |
5590 | @@ -711,8 +714,8 @@ | |
5591 | ||
5592 | _gdPutColors (im, out); | |
5593 | ||
5594 | - GD2_DBG(php_gd_error("Size: %dx%d\n", im->sx, im->sy)); | |
5595 | - GD2_DBG(php_gd_error("Chunks: %dx%d\n", ncx, ncy)); | |
5596 | + GD2_DBG(php_gd_error("Size: %dx%d", im->sx, im->sy)); | |
5597 | + GD2_DBG(php_gd_error("Chunks: %dx%d", ncx, ncy)); | |
5598 | ||
5599 | for (cy = 0; (cy < ncy); cy++) { | |
5600 | for (cx = 0; (cx < ncx); cx++) { | |
5601 | @@ -722,7 +725,7 @@ | |
5602 | yhi = im->sy; | |
5603 | } | |
5604 | ||
5605 | - GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d\n", cx, cy, ylo, yhi)); | |
5606 | + GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d", cx, cy, ylo, yhi)); | |
5607 | chunkLen = 0; | |
5608 | for (y = ylo; (y < yhi); y++) { | |
5609 | GD2_DBG(php_gd_error("y=%d: ",y)); | |
5610 | @@ -747,7 +750,7 @@ | |
5611 | } | |
5612 | } else { | |
5613 | for (x = xlo; x < xhi; x++) { | |
5614 | - GD2_DBG(php_gd_error("%d, ",x)); | |
5615 | + GD2_DBG(php_gd_error("%d, ",x)); | |
5616 | ||
5617 | if (im->trueColor) { | |
5618 | gdPutInt(im->tpixels[y][x], out); | |
5619 | @@ -756,21 +759,21 @@ | |
5620 | } | |
5621 | } | |
5622 | } | |
5623 | - GD2_DBG(php_gd_error("y=%d done.\n",y)); | |
5624 | + GD2_DBG(php_gd_error("y=%d done.",y)); | |
5625 | } | |
5626 | ||
5627 | if (gd2_compressed(fmt)) { | |
5628 | compLen = compMax; | |
5629 | if (compress((unsigned char *) &compData[0], &compLen, (unsigned char *) &chunkData[0], chunkLen) != Z_OK) { | |
5630 | - php_gd_error("Error from compressing\n"); | |
5631 | + php_gd_error("Error from compressing"); | |
5632 | } else { | |
5633 | chunkIdx[chunkNum].offset = gdTell(out); | |
5634 | chunkIdx[chunkNum++].size = compLen; | |
5635 | - GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset)); | |
5636 | + GD2_DBG(php_gd_error("Chunk %d size %d offset %d", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset)); | |
5637 | ||
5638 | if (gdPutBuf (compData, compLen, out) <= 0) { | |
5639 | /* Any alternate suggestions for handling this? */ | |
5640 | - php_gd_error_ex(E_WARNING, "Error %d on write\n", errno); | |
5641 | + php_gd_error_ex(E_WARNING, "Error %d on write", errno); | |
5642 | } | |
5643 | } | |
5644 | } | |
5645 | @@ -779,29 +782,29 @@ | |
5646 | ||
5647 | if (gd2_compressed(fmt)) { | |
5648 | /* Save the position, write the index, restore position (paranoia). */ | |
5649 | - GD2_DBG(php_gd_error("Seeking %d to write index\n", idxPos)); | |
5650 | + GD2_DBG(php_gd_error("Seeking %d to write index", idxPos)); | |
5651 | posSave = gdTell(out); | |
5652 | gdSeek(out, idxPos); | |
5653 | - GD2_DBG(php_gd_error("Writing index\n")); | |
5654 | + GD2_DBG(php_gd_error("Writing index")); | |
5655 | for (x = 0; x < chunkNum; x++) { | |
5656 | - GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", x, chunkIdx[x].size, chunkIdx[x].offset)); | |
5657 | + GD2_DBG(php_gd_error("Chunk %d size %d offset %d", x, chunkIdx[x].size, chunkIdx[x].offset)); | |
5658 | gdPutInt(chunkIdx[x].offset, out); | |
5659 | gdPutInt(chunkIdx[x].size, out); | |
5660 | } | |
5661 | gdSeek(out, posSave); | |
5662 | } | |
5663 | fail: | |
5664 | - GD2_DBG(php_gd_error("Freeing memory\n")); | |
5665 | + GD2_DBG(php_gd_error("Freeing memory")); | |
5666 | if (chunkData) { | |
5667 | gdFree(chunkData); | |
5668 | } | |
5669 | - if (compData) { | |
5670 | + if (compData) { | |
5671 | gdFree(compData); | |
5672 | } | |
5673 | if (chunkIdx) { | |
5674 | gdFree(chunkIdx); | |
5675 | } | |
5676 | - GD2_DBG(php_gd_error("Done\n")); | |
5677 | + GD2_DBG(php_gd_error("Done")); | |
5678 | } | |
5679 | ||
5680 | void gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt) | |
5681 | @@ -809,7 +812,7 @@ | |
5682 | gdIOCtx *out = gdNewFileCtx(outFile); | |
5683 | ||
5684 | _gdImageGd2(im, out, cs, fmt); | |
5685 | - | |
5686 | + | |
5687 | out->gd_free(out); | |
5688 | } | |
5689 | ||
5690 | @@ -821,6 +824,6 @@ | |
5691 | _gdImageGd2(im, out, cs, fmt); | |
5692 | rv = gdDPExtractData(out, size); | |
5693 | out->gd_free(out); | |
5694 | - | |
5695 | + | |
5696 | return rv; | |
5697 | } | |
5698 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_gd.c php-4.4.8/ext/gd/libgd/gd_gd.c | |
5699 | --- php-4.4.8.org/ext/gd/libgd/gd_gd.c 2004-03-29 20:21:00.000000000 +0200 | |
5700 | +++ php-4.4.8/ext/gd/libgd/gd_gd.c 2007-08-09 16:21:38.000000000 +0200 | |
5701 | @@ -1,4 +1,3 @@ | |
5702 | - | |
5703 | #include <stdio.h> | |
5704 | #include <math.h> | |
5705 | #include <string.h> | |
5706 | @@ -58,7 +57,7 @@ | |
5707 | } | |
5708 | ||
5709 | GD2_DBG(printf("Pallette had %d colours (T=%d)\n", im->colorsTotal, im->transparent)); | |
5710 | - | |
5711 | + | |
5712 | if (im->trueColor) { | |
5713 | return TRUE; | |
5714 | } | |
5715 | @@ -123,6 +122,9 @@ | |
5716 | } else { | |
5717 | im = gdImageCreate(*sx, *sy); | |
5718 | } | |
5719 | + if(!im) { | |
5720 | + goto fail1; | |
5721 | + } | |
5722 | if (!_gdGetColors(in, im, gd2xFlag)) { | |
5723 | goto fail2; | |
5724 | } | |
5725 | @@ -225,7 +227,7 @@ | |
5726 | ||
5727 | static void _gdPutHeader (gdImagePtr im, gdIOCtx * out) | |
5728 | { | |
5729 | - /* 65535 indicates this is a gd 2.x .gd file. | |
5730 | + /* 65535 indicates this is a gd 2.x .gd file. | |
5731 | * 2.0.12: 65534 indicates truecolor. | |
5732 | */ | |
5733 | if (im->trueColor) { | |
5734 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_gif_in.c php-4.4.8/ext/gd/libgd/gd_gif_in.c | |
5735 | --- php-4.4.8.org/ext/gd/libgd/gd_gif_in.c 2007-06-08 07:31:02.000000000 +0200 | |
5736 | +++ php-4.4.8/ext/gd/libgd/gd_gif_in.c 2007-06-07 23:07:33.000000000 +0200 | |
5737 | @@ -17,9 +17,9 @@ | |
5738 | ||
5739 | static int set_verbose(void) | |
5740 | { | |
5741 | - verbose = !!getenv("GIF_VERBOSE"); | |
5742 | - verbose_set = 1; | |
5743 | - return(verbose); | |
5744 | + verbose = !!getenv("GIF_VERBOSE"); | |
5745 | + verbose_set = 1; | |
5746 | + return(verbose); | |
5747 | } | |
5748 | ||
5749 | #else | |
5750 | @@ -44,270 +44,313 @@ | |
5751 | #define LOCALCOLORMAP 0x80 | |
5752 | #define BitSet(byte, bit) (((byte) & (bit)) == (bit)) | |
5753 | ||
5754 | -#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) != 0) | |
5755 | +#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) > 0) | |
5756 | ||
5757 | #define LM_to_uint(a,b) (((b)<<8)|(a)) | |
5758 | ||
5759 | /* We may eventually want to use this information, but def it out for now */ | |
5760 | #if 0 | |
5761 | static struct { | |
5762 | - unsigned int Width; | |
5763 | - unsigned int Height; | |
5764 | - unsigned char ColorMap[3][MAXCOLORMAPSIZE]; | |
5765 | - unsigned int BitPixel; | |
5766 | - unsigned int ColorResolution; | |
5767 | - unsigned int Background; | |
5768 | - unsigned int AspectRatio; | |
5769 | + unsigned int Width; | |
5770 | + unsigned int Height; | |
5771 | + unsigned char ColorMap[3][MAXCOLORMAPSIZE]; | |
5772 | + unsigned int BitPixel; | |
5773 | + unsigned int ColorResolution; | |
5774 | + unsigned int Background; | |
5775 | + unsigned int AspectRatio; | |
5776 | } GifScreen; | |
5777 | #endif | |
5778 | ||
5779 | +#if 0 | |
5780 | static struct { | |
5781 | - int transparent; | |
5782 | - int delayTime; | |
5783 | - int inputFlag; | |
5784 | - int disposal; | |
5785 | + int transparent; | |
5786 | + int delayTime; | |
5787 | + int inputFlag; | |
5788 | + int disposal; | |
5789 | } Gif89 = { -1, -1, -1, 0 }; | |
5790 | +#endif | |
5791 | ||
5792 | -static int ReadColorMap (gdIOCtx *fd, int number, unsigned char (*buffer)[256]); | |
5793 | -static int DoExtension (gdIOCtx *fd, int label, int *Transparent); | |
5794 | -static int GetDataBlock (gdIOCtx *fd, unsigned char *buf); | |
5795 | -static int GetCode (gdIOCtx *fd, int code_size, int flag); | |
5796 | -static int LWZReadByte (gdIOCtx *fd, int flag, int input_code_size); | |
5797 | +#define STACK_SIZE ((1<<(MAX_LWZ_BITS))*2) | |
5798 | ||
5799 | -static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace); /*1.4//, int ignore); */ | |
5800 | +typedef struct { | |
5801 | + unsigned char buf[280]; | |
5802 | + int curbit, lastbit, done, last_byte; | |
5803 | +} CODE_STATIC_DATA; | |
5804 | + | |
5805 | +typedef struct { | |
5806 | + int fresh; | |
5807 | + int code_size, set_code_size; | |
5808 | + int max_code, max_code_size; | |
5809 | + int firstcode, oldcode; | |
5810 | + int clear_code, end_code; | |
5811 | + int table[2][(1<< MAX_LWZ_BITS)]; | |
5812 | + int stack[STACK_SIZE], *sp; | |
5813 | + CODE_STATIC_DATA scd; | |
5814 | +} LZW_STATIC_DATA; | |
5815 | ||
5816 | -int ZeroDataBlock; | |
5817 | +static int ReadColorMap (gdIOCtx *fd, int number, unsigned char (*buffer)[256]); | |
5818 | +static int DoExtension (gdIOCtx *fd, int label, int *Transparent, int *ZeroDataBlockP); | |
5819 | +static int GetDataBlock (gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP); | |
5820 | +static int GetCode (gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP); | |
5821 | +static int LWZReadByte (gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, int *ZeroDataBlockP); | |
5822 | + | |
5823 | +static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace, int *ZeroDataBlockP); /*1.4//, int ignore); */ | |
5824 | ||
5825 | -gdImagePtr gdImageCreateFromGifSource(gdSourcePtr inSource) | |
5826 | +gdImagePtr gdImageCreateFromGifSource(gdSourcePtr inSource) /* {{{ */ | |
5827 | { | |
5828 | - gdIOCtx *in = gdNewSSCtx(inSource, NULL); | |
5829 | - gdImagePtr im; | |
5830 | + gdIOCtx *in = gdNewSSCtx(inSource, NULL); | |
5831 | + gdImagePtr im; | |
5832 | ||
5833 | - im = gdImageCreateFromGifCtx(in); | |
5834 | + im = gdImageCreateFromGifCtx(in); | |
5835 | ||
5836 | - in->gd_free(in); | |
5837 | + in->gd_free(in); | |
5838 | ||
5839 | - return im; | |
5840 | + return im; | |
5841 | } | |
5842 | +/* }}} */ | |
5843 | ||
5844 | -gdImagePtr | |
5845 | -gdImageCreateFromGif(FILE *fdFile) | |
5846 | +gdImagePtr gdImageCreateFromGif(FILE *fdFile) /* {{{ */ | |
5847 | { | |
5848 | - gdIOCtx *fd = gdNewFileCtx(fdFile); | |
5849 | - gdImagePtr im = 0; | |
5850 | + gdIOCtx *fd = gdNewFileCtx(fdFile); | |
5851 | + gdImagePtr im = 0; | |
5852 | ||
5853 | - im = gdImageCreateFromGifCtx(fd); | |
5854 | + im = gdImageCreateFromGifCtx(fd); | |
5855 | ||
5856 | - fd->gd_free(fd); | |
5857 | + fd->gd_free(fd); | |
5858 | ||
5859 | - return im; | |
5860 | + return im; | |
5861 | } | |
5862 | +/* }}} */ | |
5863 | ||
5864 | -gdImagePtr | |
5865 | -gdImageCreateFromGifCtx(gdIOCtxPtr fd) | |
5866 | +gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */ | |
5867 | { | |
5868 | -/* 1.4 int imageNumber; */ | |
5869 | - int BitPixel; | |
5870 | - int ColorResolution; | |
5871 | - int Background; | |
5872 | - int AspectRatio; | |
5873 | - int Transparent = (-1); | |
5874 | - unsigned char buf[16]; | |
5875 | - unsigned char c; | |
5876 | - unsigned char ColorMap[3][MAXCOLORMAPSIZE]; | |
5877 | - unsigned char localColorMap[3][MAXCOLORMAPSIZE]; | |
5878 | - int imw, imh; | |
5879 | - int useGlobalColormap; | |
5880 | - int bitPixel; | |
5881 | - int i; | |
5882 | - /*1.4//int imageCount = 0; */ | |
5883 | - char version[4]; | |
5884 | - | |
5885 | - gdImagePtr im = 0; | |
5886 | - ZeroDataBlock = FALSE; | |
5887 | + int BitPixel; | |
5888 | +#if 0 | |
5889 | + int ColorResolution; | |
5890 | + int Background; | |
5891 | + int AspectRatio; | |
5892 | +#endif | |
5893 | + int Transparent = (-1); | |
5894 | + unsigned char buf[16]; | |
5895 | + unsigned char c; | |
5896 | + unsigned char ColorMap[3][MAXCOLORMAPSIZE]; | |
5897 | + unsigned char localColorMap[3][MAXCOLORMAPSIZE]; | |
5898 | + int imw, imh, screen_width, screen_height; | |
5899 | + int gif87a, useGlobalColormap; | |
5900 | + int bitPixel; | |
5901 | + int i; | |
5902 | + /*1.4//int imageCount = 0; */ | |
5903 | + | |
5904 | + int ZeroDataBlock = FALSE; | |
5905 | + int haveGlobalColormap; | |
5906 | + gdImagePtr im = 0; | |
5907 | ||
5908 | - /*1.4//imageNumber = 1; */ | |
5909 | - if (! ReadOK(fd,buf,6)) { | |
5910 | + /*1.4//imageNumber = 1; */ | |
5911 | + if (! ReadOK(fd,buf,6)) { | |
5912 | return 0; | |
5913 | } | |
5914 | - if (strncmp((char *)buf,"GIF",3) != 0) { | |
5915 | + if (strncmp((char *)buf,"GIF",3) != 0) { | |
5916 | return 0; | |
5917 | } | |
5918 | - strncpy(version, (char *)buf + 3, 3); | |
5919 | - version[3] = '\0'; | |
5920 | ||
5921 | - if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) { | |
5922 | + if (memcmp((char *)buf+3, "87a", 3) == 0) { | |
5923 | + gif87a = 1; | |
5924 | + } else if (memcmp((char *)buf+3, "89a", 3) == 0) { | |
5925 | + gif87a = 0; | |
5926 | + } else { | |
5927 | return 0; | |
5928 | } | |
5929 | - if (! ReadOK(fd,buf,7)) { | |
5930 | + | |
5931 | + if (! ReadOK(fd,buf,7)) { | |
5932 | return 0; | |
5933 | } | |
5934 | - BitPixel = 2<<(buf[4]&0x07); | |
5935 | - ColorResolution = (int) (((buf[4]&0x70)>>3)+1); | |
5936 | - Background = buf[5]; | |
5937 | - AspectRatio = buf[6]; | |
5938 | ||
5939 | - imw = LM_to_uint(buf[0],buf[1]); | |
5940 | - imh = LM_to_uint(buf[2],buf[3]); | |
5941 | + BitPixel = 2<<(buf[4]&0x07); | |
5942 | +#if 0 | |
5943 | + ColorResolution = (int) (((buf[4]&0x70)>>3)+1); | |
5944 | + Background = buf[5]; | |
5945 | + AspectRatio = buf[6]; | |
5946 | +#endif | |
5947 | + screen_width = imw = LM_to_uint(buf[0],buf[1]); | |
5948 | + screen_height = imh = LM_to_uint(buf[2],buf[3]); | |
5949 | ||
5950 | - if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */ | |
5951 | - if (ReadColorMap(fd, BitPixel, ColorMap)) { | |
5952 | + haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */ | |
5953 | + if (haveGlobalColormap) { | |
5954 | + if (ReadColorMap(fd, BitPixel, ColorMap)) { | |
5955 | return 0; | |
5956 | } | |
5957 | - } | |
5958 | - for (;;) { | |
5959 | - if (! ReadOK(fd,&c,1)) { | |
5960 | - return 0; | |
5961 | - } | |
5962 | - if (c == ';') { /* GIF terminator */ | |
5963 | + } | |
5964 | + | |
5965 | + for (;;) { | |
5966 | + int top, left; | |
5967 | + int width, height; | |
5968 | + | |
5969 | + if (! ReadOK(fd,&c,1)) { | |
5970 | + return 0; | |
5971 | + } | |
5972 | + if (c == ';') { /* GIF terminator */ | |
5973 | goto terminated; | |
5974 | - } | |
5975 | + } | |
5976 | + | |
5977 | + if (c == '!') { /* Extension */ | |
5978 | + if (! ReadOK(fd,&c,1)) { | |
5979 | + return 0; | |
5980 | + } | |
5981 | + DoExtension(fd, c, &Transparent, &ZeroDataBlock); | |
5982 | + continue; | |
5983 | + } | |
5984 | ||
5985 | - if (c == '!') { /* Extension */ | |
5986 | - if (! ReadOK(fd,&c,1)) { | |
5987 | - return 0; | |
5988 | - } | |
5989 | - DoExtension(fd, c, &Transparent); | |
5990 | - continue; | |
5991 | - } | |
5992 | - | |
5993 | - if (c != ',') { /* Not a valid start character */ | |
5994 | - continue; | |
5995 | - } | |
5996 | - | |
5997 | - /*1.4//++imageCount; */ | |
5998 | - | |
5999 | - if (! ReadOK(fd,buf,9)) { | |
6000 | - return 0; | |
6001 | - } | |
6002 | - | |
6003 | - useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP); | |
6004 | - | |
6005 | - bitPixel = 1<<((buf[8]&0x07)+1); | |
6006 | - | |
6007 | - if (!useGlobalColormap) { | |
6008 | - if (ReadColorMap(fd, bitPixel, localColorMap)) { | |
6009 | - return 0; | |
6010 | - } | |
6011 | - } | |
6012 | - | |
6013 | - if (!(im = gdImageCreate(imw, imh))) { | |
6014 | - return 0; | |
6015 | - } | |
6016 | - im->interlace = BitSet(buf[8], INTERLACE); | |
6017 | - if (! useGlobalColormap) { | |
6018 | - ReadImage(im, fd, imw, imh, localColorMap, | |
6019 | - BitSet(buf[8], INTERLACE)); | |
6020 | - /*1.4//imageCount != imageNumber); */ | |
6021 | - } else { | |
6022 | - ReadImage(im, fd, imw, imh, | |
6023 | - ColorMap, | |
6024 | - BitSet(buf[8], INTERLACE)); | |
6025 | - /*1.4//imageCount != imageNumber); */ | |
6026 | - } | |
6027 | - if (Transparent != (-1)) { | |
6028 | - gdImageColorTransparent(im, Transparent); | |
6029 | - } | |
6030 | - goto terminated; | |
6031 | - } | |
6032 | + if (c != ',') { /* Not a valid start character */ | |
6033 | + continue; | |
6034 | + } | |
6035 | ||
6036 | -terminated: | |
6037 | - /* Terminator before any image was declared! */ | |
6038 | - if (!im) { | |
6039 | - return 0; | |
6040 | - } | |
6041 | + /*1.4//++imageCount; */ | |
6042 | ||
6043 | - if (!im->colorsTotal) { | |
6044 | - gdImageDestroy(im); | |
6045 | + if (! ReadOK(fd,buf,9)) { | |
6046 | return 0; | |
6047 | } | |
6048 | ||
6049 | - /* Check for open colors at the end, so | |
6050 | - we can reduce colorsTotal and ultimately | |
6051 | - BitsPerPixel */ | |
6052 | - for (i=((im->colorsTotal-1)); (i>=0); i--) { | |
6053 | + useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP); | |
6054 | + | |
6055 | + bitPixel = 1<<((buf[8]&0x07)+1); | |
6056 | + left = LM_to_uint(buf[0], buf[1]); | |
6057 | + top = LM_to_uint(buf[2], buf[3]); | |
6058 | + width = LM_to_uint(buf[4], buf[5]); | |
6059 | + height = LM_to_uint(buf[6], buf[7]); | |
6060 | + | |
6061 | + if (left + width > screen_width || top + height > screen_height) { | |
6062 | + if (VERBOSE) { | |
6063 | + printf("Frame is not confined to screen dimension.\n"); | |
6064 | + } | |
6065 | + return 0; | |
6066 | + } | |
6067 | + | |
6068 | + if (!(im = gdImageCreate(width, height))) { | |
6069 | + return 0; | |
6070 | + } | |
6071 | + im->interlace = BitSet(buf[8], INTERLACE); | |
6072 | + if (!useGlobalColormap) { | |
6073 | + if (ReadColorMap(fd, bitPixel, localColorMap)) { | |
6074 | + gdImageDestroy(im); | |
6075 | + return 0; | |
6076 | + } | |
6077 | + ReadImage(im, fd, width, height, localColorMap, | |
6078 | + BitSet(buf[8], INTERLACE), &ZeroDataBlock); | |
6079 | + } else { | |
6080 | + if (!haveGlobalColormap) { | |
6081 | + gdImageDestroy(im); | |
6082 | + return 0; | |
6083 | + } | |
6084 | + ReadImage(im, fd, width, height, | |
6085 | + ColorMap, | |
6086 | + BitSet(buf[8], INTERLACE), &ZeroDataBlock); | |
6087 | + } | |
6088 | + if (Transparent != (-1)) { | |
6089 | + gdImageColorTransparent(im, Transparent); | |
6090 | + } | |
6091 | + goto terminated; | |
6092 | + } | |
6093 | + | |
6094 | +terminated: | |
6095 | + /* Terminator before any image was declared! */ | |
6096 | + if (!im) { | |
6097 | + return 0; | |
6098 | + } | |
6099 | + if (!im->colorsTotal) { | |
6100 | + gdImageDestroy(im); | |
6101 | + return 0; | |
6102 | + } | |
6103 | + /* Check for open colors at the end, so | |
6104 | + we can reduce colorsTotal and ultimately | |
6105 | + BitsPerPixel */ | |
6106 | + for (i=((im->colorsTotal-1)); (i>=0); i--) { | |
6107 | if (im->open[i]) { | |
6108 | - im->colorsTotal--; | |
6109 | - } else { | |
6110 | - break; | |
6111 | - } | |
6112 | - } | |
6113 | - return im; | |
6114 | + im->colorsTotal--; | |
6115 | + } else { | |
6116 | + break; | |
6117 | + } | |
6118 | + } | |
6119 | + return im; | |
6120 | } | |
6121 | +/* }}} */ | |
6122 | ||
6123 | -static int | |
6124 | -ReadColorMap(gdIOCtx *fd, int number, unsigned char (*buffer)[256]) | |
6125 | +static int ReadColorMap(gdIOCtx *fd, int number, unsigned char (*buffer)[256]) /* {{{ */ | |
6126 | { | |
6127 | - int i; | |
6128 | - unsigned char rgb[3]; | |
6129 | + int i; | |
6130 | + unsigned char rgb[3]; | |
6131 | ||
6132 | ||
6133 | - for (i = 0; i < number; ++i) { | |
6134 | - if (! ReadOK(fd, rgb, sizeof(rgb))) { | |
6135 | - return TRUE; | |
6136 | - } | |
6137 | - buffer[CM_RED][i] = rgb[0] ; | |
6138 | - buffer[CM_GREEN][i] = rgb[1] ; | |
6139 | - buffer[CM_BLUE][i] = rgb[2] ; | |
6140 | - } | |
6141 | + for (i = 0; i < number; ++i) { | |
6142 | + if (! ReadOK(fd, rgb, sizeof(rgb))) { | |
6143 | + return TRUE; | |
6144 | + } | |
6145 | + buffer[CM_RED][i] = rgb[0] ; | |
6146 | + buffer[CM_GREEN][i] = rgb[1] ; | |
6147 | + buffer[CM_BLUE][i] = rgb[2] ; | |
6148 | + } | |
6149 | ||
6150 | ||
6151 | - return FALSE; | |
6152 | + return FALSE; | |
6153 | } | |
6154 | +/* }}} */ | |
6155 | ||
6156 | static int | |
6157 | -DoExtension(gdIOCtx *fd, int label, int *Transparent) | |
6158 | +DoExtension(gdIOCtx *fd, int label, int *Transparent, int *ZeroDataBlockP) | |
6159 | { | |
6160 | - static unsigned char buf[256]; | |
6161 | + unsigned char buf[256]; | |
6162 | + | |
6163 | + switch (label) { | |
6164 | + case 0xf9: /* Graphic Control Extension */ | |
6165 | + memset(buf, 0, 4); /* initialize a few bytes in the case the next function fails */ | |
6166 | + (void) GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP); | |
6167 | +#if 0 | |
6168 | + Gif89.disposal = (buf[0] >> 2) & 0x7; | |
6169 | + Gif89.inputFlag = (buf[0] >> 1) & 0x1; | |
6170 | + Gif89.delayTime = LM_to_uint(buf[1],buf[2]); | |
6171 | +#endif | |
6172 | + if ((buf[0] & 0x1) != 0) | |
6173 | + *Transparent = buf[3]; | |
6174 | ||
6175 | - switch (label) { | |
6176 | - case 0xf9: /* Graphic Control Extension */ | |
6177 | - (void) GetDataBlock(fd, (unsigned char*) buf); | |
6178 | - Gif89.disposal = (buf[0] >> 2) & 0x7; | |
6179 | - Gif89.inputFlag = (buf[0] >> 1) & 0x1; | |
6180 | - Gif89.delayTime = LM_to_uint(buf[1],buf[2]); | |
6181 | - if ((buf[0] & 0x1) != 0) | |
6182 | - *Transparent = buf[3]; | |
6183 | - | |
6184 | - while (GetDataBlock(fd, (unsigned char*) buf) > 0) | |
6185 | - ; | |
6186 | - return FALSE; | |
6187 | - default: | |
6188 | - break; | |
6189 | - } | |
6190 | - while (GetDataBlock(fd, (unsigned char*) buf) > 0) | |
6191 | - ; | |
6192 | + while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0); | |
6193 | + return FALSE; | |
6194 | + default: | |
6195 | + break; | |
6196 | + } | |
6197 | + while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0) | |
6198 | + ; | |
6199 | ||
6200 | - return FALSE; | |
6201 | + return FALSE; | |
6202 | } | |
6203 | +/* }}} */ | |
6204 | ||
6205 | static int | |
6206 | -GetDataBlock_(gdIOCtx *fd, unsigned char *buf) | |
6207 | +GetDataBlock_(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP) | |
6208 | { | |
6209 | - unsigned char count; | |
6210 | + unsigned char count; | |
6211 | ||
6212 | - if (! ReadOK(fd,&count,1)) { | |
6213 | - return -1; | |
6214 | - } | |
6215 | + if (! ReadOK(fd,&count,1)) { | |
6216 | + return -1; | |
6217 | + } | |
6218 | ||
6219 | - ZeroDataBlock = count == 0; | |
6220 | + *ZeroDataBlockP = count == 0; | |
6221 | ||
6222 | - if ((count != 0) && (! ReadOK(fd, buf, count))) { | |
6223 | - return -1; | |
6224 | - } | |
6225 | + if ((count != 0) && (! ReadOK(fd, buf, count))) { | |
6226 | + return -1; | |
6227 | + } | |
6228 | ||
6229 | - return count; | |
6230 | + return count; | |
6231 | } | |
6232 | +/* }}} */ | |
6233 | ||
6234 | static int | |
6235 | -GetDataBlock(gdIOCtx *fd, unsigned char *buf) | |
6236 | +GetDataBlock(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP) | |
6237 | { | |
6238 | int rv; | |
6239 | int i; | |
6240 | - char *tmp = NULL; | |
6241 | - | |
6242 | - rv = GetDataBlock_(fd,buf); | |
6243 | + | |
6244 | + rv = GetDataBlock_(fd,buf, ZeroDataBlockP); | |
6245 | if (VERBOSE) { | |
6246 | + char *tmp = NULL; | |
6247 | if (rv > 0) { | |
6248 | tmp = safe_emalloc(3 * rv, sizeof(char), 1); | |
6249 | for (i=0;i<rv;i++) { | |
6250 | @@ -321,281 +364,275 @@ | |
6251 | } | |
6252 | return(rv); | |
6253 | } | |
6254 | +/* }}} */ | |
6255 | ||
6256 | static int | |
6257 | -GetCode_(gdIOCtx *fd, int code_size, int flag) | |
6258 | +GetCode_(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP) | |
6259 | { | |
6260 | - static unsigned char buf[280]; | |
6261 | - static int curbit, lastbit, done, last_byte; | |
6262 | - int i, j, ret; | |
6263 | - unsigned char count; | |
6264 | - | |
6265 | - if (flag) { | |
6266 | - curbit = 0; | |
6267 | - lastbit = 0; | |
6268 | - done = FALSE; | |
6269 | - return 0; | |
6270 | - } | |
6271 | - | |
6272 | - if ( (curbit+code_size) >= lastbit) { | |
6273 | - if (done) { | |
6274 | - if (curbit >= lastbit) { | |
6275 | - /* Oh well */ | |
6276 | - } | |
6277 | - return -1; | |
6278 | - } | |
6279 | - buf[0] = buf[last_byte-2]; | |
6280 | - buf[1] = buf[last_byte-1]; | |
6281 | - | |
6282 | - if ((count = GetDataBlock(fd, &buf[2])) <= 0) | |
6283 | - done = TRUE; | |
6284 | - | |
6285 | - last_byte = 2 + count; | |
6286 | - curbit = (curbit - lastbit) + 16; | |
6287 | - lastbit = (2+count)*8 ; | |
6288 | - } | |
6289 | - | |
6290 | - ret = 0; | |
6291 | - for (i = curbit, j = 0; j < code_size; ++i, ++j) | |
6292 | - ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j; | |
6293 | + int i, j, ret; | |
6294 | + unsigned char count; | |
6295 | + | |
6296 | + if (flag) { | |
6297 | + scd->curbit = 0; | |
6298 | + scd->lastbit = 0; | |
6299 | + scd->last_byte = 0; | |
6300 | + scd->done = FALSE; | |
6301 | + return 0; | |
6302 | + } | |
6303 | + | |
6304 | + if ( (scd->curbit + code_size) >= scd->lastbit) { | |
6305 | + if (scd->done) { | |
6306 | + if (scd->curbit >= scd->lastbit) { | |
6307 | + /* Oh well */ | |
6308 | + } | |
6309 | + return -1; | |
6310 | + } | |
6311 | + scd->buf[0] = scd->buf[scd->last_byte-2]; | |
6312 | + scd->buf[1] = scd->buf[scd->last_byte-1]; | |
6313 | + | |
6314 | + if ((count = GetDataBlock(fd, &scd->buf[2], ZeroDataBlockP)) <= 0) | |
6315 | + scd->done = TRUE; | |
6316 | + | |
6317 | + scd->last_byte = 2 + count; | |
6318 | + scd->curbit = (scd->curbit - scd->lastbit) + 16; | |
6319 | + scd->lastbit = (2+count)*8 ; | |
6320 | + } | |
6321 | ||
6322 | - curbit += code_size; | |
6323 | - return ret; | |
6324 | + ret = 0; | |
6325 | + for (i = scd->curbit, j = 0; j < code_size; ++i, ++j) | |
6326 | + ret |= ((scd->buf[ i / 8 ] & (1 << (i % 8))) != 0) << j; | |
6327 | + | |
6328 | + scd->curbit += code_size; | |
6329 | + return ret; | |
6330 | } | |
6331 | ||
6332 | static int | |
6333 | -GetCode(gdIOCtx *fd, int code_size, int flag) | |
6334 | +GetCode(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP) | |
6335 | { | |
6336 | - int rv; | |
6337 | + int rv; | |
6338 | ||
6339 | - rv = GetCode_(fd,code_size,flag); | |
6340 | - if (VERBOSE) php_gd_error_ex(E_NOTICE, "[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv); | |
6341 | - return(rv); | |
6342 | + rv = GetCode_(fd, scd, code_size,flag, ZeroDataBlockP); | |
6343 | + if (VERBOSE) printf("[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv); | |
6344 | + return(rv); | |
6345 | } | |
6346 | +/* }}} */ | |
6347 | ||
6348 | -#define STACK_SIZE ((1<<(MAX_LWZ_BITS))*2) | |
6349 | static int | |
6350 | -LWZReadByte_(gdIOCtx *fd, int flag, int input_code_size) | |
6351 | +LWZReadByte_(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, int *ZeroDataBlockP) | |
6352 | { | |
6353 | - static int fresh = FALSE; | |
6354 | - int code, incode; | |
6355 | - static int code_size, set_code_size; | |
6356 | - static int max_code, max_code_size; | |
6357 | - static int firstcode, oldcode; | |
6358 | - static int clear_code, end_code; | |
6359 | - static int table[2][(1<< MAX_LWZ_BITS)]; | |
6360 | - static int stack[STACK_SIZE], *sp; | |
6361 | - register int i; | |
6362 | - | |
6363 | - if (flag) { | |
6364 | - set_code_size = input_code_size; | |
6365 | - code_size = set_code_size+1; | |
6366 | - clear_code = 1 << set_code_size ; | |
6367 | - end_code = clear_code + 1; | |
6368 | - max_code_size = 2*clear_code; | |
6369 | - max_code = clear_code+2; | |
6370 | - | |
6371 | - GetCode(fd, 0, TRUE); | |
6372 | - | |
6373 | - fresh = TRUE; | |
6374 | - | |
6375 | - for (i = 0; i < clear_code; ++i) { | |
6376 | - table[0][i] = 0; | |
6377 | - table[1][i] = i; | |
6378 | - } | |
6379 | - for (; i < (1<<MAX_LWZ_BITS); ++i) | |
6380 | - table[0][i] = table[1][0] = 0; | |
6381 | - | |
6382 | - sp = stack; | |
6383 | - | |
6384 | - return 0; | |
6385 | - } else if (fresh) { | |
6386 | - fresh = FALSE; | |
6387 | - do { | |
6388 | - firstcode = oldcode = | |
6389 | - GetCode(fd, code_size, FALSE); | |
6390 | - } while (firstcode == clear_code); | |
6391 | - return firstcode; | |
6392 | - } | |
6393 | - | |
6394 | - if (sp > stack) | |
6395 | - return *--sp; | |
6396 | - | |
6397 | - while ((code = GetCode(fd, code_size, FALSE)) >= 0) { | |
6398 | - if (code == clear_code) { | |
6399 | - for (i = 0; i < clear_code; ++i) { | |
6400 | - table[0][i] = 0; | |
6401 | - table[1][i] = i; | |
6402 | - } | |
6403 | - for (; i < (1<<MAX_LWZ_BITS); ++i) | |
6404 | - table[0][i] = table[1][i] = 0; | |
6405 | - code_size = set_code_size+1; | |
6406 | - max_code_size = 2*clear_code; | |
6407 | - max_code = clear_code+2; | |
6408 | - sp = stack; | |
6409 | - firstcode = oldcode = | |
6410 | - GetCode(fd, code_size, FALSE); | |
6411 | - return firstcode; | |
6412 | - } else if (code == end_code) { | |
6413 | - int count; | |
6414 | - unsigned char buf[260]; | |
6415 | - | |
6416 | - if (ZeroDataBlock) | |
6417 | - return -2; | |
6418 | - | |
6419 | - while ((count = GetDataBlock(fd, buf)) > 0) | |
6420 | - ; | |
6421 | - | |
6422 | - if (count != 0) | |
6423 | - return -2; | |
6424 | - } | |
6425 | - | |
6426 | - incode = code; | |
6427 | - | |
6428 | - if (sp == (stack + STACK_SIZE)) { | |
6429 | - /* Bad compressed data stream */ | |
6430 | - return -1; | |
6431 | - } | |
6432 | - | |
6433 | - if (code >= max_code) { | |
6434 | - *sp++ = firstcode; | |
6435 | - code = oldcode; | |
6436 | - } | |
6437 | - | |
6438 | - while (code >= clear_code) { | |
6439 | - if (sp == (stack + STACK_SIZE)) { | |
6440 | - /* Bad compressed data stream */ | |
6441 | - return -1; | |
6442 | - } | |
6443 | - *sp++ = table[1][code]; | |
6444 | - if (code == table[0][code]) { | |
6445 | - /* Oh well */ | |
6446 | - } | |
6447 | - code = table[0][code]; | |
6448 | - } | |
6449 | - | |
6450 | - *sp++ = firstcode = table[1][code]; | |
6451 | - | |
6452 | - if ((code = max_code) <(1<<MAX_LWZ_BITS)) { | |
6453 | - table[0][code] = oldcode; | |
6454 | - table[1][code] = firstcode; | |
6455 | - ++max_code; | |
6456 | - if ((max_code >= max_code_size) && | |
6457 | - (max_code_size < (1<<MAX_LWZ_BITS))) { | |
6458 | - max_code_size *= 2; | |
6459 | - ++code_size; | |
6460 | - } | |
6461 | - } | |
6462 | - | |
6463 | - oldcode = incode; | |
6464 | - | |
6465 | - if (sp > stack) | |
6466 | - return *--sp; | |
6467 | - } | |
6468 | - return code; | |
6469 | + int code, incode, i; | |
6470 | + | |
6471 | + if (flag) { | |
6472 | + sd->set_code_size = input_code_size; | |
6473 | + sd->code_size = sd->set_code_size+1; | |
6474 | + sd->clear_code = 1 << sd->set_code_size ; | |
6475 | + sd->end_code = sd->clear_code + 1; | |
6476 | + sd->max_code_size = 2*sd->clear_code; | |
6477 | + sd->max_code = sd->clear_code+2; | |
6478 | + | |
6479 | + GetCode(fd, &sd->scd, 0, TRUE, ZeroDataBlockP); | |
6480 | + | |
6481 | + sd->fresh = TRUE; | |
6482 | + | |
6483 | + for (i = 0; i < sd->clear_code; ++i) { | |
6484 | + sd->table[0][i] = 0; | |
6485 | + sd->table[1][i] = i; | |
6486 | + } | |
6487 | + for (; i < (1<<MAX_LWZ_BITS); ++i) | |
6488 | + sd->table[0][i] = sd->table[1][0] = 0; | |
6489 | + | |
6490 | + sd->sp = sd->stack; | |
6491 | + | |
6492 | + return 0; | |
6493 | + } else if (sd->fresh) { | |
6494 | + sd->fresh = FALSE; | |
6495 | + do { | |
6496 | + sd->firstcode = sd->oldcode = | |
6497 | + GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP); | |
6498 | + } while (sd->firstcode == sd->clear_code); | |
6499 | + return sd->firstcode; | |
6500 | + } | |
6501 | + | |
6502 | + if (sd->sp > sd->stack) | |
6503 | + return *--sd->sp; | |
6504 | + | |
6505 | + while ((code = GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP)) >= 0) { | |
6506 | + if (code == sd->clear_code) { | |
6507 | + for (i = 0; i < sd->clear_code; ++i) { | |
6508 | + sd->table[0][i] = 0; | |
6509 | + sd->table[1][i] = i; | |
6510 | + } | |
6511 | + for (; i < (1<<MAX_LWZ_BITS); ++i) | |
6512 | + sd->table[0][i] = sd->table[1][i] = 0; | |
6513 | + sd->code_size = sd->set_code_size+1; | |
6514 | + sd->max_code_size = 2*sd->clear_code; | |
6515 | + sd->max_code = sd->clear_code+2; | |
6516 | + sd->sp = sd->stack; | |
6517 | + sd->firstcode = sd->oldcode = | |
6518 | + GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP); | |
6519 | + return sd->firstcode; | |
6520 | + } else if (code == sd->end_code) { | |
6521 | + int count; | |
6522 | + unsigned char buf[260]; | |
6523 | + | |
6524 | + if (*ZeroDataBlockP) | |
6525 | + return -2; | |
6526 | + | |
6527 | + while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0) | |
6528 | + ; | |
6529 | + | |
6530 | + if (count != 0) | |
6531 | + return -2; | |
6532 | + } | |
6533 | + | |
6534 | + incode = code; | |
6535 | + | |
6536 | + if (sd->sp == (sd->stack + STACK_SIZE)) { | |
6537 | + /* Bad compressed data stream */ | |
6538 | + return -1; | |
6539 | + } | |
6540 | + | |
6541 | + if (code >= sd->max_code) { | |
6542 | + *sd->sp++ = sd->firstcode; | |
6543 | + code = sd->oldcode; | |
6544 | + } | |
6545 | + | |
6546 | + while (code >= sd->clear_code) { | |
6547 | + if (sd->sp == (sd->stack + STACK_SIZE)) { | |
6548 | + /* Bad compressed data stream */ | |
6549 | + return -1; | |
6550 | + } | |
6551 | + *sd->sp++ = sd->table[1][code]; | |
6552 | + if (code == sd->table[0][code]) { | |
6553 | + /* Oh well */ | |
6554 | + } | |
6555 | + code = sd->table[0][code]; | |
6556 | + } | |
6557 | + | |
6558 | + *sd->sp++ = sd->firstcode = sd->table[1][code]; | |
6559 | + | |
6560 | + if ((code = sd->max_code) <(1<<MAX_LWZ_BITS)) { | |
6561 | + sd->table[0][code] = sd->oldcode; | |
6562 | + sd->table[1][code] = sd->firstcode; | |
6563 | + ++sd->max_code; | |
6564 | + if ((sd->max_code >= sd->max_code_size) && | |
6565 | + (sd->max_code_size < (1<<MAX_LWZ_BITS))) { | |
6566 | + sd->max_code_size *= 2; | |
6567 | + ++sd->code_size; | |
6568 | + } | |
6569 | + } | |
6570 | + | |
6571 | + sd->oldcode = incode; | |
6572 | + | |
6573 | + if (sd->sp > sd->stack) | |
6574 | + return *--sd->sp; | |
6575 | + } | |
6576 | + return code; | |
6577 | } | |
6578 | +/* }}} */ | |
6579 | ||
6580 | static int | |
6581 | -LWZReadByte(gdIOCtx *fd, int flag, int input_code_size) | |
6582 | +LWZReadByte(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, int *ZeroDataBlockP) | |
6583 | { | |
6584 | - int rv; | |
6585 | + int rv; | |
6586 | ||
6587 | - rv = LWZReadByte_(fd,flag,input_code_size); | |
6588 | - if (VERBOSE) php_gd_error_ex(E_NOTICE, "[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv); | |
6589 | - return(rv); | |
6590 | + rv = LWZReadByte_(fd, sd, flag, input_code_size, ZeroDataBlockP); | |
6591 | + if (VERBOSE) printf("[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv); | |
6592 | + return(rv); | |
6593 | } | |
6594 | +/* }}} */ | |
6595 | ||
6596 | static void | |
6597 | -ReadImage(gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace) /*1.4//, int ignore) */ | |
6598 | +ReadImage(gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace, int *ZeroDataBlockP) /*1.4//, int ignore) */ | |
6599 | { | |
6600 | - unsigned char c; | |
6601 | - int v; | |
6602 | - int xpos = 0, ypos = 0, pass = 0; | |
6603 | - int i; | |
6604 | - | |
6605 | - /* | |
6606 | - ** Initialize the Compression routines | |
6607 | - */ | |
6608 | - if (! ReadOK(fd,&c,1)) { | |
6609 | - return; | |
6610 | - } | |
6611 | - | |
6612 | - if (c > MAX_LWZ_BITS) { | |
6613 | - return; | |
6614 | - } | |
6615 | - | |
6616 | - | |
6617 | - /* Stash the color map into the image */ | |
6618 | - for (i=0; (i<gdMaxColors); i++) { | |
6619 | - im->red[i] = cmap[CM_RED][i]; | |
6620 | - im->green[i] = cmap[CM_GREEN][i]; | |
6621 | - im->blue[i] = cmap[CM_BLUE][i]; | |
6622 | - im->open[i] = 1; | |
6623 | - } | |
6624 | - /* Many (perhaps most) of these colors will remain marked open. */ | |
6625 | - im->colorsTotal = gdMaxColors; | |
6626 | - | |
6627 | - if (LWZReadByte(fd, TRUE, c) < 0) { | |
6628 | - return; | |
6629 | - } | |
6630 | - | |
6631 | - /* | |
6632 | - ** If this is an "uninteresting picture" ignore it. | |
6633 | - ** REMOVED For 1.4 | |
6634 | - */ | |
6635 | - /*if (ignore) { */ | |
6636 | - /* while (LWZReadByte(fd, FALSE, c) >= 0) */ | |
6637 | - /* ; */ | |
6638 | - /* return; */ | |
6639 | - /*} */ | |
6640 | - | |
6641 | - while ((v = LWZReadByte(fd,FALSE,c)) >= 0 ) { | |
6642 | - if (v >= gdMaxColors) { | |
6643 | - v = 0; | |
6644 | + unsigned char c; | |
6645 | + int v; | |
6646 | + int xpos = 0, ypos = 0, pass = 0; | |
6647 | + int i; | |
6648 | + LZW_STATIC_DATA sd; | |
6649 | + | |
6650 | + | |
6651 | + /* | |
6652 | + ** Initialize the Compression routines | |
6653 | + */ | |
6654 | + if (! ReadOK(fd,&c,1)) { | |
6655 | + return; | |
6656 | + } | |
6657 | + | |
6658 | + if (c > MAX_LWZ_BITS) { | |
6659 | + return; | |
6660 | + } | |
6661 | + | |
6662 | + /* Stash the color map into the image */ | |
6663 | + for (i=0; (i<gdMaxColors); i++) { | |
6664 | + im->red[i] = cmap[CM_RED][i]; | |
6665 | + im->green[i] = cmap[CM_GREEN][i]; | |
6666 | + im->blue[i] = cmap[CM_BLUE][i]; | |
6667 | + im->open[i] = 1; | |
6668 | + } | |
6669 | + /* Many (perhaps most) of these colors will remain marked open. */ | |
6670 | + im->colorsTotal = gdMaxColors; | |
6671 | + if (LWZReadByte(fd, &sd, TRUE, c, ZeroDataBlockP) < 0) { | |
6672 | + return; | |
6673 | + } | |
6674 | + | |
6675 | + /* | |
6676 | + ** If this is an "uninteresting picture" ignore it. | |
6677 | + ** REMOVED For 1.4 | |
6678 | + */ | |
6679 | + /*if (ignore) { */ | |
6680 | + /* while (LWZReadByte(fd, &sd, FALSE, c) >= 0) */ | |
6681 | + /* ; */ | |
6682 | + /* return; */ | |
6683 | + /*} */ | |
6684 | + | |
6685 | + while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0) { | |
6686 | + if (v >= gdMaxColors) { | |
6687 | + v = 0; | |
6688 | + } | |
6689 | + /* This how we recognize which colors are actually used. */ | |
6690 | + if (im->open[v]) { | |
6691 | + im->open[v] = 0; | |
6692 | + } | |
6693 | + gdImageSetPixel(im, xpos, ypos, v); | |
6694 | + ++xpos; | |
6695 | + if (xpos == len) { | |
6696 | + xpos = 0; | |
6697 | + if (interlace) { | |
6698 | + switch (pass) { | |
6699 | + case 0: | |
6700 | + case 1: | |
6701 | + ypos += 8; break; | |
6702 | + case 2: | |
6703 | + ypos += 4; break; | |
6704 | + case 3: | |
6705 | + ypos += 2; break; | |
6706 | } | |
6707 | - /* This how we recognize which colors are actually used. */ | |
6708 | - if (im->open[v]) { | |
6709 | - im->open[v] = 0; | |
6710 | - } | |
6711 | - gdImageSetPixel(im, xpos, ypos, v); | |
6712 | - ++xpos; | |
6713 | - if (xpos == len) { | |
6714 | - xpos = 0; | |
6715 | - if (interlace) { | |
6716 | - switch (pass) { | |
6717 | - case 0: | |
6718 | - case 1: | |
6719 | - ypos += 8; break; | |
6720 | - case 2: | |
6721 | - ypos += 4; break; | |
6722 | - case 3: | |
6723 | - ypos += 2; break; | |
6724 | - } | |
6725 | - | |
6726 | - if (ypos >= height) { | |
6727 | - ++pass; | |
6728 | - switch (pass) { | |
6729 | - case 1: | |
6730 | - ypos = 4; break; | |
6731 | - case 2: | |
6732 | - ypos = 2; break; | |
6733 | - case 3: | |
6734 | - ypos = 1; break; | |
6735 | - default: | |
6736 | - goto fini; | |
6737 | - } | |
6738 | - } | |
6739 | - } else { | |
6740 | - ++ypos; | |
6741 | - } | |
6742 | - } | |
6743 | - if (ypos >= height) | |
6744 | - break; | |
6745 | - } | |
6746 | + | |
6747 | + if (ypos >= height) { | |
6748 | + ++pass; | |
6749 | + switch (pass) { | |
6750 | + case 1: | |
6751 | + ypos = 4; break; | |
6752 | + case 2: | |
6753 | + ypos = 2; break; | |
6754 | + case 3: | |
6755 | + ypos = 1; break; | |
6756 | + default: | |
6757 | + goto fini; | |
6758 | + } | |
6759 | + } | |
6760 | + } else { | |
6761 | + ++ypos; | |
6762 | + } | |
6763 | + } | |
6764 | + if (ypos >= height) | |
6765 | + break; | |
6766 | + } | |
6767 | ||
6768 | fini: | |
6769 | - if (LWZReadByte(fd,FALSE,c)>=0) { | |
6770 | - /* Ignore extra */ | |
6771 | - } | |
6772 | + if (LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP) >=0) { | |
6773 | + /* Ignore extra */ | |
6774 | + } | |
6775 | } | |
6776 | - | |
6777 | +/* }}} */ | |
6778 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_gif_out.c php-4.4.8/ext/gd/libgd/gd_gif_out.c | |
6779 | --- php-4.4.8.org/ext/gd/libgd/gd_gif_out.c 2004-07-23 01:09:24.000000000 +0200 | |
6780 | +++ php-4.4.8/ext/gd/libgd/gd_gif_out.c 2006-07-26 12:03:09.000000000 +0200 | |
6781 | @@ -133,7 +133,7 @@ | |
6782 | BitsPerPixel = colorstobpp(tim->colorsTotal); | |
6783 | /* All set, let's do it. */ | |
6784 | GIFEncode( | |
6785 | - out, tim->sx, tim->sy, interlace, 0, transparent, BitsPerPixel, | |
6786 | + out, tim->sx, tim->sy, tim->interlace, 0, tim->transparent, BitsPerPixel, | |
6787 | tim->red, tim->green, tim->blue, tim); | |
6788 | if (pim) { | |
6789 | /* Destroy palette based temporary image. */ | |
6790 | @@ -264,10 +264,12 @@ | |
6791 | int ColorMapSize; | |
6792 | int InitCodeSize; | |
6793 | int i; | |
6794 | - GifCtx ctx; | |
6795 | + GifCtx ctx; | |
6796 | + | |
6797 | + memset(&ctx, 0, sizeof(ctx)); | |
6798 | ctx.Interlace = GInterlace; | |
6799 | - ctx.in_count = 1; | |
6800 | - memset(&ctx, 0, sizeof(ctx)); | |
6801 | + ctx.in_count = 1; | |
6802 | + | |
6803 | ColorMapSize = 1 << BitsPerPixel; | |
6804 | ||
6805 | RWidth = ctx.Width = GWidth; | |
6806 | diff -urN php-4.4.8.org/ext/gd/libgd/gd.h php-4.4.8/ext/gd/libgd/gd.h | |
6807 | --- php-4.4.8.org/ext/gd/libgd/gd.h 2004-07-23 01:09:24.000000000 +0200 | |
6808 | +++ php-4.4.8/ext/gd/libgd/gd.h 2007-09-12 01:34:25.000000000 +0200 | |
6809 | @@ -5,14 +5,30 @@ | |
6810 | extern "C" { | |
6811 | #endif | |
6812 | ||
6813 | -#ifndef WIN32 | |
6814 | -/* default fontpath for unix systems */ | |
6815 | -#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:." | |
6816 | -#define PATHSEPARATOR ":" | |
6817 | -#else | |
6818 | +#ifdef HAVE_CONFIG_H | |
6819 | +#include "config.h" | |
6820 | +#endif | |
6821 | + | |
6822 | +#include "php_compat.h" | |
6823 | + | |
6824 | +#define GD_MAJOR_VERSION 2 | |
6825 | +#define GD_MINOR_VERSION 0 | |
6826 | +#define GD_RELEASE_VERSION 35 | |
6827 | +#define GD_EXTRA_VERSION "" | |
6828 | +#define GD_VERSION_STRING "2.0.35" | |
6829 | + | |
6830 | +#ifdef NETWARE | |
6831 | +/* default fontpath for netware systems */ | |
6832 | +#define DEFAULT_FONTPATH "sys:/java/nwgfx/lib/x11/fonts/ttf;." | |
6833 | +#define PATHSEPARATOR ";" | |
6834 | +#elif defined(WIN32) | |
6835 | /* default fontpath for windows systems */ | |
6836 | #define DEFAULT_FONTPATH "c:\\winnt\\fonts;c:\\windows\\fonts;." | |
6837 | #define PATHSEPARATOR ";" | |
6838 | +#else | |
6839 | +/* default fontpath for unix systems */ | |
6840 | +#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:." | |
6841 | +#define PATHSEPARATOR ":" | |
6842 | #endif | |
6843 | ||
6844 | /* gd.h: declarations file for the graphic-draw module. | |
6845 | @@ -231,8 +247,8 @@ | |
6846 | gdImagePtr gdImageCreateFromPngCtx(gdIOCtxPtr in); | |
6847 | gdImagePtr gdImageCreateFromWBMP(FILE *inFile); | |
6848 | gdImagePtr gdImageCreateFromWBMPCtx(gdIOCtx *infile); | |
6849 | -gdImagePtr gdImageCreateFromJpeg(FILE *infile); | |
6850 | -gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile); | |
6851 | +gdImagePtr gdImageCreateFromJpeg(FILE *infile, int ignore_warning); | |
6852 | +gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile, int ignore_warning); | |
6853 | ||
6854 | /* A custom data source. */ | |
6855 | /* The source function must return -1 on error, otherwise the number | |
6856 | @@ -295,6 +311,14 @@ | |
6857 | void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color); | |
6858 | void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color); | |
6859 | ||
6860 | +/* | |
6861 | + * The following functions are required to be called prior to the | |
6862 | + * use of any sort of threads in a module load / shutdown function | |
6863 | + * respectively. | |
6864 | + */ | |
6865 | +void gdFontCacheMutexSetup(); | |
6866 | +void gdFontCacheMutexShutdown(); | |
6867 | + | |
6868 | /* 2.0.16: for thread-safe use of gdImageStringFT and friends, | |
6869 | * call this before allowing any thread to call gdImageStringFT. | |
6870 | * Otherwise it is invoked by the first thread to invoke | |
6871 | @@ -438,8 +462,8 @@ | |
6872 | * compression (smallest files) but takes a long time to compress, and | |
6873 | * -1 selects the default compiled into the zlib library. | |
6874 | */ | |
6875 | -void gdImagePngEx(gdImagePtr im, FILE * out, int level); | |
6876 | -void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level); | |
6877 | +void gdImagePngEx(gdImagePtr im, FILE * out, int level, int basefilter); | |
6878 | +void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level, int basefilter); | |
6879 | ||
6880 | void gdImageWBMP(gdImagePtr image, int fg, FILE *out); | |
6881 | void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out); | |
6882 | @@ -483,7 +507,7 @@ | |
6883 | ||
6884 | /* Best to free this memory with gdFree(), not free() */ | |
6885 | void* gdImageGdPtr(gdImagePtr im, int *size); | |
6886 | -void *gdImagePngPtrEx(gdImagePtr im, int *size, int level); | |
6887 | +void *gdImagePngPtrEx(gdImagePtr im, int *size, int level, int basefilter); | |
6888 | ||
6889 | /* Best to free this memory with gdFree(), not free() */ | |
6890 | void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size); | |
6891 | @@ -534,11 +558,11 @@ | |
6892 | substituted automatically. */ | |
6893 | void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH); | |
6894 | ||
6895 | -gdImagePtr gdImageRotate90(gdImagePtr src); | |
6896 | -gdImagePtr gdImageRotate180(gdImagePtr src); | |
6897 | -gdImagePtr gdImageRotate270(gdImagePtr src); | |
6898 | -gdImagePtr gdImageRotate45(gdImagePtr src, double dAngle, int clrBack); | |
6899 | -gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack); | |
6900 | +gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent); | |
6901 | +gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent); | |
6902 | +gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent); | |
6903 | +gdImagePtr gdImageRotate45(gdImagePtr src, double dAngle, int clrBack, int ignoretransparent); | |
6904 | +gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent); | |
6905 | ||
6906 | void gdImageSetBrush(gdImagePtr im, gdImagePtr brush); | |
6907 | void gdImageSetTile(gdImagePtr im, gdImagePtr tile); | |
6908 | @@ -619,7 +643,7 @@ | |
6909 | int gdImageContrast(gdImagePtr src, double contrast); | |
6910 | ||
6911 | /* Simply adds or substracts respectively red, green or blue to a pixel */ | |
6912 | -int gdImageColor(gdImagePtr src, int red, int green, int blue); | |
6913 | +int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha); | |
6914 | ||
6915 | /* Image convolution by a 3x3 custom matrix */ | |
6916 | int gdImageConvolution(gdImagePtr src, float ft[3][3], float filter_div, float offset); | |
6917 | diff -urN php-4.4.8.org/ext/gd/libgd/gdhelpers.h php-4.4.8/ext/gd/libgd/gdhelpers.h | |
6918 | --- php-4.4.8.org/ext/gd/libgd/gdhelpers.h 2007-03-10 14:06:37.000000000 +0100 | |
6919 | +++ php-4.4.8/ext/gd/libgd/gdhelpers.h 2007-03-10 13:18:36.000000000 +0100 | |
6920 | @@ -1,4 +1,4 @@ | |
6921 | -#ifndef GDHELPERS_H | |
6922 | +#ifndef GDHELPERS_H | |
6923 | #define GDHELPERS_H 1 | |
6924 | ||
6925 | #include <sys/types.h> | |
6926 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_io.c php-4.4.8/ext/gd/libgd/gd_io.c | |
6927 | --- php-4.4.8.org/ext/gd/libgd/gd_io.c 2003-12-25 23:33:03.000000000 +0100 | |
6928 | +++ php-4.4.8/ext/gd/libgd/gd_io.c 2005-08-18 14:54:43.000000000 +0200 | |
6929 | @@ -23,153 +23,124 @@ | |
6930 | #define IO_DBG(s) | |
6931 | ||
6932 | ||
6933 | +#define GD_IO_EOF_CHK(r) \ | |
6934 | + if (r == EOF) { \ | |
6935 | + return 0; \ | |
6936 | + } \ | |
6937 | + | |
6938 | /* | |
6939 | * Write out a word to the I/O context pointer | |
6940 | */ | |
6941 | -void | |
6942 | -Putword (int w, gdIOCtx * ctx) | |
6943 | +void Putword (int w, gdIOCtx * ctx) | |
6944 | { | |
6945 | - unsigned char buf[2]; | |
6946 | - buf[0] = w & 0xff; | |
6947 | - buf[1] = (w / 256) & 0xff; | |
6948 | - (ctx->putBuf) (ctx, (char *) buf, 2); | |
6949 | + unsigned char buf[2]; | |
6950 | + | |
6951 | + buf[0] = w & 0xff; | |
6952 | + buf[1] = (w / 256) & 0xff; | |
6953 | + (ctx->putBuf) (ctx, (char *) buf, 2); | |
6954 | } | |
6955 | ||
6956 | -void | |
6957 | -Putchar (int c, gdIOCtx * ctx) | |
6958 | +void Putchar (int c, gdIOCtx * ctx) | |
6959 | { | |
6960 | - (ctx->putC) (ctx, c & 0xff); | |
6961 | + (ctx->putC) (ctx, c & 0xff); | |
6962 | } | |
6963 | ||
6964 | -void | |
6965 | -gdPutC (const unsigned char c, gdIOCtx * ctx) | |
6966 | +void gdPutC (const unsigned char c, gdIOCtx * ctx) | |
6967 | { | |
6968 | - (ctx->putC) (ctx, c); | |
6969 | + (ctx->putC) (ctx, c); | |
6970 | } | |
6971 | ||
6972 | -void | |
6973 | -gdPutWord (int w, gdIOCtx * ctx) | |
6974 | +void gdPutWord (int w, gdIOCtx * ctx) | |
6975 | { | |
6976 | - IO_DBG (printf ("Putting word...\n")); | |
6977 | - (ctx->putC) (ctx, (unsigned char) (w >> 8)); | |
6978 | - (ctx->putC) (ctx, (unsigned char) (w & 0xFF)); | |
6979 | - IO_DBG (printf ("put.\n")); | |
6980 | + IO_DBG (php_gd_error("Putting word...")); | |
6981 | + (ctx->putC) (ctx, (unsigned char) (w >> 8)); | |
6982 | + (ctx->putC) (ctx, (unsigned char) (w & 0xFF)); | |
6983 | + IO_DBG (php_gd_error("put.")); | |
6984 | } | |
6985 | ||
6986 | -void | |
6987 | -gdPutInt (int w, gdIOCtx * ctx) | |
6988 | +void gdPutInt (int w, gdIOCtx * ctx) | |
6989 | { | |
6990 | - IO_DBG (printf ("Putting int...\n")); | |
6991 | - (ctx->putC) (ctx, (unsigned char) (w >> 24)); | |
6992 | - (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF)); | |
6993 | - (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF)); | |
6994 | - (ctx->putC) (ctx, (unsigned char) (w & 0xFF)); | |
6995 | - IO_DBG (printf ("put.\n")); | |
6996 | + IO_DBG (php_gd_error("Putting int...")); | |
6997 | + (ctx->putC) (ctx, (unsigned char) (w >> 24)); | |
6998 | + (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF)); | |
6999 | + (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF)); | |
7000 | + (ctx->putC) (ctx, (unsigned char) (w & 0xFF)); | |
7001 | + IO_DBG (php_gd_error("put.")); | |
7002 | } | |
7003 | ||
7004 | -int | |
7005 | -gdGetC (gdIOCtx * ctx) | |
7006 | +int gdGetC (gdIOCtx * ctx) | |
7007 | { | |
7008 | - return ((ctx->getC) (ctx)); | |
7009 | + return ((ctx->getC) (ctx)); | |
7010 | } | |
7011 | ||
7012 | - | |
7013 | - | |
7014 | -int | |
7015 | -gdGetByte (int *result, gdIOCtx * ctx) | |
7016 | +int gdGetByte (int *result, gdIOCtx * ctx) | |
7017 | { | |
7018 | - int r; | |
7019 | - r = (ctx->getC) (ctx); | |
7020 | - if (r == EOF) | |
7021 | - { | |
7022 | - return 0; | |
7023 | - } | |
7024 | - *result = r; | |
7025 | - return 1; | |
7026 | + int r; | |
7027 | + r = (ctx->getC) (ctx); | |
7028 | + GD_IO_EOF_CHK(r); | |
7029 | + *result = r; | |
7030 | + return 1; | |
7031 | } | |
7032 | ||
7033 | -int | |
7034 | -gdGetWord (int *result, gdIOCtx * ctx) | |
7035 | +int gdGetWord (int *result, gdIOCtx * ctx) | |
7036 | { | |
7037 | - int r; | |
7038 | - r = (ctx->getC) (ctx); | |
7039 | - if (r == EOF) | |
7040 | - { | |
7041 | - return 0; | |
7042 | - } | |
7043 | - *result = r << 8; | |
7044 | - r = (ctx->getC) (ctx); | |
7045 | - if (r == EOF) | |
7046 | - { | |
7047 | - return 0; | |
7048 | - } | |
7049 | - *result += r; | |
7050 | - return 1; | |
7051 | + int r; | |
7052 | + r = (ctx->getC) (ctx); | |
7053 | + GD_IO_EOF_CHK(r); | |
7054 | + *result = r << 8; | |
7055 | + r = (ctx->getC) (ctx); | |
7056 | + GD_IO_EOF_CHK(r); | |
7057 | + *result += r; | |
7058 | + return 1; | |
7059 | } | |
7060 | ||
7061 | ||
7062 | -int | |
7063 | -gdGetInt (int *result, gdIOCtx * ctx) | |
7064 | +int gdGetInt (int *result, gdIOCtx * ctx) | |
7065 | { | |
7066 | - int r; | |
7067 | - r = (ctx->getC) (ctx); | |
7068 | - if (r == EOF) | |
7069 | - { | |
7070 | - return 0; | |
7071 | - } | |
7072 | - *result = r << 24; | |
7073 | + int r; | |
7074 | + r = (ctx->getC) (ctx); | |
7075 | + GD_IO_EOF_CHK(r); | |
7076 | + *result = r << 24; | |
7077 | ||
7078 | - r = (ctx->getC) (ctx); | |
7079 | - if (r == EOF) | |
7080 | - { | |
7081 | - return 0; | |
7082 | - } | |
7083 | - *result += r << 16; | |
7084 | + r = (ctx->getC) (ctx); | |
7085 | + GD_IO_EOF_CHK(r); | |
7086 | + *result += r << 16; | |
7087 | ||
7088 | - r = (ctx->getC) (ctx); | |
7089 | - if (r == EOF) | |
7090 | - { | |
7091 | - return 0; | |
7092 | - } | |
7093 | - *result += r << 8; | |
7094 | + r = (ctx->getC) (ctx); | |
7095 | + if (r == EOF) { | |
7096 | + return 0; | |
7097 | + } | |
7098 | + *result += r << 8; | |
7099 | ||
7100 | - r = (ctx->getC) (ctx); | |
7101 | - if (r == EOF) | |
7102 | - { | |
7103 | - return 0; | |
7104 | - } | |
7105 | - *result += r; | |
7106 | + r = (ctx->getC) (ctx); | |
7107 | + GD_IO_EOF_CHK(r); | |
7108 | + *result += r; | |
7109 | ||
7110 | - return 1; | |
7111 | + return 1; | |
7112 | } | |
7113 | ||
7114 | -int | |
7115 | -gdPutBuf (const void *buf, int size, gdIOCtx * ctx) | |
7116 | +int gdPutBuf (const void *buf, int size, gdIOCtx * ctx) | |
7117 | { | |
7118 | - IO_DBG (printf ("Putting buf...\n")); | |
7119 | - return (ctx->putBuf) (ctx, buf, size); | |
7120 | - IO_DBG (printf ("put.\n")); | |
7121 | + IO_DBG (php_gd_error("Putting buf...")); | |
7122 | + return (ctx->putBuf) (ctx, buf, size); | |
7123 | + IO_DBG (php_gd_error("put.")); | |
7124 | } | |
7125 | ||
7126 | -int | |
7127 | -gdGetBuf (void *buf, int size, gdIOCtx * ctx) | |
7128 | +int gdGetBuf (void *buf, int size, gdIOCtx * ctx) | |
7129 | { | |
7130 | - return (ctx->getBuf) (ctx, buf, size); | |
7131 | + return (ctx->getBuf) (ctx, buf, size); | |
7132 | } | |
7133 | ||
7134 | - | |
7135 | -int | |
7136 | -gdSeek (gdIOCtx * ctx, const int pos) | |
7137 | +int gdSeek (gdIOCtx * ctx, const int pos) | |
7138 | { | |
7139 | - IO_DBG (printf ("Seeking...\n")); | |
7140 | - return ((ctx->seek) (ctx, pos)); | |
7141 | - IO_DBG (printf ("Done.\n")); | |
7142 | + IO_DBG (php_gd_error("Seeking...")); | |
7143 | + return ((ctx->seek) (ctx, pos)); | |
7144 | + IO_DBG (php_gd_error("Done.")); | |
7145 | } | |
7146 | ||
7147 | -long | |
7148 | -gdTell (gdIOCtx * ctx) | |
7149 | +long gdTell (gdIOCtx * ctx) | |
7150 | { | |
7151 | - IO_DBG (printf ("Telling...\n")); | |
7152 | - return ((ctx->tell) (ctx)); | |
7153 | - IO_DBG (printf ("told.\n")); | |
7154 | + IO_DBG (php_gd_error("Telling...")); | |
7155 | + return ((ctx->tell) (ctx)); | |
7156 | + IO_DBG (php_gd_error ("told.")); | |
7157 | } | |
7158 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_io_dp.c php-4.4.8/ext/gd/libgd/gd_io_dp.c | |
7159 | --- php-4.4.8.org/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:21:00.000000000 +0200 | |
7160 | +++ php-4.4.8/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:20:33.000000000 +0200 | |
7161 | @@ -27,26 +27,23 @@ | |
7162 | ||
7163 | /* this is used for creating images in main memory */ | |
7164 | typedef struct dpStruct | |
7165 | - { | |
7166 | - void *data; | |
7167 | - int logicalSize; | |
7168 | - int realSize; | |
7169 | - int dataGood; | |
7170 | - int pos; | |
7171 | - int freeOK; | |
7172 | - } | |
7173 | -dynamicPtr; | |
7174 | +{ | |
7175 | + void *data; | |
7176 | + int logicalSize; | |
7177 | + int realSize; | |
7178 | + int dataGood; | |
7179 | + int pos; | |
7180 | + int freeOK; | |
7181 | +} dynamicPtr; | |
7182 | ||
7183 | typedef struct dpIOCtx | |
7184 | - { | |
7185 | - gdIOCtx ctx; | |
7186 | - dynamicPtr *dp; | |
7187 | - } | |
7188 | -dpIOCtx; | |
7189 | +{ | |
7190 | + gdIOCtx ctx; | |
7191 | + dynamicPtr *dp; | |
7192 | +} dpIOCtx; | |
7193 | ||
7194 | typedef struct dpIOCtx *dpIOCtxPtr; | |
7195 | ||
7196 | - | |
7197 | /* these functions operate on in-memory dynamic pointers */ | |
7198 | static int allocDynamic (dynamicPtr * dp, int initialSize, void *data); | |
7199 | static int appendDynamic (dynamicPtr * dp, const void *src, int size); | |
7200 | @@ -65,166 +62,136 @@ | |
7201 | static long dynamicTell (struct gdIOCtx *); | |
7202 | ||
7203 | /* return data as a dynamic pointer */ | |
7204 | -gdIOCtx * | |
7205 | -gdNewDynamicCtx (int initialSize, void *data) | |
7206 | +gdIOCtx * gdNewDynamicCtx (int initialSize, void *data) | |
7207 | { | |
7208 | - return gdNewDynamicCtxEx(initialSize, data, 1); | |
7209 | + return gdNewDynamicCtxEx(initialSize, data, 1); | |
7210 | } | |
7211 | - | |
7212 | + | |
7213 | gdIOCtx * gdNewDynamicCtxEx (int initialSize, void *data, int freeOKFlag) | |
7214 | { | |
7215 | - dpIOCtx *ctx; | |
7216 | - dynamicPtr *dp; | |
7217 | + dpIOCtx *ctx; | |
7218 | + dynamicPtr *dp; | |
7219 | ||
7220 | - ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx)); | |
7221 | - if (ctx == NULL) | |
7222 | - { | |
7223 | - return NULL; | |
7224 | - } | |
7225 | + ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx)); | |
7226 | ||
7227 | - dp = newDynamic (initialSize, data, freeOKFlag); | |
7228 | - if (!dp) | |
7229 | - { | |
7230 | - gdFree (ctx); | |
7231 | - return NULL; | |
7232 | - }; | |
7233 | + dp = newDynamic(initialSize, data, freeOKFlag); | |
7234 | ||
7235 | - ctx->dp = dp; | |
7236 | + ctx->dp = dp; | |
7237 | ||
7238 | - ctx->ctx.getC = dynamicGetchar; | |
7239 | - ctx->ctx.putC = dynamicPutchar; | |
7240 | + ctx->ctx.getC = dynamicGetchar; | |
7241 | + ctx->ctx.putC = dynamicPutchar; | |
7242 | ||
7243 | - ctx->ctx.getBuf = dynamicGetbuf; | |
7244 | - ctx->ctx.putBuf = dynamicPutbuf; | |
7245 | + ctx->ctx.getBuf = dynamicGetbuf; | |
7246 | + ctx->ctx.putBuf = dynamicPutbuf; | |
7247 | ||
7248 | - ctx->ctx.seek = dynamicSeek; | |
7249 | - ctx->ctx.tell = dynamicTell; | |
7250 | + ctx->ctx.seek = dynamicSeek; | |
7251 | + ctx->ctx.tell = dynamicTell; | |
7252 | ||
7253 | - ctx->ctx.gd_free = gdFreeDynamicCtx; | |
7254 | + ctx->ctx.gd_free = gdFreeDynamicCtx; | |
7255 | ||
7256 | - return (gdIOCtx *) ctx; | |
7257 | + return (gdIOCtx *) ctx; | |
7258 | } | |
7259 | ||
7260 | -void * | |
7261 | -gdDPExtractData (struct gdIOCtx *ctx, int *size) | |
7262 | +void * gdDPExtractData (struct gdIOCtx *ctx, int *size) | |
7263 | { | |
7264 | - dynamicPtr *dp; | |
7265 | - dpIOCtx *dctx; | |
7266 | - void *data; | |
7267 | + dynamicPtr *dp; | |
7268 | + dpIOCtx *dctx; | |
7269 | + void *data; | |
7270 | ||
7271 | - dctx = (dpIOCtx *) ctx; | |
7272 | - dp = dctx->dp; | |
7273 | + dctx = (dpIOCtx *) ctx; | |
7274 | + dp = dctx->dp; | |
7275 | ||
7276 | - /* clean up the data block and return it */ | |
7277 | - if (dp->dataGood) | |
7278 | - { | |
7279 | - trimDynamic (dp); | |
7280 | - *size = dp->logicalSize; | |
7281 | - data = dp->data; | |
7282 | - } | |
7283 | - else | |
7284 | - { | |
7285 | - *size = 0; | |
7286 | - data = NULL; | |
7287 | - if (dp->data != NULL && dp->freeOK) | |
7288 | - { | |
7289 | - gdFree (dp->data); | |
7290 | + /* clean up the data block and return it */ | |
7291 | + if (dp->dataGood) { | |
7292 | + trimDynamic (dp); | |
7293 | + *size = dp->logicalSize; | |
7294 | + data = dp->data; | |
7295 | + } else { | |
7296 | + *size = 0; | |
7297 | + data = NULL; | |
7298 | + if (dp->data != NULL && dp->freeOK) { | |
7299 | + gdFree(dp->data); | |
7300 | + } | |
7301 | } | |
7302 | - } | |
7303 | ||
7304 | - dp->data = NULL; | |
7305 | - dp->realSize = 0; | |
7306 | - dp->logicalSize = 0; | |
7307 | + dp->data = NULL; | |
7308 | + dp->realSize = 0; | |
7309 | + dp->logicalSize = 0; | |
7310 | ||
7311 | - return data; | |
7312 | + return data; | |
7313 | } | |
7314 | ||
7315 | -static | |
7316 | -void | |
7317 | -gdFreeDynamicCtx (struct gdIOCtx *ctx) | |
7318 | +static void gdFreeDynamicCtx (struct gdIOCtx *ctx) | |
7319 | { | |
7320 | - dynamicPtr *dp; | |
7321 | - dpIOCtx *dctx; | |
7322 | - | |
7323 | - dctx = (dpIOCtx *) ctx; | |
7324 | - dp = dctx->dp; | |
7325 | + dynamicPtr *dp; | |
7326 | + dpIOCtx *dctx; | |
7327 | ||
7328 | - gdFree (ctx); | |
7329 | + dctx = (dpIOCtx *) ctx; | |
7330 | + dp = dctx->dp; | |
7331 | ||
7332 | - dp->realSize = 0; | |
7333 | - dp->logicalSize = 0; | |
7334 | + gdFree(ctx); | |
7335 | ||
7336 | - gdFree (dp); | |
7337 | + dp->realSize = 0; | |
7338 | + dp->logicalSize = 0; | |
7339 | ||
7340 | + gdFree(dp); | |
7341 | } | |
7342 | ||
7343 | -static long | |
7344 | -dynamicTell (struct gdIOCtx *ctx) | |
7345 | +static long dynamicTell (struct gdIOCtx *ctx) | |
7346 | { | |
7347 | - dpIOCtx *dctx; | |
7348 | + dpIOCtx *dctx; | |
7349 | ||
7350 | - dctx = (dpIOCtx *) ctx; | |
7351 | - return (dctx->dp->pos); | |
7352 | + dctx = (dpIOCtx *) ctx; | |
7353 | + | |
7354 | + return (dctx->dp->pos); | |
7355 | } | |
7356 | ||
7357 | -static int | |
7358 | -dynamicSeek (struct gdIOCtx *ctx, const int pos) | |
7359 | +static int dynamicSeek (struct gdIOCtx *ctx, const int pos) | |
7360 | { | |
7361 | - int bytesNeeded; | |
7362 | - dynamicPtr *dp; | |
7363 | - dpIOCtx *dctx; | |
7364 | + int bytesNeeded; | |
7365 | + dynamicPtr *dp; | |
7366 | + dpIOCtx *dctx; | |
7367 | ||
7368 | - dctx = (dpIOCtx *) ctx; | |
7369 | - dp = dctx->dp; | |
7370 | + dctx = (dpIOCtx *) ctx; | |
7371 | + dp = dctx->dp; | |
7372 | ||
7373 | - if (!dp->dataGood) | |
7374 | - return FALSE; | |
7375 | + if (!dp->dataGood) { | |
7376 | + return FALSE; | |
7377 | + } | |
7378 | ||
7379 | - bytesNeeded = pos; | |
7380 | - if (bytesNeeded > dp->realSize) | |
7381 | - { | |
7382 | - /* 2.0.21 */ | |
7383 | - if (!dp->freeOK) { | |
7384 | - return FALSE; | |
7385 | - } | |
7386 | - if (!gdReallocDynamic (dp, dp->realSize * 2)) | |
7387 | - { | |
7388 | - dp->dataGood = FALSE; | |
7389 | - return FALSE; | |
7390 | + bytesNeeded = pos; | |
7391 | + if (bytesNeeded > dp->realSize) { | |
7392 | + /* 2.0.21 */ | |
7393 | + if (!dp->freeOK) { | |
7394 | + return FALSE; | |
7395 | + } | |
7396 | + gdReallocDynamic (dp, dp->realSize * 2); | |
7397 | } | |
7398 | - } | |
7399 | ||
7400 | - /* if we get here, we can be sure that we have enough bytes | |
7401 | - to copy safely */ | |
7402 | + /* if we get here, we can be sure that we have enough bytes to copy safely */ | |
7403 | ||
7404 | - /* Extend the logical size if we seek beyond EOF. */ | |
7405 | - if (pos > dp->logicalSize) | |
7406 | - { | |
7407 | - dp->logicalSize = pos; | |
7408 | - }; | |
7409 | + /* Extend the logical size if we seek beyond EOF. */ | |
7410 | + if (pos > dp->logicalSize) { | |
7411 | + dp->logicalSize = pos; | |
7412 | + } | |
7413 | ||
7414 | - dp->pos = pos; | |
7415 | + dp->pos = pos; | |
7416 | ||
7417 | - return TRUE; | |
7418 | + return TRUE; | |
7419 | } | |
7420 | ||
7421 | /* return data as a dynamic pointer */ | |
7422 | static dynamicPtr * newDynamic (int initialSize, void *data, int freeOKFlag) | |
7423 | { | |
7424 | - dynamicPtr *dp; | |
7425 | - dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr)); | |
7426 | - if (dp == NULL) | |
7427 | - { | |
7428 | - return NULL; | |
7429 | - } | |
7430 | + dynamicPtr *dp; | |
7431 | + dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr)); | |
7432 | ||
7433 | - if (!allocDynamic (dp, initialSize, data)) | |
7434 | - return NULL; | |
7435 | + allocDynamic (dp, initialSize, data); | |
7436 | ||
7437 | - dp->pos = 0; | |
7438 | - dp->freeOK = freeOKFlag; | |
7439 | + dp->pos = 0; | |
7440 | + dp->freeOK = freeOKFlag; | |
7441 | ||
7442 | - return dp; | |
7443 | + return dp; | |
7444 | } | |
7445 | ||
7446 | static int | |
7447 | @@ -246,64 +213,53 @@ | |
7448 | ||
7449 | } | |
7450 | ||
7451 | -static void | |
7452 | -dynamicPutchar (struct gdIOCtx *ctx, int a) | |
7453 | +static void dynamicPutchar (struct gdIOCtx *ctx, int a) | |
7454 | { | |
7455 | - unsigned char b; | |
7456 | - dpIOCtxPtr dctx; | |
7457 | + unsigned char b; | |
7458 | + dpIOCtxPtr dctx; | |
7459 | ||
7460 | - b = a; | |
7461 | - dctx = (dpIOCtxPtr) ctx; | |
7462 | + b = a; | |
7463 | + dctx = (dpIOCtxPtr) ctx; | |
7464 | ||
7465 | - appendDynamic (dctx->dp, &b, 1); | |
7466 | + appendDynamic(dctx->dp, &b, 1); | |
7467 | } | |
7468 | ||
7469 | -static int | |
7470 | -dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len) | |
7471 | +static int dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len) | |
7472 | { | |
7473 | - int rlen, remain; | |
7474 | - dpIOCtxPtr dctx; | |
7475 | - dynamicPtr *dp; | |
7476 | + int rlen, remain; | |
7477 | + dpIOCtxPtr dctx; | |
7478 | + dynamicPtr *dp; | |
7479 | ||
7480 | - dctx = (dpIOCtxPtr) ctx; | |
7481 | - dp = dctx->dp; | |
7482 | + dctx = (dpIOCtxPtr) ctx; | |
7483 | + dp = dctx->dp; | |
7484 | ||
7485 | - remain = dp->logicalSize - dp->pos; | |
7486 | - if (remain >= len) | |
7487 | - { | |
7488 | - rlen = len; | |
7489 | - } | |
7490 | - else | |
7491 | - { | |
7492 | - if (remain == 0) | |
7493 | - { | |
7494 | - return EOF; | |
7495 | + remain = dp->logicalSize - dp->pos; | |
7496 | + if (remain >= len) { | |
7497 | + rlen = len; | |
7498 | + } else { | |
7499 | + if (remain == 0) { | |
7500 | + return EOF; | |
7501 | + } | |
7502 | + rlen = remain; | |
7503 | } | |
7504 | - rlen = remain; | |
7505 | - } | |
7506 | ||
7507 | - memcpy (buf, (void *) ((char *) dp->data + dp->pos), rlen); | |
7508 | - dp->pos += rlen; | |
7509 | + memcpy(buf, (void *) ((char *) dp->data + dp->pos), rlen); | |
7510 | + dp->pos += rlen; | |
7511 | ||
7512 | - return rlen; | |
7513 | + return rlen; | |
7514 | } | |
7515 | ||
7516 | -static int | |
7517 | -dynamicGetchar (gdIOCtxPtr ctx) | |
7518 | +static int dynamicGetchar (gdIOCtxPtr ctx) | |
7519 | { | |
7520 | - unsigned char b; | |
7521 | - int rv; | |
7522 | - | |
7523 | - rv = dynamicGetbuf (ctx, &b, 1); | |
7524 | + unsigned char b; | |
7525 | + int rv; | |
7526 | ||
7527 | - if (rv != 1) | |
7528 | - { | |
7529 | - return EOF; | |
7530 | - } | |
7531 | - else | |
7532 | - { | |
7533 | - return b; /* (b & 0xff); */ | |
7534 | - } | |
7535 | + rv = dynamicGetbuf (ctx, &b, 1); | |
7536 | + if (rv != 1) { | |
7537 | + return EOF; | |
7538 | + } else { | |
7539 | + return b; /* (b & 0xff); */ | |
7540 | + } | |
7541 | } | |
7542 | ||
7543 | /* ********************************************************************* | |
7544 | @@ -316,114 +272,89 @@ | |
7545 | allocDynamic (dynamicPtr * dp, int initialSize, void *data) | |
7546 | { | |
7547 | ||
7548 | - if (data == NULL) | |
7549 | - { | |
7550 | - dp->logicalSize = 0; | |
7551 | - dp->dataGood = FALSE; | |
7552 | - dp->data = gdMalloc (initialSize); | |
7553 | - } | |
7554 | - else | |
7555 | - { | |
7556 | - dp->logicalSize = initialSize; | |
7557 | - dp->dataGood = TRUE; | |
7558 | - dp->data = data; | |
7559 | - } | |
7560 | + if (data == NULL) { | |
7561 | + dp->logicalSize = 0; | |
7562 | + dp->dataGood = FALSE; | |
7563 | + dp->data = gdMalloc(initialSize); | |
7564 | + } else { | |
7565 | + dp->logicalSize = initialSize; | |
7566 | + dp->dataGood = TRUE; | |
7567 | + dp->data = data; | |
7568 | + } | |
7569 | ||
7570 | - if (dp->data != NULL) | |
7571 | - { | |
7572 | - dp->realSize = initialSize; | |
7573 | - dp->dataGood = TRUE; | |
7574 | - dp->pos = 0; | |
7575 | - return TRUE; | |
7576 | - } | |
7577 | - else | |
7578 | - { | |
7579 | - dp->realSize = 0; | |
7580 | - return FALSE; | |
7581 | - } | |
7582 | + dp->realSize = initialSize; | |
7583 | + dp->dataGood = TRUE; | |
7584 | + dp->pos = 0; | |
7585 | + | |
7586 | + return TRUE; | |
7587 | } | |
7588 | ||
7589 | /* append bytes to the end of a dynamic pointer */ | |
7590 | -static int | |
7591 | -appendDynamic (dynamicPtr * dp, const void *src, int size) | |
7592 | +static int appendDynamic (dynamicPtr * dp, const void *src, int size) | |
7593 | { | |
7594 | - int bytesNeeded; | |
7595 | - char *tmp; | |
7596 | + int bytesNeeded; | |
7597 | + char *tmp; | |
7598 | ||
7599 | - if (!dp->dataGood) | |
7600 | - return FALSE; | |
7601 | + if (!dp->dataGood) { | |
7602 | + return FALSE; | |
7603 | + } | |
7604 | ||
7605 | -/* bytesNeeded = dp->logicalSize + size; */ | |
7606 | - bytesNeeded = dp->pos + size; | |
7607 | + /* bytesNeeded = dp->logicalSize + size; */ | |
7608 | + bytesNeeded = dp->pos + size; | |
7609 | ||
7610 | - if (bytesNeeded > dp->realSize) | |
7611 | - { | |
7612 | + if (bytesNeeded > dp->realSize) { | |
7613 | /* 2.0.21 */ | |
7614 | if (!dp->freeOK) { | |
7615 | return FALSE; | |
7616 | } | |
7617 | - if (!gdReallocDynamic (dp, bytesNeeded * 2)) | |
7618 | - { | |
7619 | - dp->dataGood = FALSE; | |
7620 | - return FALSE; | |
7621 | + gdReallocDynamic(dp, bytesNeeded * 2); | |
7622 | } | |
7623 | - } | |
7624 | ||
7625 | - /* if we get here, we can be sure that we have enough bytes | |
7626 | - to copy safely */ | |
7627 | - /*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */ | |
7628 | - | |
7629 | - tmp = (char *) dp->data; | |
7630 | - memcpy ((void *) (tmp + (dp->pos)), src, size); | |
7631 | - dp->pos += size; | |
7632 | + /* if we get here, we can be sure that we have enough bytes to copy safely */ | |
7633 | + /*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */ | |
7634 | ||
7635 | - if (dp->pos > dp->logicalSize) | |
7636 | - { | |
7637 | - dp->logicalSize = dp->pos; | |
7638 | - }; | |
7639 | + tmp = (char *) dp->data; | |
7640 | + memcpy((void *) (tmp + (dp->pos)), src, size); | |
7641 | + dp->pos += size; | |
7642 | + | |
7643 | + if (dp->pos > dp->logicalSize) { | |
7644 | + dp->logicalSize = dp->pos; | |
7645 | + } | |
7646 | ||
7647 | - return TRUE; | |
7648 | + return TRUE; | |
7649 | } | |
7650 | ||
7651 | /* grow (or shrink) dynamic pointer */ | |
7652 | -static int | |
7653 | -gdReallocDynamic (dynamicPtr * dp, int required) | |
7654 | +static int gdReallocDynamic (dynamicPtr * dp, int required) | |
7655 | { | |
7656 | - void *newPtr; | |
7657 | + void *newPtr; | |
7658 | ||
7659 | - /* First try gdRealloc(). If that doesn't work, make a new | |
7660 | - memory block and copy. */ | |
7661 | - if ((newPtr = gdRealloc (dp->data, required))) | |
7662 | - { | |
7663 | - dp->realSize = required; | |
7664 | - dp->data = newPtr; | |
7665 | - return TRUE; | |
7666 | - } | |
7667 | + /* First try gdRealloc(). If that doesn't work, make a new memory block and copy. */ | |
7668 | + if ((newPtr = gdRealloc(dp->data, required))) { | |
7669 | + dp->realSize = required; | |
7670 | + dp->data = newPtr; | |
7671 | + return TRUE; | |
7672 | + } | |
7673 | ||
7674 | - /* create a new pointer */ | |
7675 | - newPtr = gdMalloc (required); | |
7676 | - if (!newPtr) | |
7677 | - { | |
7678 | - dp->dataGood = FALSE; | |
7679 | - return FALSE; | |
7680 | - } | |
7681 | + /* create a new pointer */ | |
7682 | + newPtr = gdMalloc(required); | |
7683 | + | |
7684 | + /* copy the old data into it */ | |
7685 | + memcpy(newPtr, dp->data, dp->logicalSize); | |
7686 | + gdFree(dp->data); | |
7687 | + dp->data = newPtr; | |
7688 | ||
7689 | - /* copy the old data into it */ | |
7690 | - memcpy (newPtr, dp->data, dp->logicalSize); | |
7691 | - gdFree (dp->data); | |
7692 | - dp->data = newPtr; | |
7693 | + dp->realSize = required; | |
7694 | ||
7695 | - dp->realSize = required; | |
7696 | - return TRUE; | |
7697 | + return TRUE; | |
7698 | } | |
7699 | ||
7700 | /* trim pointer so that its real and logical sizes match */ | |
7701 | -static int | |
7702 | -trimDynamic (dynamicPtr * dp) | |
7703 | +static int trimDynamic (dynamicPtr * dp) | |
7704 | { | |
7705 | - /* 2.0.21: we don't reallocate memory we don't own */ | |
7706 | - if (!dp->freeOK) { | |
7707 | - return FALSE; | |
7708 | - } | |
7709 | - return gdReallocDynamic (dp, dp->logicalSize); | |
7710 | + /* 2.0.21: we don't reallocate memory we don't own */ | |
7711 | + if (!dp->freeOK) { | |
7712 | + return FALSE; | |
7713 | + } | |
7714 | + return gdReallocDynamic(dp, dp->logicalSize); | |
7715 | } | |
7716 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_io_file.c php-4.4.8/ext/gd/libgd/gd_io_file.c | |
7717 | --- php-4.4.8.org/ext/gd/libgd/gd_io_file.c 2003-12-25 23:33:03.000000000 +0100 | |
7718 | +++ php-4.4.8/ext/gd/libgd/gd_io_file.c 2003-12-25 23:12:12.000000000 +0100 | |
7719 | @@ -29,11 +29,10 @@ | |
7720 | /* this is used for creating images in main memory */ | |
7721 | ||
7722 | typedef struct fileIOCtx | |
7723 | - { | |
7724 | - gdIOCtx ctx; | |
7725 | - FILE *f; | |
7726 | - } | |
7727 | -fileIOCtx; | |
7728 | +{ | |
7729 | + gdIOCtx ctx; | |
7730 | + FILE *f; | |
7731 | +} fileIOCtx; | |
7732 | ||
7733 | gdIOCtx *newFileCtx (FILE * f); | |
7734 | ||
7735 | @@ -47,97 +46,83 @@ | |
7736 | static void gdFreeFileCtx (gdIOCtx * ctx); | |
7737 | ||
7738 | /* return data as a dynamic pointer */ | |
7739 | -gdIOCtx * | |
7740 | -gdNewFileCtx (FILE * f) | |
7741 | +gdIOCtx * gdNewFileCtx (FILE * f) | |
7742 | { | |
7743 | - fileIOCtx *ctx; | |
7744 | + fileIOCtx *ctx; | |
7745 | ||
7746 | - ctx = (fileIOCtx *) gdMalloc (sizeof (fileIOCtx)); | |
7747 | - if (ctx == NULL) | |
7748 | - { | |
7749 | - return NULL; | |
7750 | - } | |
7751 | + ctx = (fileIOCtx *) gdMalloc(sizeof (fileIOCtx)); | |
7752 | ||
7753 | - ctx->f = f; | |
7754 | + ctx->f = f; | |
7755 | ||
7756 | - ctx->ctx.getC = fileGetchar; | |
7757 | - ctx->ctx.putC = filePutchar; | |
7758 | + ctx->ctx.getC = fileGetchar; | |
7759 | + ctx->ctx.putC = filePutchar; | |
7760 | ||
7761 | - ctx->ctx.getBuf = fileGetbuf; | |
7762 | - ctx->ctx.putBuf = filePutbuf; | |
7763 | + ctx->ctx.getBuf = fileGetbuf; | |
7764 | + ctx->ctx.putBuf = filePutbuf; | |
7765 | ||
7766 | - ctx->ctx.tell = fileTell; | |
7767 | - ctx->ctx.seek = fileSeek; | |
7768 | + ctx->ctx.tell = fileTell; | |
7769 | + ctx->ctx.seek = fileSeek; | |
7770 | ||
7771 | - ctx->ctx.gd_free = gdFreeFileCtx; | |
7772 | + ctx->ctx.gd_free = gdFreeFileCtx; | |
7773 | ||
7774 | - return (gdIOCtx *) ctx; | |
7775 | + return (gdIOCtx *) ctx; | |
7776 | } | |
7777 | ||
7778 | -static | |
7779 | -void | |
7780 | -gdFreeFileCtx (gdIOCtx * ctx) | |
7781 | +static void gdFreeFileCtx (gdIOCtx * ctx) | |
7782 | { | |
7783 | - gdFree (ctx); | |
7784 | + gdFree(ctx); | |
7785 | } | |
7786 | ||
7787 | ||
7788 | -static int | |
7789 | -filePutbuf (gdIOCtx * ctx, const void *buf, int size) | |
7790 | +static int filePutbuf (gdIOCtx * ctx, const void *buf, int size) | |
7791 | { | |
7792 | - fileIOCtx *fctx; | |
7793 | - fctx = (fileIOCtx *) ctx; | |
7794 | + fileIOCtx *fctx; | |
7795 | + fctx = (fileIOCtx *) ctx; | |
7796 | ||
7797 | - return fwrite (buf, 1, size, fctx->f); | |
7798 | + return fwrite(buf, 1, size, fctx->f); | |
7799 | ||
7800 | } | |
7801 | ||
7802 | -static int | |
7803 | -fileGetbuf (gdIOCtx * ctx, void *buf, int size) | |
7804 | +static int fileGetbuf (gdIOCtx * ctx, void *buf, int size) | |
7805 | { | |
7806 | - fileIOCtx *fctx; | |
7807 | - fctx = (fileIOCtx *) ctx; | |
7808 | - | |
7809 | - return (fread (buf, 1, size, fctx->f)); | |
7810 | + fileIOCtx *fctx; | |
7811 | + fctx = (fileIOCtx *) ctx; | |
7812 | ||
7813 | + return fread(buf, 1, size, fctx->f); | |
7814 | } | |
7815 | ||
7816 | -static void | |
7817 | -filePutchar (gdIOCtx * ctx, int a) | |
7818 | +static void filePutchar (gdIOCtx * ctx, int a) | |
7819 | { | |
7820 | - unsigned char b; | |
7821 | - fileIOCtx *fctx; | |
7822 | - fctx = (fileIOCtx *) ctx; | |
7823 | + unsigned char b; | |
7824 | + fileIOCtx *fctx; | |
7825 | + fctx = (fileIOCtx *) ctx; | |
7826 | ||
7827 | - b = a; | |
7828 | + b = a; | |
7829 | ||
7830 | - putc (b, fctx->f); | |
7831 | + putc (b, fctx->f); | |
7832 | } | |
7833 | ||
7834 | -static int | |
7835 | -fileGetchar (gdIOCtx * ctx) | |
7836 | +static int fileGetchar (gdIOCtx * ctx) | |
7837 | { | |
7838 | - fileIOCtx *fctx; | |
7839 | - fctx = (fileIOCtx *) ctx; | |
7840 | + fileIOCtx *fctx; | |
7841 | + fctx = (fileIOCtx *) ctx; | |
7842 | ||
7843 | - return getc (fctx->f); | |
7844 | + return getc (fctx->f); | |
7845 | } | |
7846 | ||
7847 | ||
7848 | -static int | |
7849 | -fileSeek (struct gdIOCtx *ctx, const int pos) | |
7850 | +static int fileSeek (struct gdIOCtx *ctx, const int pos) | |
7851 | { | |
7852 | - fileIOCtx *fctx; | |
7853 | - fctx = (fileIOCtx *) ctx; | |
7854 | + fileIOCtx *fctx; | |
7855 | + fctx = (fileIOCtx *) ctx; | |
7856 | ||
7857 | - return (fseek (fctx->f, pos, SEEK_SET) == 0); | |
7858 | + return (fseek (fctx->f, pos, SEEK_SET) == 0); | |
7859 | } | |
7860 | ||
7861 | -static long | |
7862 | -fileTell (struct gdIOCtx *ctx) | |
7863 | +static long fileTell (struct gdIOCtx *ctx) | |
7864 | { | |
7865 | - fileIOCtx *fctx; | |
7866 | - fctx = (fileIOCtx *) ctx; | |
7867 | + fileIOCtx *fctx; | |
7868 | + fctx = (fileIOCtx *) ctx; | |
7869 | ||
7870 | - return ftell (fctx->f); | |
7871 | + return ftell (fctx->f); | |
7872 | } | |
7873 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_io.h php-4.4.8/ext/gd/libgd/gd_io.h | |
7874 | --- php-4.4.8.org/ext/gd/libgd/gd_io.h 2003-04-05 19:24:16.000000000 +0200 | |
7875 | +++ php-4.4.8/ext/gd/libgd/gd_io.h 2003-12-28 21:11:08.000000000 +0100 | |
7876 | @@ -6,18 +6,18 @@ | |
7877 | #ifdef VMS | |
7878 | #define Putchar gdPutchar | |
7879 | #endif | |
7880 | - | |
7881 | + | |
7882 | typedef struct gdIOCtx { | |
7883 | int (*getC)(struct gdIOCtx*); | |
7884 | int (*getBuf)(struct gdIOCtx*, void*, int); | |
7885 | ||
7886 | - void (*putC)(struct gdIOCtx*, int); | |
7887 | + void (*putC)(struct gdIOCtx*, int); | |
7888 | int (*putBuf)(struct gdIOCtx*, const void*, int); | |
7889 | ||
7890 | int (*seek)(struct gdIOCtx*, const int); | |
7891 | long (*tell)(struct gdIOCtx*); | |
7892 | ||
7893 | - void (*gd_free)(struct gdIOCtx*); | |
7894 | + void (*gd_free)(struct gdIOCtx*); | |
7895 | ||
7896 | } gdIOCtx; | |
7897 | ||
7898 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_io_ss.c php-4.4.8/ext/gd/libgd/gd_io_ss.c | |
7899 | --- php-4.4.8.org/ext/gd/libgd/gd_io_ss.c 2002-10-30 00:08:01.000000000 +0100 | |
7900 | +++ php-4.4.8/ext/gd/libgd/gd_io_ss.c 2003-12-28 21:11:08.000000000 +0100 | |
7901 | @@ -12,7 +12,7 @@ | |
7902 | * used internally until it settles down a bit. | |
7903 | * | |
7904 | * This module just layers the Source/Sink interface on top of the IOCtx; no | |
7905 | - * support is provided for tell/seek, so GD2 writing is not possible, and | |
7906 | + * support is provided for tell/seek, so GD2 writing is not possible, and | |
7907 | * retrieving parts of GD2 files is also not possible. | |
7908 | * | |
7909 | * A new SS context does not need to be created with both a Source and a Sink. | |
7910 | @@ -30,12 +30,11 @@ | |
7911 | /* this is used for creating images in main memory */ | |
7912 | ||
7913 | typedef struct ssIOCtx | |
7914 | - { | |
7915 | - gdIOCtx ctx; | |
7916 | - gdSourcePtr src; | |
7917 | - gdSinkPtr snk; | |
7918 | - } | |
7919 | -ssIOCtx; | |
7920 | +{ | |
7921 | + gdIOCtx ctx; | |
7922 | + gdSourcePtr src; | |
7923 | + gdSinkPtr snk; | |
7924 | +} ssIOCtx; | |
7925 | ||
7926 | typedef struct ssIOCtx *ssIOCtxPtr; | |
7927 | ||
7928 | @@ -48,118 +47,92 @@ | |
7929 | static void gdFreeSsCtx (gdIOCtx * ctx); | |
7930 | ||
7931 | /* return data as a dynamic pointer */ | |
7932 | -gdIOCtx * | |
7933 | -gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk) | |
7934 | +gdIOCtx * gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk) | |
7935 | { | |
7936 | - ssIOCtxPtr ctx; | |
7937 | + ssIOCtxPtr ctx; | |
7938 | ||
7939 | - ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx)); | |
7940 | - if (ctx == NULL) | |
7941 | - { | |
7942 | - return NULL; | |
7943 | - } | |
7944 | + ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx)); | |
7945 | ||
7946 | - ctx->src = src; | |
7947 | - ctx->snk = snk; | |
7948 | + ctx->src = src; | |
7949 | + ctx->snk = snk; | |
7950 | ||
7951 | - ctx->ctx.getC = sourceGetchar; | |
7952 | - ctx->ctx.getBuf = sourceGetbuf; | |
7953 | + ctx->ctx.getC = sourceGetchar; | |
7954 | + ctx->ctx.getBuf = sourceGetbuf; | |
7955 | ||
7956 | - ctx->ctx.putC = sinkPutchar; | |
7957 | - ctx->ctx.putBuf = sinkPutbuf; | |
7958 | + ctx->ctx.putC = sinkPutchar; | |
7959 | + ctx->ctx.putBuf = sinkPutbuf; | |
7960 | ||
7961 | - ctx->ctx.tell = NULL; | |
7962 | - ctx->ctx.seek = NULL; | |
7963 | + ctx->ctx.tell = NULL; | |
7964 | + ctx->ctx.seek = NULL; | |
7965 | ||
7966 | - ctx->ctx.gd_free = gdFreeSsCtx; | |
7967 | + ctx->ctx.gd_free = gdFreeSsCtx; | |
7968 | ||
7969 | - return (gdIOCtx *) ctx; | |
7970 | + return (gdIOCtx *) ctx; | |
7971 | } | |
7972 | ||
7973 | -static | |
7974 | -void | |
7975 | -gdFreeSsCtx (gdIOCtx * ctx) | |
7976 | +static void gdFreeSsCtx (gdIOCtx * ctx) | |
7977 | { | |
7978 | - gdFree (ctx); | |
7979 | + gdFree(ctx); | |
7980 | } | |
7981 | ||
7982 | ||
7983 | -static int | |
7984 | -sourceGetbuf (gdIOCtx * ctx, void *buf, int size) | |
7985 | +static int sourceGetbuf (gdIOCtx * ctx, void *buf, int size) | |
7986 | { | |
7987 | - ssIOCtx *lctx; | |
7988 | - int res; | |
7989 | - | |
7990 | - lctx = (ssIOCtx *) ctx; | |
7991 | + ssIOCtx *lctx; | |
7992 | + int res; | |
7993 | ||
7994 | - res = ((lctx->src->source) (lctx->src->context, buf, size)); | |
7995 | + lctx = (ssIOCtx *) ctx; | |
7996 | ||
7997 | -/* | |
7998 | - ** Translate the return values from the Source object: | |
7999 | - ** 0 is EOF, -1 is error | |
8000 | - */ | |
8001 | + res = ((lctx->src->source) (lctx->src->context, buf, size)); | |
8002 | ||
8003 | - if (res == 0) | |
8004 | - { | |
8005 | - return EOF; | |
8006 | - } | |
8007 | - else if (res < 0) | |
8008 | - { | |
8009 | - return 0; | |
8010 | - } | |
8011 | - else | |
8012 | - { | |
8013 | - return res; | |
8014 | - }; | |
8015 | + /* | |
8016 | + * Translate the return values from the Source object: | |
8017 | + * 0 is EOF, -1 is error | |
8018 | + */ | |
8019 | ||
8020 | + if (res == 0) { | |
8021 | + return EOF; | |
8022 | + } else if (res < 0) { | |
8023 | + return 0; | |
8024 | + } else { | |
8025 | + return res; | |
8026 | + } | |
8027 | } | |
8028 | ||
8029 | -static int | |
8030 | -sourceGetchar (gdIOCtx * ctx) | |
8031 | +static int sourceGetchar (gdIOCtx * ctx) | |
8032 | { | |
8033 | - int res; | |
8034 | - unsigned char buf; | |
8035 | + int res; | |
8036 | + unsigned char buf; | |
8037 | ||
8038 | - res = sourceGetbuf (ctx, &buf, 1); | |
8039 | - | |
8040 | - if (res == 1) | |
8041 | - { | |
8042 | - return buf; | |
8043 | - } | |
8044 | - else | |
8045 | - { | |
8046 | - return EOF; | |
8047 | - }; | |
8048 | + res = sourceGetbuf (ctx, &buf, 1); | |
8049 | ||
8050 | + if (res == 1) { | |
8051 | + return buf; | |
8052 | + } else { | |
8053 | + return EOF; | |
8054 | + } | |
8055 | } | |
8056 | ||
8057 | -static int | |
8058 | -sinkPutbuf (gdIOCtx * ctx, const void *buf, int size) | |
8059 | +static int sinkPutbuf (gdIOCtx * ctx, const void *buf, int size) | |
8060 | { | |
8061 | - ssIOCtxPtr lctx; | |
8062 | - int res; | |
8063 | - | |
8064 | - lctx = (ssIOCtx *) ctx; | |
8065 | + ssIOCtxPtr lctx; | |
8066 | + int res; | |
8067 | ||
8068 | - res = (lctx->snk->sink) (lctx->snk->context, buf, size); | |
8069 | + lctx = (ssIOCtx *) ctx; | |
8070 | ||
8071 | - if (res <= 0) | |
8072 | - { | |
8073 | - return 0; | |
8074 | - } | |
8075 | - else | |
8076 | - { | |
8077 | - return res; | |
8078 | - }; | |
8079 | + res = (lctx->snk->sink) (lctx->snk->context, buf, size); | |
8080 | ||
8081 | + if (res <= 0) { | |
8082 | + return 0; | |
8083 | + } else { | |
8084 | + return res; | |
8085 | + } | |
8086 | } | |
8087 | ||
8088 | -static void | |
8089 | -sinkPutchar (gdIOCtx * ctx, int a) | |
8090 | +static void sinkPutchar (gdIOCtx * ctx, int a) | |
8091 | { | |
8092 | - unsigned char b; | |
8093 | - | |
8094 | - b = a; | |
8095 | - sinkPutbuf (ctx, &b, 1); | |
8096 | + unsigned char b; | |
8097 | ||
8098 | + b = a; | |
8099 | + sinkPutbuf (ctx, &b, 1); | |
8100 | } | |
8101 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_jpeg.c php-4.4.8/ext/gd/libgd/gd_jpeg.c | |
8102 | --- php-4.4.8.org/ext/gd/libgd/gd_jpeg.c 2004-03-29 20:21:00.000000000 +0200 | |
8103 | +++ php-4.4.8/ext/gd/libgd/gd_jpeg.c 2006-02-05 16:53:58.000000000 +0100 | |
8104 | @@ -1,7 +1,7 @@ | |
8105 | /* | |
8106 | * gd_jpeg.c: Read and write JPEG (JFIF) format image files using the | |
8107 | * gd graphics library (http://www.boutell.com/gd/). | |
8108 | - * | |
8109 | + * | |
8110 | * This software is based in part on the work of the Independent JPEG | |
8111 | * Group. For more information on the IJG JPEG software (and JPEG | |
8112 | * documentation, etc.), see ftp://ftp.uu.net/graphics/jpeg/. | |
8113 | @@ -18,13 +18,9 @@ | |
8114 | * major CGI brain damage | |
8115 | * | |
8116 | * 2.0.10: more efficient gdImageCreateFromJpegCtx, thanks to | |
8117 | - * Christian Aberger | |
8118 | + * Christian Aberger | |
8119 | */ | |
8120 | ||
8121 | -#if PHP_WIN32 && !defined(ssize_t) | |
8122 | -typedef int ssize_t; | |
8123 | -#endif | |
8124 | - | |
8125 | #include <stdio.h> | |
8126 | #include <stdlib.h> | |
8127 | #include <setjmp.h> | |
8128 | @@ -47,8 +43,44 @@ | |
8129 | typedef struct _jmpbuf_wrapper | |
8130 | { | |
8131 | jmp_buf jmpbuf; | |
8132 | + int ignore_warning; | |
8133 | } jmpbuf_wrapper; | |
8134 | ||
8135 | +static long php_jpeg_emit_message(j_common_ptr jpeg_info, int level) | |
8136 | +{ | |
8137 | + char message[JMSG_LENGTH_MAX]; | |
8138 | + jmpbuf_wrapper *jmpbufw; | |
8139 | + int ignore_warning = 0; | |
8140 | + | |
8141 | + jmpbufw = (jmpbuf_wrapper *) jpeg_info->client_data; | |
8142 | + | |
8143 | + if (jmpbufw != 0) { | |
8144 | + ignore_warning = jmpbufw->ignore_warning; | |
8145 | + } | |
8146 | + | |
8147 | + (jpeg_info->err->format_message)(jpeg_info,message); | |
8148 | + | |
8149 | + /* It is a warning message */ | |
8150 | + if (level < 0) { | |
8151 | + /* display only the 1st warning, as would do a default libjpeg | |
8152 | + * unless strace_level >= 3 | |
8153 | + */ | |
8154 | + if ((jpeg_info->err->num_warnings == 0) || (jpeg_info->err->trace_level >= 3)) { | |
8155 | + php_gd_error_ex(ignore_warning ? E_NOTICE : E_WARNING, "gd-jpeg, libjpeg: recoverable error: %s\n", message); | |
8156 | + } | |
8157 | + | |
8158 | + jpeg_info->err->num_warnings++; | |
8159 | + } else { | |
8160 | + /* strace msg, Show it if trace_level >= level. */ | |
8161 | + if (jpeg_info->err->trace_level >= level) { | |
8162 | + php_gd_error_ex(E_NOTICE, "gd-jpeg, libjpeg: strace message: %s\n", message); | |
8163 | + } | |
8164 | + } | |
8165 | + return 1; | |
8166 | +} | |
8167 | + | |
8168 | + | |
8169 | + | |
8170 | /* Called by the IJG JPEG library upon encountering a fatal error */ | |
8171 | static void fatal_jpeg_error (j_common_ptr cinfo) | |
8172 | { | |
8173 | @@ -174,7 +206,7 @@ | |
8174 | ||
8175 | nlines = jpeg_write_scanlines (&cinfo, rowptr, 1); | |
8176 | if (nlines != 1) { | |
8177 | - php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1\n", nlines); | |
8178 | + php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines); | |
8179 | } | |
8180 | } | |
8181 | } else { | |
8182 | @@ -201,7 +233,7 @@ | |
8183 | ||
8184 | nlines = jpeg_write_scanlines (&cinfo, rowptr, 1); | |
8185 | if (nlines != 1) { | |
8186 | - php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1\n", nlines); | |
8187 | + php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines); | |
8188 | } | |
8189 | } | |
8190 | } | |
8191 | @@ -211,21 +243,21 @@ | |
8192 | gdFree (row); | |
8193 | } | |
8194 | ||
8195 | -gdImagePtr gdImageCreateFromJpeg (FILE * inFile) | |
8196 | +gdImagePtr gdImageCreateFromJpeg (FILE * inFile, int ignore_warning) | |
8197 | { | |
8198 | gdImagePtr im; | |
8199 | gdIOCtx *in = gdNewFileCtx(inFile); | |
8200 | - im = gdImageCreateFromJpegCtx(in); | |
8201 | + im = gdImageCreateFromJpegCtx(in, ignore_warning); | |
8202 | in->gd_free (in); | |
8203 | ||
8204 | return im; | |
8205 | } | |
8206 | ||
8207 | -gdImagePtr gdImageCreateFromJpegPtr (int size, void *data) | |
8208 | +gdImagePtr gdImageCreateFromJpegPtr (int size, void *data, int ignore_warning) | |
8209 | { | |
8210 | gdImagePtr im; | |
8211 | gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0); | |
8212 | - im = gdImageCreateFromJpegCtx(in); | |
8213 | + im = gdImageCreateFromJpegCtx(in, ignore_warning); | |
8214 | in->gd_free(in); | |
8215 | ||
8216 | return im; | |
8217 | @@ -235,11 +267,12 @@ | |
8218 | ||
8219 | static int CMYKToRGB(int c, int m, int y, int k, int inverted); | |
8220 | ||
8221 | -/* | |
8222 | + | |
8223 | +/* | |
8224 | * Create a gd-format image from the JPEG-format INFILE. Returns the | |
8225 | * image, or NULL upon error. | |
8226 | */ | |
8227 | -gdImagePtr gdImageCreateFromJpegCtx (gdIOCtx * infile) | |
8228 | +gdImagePtr gdImageCreateFromJpegCtx (gdIOCtx * infile, int ignore_warning) | |
8229 | { | |
8230 | struct jpeg_decompress_struct cinfo; | |
8231 | struct jpeg_error_mgr jerr; | |
8232 | @@ -257,8 +290,13 @@ | |
8233 | memset (&cinfo, 0, sizeof (cinfo)); | |
8234 | memset (&jerr, 0, sizeof (jerr)); | |
8235 | ||
8236 | + jmpbufw.ignore_warning = ignore_warning; | |
8237 | + | |
8238 | cinfo.err = jpeg_std_error (&jerr); | |
8239 | cinfo.client_data = &jmpbufw; | |
8240 | + | |
8241 | + cinfo.err->emit_message = (void (*)(j_common_ptr,int)) php_jpeg_emit_message; | |
8242 | + | |
8243 | if (setjmp (jmpbufw.jmpbuf) != 0) { | |
8244 | /* we're here courtesy of longjmp */ | |
8245 | if (row) { | |
8246 | @@ -280,7 +318,7 @@ | |
8247 | jpeg_save_markers(&cinfo, JPEG_APP0 + 14, 256); | |
8248 | ||
8249 | retval = jpeg_read_header (&cinfo, TRUE); | |
8250 | - if (retval != JPEG_HEADER_OK) { | |
8251 | + if (retval != JPEG_HEADER_OK) { | |
8252 | php_gd_error_ex(E_WARNING, "gd-jpeg: warning: jpeg_read_header returned %d, expected %d", retval, JPEG_HEADER_OK); | |
8253 | } | |
8254 | ||
8255 | @@ -316,9 +354,9 @@ | |
8256 | * latest libjpeg, replaced by something else. Unfortunately | |
8257 | * there is still no right way to find out if the file was | |
8258 | * progressive or not; just declare your intent before you | |
8259 | - * write one by calling gdImageInterlace(im, 1) yourself. | |
8260 | + * write one by calling gdImageInterlace(im, 1) yourself. | |
8261 | * After all, we're not really supposed to rework JPEGs and | |
8262 | - * write them out again anyway. Lossy compression, remember? | |
8263 | + * write them out again anyway. Lossy compression, remember? | |
8264 | */ | |
8265 | #if 0 | |
8266 | gdImageInterlace (im, cinfo.progressive_mode != 0); | |
8267 | @@ -390,12 +428,12 @@ | |
8268 | if (jpeg_finish_decompress (&cinfo) != TRUE) { | |
8269 | php_gd_error("gd-jpeg: warning: jpeg_finish_decompress reports suspended data source"); | |
8270 | } | |
8271 | - | |
8272 | - /* Thanks to Truxton Fulton */ | |
8273 | - if (cinfo.err->num_warnings > 0) { | |
8274 | - goto error; | |
8275 | + if (!ignore_warning) { | |
8276 | + if (cinfo.err->num_warnings > 0) { | |
8277 | + goto error; | |
8278 | + } | |
8279 | } | |
8280 | - | |
8281 | + | |
8282 | jpeg_destroy_decompress (&cinfo); | |
8283 | gdFree (row); | |
8284 | ||
8285 | @@ -524,7 +562,7 @@ | |
8286 | int got = gdGetBuf(src->buffer + nbytes, INPUT_BUF_SIZE - nbytes, src->infile); | |
8287 | ||
8288 | if (got == EOF || got == 0) { | |
8289 | - /* EOF or error. If we got any data, don't worry about it. If we didn't, then this is unexpected. */ | |
8290 | + /* EOF or error. If we got any data, don't worry about it. If we didn't, then this is unexpected. */ | |
8291 | if (!nbytes) { | |
8292 | nbytes = -1; | |
8293 | } | |
8294 | @@ -532,7 +570,7 @@ | |
8295 | } | |
8296 | nbytes += got; | |
8297 | } | |
8298 | - | |
8299 | + | |
8300 | if (nbytes <= 0) { | |
8301 | if (src->start_of_file) { /* Treat empty input file as fatal error */ | |
8302 | ERREXIT (cinfo, JERR_INPUT_EMPTY); | |
8303 | @@ -634,7 +672,7 @@ | |
8304 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (my_source_mgr)); | |
8305 | src = (my_src_ptr) cinfo->src; | |
8306 | src->buffer = (unsigned char *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, INPUT_BUF_SIZE * sizeof (unsigned char)); | |
8307 | - | |
8308 | + | |
8309 | } | |
8310 | ||
8311 | src = (my_src_ptr) cinfo->src; | |
8312 | diff -urN php-4.4.8.org/ext/gd/libgd/gdkanji.c php-4.4.8/ext/gd/libgd/gdkanji.c | |
8313 | --- php-4.4.8.org/ext/gd/libgd/gdkanji.c 2003-04-05 19:24:16.000000000 +0200 | |
8314 | +++ php-4.4.8/ext/gd/libgd/gdkanji.c 2003-12-28 21:11:08.000000000 +0100 | |
8315 | @@ -75,7 +75,7 @@ | |
8316 | va_list args; | |
8317 | char *tmp; | |
8318 | TSRMLS_FETCH(); | |
8319 | - | |
8320 | + | |
8321 | va_start(args, format); | |
8322 | vspprintf(&tmp, 0, format, args); | |
8323 | va_end(args); | |
8324 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_png.c php-4.4.8/ext/gd/libgd/gd_png.c | |
8325 | --- php-4.4.8.org/ext/gd/libgd/gd_png.c 2007-05-17 00:54:11.000000000 +0200 | |
8326 | +++ php-4.4.8/ext/gd/libgd/gd_png.c 2007-05-17 00:19:08.000000000 +0200 | |
8327 | @@ -23,7 +23,7 @@ | |
8328 | out all fprintf() statements to disable that). | |
8329 | ||
8330 | GD 2.0 supports RGBA truecolor and will read and write truecolor PNGs. | |
8331 | - GD 2.0 supports 8 bits of color resolution per channel and | |
8332 | + GD 2.0 supports 8 bits of color resolution per channel and | |
8333 | 7 bits of alpha channel resolution. Images with more than 8 bits | |
8334 | per channel are reduced to 8 bits. Images with an alpha channel are | |
8335 | only able to resolve down to '1/128th opaque' instead of '1/256th', | |
8336 | @@ -58,11 +58,11 @@ | |
8337 | * been defined. | |
8338 | */ | |
8339 | ||
8340 | - php_gd_error_ex(E_ERROR, "gd-png: fatal libpng error: %s\n", msg); | |
8341 | + php_gd_error_ex(E_WARNING, "gd-png: fatal libpng error: %s", msg); | |
8342 | ||
8343 | jmpbuf_ptr = png_get_error_ptr (png_ptr); | |
8344 | if (jmpbuf_ptr == NULL) { /* we are completely hosed now */ | |
8345 | - php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n"); | |
8346 | + php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating."); | |
8347 | } | |
8348 | ||
8349 | longjmp (jmpbuf_ptr->jmpbuf, 1); | |
8350 | @@ -130,12 +130,15 @@ | |
8351 | ||
8352 | /* Make sure the signature can't match by dumb luck -- TBB */ | |
8353 | /* GRR: isn't sizeof(infile) equal to the size of the pointer? */ | |
8354 | - memset (infile, 0, sizeof(infile)); | |
8355 | + memset (sig, 0, sizeof(sig)); | |
8356 | ||
8357 | /* first do a quick check that the file really is a PNG image; could | |
8358 | - * have used slightly more general png_sig_cmp() function instead | |
8359 | + * have used slightly more general png_sig_cmp() function instead | |
8360 | */ | |
8361 | - gdGetBuf(sig, 8, infile); | |
8362 | + if (gdGetBuf(sig, 8, infile) < 8) { | |
8363 | + return NULL; | |
8364 | + } | |
8365 | + | |
8366 | if (!png_check_sig (sig, 8)) { /* bad signature */ | |
8367 | return NULL; | |
8368 | } | |
8369 | @@ -146,13 +149,13 @@ | |
8370 | png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); | |
8371 | #endif | |
8372 | if (png_ptr == NULL) { | |
8373 | - php_gd_error("gd-png error: cannot allocate libpng main struct\n"); | |
8374 | + php_gd_error("gd-png error: cannot allocate libpng main struct"); | |
8375 | return NULL; | |
8376 | } | |
8377 | ||
8378 | info_ptr = png_create_info_struct(png_ptr); | |
8379 | if (info_ptr == NULL) { | |
8380 | - php_gd_error("gd-png error: cannot allocate libpng info struct\n"); | |
8381 | + php_gd_error("gd-png error: cannot allocate libpng info struct"); | |
8382 | png_destroy_read_struct (&png_ptr, NULL, NULL); | |
8383 | ||
8384 | return NULL; | |
8385 | @@ -160,7 +163,7 @@ | |
8386 | ||
8387 | /* we could create a second info struct here (end_info), but it's only | |
8388 | * useful if we want to keep pre- and post-IDAT chunk info separated | |
8389 | - * (mainly for PNG-aware image editors and converters) | |
8390 | + * (mainly for PNG-aware image editors and converters) | |
8391 | */ | |
8392 | ||
8393 | /* setjmp() must be called in every non-callback function that calls a | |
8394 | @@ -168,7 +171,7 @@ | |
8395 | */ | |
8396 | #ifndef PNG_SETJMP_NOT_SUPPORTED | |
8397 | if (setjmp(gdPngJmpbufStruct.jmpbuf)) { | |
8398 | - php_gd_error("gd-png error: setjmp returns error condition\n"); | |
8399 | + php_gd_error("gd-png error: setjmp returns error condition"); | |
8400 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | |
8401 | ||
8402 | return NULL; | |
8403 | @@ -187,7 +190,7 @@ | |
8404 | im = gdImageCreate((int) width, (int) height); | |
8405 | } | |
8406 | if (im == NULL) { | |
8407 | - php_gd_error("gd-png error: cannot allocate gdImage struct\n"); | |
8408 | + php_gd_error("gd-png error: cannot allocate gdImage struct"); | |
8409 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | |
8410 | gdFree(image_data); | |
8411 | gdFree(row_pointers); | |
8412 | @@ -201,15 +204,32 @@ | |
8413 | png_set_packing (png_ptr); /* expand to 1 byte per pixel */ | |
8414 | } | |
8415 | ||
8416 | + /* setjmp() must be called in every non-callback function that calls a | |
8417 | + * PNG-reading libpng function | |
8418 | + */ | |
8419 | +#ifndef PNG_SETJMP_NOT_SUPPORTED | |
8420 | + if (setjmp(gdPngJmpbufStruct.jmpbuf)) { | |
8421 | + php_gd_error("gd-png error: setjmp returns error condition"); | |
8422 | + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | |
8423 | + gdFree(image_data); | |
8424 | + gdFree(row_pointers); | |
8425 | + if (im) { | |
8426 | + gdImageDestroy(im); | |
8427 | + } | |
8428 | + return NULL; | |
8429 | + } | |
8430 | +#endif | |
8431 | + | |
8432 | + | |
8433 | switch (color_type) { | |
8434 | case PNG_COLOR_TYPE_PALETTE: | |
8435 | png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); | |
8436 | #ifdef DEBUG | |
8437 | - php_gd_error("gd-png color_type is palette, colors: %d\n", num_palette); | |
8438 | + php_gd_error("gd-png color_type is palette, colors: %d", num_palette); | |
8439 | #endif /* DEBUG */ | |
8440 | if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) { | |
8441 | /* gd 2.0: we support this rather thoroughly now. Grab the | |
8442 | - * first fully transparent entry, if any, as the value of | |
8443 | + * first fully transparent entry, if any, as the value of | |
8444 | * the simple-transparency index, mostly for backwards | |
8445 | * binary compatibility. The alpha channel is where it's | |
8446 | * really at these days. | |
8447 | @@ -228,8 +248,8 @@ | |
8448 | case PNG_COLOR_TYPE_GRAY: | |
8449 | case PNG_COLOR_TYPE_GRAY_ALPHA: | |
8450 | /* create a fake palette and check for single-shade transparency */ | |
8451 | - if ((palette = (png_colorp) safe_emalloc(256, sizeof(png_color), 0)) == NULL) { | |
8452 | - php_gd_error("gd-png error: cannot allocate gray palette\n"); | |
8453 | + if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL) { | |
8454 | + php_gd_error("gd-png error: cannot allocate gray palette"); | |
8455 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | |
8456 | ||
8457 | return NULL; | |
8458 | @@ -263,7 +283,7 @@ | |
8459 | * custom 16-bit code to handle the case where there are gdFree | |
8460 | * palette entries. This error will be extremely rare in | |
8461 | * general, though. (Quite possibly there is only one such | |
8462 | - * image in existence.) | |
8463 | + * image in existence.) | |
8464 | */ | |
8465 | } | |
8466 | break; | |
8467 | @@ -272,16 +292,16 @@ | |
8468 | case PNG_COLOR_TYPE_RGB_ALPHA: | |
8469 | /* gd 2.0: we now support truecolor. See the comment above | |
8470 | * for a rare situation in which the transparent pixel may not | |
8471 | - * work properly with 16-bit channels. | |
8472 | + * work properly with 16-bit channels. | |
8473 | */ | |
8474 | if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { | |
8475 | png_get_tRNS(png_ptr, info_ptr, NULL, NULL, &trans_color_rgb); | |
8476 | if (bit_depth == 16) { /* png_set_strip_16() not yet in effect */ | |
8477 | - transparent = gdTrueColor(trans_color_rgb->red >> 8, | |
8478 | + transparent = gdTrueColor(trans_color_rgb->red >> 8, | |
8479 | trans_color_rgb->green >> 8, | |
8480 | trans_color_rgb->blue >> 8); | |
8481 | } else { | |
8482 | - transparent = gdTrueColor(trans_color_rgb->red, | |
8483 | + transparent = gdTrueColor(trans_color_rgb->red, | |
8484 | trans_color_rgb->green, | |
8485 | trans_color_rgb->blue); | |
8486 | } | |
8487 | @@ -295,7 +315,7 @@ | |
8488 | rowbytes = png_get_rowbytes(png_ptr, info_ptr); | |
8489 | image_data = (png_bytep) safe_emalloc(rowbytes, height, 0); | |
8490 | ||
8491 | - row_pointers = (png_bytepp) safe_emalloc(height, sizeof (png_bytep), 0); | |
8492 | + row_pointers = (png_bytepp) safe_emalloc(height, sizeof(png_bytep), 0); | |
8493 | ||
8494 | /* set the individual row_pointers to point at the correct offsets */ | |
8495 | for (h = 0; h < height; ++h) { | |
8496 | @@ -349,7 +369,7 @@ | |
8497 | register png_byte b = row_pointers[h][boffset++]; | |
8498 | ||
8499 | /* gd has only 7 bits of alpha channel resolution, and | |
8500 | - * 127 is transparent, 0 opaque. A moment of convenience, | |
8501 | + * 127 is transparent, 0 opaque. A moment of convenience, | |
8502 | * a lifetime of compatibility. | |
8503 | */ | |
8504 | ||
8505 | @@ -373,7 +393,7 @@ | |
8506 | if (!im->trueColor) { | |
8507 | for (i = num_palette; i < gdMaxColors; ++i) { | |
8508 | if (!open[i]) { | |
8509 | - php_gd_error("gd-png warning: image data references out-of-range color index (%d)\n", i); | |
8510 | + php_gd_error("gd-png warning: image data references out-of-range color index (%d)", i); | |
8511 | } | |
8512 | } | |
8513 | } | |
8514 | @@ -388,17 +408,17 @@ | |
8515 | return im; | |
8516 | } | |
8517 | ||
8518 | -void gdImagePngEx (gdImagePtr im, FILE * outFile, int level) | |
8519 | +void gdImagePngEx (gdImagePtr im, FILE * outFile, int level, int basefilter) | |
8520 | { | |
8521 | gdIOCtx *out = gdNewFileCtx(outFile); | |
8522 | - gdImagePngCtxEx(im, out, level); | |
8523 | + gdImagePngCtxEx(im, out, level, basefilter); | |
8524 | out->gd_free(out); | |
8525 | } | |
8526 | ||
8527 | void gdImagePng (gdImagePtr im, FILE * outFile) | |
8528 | { | |
8529 | gdIOCtx *out = gdNewFileCtx(outFile); | |
8530 | - gdImagePngCtxEx(im, out, -1); | |
8531 | + gdImagePngCtxEx(im, out, -1, -1); | |
8532 | out->gd_free(out); | |
8533 | } | |
8534 | ||
8535 | @@ -406,18 +426,18 @@ | |
8536 | { | |
8537 | void *rv; | |
8538 | gdIOCtx *out = gdNewDynamicCtx(2048, NULL); | |
8539 | - gdImagePngCtxEx(im, out, -1); | |
8540 | + gdImagePngCtxEx(im, out, -1, -1); | |
8541 | rv = gdDPExtractData(out, size); | |
8542 | out->gd_free(out); | |
8543 | ||
8544 | return rv; | |
8545 | } | |
8546 | ||
8547 | -void * gdImagePngPtrEx (gdImagePtr im, int *size, int level) | |
8548 | +void * gdImagePngPtrEx (gdImagePtr im, int *size, int level, int basefilter) | |
8549 | { | |
8550 | void *rv; | |
8551 | gdIOCtx *out = gdNewDynamicCtx(2048, NULL); | |
8552 | - gdImagePngCtxEx(im, out, level); | |
8553 | + gdImagePngCtxEx(im, out, level, basefilter); | |
8554 | rv = gdDPExtractData(out, size); | |
8555 | out->gd_free(out); | |
8556 | return rv; | |
8557 | @@ -425,14 +445,14 @@ | |
8558 | ||
8559 | void gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile) | |
8560 | { | |
8561 | - gdImagePngCtxEx(im, outfile, -1); | |
8562 | + gdImagePngCtxEx(im, outfile, -1, -1); | |
8563 | } | |
8564 | ||
8565 | /* This routine is based in part on code from Dale Lutz (Safe Software Inc.) | |
8566 | * and in part on demo code from Chapter 15 of "PNG: The Definitive Guide" | |
8567 | * (http://www.cdrom.com/pub/png/pngbook.html). | |
8568 | */ | |
8569 | -void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level) | |
8570 | +void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilter) | |
8571 | { | |
8572 | int i, j, bit_depth = 0, interlace_type; | |
8573 | int width = im->sx; | |
8574 | @@ -454,13 +474,13 @@ | |
8575 | png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); | |
8576 | #endif | |
8577 | if (png_ptr == NULL) { | |
8578 | - php_gd_error("gd-png error: cannot allocate libpng main struct\n"); | |
8579 | + php_gd_error("gd-png error: cannot allocate libpng main struct"); | |
8580 | return; | |
8581 | } | |
8582 | ||
8583 | info_ptr = png_create_info_struct(png_ptr); | |
8584 | if (info_ptr == NULL) { | |
8585 | - php_gd_error("gd-png error: cannot allocate libpng info struct\n"); | |
8586 | + php_gd_error("gd-png error: cannot allocate libpng info struct"); | |
8587 | png_destroy_write_struct (&png_ptr, (png_infopp) NULL); | |
8588 | ||
8589 | return; | |
8590 | @@ -468,7 +488,7 @@ | |
8591 | ||
8592 | #ifndef PNG_SETJMP_NOT_SUPPORTED | |
8593 | if (setjmp (gdPngJmpbufStruct.jmpbuf)) { | |
8594 | - php_gd_error("gd-png error: setjmp returns error condition\n"); | |
8595 | + php_gd_error("gd-png error: setjmp returns error condition"); | |
8596 | png_destroy_write_struct (&png_ptr, &info_ptr); | |
8597 | ||
8598 | return; | |
8599 | @@ -483,14 +503,17 @@ | |
8600 | * gd is intentionally imperfect and doesn't spend a lot of time | |
8601 | * fussing with such things. | |
8602 | */ | |
8603 | - | |
8604 | + | |
8605 | /* png_set_filter(png_ptr, 0, PNG_FILTER_NONE); */ | |
8606 | ||
8607 | /* 2.0.12: this is finally a parameter */ | |
8608 | png_set_compression_level(png_ptr, level); | |
8609 | + if (basefilter >= 0) { | |
8610 | + png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, basefilter); | |
8611 | + } | |
8612 | ||
8613 | /* can set this to a smaller value without compromising compression if all | |
8614 | - * image data is 16K or less; will save some decoder memory [min == 8] | |
8615 | + * image data is 16K or less; will save some decoder memory [min == 8] | |
8616 | */ | |
8617 | ||
8618 | /* png_set_compression_window_bits(png_ptr, 15); */ | |
8619 | @@ -519,13 +542,13 @@ | |
8620 | bit_depth = 1; | |
8621 | } else if (colors <= 4) { | |
8622 | bit_depth = 2; | |
8623 | - } else if (colors <= 16) { | |
8624 | + } else if (colors <= 16) { | |
8625 | bit_depth = 4; | |
8626 | } else { | |
8627 | bit_depth = 8; | |
8628 | } | |
8629 | } | |
8630 | - | |
8631 | + | |
8632 | interlace_type = im->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE; | |
8633 | ||
8634 | if (im->trueColor) { | |
8635 | @@ -552,9 +575,9 @@ | |
8636 | if (!im->trueColor) { | |
8637 | /* Oy veh. Remap the PNG palette to put the entries with interesting alpha channel | |
8638 | * values first. This minimizes the size of the tRNS chunk and thus the size | |
8639 | - * of the PNG file as a whole. | |
8640 | + * of the PNG file as a whole. | |
8641 | */ | |
8642 | - | |
8643 | + | |
8644 | int tc = 0; | |
8645 | int i; | |
8646 | int j; | |
8647 | @@ -585,7 +608,7 @@ | |
8648 | for (i = 0; i < im->colorsTotal; i++) { | |
8649 | if (!im->open[i]) { | |
8650 | if (im->alpha[i] != gdAlphaOpaque) { | |
8651 | - /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */ | |
8652 | + /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */ | |
8653 | trans_values[j] = 255 - ((im->alpha[i] << 1) + (im->alpha[i] >> 6)); | |
8654 | mapping[i] = j++; | |
8655 | } else { | |
8656 | @@ -665,7 +688,7 @@ | |
8657 | * PNG's convention in which 255 is opaque. | |
8658 | */ | |
8659 | a = gdTrueColorGetAlpha(thisPixel); | |
8660 | - /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */ | |
8661 | + /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */ | |
8662 | *pOutputRow++ = 255 - ((a << 1) + (a >> 6)); | |
8663 | } | |
8664 | } | |
8665 | @@ -677,12 +700,12 @@ | |
8666 | for (j = 0; j < height; ++j) { | |
8667 | gdFree(row_pointers[j]); | |
8668 | } | |
8669 | - | |
8670 | + | |
8671 | gdFree(row_pointers); | |
8672 | } else { | |
8673 | if (remap) { | |
8674 | png_bytep *row_pointers; | |
8675 | - row_pointers = safe_emalloc(sizeof(png_bytep), height, 0); | |
8676 | + row_pointers = safe_emalloc(height, sizeof(png_bytep), 0); | |
8677 | for (j = 0; j < height; ++j) { | |
8678 | row_pointers[j] = (png_bytep) gdMalloc(width); | |
8679 | for (i = 0; i < width; ++i) { | |
8680 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_security.c php-4.4.8/ext/gd/libgd/gd_security.c | |
8681 | --- php-4.4.8.org/ext/gd/libgd/gd_security.c 2007-03-10 14:06:37.000000000 +0100 | |
8682 | +++ php-4.4.8/ext/gd/libgd/gd_security.c 2007-10-23 03:58:08.000000000 +0200 | |
8683 | @@ -19,12 +19,10 @@ | |
8684 | ||
8685 | int overflow2(int a, int b) | |
8686 | { | |
8687 | - if(a < 0 || b < 0) { | |
8688 | - php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative, failing operation gracefully\n"); | |
8689 | + if(a <= 0 || b <= 0) { | |
8690 | + php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n"); | |
8691 | return 1; | |
8692 | } | |
8693 | - if(b == 0) | |
8694 | - return 0; | |
8695 | if(a > INT_MAX / b) { | |
8696 | php_gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n"); | |
8697 | return 1; | |
8698 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_ss.c php-4.4.8/ext/gd/libgd/gd_ss.c | |
8699 | --- php-4.4.8.org/ext/gd/libgd/gd_ss.c 2003-03-05 17:04:20.000000000 +0100 | |
8700 | +++ php-4.4.8/ext/gd/libgd/gd_ss.c 2005-08-18 14:54:44.000000000 +0200 | |
8701 | @@ -17,37 +17,33 @@ | |
8702 | #define GD_SS_DBG(s) | |
8703 | ||
8704 | #ifdef HAVE_LIBPNG | |
8705 | -void | |
8706 | -gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink) | |
8707 | +void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink) | |
8708 | { | |
8709 | - gdIOCtx *out = gdNewSSCtx (NULL, outSink); | |
8710 | - gdImagePngCtx (im, out); | |
8711 | - out->gd_free (out); | |
8712 | + gdIOCtx *out = gdNewSSCtx(NULL, outSink); | |
8713 | + gdImagePngCtx(im, out); | |
8714 | + out->gd_free(out); | |
8715 | } | |
8716 | ||
8717 | -gdImagePtr | |
8718 | -gdImageCreateFromPngSource (gdSourcePtr inSource) | |
8719 | +gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource) | |
8720 | { | |
8721 | - gdIOCtx *in = gdNewSSCtx (inSource, NULL); | |
8722 | - gdImagePtr im; | |
8723 | + gdIOCtx *in = gdNewSSCtx(inSource, NULL); | |
8724 | + gdImagePtr im; | |
8725 | ||
8726 | - im = gdImageCreateFromPngCtx (in); | |
8727 | + im = gdImageCreateFromPngCtx(in); | |
8728 | ||
8729 | - in->gd_free (in); | |
8730 | + in->gd_free(in); | |
8731 | ||
8732 | - return im; | |
8733 | + return im; | |
8734 | } | |
8735 | #else /* no HAVE_LIBPNG */ | |
8736 | -void | |
8737 | -gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink) | |
8738 | +void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink) | |
8739 | { | |
8740 | - php_gd_error("PNG support is not available\n"); | |
8741 | + php_gd_error("PNG support is not available"); | |
8742 | } | |
8743 | -gdImagePtr | |
8744 | -gdImageCreateFromPngSource (gdSourcePtr inSource) | |
8745 | +gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource) | |
8746 | { | |
8747 | - php_gd_error("PNG support is not available\n"); | |
8748 | - return NULL; | |
8749 | + php_gd_error("PNG support is not available"); | |
8750 | + return NULL; | |
8751 | } | |
8752 | #endif /* HAVE_LIBPNG */ | |
8753 | ||
8754 | diff -urN php-4.4.8.org/ext/gd/libgd/gdtables.c php-4.4.8/ext/gd/libgd/gdtables.c | |
8755 | --- php-4.4.8.org/ext/gd/libgd/gdtables.c 2002-04-13 04:03:09.000000000 +0200 | |
8756 | +++ php-4.4.8/ext/gd/libgd/gdtables.c 2006-09-15 17:11:54.000000000 +0200 | |
8757 | @@ -1,5 +1,11 @@ | |
8758 | ||
8759 | -int gdCosT[] = | |
8760 | +#ifdef HAVE_CONFIG_H | |
8761 | +#include "config.h" | |
8762 | +#endif | |
8763 | + | |
8764 | +#include "php_compat.h" | |
8765 | + | |
8766 | +const int gdCosT[] = | |
8767 | { | |
8768 | 1024, | |
8769 | 1023, | |
8770 | @@ -363,7 +369,7 @@ | |
8771 | 1023 | |
8772 | }; | |
8773 | ||
8774 | -int gdSinT[] = | |
8775 | +const int gdSinT[] = | |
8776 | { | |
8777 | 0, | |
8778 | 17, | |
8779 | diff -urN php-4.4.8.org/ext/gd/libgd/gdtest.c php-4.4.8/ext/gd/libgd/gdtest.c | |
8780 | --- php-4.4.8.org/ext/gd/libgd/gdtest.c 2002-10-30 00:08:01.000000000 +0100 | |
8781 | +++ php-4.4.8/ext/gd/libgd/gdtest.c 2007-02-24 03:17:24.000000000 +0100 | |
8782 | @@ -56,7 +56,7 @@ | |
8783 | /* */ | |
8784 | /* Send to PNG File then Ptr */ | |
8785 | /* */ | |
8786 | - sprintf (of, "%s.png", argv[1]); | |
8787 | + snprintf (of, sizeof(of), "%s.png", argv[1]); | |
8788 | out = fopen (of, "wb"); | |
8789 | gdImagePng (im, out); | |
8790 | fclose (out); | |
8791 | @@ -88,7 +88,7 @@ | |
8792 | /* */ | |
8793 | /* Send to GD2 File then Ptr */ | |
8794 | /* */ | |
8795 | - sprintf (of, "%s.gd2", argv[1]); | |
8796 | + snprintf (of, sizeof(of), "%s.gd2", argv[1]); | |
8797 | out = fopen (of, "wb"); | |
8798 | gdImageGd2 (im, out, 128, 2); | |
8799 | fclose (out); | |
8800 | @@ -123,7 +123,7 @@ | |
8801 | /* */ | |
8802 | /* Send to GD File then Ptr */ | |
8803 | /* */ | |
8804 | - sprintf (of, "%s.gd", argv[1]); | |
8805 | + snprintf (of, sizeof(of), "%s.gd", argv[1]); | |
8806 | out = fopen (of, "wb"); | |
8807 | gdImageGd (im, out); | |
8808 | fclose (out); | |
8809 | @@ -180,7 +180,7 @@ | |
8810 | ** Test gdImagePngToSink' | |
8811 | * */ | |
8812 | ||
8813 | - sprintf (of, "%s.snk", argv[1]); | |
8814 | + snprintf (of, sizeof(of), "%s.snk", argv[1]); | |
8815 | out = fopen (of, "wb"); | |
8816 | imgsnk.sink = fwriteWrapper; | |
8817 | imgsnk.context = out; | |
8818 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_topal.c php-4.4.8/ext/gd/libgd/gd_topal.c | |
8819 | --- php-4.4.8.org/ext/gd/libgd/gd_topal.c 2004-08-12 01:25:54.000000000 +0200 | |
8820 | +++ php-4.4.8/ext/gd/libgd/gd_topal.c 2007-04-04 02:30:18.000000000 +0200 | |
8821 | @@ -772,6 +772,7 @@ | |
8822 | nim->green[icolor] = 255; | |
8823 | nim->blue[icolor] = 255; | |
8824 | } | |
8825 | + nim->open[icolor] = 0; | |
8826 | #endif | |
8827 | } | |
8828 | ||
8829 | @@ -2086,6 +2087,9 @@ | |
8830 | if( (im1->sx != im2->sx) || (im1->sy != im2->sy) ) { | |
8831 | return -3; /* the images are meant to be the same dimensions */ | |
8832 | } | |
8833 | + if (im2->colorsTotal<1) { | |
8834 | + return -4; /* At least 1 color must be allocated */ | |
8835 | + } | |
8836 | ||
8837 | buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0); | |
8838 | memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal ); | |
8839 | diff -urN php-4.4.8.org/ext/gd/libgd/gd_wbmp.c php-4.4.8/ext/gd/libgd/gd_wbmp.c | |
8840 | --- php-4.4.8.org/ext/gd/libgd/gd_wbmp.c 2004-03-29 20:21:00.000000000 +0200 | |
8841 | +++ php-4.4.8/ext/gd/libgd/gd_wbmp.c 2005-08-18 14:54:44.000000000 +0200 | |
8842 | @@ -1,10 +1,8 @@ | |
8843 | - | |
8844 | - | |
8845 | /* | |
8846 | WBMP: Wireless Bitmap Type 0: B/W, Uncompressed Bitmap | |
8847 | - Specification of the WBMP format can be found in the file: | |
8848 | + Specification of the WBMP format can be found in the file: | |
8849 | SPEC-WAESpec-19990524.pdf | |
8850 | - You can download the WAP specification on: http://www.wapforum.com/ | |
8851 | + You can download the WAP specification on: http://www.wapforum.com/ | |
8852 | ||
8853 | gd_wbmp.c | |
8854 | ||
8855 | @@ -16,7 +14,7 @@ | |
8856 | (wbmp library included, but you can find the latest distribution | |
8857 | at http://www.vandenbrande.com/wbmp) | |
8858 | ||
8859 | - Implemented: gdImageCreateFromWBMPCtx, gdImageCreateFromWBMP | |
8860 | + Implemented: gdImageCreateFromWBMPCtx, gdImageCreateFromWBMP | |
8861 | ||
8862 | --------------------------------------------------------------------------- | |
8863 | ||
8864 | @@ -34,7 +32,7 @@ | |
8865 | ** implied warranty. | |
8866 | ||
8867 | --------------------------------------------------------------------------- | |
8868 | - Parts od this code are inspired by 'pbmtowbmp.c' and 'wbmptopbm.c' by | |
8869 | + Parts od this code are inspired by 'pbmtowbmp.c' and 'wbmptopbm.c' by | |
8870 | Terje Sannum <terje@looplab.com>. | |
8871 | ** | |
8872 | ** Permission to use, copy, modify, and distribute this software and its | |
8873 | @@ -67,10 +65,9 @@ | |
8874 | ** Wrapper around gdPutC for use with writewbmp | |
8875 | ** | |
8876 | */ | |
8877 | -void | |
8878 | -gd_putout (int i, void *out) | |
8879 | +void gd_putout (int i, void *out) | |
8880 | { | |
8881 | - gdPutC (i, (gdIOCtx *) out); | |
8882 | + gdPutC(i, (gdIOCtx *) out); | |
8883 | } | |
8884 | ||
8885 | ||
8886 | @@ -79,10 +76,9 @@ | |
8887 | ** Wrapper around gdGetC for use with readwbmp | |
8888 | ** | |
8889 | */ | |
8890 | -int | |
8891 | -gd_getin (void *in) | |
8892 | +int gd_getin (void *in) | |
8893 | { | |
8894 | - return (gdGetC ((gdIOCtx *) in)); | |
8895 | + return (gdGetC((gdIOCtx *) in)); | |
8896 | } | |
8897 | ||
8898 | ||
8899 | @@ -91,105 +87,93 @@ | |
8900 | ** Write the image as a wbmp file | |
8901 | ** Parameters are: | |
8902 | ** image: gd image structure; | |
8903 | - ** fg: the index of the foreground color. any other value will be | |
8904 | + ** fg: the index of the foreground color. any other value will be | |
8905 | ** considered as background and will not be written | |
8906 | ** out: the stream where to write | |
8907 | */ | |
8908 | -void | |
8909 | -gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out) | |
8910 | +void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out) | |
8911 | { | |
8912 | + int x, y, pos; | |
8913 | + Wbmp *wbmp; | |
8914 | ||
8915 | - int x, y, pos; | |
8916 | - Wbmp *wbmp; | |
8917 | + /* create the WBMP */ | |
8918 | + if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) { | |
8919 | + php_gd_error("Could not create WBMP"); | |
8920 | + } | |
8921 | ||
8922 | + /* fill up the WBMP structure */ | |
8923 | + pos = 0; | |
8924 | + for (y = 0; y < gdImageSY(image); y++) { | |
8925 | + for (x = 0; x < gdImageSX(image); x++) { | |
8926 | + if (gdImageGetPixel (image, x, y) == fg) { | |
8927 | + wbmp->bitmap[pos] = WBMP_BLACK; | |
8928 | + } | |
8929 | + pos++; | |
8930 | + } | |
8931 | + } | |
8932 | ||
8933 | - /* create the WBMP */ | |
8934 | - if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) | |
8935 | - php_gd_error("Could not create WBMP\n"); | |
8936 | - | |
8937 | - /* fill up the WBMP structure */ | |
8938 | - pos = 0; | |
8939 | - for (y = 0; y < gdImageSY (image); y++) | |
8940 | - { | |
8941 | - for (x = 0; x < gdImageSX (image); x++) | |
8942 | - { | |
8943 | - if (gdImageGetPixel (image, x, y) == fg) | |
8944 | - { | |
8945 | - wbmp->bitmap[pos] = WBMP_BLACK; | |
8946 | - } | |
8947 | - pos++; | |
8948 | - } | |
8949 | - } | |
8950 | - | |
8951 | - /* write the WBMP to a gd file descriptor */ | |
8952 | - if (writewbmp (wbmp, &gd_putout, out)) | |
8953 | - php_gd_error("Could not save WBMP\n"); | |
8954 | - /* des submitted this bugfix: gdFree the memory. */ | |
8955 | - freewbmp (wbmp); | |
8956 | + /* write the WBMP to a gd file descriptor */ | |
8957 | + if (writewbmp (wbmp, &gd_putout, out)) { | |
8958 | + php_gd_error("Could not save WBMP"); | |
8959 | + } | |
8960 | + /* des submitted this bugfix: gdFree the memory. */ | |
8961 | + freewbmp(wbmp); | |
8962 | } | |
8963 | ||
8964 | - | |
8965 | /* gdImageCreateFromWBMPCtx | |
8966 | ** ------------------------ | |
8967 | ** Create a gdImage from a WBMP file input from an gdIOCtx | |
8968 | */ | |
8969 | -gdImagePtr | |
8970 | -gdImageCreateFromWBMPCtx (gdIOCtx * infile) | |
8971 | +gdImagePtr gdImageCreateFromWBMPCtx (gdIOCtx * infile) | |
8972 | { | |
8973 | - /* FILE *wbmp_file; */ | |
8974 | - Wbmp *wbmp; | |
8975 | - gdImagePtr im = NULL; | |
8976 | - int black, white; | |
8977 | - int col, row, pos; | |
8978 | - | |
8979 | - if (readwbmp (&gd_getin, infile, &wbmp)) | |
8980 | - return (NULL); | |
8981 | - | |
8982 | - if (!(im = gdImageCreate (wbmp->width, wbmp->height))) | |
8983 | - { | |
8984 | - freewbmp (wbmp); | |
8985 | - return (NULL); | |
8986 | - } | |
8987 | - | |
8988 | - /* create the background color */ | |
8989 | - white = gdImageColorAllocate (im, 255, 255, 255); | |
8990 | - /* create foreground color */ | |
8991 | - black = gdImageColorAllocate (im, 0, 0, 0); | |
8992 | - | |
8993 | - /* fill in image (in a wbmp 1 = white/ 0 = black) */ | |
8994 | - pos = 0; | |
8995 | - for (row = 0; row < wbmp->height; row++) | |
8996 | - { | |
8997 | - for (col = 0; col < wbmp->width; col++) | |
8998 | - { | |
8999 | - if (wbmp->bitmap[pos++] == WBMP_WHITE) | |
9000 | - { | |
9001 | - gdImageSetPixel (im, col, row, white); | |
9002 | - } | |
9003 | - else | |
9004 | - { | |
9005 | - gdImageSetPixel (im, col, row, black); | |
9006 | - } | |
9007 | + /* FILE *wbmp_file; */ | |
9008 | + Wbmp *wbmp; | |
9009 | + gdImagePtr im = NULL; | |
9010 | + int black, white; | |
9011 | + int col, row, pos; | |
9012 | + | |
9013 | + if (readwbmp (&gd_getin, infile, &wbmp)) { | |
9014 | + return NULL; | |
9015 | } | |
9016 | - } | |
9017 | ||
9018 | - freewbmp (wbmp); | |
9019 | + if (!(im = gdImageCreate (wbmp->width, wbmp->height))) { | |
9020 | + freewbmp (wbmp); | |
9021 | + return NULL; | |
9022 | + } | |
9023 | ||
9024 | - return (im); | |
9025 | -} | |
9026 | + /* create the background color */ | |
9027 | + white = gdImageColorAllocate(im, 255, 255, 255); | |
9028 | + /* create foreground color */ | |
9029 | + black = gdImageColorAllocate(im, 0, 0, 0); | |
9030 | + | |
9031 | + /* fill in image (in a wbmp 1 = white/ 0 = black) */ | |
9032 | + pos = 0; | |
9033 | + for (row = 0; row < wbmp->height; row++) { | |
9034 | + for (col = 0; col < wbmp->width; col++) { | |
9035 | + if (wbmp->bitmap[pos++] == WBMP_WHITE) { | |
9036 | + gdImageSetPixel(im, col, row, white); | |
9037 | + } else { | |
9038 | + gdImageSetPixel(im, col, row, black); | |
9039 | + } | |
9040 | + } | |
9041 | + } | |
9042 | ||
9043 | + freewbmp(wbmp); | |
9044 | + | |
9045 | + return im; | |
9046 | +} | |
9047 | ||
9048 | /* gdImageCreateFromWBMP | |
9049 | ** --------------------- | |
9050 | */ | |
9051 | -gdImagePtr | |
9052 | -gdImageCreateFromWBMP (FILE * inFile) | |
9053 | +gdImagePtr gdImageCreateFromWBMP (FILE * inFile) | |
9054 | { | |
9055 | - gdImagePtr im; | |
9056 | - gdIOCtx *in = gdNewFileCtx (inFile); | |
9057 | - im = gdImageCreateFromWBMPCtx (in); | |
9058 | - in->gd_free (in); | |
9059 | - return (im); | |
9060 | + gdImagePtr im; | |
9061 | + gdIOCtx *in = gdNewFileCtx(inFile); | |
9062 | + im = gdImageCreateFromWBMPCtx(in); | |
9063 | + in->gd_free(in); | |
9064 | + | |
9065 | + return im; | |
9066 | } | |
9067 | ||
9068 | gdImagePtr gdImageCreateFromWBMPPtr (int size, void *data) | |
9069 | @@ -204,24 +188,23 @@ | |
9070 | /* gdImageWBMP | |
9071 | ** ----------- | |
9072 | */ | |
9073 | -void | |
9074 | -gdImageWBMP (gdImagePtr im, int fg, FILE * outFile) | |
9075 | +void gdImageWBMP (gdImagePtr im, int fg, FILE * outFile) | |
9076 | { | |
9077 | - gdIOCtx *out = gdNewFileCtx (outFile); | |
9078 | - gdImageWBMPCtx (im, fg, out); | |
9079 | - out->gd_free (out); | |
9080 | + gdIOCtx *out = gdNewFileCtx(outFile); | |
9081 | + gdImageWBMPCtx(im, fg, out); | |
9082 | + out->gd_free(out); | |
9083 | } | |
9084 | ||
9085 | /* gdImageWBMPPtr | |
9086 | ** -------------- | |
9087 | */ | |
9088 | -void * | |
9089 | -gdImageWBMPPtr (gdImagePtr im, int *size, int fg) | |
9090 | +void * gdImageWBMPPtr (gdImagePtr im, int *size, int fg) | |
9091 | { | |
9092 | - void *rv; | |
9093 | - gdIOCtx *out = gdNewDynamicCtx (2048, NULL); | |
9094 | - gdImageWBMPCtx (im, fg, out); | |
9095 | - rv = gdDPExtractData (out, size); | |
9096 | - out->gd_free (out); | |
9097 | - return rv; | |
9098 | + void *rv; | |
9099 | + gdIOCtx *out = gdNewDynamicCtx(2048, NULL); | |
9100 | + gdImageWBMPCtx(im, fg, out); | |
9101 | + rv = gdDPExtractData(out, size); | |
9102 | + out->gd_free(out); | |
9103 | + | |
9104 | + return rv; | |
9105 | } | |
9106 | diff -urN php-4.4.8.org/ext/gd/libgd/gdxpm.c php-4.4.8/ext/gd/libgd/gdxpm.c | |
9107 | --- php-4.4.8.org/ext/gd/libgd/gdxpm.c 2003-06-04 01:42:49.000000000 +0200 | |
9108 | +++ php-4.4.8/ext/gd/libgd/gdxpm.c 2005-08-18 14:54:44.000000000 +0200 | |
9109 | @@ -1,8 +1,8 @@ | |
9110 | ||
9111 | -/* | |
9112 | +/* | |
9113 | add ability to load xpm files to gd, requires the xpm | |
9114 | library. | |
9115 | - Caolan.McNamara@ul.ie | |
9116 | + Caolan.McNamara@ul.ie | |
9117 | http://www.csn.ul.ie/~caolan | |
9118 | */ | |
9119 | #include <stdio.h> | |
9120 | @@ -15,123 +15,125 @@ | |
9121 | ||
9122 | #include <X11/xpm.h> | |
9123 | ||
9124 | -gdImagePtr | |
9125 | -gdImageCreateFromXpm (char *filename) | |
9126 | +gdImagePtr gdImageCreateFromXpm (char *filename) | |
9127 | { | |
9128 | - XpmInfo info; | |
9129 | - XpmImage image; | |
9130 | - int i, j, k, number; | |
9131 | - char buf[5]; | |
9132 | - gdImagePtr im = 0; | |
9133 | - char *apixel; | |
9134 | - int *pointer; | |
9135 | - int red = 0, green = 0, blue = 0; | |
9136 | - int *colors; | |
9137 | - int ret; | |
9138 | - | |
9139 | - ret = XpmReadFileToXpmImage (filename, &image, &info); | |
9140 | - if (ret != XpmSuccess) | |
9141 | - return 0; | |
9142 | - | |
9143 | - if (!(im = gdImageCreate (image.width, image.height))) | |
9144 | - return 0; | |
9145 | - | |
9146 | - number = image.ncolors; | |
9147 | - colors = (int *) safe_emalloc(number, sizeof(int), 0); | |
9148 | - for (i = 0; i < number; i++) | |
9149 | - { | |
9150 | - switch (strlen (image.colorTable[i].c_color)) | |
9151 | - { | |
9152 | - case 4: | |
9153 | - buf[1] = '\0'; | |
9154 | - buf[0] = image.colorTable[i].c_color[1]; | |
9155 | - red = strtol (buf, NULL, 16); | |
9156 | - | |
9157 | - buf[0] = image.colorTable[i].c_color[3]; | |
9158 | - green = strtol (buf, NULL, 16); | |
9159 | - | |
9160 | - buf[0] = image.colorTable[i].c_color[5]; | |
9161 | - blue = strtol (buf, NULL, 16); | |
9162 | - break; | |
9163 | - case 7: | |
9164 | - buf[2] = '\0'; | |
9165 | - buf[0] = image.colorTable[i].c_color[1]; | |
9166 | - buf[1] = image.colorTable[i].c_color[2]; | |
9167 | - red = strtol (buf, NULL, 16); | |
9168 | - | |
9169 | - buf[0] = image.colorTable[i].c_color[3]; | |
9170 | - buf[1] = image.colorTable[i].c_color[4]; | |
9171 | - green = strtol (buf, NULL, 16); | |
9172 | - | |
9173 | - buf[0] = image.colorTable[i].c_color[5]; | |
9174 | - buf[1] = image.colorTable[i].c_color[6]; | |
9175 | - blue = strtol (buf, NULL, 16); | |
9176 | - break; | |
9177 | - case 10: | |
9178 | - buf[3] = '\0'; | |
9179 | - buf[0] = image.colorTable[i].c_color[1]; | |
9180 | - buf[1] = image.colorTable[i].c_color[2]; | |
9181 | - buf[2] = image.colorTable[i].c_color[3]; | |
9182 | - red = strtol (buf, NULL, 16); | |
9183 | - red /= 64; | |
9184 | - | |
9185 | - buf[0] = image.colorTable[i].c_color[4]; | |
9186 | - buf[1] = image.colorTable[i].c_color[5]; | |
9187 | - buf[2] = image.colorTable[i].c_color[6]; | |
9188 | - green = strtol (buf, NULL, 16); | |
9189 | - green /= 64; | |
9190 | - | |
9191 | - buf[0] = image.colorTable[i].c_color[7]; | |
9192 | - buf[1] = image.colorTable[i].c_color[8]; | |
9193 | - buf[2] = image.colorTable[i].c_color[9]; | |
9194 | - blue = strtol (buf, NULL, 16); | |
9195 | - blue /= 64; | |
9196 | - break; | |
9197 | - case 13: | |
9198 | - buf[4] = '\0'; | |
9199 | - buf[0] = image.colorTable[i].c_color[1]; | |
9200 | - buf[1] = image.colorTable[i].c_color[2]; | |
9201 | - buf[2] = image.colorTable[i].c_color[3]; | |
9202 | - buf[3] = image.colorTable[i].c_color[4]; | |
9203 | - red = strtol (buf, NULL, 16); | |
9204 | - red /= 256; | |
9205 | - | |
9206 | - buf[0] = image.colorTable[i].c_color[5]; | |
9207 | - buf[1] = image.colorTable[i].c_color[6]; | |
9208 | - buf[2] = image.colorTable[i].c_color[7]; | |
9209 | - buf[3] = image.colorTable[i].c_color[8]; | |
9210 | - green = strtol (buf, NULL, 16); | |
9211 | - green /= 256; | |
9212 | - | |
9213 | - buf[0] = image.colorTable[i].c_color[9]; | |
9214 | - buf[1] = image.colorTable[i].c_color[10]; | |
9215 | - buf[2] = image.colorTable[i].c_color[11]; | |
9216 | - buf[3] = image.colorTable[i].c_color[12]; | |
9217 | - blue = strtol (buf, NULL, 16); | |
9218 | - blue /= 256; | |
9219 | - break; | |
9220 | + XpmInfo info; | |
9221 | + XpmImage image; | |
9222 | + int i, j, k, number; | |
9223 | + char buf[5]; | |
9224 | + gdImagePtr im = 0; | |
9225 | + char *apixel; | |
9226 | + int *pointer; | |
9227 | + int red = 0, green = 0, blue = 0; | |
9228 | + int *colors; | |
9229 | + int ret; | |
9230 | + | |
9231 | + ret = XpmReadFileToXpmImage(filename, &image, &info); | |
9232 | + if (ret != XpmSuccess) { | |
9233 | + return 0; | |
9234 | } | |
9235 | ||
9236 | + if (!(im = gdImageCreate(image.width, image.height))) { | |
9237 | + return 0; | |
9238 | + } | |
9239 | ||
9240 | - colors[i] = gdImageColorResolve (im, red, green, blue); | |
9241 | - if (colors[i] == -1) | |
9242 | - php_gd_error("ARRRGH\n"); | |
9243 | - } | |
9244 | - | |
9245 | - apixel = (char *) gdMalloc (image.cpp + 1); | |
9246 | - apixel[image.cpp] = '\0'; | |
9247 | - | |
9248 | - pointer = (int *) image.data; | |
9249 | - for (i = 0; i < image.height; i++) | |
9250 | - { | |
9251 | - for (j = 0; j < image.width; j++) | |
9252 | - { | |
9253 | - k = *pointer++; | |
9254 | - gdImageSetPixel (im, j, i, colors[k]); | |
9255 | + number = image.ncolors; | |
9256 | + colors = (int *) safe_emalloc(number, sizeof(int), 0); | |
9257 | + for (i = 0; i < number; i++) { | |
9258 | + switch (strlen (image.colorTable[i].c_color)) { | |
9259 | + case 4: | |
9260 | + buf[1] = '\0'; | |
9261 | + buf[0] = image.colorTable[i].c_color[1]; | |
9262 | + red = strtol(buf, NULL, 16); | |
9263 | + | |
9264 | + buf[0] = image.colorTable[i].c_color[2]; | |
9265 | + green = strtol(buf, NULL, 16); | |
9266 | + | |
9267 | + buf[0] = image.colorTable[i].c_color[3]; | |
9268 | + blue = strtol(buf, NULL, 16); | |
9269 | + break; | |
9270 | + | |
9271 | + case 7: | |
9272 | + buf[2] = '\0'; | |
9273 | + buf[0] = image.colorTable[i].c_color[1]; | |
9274 | + buf[1] = image.colorTable[i].c_color[2]; | |
9275 | + red = strtol(buf, NULL, 16); | |
9276 | + | |
9277 | + buf[0] = image.colorTable[i].c_color[3]; | |
9278 | + buf[1] = image.colorTable[i].c_color[4]; | |
9279 | + green = strtol(buf, NULL, 16); | |
9280 | + | |
9281 | + buf[0] = image.colorTable[i].c_color[5]; | |
9282 | + buf[1] = image.colorTable[i].c_color[6]; | |
9283 | + blue = strtol(buf, NULL, 16); | |
9284 | + break; | |
9285 | + | |
9286 | + case 10: | |
9287 | + buf[3] = '\0'; | |
9288 | + buf[0] = image.colorTable[i].c_color[1]; | |
9289 | + buf[1] = image.colorTable[i].c_color[2]; | |
9290 | + buf[2] = image.colorTable[i].c_color[3]; | |
9291 | + red = strtol(buf, NULL, 16); | |
9292 | + red /= 64; | |
9293 | + | |
9294 | + buf[0] = image.colorTable[i].c_color[4]; | |
9295 | + buf[1] = image.colorTable[i].c_color[5]; | |
9296 | + buf[2] = image.colorTable[i].c_color[6]; | |
9297 | + green = strtol(buf, NULL, 16); | |
9298 | + green /= 64; | |
9299 | + | |
9300 | + buf[0] = image.colorTable[i].c_color[7]; | |
9301 | + buf[1] = image.colorTable[i].c_color[8]; | |
9302 | + buf[2] = image.colorTable[i].c_color[9]; | |
9303 | + blue = strtol(buf, NULL, 16); | |
9304 | + blue /= 64; | |
9305 | + break; | |
9306 | + | |
9307 | + case 13: | |
9308 | + buf[4] = '\0'; | |
9309 | + buf[0] = image.colorTable[i].c_color[1]; | |
9310 | + buf[1] = image.colorTable[i].c_color[2]; | |
9311 | + buf[2] = image.colorTable[i].c_color[3]; | |
9312 | + buf[3] = image.colorTable[i].c_color[4]; | |
9313 | + red = strtol(buf, NULL, 16); | |
9314 | + red /= 256; | |
9315 | + | |
9316 | + buf[0] = image.colorTable[i].c_color[5]; | |
9317 | + buf[1] = image.colorTable[i].c_color[6]; | |
9318 | + buf[2] = image.colorTable[i].c_color[7]; | |
9319 | + buf[3] = image.colorTable[i].c_color[8]; | |
9320 | + green = strtol(buf, NULL, 16); | |
9321 | + green /= 256; | |
9322 | + | |
9323 | + buf[0] = image.colorTable[i].c_color[9]; | |
9324 | + buf[1] = image.colorTable[i].c_color[10]; | |
9325 | + buf[2] = image.colorTable[i].c_color[11]; | |
9326 | + buf[3] = image.colorTable[i].c_color[12]; | |
9327 | + blue = strtol(buf, NULL, 16); | |
9328 | + blue /= 256; | |
9329 | + break; | |
9330 | + } | |
9331 | + | |
9332 | + | |
9333 | + colors[i] = gdImageColorResolve(im, red, green, blue); | |
9334 | + if (colors[i] == -1) { | |
9335 | + php_gd_error("ARRRGH"); | |
9336 | + } | |
9337 | } | |
9338 | - } | |
9339 | - gdFree (apixel); | |
9340 | - gdFree (colors); | |
9341 | - return (im); | |
9342 | + | |
9343 | + apixel = (char *) gdMalloc(image.cpp + 1); | |
9344 | + apixel[image.cpp] = '\0'; | |
9345 | + | |
9346 | + pointer = (int *) image.data; | |
9347 | + for (i = 0; i < image.height; i++) { | |
9348 | + for (j = 0; j < image.width; j++) { | |
9349 | + k = *pointer++; | |
9350 | + gdImageSetPixel(im, j, i, colors[k]); | |
9351 | + } | |
9352 | + } | |
9353 | + | |
9354 | + gdFree(apixel); | |
9355 | + gdFree(colors); | |
9356 | + return im; | |
9357 | } | |
9358 | #endif | |
9359 | diff -urN php-4.4.8.org/ext/gd/libgd/testac.c php-4.4.8/ext/gd/libgd/testac.c | |
9360 | --- php-4.4.8.org/ext/gd/libgd/testac.c 2002-04-13 04:03:09.000000000 +0200 | |
9361 | +++ php-4.4.8/ext/gd/libgd/testac.c 2003-12-28 21:11:08.000000000 +0100 | |
9362 | @@ -33,7 +33,7 @@ | |
9363 | } | |
9364 | /* Load original PNG, which should contain alpha channel | |
9365 | information. We will use it in two ways: preserving it | |
9366 | - literally, for use with compatible browsers, and | |
9367 | + literally, for use with compatible browsers, and | |
9368 | compositing it ourselves against a background of our | |
9369 | choosing (alpha blending). We'll change its size | |
9370 | and try creating palette versions of it. */ | |
9371 | @@ -80,7 +80,7 @@ | |
9372 | /* Create output image. */ | |
9373 | im_out = gdImageCreateTrueColor ((int) (gdImageSX (im_in) * scale), | |
9374 | (int) (gdImageSY (im_in) * scale)); | |
9375 | - /* | |
9376 | + /* | |
9377 | Request alpha blending. This causes future | |
9378 | drawing operations to perform alpha channel blending | |
9379 | with the background, resulting in an opaque image. | |
9380 | @@ -111,7 +111,7 @@ | |
9381 | ||
9382 | /* If this image is the result of alpha channel blending, | |
9383 | it will not contain an interesting alpha channel itself. | |
9384 | - Save a little file size by not saving the alpha channel. | |
9385 | + Save a little file size by not saving the alpha channel. | |
9386 | Otherwise the file would typically be slightly larger. */ | |
9387 | gdImageSaveAlpha (im_out, !blending); | |
9388 | ||
9389 | diff -urN php-4.4.8.org/ext/gd/libgd/wbmp.c php-4.4.8/ext/gd/libgd/wbmp.c | |
9390 | --- php-4.4.8.org/ext/gd/libgd/wbmp.c 2007-03-10 14:06:37.000000000 +0100 | |
9391 | +++ php-4.4.8/ext/gd/libgd/wbmp.c 2007-03-10 13:18:36.000000000 +0100 | |
9392 | @@ -28,7 +28,7 @@ | |
9393 | ||
9394 | /* getmbi | |
9395 | ** ------ | |
9396 | - ** Get a multibyte integer from a generic getin function | |
9397 | + ** Get a multibyte integer from a generic getin function | |
9398 | ** 'getin' can be getc, with in = NULL | |
9399 | ** you can find getin as a function just above the main function | |
9400 | ** This way you gain a lot of flexibilty about how this package | |
9401 | @@ -125,7 +125,7 @@ | |
9402 | return NULL; | |
9403 | } | |
9404 | ||
9405 | - if ((wbmp->bitmap = (int *) safe_emalloc(sizeof(int), (width * height), 0)) == NULL) | |
9406 | + if ((wbmp->bitmap = (int *) safe_emalloc(sizeof(int), width * height, 0)) == NULL) | |
9407 | { | |
9408 | gdFree (wbmp); | |
9409 | return (NULL); | |
9410 | @@ -192,7 +192,7 @@ | |
9411 | return (-1); | |
9412 | } | |
9413 | ||
9414 | - if ((wbmp->bitmap = (int *) safe_emalloc(sizeof(int), (wbmp->width * wbmp->height), 0)) == NULL) | |
9415 | + if ((wbmp->bitmap = (int *) safe_emalloc((size_t)wbmp->width * wbmp->height, sizeof(int), 0)) == NULL) | |
9416 | { | |
9417 | gdFree (wbmp); | |
9418 | return (-1); | |
9419 | @@ -240,7 +240,7 @@ | |
9420 | ** Why not just giving a filedescriptor to this function? | |
9421 | ** Well, the incentive to write this function was the complete | |
9422 | ** integration in gd library from www.boutell.com. They use | |
9423 | - ** their own io functions, so the passing of a function seemed to be | |
9424 | + ** their own io functions, so the passing of a function seemed to be | |
9425 | ** a logic(?) decision ... | |
9426 | ** | |
9427 | */ | |
9428 | @@ -335,7 +335,7 @@ | |
9429 | return (putc (c, (FILE *) out)); | |
9430 | } | |
9431 | ||
9432 | -/* getin from file descriptor | |
9433 | +/* getin from file descriptor | |
9434 | ** -------------------------- | |
9435 | */ | |
9436 | int | |
9437 | diff -urN php-4.4.8.org/ext/gd/libgd/wbmp.h php-4.4.8/ext/gd/libgd/wbmp.h | |
9438 | --- php-4.4.8.org/ext/gd/libgd/wbmp.h 2002-04-13 04:03:09.000000000 +0200 | |
9439 | +++ php-4.4.8/ext/gd/libgd/wbmp.h 2005-10-09 14:06:27.000000000 +0200 | |
9440 | @@ -8,17 +8,22 @@ | |
9441 | ** (c) 2000 Johan Van den Brande <johan@vandenbrande.com> | |
9442 | ** | |
9443 | ** Header file | |
9444 | -*/ | |
9445 | +*/ | |
9446 | #ifndef __WBMP_H | |
9447 | #define __WBMP_H 1 | |
9448 | ||
9449 | +#ifdef HAVE_CONFIG_H | |
9450 | +#include "config.h" | |
9451 | +#endif | |
9452 | + | |
9453 | +#include "php_compat.h" | |
9454 | ||
9455 | /* WBMP struct | |
9456 | ** ----------- | |
9457 | ** A Wireless bitmap structure | |
9458 | ** | |
9459 | */ | |
9460 | - | |
9461 | + | |
9462 | typedef struct Wbmp_ | |
9463 | { | |
9464 | int type; /* type of the wbmp */ | |
9465 | @@ -26,22 +31,22 @@ | |
9466 | int height; /* height of the image */ | |
9467 | int *bitmap; /* pointer to data: 0 = WHITE , 1 = BLACK */ | |
9468 | } Wbmp; | |
9469 | - | |
9470 | + | |
9471 | #define WBMP_WHITE 1 | |
9472 | #define WBMP_BLACK 0 | |
9473 | - | |
9474 | + | |
9475 | ||
9476 | /* Proto's | |
9477 | ** ------- | |
9478 | ** | |
9479 | */ | |
9480 | -void putmbi( int i, void (*putout)(int c, void *out), void *out); | |
9481 | +void putmbi( int i, void (*putout)(int c, void *out), void *out); | |
9482 | int getmbi ( int (*getin)(void *in), void *in ); | |
9483 | int skipheader( int (*getin)(void *in), void *in ); | |
9484 | Wbmp *createwbmp( int width, int height, int color ); | |
9485 | int readwbmp( int (*getin)(void *in), void *in, Wbmp **wbmp ); | |
9486 | int writewbmp( Wbmp *wbmp, void (*putout)( int c, void *out), void *out); | |
9487 | void freewbmp( Wbmp *wbmp ); | |
9488 | -void printwbmp( Wbmp *wbmp ); | |
9489 | +void printwbmp( Wbmp *wbmp ); | |
9490 | ||
9491 | #endif | |
9492 | diff -urN php-4.4.8.org/ext/gd/libgd/webpng.c php-4.4.8/ext/gd/libgd/webpng.c | |
9493 | --- php-4.4.8.org/ext/gd/libgd/webpng.c 2002-04-21 15:48:22.000000000 +0200 | |
9494 | +++ php-4.4.8/ext/gd/libgd/webpng.c 2007-02-24 03:17:24.000000000 +0100 | |
9495 | @@ -193,7 +193,7 @@ | |
9496 | maxy = gdImageSY(im); | |
9497 | ||
9498 | printf("alpha channel information:\n"); | |
9499 | - | |
9500 | + | |
9501 | if (im->trueColor) { | |
9502 | for (y = 0; y < maxy; y++) { | |
9503 | for (x = 0; x < maxx; x++) { | |
9504 | @@ -215,9 +215,9 @@ | |
9505 | } | |
9506 | else | |
9507 | printf("NOT a true color image\n"); | |
9508 | - no = 0; | |
9509 | + no = 0; | |
9510 | printf("%d alpha channels\n", nalpha); | |
9511 | - | |
9512 | + | |
9513 | } | |
9514 | else | |
9515 | { | |
9516 | @@ -252,7 +252,7 @@ | |
9517 | /* Open a temporary file. */ | |
9518 | ||
9519 | /* "temp.tmp" is not good temporary filename. */ | |
9520 | - sprintf (outFn, "webpng.tmp%d", getpid ()); | |
9521 | + snprintf (outFn, sizeof(outFn), "webpng.tmp%d", getpid ()); | |
9522 | out = fopen (outFn, "wb"); | |
9523 | ||
9524 | if (!out) | |
9525 | diff -urN php-4.4.8.org/ext/gd/libgd/xbm.c php-4.4.8/ext/gd/libgd/xbm.c | |
9526 | --- php-4.4.8.org/ext/gd/libgd/xbm.c 2007-12-31 08:22:47.000000000 +0100 | |
9527 | +++ php-4.4.8/ext/gd/libgd/xbm.c 2007-08-09 14:08:29.000000000 +0200 | |
84aee732 AM |
9528 | @@ -29,8 +29,8 @@ |
9529 | ||
9530 | #define MAX_XBM_LINE_SIZE 255 | |
9531 | ||
9532 | -gdImagePtr | |
9533 | -gdImageCreateFromXbm (FILE * fd) | |
9534 | +/* {{{ gdImagePtr gdImageCreateFromXbm */ | |
9535 | +gdImagePtr gdImageCreateFromXbm(FILE * fd) | |
9536 | { | |
9537 | char fline[MAX_XBM_LINE_SIZE]; | |
9538 | char iname[MAX_XBM_LINE_SIZE]; | |
9539 | @@ -46,7 +46,7 @@ | |
9540 | int ch; | |
9541 | char h[8]; | |
9542 | unsigned int b; | |
9543 | - | |
9544 | + | |
9545 | rewind(fd); | |
9546 | while (fgets(fline, MAX_XBM_LINE_SIZE, fd)) { | |
9547 | fline[MAX_XBM_LINE_SIZE-1] = '\0'; | |
9548 | @@ -59,7 +59,7 @@ | |
9549 | } else { | |
9550 | type++; | |
9551 | } | |
9552 | - | |
9553 | + | |
9554 | if (!strcmp("width", type)) { | |
9555 | width = (unsigned int) value; | |
9556 | } | |
9557 | @@ -96,7 +96,9 @@ | |
9558 | return 0; | |
9559 | } | |
9560 | ||
9561 | - im = gdImageCreate(width, height); | |
9562 | + if(!(im = gdImageCreate(width, height))) { | |
9563 | + return 0; | |
9564 | + } | |
9565 | gdImageColorAllocate(im, 255, 255, 255); | |
9566 | gdImageColorAllocate(im, 0, 0, 0); | |
9567 | h[2] = '\0'; | |
9568 | @@ -147,7 +149,93 @@ | |
9569 | } | |
9570 | } | |
9571 | ||
9572 | - php_gd_error("EOF before image was complete\n"); | |
9573 | + php_gd_error("EOF before image was complete"); | |
9574 | gdImageDestroy(im); | |
9575 | return 0; | |
9576 | } | |
9577 | +/* }}} */ | |
9578 | + | |
9579 | +/* {{{ gdCtxPrintf */ | |
9580 | +void gdCtxPrintf(gdIOCtx * out, const char *format, ...) | |
9581 | +{ | |
9582 | + char *buf; | |
9583 | + int len; | |
9584 | + va_list args; | |
9585 | + | |
9586 | + va_start(args, format); | |
9587 | + len = vspprintf(&buf, 0, format, args); | |
9588 | + va_end(args); | |
9589 | + out->putBuf(out, buf, len); | |
9590 | + efree(buf); | |
9591 | +} | |
9592 | +/* }}} */ | |
9593 | + | |
9594 | +/* {{{ gdImageXbmCtx */ | |
9595 | +void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out) | |
9596 | +{ | |
9597 | + int x, y, c, b, sx, sy, p; | |
9598 | + char *name, *f; | |
9599 | + size_t i, l; | |
9600 | + | |
9601 | + name = file_name; | |
9602 | + if ((f = strrchr(name, '/')) != NULL) name = f+1; | |
9603 | + if ((f = strrchr(name, '\\')) != NULL) name = f+1; | |
9604 | + name = estrdup(name); | |
9605 | + if ((f = strrchr(name, '.')) != NULL && !strcasecmp(f, ".XBM")) *f = '\0'; | |
9606 | + if ((l = strlen(name)) == 0) { | |
9607 | + efree(name); | |
9608 | + name = estrdup("image"); | |
9609 | + } else { | |
9610 | + for (i=0; i<l; i++) { | |
9611 | + /* only in C-locale isalnum() would work */ | |
9612 | + if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) { | |
9613 | + name[i] = '_'; | |
9614 | + } | |
9615 | + } | |
9616 | + } | |
9617 | + | |
9618 | + gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image)); | |
9619 | + gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image)); | |
9620 | + gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name); | |
9621 | + | |
9622 | + efree(name); | |
9623 | + | |
9624 | + b = 1; | |
9625 | + p = 0; | |
9626 | + c = 0; | |
9627 | + sx = gdImageSX(image); | |
9628 | + sy = gdImageSY(image); | |
9629 | + for (y = 0; y < sy; y++) { | |
9630 | + for (x = 0; x < sx; x++) { | |
9631 | + if (gdImageGetPixel(image, x, y) == fg) { | |
9632 | + c |= b; | |
9633 | + } | |
9634 | + if ((b == 128) || (x == sx && y == sy)) { | |
9635 | + b = 1; | |
9636 | + if (p) { | |
9637 | + gdCtxPrintf(out, ", "); | |
9638 | + if (!(p%12)) { | |
9639 | + gdCtxPrintf(out, "\n "); | |
9640 | + p = 12; | |
9641 | + } | |
9642 | + } | |
9643 | + p++; | |
9644 | + gdCtxPrintf(out, "0x%02X", c); | |
9645 | + c = 0; | |
9646 | + } else { | |
9647 | + b <<= 1; | |
9648 | + } | |
9649 | + } | |
9650 | + } | |
9651 | + gdCtxPrintf(out, "};\n"); | |
9652 | +} | |
9653 | +/* }}} */ | |
9654 | + | |
9655 | +/* | |
9656 | + * Local variables: | |
9657 | + * tab-width: 4 | |
9658 | + * c-basic-offset: 4 | |
9659 | + * End: | |
9660 | + * vim600: sw=4 ts=4 fdm=marker | |
9661 | + * vim<600: sw=4 ts=4 | |
9662 | + */ | |
23005b3f AM |
9663 | diff -urN php-4.4.8.org/ext/gd/php_gd.h php-4.4.8/ext/gd/php_gd.h |
9664 | --- php-4.4.8.org/ext/gd/php_gd.h 2007-12-31 08:22:47.000000000 +0100 | |
84aee732 | 9665 | +++ php-4.4.8/ext/gd/php_gd.h 2008-01-22 22:38:05.897151947 +0100 |
23005b3f AM |
9666 | @@ -32,7 +32,7 @@ |
9667 | ||
9668 | /* open_basedir and safe_mode checks */ | |
9669 | #define PHP_GD_CHECK_OPEN_BASEDIR(filename, errormsg) \ | |
9670 | - if (!filename || filename == empty_string || php_check_open_basedir(filename TSRMLS_CC) || \ | |
9671 | + if (!filename || php_check_open_basedir(filename TSRMLS_CC) || \ | |
9672 | (PG(safe_mode) && !php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR)) \ | |
9673 | ) { \ | |
9674 | php_error_docref(NULL TSRMLS_CC, E_WARNING, errormsg); \ | |
9675 | @@ -66,7 +66,9 @@ | |
9676 | /* gd.c functions */ | |
9677 | PHP_MINFO_FUNCTION(gd); | |
9678 | PHP_MINIT_FUNCTION(gd); | |
9679 | +#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX | |
9680 | PHP_MSHUTDOWN_FUNCTION(gd); | |
9681 | +#endif | |
9682 | #if HAVE_LIBGD20 && HAVE_GD_STRINGFT | |
9683 | PHP_RSHUTDOWN_FUNCTION(gd); | |
9684 | #endif | |
9685 | @@ -112,6 +114,11 @@ | |
9686 | PHP_FUNCTION(imagecopyresampled); | |
9687 | #endif | |
fa2ea656 | 9688 | |
23005b3f AM |
9689 | +#ifdef PHP_WIN32 |
9690 | +PHP_FUNCTION(imagegrabwindow); | |
9691 | +PHP_FUNCTION(imagegrabscreen); | |
9692 | +#endif | |
fa2ea656 | 9693 | + |
23005b3f AM |
9694 | #ifdef HAVE_GD_BUNDLED |
9695 | PHP_FUNCTION(imagerotate); | |
9696 | PHP_FUNCTION(imageantialias); | |
9697 | @@ -184,6 +191,8 @@ | |
9698 | PHP_FUNCTION(imagelayereffect); | |
9699 | PHP_FUNCTION(imagecolormatch); | |
9700 | PHP_FUNCTION(imagefilter); | |
9701 | +PHP_FUNCTION(imageconvolution); | |
9702 | +PHP_FUNCTION(imagexbm); | |
9703 | #endif | |
fa2ea656 | 9704 | |
23005b3f | 9705 | PHP_GD_API int phpi_get_le_gd(void); |