From 2bf2c4710c77705c21790b70a7a943456f1ced07 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Tue, 2 Mar 2010 13:42:38 -0800 Subject: [PATCH] renamed SWAP/REVERSESWAP to {LE,BE}_TO_NATIVE --- lib/modules/swfaction.c | 10 +++++----- lib/rfxswf.c | 10 +++++----- lib/types.h | 16 ++++++++-------- src/png2swf.c | 8 ++++---- src/swfextract.c | 4 ++-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/modules/swfaction.c b/lib/modules/swfaction.c index fb7474d..3d701bb 100644 --- a/lib/modules/swfaction.c +++ b/lib/modules/swfaction.c @@ -834,7 +834,7 @@ void action_fixjump(ActionMarker m1, ActionMarker m2) if (a1->op == ACTION_IF || a1->op == ACTION_JUMP) { - *(U16*)(a1->data) = SWAP16(len); + *(U16*)(a1->data) = LE_16_TO_NATIVE(len); } else if(a1->op == ACTION_WAITFORFRAME) { @@ -924,20 +924,20 @@ ActionTAG* action_End(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_END, ActionTAG* action_GotoFrame(ActionTAG*atag, U16 frame) { atag = swf_AddActionTAG(atag, ACTION_GOTOFRAME, 0, 2); - *(U16*)atag->tmp = SWAP16(frame); + *(U16*)atag->tmp = LE_16_TO_NATIVE(frame); return atag; } ActionTAG* action_Jump(ActionTAG*atag, U16 branch) { atag = swf_AddActionTAG(atag, ACTION_JUMP, 0, 2); - *(U16*)atag->tmp = SWAP16(branch); + *(U16*)atag->tmp = LE_16_TO_NATIVE(branch); return atag; } ActionTAG* action_If(ActionTAG*atag, U16 branch) { atag = swf_AddActionTAG(atag, ACTION_IF, 0, 2); - *(U16*)atag->tmp = SWAP16(branch); + *(U16*)atag->tmp = LE_16_TO_NATIVE(branch); return atag; } ActionTAG* action_StoreRegister(ActionTAG*atag, U8 reg) @@ -967,7 +967,7 @@ ActionTAG* action_WaitForFrame2(ActionTAG*atag, U8 skip) ActionTAG* action_WaitForFrame(ActionTAG*atag, U16 frame, U8 skip) { atag = swf_AddActionTAG(atag, ACTION_WAITFORFRAME, 0, 3); - *(U16*)atag->tmp = SWAP16(frame); + *(U16*)atag->tmp = LE_16_TO_NATIVE(frame); *(U8*)&atag->tmp[2] = skip; return atag; } diff --git a/lib/rfxswf.c b/lib/rfxswf.c index 278e504..6570847 100644 --- a/lib/rfxswf.c +++ b/lib/rfxswf.c @@ -1179,7 +1179,7 @@ TAG * swf_ReadTag(reader_t*reader, TAG * prev) int id; if (reader->read(reader, &raw, 2) !=2 ) return NULL; - raw = SWAP16(raw); + raw = LE_16_TO_NATIVE(raw); len = raw&0x3f; id = raw>>6; @@ -1243,7 +1243,7 @@ int swf_WriteTag2(writer_t*writer, TAG * t) #endif if (short_tag) - { raw[0] = SWAP16(len|((t->id&0x3ff)<<6)); + { raw[0] = LE_16_TO_NATIVE(len|((t->id&0x3ff)<<6)); if (writer->write(writer,raw,2)!=2) { #ifdef DEBUG_RFXSWF @@ -1254,7 +1254,7 @@ int swf_WriteTag2(writer_t*writer, TAG * t) } else { - raw[0] = SWAP16((t->id<<6)|0x3f); + raw[0] = LE_16_TO_NATIVE((t->id<<6)|0x3f); if (writer->write(writer,raw,2)!=2) { #ifdef DEBUG_RFXSWF @@ -1559,9 +1559,9 @@ int swf_ReadSWF2(reader_t*reader, SWF * swf) // Reads SWF to memory (malloc'ed reader_GetRect(reader, &swf->movieSize); reader->read(reader, &swf->frameRate, 2); - swf->frameRate = SWAP16(swf->frameRate); + swf->frameRate = LE_16_TO_NATIVE(swf->frameRate); reader->read(reader, &swf->frameCount, 2); - swf->frameCount = SWAP16(swf->frameCount); + swf->frameCount = LE_16_TO_NATIVE(swf->frameCount); /* read tags and connect to list */ t1.next = 0; diff --git a/lib/types.h b/lib/types.h index 6af6ab7..02fe287 100644 --- a/lib/types.h +++ b/lib/types.h @@ -19,15 +19,15 @@ #define GET32(ptr) (((U16)(((U8*)(ptr))[0]))+(((U16)(((U8*)(ptr))[1]))<<8)+(((U16)(((U8*)(ptr))[2]))<<16)+(((U16)(((U8*)(ptr))[3]))<<24)) #ifdef WORDS_BIGENDIAN -#define SWAP16(s) ((((s)>>8)&0x00ff)|(((s)<<8)&0xff00)) -#define SWAP32(s) (SWAP16(((s)>>16)&0x0000ffff)|((SWAP16(s)<<16)&0xffff0000)) -#define REVERSESWAP16(x) (x) -#define REVERSESWAP32(x) (x) +#define LE_16_TO_NATIVE(s) ((((s)>>8)&0x00ff)|(((s)<<8)&0xff00)) +#define LE_32_TO_NATIVE(s) (LE_16_TO_NATIVE(((s)>>16)&0x0000ffff)|((LE_16_TO_NATIVE(s)<<16)&0xffff0000)) +#define BE_16_TO_NATIVE(x) (x) +#define BE_32_TO_NATIVE(x) (x) #else -#define SWAP16(x) (x) -#define SWAP32(x) (x) -#define REVERSESWAP16(s) ((((s)>>8)&0x00ff)|(((s)<<8)&0xff00)) -#define REVERSESWAP32(s) (REVERSESWAP16(((s)>>16)&0x0000ffff)|((REVERSESWAP16(s)<<16)&0xffff0000)) +#define LE_16_TO_NATIVE(x) (x) +#define LE_32_TO_NATIVE(x) (x) +#define BE_16_TO_NATIVE(s) ((((s)>>8)&0x00ff)|(((s)<<8)&0xff00)) +#define BE_32_TO_NATIVE(s) (BE_16_TO_NATIVE(((s)>>16)&0x0000ffff)|((BE_16_TO_NATIVE(s)<<16)&0xffff0000)) #endif // SWF Types diff --git a/src/png2swf.c b/src/png2swf.c index 91f2188..05366fc 100644 --- a/src/png2swf.c +++ b/src/png2swf.c @@ -119,7 +119,7 @@ int png_read_chunk(char (*head)[4], int*destlen, U8**destdata, FILE*fi) return 0; if(!fread(head, 4, 1, fi)) return 0; - len = REVERSESWAP32(len); + len = BE_32_TO_NATIVE(len); if(destlen) *destlen = len; if(destdata) { if(len) @@ -143,7 +143,7 @@ unsigned int png_get_dword(FILE*fi) { unsigned int a; fread(&a,4,1,fi); - return REVERSESWAP32(a); + return BE_32_TO_NATIVE(a); } struct png_header @@ -173,8 +173,8 @@ int png_read_header(FILE*fi, struct png_header*header) if(!strncasecmp(id, "IHDR", 4)) { char a,b,c,f,i; if(len < 8) exit(1); - header->width = REVERSESWAP32(*(U32*)&data[0]); - header->height = REVERSESWAP32(*(U32*)&data[4]); + header->width = BE_32_TO_NATIVE(*(U32*)&data[0]); + header->height = BE_32_TO_NATIVE(*(U32*)&data[4]); a = data[8]; // should be 8 b = data[9]; // should be 3(indexed), 2(rgb), 0(grayscale) or 6(truecolor+alpha) diff --git a/src/swfextract.c b/src/swfextract.c index 79ebf05..a162e45 100644 --- a/src/swfextract.c +++ b/src/swfextract.c @@ -771,7 +771,7 @@ static inline void png_write_byte(FILE*fi, U8 byte) static void png_start_chunk(FILE*fi, char*type, int len) { U8 mytype[4]={0,0,0,0}; - U32 mylen = REVERSESWAP32(len); + U32 mylen = BE_32_TO_NATIVE(len); memcpy(mytype,type,strlen(type)); fwrite(&mylen, 4, 1, fi); mycrc32=0xffffffff; @@ -795,7 +795,7 @@ static void png_write_dword(FILE*fi, U32 dword) } static void png_end_chunk(FILE*fi) { - U32 tmp = REVERSESWAP32((mycrc32^0xffffffff)); + U32 tmp = BE_32_TO_NATIVE((mycrc32^0xffffffff)); fwrite(&tmp,4,1,fi); } -- 1.7.10.4