if (!t->readBit) t->readBit = 0x80;
while (nbits)
{ res<<=1;
+#ifdef DEBUG_RFXSWF
+ if (t->pos>=t->len)
+ { fprintf(stderr,"GetBits() out of bounds: TagID = %i, pos=%d, len=%d\n",t->id, t->pos, t->len);
+ int i,m=t->len>10?10:t->len;
+ for(i=-1;i<m;i++) {
+ fprintf(stderr, "(%d)%02x ", i, t->data[i]);
+ }
+ fprintf(stderr, "\n");
+ return res;
+ }
+#endif
if (t->data[t->pos]&t->readBit) res|=1;
t->readBit>>=1;
nbits--;
if (!t->readBit)
{ if (nbits) t->readBit = 0x80;
- #ifdef DEBUG_RFXSWF
- if (t->pos>=t->len)
- { fprintf(stderr,"GetBits() out of bounds: TagID = %i\n",t->id);
- return res;
- }
- #endif
t->pos++;
}
}
while(1) {
U8 b = swf_GetU8(tag);
nr++;
- s|=(b&127)<<shift;
+ nt i,m=t->len>10?10:t->len;
+ for(i=0;i<m;i++) {
+ fprintf(stderr, "%02x ", t->data[i]);
+ }
+ fprintf(stderr, "\n");
+ s|=(b&127)<<shift;
shift+=7;
if(!(b&128) || shift>=32) {
if(b&64) {
swf->frameCount = SWAP16(swf->frameCount);
/* read tags and connect to list */
+ t1.next = 0;
t = &t1;
while (t) {
t = swf_ReadTag(reader,t);
}
}
swf->firstTag = t1.next;
- t1.next->prev = NULL;
+ if(t1.next)
+ t1.next->prev = NULL;
}
return reader->pos;
}
+SWF* swf_OpenSWF(char*filename)
+{
+ int fi = open(filename, O_RDONLY|O_BINARY);
+ if(fi<0) {
+ fprintf(stderr, "Failed to open %s\n", filename);
+ return 0;
+ }
+ SWF* swf = rfx_alloc(sizeof(SWF));
+ swf_ReadSWF(fi, swf);
+ close(fi);
+ return swf;
+}
+
int swf_ReadSWF(int handle, SWF * swf)
{
reader_t reader;
t = swf->firstTag;
frameCount = 0;
- len += WriteExtraTags(swf, 0);
+ if(swf->firstTag && !no_extra_tags) {
+ len += WriteExtraTags(swf, 0);
+ }
while(t) {
len += swf_WriteTag(-1,t);
if(t->id == ST_DEFINESPRITE && !swf_IsFolded(t)) inSprite++;
return -1;
}
- if(!no_extra_tags) {
+ if(swf->firstTag && !no_extra_tags) {
WriteExtraTags(swf, writer);
}
t = swf->firstTag;
}
}
+int swf_SaveSWF(SWF * swf, char*filename)
+{
+ int fi = open(filename, O_BINARY|O_RDWR|O_TRUNC|O_CREAT, 0777);
+ if(fi<0) {
+ perror(filename);
+ return 0;
+ }
+ if(swf_WriteSWF(fi, swf)<0) {
+ fprintf(stderr, "Unable to write output file: %s\n", filename);
+ return 0;
+ }
+ close(fi);
+ return 1;
+}
+
int swf_WriteSWF(int handle, SWF * swf) // Writes SWF to file, returns length or <0 if fails
{
writer_t writer;