libavfilter/libmpcodecs/vf_telecine.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 "img_format.h"
00027 #include "mp_image.h"
00028 #include "vf.h"
00029 
00030 #include "libvo/fastmemcpy.h"
00031 
00032 struct vf_priv_s {
00033     int frame;
00034 };
00035 
00036 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
00037 {
00038     mp_image_t *dmpi;
00039     int ret;
00040 
00041     vf->priv->frame = (vf->priv->frame+1)%4;
00042 
00043     dmpi = vf_get_image(vf->next, mpi->imgfmt,
00044         MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
00045         MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
00046 
00047     ret = 0;
00048     //    0/0  1/1  2/2  2/3  3/0
00049     switch (vf->priv->frame) {
00050     case 0:
00051         my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
00052             mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
00053             dmpi->stride[0]*2, mpi->stride[0]*2);
00054         if (mpi->flags & MP_IMGFLAG_PLANAR) {
00055             my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
00056                 mpi->planes[1]+mpi->stride[1],
00057                 mpi->chroma_width, mpi->chroma_height/2,
00058                 dmpi->stride[1]*2, mpi->stride[1]*2);
00059             my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
00060                 mpi->planes[2]+mpi->stride[2],
00061                 mpi->chroma_width, mpi->chroma_height/2,
00062                 dmpi->stride[2]*2, mpi->stride[2]*2);
00063         }
00064         ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
00065     case 1:
00066     case 2:
00067         memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
00068             dmpi->stride[0], mpi->stride[0]);
00069         if (mpi->flags & MP_IMGFLAG_PLANAR) {
00070             memcpy_pic(dmpi->planes[1], mpi->planes[1],
00071                 mpi->chroma_width, mpi->chroma_height,
00072                 dmpi->stride[1], mpi->stride[1]);
00073             memcpy_pic(dmpi->planes[2], mpi->planes[2],
00074                 mpi->chroma_width, mpi->chroma_height,
00075                 dmpi->stride[2], mpi->stride[2]);
00076         }
00077         return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE) || ret;
00078     case 3:
00079         my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
00080             mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
00081             dmpi->stride[0]*2, mpi->stride[0]*2);
00082         if (mpi->flags & MP_IMGFLAG_PLANAR) {
00083             my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
00084                 mpi->planes[1]+mpi->stride[1],
00085                 mpi->chroma_width, mpi->chroma_height/2,
00086                 dmpi->stride[1]*2, mpi->stride[1]*2);
00087             my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
00088                 mpi->planes[2]+mpi->stride[2],
00089                 mpi->chroma_width, mpi->chroma_height/2,
00090                 dmpi->stride[2]*2, mpi->stride[2]*2);
00091         }
00092         ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
00093         my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
00094             dmpi->stride[0]*2, mpi->stride[0]*2);
00095         if (mpi->flags & MP_IMGFLAG_PLANAR) {
00096             my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
00097                 mpi->chroma_width, mpi->chroma_height/2,
00098                 dmpi->stride[1]*2, mpi->stride[1]*2);
00099             my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
00100                 mpi->chroma_width, mpi->chroma_height/2,
00101                 dmpi->stride[2]*2, mpi->stride[2]*2);
00102         }
00103         return ret;
00104     }
00105     return 0;
00106 }
00107 
00108 #if 0
00109 static int query_format(struct vf_instance *vf, unsigned int fmt)
00110 {
00111     /* FIXME - figure out which other formats work */
00112     switch (fmt) {
00113     case IMGFMT_YV12:
00114     case IMGFMT_IYUV:
00115     case IMGFMT_I420:
00116         return vf_next_query_format(vf, fmt);
00117     }
00118     return 0;
00119 }
00120 
00121 static int config(struct vf_instance *vf,
00122         int width, int height, int d_width, int d_height,
00123     unsigned int flags, unsigned int outfmt)
00124 {
00125     return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
00126 }
00127 #endif
00128 
00129 static void uninit(struct vf_instance *vf)
00130 {
00131     free(vf->priv);
00132 }
00133 
00134 static int vf_open(vf_instance_t *vf, char *args)
00135 {
00136     //vf->config = config;
00137     vf->put_image = put_image;
00138     //vf->query_format = query_format;
00139     vf->uninit = uninit;
00140     vf->default_reqs = VFCAP_ACCEPT_STRIDE;
00141     vf->priv = calloc(1, sizeof(struct vf_priv_s));
00142     vf->priv->frame = 1;
00143     if (args) sscanf(args, "%d", &vf->priv->frame);
00144     vf->priv->frame--;
00145     return 1;
00146 }
00147 
00148 const vf_info_t vf_info_telecine = {
00149     "telecine filter",
00150     "telecine",
00151     "Rich Felker",
00152     "",
00153     vf_open,
00154     NULL
00155 };