stream.h: Add 2 prototypes instead of declaring them in cache2.c
[mplayer.git] / libmpcodecs / vf_down3dright.c
blob3ad2209d33cf92a89708fd7a7fe6f9739797820f
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"
16 struct vf_priv_s {
17 int skipline;
18 int scalew;
19 int scaleh;
22 static void toright(unsigned char *dst[3], unsigned char *src[3],
23 int dststride[3], int srcstride[3],
24 int w, int h, struct vf_priv_s* p)
26 int k;
28 for (k = 0; k < 3; k++) {
29 unsigned char* fromL = src[k];
30 unsigned char* fromR = src[k];
31 unsigned char* to = dst[k];
32 int src = srcstride[k];
33 int dst = dststride[k];
34 int ss;
35 unsigned int dd;
36 int i;
38 if (k > 0) {
39 i = h / 4 - p->skipline / 2;
40 ss = src * (h / 4 + p->skipline / 2);
41 dd = w / 4;
42 } else {
43 i = h / 2 - p->skipline;
44 ss = src * (h / 2 + p->skipline);
45 dd = w / 2;
47 fromR += ss;
48 for ( ; i > 0; i--) {
49 int j;
50 unsigned char* t = to;
51 unsigned char* sL = fromL;
52 unsigned char* sR = fromR;
54 if (p->scalew == 1) {
55 for (j = dd; j > 0; j--) {
56 *t++ = (sL[0] + sL[1]) / 2;
57 sL+=2;
59 for (j = dd ; j > 0; j--) {
60 *t++ = (sR[0] + sR[1]) / 2;
61 sR+=2;
63 } else {
64 for (j = dd * 2 ; j > 0; j--)
65 *t++ = *sL++;
66 for (j = dd * 2 ; j > 0; j--)
67 *t++ = *sR++;
69 if (p->scaleh == 1) {
70 fast_memcpy(to + dst, to, dst);
71 to += dst;
73 to += dst;
74 fromL += src;
75 fromR += src;
77 //printf("K %d %d %d %d %d \n", k, w, h, src, dst);
81 static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts)
83 mp_image_t *dmpi;
85 // hope we'll get DR buffer:
86 dmpi=vf_get_image(vf->next, IMGFMT_YV12,
87 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
88 (vf->priv->scaleh == 1) ? MP_IMGFLAG_READABLE : 0,
89 mpi->w * vf->priv->scalew,
90 mpi->h / vf->priv->scaleh - vf->priv->skipline);
92 toright(dmpi->planes, mpi->planes, dmpi->stride,
93 mpi->stride, mpi->w, mpi->h, vf->priv);
95 return vf_next_put_image(vf,dmpi, pts);
98 static int config(struct vf_instance* vf,
99 int width, int height, int d_width, int d_height,
100 unsigned int flags, unsigned int outfmt)
102 /* FIXME - also support UYVY output? */
103 return vf_next_config(vf, width * vf->priv->scalew,
104 height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_YV12);
108 static int query_format(struct vf_instance* vf, unsigned int fmt)
110 /* FIXME - really any YUV 4:2:0 input format should work */
111 switch (fmt) {
112 case IMGFMT_YV12:
113 case IMGFMT_IYUV:
114 case IMGFMT_I420:
115 return vf_next_query_format(vf, IMGFMT_YV12);
117 return 0;
120 static void uninit(struct vf_instance* vf)
122 free(vf->priv);
125 static int open(vf_instance_t *vf, char* args)
127 vf->config=config;
128 vf->query_format=query_format;
129 vf->put_image=put_image;
130 vf->uninit=uninit;
132 vf->priv = calloc(1, sizeof (struct vf_priv_s));
133 vf->priv->skipline = 0;
134 vf->priv->scalew = 1;
135 vf->priv->scaleh = 2;
136 if (args) sscanf(args, "%d:%d:%d", &vf->priv->skipline, &vf->priv->scalew, &vf->priv->scaleh);
138 return 1;
141 const vf_info_t vf_info_down3dright = {
142 "convert stereo movie from top-bottom to left-right field",
143 "down3dright",
144 "Zdenek Kabelac",
146 open,
147 NULL