From: kramm Date: Sun, 23 Nov 2008 14:00:31 +0000 (+0000) Subject: added as3 data types X-Git-Tag: release-0-9-0~780 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=e742d2207abedb5f1b321b6c17d0d9c8fa31518b added as3 data types --- diff --git a/lib/rfxswf.c b/lib/rfxswf.c index aeb0733..ecc5fd3 100644 --- a/lib/rfxswf.c +++ b/lib/rfxswf.c @@ -94,6 +94,7 @@ U8 swf_GetU8(TAG * t) #ifdef DEBUG_RFXSWF if (t->pos>=t->len) { fprintf(stderr,"GetU8() out of bounds: TagID = %i\n",t->id); + *(int*)0=0; return 0; } #endif @@ -277,6 +278,144 @@ void swf_SetFixed8(TAG * t, float f) swf_SetU8(t, fr); swf_SetU8(t, (U8)f - (f<0 && fr!=0)); } +int swf_GetU30(TAG*tag) +{ + U32 shift = 0; + U32 s = 0; + while(1) { + U8 b = swf_GetU8(tag); + s|=(b&127)<len; + while(1) { + U8 val = s&0x7f; + U8 vsign = s&0x80; + s>>=7; + neg>>=7; + if(s==neg && vsign==sign) { + /* if the value we just wrote has the same sign as s + and all the remaining bits are equal to the sign of s + too, stop writing */ + if(tag) + swf_SetU8(tag, val); + nr++; + break; + } else { + if(tag) + swf_SetU8(tag, 0x80 | val); + nr++; + } + }; + return nr; + +} +int swf_SetU30(TAG*tag, U32 u) +{ + int nr = 0; + do { + if(tag) + swf_SetU8(tag, (u&~0x7f?0x80:0) | (u&0x7F)); + u>>=7; + nr++; + } while(u); + return nr; +} +int swf_SetU30String(TAG*tag, const char*str) +{ + int l = strlen(str); + int len=0; + len+=swf_SetU30(tag, l); + len+=l; + swf_SetBlock(tag, (void*)str, l); + return len; +} +double swf_GetD64(TAG*tag) +{ + /* FIXME: this is not big-endian compatible */ + double value = *(double*)&tag->data[tag->pos]; + swf_GetU32(tag); + swf_GetU32(tag); + return value; +} +int swf_SetD64(TAG*tag, double v) +{ + /* FIXME: this is not big-endian compatible */ + swf_SetU32(tag, ((U32*)&v)[0]); + swf_SetU32(tag, ((U32*)&v)[1]); + return 8; +} +int swf_GetU24(TAG*tag) +{ + int b1 = swf_GetU8(tag); + int b2 = swf_GetU8(tag); + int b3 = swf_GetU8(tag); + return b3<<16|b2<<8|b1; +} +int swf_GetS24(TAG*tag) +{ + int b1 = swf_GetU8(tag); + int b2 = swf_GetU8(tag); + int b3 = swf_GetU8(tag); + if(b3&0x80) { + return -1-((b3<<16|b2<<8|b1)^0xffffff); + } else { + return b3<<16|b2<<8|b1; + } +} +int swf_SetU24(TAG*tag, U32 v) +{ + if(tag) { + if(v&0xff000000) + fprintf(stderr, "Error: Overflow in swf_SetU24()\n"); + swf_SetU8(tag, v); + swf_SetU8(tag, v>>8); + swf_SetU8(tag, v>>16); + } + return 3; +} +int swf_SetS24(TAG*tag, U32 v) +{ + if(tag) { + if(!(v&0xff000000)) + return swf_SetU24(tag, v); + if((v&0xff000000)!=0xff000000) { + fprintf(stderr, "Error: Overflow in swf_SetS24()\n"); + } + swf_SetU8(tag, v); + swf_SetU8(tag, v>>8); + swf_SetU8(tag, v>>16); + } + return 3; +} + int swf_SetRGB(TAG * t,RGBA * col) { if (!t) return -1; @@ -762,6 +901,15 @@ void swf_SetPassword(TAG * t, const char * password) swf_SetU16(t,0); swf_SetString(t, (U8*)md5string); +} + +void swf_SetString(TAG*t, const char* s) +{ + if(!s) { + swf_SetU8(t, 0); + } else { + swf_SetBlock(t,s,strlen(s)+1); + } } int swf_VerifyPassword(TAG * t, const char * password) diff --git a/lib/rfxswf.h b/lib/rfxswf.h index 727147e..97b677d 100644 --- a/lib/rfxswf.h +++ b/lib/rfxswf.h @@ -232,7 +232,20 @@ int swf_SetU8(TAG * t,U8 v); // resets Bitcount int swf_SetU16(TAG * t,U16 v); void swf_SetS16(TAG * t,int v); int swf_SetU32(TAG * t,U32 v); -#define swf_SetString(t,s) swf_SetBlock(t,s,strlen((const char *)s)+1) +void swf_SetString(TAG*t,const char*s); + +double swf_GetD64(TAG*tag); + +int swf_SetU30String(TAG*tag, const char*str); +int swf_SetD64(TAG*tag, double v); +int swf_SetU30(TAG*tag, U32 u); +int swf_SetS30(TAG*tag, S32 s); +int swf_GetU24(TAG*tag); +int swf_GetS24(TAG*tag); +int swf_SetU24(TAG*tag, U32 v); +int swf_SetS24(TAG*tag, U32 v); +int swf_GetS30(TAG*tag); +int swf_GetU30(TAG*tag); //int swf_GetPoint(TAG * t,SPOINT * p); // resets Bitcount int swf_GetRect(TAG * t,SRECT * r); @@ -599,7 +612,7 @@ void swf_FontAddLayout(SWFFONT * f, int ascent, int descent, int leading); int swf_ParseDefineText(TAG * t, void(*callback)(void*self, int*chars, int*xpos, int nr, int fontid, int fontsize, int xstart, int ystart, RGBA* color), void*self); void swf_WriteFont(SWFFONT* font, char* filename); -SWFFONT* swf_ReadFont(char* filename); +SWFFONT* swf_ReadFont(const char* filename); void swf_FontFree(SWFFONT * f); @@ -727,7 +740,9 @@ void swf_uncgi(); // same behaviour as Steven Grimm's uncgi-library // as3/abc.c void*swf_ReadABC(TAG*tag); +void*swf_DumpABC(FILE*fo, void*code, char*prefix); void swf_WriteABC(TAG*tag, void*code); +void swf_FreeABC(void*code); void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events); // swfaction.c