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