From 1d3179a5f1dc2fdfeaac3582a925c2849ac265a9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 22 Nov 2012 19:22:38 +0100 Subject: [PATCH] mp_image: make alloc_mpi() always allocate with aligned stride By "design", mplayer normally allocates aligned images only inside the filter chain, via the vf_get_image() function. This function pads the width of the requested image if a stride is allowed, sets that new width before calling mp_image_alloc_planes(). However, newer code wants aligned images as well (basically to satisfy libswscale). This affects all uses of alloc_mpi(). To get aligned strides, simply change alloc_mpi() to request an aligned width. Remove the old hack in mp_image_alloc_planes(), which special cases some image formats to be allocated with aligned strides. This is a temporary hack until mp_image_alloc_planes() is revised. --- video/mp_image.c | 20 +++----------------- video/mp_image.h | 3 +++ 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/video/mp_image.c b/video/mp_image.c index 25b84641a7..7cfceca1c2 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -33,23 +33,6 @@ #include "libavutil/common.h" void mp_image_alloc_planes(mp_image_t *mpi) { - if (mpi->imgfmt == IMGFMT_BGRA) { - mpi->stride[0]=FFALIGN(mpi->width*4,SWS_MIN_BYTE_ALIGN); - mpi->planes[0]=av_malloc(mpi->stride[0]*mpi->height); - mpi->flags|=MP_IMGFLAG_ALLOCATED; - return; - } - if (mpi->imgfmt == IMGFMT_444P16 || mpi->imgfmt == IMGFMT_444P) { - int bp = mpi->imgfmt == IMGFMT_444P16 ? 2 : 1; - mpi->stride[0]=FFALIGN(mpi->width*bp,SWS_MIN_BYTE_ALIGN); - mpi->stride[1]=mpi->stride[2]=mpi->stride[0]; - int imgsize = mpi->stride[0] * mpi->height; - mpi->planes[0]=av_malloc(imgsize*3); - mpi->planes[1]=mpi->planes[0]+imgsize; - mpi->planes[2]=mpi->planes[1]+imgsize; - mpi->flags|=MP_IMGFLAG_ALLOCATED; - return; - } // IF09 - allocate space for 4. plane delta info - unused if (mpi->imgfmt == IMGFMT_IF09) { mpi->planes[0]=av_malloc(mpi->bpp*mpi->width*(mpi->height+2)/8+ @@ -95,8 +78,11 @@ void mp_image_alloc_planes(mp_image_t *mpi) { mp_image_t* alloc_mpi(int w, int h, unsigned long int fmt) { mp_image_t* mpi = new_mp_image(w,h); + mpi->width=FFALIGN(w, MP_STRIDE_ALIGNMENT); mp_image_setfmt(mpi,fmt); mp_image_alloc_planes(mpi); + mpi->width=w; + mp_image_setfmt(mpi,fmt); // reset chroma size return mpi; } diff --git a/video/mp_image.h b/video/mp_image.h index 8ce0b98edc..d2c7d38f50 100644 --- a/video/mp_image.h +++ b/video/mp_image.h @@ -26,6 +26,9 @@ #include "core/mp_msg.h" #include "csputils.h" +// Minimum stride alignment in pixels +#define MP_STRIDE_ALIGNMENT 32 + //--------- codec's requirements (filled by the codec/vf) --------- //--- buffer content restrictions: