typo fixes
[mplayer/greg.git] / libmpcodecs / vf_down3dright.c
blob5350903bae55a3b7b0e9394d53d8da3c4c1f3a33
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <inttypes.h>
6 #include "config.h"
7 #include "mp_msg.h"
8 #include "cpudetect.h"
10 #include "img_format.h"
11 #include "mp_image.h"
12 #include "vf.h"
14 #include "libvo/fastmemcpy.h"
15 #include "postproc/rgb2rgb.h"
17 struct vf_priv_s {
18 int skipline;
19 int scalew;
20 int scaleh;
23 static void toright(unsigned char *dst[3], unsigned char *src[3],
24 int dststride[3], int srcstride[3],
25 int w, int h, struct vf_priv_s* p)
27 int k;
29 for (k = 0; k < 3; k++) {
30 unsigned char* fromL = src[k];
31 unsigned char* fromR = src[k];
32 unsigned char* to = dst[k];
33 int src = srcstride[k];
34 int dst = dststride[k];
35 int ss;
36 unsigned int dd;
37 int i;
39 if (k > 0) {
40 i = h / 4 - p->skipline / 2;
41 ss = src * (h / 4 + p->skipline / 2);
42 dd = w / 4;
43 } else {
44 i = h / 2 - p->skipline;
45 ss = src * (h / 2 + p->skipline);
46 dd = w / 2;
48 fromR += ss;
49 for ( ; i > 0; i--) {
50 int j;
51 unsigned char* t = to;
52 unsigned char* sL = fromL;
53 unsigned char* sR = fromR;
55 if (p->scalew == 1) {
56 for (j = dd; j > 0; j--) {
57 *t++ = (sL[0] + sL[1]) / 2;
58 sL+=2;
60 for (j = dd ; j > 0; j--) {
61 *t++ = (sR[0] + sR[1]) / 2;
62 sR+=2;
64 } else {
65 for (j = dd * 2 ; j > 0; j--)
66 *t++ = *sL++;
67 for (j = dd * 2 ; j > 0; j--)
68 *t++ = *sR++;
70 if (p->scaleh == 1) {
71 memcpy(to + dst, to, dst);
72 to += dst;
74 to += dst;
75 fromL += src;
76 fromR += src;
78 //printf("K %d %d %d %d %d \n", k, w, h, src, dst);
82 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
84 mp_image_t *dmpi;
86 // hope we'll get DR buffer:
87 dmpi=vf_get_image(vf->next, IMGFMT_YV12,
88 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
89 (vf->priv->scaleh == 1) ? MP_IMGFLAG_READABLE : 0,
90 mpi->w * vf->priv->scalew,
91 mpi->h / vf->priv->scaleh - vf->priv->skipline);
93 toright(dmpi->planes, mpi->planes, dmpi->stride,
94 mpi->stride, mpi->w, mpi->h, vf->priv);
96 return vf_next_put_image(vf,dmpi, pts);
99 static int config(struct vf_instance_s* vf,
100 int width, int height, int d_width, int d_height,
101 unsigned int flags, unsigned int outfmt)
103 /* FIXME - also support UYVY output? */
104 return vf_next_config(vf, width * vf->priv->scalew,
105 height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_YV12);
109 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
111 /* FIXME - really any YUV 4:2:0 input format should work */
112 switch (fmt) {
113 case IMGFMT_YV12:
114 case IMGFMT_IYUV:
115 case IMGFMT_I420:
116 return vf_next_query_format(vf, IMGFMT_YV12);
118 return 0;
121 static void uninit(struct vf_instance_s* vf)
123 free(vf->priv);
126 static int open(vf_instance_t *vf, char* args)
128 vf->config=config;
129 vf->query_format=query_format;
130 vf->put_image=put_image;
131 vf->uninit=uninit;
133 vf->priv = calloc(1, sizeof (struct vf_priv_s));
134 vf->priv->skipline = 0;
135 vf->priv->scalew = 1;
136 vf->priv->scaleh = 2;
137 if (args) sscanf(args, "%d:%d:%d", &vf->priv->skipline, &vf->priv->scalew, &vf->priv->scaleh);
139 return 1;
142 vf_info_t vf_info_down3dright = {
143 "convert stereo movie from top-bottom to left-right field",
144 "down3dright",
145 "Zdenek Kabelac",
147 open,
148 NULL