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.
This commit is contained in:
wm4 2012-11-22 19:22:38 +01:00
parent 11783b5ede
commit 1d3179a5f1
2 changed files with 6 additions and 17 deletions

View File

@ -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;
}

View File

@ -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: