[Swfed-svn] swfed-svn [475] swf_object_purge_useless_cid の実装

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 27日 (日) 23:22:07 JST


Revision: 475
          http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=475
Author:   yoya
Date:     2011-03-27 23:22:07 +0900 (Sun, 27 Mar 2011)

Log Message:
-----------
swf_object_purge_useless_cid の実装
swf_object_replace_movieclip での Defineタグ削除処理を廃止

Modified Paths:
--------------
    trunk/src/php_swfed.c
    trunk/src/swf_object.c
    trunk/src/swf_object.h


-------------- next part --------------
Modified: trunk/src/php_swfed.c
===================================================================
--- trunk/src/php_swfed.c	2011-03-26 12:26:01 UTC (rev 474)
+++ trunk/src/php_swfed.c	2011-03-27 14:22:07 UTC (rev 475)
@@ -1190,11 +1190,13 @@
     swf = get_swf_object(getThis() TSRMLS_CC);    
     result = swf_object_replace_movieclip(swf, instance_name,
                                           instance_name_len,
-                                          swf_data, swf_data_len,
-                                          unused_cid_purge);
+                                          swf_data, swf_data_len);
     if (result) {
         RETURN_FALSE;
     }
+    if (unused_cid_purge) {
+        swf_object_purge_useless_cid(swf);
+    }
     RETURN_TRUE;
 }
 

Modified: trunk/src/swf_object.c
===================================================================
--- trunk/src/swf_object.c	2011-03-26 12:26:01 UTC (rev 474)
+++ trunk/src/swf_object.c	2011-03-27 14:22:07 UTC (rev 475)
@@ -232,6 +232,69 @@
     }
 }
 
+void
+swf_object_purge_useless_cid(swf_object_t *swf) {
+    swf_tag_t *tag;
+    trans_table_t *refcid_trans_table;
+    if (swf == NULL) {
+        fprintf(stderr, "swf_object_purge_useless_cid: swf == NULL\n");
+        return ;
+    }
+    refcid_trans_table = trans_table_open();
+    if (refcid_trans_table == NULL) {
+        fprintf(stderr, "swf_object_purge_useless_cid: trans_table_open failed\n");
+        return ;
+    }
+    // 後ろから走査
+    for (tag = swf->tag_tail; tag ; tag = tag->prev) {
+        int refcid = swf_tag_get_refcid(tag);
+        if (refcid > 0) {
+            // 制御系タグに参照IDがある場合は登録
+            trans_table_set(refcid_trans_table, refcid, TRANS_TABLE_RESERVE_ID);
+            continue;
+        }
+        int cid = swf_tag_get_cid(tag);
+        if (cid <= 0) {
+            continue;
+        }
+        // 以下コンテンツ系のタグ
+        if (trans_table_get(refcid_trans_table, cid) == TRANS_TABLE_RESERVE_ID) {
+            // no purge
+            if (isShapeTag(tag->tag)) {
+                int bitmap_id = swf_tag_shape_bitmap_get_refcid(tag);
+                if (bitmap_id > 0) {
+                    trans_table_set(refcid_trans_table, bitmap_id, TRANS_TABLE_RESERVE_ID);
+                }
+            }
+            if (isSpriteTag(tag->tag)) {
+                swf_tag_t *t;
+                swf_tag_sprite_detail_t *tag_sprite;
+                tag_sprite = swf_tag_create_input_detail(tag, swf);
+                if (tag_sprite == NULL) {
+                    fprintf(stderr, "swf_object_purge_useless_cid: tag_sprite == NULL\n");
+                } else {
+                    for (t = tag_sprite->tag ; t ; t = t->next) {
+                        int rid = swf_tag_get_refcid(t);
+                        if (rid > 0) {
+                            trans_table_set(refcid_trans_table, rid, TRANS_TABLE_RESERVE_ID);
+                        }
+                    }
+                }
+            }
+        } else { // Purge!
+            if (isShapeTag(tag->tag) || isBitmapTag(tag->tag)) {
+                // TODO:  tag == head ? tag == tail ? OK?
+                swf_tag_t *next_tag = tag->next;
+                tag->prev->next = tag->next;
+                tag->next->prev = tag->prev;
+                swf_tag_destroy(tag);
+                tag = next_tag;
+            }
+        }
+    }
+    trans_table_close(refcid_trans_table);
+}
+
 /* --- */
 
 unsigned char *
@@ -901,30 +964,6 @@
 }
 
 /*
- * 参照側の全 cid 値を取得する
- */
-static void
-trans_table_reserve_refcid_recursive(swf_tag_t *tag, trans_table_t *trans_table) {
-    for (; tag ; tag=tag->next) {
-        int tag_no = tag->tag;
-        if (isPlaceTag(tag_no)) {
-            int refcid = swf_tag_get_refcid(tag);
-            if (refcid > 0) {
-                trans_table_set(trans_table, refcid, TRANS_TABLE_RESERVE_ID);
-            }
-        } else if (isSpriteTag(tag_no)) {
-            swf_tag_sprite_detail_t *tag_sprite;
-            tag_sprite = swf_tag_create_input_detail(tag, NULL);
-            if (tag_sprite == NULL) {
-                fprintf(stderr, "trans_table_reserve_refcid_recursive: tag_sprite swf_tag_create_input_detail failed\n");
-                continue; // skip wrong sprite tag
-            }
-            trans_table_reserve_refcid_recursive(tag_sprite->tag, trans_table);
-        }
-    }
-}
-
-/*
  * 参照側の cid 値を入れ替える
  */
 static void
@@ -953,11 +992,9 @@
 int
 swf_object_replace_movieclip(swf_object_t *swf,
                              unsigned char *instance_name, int instance_name_len,
-                             unsigned char *swf_data, int swf_data_len,
-			     int unused_cid_purge) {
+                             unsigned char *swf_data, int swf_data_len) {
     int cid = 0, sprite_cid = 0, ret = 0;
     swf_tag_t *tag = NULL;
-    swf_tag_t *prev_tag = NULL;
     swf_tag_t *sprite_tag = NULL, *prev_sprite_tag = NULL;
     swf_tag_t *sprite_tag_tail = NULL; // sprite の中の最後の tag
     swf_tag_sprite_detail_t *swf_tag_sprite = NULL;
@@ -965,7 +1002,6 @@
     swf_tag_info_t *tag_info = NULL;
     swf_tag_detail_handler_t *detail_handler = NULL;
     trans_table_t *cid_trans_table = NULL;
-    trans_table_t *orig_sprite_refcid_trans_table = NULL;
 
     if (swf == NULL) {
         fprintf(stderr, "swf_object_replace_movieclip: swf == NULL\n");
@@ -1010,57 +1046,7 @@
         fprintf(stderr, "swf_object_replace_movieclip: swf_object_input (swf_data_len=%d) failed\n", swf_data_len);
         return ret;
     }
-    
 
-    if (unused_cid_purge) {
-        orig_sprite_refcid_trans_table = trans_table_open();
-        // Sprite タグから参照するコンテンツを削除する
-        swf_tag_sprite = swf_tag_create_input_detail(sprite_tag, NULL);
-        trans_table_reserve_refcid_recursive(swf_tag_sprite->tag, orig_sprite_refcid_trans_table);
-        //    trans_table_print(orig_sprite_refcid_trans_table);
-        for (tag=swf->tag_head ; tag ; tag=tag->next) {
-            int cid;
-            cid = swf_tag_get_cid(tag);
-            if ((cid > 0) && (trans_table_get(orig_sprite_refcid_trans_table, cid) == TRANS_TABLE_RESERVE_ID)) {
-                // Shape が参照するビットマップも後で削除
-                if (isShapeTag(tag->tag)) {
-                    int bitmap_id;
-                    bitmap_id = swf_tag_shape_bitmap_get_refcid(tag);
-                    trans_table_set(orig_sprite_refcid_trans_table, bitmap_id, TRANS_TABLE_RESERVE_ID);
-                }
-                // タグ削除処理
-                prev_tag->next = tag->next;
-                swf_tag_destroy(tag);
-                tag = prev_tag;
-            } else {
-                prev_tag = tag;
-            }
-        }
-        // Shape が参照するビットマップを削除
-        for (tag=swf->tag_head ; tag ; tag=tag->next) {
-            cid = swf_tag_get_cid(tag);
-            if ((cid > 0) && (trans_table_get(orig_sprite_refcid_trans_table, cid) == TRANS_TABLE_RESERVE_ID)) {
-                prev_tag->next = tag->next;
-                swf_tag_destroy(tag);
-                tag = prev_tag;
-            } else {
-                prev_tag = tag;
-            }
-        }
-        
-        // prev_sprite_tag を取り直す。(PURGE される事があるので)
-        for (tag=swf->tag_head ; tag ; tag=tag->next) {
-            if (isSpriteTag(tag->tag)) {
-                if (swf_tag_get_cid(tag) == sprite_cid) {
-                    break;
-                }
-            }
-            prev_sprite_tag = tag;
-        }
-    } else { // orig_sprite_refcid_trans_table : false
-        orig_sprite_refcid_trans_table = NULL;
-    }
-    
     // 既存の CID
     cid_trans_table = trans_table_open();
     for (tag=swf->tag_head ; tag ; tag=tag->next) {
@@ -1211,9 +1197,6 @@
         }
     }
     trans_table_close(cid_trans_table);
-    if (orig_sprite_refcid_trans_table) { // orig_sprite_refcid_trans_table
-      trans_table_close(orig_sprite_refcid_trans_table);
-    }
     swf_object_close(swf4sprite);
     return 0;
 }

Modified: trunk/src/swf_object.h
===================================================================
--- trunk/src/swf_object.h	2011-03-26 12:26:01 UTC (rev 474)
+++ trunk/src/swf_object.h	2011-03-27 14:22:07 UTC (rev 475)
@@ -34,6 +34,7 @@
 /* --- */
 
 extern void swf_object_rebuild(swf_object_t *swf);
+extern void swf_object_purge_cid(swf_object_t *swf);
 
 /* --- */
 
@@ -106,8 +107,7 @@
                                         unsigned char *instance_name,
                                         int instancee_name_len,
                                         unsigned char *swf_data,
-                                        int swf_data_len,
-                                        int unused_cid_purge);
+                                        int swf_data_len);
 
 extern int swf_object_apply_shapematrix_factor(swf_object_t *swf,int shape_id,
                                                double scale_x, double scale_y,



Swfed-svn メーリングリストの案内
Back to archive index