[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-gtk-dev
Subject:    [PHP-GTK-DEV] new_from_gd patch
From:       24.247.219.180
Date:       2007-09-21 17:43:57
Message-ID: 62.A2.56144.FA304F64 () pb1 ! pair ! com
[Download RAW message or body]

After some discussions with Sara, I think the following patch should 
allow new_from_gd

1. To throw an error if gd isn't loaded
2. To work with gd shared if it's loaded
3. To work with gd static
4. To not need gd sources or libraries to build php-gtk

Anyone brave enough to see if I've screwed it up on *nix?  Appears to 
work fine with windows.

If this works properly, I'd love to implement new_from_freeimage and 
new_from_imagemagick too ;)

["new_from_gd.patch" (text/plain)]

Index: ext/gtk+/gdk.overrides
===================================================================
RCS file: /repository/php-gtk/ext/gtk+/gdk.overrides,v
retrieving revision 1.76
diff -u -r1.76 gdk.overrides
--- ext/gtk+/gdk.overrides	15 Jun 2007 21:06:31 -0000	1.76
+++ ext/gtk+/gdk.overrides	21 Sep 2007 17:12:33 -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,23 +1911,26 @@
 
 PHP_METHOD
 {
-#if HAVE_GD_BUNDLED
     zval *php_gd;
     gdImagePtr gd;
     guint *data;
     guint pixel;
     GdkPixbuf *pixbuf;
     int x, y, c, alpha;
+    void (_stdcall *gdImageSaveAlpha)(gdImagePtr im, int saveAlphaArg);
+    int (_stdcall *phpi_get_le_gd)(void);
 
     if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "r", &php_gd)) {
         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");
-        return;
-    }
+	gdImageSaveAlpha = DL_FETCH_SYMBOL(NULL, "gdImageSaveAlpha");
+	phpi_get_le_gd = DL_FETCH_SYMBOL(NULL, "phpi_get_le_gd");
+	
+	if (!gdImageSaveAlpha || !phpi_get_le_gd)
+	{
+		php_error(E_ERROR, "Extension 'gd' not available or uses GD library version below 2.0");
+	}
 
     ZEND_FETCH_RESOURCE(gd, gdImagePtr, &php_gd, -1, "Image", phpi_get_le_gd());
 
@@ -1940,9 +1991,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