OSDN Git Service

delete png_set_gAMA
[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         // tag->code == 2 の時は count == 255 でもここに来るように
48         bitstream_putbyte(bs, fill_style_array->count);
49     } else {
50         bitstream_putbyte(bs, 255);
51         bitstream_putbytesLE(bs, fill_style_array->count, 2);
52     }
53     for (i = 0 ; i < fill_style_array->count ; i++) {
54         ret = swf_fill_style_build(bs, &(fill_style_array->fill_style[i]), tag);
55         if (ret != 0) {
56             fprintf(stderr, "swf_fill_style_array_build: swf_fill_style_build failed i=%d/count=%d\n", i, fill_style_array->count);
57             return 1;
58         }
59     }
60     return 0;
61 }
62
63 int
64 swf_fill_style_array_print(swf_fill_style_array_t *fill_style_array,
65                            int indent_depth, swf_tag_t *tag) {
66     int i;
67     print_indent(indent_depth);
68     printf("fill_style_array->count=%u\n", fill_style_array->count);
69     for (i = 0 ; i < fill_style_array->count ; i++) {
70         print_indent(indent_depth);
71         printf("[%d] ", i+1);
72         swf_fill_style_print(&(fill_style_array->fill_style[i]),
73                              indent_depth + 1, tag);
74     }
75     return 0;
76 }
77
78 int
79 swf_fill_style_array_delete(swf_fill_style_array_t *fill_style_array) {
80     int i;
81     for (i = 0 ; i < fill_style_array->count ; i++) {
82         swf_fill_style_delete(&(fill_style_array->fill_style[i]));
83     }
84     free(fill_style_array->fill_style);
85     return 0;
86 }