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