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