2 * Copyright (C) 2003 Michael Zucchi <notzed@ximian.com>
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "img_format.h"
32 #include "libvo/fastmemcpy.h"
40 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
45 switch (vf
->priv
->mode
) {
47 dmpi
= vf
->priv
->dmpi
;
49 dmpi
= vf_get_image(vf
->next
, mpi
->imgfmt
,
50 MP_IMGTYPE_STATIC
, MP_IMGFLAG_ACCEPT_STRIDE
|
52 mpi
->width
, mpi
->height
*2);
54 vf
->priv
->dmpi
= dmpi
;
56 memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
,
57 dmpi
->stride
[0]*2, mpi
->stride
[0]);
58 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
59 memcpy_pic(dmpi
->planes
[1], mpi
->planes
[1],
60 mpi
->chroma_width
, mpi
->chroma_height
,
61 dmpi
->stride
[1]*2, mpi
->stride
[1]);
62 memcpy_pic(dmpi
->planes
[2], mpi
->planes
[2],
63 mpi
->chroma_width
, mpi
->chroma_height
,
64 dmpi
->stride
[2]*2, mpi
->stride
[2]);
67 vf
->priv
->dmpi
= NULL
;
69 memcpy_pic(dmpi
->planes
[0]+dmpi
->stride
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
,
70 dmpi
->stride
[0]*2, mpi
->stride
[0]);
71 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
72 memcpy_pic(dmpi
->planes
[1]+dmpi
->stride
[1], mpi
->planes
[1],
73 mpi
->chroma_width
, mpi
->chroma_height
,
74 dmpi
->stride
[1]*2, mpi
->stride
[1]);
75 memcpy_pic(dmpi
->planes
[2]+dmpi
->stride
[2], mpi
->planes
[2],
76 mpi
->chroma_width
, mpi
->chroma_height
,
77 dmpi
->stride
[2]*2, mpi
->stride
[2]);
79 ret
= vf_next_put_image(vf
, dmpi
, MP_NOPTS_VALUE
);
83 if (vf
->priv
->frame
& 1)
84 ret
= vf_next_put_image(vf
, mpi
, MP_NOPTS_VALUE
);
87 if ((vf
->priv
->frame
& 1) == 0)
88 ret
= vf_next_put_image(vf
, mpi
, MP_NOPTS_VALUE
);
91 dmpi
= vf_get_image(vf
->next
, mpi
->imgfmt
,
92 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
93 mpi
->width
, mpi
->height
*2);
94 /* fixme, just clear alternate lines */
95 vf_mpi_clear(dmpi
, 0, 0, dmpi
->w
, dmpi
->h
);
96 if ((vf
->priv
->frame
& 1) == 0) {
97 memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
,
98 dmpi
->stride
[0]*2, mpi
->stride
[0]);
99 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
100 memcpy_pic(dmpi
->planes
[1], mpi
->planes
[1],
101 mpi
->chroma_width
, mpi
->chroma_height
,
102 dmpi
->stride
[1]*2, mpi
->stride
[1]);
103 memcpy_pic(dmpi
->planes
[2], mpi
->planes
[2],
104 mpi
->chroma_width
, mpi
->chroma_height
,
105 dmpi
->stride
[2]*2, mpi
->stride
[2]);
108 memcpy_pic(dmpi
->planes
[0]+dmpi
->stride
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
,
109 dmpi
->stride
[0]*2, mpi
->stride
[0]);
110 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
111 memcpy_pic(dmpi
->planes
[1]+dmpi
->stride
[1], mpi
->planes
[1],
112 mpi
->chroma_width
, mpi
->chroma_height
,
113 dmpi
->stride
[1]*2, mpi
->stride
[1]);
114 memcpy_pic(dmpi
->planes
[2]+dmpi
->stride
[2], mpi
->planes
[2],
115 mpi
->chroma_width
, mpi
->chroma_height
,
116 dmpi
->stride
[2]*2, mpi
->stride
[2]);
119 ret
= vf_next_put_image(vf
, dmpi
, MP_NOPTS_VALUE
);
122 // Interleave even lines (only) from Frame 'i' with odd
123 // lines (only) from Frame 'i+1', halving the Frame
124 // rate and preserving image height.
126 dmpi
= vf
->priv
->dmpi
;
128 // @@ Need help: Should I set dmpi->fields to indicate
129 // that the (new) frame will be interlaced!? E.g. ...
130 // dmpi->fields |= MP_IMGFIELD_INTERLACED;
131 // dmpi->fields |= MP_IMGFIELD_TOP_FIRST;
135 dmpi
= vf_get_image(vf
->next
, mpi
->imgfmt
,
136 MP_IMGTYPE_STATIC
, MP_IMGFLAG_ACCEPT_STRIDE
|
138 mpi
->width
, mpi
->height
);
140 vf
->priv
->dmpi
= dmpi
;
142 my_memcpy_pic(dmpi
->planes
[0], mpi
->planes
[0], mpi
->w
, mpi
->h
/2,
143 dmpi
->stride
[0]*2, mpi
->stride
[0]*2);
144 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
145 my_memcpy_pic(dmpi
->planes
[1], mpi
->planes
[1],
146 mpi
->chroma_width
, mpi
->chroma_height
/2,
147 dmpi
->stride
[1]*2, mpi
->stride
[1]*2);
148 my_memcpy_pic(dmpi
->planes
[2], mpi
->planes
[2],
149 mpi
->chroma_width
, mpi
->chroma_height
/2,
150 dmpi
->stride
[2]*2, mpi
->stride
[2]*2);
153 vf
->priv
->dmpi
= NULL
;
155 my_memcpy_pic(dmpi
->planes
[0]+dmpi
->stride
[0],
156 mpi
->planes
[0]+mpi
->stride
[0],
158 dmpi
->stride
[0]*2, mpi
->stride
[0]*2);
159 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) {
160 my_memcpy_pic(dmpi
->planes
[1]+dmpi
->stride
[1],
161 mpi
->planes
[1]+mpi
->stride
[1],
162 mpi
->chroma_width
, mpi
->chroma_height
/2,
163 dmpi
->stride
[1]*2, mpi
->stride
[1]*2);
164 my_memcpy_pic(dmpi
->planes
[2]+dmpi
->stride
[2],
165 mpi
->planes
[2]+mpi
->stride
[2],
166 mpi
->chroma_width
, mpi
->chroma_height
/2,
167 dmpi
->stride
[2]*2, mpi
->stride
[2]*2);
169 ret
= vf_next_put_image(vf
, dmpi
, MP_NOPTS_VALUE
);
179 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
181 /* FIXME - figure out which other formats work */
186 return vf_next_query_format(vf
, fmt
);
191 static int config(struct vf_instance_s
* vf
,
192 int width
, int height
, int d_width
, int d_height
,
193 unsigned int flags
, unsigned int outfmt
)
195 switch (vf
->priv
->mode
) {
198 return vf_next_config(vf
,width
,height
*2,d_width
,d_height
*2,flags
,outfmt
);
199 case 1: /* odd frames */
200 case 2: /* even frames */
201 case 4: /* alternate frame (height-preserving) interlacing */
202 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
207 static void uninit(struct vf_instance_s
* vf
)
212 static int open(vf_instance_t
*vf
, char* args
)
216 vf
->put_image
= put_image
;
217 vf
->query_format
= query_format
;
219 vf
->default_reqs
= VFCAP_ACCEPT_STRIDE
;
220 vf
->priv
= p
= calloc(1, sizeof(struct vf_priv_s
));
223 sscanf(args
, "%d", &vf
->priv
->mode
);
228 const vf_info_t vf_info_tinterlace
= {
229 "temporal field interlacing",