Benjamin Otte
2007-Jun-06 15:40 UTC
[Swfdec] 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
libswfdec/Makefile.am | 2 libswfdec/swfdec_root_movie.c | 10 +- libswfdec/swfdec_root_sprite.c | 178 ----------------------------------------- libswfdec/swfdec_root_sprite.h | 65 -------------- libswfdec/swfdec_swf_decoder.c | 64 ++++++++++++++ libswfdec/swfdec_swf_decoder.h | 20 ++++ libswfdec/swfdec_tag.c | 65 ++++++++++++++ 7 files changed, 149 insertions(+), 255 deletions(-) New commits: diff-tree d06b5d5094832befb740170c297bd3861fc7068c (from bf3f17bb8f8aa3d5a9cf4d4121e77efc2c1f048c) Author: Benjamin Otte <otte at gnome.org> Date: Wed Jun 6 17:29:39 2007 +0200 get rid of the root sprite and put the relevant information into the SwfdecSwfDecoder diff --git a/libswfdec/Makefile.am b/libswfdec/Makefile.am index 68350fc..5d8a92a 100644 --- a/libswfdec/Makefile.am +++ b/libswfdec/Makefile.am @@ -98,7 +98,6 @@ libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES swfdec_rect.c \ swfdec_ringbuffer.c \ swfdec_root_movie.c \ - swfdec_root_sprite.c \ swfdec_script.c \ swfdec_shape.c \ swfdec_sound.c \ @@ -194,7 +193,6 @@ noinst_HEADERS = \ swfdec_rect.h \ swfdec_ringbuffer.h \ swfdec_root_movie.h \ - swfdec_root_sprite.h \ swfdec_script.h \ swfdec_shape.h \ swfdec_sound.h \ diff --git a/libswfdec/swfdec_root_movie.c b/libswfdec/swfdec_root_movie.c index 1fcba46..74e2c9a 100644 --- a/libswfdec/swfdec_root_movie.c +++ b/libswfdec/swfdec_root_movie.c @@ -33,8 +33,8 @@ #include "swfdec_loader_internal.h" #include "swfdec_loadertarget.h" #include "swfdec_player_internal.h" -#include "swfdec_root_sprite.h" #include "swfdec_script.h" +#include "swfdec_sprite.h" #include "swfdec_swf_decoder.h" @@ -216,7 +216,7 @@ swfdec_root_movie_load (SwfdecRootMovie void swfdec_root_movie_perform_root_actions (SwfdecRootMovie *root, guint frame) { - SwfdecRootSprite *sprite; + SwfdecSwfDecoder *s; GArray *array; guint i; @@ -226,12 +226,12 @@ swfdec_root_movie_perform_root_actions ( if (frame < root->root_actions_performed) return; - sprite = SWFDEC_ROOT_SPRITE (SWFDEC_SPRITE_MOVIE (root)->sprite); + s = SWFDEC_SWF_DECODER (root->decoder); SWFDEC_LOG ("performing root actions for frame %u", root->root_actions_performed); root->root_actions_performed++; - if (!sprite->root_actions) + if (!s->root_actions) return; - array = sprite->root_actions[frame]; + array = s->root_actions[frame]; if (array == NULL) return; for (i = 0; i < array->len; i++) { diff --git a/libswfdec/swfdec_root_sprite.c b/libswfdec/swfdec_root_sprite.c deleted file mode 100644 index 7323a1e..0000000 --- a/libswfdec/swfdec_root_sprite.c +++ /dev/null @@ -1,178 +0,0 @@ -/* Swfdec - * Copyright (C) 2007 Benjamin Otte <otte at 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_player_internal.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; - guint count, i; - - count = swfdec_bits_get_u16 (bits); - SWFDEC_LOG ("exporting %u assets", count); - for (i = 0; i < count && swfdec_bits_left (bits); 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 if (name == NULL) { - SWFDEC_ERROR ("cannot export id %u, no name was given", id); - } 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; - char *name; - - 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; - } - name = g_strdup_printf ("InitAction %u", id); - sprite->init_action = swfdec_script_new_for_context (SWFDEC_AS_CONTEXT (SWFDEC_DECODER (s)->player), - bits, name, s->version); - g_free (name); - 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 deleted file mode 100644 index 3414164..0000000 --- a/libswfdec/swfdec_root_sprite.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Swfdec - * Copyright (C) 2007 Benjamin Otte <otte at 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 diff --git a/libswfdec/swfdec_swf_decoder.c b/libswfdec/swfdec_swf_decoder.c index 3163448..66c6e34 100644 --- a/libswfdec/swfdec_swf_decoder.c +++ b/libswfdec/swfdec_swf_decoder.c @@ -35,7 +35,8 @@ #include "swfdec_cached.h" #include "swfdec_debug.h" #include "swfdec_player_internal.h" -#include "swfdec_root_sprite.h" +#include "swfdec_script.h" +#include "swfdec_sprite.h" enum { SWFDEC_STATE_INIT1 = 0, @@ -50,6 +51,38 @@ static void swfdec_decoder_dispose (GObject *object) { SwfdecSwfDecoder *s = SWFDEC_SWF_DECODER (object); + guint i,j; + + if (s->root_actions) { + for (i = 0; i < s->main_sprite->n_frames; i++) { + GArray *array = s->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 (s->root_actions); + s->root_actions = NULL; + } g_hash_table_destroy (s->characters); g_object_unref (s->main_sprite); @@ -350,7 +383,7 @@ swfdec_swf_decoder_class_init (SwfdecSwf static void swfdec_swf_decoder_init (SwfdecSwfDecoder *s) { - s->main_sprite = g_object_new (SWFDEC_TYPE_ROOT_SPRITE, NULL); + s->main_sprite = g_object_new (SWFDEC_TYPE_SPRITE, NULL); s->characters = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); @@ -400,3 +433,30 @@ swfdec_swf_decoder_create_character (Swf return result; } + +void +swfdec_swf_decoder_add_root_action (SwfdecSwfDecoder *s, + SwfdecRootActionType type, gpointer data) +{ + SwfdecSprite *sprite; + GArray *array; + SwfdecSpriteAction action; + + g_return_if_fail (SWFDEC_IS_SWF_DECODER (s)); + sprite = s->main_sprite; + g_return_if_fail (sprite->parse_frame < sprite->n_frames); + + if (s->root_actions == NULL) + s->root_actions = g_new0 (GArray *, sprite->n_frames); + + array = s->root_actions[sprite->parse_frame]; + if (array == NULL) { + s->root_actions[sprite->parse_frame] = + g_array_new (FALSE, FALSE, sizeof (SwfdecSpriteAction)); + array = s->root_actions[sprite->parse_frame]; + } + action.type = type; + action.data = data; + g_array_append_val (array, action); +} + diff --git a/libswfdec/swfdec_swf_decoder.h b/libswfdec/swfdec_swf_decoder.h index 63dec23..a913447 100644 --- a/libswfdec/swfdec_swf_decoder.h +++ b/libswfdec/swfdec_swf_decoder.h @@ -35,6 +35,17 @@ G_BEGIN_DECLS //typedef struct _SwfdecSwfDecoder SwfdecSwfDecoder; typedef struct _SwfdecSwfDecoderClass SwfdecSwfDecoderClass; typedef int SwfdecTagFunc (SwfdecSwfDecoder *); +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_SWF_DECODER (swfdec_swf_decoder_get_type()) #define SWFDEC_IS_SWF_DECODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_SWF_DECODER)) @@ -62,6 +73,7 @@ struct _SwfdecSwfDecoder GHashTable *characters; /* list of all objects with an id (called characters) */ SwfdecSprite *main_sprite; SwfdecSprite *parse_sprite; + GArray **root_actions; /* actions to be executed by the root sprite */ gboolean protection; /* TRUE is this file is protected and may not be edited */ char *password; /* MD5'd password to open for editing or NULL if may not be opened */ @@ -77,11 +89,15 @@ struct _SwfdecSwfDecoderClass { GType swfdec_swf_decoder_get_type (void); gpointer swfdec_swf_decoder_get_character (SwfdecSwfDecoder * s, - guint id); + guint id); gpointer swfdec_swf_decoder_create_character (SwfdecSwfDecoder * s, - guint id, + guint id, GType type); +void swfdec_swf_decoder_add_root_action (SwfdecSwfDecoder * s, + SwfdecRootActionType type, + gpointer data); + SwfdecTagFunc *swfdec_swf_decoder_get_tag_func (int tag); const char *swfdec_swf_decoder_get_tag_name (int tag); int swfdec_swf_decoder_get_tag_flag (int tag); diff --git a/libswfdec/swfdec_tag.c b/libswfdec/swfdec_tag.c index 10a33b6..9fc60f5 100644 --- a/libswfdec/swfdec_tag.c +++ b/libswfdec/swfdec_tag.c @@ -39,7 +39,6 @@ #include "swfdec_movie.h" /* for SwfdecContent */ #include "swfdec_pattern.h" #include "swfdec_player_internal.h" -#include "swfdec_root_sprite.h" #include "swfdec_script.h" #include "swfdec_shape.h" #include "swfdec_sound.h" @@ -532,6 +531,70 @@ tag_func_file_attributes (SwfdecSwfDecod return SWFDEC_STATUS_OK; } +int +tag_func_export_assets (SwfdecSwfDecoder * s) +{ + SwfdecBits *bits = &s->b; + guint count, i; + + count = swfdec_bits_get_u16 (bits); + SWFDEC_LOG ("exporting %u assets", count); + for (i = 0; i < count && swfdec_bits_left (bits); 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 if (name == NULL) { + SWFDEC_ERROR ("cannot export id %u, no name was given", id); + } 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_swf_decoder_add_root_action (s, 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; + char *name; + + 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; + } + name = g_strdup_printf ("InitAction %u", id); + sprite->init_action = swfdec_script_new_for_context (SWFDEC_AS_CONTEXT (SWFDEC_DECODER (s)->player), + bits, name, s->version); + g_free (name); + if (sprite->init_action) { + swfdec_script_ref (sprite->init_action); + swfdec_swf_decoder_add_root_action (s, SWFDEC_ROOT_ACTION_INIT_SCRIPT, sprite->init_action); + } + + return SWFDEC_STATUS_OK; +} + /* may appear inside DefineSprite */ #define SPRITE 1 struct tag_func_struct
Possibly Parallel Threads
- libswfdec/swfdec_root_sprite.c libswfdec/swfdec_root_sprite.h
- 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