[Swfed-svn] swfed-svn [377] インスタンス名に対応する PlaceTag => SpriteTag を探す処理を実装

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 4日 (金) 02:24:23 JST


Revision: 377
          http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=377
Author:   yoya
Date:     2011-03-04 02:24:23 +0900 (Fri, 04 Mar 2011)

Log Message:
-----------
インスタンス名に対応する PlaceTag => SpriteTag を探す処理を実装

Modified Paths:
--------------
    trunk/src/swf_object.c
    trunk/src/swf_object.h
    trunk/src/swf_tag_place.c
    trunk/src/swf_tag_place.h
    trunk/src/swf_tag_shape.c


-------------- next part --------------
Modified: trunk/src/swf_object.c
===================================================================
--- trunk/src/swf_object.c	2011-03-03 17:23:07 UTC (rev 376)
+++ trunk/src/swf_object.c	2011-03-03 17:24:23 UTC (rev 377)
@@ -15,6 +15,7 @@
 #include "swf_tag_jpeg.h"
 #include "swf_tag_lossless.h"
 #include "swf_tag_shape.h"
+#include "swf_tag_place.h"
 #include "swf_action.h"
 #include "swf_object.h"
 #include "bitmap_util.h"
@@ -855,29 +856,55 @@
 
 int
 swf_object_replace_movieclip(swf_object_t *swf,
-                             char *instance_name, int instancee_name_len,
-                             char *swf_data, int swf_data_len) {
-    int result = 1;
-    swf_tag_t *tag;
+                             unsigned char *instance_name, int instance_name_len,
+                             unsigned char *swf_data, int swf_data_len) {
+    int cid;
+    swf_tag_t *tag, *sprite_tag = NULL;
     if (swf == NULL) {
         fprintf(stderr, "swf_object_replace_movieclip: swf == NULL\n");
         return 1;
     }
     for (tag=swf->tag ; tag ; tag=tag->next) {
-        ; // searchPlaceTagByInstanceName;
+        if (tag->tag == 26) { // PlaceObject2
+            cid = swf_tag_place_get_cid_by_instance_name(tag, instance_name, instance_name_len);
+            if (cid > 0) {
+                break; // found
+            }
+        }
     }
+    if (cid <= 0) {
+        fprintf(stderr, "swf_object_replace_movieclip: place cid <= 0\n");
+        return 1; // not found instance name;
+    }
     for (tag=swf->tag ; tag ; tag=tag->next) {
-        ; // searchSpriteTagByCID
+        if (isSpriteTag(tag->tag)) {
+            if (swf_tag_identity(tag, cid) == 0) {
+                sprite_tag = tag;
+                break;
+            }
+        }
     }
+    if (sprite_tag == NULL) {
+        fprintf(stderr, "swf_object_replace_movieclip: sprite_tag == NULL\n");
+        return 1; // not found instance name;
+    }
+    swf_object_t *swf4sprite = swf_object_open();
+    swf_object_input(swf4sprite, swf_data, swf_data_len);
 
-/*
-    result = swf_tag_replace_movieclip(tag,
-                                       instance_name, instance_name_len,
-                                       swf_data, swf_data__len,
-                                       swf);
-*/
-
-    return result;
+    // Sprite 中のタグを削除
+    for (tag=swf4sprite->tag ; tag ; tag=tag->next) {
+        switch(tag->tag) {
+            // Character Tag
+            // Sprite の前に CID が被らないように展開
+            // TODO depth が被らないように。
+            break;
+            // Control Tag
+            // Sprite の中に挿入。
+            break;
+        }
+    }
+    swf_object_close(swf4sprite);
+    return 0;
 }
 
 int

Modified: trunk/src/swf_object.h
===================================================================
--- trunk/src/swf_object.h	2011-03-03 17:23:07 UTC (rev 376)
+++ trunk/src/swf_object.h	2011-03-03 17:24:23 UTC (rev 377)
@@ -98,9 +98,10 @@
                                                  y_keyvalue_t *kv);
 
 extern int swf_object_replace_movieclip(swf_object_t *swf,
-                                        char *instance_name,
+                                        unsigned char *instance_name,
                                         int instancee_name_len,
-                                        char *swf_data, int swf_data_len);
+                                        unsigned char *swf_data,
+                                        int swf_data_len);
 
 
 extern int swf_object_apply_shapematrix_factor(swf_object_t *swf,int shape_id,

Modified: trunk/src/swf_tag_place.c
===================================================================
--- trunk/src/swf_tag_place.c	2011-03-03 17:23:07 UTC (rev 376)
+++ trunk/src/swf_tag_place.c	2011-03-03 17:24:23 UTC (rev 377)
@@ -98,7 +98,7 @@
             swf_tag_place->ratio = bitstream_getbytesLE(bs, 2);
         }
         if (swf_tag_place->flag_has_name) {
-            swf_tag_place->name = bitstream_outputstring(bs);
+            swf_tag_place->name = (char *) bitstream_outputstring(bs);
         }
         if (swf_tag_place->flag_has_clip_depth) {
             swf_tag_place->clip_depth = bitstream_getbytesLE(bs, 2);   
@@ -173,7 +173,7 @@
             bitstream_putbytesLE(bs, swf_tag_place->ratio, 2);
         }
         if (swf_tag_place->flag_has_name) {
-            bitstream_putstring(bs, swf_tag_place->name, strlen(swf_tag_place->name) + 1);
+            bitstream_putstring(bs, (unsigned char *) swf_tag_place->name, strlen(swf_tag_place->name) + 1);
         }
         if (swf_tag_place->flag_has_clip_depth) {
             bitstream_putbytesLE(bs, swf_tag_place->clip_depth, 2);
@@ -249,3 +249,24 @@
     }
     return ;
 }
+
+int
+swf_tag_place_get_cid_by_instance_name(swf_tag_t *tag, unsigned char *instance_name, int instance_name_len) {
+    swf_tag_place_detail_t *swf_tag_place;
+    if (isPlaceTag(tag->tag)) {
+        fprintf(stderr, "swf_tag_place_get_cid_by_instance_name: ! isPlaceTag(%d)\n", tag->tag);
+        return 1; // wrong tag
+    }
+    if (tag->detail) {
+        tag->detail = swf_tag_place_create_detail();
+    }
+    swf_tag_place = (swf_tag_place_detail_t *) tag->detail;
+    if (swf_tag_place->flag_has_name == 0) {
+        return 1; // no name
+    }
+    if ((strlen(swf_tag_place->name) != (size_t) instance_name_len) ||
+        (strncmp(swf_tag_place->name, (char *) instance_name, (int) instance_name_len) != 0)) {
+        return 1; // name no match
+    }
+    return 0; // found
+}

Modified: trunk/src/swf_tag_place.h
===================================================================
--- trunk/src/swf_tag_place.h	2011-03-03 17:23:07 UTC (rev 376)
+++ trunk/src/swf_tag_place.h	2011-03-03 17:24:23 UTC (rev 377)
@@ -41,5 +41,7 @@
                                        int indent_depth);
 extern void swf_tag_place_destroy_detail(swf_tag_t *tag);
 
+extern int swf_tag_place_get_cid_by_instance_name(swf_tag_t *tag, unsigned char *instance_name, int instance_name_len);
+
 #endif /* __SWF_TAG_PLACE__H__ */
 

Modified: trunk/src/swf_tag_shape.c
===================================================================
--- trunk/src/swf_tag_shape.c	2011-03-03 17:23:07 UTC (rev 376)
+++ trunk/src/swf_tag_shape.c	2011-03-03 17:24:23 UTC (rev 377)
@@ -140,7 +140,8 @@
         return 1;
     }
     if (! isShapeTag(tag->tag)) {
-        fprintf(stderr, "swf_tag_shape_bitmap_identity: ! isShapeTag(tag->tag)\n");
+        fprintf(stderr, "swf_tag_shape_bitmap_identity: ! isShapeTag(%d)\n",
+                tag->tag);
         return 1;
     }
     if (tag->detail == NULL) {



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