OSDN Git Service

add bitmap_id parameter into apply factor method.
[swfed/swfed.git] / src / swf_fill_style.c
1 #include <stdio.h>
2 #include "bitstream.h"
3 #include "swf_fill_style.h"
4 #include "swf_tag_shape.h"
5
6 int
7 swf_fill_style_parse(bitstream_t *bs, swf_fill_style_t *fill_style,
8                      swf_tag_t * tag) {
9     swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
10         
11     fill_style->type = bitstream_getbyte(bs);
12
13     if (swf_tag_shape->_parse_condition == SWF_TAG_SHAPE_PARSE_CONDITION_BITMAP) {
14         if ((fill_style->type < 0x40) ||  (0x43 < fill_style->type)) {
15             return 1;
16         }
17     }
18     
19     switch (fill_style->type) {
20       case 0x00: // solid fill
21         swf_fill_style_solid_parse(bs, &(fill_style->solid), tag);
22         break;
23       case 0x10: // linear gradient fill
24       case 0x12: // radial gradient fill
25       case 0x13: // focal  gradient fill
26         swf_fill_style_gradient_parse(bs, &(fill_style->gradient), tag);
27         break;
28       case 0x40: // tilled  bitmap fill with smoothed edges
29       case 0x41: // clipped bitmap fill with smoothed edges
30       case 0x42: // tilled  bitmap fill with hard edges
31       case 0x43: // clipped bitmap fill with hard edges
32         swf_fill_style_bitmap_parse(bs, &(fill_style->bitmap), tag);
33         break;
34     default:
35         fprintf(stderr, "swf_fill_style_parse: unknown fill_style->type=0x%02x\n", fill_style->type);
36         return 1;
37     }
38     return 0;
39 }
40
41 int
42 swf_fill_style_build(bitstream_t *bs, swf_fill_style_t *fill_style,
43                      swf_tag_t *tag) {
44     if (fill_style == NULL) {
45         fprintf(stderr, "swf_fill_style_build: fill_style == NULL\n");
46         return 1;
47     }
48     bitstream_putbyte(bs, fill_style->type);
49     switch (fill_style->type) {
50       case 0x00: // solid fill
51         swf_fill_style_solid_build(bs, &(fill_style->solid), tag);
52         break;
53       case 0x10: // linear gradient fill
54       case 0x11: // radial gradient fill
55       case 0x12: // focal  gradient fill
56         swf_fill_style_gradient_build(bs, &(fill_style->gradient), tag);
57         break;
58       case 0x40: // tilled  bitmap fill with smoothed edges
59       case 0x41: // clipped bitmap fill with smoothed edges
60       case 0x42: // tilled  bitmap fill with hard edges
61       case 0x43: // clipped bitmap fill with hard edges
62         swf_fill_style_bitmap_build(bs, &(fill_style->bitmap), tag);
63         break;
64       default:
65         fprintf(stderr, "swf_fill_style_build: unknown fill_style->type=%d\n", fill_style->type);
66         return 1;
67     }
68     return 0;
69 }
70
71 int
72 swf_fill_style_print(swf_fill_style_t *fill_style, int indent_depth,
73     swf_tag_t *tag) {
74     if (fill_style == NULL) {
75         fprintf(stderr, "swf_fill_style_print: fill_style == NULL\n");
76         return 1;
77     }
78     printf("type=0x%02x\n", fill_style->type);
79     switch (fill_style->type) {
80       case 0x00: // solid fill
81           swf_fill_style_solid_print(&(fill_style->solid),
82                                      indent_depth + 1, tag);
83           break;
84       case 0x10: // linear gradient fill
85       case 0x11: // radial gradient fill
86       case 0x12: // focal  gradient fill
87         swf_fill_style_gradient_print(&(fill_style->gradient),
88                                       indent_depth + 1, tag);
89         break;
90       case 0x40: // tilled  bitmap fill with smoothed edges
91       case 0x41: // clipped bitmap fill with smoothed edges
92       case 0x42: // tilled  bitmap fill with hard edges
93       case 0x43: // clipped bitmap fill with hard edges
94         swf_fill_style_bitmap_print(&(fill_style->bitmap),
95                                     indent_depth + 1, tag);
96         break;
97     }
98     return 0;
99 }
100
101 int
102 swf_fill_style_delete(swf_fill_style_t *fill_style) {
103     swf_fill_style_gradient_delete(&(fill_style->gradient));
104     return 0;
105 }