CVS update: php3/functions
| From: | thies | Date: | Thu, 25 Feb 1999 14:57:33 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-4281@lists.php.net to get a copy of this message | ||
Date: Thursday February 25, 1999 @ 9:57
Author: thies
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv1579/functions
Modified Files:
magick.c php3_magick.h
Log Message:
implemented ReadMagick function and "save" method
Index: php3/functions/magick.c
diff -c php3/functions/magick.c:1.1 php3/functions/magick.c:1.2
*** php3/functions/magick.c:1.1 Thu Feb 25 07:17:02 1999
--- php3/functions/magick.c Thu Feb 25 09:57:32 1999
***************
*** 27,122 ****
+----------------------------------------------------------------------+
*/
! /* $Id: magick.c,v 1.1 1999/02/25 12:17:02 thies Exp $ */
/* TODO list:
*
* - make this thing work!
*/
/* {{{ includes & stuff */
! #include <stdlib.h>
! #include <ctype.h>
! #include <stdio.h>
! #ifdef THREAD_SAFE
! #include "tls.h"
#endif
#include "php.h"
- #ifndef MSVC5
- #include "build-defs.h"
- #endif
#include "internal_functions.h"
- #include "php3_list.h"
#if HAVE_MAGICK
#include "php3_magick.h"
- #include "magick.h"
/* }}} */
! /* {{{ thread safety stuff */
int php3_minit_magick(INIT_FUNC_ARGS);
void php3_info_magick(void);
! void php3_readimage(INTERNAL_FUNCTION_PARAMETERS);
function_entry magick_functions[] = {
! {"readimage", php3_readimage, NULL},
{NULL, NULL, NULL}
};
- int le_magick;
-
php3_module_entry magick_module_entry = {
! "Magick", magick_functions, php3_minit_magick, NULL, NULL, NULL, php3_info_magick,
STANDARD_MODULE_PROPERTIES
};
! #if COMPILE_DL
! DLEXPORT php3_module_entry *get_module(void) { return &php3_magick_module_entry; }
! #endif
int php3_minit_magick(INIT_FUNC_ARGS)
{
return SUCCESS;
}
! void php3_info_magick(void)
{
! TLS_VARS;
! php3_printf("Magick support enabled");
}
- /* }}} */
/************************* INTERNAL FUNCTIONS *************************/
! /************************* EXTENSION FUNCTIONS *************************/
! /* {{{ proto int readimage(string filename)
Load an Image */
! void php3_readimage(INTERNAL_FUNCTION_PARAMETERS)
{
pval *filename;
! ImageInfo *info;
! Image *image;
! if (getParameters(ht, 1, &filename) == FAILURE) {
WRONG_PARAM_COUNT;
! }
! convert_to_string(filename);
! if (_php3_check_open_basedir(filename->value.str.val))
RETURN_FALSE;
! info = emalloc(sizeof(ImageInfo));
!
! strcpy(info->filename,filename->value.str.val);
! image = ReadImage(info);
}
/* }}} */
#endif /* HAVE_MAGICK */
--- 27,456 ----
+----------------------------------------------------------------------+
*/
! /* $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 */
! #if defined(COMPILE_DL)
! # ifdef THREAD_SAFE
! # undef THREAD_SAFE /* XXX no need in 3.0 */
! # endif
! # include "dl/phpdl.h"
#endif
+
#include "php.h"
#include "internal_functions.h"
#if HAVE_MAGICK
+ #if !(WIN32|WINNT)
+ # include "build-defs.h"
+ #endif
+
+ #include "php3_list.h"
+ #include "head.h"
#include "php3_magick.h"
/* }}} */
+ /* {{{ thread safety stuff */
+
+ #ifdef THREAD_SAFE
+ # define MAGICK_GLOBAL(a) magick_globals->a
+ # define MAGICK_TLS_VARS magick_global_struct *magick_globals = TlsGetValue(MAGICKTls);
+ void *magick_mutex;
+ DWORD MAGICKTls;
+ static int numthreads=0;
+
+ typedef struct magick_global_struct {
+ magick_module php3_magick_module;
+ } magick_global_struct;
+ #else /* !defined(THREAD_SAFE) */
+ # define MAGICK_GLOBAL(a) a
+ # define MAGICK_TLS_VARS
+ magick_module php3_magick_module;
+ #endif /* defined(THREAD_SAFE) */
+
+ /* }}} */
+ /* {{{ dynamically loadable module stuff */
+
+ #if COMPILE_DL
+ DLEXPORT php3_module_entry *get_module() { return &magick_module_entry; };
+
+ # if (WIN32|WINNT) && defined(THREAD_SAFE)
+ /* NOTE: You should have an magick.def file where you export DllMain */
+ BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call,
+ LPVOID lpReserved)
+ {
+ switch (ul_reason_for_call) {
+ case DLL_PROCESS_ATTACH:
+ if ((MAGICKTls = TlsAlloc()) == 0xFFFFFFFF){
+ return 0;
+ }
+ break;
+ case DLL_THREAD_ATTACH:
+ break;
+ case DLL_THREAD_DETACH:
+ break;
+ case DLL_PROCESS_DETACH:
+ if (!TlsFree(MAGICKTls)) {
+ return 0;
+ }
+ break;
+ }
+ return 1;
+ }
! # endif /* thread safe on Windows */
! #endif /* COMPILE_DL */
!
! /* }}} */
! /* {{{ startup/shutdown/info/internal function prototypes */
!
int php3_minit_magick(INIT_FUNC_ARGS);
+ int php3_rinit_magick(INIT_FUNC_ARGS);
+ int php3_mshutdown_magick(void);
+ int php3_rshutdown_magick(void);
void php3_info_magick(void);
! static magick_image *magick_get_image(int, const char *, HashTable *);
! 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}
};
php3_module_entry magick_module_entry = {
! "Magick", /* extension name */
! magick_functions, /* extension function list */
! php3_minit_magick, /* extension-wide startup function */
! php3_mshutdown_magick, /* extension-wide shutdown function */
! php3_rinit_magick, /* per-request startup function */
! php3_rshutdown_magick, /* per-request shutdown function */
! php3_info_magick, /* information function */
! STANDARD_MODULE_PROPERTIES
};
! /* }}} */
! /* {{{ startup, shutdown and info functions */
int php3_minit_magick(INIT_FUNC_ARGS)
{
+ #ifdef THREAD_SAFE
+ magick_global_struct *magick_globals;
+ # if !COMPILE_DL
+ # if WIN32|WINNT
+ CREATE_MUTEX(magick_mutex,"MAGICK_TLS");
+ # endif
+ SET_MUTEX(magick_mutex);
+ numthreads++;
+ if (numthreads == 1) {
+ if ((MAGICKTls = TlsAlloc()) == 0xFFFFFFFF){
+ FREE_MUTEX(magick_mutex);
+ return 0;
+ }
+ }
+ FREE_MUTEX(magick_mutex);
+ # endif /* !COMPILE_DL */
+ magick_globals =
+ (magick_global_struct *) LocalAlloc(LPTR, sizeof(magick_global_struct));
+ TlsSetValue(MAGICKTls, (void *) magick_globals);
+ #endif /* THREAD_SAFE */
+
+ #if NEEDED
+ if (cfg_get_long("oci8.allow_persistent",
+ &OCI8_GLOBAL(php3_oci8_module).allow_persistent)
+ == FAILURE) {
+ OCI8_GLOBAL(php3_oci8_module).allow_persistent = -1;
+ }
+ #endif
+ MAGICK_GLOBAL(php3_magick_module).debug_mode = 0;
+
+ MAGICK_GLOBAL(php3_magick_module).le_imageinfo =
+ register_list_destructors(magick_free_imageinfo, NULL);
+
+ MAGICK_GLOBAL(php3_magick_module).le_image =
+ register_list_destructors(magick_free_image, NULL);
+
+
+ REGISTER_LONG_CONSTANT("DEBUG_IMAGEINFO",D_IMAGEINFO, CONST_CS | CONST_PERSISTENT);
+
return SUCCESS;
}
! int php3_rinit_magick(INIT_FUNC_ARGS)
{
! MAGICK_TLS_VARS;
!
! #if NEEDED
! MAGICK_GLOBAL(php3_magick_module).num_links =
! #endif
+ return SUCCESS;
}
+ int php3_mshutdown_magick()
+ {
+ #ifdef THREAD_SAFE
+ magick_global_struct *magick_globals;
+ magick_globals = TlsGetValue(MAGICKTls);
+ if (magick_globals != 0) {
+ LocalFree((HLOCAL) magick_globals);
+ }
+ #if !COMPILE_DL
+ SET_MUTEX(magick_mutex);
+ numthreads--;
+ if (!numthreads) {
+ if (!TlsFree(MAGICKTls)) {
+ FREE_MUTEX(magick_mutex);
+ return 0;
+ }
+ }
+ FREE_MUTEX(magick_mutex);
+ #endif
+ #endif
+ return SUCCESS;
+ }
+
+ int php3_rshutdown_magick()
+ {
+ return SUCCESS;
+ }
+
+ void php3_info_magick()
+ {
+ #if !(WIN32|WINNT)
+ php3_printf("ImageMagick support enabled");
+ #endif
+ }
+ /* }}} */
/************************* INTERNAL FUNCTIONS *************************/
+ /* {{{ magick_debug() */
+ static void magick_debug(int level,const char *format,...)
+ {
+ MAGICK_TLS_VARS;
! if (MAGICK_GLOBAL(php3_magick_module).debug_mode & level) {
! char buffer[1024];
! va_list args;
!
! va_start(args, format);
! vsnprintf(buffer, sizeof(buffer)-1, format, args);
! va_end(args);
! buffer[sizeof(buffer)-1] = '\0';
! if (php3_header()) {
! php3_printf("MAGICKDebug: %s<br>\n", buffer);
! }
! }
! }
!
! /* }}} */
! /* {{{ magick_free_imageinfo() */
!
! static void
! magick_free_imageinfo(magick_imageinfo *imageinfo)
! {
! MAGICK_TLS_VARS;
!
! magick_debug(D_IMAGEINFO,"Free ImageInfo %d -> %x",imageinfo->id,imageinfo);
! efree(imageinfo);
! }
!
! /* }}} */
! /* {{{ magick_free_image() */
!
! static void
! magick_free_image(magick_image *image)
! {
! MAGICK_TLS_VARS;
!
! DestroyImage(image->image);
!
! magick_debug(D_IMAGE,"Free Image %d -> %x",image->id,image->image);
!
! efree(image);
! }
!
! /* }}} */
! /* {{{ magick_get_image() */
!
! static magick_image *
! magick_get_image(int image_id, const char *func, HashTable *list)
! {
! int type;
! magick_image *image;
! MAGICK_TLS_VARS;
!
! image = (magick_image *)php3_list_find(image_id, &type);
! if (!image || !MAGICK_IMAGE_TYPE(type)) {
! php3_error(E_WARNING, "%s: invalid image %d", func, image_id);
! return (magick_image *)NULL;
! }
! return image;
! }
!
! /* }}} */
! /************************* EXTENSION FUNCTIONS *************************/
! /* {{{ proto object ReadMagick(string filename)
Load an Image */
!
! void php3_ReadMagick(INTERNAL_FUNCTION_PARAMETERS)
{
pval *filename;
! magick_imageinfo *imageinfo;
! magick_image *image;
! MAGICK_TLS_VARS;
!
! if (getParameters(ht, 1, &filename) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
! convert_to_string(filename);
!
! if (_php3_check_open_basedir(filename->value.str.val)) {
! RETURN_FALSE;
! }
!
! imageinfo = emalloc(sizeof(magick_imageinfo));
!
! if (! imageinfo) {
! 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));
!
! if (! image) {
! 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);
! }
!
! /* }}} */
! /* {{{ proto object SaveMagick(string filename)
! Save an Image */
! void php3_SaveMagick(INTERNAL_FUNCTION_PARAMETERS)
! {
! pval *filename, *id, *pimage;
! magick_image *image;
! char savename[ MAXPATHLEN ];
! MAGICK_TLS_VARS;
!
! if (getParameters(ht, 1, &filename) == FAILURE) {
WRONG_PARAM_COUNT;
! }
! convert_to_string(filename);
! if (_php3_check_open_basedir(filename->value.str.val)) {
! RETURN_FALSE;
! }
! 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, "SaveMagick", list);
! 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 SizeMagick(object image)
! Crop an Image */
! void php3_SizeMagick(INTERNAL_FUNCTION_PARAMETERS)
! {
! RETURN_TRUE;
}
/* }}} */
+ /* {{{ proto int MagickDebug(int level)
+ Crop an Image */
+ void php3_MagickDebug(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ pval *arg;
+ int oldlevel;
+ MAGICK_TLS_VARS;
+ if (getParameters(ht, 1, &arg) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long(arg);
+ oldlevel = MAGICK_GLOBAL(php3_magick_module).debug_mode;
+
+ MAGICK_GLOBAL(php3_magick_module).debug_mode = arg->value.lval;
+
+ RETURN_LONG(oldlevel);
+ }
+ /* }}} */
+
#endif /* HAVE_MAGICK */
+
+ /*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
Index: php3/functions/php3_magick.h
diff -c php3/functions/php3_magick.h:1.1 php3/functions/php3_magick.h:1.2
*** php3/functions/php3_magick.h:1.1 Thu Feb 25 07:17:03 1999
--- php3/functions/php3_magick.h Thu Feb 25 09:57:32 1999
***************
*** 28,41 ****
*/
! /* $Id: php3_magick.h,v 1.1 1999/02/25 12:17:03 thies Exp $ */
#ifndef _PHP3_MAGICK_H
! #define _PHP3_MAGICK_H
! #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 */
--- 28,71 ----
*/
! /* $Id: php3_magick.h,v 1.2 1999/02/25 14:57:32 thies Exp $ */
#ifndef _PHP3_MAGICK_H
! #define _PHP3_MAGICK_H
!
! #if HAVE_MAGICK
! extern php3_module_entry magick_module_entry;
! # define magick_module_ptr &magick_module_entry
! # else
! # define magick_module_ptr NULL
! # endif
!
! #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;
!
#endif /* _PHP3_MAGICK_H */
+
+ /*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
--
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