summaryrefslogtreecommitdiff
path: root/libavcore
diff options
context:
space:
mode:
Diffstat (limited to 'libavcore')
-rw-r--r--libavcore/avcore.h2
-rw-r--r--libavcore/imgutils.c29
-rw-r--r--libavcore/imgutils.h13
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