- 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)
- {
- this->basedepth = depth;
- this->posx = posx;
- this->posy = posy;
- this->sizex = sizex;
- this->sizey = sizey;
- this->depth[0] = this->depth[1] = this->depth[2] = -1;
- }
- void clear(int file)
- {
- /* clear everything in the block */
- int t;
- for(t=0;t<3;t++)
- if(depth[t]>=0)
- {
- TAG*tag;
- tag = swf_InsertTag(NULL, ST_REMOVEOBJECT2);
- swf_SetU16(tag, basedepth+t); //depth
- filesize += swf_WriteTag(file, tag);
- swf_DeleteTag(tag);
- depth[t] = -1;
- }
- }
- void writeiframe(int file, GfxBlock*block)
- {
- clear(file);
-
- int gfxid = get_free_id();
- int shapeid = get_free_id();
-
- //memset(data,0,sizex*sizey*3);
- TAG*tag = swf_InsertTag(NULL, ST_DEFINEBITS);
- JPEGBITS * jb = swf_SetJPEGBitsStart(tag,sizex,sizey,jpeg_quality);
- tag->len = 0; //bad hack
- swf_SetU16(tag, gfxid);
- int y;
- for(y=0;y<sizey;y++)
- swf_SetJPEGBitsLine(jb,&block->data[y*sizex*3]);
- swf_SetJPEGBitsFinish(jb);
- filesize += swf_WriteTag(file, tag);
- swf_DeleteTag(tag);
-
- cache->insert(block, shapeid);
-
- makeshape(file, shapeid, gfxid, sizex, sizey);
- setshape(file, shapeid, basedepth+1, posx, posy, 0);
- depth[1] = shapeid;
- }
- void writereference(int file, int shapeid, CXFORM*form)
- {
- if(depth[1]!=shapeid)
- {
- clear(file);
- setshape(file, shapeid, basedepth+1, posx, posy, form);
- depth[1] = shapeid;
- }
- }
- void compress(int file, GfxBlock*block)
- {
- CXFORM form;
- int id = cache->find(block, &form);
- if(id<0)
- writeiframe(file, block);
- else {
- writereference(file, id, &form);