* bugfixes
[swftools.git] / lib / modules / swfshape.c
index 4642cff..25077ac 100644 (file)
@@ -446,6 +446,12 @@ int swf_ShapeSetLine(TAG * t,SHAPE * s,S32 x,S32 y)
   { b = swf_CountBits(x,2);
     b = swf_CountBits(y,b);
     if (b<2) b=2;
+    if(b-2 >= 16) {
+       fprintf(stderr, "Bit overflow in swf_ShapeSetLine(1)- %d\n", b);
+       fflush(stdout);
+       *(int*)0 = 0xdead;
+       b = 17;
+    }
     swf_SetBits(t, b-2, 4);
     swf_SetBits(t,1,1);
     swf_SetBits(t,x,b);
@@ -457,6 +463,10 @@ int swf_ShapeSetLine(TAG * t,SHAPE * s,S32 x,S32 y)
   { b = swf_CountBits(y,2);
     if(b<2) 
         b=2;
+    if(b-2 >= 16) {
+       fprintf(stderr, "Bit overflow in swf_ShapeSetLine(2)- %d\n", b);
+       b = 17;
+    }
     swf_SetBits(t, b-2, 4);
     swf_SetBits(t,1,2);
     swf_SetBits(t,y,b);
@@ -465,6 +475,10 @@ int swf_ShapeSetLine(TAG * t,SHAPE * s,S32 x,S32 y)
   { b = swf_CountBits(x,2);
     if(b<2) 
         b=2;
+    if(b-2 >= 16) {
+       fprintf(stderr, "Bit overflow in swf_ShapeSetLine(3)- %d\n", b);
+       b = 17;
+    }
     swf_SetBits(t, b-2, 4);
     swf_SetBits(t,0,2);
     swf_SetBits(t,x,b);
@@ -552,8 +566,8 @@ SHAPELINE* swf_ParseShapeData(U8*data, int bits, int fillbits, int linebits)
            }
            if(flags&1) { //move
                int n = swf_GetBits(tag, 5); 
-               x = swf_GetBits(tag, n); //x
-               y = swf_GetBits(tag, n); //y
+               x = swf_GetSBits(tag, n); //x
+               y = swf_GetSBits(tag, n); //y
 
                lines->next = (SHAPELINE*)malloc(sizeof(SHAPELINE));
                lines = lines->next;
@@ -570,7 +584,6 @@ SHAPELINE* swf_ParseShapeData(U8*data, int bits, int fillbits, int linebits)
            flags = swf_GetBits(tag, 1);
            if(flags) { //straight edge
                int n = swf_GetBits(tag, 4) + 2;
-               int x=0,y=0;
                if(swf_GetBits(tag, 1)) { //line flag
                    x += swf_GetSBits(tag, n); //delta x
                    y += swf_GetSBits(tag, n); //delta y
@@ -626,7 +639,8 @@ SRECT swf_GetShapeBoundingBox(SHAPELINE*shape)
     r.xmin = r.ymin = SCOORD_MAX;
     r.xmax = r.ymax = SCOORD_MIN;
     if(!shape) {
-       fprintf(stderr, "rfxswf: Warning: empty Shape\n");
+       memset(&r, 0, sizeof(SRECT));
+       return r;
     }
     while(shape) {
        if(shape->x < r.xmin) r.xmin = shape->x;
@@ -677,20 +691,112 @@ SHAPE2* swf_ShapeToShape2(SHAPE*shape) {
     return shape2;
 };
 
-SHAPE2* parseDefineShape(TAG*tag)
+/*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<count;t++)
+    {
+       int type;
+       U8*pos;
+       swf_ResetReadBits(tag);
+       type = swf_GetU8(tag); //type
+       if(type == 0) {
+           if(num == 3)
+               swf_GetRGBA(tag, NULL);
+           else 
+               swf_GetRGB(tag, NULL);
+       }
+       else if(type == 0x10 || type == 0x12)
+       {
+           swf_ResetReadBits(tag);
+           swf_GetMatrix(tag, NULL);
+           swf_ResetReadBits(tag);
+           swf_GetGradient(tag, NULL, alpha num>=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;t<count;t++) 
+    {
+       swf_GetU16(tag);
+       swf_GetU16(tag);
+       if(num == 3)
+           swf_GetRGBA(tag, NULL);
+       else
+           swf_GetRGB(tag, NULL);
+    }
+}*/
+
+/*SHAPE2* parseDefineShape(TAG*tag)
 {
     int num = 0;
+    SHAPE2*shape;
+    U16 fill,line;
     if(tag->id == ST_DEFINESHAPE)
        num = 1;
     else if(tag->id == ST_DEFINESHAPE2)
        num = 2;
     else if(tag->id == ST_DEFINESHAPE3)
        num = 3;
-    /* todo */
-    fprintf(stderr, "Not implemented yet!\n");
-    exit(1);
+    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)
@@ -709,3 +815,40 @@ int           swf_SetShape2(TAG*tag, SHAPE2*shape)
     return 0;
 }
 
+void swf_ShapeSetBitmapRect(TAG*tag, U16 gfxid, int width, int height)
+{
+    SHAPE*shape;
+    MATRIX m;
+    RGBA rgb;
+    SRECT r;
+    int lines = 0;
+    int ls,fs;
+    swf_ShapeNew(&shape);
+    rgb.b = rgb.g = rgb.r = 0xff;
+    if(lines)
+       ls = swf_ShapeAddLineStyle(shape,20,&rgb);  
+    swf_GetMatrix(NULL,&m);
+    m.sx = 20*65536;
+    m.sy = 20*65536;
+
+    fs = swf_ShapeAddBitmapFillStyle(shape,&m,gfxid,0);
+    r.xmin = 0;
+    r.ymin = 0;
+    r.xmax = width*20;
+    r.ymax = height*20;
+    swf_SetRect(tag,&r);
+
+    swf_SetShapeStyles(tag,shape);
+    swf_ShapeCountBits(shape,NULL,NULL);
+    swf_SetShapeBits(tag,shape);
+
+    swf_ShapeSetAll(tag,shape,0,0,lines?ls:0,fs,0);
+
+    swf_ShapeSetLine(tag,shape,width*20,0);
+    swf_ShapeSetLine(tag,shape,0,height*20);
+    swf_ShapeSetLine(tag,shape,-width*20,0);
+    swf_ShapeSetLine(tag,shape,0,-height*20);
+    swf_ShapeSetEnd(tag);
+    swf_ShapeFree(shape);
+}
+