emms_c();
static int mjpeg_decode_sos(MJpegDecodeContext *s,                            UINT8 *buf, int buf_size){    int len, nb_components, i, j, n, h, v;    int mb_width, mb_height, mb_x, mb_y, vmax, hmax, index, id;    int comp_index[4];    int dc_index[4];    int ac_index[4];    int nb_blocks[4];    int h_count[4];    int v_count[4];        init_get_bits(&s->gb, buf, buf_size);    /* XXX: verify len field validity */    len = get_bits(&s->gb, 16);    nb_components = get_bits(&s->gb, 8);    /* XXX: only interleaved scan accepted */    if (nb_components != 3)        return -1;    vmax = 0;    hmax = 0;    for(i=0;i<nb_components;i++) {        id = get_bits(&s->gb, 8) - 1;        /* find component index */        for(index=0;index<s->nb_components;index++)            if (id == s->component_id[index])                break;        if (index == s->nb_components)            return -1;        comp_index[i] = index;        nb_blocks[i] = s->h_count[index] * s->v_count[index];        h_count[i] = s->h_count[index];        v_count[i] = s->v_count[index];        dc_index[i] = get_bits(&s->gb, 4);        if (dc_index[i] >= 4)            return -1;        ac_index[i] = get_bits(&s->gb, 4);        if (ac_index[i] >= 4)            return -1;    }    get_bits(&s->gb, 8); /* Ss */    get_bits(&s->gb, 8); /* Se */    get_bits(&s->gb, 8); /* not used */    for(i=0;i<nb_components;i++)         s->last_dc[i] = 1024;    if (nb_components > 1) {        /* interleaved stream */        mb_width = (s->width + s->h_max * 8 - 1) / (s->h_max * 8);        mb_height = (s->height + s->v_max * 8 - 1) / (s->v_max * 8);    } else {        h = s->h_max / s->h_count[comp_index[0]];        v = s->v_max / s->v_count[comp_index[0]];        mb_width = (s->width + h * 8 - 1) / (h * 8);        mb_height = (s->height + v * 8 - 1) / (v * 8);        nb_blocks[0] = 1;        h_count[0] = 1;        v_count[0] = 1;    }    for(mb_y = 0; mb_y < mb_height; mb_y++) {        for(mb_x = 0; mb_x < mb_width; mb_x++) {            for(i=0;i<nb_components;i++) {                UINT8 *ptr;                int x, y, c;                n = nb_blocks[i];                c = comp_index[i];                h = h_count[i];                v = v_count[i];                x = 0;                y = 0;                for(j=0;j<n;j++) {                    memset(s->block, 0, sizeof(s->block));                    if (decode_block(s, s->block, i,                                      dc_index[i], ac_index[i],                                      s->quant_index[c]) < 0) {                        dprintf("error %d %d\n", mb_y, mb_x);                        return -1;                    }                    ff_idct (s->block);                    ptr = s->current_picture[c] +                         (s->linesize[c] * (v * mb_y + y) * 8) +                         (h * mb_x + x) * 8;                    put_pixels_clamped(s->block, ptr, s->linesize[c]);                    if (++x == h) {                        x = 0;                        y++;                    }                }            }        }    }    return 0;}