00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 #include "cpudetect.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 skipline;
00036 int scalew;
00037 int scaleh;
00038 };
00039
00040 static void toright(unsigned char *dst[3], unsigned char *src[3],
00041 int dststride[3], int srcstride[3],
00042 int w, int h, struct vf_priv_s* p)
00043 {
00044 int k;
00045
00046 for (k = 0; k < 3; k++) {
00047 unsigned char* fromL = src[k];
00048 unsigned char* fromR = src[k];
00049 unsigned char* to = dst[k];
00050 int src = srcstride[k];
00051 int dst = dststride[k];
00052 int ss;
00053 unsigned int dd;
00054 int i;
00055
00056 if (k > 0) {
00057 i = h / 4 - p->skipline / 2;
00058 ss = src * (h / 4 + p->skipline / 2);
00059 dd = w / 4;
00060 } else {
00061 i = h / 2 - p->skipline;
00062 ss = src * (h / 2 + p->skipline);
00063 dd = w / 2;
00064 }
00065 fromR += ss;
00066 for ( ; i > 0; i--) {
00067 int j;
00068 unsigned char* t = to;
00069 unsigned char* sL = fromL;
00070 unsigned char* sR = fromR;
00071
00072 if (p->scalew == 1) {
00073 for (j = dd; j > 0; j--) {
00074 *t++ = (sL[0] + sL[1]) / 2;
00075 sL+=2;
00076 }
00077 for (j = dd ; j > 0; j--) {
00078 *t++ = (sR[0] + sR[1]) / 2;
00079 sR+=2;
00080 }
00081 } else {
00082 for (j = dd * 2 ; j > 0; j--)
00083 *t++ = *sL++;
00084 for (j = dd * 2 ; j > 0; j--)
00085 *t++ = *sR++;
00086 }
00087 if (p->scaleh == 1) {
00088 fast_memcpy(to + dst, to, dst);
00089 to += dst;
00090 }
00091 to += dst;
00092 fromL += src;
00093 fromR += src;
00094 }
00095
00096 }
00097 }
00098
00099 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
00100 {
00101 mp_image_t *dmpi;
00102
00103
00104 dmpi=vf_get_image(vf->next, IMGFMT_YV12,
00105 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
00106 (vf->priv->scaleh == 1) ? MP_IMGFLAG_READABLE : 0,
00107 mpi->w * vf->priv->scalew,
00108 mpi->h / vf->priv->scaleh - vf->priv->skipline);
00109
00110 toright(dmpi->planes, mpi->planes, dmpi->stride,
00111 mpi->stride, mpi->w, mpi->h, vf->priv);
00112
00113 return vf_next_put_image(vf,dmpi, pts);
00114 }
00115
00116 static int config(struct vf_instance *vf,
00117 int width, int height, int d_width, int d_height,
00118 unsigned int flags, unsigned int outfmt)
00119 {
00120
00121 return vf_next_config(vf, width * vf->priv->scalew,
00122 height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_YV12);
00123 }
00124
00125
00126 static int query_format(struct vf_instance *vf, unsigned int fmt)
00127 {
00128
00129 switch (fmt) {
00130 case IMGFMT_YV12:
00131 case IMGFMT_IYUV:
00132 case IMGFMT_I420:
00133 return vf_next_query_format(vf, IMGFMT_YV12);
00134 }
00135 return 0;
00136 }
00137
00138 static void uninit(struct vf_instance *vf)
00139 {
00140 free(vf->priv);
00141 }
00142
00143 static int vf_open(vf_instance_t *vf, char *args)
00144 {
00145 vf->config=config;
00146 vf->query_format=query_format;
00147 vf->put_image=put_image;
00148 vf->uninit=uninit;
00149
00150 vf->priv = calloc(1, sizeof (struct vf_priv_s));
00151 vf->priv->skipline = 0;
00152 vf->priv->scalew = 1;
00153 vf->priv->scaleh = 2;
00154 if (args) sscanf(args, "%d:%d:%d", &vf->priv->skipline, &vf->priv->scalew, &vf->priv->scaleh);
00155
00156 return 1;
00157 }
00158
00159 const vf_info_t vf_info_down3dright = {
00160 "convert stereo movie from top-bottom to left-right field",
00161 "down3dright",
00162 "Zdenek Kabelac",
00163 "",
00164 vf_open,
00165 NULL
00166 };