core: Better -nocorrect-pts pause and filter-added frames handling
[mplayer/glamo.git] / libvo / sub.c
blob423a3f84d9c5c3f4673900d31a346e551ac894dc
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) {
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 CONFIG_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 inline static void vo_update_text_sub(struct osd_state *osd, mp_osd_obj_t* obj,int dxs,int dys){
644 unsigned char *t;
645 int c,i,j,l,x,y,font,prevc,counter;
646 int k;
647 int lastStripPosition;
648 int xsize;
649 int xmin=dxs,xmax=0;
650 int h,lasth;
651 int xtblc, utblc;
652 struct font_desc *sub_font = osd->sub_font;
654 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
656 if(!vo_sub || !osd->sub_font || !sub_visibility || (sub_font->font[40]<0)){
657 obj->flags&=~OSDFLAG_VISIBLE;
658 return;
661 obj->bbox.y2=obj->y=dys;
662 obj->params.subtitle.lines=0;
664 // too long lines divide into a smaller ones
665 i=k=lasth=0;
666 h=sub_font->height;
667 lastStripPosition=-1;
668 l=vo_sub->lines;
671 struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp;
672 struct osd_text_p *otp_sub = NULL, *otp_sub_tmp, // these are used to store the whole sub text osd
673 *otp, *tmp_otp, *pmt; // these are used to manage sub text osd coming from a single sub line
674 int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
676 while (l) {
677 xsize = -sub_font->charspace;
678 l--;
679 t=vo_sub->text[i++];
680 char_position = 0;
681 char_seq = calloc(strlen(t), sizeof(int));
683 prevc = -1;
685 otp = NULL;
686 osl = NULL;
687 x = 1;
689 // reading the subtitle words from vo_sub->text[]
690 while (*t) {
691 if (sub_utf8)
692 c = utf8_get_char(&t);
693 else if ((c = *t++) >= 0x80 && sub_unicode)
694 c = (c<<8) + *t++;
695 if (k==MAX_UCS){
696 t += strlen(t); // end here
697 mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n");
699 if (!c) c++; // avoid UCS 0
700 render_one_glyph(sub_font, c);
702 if (c == ' ') {
703 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
705 if (osl == NULL) {
706 osl = cp_ott = tmp_ott;
707 } else {
708 tmp_ott->prev = cp_ott;
709 cp_ott->next = tmp_ott;
710 tmp_ott->osd_kerning =
711 sub_font->charspace + sub_font->width[' '];
712 cp_ott = tmp_ott;
714 tmp_ott->osd_length = xsize;
715 tmp_ott->text_length = char_position;
716 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
717 for (counter = 0; counter < char_position; ++counter)
718 tmp_ott->text[counter] = char_seq[counter];
719 char_position = 0;
720 xsize = 0;
721 prevc = c;
722 } else {
723 int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_font, prevc, c);
725 if (xsize + delta_xsize <= dxs) {
726 if (!x) x = 1;
727 prevc = c;
728 char_seq[char_position++] = c;
729 xsize += delta_xsize;
730 if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) {
731 if (sub_font->pic_a[font]->h > h) {
732 h = sub_font->pic_a[font]->h;
735 } else {
736 if (x) {
737 mp_msg(MSGT_OSD, MSGL_WARN, "\nSubtitle word '%s' too long!\n", t);
738 x = 0;
742 }// for len (all words from subtitle line read)
744 // osl holds an ordered (as they appear in the lines) chain of the subtitle words
746 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
748 if (osl == NULL) {
749 osl = cp_ott = tmp_ott;
750 } else {
751 tmp_ott->prev = cp_ott;
752 cp_ott->next = tmp_ott;
753 tmp_ott->osd_kerning =
754 sub_font->charspace + sub_font->width[' '];
755 cp_ott = tmp_ott;
757 tmp_ott->osd_length = xsize;
758 tmp_ott->text_length = char_position;
759 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
760 for (counter = 0; counter < char_position; ++counter)
761 tmp_ott->text[counter] = char_seq[counter];
762 char_position = 0;
763 xsize = -sub_font->charspace;
765 free(char_seq);
767 if (osl != NULL) {
768 int value = 0, exit = 0, minimum = 0;
770 // otp will contain the chain of the osd subtitle lines coming from the single vo_sub line.
771 otp = tmp_otp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
772 tmp_otp->ott = osl;
773 for (tmp_ott = tmp_otp->ott; exit == 0; ) {
774 do {
775 value += tmp_ott->osd_kerning + tmp_ott->osd_length;
776 tmp_ott = tmp_ott->next;
777 } while ((tmp_ott != NULL) && (value + tmp_ott->osd_kerning + tmp_ott->osd_length <= xlimit));
778 if (tmp_ott != NULL) {
779 struct osd_text_p *tmp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
781 tmp_otp->value = value;
782 tmp_otp->next = tmp;
783 tmp->prev = tmp_otp;
784 tmp_otp = tmp;
785 tmp_otp->ott = tmp_ott;
786 value = -2 * sub_font->charspace - sub_font->width[' '];
787 } else {
788 tmp_otp->value = value;
789 exit = 1;
794 #ifdef NEW_SPLITTING
795 // minimum holds the 'sum of the differences in length among the lines',
796 // a measure of the evenness of the lengths of the lines
797 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
798 pmt = tmp_otp->next;
799 while (pmt != NULL) {
800 minimum += abs(tmp_otp->value - pmt->value);
801 pmt = pmt->next;
805 if (otp->next != NULL) {
806 int mem1, mem2;
807 struct osd_text_p *mem, *hold;
809 exit = 0;
810 // until the last word of a line can be moved to the beginning of following line
811 // reducing the 'sum of the differences in length among the lines', it is done
812 while (exit == 0) {
813 hold = NULL;
814 exit = 1;
815 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
816 pmt = tmp_otp->next;
817 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
818 if (pmt->value + tmp->osd_length + pmt->ott->osd_kerning <= xlimit) {
819 mem1 = tmp_otp->value;
820 mem2 = pmt->value;
821 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
822 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
824 value = 0;
825 for (mem = otp; mem->next != NULL; mem = mem->next) {
826 pmt = mem->next;
827 while (pmt != NULL) {
828 value += abs(mem->value - pmt->value);
829 pmt = pmt->next;
832 if (value < minimum) {
833 minimum = value;
834 hold = tmp_otp;
835 exit = 0;
837 tmp_otp->value = mem1;
838 tmp_otp->next->value = mem2;
841 // merging
842 if (exit == 0) {
843 tmp_otp = hold;
844 pmt = tmp_otp->next;
845 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
846 mem1 = tmp_otp->value;
847 mem2 = pmt->value;
848 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
849 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
850 pmt->ott = tmp;
851 }//~merging
852 }//~while(exit == 0)
853 }//~if(otp->next!=NULL)
854 #endif
856 // adding otp (containing splitted lines) to otp chain
857 if (otp_sub == NULL) {
858 otp_sub = otp;
859 for (otp_sub_tmp = otp_sub; otp_sub_tmp->next != NULL; otp_sub_tmp = otp_sub_tmp->next);
860 } else {
861 //updating ott chain
862 tmp = otp_sub->ott;
863 while (tmp->next != NULL) tmp = tmp->next;
864 tmp->next = otp->ott;
865 otp->ott->prev = tmp;
866 //attaching new subtitle line at the end
867 otp_sub_tmp->next = otp;
868 otp->prev = otp_sub_tmp;
870 otp_sub_tmp = otp_sub_tmp->next;
871 while (otp_sub_tmp->next != NULL);
873 }//~ if(osl != NULL)
874 } // while
876 // write lines into utbl
877 xtblc = 0;
878 utblc = 0;
879 obj->y = dys;
880 obj->params.subtitle.lines = 0;
881 for (tmp_otp = otp_sub; tmp_otp != NULL; tmp_otp = tmp_otp->next) {
883 if ((obj->params.subtitle.lines++) >= MAX_UCSLINES)
884 break;
886 if (h > obj->y) { // out of the screen so end parsing
887 obj->y -= lasth - sub_font->height; // correct the y position
888 break;
890 xsize = tmp_otp->value;
891 obj->params.subtitle.xtbl[xtblc++] = (dxs - xsize) / 2;
892 if (xmin > (dxs - xsize) / 2)
893 xmin = (dxs - xsize) / 2;
894 if (xmax < (dxs + xsize) / 2)
895 xmax = (dxs + xsize) / 2;
897 tmp = (tmp_otp->next == NULL) ? NULL : tmp_otp->next->ott;
898 for (tmp_ott = tmp_otp->ott; tmp_ott != tmp; tmp_ott = tmp_ott->next) {
899 for (counter = 0; counter < tmp_ott->text_length; ++counter) {
900 if (utblc > MAX_UCS) {
901 break;
903 c = tmp_ott->text[counter];
904 render_one_glyph(sub_font, c);
905 obj->params.subtitle.utbl[utblc++] = c;
906 k++;
908 obj->params.subtitle.utbl[utblc++] = ' ';
910 obj->params.subtitle.utbl[utblc - 1] = 0;
911 obj->y -= sub_font->height;
913 if(obj->params.subtitle.lines)
914 obj->y = dys - ((obj->params.subtitle.lines - 1) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h);
916 // free memory
917 if (otp_sub != NULL) {
918 for (tmp = otp_sub->ott; tmp->next != NULL; free(tmp->prev)) {
919 free(tmp->text);
920 tmp = tmp->next;
922 free(tmp->text);
923 free(tmp);
925 for(pmt = otp_sub; pmt->next != NULL; free(pmt->prev)) {
926 pmt = pmt->next;
928 free(pmt);
932 /// vertical alignment
933 h = dys - obj->y;
934 if (sub_alignment == 2)
935 obj->y = dys * sub_pos / 100 - h;
936 else if (sub_alignment == 1)
937 obj->y = dys * sub_pos / 100 - h / 2;
938 else
939 obj->y = dys * sub_pos / 100;
941 if (obj->y < 0)
942 obj->y = 0;
943 if (obj->y > dys - h)
944 obj->y = dys - h;
946 obj->bbox.y2 = obj->y + h;
948 // calculate bbox:
949 if (sub_justify) xmin = 10;
950 obj->bbox.x1=xmin;
951 obj->bbox.x2=xmax;
952 obj->bbox.y1=obj->y;
953 // obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height;
954 obj->flags|=OSDFLAG_BBOX;
956 alloc_buf(obj);
958 y = obj->y;
960 obj->alignment = 0;
961 switch(vo_sub->alignment) {
962 case SUB_ALIGNMENT_BOTTOMLEFT:
963 case SUB_ALIGNMENT_MIDDLELEFT:
964 case SUB_ALIGNMENT_TOPLEFT:
965 obj->alignment |= 0x1;
966 break;
967 case SUB_ALIGNMENT_BOTTOMRIGHT:
968 case SUB_ALIGNMENT_MIDDLERIGHT:
969 case SUB_ALIGNMENT_TOPRIGHT:
970 obj->alignment |= 0x2;
971 break;
972 case SUB_ALIGNMENT_BOTTOMCENTER:
973 case SUB_ALIGNMENT_MIDDLECENTER:
974 case SUB_ALIGNMENT_TOPCENTER:
975 default:
976 obj->alignment |= 0x0;
979 i=j=0;
980 if ((l = obj->params.subtitle.lines)) {
981 for(counter = dxs; i < l; ++i)
982 if (obj->params.subtitle.xtbl[i] < counter) counter = obj->params.subtitle.xtbl[i];
983 for (i = 0; i < l; ++i) {
984 switch (obj->alignment&0x3) {
985 case 1:
986 // left
987 x = counter;
988 break;
989 case 2:
990 // right
991 x = 2 * obj->params.subtitle.xtbl[i] - counter - ((obj->params.subtitle.xtbl[i] == counter) ? 0 : 1);
992 break;
993 default:
994 //center
995 x = obj->params.subtitle.xtbl[i];
997 prevc = -1;
998 while ((c=obj->params.subtitle.utbl[j++])){
999 x += kerning(sub_font,prevc,c);
1000 if ((font=sub_font->font[c])>=0)
1001 draw_alpha_buf(obj,x,y,
1002 sub_font->width[c],
1003 sub_font->pic_a[font]->h+y<obj->dys ? sub_font->pic_a[font]->h : obj->dys-y,
1004 sub_font->pic_b[font]->bmp+sub_font->start[c],
1005 sub_font->pic_a[font]->bmp+sub_font->start[c],
1006 sub_font->pic_a[font]->w);
1007 x+=sub_font->width[c]+sub_font->charspace;
1008 prevc = c;
1010 y+=sub_font->height;
1016 inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys)
1018 unsigned int bbox[4];
1019 spudec_calc_bbox(vo_spudec, dxs, dys, bbox);
1020 obj->bbox.x1 = bbox[0];
1021 obj->bbox.x2 = bbox[1];
1022 obj->bbox.y1 = bbox[2];
1023 obj->bbox.y2 = bbox[3];
1024 obj->flags |= OSDFLAG_BBOX;
1027 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)
1029 spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha, ctx);
1032 void *vo_spudec=NULL;
1033 void *vo_vobsub=NULL;
1035 static int draw_alpha_init_flag=0;
1037 void vo_draw_alpha_init(void);
1039 mp_osd_obj_t* vo_osd_list=NULL;
1041 static mp_osd_obj_t* new_osd_obj(int type){
1042 mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t));
1043 memset(osd,0,sizeof(mp_osd_obj_t));
1044 osd->next=vo_osd_list;
1045 vo_osd_list=osd;
1046 osd->type=type;
1047 osd->alpha_buffer = NULL;
1048 osd->bitmap_buffer = NULL;
1049 osd->allocated = -1;
1050 return osd;
1053 void osd_free(struct osd_state *osd)
1055 mp_osd_obj_t* obj=vo_osd_list;
1056 while(obj){
1057 mp_osd_obj_t* next=obj->next;
1058 if (obj->alpha_buffer) free(obj->alpha_buffer);
1059 if (obj->bitmap_buffer) free(obj->bitmap_buffer);
1060 free(obj);
1061 obj=next;
1063 vo_osd_list=NULL;
1064 talloc_free(osd);
1067 #define FONT_LOAD_DEFER 6
1069 int osd_update(struct osd_state *osd, int dxs, int dys)
1071 mp_osd_obj_t* obj=vo_osd_list;
1072 int chg=0;
1073 #ifdef CONFIG_FREETYPE
1074 static int defer_counter = 0, prev_dxs = 0, prev_dys = 0;
1075 #endif
1077 #ifdef CONFIG_FREETYPE
1078 // here is the right place to get screen dimensions
1079 if (((dxs != vo_image_width)
1080 && (subtitle_autoscale == 2 || subtitle_autoscale == 3))
1081 || ((dys != vo_image_height)
1082 && (subtitle_autoscale == 1 || subtitle_autoscale == 3)))
1084 // screen dimensions changed
1085 // wait a while to avoid useless reloading of the font
1086 if (dxs == prev_dxs || dys == prev_dys) {
1087 defer_counter++;
1088 } else {
1089 prev_dxs = dxs;
1090 prev_dys = dys;
1091 defer_counter = 0;
1093 if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1;
1096 if (force_load_font) {
1097 force_load_font = 0;
1098 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1099 if (sub_font_name)
1100 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1101 else
1102 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1103 prev_dxs = dxs;
1104 prev_dys = dys;
1105 defer_counter = 0;
1106 } else {
1107 if (!vo_font)
1108 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1109 if (!osd->sub_font) {
1110 if (sub_font_name)
1111 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1112 else
1113 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1116 #endif
1118 while(obj){
1119 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){
1120 int vis=obj->flags&OSDFLAG_VISIBLE;
1121 obj->flags&=~OSDFLAG_BBOX;
1122 switch(obj->type){
1123 #ifdef CONFIG_DVDNAV
1124 case OSDTYPE_DVDNAV:
1125 vo_update_nav(obj,dxs,dys);
1126 break;
1127 #endif
1128 case OSDTYPE_SUBTITLE:
1129 vo_update_text_sub(osd, obj,dxs,dys);
1130 break;
1131 #ifdef CONFIG_TV_TELETEXT
1132 case OSDTYPE_TELETEXT:
1133 vo_update_text_teletext(obj,dxs,dys);
1134 break;
1135 #endif
1136 case OSDTYPE_PROGBAR:
1137 vo_update_text_progbar(obj,dxs,dys);
1138 break;
1139 case OSDTYPE_SPU:
1140 if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){
1141 vo_update_spudec_sub(obj, dxs, dys);
1142 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1144 else
1145 obj->flags&=~OSDFLAG_VISIBLE;
1146 break;
1147 case OSDTYPE_OSD:
1148 if(vo_font && osd->osd_text[0]){
1149 vo_update_text_osd(osd, obj, dxs, dys); // update bbox
1150 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1151 } else
1152 obj->flags&=~OSDFLAG_VISIBLE;
1153 break;
1155 // check bbox:
1156 if(!(obj->flags&OSDFLAG_BBOX)){
1157 // we don't know, so assume the whole screen changed :(
1158 obj->bbox.x1=obj->bbox.y1=0;
1159 obj->bbox.x2=dxs;
1160 obj->bbox.y2=dys;
1161 obj->flags|=OSDFLAG_BBOX;
1162 } else {
1163 // check bbox, reduce it if it's out of bounds (corners):
1164 if(obj->bbox.x1<0) obj->bbox.x1=0;
1165 if(obj->bbox.y1<0) obj->bbox.y1=0;
1166 if(obj->bbox.x2>dxs) obj->bbox.x2=dxs;
1167 if(obj->bbox.y2>dys) obj->bbox.y2=dys;
1168 if(obj->flags&OSDFLAG_VISIBLE)
1169 // debug:
1170 mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n",
1171 obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1,
1172 obj->bbox.y2-obj->bbox.y1);
1174 // check if visibility changed:
1175 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED;
1176 // remove the cause of automatic update:
1177 obj->dxs=dxs; obj->dys=dys;
1178 obj->flags&=~OSDFLAG_FORCE_UPDATE;
1180 if(obj->flags&OSDFLAG_CHANGED){
1181 chg|=1<<obj->type;
1182 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);
1184 obj=obj->next;
1186 return chg;
1189 struct osd_state *osd_create(void)
1191 struct osd_state *osd = talloc_zero(NULL, struct osd_state);
1192 *osd = (struct osd_state){
1194 if(!draw_alpha_init_flag){
1195 draw_alpha_init_flag=1;
1196 vo_draw_alpha_init();
1198 // temp hack, should be moved to mplayer/mencoder later
1199 new_osd_obj(OSDTYPE_OSD);
1200 new_osd_obj(OSDTYPE_SUBTITLE);
1201 new_osd_obj(OSDTYPE_PROGBAR);
1202 new_osd_obj(OSDTYPE_SPU);
1203 #ifdef CONFIG_DVDNAV
1204 new_osd_obj(OSDTYPE_DVDNAV);
1205 #endif
1206 #if CONFIG_TV_TELETEXT
1207 new_osd_obj(OSDTYPE_TELETEXT);
1208 #endif
1209 #ifdef CONFIG_FREETYPE
1210 force_load_font = 1;
1211 #endif
1212 return osd;
1215 int vo_osd_changed_flag=0;
1217 void osd_remove_text(struct osd_state *osd, int dxs, int dys,
1218 void (*remove)(int x0, int y0, int w, int h))
1220 mp_osd_obj_t* obj=vo_osd_list;
1221 osd_update(osd, dxs, dys);
1222 while(obj){
1223 if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) &&
1224 (obj->flags&OSDFLAG_OLD_BBOX)){
1225 int w=obj->old_bbox.x2-obj->old_bbox.x1;
1226 int h=obj->old_bbox.y2-obj->old_bbox.y1;
1227 if(w>0 && h>0){
1228 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1229 remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h);
1231 // obj->flags&=~OSDFLAG_OLD_BBOX;
1233 obj=obj->next;
1237 void osd_draw_text(struct osd_state *osd, int dxs, int dys,
1238 void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h,
1239 unsigned char* src, unsigned char *srca,
1240 int stride),
1241 void *ctx)
1243 mp_osd_obj_t* obj=vo_osd_list;
1244 osd_update(osd, dxs, dys);
1245 while(obj){
1246 if(obj->flags&OSDFLAG_VISIBLE){
1247 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1248 switch(obj->type){
1249 case OSDTYPE_SPU:
1250 vo_draw_spudec_sub(obj, draw_alpha, ctx); // FIXME
1251 break;
1252 #ifdef CONFIG_DVDNAV
1253 case OSDTYPE_DVDNAV:
1254 #endif
1255 #ifdef CONFIG_TV_TELETEXT
1256 case OSDTYPE_TELETEXT:
1257 #endif
1258 case OSDTYPE_OSD:
1259 case OSDTYPE_SUBTITLE:
1260 case OSDTYPE_PROGBAR:
1261 vo_draw_text_from_buffer(obj, draw_alpha, ctx);
1262 break;
1264 obj->old_bbox=obj->bbox;
1265 obj->flags|=OSDFLAG_OLD_BBOX;
1267 obj->flags&=~OSDFLAG_CHANGED;
1268 obj=obj->next;
1272 static int vo_osd_changed_status = 0;
1274 int vo_osd_changed(int new_value)
1276 mp_osd_obj_t* obj=vo_osd_list;
1277 int ret = vo_osd_changed_status;
1278 vo_osd_changed_status = new_value;
1280 while(obj){
1281 if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
1282 obj=obj->next;
1285 return ret;
1288 // BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB
1289 // BBBBBBBBBBBB BBBBBBBBBBBBB
1290 // BBBBBBB
1292 // return TRUE if we have osd in the specified rectangular area:
1293 int vo_osd_check_range_update(int x1,int y1,int x2,int y2){
1294 mp_osd_obj_t* obj=vo_osd_list;
1295 while(obj){
1296 if(obj->flags&OSDFLAG_VISIBLE){
1297 if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) &&
1298 (obj->bbox.y1<=y2 && obj->bbox.y2>=y1) &&
1299 obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1
1300 ) return 1;
1302 obj=obj->next;
1304 return 0;