Fix crash during early exit
[mplayer.git] / libvo / sub.c
blobbffb5646a37d20dfcb0c4f07332d191922feb208
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 USE_DVDNAV
12 #include "stream/stream.h"
13 #include "stream/stream_dvdnav.h"
14 #define OSD_NAV_BOX_ALPHA 0x7f
15 #endif
17 #ifdef HAVE_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 HAVE_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 USE_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 USE_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) {
231 int len;
233 obj->bbox.x1 = obj->x = nav_hl.sx;
234 obj->bbox.y1 = obj->y = nav_hl.sy;
235 obj->bbox.x2 = nav_hl.ex;
236 obj->bbox.y2 = nav_hl.ey;
238 alloc_buf (obj);
239 len = obj->stride * (obj->bbox.y2 - obj->bbox.y1);
240 memset (obj->bitmap_buffer, OSD_NAV_BOX_ALPHA, len);
241 memset (obj->alpha_buffer, OSD_NAV_BOX_ALPHA, len);
242 obj->flags |= OSDFLAG_BBOX | OSDFLAG_CHANGED;
243 if (obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1)
244 obj->flags |= OSDFLAG_VISIBLE;
246 #endif
248 #ifdef HAVE_TV_TELETEXT
249 // renders char to a big per-object buffer where alpha and bitmap are separated
250 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)
252 int dststride = obj->stride;
253 int dstskip = obj->stride-w;
254 int srcskip = stride-w;
255 int i, j;
256 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
257 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
258 unsigned char *bs = src;
259 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) {
260 mp_msg(MSGT_OSD,MSGL_ERR,"tt osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n",
261 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2,
262 x0, x0+w, y0, y0+h);
263 return;
265 for (i = 0; i < h; i++) {
266 for (j = 0; j < w; j++, b++, a++, bs++) {
267 *b=(fg-bg)*(*bs)/255+bg;
268 *a=alpha;
270 b+= dstskip;
271 a+= dstskip;
272 bs+= srcskip;
275 inline static void vo_update_text_teletext(mp_osd_obj_t *obj, int dxs, int dys)
277 int h=0,w=0,i,j,font,flashon;
278 int wm,hm;
279 int color;
280 int x,y,x0,y0;
281 int cols,rows;
282 int wm12;
283 int hm13;
284 int hm23;
285 int start_row,max_rows;
286 int b,ax[6],ay[6],aw[6],ah[6];
287 tt_char tc;
288 tt_char* tdp=vo_osd_teletext_page;
289 unsigned char colors[8]={1,85,150,226,70,105,179,254};
290 unsigned char* buf[9];
292 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
293 if (!tdp || !vo_osd_teletext_mode) {
294 obj->flags&=~OSDFLAG_VISIBLE;
295 return;
297 flashon=(GetTimer()/1000000)%2;
298 switch(vo_osd_teletext_half){
299 case TT_ZOOM_TOP_HALF:
300 start_row=0;
301 max_rows=VBI_ROWS/2;
302 break;
303 case TT_ZOOM_BOTTOM_HALF:
304 start_row=VBI_ROWS/2;
305 max_rows=VBI_ROWS/2;
306 break;
307 default:
308 start_row=0;
309 max_rows=VBI_ROWS;
310 break;
312 wm=0;
313 for(i=start_row;i<max_rows;i++){
314 for(j=0;j<VBI_COLUMNS;j++){
315 tc=tdp[i*VBI_COLUMNS+j];
316 if(!tc.ctl && !tc.gfx)
318 render_one_glyph(vo_font, tc.unicode);
319 if (wm<vo_font->width[tc.unicode])
320 wm=vo_font->width[tc.unicode];
325 hm=vo_font->height+1;
326 wm=dxs*hm*max_rows/(dys*VBI_COLUMNS);
328 //very simple teletext font auto scaling
329 if(!vo_osd_teletext_scale && hm*(max_rows+1)>dys){
330 text_font_scale_factor*=1.0*(dys)/((max_rows+1)*hm);
331 force_load_font=1;
332 vo_osd_teletext_scale=text_font_scale_factor;
333 obj->flags&=~OSDFLAG_VISIBLE;
334 return;
337 cols=dxs/wm;
338 rows=dys/hm;
340 if(cols>VBI_COLUMNS)
341 cols=VBI_COLUMNS;
342 if(rows>max_rows)
343 rows=max_rows;
344 w=cols*wm-vo_font->charspace;
345 h=rows*hm-vo_font->charspace;
347 if(w<dxs)
348 x0=(dxs-w)/2;
349 else
350 x0=0;
351 if(h<dys)
352 y0=(dys-h)/2;
353 else
354 y0=0;
356 wm12=wm>>1;
357 hm13=(hm+1)/3;
358 hm23=hm13<<1;
360 for(i=0;i<6;i+=2){
361 ax[i+0]=0;
362 aw[i+0]=wm12;
364 ax[i+1]=wm12;
365 aw[i+1]=wm-wm12;
368 for(i=0;i<2;i++){
369 ay[i+0]=0;
370 ah[i+0]=hm13;
372 ay[i+2]=hm13;
373 ah[i+2]=hm-hm23;
375 ay[i+4]=hm-hm13;
376 ah[i+4]=hm13;
379 obj->x = 0;
380 obj->y = 0;
381 obj->bbox.x1 = x0;
382 obj->bbox.y1 = y0;
383 obj->bbox.x2 = x0+w;
384 obj->bbox.y2 = y0+h;
385 obj->flags |= OSDFLAG_BBOX;
386 alloc_buf(obj);
388 for(i=0;i<9;i++)
389 buf[i]=malloc(wm*hm);
391 //alpha
392 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_OPAQUE_INV)
393 color=1;
394 else
395 color=200;
396 memset(buf[8],color,wm*hm);
397 //colors
398 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_TRANSPARENT){
399 for(i=0;i<8;i++){
400 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[i]/255),wm*hm);
402 }else{
403 for(i=0;i<8;i++)
404 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[7-i]/255),wm*hm);
407 y=y0;
408 for(i=0;i<rows;i++){
409 x=x0;
410 for(j=0;j<cols;j++){
411 tc=tdp[(i+start_row)*VBI_COLUMNS+j];
412 if (tc.hidden) { x+=wm; continue;}
413 if(!tc.gfx || (tc.flh && !flashon)){
414 /* Rendering one text character */
415 draw_alpha_buf(obj,x,y,wm,hm,buf[tc.bg],buf[8],wm);
416 if(tc.unicode!=0x20 && tc.unicode!=0x00 && !tc.ctl &&
417 (!tc.flh || flashon) &&
418 (font=vo_font->font[tc.unicode])>=0 && y+hm<dys){
419 tt_draw_alpha_buf(obj,x,y,vo_font->width[tc.unicode],vo_font->height,
420 vo_font->pic_b[font]->bmp+vo_font->start[tc.unicode]-vo_font->charspace*vo_font->pic_a[font]->w,
421 vo_font->pic_b[font]->w,
422 buf[tc.fg][0],buf[tc.bg][0],buf[8][0]);
424 }else{
426 Rendering one graphics character
427 TODO: support for separated graphics symbols (where six rectangles does not touch each other)
429 +--+ +--+ 87654321
430 |01| |12| --------
431 |10| <= |34| <= 00100110 <= 0x26
432 |01| |56|
433 +--+ +--+
435 (0:wm/2) (wm/2:wm-wm/2)
437 ********** *********** (0:hm/3)
438 *** **** **** ****
439 *** 1 **** **** 2 ****
440 *** **** **** ****
441 ********** ***********
442 ********** ***********
444 ********** *********** (hm/3:hm-2*hm/3)
445 ********** ***********
446 *** **** **** ****
447 *** 3 **** **** 4 ****
448 *** **** **** ****
449 ********** ***********
450 ********** ***********
451 ********** ***********
453 ********** *********** (hm-hm/3:hm/3)
454 *** **** **** ****
455 *** 5 **** **** 6 ****
456 *** **** **** ****
457 ********** ***********
458 ********** ***********
461 if(tc.gfx>1){ //separated gfx
462 for(b=0;b<6;b++){
463 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
464 draw_alpha_buf(obj,x+ax[b]+1,y+ay[b]+1,aw[b]-2,ah[b]-2,buf[color],buf[8],wm);
466 //separated gfx (background borders)
467 //vertical
468 draw_alpha_buf(obj,x ,y,1,hm,buf[tc.bg],buf[8],wm);
469 draw_alpha_buf(obj,x+ax[1]-1,y,2,hm,buf[tc.bg],buf[8],wm);
470 draw_alpha_buf(obj,x+ax[1]+aw[1]-1,y,wm-ax[1]-aw[1]+1,hm,buf[tc.bg],buf[8],wm);
471 //horizontal
472 draw_alpha_buf(obj,x,y ,wm,1,buf[tc.bg],buf[8],wm);
473 draw_alpha_buf(obj,x,y+ay[0]+ah[0]-1,wm,2,buf[tc.bg],buf[8],wm);
474 draw_alpha_buf(obj,x,y+ay[2]+ah[2]-1,wm,2,buf[tc.bg],buf[8],wm);
475 draw_alpha_buf(obj,x,y+ay[4]+ah[4]-1,wm,hm-ay[4]-ah[4]+1,buf[tc.bg],buf[8],wm);
476 }else{
477 for(b=0;b<6;b++){
478 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
479 draw_alpha_buf(obj,x+ax[b],y+ay[b],aw[b],ah[b],buf[color],buf[8],wm);
483 x+=wm;
485 y+=hm;
487 for(i=0;i<9;i++)
488 free(buf[i]);
490 #endif
492 int vo_osd_progbar_type=-1;
493 int vo_osd_progbar_value=100; // 0..256
495 // if we have n=256 bars then OSD progbar looks like below
497 // 0 1 2 3 ... 256 <= vo_osd_progbar_value
498 // | | | | |
499 // [ === === === ... === ]
501 // the above schema is rescalled to n=elems bars
503 inline static void vo_update_text_progbar(mp_osd_obj_t* obj,int dxs,int dys){
505 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
507 if(vo_osd_progbar_type<0 || !vo_font){
508 obj->flags&=~OSDFLAG_VISIBLE;
509 return;
512 render_one_glyph(vo_font, OSD_PB_START);
513 render_one_glyph(vo_font, OSD_PB_END);
514 render_one_glyph(vo_font, OSD_PB_0);
515 render_one_glyph(vo_font, OSD_PB_1);
516 render_one_glyph(vo_font, vo_osd_progbar_type);
518 // calculate bbox corners:
519 { int h=0;
520 int y=(dys-vo_font->height)/2;
521 int delimw=vo_font->width[OSD_PB_START]
522 +vo_font->width[OSD_PB_END]
523 +vo_font->charspace;
524 int width=(2*dxs-3*delimw)/3;
525 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
526 int elems=width/charw;
527 int x=(dxs-elems*charw-delimw)/2;
528 int delta = 0;
529 h=get_height(OSD_PB_START,h);
530 h=get_height(OSD_PB_END,h);
531 h=get_height(OSD_PB_0,h);
532 h=get_height(OSD_PB_1,h);
533 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
534 delta = vo_font->width[vo_osd_progbar_type]+vo_font->spacewidth;
535 delta = (x-delta > 0) ? delta : x;
536 h=get_height(vo_osd_progbar_type,h);
538 obj->bbox.x1=obj->x=x;
539 obj->bbox.y1=obj->y=y;
540 obj->bbox.x2=x+width+delimw;
541 obj->bbox.y2=y+h; //vo_font->height;
542 obj->flags|=OSDFLAG_BBOX;
543 obj->params.progbar.elems=elems;
544 obj->bbox.x1-=delta; // space for an icon
547 alloc_buf(obj);
550 int minw = vo_font->width[OSD_PB_START]+vo_font->width[OSD_PB_END]+vo_font->width[OSD_PB_0];
551 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
552 minw += vo_font->width[vo_osd_progbar_type]+vo_font->charspace+vo_font->spacewidth;
554 if (obj->bbox.x2 - obj->bbox.x1 < minw) return; // space too small, don't render anything
557 // render it:
558 { unsigned char *s;
559 unsigned char *sa;
560 int i,w,h,st,mark;
561 int x=obj->x;
562 int y=obj->y;
563 int c,font;
564 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
565 int elems=obj->params.progbar.elems;
567 if (vo_osd_progbar_value<=0)
568 mark=0;
569 else {
570 int ev=vo_osd_progbar_value*elems;
571 mark=ev>>8;
572 if (ev & 0xFF) mark++;
573 if (mark>elems) mark=elems;
577 // printf("osd.progbar width=%d xpos=%d\n",width,x);
579 c=vo_osd_progbar_type;
580 if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0) {
581 int xp=x-vo_font->width[c]-vo_font->spacewidth;
582 draw_alpha_buf(obj,(xp<0?0:xp),y,
583 vo_font->width[c],
584 vo_font->pic_a[font]->h,
585 vo_font->pic_b[font]->bmp+vo_font->start[c],
586 vo_font->pic_a[font]->bmp+vo_font->start[c],
587 vo_font->pic_a[font]->w);
590 c=OSD_PB_START;
591 if ((font=vo_font->font[c])>=0)
592 draw_alpha_buf(obj,x,y,
593 vo_font->width[c],
594 vo_font->pic_a[font]->h,
595 vo_font->pic_b[font]->bmp+vo_font->start[c],
596 vo_font->pic_a[font]->bmp+vo_font->start[c],
597 vo_font->pic_a[font]->w);
598 x+=vo_font->width[c]+vo_font->charspace;
600 c=OSD_PB_0;
601 if ((font=vo_font->font[c])>=0){
602 w=vo_font->width[c];
603 h=vo_font->pic_a[font]->h;
604 s=vo_font->pic_b[font]->bmp+vo_font->start[c];
605 sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
606 st=vo_font->pic_a[font]->w;
607 if ((i=mark)) do {
608 draw_alpha_buf(obj,x,y,w,h,s,sa,st);
609 x+=charw;
610 } while(--i);
613 c=OSD_PB_1;
614 if ((font=vo_font->font[c])>=0){
615 w=vo_font->width[c];
616 h=vo_font->pic_a[font]->h;
617 s =vo_font->pic_b[font]->bmp+vo_font->start[c];
618 sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
619 st=vo_font->pic_a[font]->w;
620 if ((i=elems-mark)) do {
621 draw_alpha_buf(obj,x,y,w,h,s,sa,st);
622 x+=charw;
623 } while(--i);
626 c=OSD_PB_END;
627 if ((font=vo_font->font[c])>=0)
628 draw_alpha_buf(obj,x,y,
629 vo_font->width[c],
630 vo_font->pic_a[font]->h,
631 vo_font->pic_b[font]->bmp+vo_font->start[c],
632 vo_font->pic_a[font]->bmp+vo_font->start[c],
633 vo_font->pic_a[font]->w);
634 // x+=vo_font->width[c]+vo_font->charspace;
637 // vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF;
641 subtitle* vo_sub=NULL;
643 // vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride))
645 inline static void vo_update_text_sub(struct osd_state *osd, mp_osd_obj_t* obj,int dxs,int dys){
646 unsigned char *t;
647 int c,i,j,l,x,y,font,prevc,counter;
648 int k;
649 int lastStripPosition;
650 int xsize;
651 int xmin=dxs,xmax=0;
652 int h,lasth;
653 int xtblc, utblc;
654 struct font_desc *sub_font = osd->sub_font;
656 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
658 if(!vo_sub || !osd->sub_font || !sub_visibility || (sub_font->font[40]<0)){
659 obj->flags&=~OSDFLAG_VISIBLE;
660 return;
663 obj->bbox.y2=obj->y=dys;
664 obj->params.subtitle.lines=0;
666 // too long lines divide into a smaller ones
667 i=k=lasth=0;
668 h=sub_font->height;
669 lastStripPosition=-1;
670 l=vo_sub->lines;
673 struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp;
674 struct osd_text_p *otp_sub = NULL, *otp_sub_tmp, // these are used to store the whole sub text osd
675 *otp, *tmp_otp, *pmt; // these are used to manage sub text osd coming from a single sub line
676 int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
678 while (l) {
679 xsize = -sub_font->charspace;
680 l--;
681 t=vo_sub->text[i++];
682 char_position = 0;
683 char_seq = calloc(strlen(t), sizeof(int));
685 prevc = -1;
687 otp = NULL;
688 osl = NULL;
689 x = 1;
691 // reading the subtitle words from vo_sub->text[]
692 while (*t) {
693 if (sub_utf8)
694 c = utf8_get_char(&t);
695 else if ((c = *t++) >= 0x80 && sub_unicode)
696 c = (c<<8) + *t++;
697 if (k==MAX_UCS){
698 t += strlen(t); // end here
699 mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n");
701 if (!c) c++; // avoid UCS 0
702 render_one_glyph(sub_font, c);
704 if (c == ' ') {
705 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
707 if (osl == NULL) {
708 osl = cp_ott = tmp_ott;
709 } else {
710 tmp_ott->prev = cp_ott;
711 cp_ott->next = tmp_ott;
712 tmp_ott->osd_kerning =
713 sub_font->charspace + sub_font->width[' '];
714 cp_ott = tmp_ott;
716 tmp_ott->osd_length = xsize;
717 tmp_ott->text_length = char_position;
718 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
719 for (counter = 0; counter < char_position; ++counter)
720 tmp_ott->text[counter] = char_seq[counter];
721 char_position = 0;
722 xsize = 0;
723 prevc = c;
724 } else {
725 int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_font, prevc, c);
727 if (xsize + delta_xsize <= dxs) {
728 if (!x) x = 1;
729 prevc = c;
730 char_seq[char_position++] = c;
731 xsize += delta_xsize;
732 if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) {
733 if (sub_font->pic_a[font]->h > h) {
734 h = sub_font->pic_a[font]->h;
737 } else {
738 if (x) {
739 mp_msg(MSGT_OSD, MSGL_WARN, "\nSubtitle word '%s' too long!\n", t);
740 x = 0;
744 }// for len (all words from subtitle line read)
746 // osl holds an ordered (as they appear in the lines) chain of the subtitle words
748 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
750 if (osl == NULL) {
751 osl = cp_ott = tmp_ott;
752 } else {
753 tmp_ott->prev = cp_ott;
754 cp_ott->next = tmp_ott;
755 tmp_ott->osd_kerning =
756 sub_font->charspace + sub_font->width[' '];
757 cp_ott = tmp_ott;
759 tmp_ott->osd_length = xsize;
760 tmp_ott->text_length = char_position;
761 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
762 for (counter = 0; counter < char_position; ++counter)
763 tmp_ott->text[counter] = char_seq[counter];
764 char_position = 0;
765 xsize = -sub_font->charspace;
767 free(char_seq);
769 if (osl != NULL) {
770 int value = 0, exit = 0, minimum = 0;
772 // otp will contain the chain of the osd subtitle lines coming from the single vo_sub line.
773 otp = tmp_otp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
774 tmp_otp->ott = osl;
775 for (tmp_ott = tmp_otp->ott; exit == 0; ) {
776 do {
777 value += tmp_ott->osd_kerning + tmp_ott->osd_length;
778 tmp_ott = tmp_ott->next;
779 } while ((tmp_ott != NULL) && (value + tmp_ott->osd_kerning + tmp_ott->osd_length <= xlimit));
780 if (tmp_ott != NULL) {
781 struct osd_text_p *tmp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
783 tmp_otp->value = value;
784 tmp_otp->next = tmp;
785 tmp->prev = tmp_otp;
786 tmp_otp = tmp;
787 tmp_otp->ott = tmp_ott;
788 value = -2 * sub_font->charspace - sub_font->width[' '];
789 } else {
790 tmp_otp->value = value;
791 exit = 1;
796 #ifdef NEW_SPLITTING
797 // minimum holds the 'sum of the differences in length among the lines',
798 // a measure of the evenness of the lengths of the lines
799 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
800 pmt = tmp_otp->next;
801 while (pmt != NULL) {
802 minimum += abs(tmp_otp->value - pmt->value);
803 pmt = pmt->next;
807 if (otp->next != NULL) {
808 int mem1, mem2;
809 struct osd_text_p *mem, *hold;
811 exit = 0;
812 // until the last word of a line can be moved to the beginning of following line
813 // reducing the 'sum of the differences in length among the lines', it is done
814 while (exit == 0) {
815 hold = NULL;
816 exit = 1;
817 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
818 pmt = tmp_otp->next;
819 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
820 if (pmt->value + tmp->osd_length + pmt->ott->osd_kerning <= xlimit) {
821 mem1 = tmp_otp->value;
822 mem2 = pmt->value;
823 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
824 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
826 value = 0;
827 for (mem = otp; mem->next != NULL; mem = mem->next) {
828 pmt = mem->next;
829 while (pmt != NULL) {
830 value += abs(mem->value - pmt->value);
831 pmt = pmt->next;
834 if (value < minimum) {
835 minimum = value;
836 hold = tmp_otp;
837 exit = 0;
839 tmp_otp->value = mem1;
840 tmp_otp->next->value = mem2;
843 // merging
844 if (exit == 0) {
845 tmp_otp = hold;
846 pmt = tmp_otp->next;
847 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
848 mem1 = tmp_otp->value;
849 mem2 = pmt->value;
850 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
851 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
852 pmt->ott = tmp;
853 }//~merging
854 }//~while(exit == 0)
855 }//~if(otp->next!=NULL)
856 #endif
858 // adding otp (containing splitted lines) to otp chain
859 if (otp_sub == NULL) {
860 otp_sub = otp;
861 for (otp_sub_tmp = otp_sub; otp_sub_tmp->next != NULL; otp_sub_tmp = otp_sub_tmp->next);
862 } else {
863 //updating ott chain
864 tmp = otp_sub->ott;
865 while (tmp->next != NULL) tmp = tmp->next;
866 tmp->next = otp->ott;
867 otp->ott->prev = tmp;
868 //attaching new subtitle line at the end
869 otp_sub_tmp->next = otp;
870 otp->prev = otp_sub_tmp;
872 otp_sub_tmp = otp_sub_tmp->next;
873 while (otp_sub_tmp->next != NULL);
875 }//~ if(osl != NULL)
876 } // while
878 // write lines into utbl
879 xtblc = 0;
880 utblc = 0;
881 obj->y = dys;
882 obj->params.subtitle.lines = 0;
883 for (tmp_otp = otp_sub; tmp_otp != NULL; tmp_otp = tmp_otp->next) {
885 if ((obj->params.subtitle.lines++) >= MAX_UCSLINES)
886 break;
888 if (h > obj->y) { // out of the screen so end parsing
889 obj->y -= lasth - sub_font->height; // correct the y position
890 break;
892 xsize = tmp_otp->value;
893 obj->params.subtitle.xtbl[xtblc++] = (dxs - xsize) / 2;
894 if (xmin > (dxs - xsize) / 2)
895 xmin = (dxs - xsize) / 2;
896 if (xmax < (dxs + xsize) / 2)
897 xmax = (dxs + xsize) / 2;
899 tmp = (tmp_otp->next == NULL) ? NULL : tmp_otp->next->ott;
900 for (tmp_ott = tmp_otp->ott; tmp_ott != tmp; tmp_ott = tmp_ott->next) {
901 for (counter = 0; counter < tmp_ott->text_length; ++counter) {
902 if (utblc > MAX_UCS) {
903 break;
905 c = tmp_ott->text[counter];
906 render_one_glyph(sub_font, c);
907 obj->params.subtitle.utbl[utblc++] = c;
908 k++;
910 obj->params.subtitle.utbl[utblc++] = ' ';
912 obj->params.subtitle.utbl[utblc - 1] = 0;
913 obj->y -= sub_font->height;
915 if(obj->params.subtitle.lines)
916 obj->y = dys - ((obj->params.subtitle.lines - 1) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h);
918 // free memory
919 if (otp_sub != NULL) {
920 for (tmp = otp_sub->ott; tmp->next != NULL; free(tmp->prev)) {
921 free(tmp->text);
922 tmp = tmp->next;
924 free(tmp->text);
925 free(tmp);
927 for(pmt = otp_sub; pmt->next != NULL; free(pmt->prev)) {
928 pmt = pmt->next;
930 free(pmt);
934 /// vertical alignment
935 h = dys - obj->y;
936 if (sub_alignment == 2)
937 obj->y = dys * sub_pos / 100 - h;
938 else if (sub_alignment == 1)
939 obj->y = dys * sub_pos / 100 - h / 2;
940 else
941 obj->y = dys * sub_pos / 100;
943 if (obj->y < 0)
944 obj->y = 0;
945 if (obj->y > dys - h)
946 obj->y = dys - h;
948 obj->bbox.y2 = obj->y + h;
950 // calculate bbox:
951 if (sub_justify) xmin = 10;
952 obj->bbox.x1=xmin;
953 obj->bbox.x2=xmax;
954 obj->bbox.y1=obj->y;
955 // obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height;
956 obj->flags|=OSDFLAG_BBOX;
958 alloc_buf(obj);
960 y = obj->y;
962 obj->alignment = 0;
963 switch(vo_sub->alignment) {
964 case SUB_ALIGNMENT_BOTTOMLEFT:
965 case SUB_ALIGNMENT_MIDDLELEFT:
966 case SUB_ALIGNMENT_TOPLEFT:
967 obj->alignment |= 0x1;
968 break;
969 case SUB_ALIGNMENT_BOTTOMRIGHT:
970 case SUB_ALIGNMENT_MIDDLERIGHT:
971 case SUB_ALIGNMENT_TOPRIGHT:
972 obj->alignment |= 0x2;
973 break;
974 case SUB_ALIGNMENT_BOTTOMCENTER:
975 case SUB_ALIGNMENT_MIDDLECENTER:
976 case SUB_ALIGNMENT_TOPCENTER:
977 default:
978 obj->alignment |= 0x0;
981 i=j=0;
982 if ((l = obj->params.subtitle.lines)) {
983 for(counter = dxs; i < l; ++i)
984 if (obj->params.subtitle.xtbl[i] < counter) counter = obj->params.subtitle.xtbl[i];
985 for (i = 0; i < l; ++i) {
986 switch (obj->alignment&0x3) {
987 case 1:
988 // left
989 x = counter;
990 break;
991 case 2:
992 // right
993 x = 2 * obj->params.subtitle.xtbl[i] - counter - ((obj->params.subtitle.xtbl[i] == counter) ? 0 : 1);
994 break;
995 default:
996 //center
997 x = obj->params.subtitle.xtbl[i];
999 prevc = -1;
1000 while ((c=obj->params.subtitle.utbl[j++])){
1001 x += kerning(sub_font,prevc,c);
1002 if ((font=sub_font->font[c])>=0)
1003 draw_alpha_buf(obj,x,y,
1004 sub_font->width[c],
1005 sub_font->pic_a[font]->h+y<obj->dys ? sub_font->pic_a[font]->h : obj->dys-y,
1006 sub_font->pic_b[font]->bmp+sub_font->start[c],
1007 sub_font->pic_a[font]->bmp+sub_font->start[c],
1008 sub_font->pic_a[font]->w);
1009 x+=sub_font->width[c]+sub_font->charspace;
1010 prevc = c;
1012 y+=sub_font->height;
1018 inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys)
1020 unsigned int bbox[4];
1021 spudec_calc_bbox(vo_spudec, dxs, dys, bbox);
1022 obj->bbox.x1 = bbox[0];
1023 obj->bbox.x2 = bbox[1];
1024 obj->bbox.y1 = bbox[2];
1025 obj->bbox.y2 = bbox[3];
1026 obj->flags |= OSDFLAG_BBOX;
1029 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)
1031 spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha, ctx);
1034 void *vo_spudec=NULL;
1035 void *vo_vobsub=NULL;
1037 static int draw_alpha_init_flag=0;
1039 extern void vo_draw_alpha_init(void);
1041 mp_osd_obj_t* vo_osd_list=NULL;
1043 static mp_osd_obj_t* new_osd_obj(int type){
1044 mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t));
1045 memset(osd,0,sizeof(mp_osd_obj_t));
1046 osd->next=vo_osd_list;
1047 vo_osd_list=osd;
1048 osd->type=type;
1049 osd->alpha_buffer = NULL;
1050 osd->bitmap_buffer = NULL;
1051 osd->allocated = -1;
1052 return osd;
1055 void osd_free(struct osd_state *osd)
1057 mp_osd_obj_t* obj=vo_osd_list;
1058 while(obj){
1059 mp_osd_obj_t* next=obj->next;
1060 if (obj->alpha_buffer) free(obj->alpha_buffer);
1061 if (obj->bitmap_buffer) free(obj->bitmap_buffer);
1062 free(obj);
1063 obj=next;
1065 vo_osd_list=NULL;
1066 talloc_free(osd);
1069 #define FONT_LOAD_DEFER 6
1071 int osd_update(struct osd_state *osd, int dxs, int dys)
1073 mp_osd_obj_t* obj=vo_osd_list;
1074 int chg=0;
1075 #ifdef HAVE_FREETYPE
1076 static int defer_counter = 0, prev_dxs = 0, prev_dys = 0;
1077 #endif
1079 #ifdef HAVE_FREETYPE
1080 // here is the right place to get screen dimensions
1081 if (((dxs != vo_image_width)
1082 && (subtitle_autoscale == 2 || subtitle_autoscale == 3))
1083 || ((dys != vo_image_height)
1084 && (subtitle_autoscale == 1 || subtitle_autoscale == 3)))
1086 // screen dimensions changed
1087 // wait a while to avoid useless reloading of the font
1088 if (dxs == prev_dxs || dys == prev_dys) {
1089 defer_counter++;
1090 } else {
1091 prev_dxs = dxs;
1092 prev_dys = dys;
1093 defer_counter = 0;
1095 if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1;
1098 if (force_load_font) {
1099 force_load_font = 0;
1100 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1101 if (sub_font_name)
1102 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1103 else
1104 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1105 prev_dxs = dxs;
1106 prev_dys = dys;
1107 defer_counter = 0;
1108 } else {
1109 if (!vo_font)
1110 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1111 if (!osd->sub_font) {
1112 if (sub_font_name)
1113 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1114 else
1115 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1118 #endif
1120 while(obj){
1121 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){
1122 int vis=obj->flags&OSDFLAG_VISIBLE;
1123 obj->flags&=~OSDFLAG_BBOX;
1124 switch(obj->type){
1125 #ifdef USE_DVDNAV
1126 case OSDTYPE_DVDNAV:
1127 vo_update_nav(obj,dxs,dys);
1128 break;
1129 #endif
1130 case OSDTYPE_SUBTITLE:
1131 vo_update_text_sub(osd, obj,dxs,dys);
1132 break;
1133 #ifdef HAVE_TV_TELETEXT
1134 case OSDTYPE_TELETEXT:
1135 vo_update_text_teletext(obj,dxs,dys);
1136 break;
1137 #endif
1138 case OSDTYPE_PROGBAR:
1139 vo_update_text_progbar(obj,dxs,dys);
1140 break;
1141 case OSDTYPE_SPU:
1142 if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){
1143 vo_update_spudec_sub(obj, dxs, dys);
1144 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1146 else
1147 obj->flags&=~OSDFLAG_VISIBLE;
1148 break;
1149 case OSDTYPE_OSD:
1150 if(vo_font && osd->osd_text[0]){
1151 vo_update_text_osd(osd, obj, dxs, dys); // update bbox
1152 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1153 } else
1154 obj->flags&=~OSDFLAG_VISIBLE;
1155 break;
1157 // check bbox:
1158 if(!(obj->flags&OSDFLAG_BBOX)){
1159 // we don't know, so assume the whole screen changed :(
1160 obj->bbox.x1=obj->bbox.y1=0;
1161 obj->bbox.x2=dxs;
1162 obj->bbox.y2=dys;
1163 obj->flags|=OSDFLAG_BBOX;
1164 } else {
1165 // check bbox, reduce it if it's out of bounds (corners):
1166 if(obj->bbox.x1<0) obj->bbox.x1=0;
1167 if(obj->bbox.y1<0) obj->bbox.y1=0;
1168 if(obj->bbox.x2>dxs) obj->bbox.x2=dxs;
1169 if(obj->bbox.y2>dys) obj->bbox.y2=dys;
1170 if(obj->flags&OSDFLAG_VISIBLE)
1171 // debug:
1172 mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n",
1173 obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1,
1174 obj->bbox.y2-obj->bbox.y1);
1176 // check if visibility changed:
1177 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED;
1178 // remove the cause of automatic update:
1179 obj->dxs=dxs; obj->dys=dys;
1180 obj->flags&=~OSDFLAG_FORCE_UPDATE;
1182 if(obj->flags&OSDFLAG_CHANGED){
1183 chg|=1<<obj->type;
1184 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);
1186 obj=obj->next;
1188 return chg;
1191 struct osd_state *osd_create(void)
1193 struct osd_state *osd = talloc_zero(NULL, struct osd_state);
1194 *osd = (struct osd_state){
1196 if(!draw_alpha_init_flag){
1197 draw_alpha_init_flag=1;
1198 vo_draw_alpha_init();
1200 // temp hack, should be moved to mplayer/mencoder later
1201 new_osd_obj(OSDTYPE_OSD);
1202 new_osd_obj(OSDTYPE_SUBTITLE);
1203 new_osd_obj(OSDTYPE_PROGBAR);
1204 new_osd_obj(OSDTYPE_SPU);
1205 #ifdef USE_DVDNAV
1206 new_osd_obj(OSDTYPE_DVDNAV);
1207 #endif
1208 #if HAVE_TV_TELETEXT
1209 new_osd_obj(OSDTYPE_TELETEXT);
1210 #endif
1211 #ifdef HAVE_FREETYPE
1212 force_load_font = 1;
1213 #endif
1214 return osd;
1217 int vo_osd_changed_flag=0;
1219 void osd_remove_text(struct osd_state *osd, int dxs, int dys,
1220 void (*remove)(int x0, int y0, int w, int h))
1222 mp_osd_obj_t* obj=vo_osd_list;
1223 osd_update(osd, dxs, dys);
1224 while(obj){
1225 if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) &&
1226 (obj->flags&OSDFLAG_OLD_BBOX)){
1227 int w=obj->old_bbox.x2-obj->old_bbox.x1;
1228 int h=obj->old_bbox.y2-obj->old_bbox.y1;
1229 if(w>0 && h>0){
1230 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1231 remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h);
1233 // obj->flags&=~OSDFLAG_OLD_BBOX;
1235 obj=obj->next;
1239 void osd_draw_text(struct osd_state *osd, int dxs, int dys,
1240 void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h,
1241 unsigned char* src, unsigned char *srca,
1242 int stride),
1243 void *ctx)
1245 mp_osd_obj_t* obj=vo_osd_list;
1246 osd_update(osd, dxs, dys);
1247 while(obj){
1248 if(obj->flags&OSDFLAG_VISIBLE){
1249 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1250 switch(obj->type){
1251 case OSDTYPE_SPU:
1252 vo_draw_spudec_sub(obj, draw_alpha, ctx); // FIXME
1253 break;
1254 #ifdef USE_DVDNAV
1255 case OSDTYPE_DVDNAV:
1256 #endif
1257 #ifdef HAVE_TV_TELETEXT
1258 case OSDTYPE_TELETEXT:
1259 #endif
1260 case OSDTYPE_OSD:
1261 case OSDTYPE_SUBTITLE:
1262 case OSDTYPE_PROGBAR:
1263 vo_draw_text_from_buffer(obj, draw_alpha, ctx);
1264 break;
1266 obj->old_bbox=obj->bbox;
1267 obj->flags|=OSDFLAG_OLD_BBOX;
1269 obj->flags&=~OSDFLAG_CHANGED;
1270 obj=obj->next;
1274 static int vo_osd_changed_status = 0;
1276 int vo_osd_changed(int new_value)
1278 mp_osd_obj_t* obj=vo_osd_list;
1279 int ret = vo_osd_changed_status;
1280 vo_osd_changed_status = new_value;
1282 while(obj){
1283 if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
1284 obj=obj->next;
1287 return ret;
1290 // BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB
1291 // BBBBBBBBBBBB BBBBBBBBBBBBB
1292 // BBBBBBB
1294 // return TRUE if we have osd in the specified rectangular area:
1295 int vo_osd_check_range_update(int x1,int y1,int x2,int y2){
1296 mp_osd_obj_t* obj=vo_osd_list;
1297 while(obj){
1298 if(obj->flags&OSDFLAG_VISIBLE){
1299 if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) &&
1300 (obj->bbox.y1<=y2 && obj->bbox.y2>=y1) &&
1301 obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1
1302 ) return 1;
1304 obj=obj->next;
1306 return 0;