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 | |
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')
-rw-r--r-- | libavcore/avcore.h | 2 | ||||
-rw-r--r-- | libavcore/imgutils.c | 29 | ||||
-rw-r--r-- | libavcore/imgutils.h | 13 |
3 files changed, 43 insertions, 1 deletions
diff --git a/libavcore/avcore.h b/libavcore/avcore.h index 3d661369b0..b19efe8cdb 100644 --- a/libavcore/avcore.h +++ b/libavcore/avcore.h @@ -27,7 +27,7 @@ #include "libavutil/avutil.h" #define LIBAVCORE_VERSION_MAJOR 0 -#define LIBAVCORE_VERSION_MINOR 14 +#define LIBAVCORE_VERSION_MINOR 15 #define LIBAVCORE_VERSION_MICRO 0 #define LIBAVCORE_VERSION_INT AV_VERSION_INT(LIBAVCORE_VERSION_MAJOR, \ 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; diff --git a/libavcore/imgutils.h b/libavcore/imgutils.h index 8458fc6bb0..6c39d53119 100644 --- a/libavcore/imgutils.h +++ b/libavcore/imgutils.h @@ -78,6 +78,19 @@ int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int heigh uint8_t *ptr, const int linesizes[4]); /** + * Allocate an image with size w and h and pixel format pix_fmt, and + * fill pointers and linesizes accordingly. + * The allocated image buffer has to be freed by using + * av_freep(&pointers[0]). + * + * @param align the value to use for buffer size alignment + * @return the size in bytes required for the image buffer, a negative + * error code in case of failure + */ +int av_image_alloc(uint8_t *pointers[4], int linesizes[4], + int w, int h, enum PixelFormat pix_fmt, int align); + +/** * Copy image plane from src to dst. * That is, copy "height" number of lines of "bytewidth" bytes each. * The first byte of each successive line is separated by *_linesize |