00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00123
00124
00125
00126 dmpi = vf->priv->dmpi;
00127
00128
00129
00130
00131
00132
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
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:
00200 case 2:
00201 case 4:
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 };