Mercurial > mplayer.hg
annotate libmpcodecs/vf_boxblur.c @ 25813:ba7bd4f7e322
Add global ass_force_reload flag.
If it is set, renderer is reconfigured before the next frame.
author | eugeni |
---|---|
date | Wed, 23 Jan 2008 21:18:30 +0000 |
parents | c2b7ba444ade |
children | 82601a38e2a7 |
rev | line source |
---|---|
8010 | 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 | |
17367
401b440a6d76
Update licensing information: The FSF changed postal address.
diego
parents:
17012
diff
changeset
|
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
8010 | 17 */ |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <inttypes.h> | |
23 #include <assert.h> | |
24 | |
17012 | 25 #include "config.h" |
26 #include "mp_msg.h" | |
8010 | 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 | |
36 | |
37 //===========================================================================// | |
38 | |
39 typedef struct FilterParam{ | |
40 int radius; | |
41 int power; | |
42 }FilterParam; | |
43 | |
44 struct vf_priv_s { | |
45 FilterParam lumaParam; | |
46 FilterParam chromaParam; | |
47 }; | |
48 | |
49 | |
50 /***************************************************************************/ | |
51 | |
52 | |
53 static int config(struct vf_instance_s* vf, | |
54 int width, int height, int d_width, int d_height, | |
55 unsigned int flags, unsigned int outfmt){ | |
56 | |
57 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
58 } | |
59 | |
60 static inline void blur(uint8_t *dst, uint8_t *src, int w, int radius, int dstStep, int srcStep){ | |
61 int x; | |
62 const int length= radius*2 + 1; | |
63 const int inv= ((1<<16) + length/2)/length; | |
64 | |
65 int sum= 0; | |
66 | |
67 for(x=0; x<radius; x++){ | |
68 sum+= src[x*srcStep]<<1; | |
69 } | |
70 sum+= src[radius*srcStep]; | |
71 | |
72 for(x=0; x<=radius; x++){ | |
73 sum+= src[(radius+x)*srcStep] - src[(radius-x)*srcStep]; | |
74 dst[x*dstStep]= (sum*inv + (1<<15))>>16; | |
75 } | |
76 | |
77 for(; x<w-radius; x++){ | |
78 sum+= src[(radius+x)*srcStep] - src[(x-radius-1)*srcStep]; | |
79 dst[x*dstStep]= (sum*inv + (1<<15))>>16; | |
80 } | |
81 | |
82 for(; x<w; x++){ | |
83 sum+= src[(2*w-radius-x-1)*srcStep] - src[(x-radius-1)*srcStep]; | |
84 dst[x*dstStep]= (sum*inv + (1<<15))>>16; | |
85 } | |
86 } | |
87 | |
88 static inline void blur2(uint8_t *dst, uint8_t *src, int w, int radius, int power, int dstStep, int srcStep){ | |
89 uint8_t temp[2][4096]; | |
90 uint8_t *a= temp[0], *b=temp[1]; | |
91 | |
92 if(radius){ | |
93 blur(a, src, w, radius, 1, srcStep); | |
94 for(; power>2; power--){ | |
95 uint8_t *c; | |
96 blur(b, a, w, radius, 1, 1); | |
97 c=a; a=b; b=c; | |
98 } | |
99 if(power>1) | |
100 blur(dst, a, w, radius, dstStep, 1); | |
101 else{ | |
102 int i; | |
103 for(i=0; i<w; i++) | |
104 dst[i*dstStep]= a[i]; | |
105 } | |
106 }else{ | |
107 int i; | |
108 for(i=0; i<w; i++) | |
109 dst[i*dstStep]= src[i*srcStep]; | |
110 } | |
111 } | |
112 | |
113 static void hBlur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int radius, int power){ | |
114 int y; | |
115 | |
116 if(radius==0 && dst==src) return; | |
117 | |
118 for(y=0; y<h; y++){ | |
119 blur2(dst + y*dstStride, src + y*srcStride, w, radius, power, 1, 1); | |
120 } | |
121 } | |
122 | |
123 //FIXME optimize (x before y !!!) | |
124 static void vBlur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int radius, int power){ | |
125 int x; | |
126 | |
127 if(radius==0 && dst==src) return; | |
128 | |
129 for(x=0; x<w; x++){ | |
130 blur2(dst + x, src + x, h, radius, power, dstStride, srcStride); | |
131 } | |
132 } | |
133 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17367
diff
changeset
|
134 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
8010 | 135 int cw= mpi->w >> mpi->chroma_x_shift; |
136 int ch= mpi->h >> mpi->chroma_y_shift; | |
137 | |
138 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
16155 | 139 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE, |
8010 | 140 mpi->w,mpi->h); |
141 | |
142 assert(mpi->flags&MP_IMGFLAG_PLANAR); | |
143 | |
144 hBlur(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, | |
145 dmpi->stride[0], mpi->stride[0], vf->priv->lumaParam.radius, vf->priv->lumaParam.power); | |
146 hBlur(dmpi->planes[1], mpi->planes[1], cw,ch, | |
147 dmpi->stride[1], mpi->stride[1], vf->priv->chromaParam.radius, vf->priv->chromaParam.power); | |
148 hBlur(dmpi->planes[2], mpi->planes[2], cw,ch, | |
149 dmpi->stride[2], mpi->stride[2], vf->priv->chromaParam.radius, vf->priv->chromaParam.power); | |
150 | |
151 vBlur(dmpi->planes[0], dmpi->planes[0], mpi->w,mpi->h, | |
152 dmpi->stride[0], dmpi->stride[0], vf->priv->lumaParam.radius, vf->priv->lumaParam.power); | |
153 vBlur(dmpi->planes[1], dmpi->planes[1], cw,ch, | |
154 dmpi->stride[1], dmpi->stride[1], vf->priv->chromaParam.radius, vf->priv->chromaParam.power); | |
155 vBlur(dmpi->planes[2], dmpi->planes[2], cw,ch, | |
156 dmpi->stride[2], dmpi->stride[2], vf->priv->chromaParam.radius, vf->priv->chromaParam.power); | |
157 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17367
diff
changeset
|
158 return vf_next_put_image(vf,dmpi, pts); |
8010 | 159 } |
160 | |
161 //===========================================================================// | |
162 | |
163 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
164 switch(fmt) | |
165 { | |
166 case IMGFMT_YV12: | |
167 case IMGFMT_I420: | |
168 case IMGFMT_IYUV: | |
169 case IMGFMT_YVU9: | |
170 case IMGFMT_444P: | |
171 case IMGFMT_422P: | |
172 case IMGFMT_411P: | |
173 return vf_next_query_format(vf, fmt); | |
174 } | |
175 return 0; | |
176 } | |
177 | |
178 static int open(vf_instance_t *vf, char* args){ | |
179 int e; | |
180 | |
181 vf->config=config; | |
182 vf->put_image=put_image; | |
183 // vf->get_image=get_image; | |
184 vf->query_format=query_format; | |
185 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
186 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
187 | |
188 if(args==NULL) return 0; | |
189 | |
190 e=sscanf(args, "%d:%d:%d:%d", | |
191 &vf->priv->lumaParam.radius, | |
192 &vf->priv->lumaParam.power, | |
193 &vf->priv->chromaParam.radius, | |
194 &vf->priv->chromaParam.power | |
195 ); | |
196 | |
197 if(e==2){ | |
198 vf->priv->chromaParam.radius= vf->priv->lumaParam.radius; | |
199 vf->priv->chromaParam.power = vf->priv->lumaParam.power; | |
200 }else if(e!=4) | |
201 return 0; | |
202 | |
203 if(vf->priv->lumaParam.radius < 0) return 0; | |
204 if(vf->priv->chromaParam.radius < 0) return 0; | |
205 | |
206 return 1; | |
207 } | |
208 | |
24969
c2b7ba444ade
begin moving const filter data to .text/.rodata sections
rfelker
parents:
23373
diff
changeset
|
209 const vf_info_t vf_info_boxblur = { |
8010 | 210 "box blur", |
211 "boxblur", | |
212 "Michael Niedermayer", | |
213 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
8123
diff
changeset
|
214 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
8123
diff
changeset
|
215 NULL |
8010 | 216 }; |
217 | |
218 //===========================================================================// |