libavfilter/libmpcodecs/vf_field.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 
00023 #include "config.h"
00024 #include "mp_msg.h"
00025 
00026 #include "mp_image.h"
00027 #include "vf.h"
00028 
00029 struct vf_priv_s {
00030     int field;
00031 };
00032 
00033 //===========================================================================//
00034 
00035 static int config(struct vf_instance *vf,
00036         int width, int height, int d_width, int d_height,
00037         unsigned int flags, unsigned int outfmt){
00038     return vf_next_config(vf,width,height/2,d_width,d_height,flags,outfmt);
00039 }
00040 
00041 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
00042     vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
00043         MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE,
00044         mpi->width, mpi->height/2);
00045 
00046     // set up mpi as a double-stride image of dmpi:
00047     vf->dmpi->planes[0]=mpi->planes[0]+mpi->stride[0]*vf->priv->field;
00048     vf->dmpi->stride[0]=2*mpi->stride[0];
00049     if(vf->dmpi->flags&MP_IMGFLAG_PLANAR){
00050         vf->dmpi->planes[1]=mpi->planes[1]+
00051             mpi->stride[1]*vf->priv->field;
00052         vf->dmpi->stride[1]=2*mpi->stride[1];
00053         vf->dmpi->planes[2]=mpi->planes[2]+
00054             mpi->stride[2]*vf->priv->field;
00055         vf->dmpi->stride[2]=2*mpi->stride[2];
00056     } else
00057         vf->dmpi->planes[1]=mpi->planes[1]; // passthru bgr8 palette!!!
00058 
00059     return vf_next_put_image(vf,vf->dmpi, pts);
00060 }
00061 
00062 //===========================================================================//
00063 
00064 static void uninit(struct vf_instance *vf)
00065 {
00066         free(vf->priv);
00067 }
00068 
00069 static int vf_open(vf_instance_t *vf, char *args){
00070     vf->config=config;
00071     vf->put_image=put_image;
00072     vf->uninit=uninit;
00073     vf->default_reqs=VFCAP_ACCEPT_STRIDE;
00074     vf->priv=calloc(1, sizeof(struct vf_priv_s));
00075     if (args) sscanf(args, "%d", &vf->priv->field);
00076     vf->priv->field &= 1;
00077     return 1;
00078 }
00079 
00080 const vf_info_t vf_info_field = {
00081     "extract single field",
00082     "field",
00083     "Rich Felker",
00084     "",
00085     vf_open,
00086     NULL
00087 };
00088 
00089 //===========================================================================//