Mercurial > mplayer.hg
comparison libmpcodecs/vf_il.c @ 8004:30789258ca66
(de)interleave filter (can be used to split/merge an interlaced image so other non interlaced filters an be used with idividual fields)
author | michael |
---|---|
date | Thu, 31 Oct 2002 20:03:08 +0000 |
parents | |
children | 694502344370 |
comparison
equal
deleted
inserted
replaced
8003:6e48ba1cd342 | 8004:30789258ca66 |
---|---|
1 /* | |
2 Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at> | |
3 | |
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. | |
8 | |
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. | |
13 | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <inttypes.h> | |
23 #include <assert.h> | |
24 | |
25 #include "../config.h" | |
26 #include "../mp_msg.h" | |
27 | |
28 #ifdef HAVE_MALLOC_H | |
29 #include <malloc.h> | |
30 #endif | |
31 | |
32 #include "img_format.h" | |
33 #include "mp_image.h" | |
34 #include "vf.h" | |
35 #include "../libvo/fastmemcpy.h" | |
36 | |
37 | |
38 //===========================================================================// | |
39 | |
40 | |
41 struct vf_priv_s { | |
42 int interleave; | |
43 int chroma; | |
44 int swap; | |
45 }; | |
46 | |
47 | |
48 /***************************************************************************/ | |
49 | |
50 | |
51 static int config(struct vf_instance_s* vf, | |
52 int width, int height, int d_width, int d_height, | |
53 unsigned int flags, unsigned int outfmt){ | |
54 | |
55 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
56 } | |
57 | |
58 static int interleave(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int interleave, int swap){ | |
59 const int a= swap; | |
60 const int b= 1-a; | |
61 const int m= h>>1; | |
62 int y; | |
63 | |
64 switch(interleave){ | |
65 case -1: | |
66 for(y=0; y < m; y++){ | |
67 memcpy(dst + dstStride* y , src + srcStride*(y*2 + a), w); | |
68 memcpy(dst + dstStride*(y + m), src + srcStride*(y*2 + b), w); | |
69 } | |
70 break; | |
71 case 0: | |
72 for(y=0; y < m; y++){ | |
73 memcpy(dst + dstStride* y*2 , src + srcStride*(y*2 + a), w); | |
74 memcpy(dst + dstStride*(y*2+1), src + srcStride*(y*2 + b), w); | |
75 } | |
76 break; | |
77 case 1: | |
78 for(y=0; y < m; y++){ | |
79 memcpy(dst + dstStride*(y*2+a), src + srcStride* y , w); | |
80 memcpy(dst + dstStride*(y*2+b), src + srcStride*(y + m), w); | |
81 } | |
82 break; | |
83 } | |
84 } | |
85 | |
86 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
87 int w; | |
88 | |
89 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
90 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
91 mpi->w,mpi->h); | |
92 | |
93 if(mpi->flags&MP_IMGFLAG_PLANAR) | |
94 w= mpi->w; | |
95 else | |
96 w= mpi->w * mpi->bpp/8; | |
97 | |
98 interleave(dmpi->planes[0], mpi->planes[0], | |
99 w, mpi->h, dmpi->stride[0], mpi->stride[0], vf->priv->interleave, vf->priv->swap); | |
100 | |
101 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
102 int cw= mpi->w >> mpi->chroma_x_shift; | |
103 int ch= mpi->h >> mpi->chroma_y_shift; | |
104 | |
105 | |
106 if(vf->priv->chroma){ | |
107 interleave(dmpi->planes[1], mpi->planes[1], cw,ch, | |
108 dmpi->stride[1], mpi->stride[1], vf->priv->interleave, vf->priv->swap); | |
109 interleave(dmpi->planes[2], mpi->planes[2], cw,ch, | |
110 dmpi->stride[2], mpi->stride[2], vf->priv->interleave, vf->priv->swap); | |
111 }else{ | |
112 int y; | |
113 for(y=0; y < ch; y++) | |
114 memcpy(dmpi->planes[1] + dmpi->stride[1]*y, mpi->planes[1] + mpi->stride[1]*y, cw); | |
115 for(y=0; y < ch; y++) | |
116 memcpy(dmpi->planes[2] + dmpi->stride[2]*y, mpi->planes[2] + mpi->stride[2]*y, cw); | |
117 } | |
118 } | |
119 | |
120 return vf_next_put_image(vf,dmpi); | |
121 } | |
122 | |
123 //===========================================================================// | |
124 | |
125 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
126 /* we support all formats :) */ | |
127 return vf_next_query_format(vf, fmt); | |
128 } | |
129 | |
130 static int open(vf_instance_t *vf, char* args){ | |
131 char *pos, *max; | |
132 | |
133 vf->config=config; | |
134 vf->put_image=put_image; | |
135 // vf->get_image=get_image; | |
136 vf->query_format=query_format; | |
137 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
138 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
139 | |
140 if(args==NULL) return 0; | |
141 | |
142 max= args + strlen(args); | |
143 | |
144 pos= strchr(args, 's'); | |
145 if(pos && pos<max) vf->priv->swap=1; | |
146 pos= strchr(args, 'c'); | |
147 if(pos && pos<max) vf->priv->chroma=1; | |
148 pos= strchr(args, 'i'); | |
149 if(pos && pos<max) vf->priv->interleave=1; | |
150 pos= strchr(args, 'd'); | |
151 if(pos && pos<max) vf->priv->interleave=-1; | |
152 | |
153 return 1; | |
154 } | |
155 | |
156 vf_info_t vf_info_il = { | |
157 "(de)interleave", | |
158 "il", | |
159 "Michael Niedermayer", | |
160 "", | |
161 open | |
162 }; | |
163 | |
164 //===========================================================================// |