3 #include "swf_shape_record.h"
6 swf_shape_record_parse(bitstream_t *bs, swf_shape_record_t *shape_record,
8 int first_bit, next_5bits;
9 swf_shape_record_t *current_record = shape_record;
11 for (limit = 1; current_record ; limit ++) {
12 current_record->next = NULL; // stopper
13 int ret = bitstream_getbits(bs, 6);
15 fprintf(stderr, "swf_shape_record_parse: bitstream_getbits failed at L%d\n", __LINE__);
18 current_record->first_6bits = ret;
19 first_bit = (current_record->first_6bits >> 5) & 1;
20 next_5bits = current_record->first_6bits & 0x1f;
21 bitstream_incrpos(bs, 0, -6); // 6 bit back
22 if ((first_bit == 0) && (next_5bits == 0)) {
23 ret = swf_shape_record_end_parse(bs, &(current_record->shape.shape_end));
25 fprintf(stderr, "swf_shape_record_parse: swf_shape_record_end_parse at L%d\n", __LINE__);
29 } if (first_bit == 0) {
30 ret = swf_shape_record_setup_parse(bs, &(current_record->shape.shape_setup),
33 fprintf(stderr, "swf_shape_record_parse: swf_shape_record_setup_parse at L%d\n", __LINE__);
37 ret = swf_shape_record_edge_parse(bs, &(current_record->shape.shape_edge), tag);
39 fprintf(stderr, "swf_shape_record_parse: swf_shape_record_edge_parse at L%d\n", __LINE__);
44 if (100000 <= limit) { // XXX 100000???
45 current_record->next = NULL;
46 fprintf(stderr, "swf_shape_record_parse: limit(%d) over\n", limit);
49 current_record->next = calloc(1, sizeof(swf_shape_record_t));
50 current_record = current_record->next;
56 swf_shape_record_build(bitstream_t *bs, swf_shape_record_t *shape_record,
58 int first_bit, next_5bits;
59 swf_shape_record_t *current_record = shape_record;
60 while (current_record) {
61 first_bit = (current_record->first_6bits >> 5) & 1;
62 next_5bits = current_record->first_6bits & 0x1f;
63 if ((first_bit == 0) && (next_5bits == 0)) {
64 swf_shape_record_end_build(bs, &(current_record->shape.shape_end));
66 } if (first_bit == 0) {
67 swf_shape_record_setup_build(bs, &(current_record->shape.shape_setup),
70 swf_shape_record_edge_build(bs, &(current_record->shape.shape_edge), tag);
72 current_record = current_record->next;
78 swf_shape_record_print(swf_shape_record_t *shape_record, int indent_depth,
80 int first_bit, next_5bits;
81 swf_shape_record_t *current_record = shape_record;
83 for (i = 0 ; current_record ; i++) {
84 first_bit = (current_record->first_6bits >> 5) & 1;
85 next_5bits = current_record->first_6bits & 0x1f;
86 print_indent(indent_depth);
87 printf("shape_record [%d] ", i);
88 if ((first_bit == 0) && (next_5bits == 0)) {
90 swf_shape_record_end_print(indent_depth + 1);
92 } if (first_bit == 0) {
94 swf_shape_record_setup_print(&(current_record->shape.shape_setup),
95 indent_depth + 1, tag);
98 swf_shape_record_edge_print(&(current_record->shape.shape_edge),
101 current_record = current_record->next;
107 swf_shape_record_delete(swf_shape_record_t *shape_record) {
108 swf_shape_record_t *current, *next;
109 int first_bit, next_5bits;
111 first_bit = (shape_record->first_6bits >> 5) & 1;
112 next_5bits = shape_record->first_6bits & 0x1f;
114 if ((first_bit == 0) && (next_5bits != 0)) {
115 swf_shape_record_setup_delete(&(shape_record->shape.shape_setup));
118 current = shape_record->next;
120 first_bit = (current->first_6bits >> 5) & 1;
121 next_5bits = current->first_6bits & 0x1f;
122 if ((first_bit == 0) && (next_5bits != 0)) {
123 swf_shape_record_setup_delete(&(current->shape.shape_setup));
125 next = current->next;
133 swf_shape_record_edge_apply_factor(swf_shape_record_t *shape_record,
134 double scale_x, double scale_y,
135 signed trans_x, signed trans_y) {
136 int first_bit, next_5bits;
137 swf_shape_record_t *current_record;
139 // top-left base adjust
140 signed min_x = SWF_TWIPS*10000, min_y = SWF_TWIPS*10000;
141 for (current_record = shape_record ; current_record ; current_record = current_record->next) {
142 first_bit = (current_record->first_6bits >> 5) & 1;
143 next_5bits = current_record->first_6bits & 0x1f;
144 if (first_bit) { // edge
145 swf_shape_record_edge_t *edge = &(current_record->shape.shape_edge);
146 min_x = (edge->shape_x<min_x)?edge->shape_x:min_x;
147 min_y = (edge->shape_y<min_y)?edge->shape_y:min_y;
148 } else if (next_5bits) { // setup
149 swf_shape_record_setup_t *setup = &(current_record->shape.shape_setup);
150 min_x = (setup->shape_move_x<min_x)?setup->shape_move_x:min_x;
151 min_y = (setup->shape_move_y<min_y)?setup->shape_move_y:min_y;
157 for (current_record = shape_record ; current_record ; current_record = current_record->next) {
158 first_bit = (current_record->first_6bits >> 5) & 1;
159 next_5bits = current_record->first_6bits & 0x1f;
160 if (first_bit) { // edge
161 swf_shape_record_edge_t *edge = &(current_record->shape.shape_edge);
162 edge->shape_x = (edge->shape_x - min_x) * scale_x + min_x + trans_x * SWF_TWIPS;
163 edge->shape_y = (edge->shape_y - min_y) * scale_y + min_y + trans_y * SWF_TWIPS;
164 } else if (next_5bits) { // setup
165 swf_shape_record_setup_t *setup = &(current_record->shape.shape_setup);
166 setup->shape_move_x = (setup->shape_move_x - min_x) * scale_x + min_x + trans_x * SWF_TWIPS;
167 setup->shape_move_y = (setup->shape_move_y - min_y) * scale_y + min_y + trans_y * SWF_TWIPS;