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
3 +++ php-4.4.8/ext/gd/config.m4 2008-01-22 22:38:05.833815388 +0100
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 ])
17 if test "$PHP_GD" = "yes"; then
18 GD_MODULE_TYPE=builtin
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, [ ])
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
29 +++ php-4.4.8/ext/gd/gd.c 2008-01-22 22:38:05.837148890 +0100
35 +/* needs to be first */
41 #include "ext/standard/head.h"
55 #include <gdfontmb.h> /* 3 Medium bold font */
56 #include <gdfontl.h> /* 4 Large font */
57 #include <gdfontg.h> /* 5 Giant font */
60 #include "libgd/wbmp.h"
64 +# ifdef HAVE_LIBFREETYPE
65 +# include <ft2build.h>
66 +# include FT_FREETYPE_H
69 +# include <freetype.h>
76 #define gdNewDynamicCtxEx(len, data, val) gdNewDynamicCtx(len, data)
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)
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);
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)());
118 /* {{{ gd_functions[]
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)
126 PHP_FE(imagecopyresampled, NULL)
130 + PHP_FE(imagegrabwindow, NULL)
131 + PHP_FE(imagegrabscreen, NULL)
134 #ifdef HAVE_GD_BUNDLED
135 PHP_FE(imagerotate, NULL)
136 PHP_FE(imageantialias, NULL)
139 PHP_FE(imagelayereffect, NULL)
140 PHP_FE(imagecolormatch, NULL)
141 + PHP_FE(imagexbm, NULL)
144 +#ifdef HAVE_GD_BUNDLED
145 + PHP_FE(imagefilter, NULL)
146 + PHP_FE(imageconvolution, NULL)
154 +#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
160 -#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
161 +#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
169 +/* {{{ PHP_INI_BEGIN */
171 + PHP_INI_ENTRY("gd.jpeg_ignore_warning", "0", PHP_INI_ALL, NULL)
175 /* {{{ php_free_gd_image
177 static void php_free_gd_image(zend_rsrc_list_entry *rsrc TSRMLS_DC)
178 @@ -326,15 +400,21 @@
183 /* {{{ PHP_MSHUTDOWN_FUNCTION
185 +#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
186 PHP_MSHUTDOWN_FUNCTION(gd)
191 +#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
192 + gdFontCacheMutexShutdown();
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);
205 +#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
206 + gdFontCacheMutexSetup();
210 T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
212 le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number);
215 + REGISTER_INI_ENTRIES();
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);
220 @@ -387,16 +473,58 @@
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);
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 */
239 REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
242 +#ifdef GD_VERSION_STRING
243 + REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
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);
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...
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);
273 /* {{{ PHP_RSHUTDOWN_FUNCTION
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)
279 #if HAVE_GD_FONTCACHESHUTDOWN
284 -#define PHP_GD_VERSION_STRING "bundled (2.0.28 compatible)"
285 +#define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)"
287 #define PHP_GD_VERSION_STRING "2.0 or higher"
288 #elif HAVE_GDIMAGECOLORRESOLVE
290 php_info_print_table_row(2, "FreeType Support", "enabled");
292 php_info_print_table_row(2, "FreeType Linkage", "with freetype");
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);
300 + snprintf(tmp, sizeof(tmp), "1.x");
302 + php_info_print_table_row(2, "FreeType Version", tmp);
305 php_info_print_table_row(2, "FreeType Linkage", "with TTF library");
308 + snprintf(tmp, sizeof(tmp), "%d.%d", TT_FREETYPE_MAJOR, TT_FREETYPE_MINOR);
309 + php_info_print_table_row(2, "FreeType Version", tmp);
312 php_info_print_table_row(2, "FreeType Linkage", "with unknown library");
316 php_info_print_table_row(2, "WBMP Support", "enabled");
318 +#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
319 + php_info_print_table_row(2, "XPM Support", "enabled");
322 php_info_print_table_row(2, "XBM Support", "enabled");
326 add_assoc_bool(return_value, "WBMP Support", 0);
328 +#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
329 + add_assoc_bool(return_value, "XPM Support", 1);
331 + add_assoc_bool(return_value, "XPM Support", 0);
334 add_assoc_bool(return_value, "XBM Support", 1);
342 #ifndef HAVE_GDIMAGECOLORRESOLVE
344 @@ -763,13 +916,19 @@
345 convert_to_long_ex(x_size);
346 convert_to_long_ex(y_size);
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
352 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
356 im = gdImageCreateTrueColor(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
362 ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
365 @@ -836,15 +995,19 @@
366 result = gdImageColorMatch(im1, im2);
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" );
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" );
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" );
384 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must have at least one color" );
396 @@ -1008,6 +1172,7 @@
398 long red, green, blue, alpha;
402 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
404 @@ -1015,7 +1180,12 @@
406 ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
408 - RETURN_LONG(gdImageColorAllocateAlpha(im, red, green, blue, alpha));
409 + ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha);
414 + RETURN_LONG((long)ct);
418 @@ -1125,28 +1295,173 @@
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)
428 + long client_area = 0;
437 + long lwindow_handle;
438 + typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
439 + tPrintWindow pPrintWindow = 0;
442 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &lwindow_handle, &client_area) == FAILURE) {
446 + window = (HWND) lwindow_handle;
448 + if (!IsWindow(window)) {
449 + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid window handle");
456 + GetClientRect(window, &rc);
458 + Height = rc.bottom;
460 + GetWindowRect(window, &rc);
461 + Width = rc.right - rc.left;
462 + Height = rc.bottom - rc.top;
465 + Width = (Width/4)*4;
467 + memDC = CreateCompatibleDC(hdc);
468 + memBM = CreateCompatibleBitmap(hdc, Width, Height);
469 + hOld = (HBITMAP) SelectObject (memDC, memBM);
472 + handle = LoadLibrary("User32.dll");
473 + if ( handle == 0 ) {
476 + pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow");
478 + if ( pPrintWindow ) {
479 + pPrintWindow(window, memDC, (UINT) client_area);
481 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows API too old");
486 + FreeLibrary(handle);
488 + im = gdImageCreateTrueColor(Width, Height);
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)));
500 + SelectObject(memDC,hOld);
501 + DeleteObject(memBM);
503 + ReleaseDC( 0, hdc );
508 + ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
513 +/* {{{ proto resource imagegrabscreen()
514 + Grab a screenshot */
515 +PHP_FUNCTION(imagegrabscreen)
517 + HWND window = GetDesktopWindow();
525 + long lwindow_handle;
526 + typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
527 + tPrintWindow pPrintWindow = 0;
535 + GetWindowRect(window, &rc);
536 + Width = rc.right - rc.left;
537 + Height = rc.bottom - rc.top;
539 + Width = (Width/4)*4;
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 );
546 + im = gdImageCreateTrueColor(Width, Height);
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)));
557 + SelectObject(memDC,hOld);
558 + DeleteObject(memBM);
560 + ReleaseDC( 0, hdc );
565 + ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
569 +#endif /* PHP_WIN32 */
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)
577 - zval **SIM, **ANGLE, **BGDCOLOR;
579 gdImagePtr im_dst, im_src;
582 + long ignoretransparent = 0;
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) {
590 - ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
592 - convert_to_long_ex(BGDCOLOR);
593 - color = Z_LVAL_PP(BGDCOLOR);
594 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
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);
601 if (im_dst != NULL) {
602 ZEND_REGISTER_RESOURCE(return_value, im_dst, le_gd);
603 @@ -1215,13 +1530,19 @@
604 convert_to_long_ex(x_size);
605 convert_to_long_ex(y_size);
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
611 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
615 im = gdImageCreate(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
621 ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
624 @@ -1323,6 +1644,11 @@
625 im = (*ioctx_func_p)(io_ctx);
627 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed data is not in '%s' format", tn);
629 + io_ctx->gd_free(io_ctx);
631 + io_ctx->free(io_ctx);
636 @@ -1350,6 +1676,11 @@
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");
645 memcpy(sig, Z_STRVAL_PP(data), 8);
647 imtype = _php_image_type(sig);
648 @@ -1401,7 +1732,7 @@
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");
657 @@ -1425,6 +1756,9 @@
660 int argc=ZEND_NUM_ARGS();
662 + long ignore_warning;
665 if ((image_type == PHP_GDIMG_TYPE_GD2PART && argc != 5) ||
666 (image_type != PHP_GDIMG_TYPE_GD2PART && argc != 1) ||
667 @@ -1436,6 +1770,10 @@
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");
677 fn = Z_STRVAL_PP(file);
678 @@ -1471,6 +1809,7 @@
680 io_ctx = gdNewDynamicCtxEx(buff_size, buff, 0);
683 php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context");
686 @@ -1485,7 +1824,7 @@
688 io_ctx->free(io_ctx);
695 @@ -1505,6 +1844,18 @@
696 im = gdImageCreateFromXpm(fn);
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);
706 + im = gdImageCreateFromJpeg(fp);
714 @@ -1685,6 +2036,14 @@
719 + case PHP_GDIMG_TYPE_GD2:
723 + (*func_p)(im, fp, q, t);
729 @@ -1737,6 +2096,14 @@
734 + case PHP_GDIMG_TYPE_GD2:
738 + (*func_p)(im, tmp, q, t);
744 @@ -1762,6 +2129,16 @@
748 +/* {{{ proto int imagexbm(int im, string filename [, int foreground])
749 + Output XBM image to browser or file */
751 +PHP_FUNCTION(imagexbm)
753 + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx);
758 #ifdef HAVE_GD_GIF_CREATE
759 /* {{{ proto bool imagegif(resource im [, string filename])
760 Output GIF image to browser or file */
761 @@ -1782,7 +2159,7 @@
762 PHP_FUNCTION(imagepng)
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);
768 _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng);
770 @@ -1862,6 +2239,7 @@
772 zval **IM, **red, **green, **blue;
776 if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
777 ZEND_WRONG_PARAM_COUNT();
778 @@ -1872,8 +2250,11 @@
779 convert_to_long_ex(red);
780 convert_to_long_ex(green);
781 convert_to_long_ex(blue);
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));
792 @@ -2508,7 +2889,7 @@
793 static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
795 zval **IM, **POINTS, **NPOINTS, **COL;
800 int npoints, col, nelem, i;
801 @@ -2716,7 +3097,7 @@
802 ch = (int)((unsigned char)*(Z_STRVAL_PP(C)));
804 str = (unsigned char *) estrndup(Z_STRVAL_PP(C), Z_STRLEN_PP(C));
806 + l = strlen((char *)str);
810 @@ -3083,7 +3464,7 @@
812 char tmp_font_path[MAXPATHLEN];
814 - if (VCWD_REALPATH(fontname, tmp_font_path)) {
815 + if (VCWD_REALPATH((char *)fontname, tmp_font_path)) {
816 fontname = (unsigned char *) fontname;
819 @@ -3093,16 +3474,18 @@
820 fontname = (unsigned char *) fontname;
823 + PHP_GD_CHECK_OPEN_BASEDIR((char *)fontname, "Invalid font filename");
825 #ifdef USE_GD_IMGSTRTTF
826 # if HAVE_GD_STRINGFTEX
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);
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);
840 @@ -3155,6 +3538,9 @@
848 if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
849 ZEND_WRONG_PARAM_COUNT();
850 @@ -3162,24 +3548,18 @@
852 convert_to_string_ex(file);
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));
861 f_ind = T1_AddFont(Z_STRVAL_PP(file));
866 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't find the font file");
871 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memory allocation fault in t1lib");
875 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "An unknown error occurred in t1lib");
879 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind));
883 if (T1_LoadFont(f_ind)) {
884 @@ -3317,6 +3697,11 @@
886 T1_DeleteAllSizes(*f_ind);
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));
893 if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) {
896 @@ -3348,7 +3733,7 @@
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)
905 @@ -3371,11 +3756,6 @@
906 T1_TMATRIX *transform = NULL;
909 - int argc = ZEND_NUM_ARGS();
911 - if (argc != 8 && argc != 12) {
912 - ZEND_WRONG_PARAM_COUNT();
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) {
917 @@ -3455,7 +3835,7 @@
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));
926 @@ -3476,7 +3856,7 @@
927 str_img = T1_AASetString(*f_ind, str, str_len, space, T1_KERNING, size, transform);
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));
935 @@ -3719,7 +4099,10 @@
938 float x_ratio, y_ratio;
941 + long ignore_warning;
944 if (argc != 5 || zend_get_parameters_ex(argc, &f_org, &f_dest, &height, &width, &threshold) == FAILURE) {
945 ZEND_WRONG_PARAM_COUNT();
947 @@ -3775,7 +4158,12 @@
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);
955 im_org = gdImageCreateFromJpeg(org);
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);
960 @@ -3886,7 +4274,282 @@
962 #endif /* HAVE_GD_WBMP */
964 +#endif /* HAVE_LIBGD */
966 +/* Section Filters */
967 #ifdef HAVE_GD_BUNDLED
969 +#define PHP_GD_SINGLE_RES \
971 + gdImagePtr im_src; \
972 + if (zend_get_parameters_ex(1, &SIM) == FAILURE) { \
975 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); \
976 + if (im_src == NULL) { \
980 +static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
984 + if (gdImageNegate(im_src) == 1) {
991 +static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
995 + if (gdImageGrayScale(im_src) == 1) {
1002 +static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
1005 + gdImagePtr im_src;
1006 + long brightness, tmp;
1008 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &SIM, &tmp, &brightness) == FAILURE) {
1012 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1014 + if (im_src == NULL) {
1018 + if (gdImageBrightness(im_src, (int)brightness) == 1) {
1025 +static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
1028 + gdImagePtr im_src;
1029 + long contrast, tmp;
1031 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &SIM, &tmp, &contrast) == FAILURE) {
1035 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1037 + if (im_src == NULL) {
1041 + if (gdImageContrast(im_src, (int)contrast) == 1) {
1048 +static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
1051 + gdImagePtr im_src;
1055 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &SIM, &tmp, &r, &g, &b, &a) == FAILURE) {
1059 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1061 + if (im_src == NULL) {
1065 + if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) {
1072 +static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS)
1076 + if (gdImageEdgeDetectQuick(im_src) == 1) {
1083 +static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
1087 + if (gdImageEmboss(im_src) == 1) {
1094 +static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
1098 + if (gdImageGaussianBlur(im_src) == 1) {
1105 +static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
1109 + if (gdImageSelectiveBlur(im_src) == 1) {
1116 +static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
1120 + if (gdImageMeanRemoval(im_src) == 1) {
1127 +static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
1131 + gdImagePtr im_src;
1134 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
1138 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1140 + if (im_src == NULL) {
1144 + if (gdImageSmooth(im_src, (float)weight)==1) {
1151 +/* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] )
1152 + Applies Filter an image using a custom angle */
1153 +PHP_FUNCTION(imagefilter)
1157 + typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS);
1159 + image_filter filters[] =
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
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) {
1180 + if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
1181 + filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
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)
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}};
1197 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "radd", &SIM, &hash_matrix, &div, &offset) == FAILURE) {
1201 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1203 + nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
1205 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
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");
1216 + for (j=0; j<3; j++) {
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);
1222 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have a 3x3 matrix");
1228 + res = gdImageConvolution(im_src, matrix, div, offset);
1238 +/* End section: Filters */
1240 /* {{{ proto bool imageantialias(resource im, bool on)
1241 Should antialiased functions used or not*/
1242 PHP_FUNCTION(imageantialias)
1243 @@ -3908,8 +4571,6 @@
1247 -#endif /* HAVE_LIBGD */
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
1254 +++ php-4.4.8/ext/gd/gdcache.c 2008-01-22 22:38:05.863816915 +0100
1257 gdCacheTestFn_t gdCacheTest,
1258 gdCacheFetchFn_t gdCacheFetch,
1259 - gdCacheReleaseFn_t gdCacheRelease )
1260 + gdCacheReleaseFn_t gdCacheRelease )
1262 - gdCache_head_t *head;
1263 + gdCache_head_t *head;
1265 head = (gdCache_head_t *)pemalloc(sizeof(gdCache_head_t), 1);
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
1269 +++ php-4.4.8/ext/gd/gd_ctx.c 2008-01-22 22:38:05.863816915 +0100
1271 | Authors: Stanislav Malyshev <stas@php.net> |
1272 +----------------------------------------------------------------------+
1274 -#include "php_gd.h"
1278 +#include "php_gd.h"
1280 #define CTX_PUTC(c,ctx) ctx->putC(ctx, c)
1283 static void _php_image_output_putc(struct gdIOCtx *ctx, int c)
1285 /* without the following downcast, the write will fail
1291 -static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
1293 +/* {{{ _php_image_output_ctx */
1294 +static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
1296 - zval **imgind, **file, **quality;
1297 + zval **imgind, **file, **quality, **basefilter;
1301 int argc = ZEND_NUM_ARGS();
1306 - /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
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>().
1314 + if (argc < 2 && image_type == PHP_GDIMG_TYPE_XBM) {
1315 + WRONG_PARAM_COUNT;
1318 + if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc, &imgind, &file, &quality, &basefilter) == FAILURE)
1323 ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", phpi_get_le_gd());
1326 - convert_to_string_ex(file);
1327 + if (argc >= 2 && Z_TYPE_PP(file) != IS_NULL) {
1328 + convert_to_string_ex(file);
1330 fn = Z_STRVAL_PP(file);
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) */
1337 + convert_to_long_ex(basefilter);
1338 + f = Z_LVAL_PP(basefilter);
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))))) {
1346 PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
1348 fp = VCWD_FOPEN(fn, "wb");
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));
1356 ctx->gd_free = _php_image_output_ctxfree;
1358 ctx->free = _php_image_output_ctxfree;
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);
1368 + case PHP_GDIMG_TYPE_PNG:
1369 + (*func_p)(im, ctx, q, f);
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;
1376 - (*func_p)(im, i, ctx);
1378 + for(i=0; i < gdImageColorsTotal(im); i++) {
1379 + if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
1383 + if (image_type == PHP_GDIMG_TYPE_XBM) {
1384 + (*func_p)(im, fn, q, ctx);
1386 + (*func_p)(im, q, ctx);
1413 + * Local variables:
1415 + * c-basic-offset: 4
1417 + * vim600: sw=4 ts=4 fdm=marker
1418 + * vim<600: sw=4 ts=4
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
1422 +++ php-4.4.8/ext/gd/gdttf.c 2008-01-22 22:38:05.887151436 +0100
1424 /* ptsize below which anti-aliasing is ineffective */
1425 #define MINANTIALIASPTSIZE 0
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
1431 /* Number of colors used for anti-aliasing */
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*/
1440 #define LINESPACE 1.05
1448 unsigned char pixel; /* key */
1449 unsigned char bgcolor; /* key */
1450 int fgcolor; /* key */ /* -ve means no antialias */
1452 unsigned char bgcolor; /* key */
1453 int fgcolor; /* key */ /* -ve means no antialias */
1454 gdImagePtr im; /* key */
1458 /* forward declarations so that glyphCache can be initialized by font code */
1459 static int glyphTest ( void *element, void *key );
1462 *---------------------------------------------------------------------------
1466 #ifndef CHARSET_EBCDIC
1467 #define ASC(ch) (ch)
1468 #else /*CHARSET_EBCDIC*/
1469 @@ -205,17 +205,16 @@
1471 #define Tcl_UniChar int
1472 #define TCL_UTF_MAX 3
1474 -gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr)
1475 +static int gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr)
1476 /* str is the UTF8 next character pointer */
1477 /* chPtr is the int for the result */
1483 /* HTML4.0 entities in decimal form, e.g. Å */
1484 - byte = *((unsigned char *) str);
1485 + byte = *((unsigned char *) str);
1490 byte = *((unsigned char *) (str+1));
1493 byte = *((unsigned char *) (str+i));
1494 if (byte >= '0' && byte <= '9') {
1495 n = (n * 10) + (byte - '0');
1503 *chPtr = (Tcl_UniChar) n;
1504 @@ -233,105 +232,91 @@
1510 - * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones.
1513 - byte = ASC(*((unsigned char *) str));
1514 - if (byte < 0xC0) {
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.
1521 - *chPtr = (Tcl_UniChar) byte;
1523 - } else if (byte < 0xE0) {
1524 - if ((ASC(str[1]) & 0xC0) == 0x80) {
1526 - * Two-byte-character lead-byte followed by a trail-byte.
1529 - *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F));
1533 - * A two-byte-character lead-byte not followed by trail-byte
1534 - * represents itself.
1537 - *chPtr = (Tcl_UniChar) byte;
1539 - } else if (byte < 0xF0) {
1540 - if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) {
1542 - * Three-byte-character lead byte followed by two trail bytes.
1545 - *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12)
1546 - | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F));
1550 - * A three-byte-character lead-byte not followed by two trail-bytes
1551 - * represents itself.
1553 + /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */
1555 - *chPtr = (Tcl_UniChar) byte;
1558 + byte = ASC(*((unsigned char *) str));
1559 + if (byte < 0xC0) {
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.
1566 + *chPtr = (Tcl_UniChar) byte;
1568 + } else if (byte < 0xE0) {
1569 + if ((ASC(str[1]) & 0xC0) == 0x80) {
1570 + /* Two-byte-character lead-byte followed by a trail-byte. */
1572 + *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F));
1576 + * A two-byte-character lead-byte not followed by trail-byte
1577 + * represents itself.
1580 + *chPtr = (Tcl_UniChar) byte;
1582 + } else if (byte < 0xF0) {
1583 + if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) {
1584 + /* Three-byte-character lead byte followed by two trail bytes. */
1586 + *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F));
1589 + /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */
1591 + *chPtr = (Tcl_UniChar) byte;
1596 - int ch, total, trail;
1598 + int ch, total, trail;
1600 - total = totalBytes[byte];
1601 - trail = total - 1;
1603 - ch = byte & (0x3F >> trail);
1606 - if ((ASC(*str) & 0xC0) != 0x80) {
1611 - ch |= (ASC(*str) & 0x3F);
1613 - } while (trail > 0);
1616 + total = totalBytes[byte];
1617 + trail = total - 1;
1619 + ch = byte & (0x3F >> trail);
1622 + if ((ASC(*str) & 0xC0) != 0x80) {
1627 + ch |= (ASC(*str) & 0x3F);
1629 + } while (trail > 0);
1637 - *chPtr = (Tcl_UniChar) byte;
1639 + *chPtr = (Tcl_UniChar) byte;
1643 /********************************************************************/
1644 /* font cache functions */
1647 -fontTest ( void *element, void *key )
1648 +static int fontTest ( void *element, void *key )
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;
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);
1662 -fontFetch ( char **error, void *key )
1663 +static void * fontFetch ( char **error, void *key )
1667 - fontkey_t *b=(fontkey_t *)key;
1668 - int i, n, map_found;
1669 - short platform, encoding;
1672 + fontkey_t *b = (fontkey_t *)key;
1673 + int i, n, map_found;
1674 + short platform, encoding;
1677 a = (font_t *)pemalloc(sizeof(font_t), 1);
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";
1685 *error = "Could not read font";
1694 if (TT_Set_Instance_Resolutions(a->instance, RESOLUTION, RESOLUTION)) {
1695 *error = "Could not set device resolutions";
1697 @@ -384,12 +368,12 @@
1700 TT_Get_Instance_Metrics(a->instance, &a->imetrics);
1703 /* First, look for a Unicode charmap */
1704 n = TT_Get_CharMap_Count(a->face);
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 */
1716 - if (! map_found) {
1718 *error = "Unable to find a CharMap that I can handle";
1721 @@ -418,16 +402,14 @@
1722 a->matrix.xy = - a->matrix.yx;
1723 a->matrix.yy = a->matrix.xx;
1725 - a->glyphCache = gdCacheCreate( GLYPHCACHESIZE,
1726 - glyphTest, glyphFetch, glyphRelease);
1727 + a->glyphCache = gdCacheCreate(GLYPHCACHESIZE, glyphTest, glyphFetch, glyphRelease);
1733 -fontRelease( void *element )
1734 +static void fontRelease( void *element )
1736 - font_t *a=(font_t *)element;
1737 + font_t *a = (font_t *)element;
1739 gdCacheDelete(a->glyphCache);
1740 TT_Done_Instance(a->instance);
1741 @@ -439,26 +421,22 @@
1742 /********************************************************************/
1743 /* glyph cache functions */
1746 -glyphTest ( void *element, void *key )
1747 +static int glyphTest ( void *element, void *key )
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;
1754 + return (a->character == b->character && a->hinting == b->hinting && a->gray_render == b->gray_render);
1757 - return (a->character == b->character
1758 - && a->hinting == b->hinting
1759 - && a->gray_render == b->gray_render);
1763 -glyphFetch ( char **error, void *key )
1766 - glyphkey_t *b=(glyphkey_t *)key;
1769 - int crect[8], xmin, xmax, ymin, ymax;
1770 - double cos_a, sin_a;
1771 +static void * glyphFetch ( char **error, void *key )
1774 + glyphkey_t *b = (glyphkey_t *)key;
1777 + int crect[8], xmin, xmax, ymin, ymax;
1778 + double cos_a, sin_a;
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 */
1789 a->Bit.cols = (a->Bit.width + 7) / 8; /* 1 bit per pixel */
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;
1795 - a->bitmapCache = gdCacheCreate( BITMAPCACHESIZE,
1796 - bitmapTest, bitmapFetch, bitmapRelease);
1797 + a->bitmapCache = gdCacheCreate(BITMAPCACHESIZE, bitmapTest, bitmapFetch, bitmapRelease);
1803 -glyphRelease( void *element )
1804 +static void glyphRelease( void *element )
1806 - glyph_t *a=(glyph_t *)element;
1807 + glyph_t *a = (glyph_t *)element;
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);
1816 /********************************************************************/
1817 /* bitmap cache functions */
1820 -bitmapTest ( void *element, void *key )
1821 +static int bitmapTest ( void *element, void *key )
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;
1828 if (a->xoffset == b->xoffset && a->yoffset == b->yoffset) {
1829 b->glyph->Bit.bitmap = a->bitmap;
1830 @@ -563,11 +537,10 @@
1835 -bitmapFetch ( char **error, void *key )
1836 +static void * bitmapFetch ( char **error, void *key )
1839 - bitmapkey_t *b=(bitmapkey_t *)key;
1841 + bitmapkey_t *b = (bitmapkey_t *)key;
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);
1848 if (b->glyph->gray_render) {
1849 - TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit,
1850 - a->xoffset, a->yoffset);
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);
1857 + TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset);
1863 -bitmapRelease( void *element )
1864 +static void bitmapRelease( void *element )
1866 - bitmap_t *a=(bitmap_t *)element;
1867 + bitmap_t *a = (bitmap_t *)element;
1869 - pefree (a->bitmap, 1);
1870 - pefree ((char *)element, 1);
1871 + pefree(a->bitmap, 1);
1872 + pefree((char *)element, 1);
1875 /********************************************************************/
1876 /* tweencolor cache functions */
1879 -tweenColorTest (void *element, void *key)
1881 - tweencolor_t *a=(tweencolor_t *)element;
1882 - tweencolorkey_t *b=(tweencolorkey_t *)key;
1884 - return (a->pixel == b->pixel
1885 - && a->bgcolor == b->bgcolor
1886 - && a->fgcolor == b->fgcolor
1887 - && a->im == b->im);
1889 +static int tweenColorTest (void *element, void *key)
1891 + tweencolor_t *a = (tweencolor_t *)element;
1892 + tweencolorkey_t *b = (tweencolorkey_t *)key;
1894 + return (a->pixel == b->pixel && a->bgcolor == b->bgcolor && a->fgcolor == b->fgcolor && a->im == b->im);
1898 -tweenColorFetch (char **error, void *key)
1899 +static void * tweenColorFetch (char **error, void *key)
1902 - tweencolorkey_t *b=(tweencolorkey_t *)key;
1904 + tweencolorkey_t *b = (tweencolorkey_t *)key;
1905 int pixel, npixel, bg, fg;
1908 - a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1);
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;
1916 /* if fg is specified by a negative color idx, then don't antialias */
1919 a->tweencolor = -fg;
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);
1931 -tweenColorRelease(void *element)
1933 - pefree((char *)element, 1);
1939 +static void tweenColorRelease(void *element)
1941 + pefree((char *)element, 1);
1944 /********************************************************************/
1945 /* gdttfchar - render one character onto a gd image */
1947 -static int OneTime=0;
1948 +static int OneTime = 0;
1949 static gdCache_head_t *tweenColorCache;
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,
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;
1969 - glyphkey_t glyphkey;
1970 - bitmapkey_t bitmapkey;
1972 + glyphkey_t glyphkey;
1973 + bitmapkey_t bitmapkey;
1974 tweencolor_t *tweencolor;
1975 tweencolorkey_t tweencolorkey;
1977 /****** set up tweenColorCache on first call ************/
1979 - tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE,
1980 - tweenColorTest, tweenColorFetch, tweenColorRelease);
1982 + tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE, tweenColorTest, tweenColorFetch, tweenColorRelease);
1987 if (font->have_char_map_Unicode) { /* use UTF-8 mapping from ASCII */
1988 - len = gdTcl_UtfToUniChar(*next, &ch);
1990 + len = gdTcl_UtfToUniChar(*next, &ch);
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
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
2003 ch = (**next) & 255; /* don't extend sign */
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);
2014 + glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg < 0)) ? FALSE : TRUE;
2015 + glyphkey.font = font;
2016 + glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey);
2018 return font->glyphCache->error;
2021 *bbox = &glyph->metrics.bbox;
2022 *advance = glyph->metrics.advance;
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;
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);
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;
2048 pc = row * glyph->Bit.cols * 8;
2051 - if (y3 >= im->sy || y3 < 0) continue;
2052 + if (y3 >= im->sy || y3 < 0) {
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);
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;
2066 /* if not background */
2067 if (tweencolorkey.pixel > 0) {
2069 - if (x3 >= im->sx || x3 < 0) continue;
2070 + if (x3 >= im->sx || x3 < 0) {
2074 if (im->trueColor) {
2075 pixel = &im->tpixels[y3][x3];
2079 tweencolorkey.bgcolor = *pixel;
2080 - tweencolor = (tweencolor_t *)gdCacheGet(
2081 - tweenColorCache, &tweencolorkey);
2082 + tweencolor = (tweencolor_t *)gdCacheGet(tweenColorCache, &tweencolorkey);
2083 *pixel = tweencolor->tweencolor;
2086 @@ -769,29 +734,26 @@
2087 /********************************************************************/
2088 /* gdttf - render a utf8 string onto a gd image */
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)
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;
2099 double sin_a, cos_a;
2106 /****** initialize font engine on first call ************/
2107 - static gdCache_head_t *fontCache;
2108 + static gdCache_head_t *fontCache;
2109 static TT_Engine engine;
2111 - if (! fontCache) {
2113 if (TT_Init_FreeType(&engine)) {
2114 return "Failure to initialize font engine";
2116 - fontCache = gdCacheCreate( FONTCACHESIZE,
2117 - fontTest, fontFetch, fontRelease);
2118 + fontCache = gdCacheCreate(FONTCACHESIZE, fontTest, fontFetch, fontRelease);
2122 @@ -801,15 +763,15 @@
2123 fontkey.angle = angle;
2124 fontkey.engine = &engine;
2125 font = (font_t *)gdCacheGet(fontCache, &fontkey);
2128 return fontCache->error;
2130 sin_a = font->sin_a;
2131 cos_a = font->cos_a;
2132 advance_x = advance_y = 0;
2140 /* carriage returns */
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 */
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);
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))) {
2161 - if (! i++) { /* if first character, init BB corner values */
2162 + if (!i++) { /* if first character, init BB corner values */
2169 - if (! advance_x) ll_x = MIN(bbox->xMin, ll_x);
2172 + ll_x = MIN(bbox->xMin, ll_x);
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);
2178 + ur_y = MAX(bbox->yMax, ur_y);
2181 advance_x += advance;
2185 /* scale, round and offset brect */
2189 brect[i] = x + (brect[i] + 32) / 64;
2191 brect[i] = y - (brect[i] + 32) / 64;
2194 return (char *)NULL;
2198 #endif /* HAVE_LIBTTF */
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
2210 main (int argc, char *argv[])
2212 gdImagePtr im = gdImageCreate (WIDTH, HEIGHT);
2213 @@ -726,12 +726,12 @@
2214 out = fopen ("test/arctest.png", "wb");
2217 - php_gd_error("Can't create test/arctest.png\n");
2218 + php_gd_error("Can't create test/arctest.png");
2221 gdImagePng (im, out);
2223 - php_gd_error("Test image written to test/arctest.png\n");
2224 + php_gd_error("Test image written to test/arctest.png");
2226 gdImageDestroy (im);
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
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);
2247 -void php_gd_error_ex(int type, const char *format, ...)
2248 +void php_gd_error_ex(int type, const char *format, ...)
2256 va_start(args, format);
2257 php_verror(NULL, "", type, format, args TSRMLS_CC);
2260 void php_gd_error(const char *format, ...)
2268 va_start(args, format);
2269 php_verror(NULL, "", E_WARNING, format, args TSRMLS_CC);
2271 @@ -122,11 +120,20 @@
2275 - im = (gdImage *) gdMalloc(sizeof(gdImage));
2276 - memset(im, 0, sizeof(gdImage));
2278 + if (overflow2(sx, sy)) {
2282 + if (overflow2(sizeof(unsigned char *), sy)) {
2286 + im = (gdImage *) gdCalloc(1, sizeof(gdImage));
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);
2294 im->polyAllocated = 0;
2296 @@ -164,10 +171,23 @@
2301 + if (overflow2(sx, sy)) {
2305 + if (overflow2(sizeof(unsigned char *), sy)) {
2309 + if (overflow2(sizeof(int), sx)) {
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);
2320 im->polyAllocated = 0;
2323 static HWBType * RGB_to_HWB (RGBType RGB, HWBType * HWB)
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.
2332 float R = RGB.R, G = RGB.G, B = RGB.B, w, v, b, f;
2335 f = (R == w) ? G - B : ((G == w) ? B - R : R - G);
2336 i = (R == w) ? 3 : ((G == w) ? 5 : 1);
2339 RETURN_HWB(i - f / (v - w), w, b);
2344 static RGBType * HWB_to_RGB (HWBType HWB, RGBType * RGB)
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].
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].
2354 float h = HWB.H, w = HWB.W, b = HWB.B, v, n, f;
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 */
2370 /* now, perhaps, adjust the end of the line */
2372 *y1 -= (int)(m * *x1);
2374 im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color);
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);
2380 case gdEffectOverlay :
2381 im->tpixels[y][x] = gdLayerOverlay(im->tpixels[y][x], color);
2383 int p = gdImageGetPixel(im, x, y);
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]);
2393 x2 = x1 + gdImageSX(im->brush);
2397 if (im->trueColor) {
2398 if (im->brush->trueColor) {
2399 for (ly = y1; ly < y2; ly++) {
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)));
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);
2420 p = gdImageGetPixel(im->tile, srcx, srcy);
2421 /* Allow for transparency */
2423 float p_dist, p_alpha;
2424 unsigned char opacity;
2427 - * Find the perpendicular distance from point C (px, py) to the line
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.)
2434 int By_Cy = im->AAL_y2 - py;
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.
2442 @@ -931,12 +953,12 @@
2443 LBC_2 = (Bx_Cx * Bx_Cx) + (By_Cy * By_Cy);
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.
2450 p_dist = fabs ((float) ((Ay_Cy * im->AAL_Bx_Ax) - (Ax_Cx * im->AAL_By_Ay)) / im->AAL_LAB);
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.
2457 @@ -1017,6 +1039,43 @@
2461 +static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col)
2463 + if (im->thick > 1) {
2464 + int thickhalf = im->thick >> 1;
2465 + gdImageFilledRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col);
2473 + for (;x1 <= x2; x1++) {
2474 + gdImageSetPixel(im, x1, y, col);
2480 +static void gdImageVLine(gdImagePtr im, int x, int y1, int y2, int col)
2482 + if (im->thick > 1) {
2483 + int thickhalf = im->thick >> 1;
2484 + gdImageFilledRectangle(im, x - thickhalf, y1, x + im->thick - thickhalf - 1, y2, col);
2492 + for (;y1 <= y2; y1++) {
2493 + gdImageSetPixel(im, x, y1, col);
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 @@
2503 int thick = im->thick;
2505 + if (color == gdAntiAliased)
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.
2512 + gdImageAALine(im, x1, y1, x2, y2, im->AA_color);
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))) {
2521 - /* gdAntiAliased passed as color: set anti-aliased line (AAL) global vars. */
2522 - if (color == gdAntiAliased) {
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);
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.
2541 + gdImageVLine(im, x1, y1, y2, color);
2543 + } else if (dy == 0) {
2544 + gdImageHLine(im, y1, x1, x2, color);
2548 - dx = abs(x2 - x1);
2549 - dy = abs(y2 - y1);
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)) {
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));
2569 @@ -1115,16 +1182,17 @@
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));
2580 - if (!(wid = thick / as)) {
2593 @@ -1177,11 +1245,6 @@
2598 - /* If this is the only line we are drawing, go ahead and blend. */
2599 - if (color == gdAntiAliased && !im->AA_polygon) {
2600 - gdImageAABlend(im);
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);
2613 * Added on 2003/12 by Pierre-Alain Joye (pajoye@pearfr.org)
2614 @@ -1586,9 +1649,9 @@
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. */
2625 void gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
2626 @@ -1607,29 +1670,30 @@
2630 - if ((s % 360) == (e % 360)) {
2632 + if ((s % 360) == (e % 360)) {
2672 for (i = s; i <= e; i++) {
2674 @@ -1787,17 +1851,15 @@
2677 int leftLimit = -1, rightLimit;
2678 - int i, restoreAlphaBleding=0;
2679 + int i, restoreAlphaBlending = 0;
2682 /* Refuse to fill to a non-solid border */
2686 - if (im->alphaBlendingFlag) {
2687 - restoreAlphaBleding = 1;
2688 - im->alphaBlendingFlag = 0;
2690 + restoreAlphaBlending = im->alphaBlendingFlag;
2691 + im->alphaBlendingFlag = 0;
2695 @@ -1814,9 +1876,7 @@
2698 if (leftLimit == -1) {
2699 - if (restoreAlphaBleding) {
2700 - im->alphaBlendingFlag = 1;
2702 + im->alphaBlendingFlag = restoreAlphaBlending;
2706 @@ -1844,6 +1904,7 @@
2712 if (y < ((im->sy) - 1)) {
2714 @@ -1860,12 +1921,9 @@
2718 - if (restoreAlphaBleding) {
2719 - im->alphaBlendingFlag = 1;
2721 + im->alphaBlendingFlag = restoreAlphaBlending;
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;}
2732 -void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc);
2733 +static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc);
2735 void gdImageFill(gdImagePtr im, int x, int y, int nc)
2738 int oc; /* old pixel value */
2741 int alphablending_bak;
2743 /* stack of filled segments */
2744 /* struct seg stack[FILL_MAX],*sp = stack;; */
2745 - struct seg *stack;
2746 + struct seg *stack = NULL;
2749 + if (!im->trueColor && nc > (im->colorsTotal -1)) {
2753 alphablending_bak = im->alphaBlendingFlag;
2754 im->alphaBlendingFlag = 0;
2757 _gdImageFillTiled(im,x,y,nc);
2758 - im->alphaBlendingFlag = alphablending_bak;
2759 + im->alphaBlendingFlag = alphablending_bak;
2763 @@ -1916,8 +1980,31 @@
2764 im->alphaBlendingFlag = alphablending_bak;
2768 - stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1);
2770 + /* Do not use the 4 neighbors implementation with
2774 + int ix = x, iy = y, c;
2776 + c = gdImageGetPixel(im, ix, iy);
2780 + gdImageSetPixel(im, ix, iy, nc);
2781 + } while(ix++ < (im->sx -1));
2782 + ix = x; iy = y + 1;
2784 + c = gdImageGetPixel(im, ix, iy);
2788 + gdImageSetPixel(im, ix, iy, nc);
2789 + } while(ix++ < (im->sx -1));
2793 + stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1);
2797 @@ -1954,22 +2041,25 @@
2805 im->alphaBlendingFlag = alphablending_bak;
2808 -void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
2809 +static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
2811 - int i,l, x1, x2, dy;
2812 + int i, l, x1, x2, dy;
2813 int oc; /* old pixel value */
2816 /* stack of filled segments */
2827 @@ -1977,30 +2067,26 @@
2828 tiled = nc==gdTiled;
2830 nc = gdImageTileGet(im,x,y);
2831 - pts = (int **) ecalloc(sizeof(int *) * im->sy, sizeof(int));
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));
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);
2844 oc = gdImageGetPixel(im, x, y);
2849 /* seed segment (popped 1st) */
2850 FILL_PUSH(y+1, x, x, -1);
2852 FILL_POP(y, x1, x2, dy);
2853 for (x=x1; x>=0 && (!pts[y][x] && gdImageGetPixel(im,x,y)==oc); x--) {
2855 - /* we should never be here */
2858 nc = gdImageTileGet(im,x,y);
2861 gdImageSetPixel(im,x, y, nc);
2864 @@ -2014,13 +2100,9 @@
2868 - for (; x<=wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc) ; x++) {
2870 - /* we should never be here */
2873 + for(; x<wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc); x++) {
2874 nc = gdImageTileGet(im,x,y);
2877 gdImageSetPixel(im, x, y, nc);
2879 FILL_PUSH(y, l, x-1, dy);
2880 @@ -2028,13 +2110,15 @@
2882 FILL_PUSH(y, x2+1, x-1, -dy);
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++);
2889 - for (i=0; i<im->sy;i++) {
2891 + for(i = 0; i < im->sy + 1; i++) {
2898 @@ -2048,6 +2132,11 @@
2902 + if (x1 == x2 && y1 == y2 && thick == 1) {
2903 + gdImageSetPixel(im, x1, y1, color);
2910 @@ -2110,16 +2199,15 @@
2911 gdImageLine(im, x1v, y1v, x1v, y2v, color);
2912 gdImageLine(im, x2v, y1v, x2v, y2v, color);
2917 void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
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
2929 @@ -2133,15 +2221,15 @@
2930 if (y1 > gdImageSY(im)) {
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.
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]));
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.
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]);
2987 - mapTo = colorMap[c];
2988 + mapTo = colorMap[c];
2990 - mapTo = colorMap[c];
2991 + mapTo = colorMap[c];
2993 gdImageSetPixel (dst, tox, toy, mapTo);
2995 @@ -2257,7 +2345,7 @@
3001 for (y = srcY; y < (srcY + h); y++) {
3003 for (x = srcX; x < (srcX + w); x++) {
3004 @@ -2304,15 +2392,17 @@
3005 for (x = srcX; (x < (srcX + w)); x++) {
3007 c = gdImageGetPixel (src, x, y);
3009 /* Added 7/24/95: support transparent copies */
3010 if (gdImageGetTransparent(src) == c) {
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.
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.
3024 if (dst == src && pct == 100) {
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));
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));
3038 /* First look for an exact match */
3039 nc = gdImageColorExact(dst, ncR, ncG, ncB);
3040 @@ -2354,10 +2445,18 @@
3042 /* We only need to use floating point to determine the correct stretch vector for one line's worth. */
3044 - stx = (int *) safe_emalloc(sizeof(int), srcW, 0);
3045 - sty = (int *) safe_emalloc(sizeof(int), srcH, 0);
3048 + if (overflow2(sizeof(int), srcW)) {
3051 + if (overflow2(sizeof(int), srcH)) {
3055 + stx = (int *) gdMalloc (sizeof (int) * srcW);
3056 + sty = (int *) gdMalloc (sizeof (int) * srcH);
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];
3069 /* TK: old code follows */
3070 mapTo = gdImageGetTrueColorPixel (src, x, y);
3071 @@ -2397,7 +2496,7 @@
3072 tox += stx[x - srcX];
3078 c = gdImageGetPixel (src, x, y);
3079 /* Added 7/24/95: support transparent copies */
3080 @@ -2451,6 +2550,7 @@
3083 double sy1, sy2, sx1, sx2;
3085 if (!dst->trueColor) {
3086 gdImageCopyResized (dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
3088 @@ -2497,7 +2597,7 @@
3090 pcontribution = xportion * yportion;
3091 p = gdImageGetTrueColorPixel(src, (int) sx + srcX, (int) sy + srcY);
3094 alpha_factor = ((gdAlphaMax - gdTrueColorGetAlpha(p))) * pcontribution;
3095 red += gdTrueColorGetRed (p) * alpha_factor;
3096 green += gdTrueColorGetGreen (p) * alpha_factor;
3097 @@ -2509,12 +2609,12 @@
3110 if (spixels != 0.0f) {
3113 @@ -2524,7 +2624,7 @@
3114 if ( alpha_sum != 0.0f) {
3115 if( contrib_sum != 0.0f) {
3116 alpha_sum /= contrib_sum;
3122 @@ -2549,7 +2649,7 @@
3126 - * Rotate function Added on 2003/12
3127 + * Rotate function Added on 2003/12
3128 * by Pierre-Alain Joye (pajoye@pearfr.org)
3130 /* Begin rotate function */
3131 @@ -2558,7 +2658,7 @@
3132 #endif /* ROTATE_PI */
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)
3138 typedef int (*FuncPtr)(gdImagePtr, int, int);
3139 int i, r, g, b, a, clrBackR, clrBackG, clrBackB, clrBackA;
3140 @@ -2623,10 +2723,14 @@
3144 - pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3145 + if (ignoretransparent && pxlSrc == dst->transparent) {
3146 + pxlSrc = dst->transparent;
3148 + pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3150 - if (pxlSrc == -1) {
3151 - pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3152 + if (pxlSrc == -1) {
3153 + pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3157 if ((i + iOffset >= 0) && (i + iOffset < dst->sx)) {
3158 @@ -2651,7 +2755,7 @@
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)
3165 typedef int (*FuncPtr)(gdImagePtr, int, int);
3166 int i, iYPos=0, r, g, b, a;
3167 @@ -2710,10 +2814,14 @@
3171 - pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3172 + if (ignoretransparent && pxlSrc == dst->transparent) {
3173 + pxlSrc = dst->transparent;
3175 + pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3177 - if (pxlSrc == -1) {
3178 - pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3179 + if (pxlSrc == -1) {
3180 + pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3184 if ((iYPos >= 0) && (iYPos < dst->sy)) {
3185 @@ -2735,10 +2843,10 @@
3188 /* Rotates an image by 90 degrees (counter clockwise) */
3189 -gdImagePtr gdImageRotate90 (gdImagePtr src)
3190 +gdImagePtr gdImageRotate90 (gdImagePtr src, int ignoretransparent)
3196 typedef int (*FuncPtr)(gdImagePtr, int, int);
3198 @@ -2749,8 +2857,12 @@
3199 f = gdImageGetPixel;
3201 dst = gdImageCreateTrueColor(src->sy, src->sx);
3202 + dst->transparent = src->transparent;
3205 + int old_blendmode = dst->alphaBlendingFlag;
3206 + dst->alphaBlendingFlag = 0;
3208 gdImagePaletteCopy (dst, src);
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);
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);
3219 + gdImageSetPixel(dst, uY, (dst->sy - uX - 1), c);
3223 + dst->alphaBlendingFlag = old_blendmode;
3229 /* Rotates an image by 180 degrees (counter clockwise) */
3230 -gdImagePtr gdImageRotate180 (gdImagePtr src)
3231 +gdImagePtr gdImageRotate180 (gdImagePtr src, int ignoretransparent)
3235 @@ -2786,8 +2903,12 @@
3236 f = gdImageGetPixel;
3238 dst = gdImageCreateTrueColor(src->sx, src->sy);
3239 + dst->transparent = src->transparent;
3242 + int old_blendmode = dst->alphaBlendingFlag;
3243 + dst->alphaBlendingFlag = 0;
3245 gdImagePaletteCopy (dst, src);
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);
3252 - gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), c);
3254 + if (ignoretransparent && c == dst->transparent) {
3255 + gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), dst->transparent);
3257 + gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), c);
3261 + dst->alphaBlendingFlag = old_blendmode;
3267 /* Rotates an image by 270 degrees (counter clockwise) */
3268 -gdImagePtr gdImageRotate270 ( gdImagePtr src )
3269 +gdImagePtr gdImageRotate270 (gdImagePtr src, int ignoretransparent)
3273 @@ -2822,9 +2949,13 @@
3275 f = gdImageGetPixel;
3277 - dst = gdImageCreateTrueColor(src->sy, src->sx);
3278 + dst = gdImageCreateTrueColor (src->sy, src->sx);
3279 + dst->transparent = src->transparent;
3282 + int old_blendmode = dst->alphaBlendingFlag;
3283 + dst->alphaBlendingFlag = 0;
3285 gdImagePaletteCopy (dst, src);
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);
3292 - gdImageSetPixel(dst, (dst->sx - uY - 1), uX, c);
3294 + if (ignoretransparent && c == dst->transparent) {
3295 + gdImageSetPixel(dst, (dst->sx - uY - 1), uX, dst->transparent);
3297 + gdImageSetPixel(dst, (dst->sx - uY - 1), uX, c);
3301 + dst->alphaBlendingFlag = old_blendmode;
3307 -gdImagePtr gdImageRotate45 (gdImagePtr src, double dAngle, int clrBack)
3308 +gdImagePtr gdImageRotate45 (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent)
3310 typedef int (*FuncPtr)(gdImagePtr, int, int);
3311 gdImagePtr dst1,dst2,dst3;
3312 @@ -2869,8 +3006,8 @@
3314 f = gdImageGetPixel;
3316 - dst1 = gdImageCreateTrueColor(newx, newy);
3318 + dst1 = gdImageCreateTrueColor(newx, newy);
3319 /******* Perform 1st shear (horizontal) ******/
3322 @@ -2885,6 +3022,15 @@
3324 gdImagePaletteCopy (dst1, src);
3326 + if (ignoretransparent) {
3327 + if (gdImageTrueColor(src)) {
3328 + dst1->transparent = src->transparent;
3331 + dst1->transparent = gdTrueColorAlpha(gdImageRed(src, src->transparent), gdImageBlue(src, src->transparent), gdImageGreen(src, src->transparent), 127);
3335 dRadAngle = dAngle * ROTATE_DEG2RAD; /* Angle in radians */
3336 dSinE = sin (dRadAngle);
3337 dTan = tan (dRadAngle / 2.0);
3338 @@ -2897,7 +3043,7 @@
3341 iShear = (int)floor(dShear);
3342 - gdImageSkewX(dst1, src, u, iShear, (dShear - iShear), clrBack);
3343 + gdImageSkewX(dst1, src, u, iShear, (dShear - iShear), clrBack, ignoretransparent);
3347 @@ -2933,10 +3079,13 @@
3350 dst2->alphaBlendingFlag = gdEffectReplace;
3351 + if (ignoretransparent) {
3352 + dst2->transparent = dst1->transparent;
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);
3362 @@ -2955,6 +3104,12 @@
3363 gdImageDestroy(dst2);
3367 + dst3->alphaBlendingFlag = gdEffectReplace;
3368 + if (ignoretransparent) {
3369 + dst3->transparent = dst2->transparent;
3373 dOffset = (double)(src->sx - 1) * dSinE * -dTan;
3375 @@ -2962,8 +3117,8 @@
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);
3385 gdImageDestroy(dst2);
3386 @@ -2971,11 +3126,11 @@
3390 -gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack)
3391 +gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent)
3394 gdImagePtr rotatedImg;
3400 @@ -2993,41 +3148,33 @@
3403 if (dAngle == 90.00) {
3404 - return gdImageRotate90(src);
3405 + return gdImageRotate90(src, ignoretransparent);
3407 if (dAngle == 180.00) {
3408 - return gdImageRotate180(src);
3409 + return gdImageRotate180(src, ignoretransparent);
3411 if(dAngle == 270.00) {
3412 - return gdImageRotate270 ( src);
3413 + return gdImageRotate270 (src, ignoretransparent);
3416 if ((dAngle > 45.0) && (dAngle <= 135.0)) {
3417 - pMidImg = gdImageRotate90 (src);
3418 + pMidImg = gdImageRotate90 (src, ignoretransparent);
3420 } else if ((dAngle > 135.0) && (dAngle <= 225.0)) {
3421 - pMidImg = gdImageRotate180 (src);
3422 + pMidImg = gdImageRotate180 (src, ignoretransparent);
3424 } else if ((dAngle > 225.0) && (dAngle <= 315.0)) {
3425 - pMidImg = gdImageRotate270 (src);
3426 + pMidImg = gdImageRotate270 (src, ignoretransparent);
3429 - return gdImageRotate45 (src, dAngle, clrBack);
3430 + return gdImageRotate45 (src, dAngle, clrBack, ignoretransparent);
3433 if (pMidImg == NULL) {
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);
3445 - rotatedImg = gdImageRotate45 (pMidImg, dAngle, clrBack);
3446 + rotatedImg = gdImageRotate45 (pMidImg, dAngle, clrBack, ignoretransparent);
3447 gdImageDestroy(pMidImg);
3450 @@ -3098,20 +3245,27 @@
3454 + if (overflow2(sizeof(int), n)) {
3458 if (c == gdAntiAliased) {
3459 fill_color = im->AA_color;
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;
3470 if (im->polyAllocated < n) {
3471 while (im->polyAllocated < n) {
3472 im->polyAllocated *= 2;
3474 + if (overflow2(sizeof(int), im->polyAllocated)) {
3477 im->polyInts = (int *) gdRealloc(im->polyInts, sizeof(int) * im->polyAllocated);
3480 @@ -3131,7 +3285,7 @@
3482 if (maxy >= gdImageSY(im)) {
3483 maxy = gdImageSY(im) - 1;
3487 /* Fix in 1.3: count a vertex only once */
3488 for (y = miny; y <= maxy; y++) {
3489 @@ -3193,7 +3347,7 @@
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;
3498 @@ -3323,9 +3477,9 @@
3502 -gdAlphaBlend (int dst, int src)
3503 +gdAlphaBlendOld (int dst, int src)
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.
3510 @@ -3345,6 +3499,51 @@
3511 gdTrueColorGetBlue (dst)) / gdAlphaMax));
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;
3519 +/* -------------------------------------------------------------------- */
3520 +/* Simple cases we want to handle fast. */
3521 +/* -------------------------------------------------------------------- */
3522 + if( src_alpha == gdAlphaOpaque )
3525 + dst_alpha = gdTrueColorGetAlpha(dst);
3526 + if( src_alpha == gdAlphaTransparent )
3528 + if( dst_alpha == gdAlphaTransparent )
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;
3540 +/* -------------------------------------------------------------------- */
3541 +/* What red, green and blue result values will we use? */
3542 +/* -------------------------------------------------------------------- */
3543 + alpha = src_alpha * dst_alpha / gdAlphaMax;
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;
3552 +/* -------------------------------------------------------------------- */
3553 +/* Return merged result. */
3554 +/* -------------------------------------------------------------------- */
3555 + return ((alpha << 24) + (red << 16) + (green << 8) + blue);
3559 void gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg)
3561 im->alphaBlendingFlag = alphaBlendingArg;
3562 @@ -3362,44 +3561,6 @@
3563 im->saveAlphaFlag = saveAlphaArg;
3566 -static int gdFullAlphaBlend (int dst, int src)
3569 - a1 = gdAlphaTransparent - gdTrueColorGetAlpha(src);
3570 - a2 = gdAlphaTransparent - gdTrueColorGetAlpha(dst);
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 ))
3579 -static int gdAlphaBlendColor( int b1, int b2, int a1, int a2 )
3584 - /* deal with special cases */
3586 - if( (gdAlphaMax == a1) || (0 == a2) ) {
3587 - /* the back pixel can't be seen */
3589 - } else if(0 == a1) {
3590 - /* the front pixel can't be seen */
3592 - } else if(gdAlphaMax == a2) {
3593 - /* the back pixel is opaque */
3594 - return ( a1 * b1 + ( gdAlphaMax - a1 ) * b2 ) / gdAlphaMax;
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;
3604 static int gdLayerOverlay (int dst, int src)
3607 @@ -3415,12 +3576,12 @@
3608 static int gdAlphaOverlayColor (int src, int dst, int max )
3610 /* this function implements the algorithm
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
3622 @@ -3472,3 +3633,457 @@
3628 +/* Filters function added on 2003/12
3629 + * by Pierre-Alain Joye (pajoye@pearfr.org)
3631 +/* Begin filters function */
3632 +#ifndef HAVE_GET_TRUE_COLOR
3633 +#define GET_PIXEL_FUNCTION(src)(src->trueColor?gdImageGetTrueColorPixel:gdImageGetPixel)
3636 +/* invert src image */
3637 +int gdImageNegate(gdImagePtr src)
3642 + typedef int (*FuncPtr)(gdImagePtr, int, int);
3649 + f = GET_PIXEL_FUNCTION(src);
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);
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);
3663 + gdImageSetPixel (src, x, y, new_pxl);
3669 +/* Convert the image src to a grayscale image */
3670 +int gdImageGrayScale(gdImagePtr src)
3675 + typedef int (*FuncPtr)(gdImagePtr, int, int);
3677 + f = GET_PIXEL_FUNCTION(src);
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);
3692 + new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a);
3693 + if (new_pxl == -1) {
3694 + new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
3696 + gdImageSetPixel (src, x, y, new_pxl);
3702 +/* Set the brightness level <level> for the image src */
3703 +int gdImageBrightness(gdImagePtr src, int brightness)
3708 + typedef int (*FuncPtr)(gdImagePtr, int, int);
3710 + f = GET_PIXEL_FUNCTION(src);
3712 + if (src==NULL || (brightness < -255 || brightness>255)) {
3716 + if (brightness==0) {
3720 + for (y=0; y<src->sy; ++y) {
3721 + for (x=0; x<src->sx; ++x) {
3722 + pxl = f (src, x, y);
3724 + r = gdImageRed(src, pxl);
3725 + g = gdImageGreen(src, pxl);
3726 + b = gdImageBlue(src, pxl);
3727 + a = gdImageAlpha(src, pxl);
3729 + r = r + brightness;
3730 + g = g + brightness;
3731 + b = b + brightness;
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);
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);
3741 + gdImageSetPixel (src, x, y, new_pxl);
3748 +int gdImageContrast(gdImagePtr src, double contrast)
3754 + typedef int (*FuncPtr)(gdImagePtr, int, int);
3757 + f = GET_PIXEL_FUNCTION(src);
3763 + contrast = (double)(100.0-contrast)/100.0;
3764 + contrast = contrast*contrast;
3766 + for (y=0; y<src->sy; ++y) {
3767 + for (x=0; x<src->sx; ++x) {
3768 + pxl = f(src, x, y);
3770 + r = gdImageRed(src, pxl);
3771 + g = gdImageGreen(src, pxl);
3772 + b = gdImageBlue(src, pxl);
3773 + a = gdImageAlpha(src, pxl);
3775 + rf = (double)r/255.0;
3781 + bf = (double)b/255.0;
3787 + gf = (double)g/255.0;
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);
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);
3801 + gdImageSetPixel (src, x, y, new_pxl);
3808 +int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha)
3812 + typedef int (*FuncPtr)(gdImagePtr, int, int);
3815 + if (src == NULL) {
3819 + f = GET_PIXEL_FUNCTION(src);
3821 + for (y=0; y<src->sy; ++y) {
3822 + for (x=0; x<src->sx; ++x) {
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);
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);
3841 + new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a);
3842 + if (new_pxl == -1) {
3843 + new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
3845 + gdImageSetPixel (src, x, y, new_pxl);
3851 +int gdImageConvolution(gdImagePtr src, float filter[3][3], float filter_div, float offset)
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);
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);
3868 + if (srcback==NULL) {
3872 + f = GET_PIXEL_FUNCTION(src);
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);
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];
3889 + new_r = (new_r/filter_div)+offset;
3890 + new_g = (new_g/filter_div)+offset;
3891 + new_b = (new_b/filter_div)+offset;
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);
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);
3901 + gdImageSetPixel (src, x, y, new_pxl);
3904 + gdImageDestroy(srcback);
3908 +int gdImageSelectiveBlur( gdImagePtr src)
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;
3918 + gdImagePtr srcback;
3919 + typedef int (*FuncPtr)(gdImagePtr, int, int);
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);
3930 + if (srcback==NULL) {
3934 + f = GET_PIXEL_FUNCTION(src);
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);
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;
3946 + pxl = f(src, x-(3>>1)+i, y-(3>>1)+j);
3947 + new_a = gdImageAlpha(srcback, pxl);
3949 + new_r = ((float)gdImageRed(srcback, cpxl)) - ((float)gdImageRed (srcback, pxl));
3951 + if (new_r < 0.0f) {
3955 + flt_r[j][i] = 1.0f/new_r;
3957 + flt_r[j][i] = 1.0f;
3960 + new_g = ((float)gdImageGreen(srcback, cpxl)) - ((float)gdImageGreen(srcback, pxl));
3962 + if (new_g < 0.0f) {
3966 + flt_g[j][i] = 1.0f/new_g;
3968 + flt_g[j][i] = 1.0f;
3971 + new_b = ((float)gdImageBlue(srcback, cpxl)) - ((float)gdImageBlue(srcback, pxl));
3973 + if (new_b < 0.0f) {
3977 + flt_b[j][i] = 1.0f/new_b;
3979 + flt_b[j][i] = 1.0f;
3983 + flt_r_sum += flt_r[j][i];
3984 + flt_g_sum += flt_g[j][i];
3985 + flt_b_sum += flt_b [j][i];
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;
3994 + if (flt_g_sum != 0.0) {
3995 + flt_g[j][i] /= flt_g_sum;
3997 + if (flt_b_sum != 0.0) {
3998 + flt_b [j][i] /= flt_b_sum;
4003 + new_r = new_g = new_b = 0.0;
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];
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);
4021 + gdImageSetPixel (src, x, y, new_pxl);
4024 + gdImageDestroy(srcback);
4028 +int gdImageEdgeDetectQuick(gdImagePtr src)
4030 + float filter[3][3] = {{-1.0,0.0,-1.0},
4034 + return gdImageConvolution(src, filter, 1, 127);
4037 +int gdImageGaussianBlur(gdImagePtr im)
4039 + float filter[3][3] = {{1.0,2.0,1.0},
4043 + return gdImageConvolution(im, filter, 16, 0);
4046 +int gdImageEmboss(gdImagePtr im)
4049 + float filter[3][3] = {{1.0,1.0,1.0},
4051 + {-1.0,-1.0,-1.0}};
4053 + float filter[3][3] = {{ 1.5, 0.0, 0.0},
4055 + { 0.0, 0.0,-1.5}};
4057 + return gdImageConvolution(im, filter, 1, 127);
4060 +int gdImageMeanRemoval(gdImagePtr im)
4062 + float filter[3][3] = {{-1.0,-1.0,-1.0},
4064 + {-1.0,-1.0,-1.0}};
4066 + return gdImageConvolution(im, filter, 1, 0);
4069 +int gdImageSmooth(gdImagePtr im, float weight)
4071 + float filter[3][3] = {{1.0,1.0,1.0},
4075 + filter[1][1] = weight;
4077 + return gdImageConvolution(im, filter, weight+8, 0);
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
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.
4097 * John Ellson (ellson@graphviz.org) Oct 31, 1997
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
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.
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
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.
4135 * John Ellson (ellson@graphviz.org) Oct 31, 1997
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
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.
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
4164 #include "gdfontg.h"
4166 -char gdFontGiantData[] =
4167 +static const char gdFontGiantData[] =
4170 0, 0, 0, 0, 0, 0, 0, 0, 0,
4171 @@ -4376,7 +4376,7 @@
4176 + (char*)gdFontGiantData
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
4185 #include "gdfontl.h"
4187 -char gdFontLargeData[] =
4188 +static const char gdFontLargeData[] =
4191 0, 0, 0, 0, 0, 0, 0, 0,
4192 @@ -4633,7 +4633,7 @@
4197 + (char*)gdFontLargeData
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
4206 #include "gdfontmb.h"
4208 -char gdFontMediumBoldData[] =
4209 +static const char gdFontMediumBoldData[] =
4212 0, 0, 0, 0, 0, 0, 0,
4213 @@ -3863,7 +3863,7 @@
4217 - gdFontMediumBoldData
4218 + (char*)gdFontMediumBoldData
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
4227 #include "gdfonts.h"
4229 -char gdFontSmallData[] =
4230 +static const char gdFontSmallData[] =
4234 @@ -3863,7 +3863,7 @@
4239 + (char*)gdFontSmallData
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
4248 #include "gdfontt.h"
4250 -char gdFontTinyData[] =
4251 +static const char gdFontTinyData[] =
4255 @@ -2584,7 +2584,7 @@
4260 + (char*)gdFontTinyData
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
4271 -#define R_OK 04 /* Needed in Windows */
4273 +# define R_OK 04 /* Needed in Windows */
4279 gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist,
4280 double ptsize, double angle, int x, int y, char *string)
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);
4289 #ifndef HAVE_LIBFREETYPE
4291 double ptsize, double angle, int x, int y, char *string,
4292 gdFTStringExtraPtr strex)
4294 - return "libgd was not built with FreeType font support\n";
4295 + return "libgd was not built with FreeType font support\n";
4299 gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
4300 double ptsize, double angle, int x, int y, char *string)
4302 - return "libgd was not built with FreeType font support\n";
4303 + return "libgd was not built with FreeType font support\n";
4308 #define TWEENCOLORCACHESIZE 32
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.
4317 #define LINESPACE 1.05
4318 @@ -115,40 +116,35 @@
4322 - char *fontlist; /* key */
4323 - FT_Library *library;
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;
4330 + char *fontlist; /* key */
4331 + FT_Library *library;
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;
4339 - char *fontlist; /* key */
4340 - FT_Library *library;
4344 + char *fontlist; /* key */
4345 + FT_Library *library;
4350 - int pixel; /* key */
4351 - int bgcolor; /* key */
4352 - int fgcolor; /* key *//* -ve means no antialias */
4353 - gdImagePtr im; /* key */
4358 + int pixel; /* key */
4359 + int bgcolor; /* key */
4360 + int fgcolor; /* key *//* -ve means no antialias */
4361 + gdImagePtr im; /* key */
4367 - int pixel; /* key */
4368 - int bgcolor; /* key */
4369 - int fgcolor; /* key *//* -ve means no antialias */
4370 - gdImagePtr im; /* key */
4374 + int pixel; /* key */
4375 + int bgcolor; /* key */
4376 + int fgcolor; /* key *//* -ve means no antialias */
4377 + gdImagePtr im; /* key */
4380 /********************************************************************
4381 * gdTcl_UtfToUniChar is borrowed from Tcl ...
4382 @@ -208,160 +204,141 @@
4384 #define Tcl_UniChar int
4385 #define TCL_UTF_MAX 3
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 */
4395 + /* HTML4.0 entities in decimal form, e.g. Å */
4396 + byte = *((unsigned char *) str);
4397 + if (byte == '&') {
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';
4414 + n = (n * 16) + byte;
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');
4426 + if (byte == ';') {
4427 + *chPtr = (Tcl_UniChar) n;
4433 - /* HTML4.0 entities in decimal form, e.g. Å */
4434 - byte = *((unsigned char *) str);
4439 - byte = *((unsigned char *) (str + 1));
4442 - for (i = 2; i < 8; i++)
4444 - byte = *((unsigned char *) (str + i));
4445 - if (byte >= '0' && byte <= '9')
4447 - n = (n * 10) + (byte - '0');
4454 - *chPtr = (Tcl_UniChar) n;
4461 - * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones.
4463 + /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */
4465 - byte = *((unsigned char *) str);
4466 + byte = *((unsigned char *) str);
4468 - if (0xA1 <= byte && byte <= 0xFE)
4472 - ku = (byte & 0x7F) - 0x20;
4473 - ten = (str[1] & 0x7F) - 0x20;
4474 - if ((ku < 1 || ku > 92) || (ten < 1 || ten > 94))
4476 - *chPtr = (Tcl_UniChar) byte;
4480 - *chPtr = (Tcl_UniChar) UnicodeTbl[ku - 1][ten - 1];
4484 + if (0xA1 <= byte && byte <= 0xFE) {
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;
4494 + *chPtr = (Tcl_UniChar) UnicodeTbl[ku - 1][ten - 1];
4497 #endif /* JISX0208 */
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
4507 - *chPtr = (Tcl_UniChar) byte;
4510 - else if (byte < 0xE0)
4512 - if ((str[1] & 0xC0) == 0x80)
4515 - * Two-byte-character lead-byte followed
4516 - * by a trail-byte.
4519 - *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6)
4520 - | (str[1] & 0x3F));
4524 - * A two-byte-character lead-byte not followed by trail-byte
4525 - * represents itself.
4528 - *chPtr = (Tcl_UniChar) byte;
4531 - else if (byte < 0xF0)
4533 - if (((str[1] & 0xC0) == 0x80) && ((str[2] & 0xC0) == 0x80))
4536 - * Three-byte-character lead byte followed by
4537 - * two trail bytes.
4540 - *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12)
4541 - | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F));
4545 - * A three-byte-character lead-byte not followed by
4546 - * two trail-bytes represents itself.
4549 - *chPtr = (Tcl_UniChar) byte;
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
4559 + *chPtr = (Tcl_UniChar) byte;
4561 + } else if (byte < 0xE0) {
4562 + if ((str[1] & 0xC0) == 0x80) {
4563 + /* Two-byte-character lead-byte followed by a trail-byte. */
4565 + *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (str[1] & 0x3F));
4569 + * A two-byte-character lead-byte not followed by trail-byte
4570 + * represents itself.
4573 + *chPtr = (Tcl_UniChar) byte;
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. */
4579 + *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F));
4582 + /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */
4584 + *chPtr = (Tcl_UniChar) byte;
4590 - int ch, total, trail;
4592 - total = totalBytes[byte];
4593 - trail = total - 1;
4596 - ch = byte & (0x3F >> trail);
4600 - if ((*str & 0xC0) != 0x80)
4606 - ch |= (*str & 0x3F);
4609 - while (trail > 0);
4613 + int ch, total, trail;
4615 + total = totalBytes[byte];
4616 + trail = total - 1;
4619 + ch = byte & (0x3F >> trail);
4622 + if ((*str & 0xC0) != 0x80) {
4627 + ch |= (*str & 0x3F);
4629 + } while (trail > 0);
4637 - *chPtr = (Tcl_UniChar) byte;
4639 + *chPtr = (Tcl_UniChar) byte;
4643 /********************************************************************/
4644 /* font cache functions */
4647 -fontTest (void *element, void *key)
4648 +static int fontTest (void *element, void *key)
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;
4655 - return (strcmp (a->fontlist, b->fontlist) == 0);
4656 + return (strcmp (a->fontlist, b->fontlist) == 0);
4659 static void *fontFetch (char **error, void *key)
4661 fontsearchpath = getenv ("GDFONTPATH");
4662 if (!fontsearchpath) {
4663 fontsearchpath = DEFAULT_FONTPATH;
4666 fontlist = gdEstrdup(a->fontlist);
4669 @@ -399,8 +376,12 @@
4670 /* make a fresh copy each time - strtok corrupts it. */
4671 path = gdEstrdup (fontsearchpath);
4673 - /* if name is an absolute filename then test directly */
4674 + /* if name is an absolute filename then test directly */
4676 + if (*name == '/' || (name[0] != 0 && strstr(name, ":/"))) {
4678 if (*name == '/' || (name[0] != 0 && name[1] == ':' && (name[2] == '/' || name[2] == '\\'))) {
4680 snprintf(fullname, sizeof(fullname) - 1, "%s", name);
4681 if (access(fullname, R_OK) == 0) {
4683 @@ -437,15 +418,15 @@
4701 gdPFree(a->fontlist);
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).
4708 -tweenColorFetch (char **error, void *key)
4709 +static void * tweenColorFetch (char **error, void *key)
4712 - tweencolorkey_t *b = (tweencolorkey_t *) key;
4713 - int pixel, npixel, bg, fg;
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;
4722 - /* if fg is specified by a negative color idx, then don't antialias */
4725 - if ((pixel + pixel) >= NUMCOLORS)
4726 - a->tweencolor = -fg;
4728 - a->tweencolor = bg;
4732 - npixel = NUMCOLORS - pixel;
4733 - if (im->trueColor)
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));
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);
4754 - return (void *) a;
4756 + tweencolorkey_t *b = (tweencolorkey_t *) key;
4757 + int pixel, npixel, bg, fg;
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;
4766 + /* if fg is specified by a negative color idx, then don't antialias */
4768 + if ((pixel + pixel) >= NUMCOLORS) {
4769 + a->tweencolor = -fg;
4771 + a->tweencolor = bg;
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.
4782 + a->tweencolor = gdTrueColorAlpha(
4783 + gdTrueColorGetRed(fg),
4784 + gdTrueColorGetGreen(fg),
4785 + gdTrueColorGetBlue(fg),
4786 + gdAlphaMax - (gdTrueColorGetAlpha (fg) * pixel / NUMCOLORS));
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);
4794 + return (void *) a;
4798 -tweenColorRelease (void *element)
4799 +static void tweenColorRelease (void *element)
4801 - gdFree ((char *) element);
4802 + gdFree((char *) element);
4805 /* draw_bitmap - transfers glyph bitmap to GD image */
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)
4810 - unsigned char *pixel = NULL;
4811 - int *tpixel = NULL;
4812 - int x, y, row, col, pc, pcr;
4814 - tweencolor_t *tc_elem;
4815 - tweencolorkey_t tc_key;
4817 - /* copy to image, mapping colors */
4818 - tc_key.fgcolor = fg;
4820 - /* Truecolor version; does not require the cache */
4821 - if (im->trueColor)
4823 - for (row = 0; row < bitmap.rows; row++)
4825 - pc = row * bitmap.pitch;
4828 - /* clip if out of bounds */
4829 - /* 2.0.16: clipping rectangle, not image bounds */
4830 - if ((y > im->cy2) || (y < im->cy1))
4832 - for (col = 0; col < bitmap.width; col++, pc++)
4835 - if (bitmap.pixel_mode == ft_pixel_mode_grays)
4838 - * Scale to 128 levels of alpha for gd use.
4839 - * alpha 0 is opacity, so be sure to invert at the end
4841 - level = (bitmap.buffer[pc] * gdAlphaMax /
4842 - (bitmap.num_grays - 1));
4844 - else if (bitmap.pixel_mode == ft_pixel_mode_mono)
4846 - /* 2.0.5: mode_mono fix from Giuliano Pochini */
4847 - level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07)))
4848 - ? gdAlphaTransparent :
4853 - return "Unsupported ft_pixel_mode";
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
4860 - level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax;
4862 - level = gdAlphaMax - level;
4864 - /* clip if out of bounds */
4865 - /* 2.0.16: clip to clipping rectangle, Matt McNabb */
4866 - if ((x > im->cx2) || (x < im->cx1))
4868 - /* get pixel location in gd buffer */
4869 - tpixel = &im->tpixels[y][x];
4871 - if (level < (gdAlphaMax / 2)) {
4875 - if (im->alphaBlendingFlag) {
4876 - *tpixel = gdAlphaBlend(*tpixel, (level << 24) + (fg & 0xFFFFFF));
4878 - *tpixel = (level << 24) + (fg & 0xFFFFFF);
4883 - return (char *) NULL;
4885 - /* Non-truecolor case, restored to its more or less original form */
4886 - for (row = 0; row < bitmap.rows; row++)
4889 - pc = row * bitmap.pitch;
4891 - if(bitmap.pixel_mode==ft_pixel_mode_mono)
4892 - pc *= 8; /* pc is measured in bits for monochrome images */
4896 - /* clip if out of bounds */
4897 - if (y >= im->sy || y < 0)
4900 - for (col = 0; col < bitmap.width; col++, pc++)
4902 - if (bitmap.pixel_mode == ft_pixel_mode_grays)
4905 - * Round to NUMCOLORS levels of antialiasing for
4906 - * index color images since only 256 colors are
4909 - tc_key.pixel = ((bitmap.buffer[pc] * NUMCOLORS)
4910 - + bitmap.num_grays / 2)
4911 - / (bitmap.num_grays - 1);
4913 - else if (bitmap.pixel_mode == ft_pixel_mode_mono)
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)))
4923 - return "Unsupported ft_pixel_mode";
4925 - if (tc_key.pixel > 0) /* if not background */
4929 - /* clip if out of bounds */
4930 - if (x >= im->sx || x < 0)
4932 - /* get pixel location in gd buffer */
4933 - pixel = &im->pixels[y][x];
4934 - if (tc_key.pixel == NUMCOLORS)
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;
4942 - /* find antialised color */
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;
4953 + tweencolor_t *tc_elem;
4954 + tweencolorkey_t tc_key;
4956 + /* copy to image, mapping colors */
4957 + tc_key.fgcolor = fg;
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;
4965 + /* clip if out of bounds */
4966 + /* 2.0.16: clipping rectangle, not image bounds */
4967 + if ((y > im->cy2) || (y < im->cy1)) {
4970 + for (col = 0; col < bitmap.width; col++, pc++) {
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
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;
4981 + return "Unsupported ft_pixel_mode";
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
4989 + level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax;
4991 + level = gdAlphaMax - level;
4993 + /* clip if out of bounds */
4994 + /* 2.0.16: clip to clipping rectangle, Matt McNabb */
4995 + if ((x > im->cx2) || (x < im->cx1)) {
4998 + /* get pixel location in gd buffer */
4999 + tpixel = &im->tpixels[y][x];
5001 + if (level < (gdAlphaMax / 2)) {
5005 + if (im->alphaBlendingFlag) {
5006 + *tpixel = gdAlphaBlend(*tpixel, (level << 24) + (fg & 0xFFFFFF));
5008 + *tpixel = (level << 24) + (fg & 0xFFFFFF);
5013 + return (char *) NULL;
5015 + /* Non-truecolor case, restored to its more or less original form */
5016 + for (row = 0; row < bitmap.rows; row++) {
5018 + pc = row * bitmap.pitch;
5020 + if (bitmap.pixel_mode==ft_pixel_mode_mono) {
5021 + pc *= 8; /* pc is measured in bits for monochrome images */
5025 + /* clip if out of bounds */
5026 + if (y >= im->sy || y < 0) {
5030 + for (col = 0; col < bitmap.width; col++, pc++) {
5031 + if (bitmap.pixel_mode == ft_pixel_mode_grays) {
5033 + * Round to NUMCOLORS levels of antialiasing for
5034 + * index color images since only 256 colors are
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;
5043 + return "Unsupported ft_pixel_mode";
5045 + if (tc_key.pixel > 0) { /* if not background */
5048 + /* clip if out of bounds */
5049 + if (x >= im->sx || x < 0) {
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).
5058 + *pixel = (fg < 0) ? -fg : fg;
5060 + /* find antialised color */
5061 + tc_key.bgcolor = *pixel;
5062 + tc_elem = (tweencolor_t *) gdCacheGet(tc_cache, &tc_key);
5063 + *pixel = tc_elem->tweencolor;
5070 - return (char *) NULL;
5071 + return (char *) NULL;
5075 gdroundupdown (FT_F26Dot6 v1, int 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);
5083 void gdFontCacheShutdown()
5085 + gdMutexLock(gdFontCacheMutex);
5088 - gdMutexLock(gdFontCacheMutex);
5089 gdCacheDelete(fontCache);
5091 - gdMutexUnlock(gdFontCacheMutex);
5092 - gdMutexShutdown(gdFontCacheMutex);
5093 FT_Done_FreeType(library);
5096 + gdMutexUnlock(gdFontCacheMutex);
5099 void gdFreeFontCache()
5101 gdFontCacheShutdown();
5105 +void gdFontCacheMutexSetup()
5107 + gdMutexSetup(gdFontCacheMutex);
5110 +void gdFontCacheMutexShutdown()
5112 + gdMutexShutdown(gdFontCacheMutex);
5115 int gdFontCacheSetup(void)
5118 /* Already set up */
5121 - gdMutexSetup(gdFontCacheMutex);
5122 if (FT_Init_FreeType(&library)) {
5123 - gdMutexShutdown(gdFontCacheMutex);
5126 fontCache = gdCacheCreate (FONTCACHESIZE, fontTest, fontFetch, fontRelease);
5131 /********************************************************************/
5132 /* gdImageStringFT - render a utf8 string onto a gd image */
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)
5140 return gdImageStringFTEx(im, brect, fg, fontlist, ptsize, angle, x, y, string, 0);
5142 @@ -856,15 +814,16 @@
5144 /***** initialize font library and font cache on first call ******/
5146 + gdMutexLock(gdFontCacheMutex);
5148 if (gdFontCacheSetup() != 0) {
5149 gdCacheDelete(tc_cache);
5150 + gdMutexUnlock(gdFontCacheMutex);
5151 return "Failure to initialize font library";
5156 - gdMutexLock(gdFontCacheMutex);
5158 /* get the font (via font cache) */
5159 fontkey.fontlist = fontlist;
5160 fontkey.library = &library;
5166 /* carriage returns */
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
5176 - /* Convert to the Symbol glyph range only for a Symbol family member */
5177 len = gdTcl_UtfToUniChar (next, &ch);
5180 @@ -1008,7 +969,7 @@
5184 - case gdFTEX_Shift_JIS:
5185 + case gdFTEX_Shift_JIS:
5186 if (font->have_char_map_sjis) {
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);
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
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!
5208 #define GD2_FMT_TRUECOLOR_RAW 3
5209 #define GD2_FMT_TRUECOLOR_COMPRESSED 4
5218 extern int _gdGetColors(gdIOCtx * in, gdImagePtr im, int gd2xFlag);
5219 extern void _gdPutColors(gdImagePtr im, gdIOCtx * out);
5224 - GD2_DBG(php_gd_error("Reading gd2 header info\n"));
5225 + GD2_DBG(php_gd_error("Reading gd2 header info"));
5227 for (i = 0; i < 4; i++) {
5233 - GD2_DBG(php_gd_error("Got file code: %s\n", id));
5234 + GD2_DBG(php_gd_error("Got file code: %s", id));
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"));
5244 if (gdGetWord(vers, in) != 1) {
5247 - GD2_DBG(php_gd_error("Version: %d\n", *vers));
5248 + GD2_DBG(php_gd_error("Version: %d", *vers));
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));
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"));
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"));
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));
5270 /* Chunk Size (pixels, not bytes!) */
5271 if (gdGetWord(cs, in) != 1) {
5274 - GD2_DBG(php_gd_error("ChunkSize: %d\n", *cs));
5275 + GD2_DBG(php_gd_error("ChunkSize: %d", *cs));
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));
5283 @@ -117,10 +116,10 @@
5284 if (gdGetWord(fmt, in) != 1) {
5287 - GD2_DBG(php_gd_error("Format: %d\n", *fmt));
5288 + GD2_DBG(php_gd_error("Format: %d", *fmt));
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));
5296 @@ -128,17 +127,17 @@
5297 if (gdGetWord(ncx, in) != 1) {
5300 - GD2_DBG(php_gd_error("%d Chunks Wide\n", *ncx));
5301 + GD2_DBG(php_gd_error("%d Chunks Wide", *ncx));
5303 /* # of chunks high */
5304 if (gdGetWord(ncy, in) != 1) {
5307 - GD2_DBG(php_gd_error("%d Chunks vertically\n", *ncy));
5308 + GD2_DBG(php_gd_error("%d Chunks vertically", *ncy));
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;
5321 - GD2_DBG(php_gd_error("gd2 header complete\n"));
5322 + GD2_DBG(php_gd_error("gd2 header complete"));
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"));
5335 @@ -178,15 +177,15 @@
5336 im = gdImageCreate(*sx, *sy);
5339 - GD2_DBG(php_gd_error("Could not create gdImage\n"));
5340 + GD2_DBG(php_gd_error("Could not create gdImage"));
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"));
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));
5354 @@ -203,25 +202,25 @@
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));
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));
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) {
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);
5376 - GD2_DBG(php_gd_error("Error %d from uncompress\n", zerr));
5377 + GD2_DBG(php_gd_error("Error %d from uncompress", zerr));
5380 - GD2_DBG(php_gd_error("Got chunk\n"));
5382 + GD2_DBG(php_gd_error("Got chunk"));
5389 chunkBuf = gdCalloc(chunkMax, 1);
5390 compBuf = gdCalloc(compMax, 1);
5392 - GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes\n", compMax));
5394 + GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes", compMax));
5397 /* Read the data... */
5398 @@ -304,13 +303,13 @@
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));
5405 if (gd2_compressed(fmt)) {
5406 chunkLen = chunkMax;
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"));
5418 - GD2_DBG(php_gd_error("Freeing memory\n"));
5419 + GD2_DBG(php_gd_error("Freeing memory"));
5427 - GD2_DBG(php_gd_error("Done\n"));
5428 + GD2_DBG(php_gd_error("Done"));
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)
5440 gdIOCtx *in = gdNewFileCtx(inFile);
5441 @@ -431,6 +430,10 @@
5445 + if (w<1 || h <1) {
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.
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));
5459 /* This is the difference - make a file based on size of chunks. */
5460 if (gd2_truecolor(fmt)) {
5462 if (!_gdGetColors(in, im, vers == 2)) {
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));
5468 /* Process the header info */
5471 if (chunkMax <= 0) {
5476 chunkBuf = gdCalloc(chunkMax, 1);
5477 compBuf = gdCalloc(compMax, 1);
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));
5486 /* Loop through the chunks. */
5487 for (cy = scy; (cy <= ecy); cy++) {
5488 @@ -521,10 +524,10 @@
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));
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;
5501 @@ -533,29 +536,29 @@
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);
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));
5512 chunkNum = cx + cy * ncx;
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");
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));
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));
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)) {
5538 @@ -577,11 +580,11 @@
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;
5546 im->pixels[y - srcy][x - srcx] = ch;
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;
5569 if (im->trueColor) {
5570 @@ -693,16 +696,16 @@
5571 chunkData = safe_emalloc(cs * bytesPerPixel, cs, 0);
5572 memset(chunkData, 0, cs * bytesPerPixel * cs);
5577 compData = gdCalloc(compMax, 1);
5579 /* Save the file position of chunk index, and allocate enough space for
5580 - * each chunk_info block .
5581 + * each chunk_info block .
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);
5589 chunkIdx = safe_emalloc(idxSize, sizeof(t_chunk_info), 0);
5592 _gdPutColors (im, out);
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));
5599 for (cy = 0; (cy < ncy); cy++) {
5600 for (cx = 0; (cx < ncx); cx++) {
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));
5608 for (y = ylo; (y < yhi); y++) {
5609 GD2_DBG(php_gd_error("y=%d: ",y));
5613 for (x = xlo; x < xhi; x++) {
5614 - GD2_DBG(php_gd_error("%d, ",x));
5615 + GD2_DBG(php_gd_error("%d, ",x));
5617 if (im->trueColor) {
5618 gdPutInt(im->tpixels[y][x], out);
5619 @@ -756,21 +759,21 @@
5623 - GD2_DBG(php_gd_error("y=%d done.\n",y));
5624 + GD2_DBG(php_gd_error("y=%d done.",y));
5627 if (gd2_compressed(fmt)) {
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");
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));
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);
5645 @@ -779,29 +782,29 @@
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);
5661 gdSeek(out, posSave);
5664 - GD2_DBG(php_gd_error("Freeing memory\n"));
5665 + GD2_DBG(php_gd_error("Freeing memory"));
5676 - GD2_DBG(php_gd_error("Done\n"));
5677 + GD2_DBG(php_gd_error("Done"));
5680 void gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt)
5682 gdIOCtx *out = gdNewFileCtx(outFile);
5684 _gdImageGd2(im, out, cs, fmt);
5691 _gdImageGd2(im, out, cs, fmt);
5692 rv = gdDPExtractData(out, size);
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
5709 GD2_DBG(printf("Pallette had %d colours (T=%d)\n", im->colorsTotal, im->transparent));
5712 if (im->trueColor) {
5717 im = gdImageCreate(*sx, *sy);
5722 if (!_gdGetColors(in, im, gd2xFlag)) {
5727 static void _gdPutHeader (gdImagePtr im, gdIOCtx * out)
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.
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
5739 static int set_verbose(void)
5741 - verbose = !!getenv("GIF_VERBOSE");
5744 + verbose = !!getenv("GIF_VERBOSE");
5750 @@ -44,270 +44,313 @@
5751 #define LOCALCOLORMAP 0x80
5752 #define BitSet(byte, bit) (((byte) & (bit)) == (bit))
5754 -#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) != 0)
5755 +#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) > 0)
5757 #define LM_to_uint(a,b) (((b)<<8)|(a))
5759 /* We may eventually want to use this information, but def it out for now */
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;
5789 } Gif89 = { -1, -1, -1, 0 };
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)
5799 -static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace); /*1.4//, int ignore); */
5801 + unsigned char buf[280];
5802 + int curbit, lastbit, done, last_byte;
5803 +} CODE_STATIC_DATA;
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;
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);
5823 +static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace, int *ZeroDataBlockP); /*1.4//, int ignore); */
5825 -gdImagePtr gdImageCreateFromGifSource(gdSourcePtr inSource)
5826 +gdImagePtr gdImageCreateFromGifSource(gdSourcePtr inSource) /* {{{ */
5828 - gdIOCtx *in = gdNewSSCtx(inSource, NULL);
5830 + gdIOCtx *in = gdNewSSCtx(inSource, NULL);
5833 - im = gdImageCreateFromGifCtx(in);
5834 + im = gdImageCreateFromGifCtx(in);
5845 -gdImageCreateFromGif(FILE *fdFile)
5846 +gdImagePtr gdImageCreateFromGif(FILE *fdFile) /* {{{ */
5848 - gdIOCtx *fd = gdNewFileCtx(fdFile);
5849 - gdImagePtr im = 0;
5850 + gdIOCtx *fd = gdNewFileCtx(fdFile);
5851 + gdImagePtr im = 0;
5853 - im = gdImageCreateFromGifCtx(fd);
5854 + im = gdImageCreateFromGifCtx(fd);
5865 -gdImageCreateFromGifCtx(gdIOCtxPtr fd)
5866 +gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */
5868 -/* 1.4 int imageNumber; */
5870 - int ColorResolution;
5873 - int Transparent = (-1);
5874 - unsigned char buf[16];
5876 - unsigned char ColorMap[3][MAXCOLORMAPSIZE];
5877 - unsigned char localColorMap[3][MAXCOLORMAPSIZE];
5879 - int useGlobalColormap;
5882 - /*1.4//int imageCount = 0; */
5885 - gdImagePtr im = 0;
5886 - ZeroDataBlock = FALSE;
5889 + int ColorResolution;
5893 + int Transparent = (-1);
5894 + unsigned char buf[16];
5896 + unsigned char ColorMap[3][MAXCOLORMAPSIZE];
5897 + unsigned char localColorMap[3][MAXCOLORMAPSIZE];
5898 + int imw, imh, screen_width, screen_height;
5899 + int gif87a, useGlobalColormap;
5902 + /*1.4//int imageCount = 0; */
5904 + int ZeroDataBlock = FALSE;
5905 + int haveGlobalColormap;
5906 + gdImagePtr im = 0;
5908 - /*1.4//imageNumber = 1; */
5909 - if (! ReadOK(fd,buf,6)) {
5910 + /*1.4//imageNumber = 1; */
5911 + if (! ReadOK(fd,buf,6)) {
5914 - if (strncmp((char *)buf,"GIF",3) != 0) {
5915 + if (strncmp((char *)buf,"GIF",3) != 0) {
5918 - strncpy(version, (char *)buf + 3, 3);
5919 - version[3] = '\0';
5921 - if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) {
5922 + if (memcmp((char *)buf+3, "87a", 3) == 0) {
5924 + } else if (memcmp((char *)buf+3, "89a", 3) == 0) {
5929 - if (! ReadOK(fd,buf,7)) {
5931 + if (! ReadOK(fd,buf,7)) {
5934 - BitPixel = 2<<(buf[4]&0x07);
5935 - ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
5936 - Background = buf[5];
5937 - AspectRatio = buf[6];
5939 - imw = LM_to_uint(buf[0],buf[1]);
5940 - imh = LM_to_uint(buf[2],buf[3]);
5941 + BitPixel = 2<<(buf[4]&0x07);
5943 + ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
5944 + Background = buf[5];
5945 + AspectRatio = buf[6];
5947 + screen_width = imw = LM_to_uint(buf[0],buf[1]);
5948 + screen_height = imh = LM_to_uint(buf[2],buf[3]);
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)) {
5959 - if (! ReadOK(fd,&c,1)) {
5962 - if (c == ';') { /* GIF terminator */
5967 + int width, height;
5969 + if (! ReadOK(fd,&c,1)) {
5972 + if (c == ';') { /* GIF terminator */
5977 + if (c == '!') { /* Extension */
5978 + if (! ReadOK(fd,&c,1)) {
5981 + DoExtension(fd, c, &Transparent, &ZeroDataBlock);
5985 - if (c == '!') { /* Extension */
5986 - if (! ReadOK(fd,&c,1)) {
5989 - DoExtension(fd, c, &Transparent);
5993 - if (c != ',') { /* Not a valid start character */
5997 - /*1.4//++imageCount; */
5999 - if (! ReadOK(fd,buf,9)) {
6003 - useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
6005 - bitPixel = 1<<((buf[8]&0x07)+1);
6007 - if (!useGlobalColormap) {
6008 - if (ReadColorMap(fd, bitPixel, localColorMap)) {
6013 - if (!(im = gdImageCreate(imw, imh))) {
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); */
6022 - ReadImage(im, fd, imw, imh,
6024 - BitSet(buf[8], INTERLACE));
6025 - /*1.4//imageCount != imageNumber); */
6027 - if (Transparent != (-1)) {
6028 - gdImageColorTransparent(im, Transparent);
6032 + if (c != ',') { /* Not a valid start character */
6037 - /* Terminator before any image was declared! */
6041 + /*1.4//++imageCount; */
6043 - if (!im->colorsTotal) {
6044 - gdImageDestroy(im);
6045 + if (! ReadOK(fd,buf,9)) {
6049 - /* Check for open colors at the end, so
6050 - we can reduce colorsTotal and ultimately
6052 - for (i=((im->colorsTotal-1)); (i>=0); i--) {
6053 + useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
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]);
6061 + if (left + width > screen_width || top + height > screen_height) {
6063 + printf("Frame is not confined to screen dimension.\n");
6068 + if (!(im = gdImageCreate(width, height))) {
6071 + im->interlace = BitSet(buf[8], INTERLACE);
6072 + if (!useGlobalColormap) {
6073 + if (ReadColorMap(fd, bitPixel, localColorMap)) {
6074 + gdImageDestroy(im);
6077 + ReadImage(im, fd, width, height, localColorMap,
6078 + BitSet(buf[8], INTERLACE), &ZeroDataBlock);
6080 + if (!haveGlobalColormap) {
6081 + gdImageDestroy(im);
6084 + ReadImage(im, fd, width, height,
6086 + BitSet(buf[8], INTERLACE), &ZeroDataBlock);
6088 + if (Transparent != (-1)) {
6089 + gdImageColorTransparent(im, Transparent);
6095 + /* Terminator before any image was declared! */
6099 + if (!im->colorsTotal) {
6100 + gdImageDestroy(im);
6103 + /* Check for open colors at the end, so
6104 + we can reduce colorsTotal and ultimately
6106 + for (i=((im->colorsTotal-1)); (i>=0); i--) {
6108 - im->colorsTotal--;
6114 + im->colorsTotal--;
6124 -ReadColorMap(gdIOCtx *fd, int number, unsigned char (*buffer)[256])
6125 +static int ReadColorMap(gdIOCtx *fd, int number, unsigned char (*buffer)[256]) /* {{{ */
6128 - unsigned char rgb[3];
6130 + unsigned char rgb[3];
6133 - for (i = 0; i < number; ++i) {
6134 - if (! ReadOK(fd, rgb, sizeof(rgb))) {
6137 - buffer[CM_RED][i] = rgb[0] ;
6138 - buffer[CM_GREEN][i] = rgb[1] ;
6139 - buffer[CM_BLUE][i] = rgb[2] ;
6141 + for (i = 0; i < number; ++i) {
6142 + if (! ReadOK(fd, rgb, sizeof(rgb))) {
6145 + buffer[CM_RED][i] = rgb[0] ;
6146 + buffer[CM_GREEN][i] = rgb[1] ;
6147 + buffer[CM_BLUE][i] = rgb[2] ;
6157 -DoExtension(gdIOCtx *fd, int label, int *Transparent)
6158 +DoExtension(gdIOCtx *fd, int label, int *Transparent, int *ZeroDataBlockP)
6160 - static unsigned char buf[256];
6161 + unsigned char buf[256];
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);
6168 + Gif89.disposal = (buf[0] >> 2) & 0x7;
6169 + Gif89.inputFlag = (buf[0] >> 1) & 0x1;
6170 + Gif89.delayTime = LM_to_uint(buf[1],buf[2]);
6172 + if ((buf[0] & 0x1) != 0)
6173 + *Transparent = buf[3];
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];
6184 - while (GetDataBlock(fd, (unsigned char*) buf) > 0)
6190 - while (GetDataBlock(fd, (unsigned char*) buf) > 0)
6192 + while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0);
6197 + while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0)
6206 -GetDataBlock_(gdIOCtx *fd, unsigned char *buf)
6207 +GetDataBlock_(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP)
6209 - unsigned char count;
6210 + unsigned char count;
6212 - if (! ReadOK(fd,&count,1)) {
6215 + if (! ReadOK(fd,&count,1)) {
6219 - ZeroDataBlock = count == 0;
6220 + *ZeroDataBlockP = count == 0;
6222 - if ((count != 0) && (! ReadOK(fd, buf, count))) {
6225 + if ((count != 0) && (! ReadOK(fd, buf, count))) {
6235 -GetDataBlock(gdIOCtx *fd, unsigned char *buf)
6236 +GetDataBlock(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP)
6242 - rv = GetDataBlock_(fd,buf);
6244 + rv = GetDataBlock_(fd,buf, ZeroDataBlockP);
6248 tmp = safe_emalloc(3 * rv, sizeof(char), 1);
6249 for (i=0;i<rv;i++) {
6250 @@ -321,281 +364,275 @@
6257 -GetCode_(gdIOCtx *fd, int code_size, int flag)
6258 +GetCode_(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP)
6260 - static unsigned char buf[280];
6261 - static int curbit, lastbit, done, last_byte;
6263 - unsigned char count;
6272 - if ( (curbit+code_size) >= lastbit) {
6274 - if (curbit >= lastbit) {
6279 - buf[0] = buf[last_byte-2];
6280 - buf[1] = buf[last_byte-1];
6282 - if ((count = GetDataBlock(fd, &buf[2])) <= 0)
6285 - last_byte = 2 + count;
6286 - curbit = (curbit - lastbit) + 16;
6287 - lastbit = (2+count)*8 ;
6291 - for (i = curbit, j = 0; j < code_size; ++i, ++j)
6292 - ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
6294 + unsigned char count;
6299 + scd->last_byte = 0;
6300 + scd->done = FALSE;
6304 + if ( (scd->curbit + code_size) >= scd->lastbit) {
6306 + if (scd->curbit >= scd->lastbit) {
6311 + scd->buf[0] = scd->buf[scd->last_byte-2];
6312 + scd->buf[1] = scd->buf[scd->last_byte-1];
6314 + if ((count = GetDataBlock(fd, &scd->buf[2], ZeroDataBlockP)) <= 0)
6317 + scd->last_byte = 2 + count;
6318 + scd->curbit = (scd->curbit - scd->lastbit) + 16;
6319 + scd->lastbit = (2+count)*8 ;
6322 - curbit += code_size;
6325 + for (i = scd->curbit, j = 0; j < code_size; ++i, ++j)
6326 + ret |= ((scd->buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
6328 + scd->curbit += code_size;
6333 -GetCode(gdIOCtx *fd, int code_size, int flag)
6334 +GetCode(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP)
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);
6342 + rv = GetCode_(fd, scd, code_size,flag, ZeroDataBlockP);
6343 + if (VERBOSE) printf("[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
6348 -#define STACK_SIZE ((1<<(MAX_LWZ_BITS))*2)
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)
6353 - static int fresh = FALSE;
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;
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;
6371 - GetCode(fd, 0, TRUE);
6375 - for (i = 0; i < clear_code; ++i) {
6379 - for (; i < (1<<MAX_LWZ_BITS); ++i)
6380 - table[0][i] = table[1][0] = 0;
6385 - } else if (fresh) {
6388 - firstcode = oldcode =
6389 - GetCode(fd, code_size, FALSE);
6390 - } while (firstcode == clear_code);
6397 - while ((code = GetCode(fd, code_size, FALSE)) >= 0) {
6398 - if (code == clear_code) {
6399 - for (i = 0; i < clear_code; ++i) {
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;
6409 - firstcode = oldcode =
6410 - GetCode(fd, code_size, FALSE);
6412 - } else if (code == end_code) {
6414 - unsigned char buf[260];
6416 - if (ZeroDataBlock)
6419 - while ((count = GetDataBlock(fd, buf)) > 0)
6428 - if (sp == (stack + STACK_SIZE)) {
6429 - /* Bad compressed data stream */
6433 - if (code >= max_code) {
6434 - *sp++ = firstcode;
6438 - while (code >= clear_code) {
6439 - if (sp == (stack + STACK_SIZE)) {
6440 - /* Bad compressed data stream */
6443 - *sp++ = table[1][code];
6444 - if (code == table[0][code]) {
6447 - code = table[0][code];
6450 - *sp++ = firstcode = table[1][code];
6452 - if ((code = max_code) <(1<<MAX_LWZ_BITS)) {
6453 - table[0][code] = oldcode;
6454 - table[1][code] = firstcode;
6456 - if ((max_code >= max_code_size) &&
6457 - (max_code_size < (1<<MAX_LWZ_BITS))) {
6458 - max_code_size *= 2;
6469 + int code, incode, i;
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;
6479 + GetCode(fd, &sd->scd, 0, TRUE, ZeroDataBlockP);
6483 + for (i = 0; i < sd->clear_code; ++i) {
6484 + sd->table[0][i] = 0;
6485 + sd->table[1][i] = i;
6487 + for (; i < (1<<MAX_LWZ_BITS); ++i)
6488 + sd->table[0][i] = sd->table[1][0] = 0;
6490 + sd->sp = sd->stack;
6493 + } else if (sd->fresh) {
6494 + sd->fresh = FALSE;
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;
6502 + if (sd->sp > sd->stack)
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;
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) {
6522 + unsigned char buf[260];
6524 + if (*ZeroDataBlockP)
6527 + while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0)
6536 + if (sd->sp == (sd->stack + STACK_SIZE)) {
6537 + /* Bad compressed data stream */
6541 + if (code >= sd->max_code) {
6542 + *sd->sp++ = sd->firstcode;
6543 + code = sd->oldcode;
6546 + while (code >= sd->clear_code) {
6547 + if (sd->sp == (sd->stack + STACK_SIZE)) {
6548 + /* Bad compressed data stream */
6551 + *sd->sp++ = sd->table[1][code];
6552 + if (code == sd->table[0][code]) {
6555 + code = sd->table[0][code];
6558 + *sd->sp++ = sd->firstcode = sd->table[1][code];
6560 + if ((code = sd->max_code) <(1<<MAX_LWZ_BITS)) {
6561 + sd->table[0][code] = sd->oldcode;
6562 + sd->table[1][code] = sd->firstcode;
6564 + if ((sd->max_code >= sd->max_code_size) &&
6565 + (sd->max_code_size < (1<<MAX_LWZ_BITS))) {
6566 + sd->max_code_size *= 2;
6571 + sd->oldcode = incode;
6573 + if (sd->sp > sd->stack)
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)
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);
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);
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) */
6602 - int xpos = 0, ypos = 0, pass = 0;
6606 - ** Initialize the Compression routines
6608 - if (! ReadOK(fd,&c,1)) {
6612 - if (c > MAX_LWZ_BITS) {
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];
6624 - /* Many (perhaps most) of these colors will remain marked open. */
6625 - im->colorsTotal = gdMaxColors;
6627 - if (LWZReadByte(fd, TRUE, c) < 0) {
6632 - ** If this is an "uninteresting picture" ignore it.
6633 - ** REMOVED For 1.4
6635 - /*if (ignore) { */
6636 - /* while (LWZReadByte(fd, FALSE, c) >= 0) */
6641 - while ((v = LWZReadByte(fd,FALSE,c)) >= 0 ) {
6642 - if (v >= gdMaxColors) {
6646 + int xpos = 0, ypos = 0, pass = 0;
6648 + LZW_STATIC_DATA sd;
6652 + ** Initialize the Compression routines
6654 + if (! ReadOK(fd,&c,1)) {
6658 + if (c > MAX_LWZ_BITS) {
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];
6669 + /* Many (perhaps most) of these colors will remain marked open. */
6670 + im->colorsTotal = gdMaxColors;
6671 + if (LWZReadByte(fd, &sd, TRUE, c, ZeroDataBlockP) < 0) {
6676 + ** If this is an "uninteresting picture" ignore it.
6677 + ** REMOVED For 1.4
6679 + /*if (ignore) { */
6680 + /* while (LWZReadByte(fd, &sd, FALSE, c) >= 0) */
6685 + while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0) {
6686 + if (v >= gdMaxColors) {
6689 + /* This how we recognize which colors are actually used. */
6690 + if (im->open[v]) {
6693 + gdImageSetPixel(im, xpos, ypos, v);
6695 + if (xpos == len) {
6707 - /* This how we recognize which colors are actually used. */
6708 - if (im->open[v]) {
6711 - gdImageSetPixel(im, xpos, ypos, v);
6713 - if (xpos == len) {
6726 - if (ypos >= height) {
6743 - if (ypos >= height)
6747 + if (ypos >= height) {
6764 + if (ypos >= height)
6769 - if (LWZReadByte(fd,FALSE,c)>=0) {
6770 - /* Ignore extra */
6772 + if (LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP) >=0) {
6773 + /* Ignore extra */
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
6782 BitsPerPixel = colorstobpp(tim->colorsTotal);
6783 /* All set, let's do it. */
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);
6789 /* Destroy palette based temporary image. */
6790 @@ -264,10 +264,12 @@
6797 + memset(&ctx, 0, sizeof(ctx));
6798 ctx.Interlace = GInterlace;
6800 - memset(&ctx, 0, sizeof(ctx));
6803 ColorMapSize = 1 << BitsPerPixel;
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
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 ":"
6818 +#ifdef HAVE_CONFIG_H
6819 +#include "config.h"
6822 +#include "php_compat.h"
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"
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 ";"
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 ":"
6844 /* gd.h: declarations file for the graphic-draw module.
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);
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);
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
6865 +void gdFontCacheMutexSetup();
6866 +void gdFontCacheMutexShutdown();
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
6872 * compression (smallest files) but takes a long time to compress, and
6873 * -1 selects the default compiled into the zlib library.
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);
6880 void gdImageWBMP(gdImagePtr image, int fg, FILE *out);
6881 void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out);
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);
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);
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);
6906 void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
6907 void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
6909 int gdImageContrast(gdImagePtr src, double contrast);
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);
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
6921 -#ifndef GDHELPERS_H
6922 +#ifndef GDHELPERS_H
6923 #define GDHELPERS_H 1
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 @@
6933 +#define GD_IO_EOF_CHK(r) \
6939 * Write out a word to the I/O context pointer
6942 -Putword (int w, gdIOCtx * ctx)
6943 +void Putword (int w, gdIOCtx * ctx)
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];
6951 + buf[0] = w & 0xff;
6952 + buf[1] = (w / 256) & 0xff;
6953 + (ctx->putBuf) (ctx, (char *) buf, 2);
6957 -Putchar (int c, gdIOCtx * ctx)
6958 +void Putchar (int c, gdIOCtx * ctx)
6960 - (ctx->putC) (ctx, c & 0xff);
6961 + (ctx->putC) (ctx, c & 0xff);
6965 -gdPutC (const unsigned char c, gdIOCtx * ctx)
6966 +void gdPutC (const unsigned char c, gdIOCtx * ctx)
6968 - (ctx->putC) (ctx, c);
6969 + (ctx->putC) (ctx, c);
6973 -gdPutWord (int w, gdIOCtx * ctx)
6974 +void gdPutWord (int w, gdIOCtx * ctx)
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."));
6987 -gdPutInt (int w, gdIOCtx * ctx)
6988 +void gdPutInt (int w, gdIOCtx * ctx)
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."));
7005 -gdGetC (gdIOCtx * ctx)
7006 +int gdGetC (gdIOCtx * ctx)
7008 - return ((ctx->getC) (ctx));
7009 + return ((ctx->getC) (ctx));
7015 -gdGetByte (int *result, gdIOCtx * ctx)
7016 +int gdGetByte (int *result, gdIOCtx * ctx)
7019 - r = (ctx->getC) (ctx);
7027 + r = (ctx->getC) (ctx);
7034 -gdGetWord (int *result, gdIOCtx * ctx)
7035 +int gdGetWord (int *result, gdIOCtx * ctx)
7038 - r = (ctx->getC) (ctx);
7044 - r = (ctx->getC) (ctx);
7052 + r = (ctx->getC) (ctx);
7055 + r = (ctx->getC) (ctx);
7063 -gdGetInt (int *result, gdIOCtx * ctx)
7064 +int gdGetInt (int *result, gdIOCtx * ctx)
7067 - r = (ctx->getC) (ctx);
7072 - *result = r << 24;
7074 + r = (ctx->getC) (ctx);
7076 + *result = r << 24;
7078 - r = (ctx->getC) (ctx);
7083 - *result += r << 16;
7084 + r = (ctx->getC) (ctx);
7086 + *result += r << 16;
7088 - r = (ctx->getC) (ctx);
7093 - *result += r << 8;
7094 + r = (ctx->getC) (ctx);
7098 + *result += r << 8;
7100 - r = (ctx->getC) (ctx);
7106 + r = (ctx->getC) (ctx);
7115 -gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
7116 +int gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
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."));
7127 -gdGetBuf (void *buf, int size, gdIOCtx * ctx)
7128 +int gdGetBuf (void *buf, int size, gdIOCtx * ctx)
7130 - return (ctx->getBuf) (ctx, buf, size);
7131 + return (ctx->getBuf) (ctx, buf, size);
7136 -gdSeek (gdIOCtx * ctx, const int pos)
7137 +int gdSeek (gdIOCtx * ctx, const int pos)
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."));
7148 -gdTell (gdIOCtx * ctx)
7149 +long gdTell (gdIOCtx * ctx)
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."));
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
7163 /* this is used for creating images in main memory */
7164 typedef struct dpStruct
7183 typedef struct dpIOCtx
7194 typedef struct dpIOCtx *dpIOCtxPtr;
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 *);
7203 /* return data as a dynamic pointer */
7205 -gdNewDynamicCtx (int initialSize, void *data)
7206 +gdIOCtx * gdNewDynamicCtx (int initialSize, void *data)
7208 - return gdNewDynamicCtxEx(initialSize, data, 1);
7209 + return gdNewDynamicCtxEx(initialSize, data, 1);
7213 gdIOCtx * gdNewDynamicCtxEx (int initialSize, void *data, int freeOKFlag)
7220 - ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx));
7225 + ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx));
7227 - dp = newDynamic (initialSize, data, freeOKFlag);
7233 + dp = newDynamic(initialSize, data, freeOKFlag);
7238 - ctx->ctx.getC = dynamicGetchar;
7239 - ctx->ctx.putC = dynamicPutchar;
7240 + ctx->ctx.getC = dynamicGetchar;
7241 + ctx->ctx.putC = dynamicPutchar;
7243 - ctx->ctx.getBuf = dynamicGetbuf;
7244 - ctx->ctx.putBuf = dynamicPutbuf;
7245 + ctx->ctx.getBuf = dynamicGetbuf;
7246 + ctx->ctx.putBuf = dynamicPutbuf;
7248 - ctx->ctx.seek = dynamicSeek;
7249 - ctx->ctx.tell = dynamicTell;
7250 + ctx->ctx.seek = dynamicSeek;
7251 + ctx->ctx.tell = dynamicTell;
7253 - ctx->ctx.gd_free = gdFreeDynamicCtx;
7254 + ctx->ctx.gd_free = gdFreeDynamicCtx;
7256 - return (gdIOCtx *) ctx;
7257 + return (gdIOCtx *) ctx;
7261 -gdDPExtractData (struct gdIOCtx *ctx, int *size)
7262 +void * gdDPExtractData (struct gdIOCtx *ctx, int *size)
7271 - dctx = (dpIOCtx *) ctx;
7273 + dctx = (dpIOCtx *) ctx;
7276 - /* clean up the data block and return it */
7280 - *size = dp->logicalSize;
7287 - if (dp->data != NULL && dp->freeOK)
7289 - gdFree (dp->data);
7290 + /* clean up the data block and return it */
7291 + if (dp->dataGood) {
7293 + *size = dp->logicalSize;
7298 + if (dp->data != NULL && dp->freeOK) {
7306 - dp->logicalSize = 0;
7309 + dp->logicalSize = 0;
7317 -gdFreeDynamicCtx (struct gdIOCtx *ctx)
7318 +static void gdFreeDynamicCtx (struct gdIOCtx *ctx)
7323 - dctx = (dpIOCtx *) ctx;
7329 + dctx = (dpIOCtx *) ctx;
7333 - dp->logicalSize = 0;
7338 + dp->logicalSize = 0;
7344 -dynamicTell (struct gdIOCtx *ctx)
7345 +static long dynamicTell (struct gdIOCtx *ctx)
7350 - dctx = (dpIOCtx *) ctx;
7351 - return (dctx->dp->pos);
7352 + dctx = (dpIOCtx *) ctx;
7354 + return (dctx->dp->pos);
7358 -dynamicSeek (struct gdIOCtx *ctx, const int pos)
7359 +static int dynamicSeek (struct gdIOCtx *ctx, const int pos)
7368 - dctx = (dpIOCtx *) ctx;
7370 + dctx = (dpIOCtx *) ctx;
7373 - if (!dp->dataGood)
7375 + if (!dp->dataGood) {
7379 - bytesNeeded = pos;
7380 - if (bytesNeeded > dp->realSize)
7383 - if (!dp->freeOK) {
7386 - if (!gdReallocDynamic (dp, dp->realSize * 2))
7388 - dp->dataGood = FALSE;
7390 + bytesNeeded = pos;
7391 + if (bytesNeeded > dp->realSize) {
7393 + if (!dp->freeOK) {
7396 + gdReallocDynamic (dp, dp->realSize * 2);
7400 - /* if we get here, we can be sure that we have enough bytes
7402 + /* if we get here, we can be sure that we have enough bytes to copy safely */
7404 - /* Extend the logical size if we seek beyond EOF. */
7405 - if (pos > dp->logicalSize)
7407 - dp->logicalSize = pos;
7409 + /* Extend the logical size if we seek beyond EOF. */
7410 + if (pos > dp->logicalSize) {
7411 + dp->logicalSize = pos;
7421 /* return data as a dynamic pointer */
7422 static dynamicPtr * newDynamic (int initialSize, void *data, int freeOKFlag)
7425 - dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr));
7431 + dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr));
7433 - if (!allocDynamic (dp, initialSize, data))
7435 + allocDynamic (dp, initialSize, data);
7438 - dp->freeOK = freeOKFlag;
7440 + dp->freeOK = freeOKFlag;
7447 @@ -246,64 +213,53 @@
7452 -dynamicPutchar (struct gdIOCtx *ctx, int a)
7453 +static void dynamicPutchar (struct gdIOCtx *ctx, int a)
7461 - dctx = (dpIOCtxPtr) ctx;
7463 + dctx = (dpIOCtxPtr) ctx;
7465 - appendDynamic (dctx->dp, &b, 1);
7466 + appendDynamic(dctx->dp, &b, 1);
7470 -dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len)
7471 +static int dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len)
7480 - dctx = (dpIOCtxPtr) ctx;
7482 + dctx = (dpIOCtxPtr) ctx;
7485 - remain = dp->logicalSize - dp->pos;
7486 - if (remain >= len)
7495 + remain = dp->logicalSize - dp->pos;
7496 + if (remain >= len) {
7499 + if (remain == 0) {
7507 - memcpy (buf, (void *) ((char *) dp->data + dp->pos), rlen);
7509 + memcpy(buf, (void *) ((char *) dp->data + dp->pos), rlen);
7517 -dynamicGetchar (gdIOCtxPtr ctx)
7518 +static int dynamicGetchar (gdIOCtxPtr ctx)
7523 - rv = dynamicGetbuf (ctx, &b, 1);
7533 - return b; /* (b & 0xff); */
7535 + rv = dynamicGetbuf (ctx, &b, 1);
7539 + return b; /* (b & 0xff); */
7543 /* *********************************************************************
7544 @@ -316,114 +272,89 @@
7545 allocDynamic (dynamicPtr * dp, int initialSize, void *data)
7550 - dp->logicalSize = 0;
7551 - dp->dataGood = FALSE;
7552 - dp->data = gdMalloc (initialSize);
7556 - dp->logicalSize = initialSize;
7557 - dp->dataGood = TRUE;
7560 + if (data == NULL) {
7561 + dp->logicalSize = 0;
7562 + dp->dataGood = FALSE;
7563 + dp->data = gdMalloc(initialSize);
7565 + dp->logicalSize = initialSize;
7566 + dp->dataGood = TRUE;
7570 - if (dp->data != NULL)
7572 - dp->realSize = initialSize;
7573 - dp->dataGood = TRUE;
7582 + dp->realSize = initialSize;
7583 + dp->dataGood = TRUE;
7589 /* append bytes to the end of a dynamic pointer */
7591 -appendDynamic (dynamicPtr * dp, const void *src, int size)
7592 +static int appendDynamic (dynamicPtr * dp, const void *src, int size)
7599 - if (!dp->dataGood)
7601 + if (!dp->dataGood) {
7605 -/* bytesNeeded = dp->logicalSize + size; */
7606 - bytesNeeded = dp->pos + size;
7607 + /* bytesNeeded = dp->logicalSize + size; */
7608 + bytesNeeded = dp->pos + size;
7610 - if (bytesNeeded > dp->realSize)
7612 + if (bytesNeeded > dp->realSize) {
7617 - if (!gdReallocDynamic (dp, bytesNeeded * 2))
7619 - dp->dataGood = FALSE;
7621 + gdReallocDynamic(dp, bytesNeeded * 2);
7625 - /* if we get here, we can be sure that we have enough bytes
7627 - /*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */
7629 - tmp = (char *) dp->data;
7630 - memcpy ((void *) (tmp + (dp->pos)), src, 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); */
7635 - if (dp->pos > dp->logicalSize)
7637 - dp->logicalSize = dp->pos;
7639 + tmp = (char *) dp->data;
7640 + memcpy((void *) (tmp + (dp->pos)), src, size);
7643 + if (dp->pos > dp->logicalSize) {
7644 + dp->logicalSize = dp->pos;
7651 /* grow (or shrink) dynamic pointer */
7653 -gdReallocDynamic (dynamicPtr * dp, int required)
7654 +static int gdReallocDynamic (dynamicPtr * dp, int required)
7659 - /* First try gdRealloc(). If that doesn't work, make a new
7660 - memory block and copy. */
7661 - if ((newPtr = gdRealloc (dp->data, required)))
7663 - dp->realSize = required;
7664 - dp->data = newPtr;
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;
7674 - /* create a new pointer */
7675 - newPtr = gdMalloc (required);
7678 - dp->dataGood = FALSE;
7681 + /* create a new pointer */
7682 + newPtr = gdMalloc(required);
7684 + /* copy the old data into it */
7685 + memcpy(newPtr, dp->data, dp->logicalSize);
7687 + dp->data = newPtr;
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;
7695 - dp->realSize = required;
7700 /* trim pointer so that its real and logical sizes match */
7702 -trimDynamic (dynamicPtr * dp)
7703 +static int trimDynamic (dynamicPtr * dp)
7705 - /* 2.0.21: we don't reallocate memory we don't own */
7706 - if (!dp->freeOK) {
7709 - return gdReallocDynamic (dp, dp->logicalSize);
7710 + /* 2.0.21: we don't reallocate memory we don't own */
7711 + if (!dp->freeOK) {
7714 + return gdReallocDynamic(dp, dp->logicalSize);
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
7720 /* this is used for creating images in main memory */
7722 typedef struct fileIOCtx
7733 gdIOCtx *newFileCtx (FILE * f);
7736 static void gdFreeFileCtx (gdIOCtx * ctx);
7738 /* return data as a dynamic pointer */
7740 -gdNewFileCtx (FILE * f)
7741 +gdIOCtx * gdNewFileCtx (FILE * f)
7746 - ctx = (fileIOCtx *) gdMalloc (sizeof (fileIOCtx));
7751 + ctx = (fileIOCtx *) gdMalloc(sizeof (fileIOCtx));
7756 - ctx->ctx.getC = fileGetchar;
7757 - ctx->ctx.putC = filePutchar;
7758 + ctx->ctx.getC = fileGetchar;
7759 + ctx->ctx.putC = filePutchar;
7761 - ctx->ctx.getBuf = fileGetbuf;
7762 - ctx->ctx.putBuf = filePutbuf;
7763 + ctx->ctx.getBuf = fileGetbuf;
7764 + ctx->ctx.putBuf = filePutbuf;
7766 - ctx->ctx.tell = fileTell;
7767 - ctx->ctx.seek = fileSeek;
7768 + ctx->ctx.tell = fileTell;
7769 + ctx->ctx.seek = fileSeek;
7771 - ctx->ctx.gd_free = gdFreeFileCtx;
7772 + ctx->ctx.gd_free = gdFreeFileCtx;
7774 - return (gdIOCtx *) ctx;
7775 + return (gdIOCtx *) ctx;
7780 -gdFreeFileCtx (gdIOCtx * ctx)
7781 +static void gdFreeFileCtx (gdIOCtx * ctx)
7789 -filePutbuf (gdIOCtx * ctx, const void *buf, int size)
7790 +static int filePutbuf (gdIOCtx * ctx, const void *buf, int size)
7793 - fctx = (fileIOCtx *) ctx;
7795 + fctx = (fileIOCtx *) ctx;
7797 - return fwrite (buf, 1, size, fctx->f);
7798 + return fwrite(buf, 1, size, fctx->f);
7803 -fileGetbuf (gdIOCtx * ctx, void *buf, int size)
7804 +static int fileGetbuf (gdIOCtx * ctx, void *buf, int size)
7807 - fctx = (fileIOCtx *) ctx;
7809 - return (fread (buf, 1, size, fctx->f));
7811 + fctx = (fileIOCtx *) ctx;
7813 + return fread(buf, 1, size, fctx->f);
7817 -filePutchar (gdIOCtx * ctx, int a)
7818 +static void filePutchar (gdIOCtx * ctx, int a)
7822 - fctx = (fileIOCtx *) ctx;
7825 + fctx = (fileIOCtx *) ctx;
7830 - putc (b, fctx->f);
7831 + putc (b, fctx->f);
7835 -fileGetchar (gdIOCtx * ctx)
7836 +static int fileGetchar (gdIOCtx * ctx)
7839 - fctx = (fileIOCtx *) ctx;
7841 + fctx = (fileIOCtx *) ctx;
7843 - return getc (fctx->f);
7844 + return getc (fctx->f);
7849 -fileSeek (struct gdIOCtx *ctx, const int pos)
7850 +static int fileSeek (struct gdIOCtx *ctx, const int pos)
7853 - fctx = (fileIOCtx *) ctx;
7855 + fctx = (fileIOCtx *) ctx;
7857 - return (fseek (fctx->f, pos, SEEK_SET) == 0);
7858 + return (fseek (fctx->f, pos, SEEK_SET) == 0);
7862 -fileTell (struct gdIOCtx *ctx)
7863 +static long fileTell (struct gdIOCtx *ctx)
7866 - fctx = (fileIOCtx *) ctx;
7868 + fctx = (fileIOCtx *) ctx;
7870 - return ftell (fctx->f);
7871 + return ftell (fctx->f);
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
7878 #define Putchar gdPutchar
7882 typedef struct gdIOCtx {
7883 int (*getC)(struct gdIOCtx*);
7884 int (*getBuf)(struct gdIOCtx*, void*, int);
7886 - void (*putC)(struct gdIOCtx*, int);
7887 + void (*putC)(struct gdIOCtx*, int);
7888 int (*putBuf)(struct gdIOCtx*, const void*, int);
7890 int (*seek)(struct gdIOCtx*, const int);
7891 long (*tell)(struct gdIOCtx*);
7893 - void (*gd_free)(struct gdIOCtx*);
7894 + void (*gd_free)(struct gdIOCtx*);
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
7902 * used internally until it settles down a bit.
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.
7909 * A new SS context does not need to be created with both a Source and a Sink.
7911 /* this is used for creating images in main memory */
7913 typedef struct ssIOCtx
7926 typedef struct ssIOCtx *ssIOCtxPtr;
7928 @@ -48,118 +47,92 @@
7929 static void gdFreeSsCtx (gdIOCtx * ctx);
7931 /* return data as a dynamic pointer */
7933 -gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk)
7934 +gdIOCtx * gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk)
7939 - ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx));
7944 + ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx));
7951 - ctx->ctx.getC = sourceGetchar;
7952 - ctx->ctx.getBuf = sourceGetbuf;
7953 + ctx->ctx.getC = sourceGetchar;
7954 + ctx->ctx.getBuf = sourceGetbuf;
7956 - ctx->ctx.putC = sinkPutchar;
7957 - ctx->ctx.putBuf = sinkPutbuf;
7958 + ctx->ctx.putC = sinkPutchar;
7959 + ctx->ctx.putBuf = sinkPutbuf;
7961 - ctx->ctx.tell = NULL;
7962 - ctx->ctx.seek = NULL;
7963 + ctx->ctx.tell = NULL;
7964 + ctx->ctx.seek = NULL;
7966 - ctx->ctx.gd_free = gdFreeSsCtx;
7967 + ctx->ctx.gd_free = gdFreeSsCtx;
7969 - return (gdIOCtx *) ctx;
7970 + return (gdIOCtx *) ctx;
7975 -gdFreeSsCtx (gdIOCtx * ctx)
7976 +static void gdFreeSsCtx (gdIOCtx * ctx)
7984 -sourceGetbuf (gdIOCtx * ctx, void *buf, int size)
7985 +static int sourceGetbuf (gdIOCtx * ctx, void *buf, int size)
7990 - lctx = (ssIOCtx *) ctx;
7994 - res = ((lctx->src->source) (lctx->src->context, buf, size));
7995 + lctx = (ssIOCtx *) ctx;
7998 - ** Translate the return values from the Source object:
7999 - ** 0 is EOF, -1 is error
8001 + res = ((lctx->src->source) (lctx->src->context, buf, size));
8016 + * Translate the return values from the Source object:
8017 + * 0 is EOF, -1 is error
8022 + } else if (res < 0) {
8030 -sourceGetchar (gdIOCtx * ctx)
8031 +static int sourceGetchar (gdIOCtx * ctx)
8034 - unsigned char buf;
8036 + unsigned char buf;
8038 - res = sourceGetbuf (ctx, &buf, 1);
8048 + res = sourceGetbuf (ctx, &buf, 1);
8058 -sinkPutbuf (gdIOCtx * ctx, const void *buf, int size)
8059 +static int sinkPutbuf (gdIOCtx * ctx, const void *buf, int size)
8064 - lctx = (ssIOCtx *) ctx;
8068 - res = (lctx->snk->sink) (lctx->snk->context, buf, size);
8069 + lctx = (ssIOCtx *) ctx;
8079 + res = (lctx->snk->sink) (lctx->snk->context, buf, size);
8089 -sinkPutchar (gdIOCtx * ctx, int a)
8090 +static void sinkPutchar (gdIOCtx * ctx, int a)
8095 - sinkPutbuf (ctx, &b, 1);
8099 + sinkPutbuf (ctx, &b, 1);
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
8106 * gd_jpeg.c: Read and write JPEG (JFIF) format image files using the
8107 * gd graphics library (http://www.boutell.com/gd/).
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/.
8114 * major CGI brain damage
8116 * 2.0.10: more efficient gdImageCreateFromJpegCtx, thanks to
8117 - * Christian Aberger
8118 + * Christian Aberger
8121 -#if PHP_WIN32 && !defined(ssize_t)
8122 -typedef int ssize_t;
8129 typedef struct _jmpbuf_wrapper
8132 + int ignore_warning;
8135 +static long php_jpeg_emit_message(j_common_ptr jpeg_info, int level)
8137 + char message[JMSG_LENGTH_MAX];
8138 + jmpbuf_wrapper *jmpbufw;
8139 + int ignore_warning = 0;
8141 + jmpbufw = (jmpbuf_wrapper *) jpeg_info->client_data;
8143 + if (jmpbufw != 0) {
8144 + ignore_warning = jmpbufw->ignore_warning;
8147 + (jpeg_info->err->format_message)(jpeg_info,message);
8149 + /* It is a warning message */
8151 + /* display only the 1st warning, as would do a default libjpeg
8152 + * unless strace_level >= 3
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);
8158 + jpeg_info->err->num_warnings++;
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);
8170 /* Called by the IJG JPEG library upon encountering a fatal error */
8171 static void fatal_jpeg_error (j_common_ptr cinfo)
8175 nlines = jpeg_write_scanlines (&cinfo, rowptr, 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);
8184 nlines = jpeg_write_scanlines (&cinfo, rowptr, 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);
8191 @@ -211,21 +243,21 @@
8195 -gdImagePtr gdImageCreateFromJpeg (FILE * inFile)
8196 +gdImagePtr gdImageCreateFromJpeg (FILE * inFile, int ignore_warning)
8199 gdIOCtx *in = gdNewFileCtx(inFile);
8200 - im = gdImageCreateFromJpegCtx(in);
8201 + im = gdImageCreateFromJpegCtx(in, ignore_warning);
8207 -gdImagePtr gdImageCreateFromJpegPtr (int size, void *data)
8208 +gdImagePtr gdImageCreateFromJpegPtr (int size, void *data, int ignore_warning)
8211 gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
8212 - im = gdImageCreateFromJpegCtx(in);
8213 + im = gdImageCreateFromJpegCtx(in, ignore_warning);
8217 @@ -235,11 +267,12 @@
8219 static int CMYKToRGB(int c, int m, int y, int k, int inverted);
8224 * Create a gd-format image from the JPEG-format INFILE. Returns the
8225 * image, or NULL upon error.
8227 -gdImagePtr gdImageCreateFromJpegCtx (gdIOCtx * infile)
8228 +gdImagePtr gdImageCreateFromJpegCtx (gdIOCtx * infile, int ignore_warning)
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));
8236 + jmpbufw.ignore_warning = ignore_warning;
8238 cinfo.err = jpeg_std_error (&jerr);
8239 cinfo.client_data = &jmpbufw;
8241 + cinfo.err->emit_message = (void (*)(j_common_ptr,int)) php_jpeg_emit_message;
8243 if (setjmp (jmpbufw.jmpbuf) != 0) {
8244 /* we're here courtesy of longjmp */
8247 jpeg_save_markers(&cinfo, JPEG_APP0 + 14, 256);
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);
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?
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");
8272 - /* Thanks to Truxton Fulton */
8273 - if (cinfo.err->num_warnings > 0) {
8275 + if (!ignore_warning) {
8276 + if (cinfo.err->num_warnings > 0) {
8282 jpeg_destroy_decompress (&cinfo);
8286 int got = gdGetBuf(src->buffer + nbytes, INPUT_BUF_SIZE - nbytes, src->infile);
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. */
8301 if (src->start_of_file) { /* Treat empty input file as fatal error */
8302 ERREXIT (cinfo, JERR_INPUT_EMPTY);
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));
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
8321 va_start(args, format);
8322 vspprintf(&tmp, 0, format, 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
8328 out all fprintf() statements to disable that).
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',
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);
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.");
8349 longjmp (jmpbuf_ptr->jmpbuf, 1);
8350 @@ -130,12 +130,15 @@
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));
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
8361 - gdGetBuf(sig, 8, infile);
8362 + if (gdGetBuf(sig, 8, infile) < 8) {
8366 if (!png_check_sig (sig, 8)) { /* bad signature */
8369 @@ -146,13 +149,13 @@
8370 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
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");
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);
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)
8393 /* setjmp() must be called in every non-callback function that calls a
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);
8404 im = gdImageCreate((int) width, (int) height);
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);
8411 gdFree(row_pointers);
8412 @@ -201,15 +204,32 @@
8413 png_set_packing (png_ptr); /* expand to 1 byte per pixel */
8416 + /* setjmp() must be called in every non-callback function that calls a
8417 + * PNG-reading libpng function
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);
8426 + gdImageDestroy(im);
8433 switch (color_type) {
8434 case PNG_COLOR_TYPE_PALETTE:
8435 png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
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);
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.
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);
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.)
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.
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);
8482 - transparent = gdTrueColor(trans_color_rgb->red,
8483 + transparent = gdTrueColor(trans_color_rgb->red,
8484 trans_color_rgb->green,
8485 trans_color_rgb->blue);
8488 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
8489 image_data = (png_bytep) safe_emalloc(rowbytes, height, 0);
8491 - row_pointers = (png_bytepp) safe_emalloc(height, sizeof (png_bytep), 0);
8492 + row_pointers = (png_bytepp) safe_emalloc(height, sizeof(png_bytep), 0);
8494 /* set the individual row_pointers to point at the correct offsets */
8495 for (h = 0; h < height; ++h) {
8497 register png_byte b = row_pointers[h][boffset++];
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.
8506 if (!im->trueColor) {
8507 for (i = num_palette; i < gdMaxColors; ++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);
8514 @@ -388,17 +408,17 @@
8518 -void gdImagePngEx (gdImagePtr im, FILE * outFile, int level)
8519 +void gdImagePngEx (gdImagePtr im, FILE * outFile, int level, int basefilter)
8521 gdIOCtx *out = gdNewFileCtx(outFile);
8522 - gdImagePngCtxEx(im, out, level);
8523 + gdImagePngCtxEx(im, out, level, basefilter);
8527 void gdImagePng (gdImagePtr im, FILE * outFile)
8529 gdIOCtx *out = gdNewFileCtx(outFile);
8530 - gdImagePngCtxEx(im, out, -1);
8531 + gdImagePngCtxEx(im, out, -1, -1);
8535 @@ -406,18 +426,18 @@
8538 gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
8539 - gdImagePngCtxEx(im, out, -1);
8540 + gdImagePngCtxEx(im, out, -1, -1);
8541 rv = gdDPExtractData(out, size);
8547 -void * gdImagePngPtrEx (gdImagePtr im, int *size, int level)
8548 +void * gdImagePngPtrEx (gdImagePtr im, int *size, int level, int basefilter)
8551 gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
8552 - gdImagePngCtxEx(im, out, level);
8553 + gdImagePngCtxEx(im, out, level, basefilter);
8554 rv = gdDPExtractData(out, size);
8557 @@ -425,14 +445,14 @@
8559 void gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
8561 - gdImagePngCtxEx(im, outfile, -1);
8562 + gdImagePngCtxEx(im, outfile, -1, -1);
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).
8569 -void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level)
8570 +void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilter)
8572 int i, j, bit_depth = 0, interlace_type;
8574 @@ -454,13 +474,13 @@
8575 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
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");
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);
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);
8599 @@ -483,14 +503,17 @@
8600 * gd is intentionally imperfect and doesn't spend a lot of time
8601 * fussing with such things.
8605 /* png_set_filter(png_ptr, 0, PNG_FILTER_NONE); */
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);
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]
8618 /* png_set_compression_window_bits(png_ptr, 15); */
8619 @@ -519,13 +542,13 @@
8621 } else if (colors <= 4) {
8623 - } else if (colors <= 16) {
8624 + } else if (colors <= 16) {
8632 interlace_type = im->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
8634 if (im->trueColor) {
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.
8648 for (i = 0; i < im->colorsTotal; 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));
8657 * PNG's convention in which 255 is opaque.
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));
8665 @@ -677,12 +700,12 @@
8666 for (j = 0; j < height; ++j) {
8667 gdFree(row_pointers[j]);
8671 gdFree(row_pointers);
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
8685 int overflow2(int a, int b)
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");
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");
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
8702 #define GD_SS_DBG(s)
8706 -gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
8707 +void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
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);
8718 -gdImageCreateFromPngSource (gdSourcePtr inSource)
8719 +gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
8721 - gdIOCtx *in = gdNewSSCtx (inSource, NULL);
8723 + gdIOCtx *in = gdNewSSCtx(inSource, NULL);
8726 - im = gdImageCreateFromPngCtx (in);
8727 + im = gdImageCreateFromPngCtx(in);
8735 #else /* no HAVE_LIBPNG */
8737 -gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
8738 +void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
8740 - php_gd_error("PNG support is not available\n");
8741 + php_gd_error("PNG support is not available");
8744 -gdImageCreateFromPngSource (gdSourcePtr inSource)
8745 +gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
8747 - php_gd_error("PNG support is not available\n");
8749 + php_gd_error("PNG support is not available");
8752 #endif /* HAVE_LIBPNG */
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
8760 +#ifdef HAVE_CONFIG_H
8761 +#include "config.h"
8764 +#include "php_compat.h"
8766 +const int gdCosT[] =
8775 +const int gdSinT[] =
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
8784 /* Send to PNG File then Ptr */
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);
8793 /* Send to GD2 File then Ptr */
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);
8802 /* Send to GD File then Ptr */
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);
8810 ** Test gdImagePngToSink'
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
8822 nim->green[icolor] = 255;
8823 nim->blue[icolor] = 255;
8825 + nim->open[icolor] = 0;
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 */
8833 + if (im2->colorsTotal<1) {
8834 + return -4; /* At least 1 color must be allocated */
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
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/
8856 (wbmp library included, but you can find the latest distribution
8857 at http://www.vandenbrande.com/wbmp)
8859 - Implemented: gdImageCreateFromWBMPCtx, gdImageCreateFromWBMP
8860 + Implemented: gdImageCreateFromWBMPCtx, gdImageCreateFromWBMP
8862 ---------------------------------------------------------------------------
8865 ** implied warranty.
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>.
8872 ** Permission to use, copy, modify, and distribute this software and its
8874 ** Wrapper around gdPutC for use with writewbmp
8878 -gd_putout (int i, void *out)
8879 +void gd_putout (int i, void *out)
8881 - gdPutC (i, (gdIOCtx *) out);
8882 + gdPutC(i, (gdIOCtx *) out);
8887 ** Wrapper around gdGetC for use with readwbmp
8891 -gd_getin (void *in)
8892 +int gd_getin (void *in)
8894 - return (gdGetC ((gdIOCtx *) in));
8895 + return (gdGetC((gdIOCtx *) in));
8899 @@ -91,105 +87,93 @@
8900 ** Write the image as a wbmp file
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
8909 -gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
8910 +void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
8917 + /* create the WBMP */
8918 + if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) {
8919 + php_gd_error("Could not create WBMP");
8922 + /* fill up the WBMP structure */
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;
8933 - /* create the WBMP */
8934 - if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL)
8935 - php_gd_error("Could not create WBMP\n");
8937 - /* fill up the WBMP structure */
8939 - for (y = 0; y < gdImageSY (image); y++)
8941 - for (x = 0; x < gdImageSX (image); x++)
8943 - if (gdImageGetPixel (image, x, y) == fg)
8945 - wbmp->bitmap[pos] = WBMP_BLACK;
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. */
8956 + /* write the WBMP to a gd file descriptor */
8957 + if (writewbmp (wbmp, &gd_putout, out)) {
8958 + php_gd_error("Could not save WBMP");
8960 + /* des submitted this bugfix: gdFree the memory. */
8965 /* gdImageCreateFromWBMPCtx
8966 ** ------------------------
8967 ** Create a gdImage from a WBMP file input from an gdIOCtx
8970 -gdImageCreateFromWBMPCtx (gdIOCtx * infile)
8971 +gdImagePtr gdImageCreateFromWBMPCtx (gdIOCtx * infile)
8973 - /* FILE *wbmp_file; */
8975 - gdImagePtr im = NULL;
8977 - int col, row, pos;
8979 - if (readwbmp (&gd_getin, infile, &wbmp))
8982 - if (!(im = gdImageCreate (wbmp->width, wbmp->height)))
8988 - /* create the background color */
8989 - white = gdImageColorAllocate (im, 255, 255, 255);
8990 - /* create foreground color */
8991 - black = gdImageColorAllocate (im, 0, 0, 0);
8993 - /* fill in image (in a wbmp 1 = white/ 0 = black) */
8995 - for (row = 0; row < wbmp->height; row++)
8997 - for (col = 0; col < wbmp->width; col++)
8999 - if (wbmp->bitmap[pos++] == WBMP_WHITE)
9001 - gdImageSetPixel (im, col, row, white);
9005 - gdImageSetPixel (im, col, row, black);
9007 + /* FILE *wbmp_file; */
9009 + gdImagePtr im = NULL;
9011 + int col, row, pos;
9013 + if (readwbmp (&gd_getin, infile, &wbmp)) {
9019 + if (!(im = gdImageCreate (wbmp->width, wbmp->height))) {
9026 + /* create the background color */
9027 + white = gdImageColorAllocate(im, 255, 255, 255);
9028 + /* create foreground color */
9029 + black = gdImageColorAllocate(im, 0, 0, 0);
9031 + /* fill in image (in a wbmp 1 = white/ 0 = black) */
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);
9038 + gdImageSetPixel(im, col, row, black);
9048 /* gdImageCreateFromWBMP
9049 ** ---------------------
9052 -gdImageCreateFromWBMP (FILE * inFile)
9053 +gdImagePtr gdImageCreateFromWBMP (FILE * inFile)
9056 - gdIOCtx *in = gdNewFileCtx (inFile);
9057 - im = gdImageCreateFromWBMPCtx (in);
9061 + gdIOCtx *in = gdNewFileCtx(inFile);
9062 + im = gdImageCreateFromWBMPCtx(in);
9068 gdImagePtr gdImageCreateFromWBMPPtr (int size, void *data)
9069 @@ -204,24 +188,23 @@
9074 -gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
9075 +void gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
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);
9089 -gdImageWBMPPtr (gdImagePtr im, int *size, int fg)
9090 +void * gdImageWBMPPtr (gdImagePtr im, int *size, int fg)
9093 - gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
9094 - gdImageWBMPCtx (im, fg, out);
9095 - rv = gdDPExtractData (out, size);
9096 - out->gd_free (out);
9099 + gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
9100 + gdImageWBMPCtx(im, fg, out);
9101 + rv = gdDPExtractData(out, size);
9102 + out->gd_free(out);
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
9113 add ability to load xpm files to gd, requires the xpm
9115 - Caolan.McNamara@ul.ie
9116 + Caolan.McNamara@ul.ie
9117 http://www.csn.ul.ie/~caolan
9120 @@ -15,123 +15,125 @@
9122 #include <X11/xpm.h>
9125 -gdImageCreateFromXpm (char *filename)
9126 +gdImagePtr gdImageCreateFromXpm (char *filename)
9130 - int i, j, k, number;
9132 - gdImagePtr im = 0;
9135 - int red = 0, green = 0, blue = 0;
9139 - ret = XpmReadFileToXpmImage (filename, &image, &info);
9140 - if (ret != XpmSuccess)
9143 - if (!(im = gdImageCreate (image.width, image.height)))
9146 - number = image.ncolors;
9147 - colors = (int *) safe_emalloc(number, sizeof(int), 0);
9148 - for (i = 0; i < number; i++)
9150 - switch (strlen (image.colorTable[i].c_color))
9154 - buf[0] = image.colorTable[i].c_color[1];
9155 - red = strtol (buf, NULL, 16);
9157 - buf[0] = image.colorTable[i].c_color[3];
9158 - green = strtol (buf, NULL, 16);
9160 - buf[0] = image.colorTable[i].c_color[5];
9161 - blue = strtol (buf, NULL, 16);
9165 - buf[0] = image.colorTable[i].c_color[1];
9166 - buf[1] = image.colorTable[i].c_color[2];
9167 - red = strtol (buf, NULL, 16);
9169 - buf[0] = image.colorTable[i].c_color[3];
9170 - buf[1] = image.colorTable[i].c_color[4];
9171 - green = strtol (buf, NULL, 16);
9173 - buf[0] = image.colorTable[i].c_color[5];
9174 - buf[1] = image.colorTable[i].c_color[6];
9175 - blue = strtol (buf, NULL, 16);
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);
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);
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);
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);
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);
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);
9222 + int i, j, k, number;
9224 + gdImagePtr im = 0;
9227 + int red = 0, green = 0, blue = 0;
9231 + ret = XpmReadFileToXpmImage(filename, &image, &info);
9232 + if (ret != XpmSuccess) {
9236 + if (!(im = gdImageCreate(image.width, image.height))) {
9240 - colors[i] = gdImageColorResolve (im, red, green, blue);
9241 - if (colors[i] == -1)
9242 - php_gd_error("ARRRGH\n");
9245 - apixel = (char *) gdMalloc (image.cpp + 1);
9246 - apixel[image.cpp] = '\0';
9248 - pointer = (int *) image.data;
9249 - for (i = 0; i < image.height; i++)
9251 - for (j = 0; j < image.width; j++)
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)) {
9261 + buf[0] = image.colorTable[i].c_color[1];
9262 + red = strtol(buf, NULL, 16);
9264 + buf[0] = image.colorTable[i].c_color[2];
9265 + green = strtol(buf, NULL, 16);
9267 + buf[0] = image.colorTable[i].c_color[3];
9268 + blue = strtol(buf, NULL, 16);
9273 + buf[0] = image.colorTable[i].c_color[1];
9274 + buf[1] = image.colorTable[i].c_color[2];
9275 + red = strtol(buf, NULL, 16);
9277 + buf[0] = image.colorTable[i].c_color[3];
9278 + buf[1] = image.colorTable[i].c_color[4];
9279 + green = strtol(buf, NULL, 16);
9281 + buf[0] = image.colorTable[i].c_color[5];
9282 + buf[1] = image.colorTable[i].c_color[6];
9283 + blue = strtol(buf, NULL, 16);
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);
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);
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);
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);
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);
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);
9333 + colors[i] = gdImageColorResolve(im, red, green, blue);
9334 + if (colors[i] == -1) {
9335 + php_gd_error("ARRRGH");
9343 + apixel = (char *) gdMalloc(image.cpp + 1);
9344 + apixel[image.cpp] = '\0';
9346 + pointer = (int *) image.data;
9347 + for (i = 0; i < image.height; i++) {
9348 + for (j = 0; j < image.width; j++) {
9350 + gdImageSetPixel(im, j, i, colors[k]);
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
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. */
9372 /* Create output image. */
9373 im_out = gdImageCreateTrueColor ((int) (gdImageSX (im_in) * scale),
9374 (int) (gdImageSY (im_in) * scale));
9377 Request alpha blending. This causes future
9378 drawing operations to perform alpha channel blending
9379 with the background, resulting in an opaque image.
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);
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
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
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)
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)
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 ...
9429 return (putc (c, (FILE *) out));
9432 -/* getin from file descriptor
9433 +/* getin from file descriptor
9434 ** --------------------------
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
9441 ** (c) 2000 Johan Van den Brande <johan@vandenbrande.com>
9449 +#ifdef HAVE_CONFIG_H
9450 +#include "config.h"
9453 +#include "php_compat.h"
9457 ** A Wireless bitmap structure
9462 typedef struct Wbmp_
9464 int type; /* type of the wbmp */
9466 int height; /* height of the image */
9467 int *bitmap; /* pointer to data: 0 = WHITE , 1 = BLACK */
9471 #define WBMP_WHITE 1
9472 #define WBMP_BLACK 0
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 );
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
9496 maxy = gdImageSY(im);
9498 printf("alpha channel information:\n");
9501 if (im->trueColor) {
9502 for (y = 0; y < maxy; y++) {
9503 for (x = 0; x < maxx; x++) {
9507 printf("NOT a true color image\n");
9510 printf("%d alpha channels\n", nalpha);
9517 /* Open a temporary file. */
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");
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
9530 #define MAX_XBM_LINE_SIZE 255
9533 -gdImageCreateFromXbm (FILE * fd)
9534 +/* {{{ gdImagePtr gdImageCreateFromXbm */
9535 +gdImagePtr gdImageCreateFromXbm(FILE * fd)
9537 char fline[MAX_XBM_LINE_SIZE];
9538 char iname[MAX_XBM_LINE_SIZE];
9546 while (fgets(fline, MAX_XBM_LINE_SIZE, fd)) {
9547 fline[MAX_XBM_LINE_SIZE-1] = '\0';
9554 if (!strcmp("width", type)) {
9555 width = (unsigned int) value;
9561 - im = gdImageCreate(width, height);
9562 + if(!(im = gdImageCreate(width, height))) {
9565 gdImageColorAllocate(im, 255, 255, 255);
9566 gdImageColorAllocate(im, 0, 0, 0);
9568 @@ -147,7 +149,93 @@
9572 - php_gd_error("EOF before image was complete\n");
9573 + php_gd_error("EOF before image was complete");
9579 +/* {{{ gdCtxPrintf */
9580 +void gdCtxPrintf(gdIOCtx * out, const char *format, ...)
9586 + va_start(args, format);
9587 + len = vspprintf(&buf, 0, format, args);
9589 + out->putBuf(out, buf, len);
9594 +/* {{{ gdImageXbmCtx */
9595 +void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out)
9597 + int x, y, c, b, sx, sy, p;
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) {
9608 + name = estrdup("image");
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])) {
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);
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) {
9634 + if ((b == 128) || (x == sx && y == sy)) {
9637 + gdCtxPrintf(out, ", ");
9639 + gdCtxPrintf(out, "\n ");
9644 + gdCtxPrintf(out, "0x%02X", c);
9651 + gdCtxPrintf(out, "};\n");
9656 + * Local variables:
9658 + * c-basic-offset: 4
9660 + * vim600: sw=4 ts=4 fdm=marker
9661 + * vim<600: sw=4 ts=4
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
9665 +++ php-4.4.8/ext/gd/php_gd.h 2008-01-22 22:38:05.897151947 +0100
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)) \
9674 php_error_docref(NULL TSRMLS_CC, E_WARNING, errormsg); \
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);
9682 #if HAVE_LIBGD20 && HAVE_GD_STRINGFT
9683 PHP_RSHUTDOWN_FUNCTION(gd);
9685 @@ -112,6 +114,11 @@
9686 PHP_FUNCTION(imagecopyresampled);
9690 +PHP_FUNCTION(imagegrabwindow);
9691 +PHP_FUNCTION(imagegrabscreen);
9694 #ifdef HAVE_GD_BUNDLED
9695 PHP_FUNCTION(imagerotate);
9696 PHP_FUNCTION(imageantialias);
9698 PHP_FUNCTION(imagelayereffect);
9699 PHP_FUNCTION(imagecolormatch);
9700 PHP_FUNCTION(imagefilter);
9701 +PHP_FUNCTION(imageconvolution);
9702 +PHP_FUNCTION(imagexbm);
9705 PHP_GD_API int phpi_get_le_gd(void);