Mercurial > mplayer.hg
annotate libmenu/vf_menu.c @ 8959:106f6f651467
2 new compare functions ...
author | michael |
---|---|
date | Wed, 15 Jan 2003 19:33:01 +0000 |
parents | 81dbd28ef7c0 |
children | 6b7710f78c32 |
rev | line source |
---|---|
8197 | 1 |
2 #include "../config.h" | |
3 | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <string.h> | |
7 | |
8623
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
8 #ifdef HAVE_MALLOC_H |
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
9 #include <malloc.h> |
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
10 #endif |
8197 | 11 |
12 #include "../mp_msg.h" | |
13 | |
14 #include "../libmpcodecs/img_format.h" | |
15 #include "../libmpcodecs/mp_image.h" | |
16 #include "../libmpcodecs/vf.h" | |
17 | |
18 #include "../libvo/fastmemcpy.h" | |
19 #include "../libvo/video_out.h" | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
20 #include "../libvo/font_load.h" |
8197 | 21 #include "../input/input.h" |
22 #include "../m_struct.h" | |
23 #include "menu.h" | |
24 | |
25 extern vo_functions_t* video_out; | |
26 | |
27 | |
28 static struct vf_priv_s* st_priv = NULL; | |
29 | |
30 static mp_image_t* pause_mpi = NULL; | |
31 static int go2pause = 0; | |
32 | |
33 struct vf_priv_s { | |
34 menu_t* root; | |
35 menu_t* current; | |
36 }; | |
37 | |
38 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi); | |
39 | |
40 static mp_image_t* alloc_mpi(int w, int h, uint32_t fmt) { | |
41 mp_image_t* mpi = new_mp_image(w,h); | |
42 | |
43 mp_image_setfmt(mpi,fmt); | |
44 // IF09 - allocate space for 4. plane delta info - unused | |
45 if (mpi->imgfmt == IMGFMT_IF09) | |
46 { | |
47 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8+ | |
48 mpi->chroma_width*mpi->chroma_height); | |
49 /* delta table, just for fun ;) */ | |
50 mpi->planes[3]=mpi->planes[0]+2*(mpi->chroma_width*mpi->chroma_height); | |
51 } | |
52 else | |
53 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8); | |
54 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
55 // YV12/I420/YVU9/IF09. feel free to add other planar formats here... | |
56 if(!mpi->stride[0]) mpi->stride[0]=mpi->width; | |
57 if(!mpi->stride[1]) mpi->stride[1]=mpi->stride[2]=mpi->chroma_width; | |
58 if(mpi->flags&MP_IMGFLAG_SWAPPED){ | |
59 // I420/IYUV (Y,U,V) | |
60 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height; | |
61 mpi->planes[2]=mpi->planes[1]+mpi->chroma_width*mpi->chroma_height; | |
62 } else { | |
63 // YV12,YVU9,IF09 (Y,V,U) | |
64 mpi->planes[2]=mpi->planes[0]+mpi->width*mpi->height; | |
65 mpi->planes[1]=mpi->planes[2]+mpi->chroma_width*mpi->chroma_height; | |
66 } | |
67 } else { | |
68 if(!mpi->stride[0]) mpi->stride[0]=mpi->width*mpi->bpp/8; | |
69 } | |
70 mpi->flags|=MP_IMGFLAG_ALLOCATED; | |
71 | |
72 return mpi; | |
73 } | |
74 | |
75 void vf_menu_pause_update(struct vf_instance_s* vf) { | |
76 if(pause_mpi) { | |
77 put_image(vf,pause_mpi); | |
78 // Don't draw the osd atm | |
79 //vf->control(vf,VFCTRL_DRAW_OSD,NULL); | |
80 video_out->flip_page(); | |
81 } | |
82 } | |
83 | |
84 static int cmd_filter(mp_cmd_t* cmd, int paused, struct vf_priv_s * priv) { | |
85 | |
86 switch(cmd->id) { | |
87 case MP_CMD_PAUSE : | |
88 if(!paused && !go2pause) { // Initial pause cmd -> wait the next put_image | |
89 go2pause = 1; | |
90 return 1; | |
91 } | |
92 if(go2pause == 2) // Msg resent by put_image after saving the image | |
93 go2pause = 0; | |
94 break; | |
95 case MP_CMD_MENU : { // Convert txt cmd from the users into libmenu stuff | |
96 char* arg = cmd->args[0].v.s; | |
97 | |
98 if(!priv->current->show) | |
99 priv->current->show = 1; | |
100 else if(strcmp(arg,"up") == 0) | |
101 menu_read_cmd(priv->current,MENU_CMD_UP); | |
102 else if(strcmp(arg,"down") == 0) | |
103 menu_read_cmd(priv->current,MENU_CMD_DOWN); | |
104 else if(strcmp(arg,"ok") == 0) | |
105 menu_read_cmd(priv->current,MENU_CMD_OK); | |
106 else if(strcmp(arg,"cancel") == 0) | |
107 menu_read_cmd(priv->current,MENU_CMD_CANCEL); | |
108 else if(strcmp(arg,"hide") == 0) | |
109 priv->current->show = 0; | |
110 else | |
111 printf("Unknow menu command: '%s'\n",arg); | |
112 return 1; | |
113 } | |
114 case MP_CMD_SET_MENU : { | |
115 char* menu = cmd->args[0].v.s; | |
116 menu_t* l = priv->current; | |
117 priv->current = menu_open(menu); | |
118 if(!priv->current) { | |
119 printf("Failed to open menu '%s'\n",menu); | |
120 priv->current = l; | |
121 priv->current->show = 0; | |
122 } else { | |
123 priv->current->show = 1; | |
124 priv->current->parent = l; | |
125 } | |
126 return 1; | |
127 } | |
128 } | |
129 return 0; | |
130 } | |
131 | |
132 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
133 mp_image_t *dmpi; | |
134 | |
135 if(mpi->type == MP_IMGTYPE_TEMP && (!(mpi->flags&MP_IMGFLAG_PRESERVE)) ) { | |
136 dmpi = vf_get_image(vf->next,mpi->imgfmt,mpi->type, mpi->flags, mpi->w, mpi->h); | |
137 memcpy(mpi->planes,dmpi->planes,MP_MAX_PLANES*sizeof(unsigned char*)); | |
138 memcpy(mpi->stride,dmpi->stride,MP_MAX_PLANES*sizeof(unsigned int)); | |
139 mpi->flags|=MP_IMGFLAG_DIRECT; | |
140 mpi->priv=(void*)dmpi; | |
141 return; | |
142 } | |
143 } | |
144 | |
145 static void key_cb(int code) { | |
146 menu_read_key(st_priv->current,code); | |
147 } | |
148 | |
149 | |
150 | |
151 inline static void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi) { | |
152 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
153 memcpy_pic(dmpi->planes[0],mpi->planes[0], mpi->w, mpi->h, | |
154 dmpi->stride[0],mpi->stride[0]); | |
155 memcpy_pic(dmpi->planes[1],mpi->planes[1], mpi->chroma_width, mpi->chroma_height, | |
156 dmpi->stride[1],mpi->stride[1]); | |
157 memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, | |
158 dmpi->stride[2],mpi->stride[2]); | |
159 } else { | |
160 memcpy_pic(dmpi->planes[0],mpi->planes[0], | |
161 mpi->w*(dmpi->bpp/8), mpi->h, | |
162 dmpi->stride[0],mpi->stride[0]); | |
163 } | |
164 } | |
165 | |
166 | |
167 | |
168 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
169 mp_image_t *dmpi = NULL; | |
170 | |
8251 | 171 if(vf->priv->current->show |
172 || (vf->priv->current->parent && vf->priv->current->parent->show)) { | |
8197 | 173 // Close all menu who requested it |
174 while(vf->priv->current->cl && vf->priv->current != vf->priv->root) { | |
175 menu_t* m = vf->priv->current; | |
176 vf->priv->current = m->parent ? m->parent : vf->priv->root; | |
177 menu_close(m); | |
178 } | |
179 | |
180 // Step 1 : save the picture | |
181 while(go2pause == 1) { | |
182 static char delay = 0; // Hack : wait the 2 frame to be sure to show the right picture | |
183 delay ^= 1; // after a seek | |
184 if(!delay) break; | |
185 | |
186 if(pause_mpi && (mpi->w != pause_mpi->w || mpi->h != pause_mpi->h || | |
187 mpi->imgfmt != pause_mpi->imgfmt)) { | |
188 free_mp_image(pause_mpi); | |
189 pause_mpi = NULL; | |
190 } | |
191 if(!pause_mpi) | |
192 pause_mpi = alloc_mpi(mpi->w,mpi->h,mpi->imgfmt); | |
193 copy_mpi(pause_mpi,mpi); | |
194 mp_input_queue_cmd(mp_input_parse_cmd("pause")); | |
195 go2pause = 2; | |
196 break; | |
197 } | |
198 | |
199 // Grab // Ungrab the keys | |
200 if(!mp_input_key_cb && vf->priv->current->show) | |
201 mp_input_key_cb = key_cb; | |
202 if(mp_input_key_cb && !vf->priv->current->show) | |
203 mp_input_key_cb = NULL; | |
204 | |
205 if(mpi->flags&MP_IMGFLAG_DIRECT) | |
206 dmpi = mpi->priv; | |
207 else { | |
208 dmpi = vf_get_image(vf->next,mpi->imgfmt, | |
209 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
210 mpi->w,mpi->h); | |
211 copy_mpi(dmpi,mpi); | |
212 } | |
213 menu_draw(vf->priv->current,dmpi); | |
214 | |
8244
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
215 } else { |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
216 if(mp_input_key_cb) |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
217 mp_input_key_cb = NULL; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
218 dmpi = vf_get_image(vf->next,mpi->imgfmt, |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
219 MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
220 mpi->w,mpi->h); |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
221 |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
222 dmpi->stride[0] = mpi->stride[0]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
223 dmpi->stride[1] = mpi->stride[1]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
224 dmpi->stride[2] = mpi->stride[2]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
225 dmpi->planes[0] = mpi->planes[0]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
226 dmpi->planes[1] = mpi->planes[1]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
227 dmpi->planes[2] = mpi->planes[2]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
228 dmpi->priv = mpi->priv; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
229 } |
8197 | 230 return vf_next_put_image(vf,dmpi); |
231 } | |
232 | |
233 static void uninit(vf_instance_t *vf) { | |
234 vf->priv=NULL; | |
235 if(pause_mpi) { | |
236 free_mp_image(pause_mpi); | |
237 pause_mpi = NULL; | |
238 } | |
239 } | |
240 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
241 static int config(struct vf_instance_s* vf, int width, int height, int d_width, int d_height, |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
242 unsigned int flags, unsigned int outfmt) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
243 #ifdef HAVE_FREETYPE |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
244 // here is the right place to get screen dimensions |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
245 if (force_load_font) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
246 force_load_font = 0; |
8635
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
8623
diff
changeset
|
247 load_font_ft(width,height); |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
248 } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
249 #endif |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
250 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
251 } |
8197 | 252 static int open(vf_instance_t *vf, char* args){ |
253 if(!st_priv) { | |
254 st_priv = calloc(1,sizeof(struct vf_priv_s)); | |
255 st_priv->root = st_priv->current = menu_open(args); | |
256 if(!st_priv->current) { | |
257 free(st_priv); | |
258 st_priv = NULL; | |
259 return 0; | |
260 } | |
261 mp_input_add_cmd_filter((mp_input_cmd_filter)cmd_filter,st_priv); | |
262 } | |
263 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
264 vf->config = config; |
8197 | 265 vf->put_image = put_image; |
266 vf->get_image = get_image; | |
267 vf->uninit=uninit; | |
268 vf->priv=st_priv; | |
269 go2pause=0; | |
270 | |
271 return 1; | |
272 } | |
273 | |
274 | |
275 vf_info_t vf_info_menu = { | |
276 "Internal filter for libmenu", | |
277 "menu", | |
278 "Albeu", | |
279 "", | |
280 open | |
281 }; | |
282 | |
283 | |
284 |