diff options
author | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2010-12-04 12:56:16 +0000 |
---|---|---|
committer | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2010-12-04 12:56:16 +0000 |
commit | 4da12e3b13d362e0218956a78dd2b8f7a1260265 (patch) | |
tree | 685818343659dd00f74d638d375497651e01bf03 /libavcore/imgutils.c | |
parent | bf799f686fcee666e6bbb20ceffd838f341ec9b2 (diff) | |
download | ffmpeg-4da12e3b13d362e0218956a78dd2b8f7a1260265.tar.gz |
Implement av_image_alloc() and use it in
avfilter_default_get_video_buffer().
Originally committed as revision 25878 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcore/imgutils.c')
-rw-r--r-- | libavcore/imgutils.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libavcore/imgutils.c b/libavcore/imgutils.c index cf7909342d..0f449ff427 100644 --- a/libavcore/imgutils.c +++ b/libavcore/imgutils.c @@ -172,6 +172,35 @@ int ff_set_systematic_pal2(uint32_t pal[256], enum PixelFormat pix_fmt) return 0; } +int av_image_alloc(uint8_t *pointers[4], int linesizes[4], + int w, int h, enum PixelFormat pix_fmt, int align) +{ + int i, ret; + uint8_t *buf; + + if ((ret = av_image_check_size(w, h, 0, NULL)) < 0) + return ret; + if ((ret = av_image_fill_linesizes(linesizes, pix_fmt, w)) < 0) + return ret; + + for (i = 0; i < 4; i++) + linesizes[i] = FFALIGN(linesizes[i], align); + + if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, NULL, linesizes)) < 0) + return ret; + buf = av_malloc(ret + align); + if (!buf) + return AVERROR(ENOMEM); + if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, buf, linesizes)) < 0) { + av_free(buf); + return ret; + } + if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PAL) + ff_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt); + + return ret; +} + typedef struct ImgUtils { const AVClass *class; int log_offset; |