Use proper length specifiers in mp_msg calls, fixes the warnings:
[mplayer/greg.git] / libmpcodecs / vf_tinterlace.c
blob5a70f6c5778641ff80b900e316bac939bd2c5f05
1 /*
2 Copyright (C) 2003 Michael Zucchi <notzed@ximian.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "config.h"
24 #include "mp_msg.h"
26 #include "img_format.h"
27 #include "mp_image.h"
28 #include "vf.h"
30 #include "libvo/fastmemcpy.h"
32 struct vf_priv_s {
33 int mode;
34 int frame;
35 mp_image_t *dmpi;
38 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
40 int ret = 0;
41 mp_image_t *dmpi;
43 switch (vf->priv->mode) {
44 case 0:
45 dmpi = vf->priv->dmpi;
46 if (dmpi == NULL) {
47 dmpi = vf_get_image(vf->next, mpi->imgfmt,
48 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
49 MP_IMGFLAG_PRESERVE,
50 mpi->width, mpi->height*2);
52 vf->priv->dmpi = dmpi;
54 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
55 dmpi->stride[0]*2, mpi->stride[0]);
56 if (mpi->flags & MP_IMGFLAG_PLANAR) {
57 memcpy_pic(dmpi->planes[1], mpi->planes[1],
58 mpi->chroma_width, mpi->chroma_height,
59 dmpi->stride[1]*2, mpi->stride[1]);
60 memcpy_pic(dmpi->planes[2], mpi->planes[2],
61 mpi->chroma_width, mpi->chroma_height,
62 dmpi->stride[2]*2, mpi->stride[2]);
64 } else {
65 vf->priv->dmpi = NULL;
67 memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h,
68 dmpi->stride[0]*2, mpi->stride[0]);
69 if (mpi->flags & MP_IMGFLAG_PLANAR) {
70 memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1],
71 mpi->chroma_width, mpi->chroma_height,
72 dmpi->stride[1]*2, mpi->stride[1]);
73 memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2],
74 mpi->chroma_width, mpi->chroma_height,
75 dmpi->stride[2]*2, mpi->stride[2]);
77 ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
79 break;
80 case 1:
81 if (vf->priv->frame & 1)
82 ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
83 break;
84 case 2:
85 if ((vf->priv->frame & 1) == 0)
86 ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
87 break;
88 case 3:
89 dmpi = vf_get_image(vf->next, mpi->imgfmt,
90 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
91 mpi->width, mpi->height*2);
92 /* fixme, just clear alternate lines */
93 vf_mpi_clear(dmpi, 0, 0, dmpi->w, dmpi->h);
94 if ((vf->priv->frame & 1) == 0) {
95 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
96 dmpi->stride[0]*2, mpi->stride[0]);
97 if (mpi->flags & MP_IMGFLAG_PLANAR) {
98 memcpy_pic(dmpi->planes[1], mpi->planes[1],
99 mpi->chroma_width, mpi->chroma_height,
100 dmpi->stride[1]*2, mpi->stride[1]);
101 memcpy_pic(dmpi->planes[2], mpi->planes[2],
102 mpi->chroma_width, mpi->chroma_height,
103 dmpi->stride[2]*2, mpi->stride[2]);
105 } else {
106 memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h,
107 dmpi->stride[0]*2, mpi->stride[0]);
108 if (mpi->flags & MP_IMGFLAG_PLANAR) {
109 memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1],
110 mpi->chroma_width, mpi->chroma_height,
111 dmpi->stride[1]*2, mpi->stride[1]);
112 memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2],
113 mpi->chroma_width, mpi->chroma_height,
114 dmpi->stride[2]*2, mpi->stride[2]);
117 ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
118 break;
119 case 4:
120 // Interleave even lines (only) from Frame 'i' with odd
121 // lines (only) from Frame 'i+1', halving the Frame
122 // rate and preserving image height.
124 dmpi = vf->priv->dmpi;
126 // @@ Need help: Should I set dmpi->fields to indicate
127 // that the (new) frame will be interlaced!? E.g. ...
128 // dmpi->fields |= MP_IMGFIELD_INTERLACED;
129 // dmpi->fields |= MP_IMGFIELD_TOP_FIRST;
130 // etc.
132 if (dmpi == NULL) {
133 dmpi = vf_get_image(vf->next, mpi->imgfmt,
134 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
135 MP_IMGFLAG_PRESERVE,
136 mpi->width, mpi->height);
138 vf->priv->dmpi = dmpi;
140 my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
141 dmpi->stride[0]*2, mpi->stride[0]*2);
142 if (mpi->flags & MP_IMGFLAG_PLANAR) {
143 my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
144 mpi->chroma_width, mpi->chroma_height/2,
145 dmpi->stride[1]*2, mpi->stride[1]*2);
146 my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
147 mpi->chroma_width, mpi->chroma_height/2,
148 dmpi->stride[2]*2, mpi->stride[2]*2);
150 } else {
151 vf->priv->dmpi = NULL;
153 my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
154 mpi->planes[0]+mpi->stride[0],
155 mpi->w, mpi->h/2,
156 dmpi->stride[0]*2, mpi->stride[0]*2);
157 if (mpi->flags & MP_IMGFLAG_PLANAR) {
158 my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
159 mpi->planes[1]+mpi->stride[1],
160 mpi->chroma_width, mpi->chroma_height/2,
161 dmpi->stride[1]*2, mpi->stride[1]*2);
162 my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
163 mpi->planes[2]+mpi->stride[2],
164 mpi->chroma_width, mpi->chroma_height/2,
165 dmpi->stride[2]*2, mpi->stride[2]*2);
167 ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
169 break;
172 vf->priv->frame++;
174 return ret;
177 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
179 /* FIXME - figure out which other formats work */
180 switch (fmt) {
181 case IMGFMT_YV12:
182 case IMGFMT_IYUV:
183 case IMGFMT_I420:
184 return vf_next_query_format(vf, fmt);
186 return 0;
189 static int config(struct vf_instance_s* vf,
190 int width, int height, int d_width, int d_height,
191 unsigned int flags, unsigned int outfmt)
193 switch (vf->priv->mode) {
194 case 0:
195 case 3:
196 return vf_next_config(vf,width,height*2,d_width,d_height*2,flags,outfmt);
197 case 1: /* odd frames */
198 case 2: /* even frames */
199 case 4: /* alternate frame (height-preserving) interlacing */
200 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
202 return 0;
205 static void uninit(struct vf_instance_s* vf)
207 free(vf->priv);
210 static int open(vf_instance_t *vf, char* args)
212 struct vf_priv_s *p;
213 vf->config = config;
214 vf->put_image = put_image;
215 vf->query_format = query_format;
216 vf->uninit = uninit;
217 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
218 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
219 vf->priv->mode = 0;
220 if (args)
221 sscanf(args, "%d", &vf->priv->mode);
222 vf->priv->frame = 0;
223 return 1;
226 const vf_info_t vf_info_tinterlace = {
227 "temporal field interlacing",
228 "tinterlace",
229 "Michael Zucchi",
231 open,
232 NULL