15 #include "img_format.h"
20 #ifdef USE_LIBPOSTPROC_SO
21 #include <postproc/postprocess.h>
22 #elif defined(USE_LIBPOSTPROC)
24 #include "libpostproc/postprocess.h"
27 #include "libpostproc/postprocess_internal.h"
33 pp_mode_t
*ppMode
[PP_QUALITY_MAX
+1];
38 //===========================================================================//
40 static int config(struct vf_instance_s
* vf
,
41 int width
, int height
, int d_width
, int d_height
,
42 unsigned int voflags
, unsigned int outfmt
){
44 (gCpuCaps
.hasMMX
? PP_CPU_CAPS_MMX
: 0)
45 | (gCpuCaps
.hasMMX2
? PP_CPU_CAPS_MMX2
: 0)
46 | (gCpuCaps
.has3DNow
? PP_CPU_CAPS_3DNOW
: 0);
49 case IMGFMT_444P
: flags
|= PP_FORMAT_444
; break;
50 case IMGFMT_422P
: flags
|= PP_FORMAT_422
; break;
51 case IMGFMT_411P
: flags
|= PP_FORMAT_411
; break;
52 default: flags
|= PP_FORMAT_420
; break;
55 if(vf
->priv
->context
) pp_free_context(vf
->priv
->context
);
56 vf
->priv
->context
= pp_get_context(width
, height
, flags
);
58 return vf_next_config(vf
,width
,height
,d_width
,d_height
,voflags
,outfmt
);
61 static void uninit(struct vf_instance_s
* vf
){
63 for(i
=0; i
<=PP_QUALITY_MAX
; i
++){
64 if(vf
->priv
->ppMode
[i
])
65 pp_free_mode(vf
->priv
->ppMode
[i
]);
67 if(vf
->priv
->context
) pp_free_context(vf
->priv
->context
);
70 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
){
78 return vf_next_query_format(vf
,fmt
);
83 static int control(struct vf_instance_s
* vf
, int request
, void* data
){
85 case VFCTRL_QUERY_MAX_PP_LEVEL
:
86 return PP_QUALITY_MAX
;
87 case VFCTRL_SET_PP_LEVEL
:
88 vf
->priv
->pp
= *((unsigned int*)data
);
91 return vf_next_control(vf
,request
,data
);
94 static void get_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
){
95 if(vf
->priv
->pp
&0xFFFF) return; // non-local filters enabled
96 if((mpi
->type
==MP_IMGTYPE_IPB
|| vf
->priv
->pp
) &&
97 mpi
->flags
&MP_IMGFLAG_PRESERVE
) return; // don't change
98 if(!(mpi
->flags
&MP_IMGFLAG_ACCEPT_STRIDE
) && mpi
->imgfmt
!=vf
->priv
->outfmt
)
99 return; // colorspace differ
100 // ok, we can do pp in-place (or pp disabled):
101 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
102 mpi
->type
, mpi
->flags
| MP_IMGFLAG_READABLE
, mpi
->width
, mpi
->height
);
103 mpi
->planes
[0]=vf
->dmpi
->planes
[0];
104 mpi
->stride
[0]=vf
->dmpi
->stride
[0];
105 mpi
->width
=vf
->dmpi
->width
;
106 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
107 mpi
->planes
[1]=vf
->dmpi
->planes
[1];
108 mpi
->planes
[2]=vf
->dmpi
->planes
[2];
109 mpi
->stride
[1]=vf
->dmpi
->stride
[1];
110 mpi
->stride
[2]=vf
->dmpi
->stride
[2];
112 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
115 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
){
116 if(!(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
117 // no DR, so get a new image! hope we'll get DR buffer:
118 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
119 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
|
120 MP_IMGFLAG_PREFER_ALIGNED_STRIDE
| MP_IMGFLAG_READABLE
,
121 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
123 (mpi
->width
+7)&(~7),(mpi
->height
+7)&(~7));
124 vf
->dmpi
->w
=mpi
->w
; vf
->dmpi
->h
=mpi
->h
; // display w;h
127 if(vf
->priv
->pp
|| !(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
128 // do the postprocessing! (or copy if no DR)
129 pp_postprocess(mpi
->planes
,mpi
->stride
,
130 vf
->dmpi
->planes
,vf
->dmpi
->stride
,
131 (mpi
->w
+7)&(~7),mpi
->h
,
132 mpi
->qscale
, mpi
->qstride
,
133 vf
->priv
->ppMode
[ vf
->priv
->pp
], vf
->priv
->context
,
134 #ifdef PP_PICT_TYPE_QP2
135 mpi
->pict_type
| (mpi
->qscale_type
? PP_PICT_TYPE_QP2
: 0));
140 return vf_next_put_image(vf
,vf
->dmpi
, pts
);
143 //===========================================================================//
145 extern int divx_quality
;
147 static unsigned int fmt_list
[]={
157 static int open(vf_instance_t
*vf
, char* args
){
162 vf
->query_format
=query_format
;
165 vf
->get_image
=get_image
;
166 vf
->put_image
=put_image
;
168 vf
->default_caps
=VFCAP_ACCEPT_STRIDE
|VFCAP_POSTPROC
;
169 vf
->priv
=malloc(sizeof(struct vf_priv_s
));
170 vf
->priv
->context
=NULL
;
173 vf
->priv
->outfmt
=vf_match_csp(&vf
->next
,fmt_list
,IMGFMT_YV12
);
174 if(!vf
->priv
->outfmt
) return 0; // no csp match :(
177 hex_mode
= strtol(args
, &endptr
, 0);
189 for(i
=0; i
<=PP_QUALITY_MAX
; i
++){
190 vf
->priv
->ppMode
[i
]= pp_get_mode_by_name_and_quality(name
, i
);
191 if(vf
->priv
->ppMode
[i
]==NULL
) return -1;
195 /* hex mode for compatibility */
196 for(i
=0; i
<=PP_QUALITY_MAX
; i
++){
199 ppMode
= (PPMode
*)memalign(8, sizeof(PPMode
));
201 ppMode
->lumMode
= hex_mode
;
202 ppMode
->chromMode
= ((hex_mode
&0xFF)>>4) | (hex_mode
&0xFFFFFF00);
203 ppMode
->maxTmpNoise
[0]= 700;
204 ppMode
->maxTmpNoise
[1]= 1500;
205 ppMode
->maxTmpNoise
[2]= 3000;
206 ppMode
->maxAllowedY
= 234;
207 ppMode
->minAllowedY
= 16;
208 ppMode
->baseDcDiff
= 256/4;
209 ppMode
->flatnessThreshold
=40;
211 vf
->priv
->ppMode
[i
]= ppMode
;
216 vf
->priv
->pp
=PP_QUALITY_MAX
;
220 const vf_info_t vf_info_pp
= {
229 //===========================================================================//