2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "cpudetect.h"
33 #include "img_format.h"
36 #include "libpostproc/postprocess.h"
40 pp_mode
*ppMode
[PP_QUALITY_MAX
+1];
45 //===========================================================================//
47 static int config(struct vf_instance
*vf
,
48 int width
, int height
, int d_width
, int d_height
,
49 unsigned int voflags
, unsigned int outfmt
){
51 (gCpuCaps
.hasMMX
? PP_CPU_CAPS_MMX
: 0)
52 | (gCpuCaps
.hasMMX2
? PP_CPU_CAPS_MMX2
: 0)
53 | (gCpuCaps
.has3DNow
? PP_CPU_CAPS_3DNOW
: 0);
56 case IMGFMT_444P
: flags
|= PP_FORMAT_444
; break;
57 case IMGFMT_422P
: flags
|= PP_FORMAT_422
; break;
58 case IMGFMT_411P
: flags
|= PP_FORMAT_411
; break;
59 default: flags
|= PP_FORMAT_420
; break;
62 if(vf
->priv
->context
) pp_free_context(vf
->priv
->context
);
63 vf
->priv
->context
= pp_get_context(width
, height
, flags
);
65 return vf_next_config(vf
,width
,height
,d_width
,d_height
,voflags
,outfmt
);
68 static void uninit(struct vf_instance
*vf
){
70 for(i
=0; i
<=PP_QUALITY_MAX
; i
++){
71 if(vf
->priv
->ppMode
[i
])
72 pp_free_mode(vf
->priv
->ppMode
[i
]);
74 if(vf
->priv
->context
) pp_free_context(vf
->priv
->context
);
77 static int query_format(struct vf_instance
*vf
, unsigned int fmt
){
85 return vf_next_query_format(vf
,fmt
);
90 static int control(struct vf_instance
*vf
, int request
, void* data
){
92 case VFCTRL_QUERY_MAX_PP_LEVEL
:
93 return PP_QUALITY_MAX
;
94 case VFCTRL_SET_PP_LEVEL
:
95 vf
->priv
->pp
= *((unsigned int*)data
);
98 return vf_next_control(vf
,request
,data
);
101 static void get_image(struct vf_instance
*vf
, mp_image_t
*mpi
){
102 if(vf
->priv
->pp
&0xFFFF) return; // non-local filters enabled
103 if((mpi
->type
==MP_IMGTYPE_IPB
|| vf
->priv
->pp
) &&
104 mpi
->flags
&MP_IMGFLAG_PRESERVE
) return; // don't change
105 if(!(mpi
->flags
&MP_IMGFLAG_ACCEPT_STRIDE
) && mpi
->imgfmt
!=vf
->priv
->outfmt
)
106 return; // colorspace differ
107 // ok, we can do pp in-place (or pp disabled):
108 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
109 mpi
->type
, mpi
->flags
| MP_IMGFLAG_READABLE
, mpi
->width
, mpi
->height
);
110 mpi
->planes
[0]=vf
->dmpi
->planes
[0];
111 mpi
->stride
[0]=vf
->dmpi
->stride
[0];
112 mpi
->width
=vf
->dmpi
->width
;
113 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
114 mpi
->planes
[1]=vf
->dmpi
->planes
[1];
115 mpi
->planes
[2]=vf
->dmpi
->planes
[2];
116 mpi
->stride
[1]=vf
->dmpi
->stride
[1];
117 mpi
->stride
[2]=vf
->dmpi
->stride
[2];
119 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
122 static int put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
){
123 if(!(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
124 // no DR, so get a new image! hope we'll get DR buffer:
125 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
126 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
|
127 MP_IMGFLAG_PREFER_ALIGNED_STRIDE
| MP_IMGFLAG_READABLE
,
128 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
130 (mpi
->width
+7)&(~7),(mpi
->height
+7)&(~7));
131 vf
->dmpi
->w
=mpi
->w
; vf
->dmpi
->h
=mpi
->h
; // display w;h
134 if(vf
->priv
->pp
|| !(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
135 // do the postprocessing! (or copy if no DR)
136 pp_postprocess((const uint8_t **)mpi
->planes
, mpi
->stride
,
137 vf
->dmpi
->planes
,vf
->dmpi
->stride
,
138 (mpi
->w
+7)&(~7),mpi
->h
,
139 mpi
->qscale
, mpi
->qstride
,
140 vf
->priv
->ppMode
[ vf
->priv
->pp
], vf
->priv
->context
,
141 #ifdef PP_PICT_TYPE_QP2
142 mpi
->pict_type
| (mpi
->qscale_type
? PP_PICT_TYPE_QP2
: 0));
147 return vf_next_put_image(vf
,vf
->dmpi
, pts
);
150 //===========================================================================//
152 extern int divx_quality
;
154 static const unsigned int fmt_list
[]={
164 static int vf_open(vf_instance_t
*vf
, char *args
){
167 vf
->query_format
=query_format
;
170 vf
->get_image
=get_image
;
171 vf
->put_image
=put_image
;
173 vf
->default_caps
=VFCAP_ACCEPT_STRIDE
|VFCAP_POSTPROC
;
174 vf
->priv
=malloc(sizeof(struct vf_priv_s
));
175 vf
->priv
->context
=NULL
;
178 vf
->priv
->outfmt
=vf_match_csp(&vf
->next
,fmt_list
,IMGFMT_YV12
);
179 if(!vf
->priv
->outfmt
) return 0; // no csp match :(
181 char *name
= args
? args
: "de";
183 for(i
=0; i
<=PP_QUALITY_MAX
; i
++){
184 vf
->priv
->ppMode
[i
]= pp_get_mode_by_name_and_quality(name
, i
);
185 if(vf
->priv
->ppMode
[i
]==NULL
) return -1;
188 vf
->priv
->pp
=PP_QUALITY_MAX
;
192 const vf_info_t vf_info_pp
= {
201 //===========================================================================//