[Swfed-svn] swfed-svn [166] - getTagData を実装

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2009年 7月 2日 (木) 00:24:49 JST


Revision: 166
          http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=166
Author:   yoya
Date:     2009-07-02 00:24:49 +0900 (Thu, 02 Jul 2009)

Log Message:
-----------
- getTagData を実装
- replaceTagReplace はダミーを実装

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


-------------- next part --------------
Modified: trunk/src/php_swfed.h
===================================================================
--- trunk/src/php_swfed.h	2009-06-21 13:17:12 UTC (rev 165)
+++ trunk/src/php_swfed.h	2009-07-01 15:24:49 UTC (rev 166)
@@ -53,6 +53,7 @@
 PHP_METHOD(swfed, getTagDetail);
 PHP_METHOD(swfed, getTagInfo);
 PHP_METHOD(swfed, getTagData);
+PHP_METHOD(swfed, replaceTagData);
 PHP_METHOD(swfed, getJpegData);
 PHP_METHOD(swfed, getJpegAlpha);
 PHP_METHOD(swfed, replaceJpegData);

Modified: trunk/src/swf_object.c
===================================================================
--- trunk/src/swf_object.c	2009-06-21 13:17:12 UTC (rev 165)
+++ trunk/src/swf_object.c	2009-07-01 15:24:49 UTC (rev 166)
@@ -160,6 +160,9 @@
     bitstream_close(bs);
     return data;
 }
+
+/* --- */
+
 void
 swf_object_print(swf_object_t *swf) {
     int i;
@@ -177,7 +180,43 @@
     }
 }
 
+extern unsigned char *
+swf_object_get_tagdata(swf_object_t *swf, int tag_seqno,
+                       unsigned long *length) {
+    int i;
+    swf_tag_t *tag;
+    tag = swf->tag;
+    for (i=0 ; (i < tag_seqno) &&  tag ; i++) {
+        tag = tag->next;
+    }
+    if (tag) {
+        if (tag->data) {
+            *length = tag->length;
+            return tag->data;
+        }
+        if (tag->detail == NULL) {
+            bitstream_t *bs;
+            unsigned char *data;
+            bs = bitstream_open();
+            swf_tag_build(bs, tag, swf);
+            data = bitstream_steal(bs, length);
+            bitstream_close(bs);
+            return data;
+        }
+        if (tag->detail) {
+            *length = tag->length;
+            return tag->data;
+        }
+    }
+    return NULL;
+}
 
+int
+swf_object_replace_tagdata(swf_object_t *swf, int tag_seqno,
+                           unsigned char *data, unsigned long *length) {
+    return 1;
+}
+
 /* --- */
 
 unsigned char *

Modified: trunk/src/swf_object.h
===================================================================
--- trunk/src/swf_object.h	2009-06-21 13:17:12 UTC (rev 165)
+++ trunk/src/swf_object.h	2009-07-01 15:24:49 UTC (rev 166)
@@ -22,9 +22,18 @@
 extern void swf_object_close(swf_object_t *swf);
 extern int swf_object_input(swf_object_t *swf, unsigned char *data, unsigned long data_len);
 extern unsigned char *swf_object_output(swf_object_t *swf, unsigned long *length);
+
+/* --- */
+
 extern void swf_object_print(swf_object_t *swf);
+extern unsigned char *swf_object_get_tagdata(swf_object_t *swf, int tag_seqno,
+                                             unsigned long *length);
+extern int swf_object_replace_tagdata(swf_object_t *swf, int tag_seqno,
+                                      unsigned char *data,
+                                      unsigned long *length);
 
 /* --- */
+
 extern unsigned char *swf_object_get_jpegdata(swf_object_t *swf, unsigned long *length, int image_id);
 extern unsigned char *swf_object_get_alphadata(swf_object_t *swf, unsigned long *length, int image_id);
 extern int swf_object_replace_jpegdata(swf_object_t *swf, int image_id,

Modified: trunk/src/swfed.c
===================================================================
--- trunk/src/swfed.c	2009-06-21 13:17:12 UTC (rev 165)
+++ trunk/src/swfed.c	2009-07-01 15:24:49 UTC (rev 166)
@@ -57,6 +57,7 @@
       	PHP_ME(swfed,  getTagList, NULL, 0)
    	PHP_ME(swfed,  getTagDetail, NULL, 0)
        	PHP_ME(swfed,  getTagData, NULL, 0)
+        PHP_ME(swfed,  replaceTagData, NULL, 0)
    	PHP_ME(swfed,  getJpegData, NULL, 0)
    	PHP_ME(swfed,  getJpegAlpha, NULL, 0)
    	PHP_ME(swfed,  replaceJpegData, NULL, 0)
@@ -454,10 +455,56 @@
 }
 
 PHP_METHOD(swfed, getTagData) {
-    printf("not implemented yet.\n");
-    RETURN_FALSE;
+    long tag_seqno;
+    swf_object_t *swf;
+    unsigned char *data_ref;
+    char *new_buff;
+    unsigned long data_len;
+    
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_seqno) == FAILURE) {
+        RETURN_FALSE;
+    }
+    swf = get_swf_object(getThis() TSRMLS_CC);
+    data_ref = swf_object_get_tagdata(swf, tag_seqno, &data_len);
+    if (data_ref == NULL) {
+        fprintf(stderr, "getTagData: Can't get_tagdata\n");
+        RETURN_FALSE;
+    }
+    new_buff = emalloc(data_len);
+    if (new_buff == NULL) {
+        fprintf(stderr, "getTagData: Can't emalloc new_buff\n");
+        RETURN_FALSE;
+    }
+    memcpy(new_buff, data_ref, data_len);
+    RETURN_STRINGL(new_buff, data_len, 0);
 }
 
+PHP_METHOD(swfed, replaceTagData) {
+    char *data = NULL;
+    int data_len = 0;
+    int tag_seqno;
+    swf_object_t *swf;
+    int result = 0;
+    switch (ZEND_NUM_ARGS()) {
+      default:
+        WRONG_PARAM_COUNT;
+        RETURN_FALSE; /* XXX */
+      case 2:
+        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &tag_seqno, &data, &data_len) == FAILURE) {
+            RETURN_FALSE;
+        }
+        break;
+    }
+    swf = get_swf_object(getThis() TSRMLS_CC);
+    result = swf_object_replace_tagdata(swf, tag_seqno,
+                                        (unsigned char *)data,
+                                        (unsigned long) data_len);
+    if (result) {
+        RETURN_FALSE;
+    }
+    RETURN_TRUE;
+}
+
 PHP_METHOD(swfed, getJpegData) {
     unsigned long image_id = 0;
     unsigned long len = 0;
@@ -783,7 +830,6 @@
     }
     swf_action_list_destroy(action_list);
 }
-    
 
 PHP_METHOD(swfed, swfInfo) {
     swf_object_t *swf = get_swf_object(getThis() TSRMLS_CC);



Swfed-svn メーリングリストの案内
アーカイブの一覧に戻る