Mercurial > mplayer.hg
comparison sub/sub.c @ 32467:fbe5c829c69b
Move libvo/sub.[ch] from libvo to sub.
author | cigaes |
---|---|
date | Wed, 27 Oct 2010 17:47:13 +0000 |
parents | libvo/sub.c@9e627a1793b1 |
children | 8fa2f43cb760 |
comparison
equal
deleted
inserted
replaced
32466:9e627a1793b1 | 32467:fbe5c829c69b |
---|---|
1 /* | |
2 * This file is part of MPlayer. | |
3 * | |
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. | |
8 * | |
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. | |
13 * | |
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. | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 | |
23 #include "config.h" | |
24 #if HAVE_MALLOC_H | |
25 #include <malloc.h> | |
26 #endif | |
27 | |
28 #include "stream/stream.h" | |
29 #include "stream/stream_dvdnav.h" | |
30 #define OSD_NAV_BOX_ALPHA 0x7f | |
31 | |
32 #include "libmpcodecs/dec_teletext.h" | |
33 #include "osdep/timer.h" | |
34 | |
35 #include "mpcommon.h" | |
36 #include "mp_msg.h" | |
37 #include "help_mp.h" | |
38 #include "libvo/video_out.h" | |
39 #include "font_load.h" | |
40 #include "sub.h" | |
41 #include "spudec.h" | |
42 #include "libavutil/common.h" | |
43 | |
44 #define NEW_SPLITTING | |
45 | |
46 | |
47 // Structures needed for the new splitting algorithm. | |
48 // osd_text_t contains the single subtitle word. | |
49 // osd_text_p is used to mark the lines of subtitles | |
50 struct osd_text_t { | |
51 int osd_kerning, //kerning with the previous word | |
52 osd_length, //orizontal length inside the bbox | |
53 text_length, //number of characters | |
54 *text; //characters | |
55 struct osd_text_t *prev, | |
56 *next; | |
57 }; | |
58 | |
59 struct osd_text_p { | |
60 int value; | |
61 struct osd_text_t *ott; | |
62 struct osd_text_p *prev, | |
63 *next; | |
64 }; | |
65 //^ | |
66 | |
67 char * sub_osd_names[]={ | |
68 MSGTR_VO_SUB_Seekbar, | |
69 MSGTR_VO_SUB_Play, | |
70 MSGTR_VO_SUB_Pause, | |
71 MSGTR_VO_SUB_Stop, | |
72 MSGTR_VO_SUB_Rewind, | |
73 MSGTR_VO_SUB_Forward, | |
74 MSGTR_VO_SUB_Clock, | |
75 MSGTR_VO_SUB_Contrast, | |
76 MSGTR_VO_SUB_Saturation, | |
77 MSGTR_VO_SUB_Volume, | |
78 MSGTR_VO_SUB_Brightness, | |
79 MSGTR_VO_SUB_Hue, | |
80 MSGTR_VO_SUB_Balance | |
81 }; | |
82 char * sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", "", "" }; | |
83 | |
84 //static int vo_font_loaded=-1; | |
85 font_desc_t* vo_font=NULL; | |
86 font_desc_t* sub_font=NULL; | |
87 | |
88 unsigned char* vo_osd_text=NULL; | |
89 void* vo_osd_teletext_page=NULL; | |
90 int vo_osd_teletext_half = 0; | |
91 int vo_osd_teletext_mode=0; | |
92 int vo_osd_teletext_format=0; | |
93 int vo_osd_teletext_scale=0; | |
94 int sub_unicode=0; | |
95 int sub_utf8=0; | |
96 int sub_pos=100; | |
97 int sub_width_p=100; | |
98 int sub_alignment=2; /* 0=top, 1=center, 2=bottom */ | |
99 int sub_visibility=1; | |
100 int sub_bg_color=0; /* subtitles background color */ | |
101 int sub_bg_alpha=0; | |
102 int sub_justify=0; | |
103 #ifdef CONFIG_DVDNAV | |
104 static nav_highlight_t nav_hl; | |
105 #endif | |
106 | |
107 // return the real height of a char: | |
108 static inline int get_height(int c,int h){ | |
109 int font; | |
110 if ((font=vo_font->font[c])>=0) | |
111 if(h<vo_font->pic_a[font]->h) h=vo_font->pic_a[font]->h; | |
112 return h; | |
113 } | |
114 | |
115 // renders char to a big per-object buffer where alpha and bitmap are separated | |
116 static void draw_alpha_buf(mp_osd_obj_t* obj, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) | |
117 { | |
118 int dststride = obj->stride; | |
119 int dstskip = obj->stride-w; | |
120 int srcskip = stride-w; | |
121 int i, j; | |
122 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); | |
123 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); | |
124 unsigned char *bs = src; | |
125 unsigned char *as = srca; | |
126 | |
127 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) { | |
128 fprintf(stderr, "osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n", | |
129 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2, | |
130 x0, x0+w, y0, y0+h); | |
131 return; | |
132 } | |
133 | |
134 for (i = 0; i < h; i++) { | |
135 for (j = 0; j < w; j++, b++, a++, bs++, as++) { | |
136 if (*b < *bs) *b = *bs; | |
137 if (*as) { | |
138 if (*a == 0 || *a > *as) *a = *as; | |
139 } | |
140 } | |
141 b+= dstskip; | |
142 a+= dstskip; | |
143 bs+= srcskip; | |
144 as+= srcskip; | |
145 } | |
146 } | |
147 | |
148 // allocates/enlarges the alpha/bitmap buffer | |
149 static void alloc_buf(mp_osd_obj_t* obj) | |
150 { | |
151 int len; | |
152 if (obj->bbox.x2 < obj->bbox.x1) obj->bbox.x2 = obj->bbox.x1; | |
153 if (obj->bbox.y2 < obj->bbox.y1) obj->bbox.y2 = obj->bbox.y1; | |
154 obj->stride = ((obj->bbox.x2-obj->bbox.x1)+7)&(~7); | |
155 len = obj->stride*(obj->bbox.y2-obj->bbox.y1); | |
156 if (obj->allocated<len) { | |
157 obj->allocated = len; | |
158 free(obj->bitmap_buffer); | |
159 free(obj->alpha_buffer); | |
160 obj->bitmap_buffer = (unsigned char *)memalign(16, len); | |
161 obj->alpha_buffer = (unsigned char *)memalign(16, len); | |
162 } | |
163 memset(obj->bitmap_buffer, sub_bg_color, len); | |
164 memset(obj->alpha_buffer, sub_bg_alpha, len); | |
165 } | |
166 | |
167 // renders the buffer | |
168 inline static void vo_draw_text_from_buffer(mp_osd_obj_t* obj,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){ | |
169 if (obj->allocated > 0) { | |
170 draw_alpha(obj->bbox.x1,obj->bbox.y1, | |
171 obj->bbox.x2-obj->bbox.x1, | |
172 obj->bbox.y2-obj->bbox.y1, | |
173 obj->bitmap_buffer, | |
174 obj->alpha_buffer, | |
175 obj->stride); | |
176 } | |
177 } | |
178 | |
179 unsigned utf8_get_char(const char **str) { | |
180 const uint8_t *strp = (const uint8_t *)*str; | |
181 unsigned c; | |
182 GET_UTF8(c, *strp++, goto no_utf8;); | |
183 *str = (const char *)strp; | |
184 return c; | |
185 | |
186 no_utf8: | |
187 strp = (const uint8_t *)*str; | |
188 c = *strp++; | |
189 *str = (const char *)strp; | |
190 return c; | |
191 } | |
192 | |
193 inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){ | |
194 const char *cp=vo_osd_text; | |
195 int x=20; | |
196 int h=0; | |
197 int font; | |
198 | |
199 obj->bbox.x1=obj->x=x; | |
200 obj->bbox.y1=obj->y=10; | |
201 | |
202 while (*cp){ | |
203 uint16_t c=utf8_get_char(&cp); | |
204 render_one_glyph(vo_font, c); | |
205 x+=vo_font->width[c]+vo_font->charspace; | |
206 h=get_height(c,h); | |
207 } | |
208 | |
209 obj->bbox.x2=x-vo_font->charspace; | |
210 obj->bbox.y2=obj->bbox.y1+h; | |
211 obj->flags|=OSDFLAG_BBOX; | |
212 | |
213 alloc_buf(obj); | |
214 | |
215 cp=vo_osd_text; | |
216 x = obj->x; | |
217 while (*cp){ | |
218 uint16_t c=utf8_get_char(&cp); | |
219 if ((font=vo_font->font[c])>=0) | |
220 draw_alpha_buf(obj,x,obj->y, | |
221 vo_font->width[c], | |
222 vo_font->pic_a[font]->h, | |
223 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
224 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
225 vo_font->pic_a[font]->w); | |
226 x+=vo_font->width[c]+vo_font->charspace; | |
227 } | |
228 } | |
229 | |
230 #ifdef CONFIG_DVDNAV | |
231 void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey) { | |
232 nav_hl.sx = sx; | |
233 nav_hl.sy = sy; | |
234 nav_hl.ex = ex; | |
235 nav_hl.ey = ey; | |
236 } | |
237 | |
238 inline static void vo_update_nav (mp_osd_obj_t *obj, int dxs, int dys, int left_border, int top_border, | |
239 int right_border, int bottom_border, int orig_w, int orig_h) { | |
240 int len; | |
241 int sx = nav_hl.sx, sy = nav_hl.sy; | |
242 int ex = nav_hl.ex, ey = nav_hl.ey; | |
243 int scaled_w = dxs - left_border - right_border; | |
244 int scaled_h = dys - top_border - bottom_border; | |
245 if (scaled_w != orig_w) { | |
246 sx = sx * scaled_w / orig_w; | |
247 ex = ex * scaled_w / orig_w; | |
248 } | |
249 if (scaled_h != orig_h) { | |
250 sy = sy * scaled_h / orig_h; | |
251 ey = ey * scaled_h / orig_h; | |
252 } | |
253 sx += left_border; ex += left_border; | |
254 sy += top_border; ey += top_border; | |
255 sx = FFMIN(FFMAX(sx, 0), dxs); | |
256 ex = FFMIN(FFMAX(ex, 0), dxs); | |
257 sy = FFMIN(FFMAX(sy, 0), dys); | |
258 ey = FFMIN(FFMAX(ey, 0), dys); | |
259 | |
260 obj->bbox.x1 = obj->x = sx; | |
261 obj->bbox.y1 = obj->y = sy; | |
262 obj->bbox.x2 = ex; | |
263 obj->bbox.y2 = ey; | |
264 | |
265 alloc_buf (obj); | |
266 len = obj->stride * (obj->bbox.y2 - obj->bbox.y1); | |
267 memset (obj->bitmap_buffer, OSD_NAV_BOX_ALPHA, len); | |
268 memset (obj->alpha_buffer, OSD_NAV_BOX_ALPHA, len); | |
269 obj->flags |= OSDFLAG_BBOX | OSDFLAG_CHANGED; | |
270 if (obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1) | |
271 obj->flags |= OSDFLAG_VISIBLE; | |
272 } | |
273 #endif | |
274 | |
275 // renders char to a big per-object buffer where alpha and bitmap are separated | |
276 static void tt_draw_alpha_buf(mp_osd_obj_t* obj, int x0,int y0, int w,int h, unsigned char* src, int stride,int fg,int bg,int alpha) | |
277 { | |
278 int dststride = obj->stride; | |
279 int dstskip = obj->stride-w; | |
280 int srcskip = stride-w; | |
281 int i, j; | |
282 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); | |
283 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); | |
284 unsigned char *bs = src; | |
285 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) { | |
286 mp_msg(MSGT_OSD,MSGL_ERR,"tt osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n", | |
287 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2, | |
288 x0, x0+w, y0, y0+h); | |
289 return; | |
290 } | |
291 for (i = 0; i < h; i++) { | |
292 for (j = 0; j < w; j++, b++, a++, bs++) { | |
293 *b=(fg-bg)*(*bs)/255+bg; | |
294 *a=alpha; | |
295 } | |
296 b+= dstskip; | |
297 a+= dstskip; | |
298 bs+= srcskip; | |
299 } | |
300 } | |
301 inline static void vo_update_text_teletext(mp_osd_obj_t *obj, int dxs, int dys) | |
302 { | |
303 int h=0,w=0,i,j,font,flashon; | |
304 int wm,hm; | |
305 int color; | |
306 int x,y,x0,y0; | |
307 int cols,rows; | |
308 int wm12; | |
309 int hm13; | |
310 int hm23; | |
311 int start_row,max_rows; | |
312 int b,ax[6],ay[6],aw[6],ah[6]; | |
313 tt_char tc; | |
314 tt_char* tdp=vo_osd_teletext_page; | |
315 static const uint8_t colors[8]={1,85,150,226,70,105,179,254}; | |
316 unsigned char* buf[9]; | |
317 | |
318 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE; | |
319 if (!tdp || !vo_osd_teletext_mode) { | |
320 obj->flags&=~OSDFLAG_VISIBLE; | |
321 return; | |
322 } | |
323 flashon=(GetTimer()/1000000)%2; | |
324 switch(vo_osd_teletext_half){ | |
325 case TT_ZOOM_TOP_HALF: | |
326 start_row=0; | |
327 max_rows=VBI_ROWS/2; | |
328 break; | |
329 case TT_ZOOM_BOTTOM_HALF: | |
330 start_row=VBI_ROWS/2; | |
331 max_rows=VBI_ROWS/2; | |
332 break; | |
333 default: | |
334 start_row=0; | |
335 max_rows=VBI_ROWS; | |
336 break; | |
337 } | |
338 wm=0; | |
339 for(i=start_row;i<max_rows;i++){ | |
340 for(j=0;j<VBI_COLUMNS;j++){ | |
341 tc=tdp[i*VBI_COLUMNS+j]; | |
342 if(!tc.ctl && !tc.gfx) | |
343 { | |
344 render_one_glyph(vo_font, tc.unicode); | |
345 if (wm<vo_font->width[tc.unicode]) | |
346 wm=vo_font->width[tc.unicode]; | |
347 } | |
348 } | |
349 } | |
350 | |
351 hm=vo_font->height+1; | |
352 wm=dxs*hm*max_rows/(dys*VBI_COLUMNS); | |
353 | |
354 #ifdef CONFIG_FREETYPE | |
355 //very simple teletext font auto scaling | |
356 if(!vo_osd_teletext_scale && hm*(max_rows+1)>dys){ | |
357 osd_font_scale_factor*=1.0*(dys)/((max_rows+1)*hm); | |
358 force_load_font=1; | |
359 vo_osd_teletext_scale=osd_font_scale_factor; | |
360 obj->flags&=~OSDFLAG_VISIBLE; | |
361 return; | |
362 } | |
363 #endif | |
364 | |
365 cols=dxs/wm; | |
366 rows=dys/hm; | |
367 | |
368 if(cols>VBI_COLUMNS) | |
369 cols=VBI_COLUMNS; | |
370 if(rows>max_rows) | |
371 rows=max_rows; | |
372 w=cols*wm-vo_font->charspace; | |
373 h=rows*hm-vo_font->charspace; | |
374 | |
375 if(w<dxs) | |
376 x0=(dxs-w)/2; | |
377 else | |
378 x0=0; | |
379 if(h<dys) | |
380 y0=(dys-h)/2; | |
381 else | |
382 y0=0; | |
383 | |
384 wm12=wm>>1; | |
385 hm13=(hm+1)/3; | |
386 hm23=hm13<<1; | |
387 | |
388 for(i=0;i<6;i+=2){ | |
389 ax[i+0]=0; | |
390 aw[i+0]=wm12; | |
391 | |
392 ax[i+1]=wm12; | |
393 aw[i+1]=wm-wm12; | |
394 } | |
395 | |
396 for(i=0;i<2;i++){ | |
397 ay[i+0]=0; | |
398 ah[i+0]=hm13; | |
399 | |
400 ay[i+2]=hm13; | |
401 ah[i+2]=hm-hm23; | |
402 | |
403 ay[i+4]=hm-hm13; | |
404 ah[i+4]=hm13; | |
405 } | |
406 | |
407 obj->x = 0; | |
408 obj->y = 0; | |
409 obj->bbox.x1 = x0; | |
410 obj->bbox.y1 = y0; | |
411 obj->bbox.x2 = x0+w; | |
412 obj->bbox.y2 = y0+h; | |
413 obj->flags |= OSDFLAG_BBOX; | |
414 alloc_buf(obj); | |
415 | |
416 for(i=0;i<9;i++) | |
417 buf[i]=malloc(wm*hm); | |
418 | |
419 //alpha | |
420 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_OPAQUE_INV) | |
421 color=1; | |
422 else | |
423 color=200; | |
424 memset(buf[8],color,wm*hm); | |
425 //colors | |
426 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_TRANSPARENT){ | |
427 for(i=0;i<8;i++){ | |
428 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[i]/255),wm*hm); | |
429 } | |
430 }else{ | |
431 for(i=0;i<8;i++) | |
432 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[7-i]/255),wm*hm); | |
433 } | |
434 | |
435 y=y0; | |
436 for(i=0;i<rows;i++){ | |
437 x=x0; | |
438 for(j=0;j<cols;j++){ | |
439 tc=tdp[(i+start_row)*VBI_COLUMNS+j]; | |
440 if (tc.hidden) { x+=wm; continue;} | |
441 if(!tc.gfx || (tc.flh && !flashon)){ | |
442 /* Rendering one text character */ | |
443 draw_alpha_buf(obj,x,y,wm,hm,buf[tc.bg],buf[8],wm); | |
444 if(tc.unicode!=0x20 && tc.unicode!=0x00 && !tc.ctl && | |
445 (!tc.flh || flashon) && | |
446 (font=vo_font->font[tc.unicode])>=0 && y+hm<dys){ | |
447 tt_draw_alpha_buf(obj,x,y,vo_font->width[tc.unicode],vo_font->height, | |
448 vo_font->pic_b[font]->bmp+vo_font->start[tc.unicode]-vo_font->charspace*vo_font->pic_a[font]->w, | |
449 vo_font->pic_b[font]->w, | |
450 buf[tc.fg][0],buf[tc.bg][0],buf[8][0]); | |
451 } | |
452 }else{ | |
453 /* | |
454 Rendering one graphics character | |
455 TODO: support for separated graphics symbols (where six rectangles does not touch each other) | |
456 | |
457 +--+ +--+ 87654321 | |
458 |01| |12| -------- | |
459 |10| <= |34| <= 00100110 <= 0x26 | |
460 |01| |56| | |
461 +--+ +--+ | |
462 | |
463 (0:wm/2) (wm/2:wm-wm/2) | |
464 | |
465 ********** *********** (0:hm/3) | |
466 *** **** **** **** | |
467 *** 1 **** **** 2 **** | |
468 *** **** **** **** | |
469 ********** *********** | |
470 ********** *********** | |
471 | |
472 ********** *********** (hm/3:hm-2*hm/3) | |
473 ********** *********** | |
474 *** **** **** **** | |
475 *** 3 **** **** 4 **** | |
476 *** **** **** **** | |
477 ********** *********** | |
478 ********** *********** | |
479 ********** *********** | |
480 | |
481 ********** *********** (hm-hm/3:hm/3) | |
482 *** **** **** **** | |
483 *** 5 **** **** 6 **** | |
484 *** **** **** **** | |
485 ********** *********** | |
486 ********** *********** | |
487 | |
488 */ | |
489 if(tc.gfx>1){ //separated gfx | |
490 for(b=0;b<6;b++){ | |
491 color=(tc.unicode>>b)&1?tc.fg:tc.bg; | |
492 draw_alpha_buf(obj,x+ax[b]+1,y+ay[b]+1,aw[b]-2,ah[b]-2,buf[color],buf[8],wm); | |
493 } | |
494 //separated gfx (background borders) | |
495 //vertical | |
496 draw_alpha_buf(obj,x ,y,1,hm,buf[tc.bg],buf[8],wm); | |
497 draw_alpha_buf(obj,x+ax[1]-1,y,2,hm,buf[tc.bg],buf[8],wm); | |
498 draw_alpha_buf(obj,x+ax[1]+aw[1]-1,y,wm-ax[1]-aw[1]+1,hm,buf[tc.bg],buf[8],wm); | |
499 //horizontal | |
500 draw_alpha_buf(obj,x,y ,wm,1,buf[tc.bg],buf[8],wm); | |
501 draw_alpha_buf(obj,x,y+ay[0]+ah[0]-1,wm,2,buf[tc.bg],buf[8],wm); | |
502 draw_alpha_buf(obj,x,y+ay[2]+ah[2]-1,wm,2,buf[tc.bg],buf[8],wm); | |
503 draw_alpha_buf(obj,x,y+ay[4]+ah[4]-1,wm,hm-ay[4]-ah[4]+1,buf[tc.bg],buf[8],wm); | |
504 }else{ | |
505 for(b=0;b<6;b++){ | |
506 color=(tc.unicode>>b)&1?tc.fg:tc.bg; | |
507 draw_alpha_buf(obj,x+ax[b],y+ay[b],aw[b],ah[b],buf[color],buf[8],wm); | |
508 } | |
509 } | |
510 } | |
511 x+=wm; | |
512 } | |
513 y+=hm; | |
514 } | |
515 for(i=0;i<9;i++) | |
516 free(buf[i]); | |
517 } | |
518 | |
519 int vo_osd_progbar_type=-1; | |
520 int vo_osd_progbar_value=100; // 0..256 | |
521 | |
522 // if we have n=256 bars then OSD progbar looks like below | |
523 // | |
524 // 0 1 2 3 ... 256 <= vo_osd_progbar_value | |
525 // | | | | | | |
526 // [ === === === ... === ] | |
527 // | |
528 // the above schema is rescalled to n=elems bars | |
529 | |
530 inline static void vo_update_text_progbar(mp_osd_obj_t* obj,int dxs,int dys){ | |
531 | |
532 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE; | |
533 | |
534 if(vo_osd_progbar_type<0 || !vo_font){ | |
535 obj->flags&=~OSDFLAG_VISIBLE; | |
536 return; | |
537 } | |
538 | |
539 render_one_glyph(vo_font, OSD_PB_START); | |
540 render_one_glyph(vo_font, OSD_PB_END); | |
541 render_one_glyph(vo_font, OSD_PB_0); | |
542 render_one_glyph(vo_font, OSD_PB_1); | |
543 render_one_glyph(vo_font, vo_osd_progbar_type); | |
544 | |
545 // calculate bbox corners: | |
546 { int h=0; | |
547 int y=(dys-vo_font->height)/2; | |
548 int delimw=vo_font->width[OSD_PB_START] | |
549 +vo_font->width[OSD_PB_END] | |
550 +vo_font->charspace; | |
551 int width=(2*dxs-3*delimw)/3; | |
552 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace; | |
553 int elems=width/charw; | |
554 int x=(dxs-elems*charw-delimw)/2; | |
555 int delta = 0; | |
556 h=get_height(OSD_PB_START,h); | |
557 h=get_height(OSD_PB_END,h); | |
558 h=get_height(OSD_PB_0,h); | |
559 h=get_height(OSD_PB_1,h); | |
560 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){ | |
561 delta = vo_font->width[vo_osd_progbar_type]+vo_font->spacewidth; | |
562 delta = (x-delta > 0) ? delta : x; | |
563 h=get_height(vo_osd_progbar_type,h); | |
564 } | |
565 obj->bbox.x1=obj->x=x; | |
566 obj->bbox.y1=obj->y=y; | |
567 obj->bbox.x2=x+width+delimw; | |
568 obj->bbox.y2=y+h; //vo_font->height; | |
569 obj->flags|=OSDFLAG_BBOX; | |
570 obj->params.progbar.elems=elems; | |
571 obj->bbox.x1-=delta; // space for an icon | |
572 } | |
573 | |
574 alloc_buf(obj); | |
575 | |
576 { | |
577 int minw = vo_font->width[OSD_PB_START]+vo_font->width[OSD_PB_END]+vo_font->width[OSD_PB_0]; | |
578 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){ | |
579 minw += vo_font->width[vo_osd_progbar_type]+vo_font->charspace+vo_font->spacewidth; | |
580 } | |
581 if (obj->bbox.x2 - obj->bbox.x1 < minw) return; // space too small, don't render anything | |
582 } | |
583 | |
584 // render it: | |
585 { unsigned char *s; | |
586 unsigned char *sa; | |
587 int i,w,h,st,mark; | |
588 int x=obj->x; | |
589 int y=obj->y; | |
590 int c,font; | |
591 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace; | |
592 int elems=obj->params.progbar.elems; | |
593 | |
594 if (vo_osd_progbar_value<=0) | |
595 mark=0; | |
596 else { | |
597 int ev=vo_osd_progbar_value*elems; | |
598 mark=ev>>8; | |
599 if (ev & 0xFF) mark++; | |
600 if (mark>elems) mark=elems; | |
601 } | |
602 | |
603 | |
604 // printf("osd.progbar width=%d xpos=%d\n",width,x); | |
605 | |
606 c=vo_osd_progbar_type; | |
607 if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0) { | |
608 int xp=x-vo_font->width[c]-vo_font->spacewidth; | |
609 draw_alpha_buf(obj,(xp<0?0:xp),y, | |
610 vo_font->width[c], | |
611 vo_font->pic_a[font]->h, | |
612 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
613 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
614 vo_font->pic_a[font]->w); | |
615 } | |
616 | |
617 c=OSD_PB_START; | |
618 if ((font=vo_font->font[c])>=0) | |
619 draw_alpha_buf(obj,x,y, | |
620 vo_font->width[c], | |
621 vo_font->pic_a[font]->h, | |
622 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
623 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
624 vo_font->pic_a[font]->w); | |
625 x+=vo_font->width[c]+vo_font->charspace; | |
626 | |
627 c=OSD_PB_0; | |
628 if ((font=vo_font->font[c])>=0){ | |
629 w=vo_font->width[c]; | |
630 h=vo_font->pic_a[font]->h; | |
631 s=vo_font->pic_b[font]->bmp+vo_font->start[c]; | |
632 sa=vo_font->pic_a[font]->bmp+vo_font->start[c]; | |
633 st=vo_font->pic_a[font]->w; | |
634 if ((i=mark)) do { | |
635 draw_alpha_buf(obj,x,y,w,h,s,sa,st); | |
636 x+=charw; | |
637 } while(--i); | |
638 } | |
639 | |
640 c=OSD_PB_1; | |
641 if ((font=vo_font->font[c])>=0){ | |
642 w=vo_font->width[c]; | |
643 h=vo_font->pic_a[font]->h; | |
644 s =vo_font->pic_b[font]->bmp+vo_font->start[c]; | |
645 sa=vo_font->pic_a[font]->bmp+vo_font->start[c]; | |
646 st=vo_font->pic_a[font]->w; | |
647 if ((i=elems-mark)) do { | |
648 draw_alpha_buf(obj,x,y,w,h,s,sa,st); | |
649 x+=charw; | |
650 } while(--i); | |
651 } | |
652 | |
653 c=OSD_PB_END; | |
654 if ((font=vo_font->font[c])>=0) | |
655 draw_alpha_buf(obj,x,y, | |
656 vo_font->width[c], | |
657 vo_font->pic_a[font]->h, | |
658 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
659 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
660 vo_font->pic_a[font]->w); | |
661 // x+=vo_font->width[c]+vo_font->charspace; | |
662 | |
663 } | |
664 // vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF; | |
665 | |
666 } | |
667 | |
668 subtitle* vo_sub=NULL; | |
669 | |
670 inline static void vo_update_text_sub(mp_osd_obj_t* obj,int dxs,int dys){ | |
671 unsigned char *t; | |
672 int c,i,j,l,x,y,font,prevc,counter; | |
673 int k; | |
674 int lastStripPosition; | |
675 int xsize; | |
676 int xmin=dxs,xmax=0; | |
677 int h,lasth; | |
678 int xtblc, utblc; | |
679 | |
680 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE; | |
681 | |
682 if(!vo_sub || !sub_font || !sub_visibility || (sub_font->font[40]<0)){ | |
683 obj->flags&=~OSDFLAG_VISIBLE; | |
684 return; | |
685 } | |
686 | |
687 obj->bbox.y2=obj->y=dys; | |
688 obj->params.subtitle.lines=0; | |
689 | |
690 // too long lines divide into a smaller ones | |
691 i=k=lasth=0; | |
692 h=sub_font->height; | |
693 lastStripPosition=-1; | |
694 l=vo_sub->lines; | |
695 | |
696 { | |
697 struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp; | |
698 struct osd_text_p *otp_sub = NULL, *otp_sub_tmp, // these are used to store the whole sub text osd | |
699 *otp, *tmp_otp, *pmt; // these are used to manage sub text osd coming from a single sub line | |
700 int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter; | |
701 | |
702 while (l) { | |
703 xsize = -sub_font->charspace; | |
704 l--; | |
705 t=vo_sub->text[i++]; | |
706 char_position = 0; | |
707 char_seq = calloc(strlen(t), sizeof(int)); | |
708 | |
709 prevc = -1; | |
710 | |
711 otp = NULL; | |
712 osl = NULL; | |
713 x = 1; | |
714 | |
715 // reading the subtitle words from vo_sub->text[] | |
716 while (*t) { | |
717 if (sub_utf8) | |
718 c = utf8_get_char(&t); | |
719 else if ((c = *t++) >= 0x80 && sub_unicode) | |
720 c = (c<<8) + *t++; | |
721 if (k==MAX_UCS){ | |
722 t += strlen(t); // end here | |
723 mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n"); | |
724 } | |
725 if (!c) c++; // avoid UCS 0 | |
726 render_one_glyph(sub_font, c); | |
727 | |
728 if (c == ' ') { | |
729 struct osd_text_t *tmp_ott = calloc(1, sizeof(struct osd_text_t)); | |
730 | |
731 if (osl == NULL) { | |
732 osl = cp_ott = tmp_ott; | |
733 } else { | |
734 tmp_ott->prev = cp_ott; | |
735 cp_ott->next = tmp_ott; | |
736 tmp_ott->osd_kerning = | |
737 sub_font->charspace + sub_font->width[' ']; | |
738 cp_ott = tmp_ott; | |
739 } | |
740 tmp_ott->osd_length = xsize; | |
741 tmp_ott->text_length = char_position; | |
742 tmp_ott->text = malloc(char_position * sizeof(int)); | |
743 for (counter = 0; counter < char_position; ++counter) | |
744 tmp_ott->text[counter] = char_seq[counter]; | |
745 char_position = 0; | |
746 xsize = 0; | |
747 prevc = c; | |
748 } else { | |
749 int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_font, prevc, c); | |
750 | |
751 if (xsize + delta_xsize <= dxs) { | |
752 if (!x) x = 1; | |
753 prevc = c; | |
754 char_seq[char_position++] = c; | |
755 xsize += delta_xsize; | |
756 if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) { | |
757 if (sub_font->pic_a[font]->h > h) { | |
758 h = sub_font->pic_a[font]->h; | |
759 } | |
760 } | |
761 } else { | |
762 if (x) { | |
763 mp_msg(MSGT_OSD, MSGL_WARN, "\nSubtitle word '%s' too long!\n", t); | |
764 x = 0; | |
765 } | |
766 } | |
767 } | |
768 }// for len (all words from subtitle line read) | |
769 | |
770 // osl holds an ordered (as they appear in the lines) chain of the subtitle words | |
771 { | |
772 struct osd_text_t *tmp_ott = calloc(1, sizeof(struct osd_text_t)); | |
773 | |
774 if (osl == NULL) { | |
775 osl = cp_ott = tmp_ott; | |
776 } else { | |
777 tmp_ott->prev = cp_ott; | |
778 cp_ott->next = tmp_ott; | |
779 tmp_ott->osd_kerning = | |
780 sub_font->charspace + sub_font->width[' ']; | |
781 cp_ott = tmp_ott; | |
782 } | |
783 tmp_ott->osd_length = xsize; | |
784 tmp_ott->text_length = char_position; | |
785 tmp_ott->text = malloc(char_position * sizeof(int)); | |
786 for (counter = 0; counter < char_position; ++counter) | |
787 tmp_ott->text[counter] = char_seq[counter]; | |
788 char_position = 0; | |
789 xsize = -sub_font->charspace; | |
790 } | |
791 free(char_seq); | |
792 | |
793 if (osl != NULL) { | |
794 int value = 0, exit = 0, minimum = 0; | |
795 | |
796 // otp will contain the chain of the osd subtitle lines coming from the single vo_sub line. | |
797 otp = tmp_otp = calloc(1, sizeof(struct osd_text_p)); | |
798 tmp_otp->ott = osl; | |
799 for (tmp_ott = tmp_otp->ott; exit == 0; ) { | |
800 do { | |
801 value += tmp_ott->osd_kerning + tmp_ott->osd_length; | |
802 tmp_ott = tmp_ott->next; | |
803 } while ((tmp_ott != NULL) && (value + tmp_ott->osd_kerning + tmp_ott->osd_length <= xlimit)); | |
804 if (tmp_ott != NULL) { | |
805 struct osd_text_p *tmp = calloc(1, sizeof(struct osd_text_p)); | |
806 | |
807 tmp_otp->value = value; | |
808 tmp_otp->next = tmp; | |
809 tmp->prev = tmp_otp; | |
810 tmp_otp = tmp; | |
811 tmp_otp->ott = tmp_ott; | |
812 value = -2 * sub_font->charspace - sub_font->width[' ']; | |
813 } else { | |
814 tmp_otp->value = value; | |
815 exit = 1; | |
816 } | |
817 } | |
818 | |
819 | |
820 #ifdef NEW_SPLITTING | |
821 // minimum holds the 'sum of the differences in length among the lines', | |
822 // a measure of the evenness of the lengths of the lines | |
823 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) { | |
824 pmt = tmp_otp->next; | |
825 while (pmt != NULL) { | |
826 minimum += abs(tmp_otp->value - pmt->value); | |
827 pmt = pmt->next; | |
828 } | |
829 } | |
830 | |
831 if (otp->next != NULL) { | |
832 int mem1, mem2; | |
833 struct osd_text_p *mem, *hold; | |
834 | |
835 exit = 0; | |
836 // until the last word of a line can be moved to the beginning of following line | |
837 // reducing the 'sum of the differences in length among the lines', it is done | |
838 while (exit == 0) { | |
839 hold = NULL; | |
840 exit = 1; | |
841 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) { | |
842 pmt = tmp_otp->next; | |
843 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next); | |
844 if (pmt->value + tmp->osd_length + pmt->ott->osd_kerning <= xlimit) { | |
845 mem1 = tmp_otp->value; | |
846 mem2 = pmt->value; | |
847 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning; | |
848 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning; | |
849 | |
850 value = 0; | |
851 for (mem = otp; mem->next != NULL; mem = mem->next) { | |
852 pmt = mem->next; | |
853 while (pmt != NULL) { | |
854 value += abs(mem->value - pmt->value); | |
855 pmt = pmt->next; | |
856 } | |
857 } | |
858 if (value < minimum) { | |
859 minimum = value; | |
860 hold = tmp_otp; | |
861 exit = 0; | |
862 } | |
863 tmp_otp->value = mem1; | |
864 tmp_otp->next->value = mem2; | |
865 } | |
866 } | |
867 // merging | |
868 if (exit == 0) { | |
869 tmp_otp = hold; | |
870 pmt = tmp_otp->next; | |
871 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next); | |
872 mem1 = tmp_otp->value; | |
873 mem2 = pmt->value; | |
874 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning; | |
875 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning; | |
876 pmt->ott = tmp; | |
877 }//~merging | |
878 }//~while(exit == 0) | |
879 }//~if(otp->next!=NULL) | |
880 #endif | |
881 | |
882 // adding otp (containing splitted lines) to otp chain | |
883 if (otp_sub == NULL) { | |
884 otp_sub = otp; | |
885 for (otp_sub_tmp = otp_sub; otp_sub_tmp->next != NULL; otp_sub_tmp = otp_sub_tmp->next); | |
886 } else { | |
887 //updating ott chain | |
888 tmp = otp_sub->ott; | |
889 while (tmp->next != NULL) tmp = tmp->next; | |
890 tmp->next = otp->ott; | |
891 otp->ott->prev = tmp; | |
892 //attaching new subtitle line at the end | |
893 otp_sub_tmp->next = otp; | |
894 otp->prev = otp_sub_tmp; | |
895 do | |
896 otp_sub_tmp = otp_sub_tmp->next; | |
897 while (otp_sub_tmp->next != NULL); | |
898 } | |
899 }//~ if(osl != NULL) | |
900 } // while | |
901 | |
902 // write lines into utbl | |
903 xtblc = 0; | |
904 utblc = 0; | |
905 obj->y = dys; | |
906 obj->params.subtitle.lines = 0; | |
907 for (tmp_otp = otp_sub; tmp_otp != NULL; tmp_otp = tmp_otp->next) { | |
908 | |
909 if ((obj->params.subtitle.lines++) >= MAX_UCSLINES) | |
910 break; | |
911 | |
912 if (h > obj->y) { // out of the screen so end parsing | |
913 obj->y -= lasth - sub_font->height; // correct the y position | |
914 break; | |
915 } | |
916 xsize = tmp_otp->value; | |
917 obj->params.subtitle.xtbl[xtblc++] = (dxs - xsize) / 2; | |
918 if (xmin > (dxs - xsize) / 2) | |
919 xmin = (dxs - xsize) / 2; | |
920 if (xmax < (dxs + xsize) / 2) | |
921 xmax = (dxs + xsize) / 2; | |
922 | |
923 tmp = (tmp_otp->next == NULL) ? NULL : tmp_otp->next->ott; | |
924 for (tmp_ott = tmp_otp->ott; tmp_ott != tmp; tmp_ott = tmp_ott->next) { | |
925 for (counter = 0; counter < tmp_ott->text_length; ++counter) { | |
926 if (utblc > MAX_UCS) { | |
927 break; | |
928 } | |
929 c = tmp_ott->text[counter]; | |
930 render_one_glyph(sub_font, c); | |
931 obj->params.subtitle.utbl[utblc++] = c; | |
932 k++; | |
933 } | |
934 obj->params.subtitle.utbl[utblc++] = ' '; | |
935 } | |
936 obj->params.subtitle.utbl[utblc - 1] = 0; | |
937 obj->y -= sub_font->height; | |
938 } | |
939 if(obj->params.subtitle.lines) | |
940 obj->y = dys - ((obj->params.subtitle.lines - 1) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h); | |
941 | |
942 // free memory | |
943 if (otp_sub != NULL) { | |
944 for (tmp = otp_sub->ott; tmp->next != NULL; free(tmp->prev)) { | |
945 free(tmp->text); | |
946 tmp = tmp->next; | |
947 } | |
948 free(tmp->text); | |
949 free(tmp); | |
950 | |
951 for(pmt = otp_sub; pmt->next != NULL; free(pmt->prev)) { | |
952 pmt = pmt->next; | |
953 } | |
954 free(pmt); | |
955 } | |
956 | |
957 } | |
958 /// vertical alignment | |
959 h = dys - obj->y; | |
960 if (sub_alignment == 2) | |
961 obj->y = dys * sub_pos / 100 - h; | |
962 else if (sub_alignment == 1) | |
963 obj->y = dys * sub_pos / 100 - h / 2; | |
964 else | |
965 obj->y = dys * sub_pos / 100; | |
966 | |
967 if (obj->y < 0) | |
968 obj->y = 0; | |
969 if (obj->y > dys - h) | |
970 obj->y = dys - h; | |
971 | |
972 obj->bbox.y2 = obj->y + h; | |
973 | |
974 // calculate bbox: | |
975 if (sub_justify) xmin = 10; | |
976 obj->bbox.x1=xmin; | |
977 obj->bbox.x2=xmax; | |
978 obj->bbox.y1=obj->y; | |
979 // obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height; | |
980 obj->flags|=OSDFLAG_BBOX; | |
981 | |
982 alloc_buf(obj); | |
983 | |
984 y = obj->y; | |
985 | |
986 obj->alignment = 0; | |
987 switch(vo_sub->alignment) { | |
988 case SUB_ALIGNMENT_BOTTOMLEFT: | |
989 case SUB_ALIGNMENT_MIDDLELEFT: | |
990 case SUB_ALIGNMENT_TOPLEFT: | |
991 obj->alignment |= 0x1; | |
992 break; | |
993 case SUB_ALIGNMENT_BOTTOMRIGHT: | |
994 case SUB_ALIGNMENT_MIDDLERIGHT: | |
995 case SUB_ALIGNMENT_TOPRIGHT: | |
996 obj->alignment |= 0x2; | |
997 break; | |
998 case SUB_ALIGNMENT_BOTTOMCENTER: | |
999 case SUB_ALIGNMENT_MIDDLECENTER: | |
1000 case SUB_ALIGNMENT_TOPCENTER: | |
1001 default: | |
1002 obj->alignment |= 0x0; | |
1003 } | |
1004 | |
1005 i=j=0; | |
1006 if ((l = obj->params.subtitle.lines)) { | |
1007 for(counter = dxs; i < l; ++i) | |
1008 if (obj->params.subtitle.xtbl[i] < counter) counter = obj->params.subtitle.xtbl[i]; | |
1009 for (i = 0; i < l; ++i) { | |
1010 switch (obj->alignment&0x3) { | |
1011 case 1: | |
1012 // left | |
1013 x = counter; | |
1014 break; | |
1015 case 2: | |
1016 // right | |
1017 x = 2 * obj->params.subtitle.xtbl[i] - counter - ((obj->params.subtitle.xtbl[i] == counter) ? 0 : 1); | |
1018 break; | |
1019 default: | |
1020 //center | |
1021 x = obj->params.subtitle.xtbl[i]; | |
1022 } | |
1023 prevc = -1; | |
1024 while ((c=obj->params.subtitle.utbl[j++])){ | |
1025 x += kerning(sub_font,prevc,c); | |
1026 if ((font=sub_font->font[c])>=0) | |
1027 draw_alpha_buf(obj,x,y, | |
1028 sub_font->width[c], | |
1029 sub_font->pic_a[font]->h+y<obj->dys ? sub_font->pic_a[font]->h : obj->dys-y, | |
1030 sub_font->pic_b[font]->bmp+sub_font->start[c], | |
1031 sub_font->pic_a[font]->bmp+sub_font->start[c], | |
1032 sub_font->pic_a[font]->w); | |
1033 x+=sub_font->width[c]+sub_font->charspace; | |
1034 prevc = c; | |
1035 } | |
1036 y+=sub_font->height; | |
1037 } | |
1038 } | |
1039 | |
1040 } | |
1041 | |
1042 inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys) | |
1043 { | |
1044 unsigned int bbox[4]; | |
1045 spudec_calc_bbox(vo_spudec, dxs, dys, bbox); | |
1046 obj->bbox.x1 = bbox[0]; | |
1047 obj->bbox.x2 = bbox[1]; | |
1048 obj->bbox.y1 = bbox[2]; | |
1049 obj->bbox.y2 = bbox[3]; | |
1050 obj->flags |= OSDFLAG_BBOX; | |
1051 } | |
1052 | |
1053 inline static void vo_draw_spudec_sub(mp_osd_obj_t* obj, void (*draw_alpha)(int x0, int y0, int w, int h, unsigned char* src, unsigned char* srca, int stride)) | |
1054 { | |
1055 spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha); | |
1056 } | |
1057 | |
1058 void *vo_spudec=NULL; | |
1059 void *vo_vobsub=NULL; | |
1060 | |
1061 static int draw_alpha_init_flag=0; | |
1062 | |
1063 void vo_draw_alpha_init(void); | |
1064 | |
1065 mp_osd_obj_t* vo_osd_list=NULL; | |
1066 | |
1067 static mp_osd_obj_t* new_osd_obj(int type){ | |
1068 mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t)); | |
1069 memset(osd,0,sizeof(mp_osd_obj_t)); | |
1070 osd->next=vo_osd_list; | |
1071 vo_osd_list=osd; | |
1072 osd->type=type; | |
1073 osd->alpha_buffer = NULL; | |
1074 osd->bitmap_buffer = NULL; | |
1075 osd->allocated = -1; | |
1076 return osd; | |
1077 } | |
1078 | |
1079 void free_osd_list(void){ | |
1080 mp_osd_obj_t* obj=vo_osd_list; | |
1081 while(obj){ | |
1082 mp_osd_obj_t* next=obj->next; | |
1083 if (obj->alpha_buffer) free(obj->alpha_buffer); | |
1084 if (obj->bitmap_buffer) free(obj->bitmap_buffer); | |
1085 free(obj); | |
1086 obj=next; | |
1087 } | |
1088 vo_osd_list=NULL; | |
1089 } | |
1090 | |
1091 #define FONT_LOAD_DEFER 6 | |
1092 | |
1093 static int vo_update_osd_ext(int dxs,int dys, int left_border, int top_border, | |
1094 int right_border, int bottom_border, int orig_w, | |
1095 int orig_h) | |
1096 { | |
1097 mp_osd_obj_t* obj=vo_osd_list; | |
1098 int chg=0; | |
1099 #ifdef CONFIG_FREETYPE | |
1100 static int defer_counter = 0, prev_dxs = 0, prev_dys = 0; | |
1101 #endif | |
1102 | |
1103 #ifdef CONFIG_FREETYPE | |
1104 // here is the right place to get screen dimensions | |
1105 if (((dxs != vo_image_width) | |
1106 && (subtitle_autoscale == 2 || subtitle_autoscale == 3)) | |
1107 || ((dys != vo_image_height) | |
1108 && (subtitle_autoscale == 1 || subtitle_autoscale == 3))) | |
1109 { | |
1110 // screen dimensions changed | |
1111 // wait a while to avoid useless reloading of the font | |
1112 if (dxs == prev_dxs || dys == prev_dys) { | |
1113 defer_counter++; | |
1114 } else { | |
1115 prev_dxs = dxs; | |
1116 prev_dys = dys; | |
1117 defer_counter = 0; | |
1118 } | |
1119 if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1; | |
1120 } | |
1121 | |
1122 if (force_load_font) { | |
1123 force_load_font = 0; | |
1124 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor); | |
1125 if (sub_font_name) | |
1126 load_font_ft(dxs, dys, &sub_font, sub_font_name, text_font_scale_factor); | |
1127 else | |
1128 load_font_ft(dxs, dys, &sub_font, font_name, text_font_scale_factor); | |
1129 prev_dxs = dxs; | |
1130 prev_dys = dys; | |
1131 defer_counter = 0; | |
1132 } else { | |
1133 if (!vo_font) | |
1134 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor); | |
1135 if (!sub_font) { | |
1136 if (sub_font_name) | |
1137 load_font_ft(dxs, dys, &sub_font, sub_font_name, text_font_scale_factor); | |
1138 else | |
1139 load_font_ft(dxs, dys, &sub_font, font_name, text_font_scale_factor); | |
1140 } | |
1141 } | |
1142 #endif | |
1143 | |
1144 while(obj){ | |
1145 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){ | |
1146 int vis=obj->flags&OSDFLAG_VISIBLE; | |
1147 obj->flags&=~OSDFLAG_BBOX; | |
1148 switch(obj->type){ | |
1149 #ifdef CONFIG_DVDNAV | |
1150 case OSDTYPE_DVDNAV: | |
1151 vo_update_nav(obj,dxs,dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h); | |
1152 break; | |
1153 #endif | |
1154 case OSDTYPE_SUBTITLE: | |
1155 vo_update_text_sub(obj,dxs,dys); | |
1156 break; | |
1157 case OSDTYPE_TELETEXT: | |
1158 vo_update_text_teletext(obj,dxs,dys); | |
1159 break; | |
1160 case OSDTYPE_PROGBAR: | |
1161 vo_update_text_progbar(obj,dxs,dys); | |
1162 break; | |
1163 case OSDTYPE_SPU: | |
1164 if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){ | |
1165 vo_update_spudec_sub(obj, dxs, dys); | |
1166 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED; | |
1167 } | |
1168 else | |
1169 obj->flags&=~OSDFLAG_VISIBLE; | |
1170 break; | |
1171 case OSDTYPE_OSD: | |
1172 if(vo_font && vo_osd_text && vo_osd_text[0]){ | |
1173 vo_update_text_osd(obj,dxs,dys); // update bbox | |
1174 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED; | |
1175 } else | |
1176 obj->flags&=~OSDFLAG_VISIBLE; | |
1177 break; | |
1178 } | |
1179 // check bbox: | |
1180 if(!(obj->flags&OSDFLAG_BBOX)){ | |
1181 // we don't know, so assume the whole screen changed :( | |
1182 obj->bbox.x1=obj->bbox.y1=0; | |
1183 obj->bbox.x2=dxs; | |
1184 obj->bbox.y2=dys; | |
1185 obj->flags|=OSDFLAG_BBOX; | |
1186 } else { | |
1187 // check bbox, reduce it if it's out of bounds (corners): | |
1188 if(obj->bbox.x1<0) obj->bbox.x1=0; | |
1189 if(obj->bbox.y1<0) obj->bbox.y1=0; | |
1190 if(obj->bbox.x2>dxs) obj->bbox.x2=dxs; | |
1191 if(obj->bbox.y2>dys) obj->bbox.y2=dys; | |
1192 if(obj->flags&OSDFLAG_VISIBLE) | |
1193 // debug: | |
1194 mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n", | |
1195 obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1, | |
1196 obj->bbox.y2-obj->bbox.y1); | |
1197 } | |
1198 // check if visibility changed: | |
1199 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED; | |
1200 // remove the cause of automatic update: | |
1201 obj->dxs=dxs; obj->dys=dys; | |
1202 obj->flags&=~OSDFLAG_FORCE_UPDATE; | |
1203 } | |
1204 if(obj->flags&OSDFLAG_CHANGED){ | |
1205 chg|=1<<obj->type; | |
1206 mp_msg(MSGT_OSD,MSGL_DBG2,"OSD chg: %d V: %s pb:%d \n",obj->type,(obj->flags&OSDFLAG_VISIBLE)?"yes":"no",vo_osd_progbar_type); | |
1207 } | |
1208 obj=obj->next; | |
1209 } | |
1210 return chg; | |
1211 } | |
1212 | |
1213 int vo_update_osd(int dxs, int dys) { | |
1214 return vo_update_osd_ext(dxs, dys, 0, 0, 0, 0, dxs, dys); | |
1215 } | |
1216 | |
1217 void vo_init_osd(void){ | |
1218 if(!draw_alpha_init_flag){ | |
1219 draw_alpha_init_flag=1; | |
1220 vo_draw_alpha_init(); | |
1221 } | |
1222 if(vo_osd_list) free_osd_list(); | |
1223 // temp hack, should be moved to mplayer/mencoder later | |
1224 new_osd_obj(OSDTYPE_OSD); | |
1225 new_osd_obj(OSDTYPE_SUBTITLE); | |
1226 new_osd_obj(OSDTYPE_PROGBAR); | |
1227 new_osd_obj(OSDTYPE_SPU); | |
1228 #ifdef CONFIG_DVDNAV | |
1229 new_osd_obj(OSDTYPE_DVDNAV); | |
1230 #endif | |
1231 new_osd_obj(OSDTYPE_TELETEXT); | |
1232 #ifdef CONFIG_FREETYPE | |
1233 force_load_font = 1; | |
1234 #endif | |
1235 } | |
1236 | |
1237 int vo_osd_changed_flag=0; | |
1238 | |
1239 void vo_remove_text(int dxs,int dys,void (*remove)(int x0,int y0, int w,int h)){ | |
1240 mp_osd_obj_t* obj=vo_osd_list; | |
1241 vo_update_osd(dxs,dys); | |
1242 while(obj){ | |
1243 if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) && | |
1244 (obj->flags&OSDFLAG_OLD_BBOX)){ | |
1245 int w=obj->old_bbox.x2-obj->old_bbox.x1; | |
1246 int h=obj->old_bbox.y2-obj->old_bbox.y1; | |
1247 if(w>0 && h>0){ | |
1248 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack | |
1249 remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h); | |
1250 } | |
1251 // obj->flags&=~OSDFLAG_OLD_BBOX; | |
1252 } | |
1253 obj=obj->next; | |
1254 } | |
1255 } | |
1256 | |
1257 void vo_draw_text_ext(int dxs, int dys, int left_border, int top_border, | |
1258 int right_border, int bottom_border, int orig_w, int orig_h, | |
1259 void (*draw_alpha)(int x0, int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)) { | |
1260 mp_osd_obj_t* obj=vo_osd_list; | |
1261 vo_update_osd_ext(dxs, dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h); | |
1262 while(obj){ | |
1263 if(obj->flags&OSDFLAG_VISIBLE){ | |
1264 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack | |
1265 switch(obj->type){ | |
1266 case OSDTYPE_SPU: | |
1267 vo_draw_spudec_sub(obj, draw_alpha); // FIXME | |
1268 break; | |
1269 #ifdef CONFIG_DVDNAV | |
1270 case OSDTYPE_DVDNAV: | |
1271 #endif | |
1272 case OSDTYPE_TELETEXT: | |
1273 case OSDTYPE_OSD: | |
1274 case OSDTYPE_SUBTITLE: | |
1275 case OSDTYPE_PROGBAR: | |
1276 vo_draw_text_from_buffer(obj,draw_alpha); | |
1277 break; | |
1278 } | |
1279 obj->old_bbox=obj->bbox; | |
1280 obj->flags|=OSDFLAG_OLD_BBOX; | |
1281 } | |
1282 obj->flags&=~OSDFLAG_CHANGED; | |
1283 obj=obj->next; | |
1284 } | |
1285 } | |
1286 | |
1287 void vo_draw_text(int dxs, int dys, void (*draw_alpha)(int x0, int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)) { | |
1288 vo_draw_text_ext(dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha); | |
1289 } | |
1290 | |
1291 static int vo_osd_changed_status = 0; | |
1292 | |
1293 int vo_osd_changed(int new_value) | |
1294 { | |
1295 mp_osd_obj_t* obj=vo_osd_list; | |
1296 int ret = vo_osd_changed_status; | |
1297 vo_osd_changed_status = new_value; | |
1298 | |
1299 while(obj){ | |
1300 if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE; | |
1301 obj=obj->next; | |
1302 } | |
1303 | |
1304 return ret; | |
1305 } | |
1306 | |
1307 // BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB | |
1308 // BBBBBBBBBBBB BBBBBBBBBBBBB | |
1309 // BBBBBBB | |
1310 | |
1311 // return TRUE if we have osd in the specified rectangular area: | |
1312 int vo_osd_check_range_update(int x1,int y1,int x2,int y2){ | |
1313 mp_osd_obj_t* obj=vo_osd_list; | |
1314 while(obj){ | |
1315 if(obj->flags&OSDFLAG_VISIBLE){ | |
1316 if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) && | |
1317 (obj->bbox.y1<=y2 && obj->bbox.y2>=y1) && | |
1318 obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1 | |
1319 ) return 1; | |
1320 } | |
1321 obj=obj->next; | |
1322 } | |
1323 return 0; | |
1324 } |