X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Frfxswf.c;h=6a8d79d01e9f6548dc01ec3c5fb7977410ace2c1;hb=994d5705f3ab0c9c3bb57dcd9fa8bb2a5398de2c;hp=f188d79155093c493b95faec65253cbd69cc1fe7;hpb=50c12abc91e3ad768c1ce858c0edc37fdedb4cac;p=swftools.git diff --git a/lib/rfxswf.c b/lib/rfxswf.c index f188d79..6a8d79d 100644 --- a/lib/rfxswf.c +++ b/lib/rfxswf.c @@ -31,6 +31,8 @@ #endif // HAVE_ZLIB_H #endif // HAVE_LIBZ +#include "./bitio.h" + // internal constants #define MALLOC_SIZE 128 @@ -128,6 +130,7 @@ int swf_SetBlock(TAG * t,U8 * b,int l) { #ifdef DEBUG_RFXSWF fprintf(stderr,"Fatal Error: malloc()/realloc() failed (1). (%d bytes)\n", newmem); + *(int*)0=0; #endif return 0; } @@ -198,9 +201,6 @@ U32 swf_GetBits(TAG * t,int nbits) return res; } -/* reader/writer stuff - from ../src/bitio.c */ -#include "./bitio.c" - S32 swf_GetSBits(TAG * t,int nbits) { U32 res = swf_GetBits(t,nbits); if (res&(1<<(nbits-1))) res|=(0xffffffff<firstTag; - swf->frameCount = 0; + frameCount = 0; while(t) { len += swf_WriteTag(-1, t); - if (t->id==ST_SHOWFRAME) swf->frameCount++; + if (t->id==ST_SHOWFRAME) frameCount++; t = swf_NextTag(t); } @@ -896,9 +897,13 @@ int swf_WriteSWF2(struct writer_t*writer, SWF * swf, bool compress) // Writ swf_SetU16(&t2, swf->frameCount); l = swf_GetTagLen(&t2)+8; } - swf->fileSize = l+len; + + if(len) {// don't touch headers without tags + swf->fileSize = l+len; + swf->frameCount = frameCount; + } - if(compress) { + if(swf->compressed) { char*id = "CWS"; writer->write(writer, id, 3); } @@ -911,7 +916,7 @@ int swf_WriteSWF2(struct writer_t*writer, SWF * swf, bool compress) // Writ PUT32(b4, swf->fileSize); writer->write(writer, b4, 4); - if(compress) { + if(swf->compressed) { writer_init_zlibdeflate(&zwriter, writer); writer = &zwriter; } @@ -947,21 +952,30 @@ int swf_WriteSWF2(struct writer_t*writer, SWF * swf, bool compress) // Writ int swf_WriteSWF(int handle, SWF * swf) // Writes SWF to file, returns length or <0 if fails { struct writer_t writer; + swf->compressed = 0; if(handle<0) - return swf_WriteSWF2(&writer, swf, FALSE); + return swf_WriteSWF2(&writer, swf); writer_init_filewriter(&writer, handle); - return swf_WriteSWF2(&writer, swf, FALSE); + return swf_WriteSWF2(&writer, swf); } int swf_WriteSWC(int handle, SWF * swf) // Writes SWF to file, returns length or <0 if fails { struct writer_t writer; + swf->compressed = 1; if(handle<0) - return swf_WriteSWF2(&writer, swf, TRUE); + return swf_WriteSWF2(&writer, swf); writer_init_filewriter(&writer, handle); - return swf_WriteSWF2(&writer, swf, TRUE); + return swf_WriteSWF2(&writer, swf); } +int swf_WriteHeader2(struct writer_t*writer,SWF * swf) +{ + SWF myswf; + memcpy(&myswf,swf,sizeof(SWF)); + myswf.firstTag = 0; + return swf_WriteSWF2(writer, &myswf); +} int swf_WriteHeader(int handle,SWF * swf) {