3 #include "swf_shape_record_edge.h"
4 #include "swf_tag_shape.h"
7 swf_shape_record_edge_parse(bitstream_t *bs,
8 swf_shape_record_edge_t *shape_record_edge,
11 unsigned int shape_coord_real_size;
12 swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
14 result = bitstream_getbit(bs);
18 shape_record_edge->shape_record_type = result;
19 shape_record_edge->shape_edge_type = bitstream_getbit(bs);
20 shape_record_edge->shape_coord_size = bitstream_getbits(bs, 4);
21 shape_coord_real_size = shape_record_edge->shape_coord_size + 2;
22 if (shape_record_edge->shape_edge_type == 0) {
23 signed control_delta_x, control_delta_y;
24 signed anchor_delta_x, anchor_delta_y;
25 control_delta_x = bitstream_getbits_signed(bs, shape_coord_real_size);
26 control_delta_y = bitstream_getbits_signed(bs, shape_coord_real_size);
27 anchor_delta_x = bitstream_getbits_signed(bs, shape_coord_real_size);
28 anchor_delta_y = bitstream_getbits_signed(bs, shape_coord_real_size);
30 swf_tag_shape->_current_x += control_delta_x;
31 swf_tag_shape->_current_y += control_delta_y;
32 shape_record_edge->shape_control_x = swf_tag_shape->_current_x;
33 shape_record_edge->shape_control_y = swf_tag_shape->_current_y;
34 swf_tag_shape->_current_x += anchor_delta_x;
35 swf_tag_shape->_current_y += anchor_delta_y;
36 shape_record_edge->shape_anchor_x = swf_tag_shape->_current_x;
37 shape_record_edge->shape_anchor_y = swf_tag_shape->_current_y;
39 shape_record_edge->shape_line_has_x_and_y = bitstream_getbit(bs);
40 if (shape_record_edge->shape_line_has_x_and_y == 1) {
41 signed delta_x, delta_y;
42 delta_x = bitstream_getbits_signed(bs, shape_coord_real_size);
43 delta_y = bitstream_getbits_signed(bs, shape_coord_real_size);
44 swf_tag_shape->_current_x += delta_x;
45 swf_tag_shape->_current_y += delta_y;
47 shape_record_edge->shape_line_has_x_or_y = bitstream_getbit(bs);
48 if (shape_record_edge->shape_line_has_x_or_y == 0) {
50 delta_x = bitstream_getbits_signed(bs, shape_coord_real_size);
51 swf_tag_shape->_current_x += delta_x;
54 delta_y = bitstream_getbits_signed(bs, shape_coord_real_size);
55 swf_tag_shape->_current_y += delta_y;
58 shape_record_edge->shape_x = swf_tag_shape->_current_x;
59 shape_record_edge->shape_y = swf_tag_shape->_current_y;
65 swf_shape_record_edge_build(bitstream_t *bs,
66 swf_shape_record_edge_t *shape_record_edge,
69 unsigned int size, shape_coord_real_size = 2;
70 swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
72 bitstream_putbit(bs, shape_record_edge->shape_record_type);
73 bitstream_putbit(bs, shape_record_edge->shape_edge_type);
75 if (shape_record_edge->shape_edge_type == 0) {
76 size = bitstream_need_bits_signed(shape_record_edge->shape_control_x - swf_tag_shape->_current_x);
77 shape_coord_real_size = (shape_coord_real_size>size)?shape_coord_real_size:size;
78 size = bitstream_need_bits_signed(shape_record_edge->shape_control_y - swf_tag_shape->_current_y);
79 shape_coord_real_size = (shape_coord_real_size>size)?shape_coord_real_size:size;
80 size = bitstream_need_bits_signed(shape_record_edge->shape_anchor_x - shape_record_edge->shape_control_x);
81 shape_coord_real_size = (shape_coord_real_size>size)?shape_coord_real_size:size;
82 size = bitstream_need_bits_signed(shape_record_edge->shape_anchor_y - shape_record_edge->shape_control_y);
83 shape_coord_real_size = (shape_coord_real_size>size)?shape_coord_real_size:size;
85 size = bitstream_need_bits_signed(shape_record_edge->shape_x - swf_tag_shape->_current_x);
86 shape_coord_real_size = (shape_coord_real_size>size)?shape_coord_real_size:size;
87 size = bitstream_need_bits_signed(shape_record_edge->shape_y - swf_tag_shape->_current_y);
88 shape_coord_real_size = (shape_coord_real_size>size)?shape_coord_real_size:size;
90 shape_record_edge->shape_coord_size = shape_coord_real_size - 2;
91 bitstream_putbits(bs, shape_record_edge->shape_coord_size, 4);
93 if (shape_record_edge->shape_edge_type == 0) {
94 signed control_delta_x = shape_record_edge->shape_control_x - swf_tag_shape->_current_x;
95 signed control_delta_y = shape_record_edge->shape_control_y - swf_tag_shape->_current_y;
96 signed anchor_delta_x = shape_record_edge->shape_anchor_x - shape_record_edge->shape_control_x;
97 signed anchor_delta_y = shape_record_edge->shape_anchor_y - shape_record_edge->shape_control_y;
98 bitstream_putbits_signed(bs, control_delta_x, shape_coord_real_size);
99 bitstream_putbits_signed(bs, control_delta_y, shape_coord_real_size);
100 bitstream_putbits_signed(bs, anchor_delta_x, shape_coord_real_size);
101 bitstream_putbits_signed(bs, anchor_delta_y, shape_coord_real_size);
102 swf_tag_shape->_current_x = shape_record_edge->shape_anchor_x;
103 swf_tag_shape->_current_y = shape_record_edge->shape_anchor_y;
105 signed delta_x = shape_record_edge->shape_x - swf_tag_shape->_current_x;
106 signed delta_y = shape_record_edge->shape_y - swf_tag_shape->_current_y;
107 if (delta_x && delta_y) {
108 shape_record_edge->shape_line_has_x_and_y = 1;
110 shape_record_edge->shape_line_has_x_and_y = 0;
112 bitstream_putbit(bs, shape_record_edge->shape_line_has_x_and_y);
113 if (shape_record_edge->shape_line_has_x_and_y == 1) {
114 bitstream_putbits_signed(bs, delta_x, shape_coord_real_size);
115 bitstream_putbits_signed(bs, delta_y, shape_coord_real_size);
118 shape_record_edge->shape_line_has_x_or_y = 0;
120 shape_record_edge->shape_line_has_x_or_y = 1;
122 bitstream_putbit(bs, shape_record_edge->shape_line_has_x_or_y);
123 if (shape_record_edge->shape_line_has_x_or_y == 0) {
124 bitstream_putbits_signed(bs, delta_x, shape_coord_real_size);
126 bitstream_putbits_signed(bs, delta_y, shape_coord_real_size);
129 swf_tag_shape->_current_x = shape_record_edge->shape_x;
130 swf_tag_shape->_current_y = shape_record_edge->shape_y;
136 swf_shape_record_edge_print(swf_shape_record_edge_t *shape_record_edge,
138 print_indent(indent_depth);
139 printf("shape_edge_type=%d (shape_coord_size=%d+2)\n",
140 shape_record_edge->shape_edge_type ,
141 shape_record_edge->shape_coord_size);
142 if (shape_record_edge->shape_edge_type == 0) {
143 print_indent(indent_depth);
144 printf("shape_control_(x,y)=(%.2f,%.2f) shape_anchor_(x,y)=(%.2f,%.2f)\n",
145 (float) shape_record_edge->shape_control_x / SWF_TWIPS,
146 (float) shape_record_edge->shape_control_y / SWF_TWIPS,
147 (float) shape_record_edge->shape_anchor_x / SWF_TWIPS,
148 (float) shape_record_edge->shape_anchor_y / SWF_TWIPS);
150 print_indent(indent_depth);
152 printf("shape_line_has_(x_and_y, x_or_y)=(%d, %d) ",
153 shape_record_edge->shape_line_has_x_and_y,
154 shape_record_edge->shape_line_has_x_or_y);
156 printf("shape_(x,y)=(%.2f,%.2f)\n",
157 (float) shape_record_edge->shape_x / SWF_TWIPS,
158 (float) shape_record_edge->shape_y / SWF_TWIPS);