git.asbjorn.biz
/
swftools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
removed \t characters. MacOS X has a problem with them.
[swftools.git]
/
lib
/
rfxswf.c
diff --git
a/lib/rfxswf.c
b/lib/rfxswf.c
index
5347ba0
..
9b96235
100644
(file)
--- a/
lib/rfxswf.c
+++ b/
lib/rfxswf.c
@@
-31,6
+31,11
@@
#endif // HAVE_ZLIB_H
#endif // HAVE_LIBZ
#endif // HAVE_ZLIB_H
#endif // HAVE_LIBZ
+#define LAME
+#include "lame/lame.h"
+
+#include "./bitio.h"
+
// internal constants
#define MALLOC_SIZE 128
// internal constants
#define MALLOC_SIZE 128
@@
-128,6
+133,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);
{
#ifdef DEBUG_RFXSWF
fprintf(stderr,"Fatal Error: malloc()/realloc() failed (1). (%d bytes)\n", newmem);
+ *(int*)0=0;
#endif
return 0;
}
#endif
return 0;
}
@@
-198,9
+204,6
@@
U32 swf_GetBits(TAG * t,int nbits)
return res;
}
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<<nbits);
S32 swf_GetSBits(TAG * t,int nbits)
{ U32 res = swf_GetBits(t,nbits);
if (res&(1<<(nbits-1))) res|=(0xffffffff<<nbits);
@@
-347,6
+350,10
@@
int swf_SetRect(TAG * t,SRECT * r)
nbits = swf_CountBits(r->xmax,nbits);
nbits = swf_CountBits(r->ymin,nbits);
nbits = swf_CountBits(r->ymax,nbits);
nbits = swf_CountBits(r->xmax,nbits);
nbits = swf_CountBits(r->ymin,nbits);
nbits = swf_CountBits(r->ymax,nbits);
+ if(nbits>=32) {
+ fprintf(stderr, "rfxswf: Warning: num_bits overflow in swf_SetRect\n");
+ nbits=31;
+ }
swf_SetBits(t,nbits,5);
swf_SetBits(t,r->xmin,nbits);
swf_SetBits(t,nbits,5);
swf_SetBits(t,r->xmin,nbits);
@@
-747,6
+754,10
@@
void swf_FoldSprite(TAG * t)
fprintf(stderr, "Error: Sprite has no ID!");
return;
}
fprintf(stderr, "Error: Sprite has no ID!");
return;
}
+ if(t->len>4) {
+ /* sprite is already folded */
+ return;
+ }
t->pos = 0;
id = swf_GetU16(t);
t->pos = 0;
id = swf_GetU16(t);
@@
-838,7
+849,7
@@
int swf_ReadSWF2(struct reader_t*reader, SWF * swf) // Reads SWF to memory (ma
t1.next->prev = NULL;
}
t1.next->prev = NULL;
}
- return 0;
+ return reader->pos;
}
int swf_ReadSWF(int handle, SWF * swf)
}
int swf_ReadSWF(int handle, SWF * swf)
@@
-848,10
+859,12
@@
int swf_ReadSWF(int handle, SWF * swf)
return swf_ReadSWF2(&reader, swf);
}
return swf_ReadSWF2(&reader, swf);
}
-int swf_WriteSWF2(struct writer_t*writer, SWF * swf, bool compress) // Writes SWF to file, returns length or <0 if fails
+int swf_WriteSWF2(struct writer_t*writer, SWF * swf) // Writes SWF to file, returns length or <0 if fails
{ U32 len;
TAG * t;
{ U32 len;
TAG * t;
+ int frameCount=0;
struct writer_t zwriter;
struct writer_t zwriter;
+ int fileSize = 0;
if (!swf) return -1;
if (!swf) return -1;
@@
-869,11
+882,11
@@
int swf_WriteSWF2(struct writer_t*writer, SWF * swf, bool compress) // Writ
len = 0;
t = swf->firstTag;
len = 0;
t = swf->firstTag;
- swf->frameCount = 0;
+ frameCount = 0;
while(t)
{ len += swf_WriteTag(-1, t);
while(t)
{ len += swf_WriteTag(-1, t);
- if (t->id==ST_SHOWFRAME) swf->frameCount++;
+ if (t->id==ST_SHOWFRAME) frameCount++;
t = swf_NextTag(t);
}
t = swf_NextTag(t);
}
@@
-896,9
+909,14
@@
int swf_WriteSWF2(struct writer_t*writer, SWF * swf, bool compress) // Writ
swf_SetU16(&t2, swf->frameCount);
l = swf_GetTagLen(&t2)+8;
}
swf_SetU16(&t2, swf->frameCount);
l = swf_GetTagLen(&t2)+8;
}
- swf->fileSize = l+len;
+
+ fileSize = l+len;
+ if(len) {// don't touch headers without tags
+ swf->fileSize = fileSize;
+ swf->frameCount = frameCount;
+ }
- if(compress) {
+ if(swf->compressed) {
char*id = "CWS";
writer->write(writer, id, 3);
}
char*id = "CWS";
writer->write(writer, id, 3);
}
@@
-911,7
+929,7
@@
int swf_WriteSWF2(struct writer_t*writer, SWF * swf, bool compress) // Writ
PUT32(b4, swf->fileSize);
writer->write(writer, b4, 4);
PUT32(b4, swf->fileSize);
writer->write(writer, b4, 4);
- if(compress) {
+ if(swf->compressed) {
writer_init_zlibdeflate(&zwriter, writer);
writer = &zwriter;
}
writer_init_zlibdeflate(&zwriter, writer);
writer = &zwriter;
}
@@
-941,35
+959,43
@@
int swf_WriteSWF2(struct writer_t*writer, SWF * swf, bool compress) // Writ
writer->finish(writer); //e.g. flush zlib buffers
}
}
writer->finish(writer); //e.g. flush zlib buffers
}
}
- return (int)swf->fileSize;
+ return (int)fileSize;
}
int swf_WriteSWF(int handle, SWF * swf) // Writes SWF to file, returns length or <0 if fails
{
struct writer_t writer;
}
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)
if(handle<0)
- return swf_WriteSWF2(&writer, swf, FALSE);
+ return swf_WriteSWF2(&writer, swf);
writer_init_filewriter(&writer, handle);
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;
}
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)
if(handle<0)
- return swf_WriteSWF2(&writer, swf, TRUE);
+ return swf_WriteSWF2(&writer, swf);
writer_init_filewriter(&writer, handle);
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)
{
SWF myswf;
memcpy(&myswf,swf,sizeof(SWF));
myswf.firstTag = 0;
int swf_WriteHeader(int handle,SWF * swf)
{
SWF myswf;
memcpy(&myswf,swf,sizeof(SWF));
myswf.firstTag = 0;
- swf_WriteSWF(handle, &myswf);
- return 0;
+ return swf_WriteSWF(handle, &myswf);
}
int swf_WriteCGI(SWF * swf)
}
int swf_WriteCGI(SWF * swf)