Benjamin Otte
2007-Mar-09 13:08 UTC
[Swfdec] libswfdec/swfdec_root_sprite.c libswfdec/swfdec_root_sprite.h
libswfdec/swfdec_root_sprite.c | 172 +++++++++++++++++++++++++++++++++++++++++ libswfdec/swfdec_root_sprite.h | 65 +++++++++++++++ 2 files changed, 237 insertions(+) New commits: diff-tree b86811135dd32ae460e5082f4f986664de624b89 (from 09541f87302d441396064f480fa3c8da0a07993e) Author: Benjamin Otte <otte@gnome.org> Date: Fri Mar 9 22:08:56 2007 +0100 Those files seem to be missing for ages diff --git a/libswfdec/swfdec_root_sprite.c b/libswfdec/swfdec_root_sprite.c new file mode 100644 index 0000000..e8e868b --- /dev/null +++ b/libswfdec/swfdec_root_sprite.c @@ -0,0 +1,172 @@ +/* Swfdec + * Copyright (C) 2007 Benjamin Otte <otte@gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include <string.h> + +#include "swfdec_root_sprite.h" +#include "swfdec_debug.h" +#include "swfdec_script.h" +#include "swfdec_swf_decoder.h" + +G_DEFINE_TYPE (SwfdecRootSprite, swfdec_root_sprite, SWFDEC_TYPE_SPRITE) + +void +swfdec_root_sprite_dispose (GObject *object) +{ + SwfdecSprite *sprite = SWFDEC_SPRITE (object); + SwfdecRootSprite *root = SWFDEC_ROOT_SPRITE (object); + guint i,j; + + if (root->root_actions) { + for (i = 0; i < sprite->n_frames; i++) { + GArray *array = root->root_actions[i]; + if (array) { + for (j = 0; j < array->len; j++) { + SwfdecSpriteAction *action = &g_array_index (array, SwfdecSpriteAction, j); + + switch (action->type) { + case SWFDEC_ROOT_ACTION_EXPORT: + { + SwfdecRootExportData *data = action->data; + g_free (data->name); + g_object_unref (data->character); + g_free (data); + } + break; + case SWFDEC_ROOT_ACTION_INIT_SCRIPT: + swfdec_script_unref (action->data); + break; + default: + g_assert_not_reached (); + break; + } + } + g_array_free (array, TRUE); + } + } + g_free (root->root_actions); + root->root_actions = NULL; + } + + G_OBJECT_CLASS (swfdec_root_sprite_parent_class)->dispose (object); +} + +static void +swfdec_root_sprite_class_init (SwfdecRootSpriteClass * g_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (g_class); + + object_class->dispose = swfdec_root_sprite_dispose; +} + +static void +swfdec_root_sprite_init (SwfdecRootSprite * root_sprite) +{ +} + +void +swfdec_root_sprite_add_root_action (SwfdecRootSprite *root, + SwfdecRootActionType type, gpointer data) +{ + SwfdecSprite *sprite; + GArray *array; + SwfdecSpriteAction action; + + g_return_if_fail (SWFDEC_IS_ROOT_SPRITE (root)); + sprite = SWFDEC_SPRITE (root); + g_return_if_fail (sprite->parse_frame < sprite->n_frames); + + if (root->root_actions == NULL) + root->root_actions = g_new0 (GArray *, sprite->n_frames); + + array = root->root_actions[sprite->parse_frame]; + if (array == NULL) { + root->root_actions[sprite->parse_frame] = + g_array_new (FALSE, FALSE, sizeof (SwfdecSpriteAction)); + array = root->root_actions[sprite->parse_frame]; + } + action.type = type; + action.data = data; + g_array_append_val (array, action); +} + +int +tag_func_export_assets (SwfdecSwfDecoder * s) +{ + SwfdecBits *bits = &s->b; + unsigned int count, i; + + count = swfdec_bits_get_u16 (bits); + SWFDEC_LOG ("exporting %u assets", count); + for (i = 0; i < count; i++) { + guint id; + SwfdecCharacter *object; + char *name; + id = swfdec_bits_get_u16 (bits); + object = swfdec_swf_decoder_get_character (s, id); + name = swfdec_bits_get_string (bits); + if (object == NULL) { + SWFDEC_ERROR ("cannot export id %u as %s, id wasn't found", id, name); + g_free (name); + } else { + SwfdecRootExportData *data = g_new (SwfdecRootExportData, 1); + data->name = name; + data->character = object; + SWFDEC_LOG ("exporting %s %u as %s", G_OBJECT_TYPE_NAME (object), id, name); + g_object_ref (object); + swfdec_root_sprite_add_root_action (SWFDEC_ROOT_SPRITE (s->main_sprite), + SWFDEC_ROOT_ACTION_EXPORT, data); + } + } + + return SWFDEC_STATUS_OK; +} + +int +tag_func_do_init_action (SwfdecSwfDecoder * s) +{ + SwfdecBits *bits = &s->b; + guint id; + SwfdecSprite *sprite; + + id = swfdec_bits_get_u16 (bits); + SWFDEC_LOG (" id = %u", id); + sprite = swfdec_swf_decoder_get_character (s, id); + if (!SWFDEC_IS_SPRITE (sprite)) { + SWFDEC_ERROR ("character %u is not a sprite", id); + return SWFDEC_STATUS_OK; + } + if (sprite->init_action != NULL) { + SWFDEC_ERROR ("sprite %u already has an init action", id); + return SWFDEC_STATUS_OK; + } + sprite->init_action = swfdec_script_new_for_player (SWFDEC_DECODER (s)->player, + bits, "InitAction", s->version); + if (sprite->init_action) { + swfdec_script_ref (sprite->init_action); + swfdec_root_sprite_add_root_action (SWFDEC_ROOT_SPRITE (s->main_sprite), + SWFDEC_ROOT_ACTION_INIT_SCRIPT, sprite->init_action); + } + + return SWFDEC_STATUS_OK; +} + diff --git a/libswfdec/swfdec_root_sprite.h b/libswfdec/swfdec_root_sprite.h new file mode 100644 index 0000000..3414164 --- /dev/null +++ b/libswfdec/swfdec_root_sprite.h @@ -0,0 +1,65 @@ +/* Swfdec + * Copyright (C) 2007 Benjamin Otte <otte@gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef _SWFDEC_ROOT_SPRITE_H_ +#define _SWFDEC_ROOT_SPRITE_H_ + +#include <libswfdec/swfdec_sprite.h> + +G_BEGIN_DECLS + +typedef struct _SwfdecRootSpriteClass SwfdecRootSpriteClass; +typedef struct _SwfdecRootExportData SwfdecRootExportData; + +typedef enum { + SWFDEC_ROOT_ACTION_EXPORT, /* contains a SwfdecExportData */ + SWFDEC_ROOT_ACTION_INIT_SCRIPT, /* contains a SwfdecScript */ +} SwfdecRootActionType; + +struct _SwfdecRootExportData { + char * name; + SwfdecCharacter * character; +}; + +#define SWFDEC_TYPE_ROOT_SPRITE (swfdec_root_sprite_get_type()) +#define SWFDEC_IS_ROOT_SPRITE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_ROOT_SPRITE)) +#define SWFDEC_IS_ROOT_SPRITE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_ROOT_SPRITE)) +#define SWFDEC_ROOT_SPRITE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_ROOT_SPRITE, SwfdecRootSprite)) +#define SWFDEC_ROOT_SPRITE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_ROOT_SPRITE, SwfdecRootSpriteClass)) + +struct _SwfdecRootSprite +{ + SwfdecSprite sprite; + + GArray ** root_actions; /* n_frames of root actions */ +}; + +struct _SwfdecRootSpriteClass +{ + SwfdecGraphicClass graphic_class; +}; + +GType swfdec_root_sprite_get_type (void); + +int tag_func_export_assets (SwfdecSwfDecoder * s); +int tag_func_do_init_action (SwfdecSwfDecoder * s); + + +G_END_DECLS +#endif
Seemingly Similar Threads
- Branch 'as' - libswfdec/Makefile.am libswfdec/swfdec_root_movie.c libswfdec/swfdec_root_sprite.c libswfdec/swfdec_root_sprite.h libswfdec/swfdec_swf_decoder.c libswfdec/swfdec_swf_decoder.h libswfdec/swfdec_tag.c
- 13 commits - libswfdec/Makefile.am libswfdec/swfdec_js_global.c libswfdec/swfdec_js_movie.c libswfdec/swfdec_root_movie.c libswfdec/swfdec_root_movie.h libswfdec/swfdec_script.c libswfdec/swfdec_sprite.h libswfdec/swfdec_sprite_movie.c
- 6 commits - libswfdec/swfdec_as_interpret.c libswfdec/swfdec_event.c libswfdec/swfdec_event.h libswfdec/swfdec_movie.c libswfdec/swfdec_movie.h libswfdec/swfdec_player.c libswfdec/swfdec_player_internal.h libswfdec/swfdec_resource.c
- Branch 'as' - 8 commits - libswfdec/swfdec_movie.c libswfdec/swfdec_sprite.c libswfdec/swfdec_sprite.h libswfdec/swfdec_sprite_movie.c libswfdec/swfdec_sprite_movie.h libswfdec/swfdec_swf_decoder.c libswfdec/swfdec_swf_decoder.h
- 8 commits - libswfdec/swfdec_buffer.c libswfdec/swfdec_buffer.h libswfdec/swfdec_root_sprite.c libswfdec/swfdec_swf_decoder.c libswfdec/swfdec_tag.c NEWS test/parse.c