Fix planarCopy to ignore the GRAY8 "pseudo"-palette, fixes libavtest regression test.
[mplayer/glamo.git] / libmpcodecs / vf_telecine.c
blob3ce136e5bfadcbc762964342e0de94b142f14d76
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "config.h"
6 #include "mp_msg.h"
8 #include "img_format.h"
9 #include "mp_image.h"
10 #include "vf.h"
12 #include "libvo/fastmemcpy.h"
14 struct vf_priv_s {
15 int frame;
18 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
20 mp_image_t *dmpi;
21 int ret;
23 vf->priv->frame = (vf->priv->frame+1)%4;
25 dmpi = vf_get_image(vf->next, mpi->imgfmt,
26 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
27 MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
29 ret = 0;
30 // 0/0 1/1 2/2 2/3 3/0
31 switch (vf->priv->frame) {
32 case 0:
33 my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
34 mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
35 dmpi->stride[0]*2, mpi->stride[0]*2);
36 if (mpi->flags & MP_IMGFLAG_PLANAR) {
37 my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
38 mpi->planes[1]+mpi->stride[1],
39 mpi->chroma_width, mpi->chroma_height/2,
40 dmpi->stride[1]*2, mpi->stride[1]*2);
41 my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
42 mpi->planes[2]+mpi->stride[2],
43 mpi->chroma_width, mpi->chroma_height/2,
44 dmpi->stride[2]*2, mpi->stride[2]*2);
46 ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
47 case 1:
48 case 2:
49 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
50 dmpi->stride[0], mpi->stride[0]);
51 if (mpi->flags & MP_IMGFLAG_PLANAR) {
52 memcpy_pic(dmpi->planes[1], mpi->planes[1],
53 mpi->chroma_width, mpi->chroma_height,
54 dmpi->stride[1], mpi->stride[1]);
55 memcpy_pic(dmpi->planes[2], mpi->planes[2],
56 mpi->chroma_width, mpi->chroma_height,
57 dmpi->stride[2], mpi->stride[2]);
59 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE) || ret;
60 case 3:
61 my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
62 mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
63 dmpi->stride[0]*2, mpi->stride[0]*2);
64 if (mpi->flags & MP_IMGFLAG_PLANAR) {
65 my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
66 mpi->planes[1]+mpi->stride[1],
67 mpi->chroma_width, mpi->chroma_height/2,
68 dmpi->stride[1]*2, mpi->stride[1]*2);
69 my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
70 mpi->planes[2]+mpi->stride[2],
71 mpi->chroma_width, mpi->chroma_height/2,
72 dmpi->stride[2]*2, mpi->stride[2]*2);
74 ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
75 my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
76 dmpi->stride[0]*2, mpi->stride[0]*2);
77 if (mpi->flags & MP_IMGFLAG_PLANAR) {
78 my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
79 mpi->chroma_width, mpi->chroma_height/2,
80 dmpi->stride[1]*2, mpi->stride[1]*2);
81 my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
82 mpi->chroma_width, mpi->chroma_height/2,
83 dmpi->stride[2]*2, mpi->stride[2]*2);
85 return ret;
87 return 0;
90 #if 0
91 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
93 /* FIXME - figure out which other formats work */
94 switch (fmt) {
95 case IMGFMT_YV12:
96 case IMGFMT_IYUV:
97 case IMGFMT_I420:
98 return vf_next_query_format(vf, fmt);
100 return 0;
103 static int config(struct vf_instance_s* vf,
104 int width, int height, int d_width, int d_height,
105 unsigned int flags, unsigned int outfmt)
107 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
109 #endif
111 static void uninit(struct vf_instance_s* vf)
113 free(vf->priv);
116 static int open(vf_instance_t *vf, char* args)
118 //vf->config = config;
119 vf->put_image = put_image;
120 //vf->query_format = query_format;
121 vf->uninit = uninit;
122 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
123 vf->priv = calloc(1, sizeof(struct vf_priv_s));
124 vf->priv->frame = 1;
125 if (args) sscanf(args, "%d", &vf->priv->frame);
126 vf->priv->frame--;
127 return 1;
130 const vf_info_t vf_info_telecine = {
131 "telecine filter",
132 "telecine",
133 "Rich Felker",
135 open,
136 NULL