From 92a1b6fa21493f8497617704cd30172ebcd4d852 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 26 Dec 2012 21:27:53 +0100 Subject: vf_mirror: rewrite Properly handle odd image sizes. Probably makes it work with more image formats. --- video/filter/vf_mirror.c | 117 +++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 65 deletions(-) (limited to 'video') diff --git a/video/filter/vf_mirror.c b/video/filter/vf_mirror.c index 56fc2ebb3d..301583594f 100644 --- a/video/filter/vf_mirror.c +++ b/video/filter/vf_mirror.c @@ -28,90 +28,77 @@ #include "video/mp_image.h" #include "vf.h" +static int config(struct vf_instance *vf, int width, int height, + int d_width, int d_height, + unsigned int flags, unsigned int fmt) +{ + struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt); + int a_w = MP_ALIGN_DOWN(width, desc.align_x); + vf_rescale_dsize(vf, &d_width, &d_height, width, height, a_w, height); + return vf_next_config(vf, a_w, height, d_width, d_height, flags, fmt); +} -static void mirror(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,unsigned int fmt){ - int y; - for(y=0;y>1; - for(x=0;x>1; - for(x=0;xflags&MP_IMGFLAG_PLANAR){ - mirror(dmpi->planes[0],mpi->planes[0], - dmpi->stride[0],mpi->stride[0], - dmpi->w,dmpi->h,1,mpi->imgfmt); - mirror(dmpi->planes[1],mpi->planes[1], - dmpi->stride[1],mpi->stride[1], - dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt); - mirror(dmpi->planes[2],mpi->planes[2], - dmpi->stride[2],mpi->stride[2], - dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt); - } else { - mirror(dmpi->planes[0],mpi->planes[0], - dmpi->stride[0],mpi->stride[0], - dmpi->w,dmpi->h,dmpi->bpp>>3,mpi->imgfmt); + for (int p = 0; p < mpi->num_planes; p++) { + for (int y = 0; y < mpi->plane_h[p]; y++) { + void *p_src = mpi->planes[p] + mpi->stride[p] * y; + void *p_dst = dmpi->planes[p] + dmpi->stride[p] * y; + int w = dmpi->plane_w[p]; + if (mpi->imgfmt == IMGFMT_YUYV) { + mirror_4_m(p_dst, p_src, w / 2, 2, 1, 0, 3); + } else if (mpi->imgfmt == IMGFMT_UYVY) { + mirror_4_m(p_dst, p_src, w / 2, 0, 3, 2, 1); + } else { + // make the compiler unroll the memcpy in mirror() + switch (mpi->fmt.bytes[p]) { + case 1: mirror(p_dst, p_src, 1, w); break; + case 2: mirror(p_dst, p_src, 2, w); break; + case 3: mirror(p_dst, p_src, 3, w); break; + case 4: mirror(p_dst, p_src, 4, w); break; + default: + mirror(p_dst, p_src, mpi->fmt.bytes[p], w); + } + } + } } talloc_free(mpi); return dmpi; } -//===========================================================================// +static int query_format(struct vf_instance *vf, unsigned int fmt) +{ + struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt); + if (!(desc.flags & MP_IMGFLAG_BYTE_ALIGNED)) + return 0; + return vf_next_query_format(vf, fmt); +} static int vf_open(vf_instance_t *vf, char *args){ - //vf->config=config; + vf->config=config; vf->filter=filter; + vf->query_format=query_format; return 1; } -- cgit v1.2.3