From f282d0b290afbb8c4043316d36ea0085f427779e Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 26 Dec 2012 21:22:44 +0100 Subject: vf_crop: make it work with more image formats --- video/filter/vf_crop.c | 59 +++++++++++++++++--------------------------------- video/mp_image.h | 4 ++++ 2 files changed, 24 insertions(+), 39 deletions(-) (limited to 'video') diff --git a/video/filter/vf_crop.c b/video/filter/vf_crop.c index f9cb99eb75..6ef0d8d0c1 100644 --- a/video/filter/vf_crop.c +++ b/video/filter/vf_crop.c @@ -43,69 +43,50 @@ static const struct vf_priv_s { static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, - unsigned int flags, unsigned int outfmt){ - struct MPOpts *opts = vf->opts; + unsigned int flags, unsigned int outfmt) +{ // calculate the missing parameters: if(vf->priv->crop_w<=0 || vf->priv->crop_w>width) vf->priv->crop_w=width; if(vf->priv->crop_h<=0 || vf->priv->crop_h>height) vf->priv->crop_h=height; if(vf->priv->crop_x<0) vf->priv->crop_x=(width-vf->priv->crop_w)/2; if(vf->priv->crop_y<0) vf->priv->crop_y=(height-vf->priv->crop_h)/2; // rounding: - if(!IMGFMT_IS_RGB(outfmt)){ - switch(outfmt){ - case IMGFMT_444P: - case IMGFMT_Y8: - break; - case IMGFMT_410P: - vf->priv->crop_y&=~3; - case IMGFMT_411P: - vf->priv->crop_x&=~3; - break; - case IMGFMT_420P: - vf->priv->crop_y&=~1; - default: - vf->priv->crop_x&=~1; - } - } + + struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(outfmt); + + vf->priv->crop_x = MP_ALIGN_DOWN(vf->priv->crop_x, fmt.align_x); + vf->priv->crop_y = MP_ALIGN_DOWN(vf->priv->crop_y, fmt.align_y); + // check: if(vf->priv->crop_w+vf->priv->crop_x>width || vf->priv->crop_h+vf->priv->crop_y>height){ mp_tmsg(MSGT_VFILTER, MSGL_WARN, "[CROP] Bad position/width/height - cropped area outside of the original!\n"); return 0; } - if(!opts->screen_size_x && !opts->screen_size_y){ - d_width=d_width*vf->priv->crop_w/width; - d_height=d_height*vf->priv->crop_h/height; - } + vf_rescale_dsize(vf, &d_width, &d_height, width, height, + vf->priv->crop_w, vf->priv->crop_h); return vf_next_config(vf,vf->priv->crop_w,vf->priv->crop_h,d_width,d_height,flags,outfmt); } static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) { - mp_image_t *dmpi = mpi; - if(mpi->flags&MP_IMGFLAG_PLANAR){ - dmpi->planes[0]=mpi->planes[0]+ - vf->priv->crop_y*mpi->stride[0]+vf->priv->crop_x; - dmpi->planes[1]=mpi->planes[1]+ - (vf->priv->crop_y>>mpi->chroma_y_shift)*mpi->stride[1]+(vf->priv->crop_x>>mpi->chroma_x_shift); - dmpi->planes[2]=mpi->planes[2]+ - (vf->priv->crop_y>>mpi->chroma_y_shift)*mpi->stride[2]+(vf->priv->crop_x>>mpi->chroma_x_shift); - dmpi->stride[1]=mpi->stride[1]; - dmpi->stride[2]=mpi->stride[2]; - } else { - dmpi->planes[0]=mpi->planes[0]+ - vf->priv->crop_y*mpi->stride[0]+ - vf->priv->crop_x*(mpi->bpp/8); - } - mp_image_set_size(dmpi, vf->priv->crop_w, vf->priv->crop_h); + mp_image_crop(mpi, vf->priv->crop_x, vf->priv->crop_y, + vf->priv->crop_x + vf->priv->crop_w, + vf->priv->crop_y + vf->priv->crop_h); return mpi; } -//===========================================================================// +static int query_format(struct vf_instance *vf, unsigned int fmt) +{ + if (!IMGFMT_IS_HWACCEL(fmt)) + return vf_next_query_format(vf, fmt); + return 0; +} static int vf_open(vf_instance_t *vf, char *args){ vf->config=config; vf->filter=filter; + vf->query_format=query_format; mp_msg(MSGT_VFILTER, MSGL_INFO, "Crop: %d x %d, %d ; %d\n", vf->priv->crop_w, vf->priv->crop_h, diff --git a/video/mp_image.h b/video/mp_image.h index efbb7551b3..f5f246021a 100644 --- a/video/mp_image.h +++ b/video/mp_image.h @@ -126,4 +126,8 @@ struct mp_csp_details; void mp_image_set_colorspace_details(struct mp_image *image, struct mp_csp_details *csp); +// align must be a power of two (align >= 1), v >= 0 +#define MP_ALIGN_UP(v, align) FFALIGN(v, align) +#define MP_ALIGN_DOWN(v, align) ((v) & ~((align) - 1)) + #endif /* MPLAYER_MP_IMAGE_H */ -- cgit v1.2.3