rfxswf-lib:
* modules/swfshape doesn't allow changing to fillstyle 0
- * DataPos should be named DataReadPos, DataSize DataWritePos.
- * bitcount should be named BitWritePos, bitmask BitReadPos
+
if (FAILED(swf_ShapeNew(s))) return -1;
sh = s[0];
- swf_ResetBitmask(t);
+ swf_ResetReadBits(t);
sh->bits.fill = (U16)swf_GetBits(t,4);
sh->bits.line = (U16)swf_GetBits(t,4);
bitl = 0; end = 0; pos = swf_GetTagPos(t);
l = (s->bitlen+7)/8;
if (t)
- { swf_ResetBitcount(t);
+ { swf_ResetWriteBits(t);
swf_SetBits(t,s->bits.fill,4);
swf_SetBits(t,s->bits.line,4);
swf_SetBlock(t,s->data,l);
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
}
return l+1;
}
int swf_SetShapeBits(TAG * t,SHAPE * s)
{ if ((!t)||(!s)) return -1;
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
swf_SetBits(t,s->bits.fill,4);
swf_SetBits(t,s->bits.line,4);
return 0;
int swf_ShapeSetEnd(TAG * t)
{ if (!t) return -1;
swf_SetBits(t,0,6);
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
return 0;
}
int p,i,j;
if ((!t)||(!f)) return -1;
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
swf_SetU16(t,f->id);
p = 0; j = 0;
if (f->glyph[i].shape)
swf_SetSimpleShape(t,f->glyph[i].shape);
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
return 0;
}
int swf_FontSetInfo(TAG * t,SWFFONT * f)
{ int l,i;
if ((!t)||(!f)) return -1;
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
swf_SetU16(t,f->id);
l = strlen(f->name); if (l>255) l = 255;
swf_SetU8(t,l);
swf_SetBits(t,(((U32)font->glyph[s[i]].advance)*scale)/100,abits);
}
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
return 0;
}
return depth;
}
-char* swf_GetTagName(TAG * t)
+char* swf_GetName(TAG * t)
{
char* name = 0;
U32 oldTagPos;
if(flags&PF_RATIO)
swf_GetU16(t);
if(flags&PF_NAME) {
- swf_ResetBitmask(t);
+ swf_ResetReadBits(t);
name = &t->data[swf_GetTagPos(t)];
}
}
-/* old_rfxswf.h\r
-\r
- File which defines macros and typedefs for old versions of\r
- the rfxswf lib functions and datatypes. (For routines which\r
- still use them)\r
-\r
- Part of the swftools package.\r
-\r
- Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>\r
- \r
- This file is distributed under the GPL, see file COPYING for details \r
-\r
-*/\r
-\r
-#include "rfxswf.h"\r
-\r
-/*\r
-#define DataPos dataReadPos\r
-#define DataSize dataWritePos\r
-#define bitcount bitWritePos\r
-#define bitmask bitWritePos\r
-\r
-*/\r
+/* old_rfxswf.h
+
+ File which defines macros and typedefs for old versions of
+ the rfxswf lib functions and datatypes. (For routines which
+ still use them)
+
+ Part of the swftools package.
+
+ Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
+
+ This file is distributed under the GPL, see file COPYING for details
+
+*/
+
+#include "rfxswf.h"
+
+/*
+#define DataPos dataReadPos
+#define DataSize dataWritePos
+#define bitcount bitWritePos
+#define bitmask bitWritePos
+
+*/
// Basic Data Access Functions
-#define swf_ResetBitmask(tag) if (tag->bitmask) { tag->pos++; tag->bitmask = 0; }
-#define swf_ResetBitcount(tag) if (tag->bitcount) { tag->bitcount = 0; }
+#define swf_ResetReadBits(tag) if (tag->readBit) { tag->pos++; tag->readBit = 0; }
+#define swf_ResetWriteBits(tag) if (tag->writeBit) { tag->writeBit = 0; }
-// for future purpose: avoid high level lib functions to change tagpos/bitcount
+// for future purpose: avoid high level lib functions to change tagpos/bitpos
#define swf_SaveTagPos(tag)
#define swf_RestoreTagPos(tag)
void swf_SetTagPos(TAG * t,U32 pos)
-{ swf_ResetBitmask(t);
+{ swf_ResetReadBits(t);
if (pos<=t->len) t->pos = pos;
#ifdef DEBUG_RFXSWF
else fprintf(stderr,"SetTagPos() out of bounds: TagID = %i\n",t->id);
}
U8 swf_GetU8(TAG * t)
-{ swf_ResetBitmask(t);
+{ swf_ResetReadBits(t);
#ifdef DEBUG_RFXSWF
if (t->pos>=t->len)
{ fprintf(stderr,"GetU8() out of bounds: TagID = %i\n",t->id);
U16 swf_GetU16(TAG * t)
{ U16 res;
- swf_ResetBitmask(t);
+ swf_ResetReadBits(t);
#ifdef DEBUG_RFXSWF
if (t->pos>(t->len-2))
{ fprintf(stderr,"GetU16() out of bounds: TagID = %i\n",t->id);
U32 swf_GetU32(TAG * t)
{ U32 res;
- swf_ResetBitmask(t);
+ swf_ResetReadBits(t);
#ifdef DEBUG_RFXSWF
if (t->pos>(t->len-4))
{ fprintf(stderr,"GetU32() out of bounds: TagID = %i\n",t->id);
int swf_GetBlock(TAG * t,U8 * b,int l)
// returns number of bytes written (<=l)
// b = NULL -> skip data
-{ swf_ResetBitmask(t);
+{ swf_ResetReadBits(t);
if ((t->len-t->pos)<l) l=t->len-t->pos;
if (b && l) memcpy(b,&t->data[t->pos],l);
t->pos+=l;
int swf_SetBlock(TAG * t,U8 * b,int l)
// Appends Block to the end of Tagdata, returns size
{ U32 newlen = t->len + l;
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
if (newlen>t->memsize)
{ U32 newmem = MEMSIZE(newlen);
U8 * newdata = (U8*)((t->data)?realloc(t->data,newmem):malloc(newmem));
}
int swf_SetU8(TAG * t,U8 v)
-{ swf_ResetBitcount(t);
+{ swf_ResetWriteBits(t);
if ((t->len+1)>t->memsize) return (swf_SetBlock(t,&v,1)==1)?0:-1;
t->data[t->len++] = v;
return 0;
a[0] = v&0xff;
a[1] = v>>8;
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
if ((t->len+2)>t->memsize) return (swf_SetBlock(t,a,2)==2)?0:-1;
t->data[t->len++] = a[0];
t->data[t->len++] = a[1];
a[2] = (v>>16)&0xff;
a[3] = (v>>24)&0xff;
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
if ((t->len+4)>t->memsize) return (swf_SetBlock(t,a,4)==4)?0:-1;
t->data[t->len++] = a[0];
t->data[t->len++] = a[1];
U32 swf_GetBits(TAG * t,int nbits)
{ U32 res = 0;
if (!nbits) return 0;
- if (!t->bitmask) t->bitmask = 0x80;
+ if (!t->readBit) t->readBit = 0x80;
while (nbits)
{ res<<=1;
- if (t->data[t->pos]&t->bitmask) res|=1;
- t->bitmask>>=1;
+ if (t->data[t->pos]&t->readBit) res|=1;
+ t->readBit>>=1;
nbits--;
- if (!t->bitmask)
- { if (nbits) t->bitmask = 0x80;
+ 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);
{ U32 bm = 1<<(nbits-1);
while (nbits)
- { if (!t->bitcount)
+ { if (!t->writeBit)
{ if (FAILED(swf_SetU8(t,0))) return -1;
- t->bitcount = 0x80;
+ t->writeBit = 0x80;
}
- if (v&bm) t->data[t->len-1] |= t->bitcount;
+ if (v&bm) t->data[t->len-1] |= t->writeBit;
bm>>=1;
- t->bitcount>>=1;
+ t->writeBit>>=1;
nbits--;
}
return 0;
return -1;
}
- swf_ResetBitmask(t);
+ swf_ResetReadBits(t);
if (swf_GetBits(t,1))
{ nbits = swf_GetBits(t,5);
ma.tx = ma.ty = 0;
}
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
if ((m->sx==0x10000)&&(m->sy==0x10000)) swf_SetBits(t,0,1);
else
if (!t) return 0;
- swf_ResetBitmask(t);
+ swf_ResetReadBits(t);
hasadd = swf_GetBits(t,1);
hasmul = swf_GetBits(t,1);
nbits = swf_GetBits(t,4);
nbits = swf_CountBits((S32)cx->b1,nbits);
}
- swf_ResetBitcount(t);
+ swf_ResetWriteBits(t);
swf_SetBits(t,hasadd?1:0,1);
swf_SetBits(t,hasmul?1:0,1);
swf_SetBits(t,nbits,4);
if (t)
{ memset(t,0x00,sizeof(TAG));
t->id = id;
- t->bitcount = 0x80;
+ t->writeBit = 0x80;
if (after)
{ t->frame = after->frame;
typedef struct _TAG // NEVER access a Tag-Struct directly !
{ U16 id;
- U32 len;
U8 * data;
+ U32 memsize; // to minimize realloc() calls
+
+ union
+ { U32 len; // for Set-Access
+ U32 dataWritePos;
+ };
+
+ union
+ { U32 pos; // for Get-Access
+ U32 dataReadPos;
+ };
- int frame;
+ int frame; // not really up-to-date
struct _TAG * next;
struct _TAG * prev;
- U32 memsize; // to minimize realloc() calls
- U32 pos; // for Get/Set-Access
- U8 bitmask; // for Bit-Manipulating Functions [read]
- U8 bitcount; // [write]
+ U8 readBit; // for Bit-Manipulating Functions [read]
+ U8 writeBit; // [write]
+
} TAG, * LPTAG;
typedef struct _ActionTAG
U16 swf_GetDefineID(TAG * t);
U16 swf_GetPlaceID(TAG * t); //PLACEOBJECT, PLACEOBJECT2 (sometimes), REMOVEOBJECT
U16 swf_GetDepth(TAG * t); //PLACEOBJECT,PLACEOBJECT2,REMOVEOBJECT,REMOVEOBJECT2
-char* swf_GetTagName(TAG * t); //PLACEOBJECT2, FRAMELABEL
+char* swf_GetName(TAG * t); //PLACEOBJECT2, FRAMELABEL
MATRIX * swf_MatrixJoin(MATRIX * d,MATRIX * s1,MATRIX * s2);
MATRIX * swf_MatrixMapTriangle(MATRIX * m,int dx,int dy,
int x0,int y0,int x1,int y1,int x2,int y2);
}
if(charstorepos && pass==1)
{
- tag->bitcount = 0;
+ tag->writeBit = 0; // Q&D
swf_SetBits(tag, 0, 1); // GLYPH Record
swf_SetBits(tag, charstorepos, 7); // number of glyphs
int s;
if(lastfontid != chardata[t].fontid || lastsize != chardata[t].size)
newfont = &font;
- tag->bitcount = 0;
+ tag->writeBit = 0; // Q&D
swf_TextSetInfoRecord(tag, newfont, chardata[t].size, newcolor, newx,newy);
}
int args_callback_option(char*name,char*val)
{
if(!strcmp(name, "V")) {
- printf("swfdump - part of %s %s\n", PACKAGE, VERSION);
- exit(0);
+ printf("swfdump - part of %s %s\n", PACKAGE, VERSION);
+ exit(0);
}
else if(name[0]=='a') {
- action = 1;
- return 0;
+ action = 1;
+ return 0;
}
else {
- printf("Unknown option: -%s\n", name);
+ printf("Unknown option: -%s\n", name);
}
return 0;
int args_callback_command(char*name,char*val)
{
if(filename) {
- fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
- filename, name);
+ fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
+ filename, name);
}
filename = name;
return 0;
if(!filename)
{
- fprintf(stderr, "You must supply a filename.\n");
- return 1;
+ fprintf(stderr, "You must supply a filename.\n");
+ return 1;
}
f = open(filename,O_RDONLY);
if (f<0)
{
- perror("Couldn't open file: ");
- exit(1);
+ perror("Couldn't open file: ");
+ exit(1);
}
if FAILED(swf_ReadSWF(f,&swf))
{
- fprintf(stderr, "%s is not a valid SWF file or contains errors.\n",filename);
+ fprintf(stderr, "%s is not a valid SWF file or contains errors.\n",filename);
close(f);
- exit(1);
+ exit(1);
}
#ifdef HAVE_STAT
fstat(f, &statbuf);
if(statbuf.st_size != swf.FileSize)
- fprintf(stderr, "Error: Real Filesize (%d) doesn't match header Filesize (%d)",
- statbuf.st_size, swf.FileSize);
+ fprintf(stderr, "Error: Real Filesize (%d) doesn't match header Filesize (%d)",
+ statbuf.st_size, swf.FileSize);
#endif
close(f);
tag = swf.firstTag;
while(tag) {
- char*name = swf_GetTagName(tag);
- if(!name) {
- fprintf(stderr, "Error: Unknown tag:0x%03x\n", tag->id);
- tag = tag->next;
- continue;
- }
- printf("[%03x] %9ld %s%s", tag->id, tag->len, prefix, swf_GetTagName(tag));
-
- if(swf_isDefiningTag(tag)) {
- U16 id = swf_GetDefineID(tag);
- printf(" defines id %04x", id);
- if(idtab[id])
- fprintf(stderr, "Error: Id %04x is defined more than once.\n", id);
- idtab[id] = 1;
- }
- else if(tag->id == ST_PLACEOBJECT ||
- tag->id == ST_PLACEOBJECT2) {
- printf(" places id %04x at depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
- if(swf_TagGetName(tag))
- printf(" name \"%s\"",swf_TagGetName(tag));
+ char*name = swf_TagGetName(tag);
+ if(!name) {
+ fprintf(stderr, "Error: Unknown tag:0x%03x\n", tag->id);
+ tag = tag->next;
+ continue;
}
- else if(tag->id == ST_REMOVEOBJECT) {
- printf(" removes id %04x from depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
- }
- else if(tag->id == ST_REMOVEOBJECT2) {
- printf(" removes object from depth %04x", swf_GetDepth(tag));
- }
-
- printf("\n");
-
- if(tag->id == ST_DEFINESPRITE) {
- sprintf(prefix, " ");
- }
- else if(tag->id == ST_END) {
- *prefix = 0;
- }
- else if(tag->id == ST_DOACTION && action) {
- char myprefix[128];
- ActionTAG*actions;
- sprintf(myprefix, " %s", prefix);
-
- actions = swf_GetActions(tag);
-
- swf_DumpActions(actions, myprefix);
-
-/* what = "URL";
- ActionEnumerateURLs(actions, testfunc);
- what = "String";
- ActionEnumerateStrings(actions, testfunc);
- what = "Target";
- ActionEnumerateTargets(actions, testfunc);*/
- }
- tag = tag->next;
+ printf("[%03x] %9ld %s%s", tag->id, tag->len, prefix, swf_TagGetName(tag));
+
+ if(swf_isDefiningTag(tag)) {
+ U16 id = swf_GetDefineID(tag);
+ printf(" defines id %04x", id);
+ if(idtab[id])
+ fprintf(stderr, "Error: Id %04x is defined more than once.\n", id);
+ idtab[id] = 1;
+ }
+ else if(tag->id == ST_PLACEOBJECT ||
+ tag->id == ST_PLACEOBJECT2) {
+ printf(" places id %04x at depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
+ if(swf_GetName(tag))
+ printf(" name \"%s\"",swf_GetName(tag));
+ }
+ else if(tag->id == ST_REMOVEOBJECT) {
+ printf(" removes id %04x from depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
+ }
+ else if(tag->id == ST_REMOVEOBJECT2) {
+ printf(" removes object from depth %04x", swf_GetDepth(tag));
+ }
+
+ printf("\n");
+
+ if(tag->id == ST_DEFINESPRITE) {
+ sprintf(prefix, " ");
+ }
+ else if(tag->id == ST_END) {
+ *prefix = 0;
+ }
+ else if(tag->id == ST_DOACTION && action) {
+ char myprefix[128];
+ ActionTAG*actions;
+ sprintf(myprefix, " %s", prefix);
+
+ actions = swf_GetActions(tag);
+
+ swf_DumpActions(actions, myprefix);
+
+/* what = "URL";
+ ActionEnumerateURLs(actions, testfunc);
+ what = "String";
+ ActionEnumerateStrings(actions, testfunc);
+ what = "Target";
+ ActionEnumerateTargets(actions, testfunc);*/
+ }
+ tag = tag->next;
}
swf_FreeTags(&swf);