[FFmpeg-devel] [PATCH 7/7] Re-implement avpicture_layout() using pixdesc and imgutils API.

Stefano Sabatini stefano.sabatini-lala
Mon Nov 15 12:40:43 CET 2010


On date Tuesday 2010-11-09 19:31:16 +0100, Michael Niedermayer encoded:
> On Sun, Nov 07, 2010 at 11:07:30PM +0100, Stefano Sabatini wrote:
> > The new implementation is more compact, more correct and doesn't hurt
> > the eyes.
> > ---
> >  libavcodec/imgconvert.c |   65 ++++++++++------------------------------------
> >  1 files changed, 14 insertions(+), 51 deletions(-)
> > 
> > diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
> > index df2a90e..6fba703 100644
> > --- a/libavcodec/imgconvert.c
> > +++ b/libavcodec/imgconvert.c
> > @@ -490,68 +490,31 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
> >  int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height,
> >                       unsigned char *dest, int dest_size)
> >  {
> > -    const PixFmtInfo* pf = &pix_fmt_info[pix_fmt];
> > +    int i, j, nb_planes = 0, linesizes[4];
> >      const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
> > -    int i, j, w, ow, h, oh, data_planes;
> > -    const unsigned char* s;
> >      int size = avpicture_get_size(pix_fmt, width, height);
> >  
> >      if (size > dest_size || size < 0)
> > -        return -1;
> > -
> > -    if (pf->pixel_type == FF_PIXEL_PACKED || pf->pixel_type == FF_PIXEL_PALETTE) {
> > -        if (pix_fmt == PIX_FMT_YUYV422 ||
> > -            pix_fmt == PIX_FMT_UYVY422 ||
> > -            pix_fmt == PIX_FMT_BGR565BE ||
> > -            pix_fmt == PIX_FMT_BGR565LE ||
> > -            pix_fmt == PIX_FMT_BGR555BE ||
> > -            pix_fmt == PIX_FMT_BGR555LE ||
> > -            pix_fmt == PIX_FMT_BGR444BE ||
> > -            pix_fmt == PIX_FMT_BGR444LE ||
> > -            pix_fmt == PIX_FMT_RGB565BE ||
> > -            pix_fmt == PIX_FMT_RGB565LE ||
> > -            pix_fmt == PIX_FMT_RGB555BE ||
> > -            pix_fmt == PIX_FMT_RGB555LE ||
> > -            pix_fmt == PIX_FMT_RGB444BE ||
> > -            pix_fmt == PIX_FMT_RGB444LE)
> > -            w = width * 2;
> > -        else if (pix_fmt == PIX_FMT_UYYVYY411)
> > -            w = width + width/2;
> > -        else if (pix_fmt == PIX_FMT_PAL8)
> > -            w = width;
> > -        else
> > -            w = width * (pf->depth * pf->nb_channels / 8);
> > +        return AVERROR(EINVAL);
> >  
> > -        data_planes = 1;
> > -        h = height;
> > -    } else {
> > -        data_planes = pf->nb_channels;
> > -        w = (width*pf->depth + 7)/8;
> > -        h = height;
> > -    }
> > +    for (i = 0; i < desc->nb_components; i++)
> > +        nb_planes = FFMAX(desc->comp[i].plane, nb_planes);
> > +    nb_planes++;
> >  
> > -    ow = w;
> > -    oh = h;
> > +    av_image_fill_linesizes(linesizes, pix_fmt, width);
> > +    for (i = 0; i < nb_planes; i++) {
> > +        int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
> > +        h = (height + (1 << s) - 1) >> s;
> >  
> > -    for (i=0; i<data_planes; i++) {
> > -        if (i == 1) {
> > -            w = (- ((-width) >> desc->log2_chroma_w) * pf->depth + 7) / 8;
> > -            h = -((-height) >> desc->log2_chroma_h);
> > -            if (pix_fmt == PIX_FMT_NV12 || pix_fmt == PIX_FMT_NV21)
> > -                w <<= 1;
> > -        } else if (i == 3) {
> > -            w = ow;
> > -            h = oh;
> > -        }
> >          s = src->data[i];
> > -        for(j=0; j<h; j++) {
> > -            memcpy(dest, s, w);
> > -            dest += w;
> > +        for (j = 0; j < h; j++) {
> > +            memcpy(dest, s, linesizes[i]);
> 
> if linesize > w then this copies more than is defined in the input i think

w = linesizes[i]

that is the linesizes[i] computed by av_fill_image_linesizes() is
(almost) the same computed by the old code, but the new code is more
complete and more correct (e.g. with yuyv, uyvy, uyyvyy411, nv12,
nv21).

See result of the attached test code:

layout_test:yuv420p
	plane:0 w:103 h:103
	plane:1 w:52 h:52
	plane:2 w:52 h:52
layout_test2:yuv420p
	plane:0 w:103 h:103
	plane:1 w:52 h:52
	plane:2 w:52 h:52
layout_test:yuyv422
	plane:0 w:206 h:103
layout_test2:yuyv422
	plane:0 w:208 h:103
layout_test:rgb24
	plane:0 w:309 h:103
layout_test2:rgb24
	plane:0 w:309 h:103
layout_test:bgr24
	plane:0 w:309 h:103
layout_test2:bgr24
	plane:0 w:309 h:103
layout_test:yuv422p
	plane:0 w:103 h:103
	plane:1 w:52 h:103
	plane:2 w:52 h:103
layout_test2:yuv422p
	plane:0 w:103 h:103
	plane:1 w:52 h:103
	plane:2 w:52 h:103
layout_test:yuv444p
	plane:0 w:103 h:103
	plane:1 w:103 h:103
	plane:2 w:103 h:103
layout_test2:yuv444p
	plane:0 w:103 h:103
	plane:1 w:103 h:103
	plane:2 w:103 h:103
layout_test:yuv410p
	plane:0 w:103 h:103
	plane:1 w:26 h:26
	plane:2 w:26 h:26
layout_test2:yuv410p
	plane:0 w:103 h:103
	plane:1 w:26 h:26
	plane:2 w:26 h:26
layout_test:yuv411p
	plane:0 w:103 h:103
	plane:1 w:26 h:103
	plane:2 w:26 h:103
layout_test2:yuv411p
	plane:0 w:103 h:103
	plane:1 w:26 h:103
	plane:2 w:26 h:103
layout_test:gray
	plane:0 w:103 h:103
layout_test2:gray
	plane:0 w:103 h:103
layout_test:monow
	plane:0 w:13 h:103
layout_test2:monow
	plane:0 w:13 h:103
layout_test:monob
	plane:0 w:13 h:103
layout_test2:monob
	plane:0 w:13 h:103
layout_test:pal8
	plane:0 w:103 h:103
layout_test2:pal8
	plane:0 w:103 h:103
layout_test:yuvj420p
	plane:0 w:103 h:103
	plane:1 w:52 h:52
	plane:2 w:52 h:52
layout_test2:yuvj420p
	plane:0 w:103 h:103
	plane:1 w:52 h:52
	plane:2 w:52 h:52
layout_test:yuvj422p
	plane:0 w:103 h:103
	plane:1 w:52 h:103
	plane:2 w:52 h:103
layout_test2:yuvj422p
	plane:0 w:103 h:103
	plane:1 w:52 h:103
	plane:2 w:52 h:103
layout_test:yuvj444p
	plane:0 w:103 h:103
	plane:1 w:103 h:103
	plane:2 w:103 h:103
layout_test2:yuvj444p
	plane:0 w:103 h:103
	plane:1 w:103 h:103
	plane:2 w:103 h:103
layout_test:layout_test2:xvmcmc
	plane:0 w:0 h:103
layout_test:layout_test2:xvmcidct
	plane:0 w:0 h:103
layout_test:uyvy422
	plane:0 w:206 h:103
layout_test2:uyvy422
	plane:0 w:208 h:103
layout_test:uyyvyy411
	plane:0 w:154 h:103
layout_test2:uyyvyy411
	plane:0 w:156 h:103
layout_test:bgr8
	plane:0 w:103 h:103
layout_test2:bgr8
	plane:0 w:103 h:103
layout_test:bgr4
	plane:0 w:0 h:103
layout_test2:bgr4
	plane:0 w:52 h:103
layout_test:bgr4_byte
	plane:0 w:103 h:103
layout_test2:bgr4_byte
	plane:0 w:103 h:103
layout_test:rgb8
	plane:0 w:103 h:103
layout_test2:rgb8
	plane:0 w:103 h:103
layout_test:rgb4
	plane:0 w:0 h:103
layout_test2:rgb4
	plane:0 w:52 h:103
layout_test:rgb4_byte
	plane:0 w:103 h:103
layout_test2:rgb4_byte
	plane:0 w:103 h:103
layout_test:nv12
	plane:0 w:103 h:103
	plane:1 w:104 h:52
layout_test2:nv12
	plane:0 w:103 h:103
	plane:1 w:104 h:52
layout_test:nv21
	plane:0 w:103 h:103
	plane:1 w:104 h:52
layout_test2:nv21
	plane:0 w:103 h:103
	plane:1 w:104 h:52
layout_test:argb
	plane:0 w:412 h:103
layout_test2:argb
	plane:0 w:412 h:103
layout_test:rgba
	plane:0 w:412 h:103
layout_test2:rgba
	plane:0 w:412 h:103
layout_test:abgr
	plane:0 w:412 h:103
layout_test2:abgr
	plane:0 w:412 h:103
layout_test:bgra
	plane:0 w:412 h:103
layout_test2:bgra
	plane:0 w:412 h:103
layout_test:gray16be
	plane:0 w:206 h:103
layout_test2:gray16be
	plane:0 w:206 h:103
layout_test:gray16le
	plane:0 w:206 h:103
layout_test2:gray16le
	plane:0 w:206 h:103
layout_test:yuv440p
	plane:0 w:103 h:103
	plane:1 w:103 h:52
	plane:2 w:103 h:52
layout_test2:yuv440p
	plane:0 w:103 h:103
	plane:1 w:103 h:52
	plane:2 w:103 h:52
layout_test:yuvj440p
	plane:0 w:103 h:103
	plane:1 w:103 h:52
	plane:2 w:103 h:52
layout_test2:yuvj440p
	plane:0 w:103 h:103
	plane:1 w:103 h:52
	plane:2 w:103 h:52
layout_test:yuva420p
	plane:0 w:103 h:103
	plane:1 w:52 h:52
	plane:2 w:52 h:52
	plane:3 w:103 h:103
layout_test2:yuva420p
	plane:0 w:103 h:103
	plane:1 w:52 h:52
	plane:2 w:52 h:52
	plane:3 w:103 h:103
layout_test:layout_test2:vdpau_h264
	plane:0 w:0 h:103
layout_test:layout_test2:vdpau_mpeg1
	plane:0 w:0 h:103
layout_test:layout_test2:vdpau_mpeg2
	plane:0 w:0 h:103
layout_test:layout_test2:vdpau_wmv3
	plane:0 w:0 h:103
layout_test:layout_test2:vdpau_vc1
	plane:0 w:0 h:103
layout_test:rgb48be
	plane:0 w:618 h:103
layout_test2:rgb48be
	plane:0 w:618 h:103
layout_test:rgb48le
	plane:0 w:618 h:103
layout_test2:rgb48le
	plane:0 w:618 h:103
layout_test:rgb565be
	plane:0 w:206 h:103
layout_test2:rgb565be
	plane:0 w:206 h:103
layout_test:rgb565le
	plane:0 w:206 h:103
layout_test2:rgb565le
	plane:0 w:206 h:103
layout_test:rgb555be
	plane:0 w:206 h:103
layout_test2:rgb555be
	plane:0 w:206 h:103
layout_test:rgb555le
	plane:0 w:206 h:103
layout_test2:rgb555le
	plane:0 w:206 h:103
layout_test:bgr565be
	plane:0 w:206 h:103
layout_test2:bgr565be
	plane:0 w:206 h:103
layout_test:bgr565le
	plane:0 w:206 h:103
layout_test2:bgr565le
	plane:0 w:206 h:103
layout_test:bgr555be
	plane:0 w:206 h:103
layout_test2:bgr555be
	plane:0 w:206 h:103
layout_test:bgr555le
	plane:0 w:206 h:103
layout_test2:bgr555le
	plane:0 w:206 h:103
layout_test:layout_test2:vaapi_moco
	plane:0 w:0 h:103
layout_test:layout_test2:vaapi_idct
	plane:0 w:0 h:103
layout_test:layout_test2:vaapi_vld
	plane:0 w:0 h:103
layout_test:yuv420p16le
	plane:0 w:206 h:103
	plane:1 w:104 h:52
	plane:2 w:104 h:52
layout_test2:yuv420p16le
	plane:0 w:206 h:103
	plane:1 w:104 h:52
	plane:2 w:104 h:52
layout_test:yuv420p16be
	plane:0 w:206 h:103
	plane:1 w:104 h:52
	plane:2 w:104 h:52
layout_test2:yuv420p16be
	plane:0 w:206 h:103
	plane:1 w:104 h:52
	plane:2 w:104 h:52
layout_test:yuv422p16le
	plane:0 w:206 h:103
	plane:1 w:104 h:103
	plane:2 w:104 h:103
layout_test2:yuv422p16le
	plane:0 w:206 h:103
	plane:1 w:104 h:103
	plane:2 w:104 h:103
layout_test:yuv422p16be
	plane:0 w:206 h:103
	plane:1 w:104 h:103
	plane:2 w:104 h:103
layout_test2:yuv422p16be
	plane:0 w:206 h:103
	plane:1 w:104 h:103
	plane:2 w:104 h:103
layout_test:yuv444p16le
	plane:0 w:206 h:103
	plane:1 w:206 h:103
	plane:2 w:206 h:103
layout_test2:yuv444p16le
	plane:0 w:206 h:103
	plane:1 w:206 h:103
	plane:2 w:206 h:103
layout_test:yuv444p16be
	plane:0 w:206 h:103
	plane:1 w:206 h:103
	plane:2 w:206 h:103
layout_test2:yuv444p16be
	plane:0 w:206 h:103
	plane:1 w:206 h:103
	plane:2 w:206 h:103
layout_test:layout_test2:vdpau_mpeg4
	plane:0 w:0 h:103
layout_test:layout_test2:dxva2_vld
	plane:0 w:0 h:103
layout_test:rgb444be
	plane:0 w:206 h:103
layout_test2:rgb444be
	plane:0 w:206 h:103
layout_test:rgb444le
	plane:0 w:206 h:103
layout_test2:rgb444le
	plane:0 w:206 h:103
layout_test:bgr444be
	plane:0 w:206 h:103
layout_test2:bgr444be
	plane:0 w:206 h:103
layout_test:bgr444le
	plane:0 w:206 h:103
layout_test2:bgr444le
	plane:0 w:206 h:103
layout_test:y400a
layout_test2:y400a
	plane:0 w:206 h:103
-- 
FFmpeg = Fast and Free Murdering Puritan Elastic Gadget



More information about the ffmpeg-devel mailing list