📄 fad.frame.c
字号:
/** * libFAD - Flash Animation Decode library * Copyright (C) 2005-2006 VGSystem Technologies, Inc. * * libFAD is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: fad.frame.c,v 1.65 2006/03/22 01:44:59 wrxzzj Exp $ */#include "fad.types.h"#include "fad.dl.h"#include "fad.shape.h"#include "fad.sound.h"#include "fad.button.h"#include "fad.fontext.h"#include "fad.jpeg.h"#include "fad.bitmap.h"#include "fad.morph.h"#include "fad.bits.h"#include "fad.tags.h"#include "fad.dynarray.h"#include "fad.sprite.h"#include "fad.actions.h"typedef struct { const char* tag_string; s32_t (* tag_decode) (fad_frame_t* frame, fad_stream_t* s);} fad_tag_t;static fad_render_t default_render;static fad_tag_t g_tag_array[] = { {"TAG_END", NULL }, { "TAG_SHOWFRAME", NULL }, { "TAG_DEFINESHAPE", style_shape_decode }, { "TAG_FREECHARACTER", NULL }, { "TAG_PLACEOBJECT", place_object_decode }, { "TAG_REMOVEOBJECT", NULL }, { "TAG_DEFINEBITS/JPEG", jpeg_bits_decode }, { "TAG_DEFINEBUTTON", button_decode }, { "TAG_JPEGTABLES", jpeg_tables_decode }, { "TAG_SETBACKGROUNDCOLOR", NULL }, { "TAG_DEFINEFONT", font_v1_decode }, { "TAG_DEFINETEXT", static_text_decode },#ifdef LIBFAD_AS2 { "TAG_DOACTION", action_script_decode },#else { "TAG_DOACTION", NULL },#endif { "TAG_DEFINEFONTINFO", fontinfo_decode }, { "TAG_DEFINESOUND", event_sound_decode }, { "TAG_STARTSOUND", NULL }, { "TAG_UNDEFINE(val=16)", NULL }, { "TAG_DEFINEBUTTONSOUND", button_sound_decode }, { "TAG_SOUNDSTREAMHEAD", stream_sound_head_decode }, { "TAG_SOUNDSTREAMBLOCK", stream_sound_block_decode }, { "TAG_DEFINEBITSLOSSLESS", bitmap_bits_decode }, { "TAG_DEFINEBITSJPEG2", jpeg_bits_decode }, { "TAG_DEFINESHAPE2", style_shape_decode }, { "TAG_DEFINEBUTTONCXFORM", button_cxform_decode }, { "TAG_PROTECT", NULL }, { "TAG_UNDEFINE(val=25)", NULL }, { "TAG_PLACEOBJECT2", place_object2_decode }, { "TAG_UNDEFINE(val=27)", NULL }, { "TAG_REMOVEOBJECT2", NULL }, { "TAG_UNDEFINE(val=29)", NULL }, { "TAG_UNDEFINE(val=30)", NULL }, { "TAG_UNDEFINE(val=31)", NULL }, { "TAG_DEFINESHAPE3", style_shape_decode }, { "TAG_DEFINETEXT2", static_text_decode }, { "TAG_DEFINEBUTTON2", button_decode }, { "TAG_DEFINEBITSJPEG3", jpeg_bits_decode }, { "TAG_DEFINEBITSLOSSLESS2", bitmap_bits_decode }, { "TAG_DEFINEEDITTEXT", NULL }, { "TAG_DEFINEMOVIE", NULL }, { "TAG_DEFINESPRITE", sprite_mc_decode }, { "TAG_NAMECHARACTER", NULL }, { "TAG_SERIALNUMBER", NULL }, { "TAG_GENERATORTEXT", NULL }, { "TAG_FRAMELABEL", NULL }, { "TAG_UNDEFINE(val=44)", NULL }, { "TAG_SOUNDSTREAMHEAD2", stream_sound_head_decode }, { "TAG_DEFINEMORPHSHAPE", morph_shape_decode }, { "TAG_UNDEFINE(val=47)", NULL }, { "TAG_DEFINEFONT2", font_v2_decode }, { "TAG_TEMPLATECOMMAND", NULL }, { "TAG_GENERATOR3", NULL }, { "TAG_UNDEFINE(val=51)", NULL }, { "TAG_EXTERNALFONT", NULL }, { "TAG_UNDEFINE(val=53)", NULL }, { "TAG_UNDEFINE(val=54)", NULL }, { "TAG_UNDEFINE(val=55)", NULL }, { "TAG_EXPORTASSET", NULL }, { "TAG_IMPORTASSETS", NULL }, { "TAG_ENABLEDEBUGGER", NULL }, { "TAG_DOINITACTION", NULL }, { "TAG_DEFINEVIDEOSTREAM", NULL }, { "TAG_VIDEOFRAME", NULL }, { "TAG_DEFINEFONTINFO2", fontinfo_decode }, { "TAG_MX4", NULL }, { "TAG_ENABLEDEBUGGER2", NULL }, { "TAG_SCRIPTLIMITS", NULL }, { "TAG_SETTABINDEX", NULL }};static s32_t _fad_frame_proc_mbevt(fad_frame_t *frame, u8_t evt, s32_t x, s32_t y);static s32_t _tag_decode_default_method (fad_frame_t* frame, fad_stream_t* s) { s32_t ret = 0; switch(s->tag_id) { case TAG_END: frame->sta = FAD_STA_FINISH; break; case TAG_SHOWFRAME: frame->output_frame++; frame->sta = FAD_STA_DORENDER; break; case TAG_STARTSOUND: { FAD_FRAME_SET_EVENTSOUND(frame->attr); frame->es_id = bits_get_u16(&s->bits); frame->es_si = bits_tell(&s->bits); } break; case TAG_REMOVEOBJECT: bits_get_u16(&s->bits); case TAG_REMOVEOBJECT2: { dl_node_t *node = NULL; u16_t depth = bits_get_u16(&s->bits); node = frame->dlhdr.rmv(&frame->dlhdr, depth); if(node) free(node); node = NULL; } break; case TAG_SETBACKGROUNDCOLOR: { u8_t* ptr = bits_tell(&s->bits); frame->r = *ptr; frame->g = *(ptr+1); frame->b = *(ptr+2); FAD_ERROR("frame background color(%d, %d, %d)\n", frame->r, frame->g, frame->b); } break; default: FAD_DEBUG("decode %s isn't implement now, ignore.\n", g_tag_array[s->tag_id].tag_string); ret = -1; break; } return ret;}void fad_frame_init(fad_frame_t* frame) { frame_priv_t *priv = NULL; dl_header_init(&frame->dlhdr); frame->attr = 0; frame->nbtn = 0; frame->output_frame = 0; frame->render = &default_render; default_render_init(frame->render); frame->sta = FAD_STA_INIT; frame->proc_mbevt = _fad_frame_proc_mbevt; if(! frame->priv) { priv = frame->priv = calloc(1, sizeof(frame_priv_t)); } mad_frame_init(&priv->mad_frame); mad_synth_init(&priv->mad_synth); mad_stream_init(&priv->mad_stream);}void fad_frame_finish(fad_frame_t* frame) { frame_priv_t *priv = NULL; dl_node_t* node = NULL; u16_t idx = 0, count = 0; dl_header_finish(&frame->dlhdr); default_render_term(frame->render); priv = (frame_priv_t *)frame->priv; if(priv) { mad_frame_finish(&priv->mad_frame); mad_synth_finish(&priv->mad_synth); mad_stream_finish(&priv->mad_stream); free(priv); frame->priv = NULL; }}s32_t fad_frame_seek(fad_frame_t *frame, fad_stream_t *s, s32_t idx) { s32_t offset = idx-frame->output_frame; if(offset > 0) { while(frame->output_frame < idx) fad_frame_decode(frame, s); } else if(offset < 0) { dl_header_finish(&frame->dlhdr); bits_buffer(&s->bits, s->bufbeg); frame->sta = FAD_STA_INIT; fad_frame_decode(frame, s); frame->sta = FAD_STA_SEEK; while(idx--) fad_frame_decode(frame, s); } return offset;}s32_t fad_frame_decode(fad_frame_t* frame, fad_stream_t* s) { u8_t* ptr = NULL; u16_t tag_id = 0; u32_t offset = 0; s32_t ret = 0, width = 0, height = 0; s32_t (* tag_decode_call)(fad_frame_t* frame, fad_stream_t* s); switch(frame->sta) { case FAD_STA_INIT: bits_get_rect(&s->bits, &frame->size); frame->rate = bits_get_u16(&s->bits); frame->total_frame = bits_get_u16(&s->bits); frame->sta = FAD_STA_DOTAG; FAD_ERROR("frame.total_frame = %d, frame.rate = %f, frame.size(%d, %d, %d, %d)\n\n", frame->total_frame, (double)frame->rate/0xff, frame->size.x0, frame->size.y0, frame->size.x1, frame->size.y1); break; case FAD_STA_SEEK: case FAD_STA_DOTAG: tag_id = bits_get_u16(&s->bits); s->tag_len = tag_id & 0x3F; tag_id = tag_id >> 6; if(s->tag_len == 0x3F) s->tag_len = bits_get_u32(&s->bits);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -