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/CREDITS php-4.4.8/ext/gd/CREDITS
28 --- php-4.4.8.org/ext/gd/CREDITS 2003-03-01 02:16:00.000000000 +0100
29 +++ php-4.4.8/ext/gd/CREDITS 2008-01-22 22:38:05.837148890 +0100
32 -Rasmus Lerdorf, Stig Bakken, Jim Winstead, Jouni Ahto, Ilia Alshanetsky, Pierre-Alain Joye
33 +Rasmus Lerdorf, Stig Bakken, Jim Winstead, Jouni Ahto, Ilia Alshanetsky, Pierre-Alain Joye, Marcus Boerger
34 diff -urN php-4.4.8.org/ext/gd/gd.c php-4.4.8/ext/gd/gd.c
35 --- php-4.4.8.org/ext/gd/gd.c 2007-12-31 08:22:47.000000000 +0100
36 +++ php-4.4.8/ext/gd/gd.c 2008-01-22 22:38:05.837148890 +0100
39 +----------------------------------------------------------------------+
42 +----------------------------------------------------------------------+
43 - | Copyright (c) 1997-2008 The PHP Group |
44 + | Copyright (c) 1997-2007 The PHP Group |
45 +----------------------------------------------------------------------+
46 | This source file is subject to version 3.01 of the PHP license, |
47 | that is bundled with this package in the file LICENSE, and is |
49 | license@php.net so we can mail you a copy immediately. |
50 +----------------------------------------------------------------------+
51 | Authors: Rasmus Lerdorf <rasmus@php.net> |
52 - | Stig Bakken <ssb@fast.no> |
53 + | Stig Bakken <ssb@php.net> |
54 | Jim Winstead <jimw@php.net> |
55 +----------------------------------------------------------------------+
61 -/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
62 +/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
63 Cold Spring Harbor Labs. */
65 /* Note that there is no code from the gd package in this file */
71 +/* needs to be first */
77 #include "ext/standard/head.h"
91 #include <gdfontmb.h> /* 3 Medium bold font */
92 #include <gdfontl.h> /* 4 Large font */
93 #include <gdfontg.h> /* 5 Giant font */
96 #include "libgd/wbmp.h"
100 +# ifdef HAVE_LIBFREETYPE
101 +# include <ft2build.h>
102 +# include FT_FREETYPE_H
105 +# include <freetype.h>
112 #define gdNewDynamicCtxEx(len, data, val) gdNewDynamicCtx(len, data)
115 +/* Section Filters Declarations */
116 +/* IMPORTANT NOTE FOR NEW FILTER
117 + * Do not forget to update:
118 + * IMAGE_FILTER_MAX: define the last filter index
119 + * IMAGE_FILTER_MAX_ARGS: define the biggest amout of arguments
120 + * image_filter array in PHP_FUNCTION(imagefilter)
123 +#define IMAGE_FILTER_NEGATE 0
124 +#define IMAGE_FILTER_GRAYSCALE 1
125 +#define IMAGE_FILTER_BRIGHTNESS 2
126 +#define IMAGE_FILTER_CONTRAST 3
127 +#define IMAGE_FILTER_COLORIZE 4
128 +#define IMAGE_FILTER_EDGEDETECT 5
129 +#define IMAGE_FILTER_EMBOSS 6
130 +#define IMAGE_FILTER_GAUSSIAN_BLUR 7
131 +#define IMAGE_FILTER_SELECTIVE_BLUR 8
132 +#define IMAGE_FILTER_MEAN_REMOVAL 9
133 +#define IMAGE_FILTER_SMOOTH 10
134 +#define IMAGE_FILTER_MAX 10
135 +#define IMAGE_FILTER_MAX_ARGS 5
136 +static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS);
137 +static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS);
138 +static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS);
139 +static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS);
140 +static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS);
141 +static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS);
142 +static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS);
143 +static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS);
144 +static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS);
145 +static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS);
146 +static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS);
148 +/* End Section filters declarations */
149 static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC);
150 static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)());
151 static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)());
154 /* {{{ gd_functions[]
156 -function_entry gd_functions[] = {
157 +zend_function_entry gd_functions[] = {
158 PHP_FE(gd_info, NULL)
159 PHP_FE(imagearc, NULL)
160 PHP_FE(imageellipse, NULL)
162 PHP_FE(imagecopyresampled, NULL)
166 + PHP_FE(imagegrabwindow, NULL)
167 + PHP_FE(imagegrabscreen, NULL)
170 #ifdef HAVE_GD_BUNDLED
171 PHP_FE(imagerotate, NULL)
172 PHP_FE(imageantialias, NULL)
175 PHP_FE(imagelayereffect, NULL)
176 PHP_FE(imagecolormatch, NULL)
177 + PHP_FE(imagexbm, NULL)
180 +#ifdef HAVE_GD_BUNDLED
181 + PHP_FE(imagefilter, NULL)
182 + PHP_FE(imageconvolution, NULL)
190 +#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
196 -#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
197 +#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
205 +/* {{{ PHP_INI_BEGIN */
207 + PHP_INI_ENTRY("gd.jpeg_ignore_warning", "0", PHP_INI_ALL, NULL)
211 /* {{{ php_free_gd_image
213 static void php_free_gd_image(zend_rsrc_list_entry *rsrc TSRMLS_DC)
214 @@ -326,15 +400,21 @@
219 /* {{{ PHP_MSHUTDOWN_FUNCTION
221 +#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
222 PHP_MSHUTDOWN_FUNCTION(gd)
227 +#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
228 + gdFontCacheMutexShutdown();
238 le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
239 le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
241 +#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
242 + gdFontCacheMutexSetup();
246 T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
248 le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number);
251 + REGISTER_INI_ENTRIES();
253 REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT);
254 REGISTER_LONG_CONSTANT("IMG_JPG", 2, CONST_CS | CONST_PERSISTENT);
255 REGISTER_LONG_CONSTANT("IMG_JPEG", 2, CONST_CS | CONST_PERSISTENT);
256 @@ -387,16 +473,58 @@
257 REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT);
258 REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT);
259 REGISTER_LONG_CONSTANT("GD_BUNDLED", 1, CONST_CS | CONST_PERSISTENT);
261 + /* Section Filters */
262 + REGISTER_LONG_CONSTANT("IMG_FILTER_NEGATE", IMAGE_FILTER_NEGATE, CONST_CS | CONST_PERSISTENT);
263 + REGISTER_LONG_CONSTANT("IMG_FILTER_GRAYSCALE", IMAGE_FILTER_GRAYSCALE, CONST_CS | CONST_PERSISTENT);
264 + REGISTER_LONG_CONSTANT("IMG_FILTER_BRIGHTNESS", IMAGE_FILTER_BRIGHTNESS, CONST_CS | CONST_PERSISTENT);
265 + REGISTER_LONG_CONSTANT("IMG_FILTER_CONTRAST", IMAGE_FILTER_CONTRAST, CONST_CS | CONST_PERSISTENT);
266 + REGISTER_LONG_CONSTANT("IMG_FILTER_COLORIZE", IMAGE_FILTER_COLORIZE, CONST_CS | CONST_PERSISTENT);
267 + REGISTER_LONG_CONSTANT("IMG_FILTER_EDGEDETECT", IMAGE_FILTER_EDGEDETECT, CONST_CS | CONST_PERSISTENT);
268 + REGISTER_LONG_CONSTANT("IMG_FILTER_GAUSSIAN_BLUR", IMAGE_FILTER_GAUSSIAN_BLUR, CONST_CS | CONST_PERSISTENT);
269 + REGISTER_LONG_CONSTANT("IMG_FILTER_SELECTIVE_BLUR", IMAGE_FILTER_SELECTIVE_BLUR, CONST_CS | CONST_PERSISTENT);
270 + REGISTER_LONG_CONSTANT("IMG_FILTER_EMBOSS", IMAGE_FILTER_EMBOSS, CONST_CS | CONST_PERSISTENT);
271 + REGISTER_LONG_CONSTANT("IMG_FILTER_MEAN_REMOVAL", IMAGE_FILTER_MEAN_REMOVAL, CONST_CS | CONST_PERSISTENT);
272 + REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT);
273 + /* End Section Filters */
275 REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
278 +#ifdef GD_VERSION_STRING
279 + REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
282 +#if defined(GD_MAJOR_VERSION) && defined(GD_MINOR_VERSION) && defined(GD_RELEASE_VERSION) && defined(GD_EXTRA_VERSION)
283 + REGISTER_LONG_CONSTANT("GD_MAJOR_VERSION", GD_MAJOR_VERSION, CONST_CS | CONST_PERSISTENT);
284 + REGISTER_LONG_CONSTANT("GD_MINOR_VERSION", GD_MINOR_VERSION, CONST_CS | CONST_PERSISTENT);
285 + REGISTER_LONG_CONSTANT("GD_RELEASE_VERSION", GD_RELEASE_VERSION, CONST_CS | CONST_PERSISTENT);
286 + REGISTER_STRING_CONSTANT("GD_EXTRA_VERSION", GD_EXTRA_VERSION, CONST_CS | CONST_PERSISTENT);
293 + * cannot include #include "png.h"
294 + * /usr/include/pngconf.h:310:2: error: #error png.h already includes setjmp.h with some additional fixup.
295 + * as error, use the values for now...
297 + REGISTER_LONG_CONSTANT("PNG_NO_FILTER", 0x00, CONST_CS | CONST_PERSISTENT);
298 + REGISTER_LONG_CONSTANT("PNG_FILTER_NONE", 0x08, CONST_CS | CONST_PERSISTENT);
299 + REGISTER_LONG_CONSTANT("PNG_FILTER_SUB", 0x10, CONST_CS | CONST_PERSISTENT);
300 + REGISTER_LONG_CONSTANT("PNG_FILTER_UP", 0x20, CONST_CS | CONST_PERSISTENT);
301 + REGISTER_LONG_CONSTANT("PNG_FILTER_AVG", 0x40, CONST_CS | CONST_PERSISTENT);
302 + REGISTER_LONG_CONSTANT("PNG_FILTER_PAETH", 0x80, CONST_CS | CONST_PERSISTENT);
303 + REGISTER_LONG_CONSTANT("PNG_ALL_FILTERS", 0x08 | 0x10 | 0x20 | 0x40 | 0x80, CONST_CS | CONST_PERSISTENT);
309 /* {{{ PHP_RSHUTDOWN_FUNCTION
311 -#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
312 +#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
313 PHP_RSHUTDOWN_FUNCTION(gd)
315 #if HAVE_GD_FONTCACHESHUTDOWN
320 -#define PHP_GD_VERSION_STRING "bundled (2.0.28 compatible)"
321 +#define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)"
323 #define PHP_GD_VERSION_STRING "2.0 or higher"
324 #elif HAVE_GDIMAGECOLORRESOLVE
326 php_info_print_table_row(2, "FreeType Support", "enabled");
328 php_info_print_table_row(2, "FreeType Linkage", "with freetype");
331 +#ifdef FREETYPE_PATCH
332 + snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
333 +#elif defined(FREETYPE_MAJOR)
334 + snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR);
336 + snprintf(tmp, sizeof(tmp), "1.x");
338 + php_info_print_table_row(2, "FreeType Version", tmp);
341 php_info_print_table_row(2, "FreeType Linkage", "with TTF library");
344 + snprintf(tmp, sizeof(tmp), "%d.%d", TT_FREETYPE_MAJOR, TT_FREETYPE_MINOR);
345 + php_info_print_table_row(2, "FreeType Version", tmp);
348 php_info_print_table_row(2, "FreeType Linkage", "with unknown library");
352 php_info_print_table_row(2, "WBMP Support", "enabled");
354 +#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
355 + php_info_print_table_row(2, "XPM Support", "enabled");
358 php_info_print_table_row(2, "XBM Support", "enabled");
362 add_assoc_bool(return_value, "WBMP Support", 0);
364 +#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
365 + add_assoc_bool(return_value, "XPM Support", 1);
367 + add_assoc_bool(return_value, "XPM Support", 0);
370 add_assoc_bool(return_value, "XBM Support", 1);
378 #ifndef HAVE_GDIMAGECOLORRESOLVE
380 @@ -763,13 +916,19 @@
381 convert_to_long_ex(x_size);
382 convert_to_long_ex(y_size);
384 - if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0) {
385 + if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 ||
386 + Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX
388 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
392 im = gdImageCreateTrueColor(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
398 ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
401 @@ -836,15 +995,19 @@
402 result = gdImageColorMatch(im1, im2);
405 - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image1 must be TrueColor" );
406 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 must be TrueColor" );
410 - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image2 must be Palette" );
411 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must be Palette" );
415 - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image1 and Image2 must be the same size" );
416 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 and Image2 must be the same size" );
420 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must have at least one color" );
432 @@ -1008,6 +1172,7 @@
434 long red, green, blue, alpha;
438 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
440 @@ -1015,7 +1180,12 @@
442 ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
444 - RETURN_LONG(gdImageColorAllocateAlpha(im, red, green, blue, alpha));
445 + ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha);
450 + RETURN_LONG((long)ct);
454 @@ -1125,28 +1295,173 @@
459 +/* {{{ proto resource imagegrabwindow(int window_handle [, int client_area])
460 + Grab a window or its client area using a windows handle (HWND property in COM instance) */
461 +PHP_FUNCTION(imagegrabwindow)
464 + long client_area = 0;
473 + long lwindow_handle;
474 + typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
475 + tPrintWindow pPrintWindow = 0;
478 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &lwindow_handle, &client_area) == FAILURE) {
482 + window = (HWND) lwindow_handle;
484 + if (!IsWindow(window)) {
485 + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid window handle");
492 + GetClientRect(window, &rc);
494 + Height = rc.bottom;
496 + GetWindowRect(window, &rc);
497 + Width = rc.right - rc.left;
498 + Height = rc.bottom - rc.top;
501 + Width = (Width/4)*4;
503 + memDC = CreateCompatibleDC(hdc);
504 + memBM = CreateCompatibleBitmap(hdc, Width, Height);
505 + hOld = (HBITMAP) SelectObject (memDC, memBM);
508 + handle = LoadLibrary("User32.dll");
509 + if ( handle == 0 ) {
512 + pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow");
514 + if ( pPrintWindow ) {
515 + pPrintWindow(window, memDC, (UINT) client_area);
517 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows API too old");
522 + FreeLibrary(handle);
524 + im = gdImageCreateTrueColor(Width, Height);
527 + for (y=0; y <= Height; y++) {
528 + for (x=0; x <= Width; x++) {
529 + int c = GetPixel(memDC, x,y);
530 + gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
536 + SelectObject(memDC,hOld);
537 + DeleteObject(memBM);
539 + ReleaseDC( 0, hdc );
544 + ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
549 +/* {{{ proto resource imagegrabscreen()
550 + Grab a screenshot */
551 +PHP_FUNCTION(imagegrabscreen)
553 + HWND window = GetDesktopWindow();
561 + long lwindow_handle;
562 + typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
563 + tPrintWindow pPrintWindow = 0;
571 + GetWindowRect(window, &rc);
572 + Width = rc.right - rc.left;
573 + Height = rc.bottom - rc.top;
575 + Width = (Width/4)*4;
577 + memDC = CreateCompatibleDC(hdc);
578 + memBM = CreateCompatibleBitmap(hdc, Width, Height);
579 + hOld = (HBITMAP) SelectObject (memDC, memBM);
580 + BitBlt( memDC, 0, 0, Width, Height , hdc, rc.left, rc.top , SRCCOPY );
582 + im = gdImageCreateTrueColor(Width, Height);
585 + for (y=0; y <= Height; y++) {
586 + for (x=0; x <= Width; x++) {
587 + int c = GetPixel(memDC, x,y);
588 + gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
593 + SelectObject(memDC,hOld);
594 + DeleteObject(memBM);
596 + ReleaseDC( 0, hdc );
601 + ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
605 +#endif /* PHP_WIN32 */
607 #ifdef HAVE_GD_BUNDLED
608 -/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor)
609 +/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor [, int ignoretransparent])
610 Rotate an image using a custom angle */
611 PHP_FUNCTION(imagerotate)
613 - zval **SIM, **ANGLE, **BGDCOLOR;
615 gdImagePtr im_dst, im_src;
618 + long ignoretransparent = 0;
620 - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &SIM, &ANGLE, &BGDCOLOR) == FAILURE) {
621 - ZEND_WRONG_PARAM_COUNT();
622 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdl|l", &SIM, °rees, &color, &ignoretransparent) == FAILURE) {
626 - ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
628 - convert_to_long_ex(BGDCOLOR);
629 - color = Z_LVAL_PP(BGDCOLOR);
630 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
632 - convert_to_double_ex(ANGLE);
633 - degrees = Z_DVAL_PP(ANGLE);
634 - im_dst = gdImageRotate(im_src, degrees, color);
635 + im_dst = gdImageRotate(im_src, degrees, color, ignoretransparent);
637 if (im_dst != NULL) {
638 ZEND_REGISTER_RESOURCE(return_value, im_dst, le_gd);
639 @@ -1215,13 +1530,19 @@
640 convert_to_long_ex(x_size);
641 convert_to_long_ex(y_size);
643 - if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0) {
644 + if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 ||
645 + Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX
647 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
651 im = gdImageCreate(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
657 ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
660 @@ -1323,6 +1644,11 @@
661 im = (*ioctx_func_p)(io_ctx);
663 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed data is not in '%s' format", tn);
665 + io_ctx->gd_free(io_ctx);
667 + io_ctx->free(io_ctx);
672 @@ -1350,6 +1676,11 @@
675 convert_to_string_ex(data);
676 + if (Z_STRLEN_PP(data) < 8) {
677 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string or invalid image");
681 memcpy(sig, Z_STRVAL_PP(data), 8);
683 imtype = _php_image_type(sig);
684 @@ -1401,7 +1732,7 @@
688 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format.");
689 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format");
693 @@ -1425,6 +1756,9 @@
696 int argc=ZEND_NUM_ARGS();
698 + long ignore_warning;
701 if ((image_type == PHP_GDIMG_TYPE_GD2PART && argc != 5) ||
702 (image_type != PHP_GDIMG_TYPE_GD2PART && argc != 1) ||
703 @@ -1436,6 +1770,10 @@
705 if (argc == 5 && image_type == PHP_GDIMG_TYPE_GD2PART) {
706 multi_convert_to_long_ex(4, srcx, srcy, width, height);
707 + if (Z_LVAL_PP(width) < 1 || Z_LVAL_PP(height) < 1) {
708 + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Zero width or height not allowed");
713 fn = Z_STRVAL_PP(file);
714 @@ -1471,6 +1809,7 @@
716 io_ctx = gdNewDynamicCtxEx(buff_size, buff, 0);
719 php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context");
722 @@ -1485,7 +1824,7 @@
724 io_ctx->free(io_ctx);
731 @@ -1505,6 +1844,18 @@
732 im = gdImageCreateFromXpm(fn);
737 + case PHP_GDIMG_TYPE_JPG:
738 + ignore_warning = INI_INT("gd.jpeg_ignore_warning");
739 +#ifdef HAVE_GD_BUNDLED
740 + im = gdImageCreateFromJpeg(fp, ignore_warning);
742 + im = gdImageCreateFromJpeg(fp);
750 @@ -1685,6 +2036,14 @@
755 + case PHP_GDIMG_TYPE_GD2:
759 + (*func_p)(im, fp, q, t);
765 @@ -1737,6 +2096,14 @@
770 + case PHP_GDIMG_TYPE_GD2:
774 + (*func_p)(im, tmp, q, t);
780 @@ -1762,6 +2129,16 @@
784 +/* {{{ proto int imagexbm(int im, string filename [, int foreground])
785 + Output XBM image to browser or file */
787 +PHP_FUNCTION(imagexbm)
789 + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx);
794 #ifdef HAVE_GD_GIF_CREATE
795 /* {{{ proto bool imagegif(resource im [, string filename])
796 Output GIF image to browser or file */
797 @@ -1782,7 +2159,7 @@
798 PHP_FUNCTION(imagepng)
801 - _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtx);
802 + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtxEx);
804 _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng);
806 @@ -1862,6 +2239,7 @@
808 zval **IM, **red, **green, **blue;
812 if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
813 ZEND_WRONG_PARAM_COUNT();
814 @@ -1872,8 +2250,11 @@
815 convert_to_long_ex(red);
816 convert_to_long_ex(green);
817 convert_to_long_ex(blue);
819 - RETURN_LONG(gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
820 + ct = gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue));
828 @@ -2508,7 +2889,7 @@
829 static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
831 zval **IM, **POINTS, **NPOINTS, **COL;
836 int npoints, col, nelem, i;
837 @@ -2716,7 +3097,7 @@
838 ch = (int)((unsigned char)*(Z_STRVAL_PP(C)));
840 str = (unsigned char *) estrndup(Z_STRVAL_PP(C), Z_STRLEN_PP(C));
842 + l = strlen((char *)str);
846 @@ -3083,7 +3464,7 @@
848 char tmp_font_path[MAXPATHLEN];
850 - if (VCWD_REALPATH(fontname, tmp_font_path)) {
851 + if (VCWD_REALPATH((char *)fontname, tmp_font_path)) {
852 fontname = (unsigned char *) fontname;
855 @@ -3093,16 +3474,18 @@
856 fontname = (unsigned char *) fontname;
859 + PHP_GD_CHECK_OPEN_BASEDIR((char *)fontname, "Invalid font filename");
861 #ifdef USE_GD_IMGSTRTTF
862 # if HAVE_GD_STRINGFTEX
864 - error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
865 + error = gdImageStringFTEx(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str, &strex);
870 # if HAVE_GD_STRINGFT
871 - error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);
872 + error = gdImageStringFT(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str);
873 # elif HAVE_GD_STRINGTTF
874 error = gdImageStringTTF(im, brect, col, fontname, ptsize, angle, x, y, str);
876 @@ -3155,6 +3538,9 @@
884 if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
885 ZEND_WRONG_PARAM_COUNT();
886 @@ -3162,24 +3548,18 @@
888 convert_to_string_ex(file);
891 + if (VCWD_STAT(Z_STRVAL_PP(file), &st) < 0) {
892 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Font file not found (%s)", Z_STRVAL_PP(file));
897 f_ind = T1_AddFont(Z_STRVAL_PP(file));
902 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't find the font file");
907 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memory allocation fault in t1lib");
911 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "An unknown error occurred in t1lib");
915 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind));
919 if (T1_LoadFont(f_ind)) {
920 @@ -3317,6 +3697,11 @@
922 T1_DeleteAllSizes(*f_ind);
924 + if (Z_DVAL_PP(ext) <= 0) {
925 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter %F out of range (must be > 0)", Z_DVAL_PP(ext));
929 if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) {
932 @@ -3348,7 +3733,7 @@
936 -/* {{{ proto array imagepstext(resource image, string text, resource font, int size, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias])
937 +/* {{{ proto array imagepstext(resource image, string text, resource font, int size, int foreground, int background, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias])
938 Rasterize a string over an image */
939 PHP_FUNCTION(imagepstext)
941 @@ -3371,11 +3756,6 @@
942 T1_TMATRIX *transform = NULL;
945 - int argc = ZEND_NUM_ARGS();
947 - if (argc != 8 && argc != 12) {
948 - ZEND_WRONG_PARAM_COUNT();
951 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrlllll|lldl", &img, &str, &str_len, &fnt, &size, &_fg, &_bg, &x, &y, &space, &width, &angle, &aa_steps) == FAILURE) {
953 @@ -3455,7 +3835,7 @@
957 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "libt1 returned error %d", T1_errno);
958 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
962 @@ -3476,7 +3856,7 @@
963 str_img = T1_AASetString(*f_ind, str, str_len, space, T1_KERNING, size, transform);
966 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "libt1 returned error %d", T1_errno);
967 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
971 @@ -3719,7 +4099,10 @@
974 float x_ratio, y_ratio;
977 + long ignore_warning;
980 if (argc != 5 || zend_get_parameters_ex(argc, &f_org, &f_dest, &height, &width, &threshold) == FAILURE) {
981 ZEND_WRONG_PARAM_COUNT();
983 @@ -3775,7 +4158,12 @@
986 case PHP_GDIMG_TYPE_JPG:
987 + ignore_warning = INI_INT("gd.jpeg_ignore_warning");
988 +#ifdef HAVE_GD_BUNDLED
989 + im_org = gdImageCreateFromJpeg(org, ignore_warning);
991 im_org = gdImageCreateFromJpeg(org);
993 if (im_org == NULL) {
994 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid JPEG file", fn_dest);
996 @@ -3886,7 +4274,282 @@
998 #endif /* HAVE_GD_WBMP */
1000 +#endif /* HAVE_LIBGD */
1002 +/* Section Filters */
1003 #ifdef HAVE_GD_BUNDLED
1005 +#define PHP_GD_SINGLE_RES \
1007 + gdImagePtr im_src; \
1008 + if (zend_get_parameters_ex(1, &SIM) == FAILURE) { \
1011 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); \
1012 + if (im_src == NULL) { \
1016 +static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
1020 + if (gdImageNegate(im_src) == 1) {
1027 +static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
1031 + if (gdImageGrayScale(im_src) == 1) {
1038 +static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
1041 + gdImagePtr im_src;
1042 + long brightness, tmp;
1044 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &SIM, &tmp, &brightness) == FAILURE) {
1048 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1050 + if (im_src == NULL) {
1054 + if (gdImageBrightness(im_src, (int)brightness) == 1) {
1061 +static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
1064 + gdImagePtr im_src;
1065 + long contrast, tmp;
1067 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &SIM, &tmp, &contrast) == FAILURE) {
1071 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1073 + if (im_src == NULL) {
1077 + if (gdImageContrast(im_src, (int)contrast) == 1) {
1084 +static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
1087 + gdImagePtr im_src;
1091 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &SIM, &tmp, &r, &g, &b, &a) == FAILURE) {
1095 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1097 + if (im_src == NULL) {
1101 + if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) {
1108 +static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS)
1112 + if (gdImageEdgeDetectQuick(im_src) == 1) {
1119 +static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
1123 + if (gdImageEmboss(im_src) == 1) {
1130 +static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
1134 + if (gdImageGaussianBlur(im_src) == 1) {
1141 +static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
1145 + if (gdImageSelectiveBlur(im_src) == 1) {
1152 +static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
1156 + if (gdImageMeanRemoval(im_src) == 1) {
1163 +static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
1167 + gdImagePtr im_src;
1170 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
1174 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1176 + if (im_src == NULL) {
1180 + if (gdImageSmooth(im_src, (float)weight)==1) {
1187 +/* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] )
1188 + Applies Filter an image using a custom angle */
1189 +PHP_FUNCTION(imagefilter)
1193 + typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS);
1195 + image_filter filters[] =
1197 + php_image_filter_negate ,
1198 + php_image_filter_grayscale,
1199 + php_image_filter_brightness,
1200 + php_image_filter_contrast,
1201 + php_image_filter_colorize,
1202 + php_image_filter_edgedetect,
1203 + php_image_filter_emboss,
1204 + php_image_filter_gaussian_blur,
1205 + php_image_filter_selective_blur,
1206 + php_image_filter_mean_removal,
1207 + php_image_filter_smooth
1210 + if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 6) {
1211 + WRONG_PARAM_COUNT;
1212 + } else if (zend_parse_parameters(2 TSRMLS_CC, "rl", &tmp, &filtertype) == FAILURE) {
1216 + if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
1217 + filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
1222 +/* {{{ proto resource imageconvolution(resource src_im, array matrix3x3, double div, double offset)
1223 + Apply a 3x3 convolution matrix, using coefficient div and offset */
1224 +PHP_FUNCTION(imageconvolution)
1226 + zval *SIM, *hash_matrix;
1227 + zval **var = NULL, **var2 = NULL;
1228 + gdImagePtr im_src = NULL;
1229 + double div, offset;
1230 + int nelem, i, j, res;
1231 + float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}};
1233 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "radd", &SIM, &hash_matrix, &div, &offset) == FAILURE) {
1237 + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
1239 + nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
1241 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
1245 + for (i=0; i<3; i++) {
1246 + if (zend_hash_index_find(Z_ARRVAL_P(hash_matrix), (i), (void **) &var) == SUCCESS && Z_TYPE_PP(var) == IS_ARRAY) {
1247 + if (Z_TYPE_PP(var) != IS_ARRAY || zend_hash_num_elements(Z_ARRVAL_PP(var)) != 3 ) {
1248 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
1252 + for (j=0; j<3; j++) {
1253 + if (zend_hash_index_find(Z_ARRVAL_PP(var), (j), (void **) &var2) == SUCCESS) {
1254 + SEPARATE_ZVAL(var2);
1255 + convert_to_double(*var2);
1256 + matrix[i][j] = Z_DVAL_PP(var2);
1258 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have a 3x3 matrix");
1264 + res = gdImageConvolution(im_src, matrix, div, offset);
1274 +/* End section: Filters */
1276 /* {{{ proto bool imageantialias(resource im, bool on)
1277 Should antialiased functions used or not*/
1278 PHP_FUNCTION(imageantialias)
1279 @@ -3908,8 +4571,6 @@
1283 -#endif /* HAVE_LIBGD */
1288 diff -urN php-4.4.8.org/ext/gd/gdcache.c php-4.4.8/ext/gd/gdcache.c
1289 --- php-4.4.8.org/ext/gd/gdcache.c 2005-01-09 22:05:31.000000000 +0100
1290 +++ php-4.4.8/ext/gd/gdcache.c 2008-01-22 22:38:05.863816915 +0100
1297 - * Caches of pointers to user structs in which the least-recently-used
1298 - * element is replaced in the event of a cache miss after the cache has
1299 + * Caches of pointers to user structs in which the least-recently-used
1300 + * element is replaced in the event of a cache miss after the cache has
1301 * reached a given size.
1303 * John Ellson (ellson@lucent.com) Oct 31, 1997
1305 * The head structure has a pointer to the most-recently-used
1306 * element, and elements are moved to this position in the list each
1307 * time they are used. The head also contains pointers to three
1308 - * user defined functions:
1309 - * - a function to test if a cached userdata matches some keydata
1310 - * - a function to provide a new userdata struct to the cache
1311 + * user defined functions:
1312 + * - a function to test if a cached userdata matches some keydata
1313 + * - a function to provide a new userdata struct to the cache
1314 * if there has been a cache miss.
1315 * - a function to release a userdata struct when it is
1316 * no longer being managed by the cache
1318 * In the event of a cache miss the cache is allowed to grow up to
1319 * a specified maximum size. After the maximum size is reached then
1320 - * the least-recently-used element is discarded to make room for the
1321 - * new. The most-recently-returned value is always left at the
1322 + * the least-recently-used element is discarded to make room for the
1323 + * new. The most-recently-returned value is always left at the
1324 * beginning of the list after retrieval.
1326 * In the current implementation the cache is traversed by a linear
1329 gdCacheTestFn_t gdCacheTest,
1330 gdCacheFetchFn_t gdCacheFetch,
1331 - gdCacheReleaseFn_t gdCacheRelease )
1332 + gdCacheReleaseFn_t gdCacheRelease )
1334 - gdCache_head_t *head;
1335 + gdCache_head_t *head;
1337 head = (gdCache_head_t *)pemalloc(sizeof(gdCache_head_t), 1);
1339 diff -urN php-4.4.8.org/ext/gd/gdcache.h php-4.4.8/ext/gd/gdcache.h
1340 --- php-4.4.8.org/ext/gd/gdcache.h 2003-03-05 17:04:20.000000000 +0100
1341 +++ php-4.4.8/ext/gd/gdcache.h 2008-01-22 22:38:05.863816915 +0100
1348 - * Caches of pointers to user structs in which the least-recently-used
1349 - * element is replaced in the event of a cache miss after the cache has
1350 + * Caches of pointers to user structs in which the least-recently-used
1351 + * element is replaced in the event of a cache miss after the cache has
1352 * reached a given size.
1354 * John Ellson (ellson@lucent.com) Oct 31, 1997
1356 * The head structure has a pointer to the most-recently-used
1357 * element, and elements are moved to this position in the list each
1358 * time they are used. The head also contains pointers to three
1359 - * user defined functions:
1360 - * - a function to test if a cached userdata matches some keydata
1361 - * - a function to provide a new userdata struct to the cache
1362 + * user defined functions:
1363 + * - a function to test if a cached userdata matches some keydata
1364 + * - a function to provide a new userdata struct to the cache
1365 * if there has been a cache miss.
1366 * - a function to release a userdata struct when it is
1367 * no longer being managed by the cache
1369 * In the event of a cache miss the cache is allowed to grow up to
1370 * a specified maximum size. After the maximum size is reached then
1371 - * the least-recently-used element is discarded to make room for the
1372 - * new. The most-recently-returned value is always left at the
1373 + * the least-recently-used element is discarded to make room for the
1374 + * new. The most-recently-returned value is always left at the
1375 * beginning of the list after retrieval.
1377 * In the current implementation the cache is traversed by a linear
1378 diff -urN php-4.4.8.org/ext/gd/gd_ctx.c php-4.4.8/ext/gd/gd_ctx.c
1379 --- php-4.4.8.org/ext/gd/gd_ctx.c 2007-12-31 08:22:47.000000000 +0100
1380 +++ php-4.4.8/ext/gd/gd_ctx.c 2008-01-22 22:38:05.863816915 +0100
1383 +----------------------------------------------------------------------+
1386 +----------------------------------------------------------------------+
1387 - | Copyright (c) 1997-2008 The PHP Group |
1388 + | Copyright (c) 1997-2007 The PHP Group |
1389 +----------------------------------------------------------------------+
1390 | This source file is subject to version 3.01 of the PHP license, |
1391 | that is bundled with this package in the file LICENSE, and is |
1392 | available through the world-wide-web at the following url: |
1393 - | http://www.php.net/license/3_0.txt. |
1394 + | http://www.php.net/license/3_01.txt |
1395 | If you did not receive a copy of the PHP license and are unable to |
1396 | obtain it through the world-wide-web, please send a note to |
1397 | license@php.net so we can mail you a copy immediately. |
1399 | Authors: Stanislav Malyshev <stas@php.net> |
1400 +----------------------------------------------------------------------+
1402 -#include "php_gd.h"
1406 +#include "php_gd.h"
1408 #define CTX_PUTC(c,ctx) ctx->putC(ctx, c)
1411 static void _php_image_output_putc(struct gdIOCtx *ctx, int c)
1413 /* without the following downcast, the write will fail
1419 -static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
1421 +/* {{{ _php_image_output_ctx */
1422 +static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
1424 - zval **imgind, **file, **quality;
1425 + zval **imgind, **file, **quality, **basefilter;
1429 int argc = ZEND_NUM_ARGS();
1434 - /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
1436 - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE)
1437 + /* The third (quality) parameter for Wbmp stands for the threshold when called from image2wbmp().
1438 + * The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called
1439 + * from imagey<type>().
1442 + if (argc < 2 && image_type == PHP_GDIMG_TYPE_XBM) {
1443 + WRONG_PARAM_COUNT;
1446 + if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc, &imgind, &file, &quality, &basefilter) == FAILURE)
1451 ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", phpi_get_le_gd());
1454 - convert_to_string_ex(file);
1455 + if (argc >= 2 && Z_TYPE_PP(file) != IS_NULL) {
1456 + convert_to_string_ex(file);
1458 fn = Z_STRVAL_PP(file);
1461 convert_to_long_ex(quality);
1462 - q = Z_LVAL_PP(quality);
1463 + q = Z_LVAL_PP(quality);/* or colorindex for foreground of BW images (defaults to black) */
1465 + convert_to_long_ex(basefilter);
1466 + f = Z_LVAL_PP(basefilter);
1471 - if ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))) {
1472 + if (argc > 1 && (Z_TYPE_PP(file) != IS_NULL && ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))))) {
1474 PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
1476 fp = VCWD_FOPEN(fn, "wb");
1478 - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn);
1479 + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing: %s", fn, strerror(errno));
1484 ctx->gd_free = _php_image_output_ctxfree;
1486 ctx->free = _php_image_output_ctxfree;
1490 #if APACHE && defined(CHARSET_EBCDIC)
1491 /* XXX this is unlikely to work any more thies@thieso.net */
1492 @@ -107,27 +125,48 @@
1493 case PHP_GDIMG_TYPE_JPG:
1494 (*func_p)(im, ctx, q);
1496 + case PHP_GDIMG_TYPE_PNG:
1497 + (*func_p)(im, ctx, q, f);
1499 + case PHP_GDIMG_TYPE_XBM:
1500 case PHP_GDIMG_TYPE_WBM:
1501 - for(i=0; i < gdImageColorsTotal(im); i++) {
1502 - if(gdImageRed(im, i) == 0) break;
1504 - (*func_p)(im, i, ctx);
1506 + for(i=0; i < gdImageColorsTotal(im); i++) {
1507 + if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
1511 + if (image_type == PHP_GDIMG_TYPE_XBM) {
1512 + (*func_p)(im, fn, q, ctx);
1514 + (*func_p)(im, q, ctx);
1541 + * Local variables:
1543 + * c-basic-offset: 4
1545 + * vim600: sw=4 ts=4 fdm=marker
1546 + * vim<600: sw=4 ts=4
1548 diff -urN php-4.4.8.org/ext/gd/gd.dsp php-4.4.8/ext/gd/gd.dsp
1549 --- php-4.4.8.org/ext/gd/gd.dsp 2007-05-03 04:55:11.000000000 +0200
1550 +++ php-4.4.8/ext/gd/gd.dsp 2008-01-22 22:38:05.887151436 +0100
1552 # ADD BASE BSC32 /nologo
\r
1553 # ADD BSC32 /nologo
\r
1555 -# ADD BASE LINK32 php4ts.lib libjpeg.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd2.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
\r
1556 +# ADD BASE LINK32 php5ts.lib libjpeg.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd2.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
\r
1557 # SUBTRACT BASE LINK32 /pdb:none
\r
1558 -# ADD LINK32 php4ts.lib freetype2.lib libjpeg.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd2.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\zlib\Release"
\r
1559 +# ADD LINK32 php5ts.lib freetype2.lib libjpeg.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd2.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\zlib\Release"
\r
1560 # SUBTRACT LINK32 /pdb:none
\r
1562 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1564 # ADD BASE BSC32 /nologo
\r
1565 # ADD BSC32 /nologo
\r
1567 -# ADD BASE LINK32 php4ts_debug.lib libjpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd2.dll" /libpath:"..\..\Debug_TS"
\r
1568 +# ADD BASE LINK32 php5ts_debug.lib libjpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd2.dll" /libpath:"..\..\Debug_TS"
\r
1569 # SUBTRACT BASE LINK32 /pdb:none
\r
1570 -# ADD LINK32 php4ts_debug.lib libpng.lib zlib.lib libjpeg.lib freetype2.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /nodefaultlib:"MSVCRT" /out:"..\..\Debug_TS/php_gd2.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\zlib\Debug"
\r
1571 +# ADD LINK32 php5ts_debug.lib libpng.lib zlib.lib libjpeg.lib freetype2.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd2.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\zlib\Debug"
\r
1572 # SUBTRACT LINK32 /pdb:none
\r
1576 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1578 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1584 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1586 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1592 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1594 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1600 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1602 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1608 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1610 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1615 @@ -216,18 +211,6 @@
1616 # Begin Source File
\r
1618 SOURCE=.\libgd\gd_gif_in.c
\r
1620 -!IF "$(CFG)" == "gd - Win32 Release_TS GD2"
\r
1622 -# PROP Intermediate_Dir "Release_TS_bundled"
\r
1624 -!ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1626 -# PROP Intermediate_Dir "Debug_TS_bundled"
\r
1632 # Begin Source File
\r
1635 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1637 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1643 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1645 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1651 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1653 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1659 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1661 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1667 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1669 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1674 @@ -324,17 +302,12 @@
1675 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1677 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1683 # Begin Source File
\r
1685 -SOURCE=.\libgd\gd_security.c
\r
1686 -# End Source File
\r
1687 -# Begin Source File
\r
1689 SOURCE=.\libgd\gd_ss.c
\r
1691 !IF "$(CFG)" == "gd - Win32 Release_TS GD2"
\r
1693 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1695 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1701 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1703 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1709 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1711 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1717 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1719 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1725 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1727 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1733 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1735 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1741 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1743 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1749 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1751 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1757 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1759 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1765 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1767 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1773 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1775 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1781 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1783 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1789 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1791 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1797 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1799 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1805 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1807 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1813 !ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
\r
1815 # PROP Intermediate_Dir "Debug_TS_bundled"
\r
1820 diff -urN php-4.4.8.org/ext/gd/gdttf.c php-4.4.8/ext/gd/gdttf.c
1821 --- php-4.4.8.org/ext/gd/gdttf.c 2005-01-09 22:05:31.000000000 +0100
1822 +++ php-4.4.8/ext/gd/gdttf.c 2008-01-22 22:38:05.887151436 +0100
1825 /* John Ellson ellson@lucent.com */
1833 /* number of fonts cached before least recently used is replaced */
1834 #define FONTCACHESIZE 6
1836 -/* number of character glyphs cached per font before
1837 +/* number of character glyphs cached per font before
1838 least-recently-used is replaced */
1839 #define GLYPHCACHESIZE 120
1841 -/* number of bitmaps cached per glyph before
1842 +/* number of bitmaps cached per glyph before
1843 least-recently-used is replaced */
1844 #define BITMAPCACHESIZE 8
1847 /* ptsize below which anti-aliasing is ineffective */
1848 #define MINANTIALIASPTSIZE 0
1850 -/* display resolution - (Not really. This has to be 72 or hinting is wrong) */
1851 +/* display resolution - (Not really. This has to be 72 or hinting is wrong) */
1852 #define RESOLUTION 72
1854 /* Number of colors used for anti-aliasing */
1858 -/* Line separation as a factor of font height.
1859 - No space between if LINESPACE = 1.00
1860 +/* Line separation as a factor of font height.
1861 + No space between if LINESPACE = 1.00
1862 Line separation will be rounded up to next pixel row*/
1863 #define LINESPACE 1.05
1871 unsigned char pixel; /* key */
1872 unsigned char bgcolor; /* key */
1873 int fgcolor; /* key */ /* -ve means no antialias */
1875 unsigned char bgcolor; /* key */
1876 int fgcolor; /* key */ /* -ve means no antialias */
1877 gdImagePtr im; /* key */
1881 /* forward declarations so that glyphCache can be initialized by font code */
1882 static int glyphTest ( void *element, void *key );
1885 *---------------------------------------------------------------------------
1889 #ifndef CHARSET_EBCDIC
1890 #define ASC(ch) (ch)
1891 #else /*CHARSET_EBCDIC*/
1892 @@ -205,17 +205,16 @@
1894 #define Tcl_UniChar int
1895 #define TCL_UTF_MAX 3
1897 -gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr)
1898 +static int gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr)
1899 /* str is the UTF8 next character pointer */
1900 /* chPtr is the int for the result */
1906 /* HTML4.0 entities in decimal form, e.g. Å */
1907 - byte = *((unsigned char *) str);
1908 + byte = *((unsigned char *) str);
1913 byte = *((unsigned char *) (str+1));
1916 byte = *((unsigned char *) (str+i));
1917 if (byte >= '0' && byte <= '9') {
1918 n = (n * 10) + (byte - '0');
1926 *chPtr = (Tcl_UniChar) n;
1927 @@ -233,105 +232,91 @@
1933 - * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones.
1936 - byte = ASC(*((unsigned char *) str));
1937 - if (byte < 0xC0) {
1939 - * Handles properly formed UTF-8 characters between 0x01 and 0x7F.
1940 - * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
1941 - * characters representing themselves.
1944 - *chPtr = (Tcl_UniChar) byte;
1946 - } else if (byte < 0xE0) {
1947 - if ((ASC(str[1]) & 0xC0) == 0x80) {
1949 - * Two-byte-character lead-byte followed by a trail-byte.
1952 - *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F));
1956 - * A two-byte-character lead-byte not followed by trail-byte
1957 - * represents itself.
1960 - *chPtr = (Tcl_UniChar) byte;
1962 - } else if (byte < 0xF0) {
1963 - if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) {
1965 - * Three-byte-character lead byte followed by two trail bytes.
1968 - *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12)
1969 - | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F));
1973 - * A three-byte-character lead-byte not followed by two trail-bytes
1974 - * represents itself.
1976 + /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */
1978 - *chPtr = (Tcl_UniChar) byte;
1981 + byte = ASC(*((unsigned char *) str));
1982 + if (byte < 0xC0) {
1984 + * Handles properly formed UTF-8 characters between 0x01 and 0x7F.
1985 + * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
1986 + * characters representing themselves.
1989 + *chPtr = (Tcl_UniChar) byte;
1991 + } else if (byte < 0xE0) {
1992 + if ((ASC(str[1]) & 0xC0) == 0x80) {
1993 + /* Two-byte-character lead-byte followed by a trail-byte. */
1995 + *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F));
1999 + * A two-byte-character lead-byte not followed by trail-byte
2000 + * represents itself.
2003 + *chPtr = (Tcl_UniChar) byte;
2005 + } else if (byte < 0xF0) {
2006 + if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) {
2007 + /* Three-byte-character lead byte followed by two trail bytes. */
2009 + *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F));
2012 + /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */
2014 + *chPtr = (Tcl_UniChar) byte;
2019 - int ch, total, trail;
2021 + int ch, total, trail;
2023 - total = totalBytes[byte];
2024 - trail = total - 1;
2026 - ch = byte & (0x3F >> trail);
2029 - if ((ASC(*str) & 0xC0) != 0x80) {
2034 - ch |= (ASC(*str) & 0x3F);
2036 - } while (trail > 0);
2039 + total = totalBytes[byte];
2040 + trail = total - 1;
2042 + ch = byte & (0x3F >> trail);
2045 + if ((ASC(*str) & 0xC0) != 0x80) {
2050 + ch |= (ASC(*str) & 0x3F);
2052 + } while (trail > 0);
2060 - *chPtr = (Tcl_UniChar) byte;
2062 + *chPtr = (Tcl_UniChar) byte;
2066 /********************************************************************/
2067 /* font cache functions */
2070 -fontTest ( void *element, void *key )
2071 +static int fontTest ( void *element, void *key )
2073 - font_t *a=(font_t *)element;
2074 - fontkey_t *b=(fontkey_t *)key;
2075 + font_t *a = (font_t *)element;
2076 + fontkey_t *b = (fontkey_t *)key;
2078 - return ( strcmp(a->fontname, b->fontname) == 0
2079 - && a->ptsize == b->ptsize
2080 - && a->angle == b->angle);
2081 + return (strcmp(a->fontname, b->fontname) == 0 && a->ptsize == b->ptsize && a->angle == b->angle);
2085 -fontFetch ( char **error, void *key )
2086 +static void * fontFetch ( char **error, void *key )
2090 - fontkey_t *b=(fontkey_t *)key;
2091 - int i, n, map_found;
2092 - short platform, encoding;
2095 + fontkey_t *b = (fontkey_t *)key;
2096 + int i, n, map_found;
2097 + short platform, encoding;
2100 a = (font_t *)pemalloc(sizeof(font_t), 1);
2102 if ((err = TT_Open_Face(*b->engine, a->fontname, &a->face))) {
2103 if (err == TT_Err_Could_Not_Open_File) {
2104 *error = "Could not find/open font";
2108 *error = "Could not read font";
2117 if (TT_Set_Instance_Resolutions(a->instance, RESOLUTION, RESOLUTION)) {
2118 *error = "Could not set device resolutions";
2120 @@ -384,12 +368,12 @@
2123 TT_Get_Instance_Metrics(a->instance, &a->imetrics);
2126 /* First, look for a Unicode charmap */
2127 n = TT_Get_CharMap_Count(a->face);
2129 for (i = 0; i < n; i++) {
2130 - TT_Get_CharMap_ID(a->face, i, &platform, &encoding);
2131 + TT_Get_CharMap_ID(a->face, i, &platform, &encoding);
2132 if ((platform == 3 && encoding == 1) /* Windows Unicode */
2133 || (platform == 2 && encoding == 1)
2134 || (platform == 0)) { /* ?? Unicode */
2139 - if (! map_found) {
2141 *error = "Unable to find a CharMap that I can handle";
2144 @@ -418,16 +402,14 @@
2145 a->matrix.xy = - a->matrix.yx;
2146 a->matrix.yy = a->matrix.xx;
2148 - a->glyphCache = gdCacheCreate( GLYPHCACHESIZE,
2149 - glyphTest, glyphFetch, glyphRelease);
2150 + a->glyphCache = gdCacheCreate(GLYPHCACHESIZE, glyphTest, glyphFetch, glyphRelease);
2156 -fontRelease( void *element )
2157 +static void fontRelease( void *element )
2159 - font_t *a=(font_t *)element;
2160 + font_t *a = (font_t *)element;
2162 gdCacheDelete(a->glyphCache);
2163 TT_Done_Instance(a->instance);
2164 @@ -439,26 +421,22 @@
2165 /********************************************************************/
2166 /* glyph cache functions */
2169 -glyphTest ( void *element, void *key )
2170 +static int glyphTest ( void *element, void *key )
2172 - glyph_t *a=(glyph_t *)element;
2173 - glyphkey_t *b=(glyphkey_t *)key;
2174 + glyph_t *a = (glyph_t *)element;
2175 + glyphkey_t *b = (glyphkey_t *)key;
2177 + return (a->character == b->character && a->hinting == b->hinting && a->gray_render == b->gray_render);
2180 - return (a->character == b->character
2181 - && a->hinting == b->hinting
2182 - && a->gray_render == b->gray_render);
2186 -glyphFetch ( char **error, void *key )
2189 - glyphkey_t *b=(glyphkey_t *)key;
2192 - int crect[8], xmin, xmax, ymin, ymax;
2193 - double cos_a, sin_a;
2194 +static void * glyphFetch ( char **error, void *key )
2197 + glyphkey_t *b = (glyphkey_t *)key;
2200 + int crect[8], xmin, xmax, ymin, ymax;
2201 + double cos_a, sin_a;
2203 a = (glyph_t *)pemalloc(sizeof(glyph_t), 1);
2204 a->character = b->character;
2205 @@ -523,38 +501,34 @@
2206 a->Bit.flow = TT_Flow_Up;
2207 if (a->gray_render) {
2208 a->Bit.cols = a->Bit.width; /* 1 byte per pixel */
2212 a->Bit.cols = (a->Bit.width + 7) / 8; /* 1 bit per pixel */
2214 a->Bit.cols = (a->Bit.cols + 3) & ~3; /* pad to 32 bits */
2215 a->Bit.size = a->Bit.rows * a->Bit.cols; /* # of bytes in buffer */
2216 a->Bit.bitmap = NULL;
2218 - a->bitmapCache = gdCacheCreate( BITMAPCACHESIZE,
2219 - bitmapTest, bitmapFetch, bitmapRelease);
2220 + a->bitmapCache = gdCacheCreate(BITMAPCACHESIZE, bitmapTest, bitmapFetch, bitmapRelease);
2226 -glyphRelease( void *element )
2227 +static void glyphRelease( void *element )
2229 - glyph_t *a=(glyph_t *)element;
2230 + glyph_t *a = (glyph_t *)element;
2232 gdCacheDelete(a->bitmapCache);
2233 - TT_Done_Glyph( a->glyph );
2234 - pefree ((char *)element, 1);
2235 + TT_Done_Glyph(a->glyph);
2236 + pefree((char *)element, 1);
2239 /********************************************************************/
2240 /* bitmap cache functions */
2243 -bitmapTest ( void *element, void *key )
2244 +static int bitmapTest ( void *element, void *key )
2246 - bitmap_t *a=(bitmap_t *)element;
2247 - bitmapkey_t *b=(bitmapkey_t *)key;
2248 + bitmap_t *a = (bitmap_t *)element;
2249 + bitmapkey_t *b = (bitmapkey_t *)key;
2251 if (a->xoffset == b->xoffset && a->yoffset == b->yoffset) {
2252 b->glyph->Bit.bitmap = a->bitmap;
2253 @@ -563,11 +537,10 @@
2258 -bitmapFetch ( char **error, void *key )
2259 +static void * bitmapFetch ( char **error, void *key )
2262 - bitmapkey_t *b=(bitmapkey_t *)key;
2264 + bitmapkey_t *b = (bitmapkey_t *)key;
2266 a = (bitmap_t *)pemalloc(sizeof(bitmap_t), 1);
2267 a->xoffset = b->xoffset;
2268 @@ -577,56 +550,47 @@
2269 memset(a->bitmap, 0, b->glyph->Bit.size);
2271 if (b->glyph->gray_render) {
2272 - TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit,
2273 - a->xoffset, a->yoffset);
2276 - TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit,
2277 - a->xoffset, a->yoffset);
2278 + TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset);
2280 + TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset);
2286 -bitmapRelease( void *element )
2287 +static void bitmapRelease( void *element )
2289 - bitmap_t *a=(bitmap_t *)element;
2290 + bitmap_t *a = (bitmap_t *)element;
2292 - pefree (a->bitmap, 1);
2293 - pefree ((char *)element, 1);
2294 + pefree(a->bitmap, 1);
2295 + pefree((char *)element, 1);
2298 /********************************************************************/
2299 /* tweencolor cache functions */
2302 -tweenColorTest (void *element, void *key)
2304 - tweencolor_t *a=(tweencolor_t *)element;
2305 - tweencolorkey_t *b=(tweencolorkey_t *)key;
2307 - return (a->pixel == b->pixel
2308 - && a->bgcolor == b->bgcolor
2309 - && a->fgcolor == b->fgcolor
2310 - && a->im == b->im);
2312 +static int tweenColorTest (void *element, void *key)
2314 + tweencolor_t *a = (tweencolor_t *)element;
2315 + tweencolorkey_t *b = (tweencolorkey_t *)key;
2317 + return (a->pixel == b->pixel && a->bgcolor == b->bgcolor && a->fgcolor == b->fgcolor && a->im == b->im);
2321 -tweenColorFetch (char **error, void *key)
2322 +static void * tweenColorFetch (char **error, void *key)
2325 - tweencolorkey_t *b=(tweencolorkey_t *)key;
2327 + tweencolorkey_t *b = (tweencolorkey_t *)key;
2328 int pixel, npixel, bg, fg;
2331 - a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1);
2333 + a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1);
2334 pixel = a->pixel = b->pixel;
2335 bg = a->bgcolor = b->bgcolor;
2336 fg = a->fgcolor = b->fgcolor;
2339 /* if fg is specified by a negative color idx, then don't antialias */
2342 a->tweencolor = -fg;
2344 npixel = NUMCOLORS - pixel;
2345 @@ -635,20 +599,19 @@
2346 (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS,
2347 (pixel * im->blue [fg] + npixel * im->blue [bg]) / NUMCOLORS);
2354 -tweenColorRelease(void *element)
2356 - pefree((char *)element, 1);
2362 +static void tweenColorRelease(void *element)
2364 + pefree((char *)element, 1);
2367 /********************************************************************/
2368 /* gdttfchar - render one character onto a gd image */
2370 -static int OneTime=0;
2371 +static int OneTime = 0;
2372 static gdCache_head_t *tweenColorCache;
2375 @@ -656,38 +619,37 @@
2376 int x, int y, /* string start pos in pixels */
2377 TT_F26Dot6 x1, TT_F26Dot6 y1, /* char start offset (*64) from x,y */
2378 TT_F26Dot6 *advance,
2386 - int x2, y2; /* char start pos in pixels */
2387 + int x2, y2; /* char start pos in pixels */
2388 int x3, y3; /* current pixel pos */
2389 unsigned char *pixel;
2392 - glyphkey_t glyphkey;
2393 - bitmapkey_t bitmapkey;
2395 + glyphkey_t glyphkey;
2396 + bitmapkey_t bitmapkey;
2397 tweencolor_t *tweencolor;
2398 tweencolorkey_t tweencolorkey;
2400 /****** set up tweenColorCache on first call ************/
2402 - tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE,
2403 - tweenColorTest, tweenColorFetch, tweenColorRelease);
2405 + tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE, tweenColorTest, tweenColorFetch, tweenColorRelease);
2410 if (font->have_char_map_Unicode) { /* use UTF-8 mapping from ASCII */
2411 - len = gdTcl_UtfToUniChar(*next, &ch);
2413 + len = gdTcl_UtfToUniChar(*next, &ch);
2418 - * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref:
2419 - * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs
2423 + * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref:
2424 + * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs
2426 ch = (**next) & 255; /* don't extend sign */
2428 if (ch >= 161 /* first code of JIS-8 pair */
2429 @@ -700,18 +662,20 @@
2430 glyphkey.character = ch;
2431 glyphkey.hinting = 1;
2432 /* if fg is specified by a negative color idx, then don't antialias */
2433 - glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg <0))?FALSE:TRUE;
2434 - glyphkey.font = font;
2435 - glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey);
2437 + glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg < 0)) ? FALSE : TRUE;
2438 + glyphkey.font = font;
2439 + glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey);
2441 return font->glyphCache->error;
2444 *bbox = &glyph->metrics.bbox;
2445 *advance = glyph->metrics.advance;
2447 /* if null *im, or invalid color, then assume user just wants brect */
2448 - if (!im || fg > 255 || fg < -255)
2449 + if (!im || fg > 255 || fg < -255) {
2450 return (char *)NULL;
2453 /* render (via cache) a bitmap for the current fractional offset */
2454 bitmapkey.xoffset = ((x1+32) & 63) - 32 - ((glyph->xmin+32) & -64);
2455 @@ -720,30 +684,32 @@
2456 gdCacheGet(glyph->bitmapCache, &bitmapkey);
2458 /* copy to gif, mapping colors */
2459 - x2 = x + (((glyph->xmin+32) & -64) + ((x1+32) & -64)) / 64;
2460 - y2 = y - (((glyph->ymin+32) & -64) + ((y1+32) & -64)) / 64;
2461 + x2 = x + (((glyph->xmin+32) & -64) + ((x1+32) & -64)) / 64;
2462 + y2 = y - (((glyph->ymin+32) & -64) + ((y1+32) & -64)) / 64;
2463 tweencolorkey.fgcolor = fg;
2464 tweencolorkey.im = im;
2465 for (row = 0; row < glyph->Bit.rows; row++) {
2466 - if (glyph->gray_render)
2467 + if (glyph->gray_render) {
2468 pc = row * glyph->Bit.cols;
2471 pc = row * glyph->Bit.cols * 8;
2474 - if (y3 >= im->sy || y3 < 0) continue;
2475 + if (y3 >= im->sy || y3 < 0) {
2478 for (col = 0; col < glyph->Bit.width; col++, pc++) {
2479 if (glyph->gray_render) {
2480 - tweencolorkey.pixel =
2481 - *((unsigned char *)(glyph->Bit.bitmap) + pc);
2482 + tweencolorkey.pixel = *((unsigned char *)(glyph->Bit.bitmap) + pc);
2484 - tweencolorkey.pixel =
2485 - (((*((unsigned char *)(glyph->Bit.bitmap) + pc/8))
2486 - <<(pc%8))&128)?4:0;
2487 + tweencolorkey.pixel = (((*((unsigned char *)(glyph->Bit.bitmap) + pc/8)) << (pc%8))&128)?4:0;
2489 /* if not background */
2490 if (tweencolorkey.pixel > 0) {
2492 - if (x3 >= im->sx || x3 < 0) continue;
2493 + if (x3 >= im->sx || x3 < 0) {
2497 if (im->trueColor) {
2498 pixel = &im->tpixels[y3][x3];
2502 tweencolorkey.bgcolor = *pixel;
2503 - tweencolor = (tweencolor_t *)gdCacheGet(
2504 - tweenColorCache, &tweencolorkey);
2505 + tweencolor = (tweencolor_t *)gdCacheGet(tweenColorCache, &tweencolorkey);
2506 *pixel = tweencolor->tweencolor;
2509 @@ -769,29 +734,26 @@
2510 /********************************************************************/
2511 /* gdttf - render a utf8 string onto a gd image */
2514 -gdttf(gdImage *im, int *brect, int fg, char *fontname,
2515 - double ptsize, double angle, int x, int y, char *str)
2516 +char * gdttf(gdImage *im, int *brect, int fg, char *fontname, double ptsize, double angle, int x, int y, char *str)
2518 - TT_F26Dot6 ur_x=0, ur_y=0, ll_x=0, ll_y=0;
2519 + TT_F26Dot6 ur_x = 0, ur_y = 0, ll_x = 0, ll_y = 0;
2520 TT_F26Dot6 advance_x, advance_y, advance, x1, y1;
2522 double sin_a, cos_a;
2529 /****** initialize font engine on first call ************/
2530 - static gdCache_head_t *fontCache;
2531 + static gdCache_head_t *fontCache;
2532 static TT_Engine engine;
2534 - if (! fontCache) {
2536 if (TT_Init_FreeType(&engine)) {
2537 return "Failure to initialize font engine";
2539 - fontCache = gdCacheCreate( FONTCACHESIZE,
2540 - fontTest, fontFetch, fontRelease);
2541 + fontCache = gdCacheCreate(FONTCACHESIZE, fontTest, fontFetch, fontRelease);
2545 @@ -801,15 +763,15 @@
2546 fontkey.angle = angle;
2547 fontkey.engine = &engine;
2548 font = (font_t *)gdCacheGet(fontCache, &fontkey);
2551 return fontCache->error;
2553 sin_a = font->sin_a;
2554 cos_a = font->cos_a;
2555 advance_x = advance_y = 0;
2563 /* carriage returns */
2568 - advance_y -= (TT_F26Dot6)(font->imetrics.y_ppem * LINESPACE * 64);
2569 - advance_y = (advance_y-32) & -64; /* round to next pixel row */
2570 + advance_y -= (TT_F26Dot6)(font->imetrics.y_ppem * LINESPACE * 64);
2571 + advance_y = (advance_y-32) & -64; /* round to next pixel row */
2575 @@ -829,20 +791,24 @@
2576 x1 = (TT_F26Dot6)(advance_x * cos_a - advance_y * sin_a);
2577 y1 = (TT_F26Dot6)(advance_x * sin_a + advance_y * cos_a);
2579 - if ((error=gdttfchar(im, fg, font, x, y, x1, y1, &advance, &bbox, &next)))
2580 + if ((error = gdttfchar(im, fg, font, x, y, x1, y1, &advance, &bbox, &next))) {
2584 - if (! i++) { /* if first character, init BB corner values */
2585 + if (!i++) { /* if first character, init BB corner values */
2592 - if (! advance_x) ll_x = MIN(bbox->xMin, ll_x);
2595 + ll_x = MIN(bbox->xMin, ll_x);
2597 ll_y = MIN(advance_y + bbox->yMin, ll_y);
2598 ur_x = MAX(advance_x + bbox->xMax, ur_x);
2599 - if (! advance_y) ur_y = MAX(bbox->yMax, ur_y);
2601 + ur_y = MAX(bbox->yMax, ur_y);
2604 advance_x += advance;
2608 /* scale, round and offset brect */
2612 brect[i] = x + (brect[i] + 32) / 64;
2614 brect[i] = y - (brect[i] + 32) / 64;
2617 return (char *)NULL;
2621 #endif /* HAVE_LIBTTF */
2624 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
2625 --- php-4.4.8.org/ext/gd/libgd/gd_arc_f_buggy.c 2003-03-05 17:04:20.000000000 +0100
2626 +++ php-4.4.8/ext/gd/libgd/gd_arc_f_buggy.c 2005-08-18 14:54:43.000000000 +0200
2628 /* This is potentially great stuff, but fails against the test
2629 - program at the end. This would probably be much more
2630 - efficent than the implementation currently in gd.c if the
2631 + program at the end. This would probably be much more
2632 + efficent than the implementation currently in gd.c if the
2633 errors in the output were corrected. TBB */
2642 main (int argc, char *argv[])
2644 gdImagePtr im = gdImageCreate (WIDTH, HEIGHT);
2645 @@ -726,12 +726,12 @@
2646 out = fopen ("test/arctest.png", "wb");
2649 - php_gd_error("Can't create test/arctest.png\n");
2650 + php_gd_error("Can't create test/arctest.png");
2653 gdImagePng (im, out);
2655 - php_gd_error("Test image written to test/arctest.png\n");
2656 + php_gd_error("Test image written to test/arctest.png");
2658 gdImageDestroy (im);
2660 diff -urN php-4.4.8.org/ext/gd/libgd/gd.c php-4.4.8/ext/gd/libgd/gd.c
2661 --- php-4.4.8.org/ext/gd/libgd/gd.c 2007-10-20 17:29:04.000000000 +0200
2662 +++ php-4.4.8/ext/gd/libgd/gd.c 2007-11-05 00:56:00.000000000 +0100
2670 static void gdImageBrushApply(gdImagePtr im, int x, int y);
2671 static void gdImageTileApply(gdImagePtr im, int x, int y);
2672 static void gdImageAntiAliasedApply(gdImagePtr im, int x, int y);
2673 -static int gdFullAlphaBlend(int dst, int src);
2674 static int gdLayerOverlay(int dst, int src);
2675 -static int gdAlphaBlendColor(int b1, int b2, int a1, int a2);
2676 static int gdAlphaOverlayColor(int src, int dst, int max);
2677 int gdImageGetTrueColorPixel(gdImagePtr im, int x, int y);
2679 -void php_gd_error_ex(int type, const char *format, ...)
2680 +void php_gd_error_ex(int type, const char *format, ...)
2688 va_start(args, format);
2689 php_verror(NULL, "", type, format, args TSRMLS_CC);
2692 void php_gd_error(const char *format, ...)
2700 va_start(args, format);
2701 php_verror(NULL, "", E_WARNING, format, args TSRMLS_CC);
2703 @@ -122,11 +120,20 @@
2707 - im = (gdImage *) gdMalloc(sizeof(gdImage));
2708 - memset(im, 0, sizeof(gdImage));
2710 + if (overflow2(sx, sy)) {
2714 + if (overflow2(sizeof(unsigned char *), sy)) {
2718 + im = (gdImage *) gdCalloc(1, sizeof(gdImage));
2720 /* Row-major ever since gd 1.3 */
2721 - im->pixels = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0);
2722 - im->AA_opacity = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0);
2723 + im->pixels = (unsigned char **) gdMalloc(sizeof(unsigned char *) * sy);
2724 + im->AA_opacity = (unsigned char **) gdMalloc(sizeof(unsigned char *) * sy);
2726 im->polyAllocated = 0;
2728 @@ -164,10 +171,23 @@
2733 + if (overflow2(sx, sy)) {
2737 + if (overflow2(sizeof(unsigned char *), sy)) {
2741 + if (overflow2(sizeof(int), sx)) {
2745 im = (gdImage *) gdMalloc(sizeof(gdImage));
2746 memset(im, 0, sizeof(gdImage));
2747 - im->tpixels = (int **) safe_emalloc(sizeof(int *), sy, 0);
2748 - im->AA_opacity = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0);
2749 + im->tpixels = (int **) gdMalloc(sizeof(int *) * sy);
2750 + im->AA_opacity = (unsigned char **) gdMalloc(sizeof(unsigned char *) * sy);
2752 im->polyAllocated = 0;
2757 /* This code is taken from http://www.acm.org/jgt/papers/SmithLyons96/hwb_rgb.html, an article
2758 - * on colour conversion to/from RBG and HWB colour systems.
2759 - * It has been modified to return the converted value as a * parameter.
2760 + * on colour conversion to/from RBG and HWB colour systems.
2761 + * It has been modified to return the converted value as a * parameter.
2764 #define RETURN_HWB(h, w, b) {HWB->H = h; HWB->W = w; HWB->B = b; return HWB;}
2769 - * Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. Pure
2770 - * red always maps to 6 in this implementation. Therefore UNDEFINED can be
2771 + * Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. Pure
2772 + * red always maps to 6 in this implementation. Therefore UNDEFINED can be
2773 * defined as 0 in situations where only unsigned numbers are desired.
2777 static HWBType * RGB_to_HWB (RGBType RGB, HWBType * HWB)
2780 - * RGB are each on [0, 1]. W and B are returned on [0, 1] and H is
2781 - * returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B.
2782 + * RGB are each on [0, 1]. W and B are returned on [0, 1] and H is
2783 + * returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B.
2786 float R = RGB.R, G = RGB.G, B = RGB.B, w, v, b, f;
2789 f = (R == w) ? G - B : ((G == w) ? B - R : R - G);
2790 i = (R == w) ? 3 : ((G == w) ? 5 : 1);
2793 RETURN_HWB(i - f / (v - w), w, b);
2798 static RGBType * HWB_to_RGB (HWBType HWB, RGBType * RGB)
2801 - * H is given on [0, 6] or UNDEFINED. W and B are given on [0, 1].
2802 - * RGB are each returned on [0, 1].
2804 + * H is given on [0, 6] or UNDEFINED. W and B are given on [0, 1].
2805 + * RGB are each returned on [0, 1].
2808 float h = HWB.H, w = HWB.W, b = HWB.B, v, n, f;
2819 * Given the end points of a line, and a bounding rectangle (which we
2820 * know to be from (0,0) to (SX,SY)), adjust the endpoints to be on
2821 * the edges of the rectangle if the line should be drawn at all,
2822 - * otherwise return a failure code
2823 + * otherwise return a failure code
2826 /* this does "one-dimensional" clipping: note that the second time it
2828 * - the comments ignore this (if you can understand it when it's
2829 * looking at the X parameters, it should become clear what happens on
2830 * the second call!) The code is simplified from that in the article,
2831 - * as we know that gd images always start at (0,0)
2832 + * as we know that gd images always start at (0,0)
2835 static int clip_1d(int *x0, int *y0, int *x1, int *y1, int maxdim) {
2838 m = (*y1 - *y0)/(double)(*x1 - *x0); /* calculate the slope of the line */
2839 *y0 += (int)(m * (maxdim - *x0)); /* adjust so point is on the right boundary */
2842 /* now, perhaps, adjust the end of the line */
2844 *y1 -= (int)(m * *x1);
2846 im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color);
2848 case gdEffectNormal:
2849 - im->tpixels[y][x] = gdFullAlphaBlend(im->tpixels[y][x], color);
2850 + im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color);
2852 case gdEffectOverlay :
2853 im->tpixels[y][x] = gdLayerOverlay(im->tpixels[y][x], color);
2855 int p = gdImageGetPixel(im, x, y);
2857 if (!im->trueColor) {
2858 - return gdTrueColorAlpha(im->red[p], im->green[p], im->blue[p], (im->transparent == p) ? gdAlphaTransparent : gdAlphaOpaque);
2859 + return gdTrueColorAlpha(im->red[p], im->green[p], im->blue[p], (im->transparent == p) ? gdAlphaTransparent : im->alpha[p]);
2865 x2 = x1 + gdImageSX(im->brush);
2869 if (im->trueColor) {
2870 if (im->brush->trueColor) {
2871 for (ly = y1; ly < y2; ly++) {
2873 if (p != gdImageGetTransparent(im->brush)) {
2874 /* Truecolor brush. Very slow on a palette destination. */
2875 if (im->brush->trueColor) {
2876 - gdImageSetPixel(im, lx, ly, gdImageColorResolveAlpha(im, gdTrueColorGetRed(p),
2877 - gdTrueColorGetGreen(p),
2878 + gdImageSetPixel(im, lx, ly, gdImageColorResolveAlpha(im, gdTrueColorGetRed(p),
2879 + gdTrueColorGetGreen(p),
2880 gdTrueColorGetBlue(p),
2881 gdTrueColorGetAlpha(p)));
2884 srcy = y % gdImageSY(im->tile);
2885 if (im->trueColor) {
2886 p = gdImageGetTrueColorPixel(im->tile, srcx, srcy);
2887 - gdImageSetPixel(im, x, y, p);
2888 + if (p != gdImageGetTransparent (im->tile)) {
2889 + gdImageSetPixel(im, x, y, p);
2892 p = gdImageGetPixel(im->tile, srcx, srcy);
2893 /* Allow for transparency */
2895 float p_dist, p_alpha;
2896 unsigned char opacity;
2899 - * Find the perpendicular distance from point C (px, py) to the line
2901 + * Find the perpendicular distance from point C (px, py) to the line
2902 * segment AB that is being drawn. (Adapted from an algorithm from the
2903 * comp.graphics.algorithms FAQ.)
2906 int By_Cy = im->AAL_y2 - py;
2908 /* 2.0.13: bounds check! AA_opacity is just as capable of
2909 - * overflowing as the main pixel array. Arne Jorgensen.
2910 + * overflowing as the main pixel array. Arne Jorgensen.
2911 * 2.0.14: typo fixed. 2.0.15: moved down below declarations
2912 * to satisfy non-C++ compilers.
2914 @@ -931,12 +953,12 @@
2915 LBC_2 = (Bx_Cx * Bx_Cx) + (By_Cy * By_Cy);
2917 if (((im->AAL_LAB_2 + LAC_2) >= LBC_2) && ((im->AAL_LAB_2 + LBC_2) >= LAC_2)) {
2918 - /* The two angles are acute. The point lies inside the portion of the
2919 + /* The two angles are acute. The point lies inside the portion of the
2920 * plane spanned by the line segment.
2922 p_dist = fabs ((float) ((Ay_Cy * im->AAL_Bx_Ax) - (Ax_Cx * im->AAL_By_Ay)) / im->AAL_LAB);
2924 - /* The point is past an end of the line segment. It's length from the
2925 + /* The point is past an end of the line segment. It's length from the
2926 * segment is the shorter of the lengths from the endpoints, but call
2927 * the distance -1, so as not to compute the alpha nor draw the pixel.
2929 @@ -1017,6 +1039,43 @@
2933 +static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col)
2935 + if (im->thick > 1) {
2936 + int thickhalf = im->thick >> 1;
2937 + gdImageFilledRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col);
2945 + for (;x1 <= x2; x1++) {
2946 + gdImageSetPixel(im, x1, y, col);
2952 +static void gdImageVLine(gdImagePtr im, int x, int y1, int y2, int col)
2954 + if (im->thick > 1) {
2955 + int thickhalf = im->thick >> 1;
2956 + gdImageFilledRectangle(im, x - thickhalf, y1, x + im->thick - thickhalf - 1, y2, col);
2964 + for (;y1 <= y2; y1++) {
2965 + gdImageSetPixel(im, x, y1, col);
2971 /* Bresenham as presented in Foley & Van Dam */
2972 void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
2973 @@ -1026,39 +1085,47 @@
2975 int thick = im->thick;
2977 + if (color == gdAntiAliased)
2980 + gdAntiAliased passed as color: use the much faster, much cheaper
2981 + and equally attractive gdImageAALine implementation. That
2982 + clips too, so don't clip twice.
2984 + gdImageAALine(im, x1, y1, x2, y2, im->AA_color);
2988 /* 2.0.10: Nick Atty: clip to edges of drawing rectangle, return if no points need to be drawn */
2989 if (!clip_1d(&x1,&y1,&x2,&y2,gdImageSX(im)) || !clip_1d(&y1,&x1,&y2,&x2,gdImageSY(im))) {
2993 - /* gdAntiAliased passed as color: set anti-aliased line (AAL) global vars. */
2994 - if (color == gdAntiAliased) {
3000 - /* Compute what we can for point-to-line distance calculation later. */
3001 - im->AAL_Bx_Ax = x2 - x1;
3002 - im->AAL_By_Ay = y2 - y1;
3003 - im->AAL_LAB_2 = (im->AAL_Bx_Ax * im->AAL_Bx_Ax) + (im->AAL_By_Ay * im->AAL_By_Ay);
3004 - im->AAL_LAB = sqrt (im->AAL_LAB_2);
3005 + dx = abs (x2 - x1);
3006 + dy = abs (y2 - y1);
3008 - /* For AA, we must draw pixels outside the width of the line. Keep in
3009 - * mind that this will be curtailed by cos/sin of theta later.
3013 + gdImageVLine(im, x1, y1, y2, color);
3015 + } else if (dy == 0) {
3016 + gdImageHLine(im, y1, x1, x2, color);
3020 - dx = abs(x2 - x1);
3021 - dy = abs(y2 - y1);
3024 /* More-or-less horizontal. use wid for vertical stroke */
3025 /* Doug Claar: watch out for NaN in atan2 (2.0.5) */
3026 if ((dx == 0) && (dy == 0)) {
3029 - wid = (int)(thick * cos (atan2 (dy, dx)));
3030 + /* 2.0.12: Michael Schwartz: divide rather than multiply;
3031 +TBB: but watch out for /0! */
3032 + double ac = cos (atan2 (dy, dx));
3041 @@ -1115,16 +1182,17 @@
3044 /* More-or-less vertical. use wid for horizontal stroke */
3045 - /* 2.0.12: Michael Schwartz: divide rather than multiply;
3046 - TBB: but watch out for /0! */
3047 - double as = sin(atan2(dy, dx));
3048 + /* 2.0.12: Michael Schwartz: divide rather than multiply;
3049 + TBB: but watch out for /0! */
3050 + double as = sin (atan2 (dy, dx));
3052 - if (!(wid = thick / as)) {
3065 @@ -1177,11 +1245,6 @@
3070 - /* If this is the only line we are drawing, go ahead and blend. */
3071 - if (color == gdAntiAliased && !im->AA_polygon) {
3072 - gdImageAABlend(im);
3077 @@ -1207,7 +1270,7 @@
3078 BLEND_COLOR(t, dg, g, dg);
3079 BLEND_COLOR(t, db, b, db);
3080 im->tpixels[y][x]=gdTrueColorAlpha(dr, dg, db, gdAlphaOpaque);
3085 * Added on 2003/12 by Pierre-Alain Joye (pajoye@pearfr.org)
3086 @@ -1586,9 +1649,9 @@
3088 /* s and e are integers modulo 360 (degrees), with 0 degrees
3089 being the rightmost extreme and degrees changing clockwise.
3090 - cx and cy are the center in pixels; w and h are the horizontal
3091 + cx and cy are the center in pixels; w and h are the horizontal
3092 and vertical diameter in pixels. Nice interface, but slow.
3093 - See gd_arc_f_buggy.c for a better version that doesn't
3094 + See gd_arc_f_buggy.c for a better version that doesn't
3095 seem to be bug-free yet. */
3097 void gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
3098 @@ -1607,29 +1670,30 @@
3102 - if ((s % 360) == (e % 360)) {
3104 + if ((s % 360) == (e % 360)) {
3144 for (i = s; i <= e; i++) {
3146 @@ -1787,17 +1851,15 @@
3149 int leftLimit = -1, rightLimit;
3150 - int i, restoreAlphaBleding=0;
3151 + int i, restoreAlphaBlending = 0;
3154 /* Refuse to fill to a non-solid border */
3158 - if (im->alphaBlendingFlag) {
3159 - restoreAlphaBleding = 1;
3160 - im->alphaBlendingFlag = 0;
3162 + restoreAlphaBlending = im->alphaBlendingFlag;
3163 + im->alphaBlendingFlag = 0;
3167 @@ -1814,9 +1876,7 @@
3170 if (leftLimit == -1) {
3171 - if (restoreAlphaBleding) {
3172 - im->alphaBlendingFlag = 1;
3174 + im->alphaBlendingFlag = restoreAlphaBlending;
3178 @@ -1844,6 +1904,7 @@
3184 if (y < ((im->sy) - 1)) {
3186 @@ -1860,12 +1921,9 @@
3190 - if (restoreAlphaBleding) {
3191 - im->alphaBlendingFlag = 1;
3193 + im->alphaBlendingFlag = restoreAlphaBlending;
3198 * set the pixel at (x,y) and its 4-connected neighbors
3199 * with the same pixel value to the new pixel value nc (new color).
3200 @@ -1888,25 +1946,31 @@
3201 #define FILL_POP(Y, XL, XR, DY) \
3202 {sp--; Y = sp->y+(DY = sp->dy); XL = sp->xl; XR = sp->xr;}
3204 -void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc);
3205 +static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc);
3207 void gdImageFill(gdImagePtr im, int x, int y, int nc)
3210 int oc; /* old pixel value */
3213 int alphablending_bak;
3215 /* stack of filled segments */
3216 /* struct seg stack[FILL_MAX],*sp = stack;; */
3217 - struct seg *stack;
3218 + struct seg *stack = NULL;
3221 + if (!im->trueColor && nc > (im->colorsTotal -1)) {
3225 alphablending_bak = im->alphaBlendingFlag;
3226 im->alphaBlendingFlag = 0;
3229 _gdImageFillTiled(im,x,y,nc);
3230 - im->alphaBlendingFlag = alphablending_bak;
3231 + im->alphaBlendingFlag = alphablending_bak;
3235 @@ -1916,8 +1980,31 @@
3236 im->alphaBlendingFlag = alphablending_bak;
3240 - stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1);
3242 + /* Do not use the 4 neighbors implementation with
3246 + int ix = x, iy = y, c;
3248 + c = gdImageGetPixel(im, ix, iy);
3252 + gdImageSetPixel(im, ix, iy, nc);
3253 + } while(ix++ < (im->sx -1));
3254 + ix = x; iy = y + 1;
3256 + c = gdImageGetPixel(im, ix, iy);
3260 + gdImageSetPixel(im, ix, iy, nc);
3261 + } while(ix++ < (im->sx -1));
3265 + stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1);
3269 @@ -1954,22 +2041,25 @@
3277 im->alphaBlendingFlag = alphablending_bak;
3280 -void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
3281 +static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
3283 - int i,l, x1, x2, dy;
3284 + int i, l, x1, x2, dy;
3285 int oc; /* old pixel value */
3288 /* stack of filled segments */
3299 @@ -1977,30 +2067,26 @@
3300 tiled = nc==gdTiled;
3302 nc = gdImageTileGet(im,x,y);
3303 - pts = (int **) ecalloc(sizeof(int *) * im->sy, sizeof(int));
3305 - for (i=0; i<im->sy;i++) {
3306 - pts[i] = (int *) ecalloc(im->sx, sizeof(int));
3307 + pts = (char **) ecalloc(im->sy + 1, sizeof(char *));
3308 + for (i = 0; i < im->sy + 1; i++) {
3309 + pts[i] = (char *) ecalloc(im->sx + 1, sizeof(char));
3312 - stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1);
3313 + stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1);
3316 oc = gdImageGetPixel(im, x, y);
3321 /* seed segment (popped 1st) */
3322 FILL_PUSH(y+1, x, x, -1);
3324 FILL_POP(y, x1, x2, dy);
3325 for (x=x1; x>=0 && (!pts[y][x] && gdImageGetPixel(im,x,y)==oc); x--) {
3327 - /* we should never be here */
3330 nc = gdImageTileGet(im,x,y);
3333 gdImageSetPixel(im,x, y, nc);
3336 @@ -2014,13 +2100,9 @@
3340 - for (; x<=wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc) ; x++) {
3342 - /* we should never be here */
3345 + for(; x<wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc); x++) {
3346 nc = gdImageTileGet(im,x,y);
3349 gdImageSetPixel(im, x, y, nc);
3351 FILL_PUSH(y, l, x-1, dy);
3352 @@ -2028,13 +2110,15 @@
3354 FILL_PUSH(y, x2+1, x-1, -dy);
3356 -skip: for (x++; x<=x2 && (pts[y][x] || gdImageGetPixel(im,x, y)!=oc); x++);
3357 +skip: for(x++; x<=x2 && (pts[y][x] || gdImageGetPixel(im,x, y)!=oc); x++);
3361 - for (i=0; i<im->sy;i++) {
3363 + for(i = 0; i < im->sy + 1; i++) {
3370 @@ -2048,6 +2132,11 @@
3374 + if (x1 == x2 && y1 == y2 && thick == 1) {
3375 + gdImageSetPixel(im, x1, y1, color);
3382 @@ -2110,16 +2199,15 @@
3383 gdImageLine(im, x1v, y1v, x1v, y2v, color);
3384 gdImageLine(im, x2v, y1v, x2v, y2v, color);
3389 void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
3394 /* Nick Atty: limit the points at the edge. Note that this also
3395 * nicely kills any plotting for rectangles completely outside the
3396 - * window as it makes the tests in the for loops fail
3397 + * window as it makes the tests in the for loops fail
3401 @@ -2133,15 +2221,15 @@
3402 if (y1 > gdImageSY(im)) {
3424 for (y = y1; (y <= y2); y++) {
3425 @@ -2162,9 +2250,9 @@
3426 if (dst->trueColor) {
3427 /* 2.0: much easier when the destination is truecolor. */
3428 /* 2.0.10: needs a transparent-index check that is still valid if
3429 - * the source is not truecolor. Thanks to Frank Warmerdam.
3430 + * the source is not truecolor. Thanks to Frank Warmerdam.
3434 if (src->trueColor) {
3435 for (y = 0; (y < h); y++) {
3436 for (x = 0; (x < w); x++) {
3437 @@ -2178,7 +2266,7 @@
3438 for (x = 0; (x < w); x++) {
3439 int c = gdImageGetPixel (src, srcX + x, srcY + y);
3440 if (c != src->transparent) {
3441 - gdImageSetPixel (dst, dstX + x, dstY + y, gdTrueColor(src->red[c], src->green[c], src->blue[c]));
3442 + gdImageSetPixel(dst, dstX + x, dstY + y, gdTrueColorAlpha(src->red[c], src->green[c], src->blue[c], src->alpha[c]));
3446 @@ -2225,7 +2313,7 @@
3447 /* Have we established a mapping for this color? */
3448 if (src->trueColor) {
3449 /* 2.05: remap to the palette available in the destination image. This is slow and
3450 - * works badly, but it beats crashing! Thanks to Padhrig McCarthy.
3451 + * works badly, but it beats crashing! Thanks to Padhrig McCarthy.
3453 mapTo = gdImageColorResolveAlpha (dst, gdTrueColorGetRed (c), gdTrueColorGetGreen (c), gdTrueColorGetBlue (c), gdTrueColorGetAlpha (c));
3454 } else if (colorMap[c] == (-1)) {
3455 @@ -2237,9 +2325,9 @@
3456 nc = gdImageColorResolveAlpha (dst, src->red[c], src->green[c], src->blue[c], src->alpha[c]);
3459 - mapTo = colorMap[c];
3460 + mapTo = colorMap[c];
3462 - mapTo = colorMap[c];
3463 + mapTo = colorMap[c];
3465 gdImageSetPixel (dst, tox, toy, mapTo);
3467 @@ -2257,7 +2345,7 @@
3473 for (y = srcY; y < (srcY + h); y++) {
3475 for (x = srcX; x < (srcX + w); x++) {
3476 @@ -2304,15 +2392,17 @@
3477 for (x = srcX; (x < (srcX + w)); x++) {
3479 c = gdImageGetPixel (src, x, y);
3481 /* Added 7/24/95: support transparent copies */
3482 if (gdImageGetTransparent(src) == c) {
3487 - * If it's the same image, mapping is NOT trivial since we
3488 - * merge with greyscale target, but if pct is 100, the grey
3489 - * value is not used, so it becomes trivial. pjw 2.0.12.
3492 + * If it's the same image, mapping is NOT trivial since we
3493 + * merge with greyscale target, but if pct is 100, the grey
3494 + * value is not used, so it becomes trivial. pjw 2.0.12.
3496 if (dst == src && pct == 100) {
3498 @@ -2320,9 +2410,10 @@
3499 dc = gdImageGetPixel(dst, tox, toy);
3500 g = (0.29900f * gdImageRed(dst, dc)) + (0.58700f * gdImageGreen(dst, dc)) + (0.11400f * gdImageBlue(dst, dc));
3502 - ncR = (int)(gdImageRed (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3503 - ncG = (int)(gdImageGreen (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3504 - ncB = (int)(gdImageBlue (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3505 + ncR = (int)(gdImageRed (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3506 + ncG = (int)(gdImageGreen (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3507 + ncB = (int)(gdImageBlue (src, c) * (pct / 100.0f) + g * ((100 - pct) / 100.0));
3510 /* First look for an exact match */
3511 nc = gdImageColorExact(dst, ncR, ncG, ncB);
3512 @@ -2354,10 +2445,18 @@
3514 /* We only need to use floating point to determine the correct stretch vector for one line's worth. */
3516 - stx = (int *) safe_emalloc(sizeof(int), srcW, 0);
3517 - sty = (int *) safe_emalloc(sizeof(int), srcH, 0);
3520 + if (overflow2(sizeof(int), srcW)) {
3523 + if (overflow2(sizeof(int), srcH)) {
3527 + stx = (int *) gdMalloc (sizeof (int) * srcW);
3528 + sty = (int *) gdMalloc (sizeof (int) * srcH);
3531 /* Fixed by Mao Morimoto 2.0.16 */
3532 for (i = 0; (i < srcW); i++) {
3533 stx[i] = dstW * (i+1) / srcW - dstW * i / srcW ;
3534 @@ -2387,7 +2486,7 @@
3535 /* 2.0.21, TK: not tox++ */
3536 tox += stx[x - srcX];
3541 /* TK: old code follows */
3542 mapTo = gdImageGetTrueColorPixel (src, x, y);
3543 @@ -2397,7 +2496,7 @@
3544 tox += stx[x - srcX];
3550 c = gdImageGetPixel (src, x, y);
3551 /* Added 7/24/95: support transparent copies */
3552 @@ -2451,6 +2550,7 @@
3555 double sy1, sy2, sx1, sx2;
3557 if (!dst->trueColor) {
3558 gdImageCopyResized (dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
3560 @@ -2497,7 +2597,7 @@
3562 pcontribution = xportion * yportion;
3563 p = gdImageGetTrueColorPixel(src, (int) sx + srcX, (int) sy + srcY);
3566 alpha_factor = ((gdAlphaMax - gdTrueColorGetAlpha(p))) * pcontribution;
3567 red += gdTrueColorGetRed (p) * alpha_factor;
3568 green += gdTrueColorGetGreen (p) * alpha_factor;
3569 @@ -2509,12 +2609,12 @@
3582 if (spixels != 0.0f) {
3585 @@ -2524,7 +2624,7 @@
3586 if ( alpha_sum != 0.0f) {
3587 if( contrib_sum != 0.0f) {
3588 alpha_sum /= contrib_sum;
3594 @@ -2549,7 +2649,7 @@
3598 - * Rotate function Added on 2003/12
3599 + * Rotate function Added on 2003/12
3600 * by Pierre-Alain Joye (pajoye@pearfr.org)
3602 /* Begin rotate function */
3603 @@ -2558,7 +2658,7 @@
3604 #endif /* ROTATE_PI */
3606 #define ROTATE_DEG2RAD 3.1415926535897932384626433832795/180
3607 -void gdImageSkewX (gdImagePtr dst, gdImagePtr src, int uRow, int iOffset, double dWeight, int clrBack)
3608 +void gdImageSkewX (gdImagePtr dst, gdImagePtr src, int uRow, int iOffset, double dWeight, int clrBack, int ignoretransparent)
3610 typedef int (*FuncPtr)(gdImagePtr, int, int);
3611 int i, r, g, b, a, clrBackR, clrBackG, clrBackB, clrBackA;
3612 @@ -2623,10 +2723,14 @@
3616 - pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3617 + if (ignoretransparent && pxlSrc == dst->transparent) {
3618 + pxlSrc = dst->transparent;
3620 + pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3622 - if (pxlSrc == -1) {
3623 - pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3624 + if (pxlSrc == -1) {
3625 + pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3629 if ((i + iOffset >= 0) && (i + iOffset < dst->sx)) {
3630 @@ -2651,7 +2755,7 @@
3634 -void gdImageSkewY (gdImagePtr dst, gdImagePtr src, int uCol, int iOffset, double dWeight, int clrBack)
3635 +void gdImageSkewY (gdImagePtr dst, gdImagePtr src, int uCol, int iOffset, double dWeight, int clrBack, int ignoretransparent)
3637 typedef int (*FuncPtr)(gdImagePtr, int, int);
3638 int i, iYPos=0, r, g, b, a;
3639 @@ -2710,10 +2814,14 @@
3643 - pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3644 + if (ignoretransparent && pxlSrc == dst->transparent) {
3645 + pxlSrc = dst->transparent;
3647 + pxlSrc = gdImageColorAllocateAlpha(dst, r, g, b, a);
3649 - if (pxlSrc == -1) {
3650 - pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3651 + if (pxlSrc == -1) {
3652 + pxlSrc = gdImageColorClosestAlpha(dst, r, g, b, a);
3656 if ((iYPos >= 0) && (iYPos < dst->sy)) {
3657 @@ -2735,10 +2843,10 @@
3660 /* Rotates an image by 90 degrees (counter clockwise) */
3661 -gdImagePtr gdImageRotate90 (gdImagePtr src)
3662 +gdImagePtr gdImageRotate90 (gdImagePtr src, int ignoretransparent)
3668 typedef int (*FuncPtr)(gdImagePtr, int, int);
3670 @@ -2749,8 +2857,12 @@
3671 f = gdImageGetPixel;
3673 dst = gdImageCreateTrueColor(src->sy, src->sx);
3674 + dst->transparent = src->transparent;
3677 + int old_blendmode = dst->alphaBlendingFlag;
3678 + dst->alphaBlendingFlag = 0;
3680 gdImagePaletteCopy (dst, src);
3682 for (uY = 0; uY<src->sy; uY++) {
3683 @@ -2763,16 +2875,21 @@
3684 a = gdImageAlpha(src,c);
3685 c = gdTrueColorAlpha(r, g, b, a);
3687 - gdImageSetPixel(dst, uY, (dst->sy - uX - 1), c);
3688 + if (ignoretransparent && c == dst->transparent) {
3689 + gdImageSetPixel(dst, uY, (dst->sy - uX - 1), dst->transparent);
3691 + gdImageSetPixel(dst, uY, (dst->sy - uX - 1), c);
3695 + dst->alphaBlendingFlag = old_blendmode;
3701 /* Rotates an image by 180 degrees (counter clockwise) */
3702 -gdImagePtr gdImageRotate180 (gdImagePtr src)
3703 +gdImagePtr gdImageRotate180 (gdImagePtr src, int ignoretransparent)
3707 @@ -2786,8 +2903,12 @@
3708 f = gdImageGetPixel;
3710 dst = gdImageCreateTrueColor(src->sx, src->sy);
3711 + dst->transparent = src->transparent;
3714 + int old_blendmode = dst->alphaBlendingFlag;
3715 + dst->alphaBlendingFlag = 0;
3717 gdImagePaletteCopy (dst, src);
3719 for (uY = 0; uY<src->sy; uY++) {
3720 @@ -2800,16 +2921,22 @@
3721 a = gdImageAlpha(src,c);
3722 c = gdTrueColorAlpha(r, g, b, a);
3724 - gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), c);
3726 + if (ignoretransparent && c == dst->transparent) {
3727 + gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), dst->transparent);
3729 + gdImageSetPixel(dst, (dst->sx - uX - 1), (dst->sy - uY - 1), c);
3733 + dst->alphaBlendingFlag = old_blendmode;
3739 /* Rotates an image by 270 degrees (counter clockwise) */
3740 -gdImagePtr gdImageRotate270 ( gdImagePtr src )
3741 +gdImagePtr gdImageRotate270 (gdImagePtr src, int ignoretransparent)
3745 @@ -2822,9 +2949,13 @@
3747 f = gdImageGetPixel;
3749 - dst = gdImageCreateTrueColor(src->sy, src->sx);
3750 + dst = gdImageCreateTrueColor (src->sy, src->sx);
3751 + dst->transparent = src->transparent;
3754 + int old_blendmode = dst->alphaBlendingFlag;
3755 + dst->alphaBlendingFlag = 0;
3757 gdImagePaletteCopy (dst, src);
3759 for (uY = 0; uY<src->sy; uY++) {
3760 @@ -2837,15 +2968,21 @@
3761 a = gdImageAlpha(src,c);
3762 c = gdTrueColorAlpha(r, g, b, a);
3764 - gdImageSetPixel(dst, (dst->sx - uY - 1), uX, c);
3766 + if (ignoretransparent && c == dst->transparent) {
3767 + gdImageSetPixel(dst, (dst->sx - uY - 1), uX, dst->transparent);
3769 + gdImageSetPixel(dst, (dst->sx - uY - 1), uX, c);
3773 + dst->alphaBlendingFlag = old_blendmode;
3779 -gdImagePtr gdImageRotate45 (gdImagePtr src, double dAngle, int clrBack)
3780 +gdImagePtr gdImageRotate45 (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent)
3782 typedef int (*FuncPtr)(gdImagePtr, int, int);
3783 gdImagePtr dst1,dst2,dst3;
3784 @@ -2869,8 +3006,8 @@
3786 f = gdImageGetPixel;
3788 - dst1 = gdImageCreateTrueColor(newx, newy);
3790 + dst1 = gdImageCreateTrueColor(newx, newy);
3791 /******* Perform 1st shear (horizontal) ******/
3794 @@ -2885,6 +3022,15 @@
3796 gdImagePaletteCopy (dst1, src);
3798 + if (ignoretransparent) {
3799 + if (gdImageTrueColor(src)) {
3800 + dst1->transparent = src->transparent;
3803 + dst1->transparent = gdTrueColorAlpha(gdImageRed(src, src->transparent), gdImageBlue(src, src->transparent), gdImageGreen(src, src->transparent), 127);
3807 dRadAngle = dAngle * ROTATE_DEG2RAD; /* Angle in radians */
3808 dSinE = sin (dRadAngle);
3809 dTan = tan (dRadAngle / 2.0);
3810 @@ -2897,7 +3043,7 @@
3813 iShear = (int)floor(dShear);
3814 - gdImageSkewX(dst1, src, u, iShear, (dShear - iShear), clrBack);
3815 + gdImageSkewX(dst1, src, u, iShear, (dShear - iShear), clrBack, ignoretransparent);
3819 @@ -2933,10 +3079,13 @@
3822 dst2->alphaBlendingFlag = gdEffectReplace;
3823 + if (ignoretransparent) {
3824 + dst2->transparent = dst1->transparent;
3827 for (u = 0; u < dst2->sx; u++, dOffset -= dSinE) {
3828 iShear = (int)floor (dOffset);
3829 - gdImageSkewY(dst2, dst1, u, iShear, (dOffset - (double)iShear), clrBack);
3830 + gdImageSkewY(dst2, dst1, u, iShear, (dOffset - (double)iShear), clrBack, ignoretransparent);
3834 @@ -2955,6 +3104,12 @@
3835 gdImageDestroy(dst2);
3839 + dst3->alphaBlendingFlag = gdEffectReplace;
3840 + if (ignoretransparent) {
3841 + dst3->transparent = dst2->transparent;
3845 dOffset = (double)(src->sx - 1) * dSinE * -dTan;
3847 @@ -2962,8 +3117,8 @@
3850 for (u = 0; u < dst3->sy; u++, dOffset += dTan) {
3851 - int iShear = (int)floor(dOffset);
3852 - gdImageSkewX(dst3, dst2, u, iShear, (dOffset - iShear), clrBack);
3853 + int iShear = (int)floor(dOffset);
3854 + gdImageSkewX(dst3, dst2, u, iShear, (dOffset - iShear), clrBack, ignoretransparent);
3857 gdImageDestroy(dst2);
3858 @@ -2971,11 +3126,11 @@
3862 -gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack)
3863 +gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent)
3866 gdImagePtr rotatedImg;
3872 @@ -2993,41 +3148,33 @@
3875 if (dAngle == 90.00) {
3876 - return gdImageRotate90(src);
3877 + return gdImageRotate90(src, ignoretransparent);
3879 if (dAngle == 180.00) {
3880 - return gdImageRotate180(src);
3881 + return gdImageRotate180(src, ignoretransparent);
3883 if(dAngle == 270.00) {
3884 - return gdImageRotate270 ( src);
3885 + return gdImageRotate270 (src, ignoretransparent);
3888 if ((dAngle > 45.0) && (dAngle <= 135.0)) {
3889 - pMidImg = gdImageRotate90 (src);
3890 + pMidImg = gdImageRotate90 (src, ignoretransparent);
3892 } else if ((dAngle > 135.0) && (dAngle <= 225.0)) {
3893 - pMidImg = gdImageRotate180 (src);
3894 + pMidImg = gdImageRotate180 (src, ignoretransparent);
3896 } else if ((dAngle > 225.0) && (dAngle <= 315.0)) {
3897 - pMidImg = gdImageRotate270 (src);
3898 + pMidImg = gdImageRotate270 (src, ignoretransparent);
3901 - return gdImageRotate45 (src, dAngle, clrBack);
3902 + return gdImageRotate45 (src, dAngle, clrBack, ignoretransparent);
3905 if (pMidImg == NULL) {
3909 - if(!src->trueColor) {
3910 - r = gdImageRed(src, clrBack);
3911 - g = gdImageGreen(src, clrBack);
3912 - b = gdImageBlue(src, clrBack);
3913 - a = gdImageAlpha(src, clrBack);
3914 - clrBack = gdTrueColorAlpha(r,g,b,a);
3917 - rotatedImg = gdImageRotate45 (pMidImg, dAngle, clrBack);
3918 + rotatedImg = gdImageRotate45 (pMidImg, dAngle, clrBack, ignoretransparent);
3919 gdImageDestroy(pMidImg);
3922 @@ -3098,20 +3245,27 @@
3926 + if (overflow2(sizeof(int), n)) {
3930 if (c == gdAntiAliased) {
3931 fill_color = im->AA_color;
3937 if (!im->polyAllocated) {
3938 - im->polyInts = (int *) safe_emalloc(sizeof(int), n, 0);
3939 + im->polyInts = (int *) gdMalloc(sizeof(int) * n);
3940 im->polyAllocated = n;
3942 if (im->polyAllocated < n) {
3943 while (im->polyAllocated < n) {
3944 im->polyAllocated *= 2;
3946 + if (overflow2(sizeof(int), im->polyAllocated)) {
3949 im->polyInts = (int *) gdRealloc(im->polyInts, sizeof(int) * im->polyAllocated);
3952 @@ -3131,7 +3285,7 @@
3954 if (maxy >= gdImageSY(im)) {
3955 maxy = gdImageSY(im) - 1;
3959 /* Fix in 1.3: count a vertex only once */
3960 for (y = miny; y <= maxy; y++) {
3961 @@ -3193,7 +3347,7 @@
3965 - im->style = (int *) safe_emalloc(sizeof(int), noOfPixels, 0);
3966 + im->style = (int *) gdMalloc(sizeof(int) * noOfPixels);
3967 memcpy(im->style, style, sizeof(int) * noOfPixels);
3968 im->styleLength = noOfPixels;
3970 @@ -3323,9 +3477,9 @@
3974 -gdAlphaBlend (int dst, int src)
3975 +gdAlphaBlendOld (int dst, int src)
3977 - /* 2.0.12: TBB: alpha in the destination should be a
3978 + /* 2.0.12: TBB: alpha in the destination should be a
3979 * component of the result. Thanks to Frank Warmerdam for
3980 * pointing out the issue.
3982 @@ -3345,6 +3499,51 @@
3983 gdTrueColorGetBlue (dst)) / gdAlphaMax));
3986 +int gdAlphaBlend (int dst, int src) {
3987 + int src_alpha = gdTrueColorGetAlpha(src);
3988 + int dst_alpha, alpha, red, green, blue;
3989 + int src_weight, dst_weight, tot_weight;
3991 +/* -------------------------------------------------------------------- */
3992 +/* Simple cases we want to handle fast. */
3993 +/* -------------------------------------------------------------------- */
3994 + if( src_alpha == gdAlphaOpaque )
3997 + dst_alpha = gdTrueColorGetAlpha(dst);
3998 + if( src_alpha == gdAlphaTransparent )
4000 + if( dst_alpha == gdAlphaTransparent )
4003 +/* -------------------------------------------------------------------- */
4004 +/* What will the source and destination alphas be? Note that */
4005 +/* the destination weighting is substantially reduced as the */
4006 +/* overlay becomes quite opaque. */
4007 +/* -------------------------------------------------------------------- */
4008 + src_weight = gdAlphaTransparent - src_alpha;
4009 + dst_weight = (gdAlphaTransparent - dst_alpha) * src_alpha / gdAlphaMax;
4010 + tot_weight = src_weight + dst_weight;
4012 +/* -------------------------------------------------------------------- */
4013 +/* What red, green and blue result values will we use? */
4014 +/* -------------------------------------------------------------------- */
4015 + alpha = src_alpha * dst_alpha / gdAlphaMax;
4017 + red = (gdTrueColorGetRed(src) * src_weight
4018 + + gdTrueColorGetRed(dst) * dst_weight) / tot_weight;
4019 + green = (gdTrueColorGetGreen(src) * src_weight
4020 + + gdTrueColorGetGreen(dst) * dst_weight) / tot_weight;
4021 + blue = (gdTrueColorGetBlue(src) * src_weight
4022 + + gdTrueColorGetBlue(dst) * dst_weight) / tot_weight;
4024 +/* -------------------------------------------------------------------- */
4025 +/* Return merged result. */
4026 +/* -------------------------------------------------------------------- */
4027 + return ((alpha << 24) + (red << 16) + (green << 8) + blue);
4031 void gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg)
4033 im->alphaBlendingFlag = alphaBlendingArg;
4034 @@ -3362,44 +3561,6 @@
4035 im->saveAlphaFlag = saveAlphaArg;
4038 -static int gdFullAlphaBlend (int dst, int src)
4041 - a1 = gdAlphaTransparent - gdTrueColorGetAlpha(src);
4042 - a2 = gdAlphaTransparent - gdTrueColorGetAlpha(dst);
4044 - return ( ((gdAlphaTransparent - ((a1+a2)-(a1*a2/gdAlphaMax))) << 24) +
4045 - (gdAlphaBlendColor( gdTrueColorGetRed(src), gdTrueColorGetRed(dst), a1, a2 ) << 16) +
4046 - (gdAlphaBlendColor( gdTrueColorGetGreen(src), gdTrueColorGetGreen(dst), a1, a2 ) << 8) +
4047 - (gdAlphaBlendColor( gdTrueColorGetBlue(src), gdTrueColorGetBlue(dst), a1, a2 ))
4051 -static int gdAlphaBlendColor( int b1, int b2, int a1, int a2 )
4056 - /* deal with special cases */
4058 - if( (gdAlphaMax == a1) || (0 == a2) ) {
4059 - /* the back pixel can't be seen */
4061 - } else if(0 == a1) {
4062 - /* the front pixel can't be seen */
4064 - } else if(gdAlphaMax == a2) {
4065 - /* the back pixel is opaque */
4066 - return ( a1 * b1 + ( gdAlphaMax - a1 ) * b2 ) / gdAlphaMax;
4069 - /* the general case */
4070 - w = ( a1 * ( gdAlphaMax - a2 ) / ( gdAlphaMax - a1 * a2 / gdAlphaMax ) * b1 + \
4071 - a2 * ( gdAlphaMax - a1 ) / ( gdAlphaMax - a1 * a2 / gdAlphaMax ) * b2 ) / gdAlphaMax;
4072 - c = (a2 * b2 + ( gdAlphaMax - a2 ) * w ) / gdAlphaMax;
4073 - return ( a1 * b1 + ( gdAlphaMax - a1 ) * c ) / gdAlphaMax;
4076 static int gdLayerOverlay (int dst, int src)
4079 @@ -3415,12 +3576,12 @@
4080 static int gdAlphaOverlayColor (int src, int dst, int max )
4082 /* this function implements the algorithm
4085 * for dst[rgb] < 0.5,
4086 * c[rgb] = 2.src[rgb].dst[rgb]
4087 * and for dst[rgb] > 0.5,
4088 * c[rgb] = -2.src[rgb].dst[rgb] + 2.dst[rgb] + 2.src[rgb] - 1
4094 @@ -3472,3 +3633,457 @@
4100 +/* Filters function added on 2003/12
4101 + * by Pierre-Alain Joye (pajoye@pearfr.org)
4103 +/* Begin filters function */
4104 +#ifndef HAVE_GET_TRUE_COLOR
4105 +#define GET_PIXEL_FUNCTION(src)(src->trueColor?gdImageGetTrueColorPixel:gdImageGetPixel)
4108 +/* invert src image */
4109 +int gdImageNegate(gdImagePtr src)
4114 + typedef int (*FuncPtr)(gdImagePtr, int, int);
4121 + f = GET_PIXEL_FUNCTION(src);
4123 + for (y=0; y<src->sy; ++y) {
4124 + for (x=0; x<src->sx; ++x) {
4125 + pxl = f (src, x, y);
4126 + r = gdImageRed(src, pxl);
4127 + g = gdImageGreen(src, pxl);
4128 + b = gdImageBlue(src, pxl);
4129 + a = gdImageAlpha(src, pxl);
4131 + new_pxl = gdImageColorAllocateAlpha(src, 255-r, 255-g, 255-b, a);
4132 + if (new_pxl == -1) {
4133 + new_pxl = gdImageColorClosestAlpha(src, 255-r, 255-g, 255-b, a);
4135 + gdImageSetPixel (src, x, y, new_pxl);
4141 +/* Convert the image src to a grayscale image */
4142 +int gdImageGrayScale(gdImagePtr src)
4147 + typedef int (*FuncPtr)(gdImagePtr, int, int);
4149 + f = GET_PIXEL_FUNCTION(src);
4155 + for (y=0; y<src->sy; ++y) {
4156 + for (x=0; x<src->sx; ++x) {
4157 + pxl = f (src, x, y);
4158 + r = gdImageRed(src, pxl);
4159 + g = gdImageGreen(src, pxl);
4160 + b = gdImageBlue(src, pxl);
4161 + a = gdImageAlpha(src, pxl);
4162 + r = g = b = (int) (.299 * r + .587 * g + .114 * b);
4164 + new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a);
4165 + if (new_pxl == -1) {
4166 + new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
4168 + gdImageSetPixel (src, x, y, new_pxl);
4174 +/* Set the brightness level <level> for the image src */
4175 +int gdImageBrightness(gdImagePtr src, int brightness)
4180 + typedef int (*FuncPtr)(gdImagePtr, int, int);
4182 + f = GET_PIXEL_FUNCTION(src);
4184 + if (src==NULL || (brightness < -255 || brightness>255)) {
4188 + if (brightness==0) {
4192 + for (y=0; y<src->sy; ++y) {
4193 + for (x=0; x<src->sx; ++x) {
4194 + pxl = f (src, x, y);
4196 + r = gdImageRed(src, pxl);
4197 + g = gdImageGreen(src, pxl);
4198 + b = gdImageBlue(src, pxl);
4199 + a = gdImageAlpha(src, pxl);
4201 + r = r + brightness;
4202 + g = g + brightness;
4203 + b = b + brightness;
4205 + r = (r > 255)? 255 : ((r < 0)? 0:r);
4206 + g = (g > 255)? 255 : ((g < 0)? 0:g);
4207 + b = (b > 255)? 255 : ((b < 0)? 0:b);
4209 + new_pxl = gdImageColorAllocateAlpha(src, (int)r, (int)g, (int)b, a);
4210 + if (new_pxl == -1) {
4211 + new_pxl = gdImageColorClosestAlpha(src, (int)r, (int)g, (int)b, a);
4213 + gdImageSetPixel (src, x, y, new_pxl);
4220 +int gdImageContrast(gdImagePtr src, double contrast)
4226 + typedef int (*FuncPtr)(gdImagePtr, int, int);
4229 + f = GET_PIXEL_FUNCTION(src);
4235 + contrast = (double)(100.0-contrast)/100.0;
4236 + contrast = contrast*contrast;
4238 + for (y=0; y<src->sy; ++y) {
4239 + for (x=0; x<src->sx; ++x) {
4240 + pxl = f(src, x, y);
4242 + r = gdImageRed(src, pxl);
4243 + g = gdImageGreen(src, pxl);
4244 + b = gdImageBlue(src, pxl);
4245 + a = gdImageAlpha(src, pxl);
4247 + rf = (double)r/255.0;
4253 + bf = (double)b/255.0;
4259 + gf = (double)g/255.0;
4265 + rf = (rf > 255.0)? 255.0 : ((rf < 0.0)? 0.0:rf);
4266 + gf = (gf > 255.0)? 255.0 : ((gf < 0.0)? 0.0:gf);
4267 + bf = (bf > 255.0)? 255.0 : ((bf < 0.0)? 0.0:bf);
4269 + new_pxl = gdImageColorAllocateAlpha(src, (int)rf, (int)gf, (int)bf, a);
4270 + if (new_pxl == -1) {
4271 + new_pxl = gdImageColorClosestAlpha(src, (int)rf, (int)gf, (int)bf, a);
4273 + gdImageSetPixel (src, x, y, new_pxl);
4280 +int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha)
4284 + typedef int (*FuncPtr)(gdImagePtr, int, int);
4287 + if (src == NULL) {
4291 + f = GET_PIXEL_FUNCTION(src);
4293 + for (y=0; y<src->sy; ++y) {
4294 + for (x=0; x<src->sx; ++x) {
4297 + pxl = f(src, x, y);
4298 + r = gdImageRed(src, pxl);
4299 + g = gdImageGreen(src, pxl);
4300 + b = gdImageBlue(src, pxl);
4301 + a = gdImageAlpha(src, pxl);
4308 + r = (r > 255)? 255 : ((r < 0)? 0 : r);
4309 + g = (g > 255)? 255 : ((g < 0)? 0 : g);
4310 + b = (b > 255)? 255 : ((b < 0)? 0 : b);
4311 + a = (a > 127)? 127 : ((a < 0)? 0 : a);
4313 + new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a);
4314 + if (new_pxl == -1) {
4315 + new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
4317 + gdImageSetPixel (src, x, y, new_pxl);
4323 +int gdImageConvolution(gdImagePtr src, float filter[3][3], float filter_div, float offset)
4325 + int x, y, i, j, new_a;
4326 + float new_r, new_g, new_b;
4327 + int new_pxl, pxl=0;
4328 + gdImagePtr srcback;
4329 + typedef int (*FuncPtr)(gdImagePtr, int, int);
4336 + /* We need the orinal image with each safe neoghb. pixel */
4337 + srcback = gdImageCreateTrueColor (src->sx, src->sy);
4338 + gdImageCopy(srcback, src,0,0,0,0,src->sx,src->sy);
4340 + if (srcback==NULL) {
4344 + f = GET_PIXEL_FUNCTION(src);
4346 + for ( y=0; y<src->sy; y++) {
4347 + for(x=0; x<src->sx; x++) {
4348 + new_r = new_g = new_b = 0;
4349 + new_a = gdImageAlpha(srcback, pxl);
4351 + for (j=0; j<3; j++) {
4352 + int yv = MIN(MAX(y - 1 + j, 0), src->sy - 1);
4353 + for (i=0; i<3; i++) {
4354 + pxl = f(srcback, MIN(MAX(x - 1 + i, 0), src->sx - 1), yv);
4355 + new_r += (float)gdImageRed(srcback, pxl) * filter[j][i];
4356 + new_g += (float)gdImageGreen(srcback, pxl) * filter[j][i];
4357 + new_b += (float)gdImageBlue(srcback, pxl) * filter[j][i];
4361 + new_r = (new_r/filter_div)+offset;
4362 + new_g = (new_g/filter_div)+offset;
4363 + new_b = (new_b/filter_div)+offset;
4365 + new_r = (new_r > 255.0f)? 255.0f : ((new_r < 0.0f)? 0.0f:new_r);
4366 + new_g = (new_g > 255.0f)? 255.0f : ((new_g < 0.0f)? 0.0f:new_g);
4367 + new_b = (new_b > 255.0f)? 255.0f : ((new_b < 0.0f)? 0.0f:new_b);
4369 + new_pxl = gdImageColorAllocateAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
4370 + if (new_pxl == -1) {
4371 + new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
4373 + gdImageSetPixel (src, x, y, new_pxl);
4376 + gdImageDestroy(srcback);
4380 +int gdImageSelectiveBlur( gdImagePtr src)
4383 + float new_r, new_g, new_b;
4384 + int new_pxl, cpxl, pxl, new_a=0;
4385 + float flt_r [3][3];
4386 + float flt_g [3][3];
4387 + float flt_b [3][3];
4388 + float flt_r_sum, flt_g_sum, flt_b_sum;
4390 + gdImagePtr srcback;
4391 + typedef int (*FuncPtr)(gdImagePtr, int, int);
4398 + /* We need the orinal image with each safe neoghb. pixel */
4399 + srcback = gdImageCreateTrueColor (src->sx, src->sy);
4400 + gdImageCopy(srcback, src,0,0,0,0,src->sx,src->sy);
4402 + if (srcback==NULL) {
4406 + f = GET_PIXEL_FUNCTION(src);
4408 + for(y = 0; y<src->sy; y++) {
4409 + for (x=0; x<src->sx; x++) {
4410 + flt_r_sum = flt_g_sum = flt_b_sum = 0.0;
4411 + cpxl = f(src, x, y);
4413 + for (j=0; j<3; j++) {
4414 + for (i=0; i<3; i++) {
4415 + if ((j == 1) && (i == 1)) {
4416 + flt_r[1][1] = flt_g[1][1] = flt_b[1][1] = 0.5;
4418 + pxl = f(src, x-(3>>1)+i, y-(3>>1)+j);
4419 + new_a = gdImageAlpha(srcback, pxl);
4421 + new_r = ((float)gdImageRed(srcback, cpxl)) - ((float)gdImageRed (srcback, pxl));
4423 + if (new_r < 0.0f) {
4427 + flt_r[j][i] = 1.0f/new_r;
4429 + flt_r[j][i] = 1.0f;
4432 + new_g = ((float)gdImageGreen(srcback, cpxl)) - ((float)gdImageGreen(srcback, pxl));
4434 + if (new_g < 0.0f) {
4438 + flt_g[j][i] = 1.0f/new_g;
4440 + flt_g[j][i] = 1.0f;
4443 + new_b = ((float)gdImageBlue(srcback, cpxl)) - ((float)gdImageBlue(srcback, pxl));
4445 + if (new_b < 0.0f) {
4449 + flt_b[j][i] = 1.0f/new_b;
4451 + flt_b[j][i] = 1.0f;
4455 + flt_r_sum += flt_r[j][i];
4456 + flt_g_sum += flt_g[j][i];
4457 + flt_b_sum += flt_b [j][i];
4461 + for (j=0; j<3; j++) {
4462 + for (i=0; i<3; i++) {
4463 + if (flt_r_sum != 0.0) {
4464 + flt_r[j][i] /= flt_r_sum;
4466 + if (flt_g_sum != 0.0) {
4467 + flt_g[j][i] /= flt_g_sum;
4469 + if (flt_b_sum != 0.0) {
4470 + flt_b [j][i] /= flt_b_sum;
4475 + new_r = new_g = new_b = 0.0;
4477 + for (j=0; j<3; j++) {
4478 + for (i=0; i<3; i++) {
4479 + pxl = f(src, x-(3>>1)+i, y-(3>>1)+j);
4480 + new_r += (float)gdImageRed(srcback, pxl) * flt_r[j][i];
4481 + new_g += (float)gdImageGreen(srcback, pxl) * flt_g[j][i];
4482 + new_b += (float)gdImageBlue(srcback, pxl) * flt_b[j][i];
4486 + new_r = (new_r > 255.0f)? 255.0f : ((new_r < 0.0f)? 0.0f:new_r);
4487 + new_g = (new_g > 255.0f)? 255.0f : ((new_g < 0.0f)? 0.0f:new_g);
4488 + new_b = (new_b > 255.0f)? 255.0f : ((new_b < 0.0f)? 0.0f:new_b);
4489 + new_pxl = gdImageColorAllocateAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
4490 + if (new_pxl == -1) {
4491 + new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
4493 + gdImageSetPixel (src, x, y, new_pxl);
4496 + gdImageDestroy(srcback);
4500 +int gdImageEdgeDetectQuick(gdImagePtr src)
4502 + float filter[3][3] = {{-1.0,0.0,-1.0},
4506 + return gdImageConvolution(src, filter, 1, 127);
4509 +int gdImageGaussianBlur(gdImagePtr im)
4511 + float filter[3][3] = {{1.0,2.0,1.0},
4515 + return gdImageConvolution(im, filter, 16, 0);
4518 +int gdImageEmboss(gdImagePtr im)
4521 + float filter[3][3] = {{1.0,1.0,1.0},
4523 + {-1.0,-1.0,-1.0}};
4525 + float filter[3][3] = {{ 1.5, 0.0, 0.0},
4527 + { 0.0, 0.0,-1.5}};
4529 + return gdImageConvolution(im, filter, 1, 127);
4532 +int gdImageMeanRemoval(gdImagePtr im)
4534 + float filter[3][3] = {{-1.0,-1.0,-1.0},
4536 + {-1.0,-1.0,-1.0}};
4538 + return gdImageConvolution(im, filter, 1, 0);
4541 +int gdImageSmooth(gdImagePtr im, float weight)
4543 + float filter[3][3] = {{1.0,1.0,1.0},
4547 + filter[1][1] = weight;
4549 + return gdImageConvolution(im, filter, weight+8, 0);
4551 +/* End filters function */
4552 diff -urN php-4.4.8.org/ext/gd/libgd/gdcache.c php-4.4.8/ext/gd/libgd/gdcache.c
4553 --- php-4.4.8.org/ext/gd/libgd/gdcache.c 2003-04-05 19:24:16.000000000 +0200
4554 +++ php-4.4.8/ext/gd/libgd/gdcache.c 2003-12-28 21:11:08.000000000 +0100
4563 - * Caches of pointers to user structs in which the least-recently-used
4564 - * element is replaced in the event of a cache miss after the cache has
4565 + * Caches of pointers to user structs in which the least-recently-used
4566 + * element is replaced in the event of a cache miss after the cache has
4567 * reached a given size.
4569 * John Ellson (ellson@graphviz.org) Oct 31, 1997
4571 * The head structure has a pointer to the most-recently-used
4572 * element, and elements are moved to this position in the list each
4573 * time they are used. The head also contains pointers to three
4574 - * user defined functions:
4575 - * - a function to test if a cached userdata matches some keydata
4576 - * - a function to provide a new userdata struct to the cache
4577 + * user defined functions:
4578 + * - a function to test if a cached userdata matches some keydata
4579 + * - a function to provide a new userdata struct to the cache
4580 * if there has been a cache miss.
4581 * - a function to release a userdata struct when it is
4582 * no longer being managed by the cache
4584 * In the event of a cache miss the cache is allowed to grow up to
4585 * a specified maximum size. After the maximum size is reached then
4586 - * the least-recently-used element is discarded to make room for the
4587 - * new. The most-recently-returned value is always left at the
4588 + * the least-recently-used element is discarded to make room for the
4589 + * new. The most-recently-returned value is always left at the
4590 * beginning of the list after retrieval.
4592 * In the current implementation the cache is traversed by a linear
4593 diff -urN php-4.4.8.org/ext/gd/libgd/gdcache.h php-4.4.8/ext/gd/libgd/gdcache.h
4594 --- php-4.4.8.org/ext/gd/libgd/gdcache.h 2003-04-05 19:24:16.000000000 +0200
4595 +++ php-4.4.8/ext/gd/libgd/gdcache.h 2003-12-28 21:11:08.000000000 +0100
4601 - * Caches of pointers to user structs in which the least-recently-used
4602 - * element is replaced in the event of a cache miss after the cache has
4603 + * Caches of pointers to user structs in which the least-recently-used
4604 + * element is replaced in the event of a cache miss after the cache has
4605 * reached a given size.
4607 * John Ellson (ellson@graphviz.org) Oct 31, 1997
4609 * The head structure has a pointer to the most-recently-used
4610 * element, and elements are moved to this position in the list each
4611 * time they are used. The head also contains pointers to three
4612 - * user defined functions:
4613 - * - a function to test if a cached userdata matches some keydata
4614 - * - a function to provide a new userdata struct to the cache
4615 + * user defined functions:
4616 + * - a function to test if a cached userdata matches some keydata
4617 + * - a function to provide a new userdata struct to the cache
4618 * if there has been a cache miss.
4619 * - a function to release a userdata struct when it is
4620 * no longer being managed by the cache
4622 * In the event of a cache miss the cache is allowed to grow up to
4623 * a specified maximum size. After the maximum size is reached then
4624 - * the least-recently-used element is discarded to make room for the
4625 - * new. The most-recently-returned value is always left at the
4626 + * the least-recently-used element is discarded to make room for the
4627 + * new. The most-recently-returned value is always left at the
4628 * beginning of the list after retrieval.
4630 * In the current implementation the cache is traversed by a linear
4631 diff -urN php-4.4.8.org/ext/gd/libgd/gdfontg.c php-4.4.8/ext/gd/libgd/gdfontg.c
4632 --- php-4.4.8.org/ext/gd/libgd/gdfontg.c 2004-03-29 20:21:00.000000000 +0200
4633 +++ php-4.4.8/ext/gd/libgd/gdfontg.c 2006-09-16 21:07:45.000000000 +0200
4636 #include "gdfontg.h"
4638 -char gdFontGiantData[] =
4639 +static const char gdFontGiantData[] =
4642 0, 0, 0, 0, 0, 0, 0, 0, 0,
4643 @@ -4376,7 +4376,7 @@
4648 + (char*)gdFontGiantData
4651 gdFontPtr gdFontGiant = &gdFontGiantRep;
4652 diff -urN php-4.4.8.org/ext/gd/libgd/gdfontl.c php-4.4.8/ext/gd/libgd/gdfontl.c
4653 --- php-4.4.8.org/ext/gd/libgd/gdfontl.c 2004-03-29 20:21:00.000000000 +0200
4654 +++ php-4.4.8/ext/gd/libgd/gdfontl.c 2006-09-16 21:07:45.000000000 +0200
4657 #include "gdfontl.h"
4659 -char gdFontLargeData[] =
4660 +static const char gdFontLargeData[] =
4663 0, 0, 0, 0, 0, 0, 0, 0,
4664 @@ -4633,7 +4633,7 @@
4669 + (char*)gdFontLargeData
4672 gdFontPtr gdFontLarge = &gdFontLargeRep;
4673 diff -urN php-4.4.8.org/ext/gd/libgd/gdfontmb.c php-4.4.8/ext/gd/libgd/gdfontmb.c
4674 --- php-4.4.8.org/ext/gd/libgd/gdfontmb.c 2004-03-29 20:21:00.000000000 +0200
4675 +++ php-4.4.8/ext/gd/libgd/gdfontmb.c 2006-09-16 21:07:46.000000000 +0200
4678 #include "gdfontmb.h"
4680 -char gdFontMediumBoldData[] =
4681 +static const char gdFontMediumBoldData[] =
4684 0, 0, 0, 0, 0, 0, 0,
4685 @@ -3863,7 +3863,7 @@
4689 - gdFontMediumBoldData
4690 + (char*)gdFontMediumBoldData
4693 gdFontPtr gdFontMediumBold = &gdFontMediumBoldRep;
4694 diff -urN php-4.4.8.org/ext/gd/libgd/gdfonts.c php-4.4.8/ext/gd/libgd/gdfonts.c
4695 --- php-4.4.8.org/ext/gd/libgd/gdfonts.c 2004-03-29 20:21:00.000000000 +0200
4696 +++ php-4.4.8/ext/gd/libgd/gdfonts.c 2006-09-16 21:07:46.000000000 +0200
4699 #include "gdfonts.h"
4701 -char gdFontSmallData[] =
4702 +static const char gdFontSmallData[] =
4706 @@ -3863,7 +3863,7 @@
4711 + (char*)gdFontSmallData
4714 gdFontPtr gdFontSmall = &gdFontSmallRep;
4715 diff -urN php-4.4.8.org/ext/gd/libgd/gdfontt.c php-4.4.8/ext/gd/libgd/gdfontt.c
4716 --- php-4.4.8.org/ext/gd/libgd/gdfontt.c 2004-03-29 20:21:00.000000000 +0200
4717 +++ php-4.4.8/ext/gd/libgd/gdfontt.c 2006-09-16 21:07:46.000000000 +0200
4720 #include "gdfontt.h"
4722 -char gdFontTinyData[] =
4723 +static const char gdFontTinyData[] =
4727 @@ -2584,7 +2584,7 @@
4732 + (char*)gdFontTinyData
4735 gdFontPtr gdFontTiny = &gdFontTinyRep;
4736 diff -urN php-4.4.8.org/ext/gd/libgd/gdft.c php-4.4.8/ext/gd/libgd/gdft.c
4737 --- php-4.4.8.org/ext/gd/libgd/gdft.c 2007-03-10 13:51:07.000000000 +0100
4738 +++ php-4.4.8/ext/gd/libgd/gdft.c 2007-04-23 17:17:47.000000000 +0200
4743 -#define R_OK 04 /* Needed in Windows */
4745 +# define R_OK 04 /* Needed in Windows */
4751 gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist,
4752 double ptsize, double angle, int x, int y, char *string)
4754 - /* 2.0.6: valid return */
4755 - return gdImageStringFT (im, brect, fg, fontlist, ptsize,
4756 - angle, x, y, string);
4757 + /* 2.0.6: valid return */
4758 + return gdImageStringFT (im, brect, fg, fontlist, ptsize, angle, x, y, string);
4761 #ifndef HAVE_LIBFREETYPE
4763 double ptsize, double angle, int x, int y, char *string,
4764 gdFTStringExtraPtr strex)
4766 - return "libgd was not built with FreeType font support\n";
4767 + return "libgd was not built with FreeType font support\n";
4771 gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
4772 double ptsize, double angle, int x, int y, char *string)
4774 - return "libgd was not built with FreeType font support\n";
4775 + return "libgd was not built with FreeType font support\n";
4780 #define TWEENCOLORCACHESIZE 32
4783 - * Line separation as a factor of font height.
4784 - * No space between if LINESPACE = 1.00
4785 + * Line separation as a factor of font height.
4786 + * No space between if LINESPACE = 1.00
4787 * Line separation will be rounded up to next pixel row.
4789 #define LINESPACE 1.05
4790 @@ -115,40 +116,35 @@
4794 - char *fontlist; /* key */
4795 - FT_Library *library;
4797 - FT_Bool have_char_map_unicode, have_char_map_big5, have_char_map_sjis,
4798 - have_char_map_apple_roman;
4799 - gdCache_head_t *glyphCache;
4802 + char *fontlist; /* key */
4803 + FT_Library *library;
4805 + FT_Bool have_char_map_unicode, have_char_map_big5, have_char_map_sjis, have_char_map_apple_roman;
4806 + gdCache_head_t *glyphCache;
4811 - char *fontlist; /* key */
4812 - FT_Library *library;
4816 + char *fontlist; /* key */
4817 + FT_Library *library;
4822 - int pixel; /* key */
4823 - int bgcolor; /* key */
4824 - int fgcolor; /* key *//* -ve means no antialias */
4825 - gdImagePtr im; /* key */
4830 + int pixel; /* key */
4831 + int bgcolor; /* key */
4832 + int fgcolor; /* key *//* -ve means no antialias */
4833 + gdImagePtr im; /* key */
4839 - int pixel; /* key */
4840 - int bgcolor; /* key */
4841 - int fgcolor; /* key *//* -ve means no antialias */
4842 - gdImagePtr im; /* key */
4846 + int pixel; /* key */
4847 + int bgcolor; /* key */
4848 + int fgcolor; /* key *//* -ve means no antialias */
4849 + gdImagePtr im; /* key */
4852 /********************************************************************
4853 * gdTcl_UtfToUniChar is borrowed from Tcl ...
4854 @@ -208,160 +204,141 @@
4856 #define Tcl_UniChar int
4857 #define TCL_UTF_MAX 3
4859 -gdTcl_UtfToUniChar (char *str, Tcl_UniChar * chPtr)
4860 +static int gdTcl_UtfToUniChar (char *str, Tcl_UniChar * chPtr)
4861 /* str is the UTF8 next character pointer */
4862 /* chPtr is the int for the result */
4867 + /* HTML4.0 entities in decimal form, e.g. Å */
4868 + byte = *((unsigned char *) str);
4869 + if (byte == '&') {
4872 + byte = *((unsigned char *) (str + 1));
4873 + if (byte == '#') {
4874 + byte = *((unsigned char *) (str + 2));
4875 + if (byte == 'x' || byte == 'X') {
4876 + for (i = 3; i < 8; i++) {
4877 + byte = *((unsigned char *) (str + i));
4878 + if (byte >= 'A' && byte <= 'F')
4879 + byte = byte - 'A' + 10;
4880 + else if (byte >= 'a' && byte <= 'f')
4881 + byte = byte - 'a' + 10;
4882 + else if (byte >= '0' && byte <= '9')
4883 + byte = byte - '0';
4886 + n = (n * 16) + byte;
4889 + for (i = 2; i < 8; i++) {
4890 + byte = *((unsigned char *) (str + i));
4891 + if (byte >= '0' && byte <= '9') {
4892 + n = (n * 10) + (byte - '0');
4898 + if (byte == ';') {
4899 + *chPtr = (Tcl_UniChar) n;
4905 - /* HTML4.0 entities in decimal form, e.g. Å */
4906 - byte = *((unsigned char *) str);
4911 - byte = *((unsigned char *) (str + 1));
4914 - for (i = 2; i < 8; i++)
4916 - byte = *((unsigned char *) (str + i));
4917 - if (byte >= '0' && byte <= '9')
4919 - n = (n * 10) + (byte - '0');
4926 - *chPtr = (Tcl_UniChar) n;
4933 - * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones.
4935 + /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */
4937 - byte = *((unsigned char *) str);
4938 + byte = *((unsigned char *) str);
4940 - if (0xA1 <= byte && byte <= 0xFE)
4944 - ku = (byte & 0x7F) - 0x20;
4945 - ten = (str[1] & 0x7F) - 0x20;
4946 - if ((ku < 1 || ku > 92) || (ten < 1 || ten > 94))
4948 - *chPtr = (Tcl_UniChar) byte;
4952 - *chPtr = (Tcl_UniChar) UnicodeTbl[ku - 1][ten - 1];
4956 + if (0xA1 <= byte && byte <= 0xFE) {
4959 + ku = (byte & 0x7F) - 0x20;
4960 + ten = (str[1] & 0x7F) - 0x20;
4961 + if ((ku < 1 || ku > 92) || (ten < 1 || ten > 94)) {
4962 + *chPtr = (Tcl_UniChar) byte;
4966 + *chPtr = (Tcl_UniChar) UnicodeTbl[ku - 1][ten - 1];
4969 #endif /* JISX0208 */
4973 - * Handles properly formed UTF-8 characters between
4974 - * 0x01 and 0x7F. Also treats \0 and naked trail
4975 - * bytes 0x80 to 0xBF as valid characters representing
4979 - *chPtr = (Tcl_UniChar) byte;
4982 - else if (byte < 0xE0)
4984 - if ((str[1] & 0xC0) == 0x80)
4987 - * Two-byte-character lead-byte followed
4988 - * by a trail-byte.
4991 - *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6)
4992 - | (str[1] & 0x3F));
4996 - * A two-byte-character lead-byte not followed by trail-byte
4997 - * represents itself.
5000 - *chPtr = (Tcl_UniChar) byte;
5003 - else if (byte < 0xF0)
5005 - if (((str[1] & 0xC0) == 0x80) && ((str[2] & 0xC0) == 0x80))
5008 - * Three-byte-character lead byte followed by
5009 - * two trail bytes.
5012 - *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12)
5013 - | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F));
5017 - * A three-byte-character lead-byte not followed by
5018 - * two trail-bytes represents itself.
5021 - *chPtr = (Tcl_UniChar) byte;
5024 + if (byte < 0xC0) {
5025 + /* Handles properly formed UTF-8 characters between
5026 + * 0x01 and 0x7F. Also treats \0 and naked trail
5027 + * bytes 0x80 to 0xBF as valid characters representing
5031 + *chPtr = (Tcl_UniChar) byte;
5033 + } else if (byte < 0xE0) {
5034 + if ((str[1] & 0xC0) == 0x80) {
5035 + /* Two-byte-character lead-byte followed by a trail-byte. */
5037 + *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (str[1] & 0x3F));
5041 + * A two-byte-character lead-byte not followed by trail-byte
5042 + * represents itself.
5045 + *chPtr = (Tcl_UniChar) byte;
5047 + } else if (byte < 0xF0) {
5048 + if (((str[1] & 0xC0) == 0x80) && ((str[2] & 0xC0) == 0x80)) {
5049 + /* Three-byte-character lead byte followed by two trail bytes. */
5051 + *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F));
5054 + /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */
5056 + *chPtr = (Tcl_UniChar) byte;
5062 - int ch, total, trail;
5064 - total = totalBytes[byte];
5065 - trail = total - 1;
5068 - ch = byte & (0x3F >> trail);
5072 - if ((*str & 0xC0) != 0x80)
5078 - ch |= (*str & 0x3F);
5081 - while (trail > 0);
5085 + int ch, total, trail;
5087 + total = totalBytes[byte];
5088 + trail = total - 1;
5091 + ch = byte & (0x3F >> trail);
5094 + if ((*str & 0xC0) != 0x80) {
5099 + ch |= (*str & 0x3F);
5101 + } while (trail > 0);
5109 - *chPtr = (Tcl_UniChar) byte;
5111 + *chPtr = (Tcl_UniChar) byte;
5115 /********************************************************************/
5116 /* font cache functions */
5119 -fontTest (void *element, void *key)
5120 +static int fontTest (void *element, void *key)
5122 - font_t *a = (font_t *) element;
5123 - fontkey_t *b = (fontkey_t *) key;
5124 + font_t *a = (font_t *) element;
5125 + fontkey_t *b = (fontkey_t *) key;
5127 - return (strcmp (a->fontlist, b->fontlist) == 0);
5128 + return (strcmp (a->fontlist, b->fontlist) == 0);
5131 static void *fontFetch (char **error, void *key)
5133 fontsearchpath = getenv ("GDFONTPATH");
5134 if (!fontsearchpath) {
5135 fontsearchpath = DEFAULT_FONTPATH;
5138 fontlist = gdEstrdup(a->fontlist);
5141 @@ -399,8 +376,12 @@
5142 /* make a fresh copy each time - strtok corrupts it. */
5143 path = gdEstrdup (fontsearchpath);
5145 - /* if name is an absolute filename then test directly */
5146 + /* if name is an absolute filename then test directly */
5148 + if (*name == '/' || (name[0] != 0 && strstr(name, ":/"))) {
5150 if (*name == '/' || (name[0] != 0 && name[1] == ':' && (name[2] == '/' || name[2] == '\\'))) {
5152 snprintf(fullname, sizeof(fullname) - 1, "%s", name);
5153 if (access(fullname, R_OK) == 0) {
5155 @@ -437,15 +418,15 @@
5173 gdPFree(a->fontlist);
5175 @@ -556,257 +537,234 @@
5176 * does the work so that text can be alpha blended across a complex
5177 * background (TBB; and for real in 2.0.2).
5180 -tweenColorFetch (char **error, void *key)
5181 +static void * tweenColorFetch (char **error, void *key)
5184 - tweencolorkey_t *b = (tweencolorkey_t *) key;
5185 - int pixel, npixel, bg, fg;
5188 - a = (tweencolor_t *) gdMalloc (sizeof (tweencolor_t));
5189 - pixel = a->pixel = b->pixel;
5190 - bg = a->bgcolor = b->bgcolor;
5191 - fg = a->fgcolor = b->fgcolor;
5194 - /* if fg is specified by a negative color idx, then don't antialias */
5197 - if ((pixel + pixel) >= NUMCOLORS)
5198 - a->tweencolor = -fg;
5200 - a->tweencolor = bg;
5204 - npixel = NUMCOLORS - pixel;
5205 - if (im->trueColor)
5207 - /* 2.0.1: use gdImageSetPixel to do the alpha blending work,
5208 - or to just store the alpha level. All we have to do here
5209 - is incorporate our knowledge of the percentage of this
5210 - pixel that is really "lit" by pushing the alpha value
5211 - up toward transparency in edge regions. */
5212 - a->tweencolor = gdTrueColorAlpha (
5213 - gdTrueColorGetRed (fg),
5214 - gdTrueColorGetGreen (fg),
5215 - gdTrueColorGetBlue (fg),
5216 - gdAlphaMax - (gdTrueColorGetAlpha (fg) * pixel / NUMCOLORS));
5220 - a->tweencolor = gdImageColorResolve (im,
5221 - (pixel * im->red[fg] + npixel * im->red[bg]) / NUMCOLORS,
5222 - (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS,
5223 - (pixel * im->blue[fg] + npixel * im->blue[bg]) / NUMCOLORS);
5226 - return (void *) a;
5228 + tweencolorkey_t *b = (tweencolorkey_t *) key;
5229 + int pixel, npixel, bg, fg;
5232 + a = (tweencolor_t *) gdMalloc (sizeof (tweencolor_t));
5233 + pixel = a->pixel = b->pixel;
5234 + bg = a->bgcolor = b->bgcolor;
5235 + fg = a->fgcolor = b->fgcolor;
5236 + im = a->im = b->im;
5238 + /* if fg is specified by a negative color idx, then don't antialias */
5240 + if ((pixel + pixel) >= NUMCOLORS) {
5241 + a->tweencolor = -fg;
5243 + a->tweencolor = bg;
5246 + npixel = NUMCOLORS - pixel;
5247 + if (im->trueColor) {
5248 + /* 2.0.1: use gdImageSetPixel to do the alpha blending work,
5249 + * or to just store the alpha level. All we have to do here
5250 + * is incorporate our knowledge of the percentage of this
5251 + * pixel that is really "lit" by pushing the alpha value
5252 + * up toward transparency in edge regions.
5254 + a->tweencolor = gdTrueColorAlpha(
5255 + gdTrueColorGetRed(fg),
5256 + gdTrueColorGetGreen(fg),
5257 + gdTrueColorGetBlue(fg),
5258 + gdAlphaMax - (gdTrueColorGetAlpha (fg) * pixel / NUMCOLORS));
5260 + a->tweencolor = gdImageColorResolve(im,
5261 + (pixel * im->red[fg] + npixel * im->red[bg]) / NUMCOLORS,
5262 + (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS,
5263 + (pixel * im->blue[fg] + npixel * im->blue[bg]) / NUMCOLORS);
5266 + return (void *) a;
5270 -tweenColorRelease (void *element)
5271 +static void tweenColorRelease (void *element)
5273 - gdFree ((char *) element);
5274 + gdFree((char *) element);
5277 /* draw_bitmap - transfers glyph bitmap to GD image */
5279 -gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
5280 +static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
5282 - unsigned char *pixel = NULL;
5283 - int *tpixel = NULL;
5284 - int x, y, row, col, pc, pcr;
5286 - tweencolor_t *tc_elem;
5287 - tweencolorkey_t tc_key;
5289 - /* copy to image, mapping colors */
5290 - tc_key.fgcolor = fg;
5292 - /* Truecolor version; does not require the cache */
5293 - if (im->trueColor)
5295 - for (row = 0; row < bitmap.rows; row++)
5297 - pc = row * bitmap.pitch;
5300 - /* clip if out of bounds */
5301 - /* 2.0.16: clipping rectangle, not image bounds */
5302 - if ((y > im->cy2) || (y < im->cy1))
5304 - for (col = 0; col < bitmap.width; col++, pc++)
5307 - if (bitmap.pixel_mode == ft_pixel_mode_grays)
5310 - * Scale to 128 levels of alpha for gd use.
5311 - * alpha 0 is opacity, so be sure to invert at the end
5313 - level = (bitmap.buffer[pc] * gdAlphaMax /
5314 - (bitmap.num_grays - 1));
5316 - else if (bitmap.pixel_mode == ft_pixel_mode_mono)
5318 - /* 2.0.5: mode_mono fix from Giuliano Pochini */
5319 - level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07)))
5320 - ? gdAlphaTransparent :
5325 - return "Unsupported ft_pixel_mode";
5327 - if ((fg >= 0) && (im->trueColor)) {
5328 - /* Consider alpha in the foreground color itself to be an
5329 - upper bound on how opaque things get, when truecolor is
5330 - available. Without truecolor this results in far too many
5332 - level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax;
5334 - level = gdAlphaMax - level;
5336 - /* clip if out of bounds */
5337 - /* 2.0.16: clip to clipping rectangle, Matt McNabb */
5338 - if ((x > im->cx2) || (x < im->cx1))
5340 - /* get pixel location in gd buffer */
5341 - tpixel = &im->tpixels[y][x];
5343 - if (level < (gdAlphaMax / 2)) {
5347 - if (im->alphaBlendingFlag) {
5348 - *tpixel = gdAlphaBlend(*tpixel, (level << 24) + (fg & 0xFFFFFF));
5350 - *tpixel = (level << 24) + (fg & 0xFFFFFF);
5355 - return (char *) NULL;
5357 - /* Non-truecolor case, restored to its more or less original form */
5358 - for (row = 0; row < bitmap.rows; row++)
5361 - pc = row * bitmap.pitch;
5363 - if(bitmap.pixel_mode==ft_pixel_mode_mono)
5364 - pc *= 8; /* pc is measured in bits for monochrome images */
5368 - /* clip if out of bounds */
5369 - if (y >= im->sy || y < 0)
5372 - for (col = 0; col < bitmap.width; col++, pc++)
5374 - if (bitmap.pixel_mode == ft_pixel_mode_grays)
5377 - * Round to NUMCOLORS levels of antialiasing for
5378 - * index color images since only 256 colors are
5381 - tc_key.pixel = ((bitmap.buffer[pc] * NUMCOLORS)
5382 - + bitmap.num_grays / 2)
5383 - / (bitmap.num_grays - 1);
5385 - else if (bitmap.pixel_mode == ft_pixel_mode_mono)
5387 - tc_key.pixel = ((bitmap.buffer[pc / 8]
5388 - << (pc % 8)) & 128) ? NUMCOLORS : 0;
5389 - /* 2.0.5: mode_mono fix from Giuliano Pochini */
5390 - tc_key.pixel = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07)))
5395 - return "Unsupported ft_pixel_mode";
5397 - if (tc_key.pixel > 0) /* if not background */
5401 - /* clip if out of bounds */
5402 - if (x >= im->sx || x < 0)
5404 - /* get pixel location in gd buffer */
5405 - pixel = &im->pixels[y][x];
5406 - if (tc_key.pixel == NUMCOLORS)
5408 - /* use fg color directly. gd 2.0.2: watch out for
5409 - negative indexes (thanks to David Marwood). */
5410 - *pixel = (fg < 0) ? -fg : fg;
5414 - /* find antialised color */
5416 - tc_key.bgcolor = *pixel;
5417 - gdMutexLock(gdFontCacheMutex);
5418 - tc_elem = (tweencolor_t *) gdCacheGet (tc_cache, &tc_key);
5419 - *pixel = tc_elem->tweencolor;
5420 - gdMutexUnlock(gdFontCacheMutex);
5421 + unsigned char *pixel = NULL;
5422 + int *tpixel = NULL;
5423 + int x, y, row, col, pc, pcr;
5425 + tweencolor_t *tc_elem;
5426 + tweencolorkey_t tc_key;
5428 + /* copy to image, mapping colors */
5429 + tc_key.fgcolor = fg;
5431 + /* Truecolor version; does not require the cache */
5432 + if (im->trueColor) {
5433 + for (row = 0; row < bitmap.rows; row++) {
5434 + pc = row * bitmap.pitch;
5437 + /* clip if out of bounds */
5438 + /* 2.0.16: clipping rectangle, not image bounds */
5439 + if ((y > im->cy2) || (y < im->cy1)) {
5442 + for (col = 0; col < bitmap.width; col++, pc++) {
5444 + if (bitmap.pixel_mode == ft_pixel_mode_grays) {
5445 + /* Scale to 128 levels of alpha for gd use.
5446 + * alpha 0 is opacity, so be sure to invert at the end
5448 + level = (bitmap.buffer[pc] * gdAlphaMax / (bitmap.num_grays - 1));
5449 + } else if (bitmap.pixel_mode == ft_pixel_mode_mono) {
5450 + /* 2.0.5: mode_mono fix from Giuliano Pochini */
5451 + level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) ? gdAlphaTransparent : gdAlphaOpaque;
5453 + return "Unsupported ft_pixel_mode";
5455 + if ((fg >= 0) && (im->trueColor)) {
5456 + /* Consider alpha in the foreground color itself to be an
5457 + * upper bound on how opaque things get, when truecolor is
5458 + * available. Without truecolor this results in far too many
5461 + level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax;
5463 + level = gdAlphaMax - level;
5465 + /* clip if out of bounds */
5466 + /* 2.0.16: clip to clipping rectangle, Matt McNabb */
5467 + if ((x > im->cx2) || (x < im->cx1)) {
5470 + /* get pixel location in gd buffer */
5471 + tpixel = &im->tpixels[y][x];
5473 + if (level < (gdAlphaMax / 2)) {
5477 + if (im->alphaBlendingFlag) {
5478 + *tpixel = gdAlphaBlend(*tpixel, (level << 24) + (fg & 0xFFFFFF));
5480 + *tpixel = (level << 24) + (fg & 0xFFFFFF);
5485 + return (char *) NULL;
5487 + /* Non-truecolor case, restored to its more or less original form */
5488 + for (row = 0; row < bitmap.rows; row++) {
5490 + pc = row * bitmap.pitch;
5492 + if (bitmap.pixel_mode==ft_pixel_mode_mono) {
5493 + pc *= 8; /* pc is measured in bits for monochrome images */
5497 + /* clip if out of bounds */
5498 + if (y >= im->sy || y < 0) {
5502 + for (col = 0; col < bitmap.width; col++, pc++) {
5503 + if (bitmap.pixel_mode == ft_pixel_mode_grays) {
5505 + * Round to NUMCOLORS levels of antialiasing for
5506 + * index color images since only 256 colors are
5509 + tc_key.pixel = ((bitmap.buffer[pc] * NUMCOLORS) + bitmap.num_grays / 2) / (bitmap.num_grays - 1);
5510 + } else if (bitmap.pixel_mode == ft_pixel_mode_mono) {
5511 + tc_key.pixel = ((bitmap.buffer[pc / 8] << (pc % 8)) & 128) ? NUMCOLORS : 0;
5512 + /* 2.0.5: mode_mono fix from Giuliano Pochini */
5513 + tc_key.pixel = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07))) ? NUMCOLORS : 0;
5515 + return "Unsupported ft_pixel_mode";
5517 + if (tc_key.pixel > 0) { /* if not background */
5520 + /* clip if out of bounds */
5521 + if (x >= im->sx || x < 0) {
5524 + /* get pixel location in gd buffer */
5525 + pixel = &im->pixels[y][x];
5526 + if (tc_key.pixel == NUMCOLORS) {
5527 + /* use fg color directly. gd 2.0.2: watch out for
5528 + * negative indexes (thanks to David Marwood).
5530 + *pixel = (fg < 0) ? -fg : fg;
5532 + /* find antialised color */
5533 + tc_key.bgcolor = *pixel;
5534 + tc_elem = (tweencolor_t *) gdCacheGet(tc_cache, &tc_key);
5535 + *pixel = tc_elem->tweencolor;
5542 - return (char *) NULL;
5543 + return (char *) NULL;
5547 gdroundupdown (FT_F26Dot6 v1, int updown)
5550 - ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6)
5551 - : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6);
5552 + return (!updown) ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6) : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6);
5555 void gdFontCacheShutdown()
5557 + gdMutexLock(gdFontCacheMutex);
5560 - gdMutexLock(gdFontCacheMutex);
5561 gdCacheDelete(fontCache);
5563 - gdMutexUnlock(gdFontCacheMutex);
5564 - gdMutexShutdown(gdFontCacheMutex);
5565 FT_Done_FreeType(library);
5568 + gdMutexUnlock(gdFontCacheMutex);
5571 void gdFreeFontCache()
5573 gdFontCacheShutdown();
5577 +void gdFontCacheMutexSetup()
5579 + gdMutexSetup(gdFontCacheMutex);
5582 +void gdFontCacheMutexShutdown()
5584 + gdMutexShutdown(gdFontCacheMutex);
5587 int gdFontCacheSetup(void)
5590 /* Already set up */
5593 - gdMutexSetup(gdFontCacheMutex);
5594 if (FT_Init_FreeType(&library)) {
5595 - gdMutexShutdown(gdFontCacheMutex);
5598 fontCache = gdCacheCreate (FONTCACHESIZE, fontTest, fontFetch, fontRelease);
5603 /********************************************************************/
5604 /* gdImageStringFT - render a utf8 string onto a gd image */
5607 -gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
5608 - double ptsize, double angle, int x, int y, char *string)
5609 +gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
5610 + double ptsize, double angle, int x, int y, char *string)
5612 return gdImageStringFTEx(im, brect, fg, fontlist, ptsize, angle, x, y, string, 0);
5614 @@ -856,15 +814,16 @@
5616 /***** initialize font library and font cache on first call ******/
5618 + gdMutexLock(gdFontCacheMutex);
5620 if (gdFontCacheSetup() != 0) {
5621 gdCacheDelete(tc_cache);
5622 + gdMutexUnlock(gdFontCacheMutex);
5623 return "Failure to initialize font library";
5628 - gdMutexLock(gdFontCacheMutex);
5630 /* get the font (via font cache) */
5631 fontkey.fontlist = fontlist;
5632 fontkey.library = &library;
5638 /* carriage returns */
5642 /* I do not know the significance of the constant 0xf000.
5643 * It was determined by inspection of the character codes
5644 * stored in Microsoft font symbol.
5645 + * Added by Pierre (pajoye@php.net):
5646 + * Convert to the Symbol glyph range only for a Symbol family member
5648 - /* Convert to the Symbol glyph range only for a Symbol family member */
5649 len = gdTcl_UtfToUniChar (next, &ch);
5652 @@ -1008,7 +969,7 @@
5656 - case gdFTEX_Shift_JIS:
5657 + case gdFTEX_Shift_JIS:
5658 if (font->have_char_map_sjis) {
5661 @@ -1063,7 +1024,7 @@
5662 FT_Set_Transform(face, &matrix, NULL);
5663 /* Convert character code to glyph index */
5664 glyph_index = FT_Get_Char_Index(face, ch);
5667 /* retrieve kerning distance and move pen position */
5668 if (use_kerning && previous && glyph_index) {
5669 FT_Get_Kerning(face, previous, glyph_index, ft_kerning_default, &delta);
5670 diff -urN php-4.4.8.org/ext/gd/libgd/gd_gd2.c php-4.4.8/ext/gd/libgd/gd_gd2.c
5671 --- php-4.4.8.org/ext/gd/libgd/gd_gd2.c 2004-03-29 20:21:00.000000000 +0200
5672 +++ php-4.4.8/ext/gd/libgd/gd_gd2.c 2006-08-08 13:56:36.000000000 +0200
5674 /* 2.11: not part of the API, as the save routine can figure it out
5675 * from im->trueColor, and the load routine doesn't need to tell
5676 * the end user the saved format. NOTE: adding 2 is assumed
5677 - * to result in the correct format value for truecolor!
5678 + * to result in the correct format value for truecolor!
5680 #define GD2_FMT_TRUECOLOR_RAW 3
5681 #define GD2_FMT_TRUECOLOR_COMPRESSED 4
5690 extern int _gdGetColors(gdIOCtx * in, gdImagePtr im, int gd2xFlag);
5691 extern void _gdPutColors(gdImagePtr im, gdIOCtx * out);
5696 - GD2_DBG(php_gd_error("Reading gd2 header info\n"));
5697 + GD2_DBG(php_gd_error("Reading gd2 header info"));
5699 for (i = 0; i < 4; i++) {
5705 - GD2_DBG(php_gd_error("Got file code: %s\n", id));
5706 + GD2_DBG(php_gd_error("Got file code: %s", id));
5708 /* Equiv. of 'magick'. */
5709 if (strcmp(id, GD2_ID) != 0) {
5710 - GD2_DBG(php_gd_error("Not a valid gd2 file\n"));
5711 + GD2_DBG(php_gd_error("Not a valid gd2 file"));
5716 if (gdGetWord(vers, in) != 1) {
5719 - GD2_DBG(php_gd_error("Version: %d\n", *vers));
5720 + GD2_DBG(php_gd_error("Version: %d", *vers));
5722 if ((*vers != 1) && (*vers != 2)) {
5723 - GD2_DBG(php_gd_error("Bad version: %d\n", *vers));
5724 + GD2_DBG(php_gd_error("Bad version: %d", *vers));
5729 if (!gdGetWord(sx, in)) {
5730 - GD2_DBG(php_gd_error("Could not get x-size\n"));
5731 + GD2_DBG(php_gd_error("Could not get x-size"));
5734 if (!gdGetWord(sy, in)) {
5735 - GD2_DBG(php_gd_error("Could not get y-size\n"));
5736 + GD2_DBG(php_gd_error("Could not get y-size"));
5739 - GD2_DBG(php_gd_error("Image is %dx%d\n", *sx, *sy));
5740 + GD2_DBG(php_gd_error("Image is %dx%d", *sx, *sy));
5742 /* Chunk Size (pixels, not bytes!) */
5743 if (gdGetWord(cs, in) != 1) {
5746 - GD2_DBG(php_gd_error("ChunkSize: %d\n", *cs));
5747 + GD2_DBG(php_gd_error("ChunkSize: %d", *cs));
5749 if ((*cs < GD2_CHUNKSIZE_MIN) || (*cs > GD2_CHUNKSIZE_MAX)) {
5750 - GD2_DBG(php_gd_error("Bad chunk size: %d\n", *cs));
5751 + GD2_DBG(php_gd_error("Bad chunk size: %d", *cs));
5755 @@ -117,10 +116,10 @@
5756 if (gdGetWord(fmt, in) != 1) {
5759 - GD2_DBG(php_gd_error("Format: %d\n", *fmt));
5760 + GD2_DBG(php_gd_error("Format: %d", *fmt));
5762 if ((*fmt != GD2_FMT_RAW) && (*fmt != GD2_FMT_COMPRESSED) && (*fmt != GD2_FMT_TRUECOLOR_RAW) && (*fmt != GD2_FMT_TRUECOLOR_COMPRESSED)) {
5763 - GD2_DBG(php_gd_error("Bad data format: %d\n", *fmt));
5764 + GD2_DBG(php_gd_error("Bad data format: %d", *fmt));
5768 @@ -128,17 +127,17 @@
5769 if (gdGetWord(ncx, in) != 1) {
5772 - GD2_DBG(php_gd_error("%d Chunks Wide\n", *ncx));
5773 + GD2_DBG(php_gd_error("%d Chunks Wide", *ncx));
5775 /* # of chunks high */
5776 if (gdGetWord(ncy, in) != 1) {
5779 - GD2_DBG(php_gd_error("%d Chunks vertically\n", *ncy));
5780 + GD2_DBG(php_gd_error("%d Chunks vertically", *ncy));
5782 if (gd2_compressed(*fmt)) {
5783 nc = (*ncx) * (*ncy);
5784 - GD2_DBG(php_gd_error("Reading %d chunk index entries\n", nc));
5785 + GD2_DBG(php_gd_error("Reading %d chunk index entries", nc));
5786 sidx = sizeof(t_chunk_info) * nc;
5793 - GD2_DBG(php_gd_error("gd2 header complete\n"));
5794 + GD2_DBG(php_gd_error("gd2 header complete"));
5801 if (_gd2GetHeader (in, sx, sy, cs, vers, fmt, ncx, ncy, cidx) != 1) {
5802 - GD2_DBG(php_gd_error("Bad GD2 header\n"));
5803 + GD2_DBG(php_gd_error("Bad GD2 header"));
5807 @@ -178,15 +177,15 @@
5808 im = gdImageCreate(*sx, *sy);
5811 - GD2_DBG(php_gd_error("Could not create gdImage\n"));
5812 + GD2_DBG(php_gd_error("Could not create gdImage"));
5816 if (!_gdGetColors(in, im, (*vers) == 2)) {
5817 - GD2_DBG(php_gd_error("Could not read color palette\n"));
5818 + GD2_DBG(php_gd_error("Could not read color palette"));
5821 - GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal));
5822 + GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal));
5826 @@ -203,25 +202,25 @@
5829 if (gdTell(in) != offset) {
5830 - GD2_DBG(php_gd_error("Positioning in file to %d\n", offset));
5831 + GD2_DBG(php_gd_error("Positioning in file to %d", offset));
5834 - GD2_DBG(php_gd_error("Already Positioned in file to %d\n", offset));
5835 + GD2_DBG(php_gd_error("Already Positioned in file to %d", offset));
5838 /* Read and uncompress an entire chunk. */
5839 - GD2_DBG(php_gd_error("Reading file\n"));
5840 + GD2_DBG(php_gd_error("Reading file"));
5841 if (gdGetBuf(compBuf, compSize, in) != compSize) {
5844 - GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes\n", compSize, (int)*chunkLen));
5845 + GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes", compSize, (int)*chunkLen));
5846 zerr = uncompress((unsigned char *) chunkBuf, chunkLen, (unsigned char *) compBuf, compSize);
5848 - GD2_DBG(php_gd_error("Error %d from uncompress\n", zerr));
5849 + GD2_DBG(php_gd_error("Error %d from uncompress", zerr));
5852 - GD2_DBG(php_gd_error("Got chunk\n"));
5854 + GD2_DBG(php_gd_error("Got chunk"));
5861 chunkBuf = gdCalloc(chunkMax, 1);
5862 compBuf = gdCalloc(compMax, 1);
5864 - GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes\n", compMax));
5866 + GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes", compMax));
5869 /* Read the data... */
5870 @@ -304,13 +303,13 @@
5874 - GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d\n", chunkNum, cx, cy, ylo, yhi));
5875 + GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d", chunkNum, cx, cy, ylo, yhi));
5877 if (gd2_compressed(fmt)) {
5878 chunkLen = chunkMax;
5880 if (!_gd2ReadChunk(chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *) chunkBuf, &chunkLen, in)) {
5881 - GD2_DBG(php_gd_error("Error reading comproessed chunk\n"));
5882 + GD2_DBG(php_gd_error("Error reading comproessed chunk"));
5890 - GD2_DBG(php_gd_error("Freeing memory\n"));
5891 + GD2_DBG(php_gd_error("Freeing memory"));
5899 - GD2_DBG(php_gd_error("Done\n"));
5900 + GD2_DBG(php_gd_error("Done"));
5908 -gdImagePtr gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h)
5909 +gdImagePtr gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h)
5912 gdIOCtx *in = gdNewFileCtx(inFile);
5913 @@ -431,6 +430,10 @@
5917 + if (w<1 || h <1) {
5921 /* The next few lines are basically copied from gd2CreateFromFile
5922 * we change the file size, so don't want to use the code directly.
5923 * but we do need to know the file size.
5928 - GD2_DBG(php_gd_error("File size is %dx%d\n", fsx, fsy));
5929 + GD2_DBG(php_gd_error("File size is %dx%d", fsx, fsy));
5931 /* This is the difference - make a file based on size of chunks. */
5932 if (gd2_truecolor(fmt)) {
5934 if (!_gdGetColors(in, im, vers == 2)) {
5937 - GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal));
5938 + GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal));
5940 /* Process the header info */
5943 if (chunkMax <= 0) {
5948 chunkBuf = gdCalloc(chunkMax, 1);
5949 compBuf = gdCalloc(compMax, 1);
5953 /* Remember file position of image data. */
5954 dstart = gdTell(in);
5955 - GD2_DBG(php_gd_error("Data starts at %d\n", dstart));
5956 + GD2_DBG(php_gd_error("Data starts at %d", dstart));
5958 /* Loop through the chunks. */
5959 for (cy = scy; (cy <= ecy); cy++) {
5960 @@ -521,10 +524,10 @@
5964 - GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d\n", cx, cy, ylo, yhi));
5965 + GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d", cx, cy, ylo, yhi));
5967 if (!gd2_compressed(fmt)) {
5968 - GD2_DBG(php_gd_error("Using raw format data\n"));
5969 + GD2_DBG(php_gd_error("Using raw format data"));
5970 if (im->trueColor) {
5971 dpos = (cy * (cs * fsx) * 4 + cx * cs * (yhi - ylo) * 4) + dstart;
5973 @@ -533,29 +536,29 @@
5975 /* gd 2.0.11: gdSeek returns TRUE on success, not 0. Longstanding bug. 01/16/03 */
5976 if (!gdSeek(in, dpos)) {
5977 - php_gd_error_ex(E_WARNING, "Error from seek: %d\n", errno);
5978 + php_gd_error_ex(E_WARNING, "Error from seek: %d", errno);
5981 - GD2_DBG(php_gd_error("Reading (%d, %d) from position %d\n", cx, cy, dpos - dstart));
5982 + GD2_DBG(php_gd_error("Reading (%d, %d) from position %d", cx, cy, dpos - dstart));
5984 chunkNum = cx + cy * ncx;
5986 chunkLen = chunkMax;
5987 - if (!_gd2ReadChunk (chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, chunkBuf, &chunkLen, in)) {
5988 - php_gd_error("Error reading comproessed chunk\n");
5989 + if (!_gd2ReadChunk (chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *)chunkBuf, &chunkLen, in)) {
5990 + php_gd_error("Error reading comproessed chunk");
5994 - GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d\n", cx, cy, chunkNum));
5995 + GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d", cx, cy, chunkNum));
5998 - GD2_DBG(php_gd_error(" into (%d, %d) - (%d, %d)\n", xlo, ylo, xhi, yhi));
5999 + GD2_DBG(php_gd_error(" into (%d, %d) - (%d, %d)", xlo, ylo, xhi, yhi));
6001 for (y = ylo; (y < yhi); y++) {
6002 for (x = xlo; x < xhi; x++) {
6003 if (!gd2_compressed(fmt)) {
6004 if (im->trueColor) {
6005 - if (!gdGetInt(&ch, in)) {
6006 + if (!gdGetInt((int *)&ch, in)) {
6010 @@ -577,11 +580,11 @@
6012 /* Only use a point that is in the image. */
6013 if ((x >= srcx) && (x < (srcx + w)) && (x < fsx) && (x >= 0) && (y >= srcy) && (y < (srcy + h)) && (y < fsy) && (y >= 0)) {
6014 - if (im->trueColor) {
6015 + if (im->trueColor) {
6016 im->tpixels[y - srcy][x - srcx] = ch;
6018 im->pixels[y - srcy][x - srcx] = ch;
6036 /* Force fmt to a valid value since we don't return anything. */
6037 - if ((fmt != GD2_FMT_RAW) && (fmt != GD2_FMT_COMPRESSED)) {
6038 + if ((fmt != GD2_FMT_RAW) && (fmt != GD2_FMT_COMPRESSED)) {
6039 fmt = im->trueColor ? GD2_FMT_TRUECOLOR_COMPRESSED : GD2_FMT_COMPRESSED;
6041 if (im->trueColor) {
6042 @@ -693,16 +696,16 @@
6043 chunkData = safe_emalloc(cs * bytesPerPixel, cs, 0);
6044 memset(chunkData, 0, cs * bytesPerPixel * cs);
6049 compData = gdCalloc(compMax, 1);
6051 /* Save the file position of chunk index, and allocate enough space for
6052 - * each chunk_info block .
6053 + * each chunk_info block .
6055 idxPos = gdTell(out);
6056 idxSize = ncx * ncy * sizeof(t_chunk_info);
6057 - GD2_DBG(php_gd_error("Index size is %d\n", idxSize));
6058 + GD2_DBG(php_gd_error("Index size is %d", idxSize));
6059 gdSeek(out, idxPos + idxSize);
6061 chunkIdx = safe_emalloc(idxSize, sizeof(t_chunk_info), 0);
6064 _gdPutColors (im, out);
6066 - GD2_DBG(php_gd_error("Size: %dx%d\n", im->sx, im->sy));
6067 - GD2_DBG(php_gd_error("Chunks: %dx%d\n", ncx, ncy));
6068 + GD2_DBG(php_gd_error("Size: %dx%d", im->sx, im->sy));
6069 + GD2_DBG(php_gd_error("Chunks: %dx%d", ncx, ncy));
6071 for (cy = 0; (cy < ncy); cy++) {
6072 for (cx = 0; (cx < ncx); cx++) {
6077 - GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d\n", cx, cy, ylo, yhi));
6078 + GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d", cx, cy, ylo, yhi));
6080 for (y = ylo; (y < yhi); y++) {
6081 GD2_DBG(php_gd_error("y=%d: ",y));
6085 for (x = xlo; x < xhi; x++) {
6086 - GD2_DBG(php_gd_error("%d, ",x));
6087 + GD2_DBG(php_gd_error("%d, ",x));
6089 if (im->trueColor) {
6090 gdPutInt(im->tpixels[y][x], out);
6091 @@ -756,21 +759,21 @@
6095 - GD2_DBG(php_gd_error("y=%d done.\n",y));
6096 + GD2_DBG(php_gd_error("y=%d done.",y));
6099 if (gd2_compressed(fmt)) {
6101 if (compress((unsigned char *) &compData[0], &compLen, (unsigned char *) &chunkData[0], chunkLen) != Z_OK) {
6102 - php_gd_error("Error from compressing\n");
6103 + php_gd_error("Error from compressing");
6105 chunkIdx[chunkNum].offset = gdTell(out);
6106 chunkIdx[chunkNum++].size = compLen;
6107 - GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
6108 + GD2_DBG(php_gd_error("Chunk %d size %d offset %d", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
6110 if (gdPutBuf (compData, compLen, out) <= 0) {
6111 /* Any alternate suggestions for handling this? */
6112 - php_gd_error_ex(E_WARNING, "Error %d on write\n", errno);
6113 + php_gd_error_ex(E_WARNING, "Error %d on write", errno);
6117 @@ -779,29 +782,29 @@
6119 if (gd2_compressed(fmt)) {
6120 /* Save the position, write the index, restore position (paranoia). */
6121 - GD2_DBG(php_gd_error("Seeking %d to write index\n", idxPos));
6122 + GD2_DBG(php_gd_error("Seeking %d to write index", idxPos));
6123 posSave = gdTell(out);
6124 gdSeek(out, idxPos);
6125 - GD2_DBG(php_gd_error("Writing index\n"));
6126 + GD2_DBG(php_gd_error("Writing index"));
6127 for (x = 0; x < chunkNum; x++) {
6128 - GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", x, chunkIdx[x].size, chunkIdx[x].offset));
6129 + GD2_DBG(php_gd_error("Chunk %d size %d offset %d", x, chunkIdx[x].size, chunkIdx[x].offset));
6130 gdPutInt(chunkIdx[x].offset, out);
6131 gdPutInt(chunkIdx[x].size, out);
6133 gdSeek(out, posSave);
6136 - GD2_DBG(php_gd_error("Freeing memory\n"));
6137 + GD2_DBG(php_gd_error("Freeing memory"));
6148 - GD2_DBG(php_gd_error("Done\n"));
6149 + GD2_DBG(php_gd_error("Done"));
6152 void gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt)
6154 gdIOCtx *out = gdNewFileCtx(outFile);
6156 _gdImageGd2(im, out, cs, fmt);
6163 _gdImageGd2(im, out, cs, fmt);
6164 rv = gdDPExtractData(out, size);
6170 diff -urN php-4.4.8.org/ext/gd/libgd/gd_gd.c php-4.4.8/ext/gd/libgd/gd_gd.c
6171 --- php-4.4.8.org/ext/gd/libgd/gd_gd.c 2004-03-29 20:21:00.000000000 +0200
6172 +++ php-4.4.8/ext/gd/libgd/gd_gd.c 2007-08-09 16:21:38.000000000 +0200
6181 GD2_DBG(printf("Pallette had %d colours (T=%d)\n", im->colorsTotal, im->transparent));
6184 if (im->trueColor) {
6189 im = gdImageCreate(*sx, *sy);
6194 if (!_gdGetColors(in, im, gd2xFlag)) {
6199 static void _gdPutHeader (gdImagePtr im, gdIOCtx * out)
6201 - /* 65535 indicates this is a gd 2.x .gd file.
6202 + /* 65535 indicates this is a gd 2.x .gd file.
6203 * 2.0.12: 65534 indicates truecolor.
6205 if (im->trueColor) {
6206 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
6207 --- php-4.4.8.org/ext/gd/libgd/gd_gif_in.c 2007-06-08 07:31:02.000000000 +0200
6208 +++ php-4.4.8/ext/gd/libgd/gd_gif_in.c 2007-06-07 23:07:33.000000000 +0200
6211 static int set_verbose(void)
6213 - verbose = !!getenv("GIF_VERBOSE");
6216 + verbose = !!getenv("GIF_VERBOSE");
6222 @@ -44,270 +44,313 @@
6223 #define LOCALCOLORMAP 0x80
6224 #define BitSet(byte, bit) (((byte) & (bit)) == (bit))
6226 -#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) != 0)
6227 +#define ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) > 0)
6229 #define LM_to_uint(a,b) (((b)<<8)|(a))
6231 /* We may eventually want to use this information, but def it out for now */
6234 - unsigned int Width;
6235 - unsigned int Height;
6236 - unsigned char ColorMap[3][MAXCOLORMAPSIZE];
6237 - unsigned int BitPixel;
6238 - unsigned int ColorResolution;
6239 - unsigned int Background;
6240 - unsigned int AspectRatio;
6241 + unsigned int Width;
6242 + unsigned int Height;
6243 + unsigned char ColorMap[3][MAXCOLORMAPSIZE];
6244 + unsigned int BitPixel;
6245 + unsigned int ColorResolution;
6246 + unsigned int Background;
6247 + unsigned int AspectRatio;
6261 } Gif89 = { -1, -1, -1, 0 };
6264 -static int ReadColorMap (gdIOCtx *fd, int number, unsigned char (*buffer)[256]);
6265 -static int DoExtension (gdIOCtx *fd, int label, int *Transparent);
6266 -static int GetDataBlock (gdIOCtx *fd, unsigned char *buf);
6267 -static int GetCode (gdIOCtx *fd, int code_size, int flag);
6268 -static int LWZReadByte (gdIOCtx *fd, int flag, int input_code_size);
6269 +#define STACK_SIZE ((1<<(MAX_LWZ_BITS))*2)
6271 -static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace); /*1.4//, int ignore); */
6273 + unsigned char buf[280];
6274 + int curbit, lastbit, done, last_byte;
6275 +} CODE_STATIC_DATA;
6279 + int code_size, set_code_size;
6280 + int max_code, max_code_size;
6281 + int firstcode, oldcode;
6282 + int clear_code, end_code;
6283 + int table[2][(1<< MAX_LWZ_BITS)];
6284 + int stack[STACK_SIZE], *sp;
6285 + CODE_STATIC_DATA scd;
6289 +static int ReadColorMap (gdIOCtx *fd, int number, unsigned char (*buffer)[256]);
6290 +static int DoExtension (gdIOCtx *fd, int label, int *Transparent, int *ZeroDataBlockP);
6291 +static int GetDataBlock (gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP);
6292 +static int GetCode (gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP);
6293 +static int LWZReadByte (gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, int *ZeroDataBlockP);
6295 +static void ReadImage (gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace, int *ZeroDataBlockP); /*1.4//, int ignore); */
6297 -gdImagePtr gdImageCreateFromGifSource(gdSourcePtr inSource)
6298 +gdImagePtr gdImageCreateFromGifSource(gdSourcePtr inSource) /* {{{ */
6300 - gdIOCtx *in = gdNewSSCtx(inSource, NULL);
6302 + gdIOCtx *in = gdNewSSCtx(inSource, NULL);
6305 - im = gdImageCreateFromGifCtx(in);
6306 + im = gdImageCreateFromGifCtx(in);
6317 -gdImageCreateFromGif(FILE *fdFile)
6318 +gdImagePtr gdImageCreateFromGif(FILE *fdFile) /* {{{ */
6320 - gdIOCtx *fd = gdNewFileCtx(fdFile);
6321 - gdImagePtr im = 0;
6322 + gdIOCtx *fd = gdNewFileCtx(fdFile);
6323 + gdImagePtr im = 0;
6325 - im = gdImageCreateFromGifCtx(fd);
6326 + im = gdImageCreateFromGifCtx(fd);
6337 -gdImageCreateFromGifCtx(gdIOCtxPtr fd)
6338 +gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */
6340 -/* 1.4 int imageNumber; */
6342 - int ColorResolution;
6345 - int Transparent = (-1);
6346 - unsigned char buf[16];
6348 - unsigned char ColorMap[3][MAXCOLORMAPSIZE];
6349 - unsigned char localColorMap[3][MAXCOLORMAPSIZE];
6351 - int useGlobalColormap;
6354 - /*1.4//int imageCount = 0; */
6357 - gdImagePtr im = 0;
6358 - ZeroDataBlock = FALSE;
6361 + int ColorResolution;
6365 + int Transparent = (-1);
6366 + unsigned char buf[16];
6368 + unsigned char ColorMap[3][MAXCOLORMAPSIZE];
6369 + unsigned char localColorMap[3][MAXCOLORMAPSIZE];
6370 + int imw, imh, screen_width, screen_height;
6371 + int gif87a, useGlobalColormap;
6374 + /*1.4//int imageCount = 0; */
6376 + int ZeroDataBlock = FALSE;
6377 + int haveGlobalColormap;
6378 + gdImagePtr im = 0;
6380 - /*1.4//imageNumber = 1; */
6381 - if (! ReadOK(fd,buf,6)) {
6382 + /*1.4//imageNumber = 1; */
6383 + if (! ReadOK(fd,buf,6)) {
6386 - if (strncmp((char *)buf,"GIF",3) != 0) {
6387 + if (strncmp((char *)buf,"GIF",3) != 0) {
6390 - strncpy(version, (char *)buf + 3, 3);
6391 - version[3] = '\0';
6393 - if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) {
6394 + if (memcmp((char *)buf+3, "87a", 3) == 0) {
6396 + } else if (memcmp((char *)buf+3, "89a", 3) == 0) {
6401 - if (! ReadOK(fd,buf,7)) {
6403 + if (! ReadOK(fd,buf,7)) {
6406 - BitPixel = 2<<(buf[4]&0x07);
6407 - ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
6408 - Background = buf[5];
6409 - AspectRatio = buf[6];
6411 - imw = LM_to_uint(buf[0],buf[1]);
6412 - imh = LM_to_uint(buf[2],buf[3]);
6413 + BitPixel = 2<<(buf[4]&0x07);
6415 + ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
6416 + Background = buf[5];
6417 + AspectRatio = buf[6];
6419 + screen_width = imw = LM_to_uint(buf[0],buf[1]);
6420 + screen_height = imh = LM_to_uint(buf[2],buf[3]);
6422 - if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */
6423 - if (ReadColorMap(fd, BitPixel, ColorMap)) {
6424 + haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */
6425 + if (haveGlobalColormap) {
6426 + if (ReadColorMap(fd, BitPixel, ColorMap)) {
6431 - if (! ReadOK(fd,&c,1)) {
6434 - if (c == ';') { /* GIF terminator */
6439 + int width, height;
6441 + if (! ReadOK(fd,&c,1)) {
6444 + if (c == ';') { /* GIF terminator */
6449 + if (c == '!') { /* Extension */
6450 + if (! ReadOK(fd,&c,1)) {
6453 + DoExtension(fd, c, &Transparent, &ZeroDataBlock);
6457 - if (c == '!') { /* Extension */
6458 - if (! ReadOK(fd,&c,1)) {
6461 - DoExtension(fd, c, &Transparent);
6465 - if (c != ',') { /* Not a valid start character */
6469 - /*1.4//++imageCount; */
6471 - if (! ReadOK(fd,buf,9)) {
6475 - useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
6477 - bitPixel = 1<<((buf[8]&0x07)+1);
6479 - if (!useGlobalColormap) {
6480 - if (ReadColorMap(fd, bitPixel, localColorMap)) {
6485 - if (!(im = gdImageCreate(imw, imh))) {
6488 - im->interlace = BitSet(buf[8], INTERLACE);
6489 - if (! useGlobalColormap) {
6490 - ReadImage(im, fd, imw, imh, localColorMap,
6491 - BitSet(buf[8], INTERLACE));
6492 - /*1.4//imageCount != imageNumber); */
6494 - ReadImage(im, fd, imw, imh,
6496 - BitSet(buf[8], INTERLACE));
6497 - /*1.4//imageCount != imageNumber); */
6499 - if (Transparent != (-1)) {
6500 - gdImageColorTransparent(im, Transparent);
6504 + if (c != ',') { /* Not a valid start character */
6509 - /* Terminator before any image was declared! */
6513 + /*1.4//++imageCount; */
6515 - if (!im->colorsTotal) {
6516 - gdImageDestroy(im);
6517 + if (! ReadOK(fd,buf,9)) {
6521 - /* Check for open colors at the end, so
6522 - we can reduce colorsTotal and ultimately
6524 - for (i=((im->colorsTotal-1)); (i>=0); i--) {
6525 + useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
6527 + bitPixel = 1<<((buf[8]&0x07)+1);
6528 + left = LM_to_uint(buf[0], buf[1]);
6529 + top = LM_to_uint(buf[2], buf[3]);
6530 + width = LM_to_uint(buf[4], buf[5]);
6531 + height = LM_to_uint(buf[6], buf[7]);
6533 + if (left + width > screen_width || top + height > screen_height) {
6535 + printf("Frame is not confined to screen dimension.\n");
6540 + if (!(im = gdImageCreate(width, height))) {
6543 + im->interlace = BitSet(buf[8], INTERLACE);
6544 + if (!useGlobalColormap) {
6545 + if (ReadColorMap(fd, bitPixel, localColorMap)) {
6546 + gdImageDestroy(im);
6549 + ReadImage(im, fd, width, height, localColorMap,
6550 + BitSet(buf[8], INTERLACE), &ZeroDataBlock);
6552 + if (!haveGlobalColormap) {
6553 + gdImageDestroy(im);
6556 + ReadImage(im, fd, width, height,
6558 + BitSet(buf[8], INTERLACE), &ZeroDataBlock);
6560 + if (Transparent != (-1)) {
6561 + gdImageColorTransparent(im, Transparent);
6567 + /* Terminator before any image was declared! */
6571 + if (!im->colorsTotal) {
6572 + gdImageDestroy(im);
6575 + /* Check for open colors at the end, so
6576 + we can reduce colorsTotal and ultimately
6578 + for (i=((im->colorsTotal-1)); (i>=0); i--) {
6580 - im->colorsTotal--;
6586 + im->colorsTotal--;
6596 -ReadColorMap(gdIOCtx *fd, int number, unsigned char (*buffer)[256])
6597 +static int ReadColorMap(gdIOCtx *fd, int number, unsigned char (*buffer)[256]) /* {{{ */
6600 - unsigned char rgb[3];
6602 + unsigned char rgb[3];
6605 - for (i = 0; i < number; ++i) {
6606 - if (! ReadOK(fd, rgb, sizeof(rgb))) {
6609 - buffer[CM_RED][i] = rgb[0] ;
6610 - buffer[CM_GREEN][i] = rgb[1] ;
6611 - buffer[CM_BLUE][i] = rgb[2] ;
6613 + for (i = 0; i < number; ++i) {
6614 + if (! ReadOK(fd, rgb, sizeof(rgb))) {
6617 + buffer[CM_RED][i] = rgb[0] ;
6618 + buffer[CM_GREEN][i] = rgb[1] ;
6619 + buffer[CM_BLUE][i] = rgb[2] ;
6629 -DoExtension(gdIOCtx *fd, int label, int *Transparent)
6630 +DoExtension(gdIOCtx *fd, int label, int *Transparent, int *ZeroDataBlockP)
6632 - static unsigned char buf[256];
6633 + unsigned char buf[256];
6636 + case 0xf9: /* Graphic Control Extension */
6637 + memset(buf, 0, 4); /* initialize a few bytes in the case the next function fails */
6638 + (void) GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP);
6640 + Gif89.disposal = (buf[0] >> 2) & 0x7;
6641 + Gif89.inputFlag = (buf[0] >> 1) & 0x1;
6642 + Gif89.delayTime = LM_to_uint(buf[1],buf[2]);
6644 + if ((buf[0] & 0x1) != 0)
6645 + *Transparent = buf[3];
6648 - case 0xf9: /* Graphic Control Extension */
6649 - (void) GetDataBlock(fd, (unsigned char*) buf);
6650 - Gif89.disposal = (buf[0] >> 2) & 0x7;
6651 - Gif89.inputFlag = (buf[0] >> 1) & 0x1;
6652 - Gif89.delayTime = LM_to_uint(buf[1],buf[2]);
6653 - if ((buf[0] & 0x1) != 0)
6654 - *Transparent = buf[3];
6656 - while (GetDataBlock(fd, (unsigned char*) buf) > 0)
6662 - while (GetDataBlock(fd, (unsigned char*) buf) > 0)
6664 + while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0);
6669 + while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0)
6678 -GetDataBlock_(gdIOCtx *fd, unsigned char *buf)
6679 +GetDataBlock_(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP)
6681 - unsigned char count;
6682 + unsigned char count;
6684 - if (! ReadOK(fd,&count,1)) {
6687 + if (! ReadOK(fd,&count,1)) {
6691 - ZeroDataBlock = count == 0;
6692 + *ZeroDataBlockP = count == 0;
6694 - if ((count != 0) && (! ReadOK(fd, buf, count))) {
6697 + if ((count != 0) && (! ReadOK(fd, buf, count))) {
6707 -GetDataBlock(gdIOCtx *fd, unsigned char *buf)
6708 +GetDataBlock(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP)
6714 - rv = GetDataBlock_(fd,buf);
6716 + rv = GetDataBlock_(fd,buf, ZeroDataBlockP);
6720 tmp = safe_emalloc(3 * rv, sizeof(char), 1);
6721 for (i=0;i<rv;i++) {
6722 @@ -321,281 +364,275 @@
6729 -GetCode_(gdIOCtx *fd, int code_size, int flag)
6730 +GetCode_(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP)
6732 - static unsigned char buf[280];
6733 - static int curbit, lastbit, done, last_byte;
6735 - unsigned char count;
6744 - if ( (curbit+code_size) >= lastbit) {
6746 - if (curbit >= lastbit) {
6751 - buf[0] = buf[last_byte-2];
6752 - buf[1] = buf[last_byte-1];
6754 - if ((count = GetDataBlock(fd, &buf[2])) <= 0)
6757 - last_byte = 2 + count;
6758 - curbit = (curbit - lastbit) + 16;
6759 - lastbit = (2+count)*8 ;
6763 - for (i = curbit, j = 0; j < code_size; ++i, ++j)
6764 - ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
6766 + unsigned char count;
6771 + scd->last_byte = 0;
6772 + scd->done = FALSE;
6776 + if ( (scd->curbit + code_size) >= scd->lastbit) {
6778 + if (scd->curbit >= scd->lastbit) {
6783 + scd->buf[0] = scd->buf[scd->last_byte-2];
6784 + scd->buf[1] = scd->buf[scd->last_byte-1];
6786 + if ((count = GetDataBlock(fd, &scd->buf[2], ZeroDataBlockP)) <= 0)
6789 + scd->last_byte = 2 + count;
6790 + scd->curbit = (scd->curbit - scd->lastbit) + 16;
6791 + scd->lastbit = (2+count)*8 ;
6794 - curbit += code_size;
6797 + for (i = scd->curbit, j = 0; j < code_size; ++i, ++j)
6798 + ret |= ((scd->buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
6800 + scd->curbit += code_size;
6805 -GetCode(gdIOCtx *fd, int code_size, int flag)
6806 +GetCode(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP)
6811 - rv = GetCode_(fd,code_size,flag);
6812 - if (VERBOSE) php_gd_error_ex(E_NOTICE, "[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
6814 + rv = GetCode_(fd, scd, code_size,flag, ZeroDataBlockP);
6815 + if (VERBOSE) printf("[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
6820 -#define STACK_SIZE ((1<<(MAX_LWZ_BITS))*2)
6822 -LWZReadByte_(gdIOCtx *fd, int flag, int input_code_size)
6823 +LWZReadByte_(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, int *ZeroDataBlockP)
6825 - static int fresh = FALSE;
6827 - static int code_size, set_code_size;
6828 - static int max_code, max_code_size;
6829 - static int firstcode, oldcode;
6830 - static int clear_code, end_code;
6831 - static int table[2][(1<< MAX_LWZ_BITS)];
6832 - static int stack[STACK_SIZE], *sp;
6836 - set_code_size = input_code_size;
6837 - code_size = set_code_size+1;
6838 - clear_code = 1 << set_code_size ;
6839 - end_code = clear_code + 1;
6840 - max_code_size = 2*clear_code;
6841 - max_code = clear_code+2;
6843 - GetCode(fd, 0, TRUE);
6847 - for (i = 0; i < clear_code; ++i) {
6851 - for (; i < (1<<MAX_LWZ_BITS); ++i)
6852 - table[0][i] = table[1][0] = 0;
6857 - } else if (fresh) {
6860 - firstcode = oldcode =
6861 - GetCode(fd, code_size, FALSE);
6862 - } while (firstcode == clear_code);
6869 - while ((code = GetCode(fd, code_size, FALSE)) >= 0) {
6870 - if (code == clear_code) {
6871 - for (i = 0; i < clear_code; ++i) {
6875 - for (; i < (1<<MAX_LWZ_BITS); ++i)
6876 - table[0][i] = table[1][i] = 0;
6877 - code_size = set_code_size+1;
6878 - max_code_size = 2*clear_code;
6879 - max_code = clear_code+2;
6881 - firstcode = oldcode =
6882 - GetCode(fd, code_size, FALSE);
6884 - } else if (code == end_code) {
6886 - unsigned char buf[260];
6888 - if (ZeroDataBlock)
6891 - while ((count = GetDataBlock(fd, buf)) > 0)
6900 - if (sp == (stack + STACK_SIZE)) {
6901 - /* Bad compressed data stream */
6905 - if (code >= max_code) {
6906 - *sp++ = firstcode;
6910 - while (code >= clear_code) {
6911 - if (sp == (stack + STACK_SIZE)) {
6912 - /* Bad compressed data stream */
6915 - *sp++ = table[1][code];
6916 - if (code == table[0][code]) {
6919 - code = table[0][code];
6922 - *sp++ = firstcode = table[1][code];
6924 - if ((code = max_code) <(1<<MAX_LWZ_BITS)) {
6925 - table[0][code] = oldcode;
6926 - table[1][code] = firstcode;
6928 - if ((max_code >= max_code_size) &&
6929 - (max_code_size < (1<<MAX_LWZ_BITS))) {
6930 - max_code_size *= 2;
6941 + int code, incode, i;
6944 + sd->set_code_size = input_code_size;
6945 + sd->code_size = sd->set_code_size+1;
6946 + sd->clear_code = 1 << sd->set_code_size ;
6947 + sd->end_code = sd->clear_code + 1;
6948 + sd->max_code_size = 2*sd->clear_code;
6949 + sd->max_code = sd->clear_code+2;
6951 + GetCode(fd, &sd->scd, 0, TRUE, ZeroDataBlockP);
6955 + for (i = 0; i < sd->clear_code; ++i) {
6956 + sd->table[0][i] = 0;
6957 + sd->table[1][i] = i;
6959 + for (; i < (1<<MAX_LWZ_BITS); ++i)
6960 + sd->table[0][i] = sd->table[1][0] = 0;
6962 + sd->sp = sd->stack;
6965 + } else if (sd->fresh) {
6966 + sd->fresh = FALSE;
6968 + sd->firstcode = sd->oldcode =
6969 + GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
6970 + } while (sd->firstcode == sd->clear_code);
6971 + return sd->firstcode;
6974 + if (sd->sp > sd->stack)
6977 + while ((code = GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP)) >= 0) {
6978 + if (code == sd->clear_code) {
6979 + for (i = 0; i < sd->clear_code; ++i) {
6980 + sd->table[0][i] = 0;
6981 + sd->table[1][i] = i;
6983 + for (; i < (1<<MAX_LWZ_BITS); ++i)
6984 + sd->table[0][i] = sd->table[1][i] = 0;
6985 + sd->code_size = sd->set_code_size+1;
6986 + sd->max_code_size = 2*sd->clear_code;
6987 + sd->max_code = sd->clear_code+2;
6988 + sd->sp = sd->stack;
6989 + sd->firstcode = sd->oldcode =
6990 + GetCode(fd, &sd->scd, sd->code_size, FALSE, ZeroDataBlockP);
6991 + return sd->firstcode;
6992 + } else if (code == sd->end_code) {
6994 + unsigned char buf[260];
6996 + if (*ZeroDataBlockP)
6999 + while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0)
7008 + if (sd->sp == (sd->stack + STACK_SIZE)) {
7009 + /* Bad compressed data stream */
7013 + if (code >= sd->max_code) {
7014 + *sd->sp++ = sd->firstcode;
7015 + code = sd->oldcode;
7018 + while (code >= sd->clear_code) {
7019 + if (sd->sp == (sd->stack + STACK_SIZE)) {
7020 + /* Bad compressed data stream */
7023 + *sd->sp++ = sd->table[1][code];
7024 + if (code == sd->table[0][code]) {
7027 + code = sd->table[0][code];
7030 + *sd->sp++ = sd->firstcode = sd->table[1][code];
7032 + if ((code = sd->max_code) <(1<<MAX_LWZ_BITS)) {
7033 + sd->table[0][code] = sd->oldcode;
7034 + sd->table[1][code] = sd->firstcode;
7036 + if ((sd->max_code >= sd->max_code_size) &&
7037 + (sd->max_code_size < (1<<MAX_LWZ_BITS))) {
7038 + sd->max_code_size *= 2;
7043 + sd->oldcode = incode;
7045 + if (sd->sp > sd->stack)
7053 -LWZReadByte(gdIOCtx *fd, int flag, int input_code_size)
7054 +LWZReadByte(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, int *ZeroDataBlockP)
7059 - rv = LWZReadByte_(fd,flag,input_code_size);
7060 - if (VERBOSE) php_gd_error_ex(E_NOTICE, "[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
7062 + rv = LWZReadByte_(fd, sd, flag, input_code_size, ZeroDataBlockP);
7063 + if (VERBOSE) printf("[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
7069 -ReadImage(gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace) /*1.4//, int ignore) */
7070 +ReadImage(gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)[256], int interlace, int *ZeroDataBlockP) /*1.4//, int ignore) */
7074 - int xpos = 0, ypos = 0, pass = 0;
7078 - ** Initialize the Compression routines
7080 - if (! ReadOK(fd,&c,1)) {
7084 - if (c > MAX_LWZ_BITS) {
7089 - /* Stash the color map into the image */
7090 - for (i=0; (i<gdMaxColors); i++) {
7091 - im->red[i] = cmap[CM_RED][i];
7092 - im->green[i] = cmap[CM_GREEN][i];
7093 - im->blue[i] = cmap[CM_BLUE][i];
7096 - /* Many (perhaps most) of these colors will remain marked open. */
7097 - im->colorsTotal = gdMaxColors;
7099 - if (LWZReadByte(fd, TRUE, c) < 0) {
7104 - ** If this is an "uninteresting picture" ignore it.
7105 - ** REMOVED For 1.4
7107 - /*if (ignore) { */
7108 - /* while (LWZReadByte(fd, FALSE, c) >= 0) */
7113 - while ((v = LWZReadByte(fd,FALSE,c)) >= 0 ) {
7114 - if (v >= gdMaxColors) {
7118 + int xpos = 0, ypos = 0, pass = 0;
7120 + LZW_STATIC_DATA sd;
7124 + ** Initialize the Compression routines
7126 + if (! ReadOK(fd,&c,1)) {
7130 + if (c > MAX_LWZ_BITS) {
7134 + /* Stash the color map into the image */
7135 + for (i=0; (i<gdMaxColors); i++) {
7136 + im->red[i] = cmap[CM_RED][i];
7137 + im->green[i] = cmap[CM_GREEN][i];
7138 + im->blue[i] = cmap[CM_BLUE][i];
7141 + /* Many (perhaps most) of these colors will remain marked open. */
7142 + im->colorsTotal = gdMaxColors;
7143 + if (LWZReadByte(fd, &sd, TRUE, c, ZeroDataBlockP) < 0) {
7148 + ** If this is an "uninteresting picture" ignore it.
7149 + ** REMOVED For 1.4
7151 + /*if (ignore) { */
7152 + /* while (LWZReadByte(fd, &sd, FALSE, c) >= 0) */
7157 + while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0) {
7158 + if (v >= gdMaxColors) {
7161 + /* This how we recognize which colors are actually used. */
7162 + if (im->open[v]) {
7165 + gdImageSetPixel(im, xpos, ypos, v);
7167 + if (xpos == len) {
7179 - /* This how we recognize which colors are actually used. */
7180 - if (im->open[v]) {
7183 - gdImageSetPixel(im, xpos, ypos, v);
7185 - if (xpos == len) {
7198 - if (ypos >= height) {
7215 - if (ypos >= height)
7219 + if (ypos >= height) {
7236 + if (ypos >= height)
7241 - if (LWZReadByte(fd,FALSE,c)>=0) {
7242 - /* Ignore extra */
7244 + if (LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP) >=0) {
7245 + /* Ignore extra */
7250 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
7251 --- php-4.4.8.org/ext/gd/libgd/gd_gif_out.c 2004-07-23 01:09:24.000000000 +0200
7252 +++ php-4.4.8/ext/gd/libgd/gd_gif_out.c 2006-07-26 12:03:09.000000000 +0200
7254 BitsPerPixel = colorstobpp(tim->colorsTotal);
7255 /* All set, let's do it. */
7257 - out, tim->sx, tim->sy, interlace, 0, transparent, BitsPerPixel,
7258 + out, tim->sx, tim->sy, tim->interlace, 0, tim->transparent, BitsPerPixel,
7259 tim->red, tim->green, tim->blue, tim);
7261 /* Destroy palette based temporary image. */
7262 @@ -264,10 +264,12 @@
7269 + memset(&ctx, 0, sizeof(ctx));
7270 ctx.Interlace = GInterlace;
7272 - memset(&ctx, 0, sizeof(ctx));
7275 ColorMapSize = 1 << BitsPerPixel;
7277 RWidth = ctx.Width = GWidth;
7278 diff -urN php-4.4.8.org/ext/gd/libgd/gd.h php-4.4.8/ext/gd/libgd/gd.h
7279 --- php-4.4.8.org/ext/gd/libgd/gd.h 2004-07-23 01:09:24.000000000 +0200
7280 +++ php-4.4.8/ext/gd/libgd/gd.h 2007-09-12 01:34:25.000000000 +0200
7286 -/* default fontpath for unix systems */
7287 -#define DEFAULT_FONTPATH "/usr/X11R6/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/truetype:/usr/X11R6/lib/X11/fonts/TTF:/usr/share/fonts/TrueType:/usr/share/fonts/truetype:/usr/openwin/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/Type1:."
7288 -#define PATHSEPARATOR ":"
7290 +#ifdef HAVE_CONFIG_H
7291 +#include "config.h"
7294 +#include "php_compat.h"
7296 +#define GD_MAJOR_VERSION 2
7297 +#define GD_MINOR_VERSION 0
7298 +#define GD_RELEASE_VERSION 35
7299 +#define GD_EXTRA_VERSION ""
7300 +#define GD_VERSION_STRING "2.0.35"
7303 +/* default fontpath for netware systems */
7304 +#define DEFAULT_FONTPATH "sys:/java/nwgfx/lib/x11/fonts/ttf;."
7305 +#define PATHSEPARATOR ";"
7306 +#elif defined(WIN32)
7307 /* default fontpath for windows systems */
7308 #define DEFAULT_FONTPATH "c:\\winnt\\fonts;c:\\windows\\fonts;."
7309 #define PATHSEPARATOR ";"
7311 +/* default fontpath for unix systems */
7312 +#define DEFAULT_FONTPATH "/usr/X11R6/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/truetype:/usr/X11R6/lib/X11/fonts/TTF:/usr/share/fonts/TrueType:/usr/share/fonts/truetype:/usr/openwin/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/Type1:."
7313 +#define PATHSEPARATOR ":"
7316 /* gd.h: declarations file for the graphic-draw module.
7318 gdImagePtr gdImageCreateFromPngCtx(gdIOCtxPtr in);
7319 gdImagePtr gdImageCreateFromWBMP(FILE *inFile);
7320 gdImagePtr gdImageCreateFromWBMPCtx(gdIOCtx *infile);
7321 -gdImagePtr gdImageCreateFromJpeg(FILE *infile);
7322 -gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile);
7323 +gdImagePtr gdImageCreateFromJpeg(FILE *infile, int ignore_warning);
7324 +gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile, int ignore_warning);
7326 /* A custom data source. */
7327 /* The source function must return -1 on error, otherwise the number
7328 @@ -295,6 +311,14 @@
7329 void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
7330 void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
7333 + * The following functions are required to be called prior to the
7334 + * use of any sort of threads in a module load / shutdown function
7337 +void gdFontCacheMutexSetup();
7338 +void gdFontCacheMutexShutdown();
7340 /* 2.0.16: for thread-safe use of gdImageStringFT and friends,
7341 * call this before allowing any thread to call gdImageStringFT.
7342 * Otherwise it is invoked by the first thread to invoke
7344 * compression (smallest files) but takes a long time to compress, and
7345 * -1 selects the default compiled into the zlib library.
7347 -void gdImagePngEx(gdImagePtr im, FILE * out, int level);
7348 -void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level);
7349 +void gdImagePngEx(gdImagePtr im, FILE * out, int level, int basefilter);
7350 +void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level, int basefilter);
7352 void gdImageWBMP(gdImagePtr image, int fg, FILE *out);
7353 void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out);
7356 /* Best to free this memory with gdFree(), not free() */
7357 void* gdImageGdPtr(gdImagePtr im, int *size);
7358 -void *gdImagePngPtrEx(gdImagePtr im, int *size, int level);
7359 +void *gdImagePngPtrEx(gdImagePtr im, int *size, int level, int basefilter);
7361 /* Best to free this memory with gdFree(), not free() */
7362 void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size);
7363 @@ -534,11 +558,11 @@
7364 substituted automatically. */
7365 void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
7367 -gdImagePtr gdImageRotate90(gdImagePtr src);
7368 -gdImagePtr gdImageRotate180(gdImagePtr src);
7369 -gdImagePtr gdImageRotate270(gdImagePtr src);
7370 -gdImagePtr gdImageRotate45(gdImagePtr src, double dAngle, int clrBack);
7371 -gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack);
7372 +gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent);
7373 +gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
7374 +gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
7375 +gdImagePtr gdImageRotate45(gdImagePtr src, double dAngle, int clrBack, int ignoretransparent);
7376 +gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack, int ignoretransparent);
7378 void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
7379 void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
7381 int gdImageContrast(gdImagePtr src, double contrast);
7383 /* Simply adds or substracts respectively red, green or blue to a pixel */
7384 -int gdImageColor(gdImagePtr src, int red, int green, int blue);
7385 +int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha);
7387 /* Image convolution by a 3x3 custom matrix */
7388 int gdImageConvolution(gdImagePtr src, float ft[3][3], float filter_div, float offset);
7389 diff -urN php-4.4.8.org/ext/gd/libgd/gdhelpers.h php-4.4.8/ext/gd/libgd/gdhelpers.h
7390 --- php-4.4.8.org/ext/gd/libgd/gdhelpers.h 2007-03-10 14:06:37.000000000 +0100
7391 +++ php-4.4.8/ext/gd/libgd/gdhelpers.h 2007-03-10 13:18:36.000000000 +0100
7393 -#ifndef GDHELPERS_H
7394 +#ifndef GDHELPERS_H
7395 #define GDHELPERS_H 1
7397 #include <sys/types.h>
7398 diff -urN php-4.4.8.org/ext/gd/libgd/gd_io.c php-4.4.8/ext/gd/libgd/gd_io.c
7399 --- php-4.4.8.org/ext/gd/libgd/gd_io.c 2003-12-25 23:33:03.000000000 +0100
7400 +++ php-4.4.8/ext/gd/libgd/gd_io.c 2005-08-18 14:54:43.000000000 +0200
7401 @@ -23,153 +23,124 @@
7405 +#define GD_IO_EOF_CHK(r) \
7411 * Write out a word to the I/O context pointer
7414 -Putword (int w, gdIOCtx * ctx)
7415 +void Putword (int w, gdIOCtx * ctx)
7417 - unsigned char buf[2];
7418 - buf[0] = w & 0xff;
7419 - buf[1] = (w / 256) & 0xff;
7420 - (ctx->putBuf) (ctx, (char *) buf, 2);
7421 + unsigned char buf[2];
7423 + buf[0] = w & 0xff;
7424 + buf[1] = (w / 256) & 0xff;
7425 + (ctx->putBuf) (ctx, (char *) buf, 2);
7429 -Putchar (int c, gdIOCtx * ctx)
7430 +void Putchar (int c, gdIOCtx * ctx)
7432 - (ctx->putC) (ctx, c & 0xff);
7433 + (ctx->putC) (ctx, c & 0xff);
7437 -gdPutC (const unsigned char c, gdIOCtx * ctx)
7438 +void gdPutC (const unsigned char c, gdIOCtx * ctx)
7440 - (ctx->putC) (ctx, c);
7441 + (ctx->putC) (ctx, c);
7445 -gdPutWord (int w, gdIOCtx * ctx)
7446 +void gdPutWord (int w, gdIOCtx * ctx)
7448 - IO_DBG (printf ("Putting word...\n"));
7449 - (ctx->putC) (ctx, (unsigned char) (w >> 8));
7450 - (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
7451 - IO_DBG (printf ("put.\n"));
7452 + IO_DBG (php_gd_error("Putting word..."));
7453 + (ctx->putC) (ctx, (unsigned char) (w >> 8));
7454 + (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
7455 + IO_DBG (php_gd_error("put."));
7459 -gdPutInt (int w, gdIOCtx * ctx)
7460 +void gdPutInt (int w, gdIOCtx * ctx)
7462 - IO_DBG (printf ("Putting int...\n"));
7463 - (ctx->putC) (ctx, (unsigned char) (w >> 24));
7464 - (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF));
7465 - (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF));
7466 - (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
7467 - IO_DBG (printf ("put.\n"));
7468 + IO_DBG (php_gd_error("Putting int..."));
7469 + (ctx->putC) (ctx, (unsigned char) (w >> 24));
7470 + (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF));
7471 + (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF));
7472 + (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
7473 + IO_DBG (php_gd_error("put."));
7477 -gdGetC (gdIOCtx * ctx)
7478 +int gdGetC (gdIOCtx * ctx)
7480 - return ((ctx->getC) (ctx));
7481 + return ((ctx->getC) (ctx));
7487 -gdGetByte (int *result, gdIOCtx * ctx)
7488 +int gdGetByte (int *result, gdIOCtx * ctx)
7491 - r = (ctx->getC) (ctx);
7499 + r = (ctx->getC) (ctx);
7506 -gdGetWord (int *result, gdIOCtx * ctx)
7507 +int gdGetWord (int *result, gdIOCtx * ctx)
7510 - r = (ctx->getC) (ctx);
7516 - r = (ctx->getC) (ctx);
7524 + r = (ctx->getC) (ctx);
7527 + r = (ctx->getC) (ctx);
7535 -gdGetInt (int *result, gdIOCtx * ctx)
7536 +int gdGetInt (int *result, gdIOCtx * ctx)
7539 - r = (ctx->getC) (ctx);
7544 - *result = r << 24;
7546 + r = (ctx->getC) (ctx);
7548 + *result = r << 24;
7550 - r = (ctx->getC) (ctx);
7555 - *result += r << 16;
7556 + r = (ctx->getC) (ctx);
7558 + *result += r << 16;
7560 - r = (ctx->getC) (ctx);
7565 - *result += r << 8;
7566 + r = (ctx->getC) (ctx);
7570 + *result += r << 8;
7572 - r = (ctx->getC) (ctx);
7578 + r = (ctx->getC) (ctx);
7587 -gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
7588 +int gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
7590 - IO_DBG (printf ("Putting buf...\n"));
7591 - return (ctx->putBuf) (ctx, buf, size);
7592 - IO_DBG (printf ("put.\n"));
7593 + IO_DBG (php_gd_error("Putting buf..."));
7594 + return (ctx->putBuf) (ctx, buf, size);
7595 + IO_DBG (php_gd_error("put."));
7599 -gdGetBuf (void *buf, int size, gdIOCtx * ctx)
7600 +int gdGetBuf (void *buf, int size, gdIOCtx * ctx)
7602 - return (ctx->getBuf) (ctx, buf, size);
7603 + return (ctx->getBuf) (ctx, buf, size);
7608 -gdSeek (gdIOCtx * ctx, const int pos)
7609 +int gdSeek (gdIOCtx * ctx, const int pos)
7611 - IO_DBG (printf ("Seeking...\n"));
7612 - return ((ctx->seek) (ctx, pos));
7613 - IO_DBG (printf ("Done.\n"));
7614 + IO_DBG (php_gd_error("Seeking..."));
7615 + return ((ctx->seek) (ctx, pos));
7616 + IO_DBG (php_gd_error("Done."));
7620 -gdTell (gdIOCtx * ctx)
7621 +long gdTell (gdIOCtx * ctx)
7623 - IO_DBG (printf ("Telling...\n"));
7624 - return ((ctx->tell) (ctx));
7625 - IO_DBG (printf ("told.\n"));
7626 + IO_DBG (php_gd_error("Telling..."));
7627 + return ((ctx->tell) (ctx));
7628 + IO_DBG (php_gd_error ("told."));
7630 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
7631 --- php-4.4.8.org/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:21:00.000000000 +0200
7632 +++ php-4.4.8/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:20:33.000000000 +0200
7635 /* this is used for creating images in main memory */
7636 typedef struct dpStruct
7655 typedef struct dpIOCtx
7666 typedef struct dpIOCtx *dpIOCtxPtr;
7669 /* these functions operate on in-memory dynamic pointers */
7670 static int allocDynamic (dynamicPtr * dp, int initialSize, void *data);
7671 static int appendDynamic (dynamicPtr * dp, const void *src, int size);
7672 @@ -65,166 +62,136 @@
7673 static long dynamicTell (struct gdIOCtx *);
7675 /* return data as a dynamic pointer */
7677 -gdNewDynamicCtx (int initialSize, void *data)
7678 +gdIOCtx * gdNewDynamicCtx (int initialSize, void *data)
7680 - return gdNewDynamicCtxEx(initialSize, data, 1);
7681 + return gdNewDynamicCtxEx(initialSize, data, 1);
7685 gdIOCtx * gdNewDynamicCtxEx (int initialSize, void *data, int freeOKFlag)
7692 - ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx));
7697 + ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx));
7699 - dp = newDynamic (initialSize, data, freeOKFlag);
7705 + dp = newDynamic(initialSize, data, freeOKFlag);
7710 - ctx->ctx.getC = dynamicGetchar;
7711 - ctx->ctx.putC = dynamicPutchar;
7712 + ctx->ctx.getC = dynamicGetchar;
7713 + ctx->ctx.putC = dynamicPutchar;
7715 - ctx->ctx.getBuf = dynamicGetbuf;
7716 - ctx->ctx.putBuf = dynamicPutbuf;
7717 + ctx->ctx.getBuf = dynamicGetbuf;
7718 + ctx->ctx.putBuf = dynamicPutbuf;
7720 - ctx->ctx.seek = dynamicSeek;
7721 - ctx->ctx.tell = dynamicTell;
7722 + ctx->ctx.seek = dynamicSeek;
7723 + ctx->ctx.tell = dynamicTell;
7725 - ctx->ctx.gd_free = gdFreeDynamicCtx;
7726 + ctx->ctx.gd_free = gdFreeDynamicCtx;
7728 - return (gdIOCtx *) ctx;
7729 + return (gdIOCtx *) ctx;
7733 -gdDPExtractData (struct gdIOCtx *ctx, int *size)
7734 +void * gdDPExtractData (struct gdIOCtx *ctx, int *size)
7743 - dctx = (dpIOCtx *) ctx;
7745 + dctx = (dpIOCtx *) ctx;
7748 - /* clean up the data block and return it */
7752 - *size = dp->logicalSize;
7759 - if (dp->data != NULL && dp->freeOK)
7761 - gdFree (dp->data);
7762 + /* clean up the data block and return it */
7763 + if (dp->dataGood) {
7765 + *size = dp->logicalSize;
7770 + if (dp->data != NULL && dp->freeOK) {
7778 - dp->logicalSize = 0;
7781 + dp->logicalSize = 0;
7789 -gdFreeDynamicCtx (struct gdIOCtx *ctx)
7790 +static void gdFreeDynamicCtx (struct gdIOCtx *ctx)
7795 - dctx = (dpIOCtx *) ctx;
7801 + dctx = (dpIOCtx *) ctx;
7805 - dp->logicalSize = 0;
7810 + dp->logicalSize = 0;
7816 -dynamicTell (struct gdIOCtx *ctx)
7817 +static long dynamicTell (struct gdIOCtx *ctx)
7822 - dctx = (dpIOCtx *) ctx;
7823 - return (dctx->dp->pos);
7824 + dctx = (dpIOCtx *) ctx;
7826 + return (dctx->dp->pos);
7830 -dynamicSeek (struct gdIOCtx *ctx, const int pos)
7831 +static int dynamicSeek (struct gdIOCtx *ctx, const int pos)
7840 - dctx = (dpIOCtx *) ctx;
7842 + dctx = (dpIOCtx *) ctx;
7845 - if (!dp->dataGood)
7847 + if (!dp->dataGood) {
7851 - bytesNeeded = pos;
7852 - if (bytesNeeded > dp->realSize)
7855 - if (!dp->freeOK) {
7858 - if (!gdReallocDynamic (dp, dp->realSize * 2))
7860 - dp->dataGood = FALSE;
7862 + bytesNeeded = pos;
7863 + if (bytesNeeded > dp->realSize) {
7865 + if (!dp->freeOK) {
7868 + gdReallocDynamic (dp, dp->realSize * 2);
7872 - /* if we get here, we can be sure that we have enough bytes
7874 + /* if we get here, we can be sure that we have enough bytes to copy safely */
7876 - /* Extend the logical size if we seek beyond EOF. */
7877 - if (pos > dp->logicalSize)
7879 - dp->logicalSize = pos;
7881 + /* Extend the logical size if we seek beyond EOF. */
7882 + if (pos > dp->logicalSize) {
7883 + dp->logicalSize = pos;
7893 /* return data as a dynamic pointer */
7894 static dynamicPtr * newDynamic (int initialSize, void *data, int freeOKFlag)
7897 - dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr));
7903 + dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr));
7905 - if (!allocDynamic (dp, initialSize, data))
7907 + allocDynamic (dp, initialSize, data);
7910 - dp->freeOK = freeOKFlag;
7912 + dp->freeOK = freeOKFlag;
7919 @@ -246,64 +213,53 @@
7924 -dynamicPutchar (struct gdIOCtx *ctx, int a)
7925 +static void dynamicPutchar (struct gdIOCtx *ctx, int a)
7933 - dctx = (dpIOCtxPtr) ctx;
7935 + dctx = (dpIOCtxPtr) ctx;
7937 - appendDynamic (dctx->dp, &b, 1);
7938 + appendDynamic(dctx->dp, &b, 1);
7942 -dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len)
7943 +static int dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len)
7952 - dctx = (dpIOCtxPtr) ctx;
7954 + dctx = (dpIOCtxPtr) ctx;
7957 - remain = dp->logicalSize - dp->pos;
7958 - if (remain >= len)
7967 + remain = dp->logicalSize - dp->pos;
7968 + if (remain >= len) {
7971 + if (remain == 0) {
7979 - memcpy (buf, (void *) ((char *) dp->data + dp->pos), rlen);
7981 + memcpy(buf, (void *) ((char *) dp->data + dp->pos), rlen);
7989 -dynamicGetchar (gdIOCtxPtr ctx)
7990 +static int dynamicGetchar (gdIOCtxPtr ctx)
7995 - rv = dynamicGetbuf (ctx, &b, 1);
8005 - return b; /* (b & 0xff); */
8007 + rv = dynamicGetbuf (ctx, &b, 1);
8011 + return b; /* (b & 0xff); */
8015 /* *********************************************************************
8016 @@ -316,114 +272,89 @@
8017 allocDynamic (dynamicPtr * dp, int initialSize, void *data)
8022 - dp->logicalSize = 0;
8023 - dp->dataGood = FALSE;
8024 - dp->data = gdMalloc (initialSize);
8028 - dp->logicalSize = initialSize;
8029 - dp->dataGood = TRUE;
8032 + if (data == NULL) {
8033 + dp->logicalSize = 0;
8034 + dp->dataGood = FALSE;
8035 + dp->data = gdMalloc(initialSize);
8037 + dp->logicalSize = initialSize;
8038 + dp->dataGood = TRUE;
8042 - if (dp->data != NULL)
8044 - dp->realSize = initialSize;
8045 - dp->dataGood = TRUE;
8054 + dp->realSize = initialSize;
8055 + dp->dataGood = TRUE;
8061 /* append bytes to the end of a dynamic pointer */
8063 -appendDynamic (dynamicPtr * dp, const void *src, int size)
8064 +static int appendDynamic (dynamicPtr * dp, const void *src, int size)
8071 - if (!dp->dataGood)
8073 + if (!dp->dataGood) {
8077 -/* bytesNeeded = dp->logicalSize + size; */
8078 - bytesNeeded = dp->pos + size;
8079 + /* bytesNeeded = dp->logicalSize + size; */
8080 + bytesNeeded = dp->pos + size;
8082 - if (bytesNeeded > dp->realSize)
8084 + if (bytesNeeded > dp->realSize) {
8089 - if (!gdReallocDynamic (dp, bytesNeeded * 2))
8091 - dp->dataGood = FALSE;
8093 + gdReallocDynamic(dp, bytesNeeded * 2);
8097 - /* if we get here, we can be sure that we have enough bytes
8099 - /*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */
8101 - tmp = (char *) dp->data;
8102 - memcpy ((void *) (tmp + (dp->pos)), src, size);
8104 + /* if we get here, we can be sure that we have enough bytes to copy safely */
8105 + /*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */
8107 - if (dp->pos > dp->logicalSize)
8109 - dp->logicalSize = dp->pos;
8111 + tmp = (char *) dp->data;
8112 + memcpy((void *) (tmp + (dp->pos)), src, size);
8115 + if (dp->pos > dp->logicalSize) {
8116 + dp->logicalSize = dp->pos;
8123 /* grow (or shrink) dynamic pointer */
8125 -gdReallocDynamic (dynamicPtr * dp, int required)
8126 +static int gdReallocDynamic (dynamicPtr * dp, int required)
8131 - /* First try gdRealloc(). If that doesn't work, make a new
8132 - memory block and copy. */
8133 - if ((newPtr = gdRealloc (dp->data, required)))
8135 - dp->realSize = required;
8136 - dp->data = newPtr;
8139 + /* First try gdRealloc(). If that doesn't work, make a new memory block and copy. */
8140 + if ((newPtr = gdRealloc(dp->data, required))) {
8141 + dp->realSize = required;
8142 + dp->data = newPtr;
8146 - /* create a new pointer */
8147 - newPtr = gdMalloc (required);
8150 - dp->dataGood = FALSE;
8153 + /* create a new pointer */
8154 + newPtr = gdMalloc(required);
8156 + /* copy the old data into it */
8157 + memcpy(newPtr, dp->data, dp->logicalSize);
8159 + dp->data = newPtr;
8161 - /* copy the old data into it */
8162 - memcpy (newPtr, dp->data, dp->logicalSize);
8163 - gdFree (dp->data);
8164 - dp->data = newPtr;
8165 + dp->realSize = required;
8167 - dp->realSize = required;
8172 /* trim pointer so that its real and logical sizes match */
8174 -trimDynamic (dynamicPtr * dp)
8175 +static int trimDynamic (dynamicPtr * dp)
8177 - /* 2.0.21: we don't reallocate memory we don't own */
8178 - if (!dp->freeOK) {
8181 - return gdReallocDynamic (dp, dp->logicalSize);
8182 + /* 2.0.21: we don't reallocate memory we don't own */
8183 + if (!dp->freeOK) {
8186 + return gdReallocDynamic(dp, dp->logicalSize);
8188 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
8189 --- php-4.4.8.org/ext/gd/libgd/gd_io_file.c 2003-12-25 23:33:03.000000000 +0100
8190 +++ php-4.4.8/ext/gd/libgd/gd_io_file.c 2003-12-25 23:12:12.000000000 +0100
8192 /* this is used for creating images in main memory */
8194 typedef struct fileIOCtx
8205 gdIOCtx *newFileCtx (FILE * f);
8208 static void gdFreeFileCtx (gdIOCtx * ctx);
8210 /* return data as a dynamic pointer */
8212 -gdNewFileCtx (FILE * f)
8213 +gdIOCtx * gdNewFileCtx (FILE * f)
8218 - ctx = (fileIOCtx *) gdMalloc (sizeof (fileIOCtx));
8223 + ctx = (fileIOCtx *) gdMalloc(sizeof (fileIOCtx));
8228 - ctx->ctx.getC = fileGetchar;
8229 - ctx->ctx.putC = filePutchar;
8230 + ctx->ctx.getC = fileGetchar;
8231 + ctx->ctx.putC = filePutchar;
8233 - ctx->ctx.getBuf = fileGetbuf;
8234 - ctx->ctx.putBuf = filePutbuf;
8235 + ctx->ctx.getBuf = fileGetbuf;
8236 + ctx->ctx.putBuf = filePutbuf;
8238 - ctx->ctx.tell = fileTell;
8239 - ctx->ctx.seek = fileSeek;
8240 + ctx->ctx.tell = fileTell;
8241 + ctx->ctx.seek = fileSeek;
8243 - ctx->ctx.gd_free = gdFreeFileCtx;
8244 + ctx->ctx.gd_free = gdFreeFileCtx;
8246 - return (gdIOCtx *) ctx;
8247 + return (gdIOCtx *) ctx;
8252 -gdFreeFileCtx (gdIOCtx * ctx)
8253 +static void gdFreeFileCtx (gdIOCtx * ctx)
8261 -filePutbuf (gdIOCtx * ctx, const void *buf, int size)
8262 +static int filePutbuf (gdIOCtx * ctx, const void *buf, int size)
8265 - fctx = (fileIOCtx *) ctx;
8267 + fctx = (fileIOCtx *) ctx;
8269 - return fwrite (buf, 1, size, fctx->f);
8270 + return fwrite(buf, 1, size, fctx->f);
8275 -fileGetbuf (gdIOCtx * ctx, void *buf, int size)
8276 +static int fileGetbuf (gdIOCtx * ctx, void *buf, int size)
8279 - fctx = (fileIOCtx *) ctx;
8281 - return (fread (buf, 1, size, fctx->f));
8283 + fctx = (fileIOCtx *) ctx;
8285 + return fread(buf, 1, size, fctx->f);
8289 -filePutchar (gdIOCtx * ctx, int a)
8290 +static void filePutchar (gdIOCtx * ctx, int a)
8294 - fctx = (fileIOCtx *) ctx;
8297 + fctx = (fileIOCtx *) ctx;
8302 - putc (b, fctx->f);
8303 + putc (b, fctx->f);
8307 -fileGetchar (gdIOCtx * ctx)
8308 +static int fileGetchar (gdIOCtx * ctx)
8311 - fctx = (fileIOCtx *) ctx;
8313 + fctx = (fileIOCtx *) ctx;
8315 - return getc (fctx->f);
8316 + return getc (fctx->f);
8321 -fileSeek (struct gdIOCtx *ctx, const int pos)
8322 +static int fileSeek (struct gdIOCtx *ctx, const int pos)
8325 - fctx = (fileIOCtx *) ctx;
8327 + fctx = (fileIOCtx *) ctx;
8329 - return (fseek (fctx->f, pos, SEEK_SET) == 0);
8330 + return (fseek (fctx->f, pos, SEEK_SET) == 0);
8334 -fileTell (struct gdIOCtx *ctx)
8335 +static long fileTell (struct gdIOCtx *ctx)
8338 - fctx = (fileIOCtx *) ctx;
8340 + fctx = (fileIOCtx *) ctx;
8342 - return ftell (fctx->f);
8343 + return ftell (fctx->f);
8345 diff -urN php-4.4.8.org/ext/gd/libgd/gd_io.h php-4.4.8/ext/gd/libgd/gd_io.h
8346 --- php-4.4.8.org/ext/gd/libgd/gd_io.h 2003-04-05 19:24:16.000000000 +0200
8347 +++ php-4.4.8/ext/gd/libgd/gd_io.h 2003-12-28 21:11:08.000000000 +0100
8350 #define Putchar gdPutchar
8354 typedef struct gdIOCtx {
8355 int (*getC)(struct gdIOCtx*);
8356 int (*getBuf)(struct gdIOCtx*, void*, int);
8358 - void (*putC)(struct gdIOCtx*, int);
8359 + void (*putC)(struct gdIOCtx*, int);
8360 int (*putBuf)(struct gdIOCtx*, const void*, int);
8362 int (*seek)(struct gdIOCtx*, const int);
8363 long (*tell)(struct gdIOCtx*);
8365 - void (*gd_free)(struct gdIOCtx*);
8366 + void (*gd_free)(struct gdIOCtx*);
8370 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
8371 --- php-4.4.8.org/ext/gd/libgd/gd_io_ss.c 2002-10-30 00:08:01.000000000 +0100
8372 +++ php-4.4.8/ext/gd/libgd/gd_io_ss.c 2003-12-28 21:11:08.000000000 +0100
8374 * used internally until it settles down a bit.
8376 * This module just layers the Source/Sink interface on top of the IOCtx; no
8377 - * support is provided for tell/seek, so GD2 writing is not possible, and
8378 + * support is provided for tell/seek, so GD2 writing is not possible, and
8379 * retrieving parts of GD2 files is also not possible.
8381 * A new SS context does not need to be created with both a Source and a Sink.
8383 /* this is used for creating images in main memory */
8385 typedef struct ssIOCtx
8398 typedef struct ssIOCtx *ssIOCtxPtr;
8400 @@ -48,118 +47,92 @@
8401 static void gdFreeSsCtx (gdIOCtx * ctx);
8403 /* return data as a dynamic pointer */
8405 -gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk)
8406 +gdIOCtx * gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk)
8411 - ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx));
8416 + ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx));
8423 - ctx->ctx.getC = sourceGetchar;
8424 - ctx->ctx.getBuf = sourceGetbuf;
8425 + ctx->ctx.getC = sourceGetchar;
8426 + ctx->ctx.getBuf = sourceGetbuf;
8428 - ctx->ctx.putC = sinkPutchar;
8429 - ctx->ctx.putBuf = sinkPutbuf;
8430 + ctx->ctx.putC = sinkPutchar;
8431 + ctx->ctx.putBuf = sinkPutbuf;
8433 - ctx->ctx.tell = NULL;
8434 - ctx->ctx.seek = NULL;
8435 + ctx->ctx.tell = NULL;
8436 + ctx->ctx.seek = NULL;
8438 - ctx->ctx.gd_free = gdFreeSsCtx;
8439 + ctx->ctx.gd_free = gdFreeSsCtx;
8441 - return (gdIOCtx *) ctx;
8442 + return (gdIOCtx *) ctx;
8447 -gdFreeSsCtx (gdIOCtx * ctx)
8448 +static void gdFreeSsCtx (gdIOCtx * ctx)
8456 -sourceGetbuf (gdIOCtx * ctx, void *buf, int size)
8457 +static int sourceGetbuf (gdIOCtx * ctx, void *buf, int size)
8462 - lctx = (ssIOCtx *) ctx;
8466 - res = ((lctx->src->source) (lctx->src->context, buf, size));
8467 + lctx = (ssIOCtx *) ctx;
8470 - ** Translate the return values from the Source object:
8471 - ** 0 is EOF, -1 is error
8473 + res = ((lctx->src->source) (lctx->src->context, buf, size));
8488 + * Translate the return values from the Source object:
8489 + * 0 is EOF, -1 is error
8494 + } else if (res < 0) {
8502 -sourceGetchar (gdIOCtx * ctx)
8503 +static int sourceGetchar (gdIOCtx * ctx)
8506 - unsigned char buf;
8508 + unsigned char buf;
8510 - res = sourceGetbuf (ctx, &buf, 1);
8520 + res = sourceGetbuf (ctx, &buf, 1);
8530 -sinkPutbuf (gdIOCtx * ctx, const void *buf, int size)
8531 +static int sinkPutbuf (gdIOCtx * ctx, const void *buf, int size)
8536 - lctx = (ssIOCtx *) ctx;
8540 - res = (lctx->snk->sink) (lctx->snk->context, buf, size);
8541 + lctx = (ssIOCtx *) ctx;
8551 + res = (lctx->snk->sink) (lctx->snk->context, buf, size);
8561 -sinkPutchar (gdIOCtx * ctx, int a)
8562 +static void sinkPutchar (gdIOCtx * ctx, int a)
8567 - sinkPutbuf (ctx, &b, 1);
8571 + sinkPutbuf (ctx, &b, 1);
8573 diff -urN php-4.4.8.org/ext/gd/libgd/gd_jpeg.c php-4.4.8/ext/gd/libgd/gd_jpeg.c
8574 --- php-4.4.8.org/ext/gd/libgd/gd_jpeg.c 2004-03-29 20:21:00.000000000 +0200
8575 +++ php-4.4.8/ext/gd/libgd/gd_jpeg.c 2006-02-05 16:53:58.000000000 +0100
8578 * gd_jpeg.c: Read and write JPEG (JFIF) format image files using the
8579 * gd graphics library (http://www.boutell.com/gd/).
8582 * This software is based in part on the work of the Independent JPEG
8583 * Group. For more information on the IJG JPEG software (and JPEG
8584 * documentation, etc.), see ftp://ftp.uu.net/graphics/jpeg/.
8586 * major CGI brain damage
8588 * 2.0.10: more efficient gdImageCreateFromJpegCtx, thanks to
8589 - * Christian Aberger
8590 + * Christian Aberger
8593 -#if PHP_WIN32 && !defined(ssize_t)
8594 -typedef int ssize_t;
8601 typedef struct _jmpbuf_wrapper
8604 + int ignore_warning;
8607 +static long php_jpeg_emit_message(j_common_ptr jpeg_info, int level)
8609 + char message[JMSG_LENGTH_MAX];
8610 + jmpbuf_wrapper *jmpbufw;
8611 + int ignore_warning = 0;
8613 + jmpbufw = (jmpbuf_wrapper *) jpeg_info->client_data;
8615 + if (jmpbufw != 0) {
8616 + ignore_warning = jmpbufw->ignore_warning;
8619 + (jpeg_info->err->format_message)(jpeg_info,message);
8621 + /* It is a warning message */
8623 + /* display only the 1st warning, as would do a default libjpeg
8624 + * unless strace_level >= 3
8626 + if ((jpeg_info->err->num_warnings == 0) || (jpeg_info->err->trace_level >= 3)) {
8627 + php_gd_error_ex(ignore_warning ? E_NOTICE : E_WARNING, "gd-jpeg, libjpeg: recoverable error: %s\n", message);
8630 + jpeg_info->err->num_warnings++;
8632 + /* strace msg, Show it if trace_level >= level. */
8633 + if (jpeg_info->err->trace_level >= level) {
8634 + php_gd_error_ex(E_NOTICE, "gd-jpeg, libjpeg: strace message: %s\n", message);
8642 /* Called by the IJG JPEG library upon encountering a fatal error */
8643 static void fatal_jpeg_error (j_common_ptr cinfo)
8647 nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
8649 - php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1\n", nlines);
8650 + php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
8656 nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
8658 - php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1\n", nlines);
8659 + php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
8663 @@ -211,21 +243,21 @@
8667 -gdImagePtr gdImageCreateFromJpeg (FILE * inFile)
8668 +gdImagePtr gdImageCreateFromJpeg (FILE * inFile, int ignore_warning)
8671 gdIOCtx *in = gdNewFileCtx(inFile);
8672 - im = gdImageCreateFromJpegCtx(in);
8673 + im = gdImageCreateFromJpegCtx(in, ignore_warning);
8679 -gdImagePtr gdImageCreateFromJpegPtr (int size, void *data)
8680 +gdImagePtr gdImageCreateFromJpegPtr (int size, void *data, int ignore_warning)
8683 gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
8684 - im = gdImageCreateFromJpegCtx(in);
8685 + im = gdImageCreateFromJpegCtx(in, ignore_warning);
8689 @@ -235,11 +267,12 @@
8691 static int CMYKToRGB(int c, int m, int y, int k, int inverted);
8696 * Create a gd-format image from the JPEG-format INFILE. Returns the
8697 * image, or NULL upon error.
8699 -gdImagePtr gdImageCreateFromJpegCtx (gdIOCtx * infile)
8700 +gdImagePtr gdImageCreateFromJpegCtx (gdIOCtx * infile, int ignore_warning)
8702 struct jpeg_decompress_struct cinfo;
8703 struct jpeg_error_mgr jerr;
8704 @@ -257,8 +290,13 @@
8705 memset (&cinfo, 0, sizeof (cinfo));
8706 memset (&jerr, 0, sizeof (jerr));
8708 + jmpbufw.ignore_warning = ignore_warning;
8710 cinfo.err = jpeg_std_error (&jerr);
8711 cinfo.client_data = &jmpbufw;
8713 + cinfo.err->emit_message = (void (*)(j_common_ptr,int)) php_jpeg_emit_message;
8715 if (setjmp (jmpbufw.jmpbuf) != 0) {
8716 /* we're here courtesy of longjmp */
8719 jpeg_save_markers(&cinfo, JPEG_APP0 + 14, 256);
8721 retval = jpeg_read_header (&cinfo, TRUE);
8722 - if (retval != JPEG_HEADER_OK) {
8723 + if (retval != JPEG_HEADER_OK) {
8724 php_gd_error_ex(E_WARNING, "gd-jpeg: warning: jpeg_read_header returned %d, expected %d", retval, JPEG_HEADER_OK);
8728 * latest libjpeg, replaced by something else. Unfortunately
8729 * there is still no right way to find out if the file was
8730 * progressive or not; just declare your intent before you
8731 - * write one by calling gdImageInterlace(im, 1) yourself.
8732 + * write one by calling gdImageInterlace(im, 1) yourself.
8733 * After all, we're not really supposed to rework JPEGs and
8734 - * write them out again anyway. Lossy compression, remember?
8735 + * write them out again anyway. Lossy compression, remember?
8738 gdImageInterlace (im, cinfo.progressive_mode != 0);
8739 @@ -390,12 +428,12 @@
8740 if (jpeg_finish_decompress (&cinfo) != TRUE) {
8741 php_gd_error("gd-jpeg: warning: jpeg_finish_decompress reports suspended data source");
8744 - /* Thanks to Truxton Fulton */
8745 - if (cinfo.err->num_warnings > 0) {
8747 + if (!ignore_warning) {
8748 + if (cinfo.err->num_warnings > 0) {
8754 jpeg_destroy_decompress (&cinfo);
8758 int got = gdGetBuf(src->buffer + nbytes, INPUT_BUF_SIZE - nbytes, src->infile);
8760 if (got == EOF || got == 0) {
8761 - /* EOF or error. If we got any data, don't worry about it. If we didn't, then this is unexpected. */
8762 + /* EOF or error. If we got any data, don't worry about it. If we didn't, then this is unexpected. */
8773 if (src->start_of_file) { /* Treat empty input file as fatal error */
8774 ERREXIT (cinfo, JERR_INPUT_EMPTY);
8776 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (my_source_mgr));
8777 src = (my_src_ptr) cinfo->src;
8778 src->buffer = (unsigned char *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, INPUT_BUF_SIZE * sizeof (unsigned char));
8783 src = (my_src_ptr) cinfo->src;
8784 diff -urN php-4.4.8.org/ext/gd/libgd/gdkanji.c php-4.4.8/ext/gd/libgd/gdkanji.c
8785 --- php-4.4.8.org/ext/gd/libgd/gdkanji.c 2003-04-05 19:24:16.000000000 +0200
8786 +++ php-4.4.8/ext/gd/libgd/gdkanji.c 2003-12-28 21:11:08.000000000 +0100
8793 va_start(args, format);
8794 vspprintf(&tmp, 0, format, args);
8796 diff -urN php-4.4.8.org/ext/gd/libgd/gd_png.c php-4.4.8/ext/gd/libgd/gd_png.c
8797 --- php-4.4.8.org/ext/gd/libgd/gd_png.c 2007-05-17 00:54:11.000000000 +0200
8798 +++ php-4.4.8/ext/gd/libgd/gd_png.c 2007-05-17 00:19:08.000000000 +0200
8800 out all fprintf() statements to disable that).
8802 GD 2.0 supports RGBA truecolor and will read and write truecolor PNGs.
8803 - GD 2.0 supports 8 bits of color resolution per channel and
8804 + GD 2.0 supports 8 bits of color resolution per channel and
8805 7 bits of alpha channel resolution. Images with more than 8 bits
8806 per channel are reduced to 8 bits. Images with an alpha channel are
8807 only able to resolve down to '1/128th opaque' instead of '1/256th',
8812 - php_gd_error_ex(E_ERROR, "gd-png: fatal libpng error: %s\n", msg);
8813 + php_gd_error_ex(E_WARNING, "gd-png: fatal libpng error: %s", msg);
8815 jmpbuf_ptr = png_get_error_ptr (png_ptr);
8816 if (jmpbuf_ptr == NULL) { /* we are completely hosed now */
8817 - php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
8818 + php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.");
8821 longjmp (jmpbuf_ptr->jmpbuf, 1);
8822 @@ -130,12 +130,15 @@
8824 /* Make sure the signature can't match by dumb luck -- TBB */
8825 /* GRR: isn't sizeof(infile) equal to the size of the pointer? */
8826 - memset (infile, 0, sizeof(infile));
8827 + memset (sig, 0, sizeof(sig));
8829 /* first do a quick check that the file really is a PNG image; could
8830 - * have used slightly more general png_sig_cmp() function instead
8831 + * have used slightly more general png_sig_cmp() function instead
8833 - gdGetBuf(sig, 8, infile);
8834 + if (gdGetBuf(sig, 8, infile) < 8) {
8838 if (!png_check_sig (sig, 8)) { /* bad signature */
8841 @@ -146,13 +149,13 @@
8842 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
8844 if (png_ptr == NULL) {
8845 - php_gd_error("gd-png error: cannot allocate libpng main struct\n");
8846 + php_gd_error("gd-png error: cannot allocate libpng main struct");
8850 info_ptr = png_create_info_struct(png_ptr);
8851 if (info_ptr == NULL) {
8852 - php_gd_error("gd-png error: cannot allocate libpng info struct\n");
8853 + php_gd_error("gd-png error: cannot allocate libpng info struct");
8854 png_destroy_read_struct (&png_ptr, NULL, NULL);
8859 /* we could create a second info struct here (end_info), but it's only
8860 * useful if we want to keep pre- and post-IDAT chunk info separated
8861 - * (mainly for PNG-aware image editors and converters)
8862 + * (mainly for PNG-aware image editors and converters)
8865 /* setjmp() must be called in every non-callback function that calls a
8868 #ifndef PNG_SETJMP_NOT_SUPPORTED
8869 if (setjmp(gdPngJmpbufStruct.jmpbuf)) {
8870 - php_gd_error("gd-png error: setjmp returns error condition\n");
8871 + php_gd_error("gd-png error: setjmp returns error condition");
8872 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
8876 im = gdImageCreate((int) width, (int) height);
8879 - php_gd_error("gd-png error: cannot allocate gdImage struct\n");
8880 + php_gd_error("gd-png error: cannot allocate gdImage struct");
8881 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
8883 gdFree(row_pointers);
8884 @@ -201,15 +204,32 @@
8885 png_set_packing (png_ptr); /* expand to 1 byte per pixel */
8888 + /* setjmp() must be called in every non-callback function that calls a
8889 + * PNG-reading libpng function
8891 +#ifndef PNG_SETJMP_NOT_SUPPORTED
8892 + if (setjmp(gdPngJmpbufStruct.jmpbuf)) {
8893 + php_gd_error("gd-png error: setjmp returns error condition");
8894 + png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
8895 + gdFree(image_data);
8896 + gdFree(row_pointers);
8898 + gdImageDestroy(im);
8905 switch (color_type) {
8906 case PNG_COLOR_TYPE_PALETTE:
8907 png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
8909 - php_gd_error("gd-png color_type is palette, colors: %d\n", num_palette);
8910 + php_gd_error("gd-png color_type is palette, colors: %d", num_palette);
8912 if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) {
8913 /* gd 2.0: we support this rather thoroughly now. Grab the
8914 - * first fully transparent entry, if any, as the value of
8915 + * first fully transparent entry, if any, as the value of
8916 * the simple-transparency index, mostly for backwards
8917 * binary compatibility. The alpha channel is where it's
8918 * really at these days.
8920 case PNG_COLOR_TYPE_GRAY:
8921 case PNG_COLOR_TYPE_GRAY_ALPHA:
8922 /* create a fake palette and check for single-shade transparency */
8923 - if ((palette = (png_colorp) safe_emalloc(256, sizeof(png_color), 0)) == NULL) {
8924 - php_gd_error("gd-png error: cannot allocate gray palette\n");
8925 + if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL) {
8926 + php_gd_error("gd-png error: cannot allocate gray palette");
8927 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
8931 * custom 16-bit code to handle the case where there are gdFree
8932 * palette entries. This error will be extremely rare in
8933 * general, though. (Quite possibly there is only one such
8934 - * image in existence.)
8935 + * image in existence.)
8939 @@ -272,16 +292,16 @@
8940 case PNG_COLOR_TYPE_RGB_ALPHA:
8941 /* gd 2.0: we now support truecolor. See the comment above
8942 * for a rare situation in which the transparent pixel may not
8943 - * work properly with 16-bit channels.
8944 + * work properly with 16-bit channels.
8946 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
8947 png_get_tRNS(png_ptr, info_ptr, NULL, NULL, &trans_color_rgb);
8948 if (bit_depth == 16) { /* png_set_strip_16() not yet in effect */
8949 - transparent = gdTrueColor(trans_color_rgb->red >> 8,
8950 + transparent = gdTrueColor(trans_color_rgb->red >> 8,
8951 trans_color_rgb->green >> 8,
8952 trans_color_rgb->blue >> 8);
8954 - transparent = gdTrueColor(trans_color_rgb->red,
8955 + transparent = gdTrueColor(trans_color_rgb->red,
8956 trans_color_rgb->green,
8957 trans_color_rgb->blue);
8960 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
8961 image_data = (png_bytep) safe_emalloc(rowbytes, height, 0);
8963 - row_pointers = (png_bytepp) safe_emalloc(height, sizeof (png_bytep), 0);
8964 + row_pointers = (png_bytepp) safe_emalloc(height, sizeof(png_bytep), 0);
8966 /* set the individual row_pointers to point at the correct offsets */
8967 for (h = 0; h < height; ++h) {
8969 register png_byte b = row_pointers[h][boffset++];
8971 /* gd has only 7 bits of alpha channel resolution, and
8972 - * 127 is transparent, 0 opaque. A moment of convenience,
8973 + * 127 is transparent, 0 opaque. A moment of convenience,
8974 * a lifetime of compatibility.
8978 if (!im->trueColor) {
8979 for (i = num_palette; i < gdMaxColors; ++i) {
8981 - php_gd_error("gd-png warning: image data references out-of-range color index (%d)\n", i);
8982 + php_gd_error("gd-png warning: image data references out-of-range color index (%d)", i);
8986 @@ -388,17 +408,17 @@
8990 -void gdImagePngEx (gdImagePtr im, FILE * outFile, int level)
8991 +void gdImagePngEx (gdImagePtr im, FILE * outFile, int level, int basefilter)
8993 gdIOCtx *out = gdNewFileCtx(outFile);
8994 - gdImagePngCtxEx(im, out, level);
8995 + gdImagePngCtxEx(im, out, level, basefilter);
8999 void gdImagePng (gdImagePtr im, FILE * outFile)
9001 gdIOCtx *out = gdNewFileCtx(outFile);
9002 - gdImagePngCtxEx(im, out, -1);
9003 + gdImagePngCtxEx(im, out, -1, -1);
9007 @@ -406,18 +426,18 @@
9010 gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
9011 - gdImagePngCtxEx(im, out, -1);
9012 + gdImagePngCtxEx(im, out, -1, -1);
9013 rv = gdDPExtractData(out, size);
9019 -void * gdImagePngPtrEx (gdImagePtr im, int *size, int level)
9020 +void * gdImagePngPtrEx (gdImagePtr im, int *size, int level, int basefilter)
9023 gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
9024 - gdImagePngCtxEx(im, out, level);
9025 + gdImagePngCtxEx(im, out, level, basefilter);
9026 rv = gdDPExtractData(out, size);
9029 @@ -425,14 +445,14 @@
9031 void gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
9033 - gdImagePngCtxEx(im, outfile, -1);
9034 + gdImagePngCtxEx(im, outfile, -1, -1);
9037 /* This routine is based in part on code from Dale Lutz (Safe Software Inc.)
9038 * and in part on demo code from Chapter 15 of "PNG: The Definitive Guide"
9039 * (http://www.cdrom.com/pub/png/pngbook.html).
9041 -void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level)
9042 +void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilter)
9044 int i, j, bit_depth = 0, interlace_type;
9046 @@ -454,13 +474,13 @@
9047 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
9049 if (png_ptr == NULL) {
9050 - php_gd_error("gd-png error: cannot allocate libpng main struct\n");
9051 + php_gd_error("gd-png error: cannot allocate libpng main struct");
9055 info_ptr = png_create_info_struct(png_ptr);
9056 if (info_ptr == NULL) {
9057 - php_gd_error("gd-png error: cannot allocate libpng info struct\n");
9058 + php_gd_error("gd-png error: cannot allocate libpng info struct");
9059 png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
9064 #ifndef PNG_SETJMP_NOT_SUPPORTED
9065 if (setjmp (gdPngJmpbufStruct.jmpbuf)) {
9066 - php_gd_error("gd-png error: setjmp returns error condition\n");
9067 + php_gd_error("gd-png error: setjmp returns error condition");
9068 png_destroy_write_struct (&png_ptr, &info_ptr);
9071 @@ -483,14 +503,17 @@
9072 * gd is intentionally imperfect and doesn't spend a lot of time
9073 * fussing with such things.
9077 /* png_set_filter(png_ptr, 0, PNG_FILTER_NONE); */
9079 /* 2.0.12: this is finally a parameter */
9080 png_set_compression_level(png_ptr, level);
9081 + if (basefilter >= 0) {
9082 + png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, basefilter);
9085 /* can set this to a smaller value without compromising compression if all
9086 - * image data is 16K or less; will save some decoder memory [min == 8]
9087 + * image data is 16K or less; will save some decoder memory [min == 8]
9090 /* png_set_compression_window_bits(png_ptr, 15); */
9091 @@ -519,13 +542,13 @@
9093 } else if (colors <= 4) {
9095 - } else if (colors <= 16) {
9096 + } else if (colors <= 16) {
9104 interlace_type = im->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
9106 if (im->trueColor) {
9108 if (!im->trueColor) {
9109 /* Oy veh. Remap the PNG palette to put the entries with interesting alpha channel
9110 * values first. This minimizes the size of the tRNS chunk and thus the size
9111 - * of the PNG file as a whole.
9112 + * of the PNG file as a whole.
9120 for (i = 0; i < im->colorsTotal; i++) {
9122 if (im->alpha[i] != gdAlphaOpaque) {
9123 - /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
9124 + /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
9125 trans_values[j] = 255 - ((im->alpha[i] << 1) + (im->alpha[i] >> 6));
9129 * PNG's convention in which 255 is opaque.
9131 a = gdTrueColorGetAlpha(thisPixel);
9132 - /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
9133 + /* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
9134 *pOutputRow++ = 255 - ((a << 1) + (a >> 6));
9137 @@ -677,12 +700,12 @@
9138 for (j = 0; j < height; ++j) {
9139 gdFree(row_pointers[j]);
9143 gdFree(row_pointers);
9146 png_bytep *row_pointers;
9147 - row_pointers = safe_emalloc(sizeof(png_bytep), height, 0);
9148 + row_pointers = safe_emalloc(height, sizeof(png_bytep), 0);
9149 for (j = 0; j < height; ++j) {
9150 row_pointers[j] = (png_bytep) gdMalloc(width);
9151 for (i = 0; i < width; ++i) {
9152 diff -urN php-4.4.8.org/ext/gd/libgd/gd_security.c php-4.4.8/ext/gd/libgd/gd_security.c
9153 --- php-4.4.8.org/ext/gd/libgd/gd_security.c 2007-03-10 14:06:37.000000000 +0100
9154 +++ php-4.4.8/ext/gd/libgd/gd_security.c 2007-10-23 03:58:08.000000000 +0200
9157 int overflow2(int a, int b)
9159 - if(a < 0 || b < 0) {
9160 - php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative, failing operation gracefully\n");
9161 + if(a <= 0 || b <= 0) {
9162 + php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
9167 if(a > INT_MAX / b) {
9168 php_gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
9170 diff -urN php-4.4.8.org/ext/gd/libgd/gd_ss.c php-4.4.8/ext/gd/libgd/gd_ss.c
9171 --- php-4.4.8.org/ext/gd/libgd/gd_ss.c 2003-03-05 17:04:20.000000000 +0100
9172 +++ php-4.4.8/ext/gd/libgd/gd_ss.c 2005-08-18 14:54:44.000000000 +0200
9174 #define GD_SS_DBG(s)
9178 -gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
9179 +void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
9181 - gdIOCtx *out = gdNewSSCtx (NULL, outSink);
9182 - gdImagePngCtx (im, out);
9183 - out->gd_free (out);
9184 + gdIOCtx *out = gdNewSSCtx(NULL, outSink);
9185 + gdImagePngCtx(im, out);
9186 + out->gd_free(out);
9190 -gdImageCreateFromPngSource (gdSourcePtr inSource)
9191 +gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
9193 - gdIOCtx *in = gdNewSSCtx (inSource, NULL);
9195 + gdIOCtx *in = gdNewSSCtx(inSource, NULL);
9198 - im = gdImageCreateFromPngCtx (in);
9199 + im = gdImageCreateFromPngCtx(in);
9207 #else /* no HAVE_LIBPNG */
9209 -gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
9210 +void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
9212 - php_gd_error("PNG support is not available\n");
9213 + php_gd_error("PNG support is not available");
9216 -gdImageCreateFromPngSource (gdSourcePtr inSource)
9217 +gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
9219 - php_gd_error("PNG support is not available\n");
9221 + php_gd_error("PNG support is not available");
9224 #endif /* HAVE_LIBPNG */
9226 diff -urN php-4.4.8.org/ext/gd/libgd/gdtables.c php-4.4.8/ext/gd/libgd/gdtables.c
9227 --- php-4.4.8.org/ext/gd/libgd/gdtables.c 2002-04-13 04:03:09.000000000 +0200
9228 +++ php-4.4.8/ext/gd/libgd/gdtables.c 2006-09-15 17:11:54.000000000 +0200
9232 +#ifdef HAVE_CONFIG_H
9233 +#include "config.h"
9236 +#include "php_compat.h"
9238 +const int gdCosT[] =
9247 +const int gdSinT[] =
9251 diff -urN php-4.4.8.org/ext/gd/libgd/gdtest.c php-4.4.8/ext/gd/libgd/gdtest.c
9252 --- php-4.4.8.org/ext/gd/libgd/gdtest.c 2002-10-30 00:08:01.000000000 +0100
9253 +++ php-4.4.8/ext/gd/libgd/gdtest.c 2007-02-24 03:17:24.000000000 +0100
9256 /* Send to PNG File then Ptr */
9258 - sprintf (of, "%s.png", argv[1]);
9259 + snprintf (of, sizeof(of), "%s.png", argv[1]);
9260 out = fopen (of, "wb");
9261 gdImagePng (im, out);
9265 /* Send to GD2 File then Ptr */
9267 - sprintf (of, "%s.gd2", argv[1]);
9268 + snprintf (of, sizeof(of), "%s.gd2", argv[1]);
9269 out = fopen (of, "wb");
9270 gdImageGd2 (im, out, 128, 2);
9274 /* Send to GD File then Ptr */
9276 - sprintf (of, "%s.gd", argv[1]);
9277 + snprintf (of, sizeof(of), "%s.gd", argv[1]);
9278 out = fopen (of, "wb");
9279 gdImageGd (im, out);
9282 ** Test gdImagePngToSink'
9285 - sprintf (of, "%s.snk", argv[1]);
9286 + snprintf (of, sizeof(of), "%s.snk", argv[1]);
9287 out = fopen (of, "wb");
9288 imgsnk.sink = fwriteWrapper;
9289 imgsnk.context = out;
9290 diff -urN php-4.4.8.org/ext/gd/libgd/gd_topal.c php-4.4.8/ext/gd/libgd/gd_topal.c
9291 --- php-4.4.8.org/ext/gd/libgd/gd_topal.c 2004-08-12 01:25:54.000000000 +0200
9292 +++ php-4.4.8/ext/gd/libgd/gd_topal.c 2007-04-04 02:30:18.000000000 +0200
9294 nim->green[icolor] = 255;
9295 nim->blue[icolor] = 255;
9297 + nim->open[icolor] = 0;
9301 @@ -2086,6 +2087,9 @@
9302 if( (im1->sx != im2->sx) || (im1->sy != im2->sy) ) {
9303 return -3; /* the images are meant to be the same dimensions */
9305 + if (im2->colorsTotal<1) {
9306 + return -4; /* At least 1 color must be allocated */
9309 buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0);
9310 memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal );
9311 diff -urN php-4.4.8.org/ext/gd/libgd/gd_wbmp.c php-4.4.8/ext/gd/libgd/gd_wbmp.c
9312 --- php-4.4.8.org/ext/gd/libgd/gd_wbmp.c 2004-03-29 20:21:00.000000000 +0200
9313 +++ php-4.4.8/ext/gd/libgd/gd_wbmp.c 2005-08-18 14:54:44.000000000 +0200
9318 WBMP: Wireless Bitmap Type 0: B/W, Uncompressed Bitmap
9319 - Specification of the WBMP format can be found in the file:
9320 + Specification of the WBMP format can be found in the file:
9321 SPEC-WAESpec-19990524.pdf
9322 - You can download the WAP specification on: http://www.wapforum.com/
9323 + You can download the WAP specification on: http://www.wapforum.com/
9328 (wbmp library included, but you can find the latest distribution
9329 at http://www.vandenbrande.com/wbmp)
9331 - Implemented: gdImageCreateFromWBMPCtx, gdImageCreateFromWBMP
9332 + Implemented: gdImageCreateFromWBMPCtx, gdImageCreateFromWBMP
9334 ---------------------------------------------------------------------------
9337 ** implied warranty.
9339 ---------------------------------------------------------------------------
9340 - Parts od this code are inspired by 'pbmtowbmp.c' and 'wbmptopbm.c' by
9341 + Parts od this code are inspired by 'pbmtowbmp.c' and 'wbmptopbm.c' by
9342 Terje Sannum <terje@looplab.com>.
9344 ** Permission to use, copy, modify, and distribute this software and its
9346 ** Wrapper around gdPutC for use with writewbmp
9350 -gd_putout (int i, void *out)
9351 +void gd_putout (int i, void *out)
9353 - gdPutC (i, (gdIOCtx *) out);
9354 + gdPutC(i, (gdIOCtx *) out);
9359 ** Wrapper around gdGetC for use with readwbmp
9363 -gd_getin (void *in)
9364 +int gd_getin (void *in)
9366 - return (gdGetC ((gdIOCtx *) in));
9367 + return (gdGetC((gdIOCtx *) in));
9371 @@ -91,105 +87,93 @@
9372 ** Write the image as a wbmp file
9374 ** image: gd image structure;
9375 - ** fg: the index of the foreground color. any other value will be
9376 + ** fg: the index of the foreground color. any other value will be
9377 ** considered as background and will not be written
9378 ** out: the stream where to write
9381 -gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
9382 +void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
9389 + /* create the WBMP */
9390 + if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) {
9391 + php_gd_error("Could not create WBMP");
9394 + /* fill up the WBMP structure */
9396 + for (y = 0; y < gdImageSY(image); y++) {
9397 + for (x = 0; x < gdImageSX(image); x++) {
9398 + if (gdImageGetPixel (image, x, y) == fg) {
9399 + wbmp->bitmap[pos] = WBMP_BLACK;
9405 - /* create the WBMP */
9406 - if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL)
9407 - php_gd_error("Could not create WBMP\n");
9409 - /* fill up the WBMP structure */
9411 - for (y = 0; y < gdImageSY (image); y++)
9413 - for (x = 0; x < gdImageSX (image); x++)
9415 - if (gdImageGetPixel (image, x, y) == fg)
9417 - wbmp->bitmap[pos] = WBMP_BLACK;
9423 - /* write the WBMP to a gd file descriptor */
9424 - if (writewbmp (wbmp, &gd_putout, out))
9425 - php_gd_error("Could not save WBMP\n");
9426 - /* des submitted this bugfix: gdFree the memory. */
9428 + /* write the WBMP to a gd file descriptor */
9429 + if (writewbmp (wbmp, &gd_putout, out)) {
9430 + php_gd_error("Could not save WBMP");
9432 + /* des submitted this bugfix: gdFree the memory. */
9437 /* gdImageCreateFromWBMPCtx
9438 ** ------------------------
9439 ** Create a gdImage from a WBMP file input from an gdIOCtx
9442 -gdImageCreateFromWBMPCtx (gdIOCtx * infile)
9443 +gdImagePtr gdImageCreateFromWBMPCtx (gdIOCtx * infile)
9445 - /* FILE *wbmp_file; */
9447 - gdImagePtr im = NULL;
9449 - int col, row, pos;
9451 - if (readwbmp (&gd_getin, infile, &wbmp))
9454 - if (!(im = gdImageCreate (wbmp->width, wbmp->height)))
9460 - /* create the background color */
9461 - white = gdImageColorAllocate (im, 255, 255, 255);
9462 - /* create foreground color */
9463 - black = gdImageColorAllocate (im, 0, 0, 0);
9465 - /* fill in image (in a wbmp 1 = white/ 0 = black) */
9467 - for (row = 0; row < wbmp->height; row++)
9469 - for (col = 0; col < wbmp->width; col++)
9471 - if (wbmp->bitmap[pos++] == WBMP_WHITE)
9473 - gdImageSetPixel (im, col, row, white);
9477 - gdImageSetPixel (im, col, row, black);
9479 + /* FILE *wbmp_file; */
9481 + gdImagePtr im = NULL;
9483 + int col, row, pos;
9485 + if (readwbmp (&gd_getin, infile, &wbmp)) {
9491 + if (!(im = gdImageCreate (wbmp->width, wbmp->height))) {
9498 + /* create the background color */
9499 + white = gdImageColorAllocate(im, 255, 255, 255);
9500 + /* create foreground color */
9501 + black = gdImageColorAllocate(im, 0, 0, 0);
9503 + /* fill in image (in a wbmp 1 = white/ 0 = black) */
9505 + for (row = 0; row < wbmp->height; row++) {
9506 + for (col = 0; col < wbmp->width; col++) {
9507 + if (wbmp->bitmap[pos++] == WBMP_WHITE) {
9508 + gdImageSetPixel(im, col, row, white);
9510 + gdImageSetPixel(im, col, row, black);
9520 /* gdImageCreateFromWBMP
9521 ** ---------------------
9524 -gdImageCreateFromWBMP (FILE * inFile)
9525 +gdImagePtr gdImageCreateFromWBMP (FILE * inFile)
9528 - gdIOCtx *in = gdNewFileCtx (inFile);
9529 - im = gdImageCreateFromWBMPCtx (in);
9533 + gdIOCtx *in = gdNewFileCtx(inFile);
9534 + im = gdImageCreateFromWBMPCtx(in);
9540 gdImagePtr gdImageCreateFromWBMPPtr (int size, void *data)
9541 @@ -204,24 +188,23 @@
9546 -gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
9547 +void gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
9549 - gdIOCtx *out = gdNewFileCtx (outFile);
9550 - gdImageWBMPCtx (im, fg, out);
9551 - out->gd_free (out);
9552 + gdIOCtx *out = gdNewFileCtx(outFile);
9553 + gdImageWBMPCtx(im, fg, out);
9554 + out->gd_free(out);
9561 -gdImageWBMPPtr (gdImagePtr im, int *size, int fg)
9562 +void * gdImageWBMPPtr (gdImagePtr im, int *size, int fg)
9565 - gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
9566 - gdImageWBMPCtx (im, fg, out);
9567 - rv = gdDPExtractData (out, size);
9568 - out->gd_free (out);
9571 + gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
9572 + gdImageWBMPCtx(im, fg, out);
9573 + rv = gdDPExtractData(out, size);
9574 + out->gd_free(out);
9578 diff -urN php-4.4.8.org/ext/gd/libgd/gdxpm.c php-4.4.8/ext/gd/libgd/gdxpm.c
9579 --- php-4.4.8.org/ext/gd/libgd/gdxpm.c 2003-06-04 01:42:49.000000000 +0200
9580 +++ php-4.4.8/ext/gd/libgd/gdxpm.c 2005-08-18 14:54:44.000000000 +0200
9585 add ability to load xpm files to gd, requires the xpm
9587 - Caolan.McNamara@ul.ie
9588 + Caolan.McNamara@ul.ie
9589 http://www.csn.ul.ie/~caolan
9592 @@ -15,123 +15,125 @@
9594 #include <X11/xpm.h>
9597 -gdImageCreateFromXpm (char *filename)
9598 +gdImagePtr gdImageCreateFromXpm (char *filename)
9602 - int i, j, k, number;
9604 - gdImagePtr im = 0;
9607 - int red = 0, green = 0, blue = 0;
9611 - ret = XpmReadFileToXpmImage (filename, &image, &info);
9612 - if (ret != XpmSuccess)
9615 - if (!(im = gdImageCreate (image.width, image.height)))
9618 - number = image.ncolors;
9619 - colors = (int *) safe_emalloc(number, sizeof(int), 0);
9620 - for (i = 0; i < number; i++)
9622 - switch (strlen (image.colorTable[i].c_color))
9626 - buf[0] = image.colorTable[i].c_color[1];
9627 - red = strtol (buf, NULL, 16);
9629 - buf[0] = image.colorTable[i].c_color[3];
9630 - green = strtol (buf, NULL, 16);
9632 - buf[0] = image.colorTable[i].c_color[5];
9633 - blue = strtol (buf, NULL, 16);
9637 - buf[0] = image.colorTable[i].c_color[1];
9638 - buf[1] = image.colorTable[i].c_color[2];
9639 - red = strtol (buf, NULL, 16);
9641 - buf[0] = image.colorTable[i].c_color[3];
9642 - buf[1] = image.colorTable[i].c_color[4];
9643 - green = strtol (buf, NULL, 16);
9645 - buf[0] = image.colorTable[i].c_color[5];
9646 - buf[1] = image.colorTable[i].c_color[6];
9647 - blue = strtol (buf, NULL, 16);
9651 - buf[0] = image.colorTable[i].c_color[1];
9652 - buf[1] = image.colorTable[i].c_color[2];
9653 - buf[2] = image.colorTable[i].c_color[3];
9654 - red = strtol (buf, NULL, 16);
9657 - buf[0] = image.colorTable[i].c_color[4];
9658 - buf[1] = image.colorTable[i].c_color[5];
9659 - buf[2] = image.colorTable[i].c_color[6];
9660 - green = strtol (buf, NULL, 16);
9663 - buf[0] = image.colorTable[i].c_color[7];
9664 - buf[1] = image.colorTable[i].c_color[8];
9665 - buf[2] = image.colorTable[i].c_color[9];
9666 - blue = strtol (buf, NULL, 16);
9671 - buf[0] = image.colorTable[i].c_color[1];
9672 - buf[1] = image.colorTable[i].c_color[2];
9673 - buf[2] = image.colorTable[i].c_color[3];
9674 - buf[3] = image.colorTable[i].c_color[4];
9675 - red = strtol (buf, NULL, 16);
9678 - buf[0] = image.colorTable[i].c_color[5];
9679 - buf[1] = image.colorTable[i].c_color[6];
9680 - buf[2] = image.colorTable[i].c_color[7];
9681 - buf[3] = image.colorTable[i].c_color[8];
9682 - green = strtol (buf, NULL, 16);
9685 - buf[0] = image.colorTable[i].c_color[9];
9686 - buf[1] = image.colorTable[i].c_color[10];
9687 - buf[2] = image.colorTable[i].c_color[11];
9688 - buf[3] = image.colorTable[i].c_color[12];
9689 - blue = strtol (buf, NULL, 16);
9694 + int i, j, k, number;
9696 + gdImagePtr im = 0;
9699 + int red = 0, green = 0, blue = 0;
9703 + ret = XpmReadFileToXpmImage(filename, &image, &info);
9704 + if (ret != XpmSuccess) {
9708 + if (!(im = gdImageCreate(image.width, image.height))) {
9712 - colors[i] = gdImageColorResolve (im, red, green, blue);
9713 - if (colors[i] == -1)
9714 - php_gd_error("ARRRGH\n");
9717 - apixel = (char *) gdMalloc (image.cpp + 1);
9718 - apixel[image.cpp] = '\0';
9720 - pointer = (int *) image.data;
9721 - for (i = 0; i < image.height; i++)
9723 - for (j = 0; j < image.width; j++)
9726 - gdImageSetPixel (im, j, i, colors[k]);
9727 + number = image.ncolors;
9728 + colors = (int *) safe_emalloc(number, sizeof(int), 0);
9729 + for (i = 0; i < number; i++) {
9730 + switch (strlen (image.colorTable[i].c_color)) {
9733 + buf[0] = image.colorTable[i].c_color[1];
9734 + red = strtol(buf, NULL, 16);
9736 + buf[0] = image.colorTable[i].c_color[2];
9737 + green = strtol(buf, NULL, 16);
9739 + buf[0] = image.colorTable[i].c_color[3];
9740 + blue = strtol(buf, NULL, 16);
9745 + buf[0] = image.colorTable[i].c_color[1];
9746 + buf[1] = image.colorTable[i].c_color[2];
9747 + red = strtol(buf, NULL, 16);
9749 + buf[0] = image.colorTable[i].c_color[3];
9750 + buf[1] = image.colorTable[i].c_color[4];
9751 + green = strtol(buf, NULL, 16);
9753 + buf[0] = image.colorTable[i].c_color[5];
9754 + buf[1] = image.colorTable[i].c_color[6];
9755 + blue = strtol(buf, NULL, 16);
9760 + buf[0] = image.colorTable[i].c_color[1];
9761 + buf[1] = image.colorTable[i].c_color[2];
9762 + buf[2] = image.colorTable[i].c_color[3];
9763 + red = strtol(buf, NULL, 16);
9766 + buf[0] = image.colorTable[i].c_color[4];
9767 + buf[1] = image.colorTable[i].c_color[5];
9768 + buf[2] = image.colorTable[i].c_color[6];
9769 + green = strtol(buf, NULL, 16);
9772 + buf[0] = image.colorTable[i].c_color[7];
9773 + buf[1] = image.colorTable[i].c_color[8];
9774 + buf[2] = image.colorTable[i].c_color[9];
9775 + blue = strtol(buf, NULL, 16);
9781 + buf[0] = image.colorTable[i].c_color[1];
9782 + buf[1] = image.colorTable[i].c_color[2];
9783 + buf[2] = image.colorTable[i].c_color[3];
9784 + buf[3] = image.colorTable[i].c_color[4];
9785 + red = strtol(buf, NULL, 16);
9788 + buf[0] = image.colorTable[i].c_color[5];
9789 + buf[1] = image.colorTable[i].c_color[6];
9790 + buf[2] = image.colorTable[i].c_color[7];
9791 + buf[3] = image.colorTable[i].c_color[8];
9792 + green = strtol(buf, NULL, 16);
9795 + buf[0] = image.colorTable[i].c_color[9];
9796 + buf[1] = image.colorTable[i].c_color[10];
9797 + buf[2] = image.colorTable[i].c_color[11];
9798 + buf[3] = image.colorTable[i].c_color[12];
9799 + blue = strtol(buf, NULL, 16);
9805 + colors[i] = gdImageColorResolve(im, red, green, blue);
9806 + if (colors[i] == -1) {
9807 + php_gd_error("ARRRGH");
9815 + apixel = (char *) gdMalloc(image.cpp + 1);
9816 + apixel[image.cpp] = '\0';
9818 + pointer = (int *) image.data;
9819 + for (i = 0; i < image.height; i++) {
9820 + for (j = 0; j < image.width; j++) {
9822 + gdImageSetPixel(im, j, i, colors[k]);
9831 diff -urN php-4.4.8.org/ext/gd/libgd/testac.c php-4.4.8/ext/gd/libgd/testac.c
9832 --- php-4.4.8.org/ext/gd/libgd/testac.c 2002-04-13 04:03:09.000000000 +0200
9833 +++ php-4.4.8/ext/gd/libgd/testac.c 2003-12-28 21:11:08.000000000 +0100
9836 /* Load original PNG, which should contain alpha channel
9837 information. We will use it in two ways: preserving it
9838 - literally, for use with compatible browsers, and
9839 + literally, for use with compatible browsers, and
9840 compositing it ourselves against a background of our
9841 choosing (alpha blending). We'll change its size
9842 and try creating palette versions of it. */
9844 /* Create output image. */
9845 im_out = gdImageCreateTrueColor ((int) (gdImageSX (im_in) * scale),
9846 (int) (gdImageSY (im_in) * scale));
9849 Request alpha blending. This causes future
9850 drawing operations to perform alpha channel blending
9851 with the background, resulting in an opaque image.
9854 /* If this image is the result of alpha channel blending,
9855 it will not contain an interesting alpha channel itself.
9856 - Save a little file size by not saving the alpha channel.
9857 + Save a little file size by not saving the alpha channel.
9858 Otherwise the file would typically be slightly larger. */
9859 gdImageSaveAlpha (im_out, !blending);
9861 diff -urN php-4.4.8.org/ext/gd/libgd/wbmp.c php-4.4.8/ext/gd/libgd/wbmp.c
9862 --- php-4.4.8.org/ext/gd/libgd/wbmp.c 2007-03-10 14:06:37.000000000 +0100
9863 +++ php-4.4.8/ext/gd/libgd/wbmp.c 2007-03-10 13:18:36.000000000 +0100
9868 - ** Get a multibyte integer from a generic getin function
9869 + ** Get a multibyte integer from a generic getin function
9870 ** 'getin' can be getc, with in = NULL
9871 ** you can find getin as a function just above the main function
9872 ** This way you gain a lot of flexibilty about how this package
9877 - if ((wbmp->bitmap = (int *) safe_emalloc(sizeof(int), (width * height), 0)) == NULL)
9878 + if ((wbmp->bitmap = (int *) safe_emalloc(sizeof(int), width * height, 0)) == NULL)
9886 - if ((wbmp->bitmap = (int *) safe_emalloc(sizeof(int), (wbmp->width * wbmp->height), 0)) == NULL)
9887 + if ((wbmp->bitmap = (int *) safe_emalloc((size_t)wbmp->width * wbmp->height, sizeof(int), 0)) == NULL)
9892 ** Why not just giving a filedescriptor to this function?
9893 ** Well, the incentive to write this function was the complete
9894 ** integration in gd library from www.boutell.com. They use
9895 - ** their own io functions, so the passing of a function seemed to be
9896 + ** their own io functions, so the passing of a function seemed to be
9897 ** a logic(?) decision ...
9901 return (putc (c, (FILE *) out));
9904 -/* getin from file descriptor
9905 +/* getin from file descriptor
9906 ** --------------------------
9909 diff -urN php-4.4.8.org/ext/gd/libgd/wbmp.h php-4.4.8/ext/gd/libgd/wbmp.h
9910 --- php-4.4.8.org/ext/gd/libgd/wbmp.h 2002-04-13 04:03:09.000000000 +0200
9911 +++ php-4.4.8/ext/gd/libgd/wbmp.h 2005-10-09 14:06:27.000000000 +0200
9913 ** (c) 2000 Johan Van den Brande <johan@vandenbrande.com>
9921 +#ifdef HAVE_CONFIG_H
9922 +#include "config.h"
9925 +#include "php_compat.h"
9929 ** A Wireless bitmap structure
9934 typedef struct Wbmp_
9936 int type; /* type of the wbmp */
9938 int height; /* height of the image */
9939 int *bitmap; /* pointer to data: 0 = WHITE , 1 = BLACK */
9943 #define WBMP_WHITE 1
9944 #define WBMP_BLACK 0
9952 -void putmbi( int i, void (*putout)(int c, void *out), void *out);
9953 +void putmbi( int i, void (*putout)(int c, void *out), void *out);
9954 int getmbi ( int (*getin)(void *in), void *in );
9955 int skipheader( int (*getin)(void *in), void *in );
9956 Wbmp *createwbmp( int width, int height, int color );
9957 int readwbmp( int (*getin)(void *in), void *in, Wbmp **wbmp );
9958 int writewbmp( Wbmp *wbmp, void (*putout)( int c, void *out), void *out);
9959 void freewbmp( Wbmp *wbmp );
9960 -void printwbmp( Wbmp *wbmp );
9961 +void printwbmp( Wbmp *wbmp );
9964 diff -urN php-4.4.8.org/ext/gd/libgd/webpng.c php-4.4.8/ext/gd/libgd/webpng.c
9965 --- php-4.4.8.org/ext/gd/libgd/webpng.c 2002-04-21 15:48:22.000000000 +0200
9966 +++ php-4.4.8/ext/gd/libgd/webpng.c 2007-02-24 03:17:24.000000000 +0100
9968 maxy = gdImageSY(im);
9970 printf("alpha channel information:\n");
9973 if (im->trueColor) {
9974 for (y = 0; y < maxy; y++) {
9975 for (x = 0; x < maxx; x++) {
9979 printf("NOT a true color image\n");
9982 printf("%d alpha channels\n", nalpha);
9989 /* Open a temporary file. */
9991 /* "temp.tmp" is not good temporary filename. */
9992 - sprintf (outFn, "webpng.tmp%d", getpid ());
9993 + snprintf (outFn, sizeof(outFn), "webpng.tmp%d", getpid ());
9994 out = fopen (outFn, "wb");
9997 diff -urN php-4.4.8.org/ext/gd/libgd/xbm.c php-4.4.8/ext/gd/libgd/xbm.c
9998 --- php-4.4.8.org/ext/gd/libgd/xbm.c 2007-12-31 08:22:47.000000000 +0100
9999 +++ php-4.4.8/ext/gd/libgd/xbm.c 2007-08-09 14:08:29.000000000 +0200
10002 +----------------------------------------------------------------------+
10003 - | PHP Version 4 |
10004 + | PHP Version 5 |
10005 +----------------------------------------------------------------------+
10006 - | Copyright (c) 1997-2008 The PHP Group |
10007 + | Copyright (c) 1997-2007 The PHP Group |
10008 +----------------------------------------------------------------------+
10009 | This source file is subject to version 3.01 of the PHP license, |
10010 | that is bundled with this package in the file LICENSE, and is |
10012 +----------------------------------------------------------------------+
10022 #define MAX_XBM_LINE_SIZE 255
10025 -gdImageCreateFromXbm (FILE * fd)
10026 +/* {{{ gdImagePtr gdImageCreateFromXbm */
10027 +gdImagePtr gdImageCreateFromXbm(FILE * fd)
10029 char fline[MAX_XBM_LINE_SIZE];
10030 char iname[MAX_XBM_LINE_SIZE];
10038 while (fgets(fline, MAX_XBM_LINE_SIZE, fd)) {
10039 fline[MAX_XBM_LINE_SIZE-1] = '\0';
10046 if (!strcmp("width", type)) {
10047 width = (unsigned int) value;
10053 - im = gdImageCreate(width, height);
10054 + if(!(im = gdImageCreate(width, height))) {
10057 gdImageColorAllocate(im, 255, 255, 255);
10058 gdImageColorAllocate(im, 0, 0, 0);
10060 @@ -147,7 +149,93 @@
10064 - php_gd_error("EOF before image was complete\n");
10065 + php_gd_error("EOF before image was complete");
10066 gdImageDestroy(im);
10071 +/* {{{ gdCtxPrintf */
10072 +void gdCtxPrintf(gdIOCtx * out, const char *format, ...)
10078 + va_start(args, format);
10079 + len = vspprintf(&buf, 0, format, args);
10081 + out->putBuf(out, buf, len);
10086 +/* {{{ gdImageXbmCtx */
10087 +void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out)
10089 + int x, y, c, b, sx, sy, p;
10093 + name = file_name;
10094 + if ((f = strrchr(name, '/')) != NULL) name = f+1;
10095 + if ((f = strrchr(name, '\\')) != NULL) name = f+1;
10096 + name = estrdup(name);
10097 + if ((f = strrchr(name, '.')) != NULL && !strcasecmp(f, ".XBM")) *f = '\0';
10098 + if ((l = strlen(name)) == 0) {
10100 + name = estrdup("image");
10102 + for (i=0; i<l; i++) {
10103 + /* only in C-locale isalnum() would work */
10104 + if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) {
10110 + gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image));
10111 + gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image));
10112 + gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name);
10119 + sx = gdImageSX(image);
10120 + sy = gdImageSY(image);
10121 + for (y = 0; y < sy; y++) {
10122 + for (x = 0; x < sx; x++) {
10123 + if (gdImageGetPixel(image, x, y) == fg) {
10126 + if ((b == 128) || (x == sx && y == sy)) {
10129 + gdCtxPrintf(out, ", ");
10131 + gdCtxPrintf(out, "\n ");
10136 + gdCtxPrintf(out, "0x%02X", c);
10143 + gdCtxPrintf(out, "};\n");
10148 + * Local variables:
10150 + * c-basic-offset: 4
10152 + * vim600: sw=4 ts=4 fdm=marker
10153 + * vim<600: sw=4 ts=4
10155 diff -urN php-4.4.8.org/ext/gd/php_gd.h php-4.4.8/ext/gd/php_gd.h
10156 --- php-4.4.8.org/ext/gd/php_gd.h 2007-12-31 08:22:47.000000000 +0100
10157 +++ php-4.4.8/ext/gd/php_gd.h 2008-01-22 22:38:05.897151947 +0100
10160 +----------------------------------------------------------------------+
10161 - | PHP Version 4 |
10162 + | PHP Version 5 |
10163 +----------------------------------------------------------------------+
10164 - | Copyright (c) 1997-2008 The PHP Group |
10165 + | Copyright (c) 1997-2007 The PHP Group |
10166 +----------------------------------------------------------------------+
10167 | This source file is subject to version 3.01 of the PHP license, |
10168 | that is bundled with this package in the file LICENSE, and is |
10169 @@ -13,11 +13,11 @@
10170 | license@php.net so we can mail you a copy immediately. |
10171 +----------------------------------------------------------------------+
10172 | Authors: Rasmus Lerdorf <rasmus@php.net> |
10173 - | Stig Bakken <ssb@fast.no> |
10174 + | Stig Bakken <ssb@php.net> |
10175 +----------------------------------------------------------------------+
10185 /* open_basedir and safe_mode checks */
10186 #define PHP_GD_CHECK_OPEN_BASEDIR(filename, errormsg) \
10187 - if (!filename || filename == empty_string || php_check_open_basedir(filename TSRMLS_CC) || \
10188 + if (!filename || php_check_open_basedir(filename TSRMLS_CC) || \
10189 (PG(safe_mode) && !php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR)) \
10191 php_error_docref(NULL TSRMLS_CC, E_WARNING, errormsg); \
10193 /* gd.c functions */
10194 PHP_MINFO_FUNCTION(gd);
10195 PHP_MINIT_FUNCTION(gd);
10196 +#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
10197 PHP_MSHUTDOWN_FUNCTION(gd);
10199 #if HAVE_LIBGD20 && HAVE_GD_STRINGFT
10200 PHP_RSHUTDOWN_FUNCTION(gd);
10202 @@ -112,6 +114,11 @@
10203 PHP_FUNCTION(imagecopyresampled);
10207 +PHP_FUNCTION(imagegrabwindow);
10208 +PHP_FUNCTION(imagegrabscreen);
10211 #ifdef HAVE_GD_BUNDLED
10212 PHP_FUNCTION(imagerotate);
10213 PHP_FUNCTION(imageantialias);
10214 @@ -184,6 +191,8 @@
10215 PHP_FUNCTION(imagelayereffect);
10216 PHP_FUNCTION(imagecolormatch);
10217 PHP_FUNCTION(imagefilter);
10218 +PHP_FUNCTION(imageconvolution);
10219 +PHP_FUNCTION(imagexbm);
10222 PHP_GD_API int phpi_get_le_gd(void);