}
void reader_input2(struct reader_t*r, void*target)
{
- *(u16*)target = SWAP16(*(u16*)&r->data[r->datapos]);
+ *(u16*)target = GET16(&r->data[r->datapos]);
r->datapos += 2;
}
void reader_input4(struct reader_t*r, void*target)
{
- *(u32*)target = SWAP32(*(u32*)&r->data[r->datapos]);
+ *(u32*)target = GET32(&r->data[r->datapos]);
r->datapos += 4;
}
uchar*reader_getinputpos(struct reader_t*r)
#define __bitio_h__
#include "types.h"
+#include "../lib/rfxswf.h"
struct reader_t {
u8* data;
{
/* fucking big endian byte order */
if(tag->id == TAGID_PLACEOBJECT)
- (*(u16*)&tag->data[2]) =
- SWAP16(SWAP16(*(u16*)&tag->data[2]) + add);
+ PUT16(&tag->data[2],GET16(&tag->data[2])+add);
if(tag->id == TAGID_PLACEOBJECT2)
- (*(u16*)&tag->data[1]) =
- SWAP16(SWAP16(*(u16*)&tag->data[1]) + add);
+ PUT16(&tag->data[1],GET16(&tag->data[1])+add);
if(tag->id == TAGID_REMOVEOBJECT)
- (*(u16*)&tag->data[2]) =
- SWAP16(SWAP16(*(u16*)&tag->data[2]) + add);
+ PUT16(&tag->data[2],GET16(&tag->data[2])+add);
if(tag->id == TAGID_REMOVEOBJECT2)
- (*(u16*)&tag->data[0]) =
- SWAP16(SWAP16(*(u16*)&tag->data[0]) + add);
+ PUT16(&tag->data[0],GET16(&tag->data[0])+add);
}
void jpeg_assert()
}
while(slave.tags[pos++].id != TAGID_END);
- *tagidpos = SWAP32((u8*)writer_getpos(w) - startpos); // set length of sprite (in header)
- logf("<verbose> sprite length is %d",SWAP32(*tagidpos));
+ PUT32(tagidpos, (u8*)writer_getpos(w) - startpos); // set length of sprite (in header)
+ logf("<verbose> sprite length is %d",GET32(tagidpos));
}
static char tag_ok_for_slave(int id)
{
if(config.overlay)
{
- *(u16*)master.tags[pos].data = SWAP16(replaceddefine);
+ PUT16(master.tags[pos].data, replaceddefine);
writer_write(w, master.tags[pos].fulldata, master.tags[pos].fulllength);
} else {
/* don't write this tag */
if(config.clip) {
logf("<fatal> Can't combine --clip and --frame");
}
- *(u16*)&data[0] = SWAP16((u16)(TAGID_PLACEOBJECT2<<6) + 5);
+ PUT16(&data[0], (u16)(TAGID_PLACEOBJECT2<<6) + 5);
*(u8*)&data[2]= 2; //flags: id
- *(u16*)&data[3]= SWAP16(depth); // depth
- *(u16*)&data[5]= SWAP16(id);
+ PUT16(&data[3], depth);
+ PUT16(&data[5], id);
write_sprite_defines(w);
write_sprite(w, id, -1);
writer_write(w,data,7);
{
char data[16];
int len;
- *(u16*)(&data[0]) = SWAP16((TAGID_REMOVEOBJECT2<<6) + 2);
- *(u16*)(&data[2]) = SWAP16(t);
+ PUT16(&data[0], (TAGID_REMOVEOBJECT2<<6) + 2);
+ PUT16(&data[2], t);
writer_write(&w, data, 4);
}
free(depths);
tmp32 = (u8*)writer_getpos(&w) - (u8*)newdata; //length
*newlength = tmp32;
- *headlength = SWAP32(tmp32); // set the header to the correct length
+ PUT32(headlength, tmp32); // set the header to the correct length
return newdata; //length
}
tmp32 = (u8*)writer_getpos(&w) - (u8*)newdata; //length
*newlength = tmp32;
- *headlength = SWAP32(tmp32); // set the header to the correct length
+ PUT32(headlength, tmp32);
return newdata; //length
}
struct swf_tag
{
- u8 id;
+ u16 id;
u32 length;
u8*data;
u32 fulllength; // includes id
void maponeid(void*idpos)
{
u16*idptr = (u16*)idpos;
- if(slaveids[SWAP16(*idptr)]<0) {
- logf("<error> Trying to map id never encountered before: id=%d", SWAP16(*idptr));
+ U16 id = GET16(idptr);
+ if(slaveids[id]<0) {
+ logf("<error> Trying to map id never encountered before: id=%d", id);
return ;
}
- logf("<debug> mapping %d to %d", SWAP16(*idptr), slaveids[SWAP16(*idptr)]);
- *idptr = SWAP16(slaveids[*idptr]);
+ logf("<debug> mapping %d to %d", id, slaveids[id]);
+ PUT16(idptr, slaveids[id]);
}
u16 charid;
if(!reader_readu8(&reader)) //flags
break;
- charid = SWAP16(*(u16*)reader_getinputpos(&reader));
+ charid = GET16(reader_getinputpos(&reader));
callback(reader_getinputpos(&reader));
reader_readu16(&reader); //char
reader_readu16(&reader); //layer
pos += sizeof(head);
*pos++ = fileversion;
fixpos = (u32*)pos;
- *(u32*)pos = SWAP32(0x12345678); // to be overwritten
+ PUT32(pos, 0x12345678); // to be overwritten
pos += 4;
writeRECT(&pos, &box);
- *(u16*)pos = SWAP16(0x2000); // framerate
+ PUT16(pos, 0x2000) // framerate
pos += 2;
- *(u16*)pos = SWAP16(numslaves);
+ PUT16(pos, numslaves) // framerate
pos += 2;
for(t=0;t<numslaves;t++)
{
}
namelen = strlen(slave_name[t]);
- *(u16*)&pos[0] = SWAP16((u16)(TAGID_DEFINESPRITE<<6) + 6);
- *(u16*)&pos[2] = SWAP16(t+1); //ID
- *(u16*)&pos[4] = 0; // Frames
- *(u16*)&pos[6] = 0; // TAG1
- *(u16*)&pos[8] = SWAP16((u16)(TAGID_PLACEOBJECT2<<6) + 6 + namelen);
- *(u16*)&pos[10]= SWAP16(34); //flags: id+name
- *(u16*)&pos[11]= SWAP16(1+t); // depth
- *(u16*)&pos[13]= SWAP16(t+1); // id
+ PUT16(&pos[0] , ((u16)(TAGID_DEFINESPRITE<<6) + 6));
+ PUT16(&pos[2] , (t+1)); //ID
+ PUT16(&pos[4] , 0); // Frames
+ PUT16(&pos[6] , 0); // TAG1
+ PUT16(&pos[8] , ((u16)(TAGID_PLACEOBJECT2<<6) + 6 + namelen));
+ PUT16(&pos[10], (34)); //flags: id+name
+ PUT16(&pos[11], (1+t)); // depth
+ PUT16(&pos[13], (t+1)); // id
sprintf(&pos[15],slave_name[t]);
pos += 15 + namelen + 1;
if(!config.stack1 || t == numslaves-1) {
- *(u16*)&pos[0]= SWAP16((u16)(TAGID_SHOWFRAME<<6) + 0);
+ PUT16(&pos[0],((u16)(TAGID_SHOWFRAME<<6) + 0));
pos += 2;
}
if(!config.stack)
if(t!=numslaves-1)
{
- *(u16*)&pos[0]= SWAP16((u16)(TAGID_REMOVEOBJECT2<<6) + 2);
- *(u16*)&pos[2]= SWAP16(1+t); // depth;
+ PUT16(&pos[0], ((u16)(TAGID_REMOVEOBJECT2<<6) + 2));
+ PUT16(&pos[2], (1+t)); // depth;
pos += 4;
}
}
- *(u16*)pos = SWAP16(TAGID_END<<6 + 0);
+ PUT16(pos, (TAGID_END<<6 + 0));
*masterlength = pos - *masterdata;
- *fixpos = SWAP32(*masterlength);
+ PUT32(fixpos, *masterlength);
}
struct config_t config;
slavedata[1] = 'W';
slavedata[2] = 'S';
slavedata[3] = 4; //version
- *(u32*)&slavedata[4] = SWAP32(14); // length
+ PUT32(&slavedata[4], 14); ; // length
slavedata[8] = 0; // boundingbox
- *(u16*)&slavedata[9] = SWAP16(0); // rate
- *(u16*)&slavedata[11] = SWAP16(0); // count
- *(u16*)&slavedata[13] = SWAP16(0); // end tag
+ PUT16(&slavedata[9] , (0)); // rate
+ PUT16(&slavedata[11] , (0)); // count
+ PUT16(&slavedata[13] , (0)); // end tag
slavelength = 17;
}
void idcallback(void*data)
{
- if(!(used[SWAP16(*(U16*)data)]&1)) {
+ if(!(used[GET16(data)]&1)) {
changed = 1;
- used[SWAP16(*(U16*)data)] |= 1;
+ used[GET16(data)] |= 1;
}
}
if(tag->len>=64) {
len += 6;
data = (U8*)malloc(len);
- *(U16*)data = SWAP16((tag->id<<6)+63);
+ PUT16(data, (tag->id<<6)+63);
*(U8*)&data[2] = tag->len;
*(U8*)&data[3] = tag->len>>8;
*(U8*)&data[4] = tag->len>>16;
} else {
len += 2;
data = (U8*)malloc(len);
- *(U16*)data = SWAP16((tag->id<<6)+tag->len);
+ PUT16(data, (tag->id<<6)+tag->len);
memcpy(&data[2], tag->data, tag->len);
}
map_ids_mem(data, len, callback);
{
char name[80];
FILE*fi;
- sprintf(name, "pic%d.jpeg", SWAP16(*(U16*)tag->data));
+ sprintf(name, "pic%d.jpeg", GET16(tag->data));
/* swf jpeg images have two streams, which both start with ff d8 and
end with ff d9. The following code handles sorting the middle
<ff d9 ff d8> bytes out, so that one stream remains */
fclose(fi);
}
if(tag->id == ST_DEFINEBITSJPEG3 && tag->len>6) {
- U32 end = SWAP32(*(U32*)&tag->data[2])+6;
+ U32 end = GET32(&tag->data[2])+6;
int pos = findjpegboundary(&tag->data[6], tag->len-6);
if(pos<0)
return;