X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Freaders%2Fswf.c;h=fac12e23e9443e6611f23ff5fc4e3de9c79b4528;hb=10b60d36fcf6cc9532bf397866c5bdc3393246eb;hp=f517c3db631ba76596410d49098a9e31482a2f63;hpb=2bc6880f5a82798f20553459b1de148f409091ef;p=swftools.git diff --git a/lib/readers/swf.c b/lib/readers/swf.c index f517c3d..fac12e2 100644 --- a/lib/readers/swf.c +++ b/lib/readers/swf.c @@ -1,3 +1,4 @@ +#include #include #include "../gfxdevice.h" #include "../gfxsource.h" @@ -21,7 +22,6 @@ typedef struct _swf_page_internal typedef struct _swf_doc_internal { map16_t*id2char; - int clips; SWF swf; int width,height; MATRIX m; @@ -149,21 +149,27 @@ static gfxgradient_t* convertGradient(GRADIENT*from) gfxline_t* swfline_to_gfxline(SHAPELINE*line, int linestyle, int fillstyle0) { gfxdrawer_t d; - SCOORD x=0,y=0; + SCOORD x=0,y=0,xx=0,yy=0; gfxline_t*l; gfxdrawer_target_gfxline(&d); if(line && line->type != moveTo) { fprintf(stderr, "Warning: Shape doesn't start with a moveTo\n"); } + xx = line?line->x+1:0; while(line) { - if(line->fillstyle0 == fillstyle0 || line->fillstyle1 == fillstyle0 || + if(line->fillstyle0 == fillstyle0 || + line->fillstyle1 == fillstyle0 || line->linestyle == linestyle) { if(line->type == lineTo) { - d.moveTo(&d, x/20.0,y/20.0); + if(xx!=x || yy!=y) d.moveTo(&d, x/20.0,y/20.0); d.lineTo(&d, line->x/20.0,line->y/20.0); + xx = line->x; + yy = line->y; } else if(line->type == splineTo) { - d.moveTo(&d, x/20.0,y/20.0); + if(xx!=x || yy!=y) d.moveTo(&d, x/20.0,y/20.0); d.splineTo(&d, line->sx/20.0, line->sy/20.0, line->x/20.0,line->y/20.0); + xx = line->x; + yy = line->y; } } x = line->x; @@ -220,7 +226,6 @@ static void renderFilled(render_t*r, gfxline_t*line, FILLSTYLE*f, CXFORM*cx, MAT convertCXForm(cx, &gfxcx); MATRIX m2; swf_MatrixJoin(&m2, po_m, &f->m); - swf_DumpMatrix(stdout, &m2); convertMatrix(&m2, &m); m.m00/=20.0; m.m10/=20.0; m.m01/=20.0; m.m11/=20.0; @@ -410,9 +415,11 @@ static map16_t* extractFrame(TAG*startTag, int frame_to_extract) TAG*tag = startTag; int frame = 1; int insprite = 0; + + SWF*swf = rfx_calloc(sizeof(SWF)); + swf->firstTag = startTag; + for(;tag;tag = tag->next) { - if(tag->id == ST_END) - break; if(tag->id == ST_DEFINESPRITE) { while(tag->id != ST_END) tag = tag->next; @@ -438,7 +445,7 @@ static map16_t* extractFrame(TAG*startTag, int frame_to_extract) U16 depth = swf_GetDepth(tag); map16_remove_id(depthmap, depth); } - if(tag->id == ST_SHOWFRAME || tag->id == ST_END) { + if(tag->id == ST_SHOWFRAME || tag->id == ST_END || !tag->next) { if(frame == frame_to_extract) { return depthmap; } @@ -447,21 +454,14 @@ static map16_t* extractFrame(TAG*startTag, int frame_to_extract) map16_enumerate(depthmap, increaseAge, 0); } } + if(tag->id == ST_END) + break; } - fprintf(stderr, "gfxsource_swf: frame %d not found\n", frame_to_extract); return depthmap; } // ---- rendering ---- -static void stopClippings(int from, render_t*r) -{ - int t; - for(t=from;tclips;t++) - r->device->endclip(r->device); - r->clips = from; -} - void swf_ShapeApplyMatrix(SHAPE2*shape, MATRIX*m) { } @@ -514,7 +514,6 @@ static void renderCharacter(render_t*r, placement_t*p, character_t*c) } else { r->device->startclip(r->device, line); r->clips_waiting[p->po.clipdepth]++; - r->clips++; } } gfxline_free(line); @@ -555,11 +554,23 @@ static void placeObject(void*self, int id, void*data) return; } if(c->type == TYPE_SPRITE) { - int oldclip = r->clips; + int*old_clips_waiting = r->clips_waiting; + r->clips_waiting = rfx_calloc(sizeof(r->clips_waiting[0])*65536); + sprite_t* s = (sprite_t*)c->data; - map16_t* depths = extractFrame(c->tag, p->age % s->frameCount); + + map16_t* depths = extractFrame(c->tag->next, p->age % s->frameCount); map16_enumerate(depths, placeObject, r); - stopClippings(oldclip, r); + + int t; + for(t=0;t<65536;t++) { + int i; + for(i=0; iclips_waiting[t]; i++) { + r->device->endclip(r->device); + } + } + free(r->clips_waiting); + r->clips_waiting = old_clips_waiting; return; } renderCharacter(r, p, c); @@ -588,9 +599,11 @@ void swfpage_render(gfxpage_t*page, gfxdevice_t*output) int t; for(t=0;t<65536;t++) { int i; + for(i=0; iendclip(output); } + if(depths->ids[t]) { placeObject(&r, t, depths->ids[t]); } @@ -692,11 +705,20 @@ gfxdocument_t*swf_open(gfxsource_t*src, const char*filename) return swf_doc; } +static void swf_destroy(gfxsource_t*src) +{ + memset(src, 0, sizeof(*src)); + free(src); +} + + gfxsource_t*gfxsource_swf_create() { gfxsource_t*src = (gfxsource_t*)malloc(sizeof(gfxsource_t)); memset(src, 0, sizeof(gfxsource_t)); src->set_parameter = swf_set_parameter; src->open = swf_open; + src->destroy = swf_destroy; return src; } +