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