Mercurial > mplayer.hg
annotate libmpcodecs/vf_pp.c @ 7960:0a4ab841ae29
better deblocking filter
author | michael |
---|---|
date | Tue, 29 Oct 2002 18:35:15 +0000 |
parents | 0aedfdc5d6ef |
children | 78e0f2776da7 |
rev | line source |
---|---|
5512 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
7946 | 4 #include <inttypes.h> |
5512 | 5 |
6 #include "../config.h" | |
7 #include "../mp_msg.h" | |
8 | |
5607 | 9 #include "img_format.h" |
10 #include "mp_image.h" | |
5512 | 11 #include "vf.h" |
12 | |
13 #include "../postproc/postprocess.h" | |
14 | |
15 struct vf_priv_s { | |
7946 | 16 int pp; |
17 PPMode ppMode[GET_PP_QUALITY_MAX+1]; | |
18 void *context; | |
5512 | 19 mp_image_t *dmpi; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
20 unsigned int outfmt; |
5512 | 21 }; |
22 | |
23 //===========================================================================// | |
24 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
25 static int config(struct vf_instance_s* vf, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
26 int width, int height, int d_width, int d_height, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
27 unsigned int voflags, unsigned int outfmt){ |
7946 | 28 vf->priv->context= getPPContext(width, height); |
29 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
30 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
|
31 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
32 |
7949 | 33 static void uninit(struct vf_instance_s* vf){ |
34 if(vf->priv->context) freePPContext(vf->priv->context); | |
35 } | |
36 | |
5518 | 37 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
38 switch(fmt){ | |
39 case IMGFMT_YV12: | |
40 case IMGFMT_I420: | |
41 case IMGFMT_IYUV: | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
42 return vf_next_query_format(vf,vf->priv->outfmt); |
5518 | 43 } |
44 return 0; | |
45 } | |
46 | |
5519 | 47 static int control(struct vf_instance_s* vf, int request, void* data){ |
48 switch(request){ | |
49 case VFCTRL_QUERY_MAX_PP_LEVEL: | |
50 return GET_PP_QUALITY_MAX; | |
51 case VFCTRL_SET_PP_LEVEL: | |
7946 | 52 vf->priv->pp= *((unsigned int*)data); |
5519 | 53 return CONTROL_TRUE; |
54 } | |
55 return vf_next_control(vf,request,data); | |
56 } | |
57 | |
5512 | 58 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
59 if(vf->priv->pp&0xFFFF) return; // non-local filters enabled | |
5513 | 60 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) && |
61 mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
62 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
|
63 return; // colorspace differ |
5512 | 64 // ok, we can do pp in-place (or pp disabled): |
65 vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
66 mpi->type, mpi->flags, mpi->w, mpi->h); | |
67 mpi->planes[0]=vf->priv->dmpi->planes[0]; | |
68 mpi->stride[0]=vf->priv->dmpi->stride[0]; | |
69 mpi->width=vf->priv->dmpi->width; | |
70 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
71 mpi->planes[1]=vf->priv->dmpi->planes[1]; | |
72 mpi->planes[2]=vf->priv->dmpi->planes[2]; | |
73 mpi->stride[1]=vf->priv->dmpi->stride[1]; | |
74 mpi->stride[2]=vf->priv->dmpi->stride[2]; | |
75 } | |
76 mpi->flags|=MP_IMGFLAG_DIRECT; | |
77 } | |
78 | |
7368 | 79 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
5512 | 80 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
81 // 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
|
82 vf->priv->dmpi=vf_get_image(vf->next,vf->priv->outfmt, |
6875 | 83 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, |
84 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
85 // mpi->w,mpi->h); | |
86 (mpi->w+7)&(~7),(mpi->h+7)&(~7)); | |
87 vf->priv->dmpi->w=mpi->w; vf->priv->dmpi->h=mpi->h; // display w;h | |
5512 | 88 } |
89 | |
90 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
91 // do the postprocessing! (or copy if no DR) | |
7946 | 92 postprocess(mpi->planes ,mpi->stride, |
93 vf->priv->dmpi->planes,vf->priv->dmpi->stride, | |
6875 | 94 (mpi->w+7)&(~7),mpi->h, |
5512 | 95 mpi->qscale, mpi->qstride, |
7960 | 96 &vf->priv->ppMode[ vf->priv->pp ], vf->priv->context, |
97 mpi->pict_type); | |
5512 | 98 } |
99 | |
7368 | 100 return vf_next_put_image(vf,vf->priv->dmpi); |
5512 | 101 } |
102 | |
103 //===========================================================================// | |
104 | |
105 extern int divx_quality; | |
106 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
107 static unsigned int fmt_list[]={ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
108 IMGFMT_YV12, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
109 IMGFMT_I420, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
110 IMGFMT_IYUV, |
7127 | 111 0 |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
112 }; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
113 |
5512 | 114 static int open(vf_instance_t *vf, char* args){ |
7946 | 115 char *endptr, *name; |
116 int i; | |
117 int hex_mode=0; | |
118 | |
5518 | 119 vf->query_format=query_format; |
5519 | 120 vf->control=control; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
121 vf->config=config; |
5512 | 122 vf->get_image=get_image; |
123 vf->put_image=put_image; | |
7949 | 124 vf->uninit=uninit; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
125 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC; |
5512 | 126 vf->priv=malloc(sizeof(struct vf_priv_s)); |
7949 | 127 vf->priv->context=NULL; |
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 // check csp: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
130 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
|
131 if(!vf->priv->outfmt) return 0; // no csp match :( |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5519
diff
changeset
|
132 |
5514 | 133 if(args){ |
7946 | 134 if(!strcmp("help", args)){ |
135 printf("%s", postproc_help); | |
136 exit(1); | |
137 } | |
138 | |
139 hex_mode= strtol(args, &endptr, 0); | |
140 if(*endptr){ | |
141 name= args; | |
142 }else | |
143 name= NULL; | |
144 }else{ | |
145 name="de"; | |
5514 | 146 } |
7946 | 147 |
148 if(name){ | |
149 for(i=0; i<=GET_PP_QUALITY_MAX; i++){ | |
150 vf->priv->ppMode[i]= getPPModeByNameAndQuality(name, i); | |
151 if(vf->priv->ppMode[i].error) return -1; | |
152 } | |
153 }else{ | |
154 /* hex mode for compatibility */ | |
155 for(i=0; i<=GET_PP_QUALITY_MAX; i++){ | |
156 PPMode ppMode; | |
157 | |
158 ppMode.lumMode= hex_mode; | |
159 ppMode.chromMode= ((hex_mode&0xFF)>>4) | (hex_mode&0xFFFFFF00); | |
160 ppMode.maxTmpNoise[0]= 700; | |
161 ppMode.maxTmpNoise[1]= 1500; | |
162 ppMode.maxTmpNoise[2]= 3000; | |
163 ppMode.maxAllowedY= 234; | |
164 ppMode.minAllowedY= 16; | |
7960 | 165 ppMode.baseDcDiff= 256/4; |
7946 | 166 ppMode.flatnessThreshold=40; |
167 | |
168 vf->priv->ppMode[i]= ppMode; | |
169 } | |
170 } | |
171 | |
172 vf->priv->pp=GET_PP_QUALITY_MAX; //divx_quality; | |
5512 | 173 return 1; |
174 } | |
175 | |
176 vf_info_t vf_info_pp = { | |
177 "postprocessing", | |
178 "pp", | |
179 "A'rpi", | |
180 "", | |
181 open | |
182 }; | |
183 | |
184 //===========================================================================// |