Mercurial > mplayer.hg
annotate libmpcodecs/vf_pp.c @ 8100:fd0da9a7d2e3
shape adaptive blur (slightly slow though)
author | michael |
---|---|
date | Mon, 04 Nov 2002 16:42:17 +0000 |
parents | 5241f95b5ec4 |
children | 9fc45fe0d444 |
rev | line source |
---|---|
5512 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
7946 | 4 #include <inttypes.h> |
7963 | 5 #include <errno.h> |
5512 | 6 |
7 #include "../config.h" | |
8 #include "../mp_msg.h" | |
7972 | 9 #include "../cpudetect.h" |
5512 | 10 |
5607 | 11 #include "img_format.h" |
12 #include "mp_image.h" | |
5512 | 13 #include "vf.h" |
14 | |
8038 | 15 #define EMU_OLD |
16 | |
5512 | 17 #include "../postproc/postprocess.h" |
18 | |
8038 | 19 #ifdef EMU_OLD |
20 #include "../postproc/postprocess_internal.h" | |
21 #endif | |
22 | |
5512 | 23 struct vf_priv_s { |
7946 | 24 int pp; |
8040 | 25 pp_mode_t *ppMode[PP_QUALITY_MAX+1]; |
7946 | 26 void *context; |
5512 | 27 mp_image_t *dmpi; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
28 unsigned int outfmt; |
5512 | 29 }; |
30 | |
31 //===========================================================================// | |
32 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
33 static int config(struct vf_instance_s* vf, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
34 int width, int height, int d_width, int d_height, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
35 unsigned int voflags, unsigned int outfmt){ |
7985 | 36 vf->priv->context= pp_get_context(width, height, |
37 (gCpuCaps.hasMMX ? PP_CPU_CAPS_MMX : 0) | |
38 | (gCpuCaps.hasMMX2 ? PP_CPU_CAPS_MMX2 : 0) | |
39 | (gCpuCaps.has3DNow ? PP_CPU_CAPS_3DNOW : 0) | |
40 ); | |
7946 | 41 |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
42 return vf_next_config(vf,width,height,d_width,d_height,voflags,vf->priv->outfmt); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
43 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
44 |
7949 | 45 static void uninit(struct vf_instance_s* vf){ |
8038 | 46 int i; |
8040 | 47 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 48 if(vf->priv->ppMode[i]) |
49 pp_free_mode(vf->priv->ppMode[i]); | |
50 } | |
7961 | 51 if(vf->priv->context) pp_free_context(vf->priv->context); |
7949 | 52 } |
53 | |
5518 | 54 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
55 switch(fmt){ | |
56 case IMGFMT_YV12: | |
57 case IMGFMT_I420: | |
58 case IMGFMT_IYUV: | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
59 return vf_next_query_format(vf,vf->priv->outfmt); |
5518 | 60 } |
61 return 0; | |
62 } | |
63 | |
5519 | 64 static int control(struct vf_instance_s* vf, int request, void* data){ |
65 switch(request){ | |
66 case VFCTRL_QUERY_MAX_PP_LEVEL: | |
8040 | 67 return PP_QUALITY_MAX; |
5519 | 68 case VFCTRL_SET_PP_LEVEL: |
7946 | 69 vf->priv->pp= *((unsigned int*)data); |
5519 | 70 return CONTROL_TRUE; |
71 } | |
72 return vf_next_control(vf,request,data); | |
73 } | |
74 | |
5512 | 75 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
76 if(vf->priv->pp&0xFFFF) return; // non-local filters enabled | |
5513 | 77 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) && |
78 mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
79 if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt) |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
80 return; // colorspace differ |
5512 | 81 // ok, we can do pp in-place (or pp disabled): |
82 vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
83 mpi->type, mpi->flags, mpi->w, mpi->h); | |
84 mpi->planes[0]=vf->priv->dmpi->planes[0]; | |
85 mpi->stride[0]=vf->priv->dmpi->stride[0]; | |
86 mpi->width=vf->priv->dmpi->width; | |
87 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
88 mpi->planes[1]=vf->priv->dmpi->planes[1]; | |
89 mpi->planes[2]=vf->priv->dmpi->planes[2]; | |
90 mpi->stride[1]=vf->priv->dmpi->stride[1]; | |
91 mpi->stride[2]=vf->priv->dmpi->stride[2]; | |
92 } | |
93 mpi->flags|=MP_IMGFLAG_DIRECT; | |
94 } | |
95 | |
7368 | 96 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
5512 | 97 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
98 // no DR, so get a new image! hope we'll get DR buffer: | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
99 vf->priv->dmpi=vf_get_image(vf->next,vf->priv->outfmt, |
6875 | 100 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, |
101 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
102 // mpi->w,mpi->h); | |
103 (mpi->w+7)&(~7),(mpi->h+7)&(~7)); | |
104 vf->priv->dmpi->w=mpi->w; vf->priv->dmpi->h=mpi->h; // display w;h | |
5512 | 105 } |
106 | |
107 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
108 // do the postprocessing! (or copy if no DR) | |
7961 | 109 pp_postprocess(mpi->planes ,mpi->stride, |
7946 | 110 vf->priv->dmpi->planes,vf->priv->dmpi->stride, |
6875 | 111 (mpi->w+7)&(~7),mpi->h, |
5512 | 112 mpi->qscale, mpi->qstride, |
8038 | 113 vf->priv->ppMode[ vf->priv->pp ], vf->priv->context, |
7960 | 114 mpi->pict_type); |
5512 | 115 } |
7368 | 116 return vf_next_put_image(vf,vf->priv->dmpi); |
5512 | 117 } |
118 | |
119 //===========================================================================// | |
120 | |
121 extern int divx_quality; | |
122 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
123 static unsigned int fmt_list[]={ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
124 IMGFMT_YV12, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
125 IMGFMT_I420, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
126 IMGFMT_IYUV, |
7127 | 127 0 |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
128 }; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
129 |
5512 | 130 static int open(vf_instance_t *vf, char* args){ |
7946 | 131 char *endptr, *name; |
132 int i; | |
133 int hex_mode=0; | |
134 | |
5518 | 135 vf->query_format=query_format; |
5519 | 136 vf->control=control; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
137 vf->config=config; |
5512 | 138 vf->get_image=get_image; |
139 vf->put_image=put_image; | |
7949 | 140 vf->uninit=uninit; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
141 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC; |
5512 | 142 vf->priv=malloc(sizeof(struct vf_priv_s)); |
7949 | 143 vf->priv->context=NULL; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
144 |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
145 // check csp: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
146 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
147 if(!vf->priv->outfmt) return 0; // no csp match :( |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
148 |
5514 | 149 if(args){ |
7946 | 150 if(!strcmp("help", args)){ |
7961 | 151 printf("%s", pp_help); |
7946 | 152 exit(1); |
153 } | |
154 | |
155 hex_mode= strtol(args, &endptr, 0); | |
156 if(*endptr){ | |
157 name= args; | |
158 }else | |
159 name= NULL; | |
160 }else{ | |
161 name="de"; | |
5514 | 162 } |
7972 | 163 |
8038 | 164 #ifdef EMU_OLD |
7946 | 165 if(name){ |
8038 | 166 #endif |
8040 | 167 for(i=0; i<=PP_QUALITY_MAX; i++){ |
7961 | 168 vf->priv->ppMode[i]= pp_get_mode_by_name_and_quality(name, i); |
8038 | 169 if(vf->priv->ppMode[i]==NULL) return -1; |
7946 | 170 } |
8038 | 171 #ifdef EMU_OLD |
7946 | 172 }else{ |
173 /* hex mode for compatibility */ | |
8040 | 174 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 175 PPMode *ppMode; |
176 | |
177 ppMode= (PPMode*)memalign(8, sizeof(PPMode)); | |
7946 | 178 |
8038 | 179 ppMode->lumMode= hex_mode; |
180 ppMode->chromMode= ((hex_mode&0xFF)>>4) | (hex_mode&0xFFFFFF00); | |
181 ppMode->maxTmpNoise[0]= 700; | |
182 ppMode->maxTmpNoise[1]= 1500; | |
183 ppMode->maxTmpNoise[2]= 3000; | |
184 ppMode->maxAllowedY= 234; | |
185 ppMode->minAllowedY= 16; | |
186 ppMode->baseDcDiff= 256/4; | |
187 ppMode->flatnessThreshold=40; | |
7946 | 188 |
189 vf->priv->ppMode[i]= ppMode; | |
190 } | |
191 } | |
8038 | 192 #endif |
7946 | 193 |
8040 | 194 vf->priv->pp=PP_QUALITY_MAX; //divx_quality; |
5512 | 195 return 1; |
196 } | |
197 | |
7963 | 198 int readPPOpt(void *conf, char *arg) |
199 { | |
200 int val; | |
201 | |
202 if(arg == NULL) | |
203 return -2; // ERR_MISSING_PARAM | |
204 errno = 0; | |
205 val = (int)strtol(arg,NULL,0); | |
206 if(errno != 0) | |
207 return -4; // What about include cfgparser.h and use ERR_* defines */ | |
208 if(val < 0) | |
209 return -3; // ERR_OUT_OF_RANGE | |
210 | |
211 divx_quality = val; | |
212 | |
213 return 1; | |
214 } | |
215 | |
216 void revertPPOpt(void *conf, char* opt) | |
217 { | |
218 divx_quality=0; | |
219 } | |
220 | |
5512 | 221 vf_info_t vf_info_pp = { |
222 "postprocessing", | |
223 "pp", | |
224 "A'rpi", | |
225 "", | |
226 open | |
227 }; | |
228 | |
229 //===========================================================================// |