📄 ming.c
字号:
/* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_01.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: dave@opaque.net | +----------------------------------------------------------------------+*/#include <stdio.h>#include <math.h>#ifdef HAVE_CONFIG_H#include "ming_config.h"#endif#include "php.h"#include "php_ming.h"#include "ext/standard/info.h"#include "ext/standard/file.h"#include "ext/standard/fsock.h"#if HAVE_MINGstatic zend_function_entry ming_functions[] = { PHP_FALIAS(ming_setcubicthreshold, ming_setCubicThreshold, NULL) PHP_FALIAS(ming_setscale, ming_setScale, NULL) PHP_FALIAS(ming_useswfversion, ming_useSWFVersion, NULL) PHP_FALIAS(swfbutton_keypress, swfbutton_keypress, NULL) PHP_FALIAS(ming_useconstants, ming_useConstants, NULL) { NULL, NULL, NULL }};static SWFMovie getMovie(zval *id TSRMLS_DC);static SWFFill getFill(zval *id TSRMLS_DC);static SWFGradient getGradient(zval *id TSRMLS_DC);static SWFBitmap getBitmap(zval *id TSRMLS_DC);static SWFShape getShape(zval *id TSRMLS_DC);static SWFFont getFont(zval *id TSRMLS_DC);static SWFFontCharacter getFontCharacter(zval *id TSRMLS_DC);static SWFText getText(zval *id TSRMLS_DC);static SWFTextField getTextField(zval *id TSRMLS_DC);static SWFDisplayItem getDisplayItem(zval *id TSRMLS_DC);static SWFButton getButton(zval *id TSRMLS_DC);static SWFAction getAction(zval *id TSRMLS_DC);static SWFMorph getMorph(zval *id TSRMLS_DC);static SWFMovieClip getSprite(zval *id TSRMLS_DC);static SWFSound getSound(zval *id TSRMLS_DC);static SWFSoundInstance getSoundInstance(zval *id TSRMLS_DC);static SWFVideoStream getVideoStream(zval *id TSRMLS_DC);/* {{{ proto void ming_setcubicthreshold (int threshold) Set cubic threshold (?) */PHP_FUNCTION(ming_setCubicThreshold){ zval **num; if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) WRONG_PARAM_COUNT; convert_to_long_ex(num); Ming_setCubicThreshold(Z_LVAL_PP(num));}/* }}} *//* {{{ proto void ming_setscale(int scale) Set scale (?) */PHP_FUNCTION(ming_setScale){ zval **num; if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) WRONG_PARAM_COUNT; convert_to_double_ex(num); Ming_setScale(Z_DVAL_PP(num));}/* }}} *//* {{{ proto void ming_useswfversion(int version) Use SWF version (?) */ PHP_FUNCTION(ming_useSWFVersion){ zval **num; if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) WRONG_PARAM_COUNT; convert_to_long_ex(num); Ming_useSWFVersion(Z_LVAL_PP(num));}/* }}} *//* {{{ proto void ming_useconstants(int use) Use constant pool (?) */ PHP_FUNCTION(ming_useConstants){ zval **num; if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) WRONG_PARAM_COUNT; convert_to_long_ex(num); Ming_useConstants(Z_LVAL_PP(num));}/* }}} */static int le_swfmoviep;static int le_swfshapep;static int le_swffillp;static int le_swfgradientp;static int le_swfbitmapp;static int le_swffontp;static int le_swffontcharp;static int le_swftextp;static int le_swftextfieldp;static int le_swfdisplayitemp;static int le_swfbuttonp;static int le_swfactionp;static int le_swfmorphp;static int le_swfspritep;static int le_swfinputp;static int le_swfsoundp;static int le_swfsoundinstancep;static int le_swfvideostreamp;zend_class_entry movie_class_entry;zend_class_entry shape_class_entry;zend_class_entry fill_class_entry;zend_class_entry gradient_class_entry;zend_class_entry bitmap_class_entry;zend_class_entry font_class_entry;zend_class_entry fontchar_class_entry;zend_class_entry text_class_entry;zend_class_entry textfield_class_entry;zend_class_entry displayitem_class_entry;zend_class_entry button_class_entry;zend_class_entry action_class_entry;zend_class_entry morph_class_entry;zend_class_entry sprite_class_entry;zend_class_entry sound_class_entry;zend_class_entry soundinstance_class_entry;zend_class_entry videostream_class_entry;/* {{{ internal function SWFgetProperty */static void *SWFgetProperty(zval *id, char *name, int namelen, int proptype TSRMLS_DC){ zval **tmp; int id_to_find; void *property; int type; if(id) { if(zend_hash_find(Z_OBJPROP_P(id), name, namelen+1, (void **)&tmp) == FAILURE) { php_error(E_WARNING, "unable to find property %s", name); return NULL; } id_to_find = Z_LVAL_PP(tmp); } else return NULL; property = zend_list_find(id_to_find, &type); if (!property || type != proptype) { php_error(E_WARNING, "unable to find identifier (%d)", id_to_find); return NULL; } return property;}/* }}} *//* {{{ SWFCharacter - not a real class *//* {{{ internal function SWFCharacter getCharacter(zval *id) Returns the SWFCharacter contained in zval *id */SWFCharacter getCharacter(zval *id TSRMLS_DC){ if(Z_OBJCE_P(id) == &shape_class_entry) return (SWFCharacter)getShape(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &font_class_entry) return (SWFCharacter)getFont(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &fontchar_class_entry) return (SWFCharacter)getFontCharacter(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &text_class_entry) return (SWFCharacter)getText(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &textfield_class_entry) return (SWFCharacter)getTextField(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &button_class_entry) return (SWFCharacter)getButton(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &morph_class_entry) return (SWFCharacter)getMorph(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &sprite_class_entry) return (SWFCharacter)getSprite(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &bitmap_class_entry) return (SWFCharacter)getBitmap(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &sound_class_entry) return (SWFCharacter)getSound(id TSRMLS_CC); else if(Z_OBJCE_P(id) == &videostream_class_entry) return (SWFCharacter)getVideoStream(id TSRMLS_CC);// else if(Z_OBJCE_P(id) == &soundinstance_class_entry)// return (SWFCharacter)getSoundInstance(id TSRMLS_CC); else php_error(E_ERROR, "called object is not an SWFCharacter"); return NULL;}/* }}} *//* }}} *//* {{{ getInput - utility func for making an SWFInput from an fopened resource */static void destroy_SWFInput_resource(zend_rsrc_list_entry *resource TSRMLS_DC){ destroySWFInput((SWFInput)resource->ptr);}/* not sure about the date to enter here.... */#if (ZEND_MODULE_API_NO > 20020429)static SWFInput getInput(zval **zfile TSRMLS_DC){ FILE *file; void *what; int type; SWFInput input; what = zend_fetch_resource(zfile TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream()); if (php_stream_cast((php_stream*)what, PHP_STREAM_AS_STDIO, (void *) &file, REPORT_ERRORS) != SUCCESS) { return NULL; } input = newSWFInput_file(file); zend_list_addref(Z_LVAL_PP(zfile)); zend_list_addref(zend_list_insert(input, le_swfinputp)); return input;}#else#define SOCKBUF_INCREMENT 10240/* turn a socket into an SWFInput by copying everything to a buffer. *//* not pretty, but it works */static SWFInput newSWFInput_sock(int socket){ char *buffer = NULL; int l, offset = 0, alloced = 0; do { if(offset <= alloced) { alloced += SOCKBUF_INCREMENT; buffer = realloc(buffer, alloced); } l = SOCK_FREAD(buffer+offset, SOCKBUF_INCREMENT, socket); offset += l; } while(l > 0); return newSWFInput_allocedBuffer(buffer, offset);}static SWFInput getInput(zval **zfile TSRMLS_DC){ FILE *file; int type; SWFInput input; file = (FILE *) zend_fetch_resource(zfile TSRMLS_CC, -1, "File-Handle", &type, 3, php_file_le_fopen(), php_file_le_popen(), php_file_le_socket()); if(type == php_file_le_socket()) input = newSWFInput_sock(*(int *)file); else { input = newSWFInput_file(file); zend_list_addref(Z_LVAL_PP(zfile)); } zend_list_addref(zend_list_insert(input, le_swfinputp)); return input;}#endif/* }}} *//* {{{ SWFAction */static zend_function_entry swfaction_functions[] = { PHP_FALIAS(swfaction, swfaction_init, NULL) { NULL, NULL, NULL }};/* {{{ proto object swfaction_init(string) Returns a new SWFAction object, compiling the given script */PHP_FUNCTION(swfaction_init){ SWFAction action; zval **script; int ret; if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &script) == FAILURE) WRONG_PARAM_COUNT; convert_to_string_ex(script); action = compileSWFActionCode(Z_STRVAL_PP(script)); if(!action) php_error(E_ERROR, "Couldn't compile actionscript."); ret = zend_list_insert(action, le_swfactionp); object_init_ex(getThis(), &action_class_entry); add_property_resource(getThis(), "action", ret); zend_list_addref(ret);}/* no destructor for SWFAction, it's not a character *//* }}} *//* {{{ internal function getAction Returns the SWFAction object contained in zval *id */static SWFAction getAction(zval *id TSRMLS_DC){ void *action = SWFgetProperty(id, "action", 6, le_swfactionp TSRMLS_CC); if(!action) php_error(E_ERROR, "called object is not an SWFAction!"); return (SWFAction)action;}/* }}} *//* }}} *//* {{{ SWFVideoStream */static zend_function_entry swfvideostream_functions[] = { PHP_FALIAS(swfvideostream, swfvideostream_init, NULL) PHP_FALIAS(setdimension, swfvideostream_setdimension, NULL) PHP_FALIAS(getnumframes, swfvideostream_getnumframes, NULL) { NULL, NULL, NULL }};/* {{{ proto class swfvideostream_init([file]) Returns a SWVideoStream object */PHP_FUNCTION(swfvideostream_init){ zval **zfile = NULL; SWFVideoStream stream; SWFInput input; int ret; switch(ZEND_NUM_ARGS()) { case 1: if(zend_get_parameters_ex(1, &zfile) == FAILURE) WRONG_PARAM_COUNT; if(Z_TYPE_PP(zfile) != IS_RESOURCE) { convert_to_string_ex(zfile); input = newSWFInput_buffer(Z_STRVAL_PP(zfile), Z_STRLEN_PP(zfile)); zend_list_addref(zend_list_insert(input, le_swfinputp)); } else input = getInput(zfile TSRMLS_CC); stream = newSWFVideoStream_fromInput(input); break; case 0: stream = newSWFVideoStream(); break; default: WRONG_PARAM_COUNT; break; } if(stream) { ret = zend_list_insert(stream, le_swfvideostreamp); object_init_ex(getThis(), &videostream_class_entry); add_property_resource(getThis(), "videostream", ret); zend_list_addref(ret); } } static void destroy_SWFVideoStream_resource(zend_rsrc_list_entry *resource TSRMLS_DC){ destroySWFVideoStream((SWFVideoStream)resource->ptr);}/* }}} *//* {{{ internal function getVideoStream Returns the SWFVideoStream object contained in zval *id */ static SWFVideoStream getVideoStream(zval *id TSRMLS_DC){ void *stream = SWFgetProperty(id, "videostream", 11, le_swfvideostreamp TSRMLS_CC); if(!stream) php_error(E_ERROR, "called object is not an SWFVideoStream!"); return (SWFVideoStream)stream;}/* }}} *//* {{{ setDimension */PHP_FUNCTION(swfvideostream_setdimension){ zval **x, **y; SWFVideoStream stream = getVideoStream(getThis() TSRMLS_CC); if(!stream) php_error(E_ERROR, "getVideoSTream returned NULL"); if( ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &x, &y) == FAILURE ) WRONG_PARAM_COUNT; convert_to_long_ex(x); convert_to_long_ex(y); SWFVideoStream_setDimension(stream, Z_LVAL_PP(x), Z_LVAL_PP(y));}/* }}} *//* {{{ getNumFrames */PHP_FUNCTION(swfvideostream_getnumframes) { if(ZEND_NUM_ARGS() != 0) WRONG_PARAM_COUNT; RETURN_LONG(SWFVideoStream_getNumFrames(getVideoStream(getThis() TSRMLS_CC)));}/* }}} */ /* }}} *//* {{{ SWFBitmap */static zend_function_entry swfbitmap_functions[] = { PHP_FALIAS(swfbitmap, swfbitmap_init, NULL) PHP_FALIAS(getwidth, swfbitmap_getWidth, NULL) PHP_FALIAS(getheight, swfbitmap_getHeight, NULL) { NULL, NULL, NULL }};/* {{{ proto class swfbitmap_init(file [, maskfile]) Returns a new SWFBitmap object from jpg (with optional mask) or dbl file */PHP_FUNCTION(swfbitmap_init){ zval **zfile, **zmask = NULL; SWFBitmap bitmap; SWFInput input, maskinput; int ret;//fprintf(stderr, "newSWFBitmap_fromInput %x %d\n", newSWFBitmap_fromInput, getpid()); sleep(30); if(ZEND_NUM_ARGS() == 1) { if(zend_get_parameters_ex(1, &zfile) == FAILURE) WRONG_PARAM_COUNT; } else if(ZEND_NUM_ARGS() == 2) { if(zend_get_parameters_ex(2, &zfile, &zmask) == FAILURE) WRONG_PARAM_COUNT; } else WRONG_PARAM_COUNT; if(Z_TYPE_PP(zfile) != IS_RESOURCE) { convert_to_string_ex(zfile); input = newSWFInput_buffer(Z_STRVAL_PP(zfile), Z_STRLEN_PP(zfile)); zend_list_addref(zend_list_insert(input, le_swfinputp)); } else input = getInput(zfile TSRMLS_CC); if(zmask != NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -