vf_pp: Remove deprecated "hex mode" support
[mplayer/glamo.git] / libmpcodecs / vf_pp.c
blob6d589a991895309ae263998e7981843dd9a64124
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <inttypes.h>
5 #include <errno.h>
7 #include "config.h"
8 #include "mp_msg.h"
9 #include "cpudetect.h"
11 #if HAVE_MALLOC_H
12 #include <malloc.h>
13 #endif
15 #include "img_format.h"
16 #include "mp_image.h"
17 #include "vf.h"
18 #include "libpostproc/postprocess.h"
20 struct vf_priv_s {
21 int pp;
22 pp_mode_t *ppMode[PP_QUALITY_MAX+1];
23 void *context;
24 unsigned int outfmt;
27 //===========================================================================//
29 static int config(struct vf_instance* vf,
30 int width, int height, int d_width, int d_height,
31 unsigned int voflags, unsigned int outfmt){
32 int flags=
33 (gCpuCaps.hasMMX ? PP_CPU_CAPS_MMX : 0)
34 | (gCpuCaps.hasMMX2 ? PP_CPU_CAPS_MMX2 : 0)
35 | (gCpuCaps.has3DNow ? PP_CPU_CAPS_3DNOW : 0);
37 switch(outfmt){
38 case IMGFMT_444P: flags|= PP_FORMAT_444; break;
39 case IMGFMT_422P: flags|= PP_FORMAT_422; break;
40 case IMGFMT_411P: flags|= PP_FORMAT_411; break;
41 default: flags|= PP_FORMAT_420; break;
44 if(vf->priv->context) pp_free_context(vf->priv->context);
45 vf->priv->context= pp_get_context(width, height, flags);
47 return vf_next_config(vf,width,height,d_width,d_height,voflags,outfmt);
50 static void uninit(struct vf_instance* vf){
51 int i;
52 for(i=0; i<=PP_QUALITY_MAX; i++){
53 if(vf->priv->ppMode[i])
54 pp_free_mode(vf->priv->ppMode[i]);
56 if(vf->priv->context) pp_free_context(vf->priv->context);
59 static int query_format(struct vf_instance* vf, unsigned int fmt){
60 switch(fmt){
61 case IMGFMT_YV12:
62 case IMGFMT_I420:
63 case IMGFMT_IYUV:
64 case IMGFMT_444P:
65 case IMGFMT_422P:
66 case IMGFMT_411P:
67 return vf_next_query_format(vf,fmt);
69 return 0;
72 static int control(struct vf_instance* vf, int request, void* data){
73 switch(request){
74 case VFCTRL_QUERY_MAX_PP_LEVEL:
75 return PP_QUALITY_MAX;
76 case VFCTRL_SET_PP_LEVEL:
77 vf->priv->pp= *((unsigned int*)data);
78 return CONTROL_TRUE;
80 return vf_next_control(vf,request,data);
83 static void get_image(struct vf_instance* vf, mp_image_t *mpi){
84 if(vf->priv->pp&0xFFFF) return; // non-local filters enabled
85 if((mpi->type==MP_IMGTYPE_IPB || vf->priv->pp) &&
86 mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
87 if(!(mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) && mpi->imgfmt!=vf->priv->outfmt)
88 return; // colorspace differ
89 // ok, we can do pp in-place (or pp disabled):
90 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
91 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
92 mpi->planes[0]=vf->dmpi->planes[0];
93 mpi->stride[0]=vf->dmpi->stride[0];
94 mpi->width=vf->dmpi->width;
95 if(mpi->flags&MP_IMGFLAG_PLANAR){
96 mpi->planes[1]=vf->dmpi->planes[1];
97 mpi->planes[2]=vf->dmpi->planes[2];
98 mpi->stride[1]=vf->dmpi->stride[1];
99 mpi->stride[2]=vf->dmpi->stride[2];
101 mpi->flags|=MP_IMGFLAG_DIRECT;
104 static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts){
105 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
106 // no DR, so get a new image! hope we'll get DR buffer:
107 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
108 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
109 MP_IMGFLAG_PREFER_ALIGNED_STRIDE | MP_IMGFLAG_READABLE,
110 // MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
111 // mpi->w,mpi->h);
112 (mpi->width+7)&(~7),(mpi->height+7)&(~7));
113 vf->dmpi->w=mpi->w; vf->dmpi->h=mpi->h; // display w;h
116 if(vf->priv->pp || !(mpi->flags&MP_IMGFLAG_DIRECT)){
117 // do the postprocessing! (or copy if no DR)
118 pp_postprocess(mpi->planes ,mpi->stride,
119 vf->dmpi->planes,vf->dmpi->stride,
120 (mpi->w+7)&(~7),mpi->h,
121 mpi->qscale, mpi->qstride,
122 vf->priv->ppMode[ vf->priv->pp ], vf->priv->context,
123 #ifdef PP_PICT_TYPE_QP2
124 mpi->pict_type | (mpi->qscale_type ? PP_PICT_TYPE_QP2 : 0));
125 #else
126 mpi->pict_type);
127 #endif
129 return vf_next_put_image(vf,vf->dmpi, pts);
132 //===========================================================================//
134 extern int divx_quality;
136 static const unsigned int fmt_list[]={
137 IMGFMT_YV12,
138 IMGFMT_I420,
139 IMGFMT_IYUV,
140 IMGFMT_444P,
141 IMGFMT_422P,
142 IMGFMT_411P,
146 static int open(vf_instance_t *vf, char* args){
147 char *endptr, *name;
148 int i;
149 int hex_mode=0;
151 vf->query_format=query_format;
152 vf->control=control;
153 vf->config=config;
154 vf->get_image=get_image;
155 vf->put_image=put_image;
156 vf->uninit=uninit;
157 vf->default_caps=VFCAP_ACCEPT_STRIDE|VFCAP_POSTPROC;
158 vf->priv=malloc(sizeof(struct vf_priv_s));
159 vf->priv->context=NULL;
161 // check csp:
162 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
163 if(!vf->priv->outfmt) return 0; // no csp match :(
165 if(args){
166 hex_mode= strtol(args, &endptr, 0);
167 if(*endptr){
168 name= args;
169 }else
170 name= NULL;
171 }else{
172 name="de";
175 for(i=0; i<=PP_QUALITY_MAX; i++){
176 vf->priv->ppMode[i]= pp_get_mode_by_name_and_quality(name, i);
177 if(vf->priv->ppMode[i]==NULL) return -1;
180 vf->priv->pp=PP_QUALITY_MAX;
181 return 1;
184 const vf_info_t vf_info_pp = {
185 "postprocessing",
186 "pp",
187 "A'rpi",
189 open,
190 NULL
193 //===========================================================================//