static int decode_block(MJpegDecodeContext *s, int16_t *block, int component,

                        int dc_index, int ac_index, int16_t *quant_matrix)

{

    int code, i, j, level, val;



    /* DC coef */

    val = mjpeg_decode_dc(s, dc_index);

    if (val == 0xfffff) {

        av_log(s->avctx, AV_LOG_ERROR, "error dc\n");

        return AVERROR_INVALIDDATA;

    }

    val = val * quant_matrix[0] + s->last_dc[component];


    s->last_dc[component] = val;

    block[0] = val;

    /* AC coefs */

    i = 0;

    {OPEN_READER(re, &s->gb);

    do {

        UPDATE_CACHE(re, &s->gb);

        GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2);



        i += ((unsigned)code) >> 4;

            code &= 0xf;

        if (code) {

            if (code > MIN_CACHE_BITS - 16)

                UPDATE_CACHE(re, &s->gb);



            {

                int cache = GET_CACHE(re, &s->gb);

                int sign  = (~cache) >> 31;

                level     = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;

            }



            LAST_SKIP_BITS(re, &s->gb, code);



            if (i > 63) {

                av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);

                return AVERROR_INVALIDDATA;

            }

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

            block[j] = level * quant_matrix[j];

        }

    } while (i < 63);

    CLOSE_READER(re, &s->gb);}



    return 0;

}