From e44f3c8da28626ae8de2a582bb0a8ff646f75dfd Mon Sep 17 00:00:00 2001 From: Andrei Zmievski Date: Tue, 22 Oct 2002 19:02:41 +0000 Subject: [PATCH] - Small fixes to gdk-pixbuf test script. - gdk-pixbuf 2.0 has a fill function. Implemented a manual emulation of it for now. - Made interpolation parameter for GdkPixbuf::scale_simple() optional. - Realized that the code to set tile/stipple/clip_mask of GdkGC was broken and only accepted GdkWindow's instead of GdkPixmap/GdkBitmap. --- ext/gdkpixbuf/gdk-pixbuf.php | 5 ++-- ext/gdkpixbuf/gdkpixbuf.defs | 2 +- ext/gdkpixbuf/gdkpixbuf.overrides | 43 +++++++++++++++++++++++++++++++ ext/gdkpixbuf/php_gdkpixbuf.h | 4 +-- ext/gtk+/php_gtk+_types.c | 19 +++++++++----- 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/ext/gdkpixbuf/gdk-pixbuf.php b/ext/gdkpixbuf/gdk-pixbuf.php index 2b9249c..e02d39f 100644 --- a/ext/gdkpixbuf/gdk-pixbuf.php +++ b/ext/gdkpixbuf/gdk-pixbuf.php @@ -22,7 +22,7 @@ $font = gdk::font_load("-*-helvetica-bold-r-*-*-*-120-*-*-*-*-*-*"); $extents = $font->extents($image_file); $area = &new GtkDrawingArea(); -$area->size($pixbuf->get_width() - 2, $pixbuf->get_height() - 2); +$area->size($pixbuf->get_width(), $pixbuf->get_height()); $area->connect('expose_event', 'expose_event', $pixbuf, $font, $extents, basename($image_file)); $frame = &new GtkFrame(); $frame->add($area); @@ -40,8 +40,7 @@ function expose_event($area, $event, $pixbuf, $font, $extents, $image_file) $event->area->x, $event->area->y, $event->area->x, $event->area->y, $event->area->width, $event->area->height, - GDK_RGB_DITHER_NORMAL, - $event->area->x, $event->area->y); + GDK_RGB_DITHER_NORMAL, 0, 0); if ($event->area->x < $extents[2] + 3 && $event->area->y < $extents[3] + $extents[4] + 3) { diff --git a/ext/gdkpixbuf/gdkpixbuf.defs b/ext/gdkpixbuf/gdkpixbuf.defs index 8015b79..6896088 100644 --- a/ext/gdkpixbuf/gdkpixbuf.defs +++ b/ext/gdkpixbuf/gdkpixbuf.defs @@ -308,7 +308,7 @@ (return-type GdkPixbuf*) (parameter (type-and-name int dest_width)) (parameter (type-and-name int dest_height)) - (parameter (type-and-name GdkInterpType interp_type)) + (parameter (type-and-name GdkInterpType interp_type) (default GDK_INTERP_BILINEAR)) ) (method composite_color_simple diff --git a/ext/gdkpixbuf/gdkpixbuf.overrides b/ext/gdkpixbuf/gdkpixbuf.overrides index d1d66b4..5c284fa 100644 --- a/ext/gdkpixbuf/gdkpixbuf.overrides +++ b/ext/gdkpixbuf/gdkpixbuf.overrides @@ -49,3 +49,46 @@ PHP_FUNCTION(gdk_pixbuf_render_pixmap_and_mask) *return_value = *php_gtk_build_value("(NN)", php_gdk_pixmap_new(pixmap), php_gdk_bitmap_new(mask)); } +%% +override gdk_pixbuf_fill fill GdkPixbuf +PHP_FUNCTION(gdk_pixbuf_fill) +{ + unsigned int color; + int x, y, width, height, rowstride, n_chan; + guchar *pixels; + gboolean alpha; + GdkPixbuf *pixbuf; + guchar *p, *row; + + NOT_STATIC_METHOD(); + + if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "i", &color)) + return; + + pixbuf = PHP_GDK_PIXBUF_GET(this_ptr); + width = gdk_pixbuf_get_width(pixbuf); + height = gdk_pixbuf_get_height(pixbuf); + pixels = gdk_pixbuf_get_pixels(pixbuf); + rowstride = gdk_pixbuf_get_rowstride(pixbuf); + n_chan = gdk_pixbuf_get_n_channels(pixbuf); + alpha = gdk_pixbuf_get_has_alpha(pixbuf); + + row = pixels; + for (y = 0; y < height; y++, row += rowstride) { + p = row; + if (alpha) { + for (x = 0; x < width; x++, p += n_chan) { + p[0] = color >> 24; + p[1] = color >> 16; + p[2] = color >> 8; + p[3] = color; + } + } else { + for (x = 0; x < width; x++, p += n_chan) { + p[0] = color >> 16; + p[1] = color >> 8; + p[2] = color; + } + } + } +} diff --git a/ext/gdkpixbuf/php_gdkpixbuf.h b/ext/gdkpixbuf/php_gdkpixbuf.h index 623a00e..2eccec7 100644 --- a/ext/gdkpixbuf/php_gdkpixbuf.h +++ b/ext/gdkpixbuf/php_gdkpixbuf.h @@ -36,8 +36,8 @@ extern int le_gdk_pixbuf; extern php_gtk_ext_entry gdkpixbuf_ext_entry; #define gdkpixbuf_ext_ptr &gdkpixbuf_ext_entry -void php_gdkpixbuf_register_constants(int module_number TSRMLS_DC); -void php_gdkpixbuf_register_classes(); +void php_gdk_pixbuf_register_constants(int module_number TSRMLS_DC); +void php_gdk_pixbuf_register_classes(); zval *php_gdk_pixbuf_new(GdkPixbuf *pixbuf); #define PHP_GDK_PIXBUF_GET(w) PHP_GTK_GET_GENERIC(w, GdkPixbuf*, le_gdk_pixbuf) diff --git a/ext/gtk+/php_gtk+_types.c b/ext/gtk+/php_gtk+_types.c index 920d74b..96ff942 100644 --- a/ext/gtk+/php_gtk+_types.c +++ b/ext/gtk+/php_gtk+_types.c @@ -1615,15 +1615,22 @@ static int gdk_gc_set_property(zval *object, zend_llist_element **element, zval gdk_gc_set_font(gc, PHP_GDK_FONT_GET(value)); else type_mismatch = 1; - } else if (php_gtk_check_class(value, gdk_window_ce) || Z_TYPE_P(value) == IS_NULL) { - GdkWindow *w = (Z_TYPE_P(value) == IS_NULL) ? NULL : PHP_GDK_WINDOW_GET(value); - + } else if (php_gtk_check_class(value, gdk_pixmap_ce) || php_gtk_check_class(value, gdk_bitmap_ce) || Z_TYPE_P(value) == IS_NULL) { + GdkDrawable *d = NULL; + + if (Z_TYPE_P(value) != IS_NULL) { + if (php_gtk_check_class(value, gdk_pixmap_ce)) + d = PHP_GDK_PIXMAP_GET(value); + else + d = PHP_GDK_BITMAP_GET(value); + } + if (!strcmp(prop_name, "tile")) - gdk_gc_set_tile(gc, w); + gdk_gc_set_tile(gc, d); else if (!strcmp(prop_name, "stipple")) - gdk_gc_set_stipple(gc, w); + gdk_gc_set_stipple(gc, d); else if (!strcmp(prop_name, "clip_mask")) - gdk_gc_set_clip_mask(gc, w); + gdk_gc_set_clip_mask(gc, d); else type_mismatch = 1; } else