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

libavfilter/libmpcodecs/vf_tinterlace.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 Michael Zucchi <notzed@ximian.com>
00003  *
00004  * This file is part of MPlayer.
00005  *
00006  * MPlayer is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * MPlayer is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
00018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 
00025 #include "config.h"
00026 #include "mp_msg.h"
00027 
00028 #include "img_format.h"
00029 #include "mp_image.h"
00030 #include "vf.h"
00031 
00032 #include "libvo/fastmemcpy.h"
00033 
00034 struct vf_priv_s {
00035     int mode;
00036     int frame;
00037     mp_image_t *dmpi;
00038 };
00039 
00040 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
00041 {
00042     int ret = 0;
00043     mp_image_t *dmpi;
00044 
00045     switch (vf->priv->mode) {
00046     case 0:
00047         dmpi = vf->priv->dmpi;
00048         if (dmpi == NULL) {
00049             dmpi = vf_get_image(vf->next, mpi->imgfmt,
00050                         MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
00051                         MP_IMGFLAG_PRESERVE,
00052                         mpi->width, mpi->height*2);
00053 
00054             vf->priv->dmpi = dmpi;
00055 
00056             memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
00057                    dmpi->stride[0]*2, mpi->stride[0]);
00058             if (mpi->flags & MP_IMGFLAG_PLANAR) {
00059                 memcpy_pic(dmpi->planes[1], mpi->planes[1],
00060                        mpi->chroma_width, mpi->chroma_height,
00061                        dmpi->stride[1]*2, mpi->stride[1]);
00062                 memcpy_pic(dmpi->planes[2], mpi->planes[2],
00063                        mpi->chroma_width, mpi->chroma_height,
00064                        dmpi->stride[2]*2, mpi->stride[2]);
00065             }
00066         } else {
00067             vf->priv->dmpi = NULL;
00068 
00069             memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h,
00070                    dmpi->stride[0]*2, mpi->stride[0]);
00071             if (mpi->flags & MP_IMGFLAG_PLANAR) {
00072                 memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1],
00073                        mpi->chroma_width, mpi->chroma_height,
00074                        dmpi->stride[1]*2, mpi->stride[1]);
00075                 memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2],
00076                        mpi->chroma_width, mpi->chroma_height,
00077                        dmpi->stride[2]*2, mpi->stride[2]);
00078             }
00079             ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
00080         }
00081         break;
00082     case 1:
00083         if (vf->priv->frame & 1)
00084             ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
00085         break;
00086     case 2:
00087         if ((vf->priv->frame & 1) == 0)
00088             ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
00089         break;
00090     case 3:
00091         dmpi = vf_get_image(vf->next, mpi->imgfmt,
00092                     MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
00093                     mpi->width, mpi->height*2);
00094         /* fixme, just clear alternate lines */
00095         vf_mpi_clear(dmpi, 0, 0, dmpi->w, dmpi->h);
00096         if ((vf->priv->frame & 1) == 0) {
00097             memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
00098                    dmpi->stride[0]*2, mpi->stride[0]);
00099             if (mpi->flags & MP_IMGFLAG_PLANAR) {
00100                 memcpy_pic(dmpi->planes[1], mpi->planes[1],
00101                        mpi->chroma_width, mpi->chroma_height,
00102                        dmpi->stride[1]*2, mpi->stride[1]);
00103                 memcpy_pic(dmpi->planes[2], mpi->planes[2],
00104                        mpi->chroma_width, mpi->chroma_height,
00105                        dmpi->stride[2]*2, mpi->stride[2]);
00106             }
00107         } else {
00108             memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h,
00109                    dmpi->stride[0]*2, mpi->stride[0]);
00110             if (mpi->flags & MP_IMGFLAG_PLANAR) {
00111                 memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1],
00112                        mpi->chroma_width, mpi->chroma_height,
00113                        dmpi->stride[1]*2, mpi->stride[1]);
00114                 memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2],
00115                        mpi->chroma_width, mpi->chroma_height,
00116                        dmpi->stride[2]*2, mpi->stride[2]);
00117             }
00118         }
00119         ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
00120         break;
00121     case 4:
00122         // Interleave even lines (only) from Frame 'i' with odd
00123         // lines (only) from Frame 'i+1', halving the Frame
00124         // rate and preserving image height.
00125 
00126         dmpi = vf->priv->dmpi;
00127 
00128         // @@ Need help:  Should I set dmpi->fields to indicate
00129         // that the (new) frame will be interlaced!?  E.g. ...
00130         // dmpi->fields |= MP_IMGFIELD_INTERLACED;
00131         // dmpi->fields |= MP_IMGFIELD_TOP_FIRST;
00132         // etc.
00133 
00134         if (dmpi == NULL) {
00135             dmpi = vf_get_image(vf->next, mpi->imgfmt,
00136                         MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
00137                         MP_IMGFLAG_PRESERVE,
00138                         mpi->width, mpi->height);
00139 
00140             vf->priv->dmpi = dmpi;
00141 
00142             my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
00143                       dmpi->stride[0]*2, mpi->stride[0]*2);
00144             if (mpi->flags & MP_IMGFLAG_PLANAR) {
00145                 my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
00146                           mpi->chroma_width, mpi->chroma_height/2,
00147                           dmpi->stride[1]*2, mpi->stride[1]*2);
00148                 my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
00149                           mpi->chroma_width, mpi->chroma_height/2,
00150                           dmpi->stride[2]*2, mpi->stride[2]*2);
00151             }
00152         } else {
00153             vf->priv->dmpi = NULL;
00154 
00155             my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
00156                       mpi->planes[0]+mpi->stride[0],
00157                       mpi->w, mpi->h/2,
00158                       dmpi->stride[0]*2, mpi->stride[0]*2);
00159             if (mpi->flags & MP_IMGFLAG_PLANAR) {
00160                 my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
00161                           mpi->planes[1]+mpi->stride[1],
00162                           mpi->chroma_width, mpi->chroma_height/2,
00163                           dmpi->stride[1]*2, mpi->stride[1]*2);
00164                 my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
00165                           mpi->planes[2]+mpi->stride[2],
00166                           mpi->chroma_width, mpi->chroma_height/2,
00167                           dmpi->stride[2]*2, mpi->stride[2]*2);
00168             }
00169             ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
00170         }
00171         break;
00172     }
00173 
00174     vf->priv->frame++;
00175 
00176     return ret;
00177 }
00178 
00179 static int query_format(struct vf_instance *vf, unsigned int fmt)
00180 {
00181     /* FIXME - figure out which other formats work */
00182     switch (fmt) {
00183     case IMGFMT_YV12:
00184     case IMGFMT_IYUV:
00185     case IMGFMT_I420:
00186         return vf_next_query_format(vf, fmt);
00187     }
00188     return 0;
00189 }
00190 
00191 static int config(struct vf_instance *vf,
00192     int width, int height, int d_width, int d_height,
00193     unsigned int flags, unsigned int outfmt)
00194 {
00195     switch (vf->priv->mode) {
00196     case 0:
00197     case 3:
00198         return vf_next_config(vf,width,height*2,d_width,d_height*2,flags,outfmt);
00199     case 1:            /* odd frames */
00200     case 2:            /* even frames */
00201     case 4:            /* alternate frame (height-preserving) interlacing */
00202         return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
00203     }
00204     return 0;
00205 }
00206 
00207 static void uninit(struct vf_instance *vf)
00208 {
00209     free(vf->priv);
00210 }
00211 
00212 static int vf_open(vf_instance_t *vf, char *args)
00213 {
00214     struct vf_priv_s *p;
00215     vf->config = config;
00216     vf->put_image = put_image;
00217     vf->query_format = query_format;
00218     vf->uninit = uninit;
00219     vf->default_reqs = VFCAP_ACCEPT_STRIDE;
00220     vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
00221     vf->priv->mode = 0;
00222     if (args)
00223       sscanf(args, "%d", &vf->priv->mode);
00224     vf->priv->frame = 0;
00225     return 1;
00226 }
00227 
00228 const vf_info_t vf_info_tinterlace = {
00229     "temporal field interlacing",
00230     "tinterlace",
00231     "Michael Zucchi",
00232     "",
00233     vf_open,
00234     NULL
00235 };

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