mp_image: don't reset pixel aspect with mp_image_set_size()

No reason to do so. See also commit 240ba92b.

Since now many mp_images will never have a pixel aspect ratio set,
redefine a 0/0 aspect ratio to "undefined" instead invalid. This also
brings it more in line with how decoder vs. container aspect ratios are
handled.

Most callers seem to be fine with the new behavior.

mp_image_params_valid() in particular has to be adjusted, or some things
stop working due to mp_images not becoming valid after setting size and
format.
This commit is contained in:
wm4 2016-05-30 19:07:09 +02:00
parent 15bb05d2fe
commit 079f67268f
2 changed files with 3 additions and 4 deletions

View File

@ -87,7 +87,6 @@ void mp_image_setfmt(struct mp_image *mpi, int out_fmt)
mpi->fmt = fmt; mpi->fmt = fmt;
mpi->imgfmt = fmt.id; mpi->imgfmt = fmt.id;
mpi->num_planes = fmt.num_planes; mpi->num_planes = fmt.num_planes;
mp_image_set_size(mpi, mpi->w, mpi->h);
mpi->params = params; mpi->params = params;
} }
@ -122,7 +121,6 @@ void mp_image_set_size(struct mp_image *mpi, int w, int h)
assert(w >= 0 && h >= 0); assert(w >= 0 && h >= 0);
mpi->w = mpi->params.w = w; mpi->w = mpi->params.w = w;
mpi->h = mpi->params.h = h; mpi->h = mpi->params.h = h;
mpi->params.p_w = mpi->params.p_h = 1;
} }
void mp_image_set_params(struct mp_image *image, void mp_image_set_params(struct mp_image *image,
@ -543,7 +541,7 @@ bool mp_image_params_valid(const struct mp_image_params *p)
if (p->w <= 0 || p->h <= 0 || (p->w + 128LL) * (p->h + 128LL) >= INT_MAX / 8) if (p->w <= 0 || p->h <= 0 || (p->w + 128LL) * (p->h + 128LL) >= INT_MAX / 8)
return false; return false;
if (p->p_w <= 0 || p->p_h <= 0) if (p->p_w < 0 || p->p_h < 0)
return false; return false;
if (p->rotate < 0 || p->rotate >= 360) if (p->rotate < 0 || p->rotate >= 360)
@ -673,6 +671,7 @@ static void mp_image_copy_fields_from_av_frame(struct mp_image *dst,
{ {
mp_image_setfmt(dst, pixfmt2imgfmt(src->format)); mp_image_setfmt(dst, pixfmt2imgfmt(src->format));
mp_image_set_size(dst, src->width, src->height); mp_image_set_size(dst, src->width, src->height);
dst->params.p_w = dst->params.p_h = 1;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
dst->planes[i] = src->data[i]; dst->planes[i] = src->data[i];

View File

@ -42,7 +42,7 @@ struct mp_image_params {
uint64_t hw_subfmt; // underlying format for some hwaccel pixfmts uint64_t hw_subfmt; // underlying format for some hwaccel pixfmts
// (will use the HW API's format identifiers) // (will use the HW API's format identifiers)
int w, h; // image dimensions int w, h; // image dimensions
int p_w, p_h; // define pixel aspect ratio (never 0/0) int p_w, p_h; // define pixel aspect ratio (undefined: 0/0)
enum mp_csp colorspace; enum mp_csp colorspace;
enum mp_csp_levels colorlevels; enum mp_csp_levels colorlevels;
enum mp_csp_prim primaries; enum mp_csp_prim primaries;