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