⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swfdec_tag.c

📁 Swfdec is a decoder/renderer for Macromedia Flash animations. The decoding and rendering engine is
💻 C
📖 第 1 页 / 共 2 页
字号:
  SWFDEC_LOG ("  length of region = %d", length);  if (length)    swfdec_bits_init_bits (&bits, &s->b, length > 2 ? length - 2 : 0);  else    swfdec_bits_init_bits (&bits, &s->b, swfdec_bits_left (&s->b) / 8);  while (swfdec_bits_peek_u8 (&bits)) {    guint character;    guint depth;    guint states;    gboolean blend_mode, has_filters;    SwfdecContent *content;    if (s->version >= 8) {      reserved = swfdec_bits_getbits (&bits, 2);      blend_mode = swfdec_bits_getbit (&bits);      has_filters = swfdec_bits_getbit (&bits);      SWFDEC_LOG ("  reserved = %d", reserved);      SWFDEC_LOG ("  blend_mode = %d", blend_mode);      SWFDEC_LOG ("  has_filters = %d", has_filters);    } else {      reserved = swfdec_bits_getbits (&bits, 4);      blend_mode = 0;      has_filters = 0;      SWFDEC_LOG ("  reserved = %d", reserved);    }    states = swfdec_bits_getbits (&bits, 4);    character = swfdec_bits_get_u16 (&bits);    depth = swfdec_bits_get_u16 (&bits);    SWFDEC_LOG ("  states: %s%s%s%scharacter=%u layer=%u",        states & (1 << SWFDEC_BUTTON_HIT) ? "HIT " : "", 	states & (1 << SWFDEC_BUTTON_DOWN) ? "DOWN " : "",         states & (1 << SWFDEC_BUTTON_OVER) ? "OVER " : "",	states & (1 << SWFDEC_BUTTON_UP) ? "UP " : "", 	character, depth);    content = swfdec_content_new (depth);    swfdec_bits_get_matrix (&bits, &content->transform, NULL);    content->has_transform = TRUE;    SWFDEC_LOG ("matrix: %g %g  %g %g   %g %g",	content->transform.xx, content->transform.yy, 	content->transform.xy, content->transform.yx,	content->transform.x0, content->transform.y0);    swfdec_bits_get_color_transform (&bits, &content->color_transform);    content->has_color_transform = TRUE;    content->graphic = swfdec_swf_decoder_get_character (s, character);    if (blend_mode) {      guint mode = swfdec_bits_get_u8 (&bits);      SWFDEC_WARNING ("  blend mode = %u", mode);    }    if (has_filters)      swfdec_filters_parse (&bits);    if (!SWFDEC_IS_GRAPHIC (content->graphic)) {      SWFDEC_ERROR ("id %u does not reference a graphic, ignoring", character);      swfdec_content_free (content);    } else {      swfdec_button_append_content (button, states, content);    }  }  swfdec_bits_get_u8 (&bits);  if (swfdec_bits_left (&bits)) {    SWFDEC_WARNING ("%u bytes left when parsing button records", swfdec_bits_left (&bits) / 8);  }  script_name = g_strdup_printf ("Button%u", SWFDEC_CHARACTER (button)->id);  while (length != 0) {    guint condition, key;    length = swfdec_bits_get_u16 (&s->b);    if (length)      swfdec_bits_init_bits (&bits, &s->b, length > 2 ? length - 2 : 0);    else      swfdec_bits_init_bits (&bits, &s->b, swfdec_bits_left (&s->b) / 8);    condition = swfdec_bits_get_u16 (&bits);    key = condition >> 9;    condition &= 0x1FF;    SWFDEC_LOG (" length = %d", length);    if (button->events == NULL)      button->events = swfdec_event_list_new (SWFDEC_DECODER (s)->player);    SWFDEC_LOG ("  new event for condition %u (key %u)", condition, key);    swfdec_event_list_parse (button->events, &bits, s->version, condition, key,	script_name);    if (swfdec_bits_left (&bits)) {      SWFDEC_WARNING ("%u bytes left after parsing script", swfdec_bits_left (&bits) / 8);    }  }  g_free (script_name);  return SWFDEC_STATUS_OK;}static inttag_func_define_button (SwfdecSwfDecoder * s, guint tag){  SwfdecBits *bits = &s->b;  int id;  SwfdecButton *button;  char *script_name;  id = swfdec_bits_get_u16 (bits);  button = swfdec_swf_decoder_create_character (s, id, SWFDEC_TYPE_BUTTON);  if (!button)    return SWFDEC_STATUS_OK;  SWFDEC_LOG ("  ID: %d", id);  while (swfdec_bits_peek_u8 (bits)) {    int reserved;    guint character;    guint depth;    guint states;    SwfdecContent *content;    swfdec_bits_syncbits (bits);    reserved = swfdec_bits_getbits (bits, 4);    states = swfdec_bits_getbits (bits, 4);    character = swfdec_bits_get_u16 (bits);    depth = swfdec_bits_get_u16 (bits);    SWFDEC_LOG ("  reserved = %d", reserved);    SWFDEC_LOG ("states: %s%s%s%scharacter=%u layer=%u",        states & (1 << SWFDEC_BUTTON_HIT) ? "HIT " : "", 	states & (1 << SWFDEC_BUTTON_DOWN) ? "DOWN " : "",         states & (1 << SWFDEC_BUTTON_OVER) ? "OVER " : "",	states & (1 << SWFDEC_BUTTON_UP) ? "UP " : "", 	character, depth);    content = swfdec_content_new (depth);    swfdec_bits_get_matrix (bits, &content->transform, NULL);    content->has_transform = TRUE;    SWFDEC_LOG ("matrix: %g %g  %g %g   %g %g",	content->transform.xx, content->transform.yy, 	content->transform.xy, content->transform.yx,	content->transform.x0, content->transform.y0);    content->graphic = swfdec_swf_decoder_get_character (s, character);    if (!SWFDEC_IS_GRAPHIC (content->graphic)) {      SWFDEC_ERROR ("id %u does not reference a graphic, ignoring", character);      swfdec_content_free (content);    } else {      swfdec_button_append_content (button, states, content);    }  }  swfdec_bits_get_u8 (bits);  script_name = g_strdup_printf ("Button%u", SWFDEC_CHARACTER (button)->id);  button->events = swfdec_event_list_new (SWFDEC_DECODER (s)->player);  swfdec_event_list_parse (button->events, &s->b, s->version,       SWFDEC_BUTTON_OVER_UP_TO_OVER_DOWN, 0, script_name);  g_free (script_name);  return SWFDEC_STATUS_OK;}static inttag_func_file_attributes (SwfdecSwfDecoder *s, guint tag){  int has_metadata, use_network;  if (swfdec_bits_getbits (&s->b, 3))    SWFDEC_INFO ("reserved bits (1) aren't 0");  has_metadata = swfdec_bits_getbit (&s->b);  if (swfdec_bits_getbits (&s->b, 3))    SWFDEC_INFO ("reserved bits (2) aren't 0");  use_network = swfdec_bits_getbit (&s->b);  /* FIXME: do something useful with this data */  if (swfdec_bits_getbits (&s->b, 24))    SWFDEC_INFO ("reserved bits (3) aren't 0");  return SWFDEC_STATUS_OK;}static inttag_func_export_assets (SwfdecSwfDecoder * s, guint tag){  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_with_version (bits, s->version);    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;}static inttag_func_do_init_action (SwfdecSwfDecoder * s, guint tag){  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_from_bits (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;}static inttag_func_enqueue (SwfdecSwfDecoder *s, guint tag){  SwfdecBuffer *buffer;  buffer = swfdec_bits_get_buffer (&s->b, -1);  SWFDEC_LOG ("queueing %s tag for sprite %u", swfdec_swf_decoder_get_tag_name (tag),      SWFDEC_CHARACTER (s->parse_sprite)->id);  swfdec_sprite_add_action (s->parse_sprite, tag, buffer);  return SWFDEC_STATUS_OK;}static inttag_func_show_frame (SwfdecSwfDecoder * s, guint tag){  SWFDEC_DEBUG("show_frame %d of id %d", s->parse_sprite->parse_frame,      SWFDEC_CHARACTER (s->parse_sprite)->id);  s->parse_sprite->parse_frame++;  if (s->parse_sprite->parse_frame < s->parse_sprite->n_frames) {    SwfdecSpriteFrame *old = &s->parse_sprite->frames[s->parse_sprite->parse_frame - 1];    SwfdecSpriteFrame *new = &s->parse_sprite->frames[s->parse_sprite->parse_frame];    if (old->sound_head)      new->sound_head = g_object_ref (old->sound_head);  }  tag_func_enqueue (s, tag);  return SWFDEC_STATUS_IMAGE;}static inttag_func_do_action (SwfdecSwfDecoder * s, guint tag){  SwfdecScript *script;  char *name;  name = g_strdup_printf ("Sprite%u_Frame%u", SWFDEC_CHARACTER (s->parse_sprite)->id,      s->parse_sprite->parse_frame);  script = swfdec_script_new_from_bits (&s->b, name, s->version);  g_free (name);  if (script) {    swfdec_swf_decoder_add_script (s, script);    swfdec_sprite_add_action (s->parse_sprite, tag, swfdec_buffer_ref (script->buffer));  }  return SWFDEC_STATUS_OK;}/* may appear inside DefineSprite */#define SPRITE 1struct tag_func_struct{  const char *name;  SwfdecTagFunc func;  int flag;};static struct tag_func_struct tag_funcs[] = {  [SWFDEC_TAG_END] = {"End", tag_func_end, SPRITE},  [SWFDEC_TAG_SHOWFRAME] = {"ShowFrame", tag_func_show_frame, SPRITE},  [SWFDEC_TAG_DEFINESHAPE] = {"DefineShape", tag_define_shape, 0},  [SWFDEC_TAG_FREECHARACTER] = {"FreeCharacter", NULL, 0},  [SWFDEC_TAG_PLACEOBJECT] = {"PlaceObject", NULL, SPRITE},  [SWFDEC_TAG_REMOVEOBJECT] = {"RemoveObject", tag_func_enqueue, SPRITE},  [SWFDEC_TAG_DEFINEBITSJPEG] = {"DefineBitsJPEG", tag_func_define_bits_jpeg, 0},  [SWFDEC_TAG_DEFINEBUTTON] = {"DefineButton", tag_func_define_button, 0},  [SWFDEC_TAG_JPEGTABLES] = {"JPEGTables", swfdec_image_jpegtables, 0},  [SWFDEC_TAG_SETBACKGROUNDCOLOR] =      {"SetBackgroundColor", tag_func_set_background_color, 0},  [SWFDEC_TAG_DEFINEFONT] = {"DefineFont", tag_func_define_font, 0},  [SWFDEC_TAG_DEFINETEXT] = {"DefineText", tag_func_define_text, 0},  [SWFDEC_TAG_DOACTION] = {"DoAction", tag_func_do_action, SPRITE},  [SWFDEC_TAG_DEFINEFONTINFO] = {"DefineFontInfo", tag_func_define_font_info, 0},  [SWFDEC_TAG_DEFINESOUND] = {"DefineSound", tag_func_define_sound, 0},  [SWFDEC_TAG_STARTSOUND] = {"StartSound", tag_func_start_sound, SPRITE},  [SWFDEC_TAG_DEFINEBUTTONSOUND] =      {"DefineButtonSound", tag_func_define_button_sound, 0},  [SWFDEC_TAG_SOUNDSTREAMHEAD] = {"SoundStreamHead", tag_func_sound_stream_head, SPRITE},  [SWFDEC_TAG_SOUNDSTREAMBLOCK] = {"SoundStreamBlock", tag_func_sound_stream_block, SPRITE},  [SWFDEC_TAG_DEFINEBITSLOSSLESS] =      {"DefineBitsLossless", tag_func_define_bits_lossless, 0},  [SWFDEC_TAG_DEFINEBITSJPEG2] = {"DefineBitsJPEG2", tag_func_define_bits_jpeg_2, 0},  [SWFDEC_TAG_DEFINESHAPE2] = {"DefineShape2", tag_define_shape, 0},  [SWFDEC_TAG_DEFINEBUTTONCXFORM] = {"DefineButtonCXForm", NULL, 0},  [SWFDEC_TAG_PROTECT] = {"Protect", tag_func_protect, 0},  [SWFDEC_TAG_PLACEOBJECT2] = {"PlaceObject2", tag_func_enqueue, SPRITE},  [SWFDEC_TAG_REMOVEOBJECT2] = {"RemoveObject2", tag_func_enqueue, SPRITE},  [SWFDEC_TAG_DEFINESHAPE3] = {"DefineShape3", tag_define_shape_3, 0},  [SWFDEC_TAG_DEFINETEXT2] = {"DefineText2", tag_func_define_text, 0},  [SWFDEC_TAG_DEFINEBUTTON2] = {"DefineButton2", tag_func_define_button_2, 0},  [SWFDEC_TAG_DEFINEBITSJPEG3] = {"DefineBitsJPEG3", tag_func_define_bits_jpeg_3, 0},  [SWFDEC_TAG_DEFINEBITSLOSSLESS2] =      {"DefineBitsLossless2", tag_func_define_bits_lossless_2, 0},  [SWFDEC_TAG_DEFINEEDITTEXT] = {"DefineEditText", tag_func_define_edit_text, 0},  [SWFDEC_TAG_DEFINEMOVIE] = {"DefineMovie", NULL, 0},  [SWFDEC_TAG_DEFINESPRITE] = {"DefineSprite", tag_func_define_sprite, 0},  [SWFDEC_TAG_NAMECHARACTER] = {"NameCharacter", NULL, 0},  [SWFDEC_TAG_SERIALNUMBER] = {"SerialNumber", NULL, 0},  [SWFDEC_TAG_GENERATORTEXT] = {"GeneratorText", NULL, 0},  [SWFDEC_TAG_FRAMELABEL] = {"FrameLabel", tag_func_frame_label, SPRITE},  [SWFDEC_TAG_SOUNDSTREAMHEAD2] = {"SoundStreamHead2", tag_func_sound_stream_head, SPRITE},  [SWFDEC_TAG_DEFINEMORPHSHAPE] =      {"DefineMorphShape", tag_define_morph_shape, 0},  [SWFDEC_TAG_DEFINEFONT2] = {"DefineFont2", tag_func_define_font_2, 0},  [SWFDEC_TAG_TEMPLATECOMMAND] = {"TemplateCommand", NULL, 0},  [SWFDEC_TAG_GENERATOR3] = {"Generator3", NULL, 0},  [SWFDEC_TAG_EXTERNALFONT] = {"ExternalFont", NULL, 0},  [SWFDEC_TAG_EXPORTASSETS] = {"ExportAssets", tag_func_export_assets, 0},  [SWFDEC_TAG_IMPORTASSETS] = {"ImportAssets", NULL, 0},  [SWFDEC_TAG_ENABLEDEBUGGER] = {"EnableDebugger", NULL, 0},  [SWFDEC_TAG_DOINITACTION] = {"DoInitAction", tag_func_do_init_action, SPRITE},  [SWFDEC_TAG_DEFINEVIDEOSTREAM] = {"DefineVideoStream", tag_func_define_video, 0},  [SWFDEC_TAG_VIDEOFRAME] = {"VideoFrame", tag_func_video_frame, SPRITE},  [SWFDEC_TAG_DEFINEFONTINFO2] = {"DefineFontInfo2", tag_func_define_font_info, 0},  [SWFDEC_TAG_MX4] = {"MX4", NULL, 0},  [SWFDEC_TAG_ENABLEDEBUGGER2] = {"EnableDebugger2", NULL, 0},  [SWFDEC_TAG_SCRIPTLIMITS] = {"ScriptLimits", NULL, 0},  [SWFDEC_TAG_SETTABINDEX] = {"SetTabIndex", NULL, 0},  [SWFDEC_TAG_FILEATTRIBUTES] = {"FileAttributes", tag_func_file_attributes, 0},  [SWFDEC_TAG_PLACEOBJECT3] = {"PlaceObject3", tag_func_enqueue, SPRITE},  [SWFDEC_TAG_IMPORTASSETS2] = {"ImportAssets2", NULL, 0},  [SWFDEC_TAG_DEFINEFONTALIGNZONES] = {"DefineFontAlignZones", NULL, 0},  [SWFDEC_TAG_CSMTEXTSETTINGS] = {"CSMTextSettings", NULL, 0},  [SWFDEC_TAG_DEFINEFONT3] = {"DefineFont3", tag_func_define_font_3, 0},  [SWFDEC_TAG_AVM2DECL] = {"AVM2Decl", NULL, 0},  [SWFDEC_TAG_METADATA] = {"Metadata", NULL, 0},  [SWFDEC_TAG_DEFINESCALINGGRID] = {"DefineScalingGrid", NULL, 0},  [SWFDEC_TAG_AVM2ACTION] = {"AVM2Action", NULL, 0},  [SWFDEC_TAG_DEFINESHAPE4] = {"DefineShape4", tag_define_shape_4, 0},  [SWFDEC_TAG_DEFINEMORPHSHAPE2] = {"DefineMorphShape2", NULL, 0},};static const int n_tag_funcs = sizeof (tag_funcs) / sizeof (tag_funcs[0]);const char *swfdec_swf_decoder_get_tag_name (int tag){  if (tag >= 0 && tag < n_tag_funcs) {    if (tag_funcs[tag].name) {      return tag_funcs[tag].name;    }  }    return "unknown";}SwfdecTagFuncswfdec_swf_decoder_get_tag_func (int tag){   if (tag >= 0 && tag < n_tag_funcs) {    if (tag_funcs[tag].func) {      return tag_funcs[tag].func;    }  }    return NULL;}intswfdec_swf_decoder_get_tag_flag (int tag){  if (tag >= 0 && tag < n_tag_funcs) {    return tag_funcs[tag].flag;  }    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -