[Fwd: Implementation of GdkPixbuf::get_pixel() GdkPixbuf::put_pixel() GdkPixbuf::fill_area()]

From: Date: Thu, 02 Mar 2006 14:42:13 +0000
Subject: [Fwd: Implementation of GdkPixbuf::get_pixel() GdkPixbuf::put_pixel() GdkPixbuf::fill_area()]
Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-2479@lists.php.net to get a copy of this message
Hello all, I think this methods would really help. -------- Original Message -------- Subject: Implementation of GdkPixbuf::get_pixel() GdkPixbuf::put_pixel() GdkPixbuf::fill_area() Date: Thu, 02 Mar 2006 15:39:07 +0100 From: xxoes <xxoes@nw7.de> To: cweiske@cweiske.de Implementation of GdkPixbuf::get_pixel() GdkPixbuf::put_pixel() GdkPixbuf::fill_area() , thera are no existing methodes like gdk_pixbuf_get_pixel or gdk_pixbuf_fill_area, but i think these are usefull, GdkImage has already put_pixel/get_pixel. (define-method get_pixel (of-object "GdkPixbuf") (c-name "gdk_pixbuf_get_pixel") (return-type "gint") (parameters '("int" "x_pos") '("int" "y_pos") ) ) (define-method put_pixel (of-object "GdkPixbuf") (c-name "gdk_pixbuf_put_pixel") (return-type "none") (parameters '("int" "x_pos") '("int" "y_pos") '("int" "pixel") ) ) (define-method fill_area (of-object "GdkPixbuf") (c-name "gdk_pixbuf_fill_area") (return-type "none") (parameters '("int" "x_pos") '("int" "y_pos") '("int" "width") '("int" "height") '("int" "pixel") ) ) %% override gdk_pixbuf_save PHP_METHOD { char *filename; char *type; char **option_keys = NULL; char **option_values = NULL; GError *error = NULL; int argc,i,options; zval ***args; NOT_STATIC_METHOD(); argc = ZEND_NUM_ARGS(); options = (argc-2)/2; args = (zval ***)emalloc(argc * sizeof(zval **)); if(argc < 2 || zend_get_parameters_array_ex(argc,args)==FAILURE) { efree(args); WRONG_PARAM_COUNT; } else if(argc%2) { efree(args); php_error(E_WARNING, "%s::%s() requires arguments 3-n to be key/value pairs", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); return; } option_keys = (char**)emalloc((options+1) * sizeof(char**)); option_values = (char**)emalloc((options+1) * sizeof(char**)); for(i=0;i<argc;i++) { if(Z_TYPE_PP(args[i]) != IS_STRING) { convert_to_string_ex(args[i]); } if(i == 0) { filename = Z_STRVAL_PP(args[i]); } else if(i == 1) { type = Z_STRVAL_PP(args[i]); } else if(!(i%2)) { option_keys[(i-2)/2] = Z_STRVAL_PP(args[i]); } else { option_values[(i-2)/2] = Z_STRVAL_PP(args[i]); } } option_keys[(i-2)/2] = 0; option_values[(i-2)/2] = 0; if(gdk_pixbuf_savev(GDK_PIXBUF(PHPG_GOBJECT(this_ptr)), filename, type, option_keys, option_values, &error)) { efree(args); efree(option_keys); efree(option_values); RETURN_TRUE; } else { efree(args); efree(option_keys); efree(option_values); if(error) { php_error(E_WARNING, "%s::%s() error->code = %u, error->message = %s", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C), error->code,error->message); } else { php_error(E_WARNING, "%s::%s() Bad option name or wrong option value", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); } RETURN_FALSE; } } %% override gdk_pixbuf_get_pixel PHP_METHOD { gint x, y; long pixel; GdkPixbuf *pixbuf; guchar *pixels; guint r = 0, g = 0, b = 0, a = 0; gint w, h; int n_channels, rowstride; NOT_STATIC_METHOD(); if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "ii", &x, &y)) return; pixbuf = GDK_PIXBUF(PHPG_GOBJECT(this_ptr)); if ((w = gdk_pixbuf_get_width(pixbuf)) == 0 || (h = gdk_pixbuf_get_height(pixbuf)) == 0) { php_error(E_WARNING, "%s::%s() empty GdkPixbuf", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); return; } if(x < 0 || y < 0) { php_error(E_WARNING, "%s::%s() x_pos < 0 || y_pos < 0 out of range", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C),x,w,y,h); return; } if(x >= w || y >= h) { php_error(E_WARNING, "%s::%s() x_pos >= GdkPixbuf->width || y_pos >= GdkPixbuf->height out of range", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C),x,w,y,h); return; } pixels = gdk_pixbuf_get_pixels(pixbuf); n_channels = gdk_pixbuf_get_n_channels(pixbuf); rowstride = gdk_pixbuf_get_rowstride(pixbuf); pixels += rowstride*y; if(n_channels == 3) { pixels += 3*x; r = pixels[0]; g = pixels[1]; b = pixels[2]; } else if(n_channels == 4) { pixels += 4*x; r = pixels[0]; g = pixels[1]; b = pixels[2]; a = pixels[3]; } pixel = 0; pixel += r << 24; pixel += g << 16; pixel += b << 8; pixel += a; RETVAL_LONG(pixel); } %% override gdk_pixbuf_put_pixel PHP_METHOD { gint x, y; long pixel; GdkPixbuf *pixbuf; guchar *pixels; guint r, g, b, a; gint w, h; int n_channels, rowstride; NOT_STATIC_METHOD(); if(ZEND_NUM_ARGS() == 6) { if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "iiiiii", &x, &y, &r, &g, &b, &a)) return; } else { if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "iii", &x, &y, &pixel)) return; } pixbuf = GDK_PIXBUF(PHPG_GOBJECT(this_ptr)); if ((w = gdk_pixbuf_get_width(pixbuf)) == 0 || (h = gdk_pixbuf_get_height(pixbuf)) == 0) { php_error(E_WARNING, "%s::%s() empty GdkPixbuf", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); return; } if(x < 0 || y < 0) { php_error(E_WARNING, "%s::%s() x_pos < 0 || y_pos < 0 out of range", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C),x,w,y,h); return; } if(x >= w || y >= h) { php_error(E_WARNING, "%s::%s() x_pos >= GdkPixbuf->width || y_pos >= GdkPixbuf->height out of range", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C),x,w,y,h); return; } pixels = gdk_pixbuf_get_pixels(pixbuf); n_channels = gdk_pixbuf_get_n_channels(pixbuf); rowstride = gdk_pixbuf_get_rowstride(pixbuf); if(ZEND_NUM_ARGS() != 6) { r = (pixel & 0xff000000) >> 24; g = (pixel & 0x00ff0000) >> 16; b = (pixel & 0x0000ff00) >> 8; a = (pixel & 0x000000ff); } pixels += rowstride*y; if(n_channels == 3) { pixels += 3*x; pixels[0] = r; pixels[1] = g; pixels[2] = b; } else if(n_channels == 4) { pixels += 4*x; pixels[0] = r; pixels[1] = g; pixels[2] = b; pixels[3] = a; } } %% override gdk_pixbuf_fill_area PHP_METHOD { gint x, y, width, height; long pixel; GdkPixbuf *pixbuf; guchar *pixels; guint r, g, b, a; guchar *p; gint w, h; gint ix; int n_channels, rowstride; NOT_STATIC_METHOD(); if (ZEND_NUM_ARGS() == 8) { if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "iiiiiiii", &x, &y, &width, &height, &r, &g, &b, &a)) return; } else { if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "iiiii", &x, &y, &width, &height, &pixel)) return; } pixbuf = GDK_PIXBUF(PHPG_GOBJECT(this_ptr)); if(x < 0) { width = width-x; x = 0; } if(y < 0) { height = height-y; y = 0; } if ((w = gdk_pixbuf_get_width(pixbuf)) == 0 || (h = gdk_pixbuf_get_height(pixbuf)) == 0) { php_error(E_WARNING, "%s::%s() empty GdkPixbuf", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C)); return; } if(width < 0 || height < 0) { php_error(E_WARNING, "%s::%s() width < 0 || height < 0 out of range", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C),x,w,y,h); return; } if(x >= w || y >= h) { php_error(E_WARNING, "%s::%s() x_pos >= GdkPixbuf->width || y_pos >= GdkPixbuf->height out of range", get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C),x,w,y,h); return; } pixels = gdk_pixbuf_get_pixels(pixbuf); n_channels = gdk_pixbuf_get_n_channels(pixbuf); rowstride = gdk_pixbuf_get_rowstride(pixbuf); if (ZEND_NUM_ARGS() != 8) { r = (pixel & 0xff000000) >> 24; g = (pixel & 0x00ff0000) >> 16; b = (pixel & 0x0000ff00) >> 8; a = (pixel & 0x000000ff); } if(x+width < w) w = x+width; if(y+height < h) h = y+height; pixels += rowstride*y; for(y=y;y<h;y++) { p = pixels; if(n_channels == 3) { p += 3*x; for(ix=x;ix<w;ix++) { p[0] = r; p[1] = g; p[2] = b; p += 3; } } else if(n_channels == 4) { p += 4*x; for(ix=x;ix<w;ix++) { p[0] = r; p[1] = g; p[2] = b; p[3] = a; p += 4; } } pixels += rowstride; } } mfg xxoes -- Regards/MfG, Christian Weiske

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.gtk.dev (#2479) next »