static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int predictor, int point_transform)
{
    int i, mb_x, mb_y;
    uint16_t (*buffer)[4];
    int left[4], top[4], topleft[4];
    const int linesize = s->linesize[0];
    const int mask     = (1 << s->bits) - 1;
    int resync_mb_y = 0;
    int resync_mb_x = 0;
    s->restart_count = s->restart_interval;
    av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size,
                   (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0]));
    buffer = s->ljpeg_buffer;
    for (i = 0; i < 4; i++)
        buffer[0][i] = 1 << (s->bits - 1);
    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
        uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);
        if (s->interlaced && s->bottom_field)
            ptr += linesize >> 1;
        for (i = 0; i < 4; i++)
            top[i] = left[i] = topleft[i] = buffer[0][i];
        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
            int modified_predictor = predictor;
            if (s->restart_interval && !s->restart_count){
                s->restart_count = s->restart_interval;
                resync_mb_x = mb_x;
                resync_mb_y = mb_y;
                for(i=0; i<4; i++)
                    top[i] = left[i]= topleft[i]= 1 << (s->bits - 1);
            }
            if (mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || !mb_x)
                modified_predictor = 1;
            for (i=0;i<nb_components;i++) {
                int pred, dc;
                topleft[i] = top[i];
                top[i]     = buffer[mb_x][i];
                PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
                dc = mjpeg_decode_dc(s, s->dc_index[i]);
                if(dc == 0xFFFF)
                    return -1;
                left[i] = buffer[mb_x][i] =
                    mask & (pred + (dc << point_transform));
            }
            if (s->restart_interval && !--s->restart_count) {
                align_get_bits(&s->gb);
                skip_bits(&s->gb, 16); /* skip RSTn */
            }
        }
        if (s->nb_components == 4) {
            for(i=0; i<nb_components; i++) {
                int c= s->comp_index[i];
                for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
                    ptr[4*mb_x+3-c] = buffer[mb_x][i];
                }
            }
        } else if (s->rct) {
            for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
                ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200) >> 2);
                ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
                ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
            }
        } else if (s->pegasus_rct) {
            for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
                ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2]) >> 2);
                ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
                ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
            }
        } else {
            for(i=0; i<nb_components; i++) {
                int c= s->comp_index[i];
                for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
                    ptr[3*mb_x+2-c] = buffer[mb_x][i];
                }
            }
        }
    }
    return 0;
}
static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int predictor, int point_transform)
{
    int i, mb_x, mb_y;
    uint16_t (*buffer)[4];
    int left[4], top[4], topleft[4];
    const int linesize = s->linesize[0];
    const int mask     = (1 << s->bits) - 1;
    int resync_mb_y = 0;
    int resync_mb_x = 0;
    s->restart_count = s->restart_interval;
    av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size,
                   (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0]));
    buffer = s->ljpeg_buffer;
    for (i = 0; i < 4; i++)
        buffer[0][i] = 1 << (s->bits - 1);
    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
        uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);
        if (s->interlaced && s->bottom_field)
            ptr += linesize >> 1;
        for (i = 0; i < 4; i++)
            top[i] = left[i] = topleft[i] = buffer[0][i];
        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
            int modified_predictor = predictor;
            if (s->restart_interval && !s->restart_count){
                s->restart_count = s->restart_interval;
                resync_mb_x = mb_x;
                resync_mb_y = mb_y;
                for(i=0; i<4; i++)
                    top[i] = left[i]= topleft[i]= 1 << (s->bits - 1);
            }
            if (mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || !mb_x)
                modified_predictor = 1;
            for (i=0;i<nb_components;i++) {
                int pred, dc;
                topleft[i] = top[i];
                top[i]     = buffer[mb_x][i];
                PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
                dc = mjpeg_decode_dc(s, s->dc_index[i]);
                if(dc == 0xFFFF)
                    return -1;
                left[i] = buffer[mb_x][i] =
                    mask & (pred + (dc << point_transform));
            }
            if (s->restart_interval && !--s->restart_count) {
                align_get_bits(&s->gb);
                skip_bits(&s->gb, 16); 
            }
        }
        if (s->nb_components == 4) {
            for(i=0; i<nb_components; i++) {
                int c= s->comp_index[i];
                for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
                    ptr[4*mb_x+3-c] = buffer[mb_x][i];
                }
            }
        } else if (s->rct) {
            for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
                ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200) >> 2);
                ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
                ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
            }
        } else if (s->pegasus_rct) {
            for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
                ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2]) >> 2);
                ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
                ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
            }
        } else {
            for(i=0; i<nb_components; i++) {
                int c= s->comp_index[i];
                for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
                    ptr[3*mb_x+2-c] = buffer[mb_x][i];
                }
            }
        }
    }
    return 0;
}
static int FUNC_0(MJpegDecodeContext *VAR_0, int VAR_1, int VAR_2, int VAR_3)
{
    int VAR_4, VAR_5, VAR_6;
    uint16_t (*buffer)[4];
    int VAR_7[4], VAR_8[4], VAR_9[4];
    const int VAR_10 = VAR_0->VAR_10[0];
    const int VAR_11     = (1 << VAR_0->bits) - 1;
    int VAR_12 = 0;
    int VAR_13 = 0;
    VAR_0->restart_count = VAR_0->restart_interval;
    av_fast_malloc(&VAR_0->ljpeg_buffer, &VAR_0->ljpeg_buffer_size,
                   (unsigned)VAR_0->mb_width * 4 * sizeof(VAR_0->ljpeg_buffer[0][0]));
    buffer = VAR_0->ljpeg_buffer;
    for (VAR_4 = 0; VAR_4 < 4; VAR_4++)
        buffer[0][VAR_4] = 1 << (VAR_0->bits - 1);
    for (VAR_6 = 0; VAR_6 < VAR_0->mb_height; VAR_6++) {
        uint8_t *ptr = VAR_0->picture.data[0] + (VAR_10 * VAR_6);
        if (VAR_0->interlaced && VAR_0->bottom_field)
            ptr += VAR_10 >> 1;
        for (VAR_4 = 0; VAR_4 < 4; VAR_4++)
            VAR_8[VAR_4] = VAR_7[VAR_4] = VAR_9[VAR_4] = buffer[0][VAR_4];
        for (VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) {
            int modified_predictor = VAR_2;
            if (VAR_0->restart_interval && !VAR_0->restart_count){
                VAR_0->restart_count = VAR_0->restart_interval;
                VAR_13 = VAR_5;
                VAR_12 = VAR_6;
                for(VAR_4=0; VAR_4<4; VAR_4++)
                    VAR_8[VAR_4] = VAR_7[VAR_4]= VAR_9[VAR_4]= 1 << (VAR_0->bits - 1);
            }
            if (VAR_6 == VAR_12 || VAR_6 == VAR_12+1 && VAR_5 < VAR_13 || !VAR_5)
                modified_predictor = 1;
            for (VAR_4=0;VAR_4<VAR_1;VAR_4++) {
                int pred, dc;
                VAR_9[VAR_4] = VAR_8[VAR_4];
                VAR_8[VAR_4]     = buffer[VAR_5][VAR_4];
                PREDICT(pred, VAR_9[VAR_4], VAR_8[VAR_4], VAR_7[VAR_4], modified_predictor);
                dc = mjpeg_decode_dc(VAR_0, VAR_0->dc_index[VAR_4]);
                if(dc == 0xFFFF)
                    return -1;
                VAR_7[VAR_4] = buffer[VAR_5][VAR_4] =
                    VAR_11 & (pred + (dc << VAR_3));
            }
            if (VAR_0->restart_interval && !--VAR_0->restart_count) {
                align_get_bits(&VAR_0->gb);
                skip_bits(&VAR_0->gb, 16); 
            }
        }
        if (VAR_0->VAR_1 == 4) {
            for(VAR_4=0; VAR_4<VAR_1; VAR_4++) {
                int c= VAR_0->comp_index[VAR_4];
                for(VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) {
                    ptr[4*VAR_5+3-c] = buffer[VAR_5][VAR_4];
                }
            }
        } else if (VAR_0->rct) {
            for (VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) {
                ptr[3*VAR_5 + 1] = buffer[VAR_5][0] - ((buffer[VAR_5][1] + buffer[VAR_5][2] - 0x200) >> 2);
                ptr[3*VAR_5 + 0] = buffer[VAR_5][1] + ptr[3*VAR_5 + 1];
                ptr[3*VAR_5 + 2] = buffer[VAR_5][2] + ptr[3*VAR_5 + 1];
            }
        } else if (VAR_0->pegasus_rct) {
            for (VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) {
                ptr[3*VAR_5 + 1] = buffer[VAR_5][0] - ((buffer[VAR_5][1] + buffer[VAR_5][2]) >> 2);
                ptr[3*VAR_5 + 0] = buffer[VAR_5][1] + ptr[3*VAR_5 + 1];
                ptr[3*VAR_5 + 2] = buffer[VAR_5][2] + ptr[3*VAR_5 + 1];
            }
        } else {
            for(VAR_4=0; VAR_4<VAR_1; VAR_4++) {
                int c= VAR_0->comp_index[VAR_4];
                for(VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) {
                    ptr[3*VAR_5+2-c] = buffer[VAR_5][VAR_4];
                }
            }
        }
    }
    return 0;
}
static int FUNC_0(MJpegDecodeContext *VAR_0, int VAR_1, int VAR_2, int VAR_3)
{ int VAR_4, VAR_5, VAR_6; uint16_t (*buffer)[4]; int VAR_7[4], VAR_8[4], VAR_9[4]; const int VAR_10 = VAR_0->VAR_10[0]; const int VAR_11     = (1 << VAR_0->bits) - 1; int VAR_12 = 0; int VAR_13 = 0; VAR_0->restart_count = VAR_0->restart_interval; av_fast_malloc(&VAR_0->ljpeg_buffer, &VAR_0->ljpeg_buffer_size,
(unsigned)VAR_0->mb_width * 4 * sizeof(VAR_0->ljpeg_buffer[0][0])); buffer = VAR_0->ljpeg_buffer; for (VAR_4 = 0; VAR_4 < 4; VAR_4++) buffer[0][VAR_4] = 1 << (VAR_0->bits - 1); for (VAR_6 = 0; VAR_6 < VAR_0->mb_height; VAR_6++) { uint8_t *ptr = VAR_0->picture.data[0] + (VAR_10 * VAR_6); if (VAR_0->interlaced && VAR_0->bottom_field)
ptr += VAR_10 >> 1; for (VAR_4 = 0; VAR_4 < 4; VAR_4++) VAR_8[VAR_4] = VAR_7[VAR_4] = VAR_9[VAR_4] = buffer[0][VAR_4]; for (VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) { int modified_predictor = VAR_2; if (VAR_0->restart_interval && !VAR_0->restart_count){ VAR_0->restart_count = VAR_0->restart_interval; VAR_13 = VAR_5; VAR_12 = VAR_6; for(VAR_4=0; VAR_4<4; VAR_4++) VAR_8[VAR_4] = VAR_7[VAR_4]= VAR_9[VAR_4]= 1 << (VAR_0->bits - 1); } if (VAR_6 == VAR_12 || VAR_6 == VAR_12+1 && VAR_5 < VAR_13 || !VAR_5)
modified_predictor = 1; for (VAR_4=0;VAR_4<VAR_1;VAR_4++) { int pred, dc; VAR_9[VAR_4] = VAR_8[VAR_4]; VAR_8[VAR_4]     = buffer[VAR_5][VAR_4]; PREDICT(pred, VAR_9[VAR_4], VAR_8[VAR_4], VAR_7[VAR_4], modified_predictor); dc = mjpeg_decode_dc(VAR_0, VAR_0->dc_index[VAR_4]); if(dc == 0xFFFF)
return -1; VAR_7[VAR_4] = buffer[VAR_5][VAR_4] =
VAR_11 & (pred + (dc << VAR_3)); } if (VAR_0->restart_interval && !--VAR_0->restart_count) { align_get_bits(&VAR_0->gb); skip_bits(&VAR_0->gb, 16); } } if (VAR_0->VAR_1 == 4) { for(VAR_4=0; VAR_4<VAR_1; VAR_4++) { int c= VAR_0->comp_index[VAR_4]; for(VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) { ptr[4*VAR_5+3-c] = buffer[VAR_5][VAR_4]; } } } else if (VAR_0->rct) { for (VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) { ptr[3*VAR_5 + 1] = buffer[VAR_5][0] - ((buffer[VAR_5][1] + buffer[VAR_5][2] - 0x200) >> 2); ptr[3*VAR_5 + 0] = buffer[VAR_5][1] + ptr[3*VAR_5 + 1]; ptr[3*VAR_5 + 2] = buffer[VAR_5][2] + ptr[3*VAR_5 + 1]; } } else if (VAR_0->pegasus_rct) { for (VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) { ptr[3*VAR_5 + 1] = buffer[VAR_5][0] - ((buffer[VAR_5][1] + buffer[VAR_5][2]) >> 2); ptr[3*VAR_5 + 0] = buffer[VAR_5][1] + ptr[3*VAR_5 + 1]; ptr[3*VAR_5 + 2] = buffer[VAR_5][2] + ptr[3*VAR_5 + 1]; } } else { for(VAR_4=0; VAR_4<VAR_1; VAR_4++) { int c= VAR_0->comp_index[VAR_4]; for(VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) { ptr[3*VAR_5+2-c] = buffer[VAR_5][VAR_4]; } } } } return 0; }