summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2018-09-11 11:48:38 -0300
committerJames Almer <jamrial@gmail.com>2018-09-11 13:08:50 -0300
commit8822e2b9543bb02fb2889dff627b6db023053253 (patch)
treedcac55512239fc603d3470a1dedb837d96eb1b79 /libavutil
parent44ee858b6df0f3f350abd56bd18340c1d8d94ee8 (diff)
parentf89ec87afaf0d1abb6d450253b0b348fd554533b (diff)
downloadffmpeg-8822e2b9543bb02fb2889dff627b6db023053253.tar.gz
Merge commit 'f89ec87afaf0d1abb6d450253b0b348fd554533b'
* commit 'f89ec87afaf0d1abb6d450253b0b348fd554533b': frame: Simplify the video allocation Merged-by: James Almer <jamrial@gmail.com> Padding-Remixed-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/frame.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/libavutil/frame.c b/libavutil/frame.c
index deb9b6f334..6c2c28f18f 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -211,7 +211,8 @@ void av_frame_free(AVFrame **frame)
static int get_video_buffer(AVFrame *frame, int align)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
- int ret, i;
+ int ret, i, padded_height;
+ int plane_padding = FFMAX(16 + 16/*STRIDE_ALIGN*/, align);
if (!desc)
return AVERROR(EINVAL);
@@ -236,23 +237,22 @@ static int get_video_buffer(AVFrame *frame, int align)
frame->linesize[i] = FFALIGN(frame->linesize[i], align);
}
- for (i = 0; i < 4 && frame->linesize[i]; i++) {
- int h = FFALIGN(frame->height, 32);
- if (i == 1 || i == 2)
- h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
+ padded_height = FFALIGN(frame->height, 32);
+ if ((ret = av_image_fill_pointers(frame->data, frame->format, padded_height,
+ NULL, frame->linesize)) < 0)
+ return ret;
- frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h + 16 + 16/*STRIDE_ALIGN*/ - 1);
- if (!frame->buf[i])
- goto fail;
+ frame->buf[0] = av_buffer_alloc(ret + 4*plane_padding);
+ if (!frame->buf[0])
+ goto fail;
- frame->data[i] = frame->buf[i]->data;
- }
- if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & FF_PSEUDOPAL) {
- av_buffer_unref(&frame->buf[1]);
- frame->buf[1] = av_buffer_alloc(AVPALETTE_SIZE);
- if (!frame->buf[1])
- goto fail;
- frame->data[1] = frame->buf[1]->data;
+ if (av_image_fill_pointers(frame->data, frame->format, padded_height,
+ frame->buf[0]->data, frame->linesize) < 0)
+ goto fail;
+
+ for (i = 1; i < 4; i++) {
+ if (frame->data[i])
+ frame->data[i] += i * plane_padding;
}
frame->extended_data = frame->data;