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