-diff -urN php-4.4.7.org/ext/gd/config.m4 php-4.4.7/ext/gd/config.m4
---- php-4.4.7.org/ext/gd/config.m4 2007-03-10 14:06:37.000000000 +0100
-+++ php-4.4.7/ext/gd/config.m4 2007-05-30 22:09:19.568683975 +0200
-@@ -259,6 +259,7 @@
+diff -urN php-4.4.8.org/ext/gd/config.m4 php-4.4.8/ext/gd/config.m4
+--- php-4.4.8.org/ext/gd/config.m4 2007-03-10 14:06:37.000000000 +0100
++++ php-4.4.8/ext/gd/config.m4 2008-01-22 22:38:05.833815388 +0100
+@@ -259,12 +259,13 @@
PHP_CHECK_LIBRARY(gd, gdCacheCreate, [AC_DEFINE(HAVE_GD_CACHE_CREATE, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ])
PHP_CHECK_LIBRARY(gd, gdFontCacheShutdown, [AC_DEFINE(HAVE_GD_FONTCACHESHUTDOWN,1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ])
PHP_CHECK_LIBRARY(gd, gdFreeFontCache, [AC_DEFINE(HAVE_GD_FREEFONTCACHE, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ])
PHP_CHECK_LIBRARY(gd, gdNewDynamicCtxEx, [AC_DEFINE(HAVE_GD_DYNAMIC_CTX_EX, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ])
])
+ dnl
+ dnl Main GD configure
+-dnl
++dnl
+
+ if test "$PHP_GD" = "yes"; then
+ GD_MODULE_TYPE=builtin
@@ -310,6 +311,7 @@
AC_DEFINE(HAVE_GD_GIF_CREATE, 1, [ ])
AC_DEFINE(HAVE_GD_IMAGEELLIPSE, 1, [ ])
AC_DEFINE(HAVE_GD_DYNAMIC_CTX_EX, 1, [ ])
AC_DEFINE(HAVE_GD_GIF_CTX, 1, [ ])
-diff -urN php-4.4.7.org/ext/gd/gd.c php-4.4.7/ext/gd/gd.c
---- php-4.4.7.org/ext/gd/gd.c 2007-01-01 10:46:42.000000000 +0100
-+++ php-4.4.7/ext/gd/gd.c 2007-05-30 21:48:29.386645975 +0200
-@@ -333,6 +333,9 @@
- #if HAVE_LIBT1
- T1_CloseLib();
- #endif
-+#if HAVE_GD_FONTMUTEX
-+ gdFontCacheMutexShutdown();
-+#endif
- return SUCCESS;
+diff -urN php-4.4.8.org/ext/gd/gd.c php-4.4.8/ext/gd/gd.c
+--- php-4.4.8.org/ext/gd/gd.c 2007-12-31 08:22:47.000000000 +0100
++++ php-4.4.8/ext/gd/gd.c 2008-01-22 22:38:05.837148890 +0100
+@@ -29,7 +29,13 @@
+ #include "config.h"
+ #endif
+
++#ifdef HAVE_GD_PNG
++/* needs to be first */
++#include <png.h>
++#endif
++
+ #include "php.h"
++#include "php_ini.h"
+ #include "ext/standard/head.h"
+ #include <math.h>
+ #include "SAPI.h"
+@@ -46,6 +52,9 @@
+ #ifdef PHP_WIN32
+ # include <io.h>
+ # include <fcntl.h>
++#include <windows.h>
++#include <Winuser.h>
++#include <Wingdi.h>
+ #endif
+
+ #if HAVE_LIBGD
+@@ -64,10 +73,20 @@
+ #include <gdfontmb.h> /* 3 Medium bold font */
+ #include <gdfontl.h> /* 4 Large font */
+ #include <gdfontg.h> /* 5 Giant font */
++#if HAVE_GD_BUNDLED
+ #ifdef HAVE_GD_WBMP
+ #include "libgd/wbmp.h"
+ #endif
++#endif
+ #ifdef ENABLE_GD_TTF
++# ifdef HAVE_LIBFREETYPE
++# include <ft2build.h>
++# include FT_FREETYPE_H
++# else
++# ifdef HAVE_LIBTTF
++# include <freetype.h>
++# endif
++# endif
+ # include "gdttf.h"
+ #endif
+
+@@ -112,6 +131,40 @@
+ #define gdNewDynamicCtxEx(len, data, val) gdNewDynamicCtx(len, data)
+ #endif
+
++/* Section Filters Declarations */
++/* IMPORTANT NOTE FOR NEW FILTER
++ * Do not forget to update:
++ * IMAGE_FILTER_MAX: define the last filter index
++ * IMAGE_FILTER_MAX_ARGS: define the biggest amout of arguments
++ * image_filter array in PHP_FUNCTION(imagefilter)
++ * */
++#if HAVE_GD_BUNDLED
++#define IMAGE_FILTER_NEGATE 0
++#define IMAGE_FILTER_GRAYSCALE 1
++#define IMAGE_FILTER_BRIGHTNESS 2
++#define IMAGE_FILTER_CONTRAST 3
++#define IMAGE_FILTER_COLORIZE 4
++#define IMAGE_FILTER_EDGEDETECT 5
++#define IMAGE_FILTER_EMBOSS 6
++#define IMAGE_FILTER_GAUSSIAN_BLUR 7
++#define IMAGE_FILTER_SELECTIVE_BLUR 8
++#define IMAGE_FILTER_MEAN_REMOVAL 9
++#define IMAGE_FILTER_SMOOTH 10
++#define IMAGE_FILTER_MAX 10
++#define IMAGE_FILTER_MAX_ARGS 5
++static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS);
++static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS);
++#endif
++/* End Section filters declarations */
+ static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC);
+ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)());
+ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)());
+@@ -121,7 +174,7 @@
+
+ /* {{{ gd_functions[]
+ */
+-function_entry gd_functions[] = {
++zend_function_entry gd_functions[] = {
+ PHP_FE(gd_info, NULL)
+ PHP_FE(imagearc, NULL)
+ PHP_FE(imageellipse, NULL)
+@@ -167,6 +220,11 @@
+ PHP_FE(imagecopyresampled, NULL)
+ #endif
+
++#ifdef PHP_WIN32
++ PHP_FE(imagegrabwindow, NULL)
++ PHP_FE(imagegrabscreen, NULL)
++#endif
++
+ #ifdef HAVE_GD_BUNDLED
+ PHP_FE(imagerotate, NULL)
+ PHP_FE(imageantialias, NULL)
+@@ -277,6 +335,12 @@
+ #if HAVE_GD_BUNDLED
+ PHP_FE(imagelayereffect, NULL)
+ PHP_FE(imagecolormatch, NULL)
++ PHP_FE(imagexbm, NULL)
++#endif
++/* gd filters */
++#ifdef HAVE_GD_BUNDLED
++ PHP_FE(imagefilter, NULL)
++ PHP_FE(imageconvolution, NULL)
+ #endif
+
+ {NULL, NULL, NULL}
+@@ -288,9 +352,13 @@
+ "gd",
+ gd_functions,
+ PHP_MINIT(gd),
++#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
+ PHP_MSHUTDOWN(gd),
++#else
++ NULL,
++#endif
+ NULL,
+-#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
++#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
+ PHP_RSHUTDOWN(gd),
+ #else
+ NULL,
+@@ -304,6 +372,12 @@
+ ZEND_GET_MODULE(gd)
+ #endif
+
++/* {{{ PHP_INI_BEGIN */
++PHP_INI_BEGIN()
++ PHP_INI_ENTRY("gd.jpeg_ignore_warning", "0", PHP_INI_ALL, NULL)
++PHP_INI_END()
++/* }}} */
++
+ /* {{{ php_free_gd_image
+ */
+ static void php_free_gd_image(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+@@ -326,15 +400,21 @@
+ }
+ /* }}} */
+
++
+ /* {{{ PHP_MSHUTDOWN_FUNCTION
+ */
++#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
+ PHP_MSHUTDOWN_FUNCTION(gd)
+ {
+ #if HAVE_LIBT1
+ T1_CloseLib();
+ #endif
++#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
++ gdFontCacheMutexShutdown();
++#endif
+ return SUCCESS;
+ }
++#endif
+ /* }}} */
+
+
+@@ -344,6 +424,10 @@
+ {
+ le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
+ le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
++
++#if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
++ gdFontCacheMutexSetup();
++#endif
+ #if HAVE_LIBT1
+ T1_SetBitmapPad(8);
+ T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
+@@ -352,6 +436,8 @@
+ le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number);
+ #endif
+
++ REGISTER_INI_ENTRIES();
++
+ REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IMG_JPG", 2, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IMG_JPEG", 2, CONST_CS | CONST_PERSISTENT);
+@@ -387,16 +473,58 @@
+ REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GD_BUNDLED", 1, CONST_CS | CONST_PERSISTENT);
++
++ /* Section Filters */
++ REGISTER_LONG_CONSTANT("IMG_FILTER_NEGATE", IMAGE_FILTER_NEGATE, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_GRAYSCALE", IMAGE_FILTER_GRAYSCALE, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_BRIGHTNESS", IMAGE_FILTER_BRIGHTNESS, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_CONTRAST", IMAGE_FILTER_CONTRAST, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_COLORIZE", IMAGE_FILTER_COLORIZE, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_EDGEDETECT", IMAGE_FILTER_EDGEDETECT, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_GAUSSIAN_BLUR", IMAGE_FILTER_GAUSSIAN_BLUR, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_SELECTIVE_BLUR", IMAGE_FILTER_SELECTIVE_BLUR, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_EMBOSS", IMAGE_FILTER_EMBOSS, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_MEAN_REMOVAL", IMAGE_FILTER_MEAN_REMOVAL, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT);
++ /* End Section Filters */
+ #else
+ REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
+ #endif
++
++#ifdef GD_VERSION_STRING
++ REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
++#endif
++
++#if defined(GD_MAJOR_VERSION) && defined(GD_MINOR_VERSION) && defined(GD_RELEASE_VERSION) && defined(GD_EXTRA_VERSION)
++ REGISTER_LONG_CONSTANT("GD_MAJOR_VERSION", GD_MAJOR_VERSION, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("GD_MINOR_VERSION", GD_MINOR_VERSION, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("GD_RELEASE_VERSION", GD_RELEASE_VERSION, CONST_CS | CONST_PERSISTENT);
++ REGISTER_STRING_CONSTANT("GD_EXTRA_VERSION", GD_EXTRA_VERSION, CONST_CS | CONST_PERSISTENT);
++#endif
++
++
++#ifdef HAVE_GD_PNG
++
++/*
++ * cannot include #include "png.h"
++ * /usr/include/pngconf.h:310:2: error: #error png.h already includes setjmp.h with some additional fixup.
++ * as error, use the values for now...
++ */
++ REGISTER_LONG_CONSTANT("PNG_NO_FILTER", 0x00, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("PNG_FILTER_NONE", 0x08, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("PNG_FILTER_SUB", 0x10, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("PNG_FILTER_UP", 0x20, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("PNG_FILTER_AVG", 0x40, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("PNG_FILTER_PAETH", 0x80, CONST_CS | CONST_PERSISTENT);
++ REGISTER_LONG_CONSTANT("PNG_ALL_FILTERS", 0x08 | 0x10 | 0x20 | 0x40 | 0x80, CONST_CS | CONST_PERSISTENT);
++#endif
+ return SUCCESS;
+ }
+ /* }}} */
+
+ /* {{{ PHP_RSHUTDOWN_FUNCTION
+ */
+-#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
++#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
+ PHP_RSHUTDOWN_FUNCTION(gd)
+ {
+ #if HAVE_GD_FONTCACHESHUTDOWN
+@@ -410,7 +538,7 @@
+ /* }}} */
+
+ #if HAVE_GD_BUNDLED
+-#define PHP_GD_VERSION_STRING "bundled (2.0.28 compatible)"
++#define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)"
+ #elif HAVE_LIBGD20
+ #define PHP_GD_VERSION_STRING "2.0 or higher"
+ #elif HAVE_GDIMAGECOLORRESOLVE
+@@ -436,8 +564,24 @@
+ php_info_print_table_row(2, "FreeType Support", "enabled");
+ #if HAVE_LIBFREETYPE
+ php_info_print_table_row(2, "FreeType Linkage", "with freetype");
++ {
++ char tmp[256];
++#ifdef FREETYPE_PATCH
++ snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
++#elif defined(FREETYPE_MAJOR)
++ snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR);
++#else
++ snprintf(tmp, sizeof(tmp), "1.x");
++#endif
++ php_info_print_table_row(2, "FreeType Version", tmp);
++ }
+ #elif HAVE_LIBTTF
+ php_info_print_table_row(2, "FreeType Linkage", "with TTF library");
++ {
++ char tmp[256];
++ snprintf(tmp, sizeof(tmp), "%d.%d", TT_FREETYPE_MAJOR, TT_FREETYPE_MINOR);
++ php_info_print_table_row(2, "FreeType Version", tmp);
++ }
+ #else
+ php_info_print_table_row(2, "FreeType Linkage", "with unknown library");
+ #endif
+@@ -464,6 +608,9 @@
+ #ifdef HAVE_GD_WBMP
+ php_info_print_table_row(2, "WBMP Support", "enabled");
+ #endif
++#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
++ php_info_print_table_row(2, "XPM Support", "enabled");
++#endif
+ #ifdef HAVE_GD_XBM
+ php_info_print_table_row(2, "XBM Support", "enabled");
+ #endif
+@@ -530,6 +677,11 @@
+ #else
+ add_assoc_bool(return_value, "WBMP Support", 0);
+ #endif
++#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
++ add_assoc_bool(return_value, "XPM Support", 1);
++#else
++ add_assoc_bool(return_value, "XPM Support", 0);
++#endif
+ #ifdef HAVE_GD_XBM
+ add_assoc_bool(return_value, "XBM Support", 1);
+ #else
+@@ -548,6 +700,7 @@
+ {
+ return le_gd;
+ }
++/* }}} */
+
+ #ifndef HAVE_GDIMAGECOLORRESOLVE
+
+@@ -763,13 +916,19 @@
+ convert_to_long_ex(x_size);
+ convert_to_long_ex(y_size);
+
+- if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0) {
++ if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 ||
++ Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX
++ ) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
+ RETURN_FALSE;
+ }
+
+ im = gdImageCreateTrueColor(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
+
++ if (!im) {
++ RETURN_FALSE;
++ }
++
+ ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
+ }
+ /* }}} */
+@@ -836,15 +995,19 @@
+ result = gdImageColorMatch(im1, im2);
+ switch (result) {
+ case -1:
+- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image1 must be TrueColor" );
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 must be TrueColor" );
+ RETURN_FALSE;
+ break;
+ case -2:
+- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image2 must be Palette" );
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must be Palette" );
+ RETURN_FALSE;
+ break;
+ case -3:
+- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image1 and Image2 must be the same size" );
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 and Image2 must be the same size" );
++ RETURN_FALSE;
++ break;
++ case -4:
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must have at least one color" );
+ RETURN_FALSE;
+ break;
+ }
+@@ -977,6 +1140,7 @@
+
+ RETURN_TRUE;
+ }
++/* }}} */
+ #endif
+
+ #if HAVE_GD_BUNDLED
+@@ -1008,6 +1172,7 @@
+ zval *IM;
+ long red, green, blue, alpha;
+ gdImagePtr im;
++ int ct = (-1);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
+ RETURN_FALSE;
+@@ -1015,7 +1180,12 @@
+
+ ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
+
+- RETURN_LONG(gdImageColorAllocateAlpha(im, red, green, blue, alpha));
++ ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha);
++ if (ct < 0) {
++ RETURN_FALSE;
++ }
++
++ RETURN_LONG((long)ct);
+ }
+ /* }}} */
+
+@@ -1125,28 +1295,173 @@
+ /* }}} */
+ #endif
+
++#ifdef PHP_WIN32
++/* {{{ proto resource imagegrabwindow(int window_handle [, int client_area])
++ Grab a window or its client area using a windows handle (HWND property in COM instance) */
++PHP_FUNCTION(imagegrabwindow)
++{
++ HWND window;
++ long client_area = 0;
++ RECT rc = {0};
++ RECT rc_win = {0};
++ int Width, Height;
++ HDC hdc;
++ HDC memDC;
++ HBITMAP memBM;
++ HBITMAP hOld;
++ HINSTANCE handle;
++ long lwindow_handle;
++ typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
++ tPrintWindow pPrintWindow = 0;
++ gdImagePtr im;
++
++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &lwindow_handle, &client_area) == FAILURE) {
++ RETURN_FALSE;
++ }
++
++ window = (HWND) lwindow_handle;
++
++ if (!IsWindow(window)) {
++ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid window handle");
++ RETURN_FALSE;
++ }
++
++ hdc = GetDC(0);
++
++ if (client_area) {
++ GetClientRect(window, &rc);
++ Width = rc.right;
++ Height = rc.bottom;
++ } else {
++ GetWindowRect(window, &rc);
++ Width = rc.right - rc.left;
++ Height = rc.bottom - rc.top;
++ }
++
++ Width = (Width/4)*4;
++
++ memDC = CreateCompatibleDC(hdc);
++ memBM = CreateCompatibleBitmap(hdc, Width, Height);
++ hOld = (HBITMAP) SelectObject (memDC, memBM);
++
++
++ handle = LoadLibrary("User32.dll");
++ if ( handle == 0 ) {
++ goto clean;
++ }
++ pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow");
++
++ if ( pPrintWindow ) {
++ pPrintWindow(window, memDC, (UINT) client_area);
++ } else {
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows API too old");
++ RETURN_FALSE;
++ goto clean;
++ }
++
++ FreeLibrary(handle);
++
++ im = gdImageCreateTrueColor(Width, Height);
++ if (im) {
++ int x,y;
++ for (y=0; y <= Height; y++) {
++ for (x=0; x <= Width; x++) {
++ int c = GetPixel(memDC, x,y);
++ gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
++ }
++ }
++ }
++
++clean:
++ SelectObject(memDC,hOld);
++ DeleteObject(memBM);
++ DeleteDC(memDC);
++ ReleaseDC( 0, hdc );
++
++ if (!im) {
++ RETURN_FALSE;
++ } else {
++ ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
++ }
++}
++/* }}} */
++
++/* {{{ proto resource imagegrabscreen()
++ Grab a screenshot */
++PHP_FUNCTION(imagegrabscreen)
++{
++ HWND window = GetDesktopWindow();
++ RECT rc = {0};
++ int Width, Height;
++ HDC hdc;
++ HDC memDC;
++ HBITMAP memBM;
++ HBITMAP hOld;
++ HINSTANCE handle;
++ long lwindow_handle;
++ typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
++ tPrintWindow pPrintWindow = 0;
++ gdImagePtr im;
++ hdc = GetDC(0);
++
++ if (!hdc) {
++ RETURN_FALSE;
++ }
++
++ GetWindowRect(window, &rc);
++ Width = rc.right - rc.left;
++ Height = rc.bottom - rc.top;
++
++ Width = (Width/4)*4;
++
++ memDC = CreateCompatibleDC(hdc);
++ memBM = CreateCompatibleBitmap(hdc, Width, Height);
++ hOld = (HBITMAP) SelectObject (memDC, memBM);
++ BitBlt( memDC, 0, 0, Width, Height , hdc, rc.left, rc.top , SRCCOPY );
++
++ im = gdImageCreateTrueColor(Width, Height);
++ if (im) {
++ int x,y;
++ for (y=0; y <= Height; y++) {
++ for (x=0; x <= Width; x++) {
++ int c = GetPixel(memDC, x,y);
++ gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
++ }
++ }
++ }
++
++ SelectObject(memDC,hOld);
++ DeleteObject(memBM);
++ DeleteDC(memDC);
++ ReleaseDC( 0, hdc );
++
++ if (!im) {
++ RETURN_FALSE;
++ } else {
++ ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
++ }
++}
++/* }}} */
++#endif /* PHP_WIN32 */
++
+ #ifdef HAVE_GD_BUNDLED
+-/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor)
++/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor [, int ignoretransparent])
+ Rotate an image using a custom angle */
+ PHP_FUNCTION(imagerotate)
+ {
+- zval **SIM, **ANGLE, **BGDCOLOR;
++ zval *SIM;
+ gdImagePtr im_dst, im_src;
+ double degrees;
+ long color;
++ long ignoretransparent = 0;
+
+- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &SIM, &ANGLE, &BGDCOLOR) == FAILURE) {
+- ZEND_WRONG_PARAM_COUNT();
++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdl|l", &SIM, °rees, &color, &ignoretransparent) == FAILURE) {
++ RETURN_FALSE;
+ }
+
+- ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
+-
+- convert_to_long_ex(BGDCOLOR);
+- color = Z_LVAL_PP(BGDCOLOR);
++ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
+
+- convert_to_double_ex(ANGLE);
+- degrees = Z_DVAL_PP(ANGLE);
+- im_dst = gdImageRotate(im_src, degrees, color);
++ im_dst = gdImageRotate(im_src, degrees, color, ignoretransparent);
+
+ if (im_dst != NULL) {
+ ZEND_REGISTER_RESOURCE(return_value, im_dst, le_gd);
+@@ -1215,13 +1530,19 @@
+ convert_to_long_ex(x_size);
+ convert_to_long_ex(y_size);
+
+- if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0) {
++ if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 ||
++ Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX
++ ) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
+ RETURN_FALSE;
+ }
+
+ im = gdImageCreate(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
+
++ if (!im) {
++ RETURN_FALSE;
++ }
++
+ ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
+ }
+ /* }}} */
+@@ -1323,6 +1644,11 @@
+ im = (*ioctx_func_p)(io_ctx);
+ if (!im) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed data is not in '%s' format", tn);
++#if HAVE_LIBGD204
++ io_ctx->gd_free(io_ctx);
++#else
++ io_ctx->free(io_ctx);
++#endif
+ return NULL;
+ }
+
+@@ -1350,6 +1676,11 @@
+ }
+
+ convert_to_string_ex(data);
++ if (Z_STRLEN_PP(data) < 8) {
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string or invalid image");
++ RETURN_FALSE;
++ }
++
+ memcpy(sig, Z_STRVAL_PP(data), 8);
+
+ imtype = _php_image_type(sig);
+@@ -1401,7 +1732,7 @@
+ break;
+
+ default:
+- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format.");
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format");
+ RETURN_FALSE;
+ }
+
+@@ -1425,6 +1756,9 @@
+ php_stream *stream;
+ FILE * fp = NULL;
+ int argc=ZEND_NUM_ARGS();
++#ifdef HAVE_GD_JPG
++ long ignore_warning;
++#endif
+
+ if ((image_type == PHP_GDIMG_TYPE_GD2PART && argc != 5) ||
+ (image_type != PHP_GDIMG_TYPE_GD2PART && argc != 1) ||
+@@ -1436,6 +1770,10 @@
+
+ if (argc == 5 && image_type == PHP_GDIMG_TYPE_GD2PART) {
+ multi_convert_to_long_ex(4, srcx, srcy, width, height);
++ if (Z_LVAL_PP(width) < 1 || Z_LVAL_PP(height) < 1) {
++ php_error_docref(NULL TSRMLS_CC, E_WARNING,"Zero width or height not allowed");
++ RETURN_FALSE;
++ }
+ }
+
+ fn = Z_STRVAL_PP(file);
+@@ -1471,6 +1809,7 @@
+
+ io_ctx = gdNewDynamicCtxEx(buff_size, buff, 0);
+ if (!io_ctx) {
++ pefree(buff, 1);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context");
+ goto out_err;
+ }
+@@ -1485,7 +1824,7 @@
+ #else
+ io_ctx->free(io_ctx);
+ #endif
+-
++ pefree(buff, 1);
+ #endif
+ }
+ else {
+@@ -1505,6 +1844,18 @@
+ im = gdImageCreateFromXpm(fn);
+ break;
+ #endif
++
++#ifdef HAVE_GD_JPG
++ case PHP_GDIMG_TYPE_JPG:
++ ignore_warning = INI_INT("gd.jpeg_ignore_warning");
++#ifdef HAVE_GD_BUNDLED
++ im = gdImageCreateFromJpeg(fp, ignore_warning);
++#else
++ im = gdImageCreateFromJpeg(fp);
++#endif
++ break;
++#endif
++
+ default:
+ im = (*func_p)(fp);
+ break;
+@@ -1685,6 +2036,14 @@
+ (*func_p)(im, fp);
+ break;
+ #endif
++#ifdef HAVE_GD_GD2
++ case PHP_GDIMG_TYPE_GD2:
++ if (q == -1) {
++ q = 128;
++ }
++ (*func_p)(im, fp, q, t);
++ break;
++#endif
+ default:
+ if (q == -1) {
+ q = 128;
+@@ -1737,6 +2096,14 @@
+ (*func_p)(im, tmp);
+ break;
+ #endif
++#ifdef HAVE_GD_GD2
++ case PHP_GDIMG_TYPE_GD2:
++ if (q == -1) {
++ q = 128;
++ }
++ (*func_p)(im, tmp, q, t);
++ break;
++#endif
+ default:
+ (*func_p)(im, tmp);
+ break;
+@@ -1762,6 +2129,16 @@
+ }
+ /* }}} */
+
++/* {{{ proto int imagexbm(int im, string filename [, int foreground])
++ Output XBM image to browser or file */
++#if HAVE_GD_BUNDLED
++PHP_FUNCTION(imagexbm)
++{
++ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx);
++}
++#endif
++/* }}} */
++
+ #ifdef HAVE_GD_GIF_CREATE
+ /* {{{ proto bool imagegif(resource im [, string filename])
+ Output GIF image to browser or file */
+@@ -1782,7 +2159,7 @@
+ PHP_FUNCTION(imagepng)
+ {
+ #ifdef USE_GD_IOCTX
+- _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtx);
++ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtxEx);
+ #else
+ _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng);
+ #endif
+@@ -1862,6 +2239,7 @@
+ {
+ zval **IM, **red, **green, **blue;
+ gdImagePtr im;
++ int ct = (-1);
+
+ if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
+ ZEND_WRONG_PARAM_COUNT();
+@@ -1872,8 +2250,11 @@
+ convert_to_long_ex(red);
+ convert_to_long_ex(green);
+ convert_to_long_ex(blue);
+-
+- RETURN_LONG(gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
++ ct = gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue));
++ if (ct < 0) {
++ RETURN_FALSE;
++ }
++ RETURN_LONG(ct);
+ }
+ /* }}} */
+
+@@ -2508,7 +2889,7 @@
+ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
+ {
+ zval **IM, **POINTS, **NPOINTS, **COL;
+- pval **var = NULL;
++ zval **var = NULL;
+ gdImagePtr im;
+ gdPointPtr points;
+ int npoints, col, nelem, i;
+@@ -2716,7 +3097,7 @@
+ ch = (int)((unsigned char)*(Z_STRVAL_PP(C)));
+ } else {
+ str = (unsigned char *) estrndup(Z_STRVAL_PP(C), Z_STRLEN_PP(C));
+- l = strlen(str);
++ l = strlen((char *)str);
+ }
+
+ y = Z_LVAL_PP(Y);
+@@ -3083,7 +3464,7 @@
+ {
+ char tmp_font_path[MAXPATHLEN];
+
+- if (VCWD_REALPATH(fontname, tmp_font_path)) {
++ if (VCWD_REALPATH((char *)fontname, tmp_font_path)) {
+ fontname = (unsigned char *) fontname;
+ } else {
+ fontname = NULL;
+@@ -3093,16 +3474,18 @@
+ fontname = (unsigned char *) fontname;
+ #endif
+
++ PHP_GD_CHECK_OPEN_BASEDIR((char *)fontname, "Invalid font filename");
++
+ #ifdef USE_GD_IMGSTRTTF
+ # if HAVE_GD_STRINGFTEX
+ if (extended) {
+- error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
++ error = gdImageStringFTEx(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str, &strex);
+ }
+ else
+ # endif
+
+ # if HAVE_GD_STRINGFT
+- error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);
++ error = gdImageStringFT(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str);
+ # elif HAVE_GD_STRINGTTF
+ error = gdImageStringTTF(im, brect, col, fontname, ptsize, angle, x, y, str);
+ # endif
+@@ -3155,6 +3538,9 @@
+ {
+ zval **file;
+ int f_ind, *font;
++#ifdef PHP_WIN32
++ struct stat st;
++#endif
+
+ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
+ ZEND_WRONG_PARAM_COUNT();
+@@ -3162,24 +3548,18 @@
+
+ convert_to_string_ex(file);
+
++#ifdef PHP_WIN32
++ if (VCWD_STAT(Z_STRVAL_PP(file), &st) < 0) {
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Font file not found (%s)", Z_STRVAL_PP(file));
++ RETURN_FALSE;
++ }
++#endif
++
+ f_ind = T1_AddFont(Z_STRVAL_PP(file));
+
+ if (f_ind < 0) {
+- switch (f_ind) {
+- case -1:
+- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't find the font file");
+- RETURN_FALSE;
+- break;
+- case -2:
+- case -3:
+- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memory allocation fault in t1lib");
+- RETURN_FALSE;
+- break;
+- default:
+- php_error_docref(NULL TSRMLS_CC, E_WARNING, "An unknown error occurred in t1lib");
+- RETURN_FALSE;
+- break;
+- }
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind));
++ RETURN_FALSE;
+ }
+
+ if (T1_LoadFont(f_ind)) {
+@@ -3317,6 +3697,11 @@
+
+ T1_DeleteAllSizes(*f_ind);
+
++ if (Z_DVAL_PP(ext) <= 0) {
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter %F out of range (must be > 0)", Z_DVAL_PP(ext));
++ RETURN_FALSE;
++ }
++
+ if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) {
+ RETURN_FALSE;
+ }
+@@ -3348,7 +3733,7 @@
+ }
+ /* }}} */
+
+-/* {{{ proto array imagepstext(resource image, string text, resource font, int size, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias])
++/* {{{ 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])
+ Rasterize a string over an image */
+ PHP_FUNCTION(imagepstext)
+ {
+@@ -3371,11 +3756,6 @@
+ T1_TMATRIX *transform = NULL;
+ char *str;
+ int str_len;
+- int argc = ZEND_NUM_ARGS();
+-
+- if (argc != 8 && argc != 12) {
+- ZEND_WRONG_PARAM_COUNT();
+- }
+
+ 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) {
+ return;
+@@ -3455,7 +3835,7 @@
+
+ if (!str_path) {
+ if (T1_errno) {
+- php_error_docref(NULL TSRMLS_CC, E_WARNING, "libt1 returned error %d", T1_errno);
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
+ }
+ RETURN_FALSE;
+ }
+@@ -3476,7 +3856,7 @@
+ str_img = T1_AASetString(*f_ind, str, str_len, space, T1_KERNING, size, transform);
+ }
+ if (T1_errno) {
+- php_error_docref(NULL TSRMLS_CC, E_WARNING, "libt1 returned error %d", T1_errno);
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
+ RETURN_FALSE;
+ }
+
+@@ -3719,7 +4099,10 @@
+ int int_threshold;
+ int x, y;
+ float x_ratio, y_ratio;
+-
++#ifdef HAVE_GD_JPG
++ long ignore_warning;
++#endif
++
+ if (argc != 5 || zend_get_parameters_ex(argc, &f_org, &f_dest, &height, &width, &threshold) == FAILURE) {
+ ZEND_WRONG_PARAM_COUNT();
+ }
+@@ -3775,7 +4158,12 @@
+
+ #ifdef HAVE_GD_JPG
+ case PHP_GDIMG_TYPE_JPG:
++ ignore_warning = INI_INT("gd.jpeg_ignore_warning");
++#ifdef HAVE_GD_BUNDLED
++ im_org = gdImageCreateFromJpeg(org, ignore_warning);
++#else
+ im_org = gdImageCreateFromJpeg(org);
++#endif
+ if (im_org == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid JPEG file", fn_dest);
+ RETURN_FALSE;
+@@ -3886,7 +4274,282 @@
+ /* }}} */
+ #endif /* HAVE_GD_WBMP */
+
++#endif /* HAVE_LIBGD */
++
++/* Section Filters */
+ #ifdef HAVE_GD_BUNDLED
++
++#define PHP_GD_SINGLE_RES \
++ zval **SIM; \
++ gdImagePtr im_src; \
++ if (zend_get_parameters_ex(1, &SIM) == FAILURE) { \
++ RETURN_FALSE; \
++ } \
++ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); \
++ if (im_src == NULL) { \
++ RETURN_FALSE; \
++ }
++
++static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
++{
++ PHP_GD_SINGLE_RES
++
++ if (gdImageNegate(im_src) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
++{
++ PHP_GD_SINGLE_RES
++
++ if (gdImageGrayScale(im_src) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
++{
++ zval *SIM;
++ gdImagePtr im_src;
++ long brightness, tmp;
++
++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &SIM, &tmp, &brightness) == FAILURE) {
++ RETURN_FALSE;
++ }
++
++ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
++
++ if (im_src == NULL) {
++ RETURN_FALSE;
++ }
++
++ if (gdImageBrightness(im_src, (int)brightness) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
++{
++ zval *SIM;
++ gdImagePtr im_src;
++ long contrast, tmp;
++
++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &SIM, &tmp, &contrast) == FAILURE) {
++ RETURN_FALSE;
++ }
++
++ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
++
++ if (im_src == NULL) {
++ RETURN_FALSE;
++ }
++
++ if (gdImageContrast(im_src, (int)contrast) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
++{
++ zval *SIM;
++ gdImagePtr im_src;
++ long r,g,b,tmp;
++ long a = 0;
++
++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &SIM, &tmp, &r, &g, &b, &a) == FAILURE) {
++ RETURN_FALSE;
++ }
++
++ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
++
++ if (im_src == NULL) {
++ RETURN_FALSE;
++ }
++
++ if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS)
++{
++ PHP_GD_SINGLE_RES
++
++ if (gdImageEdgeDetectQuick(im_src) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
++{
++ PHP_GD_SINGLE_RES
++
++ if (gdImageEmboss(im_src) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
++{
++ PHP_GD_SINGLE_RES
++
++ if (gdImageGaussianBlur(im_src) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
++{
++ PHP_GD_SINGLE_RES
++
++ if (gdImageSelectiveBlur(im_src) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
++{
++ PHP_GD_SINGLE_RES
++
++ if (gdImageMeanRemoval(im_src) == 1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
++{
++ zval *SIM;
++ long tmp;
++ gdImagePtr im_src;
++ double weight;
++
++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
++ RETURN_FALSE;
++ }
++
++ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
++
++ if (im_src == NULL) {
++ RETURN_FALSE;
++ }
++
++ if (gdImageSmooth(im_src, (float)weight)==1) {
++ RETURN_TRUE;
++ }
++
++ RETURN_FALSE;
++}
++
++/* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] )
++ Applies Filter an image using a custom angle */
++PHP_FUNCTION(imagefilter)
++{
++ zval *tmp;
++
++ typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS);
++ long filtertype;
++ image_filter filters[] =
++ {
++ php_image_filter_negate ,
++ php_image_filter_grayscale,
++ php_image_filter_brightness,
++ php_image_filter_contrast,
++ php_image_filter_colorize,
++ php_image_filter_edgedetect,
++ php_image_filter_emboss,
++ php_image_filter_gaussian_blur,
++ php_image_filter_selective_blur,
++ php_image_filter_mean_removal,
++ php_image_filter_smooth
++ };
++
++ if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 6) {
++ WRONG_PARAM_COUNT;
++ } else if (zend_parse_parameters(2 TSRMLS_CC, "rl", &tmp, &filtertype) == FAILURE) {
++ return;
++ }
++
++ if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
++ filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
++ }
++}
++/* }}} */
++
++/* {{{ proto resource imageconvolution(resource src_im, array matrix3x3, double div, double offset)
++ Apply a 3x3 convolution matrix, using coefficient div and offset */
++PHP_FUNCTION(imageconvolution)
++{
++ zval *SIM, *hash_matrix;
++ zval **var = NULL, **var2 = NULL;
++ gdImagePtr im_src = NULL;
++ double div, offset;
++ int nelem, i, j, res;
++ float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}};
++
++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "radd", &SIM, &hash_matrix, &div, &offset) == FAILURE) {
++ RETURN_FALSE;
++ }
++
++ ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
++
++ nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
++ if (nelem != 3) {
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
++ RETURN_FALSE;
++ }
++
++ for (i=0; i<3; i++) {
++ if (zend_hash_index_find(Z_ARRVAL_P(hash_matrix), (i), (void **) &var) == SUCCESS && Z_TYPE_PP(var) == IS_ARRAY) {
++ if (Z_TYPE_PP(var) != IS_ARRAY || zend_hash_num_elements(Z_ARRVAL_PP(var)) != 3 ) {
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
++ RETURN_FALSE;
++ }
++
++ for (j=0; j<3; j++) {
++ if (zend_hash_index_find(Z_ARRVAL_PP(var), (j), (void **) &var2) == SUCCESS) {
++ SEPARATE_ZVAL(var2);
++ convert_to_double(*var2);
++ matrix[i][j] = Z_DVAL_PP(var2);
++ } else {
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have a 3x3 matrix");
++ RETURN_FALSE;
++ }
++ }
++ }
++ }
++ res = gdImageConvolution(im_src, matrix, div, offset);
++
++ if (res) {
++ RETURN_TRUE;
++ } else {
++ RETURN_FALSE;
++ }
++}
++/* }}} */
++
++/* End section: Filters */
++
+ /* {{{ proto bool imageantialias(resource im, bool on)
+ Should antialiased functions used or not*/
+ PHP_FUNCTION(imageantialias)
+@@ -3908,8 +4571,6 @@
+ /* }}} */
+ #endif
+
+-#endif /* HAVE_LIBGD */
+-
+ /*
+ * Local variables:
+ * tab-width: 4
+diff -urN php-4.4.8.org/ext/gd/gdcache.c php-4.4.8/ext/gd/gdcache.c
+--- php-4.4.8.org/ext/gd/gdcache.c 2005-01-09 22:05:31.000000000 +0100
++++ php-4.4.8/ext/gd/gdcache.c 2008-01-22 22:38:05.863816915 +0100
+@@ -59,9 +59,9 @@
+ int size,
+ gdCacheTestFn_t gdCacheTest,
+ gdCacheFetchFn_t gdCacheFetch,
+- gdCacheReleaseFn_t gdCacheRelease )
++ gdCacheReleaseFn_t gdCacheRelease )
+ {
+- gdCache_head_t *head;
++ gdCache_head_t *head;
+
+ head = (gdCache_head_t *)pemalloc(sizeof(gdCache_head_t), 1);
+ head->mru = NULL;
+diff -urN php-4.4.8.org/ext/gd/gd_ctx.c php-4.4.8/ext/gd/gd_ctx.c
+--- php-4.4.8.org/ext/gd/gd_ctx.c 2007-12-31 08:22:47.000000000 +0100
++++ php-4.4.8/ext/gd/gd_ctx.c 2008-01-22 22:38:05.863816915 +0100
+@@ -15,11 +15,13 @@
+ | Authors: Stanislav Malyshev <stas@php.net> |
+ +----------------------------------------------------------------------+
+ */
+-#include "php_gd.h"
+
++/* $Id$ */
++
++#include "php_gd.h"
+
+ #define CTX_PUTC(c,ctx) ctx->putC(ctx, c)
+-
++
+ static void _php_image_output_putc(struct gdIOCtx *ctx, int c)
+ {
+ /* without the following downcast, the write will fail
+@@ -43,20 +45,29 @@
+ efree(ctx);
+ }
+ }
+-
+-static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
++
++/* {{{ _php_image_output_ctx */
++static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
+ {
+- zval **imgind, **file, **quality;
++ zval **imgind, **file, **quality, **basefilter;
+ gdImagePtr im;
+ char *fn = NULL;
+ FILE *fp = NULL;
+ int argc = ZEND_NUM_ARGS();
+ int q = -1, i;
++ int f = -1;
+ gdIOCtx *ctx;
+
+- /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
+-
+- if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE)
++ /* The third (quality) parameter for Wbmp stands for the threshold when called from image2wbmp().
++ * The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called
++ * from imagey<type>().
++ */
++
++ if (argc < 2 && image_type == PHP_GDIMG_TYPE_XBM) {
++ WRONG_PARAM_COUNT;
++ }
++
++ if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc, &imgind, &file, &quality, &basefilter) == FAILURE)
+ {
+ WRONG_PARAM_COUNT;
+ }
+@@ -64,20 +75,27 @@
+ ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", phpi_get_le_gd());
+
+ if (argc > 1) {
+- convert_to_string_ex(file);
++ if (argc >= 2 && Z_TYPE_PP(file) != IS_NULL) {
++ convert_to_string_ex(file);
++ }
+ fn = Z_STRVAL_PP(file);
+- if (argc == 3) {
++ if (argc >= 3) {
+ convert_to_long_ex(quality);
+- q = Z_LVAL_PP(quality);
++ q = Z_LVAL_PP(quality);/* or colorindex for foreground of BW images (defaults to black) */
++ if (argc == 4) {
++ convert_to_long_ex(basefilter);
++ f = Z_LVAL_PP(basefilter);
++ }
+ }
+ }
+
+- if ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))) {
++ if (argc > 1 && (Z_TYPE_PP(file) != IS_NULL && ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))))) {
++
+ PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
+
+ fp = VCWD_FOPEN(fn, "wb");
+ if (!fp) {
+- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn);
++ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing: %s", fn, strerror(errno));
+ RETURN_FALSE;
+ }
+
+@@ -90,7 +108,7 @@
+ ctx->gd_free = _php_image_output_ctxfree;
+ #else
+ ctx->free = _php_image_output_ctxfree;
+-#endif
++#endif
+
+ #if APACHE && defined(CHARSET_EBCDIC)
+ /* XXX this is unlikely to work any more thies@thieso.net */
+@@ -107,27 +125,48 @@
+ case PHP_GDIMG_TYPE_JPG:
+ (*func_p)(im, ctx, q);
+ break;
++ case PHP_GDIMG_TYPE_PNG:
++ (*func_p)(im, ctx, q, f);
++ break;
++ case PHP_GDIMG_TYPE_XBM:
+ case PHP_GDIMG_TYPE_WBM:
+- for(i=0; i < gdImageColorsTotal(im); i++) {
+- if(gdImageRed(im, i) == 0) break;
+- }
+- (*func_p)(im, i, ctx);
++ if (argc < 3) {
++ for(i=0; i < gdImageColorsTotal(im); i++) {
++ if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
++ }
++ q = i;
++ }
++ if (image_type == PHP_GDIMG_TYPE_XBM) {
++ (*func_p)(im, fn, q, ctx);
++ } else {
++ (*func_p)(im, q, ctx);
++ }
+ break;
+ default:
+ (*func_p)(im, ctx);
+ break;
+ }
+
+-#if HAVE_LIBGD204
++#if HAVE_LIBGD204
+ ctx->gd_free(ctx);
+ #else
+ ctx->free(ctx);
+-#endif
++#endif
+
+ if(fp) {
+ fflush(fp);
+ fclose(fp);
+ }
+-
++
+ RETURN_TRUE;
+ }
++/* }}} */
++
++/*
++ * Local variables:
++ * tab-width: 4
++ * c-basic-offset: 4
++ * End:
++ * vim600: sw=4 ts=4 fdm=marker
++ * vim<600: sw=4 ts=4
++ */
+diff -urN php-4.4.8.org/ext/gd/gdttf.c php-4.4.8/ext/gd/gdttf.c
+--- php-4.4.8.org/ext/gd/gdttf.c 2005-01-09 22:05:31.000000000 +0100
++++ php-4.4.8/ext/gd/gdttf.c 2008-01-22 22:38:05.887151436 +0100
+@@ -42,15 +42,15 @@
+ /* ptsize below which anti-aliasing is ineffective */
+ #define MINANTIALIASPTSIZE 0
+
+-/* display resolution - (Not really. This has to be 72 or hinting is wrong) */
++/* display resolution - (Not really. This has to be 72 or hinting is wrong) */
+ #define RESOLUTION 72
+
+ /* Number of colors used for anti-aliasing */
+ #undef NUMCOLORS
+ #define NUMCOLORS 4
+
+-/* Line separation as a factor of font height.
+- No space between if LINESPACE = 1.00
++/* Line separation as a factor of font height.
++ No space between if LINESPACE = 1.00
+ Line separation will be rounded up to next pixel row*/
+ #define LINESPACE 1.05
+
+@@ -125,7 +125,7 @@
+ glyph_t *glyph;
+ } bitmapkey_t;
+
+-typedef struct {
++typedef struct {
+ unsigned char pixel; /* key */
+ unsigned char bgcolor; /* key */
+ int fgcolor; /* key */ /* -ve means no antialias */
+@@ -138,7 +138,7 @@
+ unsigned char bgcolor; /* key */
+ int fgcolor; /* key */ /* -ve means no antialias */
+ gdImagePtr im; /* key */
+-} tweencolorkey_t;
++} tweencolorkey_t;
+
+ /* forward declarations so that glyphCache can be initialized by font code */
+ static int glyphTest ( void *element, void *key );
+@@ -196,7 +196,7 @@
+ *
+ *---------------------------------------------------------------------------
+ */
+-
++
+ #ifndef CHARSET_EBCDIC
+ #define ASC(ch) (ch)
+ #else /*CHARSET_EBCDIC*/
+@@ -205,17 +205,16 @@
+
+ #define Tcl_UniChar int
+ #define TCL_UTF_MAX 3
+-static int
+-gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr)
++static int gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr)
+ /* str is the UTF8 next character pointer */
+ /* chPtr is the int for the result */
+ {
+- int byte;
+-
++ int byte;
++
+ /* HTML4.0 entities in decimal form, e.g. Å */
+- byte = *((unsigned char *) str);
++ byte = *((unsigned char *) str);
+ if (byte == '&') {
+- int i, n=0;
++ int i, n = 0;
+
+ byte = *((unsigned char *) (str+1));
+ if (byte == '#') {
+@@ -223,9 +222,9 @@
+ byte = *((unsigned char *) (str+i));
+ if (byte >= '0' && byte <= '9') {
+ n = (n * 10) + (byte - '0');
+- }
+- else
++ } else {
+ break;
++ }
+ }
+ if (byte == ';') {
+ *chPtr = (Tcl_UniChar) n;
+@@ -233,105 +232,91 @@
+ }
+ }
+ }
+-
+- /*
+- * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones.
+- */
+-
+- byte = ASC(*((unsigned char *) str));
+- if (byte < 0xC0) {
+- /*
+- * Handles properly formed UTF-8 characters between 0x01 and 0x7F.
+- * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
+- * characters representing themselves.
+- */
+
+- *chPtr = (Tcl_UniChar) byte;
+- return 1;
+- } else if (byte < 0xE0) {
+- if ((ASC(str[1]) & 0xC0) == 0x80) {
+- /*
+- * Two-byte-character lead-byte followed by a trail-byte.
+- */
+-
+- *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F));
+- return 2;
+- }
+- /*
+- * A two-byte-character lead-byte not followed by trail-byte
+- * represents itself.
+- */
+-
+- *chPtr = (Tcl_UniChar) byte;
+- return 1;
+- } else if (byte < 0xF0) {
+- if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) {
+- /*
+- * Three-byte-character lead byte followed by two trail bytes.
+- */
+-
+- *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12)
+- | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F));
+- return 3;
+- }
+- /*
+- * A three-byte-character lead-byte not followed by two trail-bytes
+- * represents itself.
+- */
++ /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */
+
+- *chPtr = (Tcl_UniChar) byte;
+- return 1;
+- }
++ byte = ASC(*((unsigned char *) str));
++ if (byte < 0xC0) {
++ /*
++ * Handles properly formed UTF-8 characters between 0x01 and 0x7F.
++ * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
++ * characters representing themselves.
++ */
++
++ *chPtr = (Tcl_UniChar) byte;
++ return 1;
++ } else if (byte < 0xE0) {
++ if ((ASC(str[1]) & 0xC0) == 0x80) {
++ /* Two-byte-character lead-byte followed by a trail-byte. */
++
++ *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F));
++ return 2;
++ }
++ /*
++ * A two-byte-character lead-byte not followed by trail-byte
++ * represents itself.
++ */
++
++ *chPtr = (Tcl_UniChar) byte;
++ return 1;
++ } else if (byte < 0xF0) {
++ if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) {
++ /* Three-byte-character lead byte followed by two trail bytes. */
++
++ *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F));
++ return 3;
++ }
++ /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */
++
++ *chPtr = (Tcl_UniChar) byte;
++ return 1;
++ }
+ #if TCL_UTF_MAX > 3
+- else {
+- int ch, total, trail;
++ else {
++ int ch, total, trail;
+
+- total = totalBytes[byte];
+- trail = total - 1;
+- if (trail > 0) {
+- ch = byte & (0x3F >> trail);
+- do {
+- str++;
+- if ((ASC(*str) & 0xC0) != 0x80) {
+- *chPtr = byte;
+- return 1;
+- }
+- ch <<= 6;
+- ch |= (ASC(*str) & 0x3F);
+- trail--;
+- } while (trail > 0);
+- *chPtr = ch;
+- return total;
++ total = totalBytes[byte];
++ trail = total - 1;
++ if (trail > 0) {
++ ch = byte & (0x3F >> trail);
++ do {
++ str++;
++ if ((ASC(*str) & 0xC0) != 0x80) {
++ *chPtr = byte;
++ return 1;
++ }
++ ch <<= 6;
++ ch |= (ASC(*str) & 0x3F);
++ trail--;
++ } while (trail > 0);
++ *chPtr = ch;
++ return total;
++ }
+ }
+- }
+ #endif
+
+- *chPtr = (Tcl_UniChar) byte;
+- return 1;
++ *chPtr = (Tcl_UniChar) byte;
++ return 1;
+ }
+
+ /********************************************************************/
+ /* font cache functions */
+
+-static int
+-fontTest ( void *element, void *key )
++static int fontTest ( void *element, void *key )
+ {
+- font_t *a=(font_t *)element;
+- fontkey_t *b=(fontkey_t *)key;
++ font_t *a = (font_t *)element;
++ fontkey_t *b = (fontkey_t *)key;
+
+- return ( strcmp(a->fontname, b->fontname) == 0
+- && a->ptsize == b->ptsize
+- && a->angle == b->angle);
++ return (strcmp(a->fontname, b->fontname) == 0 && a->ptsize == b->ptsize && a->angle == b->angle);
+ }
+
+-static void *
+-fontFetch ( char **error, void *key )
++static void * fontFetch ( char **error, void *key )
+ {
+- TT_Error err;
+- font_t *a;
+- fontkey_t *b=(fontkey_t *)key;
+- int i, n, map_found;
+- short platform, encoding;
++ TT_Error err;
++ font_t *a;
++ fontkey_t *b = (fontkey_t *)key;
++ int i, n, map_found;
++ short platform, encoding;
+ TSRMLS_FETCH();
+
+ a = (font_t *)pemalloc(sizeof(font_t), 1);
+@@ -354,8 +339,7 @@
+ if ((err = TT_Open_Face(*b->engine, a->fontname, &a->face))) {
+ if (err == TT_Err_Could_Not_Open_File) {
+ *error = "Could not find/open font";
+- }
+- else {
++ } else {
+ *error = "Could not read font";
+ }
+ pefree(a, 1);
+@@ -370,7 +354,7 @@
+ pefree(a, 1);
+ return NULL;
+ }
+-
++
+ if (TT_Set_Instance_Resolutions(a->instance, RESOLUTION, RESOLUTION)) {
+ *error = "Could not set device resolutions";
+ pefree(a, 1);
+@@ -384,12 +368,12 @@
+ }
+
+ TT_Get_Instance_Metrics(a->instance, &a->imetrics);
+-
++
+ /* First, look for a Unicode charmap */
+ n = TT_Get_CharMap_Count(a->face);
+
+ for (i = 0; i < n; i++) {
+- TT_Get_CharMap_ID(a->face, i, &platform, &encoding);
++ TT_Get_CharMap_ID(a->face, i, &platform, &encoding);
+ if ((platform == 3 && encoding == 1) /* Windows Unicode */
+ || (platform == 2 && encoding == 1)
+ || (platform == 0)) { /* ?? Unicode */
+@@ -407,7 +391,7 @@
+ }
+ }
+
+- if (! map_found) {
++ if (!map_found) {
+ *error = "Unable to find a CharMap that I can handle";
+ pefree(a, 1);
+ return NULL;
+@@ -418,16 +402,14 @@
+ a->matrix.xy = - a->matrix.yx;
+ a->matrix.yy = a->matrix.xx;
+
+- a->glyphCache = gdCacheCreate( GLYPHCACHESIZE,
+- glyphTest, glyphFetch, glyphRelease);
++ a->glyphCache = gdCacheCreate(GLYPHCACHESIZE, glyphTest, glyphFetch, glyphRelease);
+
+ return (void *)a;
+ }
+
+-static void
+-fontRelease( void *element )
++static void fontRelease( void *element )
+ {
+- font_t *a=(font_t *)element;
++ font_t *a = (font_t *)element;
+
+ gdCacheDelete(a->glyphCache);
+ TT_Done_Instance(a->instance);
+@@ -439,26 +421,22 @@
+ /********************************************************************/
+ /* glyph cache functions */
+
+-static int
+-glyphTest ( void *element, void *key )
++static int glyphTest ( void *element, void *key )
+ {
+- glyph_t *a=(glyph_t *)element;
+- glyphkey_t *b=(glyphkey_t *)key;
++ glyph_t *a = (glyph_t *)element;
++ glyphkey_t *b = (glyphkey_t *)key;
++
++ return (a->character == b->character && a->hinting == b->hinting && a->gray_render == b->gray_render);
++}
+
+- return (a->character == b->character
+- && a->hinting == b->hinting
+- && a->gray_render == b->gray_render);
+-}
+-
+-static void *
+-glyphFetch ( char **error, void *key )
+-{
+- glyph_t *a;
+- glyphkey_t *b=(glyphkey_t *)key;
+- short glyph_code;
+- int flags, err;
+- int crect[8], xmin, xmax, ymin, ymax;
+- double cos_a, sin_a;
++static void * glyphFetch ( char **error, void *key )
++{
++ glyph_t *a;
++ glyphkey_t *b = (glyphkey_t *)key;
++ short glyph_code;
++ int flags, err;
++ int crect[8], xmin, xmax, ymin, ymax;
++ double cos_a, sin_a;
+
+ a = (glyph_t *)pemalloc(sizeof(glyph_t), 1);
+ a->character = b->character;
+@@ -523,38 +501,34 @@
+ a->Bit.flow = TT_Flow_Up;
+ if (a->gray_render) {
+ a->Bit.cols = a->Bit.width; /* 1 byte per pixel */
+- }
+- else {
++ } else {
+ a->Bit.cols = (a->Bit.width + 7) / 8; /* 1 bit per pixel */
+ }
+ a->Bit.cols = (a->Bit.cols + 3) & ~3; /* pad to 32 bits */
+ a->Bit.size = a->Bit.rows * a->Bit.cols; /* # of bytes in buffer */
+ a->Bit.bitmap = NULL;
+
+- a->bitmapCache = gdCacheCreate( BITMAPCACHESIZE,
+- bitmapTest, bitmapFetch, bitmapRelease);
++ a->bitmapCache = gdCacheCreate(BITMAPCACHESIZE, bitmapTest, bitmapFetch, bitmapRelease);
+
+ return (void *)a;
}
- /* }}} */
-@@ -344,6 +347,9 @@
+
+-static void
+-glyphRelease( void *element )
++static void glyphRelease( void *element )
{
- le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
- le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
-+#if HAVE_GD_FONTMUTEX
-+ gdFontCacheMutexSetup();
-+#endif
- #if HAVE_LIBT1
- T1_SetBitmapPad(8);
- T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
-@@ -1146,7 +1152,7 @@
+- glyph_t *a=(glyph_t *)element;
++ glyph_t *a = (glyph_t *)element;
+
+ gdCacheDelete(a->bitmapCache);
+- TT_Done_Glyph( a->glyph );
+- pefree ((char *)element, 1);
++ TT_Done_Glyph(a->glyph);
++ pefree((char *)element, 1);
+ }
- convert_to_double_ex(ANGLE);
- degrees = Z_DVAL_PP(ANGLE);
-- im_dst = gdImageRotate(im_src, degrees, color);
-+ im_dst = gdImageRotate(im_src, degrees, color, 0);
+ /********************************************************************/
+ /* bitmap cache functions */
- if (im_dst != NULL) {
- ZEND_REGISTER_RESOURCE(return_value, im_dst, le_gd);
-@@ -3775,7 +3781,11 @@
+-static int
+-bitmapTest ( void *element, void *key )
++static int bitmapTest ( void *element, void *key )
+ {
+- bitmap_t *a=(bitmap_t *)element;
+- bitmapkey_t *b=(bitmapkey_t *)key;
++ bitmap_t *a = (bitmap_t *)element;
++ bitmapkey_t *b = (bitmapkey_t *)key;
+
+ if (a->xoffset == b->xoffset && a->yoffset == b->yoffset) {
+ b->glyph->Bit.bitmap = a->bitmap;
+@@ -563,11 +537,10 @@
+ return FALSE;
+ }
- #ifdef HAVE_GD_JPG
- case PHP_GDIMG_TYPE_JPG:
-+#ifdef HAVE_GD_BUNDLED
-+ im_org = gdImageCreateFromJpeg(org, 0);
-+#else
- im_org = gdImageCreateFromJpeg(org);
-+#endif
- if (im_org == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid JPEG file", fn_dest);
- RETURN_FALSE;
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_arc_f_buggy.c php-4.4.7/ext/gd/libgd/gd_arc_f_buggy.c
---- php-4.4.7.org/ext/gd/libgd/gd_arc_f_buggy.c 2003-03-05 17:04:20.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/gd_arc_f_buggy.c 2005-08-18 14:54:43.000000000 +0200
-@@ -1,6 +1,6 @@
- /* This is potentially great stuff, but fails against the test
-- program at the end. This would probably be much more
-- efficent than the implementation currently in gd.c if the
-+ program at the end. This would probably be much more
-+ efficent than the implementation currently in gd.c if the
- errors in the output were corrected. TBB */
+-static void *
+-bitmapFetch ( char **error, void *key )
++static void * bitmapFetch ( char **error, void *key )
+ {
+- bitmap_t *a;
+- bitmapkey_t *b=(bitmapkey_t *)key;
++ bitmap_t *a;
++ bitmapkey_t *b = (bitmapkey_t *)key;
+
+ a = (bitmap_t *)pemalloc(sizeof(bitmap_t), 1);
+ a->xoffset = b->xoffset;
+@@ -577,56 +550,47 @@
+ memset(a->bitmap, 0, b->glyph->Bit.size);
+ /* render glyph */
+ if (b->glyph->gray_render) {
+- TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit,
+- a->xoffset, a->yoffset);
+- }
+- else {
+- TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit,
+- a->xoffset, a->yoffset);
++ TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset);
++ } else {
++ TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset);
+ }
+ return (void *)a;
+ }
- #if 0
+-static void
+-bitmapRelease( void *element )
++static void bitmapRelease( void *element )
+ {
+- bitmap_t *a=(bitmap_t *)element;
++ bitmap_t *a = (bitmap_t *)element;
+
+- pefree (a->bitmap, 1);
+- pefree ((char *)element, 1);
++ pefree(a->bitmap, 1);
++ pefree((char *)element, 1);
+ }
+
+ /********************************************************************/
+ /* tweencolor cache functions */
+
+-static int
+-tweenColorTest (void *element, void *key)
+-{
+- tweencolor_t *a=(tweencolor_t *)element;
+- tweencolorkey_t *b=(tweencolorkey_t *)key;
+-
+- return (a->pixel == b->pixel
+- && a->bgcolor == b->bgcolor
+- && a->fgcolor == b->fgcolor
+- && a->im == b->im);
+-}
++static int tweenColorTest (void *element, void *key)
++{
++ tweencolor_t *a = (tweencolor_t *)element;
++ tweencolorkey_t *b = (tweencolorkey_t *)key;
++
++ return (a->pixel == b->pixel && a->bgcolor == b->bgcolor && a->fgcolor == b->fgcolor && a->im == b->im);
++}
+
+-static void *
+-tweenColorFetch (char **error, void *key)
++static void * tweenColorFetch (char **error, void *key)
+ {
+- tweencolor_t *a;
+- tweencolorkey_t *b=(tweencolorkey_t *)key;
++ tweencolor_t *a;
++ tweencolorkey_t *b = (tweencolorkey_t *)key;
+ int pixel, npixel, bg, fg;
+ gdImagePtr im;
+-
+- a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1);
++
++ a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1);
+ pixel = a->pixel = b->pixel;
+ bg = a->bgcolor = b->bgcolor;
+ fg = a->fgcolor = b->fgcolor;
+ im = b->im;
+
+ /* if fg is specified by a negative color idx, then don't antialias */
+- if (fg <0) {
++ if (fg < 0) {
+ a->tweencolor = -fg;
+ } else {
+ npixel = NUMCOLORS - pixel;
+@@ -635,20 +599,19 @@
+ (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS,
+ (pixel * im->blue [fg] + npixel * im->blue [bg]) / NUMCOLORS);
+ }
+- *error = NULL;
+- return (void *)a;
+-}
+-
+-static void
+-tweenColorRelease(void *element)
+-{
+- pefree((char *)element, 1);
+-}
++ *error = NULL;
++ return (void *)a;
++}
++
++static void tweenColorRelease(void *element)
++{
++ pefree((char *)element, 1);
++}
+
+ /********************************************************************/
+ /* gdttfchar - render one character onto a gd image */
+
+-static int OneTime=0;
++static int OneTime = 0;
+ static gdCache_head_t *tweenColorCache;
+
+ char *
+@@ -656,38 +619,37 @@
+ int x, int y, /* string start pos in pixels */
+ TT_F26Dot6 x1, TT_F26Dot6 y1, /* char start offset (*64) from x,y */
+ TT_F26Dot6 *advance,
+- TT_BBox **bbox,
++ TT_BBox **bbox,
+ char **next)
+ {
+- int pc, ch, len;
++ int pc, ch, len;
+ int row, col;
+- int x2, y2; /* char start pos in pixels */
++ int x2, y2; /* char start pos in pixels */
+ int x3, y3; /* current pixel pos */
+ unsigned char *pixel;
+
+- glyph_t *glyph;
+- glyphkey_t glyphkey;
+- bitmapkey_t bitmapkey;
++ glyph_t *glyph;
++ glyphkey_t glyphkey;
++ bitmapkey_t bitmapkey;
+ tweencolor_t *tweencolor;
+ tweencolorkey_t tweencolorkey;
+
+ /****** set up tweenColorCache on first call ************/
+- if (! OneTime) {
+- tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE,
+- tweenColorTest, tweenColorFetch, tweenColorRelease);
++ if (!OneTime) {
++ tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE, tweenColorTest, tweenColorFetch, tweenColorRelease);
+ OneTime++;
+ }
+ /**************/
+
+ if (font->have_char_map_Unicode) { /* use UTF-8 mapping from ASCII */
+- len = gdTcl_UtfToUniChar(*next, &ch);
+- *next += len;
++ len = gdTcl_UtfToUniChar(*next, &ch);
++ *next += len;
+ } else {
+- /*
+- * Big 5 mapping:
+- * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref:
+- * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs
+- */
++ /*
++ * Big 5 mapping:
++ * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref:
++ * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs
++ */
+ ch = (**next) & 255; /* don't extend sign */
+ (*next)++;
+ if (ch >= 161 /* first code of JIS-8 pair */
+@@ -700,18 +662,20 @@
+ glyphkey.character = ch;
+ glyphkey.hinting = 1;
+ /* if fg is specified by a negative color idx, then don't antialias */
+- glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg <0))?FALSE:TRUE;
+- glyphkey.font = font;
+- glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey);
+- if (! glyph)
++ glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg < 0)) ? FALSE : TRUE;
++ glyphkey.font = font;
++ glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey);
++ if (!glyph) {
+ return font->glyphCache->error;
++ }
+
+ *bbox = &glyph->metrics.bbox;
+ *advance = glyph->metrics.advance;
+
+ /* if null *im, or invalid color, then assume user just wants brect */
+- if (!im || fg > 255 || fg < -255)
++ if (!im || fg > 255 || fg < -255) {
+ return (char *)NULL;
++ }
+
+ /* render (via cache) a bitmap for the current fractional offset */
+ bitmapkey.xoffset = ((x1+32) & 63) - 32 - ((glyph->xmin+32) & -64);
+@@ -720,30 +684,32 @@
+ gdCacheGet(glyph->bitmapCache, &bitmapkey);
+
+ /* copy to gif, mapping colors */
+- x2 = x + (((glyph->xmin+32) & -64) + ((x1+32) & -64)) / 64;
+- y2 = y - (((glyph->ymin+32) & -64) + ((y1+32) & -64)) / 64;
++ x2 = x + (((glyph->xmin+32) & -64) + ((x1+32) & -64)) / 64;
++ y2 = y - (((glyph->ymin+32) & -64) + ((y1+32) & -64)) / 64;
+ tweencolorkey.fgcolor = fg;
+ tweencolorkey.im = im;
+ for (row = 0; row < glyph->Bit.rows; row++) {
+- if (glyph->gray_render)
++ if (glyph->gray_render) {
+ pc = row * glyph->Bit.cols;
+- else
++ } else {
+ pc = row * glyph->Bit.cols * 8;
++ }
+ y3 = y2 - row;
+- if (y3 >= im->sy || y3 < 0) continue;
++ if (y3 >= im->sy || y3 < 0) {
++ continue;
++ }
+ for (col = 0; col < glyph->Bit.width; col++, pc++) {
+ if (glyph->gray_render) {
+- tweencolorkey.pixel =
+- *((unsigned char *)(glyph->Bit.bitmap) + pc);
++ tweencolorkey.pixel = *((unsigned char *)(glyph->Bit.bitmap) + pc);
+ } else {
+- tweencolorkey.pixel =
+- (((*((unsigned char *)(glyph->Bit.bitmap) + pc/8))
+- <<(pc%8))&128)?4:0;
++ tweencolorkey.pixel = (((*((unsigned char *)(glyph->Bit.bitmap) + pc/8)) << (pc%8))&128)?4:0;
+ }
+ /* if not background */
+ if (tweencolorkey.pixel > 0) {
+ x3 = x2 + col;
+- if (x3 >= im->sx || x3 < 0) continue;
++ if (x3 >= im->sx || x3 < 0) {
++ continue;
++ }
+ #if HAVE_LIBGD20
+ if (im->trueColor) {
+ pixel = &im->tpixels[y3][x3];
+@@ -757,8 +723,7 @@
+ #endif
+ }
+ tweencolorkey.bgcolor = *pixel;
+- tweencolor = (tweencolor_t *)gdCacheGet(
+- tweenColorCache, &tweencolorkey);
++ tweencolor = (tweencolor_t *)gdCacheGet(tweenColorCache, &tweencolorkey);
+ *pixel = tweencolor->tweencolor;
+ }
+ }
+@@ -769,29 +734,26 @@
+ /********************************************************************/
+ /* gdttf - render a utf8 string onto a gd image */
+
+-char *
+-gdttf(gdImage *im, int *brect, int fg, char *fontname,
+- double ptsize, double angle, int x, int y, char *str)
++char * gdttf(gdImage *im, int *brect, int fg, char *fontname, double ptsize, double angle, int x, int y, char *str)
+ {
+- TT_F26Dot6 ur_x=0, ur_y=0, ll_x=0, ll_y=0;
++ TT_F26Dot6 ur_x = 0, ur_y = 0, ll_x = 0, ll_y = 0;
+ TT_F26Dot6 advance_x, advance_y, advance, x1, y1;
+ TT_BBox *bbox;
+ double sin_a, cos_a;
+- int i=0, ch;
++ int i=0, ch;
+ font_t *font;
+ fontkey_t fontkey;
+ char *error, *next;
+
+ /****** initialize font engine on first call ************/
+- static gdCache_head_t *fontCache;
++ static gdCache_head_t *fontCache;
+ static TT_Engine engine;
+
+- if (! fontCache) {
++ if (!fontCache) {
+ if (TT_Init_FreeType(&engine)) {
+ return "Failure to initialize font engine";
+ }
+- fontCache = gdCacheCreate( FONTCACHESIZE,
+- fontTest, fontFetch, fontRelease);
++ fontCache = gdCacheCreate(FONTCACHESIZE, fontTest, fontFetch, fontRelease);
+ }
+ /**************/
+
+@@ -801,15 +763,15 @@
+ fontkey.angle = angle;
+ fontkey.engine = &engine;
+ font = (font_t *)gdCacheGet(fontCache, &fontkey);
+- if (! font) {
++ if (!font) {
+ return fontCache->error;
+ }
+ sin_a = font->sin_a;
+ cos_a = font->cos_a;
+ advance_x = advance_y = 0;
+
+- next=str;
+- while (*next) {
++ next = str;
++ while (*next) {
+ ch = *next;
+
+ /* carriage returns */
+@@ -820,8 +782,8 @@
+ }
+ /* newlines */
+ if (ch == '\n') {
+- advance_y -= (TT_F26Dot6)(font->imetrics.y_ppem * LINESPACE * 64);
+- advance_y = (advance_y-32) & -64; /* round to next pixel row */
++ advance_y -= (TT_F26Dot6)(font->imetrics.y_ppem * LINESPACE * 64);
++ advance_y = (advance_y-32) & -64; /* round to next pixel row */
+ next++;
+ continue;
+ }
+@@ -829,20 +791,24 @@
+ x1 = (TT_F26Dot6)(advance_x * cos_a - advance_y * sin_a);
+ y1 = (TT_F26Dot6)(advance_x * sin_a + advance_y * cos_a);
+
+- if ((error=gdttfchar(im, fg, font, x, y, x1, y1, &advance, &bbox, &next)))
++ if ((error = gdttfchar(im, fg, font, x, y, x1, y1, &advance, &bbox, &next))) {
+ return error;
++ }
+
+- if (! i++) { /* if first character, init BB corner values */
++ if (!i++) { /* if first character, init BB corner values */
+ ll_x = bbox->xMin;
+ ll_y = bbox->yMin;
+ ur_x = bbox->xMax;
+ ur_y = bbox->yMax;
+- }
+- else {
+- if (! advance_x) ll_x = MIN(bbox->xMin, ll_x);
++ } else {
++ if (!advance_x) {
++ ll_x = MIN(bbox->xMin, ll_x);
++ }
+ ll_y = MIN(advance_y + bbox->yMin, ll_y);
+ ur_x = MAX(advance_x + bbox->xMax, ur_x);
+- if (! advance_y) ur_y = MAX(bbox->yMax, ur_y);
++ if (!advance_y) {
++ ur_y = MAX(bbox->yMax, ur_y);
++ }
+ }
+ advance_x += advance;
+ }
+@@ -859,7 +825,7 @@
+
+ /* scale, round and offset brect */
+ i = 0;
+- while (i<8) {
++ while (i < 8) {
+ brect[i] = x + (brect[i] + 32) / 64;
+ i++;
+ brect[i] = y - (brect[i] + 32) / 64;
+@@ -868,7 +834,7 @@
+
+ return (char *)NULL;
+ }
+-
++
+ #endif /* HAVE_LIBTTF */
+
+ /*
+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
+--- php-4.4.8.org/ext/gd/libgd/gd_arc_f_buggy.c 2003-03-05 17:04:20.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/gd_arc_f_buggy.c 2005-08-18 14:54:43.000000000 +0200
@@ -698,7 +698,7 @@
#define WIDTH 500
#define HEIGHT 300
/* Destroy it */
gdImageDestroy (im);
-diff -urN php-4.4.7.org/ext/gd/libgd/gd.c php-4.4.7/ext/gd/libgd/gd.c
---- php-4.4.7.org/ext/gd/libgd/gd.c 2007-04-14 19:38:38.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd.c 2007-04-14 19:33:15.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gd.c php-4.4.8/ext/gd/libgd/gd.c
+--- php-4.4.8.org/ext/gd/libgd/gd.c 2007-10-20 17:29:04.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd.c 2007-11-05 00:56:00.000000000 +0100
@@ -1,4 +1,4 @@
-#include <stdio.h>
+
va_start(args, format);
php_verror(NULL, "", E_WARNING, format, args TSRMLS_CC);
va_end(args);
-@@ -125,8 +123,8 @@
- im = (gdImage *) gdMalloc(sizeof(gdImage));
- memset(im, 0, sizeof(gdImage));
+@@ -122,11 +120,20 @@
+ {
+ int i;
+ gdImagePtr im;
+- im = (gdImage *) gdMalloc(sizeof(gdImage));
+- memset(im, 0, sizeof(gdImage));
++
++ if (overflow2(sx, sy)) {
++ return NULL;
++ }
++
++ if (overflow2(sizeof(unsigned char *), sy)) {
++ return NULL;
++ }
++
++ im = (gdImage *) gdCalloc(1, sizeof(gdImage));
++
/* Row-major ever since gd 1.3 */
- im->pixels = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0);
- im->AA_opacity = (unsigned char **) safe_emalloc(sizeof(unsigned char *), sy, 0);
im->polyInts = 0;
im->polyAllocated = 0;
im->brush = 0;
-@@ -166,8 +164,8 @@
+@@ -164,10 +171,23 @@
+ {
+ int i;
gdImagePtr im;
++
++ if (overflow2(sx, sy)) {
++ return NULL;
++ }
++
++ if (overflow2(sizeof(unsigned char *), sy)) {
++ return NULL;
++ }
++
++ if (overflow2(sizeof(int), sx)) {
++ return NULL;
++ }
++
im = (gdImage *) gdMalloc(sizeof(gdImage));
memset(im, 0, sizeof(gdImage));
- im->tpixels = (int **) safe_emalloc(sizeof(int *), sy, 0);
im->polyInts = 0;
im->polyAllocated = 0;
im->brush = 0;
-@@ -267,8 +265,8 @@
- }
-
- /* This code is taken from http://www.acm.org/jgt/papers/SmithLyons96/hwb_rgb.html, an article
-- * on colour conversion to/from RBG and HWB colour systems.
-- * It has been modified to return the converted value as a * parameter.
-+ * on colour conversion to/from RBG and HWB colour systems.
-+ * It has been modified to return the converted value as a * parameter.
- */
-
- #define RETURN_HWB(h, w, b) {HWB->H = h; HWB->W = w; HWB->B = b; return HWB;}
-@@ -287,8 +285,8 @@
-
-
- /*
-- * Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. Pure
-- * red always maps to 6 in this implementation. Therefore UNDEFINED can be
-+ * Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. Pure
-+ * red always maps to 6 in this implementation. Therefore UNDEFINED can be
- * defined as 0 in situations where only unsigned numbers are desired.
- */
- typedef struct
-@@ -305,8 +303,8 @@
+@@ -305,8 +325,8 @@
static HWBType * RGB_to_HWB (RGBType RGB, HWBType * HWB)
{
/*
*/
float R = RGB.R, G = RGB.G, B = RGB.B, w, v, b, f;
-@@ -320,7 +318,7 @@
+@@ -320,7 +340,7 @@
}
f = (R == w) ? G - B : ((G == w) ? B - R : R - G);
i = (R == w) ? 3 : ((G == w) ? 5 : 1);
RETURN_HWB(i - f / (v - w), w, b);
}
-@@ -363,9 +361,9 @@
+@@ -363,9 +383,9 @@
*/
static RGBType * HWB_to_RGB (HWBType HWB, RGBType * RGB)
{
*/
float h = HWB.H, w = HWB.W, b = HWB.B, v, n, f;
-@@ -478,7 +476,7 @@
+@@ -478,7 +498,7 @@
im->blue[ct] = b;
im->alpha[ct] = a;
im->open[ct] = 0;
return ct;
}
-@@ -629,7 +627,7 @@
- * Given the end points of a line, and a bounding rectangle (which we
- * know to be from (0,0) to (SX,SY)), adjust the endpoints to be on
- * the edges of the rectangle if the line should be drawn at all,
-- * otherwise return a failure code
-+ * otherwise return a failure code
- */
-
- /* this does "one-dimensional" clipping: note that the second time it
-@@ -637,7 +635,7 @@
- * - the comments ignore this (if you can understand it when it's
- * looking at the X parameters, it should become clear what happens on
- * the second call!) The code is simplified from that in the article,
-- * as we know that gd images always start at (0,0)
-+ * as we know that gd images always start at (0,0)
- */
-
- static int clip_1d(int *x0, int *y0, int *x1, int *y1, int maxdim) {
-@@ -664,7 +662,7 @@
+@@ -664,7 +684,7 @@
}
m = (*y1 - *y0)/(double)(*x1 - *x0); /* calculate the slope of the line */
*y0 += (int)(m * (maxdim - *x0)); /* adjust so point is on the right boundary */
/* now, perhaps, adjust the end of the line */
if (*x1 < 0) {
*y1 -= (int)(m * *x1);
-@@ -737,7 +735,7 @@
+@@ -737,7 +757,7 @@
im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color);
break;
case gdEffectNormal:
break;
case gdEffectOverlay :
im->tpixels[y][x] = gdLayerOverlay(im->tpixels[y][x], color);
-@@ -756,7 +754,7 @@
+@@ -756,7 +776,7 @@
int p = gdImageGetPixel(im, x, y);
if (!im->trueColor) {
} else {
return p;
}
-@@ -780,7 +778,7 @@
+@@ -780,7 +800,7 @@
x1 = x - hx;
x2 = x1 + gdImageSX(im->brush);
srcy = 0;
if (im->trueColor) {
if (im->brush->trueColor) {
for (ly = y1; ly < y2; ly++) {
-@@ -823,8 +821,8 @@
+@@ -823,8 +843,8 @@
if (p != gdImageGetTransparent(im->brush)) {
/* Truecolor brush. Very slow on a palette destination. */
if (im->brush->trueColor) {
gdTrueColorGetBlue(p),
gdTrueColorGetAlpha(p)));
} else {
-@@ -849,7 +847,9 @@
+@@ -849,7 +869,9 @@
srcy = y % gdImageSY(im->tile);
if (im->trueColor) {
p = gdImageGetTrueColorPixel(im->tile, srcx, srcy);
} else {
p = gdImageGetPixel(im->tile, srcx, srcy);
/* Allow for transparency */
-@@ -903,8 +903,8 @@
+@@ -903,8 +925,8 @@
float p_dist, p_alpha;
unsigned char opacity;
* segment AB that is being drawn. (Adapted from an algorithm from the
* comp.graphics.algorithms FAQ.)
*/
-@@ -918,7 +918,7 @@
+@@ -918,7 +940,7 @@
int By_Cy = im->AAL_y2 - py;
/* 2.0.13: bounds check! AA_opacity is just as capable of
* 2.0.14: typo fixed. 2.0.15: moved down below declarations
* to satisfy non-C++ compilers.
*/
-@@ -931,12 +931,12 @@
+@@ -931,12 +953,12 @@
LBC_2 = (Bx_Cx * Bx_Cx) + (By_Cy * By_Cy);
if (((im->AAL_LAB_2 + LAC_2) >= LBC_2) && ((im->AAL_LAB_2 + LBC_2) >= LAC_2)) {
* segment is the shorter of the lengths from the endpoints, but call
* the distance -1, so as not to compute the alpha nor draw the pixel.
*/
-@@ -1021,6 +1021,7 @@
- /* Bresenham as presented in Foley & Van Dam */
- void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
- {
-+ int t;
- int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
- int wid;
- int w, wstart;
-@@ -1031,6 +1032,43 @@
- return;
+@@ -1017,6 +1039,43 @@
}
+ }
-+ /* Vertical */
-+ if (x1==x2) {
-+ if (thick > 1) {
-+ int thickhalf = thick >> 1;
-+ thickhalf = thick >> 1;
-+ gdImageFilledRectangle(im, x1 - thickhalf, y1, x1 + thick - thickhalf - 1, y2, color);
-+ } else {
-+ if (y2 < y1) {
-+ t = y2;
-+ y2 = y1;
-+ y1 = t;
-+ }
++static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col)
++{
++ if (im->thick > 1) {
++ int thickhalf = im->thick >> 1;
++ gdImageFilledRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col);
++ } else {
++ if (x2 < x1) {
++ int t = x2;
++ x2 = x1;
++ x1 = t;
++ }
+
-+ for (;y1 <= y2; y1++) {
-+ gdImageSetPixel(im, x1,y1, color);
-+ }
++ for (;x1 <= x2; x1++) {
++ gdImageSetPixel(im, x1, y, col);
+ }
-+ return;
-+ } else if (y1==y2) { /* Horizontal */
-+ if (thick > 1) {
-+ int thickhalf = thick >> 1;
-+ thickhalf = thick >> 1;
-+ gdImageFilledRectangle(im, x1, y1 - thickhalf, x2, y2 + thick - thickhalf - 1, color);
-+ } else {
-+ if (x2 < x1) {
-+ t = x2;
-+ x2 = x1;
-+ x1 = t;
-+ }
++ }
++ return;
++}
+
-+ for (;x1 <= x2; x1++) {
-+ gdImageSetPixel(im, x1,y1, color);
-+ }
++static void gdImageVLine(gdImagePtr im, int x, int y1, int y2, int col)
++{
++ if (im->thick > 1) {
++ int thickhalf = im->thick >> 1;
++ gdImageFilledRectangle(im, x - thickhalf, y1, x + im->thick - thickhalf - 1, y2, col);
++ } else {
++ if (y2 < y1) {
++ int t = y1;
++ y1 = y2;
++ y2 = t;
++ }
++
++ for (;y1 <= y2; y1++) {
++ gdImageSetPixel(im, x, y1, col);
+ }
++ }
++ return;
++}
+
+ /* Bresenham as presented in Foley & Van Dam */
+ void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
+@@ -1026,39 +1085,47 @@
+ int w, wstart;
+ int thick = im->thick;
+
++ if (color == gdAntiAliased)
++ {
++ /*
++ gdAntiAliased passed as color: use the much faster, much cheaper
++ and equally attractive gdImageAALine implementation. That
++ clips too, so don't clip twice.
++ */
++ gdImageAALine(im, x1, y1, x2, y2, im->AA_color);
+ return;
+ }
+
- /* gdAntiAliased passed as color: set anti-aliased line (AAL) global vars. */
- if (color == gdAntiAliased) {
- im->AAL_x1 = x1;
-@@ -1045,11 +1083,11 @@
- im->AAL_LAB = sqrt (im->AAL_LAB_2);
+ /* 2.0.10: Nick Atty: clip to edges of drawing rectangle, return if no points need to be drawn */
+ if (!clip_1d(&x1,&y1,&x2,&y2,gdImageSX(im)) || !clip_1d(&y1,&x1,&y2,&x2,gdImageSY(im))) {
+ return;
+ }
- /* For AA, we must draw pixels outside the width of the line. Keep in
+- /* gdAntiAliased passed as color: set anti-aliased line (AAL) global vars. */
+- if (color == gdAntiAliased) {
+- im->AAL_x1 = x1;
+- im->AAL_y1 = y1;
+- im->AAL_x2 = x2;
+- im->AAL_y2 = y2;
+-
+- /* Compute what we can for point-to-line distance calculation later. */
+- im->AAL_Bx_Ax = x2 - x1;
+- im->AAL_By_Ay = y2 - y1;
+- im->AAL_LAB_2 = (im->AAL_Bx_Ax * im->AAL_Bx_Ax) + (im->AAL_By_Ay * im->AAL_By_Ay);
+- im->AAL_LAB = sqrt (im->AAL_LAB_2);
++ dx = abs (x2 - x1);
++ dy = abs (y2 - y1);
+
+- /* For AA, we must draw pixels outside the width of the line. Keep in
- * mind that this will be curtailed by cos/sin of theta later.
-+ * mind that this will be curtailed by cos/sin of theta later.
- */
- thick += 4;
+- */
+- thick += 4;
++ if (dx == 0) {
++ gdImageVLine(im, x1, y1, y2, color);
++ return;
++ } else if (dy == 0) {
++ gdImageHLine(im, y1, x1, x2, color);
++ return;
}
-
+- dx = abs(x2 - x1);
+- dy = abs(y2 - y1);
+
- dx = abs(x2 - x1);
- dy = abs(y2 - y1);
if (dy <= dx) {
-@@ -1115,7 +1153,7 @@
+ /* More-or-less horizontal. use wid for vertical stroke */
+ /* Doug Claar: watch out for NaN in atan2 (2.0.5) */
+ if ((dx == 0) && (dy == 0)) {
+ wid = 1;
+ } else {
+- wid = (int)(thick * cos (atan2 (dy, dx)));
++ /* 2.0.12: Michael Schwartz: divide rather than multiply;
++TBB: but watch out for /0! */
++ double ac = cos (atan2 (dy, dx));
++ if (ac != 0) {
++ wid = thick / ac;
++ } else {
++ wid = 1;
++ }
+ if (wid == 0) {
+ wid = 1;
+ }
+@@ -1115,16 +1182,17 @@
}
} else {
/* More-or-less vertical. use wid for horizontal stroke */
- /* 2.0.12: Michael Schwartz: divide rather than multiply;
+- TBB: but watch out for /0! */
+- double as = sin(atan2(dy, dx));
+ /* 2.0.12: Michael Schwartz: divide rather than multiply;
- TBB: but watch out for /0! */
- double as = sin(atan2(dy, dx));
++ TBB: but watch out for /0! */
++ double as = sin (atan2 (dy, dx));
if (as != 0) {
-@@ -1207,7 +1245,7 @@
+- if (!(wid = thick / as)) {
+- wid = 1;
+- }
++ wid = thick / as;
+ } else {
+ wid = 1;
+ }
++ if (wid == 0) {
++ wid = 1;
++ }
+
+ d = 2 * dx - dy;
+ incr1 = 2 * dx;
+@@ -1177,11 +1245,6 @@
+ }
+ }
+ }
+-
+- /* If this is the only line we are drawing, go ahead and blend. */
+- if (color == gdAntiAliased && !im->AA_polygon) {
+- gdImageAABlend(im);
+- }
+ }
+
+
+@@ -1207,7 +1270,7 @@
BLEND_COLOR(t, dg, g, dg);
BLEND_COLOR(t, db, b, db);
im->tpixels[y][x]=gdTrueColorAlpha(dr, dg, db, gdAlphaOpaque);
/*
* Added on 2003/12 by Pierre-Alain Joye (pajoye@pearfr.org)
-@@ -1586,9 +1624,9 @@
+@@ -1586,9 +1649,9 @@
/* s and e are integers modulo 360 (degrees), with 0 degrees
being the rightmost extreme and degrees changing clockwise.
seem to be bug-free yet. */
void gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
-@@ -1779,17 +1817,15 @@
+@@ -1607,29 +1670,30 @@
+ int lx = 0, ly = 0;
+ int fx = 0, fy = 0;
+
+- if ((s % 360) == (e % 360)) {
++
++ if ((s % 360) == (e % 360)) {
+ s = 0; e = 360;
+- } else {
+- if (s > 360) {
+- s = s % 360;
+- }
++ } else {
++ if (s > 360) {
++ s = s % 360;
++ }
+
+- if (e > 360) {
+- e = e % 360;
+- }
++ if (e > 360) {
++ e = e % 360;
++ }
+
+- while (s < 0) {
+- s += 360;
+- }
++ while (s < 0) {
++ s += 360;
++ }
+
+- while (e < s) {
+- e += 360;
+- }
++ while (e < s) {
++ e += 360;
++ }
+
+- if (s == e) {
++ if (s == e) {
+ s = 0; e = 360;
+- }
+- }
++ }
++ }
+
+ for (i = s; i <= e; i++) {
+ int x, y;
+@@ -1787,17 +1851,15 @@
int lastBorder;
/* Seek left */
int leftLimit = -1, rightLimit;
if (x >= im->sx) {
x = im->sx - 1;
-@@ -1806,9 +1842,7 @@
+@@ -1814,9 +1876,7 @@
leftLimit = i;
}
if (leftLimit == -1) {
return;
}
/* Seek right */
-@@ -1836,6 +1870,7 @@
+@@ -1844,6 +1904,7 @@
}
}
}
/* Below */
if (y < ((im->sy) - 1)) {
lastBorder = 1;
-@@ -1852,12 +1887,9 @@
+@@ -1860,12 +1921,9 @@
}
}
}
/*
* set the pixel at (x,y) and its 4-connected neighbors
* with the same pixel value to the new pixel value nc (new color).
-@@ -1887,18 +1919,24 @@
+@@ -1888,25 +1946,31 @@
+ #define FILL_POP(Y, XL, XR, DY) \
+ {sp--; Y = sp->y+(DY = sp->dy); XL = sp->xl; XR = sp->xr;}
+
+-void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc);
++static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc);
+
+ void gdImageFill(gdImagePtr im, int x, int y, int nc)
+ {
int l, x1, x2, dy;
int oc; /* old pixel value */
int wx2,wy2;
return;
}
-@@ -1908,8 +1946,31 @@
+@@ -1916,8 +1980,31 @@
im->alphaBlendingFlag = alphablending_bak;
return;
}
sp = stack;
/* required! */
-@@ -1946,7 +2007,10 @@
+@@ -1954,22 +2041,25 @@
l = x;
} while (x<=x2);
}
im->alphaBlendingFlag = alphablending_bak;
}
-@@ -1959,9 +2023,9 @@
+-void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
++static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
+ {
+- int i,l, x1, x2, dy;
++ int i, l, x1, x2, dy;
+ int oc; /* old pixel value */
+ int tiled;
+ int wx2,wy2;
/* stack of filled segments */
struct seg *stack;
struct seg *sp;
return;
}
-@@ -1969,28 +2033,24 @@
+@@ -1977,30 +2067,26 @@
tiled = nc==gdTiled;
nc = gdImageTileGet(im,x,y);
- pts = (int **) ecalloc(sizeof(int *) * im->sy, sizeof(int));
-+ pts = (char **) ecalloc(im->sy, sizeof(char*));
- for (i=0; i<im->sy;i++) {
+- for (i=0; i<im->sy;i++) {
- pts[i] = (int *) ecalloc(im->sx, sizeof(int));
-+ pts[i] = (char *) ecalloc(im->sx, sizeof(char));
++ pts = (char **) ecalloc(im->sy + 1, sizeof(char *));
++ for (i = 0; i < im->sy + 1; i++) {
++ pts[i] = (char *) ecalloc(im->sx + 1, sizeof(char));
}
- stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1);
- break;
- }
nc = gdImageTileGet(im,x,y);
- pts[y][x]=1;
+- pts[y][x]=1;
++ pts[y][x] = 1;
gdImageSetPixel(im,x, y, nc);
-@@ -2006,11 +2066,7 @@
+ }
+ if (x>=x1) {
+@@ -2014,13 +2100,9 @@
}
x = x1+1;
do {
- /* we should never be here */
- break;
- }
-+ for (; x<wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc) ; x++) {
++ for(; x<wx2 && (!pts[y][x] && gdImageGetPixel(im,x, y)==oc); x++) {
nc = gdImageTileGet(im,x,y);
- pts[y][x]=1;
+- pts[y][x]=1;
++ pts[y][x] = 1;
gdImageSetPixel(im, x, y, nc);
-@@ -2102,16 +2158,15 @@
+ }
+ FILL_PUSH(y, l, x-1, dy);
+@@ -2028,13 +2110,15 @@
+ if (x>x2+1) {
+ FILL_PUSH(y, x2+1, x-1, -dy);
+ }
+-skip: for (x++; x<=x2 && (pts[y][x] || gdImageGetPixel(im,x, y)!=oc); x++);
++skip: for(x++; x<=x2 && (pts[y][x] || gdImageGetPixel(im,x, y)!=oc); x++);
+ l = x;
+ } while (x<=x2);
+ }
+- for (i=0; i<im->sy;i++) {
++
++ for(i = 0; i < im->sy + 1; i++) {
+ efree(pts[i]);
+ }
++
+ efree(pts);
+ efree(stack);
+ }
+@@ -2048,6 +2132,11 @@
+ int half1 = 1;
+ int t;
+
++ if (x1 == x2 && y1 == y2 && thick == 1) {
++ gdImageSetPixel(im, x1, y1, color);
++ return;
++ }
++
+ if (y2 < y1) {
+ t=y1;
+ y1 = y2;
+@@ -2110,16 +2199,15 @@
gdImageLine(im, x1v, y1v, x1v, y2v, color);
gdImageLine(im, x2v, y1v, x2v, y2v, color);
}
*/
if (x1 < 0) {
x1 = 0;
-@@ -2125,15 +2180,15 @@
+@@ -2133,15 +2221,15 @@
if (y1 > gdImageSY(im)) {
y1 = gdImageSY(im);
}
}
for (y = y1; (y <= y2); y++) {
-@@ -2154,9 +2209,9 @@
+@@ -2162,9 +2250,9 @@
if (dst->trueColor) {
/* 2.0: much easier when the destination is truecolor. */
/* 2.0.10: needs a transparent-index check that is still valid if
if (src->trueColor) {
for (y = 0; (y < h); y++) {
for (x = 0; (x < w); x++) {
-@@ -2170,7 +2225,7 @@
+@@ -2178,7 +2266,7 @@
for (x = 0; (x < w); x++) {
int c = gdImageGetPixel (src, srcX + x, srcY + y);
if (c != src->transparent) {
}
}
}
-@@ -2217,7 +2272,7 @@
+@@ -2225,7 +2313,7 @@
/* Have we established a mapping for this color? */
if (src->trueColor) {
/* 2.05: remap to the palette available in the destination image. This is slow and
*/
mapTo = gdImageColorResolveAlpha (dst, gdTrueColorGetRed (c), gdTrueColorGetGreen (c), gdTrueColorGetBlue (c), gdTrueColorGetAlpha (c));
} else if (colorMap[c] == (-1)) {
-@@ -2229,9 +2284,9 @@
+@@ -2237,9 +2325,9 @@
nc = gdImageColorResolveAlpha (dst, src->red[c], src->green[c], src->blue[c], src->alpha[c]);
}
colorMap[c] = nc;
}
gdImageSetPixel (dst, tox, toy, mapTo);
tox++;
-@@ -2249,7 +2304,7 @@
+@@ -2257,7 +2345,7 @@
int tox, toy;
int ncR, ncG, ncB;
toy = dstY;
for (y = srcY; y < (srcY + h); y++) {
tox = dstX;
for (x = srcX; x < (srcX + w); x++) {
-@@ -2296,15 +2351,17 @@
+@@ -2304,15 +2392,17 @@
for (x = srcX; (x < (srcX + w)); x++) {
int nc;
c = gdImageGetPixel (src, x, y);
*/
if (dst == src && pct == 100) {
nc = c;
-@@ -2312,9 +2369,10 @@
+@@ -2320,9 +2410,10 @@
dc = gdImageGetPixel(dst, tox, toy);
g = (0.29900f * gdImageRed(dst, dc)) + (0.58700f * gdImageGreen(dst, dc)) + (0.11400f * gdImageBlue(dst, dc));
/* First look for an exact match */
nc = gdImageColorExact(dst, ncR, ncG, ncB);
-@@ -2346,10 +2404,10 @@
+@@ -2354,10 +2445,18 @@
int *stx, *sty;
/* We only need to use floating point to determine the correct stretch vector for one line's worth. */
double accum;
- stx = (int *) safe_emalloc(sizeof(int), srcW, 0);
- sty = (int *) safe_emalloc(sizeof(int), srcH, 0);
+- accum = 0;
+
++ if (overflow2(sizeof(int), srcW)) {
++ return;
++ }
++ if (overflow2(sizeof(int), srcH)) {
++ return;
++ }
++
+ stx = (int *) gdMalloc (sizeof (int) * srcW);
+ sty = (int *) gdMalloc (sizeof (int) * srcH);
- accum = 0;
--
++ accum = 0;
+
/* Fixed by Mao Morimoto 2.0.16 */
for (i = 0; (i < srcW); i++) {
stx[i] = dstW * (i+1) / srcW - dstW * i / srcW ;
-@@ -2379,7 +2437,7 @@
+@@ -2387,7 +2486,7 @@
/* 2.0.21, TK: not tox++ */
tox += stx[x - srcX];
continue;
} else {
/* TK: old code follows */
mapTo = gdImageGetTrueColorPixel (src, x, y);
-@@ -2389,7 +2447,7 @@
+@@ -2397,7 +2496,7 @@
tox += stx[x - srcX];
continue;
}
} else {
c = gdImageGetPixel (src, x, y);
/* Added 7/24/95: support transparent copies */
-@@ -2489,7 +2547,7 @@
+@@ -2451,6 +2550,7 @@
+ {
+ int x, y;
+ double sy1, sy2, sx1, sx2;
++
+ if (!dst->trueColor) {
+ gdImageCopyResized (dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
+ return;
+@@ -2497,7 +2597,7 @@
}
pcontribution = xportion * yportion;
p = gdImageGetTrueColorPixel(src, (int) sx + srcX, (int) sy + srcY);
alpha_factor = ((gdAlphaMax - gdTrueColorGetAlpha(p))) * pcontribution;
red += gdTrueColorGetRed (p) * alpha_factor;
green += gdTrueColorGetGreen (p) * alpha_factor;
-@@ -2501,12 +2559,12 @@
+@@ -2509,12 +2609,12 @@
sx += 1.0f;
}
while (sx < sx2);
if (spixels != 0.0f) {
red /= spixels;
green /= spixels;
-@@ -2516,7 +2574,7 @@
+@@ -2524,7 +2624,7 @@
if ( alpha_sum != 0.0f) {
if( contrib_sum != 0.0f) {
alpha_sum /= contrib_sum;
red /= alpha_sum;
green /= alpha_sum;
blue /= alpha_sum;
-@@ -2541,7 +2599,7 @@
+@@ -2549,7 +2649,7 @@
/*
* by Pierre-Alain Joye (pajoye@pearfr.org)
**/
/* Begin rotate function */
-@@ -2550,7 +2608,7 @@
+@@ -2558,7 +2658,7 @@
#endif /* ROTATE_PI */
#define ROTATE_DEG2RAD 3.1415926535897932384626433832795/180
{
typedef int (*FuncPtr)(gdImagePtr, int, int);
int i, r, g, b, a, clrBackR, clrBackG, clrBackB, clrBackA;
-@@ -2615,10 +2673,14 @@
+@@ -2623,10 +2723,14 @@
a = 127;
}
}
if ((i + iOffset >= 0) && (i + iOffset < dst->sx)) {
-@@ -2643,7 +2705,7 @@
+@@ -2651,7 +2755,7 @@
}
}
{
typedef int (*FuncPtr)(gdImagePtr, int, int);
int i, iYPos=0, r, g, b, a;
-@@ -2702,10 +2764,14 @@
+@@ -2710,10 +2814,14 @@
a = 127;
}
}
if ((iYPos >= 0) && (iYPos < dst->sy)) {
-@@ -2727,10 +2793,10 @@
+@@ -2735,10 +2843,10 @@
}
/* Rotates an image by 90 degrees (counter clockwise) */
gdImagePtr dst;
typedef int (*FuncPtr)(gdImagePtr, int, int);
FuncPtr f;
-@@ -2741,8 +2807,12 @@
+@@ -2749,8 +2857,12 @@
f = gdImageGetPixel;
}
dst = gdImageCreateTrueColor(src->sy, src->sx);
gdImagePaletteCopy (dst, src);
for (uY = 0; uY<src->sy; uY++) {
-@@ -2755,16 +2825,21 @@
+@@ -2763,16 +2875,21 @@
a = gdImageAlpha(src,c);
c = gdTrueColorAlpha(r, g, b, a);
}
{
int uY, uX;
int c,r,g,b,a;
-@@ -2778,8 +2853,12 @@
+@@ -2786,8 +2903,12 @@
f = gdImageGetPixel;
}
dst = gdImageCreateTrueColor(src->sx, src->sy);
gdImagePaletteCopy (dst, src);
for (uY = 0; uY<src->sy; uY++) {
-@@ -2792,16 +2871,22 @@
+@@ -2800,16 +2921,22 @@
a = gdImageAlpha(src,c);
c = gdTrueColorAlpha(r, g, b, a);
}
{
int uY, uX;
int c,r,g,b,a;
-@@ -2814,9 +2899,13 @@
+@@ -2822,9 +2949,13 @@
} else {
f = gdImageGetPixel;
}
gdImagePaletteCopy (dst, src);
for (uY = 0; uY<src->sy; uY++) {
-@@ -2829,15 +2918,21 @@
+@@ -2837,15 +2968,21 @@
a = gdImageAlpha(src,c);
c = gdTrueColorAlpha(r, g, b, a);
}
{
typedef int (*FuncPtr)(gdImagePtr, int, int);
gdImagePtr dst1,dst2,dst3;
-@@ -2861,8 +2956,8 @@
+@@ -2869,8 +3006,8 @@
} else {
f = gdImageGetPixel;
}
/******* Perform 1st shear (horizontal) ******/
if (dst1 == NULL) {
return NULL;
-@@ -2877,6 +2972,15 @@
+@@ -2885,6 +3022,15 @@
gdImagePaletteCopy (dst1, src);
dRadAngle = dAngle * ROTATE_DEG2RAD; /* Angle in radians */
dSinE = sin (dRadAngle);
dTan = tan (dRadAngle / 2.0);
-@@ -2889,7 +2993,7 @@
+@@ -2897,7 +3043,7 @@
}
iShear = (int)floor(dShear);
}
/*
-@@ -2925,10 +3029,13 @@
+@@ -2933,10 +3079,13 @@
return NULL;
}
dst2->alphaBlendingFlag = gdEffectReplace;
}
/* 3rd shear */
-@@ -2947,6 +3054,12 @@
+@@ -2955,6 +3104,12 @@
gdImageDestroy(dst2);
return NULL;
}
if (dSinE >= 0.0) {
dOffset = (double)(src->sx - 1) * dSinE * -dTan;
} else {
-@@ -2954,8 +3067,8 @@
+@@ -2962,8 +3117,8 @@
}
for (u = 0; u < dst3->sy; u++, dOffset += dTan) {
}
gdImageDestroy(dst2);
-@@ -2963,11 +3076,11 @@
+@@ -2971,11 +3126,11 @@
return dst3;
}
if (src == NULL) {
return NULL;
}
-@@ -2985,41 +3098,33 @@
+@@ -2993,41 +3148,33 @@
}
if (dAngle == 90.00) {
gdImageDestroy(pMidImg);
return rotatedImg;
-@@ -3095,9 +3200,9 @@
+@@ -3098,20 +3245,27 @@
+ return;
+ }
+
++ if (overflow2(sizeof(int), n)) {
++ return;
++ }
++
+ if (c == gdAntiAliased) {
+ fill_color = im->AA_color;
} else {
fill_color = c;
}
im->polyAllocated = n;
}
if (im->polyAllocated < n) {
-@@ -3123,7 +3228,7 @@
+ while (im->polyAllocated < n) {
+ im->polyAllocated *= 2;
+ }
++ if (overflow2(sizeof(int), im->polyAllocated)) {
++ return;
++ }
+ im->polyInts = (int *) gdRealloc(im->polyInts, sizeof(int) * im->polyAllocated);
+ }
+ miny = p[0].y;
+@@ -3131,7 +3285,7 @@
}
if (maxy >= gdImageSY(im)) {
maxy = gdImageSY(im) - 1;
/* Fix in 1.3: count a vertex only once */
for (y = miny; y <= maxy; y++) {
-@@ -3185,7 +3290,7 @@
+@@ -3193,7 +3347,7 @@
if (im->style) {
gdFree(im->style);
}
memcpy(im->style, style, sizeof(int) * noOfPixels);
im->styleLength = noOfPixels;
im->stylePos = 0;
-@@ -3315,9 +3420,9 @@
+@@ -3323,9 +3477,9 @@
}
int
* component of the result. Thanks to Frank Warmerdam for
* pointing out the issue.
*/
-@@ -3337,6 +3442,51 @@
+@@ -3345,6 +3499,51 @@
gdTrueColorGetBlue (dst)) / gdAlphaMax));
}
void gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg)
{
im->alphaBlendingFlag = alphaBlendingArg;
-@@ -3354,44 +3504,6 @@
+@@ -3362,44 +3561,6 @@
im->saveAlphaFlag = saveAlphaArg;
}
static int gdLayerOverlay (int dst, int src)
{
int a1, a2;
-@@ -3407,12 +3519,12 @@
+@@ -3415,12 +3576,12 @@
static int gdAlphaOverlayColor (int src, int dst, int max )
{
/* this function implements the algorithm
*/
dst = dst << 1;
-@@ -3464,3 +3576,468 @@
+@@ -3472,3 +3633,457 @@
*x2P = im->cx2;
*y2P = im->cy2;
}
+ if (new_pxl == -1) {
+ new_pxl = gdImageColorClosestAlpha(src, 255-r, 255-g, 255-b, a);
+ }
-+ if ((y >= 0) && (y < src->sy)) {
-+ gdImageSetPixel (src, x, y, new_pxl);
-+ }
++ gdImageSetPixel (src, x, y, new_pxl);
+ }
+ }
+ return 1;
+ if (new_pxl == -1) {
+ new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
+ }
-+ if ((y >= 0) && (y < src->sy)) {
-+ gdImageSetPixel (src, x, y, new_pxl);
-+ }
++ gdImageSetPixel (src, x, y, new_pxl);
+ }
+ }
+ return 1;
+ if (new_pxl == -1) {
+ new_pxl = gdImageColorClosestAlpha(src, (int)r, (int)g, (int)b, a);
+ }
-+ if ((y >= 0) && (y < src->sy)) {
-+ gdImageSetPixel (src, x, y, new_pxl);
-+ }
++ gdImageSetPixel (src, x, y, new_pxl);
+ }
+ }
+ return 1;
+ if (new_pxl == -1) {
+ new_pxl = gdImageColorClosestAlpha(src, (int)rf, (int)gf, (int)bf, a);
+ }
-+ if ((y >= 0) && (y < src->sy)) {
-+ gdImageSetPixel (src, x, y, new_pxl);
-+ }
++ gdImageSetPixel (src, x, y, new_pxl);
+ }
+ }
+ return 1;
+}
+
+
-+int gdImageColor(gdImagePtr src, int red, int green, int blue)
++int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha)
+{
+ int x, y;
-+ int r,g,b,a;
+ int new_pxl, pxl;
+ typedef int (*FuncPtr)(gdImagePtr, int, int);
+ FuncPtr f;
+
-+ if (src==NULL || (red<-255||red>255) || (green<-255||green>255) || (blue<-255||blue>255)) {
++ if (src == NULL) {
+ return 0;
+ }
+
+
+ for (y=0; y<src->sy; ++y) {
+ for (x=0; x<src->sx; ++x) {
++ int r,g,b,a;
++
+ pxl = f(src, x, y);
+ r = gdImageRed(src, pxl);
+ g = gdImageGreen(src, pxl);
+ r = r + red;
+ g = g + green;
+ b = b + blue;
++ a = a + alpha;
+
-+ r = (r > 255)? 255 : ((r < 0)? 0:r);
-+ g = (g > 255)? 255 : ((g < 0)? 0:g);
-+ b = (b > 255)? 255 : ((b < 0)? 0:b);
++ r = (r > 255)? 255 : ((r < 0)? 0 : r);
++ g = (g > 255)? 255 : ((g < 0)? 0 : g);
++ b = (b > 255)? 255 : ((b < 0)? 0 : b);
++ a = (a > 127)? 127 : ((a < 0)? 0 : a);
+
-+ new_pxl = gdImageColorAllocateAlpha(src, (int)r, (int)g, (int)b, a);
++ new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a);
+ if (new_pxl == -1) {
-+ new_pxl = gdImageColorClosestAlpha(src, (int)r, (int)g, (int)b, a);
-+ }
-+ if ((y >= 0) && (y < src->sy)) {
-+ gdImageSetPixel (src, x, y, new_pxl);
++ new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
+ }
++ gdImageSetPixel (src, x, y, new_pxl);
+ }
+ }
+ return 1;
+ if (new_pxl == -1) {
+ new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
+ }
-+ if ((y >= 0) && (y < src->sy)) {
-+ gdImageSetPixel (src, x, y, new_pxl);
-+ }
++ gdImageSetPixel (src, x, y, new_pxl);
+ }
+ }
+ gdImageDestroy(srcback);
+ if (new_pxl == -1) {
+ new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
+ }
-+ if ((y >= 0) && (y < src->sy)) {
-+ gdImageSetPixel (src, x, y, new_pxl);
-+ }
++ gdImageSetPixel (src, x, y, new_pxl);
+ }
+ }
+ gdImageDestroy(srcback);
+ return gdImageConvolution(im, filter, weight+8, 0);
+}
+/* End filters function */
-diff -urN php-4.4.7.org/ext/gd/libgd/gdcache.c php-4.4.7/ext/gd/libgd/gdcache.c
---- php-4.4.7.org/ext/gd/libgd/gdcache.c 2003-04-05 19:24:16.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdcache.c 2003-12-28 21:11:08.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/gdcache.c php-4.4.8/ext/gd/libgd/gdcache.c
+--- php-4.4.8.org/ext/gd/libgd/gdcache.c 2003-04-05 19:24:16.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdcache.c 2003-12-28 21:11:08.000000000 +0100
@@ -11,11 +11,11 @@
#ifdef NEED_CACHE
* beginning of the list after retrieval.
*
* In the current implementation the cache is traversed by a linear
-diff -urN php-4.4.7.org/ext/gd/libgd/gdcache.h php-4.4.7/ext/gd/libgd/gdcache.h
---- php-4.4.7.org/ext/gd/libgd/gdcache.h 2003-04-05 19:24:16.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdcache.h 2003-12-28 21:11:08.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/gdcache.h php-4.4.8/ext/gd/libgd/gdcache.h
+--- php-4.4.8.org/ext/gd/libgd/gdcache.h 2003-04-05 19:24:16.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdcache.h 2003-12-28 21:11:08.000000000 +0100
@@ -1,8 +1,8 @@
-/*
+/*
* beginning of the list after retrieval.
*
* In the current implementation the cache is traversed by a linear
-diff -urN php-4.4.7.org/ext/gd/libgd/gdfontg.c php-4.4.7/ext/gd/libgd/gdfontg.c
---- php-4.4.7.org/ext/gd/libgd/gdfontg.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdfontg.c 2006-09-16 21:07:45.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gdfontg.c php-4.4.8/ext/gd/libgd/gdfontg.c
+--- php-4.4.8.org/ext/gd/libgd/gdfontg.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdfontg.c 2006-09-16 21:07:45.000000000 +0200
@@ -13,7 +13,7 @@
#include "gdfontg.h"
};
gdFontPtr gdFontGiant = &gdFontGiantRep;
-diff -urN php-4.4.7.org/ext/gd/libgd/gdfontl.c php-4.4.7/ext/gd/libgd/gdfontl.c
---- php-4.4.7.org/ext/gd/libgd/gdfontl.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdfontl.c 2006-09-16 21:07:45.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gdfontl.c php-4.4.8/ext/gd/libgd/gdfontl.c
+--- php-4.4.8.org/ext/gd/libgd/gdfontl.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdfontl.c 2006-09-16 21:07:45.000000000 +0200
@@ -14,7 +14,7 @@
#include "gdfontl.h"
};
gdFontPtr gdFontLarge = &gdFontLargeRep;
-diff -urN php-4.4.7.org/ext/gd/libgd/gdfontmb.c php-4.4.7/ext/gd/libgd/gdfontmb.c
---- php-4.4.7.org/ext/gd/libgd/gdfontmb.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdfontmb.c 2006-09-16 21:07:46.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gdfontmb.c php-4.4.8/ext/gd/libgd/gdfontmb.c
+--- php-4.4.8.org/ext/gd/libgd/gdfontmb.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdfontmb.c 2006-09-16 21:07:46.000000000 +0200
@@ -12,7 +12,7 @@
#include "gdfontmb.h"
};
gdFontPtr gdFontMediumBold = &gdFontMediumBoldRep;
-diff -urN php-4.4.7.org/ext/gd/libgd/gdfonts.c php-4.4.7/ext/gd/libgd/gdfonts.c
---- php-4.4.7.org/ext/gd/libgd/gdfonts.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdfonts.c 2006-09-16 21:07:46.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gdfonts.c php-4.4.8/ext/gd/libgd/gdfonts.c
+--- php-4.4.8.org/ext/gd/libgd/gdfonts.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdfonts.c 2006-09-16 21:07:46.000000000 +0200
@@ -12,7 +12,7 @@
#include "gdfonts.h"
};
gdFontPtr gdFontSmall = &gdFontSmallRep;
-diff -urN php-4.4.7.org/ext/gd/libgd/gdfontt.c php-4.4.7/ext/gd/libgd/gdfontt.c
---- php-4.4.7.org/ext/gd/libgd/gdfontt.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdfontt.c 2006-09-16 21:07:46.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gdfontt.c php-4.4.8/ext/gd/libgd/gdfontt.c
+--- php-4.4.8.org/ext/gd/libgd/gdfontt.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdfontt.c 2006-09-16 21:07:46.000000000 +0200
@@ -13,7 +13,7 @@
#include "gdfontt.h"
};
gdFontPtr gdFontTiny = &gdFontTinyRep;
-diff -urN php-4.4.7.org/ext/gd/libgd/gdft.c php-4.4.7/ext/gd/libgd/gdft.c
---- php-4.4.7.org/ext/gd/libgd/gdft.c 2007-03-10 13:51:07.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/gdft.c 2007-04-23 17:17:47.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gdft.c php-4.4.8/ext/gd/libgd/gdft.c
+--- php-4.4.8.org/ext/gd/libgd/gdft.c 2007-03-10 13:51:07.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/gdft.c 2007-04-23 17:17:47.000000000 +0200
@@ -16,7 +16,9 @@
#include <unistd.h>
#else
/* retrieve kerning distance and move pen position */
if (use_kerning && previous && glyph_index) {
FT_Get_Kerning(face, previous, glyph_index, ft_kerning_default, &delta);
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_gd2.c php-4.4.7/ext/gd/libgd/gd_gd2.c
---- php-4.4.7.org/ext/gd/libgd/gd_gd2.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_gd2.c 2006-08-08 13:56:36.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_gd2.c php-4.4.8/ext/gd/libgd/gd_gd2.c
+--- php-4.4.8.org/ext/gd/libgd/gd_gd2.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_gd2.c 2006-08-08 13:56:36.000000000 +0200
@@ -26,7 +26,7 @@
/* 2.11: not part of the API, as the save routine can figure it out
* from im->trueColor, and the load routine doesn't need to tell
+
return rv;
}
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_gd.c php-4.4.7/ext/gd/libgd/gd_gd.c
---- php-4.4.7.org/ext/gd/libgd/gd_gd.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_gd.c 2004-03-29 20:20:33.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_gd.c php-4.4.8/ext/gd/libgd/gd_gd.c
+--- php-4.4.8.org/ext/gd/libgd/gd_gd.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_gd.c 2007-08-09 16:21:38.000000000 +0200
@@ -1,4 +1,3 @@
-
#include <stdio.h>
if (im->trueColor) {
return TRUE;
}
-@@ -225,7 +224,7 @@
+@@ -123,6 +122,9 @@
+ } else {
+ im = gdImageCreate(*sx, *sy);
+ }
++ if(!im) {
++ goto fail1;
++ }
+ if (!_gdGetColors(in, im, gd2xFlag)) {
+ goto fail2;
+ }
+@@ -225,7 +227,7 @@
static void _gdPutHeader (gdImagePtr im, gdIOCtx * out)
{
* 2.0.12: 65534 indicates truecolor.
*/
if (im->trueColor) {
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_gif_in.c php-4.4.7/ext/gd/libgd/gd_gif_in.c
---- php-4.4.7.org/ext/gd/libgd/gd_gif_in.c 2006-07-17 17:19:16.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_gif_in.c 2007-04-04 13:40:11.000000000 +0200
+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
+--- php-4.4.8.org/ext/gd/libgd/gd_gif_in.c 2007-06-08 07:31:02.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_gif_in.c 2007-06-07 23:07:33.000000000 +0200
@@ -17,9 +17,9 @@
static int set_verbose(void)
+#endif
+ screen_width = imw = LM_to_uint(buf[0],buf[1]);
+ screen_height = imh = LM_to_uint(buf[2],buf[3]);
-+
-+ haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */
-+ if (haveGlobalColormap) {
-+ if (ReadColorMap(fd, BitPixel, ColorMap)) {
-+ return 0;
-+ }
-+ }
-+
-+ for (;;) {
-+ int top, left;
-+ int width, height;
- if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */
- if (ReadColorMap(fd, BitPixel, ColorMap)) {
-+ if (! ReadOK(fd,&c,1)) {
++ haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */
++ if (haveGlobalColormap) {
++ if (ReadColorMap(fd, BitPixel, ColorMap)) {
return 0;
}
- }
- return 0;
- }
- if (c == ';') { /* GIF terminator */
++ }
++
++ for (;;) {
++ int top, left;
++ int width, height;
++
++ if (! ReadOK(fd,&c,1)) {
++ return 0;
++ }
+ if (c == ';') { /* GIF terminator */
goto terminated;
- }
+ }
++
++ if (c == '!') { /* Extension */
++ if (! ReadOK(fd,&c,1)) {
++ return 0;
++ }
++ DoExtension(fd, c, &Transparent, &ZeroDataBlock);
++ continue;
++ }
- if (c == '!') { /* Extension */
- if (! ReadOK(fd,&c,1)) {
- }
- goto terminated;
- }
-+ if (c == '!') { /* Extension */
-+ if (! ReadOK(fd,&c,1)) {
-+ return 0;
-+ }
-+ DoExtension(fd, c, &Transparent, &ZeroDataBlock);
++ if (c != ',') { /* Not a valid start character */
+ continue;
+ }
- if (!im) {
- return 0;
- }
-+ if (c != ',') { /* Not a valid start character */
-+ continue;
-+ }
-+
+ /*1.4//++imageCount; */
-+
+
+- if (!im->colorsTotal) {
+- gdImageDestroy(im);
+ if (! ReadOK(fd,buf,9)) {
-+ return 0;
-+ }
-+
+ return 0;
+ }
+
+- /* Check for open colors at the end, so
+- we can reduce colorsTotal and ultimately
+- BitsPerPixel */
+- for (i=((im->colorsTotal-1)); (i>=0); i--) {
+ useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
+
+ bitPixel = 1<<((buf[8]&0x07)+1);
+ }
+ return 0;
+ }
-
-- if (!im->colorsTotal) {
-- gdImageDestroy(im);
++
+ if (!(im = gdImageCreate(width, height))) {
- return 0;
- }
++ return 0;
++ }
+ im->interlace = BitSet(buf[8], INTERLACE);
+ if (!useGlobalColormap) {
+ if (ReadColorMap(fd, bitPixel, localColorMap)) {
+ }
+ goto terminated;
+ }
-
-- /* Check for open colors at the end, so
-- we can reduce colorsTotal and ultimately
-- BitsPerPixel */
-- for (i=((im->colorsTotal-1)); (i>=0); i--) {
++
+terminated:
+ /* Terminator before any image was declared! */
+ if (!im) {
{
- static unsigned char buf[256];
+ unsigned char buf[256];
++
++ switch (label) {
++ case 0xf9: /* Graphic Control Extension */
++ memset(buf, 0, 4); /* initialize a few bytes in the case the next function fails */
++ (void) GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP);
++#if 0
++ Gif89.disposal = (buf[0] >> 2) & 0x7;
++ Gif89.inputFlag = (buf[0] >> 1) & 0x1;
++ Gif89.delayTime = LM_to_uint(buf[1],buf[2]);
++#endif
++ if ((buf[0] & 0x1) != 0)
++ *Transparent = buf[3];
- switch (label) {
- case 0xf9: /* Graphic Control Extension */
- }
- while (GetDataBlock(fd, (unsigned char*) buf) > 0)
- ;
-+ switch (label) {
-+ case 0xf9: /* Graphic Control Extension */
-+ memset(buf, 0, 4); /* initialize a few bytes in the case the next function fails */
-+ (void) GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP);
-+#if 0
-+ Gif89.disposal = (buf[0] >> 2) & 0x7;
-+ Gif89.inputFlag = (buf[0] >> 1) & 0x1;
-+ Gif89.delayTime = LM_to_uint(buf[1],buf[2]);
-+#endif
-+ if ((buf[0] & 0x1) != 0)
-+ *Transparent = buf[3];
-+
+ while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0);
+ return FALSE;
+ default:
if (rv > 0) {
tmp = safe_emalloc(3 * rv, sizeof(char), 1);
for (i=0;i<rv;i++) {
-@@ -321,278 +364,272 @@
+@@ -321,281 +364,275 @@
}
return(rv);
}
- ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
+ int i, j, ret;
+ unsigned char count;
-
-- curbit += code_size;
-- return ret;
++
+ if (flag) {
+ scd->curbit = 0;
+ scd->lastbit = 0;
+ scd->curbit = (scd->curbit - scd->lastbit) + 16;
+ scd->lastbit = (2+count)*8 ;
+ }
-+
+
+- curbit += code_size;
+- return ret;
+ ret = 0;
+ for (i = scd->curbit, j = 0; j < code_size; ++i, ++j)
+ ret |= ((scd->buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
- /*} */
-
- while ((v = LWZReadByte(fd,FALSE,c)) >= 0 ) {
-- /* This how we recognize which colors are actually used. */
-- if (im->open[v]) {
-- im->open[v] = 0;
-- }
-- gdImageSetPixel(im, xpos, ypos, v);
-- ++xpos;
-- if (xpos == len) {
-- xpos = 0;
-- if (interlace) {
-- switch (pass) {
-- case 0:
-- case 1:
-- ypos += 8; break;
-- case 2:
-- ypos += 4; break;
-- case 3:
-- ypos += 2; break;
-- }
--
-- if (ypos >= height) {
-- ++pass;
-- switch (pass) {
-- case 1:
-- ypos = 4; break;
-- case 2:
-- ypos = 2; break;
-- case 3:
-- ypos = 1; break;
-- default:
-- goto fini;
-- }
-- }
-- } else {
-- ++ypos;
-- }
-- }
-- if (ypos >= height)
-- break;
-- }
+- if (v >= gdMaxColors) {
+- v = 0;
+ unsigned char c;
+ int v;
+ int xpos = 0, ypos = 0, pass = 0;
+ /* return; */
+ /*} */
+
-+ while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0 ) {
++ while ((v = LWZReadByte(fd, &sd, FALSE, c, ZeroDataBlockP)) >= 0) {
++ if (v >= gdMaxColors) {
++ v = 0;
++ }
+ /* This how we recognize which colors are actually used. */
+ if (im->open[v]) {
+ im->open[v] = 0;
+ ypos += 4; break;
+ case 3:
+ ypos += 2; break;
-+ }
+ }
+- /* This how we recognize which colors are actually used. */
+- if (im->open[v]) {
+- im->open[v] = 0;
+- }
+- gdImageSetPixel(im, xpos, ypos, v);
+- ++xpos;
+- if (xpos == len) {
+- xpos = 0;
+- if (interlace) {
+- switch (pass) {
+- case 0:
+- case 1:
+- ypos += 8; break;
+- case 2:
+- ypos += 4; break;
+- case 3:
+- ypos += 2; break;
+- }
+-
+- if (ypos >= height) {
+- ++pass;
+- switch (pass) {
+- case 1:
+- ypos = 4; break;
+- case 2:
+- ypos = 2; break;
+- case 3:
+- ypos = 1; break;
+- default:
+- goto fini;
+- }
+- }
+- } else {
+- ++ypos;
+- }
+- }
+- if (ypos >= height)
+- break;
+- }
+
+ if (ypos >= height) {
+ ++pass;
}
-
+/* }}} */
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_gif_out.c php-4.4.7/ext/gd/libgd/gd_gif_out.c
---- php-4.4.7.org/ext/gd/libgd/gd_gif_out.c 2004-07-23 01:09:24.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_gif_out.c 2006-07-26 12:03:09.000000000 +0200
+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
+--- php-4.4.8.org/ext/gd/libgd/gd_gif_out.c 2004-07-23 01:09:24.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_gif_out.c 2006-07-26 12:03:09.000000000 +0200
@@ -133,7 +133,7 @@
BitsPerPixel = colorstobpp(tim->colorsTotal);
/* All set, let's do it. */
ColorMapSize = 1 << BitsPerPixel;
RWidth = ctx.Width = GWidth;
-diff -urN php-4.4.7.org/ext/gd/libgd/gd.h php-4.4.7/ext/gd/libgd/gd.h
---- php-4.4.7.org/ext/gd/libgd/gd.h 2004-07-23 01:09:24.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd.h 2007-04-23 17:17:47.000000000 +0200
-@@ -5,14 +5,24 @@
+diff -urN php-4.4.8.org/ext/gd/libgd/gd.h php-4.4.8/ext/gd/libgd/gd.h
+--- php-4.4.8.org/ext/gd/libgd/gd.h 2004-07-23 01:09:24.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd.h 2007-09-12 01:34:25.000000000 +0200
+@@ -5,14 +5,30 @@
extern "C" {
#endif
+
+#include "php_compat.h"
+
++#define GD_MAJOR_VERSION 2
++#define GD_MINOR_VERSION 0
++#define GD_RELEASE_VERSION 35
++#define GD_EXTRA_VERSION ""
++#define GD_VERSION_STRING "2.0.35"
++
+#ifdef NETWARE
+/* default fontpath for netware systems */
+#define DEFAULT_FONTPATH "sys:/java/nwgfx/lib/x11/fonts/ttf;."
#endif
/* gd.h: declarations file for the graphic-draw module.
-@@ -231,8 +241,8 @@
+@@ -231,8 +247,8 @@
gdImagePtr gdImageCreateFromPngCtx(gdIOCtxPtr in);
gdImagePtr gdImageCreateFromWBMP(FILE *inFile);
gdImagePtr gdImageCreateFromWBMPCtx(gdIOCtx *infile);
/* A custom data source. */
/* The source function must return -1 on error, otherwise the number
-@@ -295,6 +305,14 @@
+@@ -295,6 +311,14 @@
void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
/* 2.0.16: for thread-safe use of gdImageStringFT and friends,
* call this before allowing any thread to call gdImageStringFT.
* Otherwise it is invoked by the first thread to invoke
-@@ -438,8 +456,8 @@
+@@ -438,8 +462,8 @@
* compression (smallest files) but takes a long time to compress, and
* -1 selects the default compiled into the zlib library.
*/
void gdImageWBMP(gdImagePtr image, int fg, FILE *out);
void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out);
-@@ -483,7 +501,7 @@
+@@ -483,7 +507,7 @@
/* Best to free this memory with gdFree(), not free() */
void* gdImageGdPtr(gdImagePtr im, int *size);
/* Best to free this memory with gdFree(), not free() */
void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size);
-@@ -534,11 +552,11 @@
+@@ -534,11 +558,11 @@
substituted automatically. */
void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
-diff -urN php-4.4.7.org/ext/gd/libgd/gdhelpers.h php-4.4.7/ext/gd/libgd/gdhelpers.h
---- php-4.4.7.org/ext/gd/libgd/gdhelpers.h 2007-03-10 14:06:37.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/gdhelpers.h 2007-03-10 13:18:36.000000000 +0100
+@@ -619,7 +643,7 @@
+ int gdImageContrast(gdImagePtr src, double contrast);
+
+ /* Simply adds or substracts respectively red, green or blue to a pixel */
+-int gdImageColor(gdImagePtr src, int red, int green, int blue);
++int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha);
+
+ /* Image convolution by a 3x3 custom matrix */
+ int gdImageConvolution(gdImagePtr src, float ft[3][3], float filter_div, float offset);
+diff -urN php-4.4.8.org/ext/gd/libgd/gdhelpers.h php-4.4.8/ext/gd/libgd/gdhelpers.h
+--- php-4.4.8.org/ext/gd/libgd/gdhelpers.h 2007-03-10 14:06:37.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/gdhelpers.h 2007-03-10 13:18:36.000000000 +0100
@@ -1,4 +1,4 @@
-#ifndef GDHELPERS_H
+#ifndef GDHELPERS_H
#define GDHELPERS_H 1
#include <sys/types.h>
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_io.c php-4.4.7/ext/gd/libgd/gd_io.c
---- php-4.4.7.org/ext/gd/libgd/gd_io.c 2003-12-25 23:33:03.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/gd_io.c 2005-08-18 14:54:43.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_io.c php-4.4.8/ext/gd/libgd/gd_io.c
+--- php-4.4.8.org/ext/gd/libgd/gd_io.c 2003-12-25 23:33:03.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/gd_io.c 2005-08-18 14:54:43.000000000 +0200
@@ -23,153 +23,124 @@
#define IO_DBG(s)
+ return ((ctx->tell) (ctx));
+ IO_DBG (php_gd_error ("told."));
}
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_io_dp.c php-4.4.7/ext/gd/libgd/gd_io_dp.c
---- php-4.4.7.org/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:20:33.000000000 +0200
+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
+--- php-4.4.8.org/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_io_dp.c 2004-03-29 20:20:33.000000000 +0200
@@ -27,26 +27,23 @@
/* this is used for creating images in main memory */
+ }
+ return gdReallocDynamic(dp, dp->logicalSize);
}
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_io_file.c php-4.4.7/ext/gd/libgd/gd_io_file.c
---- php-4.4.7.org/ext/gd/libgd/gd_io_file.c 2003-12-25 23:33:03.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/gd_io_file.c 2003-12-25 23:12:12.000000000 +0100
+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
+--- php-4.4.8.org/ext/gd/libgd/gd_io_file.c 2003-12-25 23:33:03.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/gd_io_file.c 2003-12-25 23:12:12.000000000 +0100
@@ -29,11 +29,10 @@
/* this is used for creating images in main memory */
- return ftell (fctx->f);
+ return ftell (fctx->f);
}
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_io.h php-4.4.7/ext/gd/libgd/gd_io.h
---- php-4.4.7.org/ext/gd/libgd/gd_io.h 2003-04-05 19:24:16.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_io.h 2003-12-28 21:11:08.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_io.h php-4.4.8/ext/gd/libgd/gd_io.h
+--- php-4.4.8.org/ext/gd/libgd/gd_io.h 2003-04-05 19:24:16.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_io.h 2003-12-28 21:11:08.000000000 +0100
@@ -6,18 +6,18 @@
#ifdef VMS
#define Putchar gdPutchar
} gdIOCtx;
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_io_ss.c php-4.4.7/ext/gd/libgd/gd_io_ss.c
---- php-4.4.7.org/ext/gd/libgd/gd_io_ss.c 2002-10-30 00:08:01.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/gd_io_ss.c 2003-12-28 21:11:08.000000000 +0100
+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
+--- php-4.4.8.org/ext/gd/libgd/gd_io_ss.c 2002-10-30 00:08:01.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/gd_io_ss.c 2003-12-28 21:11:08.000000000 +0100
@@ -12,7 +12,7 @@
* used internally until it settles down a bit.
*
+ b = a;
+ sinkPutbuf (ctx, &b, 1);
}
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_jpeg.c php-4.4.7/ext/gd/libgd/gd_jpeg.c
---- php-4.4.7.org/ext/gd/libgd/gd_jpeg.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_jpeg.c 2006-02-05 16:53:58.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_jpeg.c php-4.4.8/ext/gd/libgd/gd_jpeg.c
+--- php-4.4.8.org/ext/gd/libgd/gd_jpeg.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_jpeg.c 2006-02-05 16:53:58.000000000 +0100
@@ -1,7 +1,7 @@
/*
* gd_jpeg.c: Read and write JPEG (JFIF) format image files using the
}
src = (my_src_ptr) cinfo->src;
-diff -urN php-4.4.7.org/ext/gd/libgd/gdkanji.c php-4.4.7/ext/gd/libgd/gdkanji.c
---- php-4.4.7.org/ext/gd/libgd/gdkanji.c 2003-04-05 19:24:16.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdkanji.c 2003-12-28 21:11:08.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/gdkanji.c php-4.4.8/ext/gd/libgd/gdkanji.c
+--- php-4.4.8.org/ext/gd/libgd/gdkanji.c 2003-04-05 19:24:16.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdkanji.c 2003-12-28 21:11:08.000000000 +0100
@@ -75,7 +75,7 @@
va_list args;
char *tmp;
va_start(args, format);
vspprintf(&tmp, 0, format, args);
va_end(args);
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_png.c php-4.4.7/ext/gd/libgd/gd_png.c
---- php-4.4.7.org/ext/gd/libgd/gd_png.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_png.c 2006-12-10 02:38:01.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_png.c php-4.4.8/ext/gd/libgd/gd_png.c
+--- php-4.4.8.org/ext/gd/libgd/gd_png.c 2007-05-17 00:54:11.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_png.c 2007-05-17 00:19:08.000000000 +0200
@@ -23,7 +23,7 @@
out all fprintf() statements to disable that).
}
longjmp (jmpbuf_ptr->jmpbuf, 1);
-@@ -126,12 +126,15 @@
+@@ -130,12 +130,15 @@
/* Make sure the signature can't match by dumb luck -- TBB */
/* GRR: isn't sizeof(infile) equal to the size of the pointer? */
if (!png_check_sig (sig, 8)) { /* bad signature */
return NULL;
}
-@@ -142,13 +145,13 @@
+@@ -146,13 +149,13 @@
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
if (png_ptr == NULL) {
png_destroy_read_struct (&png_ptr, NULL, NULL);
return NULL;
-@@ -156,7 +159,7 @@
+@@ -160,7 +163,7 @@
/* we could create a second info struct here (end_info), but it's only
* useful if we want to keep pre- and post-IDAT chunk info separated
*/
/* setjmp() must be called in every non-callback function that calls a
-@@ -164,7 +167,7 @@
+@@ -168,7 +171,7 @@
*/
#ifndef PNG_SETJMP_NOT_SUPPORTED
if (setjmp(gdPngJmpbufStruct.jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
-@@ -183,7 +186,7 @@
+@@ -187,7 +190,7 @@
im = gdImageCreate((int) width, (int) height);
}
if (im == NULL) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
gdFree(image_data);
gdFree(row_pointers);
-@@ -197,15 +200,32 @@
+@@ -201,15 +204,32 @@
png_set_packing (png_ptr); /* expand to 1 byte per pixel */
}
* the simple-transparency index, mostly for backwards
* binary compatibility. The alpha channel is where it's
* really at these days.
-@@ -224,8 +244,8 @@
+@@ -228,8 +248,8 @@
case PNG_COLOR_TYPE_GRAY:
case PNG_COLOR_TYPE_GRAY_ALPHA:
/* create a fake palette and check for single-shade transparency */
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
-@@ -259,7 +279,7 @@
+@@ -263,7 +283,7 @@
* custom 16-bit code to handle the case where there are gdFree
* palette entries. This error will be extremely rare in
* general, though. (Quite possibly there is only one such
*/
}
break;
-@@ -268,16 +288,16 @@
+@@ -272,16 +292,16 @@
case PNG_COLOR_TYPE_RGB_ALPHA:
/* gd 2.0: we now support truecolor. See the comment above
* for a rare situation in which the transparent pixel may not
trans_color_rgb->green,
trans_color_rgb->blue);
}
-@@ -291,7 +311,7 @@
+@@ -295,7 +315,7 @@
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
image_data = (png_bytep) safe_emalloc(rowbytes, height, 0);
/* set the individual row_pointers to point at the correct offsets */
for (h = 0; h < height; ++h) {
-@@ -345,7 +365,7 @@
+@@ -349,7 +369,7 @@
register png_byte b = row_pointers[h][boffset++];
/* gd has only 7 bits of alpha channel resolution, and
* a lifetime of compatibility.
*/
-@@ -369,7 +389,7 @@
+@@ -373,7 +393,7 @@
if (!im->trueColor) {
for (i = num_palette; i < gdMaxColors; ++i) {
if (!open[i]) {
}
}
}
-@@ -384,17 +404,17 @@
+@@ -388,17 +408,17 @@
return im;
}
out->gd_free(out);
}
-@@ -402,18 +422,18 @@
+@@ -406,18 +426,18 @@
{
void *rv;
gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
rv = gdDPExtractData(out, size);
out->gd_free(out);
return rv;
-@@ -421,14 +441,14 @@
+@@ -425,14 +445,14 @@
void gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
{
{
int i, j, bit_depth = 0, interlace_type;
int width = im->sx;
-@@ -450,13 +470,13 @@
+@@ -454,13 +474,13 @@
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
if (png_ptr == NULL) {
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
return;
-@@ -464,7 +484,7 @@
+@@ -468,7 +488,7 @@
#ifndef PNG_SETJMP_NOT_SUPPORTED
if (setjmp (gdPngJmpbufStruct.jmpbuf)) {
png_destroy_write_struct (&png_ptr, &info_ptr);
return;
-@@ -479,14 +499,17 @@
+@@ -483,14 +503,17 @@
* gd is intentionally imperfect and doesn't spend a lot of time
* fussing with such things.
*/
*/
/* png_set_compression_window_bits(png_ptr, 15); */
-@@ -515,13 +538,13 @@
+@@ -519,13 +542,13 @@
bit_depth = 1;
} else if (colors <= 4) {
bit_depth = 2;
interlace_type = im->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
if (im->trueColor) {
-@@ -548,9 +571,9 @@
+@@ -552,9 +575,9 @@
if (!im->trueColor) {
/* Oy veh. Remap the PNG palette to put the entries with interesting alpha channel
* values first. This minimizes the size of the tRNS chunk and thus the size
int tc = 0;
int i;
int j;
-@@ -581,7 +604,7 @@
+@@ -585,7 +608,7 @@
for (i = 0; i < im->colorsTotal; i++) {
if (!im->open[i]) {
if (im->alpha[i] != gdAlphaOpaque) {
trans_values[j] = 255 - ((im->alpha[i] << 1) + (im->alpha[i] >> 6));
mapping[i] = j++;
} else {
-@@ -661,7 +684,7 @@
+@@ -665,7 +688,7 @@
* PNG's convention in which 255 is opaque.
*/
a = gdTrueColorGetAlpha(thisPixel);
*pOutputRow++ = 255 - ((a << 1) + (a >> 6));
}
}
-@@ -673,12 +696,12 @@
+@@ -677,12 +700,12 @@
for (j = 0; j < height; ++j) {
gdFree(row_pointers[j]);
}
for (j = 0; j < height; ++j) {
row_pointers[j] = (png_bytep) gdMalloc(width);
for (i = 0; i < width; ++i) {
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_ss.c php-4.4.7/ext/gd/libgd/gd_ss.c
---- php-4.4.7.org/ext/gd/libgd/gd_ss.c 2003-03-05 17:04:20.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/gd_ss.c 2005-08-18 14:54:44.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_security.c php-4.4.8/ext/gd/libgd/gd_security.c
+--- php-4.4.8.org/ext/gd/libgd/gd_security.c 2007-03-10 14:06:37.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/gd_security.c 2007-10-23 03:58:08.000000000 +0200
+@@ -19,12 +19,10 @@
+
+ int overflow2(int a, int b)
+ {
+- if(a < 0 || b < 0) {
+- php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative, failing operation gracefully\n");
++ if(a <= 0 || b <= 0) {
++ php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
+ return 1;
+ }
+- if(b == 0)
+- return 0;
+ if(a > INT_MAX / b) {
+ php_gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
+ return 1;
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_ss.c php-4.4.8/ext/gd/libgd/gd_ss.c
+--- php-4.4.8.org/ext/gd/libgd/gd_ss.c 2003-03-05 17:04:20.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/gd_ss.c 2005-08-18 14:54:44.000000000 +0200
@@ -17,37 +17,33 @@
#define GD_SS_DBG(s)
}
#endif /* HAVE_LIBPNG */
-diff -urN php-4.4.7.org/ext/gd/libgd/gdtables.c php-4.4.7/ext/gd/libgd/gdtables.c
---- php-4.4.7.org/ext/gd/libgd/gdtables.c 2002-04-13 04:03:09.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdtables.c 2006-09-15 17:11:54.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gdtables.c php-4.4.8/ext/gd/libgd/gdtables.c
+--- php-4.4.8.org/ext/gd/libgd/gdtables.c 2002-04-13 04:03:09.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdtables.c 2006-09-15 17:11:54.000000000 +0200
@@ -1,5 +1,11 @@
-int gdCosT[] =
{
0,
17,
-diff -urN php-4.4.7.org/ext/gd/libgd/gdtest.c php-4.4.7/ext/gd/libgd/gdtest.c
---- php-4.4.7.org/ext/gd/libgd/gdtest.c 2002-10-30 00:08:01.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/gdtest.c 2007-02-24 03:17:24.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/gdtest.c php-4.4.8/ext/gd/libgd/gdtest.c
+--- php-4.4.8.org/ext/gd/libgd/gdtest.c 2002-10-30 00:08:01.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/gdtest.c 2007-02-24 03:17:24.000000000 +0100
@@ -56,7 +56,7 @@
/* */
/* Send to PNG File then Ptr */
out = fopen (of, "wb");
imgsnk.sink = fwriteWrapper;
imgsnk.context = out;
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_topal.c php-4.4.7/ext/gd/libgd/gd_topal.c
---- php-4.4.7.org/ext/gd/libgd/gd_topal.c 2004-08-12 01:25:54.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_topal.c 2007-04-04 02:30:18.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_topal.c php-4.4.8/ext/gd/libgd/gd_topal.c
+--- php-4.4.8.org/ext/gd/libgd/gd_topal.c 2004-08-12 01:25:54.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_topal.c 2007-04-04 02:30:18.000000000 +0200
@@ -772,6 +772,7 @@
nim->green[icolor] = 255;
nim->blue[icolor] = 255;
buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0);
memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal );
-diff -urN php-4.4.7.org/ext/gd/libgd/gd_wbmp.c php-4.4.7/ext/gd/libgd/gd_wbmp.c
---- php-4.4.7.org/ext/gd/libgd/gd_wbmp.c 2004-03-29 20:21:00.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gd_wbmp.c 2005-08-18 14:54:44.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gd_wbmp.c php-4.4.8/ext/gd/libgd/gd_wbmp.c
+--- php-4.4.8.org/ext/gd/libgd/gd_wbmp.c 2004-03-29 20:21:00.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gd_wbmp.c 2005-08-18 14:54:44.000000000 +0200
@@ -1,10 +1,8 @@
-
-
+
+ return rv;
}
-diff -urN php-4.4.7.org/ext/gd/libgd/gdxpm.c php-4.4.7/ext/gd/libgd/gdxpm.c
---- php-4.4.7.org/ext/gd/libgd/gdxpm.c 2003-06-04 01:42:49.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/gdxpm.c 2005-08-18 14:54:44.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/gdxpm.c php-4.4.8/ext/gd/libgd/gdxpm.c
+--- php-4.4.8.org/ext/gd/libgd/gdxpm.c 2003-06-04 01:42:49.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/gdxpm.c 2005-08-18 14:54:44.000000000 +0200
@@ -1,8 +1,8 @@
-/*
+ return im;
}
#endif
-diff -urN php-4.4.7.org/ext/gd/libgd/testac.c php-4.4.7/ext/gd/libgd/testac.c
---- php-4.4.7.org/ext/gd/libgd/testac.c 2002-04-13 04:03:09.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/testac.c 2003-12-28 21:11:08.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/testac.c php-4.4.8/ext/gd/libgd/testac.c
+--- php-4.4.8.org/ext/gd/libgd/testac.c 2002-04-13 04:03:09.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/testac.c 2003-12-28 21:11:08.000000000 +0100
@@ -33,7 +33,7 @@
}
/* Load original PNG, which should contain alpha channel
Otherwise the file would typically be slightly larger. */
gdImageSaveAlpha (im_out, !blending);
-diff -urN php-4.4.7.org/ext/gd/libgd/wbmp.c php-4.4.7/ext/gd/libgd/wbmp.c
---- php-4.4.7.org/ext/gd/libgd/wbmp.c 2007-03-10 14:06:37.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/wbmp.c 2007-03-10 13:18:36.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/wbmp.c php-4.4.8/ext/gd/libgd/wbmp.c
+--- php-4.4.8.org/ext/gd/libgd/wbmp.c 2007-03-10 14:06:37.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/wbmp.c 2007-03-10 13:18:36.000000000 +0100
@@ -28,7 +28,7 @@
/* getmbi
** --------------------------
*/
int
-diff -urN php-4.4.7.org/ext/gd/libgd/wbmp.h php-4.4.7/ext/gd/libgd/wbmp.h
---- php-4.4.7.org/ext/gd/libgd/wbmp.h 2002-04-13 04:03:09.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/wbmp.h 2005-10-09 14:06:27.000000000 +0200
+diff -urN php-4.4.8.org/ext/gd/libgd/wbmp.h php-4.4.8/ext/gd/libgd/wbmp.h
+--- php-4.4.8.org/ext/gd/libgd/wbmp.h 2002-04-13 04:03:09.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/wbmp.h 2005-10-09 14:06:27.000000000 +0200
@@ -8,17 +8,22 @@
** (c) 2000 Johan Van den Brande <johan@vandenbrande.com>
**
+void printwbmp( Wbmp *wbmp );
#endif
-diff -urN php-4.4.7.org/ext/gd/libgd/webpng.c php-4.4.7/ext/gd/libgd/webpng.c
---- php-4.4.7.org/ext/gd/libgd/webpng.c 2002-04-21 15:48:22.000000000 +0200
-+++ php-4.4.7/ext/gd/libgd/webpng.c 2007-02-24 03:17:24.000000000 +0100
+diff -urN php-4.4.8.org/ext/gd/libgd/webpng.c php-4.4.8/ext/gd/libgd/webpng.c
+--- php-4.4.8.org/ext/gd/libgd/webpng.c 2002-04-21 15:48:22.000000000 +0200
++++ php-4.4.8/ext/gd/libgd/webpng.c 2007-02-24 03:17:24.000000000 +0100
@@ -193,7 +193,7 @@
maxy = gdImageSY(im);
out = fopen (outFn, "wb");
if (!out)
-diff -urN php-4.4.7.org/ext/gd/libgd/xbm.c php-4.4.7/ext/gd/libgd/xbm.c
---- php-4.4.7.org/ext/gd/libgd/xbm.c 2007-01-01 10:46:42.000000000 +0100
-+++ php-4.4.7/ext/gd/libgd/xbm.c 2007-01-01 10:36:01.000000000 +0100
-@@ -1,6 +1,6 @@
- /*
- +----------------------------------------------------------------------+
-- | PHP Version 4 |
-+ | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2007 The PHP Group |
- +----------------------------------------------------------------------+
-@@ -16,7 +16,7 @@
- +----------------------------------------------------------------------+
- */
-
--/* $Id$ */
-+/* $Id$ */
-
- #include <stdio.h>
- #include <math.h>
+diff -urN php-4.4.8.org/ext/gd/libgd/xbm.c php-4.4.8/ext/gd/libgd/xbm.c
+--- php-4.4.8.org/ext/gd/libgd/xbm.c 2007-12-31 08:22:47.000000000 +0100
++++ php-4.4.8/ext/gd/libgd/xbm.c 2007-08-09 14:08:29.000000000 +0200
@@ -29,8 +29,8 @@
#define MAX_XBM_LINE_SIZE 255
if (!strcmp("width", type)) {
width = (unsigned int) value;
}
-@@ -147,7 +147,93 @@
+@@ -96,7 +96,9 @@
+ return 0;
+ }
+
+- im = gdImageCreate(width, height);
++ if(!(im = gdImageCreate(width, height))) {
++ return 0;
++ }
+ gdImageColorAllocate(im, 255, 255, 255);
+ gdImageColorAllocate(im, 0, 0, 0);
+ h[2] = '\0';
+@@ -147,7 +149,93 @@
}
}
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
+diff -urN php-4.4.8.org/ext/gd/php_gd.h php-4.4.8/ext/gd/php_gd.h
+--- php-4.4.8.org/ext/gd/php_gd.h 2007-12-31 08:22:47.000000000 +0100
++++ php-4.4.8/ext/gd/php_gd.h 2008-01-22 22:38:05.897151947 +0100
+@@ -32,7 +32,7 @@
+
+ /* open_basedir and safe_mode checks */
+ #define PHP_GD_CHECK_OPEN_BASEDIR(filename, errormsg) \
+- if (!filename || filename == empty_string || php_check_open_basedir(filename TSRMLS_CC) || \
++ if (!filename || php_check_open_basedir(filename TSRMLS_CC) || \
+ (PG(safe_mode) && !php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR)) \
+ ) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, errormsg); \
+@@ -66,7 +66,9 @@
+ /* gd.c functions */
+ PHP_MINFO_FUNCTION(gd);
+ PHP_MINIT_FUNCTION(gd);
++#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
+ PHP_MSHUTDOWN_FUNCTION(gd);
++#endif
+ #if HAVE_LIBGD20 && HAVE_GD_STRINGFT
+ PHP_RSHUTDOWN_FUNCTION(gd);
+ #endif
+@@ -112,6 +114,11 @@
+ PHP_FUNCTION(imagecopyresampled);
+ #endif
+
++#ifdef PHP_WIN32
++PHP_FUNCTION(imagegrabwindow);
++PHP_FUNCTION(imagegrabscreen);
++#endif
++
+ #ifdef HAVE_GD_BUNDLED
+ PHP_FUNCTION(imagerotate);
+ PHP_FUNCTION(imageantialias);
+@@ -184,6 +191,8 @@
+ PHP_FUNCTION(imagelayereffect);
+ PHP_FUNCTION(imagecolormatch);
+ PHP_FUNCTION(imagefilter);
++PHP_FUNCTION(imageconvolution);
++PHP_FUNCTION(imagexbm);
+ #endif
+
+ PHP_GD_API int phpi_get_le_gd(void);