svnno****@sourc*****
svnno****@sourc*****
2009年 5月 16日 (土) 22:29:22 JST
Revision: 124 http://svn.sourceforge.jp/view?root=swfed&view=rev&rev=124 Author: yoya Date: 2009-05-16 22:29:22 +0900 (Sat, 16 May 2009) Log Message: ----------- swf tag sprite の parse/build/print 実装 Modified Paths: -------------- trunk/src/config.m4 trunk/src/swf_tag.c trunk/src/swfed.c Added Paths: ----------- trunk/src/swf_tag_sprite.c trunk/src/swf_tag_sprite.h -------------- next part -------------- Modified: trunk/src/config.m4 =================================================================== --- trunk/src/config.m4 2009-05-14 04:37:56 UTC (rev 123) +++ trunk/src/config.m4 2009-05-16 13:29:22 UTC (rev 124) @@ -61,5 +61,5 @@ 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_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_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_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_debug.c, $ext_shared) fi Modified: trunk/src/swf_tag.c =================================================================== --- trunk/src/swf_tag.c 2009-05-14 04:37:56 UTC (rev 123) +++ trunk/src/swf_tag.c 2009-05-16 13:29:22 UTC (rev 124) @@ -14,6 +14,7 @@ #include "swf_tag_edit.h" #include "swf_tag_action.h" #include "swf_tag_sound.h" +#include "swf_tag_sprite.h" swf_tag_info_t swf_tag_info_table[] = { { 0, "End", NULL }, @@ -47,7 +48,7 @@ { 35, "DefineBitsJPEG3", swf_tag_jpeg3_detail_handler }, { 36, "DefineBitsLossless2", swf_tag_lossless_detail_handler }, { 37, "DefineEditText", swf_tag_edit_detail_handler }, - { 39, "DefineSprite", NULL } , + { 39, "DefineSprite", swf_tag_sprite_detail_handler }, { 43, "FrameLabel", NULL } , { 48, "DefineFont2", NULL } , { 56, "Export", NULL } , Added: trunk/src/swf_tag_sprite.c =================================================================== --- trunk/src/swf_tag_sprite.c (rev 0) +++ trunk/src/swf_tag_sprite.c 2009-05-16 13:29:22 UTC (rev 124) @@ -0,0 +1,140 @@ +/* + +----------------------------------------------------------------------+ + | Author: yoya****@awm***** | + +----------------------------------------------------------------------+ +*/ + +#include <stdio.h> +#include <string.h> +#include "bitstream.h" +#include "swf_tag_sprite.h" +#include "swf_object.h" + +swf_tag_detail_handler_t sprite_detail_handler; + +swf_tag_detail_handler_t * +swf_tag_sprite_detail_handler(void) { + sprite_detail_handler.create = swf_tag_sprite_create_detail; + sprite_detail_handler.input = swf_tag_sprite_input_detail; + sprite_detail_handler.identity = swf_tag_sprite_identity_detail; + sprite_detail_handler.output = swf_tag_sprite_output_detail; + sprite_detail_handler.print = swf_tag_sprite_print_detail; + sprite_detail_handler.destroy = swf_tag_sprite_destroy_detail; + return &sprite_detail_handler; +} + +void * +swf_tag_sprite_create_detail(void) { + swf_tag_sprite_detail_t *swf_tag_sprite; + swf_tag_sprite = calloc(sizeof(*swf_tag_sprite), 1); + if (swf_tag_sprite == NULL) { + fprintf(stderr, "ERROR: swf_tag_sprite_create_detail: can't calloc\n"); + return NULL; + } + return swf_tag_sprite; +} + +int +swf_tag_sprite_input_detail(swf_tag_t *tag, struct swf_object_ *swf) { + swf_tag_sprite_detail_t *swf_tag_sprite = tag->detail; + unsigned char *data = tag->data; + unsigned long length = tag->length; + bitstream_t *bs; + swf_tag_t **_tag; + if (swf_tag_sprite == NULL) { + fprintf(stderr, "ERROR: swf_tag_sprite_input_detail: swf_tag_sprite == NULL\n"); + return 1; + } + bs = bitstream_open(); + bitstream_input(bs, data, length); + swf_tag_sprite->sprite_id = bitstream_getbytesLE(bs, 2); + swf_tag_sprite->frame_count = bitstream_getbytesLE(bs, 2); + // + _tag = &swf_tag_sprite->tag; + while(1) { + long pos; + pos = bitstream_getbytepos(bs); + if ((pos == -1) || ((long) length <= pos)) { + break; + } + *_tag = swf_tag_create(bs); + if (_tag == NULL) { + fprintf(stderr, "swf_object_input: swf_tag_create failed\n"); + } + _tag = &((*_tag)->next); + } + bitstream_close(bs); + return 0; +} + +int swf_tag_sprite_identity_detail(swf_tag_t *tag, int id) { + unsigned char *data = tag->data; + bitstream_t *bs; + int sprite_id; + if (tag->detail) { + swf_tag_sprite_detail_t *swf_tag_sprite = (swf_tag_sprite_detail_t *) tag->detail; + if (swf_tag_sprite->sprite_id == id) { + return 0; + } + return 1; + } + bs = bitstream_open(); + bitstream_input(bs, data, 2); + sprite_id = bitstream_getbytesLE(bs, 2); + bitstream_close(bs); + if (id == sprite_id) { + return 0; + } + return 1; +} + +unsigned char * +swf_tag_sprite_output_detail(swf_tag_t *tag, unsigned long *length, + struct swf_object_ *swf) { + swf_tag_sprite_detail_t *swf_tag_sprite = (swf_tag_sprite_detail_t *) tag->detail; + bitstream_t *bs; + unsigned char *data; + (void) tag; + *length = 0; + bs = bitstream_open(); + bitstream_putbytesLE(bs, swf_tag_sprite->sprite_id, 2); + data = bitstream_steal(bs, length); + bitstream_close(bs); + return data; +} + +void +swf_tag_sprite_print_detail(swf_tag_t *tag, + struct swf_object_ *swf) { + swf_tag_sprite_detail_t *swf_tag_sprite = (swf_tag_sprite_detail_t *) tag->detail; + int i; + swf_tag_t *_tag; + printf("\tsprite_id=%d\n", swf_tag_sprite->sprite_id); + printf("\tframe_count=%d\n", swf_tag_sprite->frame_count); + _tag = swf_tag_sprite->tag; + printf("---- start sprite_id=%d ----\n", swf_tag_sprite->sprite_id); + for (i=0 ; _tag ; i++) { + printf(" [%d] ", i); + swf_tag_print(_tag, swf); + if (_tag->tag == 0) { // END Tag + break; + } + _tag = _tag->next; + } + printf("---- end sprite_id=%d ----\n", swf_tag_sprite->sprite_id); + return ; +} + +void +swf_tag_sprite_destroy_detail(swf_tag_t *tag) { + swf_tag_sprite_detail_t *swf_tag_sprite = (swf_tag_sprite_detail_t *) tag->detail; + if (swf_tag_sprite) { + swf_tag_t *tag, *next_tag; + for (tag=swf_tag_sprite->tag ; tag ; tag=next_tag) { + next_tag = tag->next; + swf_tag_destroy(tag); + } + free(swf_tag_sprite); + } + return ; +} Added: trunk/src/swf_tag_sprite.h =================================================================== --- trunk/src/swf_tag_sprite.h (rev 0) +++ trunk/src/swf_tag_sprite.h 2009-05-16 13:29:22 UTC (rev 124) @@ -0,0 +1,30 @@ +/* + +----------------------------------------------------------------------+ + | Author: yoya****@awm***** | + +----------------------------------------------------------------------+ +*/ + +#ifndef __SWF_TAG_SPRITE__H__ +#define __SWF_TAG_SPRITE__H__ + +#include "swf_tag.h" + +typedef struct swf_tag_sprite_detail_ { + int sprite_id; + unsigned short frame_count; + swf_tag_t *tag; +} swf_tag_sprite_detail_t; + +extern swf_tag_detail_handler_t *swf_tag_sprite_detail_handler(void); + +extern void *swf_tag_sprite_create_detail(void); +extern int swf_tag_sprite_input_detail(swf_tag_t *tag, struct swf_object_ *swf); +extern int swf_tag_sprite_identity_detail(swf_tag_t *tag, int id); +extern unsigned char *swf_tag_sprite_output_detail(swf_tag_t *tag, + unsigned long *length, + struct swf_object_ *swf); +extern void swf_tag_sprite_print_detail(swf_tag_t *tag, + struct swf_object_ *swf); +extern void swf_tag_sprite_destroy_detail(swf_tag_t *tag); + +#endif /* __SWF_TAG_SPRITE__H__ */ Modified: trunk/src/swfed.c =================================================================== --- trunk/src/swfed.c 2009-05-14 04:37:56 UTC (rev 123) +++ trunk/src/swfed.c 2009-05-16 13:29:22 UTC (rev 124) @@ -33,6 +33,7 @@ #include "swf_tag_edit.h" #include "swf_tag_sound.h" #include "swf_tag_action.h" +#include "swf_tag_sprite.h" #include "swf_tag.h" #include "swf_object.h" @@ -378,6 +379,7 @@ swf_tag_edit_detail_t *tag_edit; swf_tag_sound_detail_t *tag_sound; swf_tag_action_detail_t *tag_action; + swf_tag_sprite_detail_t *tag_sprite; case 6: // DefineBitsJPEG case 21: // DefineBitsJPEG2 case 35: // DefineBitsJPEG3 @@ -439,6 +441,12 @@ (char *)tag_edit->edit_initial_text, 1); } break; + case 39: // DefineSprite; + tag_sprite = tag->detail; + array_init(return_value); + add_assoc_long(return_value, "sprite_id", tag_sprite->sprite_id); + add_assoc_long(return_value, "frame_count", tag_sprite->frame_count); + break; default: RETURN_FALSE; }