CVS update: php3/functions

From: Date: Thu, 25 Feb 1999 16:31:34 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4288@lists.php.net to get a copy of this message
Date: Thursday February 25, 1999 @ 11:31 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv8216 Modified Files: magick.c php3_magick.h Log Message: added free call moved include "magick.h" into magick.c (instead of php3_magick.h) 'cause of clashed in internal_functions.c Index: php3/functions/magick.c diff -c php3/functions/magick.c:1.2 php3/functions/magick.c:1.3 *** php3/functions/magick.c:1.2 Thu Feb 25 09:57:32 1999 --- php3/functions/magick.c Thu Feb 25 11:31:34 1999 *************** *** 27,40 **** +----------------------------------------------------------------------+ */ ! /* $Id: magick.c,v 1.2 1999/02/25 14:57:32 thies Exp $ */ /* TODO list: * * - make this thing work! * - error and warning handler * - redirect stdout ! * - error-handling & memory leaks.... */ /* {{{ includes & stuff */ --- 27,40 ---- +----------------------------------------------------------------------+ */ ! /* $Id: magick.c,v 1.3 1999/02/25 16:31:34 thies Exp $ */ /* TODO list: * * - make this thing work! * - error and warning handler * - redirect stdout ! * - Error/Warning Handlers are dodgy.... */ /* {{{ includes & stuff */ *************** *** 59,64 **** --- 59,87 ---- #include "head.h" #include "php3_magick.h" + /* XXX i would love to see that in php3_magick.h - but i'm not able to compile the internal_functions then!!! */ + + #include "magick.h" + + #define MAGICK_IMAGE_TYPE(x) ((x)==MAGICK_GLOBAL(php3_magick_module).le_image) + + typedef struct { + int id; + ImageInfo ImageInfo; + } magick_imageinfo; + + typedef struct { + int id; + magick_imageinfo *info; + Image *Image; + } magick_image; + + typedef struct { + long debug_mode; + int le_imageinfo; + int le_image; + } magick_module; + /* }}} */ /* {{{ thread safety stuff */ *************** *** 123,146 **** static void magick_debug(int level,const char *format,...); static void magick_free_imageinfo(magick_imageinfo *imageinfo); static void magick_free_image(magick_image *image); ! /* }}} */ /* {{{ extension function prototypes */ void php3_ReadMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_SaveMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_SizeMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_MagickDebug(INTERNAL_FUNCTION_PARAMETERS); /* }}} */ /* {{{ extension definition structures */ #define D_IMAGEINFO 1<<1 #define D_IMAGE 1<<2 function_entry magick_functions[] = { {"readmagick", php3_ReadMagick, NULL}, {"savemagick", php3_SaveMagick, NULL}, {"sizemagick", php3_SizeMagick, NULL}, {"magickdebug", php3_MagickDebug, NULL}, {NULL, NULL, NULL} --- 146,174 ---- static void magick_debug(int level,const char *format,...); static void magick_free_imageinfo(magick_imageinfo *imageinfo); static void magick_free_image(magick_image *image); ! static void magick_errorhandler(const unsigned int error,const char *message,const char *qualifier); ! static void magick_warninghandler(const unsigned int error,const char *message,const char *qualifier); /* }}} */ /* {{{ extension function prototypes */ void php3_ReadMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_SaveMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_SizeMagick(INTERNAL_FUNCTION_PARAMETERS); + void php3_FreeMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_MagickDebug(INTERNAL_FUNCTION_PARAMETERS); /* }}} */ /* {{{ extension definition structures */ + + #define D_IMAGEINFO 1<<1 #define D_IMAGE 1<<2 function_entry magick_functions[] = { {"readmagick", php3_ReadMagick, NULL}, {"savemagick", php3_SaveMagick, NULL}, + {"freemagick", php3_FreeMagick, NULL}, {"sizemagick", php3_SizeMagick, NULL}, {"magickdebug", php3_MagickDebug, NULL}, {NULL, NULL, NULL} *************** *** 201,206 **** --- 229,237 ---- REGISTER_LONG_CONSTANT("DEBUG_IMAGEINFO",D_IMAGEINFO, CONST_CS | CONST_PERSISTENT); + SetWarningHandler(magick_warninghandler); + SetErrorHandler(magick_errorhandler); + return SUCCESS; } *************** *** 266,272 **** va_end(args); buffer[sizeof(buffer)-1] = '\0'; if (php3_header()) { ! php3_printf("MAGICKDebug: %s<br>\n", buffer); } } } --- 297,303 ---- va_end(args); buffer[sizeof(buffer)-1] = '\0'; if (php3_header()) { ! php3_printf("ImageMagick: %s<br>\n", buffer); } } } *************** *** 292,300 **** { MAGICK_TLS_VARS; ! DestroyImage(image->image); ! magick_debug(D_IMAGE,"Free Image %d -> %x",image->id,image->image); efree(image); } --- 323,331 ---- { MAGICK_TLS_VARS; ! DestroyImage(image->Image); ! magick_debug(D_IMAGE,"Free Image %d -> %x",image->id,image->Image); efree(image); } *************** *** 318,323 **** --- 349,387 ---- } /* }}} */ + /* {{{ magick_errorhandler() */ + static void + magick_errorhandler(const unsigned int error,const char *message,const char *qualifier) + { + int error_number; + + error_number=errno; + errno=0; + + php3_error(E_WARNING,"ImageMagick Error %d: %.1024s%s%.1024s%s%s%.64s%s",error, + (message ? message : "ERROR"), + qualifier ? " (" : "",qualifier ? qualifier : "",qualifier ? ")" : "", + error_number ? " [" : "",error_number ? strerror(error_number) : "", + error_number? "]" : ""); + } + /* }}} */ + /* {{{ magick_warninghandler() */ + static void + magick_warninghandler(const unsigned int error,const char *message,const char *qualifier) + { + int error_number; + + error_number=errno; + errno=0; + + php3_error(E_WARNING,"ImageMagick Warning %d: %.1024s%s%.1024s%s%s%.64s%s",error, + (message ? message : "ERROR"), + qualifier ? " (" : "",qualifier ? qualifier : "",qualifier ? ")" : "", + error_number ? " [" : "",error_number ? strerror(error_number) : "", + error_number? "]" : ""); + } + /* }}} */ + /************************* EXTENSION FUNCTIONS *************************/ /* {{{ proto object ReadMagick(string filename) Load an Image */ *************** *** 344,356 **** RETURN_FALSE; /* out of memory */ } ! GetImageInfo(&imageinfo->imageinfo); imageinfo->id = php3_list_insert(imageinfo, MAGICK_GLOBAL(php3_magick_module).le_imageinfo); magick_debug(D_IMAGEINFO,"New ImageInfo %d -> %x",imageinfo->id,imageinfo); ! strcpy(imageinfo->imageinfo.filename,filename->value.str.val); image = emalloc(sizeof(magick_image)); --- 408,420 ---- RETURN_FALSE; /* out of memory */ } ! GetImageInfo(&imageinfo->ImageInfo); imageinfo->id = php3_list_insert(imageinfo, MAGICK_GLOBAL(php3_magick_module).le_imageinfo); magick_debug(D_IMAGEINFO,"New ImageInfo %d -> %x",imageinfo->id,imageinfo); ! strcpy(imageinfo->ImageInfo.filename,filename->value.str.val); image = emalloc(sizeof(magick_image)); *************** *** 358,378 **** RETURN_FALSE; /* out of memory */ } ! image->image = ReadImage(&imageinfo->imageinfo); image->info = imageinfo; ! if (! image->image) { RETURN_FALSE; /* print some ImageMagick error here */ } image->id = php3_list_insert(image, MAGICK_GLOBAL(php3_magick_module).le_image); ! magick_debug(D_IMAGE,"New Image %d -> %x",image->id,image->image); object_init(return_value); add_property_long(return_value, "_imageinfo", imageinfo->id); ! add_property_long(return_value, "_image", image->id ); add_method(return_value, "save", php3_SaveMagick); } /* }}} */ --- 422,455 ---- RETURN_FALSE; /* out of memory */ } ! image->Image = ReadImage(&imageinfo->ImageInfo); image->info = imageinfo; ! if (! image->Image) { RETURN_FALSE; /* print some ImageMagick error here */ } image->id = php3_list_insert(image, MAGICK_GLOBAL(php3_magick_module).le_image); ! magick_debug(D_IMAGE,"New Image %d -> %x",image->id,image->Image); object_init(return_value); add_property_long(return_value, "_imageinfo", imageinfo->id); ! add_property_long(return_value, "_image", image->id); ! ! ! add_property_long(return_value, "filesize", image->Image->filesize); ! add_property_long(return_value, "columns", image->Image->columns); ! add_property_long(return_value, "rows", image->Image->rows); ! add_property_long(return_value, "depth", image->Image->depth); ! add_property_long(return_value, "colors", image->Image->colors); ! add_property_double(return_value,"x_resolution", image->Image->x_resolution); ! add_property_double(return_value,"y_resolution", image->Image->y_resolution); ! add_property_long(return_value, "total_colors", image->Image->total_colors); ! ! add_method(return_value, "save", php3_SaveMagick); + add_method(return_value, "free", php3_FreeMagick); } /* }}} */ *************** *** 407,420 **** if (image == NULL) { RETURN_FALSE; } ! strcpy(savename,image->image->filename); ! strcpy(image->image->filename,filename->value.str.val); ! WriteImage(&(image->info->imageinfo),image->image); ! strcpy(image->image->filename,savename); RETURN_TRUE; } --- 484,527 ---- if (image == NULL) { RETURN_FALSE; } + + strcpy(savename,image->Image->filename); + + strcpy(image->Image->filename,filename->value.str.val); + + WriteImage(&(image->info->ImageInfo),image->Image); + + strcpy(image->Image->filename,savename); + + RETURN_TRUE; + } + /* }}} */ + /* {{{ proto int FreeMagick(object image) + Free an Image */ + void php3_FreeMagick(INTERNAL_FUNCTION_PARAMETERS) + { + pval *id, *pimage; + magick_image *image; + MAGICK_TLS_VARS; + + if (getThis(&id) == FAILURE) { + RETURN_FALSE; + } ! if (_php3_hash_find(id->value.ht, "_image", sizeof("_image"), (void **)&pimage) == FAILURE) { ! php3_error(E_WARNING, "unable to find my image property"); ! RETURN_FALSE; ! } ! image = magick_get_image(pimage->value.lval, "FreeMagick", list); ! if (image == NULL) { ! RETURN_FALSE; ! } ! php3_list_delete(image->info->id); ! php3_list_delete(image->id); ! /* XXX how do i free the object itself????? */ RETURN_TRUE; } Index: php3/functions/php3_magick.h diff -c php3/functions/php3_magick.h:1.3 php3/functions/php3_magick.h:1.4 *** php3/functions/php3_magick.h:1.3 Thu Feb 25 11:07:35 1999 --- php3/functions/php3_magick.h Thu Feb 25 11:31:34 1999 *************** *** 28,34 **** */ ! /* $Id: php3_magick.h,v 1.3 1999/02/25 16:07:35 rasmus Exp $ */ #ifndef _PHP3_MAGICK_H #define _PHP3_MAGICK_H --- 28,34 ---- */ ! /* $Id: php3_magick.h,v 1.4 1999/02/25 16:31:34 thies Exp $ */ #ifndef _PHP3_MAGICK_H #define _PHP3_MAGICK_H *************** *** 36,68 **** #if HAVE_MAGICK extern php3_module_entry magick_module_entry; # define magick_module_ptr &magick_module_entry - - #include "magick.h" - - #define MAGICK_IMAGE_TYPE(x) ((x)==MAGICK_GLOBAL(php3_magick_module).le_image) - - typedef struct { - int id; - ImageInfo imageinfo; - } magick_imageinfo; - - typedef struct { - int id; - magick_imageinfo *info; - Image *image; - } magick_image; - - typedef struct { - long debug_mode; - int le_imageinfo; - int le_image; - } magick_module; - # else # define magick_module_ptr NULL # endif #endif /* _PHP3_MAGICK_H */ /* * Local variables: * tab-width: 4 --- 36,47 ---- #if HAVE_MAGICK extern php3_module_entry magick_module_entry; # define magick_module_ptr &magick_module_entry # else # define magick_module_ptr NULL # endif #endif /* _PHP3_MAGICK_H */ + /* i had to remove include "magick.h" from here, cause it may clash some stuff in internal functions! */ /* * Local variables: * tab-width: 4 -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#4288) next »