[prev in list] [next in list] [prev in thread] [next in thread]
List: php-gtk-dev
Subject: [PHP-GTK-DEV] Re: new_from_gd patch
From: 24.247.219.180
Date: 2007-09-23 21:43:40
Message-ID: D5.FC.30687.EDED6F64 () pb1 ! pair ! com
[Download RAW message or body]
All right, figured out the win32 error and fixed it, windows requires
some really hacky stuff to load the code from a statically linked lib.
The code for the linux side is exactly the same as the patch before and
I have positive tests that it works for both static gd and shared gd
there. Unless I get a "oh my gosh this breaks" I'd like to commit this
patch since it fixes all the gd problems.
Just a recap -
1. You don't need gd to build php-gtk.
2. You don't have to load gd to use php-gtk, unless you want to use the
new_from_gd method.
3. You can use new_from_gd with either gd shared or static as long as
you load it before calling the method.
Thanks,
Elizabeth Smith
["new_from_gd.patch" (text/plain)]
Index: gdk.overrides
===================================================================
RCS file: /repository/php-gtk/ext/gtk+/gdk.overrides,v
retrieving revision 1.76
diff -u -r1.76 gdk.overrides
--- gdk.overrides 15 Jun 2007 21:06:31 -0000 1.76
+++ gdk.overrides 23 Sep 2007 21:25:41 -0000
@@ -1851,10 +1851,58 @@
%%
add GdkPixbuf new_from_gd ZEND_ACC_PUBLIC|ZEND_ACC_STATIC
-#if HAVE_GD_BUNDLED
-#include "ext/gd/php_gd.h"
-#include "ext/gd/libgd/gd.h"
-#endif
+#define gdMaxColors 256
+#define gdTrueColorGetAlpha(c) (((c) & 0x7F000000) >> 24)
+#define gdTrueColorGetRed(c) (((c) & 0xFF0000) >> 16)
+#define gdTrueColorGetGreen(c) (((c) & 0x00FF00) >> 8)
+#define gdTrueColorGetBlue(c) ((c) & 0x0000FF)
+typedef struct gdImageStruct {
+ unsigned char ** pixels;
+ int sx;
+ int sy;
+ int colorsTotal;
+ int red[gdMaxColors];
+ int green[gdMaxColors];
+ int blue[gdMaxColors];
+ int open[gdMaxColors];
+ int transparent;
+ int *polyInts;
+ int polyAllocated;
+ struct gdImageStruct *brush;
+ struct gdImageStruct *tile;
+ int brushColorMap[gdMaxColors];
+ int tileColorMap[gdMaxColors];
+ int styleLength;
+ int stylePos;
+ int *style;
+ int interlace;
+ int thick;
+ int alpha[gdMaxColors];
+ int trueColor;
+ int ** tpixels;
+ int alphaBlendingFlag;
+ int antialias;
+ int saveAlphaFlag;
+ int AA;
+ int AA_color;
+ int AA_dont_blend;
+ unsigned char **AA_opacity;
+ int AA_polygon;
+ int AAL_x1;
+ int AAL_y1;
+ int AAL_x2;
+ int AAL_y2;
+ int AAL_Bx_Ax;
+ int AAL_By_Ay;
+ int AAL_LAB_2;
+ float AAL_LAB;
+ int cx1;
+ int cy1;
+ int cx2;
+ int cy2;
+} gdImage;
+
+typedef gdImage * gdImagePtr;
void phpg_free_pixbuf_data(guchar *pixels, gpointer data)
{
@@ -1863,24 +1911,63 @@
PHP_METHOD
{
-#if HAVE_GD_BUNDLED
zval *php_gd;
gdImagePtr gd;
guint *data;
guint pixel;
GdkPixbuf *pixbuf;
int x, y, c, alpha;
+ struct _zend_module_entry *module;
+
+#ifdef WIN32
+int (__stdcall *phpi_get_le_gd)(void);
+BOOL (__stdcall *EnumProcessModules)(HANDLE hProcess, HMODULE* lphModule, DWORD cb, LPDWORD lpcbNeeded);
+#else
+int (*phpi_get_le_gd)(void);
+#endif
- if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "r", &php_gd)) {
+ if (zend_hash_find(&module_registry, "gd", sizeof("gd"), (void **)&module) == FAILURE) {
+ php_error(E_ERROR, "The php gd extension must be loaded to use this method");
return;
}
- if (!zend_hash_exists(&module_registry, "gd", sizeof("gd")) ||
- !zend_hash_exists(EG(function_table), "imagesavealpha", sizeof("imagesavealpha"))) {
- php_error(E_ERROR, "Extension 'gd' not available or uses GD library version below 2.0");
+ if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "r", &php_gd)) {
return;
}
+#ifdef WIN32
+ if (module->handle == NULL)
+ {
+ HANDLE cur_proc;
+ HMODULE *modules;
+ DWORD needed, i;
+
+ HMODULE psapi = LoadLibrary("psapi.dll");
+ EnumProcessModules = GetProcAddress(psapi, "EnumProcessModules");
+ cur_proc = GetCurrentProcess();
+ EnumProcessModules(cur_proc, NULL, 0, &needed);
+ modules = (HMODULE*)alloca(needed);
+ EnumProcessModules(cur_proc, modules, needed, &needed);
+ for (i=0; i < needed/sizeof(HMODULE); i++)
+ {
+ if ((phpi_get_le_gd = (void*)GetProcAddress(modules[i], "phpi_get_le_gd")))
+ break;
+ }
+ }
+ else
+ {
+ phpi_get_le_gd = DL_FETCH_SYMBOL(module->handle, "phpi_get_le_gd");
+ }
+#else
+ phpi_get_le_gd = DL_FETCH_SYMBOL(module->handle, "phpi_get_le_gd");
+#endif
+
+ if (!phpi_get_le_gd)
+ {
+ php_error(E_ERROR, "Could not load gd functions");
+ return;
+ }
+
ZEND_FETCH_RESOURCE(gd, gdImagePtr, &php_gd, -1, "Image", phpi_get_le_gd());
data = safe_emalloc(gd->sx * gd->sy, sizeof(guint), 0);
@@ -1940,9 +2027,6 @@
phpg_gobject_new(&return_value, (GObject *)pixbuf TSRMLS_CC);
g_object_unref(pixbuf); /* phpg_gobject_new() increments reference count */
-#else
- php_error(E_ERROR, "PHP-GTK was not compiled against PHP with bundled GD library");
-#endif
}
%%
--
PHP-GTK Development Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic