- TAG*tag;
- MATRIX m;
- m.sx = 0x10000; m.sy = 0x10000;
- m.r0 = 0; m.r1 = 0;
- m.tx = x*20;
- m.ty = y*20;
- if(cx && !((cx->a0!=256)||(cx->r0!=256)||(cx->g0!=256)||(cx->b0!=256)
- ||(cx->a1|cx->r1|cx->g1|cx->b1))) cx = 0;
- tag = swf_InsertTag(NULL,ST_PLACEOBJECT2);
- swf_ObjectPlace(tag,id,depth,&m,cx,0);
- filesize += swf_WriteTag(file, tag);
- swf_DeleteTag(tag);
-}
-
-
-int xblocksize;
-int yblocksize;
-struct GfxBlock {
-// static int xblocksize;
-// static int yblocksize;
- U8*data;
- int len;
-};
-
-int width=0;
-int height=0;
-
-int xblocks;
-int yblocks;
-
-U8* blockbuffer = 0;
-
-class GfxBlockCache {
-
- GfxBlock*list;
- char*expire; //0=block's free
- int*ids;
- int size;
- int pos;
- int hits;
- int misses;
-
- public:
-
- GfxBlockCache(int file)
- {
- list=0;
- size = xblocks*yblocks*cache_size;
- printf("initializing cache (%d entries)\n", size);
- list = new GfxBlock[size];
- expire = new char[size];
- ids = new int[size];
- memset(expire,0,size);
- memset(list,0,sizeof(GfxBlock)*size);
- memset(ids,0,sizeof(int)*size);
- pos = 0;
- hits =0;
- misses =0;
- }
- void insert(GfxBlock*block, int gfxid)
- {
- int oldpos = pos;
- while(++pos!=oldpos)
- {
- if(pos==size) pos=0;
- if(!expire[pos])
- break;
- }
- if(pos==oldpos) {
- // cache full- don't insert item
- return;
- }
- if(list[pos].data) {
- free(list[pos].data);
- list[pos].data = 0;
- //TODO: free this in the SWF, also
- }
- list[pos].data=(U8*)malloc(block->len);
- memcpy(list[pos].data,block->data,block->len);
- list[pos].len = block->len;
- expire[pos] = cache_size;
- ids[pos] = gfxid;
- }
- int find(GfxBlock*block, CXFORM*cxform)
- {
- //TODO: do least square regression here to derive cxform
- int s;
- int bestsum=-1;
- int bestid;
- float best;
- for(s=0;s<size;s++)
- if(expire[s])
- {
- int t = (block->len);
- U8*ptr1 = block->data;
- U8*ptr2 = list[s].data;
- int sum2 = 0;
- // notice: we treat r,g,b as equal here.
- do {
- int a = (*ptr1++)-(*ptr2++);
- sum2 += a*a;
- } while(--t);
- if(bestsum < 0 || bestsum > sum2) {
- bestid = s;
- bestsum = sum2;
- }
- }
- if(bestsum<0) {
- misses++;
- return -1;
- }
- best = bestsum/block->len;
-
- if(best > 64.0) {
- misses++;
- return -1;
- }
- expire[bestid]= cache_size;
- hits++;
- cxform->a0 = 256;
- cxform->r0 = 256;
- cxform->g0 = 256;
- cxform->b0 = 256;
- cxform->a1 = 0;
- cxform->r1 = 0;
- cxform->g1 = 0;
- cxform->b1 = 0;
- return ids[bestid];
- }
- void newframe()
- {
- int t;
- for(t=0;t<size;t++)
- if(expire[t])
- expire[t]--;
-
- }
- ~GfxBlockCache()
- {
- int t;
- printf("destroying cache...\n");
- if(hits+misses) {
- printf("hits:%d (%02d%%)\n", hits, hits*100/(hits+misses));
- printf("misses:%d (%02d%%)\n", misses, misses*100/(hits+misses));
- }
- for(t=0;t<size;t++)
- if(expire[t] && list[t].data)
- free(list[t].data);
- free(list);
- free(expire);
- free(ids);
- }
-} * cache = 0;
-
-class GfxBlockEncoder {
- int sizex;
- int sizey;
- int posx;
- int posy;
- int basedepth;
- int depth[3];
- public:
- void init(int depth, int posx,int posy, int sizex, int sizey)