OSDN Git Service

add bitmap_id parameter into apply factor method.
[swfed/swfed.git] / src / swf_fill_style_array.c
1 #include <stdio.h>
2 #include <stdlib.h> // calloc
3 #include "bitstream.h"
4 #include "swf_fill_style_array.h"
5 #include "swf_tag_shape.h"
6
7 int
8 swf_fill_style_array_parse(bitstream_t *bs,
9                            swf_fill_style_array_t *fill_style_array,
10                            swf_tag_t *tag) {
11     int i;
12     int result;
13     swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
14     
15     fill_style_array->count = bitstream_getbyte(bs);
16
17     if (swf_tag_shape->_parse_condition == SWF_TAG_SHAPE_PARSE_CONDITION_BITMAP) {
18         if (fill_style_array->count == 0) {
19             return 1;
20         }
21     }
22     
23     if ((tag->code != 2) && // ! DefineShape
24         (fill_style_array->count == 255)) {
25         fill_style_array->count = bitstream_getbytesLE(bs, 2);
26     }
27     fill_style_array->fill_style = calloc(fill_style_array->count, sizeof(swf_fill_style_t));
28     for (i = 0 ; i < fill_style_array->count ; i++) {
29         result = swf_fill_style_parse(bs, &(fill_style_array->fill_style[i]), tag);
30         if (result) {
31             fprintf(stderr, "swf_fill_style_array_parse: swf_fill_style_parse failed i=%d\n", i);
32             fill_style_array->count = i;
33             return 1;
34         }
35     }
36     return 0;
37 }
38
39 int
40 swf_fill_style_array_build(bitstream_t *bs,
41                            swf_fill_style_array_t *fill_style_array,
42                            swf_tag_t *tag) {
43     int i;
44     int ret;
45     if ((tag->code == 2) || // DefineShape
46         ((tag->code > 2) && (fill_style_array->count < 255))) {
47         bitstream_putbyte(bs, fill_style_array->count);
48     } else {
49         bitstream_putbyte(bs, 255);
50         bitstream_putbytesLE(bs, fill_style_array->count, 2);
51     }
52     for (i = 0 ; i < fill_style_array->count ; i++) {
53         ret = swf_fill_style_build(bs, &(fill_style_array->fill_style[i]), tag);
54         if (ret != 0) {
55             fprintf(stderr, "swf_fill_style_array_build: swf_fill_style_build failed i=%d/count=%d\n", i, fill_style_array->count);
56             return 1;
57         }
58     }
59     return 0;
60 }
61
62 int
63 swf_fill_style_array_print(swf_fill_style_array_t *fill_style_array,
64                            int indent_depth, swf_tag_t *tag) {
65     int i;
66     print_indent(indent_depth);
67     printf("fill_style_array->count=%u\n", fill_style_array->count);
68     for (i = 0 ; i < fill_style_array->count ; i++) {
69         print_indent(indent_depth);
70         printf("[%d] ", i+1);
71         swf_fill_style_print(&(fill_style_array->fill_style[i]),
72                              indent_depth + 1, tag);
73     }
74     return 0;
75 }
76
77 int
78 swf_fill_style_array_delete(swf_fill_style_array_t *fill_style_array) {
79     int i;
80     for (i = 0 ; i < fill_style_array->count ; i++) {
81         swf_fill_style_delete(&(fill_style_array->fill_style[i]));
82     }
83     free(fill_style_array->fill_style);
84     return 0;
85 }