Commit c4be071d authored by Ronald S. Bultje's avatar Ronald S. Bultje

Merge dav1d_picture_alloc() and dav1d_picture_alloc_copy()

Also ensure we apply film-grain to delayed pictures.
parent b716083c
......@@ -3112,11 +3112,8 @@ int dav1d_submit_frame(Dav1dContext *const c) {
f->sr_cur.p.p.fullrange = f->seq_hdr.color_range;
if (f->frame_hdr.super_res.enabled) {
res = dav1d_picture_alloc(&f->cur, f->frame_hdr.width[0],
f->frame_hdr.height, f->seq_hdr.layout,
f->seq_hdr.bpc, &c->allocator);
res = dav1d_picture_alloc_copy(&f->cur, f->frame_hdr.width[0], &f->sr_cur.p);
if (res < 0) goto error;
f->cur.poc = f->frame_hdr.frame_offset;
} else {
dav1d_picture_ref(&f->cur, &f->sr_cur.p);
}
......
......@@ -187,7 +187,7 @@ static int output_image(Dav1dContext *const c, Dav1dPicture *const out,
}
// Apply film grain to a new copy of the image to avoid corrupting refs
int res = dav1d_picture_alloc_copy(out, in);
int res = dav1d_picture_alloc_copy(out, in->p.w, in);
if (res < 0)
return res;
......@@ -233,14 +233,11 @@ int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out)
if (++c->frame_thread.next == c->n_fc)
c->frame_thread.next = 0;
if (out_delayed->p.data[0]) {
if (out_delayed->visible && !out_delayed->flushed) {
dav1d_picture_ref(out, &out_delayed->p);
}
if (out_delayed->visible && !out_delayed->flushed)
dav1d_picture_ref(&c->out, &out_delayed->p);
dav1d_thread_picture_unref(out_delayed);
if (out->data[0]) {
return 0;
}
// else continue
if (c->out.data[0])
return output_image(c, out, &c->out);
}
} while (++flush_count < c->n_fc);
return -EAGAIN;
......
......@@ -150,13 +150,6 @@ static int picture_alloc_with_edges(Dav1dPicture *const p,
return 0;
}
int dav1d_picture_alloc(Dav1dPicture *const p, const int w, const int h,
const enum Dav1dPixelLayout layout, const int bpc,
Dav1dPicAllocator *const p_allocator)
{
return picture_alloc_with_edges(p, w, h, layout, bpc, p_allocator, 0, NULL);
}
int dav1d_thread_picture_alloc(Dav1dThreadPicture *const p,
const int w, const int h,
const enum Dav1dPixelLayout layout, const int bpc,
......@@ -180,12 +173,13 @@ int dav1d_thread_picture_alloc(Dav1dThreadPicture *const p,
return res;
}
int dav1d_picture_alloc_copy(Dav1dPicture *const dst,
int dav1d_picture_alloc_copy(Dav1dPicture *const dst, const int w,
const Dav1dPicture *const src)
{
struct pic_ctx_context *const pic_ctx = src->ref->user_data;
int res = dav1d_picture_alloc(dst, src->p.w, src->p.h, src->p.layout,
src->p.bpc, &pic_ctx->allocator);
const int res = picture_alloc_with_edges(dst, w, src->p.h, src->p.layout,
src->p.bpc, &pic_ctx->allocator,
0, NULL);
if (!res) {
dst->poc = src->poc;
......
......@@ -54,10 +54,6 @@ typedef struct Dav1dThreadPicture {
/*
* Allocate a picture with custom border size.
*/
int dav1d_picture_alloc(Dav1dPicture *p, int w, int h,
enum Dav1dPixelLayout layout, int bpc,
Dav1dPicAllocator *);
int dav1d_thread_picture_alloc(Dav1dThreadPicture *p, int w, int h,
enum Dav1dPixelLayout layout, int bpc,
struct thread_data *t, int visible,
......@@ -65,8 +61,13 @@ int dav1d_thread_picture_alloc(Dav1dThreadPicture *p, int w, int h,
/**
* Allocate a picture with identical metadata to an existing picture.
* The width is a separate argument so this function can be used for
* super-res, where the width changes, but everything else is the same.
* For the more typical use case of allocating a new image of the same
* dimensions, use src->p.w as width.
*/
int dav1d_picture_alloc_copy(Dav1dPicture *dst, const Dav1dPicture *src);
int dav1d_picture_alloc_copy(Dav1dPicture *dst, const int w,
const Dav1dPicture *src);
/**
* Create a copy of a picture.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment