Mercurial > mplayer.hg
annotate libmpcodecs/vf_pp.c @ 11744:70b8047bc7df
sync, tested :-P
BTW, xml/pl fails to compile.
author | nauj27 |
---|---|
date | Mon, 05 Jan 2004 10:39:04 +0000 |
parents | e40dee59f3ba |
children | 6ca3e46894b6 |
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; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
33 unsigned int outfmt; |
5512 | 34 }; |
35 | |
36 //===========================================================================// | |
37 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
38 static int config(struct vf_instance_s* vf, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
39 int width, int height, int d_width, int d_height, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
40 unsigned int voflags, unsigned int outfmt){ |
8805 | 41 int flags= |
7985 | 42 (gCpuCaps.hasMMX ? PP_CPU_CAPS_MMX : 0) |
43 | (gCpuCaps.hasMMX2 ? PP_CPU_CAPS_MMX2 : 0) | |
8805 | 44 | (gCpuCaps.has3DNow ? PP_CPU_CAPS_3DNOW : 0); |
45 | |
46 switch(outfmt){ | |
47 case IMGFMT_444P: flags|= PP_FORMAT_444; break; | |
48 case IMGFMT_422P: flags|= PP_FORMAT_422; break; | |
49 case IMGFMT_411P: flags|= PP_FORMAT_411; break; | |
50 default: flags|= PP_FORMAT_420; break; | |
51 } | |
52 | |
53 if(vf->priv->context) pp_free_context(vf->priv->context); | |
54 vf->priv->context= pp_get_context(width, height, flags); | |
7946 | 55 |
9528 | 56 return vf_next_config(vf,width,height,d_width,d_height,voflags,outfmt); |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
57 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
58 |
7949 | 59 static void uninit(struct vf_instance_s* vf){ |
8038 | 60 int i; |
8040 | 61 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 62 if(vf->priv->ppMode[i]) |
63 pp_free_mode(vf->priv->ppMode[i]); | |
64 } | |
7961 | 65 if(vf->priv->context) pp_free_context(vf->priv->context); |
7949 | 66 } |
67 | |
5518 | 68 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
69 switch(fmt){ | |
70 case IMGFMT_YV12: | |
71 case IMGFMT_I420: | |
72 case IMGFMT_IYUV: | |
8805 | 73 case IMGFMT_444P: |
74 case IMGFMT_422P: | |
75 case IMGFMT_411P: | |
76 return vf_next_query_format(vf,fmt); | |
5518 | 77 } |
78 return 0; | |
79 } | |
80 | |
5519 | 81 static int control(struct vf_instance_s* vf, int request, void* data){ |
82 switch(request){ | |
83 case VFCTRL_QUERY_MAX_PP_LEVEL: | |
8040 | 84 return PP_QUALITY_MAX; |
5519 | 85 case VFCTRL_SET_PP_LEVEL: |
7946 | 86 vf->priv->pp= *((unsigned int*)data); |
5519 | 87 return CONTROL_TRUE; |
88 } | |
89 return vf_next_control(vf,request,data); | |
90 } | |
91 | |
5512 | 92 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
93 if(vf->priv->pp&0xFFFF) return; // non-local filters enabled | |
5513 | 94 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) && |
95 mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
96 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
|
97 return; // colorspace differ |
5512 | 98 // ok, we can do pp in-place (or pp disabled): |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
99 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, |
5512 | 100 mpi->type, mpi->flags, mpi->w, mpi->h); |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
101 mpi->planes[0]=vf->dmpi->planes[0]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
102 mpi->stride[0]=vf->dmpi->stride[0]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
103 mpi->width=vf->dmpi->width; |
5512 | 104 if(mpi->flags&MP_IMGFLAG_PLANAR){ |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
105 mpi->planes[1]=vf->dmpi->planes[1]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
106 mpi->planes[2]=vf->dmpi->planes[2]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
107 mpi->stride[1]=vf->dmpi->stride[1]; |
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
108 mpi->stride[2]=vf->dmpi->stride[2]; |
5512 | 109 } |
110 mpi->flags|=MP_IMGFLAG_DIRECT; | |
111 } | |
112 | |
7368 | 113 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
5512 | 114 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
115 // no DR, so get a new image! hope we'll get DR buffer: | |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
116 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, |
6875 | 117 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, |
118 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
119 // mpi->w,mpi->h); | |
120 (mpi->w+7)&(~7),(mpi->h+7)&(~7)); | |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
121 vf->dmpi->w=mpi->w; vf->dmpi->h=mpi->h; // display w;h |
5512 | 122 } |
123 | |
124 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
125 // do the postprocessing! (or copy if no DR) | |
7961 | 126 pp_postprocess(mpi->planes ,mpi->stride, |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
127 vf->dmpi->planes,vf->dmpi->stride, |
6875 | 128 (mpi->w+7)&(~7),mpi->h, |
5512 | 129 mpi->qscale, mpi->qstride, |
8038 | 130 vf->priv->ppMode[ vf->priv->pp ], vf->priv->context, |
9931 | 131 #ifdef PP_PICT_TYPE_QP2 |
9925
420640a0f6d0
passing qscale_type around so the pp code can fix the mpeg2 <<1 thing
michael
parents:
9593
diff
changeset
|
132 mpi->pict_type | (mpi->qscale_type ? PP_PICT_TYPE_QP2 : 0)); |
9931 | 133 #else |
134 mpi->pict_type); | |
135 #endif | |
5512 | 136 } |
10141
7d6a854a5fe5
cleanup, use vf->dmpi rather than vf->priv->dmpi for consistency
rfelker
parents:
9931
diff
changeset
|
137 return vf_next_put_image(vf,vf->dmpi); |
5512 | 138 } |
139 | |
140 //===========================================================================// | |
141 | |
142 extern int divx_quality; | |
143 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
144 static unsigned int fmt_list[]={ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
145 IMGFMT_YV12, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
146 IMGFMT_I420, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
147 IMGFMT_IYUV, |
8805 | 148 IMGFMT_444P, |
149 IMGFMT_422P, | |
150 IMGFMT_411P, | |
7127 | 151 0 |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
152 }; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
153 |
5512 | 154 static int open(vf_instance_t *vf, char* args){ |
7946 | 155 char *endptr, *name; |
156 int i; | |
157 int hex_mode=0; | |
158 | |
5518 | 159 vf->query_format=query_format; |
5519 | 160 vf->control=control; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
161 vf->config=config; |
5512 | 162 vf->get_image=get_image; |
163 vf->put_image=put_image; | |
7949 | 164 vf->uninit=uninit; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
165 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC; |
5512 | 166 vf->priv=malloc(sizeof(struct vf_priv_s)); |
7949 | 167 vf->priv->context=NULL; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
168 |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
169 // check csp: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
170 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
|
171 if(!vf->priv->outfmt) return 0; // no csp match :( |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
172 |
5514 | 173 if(args){ |
7946 | 174 hex_mode= strtol(args, &endptr, 0); |
175 if(*endptr){ | |
176 name= args; | |
177 }else | |
178 name= NULL; | |
179 }else{ | |
180 name="de"; | |
5514 | 181 } |
7972 | 182 |
8038 | 183 #ifdef EMU_OLD |
7946 | 184 if(name){ |
8038 | 185 #endif |
8040 | 186 for(i=0; i<=PP_QUALITY_MAX; i++){ |
7961 | 187 vf->priv->ppMode[i]= pp_get_mode_by_name_and_quality(name, i); |
8038 | 188 if(vf->priv->ppMode[i]==NULL) return -1; |
7946 | 189 } |
8038 | 190 #ifdef EMU_OLD |
7946 | 191 }else{ |
192 /* hex mode for compatibility */ | |
8040 | 193 for(i=0; i<=PP_QUALITY_MAX; i++){ |
8038 | 194 PPMode *ppMode; |
195 | |
196 ppMode= (PPMode*)memalign(8, sizeof(PPMode)); | |
7946 | 197 |
8038 | 198 ppMode->lumMode= hex_mode; |
199 ppMode->chromMode= ((hex_mode&0xFF)>>4) | (hex_mode&0xFFFFFF00); | |
200 ppMode->maxTmpNoise[0]= 700; | |
201 ppMode->maxTmpNoise[1]= 1500; | |
202 ppMode->maxTmpNoise[2]= 3000; | |
203 ppMode->maxAllowedY= 234; | |
204 ppMode->minAllowedY= 16; | |
205 ppMode->baseDcDiff= 256/4; | |
206 ppMode->flatnessThreshold=40; | |
7946 | 207 |
208 vf->priv->ppMode[i]= ppMode; | |
209 } | |
210 } | |
8038 | 211 #endif |
7946 | 212 |
10756 | 213 vf->priv->pp=PP_QUALITY_MAX; |
5512 | 214 return 1; |
215 } | |
216 | |
217 vf_info_t vf_info_pp = { | |
218 "postprocessing", | |
219 "pp", | |
220 "A'rpi", | |
221 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9528
diff
changeset
|
222 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9528
diff
changeset
|
223 NULL |
5512 | 224 }; |
225 | |
226 //===========================================================================// | |
9426 | 227 |
228 #endif // USE_LIBAVCODEC |