+ ((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1]) + h/2)/h;
+ RDIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h);
static void mpeg4_decode_sprite_trajectory(MpegEncContext * s){    int i;    int a= 2<<s->sprite_warping_accuracy;    int rho= 3-s->sprite_warping_accuracy;    int r=16/a;    const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes    int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}};    int sprite_ref[4][2];    int virtual_ref[2][2];    int w2, h2;    int alpha=0, beta=0;    int w= s->width;    int h= s->height;        for(i=0; i<s->num_sprite_warping_points; i++){        int length;        int x=0, y=0;        length= get_vlc(&s->gb, &sprite_trajectory);        if(length){            x= get_bits(&s->gb, length);            if ((x >> (length - 1)) == 0) /* if MSB not set it is negative*/                x = - (x ^ ((1 << length) - 1));        }// FIXME the mpeg4 std says that here should be a marker but but divx5 doesnt have one here//        skip_bits1(&s->gb); /* marker bit */                length= get_vlc(&s->gb, &sprite_trajectory);        if(length){            y=get_bits(&s->gb, length);            if ((y >> (length - 1)) == 0) /* if MSB not set it is negative*/                y = - (y ^ ((1 << length) - 1));        }        skip_bits1(&s->gb); /* marker bit *///        printf("%d %d\n", x, y);//if(i>0 && (x!=0 || y!=0)) printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n");        d[i][0]= x;        d[i][1]= y;    }    while((1<<alpha)<w) alpha++;    while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h'    w2= 1<<alpha;    h2= 1<<beta;// Note, the 4th point isnt used for GMC        sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]);    sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]);    sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]);    sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]);    sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]);    sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]);/*    sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]);    sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */    // this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...)// perhaps it should be reordered to be more readable ...// the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides// so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form// FIXME rounding (they should be positive but who knows ...)    virtual_ref[0][0]= 16*(vop_ref[0][0] + w2)         + ((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0]) + w/2)/w;    virtual_ref[0][1]= 16*vop_ref[0][1]         + ((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1]) + w/2)/w;    virtual_ref[1][0]= 16*vop_ref[0][0]         + ((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0]) + h/2)/h;    virtual_ref[1][1]= 16*(vop_ref[0][1] + h2)         + ((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1]) + h/2)/h;    switch(s->num_sprite_warping_points)    {        case 0:            s->sprite_offset[0][0]= 0;            s->sprite_offset[0][1]= 0;            s->sprite_offset[1][0]= 0;            s->sprite_offset[1][1]= 0;            s->sprite_delta[0][0][0]= a;            s->sprite_delta[0][0][1]= 0;            s->sprite_delta[0][1][0]= 0;            s->sprite_delta[0][1][1]= a;            s->sprite_delta[1][0][0]= a;            s->sprite_delta[1][0][1]= 0;            s->sprite_delta[1][1][0]= 0;            s->sprite_delta[1][1][1]= a;            s->sprite_shift[0][0]= 0;            s->sprite_shift[0][1]= 0;            s->sprite_shift[1][0]= 0;            s->sprite_shift[1][1]= 0;            break;        case 1: //GMC only            s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0];            s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1];            s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2);            s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2);            s->sprite_delta[0][0][0]= a;            s->sprite_delta[0][0][1]= 0;            s->sprite_delta[0][1][0]= 0;            s->sprite_delta[0][1][1]= a;            s->sprite_delta[1][0][0]= a;            s->sprite_delta[1][0][1]= 0;            s->sprite_delta[1][1][0]= 0;            s->sprite_delta[1][1][1]= a;            s->sprite_shift[0][0]= 0;            s->sprite_shift[0][1]= 0;            s->sprite_shift[1][0]= 0;            s->sprite_shift[1][1]= 0;            break;        case 2:        case 3: //FIXME            s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho))                                                  + ((-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0])                                                    +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1]));            s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho))                                                  + ((-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0])                                                    +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1]));            s->sprite_offset[1][0]= ((-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1)                                 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1)                                 +2*w2*r*sprite_ref[0][0] - 16*w2);            s->sprite_offset[1][1]= ((-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1)                                  +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1)                                 +2*w2*r*sprite_ref[0][1] - 16*w2);            s->sprite_delta[0][0][0]=   (-r*sprite_ref[0][0] + virtual_ref[0][0]);            s->sprite_delta[0][0][1]=   ( r*sprite_ref[0][1] - virtual_ref[0][1]);            s->sprite_delta[0][1][0]=   (-r*sprite_ref[0][1] + virtual_ref[0][1]);            s->sprite_delta[0][1][1]=   (-r*sprite_ref[0][0] + virtual_ref[0][0]);            s->sprite_delta[1][0][0]= 4*(-r*sprite_ref[0][0] + virtual_ref[0][0]);            s->sprite_delta[1][0][1]= 4*( r*sprite_ref[0][1] - virtual_ref[0][1]);            s->sprite_delta[1][1][0]= 4*(-r*sprite_ref[0][1] + virtual_ref[0][1]);            s->sprite_delta[1][1][1]= 4*(-r*sprite_ref[0][0] + virtual_ref[0][0]);            s->sprite_shift[0][0]= alpha+rho;            s->sprite_shift[0][1]= alpha+rho;            s->sprite_shift[1][0]= alpha+rho+2;            s->sprite_shift[1][1]= alpha+rho+2;            break;//        case 3:            break;    }}