OSDN Git Service

- swf_gradient_record.c の追加
authoryoya <yoya@7c90b180-03d5-4157-b861-58a559ae9d1e>
Thu, 4 Jun 2009 17:04:14 +0000 (17:04 +0000)
committeryoya <yoya@7c90b180-03d5-4157-b861-58a559ae9d1e>
Thu, 4 Jun 2009 17:04:14 +0000 (17:04 +0000)
- 他、関数の中身をいろいろ実装
TODO: swf_styles_count, swf_shape_record のその仲間たち。

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/swfed/trunk@142 7c90b180-03d5-4157-b861-58a559ae9d1e

15 files changed:
src/config.m4
src/swf_fill_style_bitmap.c
src/swf_fill_style_gradient.c
src/swf_fill_style_solid.c
src/swf_gradient.c
src/swf_gradient.h
src/swf_gradient_record.c [new file with mode: 0644]
src/swf_gradient_record.h
src/swf_line_style.c
src/swf_line_style.h
src/swf_line_style_array.c
src/swf_line_style_array.h
src/swf_shape_with_style.c
src/swf_styles.c
src/swf_tag_shape.c

index bf32d8f..94dd488 100644 (file)
@@ -61,6 +61,6 @@ if test "$PHP_SWFED" != "no"; then
   dnl
   dnl PHP_SUBST(SWFED_SHARED_LIBADD)
 
-  PHP_NEW_EXTENSION(swfed, swfed.c swf_object.c swf_header.c swf_rect.c swf_tag.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 swf_rgb.c swf_rgba.c swf_argb.c swf_xrgb.c swf_action.c swf_jpeg.c bitstream.c jpeg_segment.c swf_png.c swf_gif.c  swf_shape_with_style.c swf_styles.c swf_fill_style_array.c swf_fill_style.c swf_morph_shape_with_style.c swf_fill_style_solid.c swf_fill_style_gradient.c swf_fill_style_bitmap.c swf_line_style_array.c swf_line_style.c swf_styles_count.c swf_shape_record.c swf_gradient.c swf_matrix.c swf_debug.c, $ext_shared)
+  PHP_NEW_EXTENSION(swfed, swfed.c swf_object.c swf_header.c swf_rect.c swf_tag.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 swf_rgb.c swf_rgba.c swf_argb.c swf_xrgb.c swf_action.c swf_jpeg.c bitstream.c jpeg_segment.c swf_png.c swf_gif.c  swf_shape_with_style.c swf_styles.c swf_fill_style_array.c swf_fill_style.c swf_morph_shape_with_style.c swf_fill_style_solid.c swf_fill_style_gradient.c swf_fill_style_bitmap.c swf_line_style_array.c swf_line_style.c swf_styles_count.c swf_shape_record.c swf_gradient.c swf_matrix.c swf_gradient_record.c swf_debug.c, $ext_shared)
 fi
 
index 1a457e7..56e5836 100644 (file)
@@ -29,6 +29,8 @@ int
 swf_fill_style_bitmap_print(swf_fill_style_bitmap_t *fill_style_bitmap,
                             int indent_depth, swf_tag_t *tag) {
     print_indent(indent_depth);
+    printf("fill_style_bitmap\n");
+    print_indent(indent_depth);
     printf("bitmap_ref=%u\n", fill_style_bitmap->bitmap_ref);
     swf_matrix_print(&(fill_style_bitmap->bitmap_matrix), indent_depth);
     if (tag->tag == 46 || tag->tag == 84) { // DefineMorphShape, DefineMorphShape2
index f627e22..a5fc152 100644 (file)
@@ -10,26 +10,28 @@ swf_fill_style_gradient_parse(bitstream_t *bs,
     if (tag->tag == 46 || tag->tag == 84) {
         swf_matrix_parse(bs, &(fill_style_gradient->gradient_matrix_morph));
     }
-    swf_gradient_parse(bs, &(fill_style_gradient->gradient));
+    swf_gradient_parse(bs, &(fill_style_gradient->gradient), tag);
     return 0;
 }
 
 int
 swf_fill_style_gradient_build(bitstream_t *bs,
                               swf_fill_style_gradient_t *fill_style_gradient,
-                              swf_tag_ttag) {
+                              swf_tag_t *tag) {
     swf_matrix_build(bs, &(fill_style_gradient->gradient_matrix));
     // DefineMorphShape, DefineMorphShape2
     if (tag->tag == 46 || tag->tag == 84) {
         swf_matrix_build(bs, &(fill_style_gradient->gradient_matrix_morph));
     }
-     swf_gradient_build(bs, &(fill_style_gradient->gradient));
+    swf_gradient_build(bs, &(fill_style_gradient->gradient), tag);
     return 0;
 }
 
 int
 swf_fill_style_gradient_print(swf_fill_style_gradient_t *fill_style_gradient,
                               int indent_depth, swf_tag_t* tag) {
+    print_indent(indent_depth);
+    printf("fill_style_gradient\n");
     swf_matrix_print(&(fill_style_gradient->gradient_matrix),
                      indent_depth + 1);
     // DefineMorphShape, DefineMorphShape2
@@ -37,6 +39,6 @@ swf_fill_style_gradient_print(swf_fill_style_gradient_t *fill_style_gradient,
         swf_matrix_print(&(fill_style_gradient->gradient_matrix_morph),
                          indent_depth + 1);
     }
-    swf_gradient_print(&(fill_style_gradient->gradient), indent_depth);
+    swf_gradient_print(&(fill_style_gradient->gradient), indent_depth, tag);
     return 0;
 }
index 7795c48..8e379cd 100644 (file)
@@ -35,6 +35,8 @@ int
 swf_fill_style_solid_print(swf_fill_style_solid_t *fill_style_solid,
                            int indent_depth, swf_tag_t *tag
 ) {
+    print_indent(indent_depth);
+    printf("fill_style_solid\n");
     if (tag->tag == 46 || tag->tag == 84) { // DefineMorphShape, DefineMorphShape2
         swf_rgba_print(&(fill_style_solid->rgba), indent_depth + 1);
         swf_rgba_print(&(fill_style_solid->rgba_morph), indent_depth + 1);
index 00c7a60..3a64faa 100644 (file)
@@ -3,17 +3,33 @@
 #include "swf_gradient.h"
 
 int
-swf_gradient_parse(bitstream_t *bs, swf_gradient_t *gradient) {
+swf_gradient_parse(bitstream_t *bs, swf_gradient_t *gradient,
+                   swf_tag_t *tag) {
+    int i;
+    if (tag->tag == 83) { // DefineShape4
+        gradient->spread_mode = bitstream_getbits(bs, 2);
+        gradient->interpolation_mode = bitstream_getbits(bs, 2);
+        gradient->count = bitstream_getbits(bs, 4);
+    } else {
+        gradient->pad = bitstream_getbits(bs, 4);
+        gradient->count = bitstream_getbits(bs, 4);
+    }
+    for (i = 0 ; i < gradient->count ; i++) {
+        swf_grandient_record_parse(bs, &(gradient->gradient_record[i]));
+        gradient->focal_point = bitstream_getbytesLE(bs, 2);
+    }
     return 0;
 }
 
 int
-swf_gradient_build(bitstream_t *bs, swf_gradient_t *gradient) {
+swf_gradient_build(bitstream_t *bs, swf_gradient_t *gradient,
+                   swf_tag_t *tag) {
     return 0;
 }
 
 int
-swf_gradient_print(swf_gradient_t *gradient, int indent_depth) {
+swf_gradient_print(swf_gradient_t *gradient, int indent_depth,
+                   swf_tag_t *tag) {
     print_indent(indent_depth);
     return 0;
 }
index fd41750..639cde9 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef __SWF_GRADIENT_H__
 #define __SWF_GRADIENT_H__
 
+#include "swf_tag.h"
 #include "swf_gradient_record.h"
 
 typedef union swf_gradient_ {
@@ -19,8 +20,11 @@ typedef union swf_gradient_ {
     
 } swf_gradient_t;
 
-extern int swf_gradient_parse(bitstream_t *bs, swf_gradient_t *color);
-extern int swf_gradient_build(bitstream_t *bs, swf_gradient_t *color);
-extern int swf_gradient_print(swf_gradient_t *color, int indent_depth);
+extern int swf_gradient_parse(bitstream_t *bs, swf_gradient_t *gradient,
+                              swf_tag_t *tag);
+extern int swf_gradient_build(bitstream_t *bs, swf_gradient_t *gradient,
+                              swf_tag_t *tag);
+extern int swf_gradient_print(swf_gradient_t *gradient, int indent_depth,
+                              swf_tag_t *tag);
 
 #endif /* __SWF_GRADIENT_H__ */
diff --git a/src/swf_gradient_record.c b/src/swf_gradient_record.c
new file mode 100644 (file)
index 0000000..f080a59
--- /dev/null
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include "bitstream.h"
+#include "swf_gradient_record.h"
+
+int
+swf_gradient_record_parse(bitstream_t
+                          *bs, swf_gradient_record_t *gradient_record,
+                          swf_tag_t *tag) {
+    if (tag->tag == 46 || tag->tag == 84) { // DefineMorph || DefineMorphShape2
+        gradient_record->position = bitstream_getbyte(bs);
+        swf_rgba_parse(bs, &(gradient_record->rgba));
+        gradient_record->position_morph = bitstream_getbyte(bs);
+        swf_rgba_parse(bs, &(gradient_record->rgba_morph));
+    } else if (tag->tag == 32 || tag->tag == 83) {
+        // DefineShape3 || DefineShape4
+        gradient_record->position = bitstream_getbyte(bs);
+        swf_rgba_parse(bs, &(gradient_record->rgba));
+    } else {
+        gradient_record->position = bitstream_getbyte(bs);
+        swf_rgb_parse(bs, &(gradient_record->rgb));
+    }
+    return 0;
+}
+
+int
+swf_gradient_record_build(bitstream_t *bs,
+                          swf_gradient_record_t *gradient_record,
+                          swf_tag_t *tag) {
+    return 0;
+}
+
+int
+swf_gradient_record_print(swf_gradient_record_t *gradient_record,
+                          int indent_depth, swf_tag_t *tag) {
+    print_indent(indent_depth);
+    return 0;
+}
index 335340d..a00dbc4 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef __SWF_GRADIENT_RECORD_H__
 #define __SWF_GRADIENT_RECORD_H__
 
+#include "swf_tag.h"
 #include "swf_rgba.h"
 #include "swf_rgb.h"
 
@@ -18,8 +19,13 @@ typedef union swf_gradient_record_ {
     swf_rgb_t rgb; // other 
 } swf_gradient_record_t;
 
-extern int swf_gradient_record_parse(bitstream_t *bs, swf_gradient_record_t *color);
-extern int swf_gradient_record_build(bitstream_t *bs, swf_gradient_record_t *color);
-extern int swf_gradient_record_print(swf_gradient_record_t *color, int indent_depth);
+extern int swf_gradient_record_parse(bitstream_t *bs,
+                                     swf_gradient_record_t *gradient_record,
+                                     swf_tag_t *tag);
+extern int swf_gradient_record_build(bitstream_t *bs,
+                                     swf_gradient_record_t *gradient_record,
+                                     swf_tag_t *tag);
+extern int swf_gradient_record_print(swf_gradient_record_t *gradient_record,
+                                     int indent_depth, swf_tag_t *tag);
 
 #endif /* __SWF_GRADIENT_RECORD_H__ */
index cd74be8..9af2e56 100644 (file)
@@ -2,19 +2,58 @@
 #include "bitstream.h"
 #include "swf_line_style.h"
 
-swf_line_style_parse(bitstream_t *bs, swf_line_style_t *line_style) {
-    ;
+swf_line_style_parse(bitstream_t *bs, swf_line_style_t *line_style,
+                     swf_tag_t *tag) {
+    if (tag->tag == 46) { // DefineMorphShape
+        line_style->width = bitstream_getbytesLE(bs, 2);
+        line_style->width_morph = bitstream_getbytesLE(bs, 2);
+        swf_rgba_parse(bs, &(line_style->rgba));
+        swf_rgba_parse(bs, &(line_style->rgba_morph));
+    } else if (tag->tag == 83 || tag->tag == 84) {
+        // DefineShape4 || DefineMorphShape2
+        if (tag->tag == 84) { // DefineMorphShape2
+            line_style->width_morph = bitstream_getbytesLE(bs, 2);
+        }
+        line_style->start_cap_style = bitstream_getbits(bs, 2);
+        line_style->join_style = bitstream_getbits(bs, 2);
+        line_style->has_fill = bitstream_getbits(bs, 1);
+        line_style->no_hscale = bitstream_getbits(bs, 1);
+        line_style->no_vscale = bitstream_getbits(bs, 1);
+        line_style->pixel_hinting = bitstream_getbits(bs, 1);
+        line_style->reserved = bitstream_getbits(bs, 5);
+        line_style->no_close = bitstream_getbits(bs, 1);
+        line_style->end_cap_style = bitstream_getbits(bs, 2);
+        if (line_style->join_style == 2) {
+            line_style->miter_limit_factor = bitstream_getbytesLE(bs, 2);
+        }
+        if (line_style->has_fill) {
+            swf_fill_style_parse(bs, &(line_style->fill_style), tag);
+        } else {
+            swf_rgba_parse(bs, &(line_style->rgba));
+            if (tag->tag == 84) { // DefineMorphShape2
+                swf_rgba_parse(bs, &(line_style->rgba_morph));
+            }
+        }
+    } else if (tag->tag == 32) { // DefineShape3
+        line_style->width = bitstream_getbytesLE(bs, 2);
+        swf_rgba_parse(bs, &(line_style->rgba));
+    } else {
+        line_style->width = bitstream_getbytesLE(bs, 2);
+        swf_rgb_parse(bs, &(line_style->rgb));
+    }
     return 0;
 }
 
 int
-swf_line_style_build(bitstream_t *bs, swf_line_style_t *line_style) {
+swf_line_style_build(bitstream_t *bs, swf_line_style_t *line_style,
+                     swf_tag_t *tag) {
     ;
     return 0;
 }
 
 int
-swf_line_style_print(swf_line_style_t *line_style, int indent_depth) {
+swf_line_style_print(swf_line_style_t *line_style, int indent_depth,
+                     swf_tag_t *tag) {
     ;
     return 0;
 }
index dec5317..7bd1bfd 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef __SWF_LINE_STYLE_H__
 #define __SWF_LINE_STYLE_H__
 
+#include "swf_tag.h"
 #include "swf_rgba.h"
 #include "swf_fill_style.h"
 #include "swf_rgb.h"
@@ -32,8 +33,11 @@ typedef union swf_line_style_ {
     
 } swf_line_style_t;
 
-extern int swf_line_style_parse(bitstream_t *bs, swf_line_style_t *color);
-extern int swf_line_style_build(bitstream_t *bs, swf_line_style_t *color);
-extern int swf_line_style_print(swf_line_style_t *color, int indent_depth);
+extern int swf_line_style_parse(bitstream_t *bs,
+                                swf_line_style_t *line_style, swf_tag_t *tag);
+extern int swf_line_style_build(bitstream_t *bs,
+                                swf_line_style_t *line_style, swf_tag_t *tag);
+extern int swf_line_style_print(swf_line_style_t *line_style,
+                                int indent_depth, swf_tag_t *tag);
 
 #endif /* __SWF_LINE_STYLE_H__ */
index 551b54c..f87f39d 100644 (file)
@@ -1,23 +1,53 @@
 #include <stdio.h>
+#include <stdlib.h> // calloc
 #include "bitstream.h"
 #include "swf_line_style_array.h"
 
+int
 swf_line_style_array_parse(bitstream_t *bs,
-                           swf_line_style_array_t *line_style_array) {
-    ;
+                           swf_line_style_array_t *shape_with_style,
+                           swf_tag_t *tag) {
+    int i;
+    shape_with_style->count = bitstream_getbyte(bs);
+    if (tag->tag != 2 || // ! DefineShape
+        shape_with_style->count == 255) {
+        shape_with_style->count = bitstream_getbytesLE(bs, 2);
+    }
+    shape_with_style->line_style = calloc(shape_with_style->count, sizeof(swf_line_style_t)); // XXX free !!! XXX
+    for (i = 0 ; i < shape_with_style->count ; i++) {
+        swf_line_style_parse(bs, &(shape_with_style->line_style[i]), tag);
+    }
     return 0;
 }
 
 int
-swf_line_style_array_build(bitstream_t *bs,
-                           swf_line_style_array_t *line_style_array) {
-    ;
-    return 0;
+swf_line_style_array_build(bitstream_t *bs, swf_line_style_array_t *shape_with_style, swf_tag_t *tag) {
+    int i;
+    if (tag->tag != 2 || // ! DefineShape
+        255 <= shape_with_style->count) {
+        bitstream_putbyte(bs, 255);
+        bitstream_putbytesLE(bs, shape_with_style->count, 2);
+    } else {
+        bitstream_putbyte(bs, shape_with_style->count);
+    }
+    for (i = 0 ; i < shape_with_style->count ; i++) {
+        swf_line_style_built(bs, &(shape_with_style->line_style[i]), tag);
+    }
 }
 
 int
-swf_line_style_array_print(swf_line_style_array_t *line_style_array,
-                           int indent_depth) {
-    ;
+swf_line_style_array_print(swf_line_style_array_t *shape_with_style, int indent_depth, swf_tag_t *tag) {
+    int i;
+    print_indent(indent_depth);
+    printf("count=%u\n", shape_with_style->count);
+    for (i = 0 ; i < shape_with_style->count ; i++) {
+        swf_line_style_print(&(shape_with_style->line_style[i]),
+                             indent_depth + 1, tag);
+    }
     return 0;
 }
+
+int
+swf_line_style_array_delete(swf_line_style_array_t *line_style_array) {
+    free(line_style_array->line_style);
+}
index fac222d..2730074 100644 (file)
@@ -14,8 +14,14 @@ typedef struct swf_line_style_array_ {
     swf_line_style_t *line_style;
 } swf_line_style_array_t;
 
-extern int swf_line_style_array_parse(bitstream_t *bs, swf_line_style_array_t *color);
-extern int swf_line_style_array_build(bitstream_t *bs, swf_line_style_array_t *color);
-extern int swf_line_style_array_print(swf_line_style_array_t *color, int indent_depth);
+extern int swf_line_style_array_parse(bitstream_t *bs,
+                                      swf_line_style_array_t *line_style_array,
+                                      swf_tag_t *tag);
+extern int swf_line_style_array_build(bitstream_t *bs,
+                                      swf_line_style_array_t *line_style_array,
+                                      swf_tag_t *tag);
+extern int swf_line_style_array_print(swf_line_style_array_t *line_style_array,
+                                      int indent_depth, swf_tag_t *tag);
+extern int swf_line_style_array_delete(swf_line_style_array_t *line_style_array);
 
 #endif /* __SWF_LINE_STYLE_ARRAY_H__ */
index 805285d..8bc2ad1 100644 (file)
@@ -21,6 +21,6 @@ swf_shape_with_style_build(bitstream_t *bs, swf_shape_with_style_t *shape_with_s
 int
 swf_shape_with_style_print(swf_shape_with_style_t *shape_with_style, int indent_depth, swf_tag_t *tag) {
     swf_styles_print(&(shape_with_style->styles), indent_depth, tag);
-//   swf_shape_record_print(&(shape_with_style->shape_records), indent_depth);
+    swf_shape_record_print(&(shape_with_style->shape_records), indent_depth);
     return 0;
 }
index cd11764..91c0d4c 100644 (file)
@@ -6,7 +6,7 @@ int
 swf_styles_parse(bitstream_t *bs, swf_styles_t *shape_with_style,
                  swf_tag_t *tag) {
     swf_fill_style_array_parse(bs, &(shape_with_style->fill_styles), tag);
-    swf_line_style_array_parse(bs, &(shape_with_style->line_styles));
+    swf_line_style_array_parse(bs, &(shape_with_style->line_styles), tag);
     swf_styles_count_parse(bs, &(shape_with_style->styles_count));
     return 0;
 }
@@ -15,7 +15,7 @@ int
 swf_styles_build(bitstream_t *bs, swf_styles_t *shape_with_style,
                  swf_tag_t *tag) {
     swf_fill_style_array_build(bs, &(shape_with_style->fill_styles), tag);
-    swf_line_style_array_build(bs, &(shape_with_style->line_styles));
+    swf_line_style_array_build(bs, &(shape_with_style->line_styles), tag);
     swf_styles_count_build(bs, &(shape_with_style->styles_count));
     return 0;
 }
@@ -25,7 +25,8 @@ swf_styles_print(swf_styles_t *shape_with_style, int indent_depth,
                  swf_tag_t *tag) {
     swf_fill_style_array_print(&(shape_with_style->fill_styles), indent_depth,
         tag);
-    swf_line_style_array_print(&(shape_with_style->line_styles), indent_depth);
+    swf_line_style_array_print(&(shape_with_style->line_styles), indent_depth,
+        tag);
     swf_styles_count_print(&(shape_with_style->styles_count), indent_depth);
     return 0;
 }
@@ -33,4 +34,5 @@ swf_styles_print(swf_styles_t *shape_with_style, int indent_depth,
 int
 swf_styles_delete(swf_styles_t *styles) {
     swf_fill_styles_array_delete(&(styles->fill_styles));
+    swf_line_styles_array_delete(&(styles->line_styles));
 }
index 6fcccae..c1d718d 100644 (file)
@@ -152,6 +152,7 @@ void
 swf_tag_shape_destroy_detail(swf_tag_t *tag) {
     swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
     if (swf_tag_shape) {
+        swf_morph_shape_with_style_delete(&(swf_tag_shape->morph_shape_with_style));
         free(swf_tag_shape);
     }
     return ;