s->avctx->pix_fmt = PIX_FMT_YUV420P;
s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P;
static int mjpeg_decode_sof(MJpegDecodeContext *s){    int len, nb_components, i, width, height;    /* XXX: verify len field validity */    len = get_bits(&s->gb, 16);    s->bits= get_bits(&s->gb, 8);        if(s->pegasus_rct) s->bits=9;      if(s->bits==9 && !s->pegasus_rct) s->rct=1;    //FIXME ugly    if (s->bits != 8 && !s->lossless){        av_log(s->avctx, AV_LOG_ERROR, "only 8 bits/component accepted\n");        return -1;    }    height = get_bits(&s->gb, 16);    width = get_bits(&s->gb, 16);        dprintf("sof0: picture: %dx%d\n", width, height);    if(avcodec_check_dimensions(s->avctx, width, height))        return -1;    nb_components = get_bits(&s->gb, 8);    if (nb_components <= 0 ||        nb_components > MAX_COMPONENTS)        return -1;    s->nb_components = nb_components;    s->h_max = 1;    s->v_max = 1;    for(i=0;i<nb_components;i++) {        /* component id */        s->component_id[i] = get_bits(&s->gb, 8) - 1;        s->h_count[i] = get_bits(&s->gb, 4);        s->v_count[i] = get_bits(&s->gb, 4);        /* compute hmax and vmax (only used in interleaved case) */        if (s->h_count[i] > s->h_max)            s->h_max = s->h_count[i];        if (s->v_count[i] > s->v_max)            s->v_max = s->v_count[i];        s->quant_index[i] = get_bits(&s->gb, 8);        if (s->quant_index[i] >= 4)            return -1;        dprintf("component %d %d:%d id: %d quant:%d\n", i, s->h_count[i],	    s->v_count[i], s->component_id[i], s->quant_index[i]);    }        if(s->v_max==1 && s->h_max==1 && s->lossless==1) s->rgb=1;    /* if different size, realloc/alloc picture */    /* XXX: also check h_count and v_count */    if (width != s->width || height != s->height) {        av_freep(&s->qscale_table);                    s->width = width;        s->height = height;        avcodec_set_dimensions(s->avctx, width, height);        /* test interlaced mode */        if (s->first_picture &&            s->org_height != 0 &&            s->height < ((s->org_height * 3) / 4)) {            s->interlaced = 1;//	    s->bottom_field = (s->interlace_polarity) ? 1 : 0;            s->bottom_field = 0;            s->avctx->height *= 2;        }        s->qscale_table= av_mallocz((s->width+15)/16);        s->first_picture = 0;    }        if(s->interlaced && s->bottom_field)        return 0;     /* XXX: not complete test ! */    switch((s->h_count[0] << 4) | s->v_count[0]) {    case 0x11:        if(s->rgb){            s->avctx->pix_fmt = PIX_FMT_RGBA32;        }else if(s->nb_components==3)            s->avctx->pix_fmt = PIX_FMT_YUV444P;        else            s->avctx->pix_fmt = PIX_FMT_GRAY8;        break;    case 0x21:        s->avctx->pix_fmt = PIX_FMT_YUV422P;        break;    default:    case 0x22:        s->avctx->pix_fmt = PIX_FMT_YUV420P;        break;    }    if(s->picture.data[0])        s->avctx->release_buffer(s->avctx, &s->picture);    s->picture.reference= 0;    if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){        av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");        return -1;    }    s->picture.pict_type= I_TYPE;    s->picture.key_frame= 1;        for(i=0; i<3; i++){        s->linesize[i]= s->picture.linesize[i] << s->interlaced;    }//    printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height);        if (len != (8+(3*nb_components)))    {	dprintf("decode_sof0: error, len(%d) mismatch\n", len);    }        return 0;}