X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfshape.c;h=6bb1bada33aecde1f9ea3fb9f015a8d8a8ff2ad2;hb=d78db9583d1366c411b6d5e5e4a0c482a81fbbe4;hp=f107f925891ef0ec965a0934d5ec7c2eb351f3de;hpb=e448c7a56df8e289c9dbd5b8d87753addd541091;p=swftools.git diff --git a/lib/modules/swfshape.c b/lib/modules/swfshape.c index f107f92..6bb1bad 100644 --- a/lib/modules/swfshape.c +++ b/lib/modules/swfshape.c @@ -54,7 +54,7 @@ int swf_GetSimpleShape(TAG * t,SHAPE * * s) // without Linestyle/Fillstyle Recor if (FAILED(swf_ShapeNew(s))) return -1; sh = s[0]; - swf_ResetBitmask(t); + swf_ResetReadBits(t); sh->bits.fill = (U16)swf_GetBits(t,4); sh->bits.line = (U16)swf_GetBits(t,4); bitl = 0; end = 0; pos = swf_GetTagPos(t); @@ -144,13 +144,13 @@ int swf_SetSimpleShape(TAG * t,SHAPE * s) // without Linestyle/Fillstyle Record l = (s->bitlen+7)/8; if (t) - { swf_ResetBitcount(t); + { swf_ResetWriteBits(t); swf_SetBits(t,s->bits.fill,4); swf_SetBits(t,s->bits.line,4); swf_SetBlock(t,s->data,l); - swf_ResetBitcount(t); + swf_ResetWriteBits(t); } return l+1; } @@ -231,7 +231,7 @@ int swf_ShapeCountBits(SHAPE * s,U8 * fbits,U8 * lbits) int swf_SetShapeBits(TAG * t,SHAPE * s) { if ((!t)||(!s)) return -1; - swf_ResetBitcount(t); + swf_ResetWriteBits(t); swf_SetBits(t,s->bits.fill,4); swf_SetBits(t,s->bits.line,4); return 0; @@ -385,10 +385,6 @@ int swf_ShapeSetMove(TAG * t,SHAPE * s,S32 x,S32 y) swf_SetBits(t,x,b); swf_SetBits(t,y,b); - if (s) - { s->px = x; - s->py = y; - } return 0; } @@ -426,8 +422,6 @@ int swf_ShapeSetAll(TAG * t,SHAPE * s,S32 x,S32 y,U16 line,U16 fill0,U16 fill1) swf_SetBits(t,b,5); swf_SetBits(t,x,b); swf_SetBits(t,y,b); - s->px = x; - s->py = y; if (fill0) swf_SetBits(t,fill0,s->bits.fill); if (fill1) swf_SetBits(t,fill1,s->bits.fill); @@ -439,7 +433,7 @@ int swf_ShapeSetAll(TAG * t,SHAPE * s,S32 x,S32 y,U16 line,U16 fill0,U16 fill1) int swf_ShapeSetEnd(TAG * t) { if (!t) return -1; swf_SetBits(t,0,6); - swf_ResetBitcount(t); + swf_ResetWriteBits(t); return 0; } @@ -456,10 +450,6 @@ int swf_ShapeSetLine(TAG * t,SHAPE * s,S32 x,S32 y) swf_SetBits(t,1,1); swf_SetBits(t,x,b); swf_SetBits(t,y,b); - if (s) - { s->px += x; - s->py += y; - } return 0; } @@ -470,8 +460,7 @@ int swf_ShapeSetLine(TAG * t,SHAPE * s,S32 x,S32 y) swf_SetBits(t, b-2, 4); swf_SetBits(t,1,2); swf_SetBits(t,y,b); - s->py += y; - } + } else { b = swf_CountBits(x,2); if(b<2) @@ -479,7 +468,6 @@ int swf_ShapeSetLine(TAG * t,SHAPE * s,S32 x,S32 y) swf_SetBits(t, b-2, 4); swf_SetBits(t,0,2); swf_SetBits(t,x,b); - s->px += x; } return 0; } @@ -501,10 +489,6 @@ int swf_ShapeSetCurve(TAG * t,SHAPE * s,S32 x,S32 y,S32 ax,S32 ay) swf_SetBits(t,ax,b); swf_SetBits(t,ay,b); - if (s) - { s->px += x+ax; - s->py += y+ay; - } return 0; } @@ -528,3 +512,291 @@ int swf_ShapeSetCircle(TAG * t,SHAPE * s,S32 x,S32 y,S32 rx,S32 ry) return 0; } +/* todo: merge this with swf_GetSimpleShape */ +SHAPELINE* swf_ParseShapeData(U8*data, int bits, int fillbits, int linebits) +{ + SHAPELINE _lines; + SHAPELINE*lines = &_lines; + + TAG _tag; + TAG* tag = &_tag; + int fill0 = 0; + int fill1 = 0; + int line = 0; + int x=0,y=0; + + memset(tag, 0, sizeof(TAG)); + tag->data = data; + tag->len = tag->memsize = (bits+7)/8; + tag->pos = 0; + + lines->next = 0; + while(1) { + int flags; + flags = swf_GetBits(tag, 1); + if(!flags) { //style change + flags = swf_GetBits(tag, 5); + if(!flags) + break; + if(flags&2) + fill0 = swf_GetBits(tag, fillbits); + if(flags&4) + fill1 = swf_GetBits(tag, fillbits); + if(flags&8) + line = swf_GetBits(tag, linebits); + if(flags&16) { + return 0; + //enumerateUsedIDs_styles(tag, callback, callback_data, num); + fillbits = swf_GetBits(tag, 4); + linebits = swf_GetBits(tag, 4); + } + if(flags&1) { //move + int n = swf_GetBits(tag, 5); + x = swf_GetSBits(tag, n); //x + y = swf_GetSBits(tag, n); //y + + lines->next = (SHAPELINE*)malloc(sizeof(SHAPELINE)); + lines = lines->next; + lines->type = moveTo; + lines->x = x; + lines->y = y; + lines->sx = lines->sy = 0; + lines->fillstyle0 = fill0; + lines->fillstyle1 = fill1; + lines->linestyle = line; + lines->next = 0; + } + } else { + flags = swf_GetBits(tag, 1); + if(flags) { //straight edge + int n = swf_GetBits(tag, 4) + 2; + if(swf_GetBits(tag, 1)) { //line flag + x += swf_GetSBits(tag, n); //delta x + y += swf_GetSBits(tag, n); //delta y + } else { + int v=swf_GetBits(tag, 1); + int d; + d = swf_GetSBits(tag, n); //vert/horz + if(v) y += d; + else x += d; + } + lines->next = (SHAPELINE*)malloc(sizeof(SHAPELINE)); + lines = lines->next; + lines->type = lineTo; + lines->x = x; + lines->y = y; + lines->sx = lines->sy = 0; + lines->fillstyle0 = fill0; + lines->fillstyle1 = fill1; + lines->linestyle = line; + lines->next = 0; + } else { //curved edge + int n = swf_GetBits(tag, 4) + 2; + int x1,y1; + x += swf_GetSBits(tag, n); + y += swf_GetSBits(tag, n); + x1 = x; + y1 = y; + x += swf_GetSBits(tag, n); + y += swf_GetSBits(tag, n); + + lines->next = (SHAPELINE*)malloc(sizeof(SHAPELINE)); + lines = lines->next; + lines->type = splineTo; + lines->sx = x1; + lines->sy = y1; + lines->x = x; + lines->y = y; + lines->fillstyle0 = fill0; + lines->fillstyle1 = fill1; + lines->linestyle = line; + lines->next = 0; + } + } + } + return _lines.next; +} + +SRECT swf_GetShapeBoundingBox(SHAPELINE*shape) +{ + SRECT r; + int SCOORD_MAX = 0x7fffffff; + int SCOORD_MIN = -0x80000000; + r.xmin = r.ymin = SCOORD_MAX; + r.xmax = r.ymax = SCOORD_MIN; + if(!shape) { + fprintf(stderr, "rfxswf: Warning: empty Shape\n"); + } + while(shape) { + if(shape->x < r.xmin) r.xmin = shape->x; + if(shape->y < r.ymin) r.ymin = shape->y; + if(shape->x > r.xmax) r.xmax = shape->x; + if(shape->y > r.ymax) r.ymax = shape->y; + if(shape->type == splineTo) { + if(shape->sx < r.xmin) r.xmin = shape->sx; + if(shape->sy < r.ymin) r.ymin = shape->sy; + if(shape->sx > r.xmax) r.xmax = shape->sx; + if(shape->sy > r.ymax) r.ymax = shape->sy; + } + shape = shape->next; + } + return r; +} + +void swf_Shape2Free(SHAPE2 * s) +{ + SHAPELINE*line = s->lines; + while(line) { + SHAPELINE*next = line->next; + free(line); + line = next; + } + if(s->linestyles) + free(s->linestyles); + if(s->fillstyles) + free(s->fillstyles); + if(s->bbox) + free(s->bbox); +} + +SHAPE2* swf_ShapeToShape2(SHAPE*shape) { + + SHAPE2*shape2 = (SHAPE2*)malloc(sizeof(SHAPE2)); + + shape2->numlinestyles = shape->linestyle.n; + shape2->linestyles = (LINESTYLE*)malloc(sizeof(LINESTYLE)*shape->linestyle.n); + memcpy(shape2->linestyles, shape->linestyle.data, sizeof(LINESTYLE)*shape->linestyle.n); + + shape2->numfillstyles = shape->fillstyle.n; + shape2->fillstyles = (FILLSTYLE*)malloc(sizeof(FILLSTYLE)*shape->fillstyle.n); + memcpy(shape2->fillstyles, shape->fillstyle.data, sizeof(FILLSTYLE)*shape->fillstyle.n); + + shape2->lines = swf_ParseShapeData(shape->data, shape->bitlen, shape->bits.fill, shape->bits.line); + shape2->bbox = 0; + return shape2; +}; + +/*LINESTYLE* parseFillStyleArray(TAG*tag) +{ + U16 count; + int t; + int num=0; + if(tag->id == ST_DEFINESHAPE) + num = 1; + else if(tag->id == ST_DEFINESHAPE2) + num = 2; + else if(tag->id == ST_DEFINESHAPE3) + num = 3; + else return 0; + + count = swf_GetU8(tag); + if(count == 0xff && num>1) // defineshape2,3 only + count = swf_GetU16(tag); + + for(t=0;t=3?1:0); + } + else if(type == 0x40 || type == 0x41) + { + swf_ResetReadBits(tag); + // we made it. + if(tag->data[tag->pos] != 0xff || + tag->data[tag->pos+1] != 0xff) + //(callback)(tag, tag->pos, callback_data); + + swf_GetU16(tag); + swf_ResetReadBits(tag); + swf_GetMatrix(tag, NULL); + swf_GetMatrix(tag, NULL); + } + else { + fprintf(stderr, "rfxswf:swftools.c Unknown fillstyle:0x%02x\n",type); + } + } + swf_ResetReadBits(tag); + count = swf_GetU8(tag); // line style array + if(count == 0xff) + count = swf_GetU16(tag); + for(t=0;tid == ST_DEFINESHAPE) + num = 1; + else if(tag->id == ST_DEFINESHAPE2) + num = 2; + else if(tag->id == ST_DEFINESHAPE3) + num = 3; + else return 0; + + swf_GetU16(); + + shape = (SHAPE2*)malloc(sizeof(SHAPE2)); + +// LINESTYLE * linestyles; +// int numlinestyles; +// FILLSTYLE* fillstyles; +// int numfillstyles; +// struct _SHAPELINE * lines; +// SRECT* bbox; // may be NULL + + swf_GetRect(); + swf_ResetReadBits(t); + fill = (U16)swf_GetBits(t,4); + line = (U16)swf_GetBits(t,4); + + swf_Get + + + + + + + return 0; +}*/ + + +SHAPE* swf_Shape2ToShape(SHAPE2*shape) +{ + /* todo */ + fprintf(stderr, "Not implemented yet!\n"); + exit(1); + return 0; +} + +int swf_SetShape2(TAG*tag, SHAPE2*shape) +{ + /* todo */ + fprintf(stderr, "Not implemented yet!\n"); + exit(1); + return 0; +} +