From 73fce258b774d0480f2d2dd7ec81fa1ec1b27812 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 23 Feb 2013 19:25:46 +0100 Subject: [PATCH] vf_mp: Set pseudo pal Fixes ticket2140 Fixes null pointer dereference Signed-off-by: Michael Niedermayer --- libavfilter/libmpcodecs/mp_image.c | 9 ++++++++- libavfilter/libmpcodecs/mp_image.h | 2 ++ libavfilter/vf_mp.c | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libavfilter/libmpcodecs/mp_image.c b/libavfilter/libmpcodecs/mp_image.c index 33d5c07730..100ace92ca 100644 --- a/libavfilter/libmpcodecs/mp_image.c +++ b/libavfilter/libmpcodecs/mp_image.c @@ -31,8 +31,13 @@ #include "libvo/fastmemcpy.h" //#include "libavutil/mem.h" +#include "libavutil/imgutils.h" void ff_mp_image_alloc_planes(mp_image_t *mpi) { + uint32_t temp[256]; + if (avpriv_set_systematic_pal2(temp, ff_mp2ff_pix_fmt(mpi->imgfmt)) >= 0) + mpi->flags |= MP_IMGFLAG_RGB_PALETTE; + // 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+ @@ -65,8 +70,10 @@ void ff_mp_image_alloc_planes(mp_image_t *mpi) { } } else { mpi->stride[0]=mpi->width*mpi->bpp/8; - if (mpi->flags & MP_IMGFLAG_RGB_PALETTE) + if (mpi->flags & MP_IMGFLAG_RGB_PALETTE) { mpi->planes[1] = av_malloc(1024); + memcpy(mpi->planes[1], temp, 1024); + } } mpi->flags|=MP_IMGFLAG_ALLOCATED; } diff --git a/libavfilter/libmpcodecs/mp_image.h b/libavfilter/libmpcodecs/mp_image.h index 35b50a60f1..aedf4510cd 100644 --- a/libavfilter/libmpcodecs/mp_image.h +++ b/libavfilter/libmpcodecs/mp_image.h @@ -37,6 +37,8 @@ #define ASMALIGN(ZEROBITS) ".p2align " #ZEROBITS "\n\t" #define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC). +enum AVPixelFormat ff_mp2ff_pix_fmt(int mp); + //--------- codec's requirements (filled by the codec/vf) --------- //--- buffer content restrictions: diff --git a/libavfilter/vf_mp.c b/libavfilter/vf_mp.c index 814b21ac9a..8edb20fb8f 100644 --- a/libavfilter/vf_mp.c +++ b/libavfilter/vf_mp.c @@ -207,6 +207,12 @@ zrmjpeg CpuCaps ff_gCpuCaps; //FIXME initialize this so optims work +enum AVPixelFormat ff_mp2ff_pix_fmt(int mp){ + int i; + for(i=0; conversion_map[i].fmt && mp != conversion_map[i].fmt; i++) + ; + return mp == conversion_map[i].fmt ? conversion_map[i].pix_fmt : AV_PIX_FMT_NONE; +} static void ff_sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam) {