• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavfilter/libmpcodecs/vf_mirror.c

Go to the documentation of this file.
00001 /*
00002  * This file is part of MPlayer.
00003  *
00004  * MPlayer is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * MPlayer is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License along
00015  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <inttypes.h>
00023 
00024 #include "config.h"
00025 #include "mp_msg.h"
00026 
00027 #include "img_format.h"
00028 #include "mp_image.h"
00029 #include "vf.h"
00030 
00031 
00032 static void mirror(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,unsigned int fmt){
00033     int y;
00034     for(y=0;y<h;y++){
00035         int x;
00036         switch(bpp){
00037         case 1:
00038             for(x=0;x<w;x++) dst[x]=src[w-x-1];
00039             break;
00040         case 2:
00041             switch(fmt){
00042             case IMGFMT_UYVY: {
00043                 // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
00044                 int w2=w>>1;
00045                 for(x=0;x<w2;x++){
00046                     // TODO: optimize this...
00047                     dst[x*4+0]=src[0+(w2-x-1)*4];
00048                     dst[x*4+1]=src[3+(w2-x-1)*4];
00049                     dst[x*4+2]=src[2+(w2-x-1)*4];
00050                     dst[x*4+3]=src[1+(w2-x-1)*4];
00051                 }
00052                 break; }
00053             case IMGFMT_YUY2:
00054             case IMGFMT_YVYU: {
00055                 // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
00056                 int w2=w>>1;
00057                 for(x=0;x<w2;x++){
00058                     // TODO: optimize this...
00059                     dst[x*4+0]=src[2+(w2-x-1)*4];
00060                     dst[x*4+1]=src[1+(w2-x-1)*4];
00061                     dst[x*4+2]=src[0+(w2-x-1)*4];
00062                     dst[x*4+3]=src[3+(w2-x-1)*4];
00063                 }
00064                 break; }
00065             default:
00066                 for(x=0;x<w;x++) *((short*)(dst+x*2))=*((short*)(src+(w-x-1)*2));
00067             }
00068             break;
00069         case 3:
00070             for(x=0;x<w;x++){
00071                 dst[x*3+0]=src[0+(w-x-1)*3];
00072                 dst[x*3+1]=src[1+(w-x-1)*3];
00073                 dst[x*3+2]=src[2+(w-x-1)*3];
00074             }
00075             break;
00076         case 4:
00077             for(x=0;x<w;x++) *((int*)(dst+x*4))=*((int*)(src+(w-x-1)*4));
00078         }
00079         src+=srcstride;
00080         dst+=dststride;
00081     }
00082 }
00083 
00084 //===========================================================================//
00085 
00086 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
00087     mp_image_t *dmpi;
00088 
00089     // hope we'll get DR buffer:
00090     dmpi=vf_get_image(vf->next,mpi->imgfmt,
00091         MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
00092         mpi->w, mpi->h);
00093 
00094     if(mpi->flags&MP_IMGFLAG_PLANAR){
00095                mirror(dmpi->planes[0],mpi->planes[0],
00096                dmpi->stride[0],mpi->stride[0],
00097                dmpi->w,dmpi->h,1,mpi->imgfmt);
00098                mirror(dmpi->planes[1],mpi->planes[1],
00099                dmpi->stride[1],mpi->stride[1],
00100                dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
00101                mirror(dmpi->planes[2],mpi->planes[2],
00102                dmpi->stride[2],mpi->stride[2],
00103                dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
00104     } else {
00105         mirror(dmpi->planes[0],mpi->planes[0],
00106                dmpi->stride[0],mpi->stride[0],
00107                dmpi->w,dmpi->h,dmpi->bpp>>3,mpi->imgfmt);
00108         dmpi->planes[1]=mpi->planes[1]; // passthrough rgb8 palette
00109     }
00110 
00111     return vf_next_put_image(vf,dmpi, pts);
00112 }
00113 
00114 //===========================================================================//
00115 
00116 static int vf_open(vf_instance_t *vf, char *args){
00117     //vf->config=config;
00118     vf->put_image=put_image;
00119     return 1;
00120 }
00121 
00122 const vf_info_t vf_info_mirror = {
00123     "horizontal mirror",
00124     "mirror",
00125     "Eyck",
00126     "",
00127     vf_open,
00128     NULL
00129 };
00130 
00131 //===========================================================================//

Generated on Wed Apr 11 2012 07:31:36 for FFmpeg by  doxygen 1.7.1