2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2008 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Author: Yoshihiro Yamazaki <yoya@awm.jp> |
16 +----------------------------------------------------------------------+
27 #include "ext/standard/info.h"
28 #include "php_swfed.h"
30 #include "swf_define.h"
31 #include "y_keyvalue.h"
32 #include "bitmap_util.h"
34 #include "swf_tag_jpeg.h"
35 #include "swf_tag_lossless.h"
36 #include "swf_tag_edit.h"
37 #include "swf_tag_sound.h"
38 #include "swf_tag_action.h"
39 #include "swf_tag_sprite.h"
40 #include "swf_tag_shape.h"
41 #include "swf_tag_place.h"
43 #include "swf_object.h"
45 #define SWFED_VERSION "0.63a"
47 #define get_zend_hash_value_long(table, key, value) do { \
49 if (zend_hash_find(table, key, sizeof(key), (void**)&tmp) == SUCCESS) { \
50 convert_to_long_ex(tmp); \
51 value = Z_LVAL_PP(tmp); \
55 #define get_zend_hash_value_boolean(table, key, value) do { \
57 if (zend_hash_find(table, key, sizeof(key), (void**)&tmp) == SUCCESS) { \
58 convert_to_boolean_ex(tmp); \
59 value = Z_LVAL_PP(tmp); \
64 param_is_null(int n TSRMLS_DC) {
66 zend_parse_parameters(n TSRMLS_CC, "z", &p);
67 if(Z_TYPE_P(p) == IS_NULL) {
74 /* If you declare any globals in php_swfed.h uncomment this:
75 ZEND_DECLARE_MODULE_GLOBALS(swfed)
78 /* True global resources - no need for thread safety here */
81 /* {{{ swfed_functions[]
83 * Every user visible function must have an entry in swfed_functions[].
85 zend_function_entry swfed_functions[] = {
86 PHP_ME(swfed, __construct, NULL, 0)
87 PHP_ME(swfed, input, NULL, 0)
88 PHP_ME(swfed, output, NULL, 0)
89 PHP_ME(swfed, swfInfo, NULL, 0)
90 PHP_ME(swfed, _destroy_and_exit, NULL, 0) // for debug
92 PHP_ME(swfed, getHeaderInfo, NULL, 0)
93 PHP_ME(swfed, setHeaderInfo, NULL, 0)
94 PHP_ME(swfed, getTagList, NULL, 0)
95 PHP_ME(swfed, getTagDetail, NULL, 0)
96 PHP_ME(swfed, getTagData, NULL, 0)
97 PHP_ME(swfed, replaceTagData, NULL, 0)
98 PHP_ME(swfed, getTagDataByCID, NULL, 0)
99 PHP_ME(swfed, replaceTagDataByCID, NULL, 0)
100 PHP_ME(swfed, getTagContentsByCID, NULL, 0)
101 PHP_ME(swfed, replaceTagContentsByCID, NULL, 0)
102 PHP_ME(swfed, removeTag, NULL, 0)
103 PHP_ME(swfed, printTagData, NULL, 0)
105 PHP_ME(swfed, getShapeData, NULL, 0)
106 PHP_ME(swfed, replaceShapeData, NULL, 0)
107 PHP_ME(swfed, setShapeAdjustMode, NULL, 0)
108 PHP_ME(swfed, getShapeIdListByBitmapRef, NULL, 0)
109 PHP_ME(swfed, getBitmapSize, NULL, 0)
110 PHP_ME(swfed, getJpegData, NULL, 0)
111 PHP_ME(swfed, getJpegAlpha, NULL, 0)
112 PHP_ME(swfed, replaceJpegData, NULL, 0)
113 PHP_ME(swfed, getPNGData, NULL, 0)
114 PHP_ME(swfed, replacePNGData, NULL, 0)
115 PHP_ME(swfed, replaceGIFData, NULL, 0)
116 PHP_ME(swfed, replaceBitmapData, NULL, 0)
117 PHP_ME(swfed, convertBitmapDataToJpegTag, NULL, 0)
118 PHP_ME(swfed, applyShapeMatrixFactor, NULL, 0)
119 PHP_ME(swfed, applyShapeRectFactor, NULL, 0)
120 PHP_ME(swfed, getSoundData, NULL, 0)
121 PHP_ME(swfed, replaceMLDData, NULL, 0)
122 PHP_ME(swfed, getEditString, NULL, 0)
123 PHP_ME(swfed, replaceEditString, NULL, 0)
124 PHP_ME(swfed, getActionData, NULL, 0)
125 PHP_ME(swfed, disasmActionData, NULL, 0)
126 PHP_ME(swfed, setActionVariables, NULL, 0)
127 PHP_ME(swfed, replaceActionStrings, NULL, 0)
128 PHP_ME(swfed, replaceMovieClip, NULL, 0)
130 PHP_ME(swfed, setCompressLevel, NULL, 0)
131 PHP_ME(swfed, rebuild, NULL, 0)
132 PHP_ME(swfed, purgeUselessContents, NULL, 0)
134 PHP_ME(swfed, isShapeTagData, NULL, 0)
135 PHP_ME(swfed, isBitmapTagData, NULL, 0)
136 {NULL, NULL, NULL} /* Must be the last line in swfed_functions[] */
140 /* {{{ swfed_module_entry
142 zend_module_entry swfed_module_entry = {
143 #if ZEND_MODULE_API_NO >= 20010901
144 STANDARD_MODULE_HEADER,
147 NULL, // no global functions
149 PHP_MSHUTDOWN(swfed),
150 PHP_RINIT(swfed), /* Replace with NULL if there's nothing to do at request start */
151 PHP_RSHUTDOWN(swfed), /* Replace with NULL if there's nothing to do at request end */
153 #if ZEND_MODULE_API_NO >= 20010901
154 SWFED_VERSION, /* Replace with version number for your extension */
156 STANDARD_MODULE_PROPERTIES
160 #ifdef COMPILE_DL_SWFED
161 ZEND_GET_MODULE(swfed)
166 /* Remove comments and fill if you need to have entries in php.ini
168 STD_PHP_INI_ENTRY("swfed.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_swfed_globals, swfed_globals)
169 STD_PHP_INI_ENTRY("swfed.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_swfed_globals, swfed_globals)
174 /* {{{ php_swfed_init_globals
176 /* Uncomment this function if you have INI entries
177 static void php_swfed_init_globals(zend_swfed_globals *swfed_globals)
179 swfed_globals->global_value = 0;
180 swfed_globals->global_string = NULL;
186 static void free_swfed_resource(zend_rsrc_list_entry *resource TSRMLS_DC);
187 static swf_object_t *get_swf_object(zval *obj TSRMLS_DC);
189 /* {{{ PHP_MINIT_FUNCTION
191 PHP_MINIT_FUNCTION(swfed)
193 /* If you have INI entries, uncomment these lines
194 ZEND_INIT_MODULE_GLOBALS(swfed, php_swfed_init_globals, NULL);
195 REGISTER_INI_ENTRIES();
198 INIT_CLASS_ENTRY(ce, "SWFEditor", swfed_functions);
199 swfeditor_ce = zend_register_internal_class(&ce TSRMLS_CC);
200 le_swfed = zend_register_list_destructors_ex(free_swfed_resource, NULL, "SWFEditor", module_number);
202 zend_declare_property_stringl(swfeditor_ce,
203 "swf_object", strlen("swf_object"),
204 "", 0, ZEND_ACC_PUBLIC TSRMLS_CC);
206 REGISTER_SWFED_CLASS_CONST_LONG("SHAPE_BITMAP_NONE", SWFED_SHAPE_BITMAP_NONE);
207 REGISTER_SWFED_CLASS_CONST_LONG("SHAPE_BITMAP_MATRIX_RESCALE", SWFED_SHAPE_BITMAP_MATRIX_RESCALE);
208 REGISTER_SWFED_CLASS_CONST_LONG("SHAPE_BITMAP_RECT_RESIZE", SWFED_SHAPE_BITMAP_RECT_RESIZE);
209 REGISTER_SWFED_CLASS_CONST_LONG("SHAPE_BITMAP_TYPE_TILLED", SWFED_SHAPE_BITMAP_TYPE_TILLED);
215 /* {{{ PHP_MSHUTDOWN_FUNCTION
217 PHP_MSHUTDOWN_FUNCTION(swfed)
219 /* uncomment this line if you have INI entries
220 UNREGISTER_INI_ENTRIES();
226 /* Remove if there's nothing to do at request start */
227 /* {{{ PHP_RINIT_FUNCTION
229 PHP_RINIT_FUNCTION(swfed)
235 /* Remove if there's nothing to do at request end */
236 /* {{{ PHP_RSHUTDOWN_FUNCTION
238 PHP_RSHUTDOWN_FUNCTION(swfed)
244 /* {{{ PHP_MINFO_FUNCTION
246 PHP_MINFO_FUNCTION(swfed)
250 php_info_print_table_start();
251 php_info_print_table_header(2, "SWF Editor support", "enabled");
252 php_info_print_table_row(2, "SWF Editor version", SWFED_VERSION);
259 php_info_print_table_row(2, "SWF Editor PNG support", png_support?"yes":"no");
260 php_info_print_table_row(2, "SWF Editor GIF support", gif_support?"yes":"no");
261 php_info_print_table_end();
263 /* Remove comments if you have entries in php.ini
264 DISPLAY_INI_ENTRIES();
270 /* Remove the following function when you have succesfully modified config.m4
271 so that your module can be compiled into PHP, it exists only for testing
274 /* Every user-visible function in PHP should document itself in the source */
275 /* {{{ proto string confirm_swfed_compiled(string arg)
276 Return a string to confirm that the module is compiled in */
277 PHP_FUNCTION(confirm_swfed_compiled)
283 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
287 len = sprintf(string, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "swfed", arg);
288 // RETURN_STRINGL(string, len, 0);
289 RETURN_STRINGL(string, len, 1);
292 /* The previous line is meant for vim and emacs, so it can correctly fold and
293 unfold functions in source code. See the corresponding marks just before
294 function definition, where the functions purpose is also documented. Please
295 follow this convention for the convenience of others editing your code.
304 * vim600: noet sw=4 ts=4 fdm=marker
305 * vim<600: noet sw=4 ts=4
308 PHP_METHOD(swfed, __construct) {
309 swf_object_t *swf = swf_object_open();
312 php_error_docref(NULL TSRMLS_CC, E_ERROR, "Couldn't create swf object");
314 #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 3) || (PHP_MAJOR_VERSION > 5)
315 ret = zend_list_insert(swf, le_swfed TSRMLS_CC);
317 ret = zend_list_insert(swf, le_swfed);
319 object_init_ex(getThis(), swfeditor_ce);
320 add_property_resource(getThis(), "swfed", ret);
321 zend_list_addref(ret);
324 PHP_METHOD(swfed, input) {
327 swf_object_t *swf = NULL;
329 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
330 "s", &data, &data_len) == FAILURE) {
333 swf = get_swf_object(getThis() TSRMLS_CC);
334 result = swf_object_input(swf, (unsigned char *) data, data_len);
341 PHP_METHOD(swfed, output) {
342 unsigned long len = 0;
343 unsigned char *data = NULL;
344 char *new_buff = NULL;
345 swf_object_t *swf = NULL;
346 if (ZEND_NUM_ARGS() != 0) {
348 RETURN_FALSE; /* XXX */
350 swf = get_swf_object(getThis() TSRMLS_CC);
351 data = swf_object_output(swf, &len);
352 new_buff = emalloc(len);
353 if (new_buff == NULL) {
354 fprintf(stderr, "output: Can't emalloc new_buff\n");
358 memcpy(new_buff, data, len);
360 RETURN_STRINGL(new_buff, len, 0);
363 PHP_METHOD(swfed, swfInfo) {
364 swf_object_t *swf = get_swf_object(getThis() TSRMLS_CC);
365 swf_object_print(swf);
369 PHP_METHOD(swfed, _destroy_and_exit) { // for debug
370 swf_object_t *swf = NULL;
371 swf = get_swf_object(getThis() TSRMLS_CC);
372 swf_object_close(swf);
376 PHP_METHOD(swfed, getHeaderInfo) {
377 swf_object_t *swf = get_swf_object(getThis() TSRMLS_CC);
378 array_init(return_value);
379 if (memcmp(swf->header.magic, "CWS", 3) == 0) {
380 add_assoc_bool(return_value, "compress", 1);
382 add_assoc_bool(return_value, "compress", 0);
384 add_assoc_long(return_value, "version", swf->header.version);
386 add_assoc_long(return_value, "x_min", swf->header_movie.frame_size.x_min / SWF_TWIPS);
387 add_assoc_long(return_value, "y_min", swf->header_movie.frame_size.y_min / SWF_TWIPS);
388 add_assoc_long(return_value, "x_max", swf->header_movie.frame_size.x_max / SWF_TWIPS);
389 add_assoc_long(return_value, "y_max", swf->header_movie.frame_size.y_max / SWF_TWIPS);
394 PHP_METHOD(swfed, setHeaderInfo) {
395 zval *header_info = NULL;
396 swf_object_t *swf = NULL;
397 HashTable *header_table = NULL;
399 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
400 &header_info) == FAILURE) {
401 php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameters");
404 swf = get_swf_object(getThis() TSRMLS_CC);
405 header_table = Z_ARRVAL_P(header_info);
408 if (zend_hash_find(header_table, "compress", sizeof("compress"), (void**)&tmp) == SUCCESS) {
409 convert_to_boolean_ex(tmp);
410 if (Z_LVAL_PP(tmp) != 0) {
411 memcpy(swf->header.magic, "CWS", 3);
413 memcpy(swf->header.magic, "FWS", 3);
418 if (zend_hash_find(header_table, "version", sizeof("version"), (void**)&tmp) == SUCCESS) {
419 convert_to_long_ex(tmp);
420 swf->header.version = Z_LVAL_PP(tmp);
424 if (zend_hash_find(header_table, "x_min", sizeof("x_min"), (void**)&tmp) == SUCCESS) {
425 convert_to_long_ex(tmp);
426 swf->header_movie.frame_size.x_min = Z_LVAL_PP(tmp) * SWF_TWIPS;
428 if (zend_hash_find(header_table, "y_min", sizeof("y_min"), (void**)&tmp) == SUCCESS) {
429 convert_to_long_ex(tmp);
430 swf->header_movie.frame_size.y_min = Z_LVAL_PP(tmp) * SWF_TWIPS;
432 if (zend_hash_find(header_table, "x_max", sizeof("x_max"), (void**)&tmp) == SUCCESS) {
433 convert_to_long_ex(tmp);
434 swf->header_movie.frame_size.x_max = Z_LVAL_PP(tmp) * SWF_TWIPS;
436 if (zend_hash_find(header_table, "y_max", sizeof("y_max"), (void**)&tmp) == SUCCESS) {
437 convert_to_long_ex(tmp);
438 swf->header_movie.frame_size.y_max = Z_LVAL_PP(tmp) * SWF_TWIPS;
443 PHP_METHOD(swfed, getTagList) {
446 swf_object_t *swf = NULL;
447 swf_tag_t *tag = NULL;
448 swf_tag_info_t *tag_info = NULL;
449 if (ZEND_NUM_ARGS() != 0) {
451 RETURN_FALSE; /* XXX */
453 swf = get_swf_object(getThis() TSRMLS_CC);
454 array_init(return_value);
455 for (tag=swf->tag_head ; tag ; tag=tag->next) {
456 ALLOC_INIT_ZVAL(data);
458 add_assoc_long(data, "code", tag->code);
459 add_assoc_long(data, "tag", tag->code);
460 tag_info = get_swf_tag_info(tag->code);
461 if (tag_info && tag_info->name) {
462 add_assoc_string_ex(data,
463 "tagName", sizeof("tagName"),
464 (char *)tag_info->name, 1);
466 add_assoc_long(data, "length", tag->length);
467 if (tag_info && tag_info->detail_handler) {
468 add_assoc_bool(data, "detail", 1);
470 add_index_zval(return_value, i, data);
475 PHP_METHOD(swfed, getTagDetail) {
477 swf_object_t *swf = NULL;
478 swf_tag_t *tag = NULL;
479 swf_tag_info_t *tag_info = NULL;
481 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
482 "l", &tag_seqno) == FAILURE) {
485 swf = get_swf_object(getThis() TSRMLS_CC);
487 for (tag=swf->tag_head ; tag ; tag=tag->next) {
488 if (i == tag_seqno) {
496 tag_info = get_swf_tag_info(tag->code);
497 if ((tag_info == NULL) || (tag_info->detail_handler == NULL)) {
500 if (swf_tag_create_input_detail(tag, swf) == NULL) {
501 RETURN_FALSE; // can't create detail
504 swf_tag_jpeg_detail_t *tag_jpeg;
505 swf_tag_lossless_detail_t *tag_lossless;
506 swf_tag_edit_detail_t *tag_edit;
507 swf_tag_sound_detail_t *tag_sound;
508 swf_tag_action_detail_t *tag_action;
509 swf_tag_sprite_detail_t *tag_sprite;
510 swf_tag_shape_detail_t *tag_shape;
511 swf_tag_place_detail_t *tag_place;
512 swf_action_t *action;
513 int action_list_count;
515 int *bitmap_id_list, bitmap_id_list_num;
516 case 6: // DefineBitsJPEG
517 case 21: // DefineBitsJPEG2
518 case 35: // DefineBitsJPEG3
519 tag_jpeg = tag->detail;
520 array_init(return_value);
521 add_assoc_long(return_value, "image_id", tag_jpeg->image_id);
522 add_assoc_long(return_value, "jpeg_data_len", tag_jpeg->jpeg_data_len);
523 if ((tag_jpeg->alpha_data != NULL) &&
524 (tag_jpeg->alpha_data_len > 0)) {
525 add_assoc_long(return_value, "alpha_data_len", tag_jpeg->alpha_data_len);
528 case 20: // DefineBitsLossless
529 case 36: // DefineBitsLossless2
530 tag_lossless = tag->detail;
531 array_init(return_value);
532 add_assoc_long(return_value, "image_id", tag_lossless->image_id);
533 add_assoc_long(return_value, "format", tag_lossless->format);
534 add_assoc_long(return_value, "width", tag_lossless->width);
535 add_assoc_long(return_value, "height", tag_lossless->height);
536 if (tag_lossless->format == 3) {
537 add_assoc_long(return_value, "colormap_count", tag_lossless->colormap_count);
540 case 14: // DefineSound
541 tag_sound = tag->detail;
542 array_init(return_value);
543 add_assoc_long(return_value, "sound_id", tag_sound->sound_id);
544 add_assoc_long(return_value, "format", (unsigned long) tag_sound->sound_format);
545 add_assoc_long(return_value, "rate", (unsigned long) tag_sound->sound_rate);
546 add_assoc_long(return_value, "is_16bits", tag_sound->sound_is_16bits?1:0);
547 add_assoc_long(return_value, "is_stereo", tag_sound->sound_is_stereo?1:0);
548 add_assoc_long(return_value, "sound_samples_count", tag_sound->sound_samples_count);
549 add_assoc_long(return_value, "sound_data_len", tag_sound->sound_data_len);
552 case 59: // DoInitAction
553 tag_action = tag->detail;
554 array_init(return_value);
555 if (tag->code == 59) { // DoInitAction
556 add_assoc_long(return_value, "action_sprite", tag_action->action_sprite);
558 action = tag_action->action_list->head;
560 for (action_list_count = 0 ; action ; action_list_count++) {
561 action = action->next;
563 add_assoc_long(return_value, "action_list_count", action_list_count);
566 case 37: // DefineEditText;
567 tag_edit = tag->detail;
568 array_init(return_value);
569 add_assoc_long(return_value, "edit_id", tag_edit->edit_id);
570 if (tag_edit->edit_variable_name && tag_edit->edit_variable_name[0]) {
571 add_assoc_string_ex(return_value, "variable_name",
572 sizeof("variable_name"),
573 (char *)tag_edit->edit_variable_name, 1);
575 if (tag_edit->edit_initial_text && tag_edit->edit_initial_text[0]) {
576 add_assoc_string_ex(return_value, "initial_text",
577 sizeof("initial_text"),
578 (char *)tag_edit->edit_initial_text, 1);
581 case 39: // DefineSprite;
582 tag_sprite = tag->detail;
583 array_init(return_value);
584 add_assoc_long(return_value, "sprite_id", tag_sprite->sprite_id);
585 add_assoc_long(return_value, "frame_count", tag_sprite->frame_count);
587 case 2: // DefineShape;
588 case 22: // DefineShape2;
589 case 32: // DefineShape3;
590 case 46: // DefineMorphShape;
591 tag_shape = tag->detail;
592 array_init(return_value);
593 add_assoc_long(return_value, "shape_id", tag_shape->shape_id);
594 add_assoc_long(return_value, "fill_styles.count", tag_shape->shape_with_style.styles.fill_styles.count);
595 add_assoc_long(return_value, "line_styles.count", tag_shape->shape_with_style.styles.line_styles.count);
596 // tag_shape->shape_with_style.shape_records
597 bitmap_id_list = swf_tag_shape_bitmap_get_refcid_list(tag, &bitmap_id_list_num);
598 if (bitmap_id_list) {
600 ALLOC_INIT_ZVAL(data);
602 for (i = 0 ; i < bitmap_id_list_num ; i++) {
603 add_index_long(data, i , bitmap_id_list[i]);
605 add_assoc_zval(return_value, "bitmap_ref", data);
606 free(bitmap_id_list);
609 case 4: // PlaceObject
610 case 26: // PlaceObject2
611 tag_place = tag->detail;
612 array_init(return_value);
613 if ((tag->code == 4) || tag_place->flag_has_character) {
614 add_assoc_long(return_value, "character_id", tag_place->character_id);
616 add_assoc_long(return_value, "depth", tag_place->depth);
617 if (tag_place->flag_has_name) {
618 add_assoc_string_ex(return_value, "name",
619 sizeof("name"), (char *)tag_place->name, 1);
629 PHP_METHOD(swfed, getTagData) {
631 swf_object_t *swf = NULL;
632 unsigned char *data = NULL, *new_buff;
633 unsigned long data_len = 0;
635 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_seqno) == FAILURE) {
638 swf = get_swf_object(getThis() TSRMLS_CC);
639 data = swf_object_get_tagdata(swf, tag_seqno, &data_len);
641 fprintf(stderr, "getTagData: Can't get_tagdata\n");
644 new_buff = emalloc(data_len);
645 memcpy(new_buff, data, data_len);
647 RETURN_STRINGL(new_buff, data_len, 0);
650 PHP_METHOD(swfed, replaceTagData) {
654 swf_object_t *swf = NULL;
656 switch (ZEND_NUM_ARGS()) {
659 RETURN_FALSE; /* XXX */
661 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &tag_seqno, &data, &data_len) == FAILURE) {
666 swf = get_swf_object(getThis() TSRMLS_CC);
667 result = swf_object_replace_tagdata(swf, tag_seqno,
668 (unsigned char *)data,
669 (unsigned long) data_len);
676 PHP_METHOD(swfed, getTagDataByCID) {
678 swf_object_t *swf = NULL;
679 unsigned char *data_ref = NULL;
680 unsigned long data_len = 0;
681 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &cid) == FAILURE) {
684 swf = get_swf_object(getThis() TSRMLS_CC);
685 data_ref = swf_object_get_tagdata_bycid(swf, cid, &data_len);
686 if (data_ref == NULL) {
687 fprintf(stderr, "getTagDataByCID: Can't get_tagdata_bycid\n");
690 RETURN_STRINGL((char *) data_ref, data_len, 1);
693 PHP_METHOD(swfed, replaceTagDataByCID) {
695 unsigned long data_len = 0;
697 swf_object_t *swf = NULL;
699 switch (ZEND_NUM_ARGS()) {
702 RETURN_FALSE; /* XXX */
704 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &cid, &data, &data_len) == FAILURE) {
709 swf = get_swf_object(getThis() TSRMLS_CC);
710 result = swf_object_replace_tagdata_bycid(swf, cid,
711 (unsigned char *)data,
719 PHP_METHOD(swfed, getTagContentsByCID) {
721 swf_object_t *swf = NULL;
722 unsigned char *data_ref = NULL;
723 unsigned long data_len = 0;
724 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &cid) == FAILURE) {
727 swf = get_swf_object(getThis() TSRMLS_CC);
728 data_ref = swf_object_get_tagcontents_bycid(swf, cid, &data_len);
729 if (data_ref == NULL) {
730 fprintf(stderr, "getTagContentsByCID: Can't get_tagcontents_bycid\n");
733 RETURN_STRINGL((char *)data_ref, data_len, 1);
736 PHP_METHOD(swfed, replaceTagContentsByCID) {
738 unsigned long data_len = 0;
740 swf_object_t *swf = NULL;
742 switch (ZEND_NUM_ARGS()) {
745 RETURN_FALSE; /* XXX */
747 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &cid, &data, &data_len) == FAILURE) {
752 swf = get_swf_object(getThis() TSRMLS_CC);
753 result = swf_object_replace_tagcontents_bycid(swf, cid,
754 (unsigned char *)data,
762 PHP_METHOD(swfed, removeTag) {
764 long tag_seqno_in_sprite = -1;
765 swf_object_t *swf = NULL;
768 switch (ZEND_NUM_ARGS()) {
770 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_seqno) == FAILURE) {
775 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &tag_seqno, &tag_seqno_in_sprite) == FAILURE) {
780 swf = get_swf_object(getThis() TSRMLS_CC);
781 ret = swf_object_remove_tag(swf, tag_seqno, tag_seqno_in_sprite);
788 PHP_METHOD(swfed, printTagData) {
791 swf_object_t *swf = NULL;
793 switch (ZEND_NUM_ARGS()) {
796 RETURN_FALSE; /* XXX */
798 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) == FAILURE) {
803 swf = get_swf_object(getThis() TSRMLS_CC);
804 ret = swf_object_print_tagdata(swf, (unsigned char *)data,
805 (unsigned long) data_len);
812 PHP_METHOD(swfed, getShapeData) {
814 swf_object_t *swf = NULL;
815 unsigned char *data = NULL, *new_buff;
816 unsigned long data_len = 0;
817 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &cid) == FAILURE) {
820 swf = get_swf_object(getThis() TSRMLS_CC);
821 data = swf_object_get_shapedata(swf, cid, &data_len);
823 fprintf(stderr, "getShapeData: Can't swf_object_get_shapedata (cid=%ld)\n", cid);
826 new_buff = emalloc(data_len);
827 memcpy(new_buff, data, data_len);
829 RETURN_STRINGL((char *)new_buff, data_len, 0);
832 PHP_METHOD(swfed, replaceShapeData) {
836 swf_object_t *swf = NULL;
838 switch (ZEND_NUM_ARGS()) {
841 RETURN_FALSE; /* XXX */
843 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &cid, &data, &data_len) == FAILURE) {
848 swf = get_swf_object(getThis() TSRMLS_CC);
849 result = swf_object_replace_shapedata(swf, cid,
850 (unsigned char *)data,
851 (unsigned long)data_len);
858 PHP_METHOD(swfed, setShapeAdjustMode) {
859 swf_object_t *swf = NULL;
860 unsigned long mode = 0;
861 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
862 "l", &mode) == FAILURE) {
865 swf = get_swf_object(getThis() TSRMLS_CC);
866 swf_object_set_shape_adjust_mode(swf, mode);
870 PHP_METHOD(swfed, getShapeIdListByBitmapRef) {
872 int *bitmap_id_list, bitmap_id_list_num;
873 swf_object_t *swf = NULL;
874 swf_tag_t *tag = NULL;
876 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
877 "l", &bitmap_id) == FAILURE) {
880 swf = get_swf_object(getThis() TSRMLS_CC);
881 array_init(return_value);
883 for (tag = swf->tag_head ; tag ; tag=tag->next) {
884 register int tag_code = tag->code;
885 if (isShapeTag(tag_code)) {
886 bitmap_id_list = swf_tag_shape_bitmap_get_refcid_list(tag, &bitmap_id_list_num);
887 if (bitmap_id_list) {
889 for (j=0 ; j < bitmap_id_list_num ; j++) {
890 if (bitmap_id_list[j] == bitmap_id) {
891 swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
892 add_index_long(return_value, i, (long) swf_tag_shape->shape_id);
897 free(bitmap_id_list);
903 PHP_METHOD(swfed, getBitmapSize) {
905 swf_object_t *swf = NULL;
908 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
909 "l", &bitmap_id) == FAILURE) {
912 swf = get_swf_object(getThis() TSRMLS_CC);
913 ret = swf_object_get_bitmap_size(swf, bitmap_id, &width, &height);
917 array_init(return_value);
918 add_assoc_long(return_value, "width", (long) width);
919 add_assoc_long(return_value, "height", (long) height);
922 PHP_METHOD(swfed, getJpegData) {
923 unsigned long image_id = 0;
924 unsigned long len = 0;
925 unsigned char *data = NULL;
926 char *new_buff = NULL;
927 swf_object_t *swf = NULL;
928 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
929 "l", &image_id) == FAILURE) {
932 swf = get_swf_object(getThis() TSRMLS_CC);
933 data = swf_object_get_jpegdata(swf, &len, image_id);
937 new_buff = emalloc(len);
938 if (new_buff == NULL) {
939 fprintf(stderr, "getJpegData Can't emalloc new_buff\n");
943 memcpy(new_buff, data, len);
945 RETURN_STRINGL(new_buff, (int) len, 0);
948 PHP_METHOD(swfed, getJpegAlpha) {
949 unsigned long image_id = 0;
950 unsigned long len = 0;
951 unsigned char *data = NULL;
952 char *new_buff = NULL;
953 swf_object_t *swf = NULL;
954 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
955 "l", &image_id) == FAILURE) {
958 swf = get_swf_object(getThis() TSRMLS_CC);
959 data = swf_object_get_alphadata(swf, &len, image_id);
963 new_buff = emalloc(len);
964 if (new_buff == NULL) {
965 fprintf(stderr, "getJpegAlpha Can't emalloc new_buff\n");
969 memcpy(new_buff, data, len);
971 RETURN_STRINGL(new_buff, len, 0);
974 PHP_METHOD(swfed, replaceJpegData) {
975 char *data = NULL, *alpha_data = NULL;
976 int data_len = 0 , alpha_data_len = 0;
978 swf_object_t *swf = NULL;
980 switch (ZEND_NUM_ARGS()) {
983 RETURN_FALSE; /* XXX */
985 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &image_id, &data, &data_len) == FAILURE) {
990 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss", &image_id, &data, &data_len, &alpha_data, &alpha_data_len) == FAILURE) {
995 swf = get_swf_object(getThis() TSRMLS_CC);
996 result = swf_object_replace_jpegdata(swf, image_id,
997 (unsigned char *)data,
998 (unsigned long) data_len,
999 (unsigned char *)alpha_data,
1000 (unsigned long) alpha_data_len,
1008 PHP_METHOD(swfed, getPNGData) {
1010 fprintf(stderr, "replacePNGData: no png library\n");
1012 #else /* HAVE_PNG */
1013 unsigned long image_id = 0;
1014 unsigned long len = 0;
1015 unsigned char *data = NULL;
1016 char *new_buff = NULL;
1017 swf_object_t *swf = NULL;
1018 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
1019 "l", &image_id) == FAILURE) {
1022 swf = get_swf_object(getThis() TSRMLS_CC);
1023 data = swf_object_get_pngdata(swf, &len, image_id);
1027 new_buff = emalloc(len);
1028 if (new_buff == NULL) {
1029 fprintf(stderr, "getPNGData: Can't emalloc new_buff\n");
1033 memcpy(new_buff, data, len);
1035 RETURN_STRINGL(new_buff, (int) len, 0);
1036 #endif /* HAVE_PNG */
1039 PHP_METHOD(swfed, replacePNGData) {
1041 fprintf(stderr, "replacePNGData: no png library\n");
1043 #else /* HAVE_PNG */
1048 HashTable *opts_table = NULL;
1052 switch (ZEND_NUM_ARGS()) {
1055 RETURN_FALSE; /* XXX */
1058 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|a", &image_id, &data, &data_len, &opts) == FAILURE) {
1064 opts_table = Z_ARRVAL_P(opts);
1065 get_zend_hash_value_boolean(opts_table, "rgb15", rgb15);
1068 swf = get_swf_object(getThis() TSRMLS_CC);
1070 result = swf_object_replace_pngdata(swf, image_id,
1071 (unsigned char *)data,
1072 (unsigned long) data_len,
1078 #endif /* HAVE_PNG */
1081 PHP_METHOD(swfed, replaceGIFData) {
1083 fprintf(stderr, "replaceGIFData: no gif library\n");
1085 #else /* HAVE_GIF */
1089 swf_object_t *swf = NULL;
1091 switch (ZEND_NUM_ARGS()) {
1094 RETURN_FALSE; /* XXX */
1096 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &image_id, &data, &data_len) == FAILURE) {
1101 swf = get_swf_object(getThis() TSRMLS_CC);
1102 result = swf_object_replace_gifdata(swf, image_id,
1103 (unsigned char *)data,
1104 (unsigned long) data_len);
1109 #endif /* HAVE_GIF */
1112 PHP_METHOD(swfed, replaceBitmapData) {
1113 char *data = NULL, *alpha_data = NULL;
1114 int data_len = 0 , alpha_data_len = 0;
1115 zval *arg1 = NULL, *arg4 = NULL;
1117 HashTable *image_info_table = NULL;
1118 int width = -1, height = -1;
1119 int red = -1, green = -1, blue = -1;
1120 HashTable *opts_table = NULL;
1121 int without_converting = 0;
1123 swf_object_t *swf = NULL;
1126 if (param_is_null(1 TSRMLS_CC)) {
1127 php_error(E_WARNING, "%s() 1st arg must be not NULL", get_active_function_name(TSRMLS_C));
1128 RETURN_FALSE; /* XXX */
1130 switch (ZEND_NUM_ARGS()) {
1133 RETURN_FALSE; /* XXX */
1138 if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
1139 ZEND_NUM_ARGS() TSRMLS_CC, "zs|sz", &arg1, &data, &data_len, &alpha_data, &alpha_data_len, &arg4) == SUCCESS) {
1142 php_error(E_WARNING, "%s() expects parameter 2 to be string given", get_active_function_name(TSRMLS_C));
1147 swf = get_swf_object(getThis() TSRMLS_CC);
1149 if (Z_TYPE_P(arg1) != IS_ARRAY) { // image_id (integer)
1150 if (Z_TYPE_P(arg1) != IS_LONG) {
1151 convert_to_long(arg1);
1153 image_id = (int) Z_LVAL_P(arg1);
1154 } else { // or image_info (array)
1155 image_info_table = Z_ARRVAL_P(arg1);
1156 get_zend_hash_value_long(image_info_table, "width", width);
1157 get_zend_hash_value_long(image_info_table, "height", height);
1158 get_zend_hash_value_long(image_info_table, "red", red);
1159 get_zend_hash_value_long(image_info_table, "green", green);
1160 get_zend_hash_value_long(image_info_table, "blue", blue);
1161 image_id = swf_object_search_cid_by_bitmap_condition(swf, width, height,
1163 if (image_id <= 0) {
1164 php_error(E_WARNING, "%s() cid not found by bitmap condition(width=%d height=%d red=%d green=%d blue=%d)", get_active_function_name(TSRMLS_C),
1165 width, height, red, green, blue);
1170 if (Z_TYPE_P(arg4) != IS_ARRAY) { // without_converting (boolean)
1171 if (Z_TYPE_P(arg4) != IS_BOOL) {
1172 convert_to_boolean(arg4);
1174 without_converting = (int) Z_LVAL_P(arg4);
1175 } else { // or opts (array)
1176 opts_table = Z_ARRVAL_P(arg4);
1177 get_zend_hash_value_boolean(opts_table, "without_converting", without_converting);
1178 get_zend_hash_value_boolean(opts_table, "rgb15", rgb15);
1181 bitmap_format = detect_bitmap_format((unsigned char*) data, data_len);
1182 if (without_converting) { // for v8 JPEG Tag
1183 switch (bitmap_format) {
1184 case BITMAP_UTIL_FORMAT_JPEG:
1185 case BITMAP_UTIL_FORMAT_PNG:
1186 case BITMAP_UTIL_FORMAT_GIF:
1187 result = swf_object_replace_jpegdata(swf, image_id,
1188 (unsigned char *)data,
1189 (unsigned long) data_len,
1190 (unsigned char *) 0,
1195 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown Bitmap Format");
1199 switch (bitmap_format) {
1200 case BITMAP_UTIL_FORMAT_JPEG:
1201 result = swf_object_replace_jpegdata(swf, image_id,
1202 (unsigned char *)data,
1203 (unsigned long) data_len,
1204 (unsigned char *)alpha_data,
1205 (unsigned long) alpha_data_len,
1208 case BITMAP_UTIL_FORMAT_PNG:
1209 result = swf_object_replace_pngdata(swf, image_id,
1210 (unsigned char *)data,
1211 (unsigned long) data_len,
1215 case BITMAP_UTIL_FORMAT_GIF:
1216 result = swf_object_replace_gifdata(swf, image_id,
1217 (unsigned char *)data,
1218 (unsigned long) data_len);
1222 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown Bitmap Format");
1232 PHP_METHOD(swfed, convertBitmapDataToJpegTag) {
1233 swf_object_t *swf = NULL;
1235 swf = get_swf_object(getThis() TSRMLS_CC);
1236 ret = swf_object_convert_bitmapdata_tojpegtag(swf);
1243 PHP_METHOD(swfed, applyShapeMatrixFactor) {
1245 double scale_x = 1, scale_y = 1, rotate_rad = 0;
1246 long trans_x = 0, trans_y = 0;
1247 swf_object_t *swf = NULL;
1249 if (param_is_null(1 TSRMLS_CC)) {
1250 php_error(E_WARNING, "%s() 1st arg must be not NULL", get_active_function_name(TSRMLS_C));
1251 RETURN_FALSE; /* XXX */
1253 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
1254 "ldddll", &shape_id, &scale_x, &scale_y,
1255 &rotate_rad, &trans_x, &trans_y) == FAILURE) {
1258 swf = get_swf_object(getThis() TSRMLS_CC);
1259 result = swf_object_apply_shapematrix_factor(swf, shape_id, -1,
1260 scale_x, scale_y, rotate_rad,
1269 PHP_METHOD(swfed, applyShapeRectFactor) {
1271 double scale_x = 1, scale_y = 1;
1272 long trans_x = 0, trans_y = 0;
1273 swf_object_t *swf = NULL;
1275 if (param_is_null(1 TSRMLS_CC)) {
1276 php_error(E_WARNING, "%s() 1st arg must be not NULL", get_active_function_name(TSRMLS_C));
1277 RETURN_FALSE; /* XXX */
1279 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
1280 "lddll", &shape_id, &scale_x, &scale_y,
1281 &trans_x, &trans_y) == FAILURE) {
1284 swf = get_swf_object(getThis() TSRMLS_CC);
1285 result = swf_object_apply_shaperect_factor(swf, shape_id, -1,
1295 PHP_METHOD(swfed, adjustShapeSizeToBitmap) {
1299 PHP_METHOD(swfed, adjustShapeScaleToBitmap) {
1304 PHP_METHOD(swfed, getSoundData) {
1305 unsigned long sound_id = 0;
1306 unsigned long len = 0;
1307 unsigned char *data = NULL;
1308 char *new_buff = NULL;
1309 swf_object_t *swf = NULL;
1310 if (param_is_null(1 TSRMLS_CC)) {
1311 php_error(E_WARNING, "%s() 1st arg must be not NULL", get_active_function_name(TSRMLS_C));
1312 RETURN_FALSE; /* XXX */
1314 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
1315 "l", &sound_id) == FAILURE) {
1318 swf = get_swf_object(getThis() TSRMLS_CC);
1319 data = swf_object_get_sounddata(swf, &len, sound_id);
1323 new_buff = emalloc(len);
1324 if (new_buff == NULL) {
1325 fprintf(stderr, "getSoundData: Can't emalloc new_buff\n");
1329 memcpy(new_buff, data, len);
1331 RETURN_STRINGL(new_buff, (int) len, 0);
1334 PHP_METHOD(swfed, replaceMLDData) {
1338 swf_object_t *swf = NULL;
1340 if (param_is_null(1 TSRMLS_CC)) {
1341 php_error(E_WARNING, "%s() 1st arg must be not NULL", get_active_function_name(TSRMLS_C));
1344 switch (ZEND_NUM_ARGS()) {
1347 RETURN_FALSE; /* XXX */
1349 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &sound_id, &data, &data_len) == FAILURE) {
1354 swf = get_swf_object(getThis() TSRMLS_CC);
1355 result = swf_object_replace_melodata(swf, sound_id,
1356 (unsigned char *)data,
1357 (unsigned long) data_len);
1364 PHP_METHOD(swfed, getEditString) {
1365 char *var_name = NULL;
1366 int var_name_len = 0;
1367 swf_object_t *swf = NULL;
1368 char *data = NULL, *new_buff = NULL;
1371 if (param_is_null(1 TSRMLS_CC)) {
1372 php_error(E_WARNING, "%s() 1st arg must be not NULL", get_active_function_name(TSRMLS_C));
1375 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
1376 &var_name, &var_name_len) == FAILURE) {
1379 swf = get_swf_object(getThis() TSRMLS_CC);
1380 data = swf_object_get_editstring(swf, var_name, var_name_len, &error);
1388 str_len = strlen(data);
1389 new_buff = emalloc(str_len);
1390 if (new_buff == NULL) {
1391 fprintf(stderr, "getEditString: Can't emalloc new_buff\n");
1395 memcpy(new_buff, data, str_len);
1397 RETURN_STRINGL(new_buff, str_len, 0);
1400 PHP_METHOD(swfed, replaceEditString) {
1401 char *var_name = NULL, *ini_text = NULL;
1402 int var_name_len = 0, ini_text_len = 0;
1403 swf_object_t *swf = NULL;
1405 if (param_is_null(1 TSRMLS_CC)) {
1406 php_error(E_WARNING, "%s() 1st arg must be not NULL", get_active_function_name(TSRMLS_C));
1409 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
1410 &var_name, &var_name_len,
1411 &ini_text, &ini_text_len) == FAILURE) {
1414 swf = get_swf_object(getThis() TSRMLS_CC);
1415 result = swf_object_replace_editstring(swf, var_name, var_name_len,
1416 ini_text, ini_text_len);
1423 PHP_METHOD(swfed, getActionData) {
1425 swf_object_t *swf = NULL;
1426 unsigned char *data = NULL;
1427 char *new_buff = NULL;
1428 unsigned long data_len = 0;
1430 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_seqno) == FAILURE) {
1433 swf = get_swf_object(getThis() TSRMLS_CC);
1434 data = swf_object_get_actiondata(swf, &data_len, tag_seqno);
1436 fprintf(stderr, "getActionData: Can't get_actiondata\n");
1439 new_buff = emalloc(data_len);
1440 if (new_buff == NULL) {
1441 fprintf(stderr, "getActionData: Can't emalloc new_buff\n");
1445 memcpy(new_buff, data, data_len);
1447 RETURN_STRINGL(new_buff, data_len, 0);
1450 PHP_METHOD(swfed, disasmActionData) {
1453 bitstream_t *bs = NULL;
1454 swf_action_list_t *action_list = NULL;
1455 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
1456 "s", &data, &data_len) == FAILURE) {
1459 array_init(return_value);
1460 bs = bitstream_open();
1461 bitstream_input(bs, (unsigned char*) data, data_len);
1462 action_list = swf_action_list_create();
1463 swf_action_list_parse(bs, action_list);
1464 bitstream_close(bs);
1466 swf_action_t *action = action_list->head;
1469 // swf_action_disasm(action);
1470 action = action->next;
1473 swf_action_list_destroy(action_list);
1477 PHP_METHOD(swfed, setActionVariables) {
1478 zval *zid, *arr, **entry;
1479 HashTable *arr_hash;
1481 char *str_key, *str_value;
1482 uint str_key_len, str_value_len;
1487 swf_object_t *swf = get_swf_object(getThis() TSRMLS_CC);
1489 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arr) == FAILURE) {
1492 kv = y_keyvalue_open();
1494 arr_hash = Z_ARRVAL_P(arr);
1495 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
1496 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, &
1498 convert_to_string_ex(entry);
1499 str_value = Z_STRVAL_PP(entry);
1500 str_value_len = Z_STRLEN_PP(entry);
1501 ret = zend_hash_get_current_key_ex(Z_ARRVAL_P(arr), &str_key, &
1502 str_key_len, &tmp, 0, &pos);
1504 case HASH_KEY_IS_STRING:
1505 y_keyvalue_set(kv, str_key, str_key_len - 1, str_value, str_value_len);
1507 case HASH_KEY_IS_LONG:
1508 snprintf(tmp_str, 17, "%ld\0", tmp);
1509 y_keyvalue_set(kv, tmp_str, strlen(tmp_str), str_value, str_value_len);
1512 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array keys invalid type(%d).", ret);
1514 zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
1516 swf_object_insert_action_setvariables(swf, kv);
1517 y_keyvalue_close(kv);
1521 PHP_METHOD(swfed, replaceActionStrings) {
1522 zval *zid, *arr, **entry;
1523 HashTable *arr_hash;
1525 char *str_key, *str_value;
1526 uint str_key_len, str_value_len;
1531 swf_object_t *swf = get_swf_object(getThis() TSRMLS_CC);
1533 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arr) == FAILURE) {
1536 kv = y_keyvalue_open();
1538 arr_hash = Z_ARRVAL_P(arr);
1539 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
1540 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, &
1542 convert_to_string_ex(entry);
1543 str_value = Z_STRVAL_PP(entry);
1544 str_value_len = Z_STRLEN_PP(entry);
1545 ret = zend_hash_get_current_key_ex(Z_ARRVAL_P(arr), &str_key, &
1546 str_key_len, &tmp, 0, &pos);
1548 case HASH_KEY_IS_STRING:
1549 y_keyvalue_set(kv, str_key, str_key_len - 1, str_value, str_value_len);
1551 case HASH_KEY_IS_LONG:
1552 snprintf(tmp_str, 17, "%ld\0", tmp);
1553 y_keyvalue_set(kv, tmp_str, strlen(tmp_str), str_value, str_value_len);
1556 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array keys invalid type(%d).", ret);
1558 zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
1560 swf_object_replace_action_strings(swf, kv);
1561 y_keyvalue_close(kv);
1565 PHP_METHOD(swfed, replaceMovieClip) {
1566 char *instance_name = NULL, *swf_data = NULL;
1567 int instance_name_len = 0, swf_data_len = 0;
1568 swf_object_t *swf = NULL;
1569 zend_bool unused_cid_purge = 1; // ¥Ç¥Õ¥©¥ë¥È on
1571 if (param_is_null(1 TSRMLS_CC)) {
1572 php_error(E_WARNING, "%s() 1st arg must be not NULL", get_active_function_name(TSRMLS_C));
1575 switch (ZEND_NUM_ARGS()) {
1578 RETURN_FALSE; /* XXX */
1580 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
1581 &instance_name, &instance_name_len,
1582 &swf_data, &swf_data_len) == FAILURE) {
1587 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssb",
1588 &instance_name, &instance_name_len,
1589 &swf_data, &swf_data_len, &unused_cid_purge) == FAILURE) {
1590 // unused_cid_purge ¤Ï̵»ë¤·¤Þ¤¹¡£
1595 swf = get_swf_object(getThis() TSRMLS_CC);
1596 result = swf_object_replace_movieclip(swf,
1597 (unsigned char *)instance_name,
1599 (unsigned char *)swf_data,
1607 PHP_METHOD(swfed, rebuild) {
1608 swf_object_t *swf = get_swf_object(getThis() TSRMLS_CC);
1609 if (swf_object_rebuild(swf)) {
1615 PHP_METHOD(swfed, purgeUselessContents) {
1616 swf_object_t *swf = get_swf_object(getThis() TSRMLS_CC);
1617 swf_object_purge_contents(swf);
1621 PHP_METHOD(swfed, setCompressLevel) {
1622 unsigned long compress_level = 6 ; // Z_DEFAULT_COMPRESSION
1624 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
1625 "l", &compress_level) == FAILURE) {
1628 swf = get_swf_object(getThis() TSRMLS_CC);
1629 swf->compress_level = compress_level;
1633 PHP_METHOD(swfed, isShapeTagData) {
1636 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
1637 "s", &data, &data_len) == FAILURE) {
1640 if (swf_object_is_shape_tagdata((unsigned char *)data,
1647 PHP_METHOD(swfed, isBitmapTagData) {
1650 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
1651 "s", &data, &data_len) == FAILURE) {
1654 if (swf_object_is_bitmap_tagdata((unsigned char *)data,
1662 static swf_object_t *get_swf_object(zval *obj TSRMLS_DC) {
1663 // zval *data, **tmp;
1665 swf_object_t *swf = NULL;
1666 int id = 0, type = 0;
1667 /* XXX: zend_read_property
1668 data = zend_read_property(Z_OBJCE_P(obj), obj, "swf_object",
1669 strlen("swf_object"), 1 TSRMLS_CC);
1671 if (zend_hash_find(Z_OBJPROP_P(obj), "swfed", strlen("swfed") + 1,
1672 (void **)&tmp) == FAILURE) {
1675 id = Z_LVAL_PP(tmp);
1676 swf = (swf_object_t *) zend_list_find(id, &type);
1680 static void free_swfed_resource(zend_rsrc_list_entry *resource TSRMLS_DC)
1682 // printf("SWFEditor->destory\n");
1683 swf_object_close((swf_object_t *) resource->ptr);