summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-10 02:02:24 +0100
committerwm4 <wm4@nowhere>2013-01-13 17:39:32 +0100
commitd77d9fb933e0e7dc34de02f3d0c13791ddd80114 (patch)
treeca45e0f9d753e7ee7b5bd142eb2aed1638bf391c /video
parent1568161aadf24ee3a6d982612b7380f8b1dc4a58 (diff)
downloadmpv-d77d9fb933e0e7dc34de02f3d0c13791ddd80114.tar.bz2
mpv-d77d9fb933e0e7dc34de02f3d0c13791ddd80114.tar.xz
mp_image: require using mp_image_set_size() for setting w/h
Setting the size of a mp_image must be done with mp_image_set_size() now. Do this to guarantee that the redundant fields (like chroma_width) are updated consistently. Replacing the redundant fields by function calls would probably be better, but there are too many uses of them, and is a bit less convenient. Most code actually called mp_image_setfmt(), which did this as well. This commit just makes things a bit more explicit. Warning: the video filter chain still sets up mp_images manually, and vf_get_image() is not updated.
Diffstat (limited to 'video')
-rw-r--r--video/decode/vd_lavc.c3
-rw-r--r--video/filter/vf_screenshot.c8
-rw-r--r--video/mp_image.c19
-rw-r--r--video/mp_image.h3
-rw-r--r--video/out/vo_corevideo.m3
-rw-r--r--video/out/vo_direct3d.c10
-rw-r--r--video/out/vo_image.c3
-rw-r--r--video/out/vo_opengl.c7
-rw-r--r--video/out/vo_opengl_old.c7
-rw-r--r--video/out/vo_sdl.c3
-rw-r--r--video/out/vo_vdpau.c6
-rw-r--r--video/out/vo_x11.c3
-rw-r--r--video/out/vo_xv.c6
13 files changed, 40 insertions, 41 deletions
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 120555b283..3ee8cc7932 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -733,8 +733,7 @@ static int decode(struct sh_video *sh, struct demux_packet *packet, void *data,
struct mp_image new = {0};
new.type = MP_IMGTYPE_EXPORT;
new.flags = MP_IMGFLAG_PRESERVE;
- new.w = new.width = avctx->width;
- new.h = new.height = avctx->height;
+ mp_image_set_size(&new, avctx->width, avctx->height);
mp_image_setfmt(&new, ctx->best_csp);
for (int i = 0; i < 4; i++) {
new.planes[i] = pic->data[i];
diff --git a/video/filter/vf_screenshot.c b/video/filter/vf_screenshot.c
index 29d2e0b1e0..d94bb3c5cf 100644
--- a/video/filter/vf_screenshot.c
+++ b/video/filter/vf_screenshot.c
@@ -91,11 +91,9 @@ static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
vf->priv->shot=0;
mp_image_t image = *dmpi;
image.flags &= ~MP_IMGFLAG_ALLOCATED;
- image.w = vf->priv->image->w;
- image.h = vf->priv->image->h;
- vf_clone_mpi_attributes(&image, mpi);
- image.display_w = vf->priv->image->display_w;
- image.display_h = vf->priv->image->display_h;
+ mp_image_copy_attributes(&image, mpi);
+ mp_image_set_display_size(&image, vf->priv->image->display_w,
+ vf->priv->image->display_h);
vf->priv->image_callback(vf->priv->image_callback_ctx, &image);
}
diff --git a/video/mp_image.c b/video/mp_image.c
index 1de8abaed5..c829464a4e 100644
--- a/video/mp_image.c
+++ b/video/mp_image.c
@@ -309,11 +309,26 @@ struct mp_image *mp_image_new_empty(int w, int h)
{
struct mp_image *mpi = talloc_zero(NULL, struct mp_image);
talloc_set_destructor(mpi, mp_image_destructor);
- mpi->width=mpi->w=w;
- mpi->height=mpi->h=h;
+ mp_image_set_size(mpi, w, h);
return mpi;
}
+// Caller has to make sure this doesn't exceed the allocated plane data/strides.
+void mp_image_set_size(struct mp_image *mpi, int w, int h)
+{
+ mpi->w = mpi->width = w;
+ mpi->h = mpi->height = h;
+ mpi->chroma_width = mpi->w >> mpi->chroma_x_shift;
+ mpi->chroma_height = mpi->h >> mpi->chroma_y_shift;
+ mpi->display_w = mpi->display_h = 0;
+}
+
+void mp_image_set_display_size(struct mp_image *mpi, int dw, int dh)
+{
+ mpi->display_w = dw;
+ mpi->display_h = dh;
+}
+
struct mp_image *mp_image_alloc(unsigned int imgfmt, int w, int h)
{
struct mp_image *mpi = mp_image_new_empty(w, h);
diff --git a/video/mp_image.h b/video/mp_image.h
index c57d0a63e9..2fb693eb65 100644
--- a/video/mp_image.h
+++ b/video/mp_image.h
@@ -166,6 +166,9 @@ void mp_image_make_writeable(struct mp_image *img);
void mp_image_setrefp(struct mp_image **p_img, struct mp_image *new_value);
void mp_image_unrefp(struct mp_image **p_img);
+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);
+
struct mp_image *mp_image_new_empty(int w, int h);
void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt);
void mp_image_alloc_planes(struct mp_image *mpi);
diff --git a/video/out/vo_corevideo.m b/video/out/vo_corevideo.m
index bc8833f12f..292dfea5a5 100644
--- a/video/out/vo_corevideo.m
+++ b/video/out/vo_corevideo.m
@@ -373,8 +373,7 @@ static mp_image_t *get_screenshot(struct vo *vo)
memcpy(image->planes[0], base, image_size);
image->stride[0] = stride;
- image->display_w = vo->aspdat.prew;
- image->display_h = vo->aspdat.preh;
+ mp_image_set_display_size(image, vo->aspdat.prew, vo->aspdat.preh);
mp_image_set_colorspace_details(image, &p->colorspace);
diff --git a/video/out/vo_direct3d.c b/video/out/vo_direct3d.c
index ab69fdbdf2..d3c907f944 100644
--- a/video/out/vo_direct3d.c
+++ b/video/out/vo_direct3d.c
@@ -1558,8 +1558,7 @@ static void check_events(struct vo *vo)
static bool get_video_buffer(d3d_priv *priv, struct mp_image *out)
{
*out = (struct mp_image) {0};
- out->w = out->width = priv->src_width;
- out->h = out->height = priv->src_height;
+ mp_image_set_size(out, priv->src_width, priv->src_height);
mp_image_setfmt(out, priv->image_format);
if (!priv->d3d_device)
@@ -1639,10 +1638,9 @@ static mp_image_t *get_screenshot(d3d_priv *priv)
if (!get_video_buffer(priv, &buffer))
return NULL;
- struct mp_image *image = alloc_mpi(buffer.w, buffer.h, buffer.imgfmt);
- copy_mpi(image, &buffer);
- image->display_w = priv->vo->aspdat.prew;
- image->display_h = priv->vo->aspdat.preh;
+ struct mp_image *image = mp_image_new_copy(&buffer);
+ mp_image_set_display_size(image, priv->vo->aspdat.prew,
+ priv->vo->aspdat.preh);
mp_image_set_colorspace_details(image, &priv->colorspace);
diff --git a/video/out/vo_image.c b/video/out/vo_image.c
index 7862ceb596..12bd18862a 100644
--- a/video/out/vo_image.c
+++ b/video/out/vo_image.c
@@ -101,8 +101,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi)
struct priv *p = vo->priv;
mp_image_t img = *mpi;
- img.display_w = p->d_width;
- img.display_h = p->d_height;
+ mp_image_set_display_size(&img, p->d_width, p->d_height);
mp_image_set_colorspace_details(&img, &p->colorspace);
void *t = talloc_new(NULL);
diff --git a/video/out/vo_opengl.c b/video/out/vo_opengl.c
index 759cb96ba7..fc94a86eac 100644
--- a/video/out/vo_opengl.c
+++ b/video/out/vo_opengl.c
@@ -1350,11 +1350,8 @@ static mp_image_t *get_screenshot(struct gl_priv *p)
image->planes[n], image->stride[n]);
}
gl->ActiveTexture(GL_TEXTURE0);
-
- image->w = p->image_width;
- image->h = p->image_height;
- image->display_w = p->vo->aspdat.prew;
- image->display_h = p->vo->aspdat.preh;
+ mp_image_set_size(image, p->image_width, p->image_height);
+ mp_image_set_display_size(image, p->vo->aspdat.prew, p->vo->aspdat.preh);
mp_image_set_colorspace_details(image, &p->colorspace);
diff --git a/video/out/vo_opengl_old.c b/video/out/vo_opengl_old.c
index 3f629ed43e..a8ad21408e 100644
--- a/video/out/vo_opengl_old.c
+++ b/video/out/vo_opengl_old.c
@@ -806,11 +806,8 @@ static mp_image_t *get_screenshot(struct vo *vo)
image->stride[2]);
gl->ActiveTexture(GL_TEXTURE0);
}
-
- image->w = p->image_width;
- image->h = p->image_height;
- image->display_w = vo->aspdat.prew;
- image->display_h = vo->aspdat.preh;
+ mp_image_set_size(image, p->image_width, p->image_height);
+ mp_image_set_display_size(image, vo->aspdat.prew, vo->aspdat.preh);
mp_image_set_colorspace_details(image, &p->colorspace);
diff --git a/video/out/vo_sdl.c b/video/out/vo_sdl.c
index f5a17b84d3..d04a63e5a6 100644
--- a/video/out/vo_sdl.c
+++ b/video/out/vo_sdl.c
@@ -435,8 +435,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
}
mp_image_t *texmpi = &vc->texmpi;
- texmpi->width = texmpi->w = width;
- texmpi->height = texmpi->h = height;
+ mp_image_set_size(texmpi, width, height);
mp_image_setfmt(texmpi, format);
switch (texmpi->num_planes) {
case 1:
diff --git a/video/out/vo_vdpau.c b/video/out/vo_vdpau.c
index 67ac0593f8..661072b814 100644
--- a/video/out/vo_vdpau.c
+++ b/video/out/vo_vdpau.c
@@ -1375,8 +1375,7 @@ static struct mp_image *get_screenshot(struct vo *vo)
struct mp_image *image = read_output_surface(vc, vc->screenshot_surface,
vc->vid_width, vc->vid_height);
- image->display_w = vo->aspdat.prew;
- image->display_h = vo->aspdat.preh;
+ mp_image_set_display_size(image, vo->aspdat.prew, vo->aspdat.preh);
return image;
}
@@ -1389,8 +1388,7 @@ static struct mp_image *get_window_screenshot(struct vo *vo)
struct mp_image *image = read_output_surface(vo->priv, screen,
vc->output_surface_width,
vc->output_surface_height);
- image->width = image->w = vo->dwidth;
- image->height = image->h = vo->dheight;
+ mp_image_set_size(image, vo->dwidth, vo->dheight);
return image;
}
diff --git a/video/out/vo_x11.c b/video/out/vo_x11.c
index 98ebc7f6d1..58c709e471 100644
--- a/video/out/vo_x11.c
+++ b/video/out/vo_x11.c
@@ -419,8 +419,7 @@ static void Display_Image(struct priv *p, XImage *myximage, uint8_t *ImageData)
static struct mp_image get_x_buffer(struct priv *p)
{
struct mp_image img = {0};
- img.w = img.width = p->image_width;
- img.h = img.height = p->image_height;
+ mp_image_set_size(&img, p->image_width, p->image_height);
mp_image_setfmt(&img, p->out_format);
img.planes[0] = p->ImageData;
diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c
index cc4d55777d..46fe4649f5 100644
--- a/video/out/vo_xv.c
+++ b/video/out/vo_xv.c
@@ -318,8 +318,7 @@ static struct mp_image get_xv_buffer(struct vo *vo, int buf_index)
XvImage *xv_image = ctx->xvimage[buf_index];
struct mp_image img = {0};
- img.w = img.width = ctx->image_width;
- img.h = img.height = ctx->image_height;
+ mp_image_set_size(&img, ctx->image_width, ctx->image_height);
mp_image_setfmt(&img, ctx->image_format);
bool swapuv = ctx->image_format == IMGFMT_YV12;
@@ -398,10 +397,9 @@ static mp_image_t *get_screenshot(struct vo *vo)
struct mp_image *res = alloc_mpi(img.w, img.h, img.imgfmt);
copy_mpi(res, &img);
vf_clone_mpi_attributes(res, &img);
+ mp_image_set_display_size(res, vo->aspdat.prew, vo->aspdat.preh);
// try to get an image without OSD
mp_draw_sub_backup_restore(ctx->osd_backup, res);
- res->display_w = vo->aspdat.prew;
- res->display_h = vo->aspdat.preh;
return res;
}