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
26 #include "img_format.h"
30 #include "libvo/fastmemcpy.h"
38 // Copied verbatim from vf_telecine.c:
39 static inline void *my_memcpy_pic(void * dst
, void * src
, int bytesPerLine
, int height
, int dstStride
, int srcStride
)
44 for(i
=0; i
<height
; i
++)
46 memcpy(dst
, src
, bytesPerLine
);
54 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
59 switch (vf
->priv
->mode
) {
61 dmpi
= vf
->priv
->dmpi
;
63 dmpi
= vf_get_image(vf
->next
, mpi
->imgfmt
,
64 MP_IMGTYPE_STATIC
, MP_IMGFLAG_ACCEPT_STRIDE
|
66 mpi
->width
, mpi
->height
*2);
68 vf
->priv
->dmpi
= dmpi
;
70 memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
,
71 dmpi
->stride
[0]*2, mpi
->stride
[0]);
72 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
73 memcpy_pic(dmpi
->planes
[1], mpi
->planes
[1],
74 mpi
->chroma_width
, mpi
->chroma_height
,
75 dmpi
->stride
[1]*2, mpi
->stride
[1]);
76 memcpy_pic(dmpi
->planes
[2], mpi
->planes
[2],
77 mpi
->chroma_width
, mpi
->chroma_height
,
78 dmpi
->stride
[2]*2, mpi
->stride
[2]);
81 vf
->priv
->dmpi
= NULL
;
83 memcpy_pic(dmpi
->planes
[0]+dmpi
->stride
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
,
84 dmpi
->stride
[0]*2, mpi
->stride
[0]);
85 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
86 memcpy_pic(dmpi
->planes
[1]+dmpi
->stride
[1], mpi
->planes
[1],
87 mpi
->chroma_width
, mpi
->chroma_height
,
88 dmpi
->stride
[1]*2, mpi
->stride
[1]);
89 memcpy_pic(dmpi
->planes
[2]+dmpi
->stride
[2], mpi
->planes
[2],
90 mpi
->chroma_width
, mpi
->chroma_height
,
91 dmpi
->stride
[2]*2, mpi
->stride
[2]);
93 ret
= vf_next_put_image(vf
, dmpi
, MP_NOPTS_VALUE
);
97 if (vf
->priv
->frame
& 1)
98 ret
= vf_next_put_image(vf
, mpi
, MP_NOPTS_VALUE
);
101 if ((vf
->priv
->frame
& 1) == 0)
102 ret
= vf_next_put_image(vf
, mpi
, MP_NOPTS_VALUE
);
105 dmpi
= vf_get_image(vf
->next
, mpi
->imgfmt
,
106 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
107 mpi
->width
, mpi
->height
*2);
108 /* fixme, just clear alternate lines */
109 vf_mpi_clear(dmpi
, 0, 0, dmpi
->w
, dmpi
->h
);
110 if ((vf
->priv
->frame
& 1) == 0) {
111 memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
,
112 dmpi
->stride
[0]*2, mpi
->stride
[0]);
113 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
114 memcpy_pic(dmpi
->planes
[1], mpi
->planes
[1],
115 mpi
->chroma_width
, mpi
->chroma_height
,
116 dmpi
->stride
[1]*2, mpi
->stride
[1]);
117 memcpy_pic(dmpi
->planes
[2], mpi
->planes
[2],
118 mpi
->chroma_width
, mpi
->chroma_height
,
119 dmpi
->stride
[2]*2, mpi
->stride
[2]);
122 memcpy_pic(dmpi
->planes
[0]+dmpi
->stride
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
,
123 dmpi
->stride
[0]*2, mpi
->stride
[0]);
124 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
125 memcpy_pic(dmpi
->planes
[1]+dmpi
->stride
[1], mpi
->planes
[1],
126 mpi
->chroma_width
, mpi
->chroma_height
,
127 dmpi
->stride
[1]*2, mpi
->stride
[1]);
128 memcpy_pic(dmpi
->planes
[2]+dmpi
->stride
[2], mpi
->planes
[2],
129 mpi
->chroma_width
, mpi
->chroma_height
,
130 dmpi
->stride
[2]*2, mpi
->stride
[2]);
133 ret
= vf_next_put_image(vf
, dmpi
, MP_NOPTS_VALUE
);
136 // Interleave even lines (only) from Frame 'i' with odd
137 // lines (only) from Frame 'i+1', halving the Frame
138 // rate and preserving image height.
140 dmpi
= vf
->priv
->dmpi
;
142 // @@ Need help: Should I set dmpi->fields to indicate
143 // that the (new) frame will be interlaced!? E.g. ...
144 // dmpi->fields |= MP_IMGFIELD_INTERLACED;
145 // dmpi->fields |= MP_IMGFIELD_TOP_FIRST;
149 dmpi
= vf_get_image(vf
->next
, mpi
->imgfmt
,
150 MP_IMGTYPE_STATIC
, MP_IMGFLAG_ACCEPT_STRIDE
|
152 mpi
->width
, mpi
->height
);
154 vf
->priv
->dmpi
= dmpi
;
156 my_memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
/2,
157 dmpi
->stride
[0]*2, mpi
->stride
[0]*2);
158 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
159 my_memcpy_pic(dmpi
->planes
[1], mpi
->planes
[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], mpi
->planes
[2],
163 mpi
->chroma_width
, mpi
->chroma_height
/2,
164 dmpi
->stride
[2]*2, mpi
->stride
[2]*2);
167 vf
->priv
->dmpi
= NULL
;
169 my_memcpy_pic(dmpi
->planes
[0]+dmpi
->stride
[0],
170 mpi
->planes
[0]+mpi
->stride
[0],
172 dmpi
->stride
[0]*2, mpi
->stride
[0]*2);
173 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
174 my_memcpy_pic(dmpi
->planes
[1]+dmpi
->stride
[1],
175 mpi
->planes
[1]+mpi
->stride
[1],
176 mpi
->chroma_width
, mpi
->chroma_height
/2,
177 dmpi
->stride
[1]*2, mpi
->stride
[1]*2);
178 my_memcpy_pic(dmpi
->planes
[2]+dmpi
->stride
[2],
179 mpi
->planes
[2]+mpi
->stride
[2],
180 mpi
->chroma_width
, mpi
->chroma_height
/2,
181 dmpi
->stride
[2]*2, mpi
->stride
[2]*2);
183 ret
= vf_next_put_image(vf
, dmpi
, MP_NOPTS_VALUE
);
193 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
195 /* FIXME - figure out which other formats work */
200 return vf_next_query_format(vf
, fmt
);
205 static int config(struct vf_instance_s
* vf
,
206 int width
, int height
, int d_width
, int d_height
,
207 unsigned int flags
, unsigned int outfmt
)
209 switch (vf
->priv
->mode
) {
212 return vf_next_config(vf
,width
,height
*2,d_width
,d_height
*2,flags
,outfmt
);
213 case 1: /* odd frames */
214 case 2: /* even frames */
215 case 4: /* alternate frame (height-preserving) interlacing */
216 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
221 static void uninit(struct vf_instance_s
* vf
)
226 static int open(vf_instance_t
*vf
, char* args
)
230 vf
->put_image
= put_image
;
231 vf
->query_format
= query_format
;
233 vf
->default_reqs
= VFCAP_ACCEPT_STRIDE
;
234 vf
->priv
= p
= calloc(1, sizeof(struct vf_priv_s
));
237 sscanf(args
, "%d", &vf
->priv
->mode
);
242 vf_info_t vf_info_tinterlace
= {
243 "temporal field interlacing",