mf demuxer only works with mf:// urls, so check for that.
[mplayer/glamo.git] / libmpcodecs / vf_mirror.c
blob2466befc5a60f637fd6a1831af588713f072d017
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <inttypes.h>
6 #include "config.h"
7 #include "mp_msg.h"
9 #include "img_format.h"
10 #include "mp_image.h"
11 #include "vf.h"
13 #include "libvo/fastmemcpy.h"
16 static void mirror(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,unsigned int fmt){
17 int y;
18 for(y=0;y<h;y++){
19 int x;
20 switch(bpp){
21 case 1:
22 for(x=0;x<w;x++) dst[x]=src[w-x-1];
23 break;
24 case 2:
25 switch(fmt){
26 case IMGFMT_UYVY: {
27 // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
28 int w2=w>>1;
29 for(x=0;x<w2;x++){
30 // TODO: optimize this...
31 dst[x*4+0]=src[0+(w2-x-1)*4];
32 dst[x*4+1]=src[3+(w2-x-1)*4];
33 dst[x*4+2]=src[2+(w2-x-1)*4];
34 dst[x*4+3]=src[1+(w2-x-1)*4];
36 break; }
37 case IMGFMT_YUY2:
38 case IMGFMT_YVYU: {
39 // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
40 int w2=w>>1;
41 for(x=0;x<w2;x++){
42 // TODO: optimize this...
43 dst[x*4+0]=src[2+(w2-x-1)*4];
44 dst[x*4+1]=src[1+(w2-x-1)*4];
45 dst[x*4+2]=src[0+(w2-x-1)*4];
46 dst[x*4+3]=src[3+(w2-x-1)*4];
48 break; }
49 default:
50 for(x=0;x<w;x++) *((short*)(dst+x*2))=*((short*)(src+(w-x-1)*2));
52 break;
53 case 3:
54 for(x=0;x<w;x++){
55 dst[x*3+0]=src[0+(w-x-1)*3];
56 dst[x*3+1]=src[1+(w-x-1)*3];
57 dst[x*3+2]=src[2+(w-x-1)*3];
59 break;
60 case 4:
61 for(x=0;x<w;x++) *((int*)(dst+x*4))=*((int*)(src+(w-x-1)*4));
63 src+=srcstride;
64 dst+=dststride;
68 //===========================================================================//
70 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
71 mp_image_t *dmpi;
73 // hope we'll get DR buffer:
74 dmpi=vf_get_image(vf->next,mpi->imgfmt,
75 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
76 mpi->w, mpi->h);
78 if(mpi->flags&MP_IMGFLAG_PLANAR){
79 mirror(dmpi->planes[0],mpi->planes[0],
80 dmpi->stride[0],mpi->stride[0],
81 dmpi->w,dmpi->h,1,mpi->imgfmt);
82 mirror(dmpi->planes[1],mpi->planes[1],
83 dmpi->stride[1],mpi->stride[1],
84 dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
85 mirror(dmpi->planes[2],mpi->planes[2],
86 dmpi->stride[2],mpi->stride[2],
87 dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
88 } else {
89 mirror(dmpi->planes[0],mpi->planes[0],
90 dmpi->stride[0],mpi->stride[0],
91 dmpi->w,dmpi->h,dmpi->bpp>>3,mpi->imgfmt);
92 dmpi->planes[1]=mpi->planes[1]; // passthrough rgb8 palette
95 return vf_next_put_image(vf,dmpi, pts);
98 //===========================================================================//
100 static int open(vf_instance_t *vf, char* args){
101 //vf->config=config;
102 vf->put_image=put_image;
103 return 1;
106 vf_info_t vf_info_mirror = {
107 "horizontal mirror",
108 "mirror",
109 "Eyck",
111 open,
112 NULL
115 //===========================================================================//