svnno****@sourc*****
svnno****@sourc*****
2009年 6月 5日 (金) 23:26:48 JST
Revision: 144 http://svn.sourceforge.jp/view?root=swfed&view=rev&rev=144 Author: yoya Date: 2009-06-05 23:26:48 +0900 (Fri, 05 Jun 2009) Log Message: ----------- - bitstream_incrpos で bit_incr に負の値を渡せるようにした - swf_shape_record_~ 系の実装 - 色々と処理に抜けがあったので補完 Modified Paths: -------------- trunk/src/bitstream.c trunk/src/config.m4 trunk/src/swf_fill_style.c trunk/src/swf_fill_style.h trunk/src/swf_fill_style_array.c trunk/src/swf_fill_style_gradient.c trunk/src/swf_fill_style_gradient.h trunk/src/swf_fill_style_solid.h trunk/src/swf_gradient.c trunk/src/swf_gradient.h trunk/src/swf_gradient_record.c trunk/src/swf_line_style.c trunk/src/swf_line_style_array.c trunk/src/swf_matrix.h trunk/src/swf_morph_shape_with_style.c trunk/src/swf_shape_record.c trunk/src/swf_shape_record.h trunk/src/swf_shape_record_setup.h trunk/src/swf_shape_with_style.c trunk/src/swf_styles.c trunk/src/swf_styles_count.c Added Paths: ----------- trunk/src/swf_shape_record_edge.c trunk/src/swf_shape_record_end.c trunk/src/swf_shape_record_setup.c -------------- next part -------------- Modified: trunk/src/bitstream.c =================================================================== --- trunk/src/bitstream.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/bitstream.c 2009-06-05 14:26:48 UTC (rev 144) @@ -319,12 +319,12 @@ int bitstream_incrpos(bitstream_t *bs, signed long byte_incr, signed long bit_incr) { + while (bit_incr < 0) { + bit_incr += 8; + byte_incr --; + } bs->byte_offset += byte_incr; bs->bit_offset += bit_incr; - while (bs->bit_offset < 0) { - bs->bit_offset += 8; - bs->byte_offset --; - } while (bs->bit_offset >= 8) { bs->bit_offset -= 8; bs->byte_offset ++; Modified: trunk/src/config.m4 =================================================================== --- trunk/src/config.m4 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/config.m4 2009-06-05 14:26:48 UTC (rev 144) @@ -61,6 +61,6 @@ dnl dnl PHP_SUBST(SWFED_SHARED_LIBADD) - PHP_NEW_EXTENSION(swfed, swfed.c swf_object.c swf_header.c swf_rect.c swf_tag.c swf_tag_jpeg.c swf_tag_edit.c swf_tag_action.c swf_tag_lossless.c swf_tag_sound.c swf_tag_sprite.c swf_tag_shape.c swf_rgb.c swf_rgba.c swf_argb.c swf_xrgb.c swf_action.c swf_jpeg.c bitstream.c jpeg_segment.c swf_png.c swf_gif.c swf_shape_with_style.c swf_styles.c swf_fill_style_array.c swf_fill_style.c swf_morph_shape_with_style.c swf_fill_style_solid.c swf_fill_style_gradient.c swf_fill_style_bitmap.c swf_line_style_array.c swf_line_style.c swf_styles_count.c swf_shape_record.c swf_gradient.c swf_matrix.c swf_gradient_record.c swf_debug.c, $ext_shared) + PHP_NEW_EXTENSION(swfed, swfed.c swf_object.c swf_header.c swf_rect.c swf_tag.c swf_tag_jpeg.c swf_tag_edit.c swf_tag_action.c swf_tag_lossless.c swf_tag_sound.c swf_tag_sprite.c swf_tag_shape.c swf_rgb.c swf_rgba.c swf_argb.c swf_xrgb.c swf_action.c swf_jpeg.c bitstream.c jpeg_segment.c swf_png.c swf_gif.c swf_shape_with_style.c swf_styles.c swf_fill_style_array.c swf_fill_style.c swf_morph_shape_with_style.c swf_fill_style_solid.c swf_fill_style_gradient.c swf_fill_style_bitmap.c swf_line_style_array.c swf_line_style.c swf_styles_count.c swf_shape_record.c swf_shape_record_end.c swf_shape_record_setup.c swf_shape_record_edge.c swf_gradient.c swf_matrix.c swf_gradient_record.c swf_debug.c, $ext_shared) fi Modified: trunk/src/swf_fill_style.c =================================================================== --- trunk/src/swf_fill_style.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_fill_style.c 2009-06-05 14:26:48 UTC (rev 144) @@ -3,74 +3,79 @@ #include "swf_fill_style.h" int -swf_fill_style_parse(bitstream_t *bs, - swf_fill_style_t *shape_with_style, swf_tag_t * tag) { - shape_with_style->type = bitstream_getbyte(bs); - switch (shape_with_style->type) { +swf_fill_style_parse(bitstream_t *bs, swf_fill_style_t *fill_style, + swf_tag_t * tag) { + fill_style->type = bitstream_getbyte(bs); + switch (fill_style->type) { case 0x00: // solid fill - swf_fill_style_solid_parse(bs, &(shape_with_style->solid), tag); + swf_fill_style_solid_parse(bs, &(fill_style->solid), tag); break; - case 0x10: // linear gradientfill - case 0x11: // radial gradientfill + case 0x10: // linear gradient fill + case 0x11: // radial gradient fill case 0x12: // focal gradient fill - swf_fill_style_gradient_parse(bs, &(shape_with_style->gradient), tag); + swf_fill_style_gradient_parse(bs, &(fill_style->gradient), tag); break; case 0x40: // tilled bitmap fill with smoothed edges case 0x41: // clipped bitmap fill with smoothed edges case 0x42: // tilled bitmap fill with hard edges case 0x43: // clipped bitmap fill with hard edges - swf_fill_style_bitmap_parse(bs, &(shape_with_style->bitmap), tag); + swf_fill_style_bitmap_parse(bs, &(fill_style->bitmap), tag); break; } return 0; } int -swf_fill_style_build(bitstream_t *bs, swf_fill_style_t *shape_with_style, +swf_fill_style_build(bitstream_t *bs, swf_fill_style_t *fill_style, swf_tag_t *tag) { - bitstream_putbyte(bs, shape_with_style->type); - switch (shape_with_style->type) { + bitstream_putbyte(bs, fill_style->type); + switch (fill_style->type) { case 0x00: // solid fill - swf_fill_style_solid_build(bs, &(shape_with_style->solid), tag); + swf_fill_style_solid_build(bs, &(fill_style->solid), tag); break; - case 0x10: // linear gradientfill - case 0x11: // radial gradientfill + case 0x10: // linear gradient fill + case 0x11: // radial gradient fill case 0x12: // focal gradient fill - swf_fill_style_gradient_build(bs, &(shape_with_style->gradient), tag); + swf_fill_style_gradient_build(bs, &(fill_style->gradient), tag); break; case 0x40: // tilled bitmap fill with smoothed edges case 0x41: // clipped bitmap fill with smoothed edges case 0x42: // tilled bitmap fill with hard edges case 0x43: // clipped bitmap fill with hard edges - swf_fill_style_bitmap_build(bs, &(shape_with_style->bitmap), tag); + swf_fill_style_bitmap_build(bs, &(fill_style->bitmap), tag); break; } return 0; } int -swf_fill_style_print(swf_fill_style_t *shape_with_style, int indent_depth, +swf_fill_style_print(swf_fill_style_t *fill_style, int indent_depth, swf_tag_t *tag) { print_indent(indent_depth); - printf("type=0x%02x\n", shape_with_style->type); - switch (shape_with_style->type) { - case 0x00: // solid fill - swf_fill_style_solid_print(&(shape_with_style->solid), - indent_depth, tag); - break; - case 0x10: // linear gradientfill - case 0x11: // radial gradientfill - case 0x12: // focal gradient fill - swf_fill_style_gradient_print(&(shape_with_style->gradient), - indent_depth, tag); - break; - case 0x40: // tilled bitmap fill with smoothed edges - case 0x41: // clipped bitmap fill with smoothed edges - case 0x42: // tilled bitmap fill with hard edges - case 0x43: // clipped bitmap fill with hard edges - swf_fill_style_bitmap_print(&(shape_with_style->bitmap), - indent_depth, tag); - break; - } + printf("type=0x%02x\n", fill_style->type); + switch (fill_style->type) { + case 0x00: // solid fill + swf_fill_style_solid_print(&(fill_style->solid), + indent_depth, tag); + break; + case 0x10: // linear gradientfill + case 0x11: // radial gradientfill + case 0x12: // focal gradient fill + swf_fill_style_gradient_print(&(fill_style->gradient), + indent_depth, tag); + break; + case 0x40: // tilled bitmap fill with smoothed edges + case 0x41: // clipped bitmap fill with smoothed edges + case 0x42: // tilled bitmap fill with hard edges + case 0x43: // clipped bitmap fill with hard edges + swf_fill_style_bitmap_print(&(fill_style->bitmap), + indent_depth, tag); + break; + } return 0; } + +int +swf_fill_style_delete(swf_fill_style_t *fill_style) { + swf_fill_style_gradient_delete(&(fill_style->gradient)); +} Modified: trunk/src/swf_fill_style.h =================================================================== --- trunk/src/swf_fill_style.h 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_fill_style.h 2009-06-05 14:26:48 UTC (rev 144) @@ -19,11 +19,12 @@ swf_fill_style_bitmap_t bitmap; } swf_fill_style_t; -extern int swf_fill_style_parse(bitstream_t *bs, swf_fill_style_t *color, +extern int swf_fill_style_parse(bitstream_t *bs, swf_fill_style_t *fill_style, swf_tag_t *tag); -extern int swf_fill_style_build(bitstream_t *bs, swf_fill_style_t *color, +extern int swf_fill_style_build(bitstream_t *bs, swf_fill_style_t *fill_style, swf_tag_t *tag); -extern int swf_fill_style_print(swf_fill_style_t *color, int indent_depth, +extern int swf_fill_style_print(swf_fill_style_t *fill_style, int indent_depth, swf_tag_t *tag); +extern int swf_fill_style_delete(swf_fill_style_t *fill_style); #endif /* __SWF_FILL_STYLE_H__ */ Modified: trunk/src/swf_fill_style_array.c =================================================================== --- trunk/src/swf_fill_style_array.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_fill_style_array.c 2009-06-05 14:26:48 UTC (rev 144) @@ -5,43 +5,46 @@ int swf_fill_style_array_parse(bitstream_t *bs, - swf_fill_style_array_t *shape_with_style, + swf_fill_style_array_t *fill_style_array, swf_tag_t *tag) { int i; - shape_with_style->count = bitstream_getbyte(bs); - if (tag->tag != 2 || // ! DefineShape - shape_with_style->count == 255) { - shape_with_style->count = bitstream_getbytesLE(bs, 2); + fill_style_array->count = bitstream_getbyte(bs); + if (tag->tag != 2 && // ! DefineShape + fill_style_array->count == 255) { + fill_style_array->count = bitstream_getbytesLE(bs, 2); } - shape_with_style->fill_style = calloc(shape_with_style->count, sizeof(swf_fill_style_t)); // XXX free !!! XXX - for (i = 0 ; i < shape_with_style->count ; i++) { - swf_fill_style_parse(bs, &(shape_with_style->fill_style[i]), tag); + fill_style_array->fill_style = calloc(fill_style_array->count, sizeof(swf_fill_style_t)); + for (i = 0 ; i < fill_style_array->count ; i++) { + swf_fill_style_parse(bs, &(fill_style_array->fill_style[i]), tag); } return 0; } int -swf_fill_style_array_build(bitstream_t *bs, swf_fill_style_array_t *shape_with_style, swf_tag_t *tag) { +swf_fill_style_array_build(bitstream_t *bs, + swf_fill_style_array_t *fill_style_array, + swf_tag_t *tag) { int i; - if (tag->tag != 2 || // ! DefineShape - 255 <= shape_with_style->count) { + if (tag->tag != 2 && // ! DefineShape + 255 <= fill_style_array->count) { bitstream_putbyte(bs, 255); - bitstream_putbytesLE(bs, shape_with_style->count, 2); + bitstream_putbytesLE(bs, fill_style_array->count, 2); } else { - bitstream_putbyte(bs, shape_with_style->count); + bitstream_putbyte(bs, fill_style_array->count); } - for (i = 0 ; i < shape_with_style->count ; i++) { - swf_fill_style_built(bs, &(shape_with_style->fill_style[i]), tag); + for (i = 0 ; i < fill_style_array->count ; i++) { + swf_fill_style_build(bs, &(fill_style_array->fill_style[i]), tag); } } int -swf_fill_style_array_print(swf_fill_style_array_t *shape_with_style, int indent_depth, swf_tag_t *tag) { +swf_fill_style_array_print(swf_fill_style_array_t *fill_style_array, + int indent_depth, swf_tag_t *tag) { int i; print_indent(indent_depth); - printf("count=%u\n", shape_with_style->count); - for (i = 0 ; i < shape_with_style->count ; i++) { - swf_fill_style_print(&(shape_with_style->fill_style[i]), + printf("fill_style_array->count=%u\n", fill_style_array->count); + for (i = 0 ; i < fill_style_array->count ; i++) { + swf_fill_style_print(&(fill_style_array->fill_style[i]), indent_depth + 1, tag); } return 0; @@ -49,5 +52,9 @@ int swf_fill_style_array_delete(swf_fill_style_array_t *fill_style_array) { + int i; + for (i = 0 ; i < fill_style_array->count ; i++) { + swf_fill_style_delete(&(fill_style_array->fill_style[i])); + } free(fill_style_array->fill_style); } Modified: trunk/src/swf_fill_style_gradient.c =================================================================== --- trunk/src/swf_fill_style_gradient.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_fill_style_gradient.c 2009-06-05 14:26:48 UTC (rev 144) @@ -10,7 +10,7 @@ if (tag->tag == 46 || tag->tag == 84) { swf_matrix_parse(bs, &(fill_style_gradient->gradient_matrix_morph)); } - swf_gradient_parse(bs, &(fill_style_gradient->gradient), tag); + swf_gradient_parse(bs, &(fill_style_gradient->gradient), tag, fill_style_gradient->type); return 0; } @@ -23,7 +23,7 @@ if (tag->tag == 46 || tag->tag == 84) { swf_matrix_build(bs, &(fill_style_gradient->gradient_matrix_morph)); } - swf_gradient_build(bs, &(fill_style_gradient->gradient), tag); + swf_gradient_build(bs, &(fill_style_gradient->gradient), tag, fill_style_gradient->type); return 0; } @@ -39,6 +39,12 @@ swf_matrix_print(&(fill_style_gradient->gradient_matrix_morph), indent_depth + 1); } - swf_gradient_print(&(fill_style_gradient->gradient), indent_depth, tag); + swf_gradient_print(&(fill_style_gradient->gradient), indent_depth, tag, fill_style_gradient->type); return 0; } + + +int +swf_fill_style_gradient_delete(swf_fill_style_gradient_t *fill_style_gradient) { + swf_gradient_delete(&(fill_style_gradient->gradient)); +} Modified: trunk/src/swf_fill_style_gradient.h =================================================================== --- trunk/src/swf_fill_style_gradient.h 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_fill_style_gradient.h 2009-06-05 14:26:48 UTC (rev 144) @@ -26,5 +26,6 @@ swf_tag_t *tag); extern int swf_fill_style_gradient_print(swf_fill_style_gradient_t *gradient, int indent_depth, swf_tag_t *tag); +extern int swf_fill_style_gradient_delete(swf_fill_style_gradient_t *gradient); #endif /* __SWF_FILL_STYLE_GRADIENT_H__ */ Modified: trunk/src/swf_fill_style_solid.h =================================================================== --- trunk/src/swf_fill_style_solid.h 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_fill_style_solid.h 2009-06-05 14:26:48 UTC (rev 144) @@ -18,8 +18,13 @@ swf_rgb_t rgb; // other tag } swf_fill_style_solid_t; -extern int swf_fill_style_solid_parse(bitstream_t *bs, swf_fill_style_solid_t *color, swf_tag_t *tag); -extern int swf_fill_style_solid_build(bitstream_t *bs, swf_fill_style_solid_t *color, swf_tag_t *tag); -extern int swf_fill_style_solid_print(swf_fill_style_solid_t *color, int indent_depth, swf_tag_t *tag); +extern int swf_fill_style_solid_parse(bitstream_t *bs, + swf_fill_style_solid_t *solid, + swf_tag_t *tag); +extern int swf_fill_style_solid_build(bitstream_t *bs, + swf_fill_style_solid_t *solid, + swf_tag_t *tag); +extern int swf_fill_style_solid_print(swf_fill_style_solid_t *solid, + int indent_depth, swf_tag_t *tag); #endif /* __SWF_FILL_STYLE_SOLID_H__ */ Modified: trunk/src/swf_gradient.c =================================================================== --- trunk/src/swf_gradient.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_gradient.c 2009-06-05 14:26:48 UTC (rev 144) @@ -4,7 +4,7 @@ int swf_gradient_parse(bitstream_t *bs, swf_gradient_t *gradient, - swf_tag_t *tag) { + swf_tag_t *tag, int type) { int i; if (tag->tag == 83) { // DefineShape4 gradient->spread_mode = bitstream_getbits(bs, 2); @@ -14,22 +14,62 @@ gradient->pad = bitstream_getbits(bs, 4); gradient->count = bitstream_getbits(bs, 4); } + gradient->gradient_record = calloc(gradient->count, sizeof(*gradient->gradient_record)); // XXX for (i = 0 ; i < gradient->count ; i++) { - swf_grandient_record_parse(bs, &(gradient->gradient_record[i])); + swf_gradient_record_parse(bs, &(gradient->gradient_record[i]), tag); gradient->focal_point = bitstream_getbytesLE(bs, 2); } + if (type == 0x13) { + gradient->focal_point = bitstream_getbytesLE(bs, 2); + } return 0; } int swf_gradient_build(bitstream_t *bs, swf_gradient_t *gradient, - swf_tag_t *tag) { + swf_tag_t *tag, int type) { + int i; + if (tag->tag == 83) { // DefineShape4 + bitstream_putbits(bs, gradient->spread_mode, 2); + bitstream_putbits(bs, gradient->interpolation_mode, 2); + bitstream_putbits(bs, gradient->count, 4); + } else { + bitstream_putbits(bs, gradient->pad, 4); + bitstream_putbits(bs, gradient->count, 4); + } + for (i = 0 ; i < gradient->count ; i++) { + swf_gradient_record_build(bs, &(gradient->gradient_record[i]), tag); + } + if (type == 0x13) { + bitstream_putbytesLE(bs, gradient->focal_point, 2); + } return 0; } int swf_gradient_print(swf_gradient_t *gradient, int indent_depth, - swf_tag_t *tag) { - print_indent(indent_depth); + swf_tag_t *tag, int type) { + int i; + if (tag->tag == 83) { // DefineShape4 + print_indent(indent_depth); + printf("spread_mode=%d interpolation_mode=%d count=%d\n", + gradient->spread_mode, gradient->interpolation_mode, + gradient->count); + } else { + print_indent(indent_depth); + printf("pad=%d count=%d\n", gradient->pad, gradient->count); + } + for (i = 0 ; i < gradient->count ; i++) { + swf_gradient_record_print(&(gradient->gradient_record[i]), indent_depth+1, tag); + } + if (type == 0x13) { + print_indent(indent_depth); + printf("focal_point=%d\n", gradient->focal_point); + } return 0; } + +int +swf_gradient_delete(swf_gradient_t *gradient) { + free(gradient->gradient_record); +} Modified: trunk/src/swf_gradient.h =================================================================== --- trunk/src/swf_gradient.h 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_gradient.h 2009-06-05 14:26:48 UTC (rev 144) @@ -21,10 +21,12 @@ } swf_gradient_t; extern int swf_gradient_parse(bitstream_t *bs, swf_gradient_t *gradient, - swf_tag_t *tag); + swf_tag_t *tag, int type); extern int swf_gradient_build(bitstream_t *bs, swf_gradient_t *gradient, - swf_tag_t *tag); + swf_tag_t *tag, int type); extern int swf_gradient_print(swf_gradient_t *gradient, int indent_depth, - swf_tag_t *tag); + swf_tag_t *tag, int type); +extern int swf_gradient_delete(swf_gradient_t *gradient); + #endif /* __SWF_GRADIENT_H__ */ Modified: trunk/src/swf_gradient_record.c =================================================================== --- trunk/src/swf_gradient_record.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_gradient_record.c 2009-06-05 14:26:48 UTC (rev 144) @@ -26,12 +26,41 @@ swf_gradient_record_build(bitstream_t *bs, swf_gradient_record_t *gradient_record, swf_tag_t *tag) { + if (tag->tag == 46 || tag->tag == 84) { // DefineMorph || DefineMorphShape2 + bitstream_putbyte(bs, gradient_record->position); + swf_rgba_build(bs, &(gradient_record->rgba)); + bitstream_putbyte(bs, gradient_record->position_morph); + swf_rgba_build(bs, &(gradient_record->rgba_morph)); + } else if (tag->tag == 32 || tag->tag == 83) { + // DefineShape3 || DefineShape4 + bitstream_putbyte(bs, gradient_record->position); + swf_rgba_build(bs, &(gradient_record->rgba)); + } else { + bitstream_putbyte(bs, gradient_record->position); + swf_rgb_build(bs, &(gradient_record->rgb)); + } return 0; } int swf_gradient_record_print(swf_gradient_record_t *gradient_record, int indent_depth, swf_tag_t *tag) { - print_indent(indent_depth); + if (tag->tag == 46 || tag->tag == 84) { // DefineMorph || DefineMorphShape2 + print_indent(indent_depth); + printf("position=%d\n", gradient_record->position); + swf_rgba_print(&(gradient_record->rgba), indent_depth); + print_indent(indent_depth); + printf("position_morph=%d\n", gradient_record->position_morph); + swf_rgba_print(&(gradient_record->rgba_morph), indent_depth); + } else if (tag->tag == 32 || tag->tag == 83) { + // DefineShape3 || DefineShape4 + print_indent(indent_depth); + printf("position=%d\n", gradient_record->position); + swf_rgba_print(&(gradient_record->rgba), indent_depth); + } else { + print_indent(indent_depth); + printf("position=%d\n", gradient_record->position); + swf_rgb_print(&(gradient_record->rgb), indent_depth); + } return 0; } Modified: trunk/src/swf_line_style.c =================================================================== --- trunk/src/swf_line_style.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_line_style.c 2009-06-05 14:26:48 UTC (rev 144) @@ -47,7 +47,43 @@ int swf_line_style_build(bitstream_t *bs, swf_line_style_t *line_style, swf_tag_t *tag) { - ; + if (tag->tag == 46) { // DefineMorphShape + bitstream_putbytesLE(bs, line_style->width, 2); + bitstream_putbytesLE(bs, line_style->width_morph, 2); + swf_rgba_build(bs, &(line_style->rgba)); + swf_rgba_build(bs, &(line_style->rgba_morph)); + } else if (tag->tag == 83 || tag->tag == 84) { + // DefineShape4 || DefineMorphShape2 + if (tag->tag == 84) { // DefineMorphShape2 + bitstream_putbytesLE(bs, line_style->width_morph, 2); + } + bitstream_putbits(bs, line_style->start_cap_style, 2); + bitstream_putbits(bs, line_style->join_style, 2); + bitstream_putbits(bs, line_style->has_fill, 1); + bitstream_putbits(bs, line_style->no_hscale, 1); + bitstream_putbits(bs, line_style->no_vscale, 1); + bitstream_putbits(bs, line_style->pixel_hinting, 1); + bitstream_putbits(bs, line_style->reserved , 5); + bitstream_putbits(bs, line_style->no_close, 1); + bitstream_putbits(bs, line_style->end_cap_style, 2); + if (line_style->join_style == 2) { + bitstream_putbytesLE(bs, line_style->miter_limit_factor, 2); + } + if (line_style->has_fill) { + swf_fill_style_build(bs, &(line_style->fill_style), tag); + } else { + swf_rgba_build(bs, &(line_style->rgba)); + if (tag->tag == 84) { // DefineMorphShape2 + swf_rgba_build(bs, &(line_style->rgba_morph)); + } + } + } else if (tag->tag == 32) { // DefineShape3 + bitstream_putbytesLE(bs, line_style->width, 2); + swf_rgba_build(bs, &(line_style->rgba)); + } else { + bitstream_putbytesLE(bs, line_style->width, 2); + swf_rgb_build(bs, &(line_style->rgb)); + } return 0; } Modified: trunk/src/swf_line_style_array.c =================================================================== --- trunk/src/swf_line_style_array.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_line_style_array.c 2009-06-05 14:26:48 UTC (rev 144) @@ -13,7 +13,7 @@ shape_with_style->count == 255) { shape_with_style->count = bitstream_getbytesLE(bs, 2); } - shape_with_style->line_style = calloc(shape_with_style->count, sizeof(swf_line_style_t)); // XXX free !!! XXX + shape_with_style->line_style = calloc(shape_with_style->count, sizeof(swf_line_style_t)); for (i = 0 ; i < shape_with_style->count ; i++) { swf_line_style_parse(bs, &(shape_with_style->line_style[i]), tag); } @@ -31,7 +31,7 @@ bitstream_putbyte(bs, shape_with_style->count); } for (i = 0 ; i < shape_with_style->count ; i++) { - swf_line_style_built(bs, &(shape_with_style->line_style[i]), tag); + swf_line_style_build(bs, &(shape_with_style->line_style[i]), tag); } } Modified: trunk/src/swf_matrix.h =================================================================== --- trunk/src/swf_matrix.h 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_matrix.h 2009-06-05 14:26:48 UTC (rev 144) @@ -25,8 +25,8 @@ signed translate_y ; // : f_rotate_bits; } swf_matrix_t; -extern int swf_matrix_parse(bitstream_t *bs, swf_matrix_t *color); -extern int swf_matrix_build(bitstream_t *bs, swf_matrix_t *color); -extern int swf_matrix_print(swf_matrix_t *color, int indent_depth); +extern int swf_matrix_parse(bitstream_t *bs, swf_matrix_t *matrix); +extern int swf_matrix_build(bitstream_t *bs, swf_matrix_t *matrix); +extern int swf_matrix_print(swf_matrix_t *matrix, int indent_depth); #endif /* __SWF_MATRIX_H__ */ Modified: trunk/src/swf_morph_shape_with_style.c =================================================================== --- trunk/src/swf_morph_shape_with_style.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_morph_shape_with_style.c 2009-06-05 14:26:48 UTC (rev 144) @@ -6,9 +6,12 @@ swf_morph_shape_with_style_t *morph_shape_with_style, swf_tag_t *tag) { swf_styles_parse(bs, &(morph_shape_with_style->styles), tag); - swf_shape_record_parse(bs, &(morph_shape_with_style->shape_records)); + swf_shape_record_parse(bs, &(morph_shape_with_style->shape_records), tag, + &(morph_shape_with_style->styles.styles_count)); + bitstream_align(bs); swf_styles_count_parse(bs, &(morph_shape_with_style->styles_count)); - swf_shape_record_parse(bs, &(morph_shape_with_style->shape_records_morph)); + swf_shape_record_parse(bs, &(morph_shape_with_style->shape_records_morph), + tag, &(morph_shape_with_style->styles_count)); return 0; } @@ -17,9 +20,12 @@ swf_morph_shape_with_style_t *morph_shape_with_style, swf_tag_t *tag) { swf_styles_build(bs, &(morph_shape_with_style->styles), tag); - swf_shape_record_build(bs, &(morph_shape_with_style->shape_records)); + swf_shape_record_build(bs, &(morph_shape_with_style->shape_records), tag, + &(morph_shape_with_style->styles.styles_count)); + bitstream_align(bs); swf_styles_count_build(bs, &(morph_shape_with_style->styles_count)); - swf_shape_record_build(bs, &(morph_shape_with_style->shape_records_morph)); + swf_shape_record_build(bs, &(morph_shape_with_style->shape_records_morph), + tag, &(morph_shape_with_style->styles_count)); return 0; } @@ -28,9 +34,14 @@ int indent_depth, swf_tag_t *tag) { swf_styles_print(&(morph_shape_with_style->styles), indent_depth, tag); - swf_shape_record_print(&(morph_shape_with_style->shape_records), indent_depth); - swf_styles_count_print(&(morph_shape_with_style->styles_count), indent_depth); - swf_shape_record_print(&(morph_shape_with_style->shape_records_morph), indent_depth); + swf_shape_record_print(&(morph_shape_with_style->shape_records), + indent_depth, tag, + &(morph_shape_with_style->styles.styles_count)); + swf_styles_count_print(&(morph_shape_with_style->styles_count), + indent_depth); + swf_shape_record_print(&(morph_shape_with_style->shape_records_morph), + indent_depth, tag, + &(morph_shape_with_style->styles_count)); return 0; } Modified: trunk/src/swf_shape_record.c =================================================================== --- trunk/src/swf_shape_record.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_shape_record.c 2009-06-05 14:26:48 UTC (rev 144) @@ -2,19 +2,82 @@ #include "bitstream.h" #include "swf_shape_record.h" -swf_shape_record_parse(bitstream_t *bs, swf_shape_record_t *shape_record) { - ; +swf_shape_record_parse(bitstream_t *bs, swf_shape_record_t *shape_record, + swf_tag_t *tag, swf_styles_count_t *count) { + int first_bit, next_5bits; + swf_shape_record_t *current = shape_record; + while (current) { + shape_record->first_6bits = bitstream_getbits(bs, 6); + first_bit = (shape_record->first_6bits >> 5) & 1; + next_5bits = shape_record->first_6bits & 0x1f; + bitstream_incrpos(bs, 0, -6); // 6 bit back + if ((first_bit == 0) && (next_5bits == 0)) { + swf_shape_record_end_parse(bs, &(current->shape_end)); + current->next = NULL; + break; + } if (first_bit == 0) { + swf_shape_record_setup_parse(bs, &(current->shape_setup), tag, + count); + } else { + swf_shape_record_edge_parse(bs, &(current->shape_edge)); + } + current->next = calloc(1, sizeof(*current)); + current = current->next; + } return 0; } int -swf_shape_record_build(bitstream_t *bs, swf_shape_record_t *shape_record) { - ; +swf_shape_record_build(bitstream_t *bs, swf_shape_record_t *shape_record, + swf_tag_t *tag, swf_styles_count_t *count) { + int first_bit, next_5bits; + swf_shape_record_t *current = shape_record; + while (current) { + first_bit = (shape_record->first_6bits >> 5) & 1; + next_5bits = shape_record->first_6bits & 0x1f; + if ((first_bit == 0) && (next_5bits == 0)) { + swf_shape_record_end_build(bs, &(current->shape_end)); + break; + } if (first_bit == 0) { + swf_shape_record_setup_build(bs, &(current->shape_setup), tag, + count); + } else { + swf_shape_record_edge_build(bs, &(current->shape_edge)); + } + current = current->next; + } return 0; } int -swf_shape_record_print(swf_shape_record_t *shape_record, int indent_depth) { - ; +swf_shape_record_print(swf_shape_record_t *shape_record, int indent_depth, + swf_tag_t *tag, swf_styles_count_t *count) { + int first_bit, next_5bits; + swf_shape_record_t *current = shape_record; + while (current) { + first_bit = (shape_record->first_6bits >> 5) & 1; + next_5bits = shape_record->first_6bits & 0x1f; + if ((first_bit == 0) && (next_5bits == 0)) { + swf_shape_record_end_print(&(current->shape_end), indent_depth); + break; + } if (first_bit == 0) { + swf_shape_record_setup_print(&(current->shape_setup), + indent_depth, tag, count); + } else { + swf_shape_record_edge_print(&(current->shape_edge), indent_depth); + } + current = current->next; + } return 0; } + +int +swf_shape_record_delete(swf_shape_record_t *shape_record) { + swf_shape_record_t *current, *next; + current = shape_record->next; + while (current) { + next = current->next; + free(current); + current = next; + } +} Modified: trunk/src/swf_shape_record.h =================================================================== --- trunk/src/swf_shape_record.h 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_shape_record.h 2009-06-05 14:26:48 UTC (rev 144) @@ -7,11 +7,14 @@ #ifndef __SWF_SHAPE_RECORD_H__ #define __SWF_SHAPE_RECORD_H__ +#include "swf_tag.h" +#include "swf_styles_count.h" #include "swf_shape_record_end.h" #include "swf_shape_record_setup.h" #include "swf_shape_record_edge.h" typedef union swf_shape_record_ { + unsigned char first_6bits : 6; swf_shape_record_end_t shape_end; swf_shape_record_setup_t shape_setup; swf_shape_record_edge_t shape_edge; @@ -19,10 +22,14 @@ } swf_shape_record_t; extern int swf_shape_record_parse(bitstream_t *bs, - swf_shape_record_t *shape_record); + swf_shape_record_t *shape_record, + swf_tag_t *tag, swf_styles_count_t *count); extern int swf_shape_record_build(bitstream_t *bs, - swf_shape_record_t *shape_record); + swf_shape_record_t *shape_record, + swf_tag_t *tag, swf_styles_count_t *count); extern int swf_shape_record_print(swf_shape_record_t *shape_record, - int indent_depth); + int indent_depth, swf_tag_t *tag, + swf_styles_count_t *count); +extern int swf_shape_record_delete(swf_shape_record_t *shape_record); #endif /* __SWF_SHAPE_RECORD_H__ */ Added: trunk/src/swf_shape_record_edge.c =================================================================== --- trunk/src/swf_shape_record_edge.c (rev 0) +++ trunk/src/swf_shape_record_edge.c 2009-06-05 14:26:48 UTC (rev 144) @@ -0,0 +1,21 @@ +#include <stdio.h> +#include "bitstream.h" +#include "swf_shape_record_edge.h" + +swf_shape_record_edge_parse(bitstream_t *bs, + swf_shape_record_edge_t *shape_record_edge) { + + return 0; +} + +int +swf_shape_record_edge_build(bitstream_t *bs, + swf_shape_record_edge_t *shape_record_edge) { + return 0; +} + +int +swf_shape_record_edge_print(swf_shape_record_edge_t *shape_record_edge, + int indent_depth) { + return 0; +} Added: trunk/src/swf_shape_record_end.c =================================================================== --- trunk/src/swf_shape_record_end.c (rev 0) +++ trunk/src/swf_shape_record_end.c 2009-06-05 14:26:48 UTC (rev 144) @@ -0,0 +1,28 @@ +#include <stdio.h> +#include "bitstream.h" +#include "swf_shape_record_end.h" + +swf_shape_record_end_parse(bitstream_t *bs, + swf_shape_record_end_t *shape_record_end) { + shape_record_end->shape_record_type = bitstream_getbit(bs); + shape_record_end->end_of_shape = bitstream_getbits(bs, 5); + return 0; +} + +int +swf_shape_record_end_build(bitstream_t *bs, + swf_shape_record_end_t *shape_record_end) { + bitstream_putbit(bs, shape_record_end->shape_record_type); + bitstream_putbits(bs, shape_record_end->end_of_shape, 5); + return 0; +} + +int +swf_shape_record_end_print(swf_shape_record_end_t *shape_record_end, + int indent_depth) { + print_indent(indent_depth); + printf("shape_record_type=%d end_of_shape=%d\n", + shape_record_end->shape_record_type, + shape_record_end->end_of_shape); + return 0; +} Added: trunk/src/swf_shape_record_setup.c =================================================================== --- trunk/src/swf_shape_record_setup.c (rev 0) +++ trunk/src/swf_shape_record_setup.c 2009-06-05 14:26:48 UTC (rev 144) @@ -0,0 +1,116 @@ +#include <stdio.h> +#include "bitstream.h" +#include "swf_shape_record_setup.h" + +swf_shape_record_setup_parse(bitstream_t *bs, + swf_shape_record_setup_t *shape_record_setup, + swf_tag_t *tag, swf_styles_count_t *count) { + int shape_move_size; + shape_record_setup->shape_record_type = bitstream_getbit(bs); + shape_record_setup->shape_has_new_styles = bitstream_getbit(bs); + shape_record_setup->shape_has_line_style = bitstream_getbit(bs); + shape_record_setup->shape_has_fill_style1 = bitstream_getbit(bs); + shape_record_setup->shape_has_fill_style0 = bitstream_getbit(bs); + shape_record_setup->shape_has_move_to = bitstream_getbit(bs); + if (shape_record_setup->shape_has_move_to) { + shape_move_size = bitstream_getbits(bs, 5); // XXX + shape_record_setup->shape_move_size = shape_move_size; + shape_record_setup->shape_move_x = bitstream_getbits(bs, shape_move_size); + shape_record_setup->shape_move_y = bitstream_getbits(bs, shape_move_size); + } + if (shape_record_setup->shape_has_fill_style0) { + shape_record_setup->shape_fill_style0 = bitstream_getbits(bs, count->fill_bits_count); + + } + if (shape_record_setup->shape_has_fill_style1) { + shape_record_setup->shape_fill_style1 = bitstream_getbits(bs, count->fill_bits_count); + + } + if (shape_record_setup->shape_has_line_style) { + shape_record_setup->shape_line_style = bitstream_getbits(bs, count->line_bits_count); + } + if (shape_record_setup->shape_has_new_styles) { + swf_styles_parse(bs, &(shape_record_setup->styles), tag); + } + return 0; +} + +int +swf_shape_record_setup_build(bitstream_t *bs, + swf_shape_record_setup_t *shape_record_setup, + swf_tag_t *tag, swf_styles_count_t *count) { + int shape_move_size; + bitstream_putbit(bs, shape_record_setup->shape_record_type); + bitstream_putbit(bs, shape_record_setup->shape_has_new_styles); + bitstream_putbit(bs, shape_record_setup->shape_has_line_style); + bitstream_putbit(bs, shape_record_setup->shape_has_fill_style1); + bitstream_putbit(bs, shape_record_setup->shape_has_fill_style0); + bitstream_putbit(bs, shape_record_setup->shape_has_move_to); + if (shape_record_setup->shape_has_move_to) { + shape_move_size = shape_record_setup->shape_move_size; + bitstream_putbits(bs, shape_move_size, 5); // XXX + bitstream_putbits(bs, shape_record_setup->shape_move_x, + shape_move_size); + bitstream_putbits(bs, shape_record_setup->shape_move_y, + shape_move_size); + } + if (shape_record_setup->shape_has_fill_style0) { + bitstream_putbits(bs, shape_record_setup->shape_fill_style0, + count->fill_bits_count); + } + if (shape_record_setup->shape_has_fill_style1) { + bitstream_putbits(bs, shape_record_setup->shape_fill_style1, + count->fill_bits_count); + + } + if (shape_record_setup->shape_has_line_style) { + bitstream_putbits(bs, shape_record_setup->shape_line_style, + count->line_bits_count); + } + if (shape_record_setup->shape_has_new_styles) { + swf_styles_build(bs, &(shape_record_setup->styles), tag); + } + return 0; +} + +int +swf_shape_record_setup_print(swf_shape_record_setup_t *shape_record_setup, + int indent_depth, swf_tag_t *tag, + swf_styles_count_t *count) { + if (tag->tag != 2) { // DefineShape + print_indent(indent_depth); + printf("shape_record_type=%d\n", + shape_record_setup->shape_record_type); + } + print_indent(indent_depth); + printf("shape_has_{new_styles,line_styles, fill_style1, fill_style0, move_to}={%d,%d,%d,%d,%d}\n", + shape_record_setup->shape_has_new_styles, + shape_record_setup->shape_has_line_style, + shape_record_setup->shape_has_fill_style1, + shape_record_setup->shape_has_fill_style0, + shape_record_setup->shape_has_move_to); + if (shape_record_setup->shape_has_move_to) { + print_indent(indent_depth); + printf("shape_move_x=%d shape_move_y=%d\n", + shape_record_setup->shape_move_x, + shape_record_setup->shape_move_y); + } + if (shape_record_setup->shape_has_fill_style0) { + printf("shape_fill_style0=%d\n", + shape_record_setup->shape_fill_style0); + } + if (shape_record_setup->shape_has_fill_style1) { + printf("shape_fill_style1=%d\n", + shape_record_setup->shape_fill_style1); + } + if (shape_record_setup->shape_has_line_style) { + printf("shape_line_style=%d\n", + shape_record_setup->shape_line_style); + } + if (shape_record_setup->shape_has_new_styles) { + swf_styles_print(&(shape_record_setup->styles), indent_depth + 1, + tag); + } + + return 0; +} Modified: trunk/src/swf_shape_record_setup.h =================================================================== --- trunk/src/swf_shape_record_setup.h 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_shape_record_setup.h 2009-06-05 14:26:48 UTC (rev 144) @@ -26,8 +26,16 @@ swf_styles_t styles; } swf_shape_record_setup_t; -extern int swf_shape_record_setup_parse(bitstream_t *bs, swf_shape_record_setup_t *color); -extern int swf_shape_record_setup_build(bitstream_t *bs, swf_shape_record_setup_t *color); -extern int swf_shape_record_setup_print(swf_shape_record_setup_t *color, int indent_depth); +extern int swf_shape_record_setup_parse(bitstream_t *bs, + swf_shape_record_setup_t *setup, + swf_tag_t *tag, + swf_styles_count_t *count); +extern int swf_shape_record_setup_build(bitstream_t *bs, + swf_shape_record_setup_t *setup, + swf_tag_t *tag, + swf_styles_count_t *count); +extern int swf_shape_record_setup_print(swf_shape_record_setup_t *setup, + int indent_depth, swf_tag_t *tag, + swf_styles_count_t *count); #endif /* __SWF_SHAPE_RECORD_SETUP_H__ */ Modified: trunk/src/swf_shape_with_style.c =================================================================== --- trunk/src/swf_shape_with_style.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_shape_with_style.c 2009-06-05 14:26:48 UTC (rev 144) @@ -7,20 +7,23 @@ swf_shape_with_style_t *shape_with_style, swf_tag_t *tag) { swf_styles_parse(bs, &(shape_with_style->styles), tag); - swf_shape_record_parse(bs, &(shape_with_style->shape_records)); + swf_shape_record_parse(bs, &(shape_with_style->shape_records), tag, + &(shape_with_style->styles.styles_count)); return 0; } int swf_shape_with_style_build(bitstream_t *bs, swf_shape_with_style_t *shape_with_style, swf_tag_t *tag) { swf_styles_build(bs, &(shape_with_style->styles), tag); - swf_shape_record_build(bs, &(shape_with_style->shape_records)); + swf_shape_record_build(bs, &(shape_with_style->shape_records), tag, + &(shape_with_style->styles.styles_count)); return 0; } int swf_shape_with_style_print(swf_shape_with_style_t *shape_with_style, int indent_depth, swf_tag_t *tag) { swf_styles_print(&(shape_with_style->styles), indent_depth, tag); - swf_shape_record_print(&(shape_with_style->shape_records), indent_depth); + swf_shape_record_print(&(shape_with_style->shape_records), indent_depth, + tag, &(shape_with_style->styles.styles_count)); return 0; } Modified: trunk/src/swf_styles.c =================================================================== --- trunk/src/swf_styles.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_styles.c 2009-06-05 14:26:48 UTC (rev 144) @@ -33,6 +33,6 @@ int swf_styles_delete(swf_styles_t *styles) { - swf_fill_styles_array_delete(&(styles->fill_styles)); - swf_line_styles_array_delete(&(styles->line_styles)); + swf_fill_style_array_delete(&(styles->fill_styles)); + swf_line_style_array_delete(&(styles->line_styles)); } Modified: trunk/src/swf_styles_count.c =================================================================== --- trunk/src/swf_styles_count.c 2009-06-05 08:08:28 UTC (rev 143) +++ trunk/src/swf_styles_count.c 2009-06-05 14:26:48 UTC (rev 144) @@ -3,18 +3,22 @@ #include "swf_styles_count.h" swf_styles_count_parse(bitstream_t *bs, swf_styles_count_t *styles_count) { - ; + styles_count->fill_bits_count = bitstream_getbits(bs, 4); + styles_count->line_bits_count = bitstream_getbits(bs, 4); return 0; } int swf_styles_count_build(bitstream_t *bs, swf_styles_count_t *styles_count) { - ; + bitstream_putbits(bs, styles_count->fill_bits_count, 4); + bitstream_putbits(bs, styles_count->line_bits_count, 4); return 0; } int swf_styles_count_print(swf_styles_count_t *styles_count, int indent_depth) { - ; + print_indent(indent_depth); + printf("fill_bits_count=%d line_bits_count=%d\n", + styles_count->fill_bits_count, styles_count->line_bits_count); return 0; }