davs2_outpic_t *alloc_picture(int w, int h)
{
    davs2_outpic_t *pic = NULL;
    uint8_t *buf;

    buf = (uint8_t *)davs2_malloc(sizeof(davs2_outpic_t)     +
                                   sizeof(davs2_seq_info_t) +
                                   sizeof(davs2_picture_t)  + sizeof(pel_t) * w * h * 3 / 2);
    if (buf == NULL) {
        return NULL;
    }

    pic = (davs2_outpic_t *)buf;

    buf += sizeof(davs2_outpic_t); /* davs2_outpic_t */

    pic->frame = NULL;
    pic->next  = NULL;

    pic->head = (davs2_seq_info_t *)buf;
    buf      += sizeof(davs2_seq_info_t);

    pic->pic = (davs2_picture_t *)buf;
    buf     += sizeof(davs2_picture_t);

    pic->pic->num_planes = 3;
    pic->pic->planes[0] = buf;
    pic->pic->planes[1] = pic->pic->planes[0] + w * h * sizeof(pel_t);
    pic->pic->planes[2] = pic->pic->planes[1] + w * h / 4 * sizeof(pel_t);
    pic->pic->widths[0] = w;
    pic->pic->widths[1] = w / 2;
    pic->pic->widths[2] = w / 2;
    pic->pic->lines [0] = h;
    pic->pic->lines [1] = h / 2;
    pic->pic->lines [2] = h / 2;
    pic->pic->dec_frame = NULL;

    return pic;
}
davs2_outpic_t *alloc_picture(int w, int h)
{
    davs2_outpic_t *pic = NULL;
    uint8_t *buf;

    buf = (uint8_t *)davs2_malloc(sizeof(davs2_outpic_t)     +
                                   sizeof(davs2_seq_info_t) +
                                   sizeof(davs2_picture_t)  + sizeof(pel_t) * w * h * 3 / 2);
    if (buf == NULL) {
        return NULL;
    }

    pic = (davs2_outpic_t *)buf;

    buf += sizeof(davs2_outpic_t);  

    pic->frame = NULL;
    pic->next  = NULL;

    pic->head = (davs2_seq_info_t *)buf;
    buf      += sizeof(davs2_seq_info_t);

    pic->pic = (davs2_picture_t *)buf;
    buf     += sizeof(davs2_picture_t);

    pic->pic->num_planes = 3;
    pic->pic->planes[0] = buf;
    pic->pic->planes[1] = pic->pic->planes[0] + w * h * sizeof(pel_t);
    pic->pic->planes[2] = pic->pic->planes[1] + w * h / 4 * sizeof(pel_t);
    pic->pic->widths[0] = w;
    pic->pic->widths[1] = w / 2;
    pic->pic->widths[2] = w / 2;
    pic->pic->lines [0] = h;
    pic->pic->lines [1] = h / 2;
    pic->pic->lines [2] = h / 2;
    pic->pic->dec_frame = NULL;

    return pic;
}