static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,

                                 int point_transform)

{

    int i, mb_x, mb_y;

    const int nb_components=s->nb_components;

    int bits= (s->bits+7)&~7;

    int resync_mb_y = 0;

    int resync_mb_x = 0;



    point_transform += bits - s->bits;



    av_assert0(nb_components>=1 && nb_components<=3);



    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {

        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {

            if (s->restart_interval && !s->restart_count){

                s->restart_count = s->restart_interval;

                resync_mb_x = mb_x;

                resync_mb_y = mb_y;

            }



            if(!mb_x || mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || s->interlaced){

                int toprow  = mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x;

                int leftcol = !mb_x || mb_y == resync_mb_y && mb_x == resync_mb_x;

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

                    uint8_t *ptr;

                    uint16_t *ptr16;

                    int n, h, v, x, y, c, j, linesize;

                    n = s->nb_blocks[i];

                    c = s->comp_index[i];

                    h = s->h_scount[i];

                    v = s->v_scount[i];

                    x = 0;

                    y = 0;

                    linesize= s->linesize[c];



                    if(bits>8) linesize /= 2;



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

                        int pred, dc;



                        dc = mjpeg_decode_dc(s, s->dc_index[i]);

                        if(dc == 0xFFFF)

                            return -1;

                        if(bits<=8){

                        ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap

                        if(y==0 && toprow){

                            if(x==0 && leftcol){

                                pred= 1 << (bits - 1);

                            }else{

                                pred= ptr[-1];

                            }

                        }else{

                            if(x==0 && leftcol){

                                pred= ptr[-linesize];

                            }else{

                                PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);

                            }

                        }



                        if (s->interlaced && s->bottom_field)

                            ptr += linesize >> 1;

                        pred &= (-1)<<(8-s->bits);

                        *ptr= pred + (dc << point_transform);

                        }else{

                            ptr16 = (uint16_t*)(s->picture.data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap

                            if(y==0 && toprow){

                                if(x==0 && leftcol){

                                    pred= 1 << (bits - 1);

                                }else{

                                    pred= ptr16[-1];

                                }

                            }else{

                                if(x==0 && leftcol){

                                    pred= ptr16[-linesize];

                                }else{

                                    PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);

                                }

                            }



                            if (s->interlaced && s->bottom_field)

                                ptr16 += linesize >> 1;

                            pred &= (-1)<<(16-s->bits);

                            *ptr16= pred + (dc << point_transform);

                        }

                        if (++x == h) {

                            x = 0;

                            y++;

                        }

                    }

                }

            } else {

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

                    uint8_t *ptr;

                    uint16_t *ptr16;

                    int n, h, v, x, y, c, j, linesize, dc;

                    n        = s->nb_blocks[i];

                    c        = s->comp_index[i];

                    h        = s->h_scount[i];

                    v        = s->v_scount[i];

                    x        = 0;

                    y        = 0;

                    linesize = s->linesize[c];



                    if(bits>8) linesize /= 2;



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

                        int pred;



                        dc = mjpeg_decode_dc(s, s->dc_index[i]);

                        if(dc == 0xFFFF)

                            return -1;

                        if(bits<=8){

                            ptr = s->picture.data[c] +

                              (linesize * (v * mb_y + y)) +

                              (h * mb_x + x); //FIXME optimize this crap

                            PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);



                            pred &= (-1)<<(8-s->bits);

                            *ptr = pred + (dc << point_transform);

                        }else{

                            ptr16 = (uint16_t*)(s->picture.data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap

                            PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);



                            pred &= (-1)<<(16-s->bits);

                            *ptr16= pred + (dc << point_transform);

                        }



                        if (++x == h) {

                            x = 0;

                            y++;

                        }

                    }

                }

            }

            if (s->restart_interval && !--s->restart_count) {

                align_get_bits(&s->gb);

                skip_bits(&s->gb, 16); /* skip RSTn */

            }

        }

    }

    return 0;

}

static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,

                                 int point_transform)

{

    int i, mb_x, mb_y;

    const int nb_components=s->nb_components;

    int bits= (s->bits+7)&~7;

    int resync_mb_y = 0;

    int resync_mb_x = 0;



    point_transform += bits - s->bits;



    av_assert0(nb_components>=1 && nb_components<=3);



    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {

        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {

            if (s->restart_interval && !s->restart_count){

                s->restart_count = s->restart_interval;

                resync_mb_x = mb_x;

                resync_mb_y = mb_y;

            }



            if(!mb_x || mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || s->interlaced){

                int toprow  = mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x;

                int leftcol = !mb_x || mb_y == resync_mb_y && mb_x == resync_mb_x;

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

                    uint8_t *ptr;

                    uint16_t *ptr16;

                    int n, h, v, x, y, c, j, linesize;

                    n = s->nb_blocks[i];

                    c = s->comp_index[i];

                    h = s->h_scount[i];

                    v = s->v_scount[i];

                    x = 0;

                    y = 0;

                    linesize= s->linesize[c];



                    if(bits>8) linesize /= 2;



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

                        int pred, dc;



                        dc = mjpeg_decode_dc(s, s->dc_index[i]);

                        if(dc == 0xFFFF)

                            return -1;

                        if(bits<=8){

                        ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); 

                        if(y==0 && toprow){

                            if(x==0 && leftcol){

                                pred= 1 << (bits - 1);

                            }else{

                                pred= ptr[-1];

                            }

                        }else{

                            if(x==0 && leftcol){

                                pred= ptr[-linesize];

                            }else{

                                PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);

                            }

                        }



                        if (s->interlaced && s->bottom_field)

                            ptr += linesize >> 1;

                        pred &= (-1)<<(8-s->bits);

                        *ptr= pred + (dc << point_transform);

                        }else{

                            ptr16 = (uint16_t*)(s->picture.data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); 

                            if(y==0 && toprow){

                                if(x==0 && leftcol){

                                    pred= 1 << (bits - 1);

                                }else{

                                    pred= ptr16[-1];

                                }

                            }else{

                                if(x==0 && leftcol){

                                    pred= ptr16[-linesize];

                                }else{

                                    PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);

                                }

                            }



                            if (s->interlaced && s->bottom_field)

                                ptr16 += linesize >> 1;

                            pred &= (-1)<<(16-s->bits);

                            *ptr16= pred + (dc << point_transform);

                        }

                        if (++x == h) {

                            x = 0;

                            y++;

                        }

                    }

                }

            } else {

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

                    uint8_t *ptr;

                    uint16_t *ptr16;

                    int n, h, v, x, y, c, j, linesize, dc;

                    n        = s->nb_blocks[i];

                    c        = s->comp_index[i];

                    h        = s->h_scount[i];

                    v        = s->v_scount[i];

                    x        = 0;

                    y        = 0;

                    linesize = s->linesize[c];



                    if(bits>8) linesize /= 2;



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

                        int pred;



                        dc = mjpeg_decode_dc(s, s->dc_index[i]);

                        if(dc == 0xFFFF)

                            return -1;

                        if(bits<=8){

                            ptr = s->picture.data[c] +

                              (linesize * (v * mb_y + y)) +

                              (h * mb_x + x); 

                            PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);



                            pred &= (-1)<<(8-s->bits);

                            *ptr = pred + (dc << point_transform);

                        }else{

                            ptr16 = (uint16_t*)(s->picture.data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); 

                            PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);



                            pred &= (-1)<<(16-s->bits);

                            *ptr16= pred + (dc << point_transform);

                        }



                        if (++x == h) {

                            x = 0;

                            y++;

                        }

                    }

                }

            }

            if (s->restart_interval && !--s->restart_count) {

                align_get_bits(&s->gb);

                skip_bits(&s->gb, 16); 

            }

        }

    }

    return 0;

}

static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor,     const int nb_components=s->nb_components;
static int FUNC_0(MJpegDecodeContext *VAR_0, int VAR_1,

                                 int VAR_2)

{

    int VAR_3, VAR_4, VAR_5;

    const int VAR_6=VAR_0->VAR_6;

    int VAR_7= (VAR_0->VAR_7+7)&~7;

    int VAR_8 = 0;

    int VAR_9 = 0;



    VAR_2 += VAR_7 - VAR_0->VAR_7;



    av_assert0(VAR_6>=1 && VAR_6<=3);



    for (VAR_5 = 0; VAR_5 < VAR_0->mb_height; VAR_5++) {

        for (VAR_4 = 0; VAR_4 < VAR_0->mb_width; VAR_4++) {

            if (VAR_0->restart_interval && !VAR_0->restart_count){

                VAR_0->restart_count = VAR_0->restart_interval;

                VAR_9 = VAR_4;

                VAR_8 = VAR_5;

            }



            if(!VAR_4 || VAR_5 == VAR_8 || VAR_5 == VAR_8+1 && VAR_4 < VAR_9 || VAR_0->interlaced){

                int toprow  = VAR_5 == VAR_8 || VAR_5 == VAR_8+1 && VAR_4 < VAR_9;

                int leftcol = !VAR_4 || VAR_5 == VAR_8 && VAR_4 == VAR_9;

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

                    uint8_t *ptr;

                    uint16_t *ptr16;

                    int n, h, v, x, y, c, j, linesize;

                    n = VAR_0->nb_blocks[VAR_3];

                    c = VAR_0->comp_index[VAR_3];

                    h = VAR_0->h_scount[VAR_3];

                    v = VAR_0->v_scount[VAR_3];

                    x = 0;

                    y = 0;

                    linesize= VAR_0->linesize[c];



                    if(VAR_7>8) linesize /= 2;



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

                        int pred, dc;



                        dc = mjpeg_decode_dc(VAR_0, VAR_0->dc_index[VAR_3]);

                        if(dc == 0xFFFF)

                            return -1;

                        if(VAR_7<=8){

                        ptr = VAR_0->picture.data[c] + (linesize * (v * VAR_5 + y)) + (h * VAR_4 + x); 

                        if(y==0 && toprow){

                            if(x==0 && leftcol){

                                pred= 1 << (VAR_7 - 1);

                            }else{

                                pred= ptr[-1];

                            }

                        }else{

                            if(x==0 && leftcol){

                                pred= ptr[-linesize];

                            }else{

                                PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], VAR_1);

                            }

                        }



                        if (VAR_0->interlaced && VAR_0->bottom_field)

                            ptr += linesize >> 1;

                        pred &= (-1)<<(8-VAR_0->VAR_7);

                        *ptr= pred + (dc << VAR_2);

                        }else{

                            ptr16 = (uint16_t*)(VAR_0->picture.data[c] + 2*(linesize * (v * VAR_5 + y)) + 2*(h * VAR_4 + x)); 

                            if(y==0 && toprow){

                                if(x==0 && leftcol){

                                    pred= 1 << (VAR_7 - 1);

                                }else{

                                    pred= ptr16[-1];

                                }

                            }else{

                                if(x==0 && leftcol){

                                    pred= ptr16[-linesize];

                                }else{

                                    PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], VAR_1);

                                }

                            }



                            if (VAR_0->interlaced && VAR_0->bottom_field)

                                ptr16 += linesize >> 1;

                            pred &= (-1)<<(16-VAR_0->VAR_7);

                            *ptr16= pred + (dc << VAR_2);

                        }

                        if (++x == h) {

                            x = 0;

                            y++;

                        }

                    }

                }

            } else {

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

                    uint8_t *ptr;

                    uint16_t *ptr16;

                    int n, h, v, x, y, c, j, linesize, dc;

                    n        = VAR_0->nb_blocks[VAR_3];

                    c        = VAR_0->comp_index[VAR_3];

                    h        = VAR_0->h_scount[VAR_3];

                    v        = VAR_0->v_scount[VAR_3];

                    x        = 0;

                    y        = 0;

                    linesize = VAR_0->linesize[c];



                    if(VAR_7>8) linesize /= 2;



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

                        int pred;



                        dc = mjpeg_decode_dc(VAR_0, VAR_0->dc_index[VAR_3]);

                        if(dc == 0xFFFF)

                            return -1;

                        if(VAR_7<=8){

                            ptr = VAR_0->picture.data[c] +

                              (linesize * (v * VAR_5 + y)) +

                              (h * VAR_4 + x); 

                            PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], VAR_1);



                            pred &= (-1)<<(8-VAR_0->VAR_7);

                            *ptr = pred + (dc << VAR_2);

                        }else{

                            ptr16 = (uint16_t*)(VAR_0->picture.data[c] + 2*(linesize * (v * VAR_5 + y)) + 2*(h * VAR_4 + x)); 

                            PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], VAR_1);



                            pred &= (-1)<<(16-VAR_0->VAR_7);

                            *ptr16= pred + (dc << VAR_2);

                        }



                        if (++x == h) {

                            x = 0;

                            y++;

                        }

                    }

                }

            }

            if (VAR_0->restart_interval && !--VAR_0->restart_count) {

                align_get_bits(&VAR_0->gb);

                skip_bits(&VAR_0->gb, 16); 

            }

        }

    }

    return 0;

}

static int FUNC_0(MJpegDecodeContext *VAR_0, int VAR_1,
int VAR_2)
{ int VAR_3, VAR_4, VAR_5; const int VAR_6=VAR_0->VAR_6; int VAR_7= (VAR_0->VAR_7+7)&~7; int VAR_8 = 0; int VAR_9 = 0; VAR_2 += VAR_7 - VAR_0->VAR_7; av_assert0(VAR_6>=1 && VAR_6<=3); for (VAR_5 = 0; VAR_5 < VAR_0->mb_height; VAR_5++) { for (VAR_4 = 0; VAR_4 < VAR_0->mb_width; VAR_4++) { if (VAR_0->restart_interval && !VAR_0->restart_count){ VAR_0->restart_count = VAR_0->restart_interval; VAR_9 = VAR_4; VAR_8 = VAR_5; } if(!VAR_4 || VAR_5 == VAR_8 || VAR_5 == VAR_8+1 && VAR_4 < VAR_9 || VAR_0->interlaced){ int toprow  = VAR_5 == VAR_8 || VAR_5 == VAR_8+1 && VAR_4 < VAR_9; int leftcol = !VAR_4 || VAR_5 == VAR_8 && VAR_4 == VAR_9; for (VAR_3 = 0; VAR_3 < VAR_6; VAR_3++) { uint8_t *ptr; uint16_t *ptr16; int n, h, v, x, y, c, j, linesize; n = VAR_0->nb_blocks[VAR_3]; c = VAR_0->comp_index[VAR_3]; h = VAR_0->h_scount[VAR_3]; v = VAR_0->v_scount[VAR_3]; x = 0; y = 0; linesize= VAR_0->linesize[c]; if(VAR_7>8) linesize /= 2; for(j=0; j<n; j++) { int pred, dc; dc = mjpeg_decode_dc(VAR_0, VAR_0->dc_index[VAR_3]); if(dc == 0xFFFF)
return -1; if(VAR_7<=8){ ptr = VAR_0->picture.data[c] + (linesize * (v * VAR_5 + y)) + (h * VAR_4 + x); if(y==0 && toprow){ if(x==0 && leftcol){ pred= 1 << (VAR_7 - 1); }else{ pred= ptr[-1]; } }else{ if(x==0 && leftcol){ pred= ptr[-linesize]; }else{ PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], VAR_1); } } if (VAR_0->interlaced && VAR_0->bottom_field)
ptr += linesize >> 1; pred &= (-1)<<(8-VAR_0->VAR_7); *ptr= pred + (dc << VAR_2); }else{ ptr16 = (uint16_t*)(VAR_0->picture.data[c] + 2*(linesize * (v * VAR_5 + y)) + 2*(h * VAR_4 + x)); if(y==0 && toprow){ if(x==0 && leftcol){ pred= 1 << (VAR_7 - 1); }else{ pred= ptr16[-1]; } }else{ if(x==0 && leftcol){ pred= ptr16[-linesize]; }else{ PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], VAR_1); } } if (VAR_0->interlaced && VAR_0->bottom_field)
ptr16 += linesize >> 1; pred &= (-1)<<(16-VAR_0->VAR_7); *ptr16= pred + (dc << VAR_2); } if (++x == h) { x = 0; y++; } } } } else { for (VAR_3 = 0; VAR_3 < VAR_6; VAR_3++) { uint8_t *ptr; uint16_t *ptr16; int n, h, v, x, y, c, j, linesize, dc; n        = VAR_0->nb_blocks[VAR_3]; c        = VAR_0->comp_index[VAR_3]; h        = VAR_0->h_scount[VAR_3]; v        = VAR_0->v_scount[VAR_3]; x        = 0; y        = 0; linesize = VAR_0->linesize[c]; if(VAR_7>8) linesize /= 2; for (j = 0; j < n; j++) { int pred; dc = mjpeg_decode_dc(VAR_0, VAR_0->dc_index[VAR_3]); if(dc == 0xFFFF)
return -1; if(VAR_7<=8){ ptr = VAR_0->picture.data[c] +
(linesize * (v * VAR_5 + y)) +
(h * VAR_4 + x); PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], VAR_1); pred &= (-1)<<(8-VAR_0->VAR_7); *ptr = pred + (dc << VAR_2); }else{ ptr16 = (uint16_t*)(VAR_0->picture.data[c] + 2*(linesize * (v * VAR_5 + y)) + 2*(h * VAR_4 + x)); PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], VAR_1); pred &= (-1)<<(16-VAR_0->VAR_7); *ptr16= pred + (dc << VAR_2); } if (++x == h) { x = 0; y++; } } } } if (VAR_0->restart_interval && !--VAR_0->restart_count) { align_get_bits(&VAR_0->gb); skip_bits(&VAR_0->gb, 16); } } } return 0; }