static void qpeg_decode_inter(QpegContext *qctx, uint8_t *dst,

                              int stride, int width, int height,

                              int delta, const uint8_t *ctable,

                              uint8_t *refdata)

{

    int i, j;

    int code;

    int filled = 0;

    int orig_height;



    /* copy prev frame */

    for(i = 0; i < height; i++)

        memcpy(refdata + (i * width), dst + (i * stride), width);



    orig_height = height;

    height--;

    dst = dst + height * stride;



    while ((bytestream2_get_bytes_left(&qctx->buffer) > 0) && (height >= 0)) {

        code = bytestream2_get_byte(&qctx->buffer);



        if(delta) {

            /* motion compensation */

            while((code & 0xF0) == 0xF0) {

                if(delta == 1) {

                    int me_idx;

                    int me_w, me_h, me_x, me_y;

                    uint8_t *me_plane;

                    int corr, val;



                    /* get block size by index */

                    me_idx = code & 0xF;

                    me_w = qpeg_table_w[me_idx];

                    me_h = qpeg_table_h[me_idx];



                    /* extract motion vector */

                    corr = bytestream2_get_byte(&qctx->buffer);



                    val = corr >> 4;

                    if(val > 7)

                        val -= 16;

                    me_x = val;



                    val = corr & 0xF;

                    if(val > 7)

                        val -= 16;

                    me_y = val;



                    /* check motion vector */

                    if ((me_x + filled < 0) || (me_x + me_w + filled > width) ||

                       (height - me_y - me_h < 0) || (height - me_y > orig_height) ||

                       (filled + me_w > width) || (height - me_h < 0))

                        av_log(NULL, AV_LOG_ERROR, "Bogus motion vector (%i,%i), block size %ix%i at %i,%i\n",

                               me_x, me_y, me_w, me_h, filled, height);

                    else {

                        /* do motion compensation */

                        me_plane = refdata + (filled + me_x) + (height - me_y) * width;

                        for(j = 0; j < me_h; j++) {

                            for(i = 0; i < me_w; i++)

                                dst[filled + i - (j * stride)] = me_plane[i - (j * width)];

                        }

                    }

                }

                code = bytestream2_get_byte(&qctx->buffer);

            }

        }



        if(code == 0xE0) /* end-of-picture code */

            break;

        if(code > 0xE0) { /* run code: 0xE1..0xFF */

            int p;



            code &= 0x1F;

            p = bytestream2_get_byte(&qctx->buffer);

            for(i = 0; i <= code; i++) {

                dst[filled++] = p;

                if(filled >= width) {

                    filled = 0;

                    dst -= stride;

                    height--;

                    if (height < 0)

                        break;

                }

            }

        } else if(code >= 0xC0) { /* copy code: 0xC0..0xDF */

            code &= 0x1F;



            for(i = 0; i <= code; i++) {

                dst[filled++] = bytestream2_get_byte(&qctx->buffer);

                if(filled >= width) {

                    filled = 0;

                    dst -= stride;

                    height--;

                    if (height < 0)

                        break;

                }

            }

        } else if(code >= 0x80) { /* skip code: 0x80..0xBF */

            int skip;



            code &= 0x3F;

            /* codes 0x80 and 0x81 are actually escape codes,

               skip value minus constant is in the next byte */

            if(!code)

                skip = bytestream2_get_byte(&qctx->buffer) +  64;

            else if(code == 1)

                skip = bytestream2_get_byte(&qctx->buffer) + 320;

            else

                skip = code;

            filled += skip;

            while( filled >= width) {

                filled -= width;

                dst -= stride;

                height--;

                if(height < 0)

                    break;

            }

        } else {

            /* zero code treated as one-pixel skip */

            if(code) {

                dst[filled++] = ctable[code & 0x7F];

            }

            else

                filled++;

            if(filled >= width) {

                filled = 0;

                dst -= stride;

                height--;

            }

        }

    }

}

static void qpeg_decode_inter(QpegContext *qctx, uint8_t *dst,

                              int stride, int width, int height,

                              int delta, const uint8_t *ctable,

                              uint8_t *refdata)

{

    int i, j;

    int code;

    int filled = 0;

    int orig_height;



    

    for(i = 0; i < height; i++)

        memcpy(refdata + (i * width), dst + (i * stride), width);



    orig_height = height;

    height--;

    dst = dst + height * stride;



    while ((bytestream2_get_bytes_left(&qctx->buffer) > 0) && (height >= 0)) {

        code = bytestream2_get_byte(&qctx->buffer);



        if(delta) {

            

            while((code & 0xF0) == 0xF0) {

                if(delta == 1) {

                    int me_idx;

                    int me_w, me_h, me_x, me_y;

                    uint8_t *me_plane;

                    int corr, val;



                    

                    me_idx = code & 0xF;

                    me_w = qpeg_table_w[me_idx];

                    me_h = qpeg_table_h[me_idx];



                    

                    corr = bytestream2_get_byte(&qctx->buffer);



                    val = corr >> 4;

                    if(val > 7)

                        val -= 16;

                    me_x = val;



                    val = corr & 0xF;

                    if(val > 7)

                        val -= 16;

                    me_y = val;



                    

                    if ((me_x + filled < 0) || (me_x + me_w + filled > width) ||

                       (height - me_y - me_h < 0) || (height - me_y > orig_height) ||

                       (filled + me_w > width) || (height - me_h < 0))

                        av_log(NULL, AV_LOG_ERROR, "Bogus motion vector (%i,%i), block size %ix%i at %i,%i\n",

                               me_x, me_y, me_w, me_h, filled, height);

                    else {

                        

                        me_plane = refdata + (filled + me_x) + (height - me_y) * width;

                        for(j = 0; j < me_h; j++) {

                            for(i = 0; i < me_w; i++)

                                dst[filled + i - (j * stride)] = me_plane[i - (j * width)];

                        }

                    }

                }

                code = bytestream2_get_byte(&qctx->buffer);

            }

        }



        if(code == 0xE0) 

            break;

        if(code > 0xE0) { 

            int p;



            code &= 0x1F;

            p = bytestream2_get_byte(&qctx->buffer);

            for(i = 0; i <= code; i++) {

                dst[filled++] = p;

                if(filled >= width) {

                    filled = 0;

                    dst -= stride;

                    height--;

                    if (height < 0)

                        break;

                }

            }

        } else if(code >= 0xC0) { 

            code &= 0x1F;



            for(i = 0; i <= code; i++) {

                dst[filled++] = bytestream2_get_byte(&qctx->buffer);

                if(filled >= width) {

                    filled = 0;

                    dst -= stride;

                    height--;

                    if (height < 0)

                        break;

                }

            }

        } else if(code >= 0x80) { 

            int skip;



            code &= 0x3F;

            



            if(!code)

                skip = bytestream2_get_byte(&qctx->buffer) +  64;

            else if(code == 1)

                skip = bytestream2_get_byte(&qctx->buffer) + 320;

            else

                skip = code;

            filled += skip;

            while( filled >= width) {

                filled -= width;

                dst -= stride;

                height--;

                if(height < 0)

                    break;

            }

        } else {

            

            if(code) {

                dst[filled++] = ctable[code & 0x7F];

            }

            else

                filled++;

            if(filled >= width) {

                filled = 0;

                dst -= stride;

                height--;

            }

        }

    }

}

                       (height - me_y - me_h < 0) || (height - me_y > orig_height) ||                         av_log(NULL, AV_LOG_ERROR, "Bogus motion vector (%i,%i), block size %ix%i at %i,%i\n",
static void FUNC_0(QpegContext *VAR_0, uint8_t *VAR_1,

                              int VAR_2, int VAR_3, int VAR_4,

                              int VAR_5, const uint8_t *VAR_6,

                              uint8_t *VAR_7)

{

    int VAR_8, VAR_9;

    int VAR_10;

    int VAR_11 = 0;

    int VAR_12;



    

    for(VAR_8 = 0; VAR_8 < VAR_4; VAR_8++)

        memcpy(VAR_7 + (VAR_8 * VAR_3), VAR_1 + (VAR_8 * VAR_2), VAR_3);



    VAR_12 = VAR_4;

    VAR_4--;

    VAR_1 = VAR_1 + VAR_4 * VAR_2;



    while ((bytestream2_get_bytes_left(&VAR_0->buffer) > 0) && (VAR_4 >= 0)) {

        VAR_10 = bytestream2_get_byte(&VAR_0->buffer);



        if(VAR_5) {

            

            while((VAR_10 & 0xF0) == 0xF0) {

                if(VAR_5 == 1) {

                    int VAR_13;

                    int VAR_14, VAR_15, VAR_16, VAR_17;

                    uint8_t *me_plane;

                    int VAR_18, VAR_19;



                    

                    VAR_13 = VAR_10 & 0xF;

                    VAR_14 = qpeg_table_w[VAR_13];

                    VAR_15 = qpeg_table_h[VAR_13];



                    

                    VAR_18 = bytestream2_get_byte(&VAR_0->buffer);



                    VAR_19 = VAR_18 >> 4;

                    if(VAR_19 > 7)

                        VAR_19 -= 16;

                    VAR_16 = VAR_19;



                    VAR_19 = VAR_18 & 0xF;

                    if(VAR_19 > 7)

                        VAR_19 -= 16;

                    VAR_17 = VAR_19;



                    

                    if ((VAR_16 + VAR_11 < 0) || (VAR_16 + VAR_14 + VAR_11 > VAR_3) ||

                       (VAR_4 - VAR_17 - VAR_15 < 0) || (VAR_4 - VAR_17 > VAR_12) ||

                       (VAR_11 + VAR_14 > VAR_3) || (VAR_4 - VAR_15 < 0))

                        av_log(NULL, AV_LOG_ERROR, "Bogus motion vector (%VAR_8,%VAR_8), block size %ix%VAR_8 at %VAR_8,%VAR_8\n",

                               VAR_16, VAR_17, VAR_14, VAR_15, VAR_11, VAR_4);

                    else {

                        

                        me_plane = VAR_7 + (VAR_11 + VAR_16) + (VAR_4 - VAR_17) * VAR_3;

                        for(VAR_9 = 0; VAR_9 < VAR_15; VAR_9++) {

                            for(VAR_8 = 0; VAR_8 < VAR_14; VAR_8++)

                                VAR_1[VAR_11 + VAR_8 - (VAR_9 * VAR_2)] = me_plane[VAR_8 - (VAR_9 * VAR_3)];

                        }

                    }

                }

                VAR_10 = bytestream2_get_byte(&VAR_0->buffer);

            }

        }



        if(VAR_10 == 0xE0) 

            break;

        if(VAR_10 > 0xE0) { 

            int VAR_20;



            VAR_10 &= 0x1F;

            VAR_20 = bytestream2_get_byte(&VAR_0->buffer);

            for(VAR_8 = 0; VAR_8 <= VAR_10; VAR_8++) {

                VAR_1[VAR_11++] = VAR_20;

                if(VAR_11 >= VAR_3) {

                    VAR_11 = 0;

                    VAR_1 -= VAR_2;

                    VAR_4--;

                    if (VAR_4 < 0)

                        break;

                }

            }

        } else if(VAR_10 >= 0xC0) { 

            VAR_10 &= 0x1F;



            for(VAR_8 = 0; VAR_8 <= VAR_10; VAR_8++) {

                VAR_1[VAR_11++] = bytestream2_get_byte(&VAR_0->buffer);

                if(VAR_11 >= VAR_3) {

                    VAR_11 = 0;

                    VAR_1 -= VAR_2;

                    VAR_4--;

                    if (VAR_4 < 0)

                        break;

                }

            }

        } else if(VAR_10 >= 0x80) { 

            int VAR_21;



            VAR_10 &= 0x3F;

            



            if(!VAR_10)

                VAR_21 = bytestream2_get_byte(&VAR_0->buffer) +  64;

            else if(VAR_10 == 1)

                VAR_21 = bytestream2_get_byte(&VAR_0->buffer) + 320;

            else

                VAR_21 = VAR_10;

            VAR_11 += VAR_21;

            while( VAR_11 >= VAR_3) {

                VAR_11 -= VAR_3;

                VAR_1 -= VAR_2;

                VAR_4--;

                if(VAR_4 < 0)

                    break;

            }

        } else {

            

            if(VAR_10) {

                VAR_1[VAR_11++] = VAR_6[VAR_10 & 0x7F];

            }

            else

                VAR_11++;

            if(VAR_11 >= VAR_3) {

                VAR_11 = 0;

                VAR_1 -= VAR_2;

                VAR_4--;

            }

        }

    }

}

static void FUNC_0(QpegContext *VAR_0, uint8_t *VAR_1,
int VAR_2, int VAR_3, int VAR_4,
int VAR_5, const uint8_t *VAR_6,
uint8_t *VAR_7)
{ int VAR_8, VAR_9; int VAR_10; int VAR_11 = 0; int VAR_12; for(VAR_8 = 0; VAR_8 < VAR_4; VAR_8++) memcpy(VAR_7 + (VAR_8 * VAR_3), VAR_1 + (VAR_8 * VAR_2), VAR_3); VAR_12 = VAR_4; VAR_4--; VAR_1 = VAR_1 + VAR_4 * VAR_2; while ((bytestream2_get_bytes_left(&VAR_0->buffer) > 0) && (VAR_4 >= 0)) { VAR_10 = bytestream2_get_byte(&VAR_0->buffer); if(VAR_5) { while((VAR_10 & 0xF0) == 0xF0) { if(VAR_5 == 1) { int VAR_13; int VAR_14, VAR_15, VAR_16, VAR_17; uint8_t *me_plane; int VAR_18, VAR_19; VAR_13 = VAR_10 & 0xF; VAR_14 = qpeg_table_w[VAR_13]; VAR_15 = qpeg_table_h[VAR_13]; VAR_18 = bytestream2_get_byte(&VAR_0->buffer); VAR_19 = VAR_18 >> 4; if(VAR_19 > 7)
VAR_19 -= 16; VAR_16 = VAR_19; VAR_19 = VAR_18 & 0xF; if(VAR_19 > 7)
VAR_19 -= 16; VAR_17 = VAR_19; if ((VAR_16 + VAR_11 < 0) || (VAR_16 + VAR_14 + VAR_11 > VAR_3) ||
(VAR_4 - VAR_17 - VAR_15 < 0) || (VAR_4 - VAR_17 > VAR_12) ||
(VAR_11 + VAR_14 > VAR_3) || (VAR_4 - VAR_15 < 0))
av_log(NULL, AV_LOG_ERROR, "Bogus motion vector (%VAR_8,%VAR_8), block size %ix%VAR_8 at %VAR_8,%VAR_8\n",
VAR_16, VAR_17, VAR_14, VAR_15, VAR_11, VAR_4); else { me_plane = VAR_7 + (VAR_11 + VAR_16) + (VAR_4 - VAR_17) * VAR_3; for(VAR_9 = 0; VAR_9 < VAR_15; VAR_9++) { for(VAR_8 = 0; VAR_8 < VAR_14; VAR_8++) VAR_1[VAR_11 + VAR_8 - (VAR_9 * VAR_2)] = me_plane[VAR_8 - (VAR_9 * VAR_3)]; } } } VAR_10 = bytestream2_get_byte(&VAR_0->buffer); } } if(VAR_10 == 0xE0)
break; if(VAR_10 > 0xE0) { int VAR_20; VAR_10 &= 0x1F; VAR_20 = bytestream2_get_byte(&VAR_0->buffer); for(VAR_8 = 0; VAR_8 <= VAR_10; VAR_8++) { VAR_1[VAR_11++] = VAR_20; if(VAR_11 >= VAR_3) { VAR_11 = 0; VAR_1 -= VAR_2; VAR_4--; if (VAR_4 < 0)
break; } } } else if(VAR_10 >= 0xC0) { VAR_10 &= 0x1F; for(VAR_8 = 0; VAR_8 <= VAR_10; VAR_8++) { VAR_1[VAR_11++] = bytestream2_get_byte(&VAR_0->buffer); if(VAR_11 >= VAR_3) { VAR_11 = 0; VAR_1 -= VAR_2; VAR_4--; if (VAR_4 < 0)
break; } } } else if(VAR_10 >= 0x80) { int VAR_21; VAR_10 &= 0x3F; if(!VAR_10)
VAR_21 = bytestream2_get_byte(&VAR_0->buffer) +  64; else if(VAR_10 == 1)
VAR_21 = bytestream2_get_byte(&VAR_0->buffer) + 320; else
VAR_21 = VAR_10; VAR_11 += VAR_21; while( VAR_11 >= VAR_3) { VAR_11 -= VAR_3; VAR_1 -= VAR_2; VAR_4--; if(VAR_4 < 0)
break; } } else { if(VAR_10) { VAR_1[VAR_11++] = VAR_6[VAR_10 & 0x7F]; } else
VAR_11++; if(VAR_11 >= VAR_3) { VAR_11 = 0; VAR_1 -= VAR_2; VAR_4--; } } } }