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