Mercurial > mplayer.hg
annotate libmpcodecs/vf.c @ 5634:cc24d5e2573f
removed unused XP stuff
author | alex |
---|---|
date | Mon, 15 Apr 2002 17:08:02 +0000 |
parents | 1972c3475d93 |
children | 42e002c565cf |
rev | line source |
---|---|
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
1 #include <stdio.h> |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
2 #include <stdlib.h> |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
3 #include <string.h> |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
4 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
5 #include "../config.h" |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
6 #include "../mp_msg.h" |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
7 |
5607 | 8 #include "img_format.h" |
9 #include "mp_image.h" | |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
10 #include "vf.h" |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
11 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
12 extern vf_info_t vf_info_vo; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
13 extern vf_info_t vf_info_crop; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
14 extern vf_info_t vf_info_expand; |
5512 | 15 extern vf_info_t vf_info_pp; |
5522 | 16 extern vf_info_t vf_info_scale; |
5536 | 17 extern vf_info_t vf_info_fame; |
5539 | 18 extern vf_info_t vf_info_format; |
19 extern vf_info_t vf_info_yuy2; | |
5557 | 20 extern vf_info_t vf_info_flip; |
5594 | 21 extern vf_info_t vf_info_rgb2bgr; |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
22 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
23 char** vo_plugin_args=(char**) NULL; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
24 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
25 // list of available filters: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
26 static vf_info_t* filter_list[]={ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
27 &vf_info_crop, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
28 &vf_info_expand, |
5512 | 29 &vf_info_pp, |
5522 | 30 &vf_info_scale, |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
31 // &vf_info_osd, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
32 &vf_info_vo, |
5536 | 33 &vf_info_fame, |
5539 | 34 &vf_info_format, |
35 &vf_info_yuy2, | |
5557 | 36 &vf_info_flip, |
5594 | 37 &vf_info_rgb2bgr, |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
38 NULL |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
39 }; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
40 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
41 //============================================================================ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
42 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
43 // mpi stuff: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
44 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
45 mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, int mp_imgflag, int w, int h){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
46 mp_image_t* mpi=NULL; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
47 int w2=w; //(mp_imgflag&MP_IMGFLAG_ACCEPT_STRIDE)?((w+15)&(~15)):w; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
48 // Note: we should call libvo first to check if it supports direct rendering |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
49 // and if not, then fallback to software buffers: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
50 switch(mp_imgtype){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
51 case MP_IMGTYPE_EXPORT: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
52 if(!vf->imgctx.export_images[0]) vf->imgctx.export_images[0]=new_mp_image(w2,h); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
53 mpi=vf->imgctx.export_images[0]; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
54 break; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
55 case MP_IMGTYPE_STATIC: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
56 if(!vf->imgctx.static_images[0]) vf->imgctx.static_images[0]=new_mp_image(w2,h); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
57 mpi=vf->imgctx.static_images[0]; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
58 break; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
59 case MP_IMGTYPE_TEMP: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
60 if(!vf->imgctx.temp_images[0]) vf->imgctx.temp_images[0]=new_mp_image(w2,h); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
61 mpi=vf->imgctx.temp_images[0]; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
62 break; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
63 case MP_IMGTYPE_IPB: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
64 if(!(mp_imgflag&MP_IMGFLAG_READABLE)){ // B frame: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
65 if(!vf->imgctx.temp_images[0]) vf->imgctx.temp_images[0]=new_mp_image(w2,h); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
66 mpi=vf->imgctx.temp_images[0]; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
67 break; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
68 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
69 case MP_IMGTYPE_IP: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
70 if(!vf->imgctx.static_images[vf->imgctx.static_idx]) vf->imgctx.static_images[vf->imgctx.static_idx]=new_mp_image(w2,h); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
71 mpi=vf->imgctx.static_images[vf->imgctx.static_idx]; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
72 vf->imgctx.static_idx^=1; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
73 break; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
74 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
75 if(mpi){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
76 mpi->type=mp_imgtype; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
77 mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_DIRECT); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
78 mpi->flags|=mp_imgflag&(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH|MP_IMGFLAG_ALIGNED_STRIDE|MP_IMGFLAG_DRAW_CALLBACK); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
79 if(!vf->draw_slice) mpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
80 if((mpi->width!=w2 || mpi->height!=h) && !(mpi->flags&MP_IMGFLAG_DIRECT)){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
81 mpi->width=w2; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
82 mpi->height=h; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
83 if(mpi->flags&MP_IMGFLAG_ALLOCATED){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
84 // need to re-allocate buffer memory: |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
85 free(mpi->planes[0]); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
86 mpi->flags&=~MP_IMGFLAG_ALLOCATED; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
87 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
88 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
89 if(!mpi->bpp) mp_image_setfmt(mpi,outfmt); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
90 if(!(mpi->flags&MP_IMGFLAG_ALLOCATED) && mpi->type>MP_IMGTYPE_EXPORT){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
91 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
92 // check libvo first! |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
93 if(vf->get_image) vf->get_image(vf,mpi); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
94 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
95 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
96 // non-direct and not yet allocaed image. allocate it! |
5524 | 97 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8); |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
98 if(mpi->flags&MP_IMGFLAG_PLANAR){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
99 // YV12/I420. feel free to add other planar formats here... |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
100 if(!mpi->stride[0]) mpi->stride[0]=mpi->width; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
101 if(!mpi->stride[1]) mpi->stride[1]=mpi->stride[2]=mpi->width/2; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
102 if(mpi->flags&MP_IMGFLAG_SWAPPED){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
103 // I420/IYUV (Y,U,V) |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
104 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
105 mpi->planes[2]=mpi->planes[1]+(mpi->width>>1)*(mpi->height>>1); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
106 } else { |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
107 // YV12,YVU9 (Y,V,U) |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
108 mpi->planes[2]=mpi->planes[0]+mpi->width*mpi->height; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
109 mpi->planes[1]=mpi->planes[2]+(mpi->width>>1)*(mpi->height>>1); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
110 } |
5528 | 111 // clear! |
112 memset(mpi->planes[0],0,mpi->stride[0]*mpi->height); | |
113 memset(mpi->planes[1],128,mpi->stride[1]*(mpi->height>>1)); | |
114 memset(mpi->planes[2],128,mpi->stride[2]*(mpi->height>>1)); | |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
115 } else { |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
116 if(!mpi->stride[0]) mpi->stride[0]=mpi->width*mpi->bpp/8; |
5528 | 117 if(mpi->flags&MP_IMGFLAG_YUV){ |
5529 | 118 int size=mpi->bpp*mpi->width*mpi->height/8/4; |
119 unsigned int* p=mpi->planes[0]; | |
120 int i; | |
121 if(mpi->flags&MP_IMGFLAG_SWAPPED) | |
122 for(i=0;i<size;i+=4) p[i]=p[i+1]=p[i+2]=p[i+3]=0x00800080; | |
123 else | |
124 for(i=0;i<size;i+=4) p[i]=p[i+1]=p[i+2]=p[i+3]=0x80008000; | |
5528 | 125 } else |
126 memset(mpi->planes[0],0,mpi->bpp*mpi->width*mpi->height/8); | |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
127 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
128 mpi->flags|=MP_IMGFLAG_ALLOCATED; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
129 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
130 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
131 if(!(mpi->flags&MP_IMGFLAG_TYPE_DISPLAYED)){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
132 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"*** [%s] %s mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n", |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
133 vf->info->name, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
134 (mpi->type==MP_IMGTYPE_EXPORT)?"Exporting": |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
135 ((mpi->flags&MP_IMGFLAG_DIRECT)?"Direct Rendering":"Allocating"), |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
136 mpi->width,mpi->height,mpi->bpp, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
137 (mpi->flags&MP_IMGFLAG_YUV)?"YUV":"RGB", |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
138 (mpi->flags&MP_IMGFLAG_PLANAR)?"planar":"packed", |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
139 mpi->bpp*mpi->width*mpi->height/8); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
140 mpi->flags|=MP_IMGFLAG_TYPE_DISPLAYED; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
141 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
142 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
143 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
144 return mpi; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
145 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
146 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
147 //============================================================================ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
148 |
5550 | 149 vf_instance_t* vf_open_plugin(vf_info_t** filter_list, vf_instance_t* next, char *name, char *args){ |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
150 vf_instance_t* vf; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
151 int i; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
152 for(i=0;;i++){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
153 if(!filter_list[i]){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
154 mp_msg(MSGT_VFILTER,MSGL_ERR,"Couldn't find video filter '%s'\n",name); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
155 return NULL; // no such filter! |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
156 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
157 if(!strcmp(filter_list[i]->name,name)) break; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
158 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
159 vf=malloc(sizeof(vf_instance_t)); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
160 memset(vf,0,sizeof(vf_instance_t)); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
161 vf->info=filter_list[i]; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
162 vf->next=next; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
163 vf->config=vf_next_config; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
164 vf->control=vf_next_control; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
165 vf->query_format=vf_next_query_format; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
166 vf->put_image=vf_next_put_image; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
167 vf->default_caps=VFCAP_ACCEPT_STRIDE; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
168 vf->default_reqs=0; |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
169 if(vf->info->open(vf,args)>0) return vf; // Success! |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
170 free(vf); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
171 mp_msg(MSGT_VFILTER,MSGL_ERR,"Couldn't open video filter '%s'\n",name); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
172 return NULL; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
173 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
174 |
5550 | 175 vf_instance_t* vf_open_filter(vf_instance_t* next, char *name, char *args){ |
176 return vf_open_plugin(filter_list,next,name,args); | |
177 } | |
178 | |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
179 //============================================================================ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
180 |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
181 unsigned int vf_match_csp(vf_instance_t** vfp,unsigned int* list,unsigned int preferred){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
182 vf_instance_t* vf=*vfp; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
183 unsigned int* p; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
184 unsigned int best=0; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
185 int ret; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
186 if((p=list)) while(*p){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
187 ret=vf->query_format(vf,*p); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
188 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
189 if(ret&2){ best=*p; break;} // no conversion -> bingo! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
190 if(ret&1 && !best) best=*p; // best with conversion |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
191 ++p; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
192 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
193 if(best) return best; // bingo, they have common csp! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
194 // ok, then try with scale: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
195 if(vf->info == &vf_info_scale) return 0; // avoid infinite recursion! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
196 vf=vf_open_filter(vf,"scale",NULL); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
197 if(!vf) return 0; // failed to init "scale" |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
198 // try the preferred csp first: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
199 if(preferred && vf->query_format(vf,preferred)) best=preferred; else |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
200 // try the list again, now with "scaler" : |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
201 if((p=list)) while(*p){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
202 ret=vf->query_format(vf,*p); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
203 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
204 if(ret&2){ best=*p; break;} // no conversion -> bingo! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
205 if(ret&1 && !best) best=*p; // best with conversion |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
206 ++p; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
207 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
208 if(best) *vfp=vf; // else uninit vf !FIXME! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
209 return best; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
210 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
211 |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
212 int vf_next_config(struct vf_instance_s* vf, |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
213 int width, int height, int d_width, int d_height, |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
214 unsigned int voflags, unsigned int outfmt){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
215 int miss; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
216 int flags=vf->next->query_format(vf->next,outfmt); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
217 if(!flags){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
218 // hmm. colorspace mismatch!!! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
219 // let's insert the 'scale' filter, it does the job for us: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
220 vf_instance_t* vf2; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
221 if(vf->next->info==&vf_info_scale) return 0; // scale->scale |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
222 vf2=vf_open_filter(vf->next,"scale",NULL); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
223 if(!vf2) return 0; // shouldn't happen! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
224 vf->next=vf2; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
225 flags=vf->next->query_format(vf->next,outfmt); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
226 if(!flags){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
227 mp_msg(MSGT_VFILTER,MSGL_ERR,"Cannot find common colorspace, even by inserting 'scale' :(\n"); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
228 return 0; // FAIL |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
229 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
230 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
231 printf("REQ: flags=0x%X req=0x%X \n",flags,vf->default_reqs); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
232 miss=vf->default_reqs - (flags&vf->default_reqs); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
233 if(miss&VFCAP_ACCEPT_STRIDE){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
234 // vf requires stride support but vf->next doesn't support it! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
235 // let's insert the 'expand' filter, it does the job for us: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
236 vf_instance_t* vf2=vf_open_filter(vf->next,"expand",NULL); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
237 if(!vf2) return 0; // shouldn't happen! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
238 vf->next=vf2; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
239 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
240 return vf->next->config(vf->next,width,height,d_width,d_height,voflags,outfmt); |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
241 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
242 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
243 int vf_next_control(struct vf_instance_s* vf, int request, void* data){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
244 return vf->next->control(vf->next,request,data); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
245 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
246 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
247 int vf_next_query_format(struct vf_instance_s* vf, unsigned int fmt){ |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
248 int flags=vf->next->query_format(vf->next,fmt); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
249 if(flags) flags|=vf->default_caps; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5557
diff
changeset
|
250 return flags; |
5507
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
251 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
252 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
253 void vf_next_put_image(struct vf_instance_s* vf,mp_image_t *mpi){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
254 return vf->next->put_image(vf->next,mpi); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
255 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
256 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
257 //============================================================================ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
258 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
259 vf_instance_t* append_filters(vf_instance_t* last){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
260 vf_instance_t* vf; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
261 if(!vo_plugin_args) return last; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
262 while(*vo_plugin_args){ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
263 char* name=strdup(*vo_plugin_args); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
264 char* args=strchr(name,'='); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
265 if(args){args[0]=0;++args;} |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
266 mp_msg(MSGT_VFILTER,MSGL_INFO,"Opening video filter '%s' with args '%s'...\n",name,args); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
267 vf=vf_open_filter(last,name,args); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
268 if(vf) last=vf; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
269 free(name); |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
270 ++vo_plugin_args; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
271 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
272 return last; |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
273 } |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
274 |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
275 //============================================================================ |
d0d029fda134
video filter layer - written from scratch, but inspired a lot by Fredrik Kuivinen's patch
arpi
parents:
diff
changeset
|
276 |