w >>= 1; h >>= 1;
w = (w + 1) >> 1; h = (h + 1) >> 1;
static int jpeg_read(ByteIOContext *f,                      int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque){    AVCodecContext *c;    AVFrame *picture, picture1;    int len, size, got_picture, i;    uint8_t *inbuf_ptr, inbuf[IO_BUF_SIZE];    JpegOpaque jctx;    jctx.alloc_cb = alloc_cb;    jctx.opaque = opaque;    jctx.ret_code = -1; /* default return code is error */        c = avcodec_alloc_context();    if (!c)        return -1;    picture= avcodec_alloc_frame();    if (!picture) {        av_free(c);        return -1;    }    c->opaque = &jctx;    c->get_buffer = jpeg_get_buffer;    c->flags |= CODEC_FLAG_TRUNCATED; /* we dont send complete frames */    if (avcodec_open(c, &mjpeg_decoder) < 0)        goto fail1;    for(;;) {        size = get_buffer(f, inbuf, sizeof(inbuf));        if (size == 0)            break;        inbuf_ptr = inbuf;        while (size > 0) {            len = avcodec_decode_video(c, &picture1, &got_picture,                                        inbuf_ptr, size);            if (len < 0)                goto fail;            if (got_picture)                goto the_end;            size -= len;            inbuf_ptr += len;        }    } the_end:    /* XXX: currently, the mjpeg decoder does not use AVFrame, so we       must do it by hand */    if (jpeg_get_buffer(c, picture) < 0)        goto fail;    for(i=0;i<3;i++) {        int w, h;        w = c->width;        h = c->height;        if (i >= 1) {            switch(c->pix_fmt) {            default:            case PIX_FMT_YUV420P:                w >>= 1;                h >>= 1;                break;            case PIX_FMT_YUV422P:                w >>= 1;                break;            case PIX_FMT_YUV444P:                break;            }        }        img_copy(picture->data[i], picture->linesize[i],                 picture1.data[i], picture1.linesize[i],                 w, h);    }    jctx.ret_code = 0; fail:    avcodec_close(c); fail1:    av_free(picture);    av_free(c);    return jctx.ret_code;}