#define S64 long long
SFIXED RFXSWF_SP(SFIXED a1,SFIXED a2,SFIXED b1,SFIXED b2)
-{ S64 a;
- a = ((S64)a1*(S64)b1+(S64)a2*(S64)b2)>>16;
+{ S64 a = ((S64)a1*(S64)b1+(S64)a2*(S64)b2)>>16;
SFIXED result = (SFIXED)(a);
if(a!=result)
fprintf(stderr, "Warning: overflow in matrix multiplication");
tag->pos = 0;
switch(tag->id)
{
- case ST_DEFINEBUTTONCXFORM: {
+ case ST_DEFINEBUTTONSOUND: {
int t;
callback(tag, tag->pos + base, callback_data);
for(t=0;t<4;t++) {
}
}
} break;
- case ST_DEFINEBUTTONSOUND:
+ case ST_DEFINEBUTTONCXFORM:
callback(tag, tag->pos + base, callback_data); //button id
break;
advancebits = swf_GetU8(tag); //advancebits
while(1) {
U16 flags;
+ int t;
swf_ResetReadBits(tag);
flags = swf_GetBits(tag, 8);
if(!flags) break;
- if(flags & 128) // text style record
- {
+
+ swf_ResetReadBits(tag);
+ if(flags & 8) { // hasfont
+ callback(tag, tag->pos + base, callback_data);
+ id = swf_GetU16(tag);
+ }
+ if(flags & 4) { // hascolor
+ if(num==1) swf_GetRGB(tag, NULL);
+ else swf_GetRGBA(tag, NULL);
+ }
+ if(flags & 2) { //has x offset
swf_ResetReadBits(tag);
- if(flags & 8) { // hasfont
- callback(tag, tag->pos + base, callback_data);
- id = swf_GetU16(tag);
- }
- if(flags & 4) { // hascolor
- if(num==1) swf_GetRGB(tag, NULL);
- else swf_GetRGBA(tag, NULL);
- }
- if(flags & 2) { //has x offset
- swf_ResetReadBits(tag);
- swf_GetU16(tag);
- }
- if(flags & 1) { //has y offset
- swf_ResetReadBits(tag);
- swf_GetU16(tag);
- }
- if(flags & 8) { //has height
- swf_ResetReadBits(tag);
- swf_GetU16(tag);
- }
- } else { // glyph record
- int t;
+ swf_GetU16(tag);
+ }
+ if(flags & 1) { //has y offset
swf_ResetReadBits(tag);
- for(t=0;t<flags;t++) {
- swf_GetBits(tag, glyphbits);
- swf_GetBits(tag, advancebits);
- }
+ swf_GetU16(tag);
+ }
+ if(flags & 8) { //has height
+ swf_ResetReadBits(tag);
+ swf_GetU16(tag);
+ }
+
+ flags = swf_GetBits(tag, 8);
+ if(!flags) break;
+ swf_ResetReadBits(tag);
+ for(t=0;t<flags;t++) {
+ swf_GetBits(tag, glyphbits);
+ swf_GetBits(tag, advancebits);
}
}
break;
}
}
+/* untested */
+void swf_Relocate2(SWF*swf, int*id2id)
+{
+ TAG*tag;
+ tag = swf->firstTag;
+ while(tag) {
+ if(swf_isDefiningTag(tag)) {
+ int id = swf_GetDefineID(tag);
+ id = id2id[id];
+ if(id>=0) {
+ swf_SetDefineID(tag, id);
+ }
+ }
+ int num = swf_GetNumUsedIDs(tag);
+ if(num) {
+ int *ptr;
+ int t;
+ ptr = rfx_alloc(sizeof(int)*num);
+ swf_GetUsedIDs(tag, ptr);
+ for(t=0;t<num;t++) {
+ int id = GET16(&tag->data[ptr[t]]);
+ id = id2id[id];
+ if(id>=0) {
+ PUT16(&tag->data[ptr[t]], id);
+ }
+ }
+ }
+ }
+}
+
void swf_RelocateDepth(SWF*swf, char*bitmap)
{
TAG*tag;
while(tag)
{
+ int depth;
/* TODO * clip depths
* sprites
*/
- int depth = swf_GetDepth(tag);
+ if(tag->id == ST_PLACEOBJECT2) {
+ SWFPLACEOBJECT obj;
+ swf_GetPlaceObject(tag, &obj);
+ if(obj.clipdepth) {
+ int newdepth = obj.clipdepth+nr;
+ if(newdepth>65535) {
+ fprintf(stderr, "Couldn't relocate depths: too large values\n");
+ newdepth = 65535;
+ }
+ obj.clipdepth = newdepth;
+ swf_ResetTag(tag, ST_PLACEOBJECT2);
+ swf_SetPlaceObject(tag, &obj);
+ }
+ swf_PlaceObjectFree(&obj);
+ }
+
+ depth = swf_GetDepth(tag);
if(depth>=0) {
int newdepth = depth+nr;
if(newdepth>65535) {
}
tag = swf->firstTag;
while(tag) {
- int doremap=1;
-
TAG*next = tag->next;
/* remap the tag */
PUT16(&tag->data[positions[t]], id);
}
rfx_free(positions);
- tag = tag->next;
/* now look for previous tags with the same
content */
int match=0;
if(!dontremap[id])
while((tag2 = hashmap[hash%hash_size])) {
- if(tag2 != (TAG*)(-1) && tag->len == tag2->len) {
- int t;
- /* start at pos 2, as 0 and 1 are the id */
- for(t=2;t<tag->len;t++) {
- if(tag->data[t] != tag2->data[t])
- break;
- }
- if(t == tag->len) {
- match=1;
- }
- }
- if(match) {
- /* we found two identical tags- remap one
- of them */
- remap[id] = swf_GetDefineID(tag2);
- break;
+ if(tag2 != (TAG*)0 && tag->len == tag2->len) {
+ if(memcmp(&tag->data[2],&tag2->data[2],tag->len-2) == 0) {
+ match = 1;
+ break;
+ }
}
hash++;
}
while(hashmap[hash%hash_size]) hash++;
hashmap[hash%hash_size] = tag;
} else {
+ /* we found two identical tags- remap one
+ of them */
+ remap[id] = swf_GetDefineID(tag2);
swf_DeleteTag(tag);
if(tag == swf->firstTag)
swf->firstTag = next;
- doremap = 0;
}
} else if(swf_isPseudoDefiningTag(tag)) {
int id = swf_GetDefineID(tag);
swf_DeleteTag(tag);
if(tag == swf->firstTag)
swf->firstTag = next;
- doremap = 0;
}
}
tag = next;
}
+
rfx_free(dontremap);
rfx_free(remap);
rfx_free(id2tag);