svnno****@sourc*****
svnno****@sourc*****
2011年 4月 5日 (火) 22:18:13 JST
Revision: 520 http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=520 Author: yoya Date: 2011-04-05 22:18:13 +0900 (Tue, 05 Apr 2011) Log Message: ----------- removeTag メソッドの Sprite 中 tag 対応 (不具合あり) Modified Paths: -------------- trunk/src/php_swfed.c trunk/src/swf_object.c trunk/src/swf_object.h trunk/src/swf_tag_sprite.c Added Paths: ----------- trunk/sample/swfremovetag.php -------------- next part -------------- Added: trunk/sample/swfremovetag.php =================================================================== --- trunk/sample/swfremovetag.php (rev 0) +++ trunk/sample/swfremovetag.php 2011-04-05 13:18:13 UTC (rev 520) @@ -0,0 +1,32 @@ +<?php + +if (($argc != 3) && ($argc != 4)) { + fprintf(STDERR, "Usage: swfremovetag <swf_file> <tag_seqno> [<tag_seqno_in_sprite>]\n"); + exit(1); +} + +$swf_filename = $argv[1]; + +$swfdata = file_get_contents($swf_filename); +$obj = new SWFEditor(); + +if ($obj->input($swfdata) == false) { + fprintf(STDERR, "input failed\n"); + exit(1); +} +$tag_seqno = $argv[2]; + +if ($argc == 3) { + if ($obj->removeTag($tag_seqno) == false) { + fprintf(STDERR, "removeTag($tag_seqno) failed\n"); + exit(1); + } +} else { + $tag_seqno_in_sprite = $argv[3]; + if ($obj->removeTag($tag_seqno, $tag_seqno_in_sprite) == false) { + fprintf(STDERR, "removeTag($tag_seqno, $tag_seqno_in_sprite) failed\n"); + exit(1); + } +} + +echo $obj->output(); Property changes on: trunk/sample/swfremovetag.php ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Modified: trunk/src/php_swfed.c =================================================================== --- trunk/src/php_swfed.c 2011-04-05 12:17:08 UTC (rev 519) +++ trunk/src/php_swfed.c 2011-04-05 13:18:13 UTC (rev 520) @@ -714,13 +714,24 @@ PHP_METHOD(swfed, removeTag) { long tag_seqno = 0; + long tag_seqno_in_sprite = -1; swf_object_t *swf = NULL; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_seqno) == FAILURE) { - RETURN_FALSE; + + switch (ZEND_NUM_ARGS()) { + case 1: + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_seqno) == FAILURE) { + RETURN_FALSE; + } + break; + case 2: + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &tag_seqno, &tag_seqno_in_sprite) == FAILURE) { + RETURN_FALSE; + } + break; } swf = get_swf_object(getThis() TSRMLS_CC); - ret = swf_object_remove_tag(swf, tag_seqno); + ret = swf_object_remove_tag(swf, tag_seqno, tag_seqno_in_sprite); if (ret) { RETURN_FALSE; } Modified: trunk/src/swf_object.c =================================================================== --- trunk/src/swf_object.c 2011-04-05 12:17:08 UTC (rev 519) +++ trunk/src/swf_object.c 2011-04-05 13:18:13 UTC (rev 520) @@ -23,6 +23,7 @@ #include "trans_table.h" static int _swf_object_remove_tag(swf_object_t *swf, swf_tag_t *tag); +static int _swf_object_remove_tag_in_sprite(swf_tag_sprite_detail_t *sprite, swf_tag_t *tag); static int _swf_object_replace_tag(swf_object_t *swf, swf_tag_t *old_tag, swf_tag_t *new_tag); @@ -426,12 +427,31 @@ } int -swf_object_remove_tag(swf_object_t *swf, int tag_seqno) { +swf_object_remove_tag(swf_object_t *swf, int tag_seqno, + int tag_seqno_in_sprite) { swf_tag_t *tag; int ret = 1; + tag = swf_object_search_tag_byseqno(swf, tag_seqno); if (tag) { - ret = _swf_object_remove_tag(swf, tag); + if (tag_seqno_in_sprite >= 0) { + if (isSpriteTag(tag->tag)) { + swf_tag_sprite_detail_t *tag_sprite; + swf_tag_t *tag_in_sprite; + tag_sprite = swf_tag_create_input_detail(tag, swf); + + tag_in_sprite = swf_object_search_tag_in_sprite_byseqno(tag_sprite, tag_seqno_in_sprite); + if (tag_in_sprite) { + ret = _swf_object_remove_tag_in_sprite(tag_sprite, tag_in_sprite); + } else { + ; + } + } else { + fprintf(stderr, "swf_object_remove_tag: not SpriteTag seqno=%d\n", tag_seqno); + } + } else { + ret = _swf_object_remove_tag(swf, tag); + } } return ret; } @@ -459,6 +479,33 @@ return 0; } +static int +_swf_object_remove_tag_in_sprite(swf_tag_sprite_detail_t *sprite_tag, swf_tag_t *tag) { + + fprintf(stderr, "_swf_object_remove_tag_in_sprite: sprite_id=%d tag->prev=%p tag->next=%p\n", sprite_tag->sprite_id, tag->prev, tag->next); + if (tag->prev) { + if (tag->next) { // prev:O next:O + tag->prev->next = tag->next; + tag->next->prev = tag->prev; + } else { // prev:O next:X + tag->prev->next = NULL; + // swf->tag_tail = tag->prev; + } + } else { + if (tag->next) { // prev:X next:O + tag->next->prev = NULL; + sprite_tag->tag = tag->next; + // swf->tag_heat = tag->next; + } else { // prev:X next:X + sprite_tag->tag = NULL; + // swf->tag_head = NULL; + // swf->tag_tail = NULL; + } + } + swf_tag_destroy(tag); + return 0; +} + /* --- */ unsigned char * @@ -549,6 +596,24 @@ } swf_tag_t * +swf_object_search_tag_in_sprite_byseqno(swf_tag_sprite_detail_t *sprite, int tag_seqno) { + int i; + swf_tag_t *tag; + if (sprite == NULL) { + fprintf(stderr, "swf_object_search_tag_by_seqno: sprite == NULL\n"); + return NULL; + } + i=0; + for (tag = sprite->tag ; tag ; tag = tag->next) { + if (i >= tag_seqno) { + break; + } + i++; + } + return tag; +} + +swf_tag_t * swf_object_search_tag_bycid(swf_object_t *swf, int cid) { swf_tag_t *tag; if (swf == NULL) { Modified: trunk/src/swf_object.h =================================================================== --- trunk/src/swf_object.h 2011-04-05 12:17:08 UTC (rev 519) +++ trunk/src/swf_object.h 2011-04-05 13:18:13 UTC (rev 520) @@ -56,12 +56,15 @@ extern int swf_object_replace_tagcontents_bycid(swf_object_t *swf, int cid, unsigned char *data, unsigned long length); -extern int swf_object_remove_tag(swf_object_t *swf, int tag_seqno); +extern int swf_object_remove_tag(swf_object_t *swf, int tag_seqno, + int tag_seqno_in_sprite); /* --- */ extern swf_tag_t *swf_object_search_tag_byseqno(swf_object_t *swf, int tag_seqno); +extern swf_tag_t *swf_object_search_tag_in_sprite_byseqno(swf_tag_sprite_detail_t *sprite, int tag_seqno); + extern swf_tag_t *swf_object_search_tag_bycid(swf_object_t *swf, int cid); extern swf_tag_t *swf_object_search_shape_tag(swf_object_t *swf, Modified: trunk/src/swf_tag_sprite.c =================================================================== --- trunk/src/swf_tag_sprite.c 2011-04-05 12:17:08 UTC (rev 519) +++ trunk/src/swf_tag_sprite.c 2011-04-05 13:18:13 UTC (rev 520) @@ -68,12 +68,11 @@ if (prev_tag == NULL) { swf_tag_sprite->tag = tag_in_sprite; tag_in_sprite->prev = NULL; - tag_in_sprite->next = NULL; } else { prev_tag->next = tag_in_sprite; tag_in_sprite->prev = prev_tag; - tag_in_sprite->next = NULL; } + tag_in_sprite->next = NULL; prev_tag = tag_in_sprite; } bitstream_close(bs);