[Swfed-svn] swfed-svn [392] Defineタグ内の CID renum 処理を実装

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 8日 (火) 02:18:45 JST


Revision: 392
          http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=392
Author:   yoya
Date:     2011-03-08 02:18:45 +0900 (Tue, 08 Mar 2011)

Log Message:
-----------
Defineタグ内の CID renum 処理を実装

Modified Paths:
--------------
    trunk/src/config.m4
    trunk/src/swf_object.c

Added Paths:
-----------
    trunk/src/trans_table.c
    trunk/src/trans_table.h


-------------- next part --------------
Modified: trunk/src/config.m4
===================================================================
--- trunk/src/config.m4	2011-03-07 14:21:37 UTC (rev 391)
+++ trunk/src/config.m4	2011-03-07 17:18:45 UTC (rev 392)
@@ -74,6 +74,6 @@
 	swf_shape_record_edge.c swf_gradient.c  swf_gradient_record.c \
 	swf_tag_jpeg.c swf_tag_edit.c swf_tag_action.c swf_tag_lossless.c \
 	swf_tag_sound.c swf_tag_sprite.c swf_tag_shape.c y_keyvalue.c \
-	swf_tag_place.c swf_cxform.c \
+	swf_tag_place.c swf_cxform.c trans_table.c \
 	, $ext_shared)
 fi

Modified: trunk/src/swf_object.c
===================================================================
--- trunk/src/swf_object.c	2011-03-07 14:21:37 UTC (rev 391)
+++ trunk/src/swf_object.c	2011-03-07 17:18:45 UTC (rev 392)
@@ -20,6 +20,7 @@
 #include "swf_action.h"
 #include "swf_object.h"
 #include "bitmap_util.h"
+#include "trans_table.h"
 
 swf_object_t *
 swf_object_open(void) {
@@ -864,10 +865,10 @@
     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;
-    swf_object_t *swf4sprite;
-    swf_tag_info_t *tag_info;
-    swf_tag_detail_handler_t *detail_handler;
-    
+    swf_object_t *swf4sprite = NULL;
+    swf_tag_info_t *tag_info = NULL;
+    swf_tag_detail_handler_t *detail_handler = NULL;
+    trans_table_t *cid_trans_table;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_replace_movieclip: swf == NULL\n");
         return 1;
@@ -905,6 +906,15 @@
         fprintf(stderr, "swf_object_replace_movieclip: swf_object_input (swf_data_len=%d) failed\n", swf_data_len);
         return ret;
     }
+    // 既存の CID をチェックする
+    cid_trans_table = trans_table_open();
+    for (tag=swf->tag ; tag ; tag=tag->next) {
+        int cid;
+        cid = swf_tag_get_cid(tag);
+        if (cid > 0) {
+            trans_table_set(cid_trans_table, cid, TRANS_TABLE_RESERVE_ID);
+        }
+    }
     // Sprite タグの中を綺麗にする
     tag_info = get_swf_tag_info(sprite_tag->tag);
     detail_handler = tag_info->detail_handler();
@@ -962,8 +972,32 @@
           case 83: // DefineShape4
           case 84: // DefineMorphShape2
           case 88: // DefineFontName
-            // Sprite の前に CID が被らないように展開
-            // TODO depth が被らないように。
+              // CID 変更
+              cid = swf_tag_get_cid(tag);
+              if (cid > 0) {
+                  int to_cid;
+                  to_cid = trans_table_get(cid_trans_table, cid);
+                  if (to_cid == TRANS_TABLE_RESERVE_ID) {
+                      to_cid = trans_table_get_freeid(cid_trans_table);
+                      trans_table_set(cid_trans_table, cid, to_cid);
+                      trans_table_set(cid_trans_table, to_cid, TRANS_TABLE_RESERVE_ID);
+                  } else if (to_cid == 0) {
+                      trans_table_set(cid_trans_table, cid, cid);
+                      to_cid = cid;
+                  }
+                  fprintf(stderr, "XXX: swf_tag_replace_cid: tag(cid=%d), to_cid(%d)\n", cid, to_cid);
+                  swf_tag_replace_cid(tag, to_cid);
+              }
+              if (isShapeTag(tag_no)) {
+                  int  bitmap_id = swf_tag_shape_bitmap_get_refcid(tag);
+                  if (bitmap_id > 0) {
+                      int to_bitmap_id = trans_table_get(cid_trans_table, bitmap_id);
+                      swf_tag_shape_bitmap_replace_refcid(tag, to_bitmap_id);
+                  }
+              }
+              // TODO depth が被らないように。
+              ;
+              // Sprite の前に CID が被らないように展開
               prev_sprite_tag->next = swf_tag_move(tag);
               prev_sprite_tag = prev_sprite_tag->next;
               prev_sprite_tag->next = sprite_tag;
@@ -980,8 +1014,11 @@
           case 59: // DoInitAction
             // Sprite の中に挿入
             // TODO: Character ID の変更に追随
+              switch (tag_no) {
+                case 26: // PlaceObject2
+                    
+              }
             // TODO: 変数スコープ
-              ;
               if (sprite_tag_tail == NULL) {
                   swf_tag_sprite->tag = swf_tag_move(tag);
                   sprite_tag_tail = swf_tag_sprite->tag;
@@ -997,6 +1034,7 @@
         }
     }
     swf_object_close(swf4sprite);
+    trans_table_close(cid_trans_table);
     return 0;
 }
 

Added: trunk/src/trans_table.c
===================================================================
--- trunk/src/trans_table.c	                        (rev 0)
+++ trunk/src/trans_table.c	2011-03-07 17:18:45 UTC (rev 392)
@@ -0,0 +1,60 @@
+#include <stdlib.h>
+#include "trans_table.h"
+
+trans_table_t *
+trans_table_open() {
+    trans_table_t *trans_table;
+    trans_table = calloc(sizeof(*trans_table), 1);
+    trans_table->table_num = 256; // XXX
+    trans_table->table = calloc(trans_table->table_num, sizeof(int));
+    return trans_table;
+}
+void
+trans_table_close(trans_table_t *trans_table) {
+    if (trans_table) {
+        if (trans_table->table) {
+            free(trans_table->table);
+        }
+        free(trans_table);
+    }
+}
+
+int
+trans_table_realloc(trans_table_t *trans_table, int offset) {
+    int new_table_num = trans_table->table_num;
+    int i;
+    while (new_table_num <= offset) {
+        new_table_num *= 2;
+    }
+    trans_table->table = realloc(trans_table->table, new_table_num);
+    for (i = trans_table->table_num ; i < new_table_num ; i++) {
+        trans_table->table[i] = 0;
+    }
+}
+int
+trans_table_get(trans_table_t  *trans_table, int offset) {
+    if (trans_table->table_num <= offset) {
+        return 0;
+    }
+    return trans_table->table[offset];
+}
+int
+trans_table_set(trans_table_t  *trans_table, int offset, int cid) {
+    int i, new_table_num;
+    if (trans_table->table_num <= offset) {
+        trans_table_realloc(trans_table, offset);
+    }
+    trans_table->table[offset] = cid;
+}
+int
+trans_table_get_freeid(trans_table_t  *trans_table) {
+    int i;
+    // 0 は選択させない
+    for (i = 1 ; i < trans_table->table_num ; i++) {
+        if (trans_table->table[i] == 0) {
+            return i;
+        }
+    }
+    trans_table_realloc(trans_table, i);
+    return i;
+}

Added: trunk/src/trans_table.h
===================================================================
--- trunk/src/trans_table.h	                        (rev 0)
+++ trunk/src/trans_table.h	2011-03-07 17:18:45 UTC (rev 392)
@@ -0,0 +1,18 @@
+#ifndef __TRANS_TABLE_H__
+#define __TRANS_TABLE_H__
+
+typedef struct _trans_table_t {
+    int *table;
+    int table_num;
+} trans_table_t;
+
+#define TRANS_TABLE_RESERVE_ID -1
+
+extern trans_table_t *trans_table_open();
+extern void trans_table_close(trans_table_t  *trans_table);
+
+extern int trans_table_get(trans_table_t  *trans_table, int offset);
+extern int trans_table_set(trans_table_t  *trans_table, int offset, int cid);
+extern int trans_table_get_freeid(trans_table_t  *trans_table);
+
+#endif /* __TRANS_TABLE_H__ */



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