static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int offset)

{

    uint8_t *prev, *cur;

    int blk, blocks, t, blk2;

    int blocktypes = 0;

    int x, y, a, b;

    int pattype, pattern;

    const int width = c->avctx->width;

    uint8_t *pstart = c->prev_frame;

    uint8_t *pend = c->prev_frame + width*c->avctx->height;



    prev = c->prev_frame + offset;

    cur = c->frame;



    blocks = (c->avctx->width >> 2) * (c->avctx->height >> 2);

    blk2 = 0;

    for(blk = 0; blk < blocks; blk++){

        if(!(blk & 3))

            blocktypes = bytestream_get_byte(&buf);

        switch(blocktypes & 0xC0){

        case 0x00: //skip

            for(y = 0; y < 4; y++)

                if(check_line(prev + y*width, pstart, pend))

                    memcpy(cur + y*width, prev + y*width, 4);

                else

                    memset(cur + y*width, 0, 4);

            break;

        case 0x40:

            t = bytestream_get_byte(&buf);

            if(!t){ //raw block

                for(y = 0; y < 4; y++)

                    memcpy(cur + y*width, buf + y*4, 4);

                buf += 16;

            }else{ // motion compensation

                x = ((t & 0xF)^8) - 8;

                y = ((t >> 4) ^8) - 8;

                t = x + y*width;

                for(y = 0; y < 4; y++)

                    if(check_line(prev + t + y*width, pstart, pend))

                        memcpy(cur + y*width, prev + t + y*width, 4);

                    else

                        memset(cur + y*width, 0, 4);

            }

            break;

        case 0x80: // fill

            t = bytestream_get_byte(&buf);

            for(y = 0; y < 4; y++)

                memset(cur + y*width, t, 4);

            break;

        case 0xC0: // pattern fill

            t = bytestream_get_byte(&buf);

            pattype = t >> 6;

            pattern = vb_patterns[t & 0x3F];

            switch(pattype){

            case 0:

                a = bytestream_get_byte(&buf);

                b = bytestream_get_byte(&buf);

                for(y = 0; y < 4; y++)

                    for(x = 0; x < 4; x++, pattern >>= 1)

                        cur[x + y*width] = (pattern & 1) ? b : a;

                break;

            case 1:

                pattern = ~pattern;

            case 2:

                a = bytestream_get_byte(&buf);

                for(y = 0; y < 4; y++)

                    for(x = 0; x < 4; x++, pattern >>= 1)

                        if(pattern & 1 && check_pixel(prev + x + y*width, pstart, pend))

                            cur[x + y*width] = prev[x + y*width];

                        else

                            cur[x + y*width] = a;

                break;

            case 3:

                av_log(c->avctx, AV_LOG_ERROR, "Invalid opcode seen @%d\n",blk);

                return -1;

            }

            break;

        }

        blocktypes <<= 2;

        cur  += 4;

        prev += 4;

        blk2++;

        if(blk2 == (width >> 2)){

            blk2 = 0;

            cur  += width * 3;

            prev += width * 3;

        }

    }

    return 0;

}

static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int offset)

{

    uint8_t *prev, *cur;

    int blk, blocks, t, blk2;

    int blocktypes = 0;

    int x, y, a, b;

    int pattype, pattern;

    const int width = c->avctx->width;

    uint8_t *pstart = c->prev_frame;

    uint8_t *pend = c->prev_frame + width*c->avctx->height;



    prev = c->prev_frame + offset;

    cur = c->frame;



    blocks = (c->avctx->width >> 2) * (c->avctx->height >> 2);

    blk2 = 0;

    for(blk = 0; blk < blocks; blk++){

        if(!(blk & 3))

            blocktypes = bytestream_get_byte(&buf);

        switch(blocktypes & 0xC0){

        case 0x00: 

            for(y = 0; y < 4; y++)

                if(check_line(prev + y*width, pstart, pend))

                    memcpy(cur + y*width, prev + y*width, 4);

                else

                    memset(cur + y*width, 0, 4);

            break;

        case 0x40:

            t = bytestream_get_byte(&buf);

            if(!t){ 

                for(y = 0; y < 4; y++)

                    memcpy(cur + y*width, buf + y*4, 4);

                buf += 16;

            }else{ 

                x = ((t & 0xF)^8) - 8;

                y = ((t >> 4) ^8) - 8;

                t = x + y*width;

                for(y = 0; y < 4; y++)

                    if(check_line(prev + t + y*width, pstart, pend))

                        memcpy(cur + y*width, prev + t + y*width, 4);

                    else

                        memset(cur + y*width, 0, 4);

            }

            break;

        case 0x80: 

            t = bytestream_get_byte(&buf);

            for(y = 0; y < 4; y++)

                memset(cur + y*width, t, 4);

            break;

        case 0xC0: 

            t = bytestream_get_byte(&buf);

            pattype = t >> 6;

            pattern = vb_patterns[t & 0x3F];

            switch(pattype){

            case 0:

                a = bytestream_get_byte(&buf);

                b = bytestream_get_byte(&buf);

                for(y = 0; y < 4; y++)

                    for(x = 0; x < 4; x++, pattern >>= 1)

                        cur[x + y*width] = (pattern & 1) ? b : a;

                break;

            case 1:

                pattern = ~pattern;

            case 2:

                a = bytestream_get_byte(&buf);

                for(y = 0; y < 4; y++)

                    for(x = 0; x < 4; x++, pattern >>= 1)

                        if(pattern & 1 && check_pixel(prev + x + y*width, pstart, pend))

                            cur[x + y*width] = prev[x + y*width];

                        else

                            cur[x + y*width] = a;

                break;

            case 3:

                av_log(c->avctx, AV_LOG_ERROR, "Invalid opcode seen @%d\n",blk);

                return -1;

            }

            break;

        }

        blocktypes <<= 2;

        cur  += 4;

        prev += 4;

        blk2++;

        if(blk2 == (width >> 2)){

            blk2 = 0;

            cur  += width * 3;

            prev += width * 3;

        }

    }

    return 0;

}

static int FUNC_0(VBDecContext *VAR_0, const uint8_t *VAR_1, int VAR_2)

{

    uint8_t *prev, *cur;

    int VAR_3, VAR_4, VAR_5, VAR_6;

    int VAR_7 = 0;

    int VAR_8, VAR_9, VAR_10, VAR_11;

    int VAR_12, VAR_13;

    const int VAR_14 = VAR_0->avctx->VAR_14;

    uint8_t *pstart = VAR_0->prev_frame;

    uint8_t *pend = VAR_0->prev_frame + VAR_14*VAR_0->avctx->height;



    prev = VAR_0->prev_frame + VAR_2;

    cur = VAR_0->frame;



    VAR_4 = (VAR_0->avctx->VAR_14 >> 2) * (VAR_0->avctx->height >> 2);

    VAR_6 = 0;

    for(VAR_3 = 0; VAR_3 < VAR_4; VAR_3++){

        if(!(VAR_3 & 3))

            VAR_7 = bytestream_get_byte(&VAR_1);

        switch(VAR_7 & 0xC0){

        case 0x00: 

            for(VAR_9 = 0; VAR_9 < 4; VAR_9++)

                if(check_line(prev + VAR_9*VAR_14, pstart, pend))

                    memcpy(cur + VAR_9*VAR_14, prev + VAR_9*VAR_14, 4);

                else

                    memset(cur + VAR_9*VAR_14, 0, 4);

            break;

        case 0x40:

            VAR_5 = bytestream_get_byte(&VAR_1);

            if(!VAR_5){ 

                for(VAR_9 = 0; VAR_9 < 4; VAR_9++)

                    memcpy(cur + VAR_9*VAR_14, VAR_1 + VAR_9*4, 4);

                VAR_1 += 16;

            }else{ 

                VAR_8 = ((VAR_5 & 0xF)^8) - 8;

                VAR_9 = ((VAR_5 >> 4) ^8) - 8;

                VAR_5 = VAR_8 + VAR_9*VAR_14;

                for(VAR_9 = 0; VAR_9 < 4; VAR_9++)

                    if(check_line(prev + VAR_5 + VAR_9*VAR_14, pstart, pend))

                        memcpy(cur + VAR_9*VAR_14, prev + VAR_5 + VAR_9*VAR_14, 4);

                    else

                        memset(cur + VAR_9*VAR_14, 0, 4);

            }

            break;

        case 0x80: 

            VAR_5 = bytestream_get_byte(&VAR_1);

            for(VAR_9 = 0; VAR_9 < 4; VAR_9++)

                memset(cur + VAR_9*VAR_14, VAR_5, 4);

            break;

        case 0xC0: 

            VAR_5 = bytestream_get_byte(&VAR_1);

            VAR_12 = VAR_5 >> 6;

            VAR_13 = vb_patterns[VAR_5 & 0x3F];

            switch(VAR_12){

            case 0:

                VAR_10 = bytestream_get_byte(&VAR_1);

                VAR_11 = bytestream_get_byte(&VAR_1);

                for(VAR_9 = 0; VAR_9 < 4; VAR_9++)

                    for(VAR_8 = 0; VAR_8 < 4; VAR_8++, VAR_13 >>= 1)

                        cur[VAR_8 + VAR_9*VAR_14] = (VAR_13 & 1) ? VAR_11 : VAR_10;

                break;

            case 1:

                VAR_13 = ~VAR_13;

            case 2:

                VAR_10 = bytestream_get_byte(&VAR_1);

                for(VAR_9 = 0; VAR_9 < 4; VAR_9++)

                    for(VAR_8 = 0; VAR_8 < 4; VAR_8++, VAR_13 >>= 1)

                        if(VAR_13 & 1 && check_pixel(prev + VAR_8 + VAR_9*VAR_14, pstart, pend))

                            cur[VAR_8 + VAR_9*VAR_14] = prev[VAR_8 + VAR_9*VAR_14];

                        else

                            cur[VAR_8 + VAR_9*VAR_14] = VAR_10;

                break;

            case 3:

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid opcode seen @%d\n",VAR_3);

                return -1;

            }

            break;

        }

        VAR_7 <<= 2;

        cur  += 4;

        prev += 4;

        VAR_6++;

        if(VAR_6 == (VAR_14 >> 2)){

            VAR_6 = 0;

            cur  += VAR_14 * 3;

            prev += VAR_14 * 3;

        }

    }

    return 0;

}

static int FUNC_0(VBDecContext *VAR_0, const uint8_t *VAR_1, int VAR_2)
{ uint8_t *prev, *cur; int VAR_3, VAR_4, VAR_5, VAR_6; int VAR_7 = 0; int VAR_8, VAR_9, VAR_10, VAR_11; int VAR_12, VAR_13; const int VAR_14 = VAR_0->avctx->VAR_14; uint8_t *pstart = VAR_0->prev_frame; uint8_t *pend = VAR_0->prev_frame + VAR_14*VAR_0->avctx->height; prev = VAR_0->prev_frame + VAR_2; cur = VAR_0->frame; VAR_4 = (VAR_0->avctx->VAR_14 >> 2) * (VAR_0->avctx->height >> 2); VAR_6 = 0; for(VAR_3 = 0; VAR_3 < VAR_4; VAR_3++){ if(!(VAR_3 & 3))
VAR_7 = bytestream_get_byte(&VAR_1); switch(VAR_7 & 0xC0){ case 0x00:
for(VAR_9 = 0; VAR_9 < 4; VAR_9++) if(check_line(prev + VAR_9*VAR_14, pstart, pend))
memcpy(cur + VAR_9*VAR_14, prev + VAR_9*VAR_14, 4); else
memset(cur + VAR_9*VAR_14, 0, 4); break; case 0x40:
VAR_5 = bytestream_get_byte(&VAR_1); if(!VAR_5){ for(VAR_9 = 0; VAR_9 < 4; VAR_9++) memcpy(cur + VAR_9*VAR_14, VAR_1 + VAR_9*4, 4); VAR_1 += 16; }else{ VAR_8 = ((VAR_5 & 0xF)^8) - 8; VAR_9 = ((VAR_5 >> 4) ^8) - 8; VAR_5 = VAR_8 + VAR_9*VAR_14; for(VAR_9 = 0; VAR_9 < 4; VAR_9++) if(check_line(prev + VAR_5 + VAR_9*VAR_14, pstart, pend))
memcpy(cur + VAR_9*VAR_14, prev + VAR_5 + VAR_9*VAR_14, 4); else
memset(cur + VAR_9*VAR_14, 0, 4); } break; case 0x80:
VAR_5 = bytestream_get_byte(&VAR_1); for(VAR_9 = 0; VAR_9 < 4; VAR_9++) memset(cur + VAR_9*VAR_14, VAR_5, 4); break; case 0xC0:
VAR_5 = bytestream_get_byte(&VAR_1); VAR_12 = VAR_5 >> 6; VAR_13 = vb_patterns[VAR_5 & 0x3F]; switch(VAR_12){ case 0:
VAR_10 = bytestream_get_byte(&VAR_1); VAR_11 = bytestream_get_byte(&VAR_1); for(VAR_9 = 0; VAR_9 < 4; VAR_9++) for(VAR_8 = 0; VAR_8 < 4; VAR_8++, VAR_13 >>= 1) cur[VAR_8 + VAR_9*VAR_14] = (VAR_13 & 1) ? VAR_11 : VAR_10; break; case 1:
VAR_13 = ~VAR_13; case 2:
VAR_10 = bytestream_get_byte(&VAR_1); for(VAR_9 = 0; VAR_9 < 4; VAR_9++) for(VAR_8 = 0; VAR_8 < 4; VAR_8++, VAR_13 >>= 1) if(VAR_13 & 1 && check_pixel(prev + VAR_8 + VAR_9*VAR_14, pstart, pend))
cur[VAR_8 + VAR_9*VAR_14] = prev[VAR_8 + VAR_9*VAR_14]; else
cur[VAR_8 + VAR_9*VAR_14] = VAR_10; break; case 3:
av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid opcode seen @%d\n",VAR_3); return -1; } break; } VAR_7 <<= 2; cur  += 4; prev += 4; VAR_6++; if(VAR_6 == (VAR_14 >> 2)){ VAR_6 = 0; cur  += VAR_14 * 3; prev += VAR_14 * 3; } } return 0; }