📄 swfdec_sprite.c
字号:
static SwfdecContent *swfdec_contents_create (SwfdecSprite *sprite, int depth, gboolean copy, gboolean new){ SwfdecContent *content = swfdec_content_new (depth); content->start = sprite->parse_frame; content->end = sprite->n_frames; if (copy) { SwfdecContent *copy; copy = swfdec_content_find (sprite, depth); if (copy == NULL) { SWFDEC_WARNING ("Couldn't copy depth %u in frame %u", depth, sprite->parse_frame); } else { *content = *copy; SWFDEC_LOG ("Copying from content %p", copy); if (content->name) content->name = g_strdup (copy->name); if (content->events) content->events = swfdec_event_list_copy (copy->events); if (new) { content->start = sprite->parse_frame; content->end = sprite->n_frames; } swfdec_sprite_add_action (sprite, new ? SWFDEC_SPRITE_ACTION_ADD : SWFDEC_SPRITE_ACTION_UPDATE, content); return content; } } swfdec_sprite_add_action (sprite, SWFDEC_SPRITE_ACTION_ADD, content); return content;}intswfdec_spriteseg_place_object_2 (SwfdecSwfDecoder * s){ SwfdecBits *bits = &s->b; int has_clip_actions; int has_clip_depth; int has_name; int has_ratio; int has_color_transform; int has_matrix; int has_character; int move; int depth; SwfdecContent *content; has_clip_actions = swfdec_bits_getbit (bits); has_clip_depth = swfdec_bits_getbit (bits); has_name = swfdec_bits_getbit (bits); has_ratio = swfdec_bits_getbit (bits); has_color_transform = swfdec_bits_getbit (bits); has_matrix = swfdec_bits_getbit (bits); has_character = swfdec_bits_getbit (bits); move = swfdec_bits_getbit (bits); depth = swfdec_bits_get_u16 (bits); SWFDEC_LOG (" has_clip_actions = %d", has_clip_actions); SWFDEC_LOG (" has_clip_depth = %d", has_clip_depth); SWFDEC_LOG (" has_name = %d", has_name); SWFDEC_LOG (" has_ratio = %d", has_ratio); SWFDEC_LOG (" has_color_transform = %d", has_color_transform); SWFDEC_LOG (" has_matrix = %d", has_matrix); SWFDEC_LOG (" has_character = %d", has_character); SWFDEC_LOG (" move = %d", move); SWFDEC_LOG (" depth = %d (=> %d)", depth, depth - 16384); depth -= 16384; /* new name always means new object */ content = swfdec_contents_create (s->parse_sprite, depth, move, has_character || has_name); if (has_character) { int id = swfdec_bits_get_u16 (bits); content->graphic = swfdec_swf_decoder_get_character (s, id); if (!SWFDEC_IS_GRAPHIC (content->graphic)) { g_hash_table_remove (s->parse_sprite->live_content, GUINT_TO_POINTER (content->depth)); swfdec_content_free (content); swfdec_sprite_remove_last_action (s->parse_sprite, s->parse_sprite->parse_frame); SWFDEC_ERROR ("id %u does not specify a graphic", id); return SWFDEC_STATUS_OK; } content->sequence = content; SWFDEC_LOG (" id = %d", id); } else if (content->graphic == NULL) { SWFDEC_ERROR ("no character specified and copying didn't give one"); g_hash_table_remove (s->parse_sprite->live_content, GUINT_TO_POINTER (content->depth)); swfdec_content_free (content); swfdec_sprite_remove_last_action (s->parse_sprite, s->parse_sprite->parse_frame); return SWFDEC_STATUS_OK; } if (has_matrix) { swfdec_bits_get_matrix (bits, &content->transform, NULL); SWFDEC_LOG (" matrix = { %g %g, %g %g } + { %g %g }", content->transform.xx, content->transform.yx, content->transform.xy, content->transform.yy, content->transform.x0, content->transform.y0); } if (has_color_transform) { swfdec_bits_get_color_transform (bits, &content->color_transform); SWFDEC_LOG (" color transform = %d %d %d %d %d %d %d %d", content->color_transform.ra, content->color_transform.rb, content->color_transform.ga, content->color_transform.gb, content->color_transform.ba, content->color_transform.bb, content->color_transform.aa, content->color_transform.ab); } swfdec_bits_syncbits (bits); if (has_ratio) { content->ratio = swfdec_bits_get_u16 (bits); SWFDEC_LOG (" ratio = %d", content->ratio); } if (has_name) { g_free (content->name); content->name = swfdec_bits_get_string (bits); SWFDEC_LOG (" name = %s", content->name); } if (has_clip_depth) { content->clip_depth = swfdec_bits_get_u16 (bits) - 16384; SWFDEC_LOG (" clip_depth = %d (=> %d)", content->clip_depth + 16384, content->clip_depth); } if (has_clip_actions) { int reserved, clip_event_flags, event_flags, key_code; char *script_name; if (content->events) { swfdec_event_list_free (content->events); content->events = NULL; } reserved = swfdec_bits_get_u16 (bits); clip_event_flags = swfdec_get_clipeventflags (s, bits); if (content->name) script_name = g_strdup (content->name); else script_name = g_strdup_printf ("Sprite%u", SWFDEC_CHARACTER (content->graphic)->id); while ((event_flags = swfdec_get_clipeventflags (s, bits)) != 0) { guint length = swfdec_bits_get_u32 (bits); SwfdecBits action_bits; SwfdecBuffer *buffer = swfdec_bits_get_buffer (bits, length); if (buffer == NULL) break; swfdec_bits_init (&action_bits, buffer); if (event_flags & SWFDEC_EVENT_KEY_PRESS) key_code = swfdec_bits_get_u8 (&action_bits); else key_code = 0; SWFDEC_INFO ("clip event with flags 0x%X, key code %d", event_flags, key_code);#define SWFDEC_IMPLEMENTED_EVENTS \ (SWFDEC_EVENT_LOAD | SWFDEC_EVENT_UNLOAD | SWFDEC_EVENT_ENTER | \ SWFDEC_EVENT_MOUSE_DOWN | SWFDEC_EVENT_MOUSE_MOVE | SWFDEC_EVENT_MOUSE_UP) if (event_flags & ~SWFDEC_IMPLEMENTED_EVENTS) { SWFDEC_ERROR ("using non-implemented clip events %u", event_flags & ~SWFDEC_IMPLEMENTED_EVENTS); } if (content->events == NULL) content->events = swfdec_event_list_new (SWFDEC_DECODER (s)->player); swfdec_event_list_parse (content->events, &action_bits, s->version, event_flags, key_code, script_name); if (swfdec_bits_left (&action_bits)) { SWFDEC_ERROR ("not all action data was parsed: %u bytes left", swfdec_bits_left (&action_bits)); } swfdec_buffer_unref (buffer); } g_free (script_name); } return SWFDEC_STATUS_OK;}intswfdec_spriteseg_remove_object (SwfdecSwfDecoder * s){ int depth; swfdec_bits_get_u16 (&s->b); depth = swfdec_bits_get_u16 (&s->b); SWFDEC_LOG (" depth = %d (=> %d)", depth, depth - 16384); depth -= 16384; swfdec_sprite_add_action (s->parse_sprite, SWFDEC_SPRITE_ACTION_REMOVE, GINT_TO_POINTER (depth)); return SWFDEC_STATUS_OK;}intswfdec_spriteseg_remove_object_2 (SwfdecSwfDecoder * s){ unsigned int depth; depth = swfdec_bits_get_u16 (&s->b); SWFDEC_LOG (" depth = %u", depth); depth -= 16384; swfdec_sprite_add_action (s->parse_sprite, SWFDEC_SPRITE_ACTION_REMOVE, GINT_TO_POINTER (depth)); return SWFDEC_STATUS_OK;}static SwfdecMovie *swfdec_sprite_create_movie (SwfdecGraphic *graphic){ SwfdecSpriteMovie *ret = g_object_new (SWFDEC_TYPE_SPRITE_MOVIE, NULL); ret->sprite = SWFDEC_SPRITE (graphic); return SWFDEC_MOVIE (ret);}static voidswfdec_sprite_class_init (SwfdecSpriteClass * g_class){ GObjectClass *object_class = G_OBJECT_CLASS (g_class); SwfdecGraphicClass *graphic_class = SWFDEC_GRAPHIC_CLASS (g_class); object_class->dispose = swfdec_sprite_dispose; graphic_class->create_movie = swfdec_sprite_create_movie;}static voidswfdec_sprite_init (SwfdecSprite * sprite){ sprite->live_content = g_hash_table_new (g_direct_hash, g_direct_equal);}voidswfdec_sprite_set_n_frames (SwfdecSprite *sprite, unsigned int n_frames, unsigned int rate){ guint i; g_return_if_fail (SWFDEC_IS_SPRITE (sprite)); if (n_frames == 0) n_frames = 1; sprite->frames = g_new0 (SwfdecSpriteFrame, n_frames); sprite->n_frames = n_frames; for (i = 0; i < n_frames; i++) { sprite->frames[i].sound_samples = 44100 * 256 / rate; } SWFDEC_LOG ("n_frames = %d", sprite->n_frames);}unsigned intswfdec_sprite_get_next_frame (SwfdecSprite *sprite, unsigned int current_frame){ unsigned int next_frame, n_frames; g_return_val_if_fail (SWFDEC_IS_SPRITE (sprite), 0); n_frames = MIN (sprite->n_frames, sprite->parse_frame); next_frame = current_frame + 1; if (next_frame >= n_frames) next_frame = 0; return next_frame;}intswfdec_sprite_get_frame (SwfdecSprite *sprite, const char *label){ guint i; g_return_val_if_fail (SWFDEC_IS_SPRITE (sprite), -1); g_return_val_if_fail (label != NULL, -1); for (i = 0; i < SWFDEC_SPRITE (sprite)->n_frames; i++) { SwfdecSpriteFrame *frame = &sprite->frames[i]; if (frame->label == NULL) continue; if (g_str_equal (frame->label, label)) return i; } return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -