static void encode_block(MpegEncContext *s, int16_t *block, int n)

{

    int i, j, table_id;

    int component, dc, last_index, val, run;

    MJpegContext *m = s->mjpeg_ctx;



    /* DC coef */

    component = (n <= 3 ? 0 : (n&1) + 1);

    table_id = (n <= 3 ? 0 : 1);

    dc = block[0]; /* overflow is impossible */

    val = dc - s->last_dc[component];



    ff_mjpeg_encode_coef(m, table_id, val, 0);



    s->last_dc[component] = dc;



    /* AC coefs */



    run = 0;

    last_index = s->block_last_index[n];

    table_id |= 2;



    for(i=1;i<=last_index;i++) {

        j = s->intra_scantable.permutated[i];

        val = block[j];



        if (val == 0) {

            run++;

        } else {

            while (run >= 16) {

                ff_mjpeg_encode_code(m, table_id, 0xf0);

                run -= 16;

            }

            ff_mjpeg_encode_coef(m, table_id, val, run);

            run = 0;

        }

    }



    /* output EOB only if not already 64 values */

    if (last_index < 63 || run != 0)

        ff_mjpeg_encode_code(m, table_id, 0);

}

static void encode_block(MpegEncContext *s, int16_t *block, int n)

{

    int i, j, table_id;

    int component, dc, last_index, val, run;

    MJpegContext *m = s->mjpeg_ctx;



    

    component = (n <= 3 ? 0 : (n&1) + 1);

    table_id = (n <= 3 ? 0 : 1);

    dc = block[0]; 

    val = dc - s->last_dc[component];



    ff_mjpeg_encode_coef(m, table_id, val, 0);



    s->last_dc[component] = dc;



    



    run = 0;

    last_index = s->block_last_index[n];

    table_id |= 2;



    for(i=1;i<=last_index;i++) {

        j = s->intra_scantable.permutated[i];

        val = block[j];



        if (val == 0) {

            run++;

        } else {

            while (run >= 16) {

                ff_mjpeg_encode_code(m, table_id, 0xf0);

                run -= 16;

            }

            ff_mjpeg_encode_coef(m, table_id, val, run);

            run = 0;

        }

    }



    

    if (last_index < 63 || run != 0)

        ff_mjpeg_encode_code(m, table_id, 0);

}

static void FUNC_0(MpegEncContext *VAR_0, int16_t *VAR_1, int VAR_2)

{

    int VAR_3, VAR_4, VAR_5;

    int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10;

    MJpegContext *m = VAR_0->mjpeg_ctx;



    

    VAR_6 = (VAR_2 <= 3 ? 0 : (VAR_2&1) + 1);

    VAR_5 = (VAR_2 <= 3 ? 0 : 1);

    VAR_7 = VAR_1[0]; 

    VAR_9 = VAR_7 - VAR_0->last_dc[VAR_6];



    ff_mjpeg_encode_coef(m, VAR_5, VAR_9, 0);



    VAR_0->last_dc[VAR_6] = VAR_7;



    



    VAR_10 = 0;

    VAR_8 = VAR_0->block_last_index[VAR_2];

    VAR_5 |= 2;



    for(VAR_3=1;VAR_3<=VAR_8;VAR_3++) {

        VAR_4 = VAR_0->intra_scantable.permutated[VAR_3];

        VAR_9 = VAR_1[VAR_4];



        if (VAR_9 == 0) {

            VAR_10++;

        } else {

            while (VAR_10 >= 16) {

                ff_mjpeg_encode_code(m, VAR_5, 0xf0);

                VAR_10 -= 16;

            }

            ff_mjpeg_encode_coef(m, VAR_5, VAR_9, VAR_10);

            VAR_10 = 0;

        }

    }



    

    if (VAR_8 < 63 || VAR_10 != 0)

        ff_mjpeg_encode_code(m, VAR_5, 0);

}

static void FUNC_0(MpegEncContext *VAR_0, int16_t *VAR_1, int VAR_2)
{ int VAR_3, VAR_4, VAR_5; int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; MJpegContext *m = VAR_0->mjpeg_ctx; VAR_6 = (VAR_2 <= 3 ? 0 : (VAR_2&1) + 1); VAR_5 = (VAR_2 <= 3 ? 0 : 1); VAR_7 = VAR_1[0]; VAR_9 = VAR_7 - VAR_0->last_dc[VAR_6]; ff_mjpeg_encode_coef(m, VAR_5, VAR_9, 0); VAR_0->last_dc[VAR_6] = VAR_7; VAR_10 = 0; VAR_8 = VAR_0->block_last_index[VAR_2]; VAR_5 |= 2; for(VAR_3=1;VAR_3<=VAR_8;VAR_3++) { VAR_4 = VAR_0->intra_scantable.permutated[VAR_3]; VAR_9 = VAR_1[VAR_4]; if (VAR_9 == 0) { VAR_10++; } else { while (VAR_10 >= 16) { ff_mjpeg_encode_code(m, VAR_5, 0xf0); VAR_10 -= 16; } ff_mjpeg_encode_coef(m, VAR_5, VAR_9, VAR_10); VAR_10 = 0; } } if (VAR_8 < 63 || VAR_10 != 0)
ff_mjpeg_encode_code(m, VAR_5, 0); }