1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-22 03:08:33 +00:00

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.
This commit is contained in:
wm4 2012-11-10 02:02:24 +01:00
parent 1568161aad
commit d77d9fb933
14 changed files with 41 additions and 46 deletions

View File

@ -333,11 +333,7 @@ static void mp_image_crop(struct mp_image *img, struct mp_rect rc)
(rc.y0 >> (p ? img->chroma_y_shift : 0)) * img->stride[p] +
(rc.x0 >> (p ? img->chroma_x_shift : 0)) * bits / 8;
}
img->w = rc.x1 - rc.x0;
img->h = rc.y1 - rc.y0;
img->chroma_width = img->w >> img->chroma_x_shift;
img->chroma_height = img->h >> img->chroma_y_shift;
img->display_w = img->display_h = 0;
mp_image_set_size(img, rc.x1 - rc.x0, rc.y1 - rc.y0);
}
static bool clip_to_bb(struct mp_rect bb, struct mp_rect *rc)

View File

@ -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];

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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:

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}