summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-04-20 21:27:45 +0200
committerwm4 <wm4@nowhere>2014-04-21 02:57:16 +0200
commit5e4e248dc200606e75bc382bebe045afc1962571 (patch)
tree5484bf360536a81ae344e49b9c6d009a08c4c2f0 /video
parent44096073e96c623f3e3c80bed7ee13d58869cecd (diff)
downloadmpv-5e4e248dc200606e75bc382bebe045afc1962571.tar.bz2
mpv-5e4e248dc200606e75bc382bebe045afc1962571.tar.xz
video: make mp_image use mp_image_params directly
Minor cleanup, so that we can stuff more information into mp_image_params later.
Diffstat (limited to 'video')
-rw-r--r--video/filter/vf.c22
-rw-r--r--video/mp_image.c63
-rw-r--r--video/mp_image.h14
-rw-r--r--video/out/gl_hwdec_vaglx.c2
-rw-r--r--video/out/vo_vdpau.c5
5 files changed, 37 insertions, 69 deletions
diff --git a/video/filter/vf.c b/video/filter/vf.c
index a37afde68b..9928b8a37e 100644
--- a/video/filter/vf.c
+++ b/video/filter/vf.c
@@ -176,10 +176,7 @@ static void vf_fix_img_params(struct mp_image *img, struct mp_image_params *p)
// If --colormatrix is used, decoder and filter chain disagree too.
// In general, it's probably more convenient to force these here,
// instead of requiring filters to set these correctly.
- img->colorspace = p->colorspace;
- img->levels = p->colorlevels;
- img->chroma_location = p->chroma_location;
- mp_image_set_display_size(img, p->d_w, p->d_h);
+ img->params = *p;
}
// Get a new image for filter output, with size and pixel format according to
@@ -411,17 +408,12 @@ int vf_next_config(struct vf_instance *vf,
int width, int height, int d_width, int d_height,
unsigned int voflags, unsigned int outfmt)
{
- vf->fmt_out = (struct mp_image_params) {
- .imgfmt = outfmt,
- .w = width,
- .h = height,
- .d_w = d_width,
- .d_h = d_height,
- .colorspace = vf->fmt_in.colorspace,
- .colorlevels = vf->fmt_in.colorlevels,
- .chroma_location = vf->fmt_in.chroma_location,
- .outputlevels = vf->fmt_in.outputlevels,
- };
+ vf->fmt_out = vf->fmt_in;
+ vf->fmt_out.imgfmt = outfmt;
+ vf->fmt_out.w = width;
+ vf->fmt_out.h = height;
+ vf->fmt_out.d_w = d_width;
+ vf->fmt_out.d_h = d_height;
return 1;
}
diff --git a/video/mp_image.c b/video/mp_image.c
index b9a15de409..6329e408cf 100644
--- a/video/mp_image.c
+++ b/video/mp_image.c
@@ -152,6 +152,7 @@ static void mp_image_alloc_planes(struct mp_image *mpi)
void mp_image_setfmt(struct mp_image *mpi, int out_fmt)
{
struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(out_fmt);
+ mpi->params.imgfmt = fmt.id;
mpi->fmt = fmt;
mpi->flags = fmt.flags;
mpi->imgfmt = fmt.id;
@@ -179,8 +180,9 @@ void mp_image_set_size(struct mp_image *mpi, int w, int h)
if (w >= (1 << 14) || h >= (1 << 14) || w < 0 || h < 0)
abort();
- mpi->w = mpi->display_w = w;
- mpi->h = mpi->display_h = h;
+ mpi->w = mpi->params.w = w;
+ mpi->h = mpi->params.h = h;
+ mp_image_set_display_size(mpi, mpi->w, mpi->h);
for (int n = 0; n < mpi->num_planes; n++) {
mpi->plane_w[n] = mp_chroma_div_up(mpi->w, mpi->fmt.xs[n]);
mpi->plane_h[n] = mp_chroma_div_up(mpi->h, mpi->fmt.ys[n]);
@@ -191,10 +193,22 @@ void mp_image_set_size(struct mp_image *mpi, int w, int h)
void mp_image_set_display_size(struct mp_image *mpi, int dw, int dh)
{
+ mpi->params.d_w = dw;
+ mpi->params.d_h = dh;
mpi->display_w = dw;
mpi->display_h = dh;
}
+void mp_image_set_params(struct mp_image *image,
+ const struct mp_image_params *params)
+{
+ image->params = *params;
+ // possibly reinitialize stuff
+ mp_image_setfmt(image, params->imgfmt);
+ mp_image_set_size(image, params->w, params->h);
+ mp_image_set_display_size(image, params->d_w, params->d_h);
+}
+
struct mp_image *mp_image_alloc(int imgfmt, int w, int h)
{
struct mp_image *mpi = talloc_zero(NULL, struct mp_image);
@@ -349,9 +363,9 @@ void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src)
dst->display_h = src->display_h;
}
if ((dst->flags & MP_IMGFLAG_YUV) == (src->flags & MP_IMGFLAG_YUV)) {
- dst->colorspace = src->colorspace;
- dst->levels = src->levels;
- dst->chroma_location = src->chroma_location;
+ dst->params.colorspace = src->params.colorspace;
+ dst->params.colorlevels = src->params.colorlevels;
+ dst->params.chroma_location = src->params.chroma_location;
}
if ((dst->fmt.flags & MP_IMGFLAG_PAL) && (src->fmt.flags & MP_IMGFLAG_PAL)) {
if (dst->planes[1] && src->planes[1])
@@ -446,28 +460,7 @@ bool mp_image_params_equals(const struct mp_image_params *p1,
void mp_image_params_from_image(struct mp_image_params *params,
const struct mp_image *image)
{
- // (Ideally mp_image should use mp_image_params directly instead)
- *params = (struct mp_image_params) {
- .imgfmt = image->imgfmt,
- .w = image->w,
- .h = image->h,
- .d_w = image->display_w,
- .d_h = image->display_h,
- .colorspace = image->colorspace,
- .colorlevels = image->levels,
- .chroma_location = image->chroma_location,
- };
-}
-
-void mp_image_set_params(struct mp_image *image,
- const struct mp_image_params *params)
-{
- mp_image_setfmt(image, params->imgfmt);
- mp_image_set_size(image, params->w, params->h);
- mp_image_set_display_size(image, params->d_w, params->d_h);
- image->colorspace = params->colorspace;
- image->levels = params->colorlevels;
- image->chroma_location = params->chroma_location;
+ *params = image->params;
}
// Set most image parameters, but not image format or size.
@@ -490,18 +483,6 @@ void mp_image_set_attributes(struct mp_image *image,
mp_image_set_params(image, &nparams);
}
-void mp_image_set_colorspace_details(struct mp_image *image,
- struct mp_csp_details *csp)
-{
- struct mp_image_params params;
- mp_image_params_from_image(&params, image);
- params.colorspace = csp->format;
- params.colorlevels = csp->levels_in;
- mp_image_params_guess_csp(&params);
- image->colorspace = params.colorspace;
- image->levels = params.colorlevels;
-}
-
// If details like params->colorspace/colorlevels are missing, guess them from
// the other settings. Also, even if they are set, make them consistent with
// the colorspace as implied by the pixel format.
@@ -592,8 +573,8 @@ void mp_image_copy_fields_to_av_frame(struct AVFrame *dst,
dst->repeat_pict = 1;
#if HAVE_AVFRAME_COLORSPACE
- dst->colorspace = mp_csp_to_avcol_spc(src->colorspace);
- dst->color_range = mp_csp_levels_to_avcol_range(src->levels);
+ dst->colorspace = mp_csp_to_avcol_spc(src->params.colorspace);
+ dst->color_range = mp_csp_levels_to_avcol_range(src->params.colorlevels);
#endif
}
diff --git a/video/mp_image.h b/video/mp_image.h
index 1e2933170a..c378a01b78 100644
--- a/video/mp_image.h
+++ b/video/mp_image.h
@@ -72,9 +72,11 @@ struct mp_image_params {
*/
typedef struct mp_image {
unsigned int flags; // same as fmt.flags
- struct mp_imgfmt_desc fmt;
- // fields redundant to fmt, for convenience or compatibility
+ struct mp_image_params params;
+
+ // fields redundant to params.imgfmt, for convenience or compatibility
+ struct mp_imgfmt_desc fmt;
enum mp_imgfmt imgfmt;
int num_planes;
int chroma_x_shift; // horizontal
@@ -97,10 +99,6 @@ typedef struct mp_image {
int plane_w[MP_MAX_PLANES];
int plane_h[MP_MAX_PLANES];
- enum mp_csp colorspace;
- enum mp_csp_levels levels;
- enum mp_chroma_location chroma_location;
-
/* only inside filter chain */
double pts;
/* memory management */
@@ -139,10 +137,6 @@ struct mp_image *mp_image_new_external_ref(struct mp_image *img, void *arg,
bool (*is_unique)(void *arg),
void (*free)(void *arg));
-struct mp_csp_details;
-void mp_image_set_colorspace_details(struct mp_image *image,
- struct mp_csp_details *csp);
-
void mp_image_params_guess_csp(struct mp_image_params *params);
bool mp_image_params_equals(const struct mp_image_params *p1,
diff --git a/video/out/gl_hwdec_vaglx.c b/video/out/gl_hwdec_vaglx.c
index 278718c67a..08c7f4957f 100644
--- a/video/out/gl_hwdec_vaglx.c
+++ b/video/out/gl_hwdec_vaglx.c
@@ -114,7 +114,7 @@ static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image,
status = vaCopySurfaceGLX(p->display, p->vaglx_surface,
va_surface_id(hw_image),
- va_get_colorspace_flag(hw_image->colorspace));
+ va_get_colorspace_flag(hw_image->params.colorspace));
if (!CHECK_VA_STATUS(p, "vaCopySurfaceGLX()"))
return -1;
diff --git a/video/out/vo_vdpau.c b/video/out/vo_vdpau.c
index dfc6b4d599..40168cb734 100644
--- a/video/out/vo_vdpau.c
+++ b/video/out/vo_vdpau.c
@@ -1207,8 +1207,9 @@ static struct mp_image *read_output_surface(struct vo *vo,
return NULL;
struct mp_image *image = mp_image_alloc(IMGFMT_BGR32, width, height);
- image->colorspace = MP_CSP_RGB;
- image->levels = vo->params->outputlevels; // hardcoded with conv. matrix
+ image->params.colorspace = MP_CSP_RGB;
+ // hardcoded with conv. matrix
+ image->params.colorlevels = vo->params->outputlevels;
void *dst_planes[] = { image->planes[0] };
uint32_t dst_pitches[] = { image->stride[0] };