📄 fad.stream.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.stream.c,v 1.18 2006/03/06 04:20:48 wrxzzj Exp $ */#include <sys/mman.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include "fad.types.h"#include "fad.bits.h"#include "fad.dynarray.h"/**include zlib header*/#include "zlib/zlib.h"void fad_stream_init(fad_stream_t* s, dynarray_t* dict) { bits_init(&s->bits); s->err = FAD_ERROR_NONE; if(dict == NULL) { s->dict = calloc(1, sizeof(dynarray_t)); da_init(s->dict, 1024); } else { s->dict = dict; s->dict->ref++; } s->bufbeg = NULL;}void fad_stream_buffer(fad_stream_t* s, u8_t* buffer) { s->bufbeg = buffer; bits_buffer(&s->bits, buffer);}void fad_stream_stdio(fad_stream_t* s, FILE* infile) { u32_t size; s32_t is_zstream= 0; struct stat info; u8_t *buff = NULL, *ptr = NULL; fstat(fileno(infile), &info); ptr = buff = mmap(NULL, info.st_size, PROT_READ, MAP_PRIVATE, fileno(infile), 0); if(memcmp(ptr, "CWS", 3) == 0) { is_zstream = 1; } else if(memcmp(ptr, "FWS", 3) != 0) { s->err = FAD_ERROR_FORMAT; FAD_ERROR("invalid swf file format.\n"); return; } s->version = *(ptr+3); size = *(ptr+7)<<24|*(ptr+6)<<16|*(ptr+5)<<8|*(ptr+4); size -= 8; ptr += 8; FAD_DEBUG("compress = %d, version = %d, file size = %d Byte, file length = %d Byte\n", is_zstream, s->version, size, info.st_size); s->bufbeg = calloc(1, size); if(is_zstream) { int ret = 0; if((ret = uncompress(s->bufbeg, (unsigned long *)&size, ptr, info.st_size-8)) != Z_OK) s->err = FAD_ERROR_ZLIB; FAD_DEBUG("uncompressed data size = %d Byte, ret = %x\n", size, ret); } else memcpy(s->bufbeg, ptr, size); munmap(buff, info.st_size); if(s->err == FAD_ERROR_NONE) bits_buffer(&s->bits, s->bufbeg);}void fad_stream_finish(fad_stream_t* s) { u16_t idx = 0, count = s->dict->count; fad_object_t* fo = NULL; while(idx < s->dict->total && count > 0) { fo = (fad_object_t* )s->dict->get(s->dict, idx++); if(fo == NULL) continue; count--; if(fo->do_free) fo->do_free(fo); free(fo); } bits_finish(&s->bits); if(s->dict) { s->dict->ref--; if(s->dict->ref == 0) free(s->dict); } if(s->bufbeg) free(s->bufbeg);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -