Get rid of completely pointless vt_doit variable
[mplayer/glamo.git] / libvo / sub.c
blob665c935b349831418288ccc31dfa23e4a7e7a114
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "config.h"
24 #if HAVE_MALLOC_H
25 #include <malloc.h>
26 #endif
28 #include "stream/stream.h"
29 #include "stream/stream_dvdnav.h"
30 #define OSD_NAV_BOX_ALPHA 0x7f
32 #include "stream/tv.h"
33 #include "osdep/timer.h"
35 #include "mplayer.h"
36 #include "mp_msg.h"
37 #include "help_mp.h"
38 #include "video_out.h"
39 #include "font_load.h"
40 #include "sub.h"
41 #include "spudec.h"
42 #include "libavutil/common.h"
44 #define NEW_SPLITTING
47 // Structures needed for the new splitting algorithm.
48 // osd_text_t contains the single subtitle word.
49 // osd_text_p is used to mark the lines of subtitles
50 struct osd_text_t {
51 int osd_kerning, //kerning with the previous word
52 osd_length, //orizontal length inside the bbox
53 text_length, //number of characters
54 *text; //characters
55 struct osd_text_t *prev,
56 *next;
59 struct osd_text_p {
60 int value;
61 struct osd_text_t *ott;
62 struct osd_text_p *prev,
63 *next;
65 //^
67 char * sub_osd_names[]={
68 MSGTR_VO_SUB_Seekbar,
69 MSGTR_VO_SUB_Play,
70 MSGTR_VO_SUB_Pause,
71 MSGTR_VO_SUB_Stop,
72 MSGTR_VO_SUB_Rewind,
73 MSGTR_VO_SUB_Forward,
74 MSGTR_VO_SUB_Clock,
75 MSGTR_VO_SUB_Contrast,
76 MSGTR_VO_SUB_Saturation,
77 MSGTR_VO_SUB_Volume,
78 MSGTR_VO_SUB_Brightness,
79 MSGTR_VO_SUB_Hue,
80 MSGTR_VO_SUB_Balance
82 char * sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", "", "" };
84 //static int vo_font_loaded=-1;
85 font_desc_t* vo_font=NULL;
86 font_desc_t* sub_font=NULL;
88 unsigned char* vo_osd_text=NULL;
89 #ifdef CONFIG_TV_TELETEXT
90 void* vo_osd_teletext_page=NULL;
91 int vo_osd_teletext_half = 0;
92 int vo_osd_teletext_mode=0;
93 int vo_osd_teletext_format=0;
94 int vo_osd_teletext_scale=0;
95 #endif
96 int sub_unicode=0;
97 int sub_utf8=0;
98 int sub_pos=100;
99 int sub_width_p=100;
100 int sub_alignment=2; /* 0=top, 1=center, 2=bottom */
101 int sub_visibility=1;
102 int sub_bg_color=0; /* subtitles background color */
103 int sub_bg_alpha=0;
104 int sub_justify=0;
105 #ifdef CONFIG_DVDNAV
106 static nav_highlight_t nav_hl;
107 #endif
109 // return the real height of a char:
110 static inline int get_height(int c,int h){
111 int font;
112 if ((font=vo_font->font[c])>=0)
113 if(h<vo_font->pic_a[font]->h) h=vo_font->pic_a[font]->h;
114 return h;
117 // renders char to a big per-object buffer where alpha and bitmap are separated
118 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)
120 int dststride = obj->stride;
121 int dstskip = obj->stride-w;
122 int srcskip = stride-w;
123 int i, j;
124 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
125 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
126 unsigned char *bs = src;
127 unsigned char *as = srca;
129 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) {
130 fprintf(stderr, "osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n",
131 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2,
132 x0, x0+w, y0, y0+h);
133 return;
136 for (i = 0; i < h; i++) {
137 for (j = 0; j < w; j++, b++, a++, bs++, as++) {
138 if (*b < *bs) *b = *bs;
139 if (*as) {
140 if (*a == 0 || *a > *as) *a = *as;
143 b+= dstskip;
144 a+= dstskip;
145 bs+= srcskip;
146 as+= srcskip;
150 // allocates/enlarges the alpha/bitmap buffer
151 static void alloc_buf(mp_osd_obj_t* obj)
153 int len;
154 if (obj->bbox.x2 < obj->bbox.x1) obj->bbox.x2 = obj->bbox.x1;
155 if (obj->bbox.y2 < obj->bbox.y1) obj->bbox.y2 = obj->bbox.y1;
156 obj->stride = ((obj->bbox.x2-obj->bbox.x1)+7)&(~7);
157 len = obj->stride*(obj->bbox.y2-obj->bbox.y1);
158 if (obj->allocated<len) {
159 obj->allocated = len;
160 free(obj->bitmap_buffer);
161 free(obj->alpha_buffer);
162 obj->bitmap_buffer = (unsigned char *)memalign(16, len);
163 obj->alpha_buffer = (unsigned char *)memalign(16, len);
165 memset(obj->bitmap_buffer, sub_bg_color, len);
166 memset(obj->alpha_buffer, sub_bg_alpha, len);
169 // renders the buffer
170 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)){
171 if (obj->allocated > 0) {
172 draw_alpha(obj->bbox.x1,obj->bbox.y1,
173 obj->bbox.x2-obj->bbox.x1,
174 obj->bbox.y2-obj->bbox.y1,
175 obj->bitmap_buffer,
176 obj->alpha_buffer,
177 obj->stride);
181 unsigned utf8_get_char(const char **str) {
182 const uint8_t *strp = (const uint8_t *)*str;
183 unsigned c;
184 GET_UTF8(c, *strp++, goto no_utf8;);
185 *str = (const char *)strp;
186 return c;
188 no_utf8:
189 strp = (const uint8_t *)*str;
190 c = *strp++;
191 *str = (const char *)strp;
192 return c;
195 inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){
196 const char *cp=vo_osd_text;
197 int x=20;
198 int h=0;
199 int font;
201 obj->bbox.x1=obj->x=x;
202 obj->bbox.y1=obj->y=10;
204 while (*cp){
205 uint16_t c=utf8_get_char(&cp);
206 render_one_glyph(vo_font, c);
207 x+=vo_font->width[c]+vo_font->charspace;
208 h=get_height(c,h);
211 obj->bbox.x2=x-vo_font->charspace;
212 obj->bbox.y2=obj->bbox.y1+h;
213 obj->flags|=OSDFLAG_BBOX;
215 alloc_buf(obj);
217 cp=vo_osd_text;
218 x = obj->x;
219 while (*cp){
220 uint16_t c=utf8_get_char(&cp);
221 if ((font=vo_font->font[c])>=0)
222 draw_alpha_buf(obj,x,obj->y,
223 vo_font->width[c],
224 vo_font->pic_a[font]->h,
225 vo_font->pic_b[font]->bmp+vo_font->start[c],
226 vo_font->pic_a[font]->bmp+vo_font->start[c],
227 vo_font->pic_a[font]->w);
228 x+=vo_font->width[c]+vo_font->charspace;
232 #ifdef CONFIG_DVDNAV
233 void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey) {
234 nav_hl.sx = sx;
235 nav_hl.sy = sy;
236 nav_hl.ex = ex;
237 nav_hl.ey = ey;
240 inline static void vo_update_nav (mp_osd_obj_t *obj, int dxs, int dys, int left_border, int top_border,
241 int right_border, int bottom_border, int orig_w, int orig_h) {
242 int len;
243 int sx = nav_hl.sx, sy = nav_hl.sy;
244 int ex = nav_hl.ex, ey = nav_hl.ey;
245 int scaled_w = dxs - left_border - right_border;
246 int scaled_h = dys - top_border - bottom_border;
247 if (scaled_w != orig_w) {
248 sx = sx * scaled_w / orig_w;
249 ex = ex * scaled_w / orig_w;
251 if (scaled_h != orig_h) {
252 sy = sy * scaled_h / orig_h;
253 ey = ey * scaled_h / orig_h;
255 sx += left_border; ex += left_border;
256 sy += top_border; ey += top_border;
257 sx = FFMIN(FFMAX(sx, 0), dxs);
258 ex = FFMIN(FFMAX(ex, 0), dxs);
259 sy = FFMIN(FFMAX(sy, 0), dys);
260 ey = FFMIN(FFMAX(ey, 0), dys);
262 obj->bbox.x1 = obj->x = sx;
263 obj->bbox.y1 = obj->y = sy;
264 obj->bbox.x2 = ex;
265 obj->bbox.y2 = ey;
267 alloc_buf (obj);
268 len = obj->stride * (obj->bbox.y2 - obj->bbox.y1);
269 memset (obj->bitmap_buffer, OSD_NAV_BOX_ALPHA, len);
270 memset (obj->alpha_buffer, OSD_NAV_BOX_ALPHA, len);
271 obj->flags |= OSDFLAG_BBOX | OSDFLAG_CHANGED;
272 if (obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1)
273 obj->flags |= OSDFLAG_VISIBLE;
275 #endif
277 #ifdef CONFIG_TV_TELETEXT
278 // renders char to a big per-object buffer where alpha and bitmap are separated
279 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)
281 int dststride = obj->stride;
282 int dstskip = obj->stride-w;
283 int srcskip = stride-w;
284 int i, j;
285 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
286 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
287 unsigned char *bs = src;
288 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) {
289 mp_msg(MSGT_OSD,MSGL_ERR,"tt osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n",
290 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2,
291 x0, x0+w, y0, y0+h);
292 return;
294 for (i = 0; i < h; i++) {
295 for (j = 0; j < w; j++, b++, a++, bs++) {
296 *b=(fg-bg)*(*bs)/255+bg;
297 *a=alpha;
299 b+= dstskip;
300 a+= dstskip;
301 bs+= srcskip;
304 inline static void vo_update_text_teletext(mp_osd_obj_t *obj, int dxs, int dys)
306 int h=0,w=0,i,j,font,flashon;
307 int wm,hm;
308 int color;
309 int x,y,x0,y0;
310 int cols,rows;
311 int wm12;
312 int hm13;
313 int hm23;
314 int start_row,max_rows;
315 int b,ax[6],ay[6],aw[6],ah[6];
316 tt_char tc;
317 tt_char* tdp=vo_osd_teletext_page;
318 unsigned char colors[8]={1,85,150,226,70,105,179,254};
319 unsigned char* buf[9];
321 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
322 if (!tdp || !vo_osd_teletext_mode) {
323 obj->flags&=~OSDFLAG_VISIBLE;
324 return;
326 flashon=(GetTimer()/1000000)%2;
327 switch(vo_osd_teletext_half){
328 case TT_ZOOM_TOP_HALF:
329 start_row=0;
330 max_rows=VBI_ROWS/2;
331 break;
332 case TT_ZOOM_BOTTOM_HALF:
333 start_row=VBI_ROWS/2;
334 max_rows=VBI_ROWS/2;
335 break;
336 default:
337 start_row=0;
338 max_rows=VBI_ROWS;
339 break;
341 wm=0;
342 for(i=start_row;i<max_rows;i++){
343 for(j=0;j<VBI_COLUMNS;j++){
344 tc=tdp[i*VBI_COLUMNS+j];
345 if(!tc.ctl && !tc.gfx)
347 render_one_glyph(vo_font, tc.unicode);
348 if (wm<vo_font->width[tc.unicode])
349 wm=vo_font->width[tc.unicode];
354 hm=vo_font->height+1;
355 wm=dxs*hm*max_rows/(dys*VBI_COLUMNS);
357 //very simple teletext font auto scaling
358 if(!vo_osd_teletext_scale && hm*(max_rows+1)>dys){
359 text_font_scale_factor*=1.0*(dys)/((max_rows+1)*hm);
360 force_load_font=1;
361 vo_osd_teletext_scale=text_font_scale_factor;
362 obj->flags&=~OSDFLAG_VISIBLE;
363 return;
366 cols=dxs/wm;
367 rows=dys/hm;
369 if(cols>VBI_COLUMNS)
370 cols=VBI_COLUMNS;
371 if(rows>max_rows)
372 rows=max_rows;
373 w=cols*wm-vo_font->charspace;
374 h=rows*hm-vo_font->charspace;
376 if(w<dxs)
377 x0=(dxs-w)/2;
378 else
379 x0=0;
380 if(h<dys)
381 y0=(dys-h)/2;
382 else
383 y0=0;
385 wm12=wm>>1;
386 hm13=(hm+1)/3;
387 hm23=hm13<<1;
389 for(i=0;i<6;i+=2){
390 ax[i+0]=0;
391 aw[i+0]=wm12;
393 ax[i+1]=wm12;
394 aw[i+1]=wm-wm12;
397 for(i=0;i<2;i++){
398 ay[i+0]=0;
399 ah[i+0]=hm13;
401 ay[i+2]=hm13;
402 ah[i+2]=hm-hm23;
404 ay[i+4]=hm-hm13;
405 ah[i+4]=hm13;
408 obj->x = 0;
409 obj->y = 0;
410 obj->bbox.x1 = x0;
411 obj->bbox.y1 = y0;
412 obj->bbox.x2 = x0+w;
413 obj->bbox.y2 = y0+h;
414 obj->flags |= OSDFLAG_BBOX;
415 alloc_buf(obj);
417 for(i=0;i<9;i++)
418 buf[i]=malloc(wm*hm);
420 //alpha
421 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_OPAQUE_INV)
422 color=1;
423 else
424 color=200;
425 memset(buf[8],color,wm*hm);
426 //colors
427 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_TRANSPARENT){
428 for(i=0;i<8;i++){
429 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[i]/255),wm*hm);
431 }else{
432 for(i=0;i<8;i++)
433 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[7-i]/255),wm*hm);
436 y=y0;
437 for(i=0;i<rows;i++){
438 x=x0;
439 for(j=0;j<cols;j++){
440 tc=tdp[(i+start_row)*VBI_COLUMNS+j];
441 if (tc.hidden) { x+=wm; continue;}
442 if(!tc.gfx || (tc.flh && !flashon)){
443 /* Rendering one text character */
444 draw_alpha_buf(obj,x,y,wm,hm,buf[tc.bg],buf[8],wm);
445 if(tc.unicode!=0x20 && tc.unicode!=0x00 && !tc.ctl &&
446 (!tc.flh || flashon) &&
447 (font=vo_font->font[tc.unicode])>=0 && y+hm<dys){
448 tt_draw_alpha_buf(obj,x,y,vo_font->width[tc.unicode],vo_font->height,
449 vo_font->pic_b[font]->bmp+vo_font->start[tc.unicode]-vo_font->charspace*vo_font->pic_a[font]->w,
450 vo_font->pic_b[font]->w,
451 buf[tc.fg][0],buf[tc.bg][0],buf[8][0]);
453 }else{
455 Rendering one graphics character
456 TODO: support for separated graphics symbols (where six rectangles does not touch each other)
458 +--+ +--+ 87654321
459 |01| |12| --------
460 |10| <= |34| <= 00100110 <= 0x26
461 |01| |56|
462 +--+ +--+
464 (0:wm/2) (wm/2:wm-wm/2)
466 ********** *********** (0:hm/3)
467 *** **** **** ****
468 *** 1 **** **** 2 ****
469 *** **** **** ****
470 ********** ***********
471 ********** ***********
473 ********** *********** (hm/3:hm-2*hm/3)
474 ********** ***********
475 *** **** **** ****
476 *** 3 **** **** 4 ****
477 *** **** **** ****
478 ********** ***********
479 ********** ***********
480 ********** ***********
482 ********** *********** (hm-hm/3:hm/3)
483 *** **** **** ****
484 *** 5 **** **** 6 ****
485 *** **** **** ****
486 ********** ***********
487 ********** ***********
490 if(tc.gfx>1){ //separated gfx
491 for(b=0;b<6;b++){
492 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
493 draw_alpha_buf(obj,x+ax[b]+1,y+ay[b]+1,aw[b]-2,ah[b]-2,buf[color],buf[8],wm);
495 //separated gfx (background borders)
496 //vertical
497 draw_alpha_buf(obj,x ,y,1,hm,buf[tc.bg],buf[8],wm);
498 draw_alpha_buf(obj,x+ax[1]-1,y,2,hm,buf[tc.bg],buf[8],wm);
499 draw_alpha_buf(obj,x+ax[1]+aw[1]-1,y,wm-ax[1]-aw[1]+1,hm,buf[tc.bg],buf[8],wm);
500 //horizontal
501 draw_alpha_buf(obj,x,y ,wm,1,buf[tc.bg],buf[8],wm);
502 draw_alpha_buf(obj,x,y+ay[0]+ah[0]-1,wm,2,buf[tc.bg],buf[8],wm);
503 draw_alpha_buf(obj,x,y+ay[2]+ah[2]-1,wm,2,buf[tc.bg],buf[8],wm);
504 draw_alpha_buf(obj,x,y+ay[4]+ah[4]-1,wm,hm-ay[4]-ah[4]+1,buf[tc.bg],buf[8],wm);
505 }else{
506 for(b=0;b<6;b++){
507 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
508 draw_alpha_buf(obj,x+ax[b],y+ay[b],aw[b],ah[b],buf[color],buf[8],wm);
512 x+=wm;
514 y+=hm;
516 for(i=0;i<9;i++)
517 free(buf[i]);
519 #endif
521 int vo_osd_progbar_type=-1;
522 int vo_osd_progbar_value=100; // 0..256
524 // if we have n=256 bars then OSD progbar looks like below
526 // 0 1 2 3 ... 256 <= vo_osd_progbar_value
527 // | | | | |
528 // [ === === === ... === ]
530 // the above schema is rescalled to n=elems bars
532 inline static void vo_update_text_progbar(mp_osd_obj_t* obj,int dxs,int dys){
534 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
536 if(vo_osd_progbar_type<0 || !vo_font){
537 obj->flags&=~OSDFLAG_VISIBLE;
538 return;
541 render_one_glyph(vo_font, OSD_PB_START);
542 render_one_glyph(vo_font, OSD_PB_END);
543 render_one_glyph(vo_font, OSD_PB_0);
544 render_one_glyph(vo_font, OSD_PB_1);
545 render_one_glyph(vo_font, vo_osd_progbar_type);
547 // calculate bbox corners:
548 { int h=0;
549 int y=(dys-vo_font->height)/2;
550 int delimw=vo_font->width[OSD_PB_START]
551 +vo_font->width[OSD_PB_END]
552 +vo_font->charspace;
553 int width=(2*dxs-3*delimw)/3;
554 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
555 int elems=width/charw;
556 int x=(dxs-elems*charw-delimw)/2;
557 int delta = 0;
558 h=get_height(OSD_PB_START,h);
559 h=get_height(OSD_PB_END,h);
560 h=get_height(OSD_PB_0,h);
561 h=get_height(OSD_PB_1,h);
562 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
563 delta = vo_font->width[vo_osd_progbar_type]+vo_font->spacewidth;
564 delta = (x-delta > 0) ? delta : x;
565 h=get_height(vo_osd_progbar_type,h);
567 obj->bbox.x1=obj->x=x;
568 obj->bbox.y1=obj->y=y;
569 obj->bbox.x2=x+width+delimw;
570 obj->bbox.y2=y+h; //vo_font->height;
571 obj->flags|=OSDFLAG_BBOX;
572 obj->params.progbar.elems=elems;
573 obj->bbox.x1-=delta; // space for an icon
576 alloc_buf(obj);
579 int minw = vo_font->width[OSD_PB_START]+vo_font->width[OSD_PB_END]+vo_font->width[OSD_PB_0];
580 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
581 minw += vo_font->width[vo_osd_progbar_type]+vo_font->charspace+vo_font->spacewidth;
583 if (obj->bbox.x2 - obj->bbox.x1 < minw) return; // space too small, don't render anything
586 // render it:
587 { unsigned char *s;
588 unsigned char *sa;
589 int i,w,h,st,mark;
590 int x=obj->x;
591 int y=obj->y;
592 int c,font;
593 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
594 int elems=obj->params.progbar.elems;
596 if (vo_osd_progbar_value<=0)
597 mark=0;
598 else {
599 int ev=vo_osd_progbar_value*elems;
600 mark=ev>>8;
601 if (ev & 0xFF) mark++;
602 if (mark>elems) mark=elems;
606 // printf("osd.progbar width=%d xpos=%d\n",width,x);
608 c=vo_osd_progbar_type;
609 if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0) {
610 int xp=x-vo_font->width[c]-vo_font->spacewidth;
611 draw_alpha_buf(obj,(xp<0?0:xp),y,
612 vo_font->width[c],
613 vo_font->pic_a[font]->h,
614 vo_font->pic_b[font]->bmp+vo_font->start[c],
615 vo_font->pic_a[font]->bmp+vo_font->start[c],
616 vo_font->pic_a[font]->w);
619 c=OSD_PB_START;
620 if ((font=vo_font->font[c])>=0)
621 draw_alpha_buf(obj,x,y,
622 vo_font->width[c],
623 vo_font->pic_a[font]->h,
624 vo_font->pic_b[font]->bmp+vo_font->start[c],
625 vo_font->pic_a[font]->bmp+vo_font->start[c],
626 vo_font->pic_a[font]->w);
627 x+=vo_font->width[c]+vo_font->charspace;
629 c=OSD_PB_0;
630 if ((font=vo_font->font[c])>=0){
631 w=vo_font->width[c];
632 h=vo_font->pic_a[font]->h;
633 s=vo_font->pic_b[font]->bmp+vo_font->start[c];
634 sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
635 st=vo_font->pic_a[font]->w;
636 if ((i=mark)) do {
637 draw_alpha_buf(obj,x,y,w,h,s,sa,st);
638 x+=charw;
639 } while(--i);
642 c=OSD_PB_1;
643 if ((font=vo_font->font[c])>=0){
644 w=vo_font->width[c];
645 h=vo_font->pic_a[font]->h;
646 s =vo_font->pic_b[font]->bmp+vo_font->start[c];
647 sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
648 st=vo_font->pic_a[font]->w;
649 if ((i=elems-mark)) do {
650 draw_alpha_buf(obj,x,y,w,h,s,sa,st);
651 x+=charw;
652 } while(--i);
655 c=OSD_PB_END;
656 if ((font=vo_font->font[c])>=0)
657 draw_alpha_buf(obj,x,y,
658 vo_font->width[c],
659 vo_font->pic_a[font]->h,
660 vo_font->pic_b[font]->bmp+vo_font->start[c],
661 vo_font->pic_a[font]->bmp+vo_font->start[c],
662 vo_font->pic_a[font]->w);
663 // x+=vo_font->width[c]+vo_font->charspace;
666 // vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF;
670 subtitle* vo_sub=NULL;
672 inline static void vo_update_text_sub(mp_osd_obj_t* obj,int dxs,int dys){
673 unsigned char *t;
674 int c,i,j,l,x,y,font,prevc,counter;
675 int k;
676 int lastStripPosition;
677 int xsize;
678 int xmin=dxs,xmax=0;
679 int h,lasth;
680 int xtblc, utblc;
682 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
684 if(!vo_sub || !sub_font || !sub_visibility || (sub_font->font[40]<0)){
685 obj->flags&=~OSDFLAG_VISIBLE;
686 return;
689 obj->bbox.y2=obj->y=dys;
690 obj->params.subtitle.lines=0;
692 // too long lines divide into a smaller ones
693 i=k=lasth=0;
694 h=sub_font->height;
695 lastStripPosition=-1;
696 l=vo_sub->lines;
699 struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp;
700 struct osd_text_p *otp_sub = NULL, *otp_sub_tmp, // these are used to store the whole sub text osd
701 *otp, *tmp_otp, *pmt; // these are used to manage sub text osd coming from a single sub line
702 int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
704 while (l) {
705 xsize = -sub_font->charspace;
706 l--;
707 t=vo_sub->text[i++];
708 char_position = 0;
709 char_seq = calloc(strlen(t), sizeof(int));
711 prevc = -1;
713 otp = NULL;
714 osl = NULL;
715 x = 1;
717 // reading the subtitle words from vo_sub->text[]
718 while (*t) {
719 if (sub_utf8)
720 c = utf8_get_char(&t);
721 else if ((c = *t++) >= 0x80 && sub_unicode)
722 c = (c<<8) + *t++;
723 if (k==MAX_UCS){
724 t += strlen(t); // end here
725 mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n");
727 if (!c) c++; // avoid UCS 0
728 render_one_glyph(sub_font, c);
730 if (c == ' ') {
731 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
733 if (osl == NULL) {
734 osl = cp_ott = tmp_ott;
735 } else {
736 tmp_ott->prev = cp_ott;
737 cp_ott->next = tmp_ott;
738 tmp_ott->osd_kerning =
739 sub_font->charspace + sub_font->width[' '];
740 cp_ott = tmp_ott;
742 tmp_ott->osd_length = xsize;
743 tmp_ott->text_length = char_position;
744 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
745 for (counter = 0; counter < char_position; ++counter)
746 tmp_ott->text[counter] = char_seq[counter];
747 char_position = 0;
748 xsize = 0;
749 prevc = c;
750 } else {
751 int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_font, prevc, c);
753 if (xsize + delta_xsize <= dxs) {
754 if (!x) x = 1;
755 prevc = c;
756 char_seq[char_position++] = c;
757 xsize += delta_xsize;
758 if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) {
759 if (sub_font->pic_a[font]->h > h) {
760 h = sub_font->pic_a[font]->h;
763 } else {
764 if (x) {
765 mp_msg(MSGT_OSD, MSGL_WARN, "\nSubtitle word '%s' too long!\n", t);
766 x = 0;
770 }// for len (all words from subtitle line read)
772 // osl holds an ordered (as they appear in the lines) chain of the subtitle words
774 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
776 if (osl == NULL) {
777 osl = cp_ott = tmp_ott;
778 } else {
779 tmp_ott->prev = cp_ott;
780 cp_ott->next = tmp_ott;
781 tmp_ott->osd_kerning =
782 sub_font->charspace + sub_font->width[' '];
783 cp_ott = tmp_ott;
785 tmp_ott->osd_length = xsize;
786 tmp_ott->text_length = char_position;
787 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
788 for (counter = 0; counter < char_position; ++counter)
789 tmp_ott->text[counter] = char_seq[counter];
790 char_position = 0;
791 xsize = -sub_font->charspace;
793 free(char_seq);
795 if (osl != NULL) {
796 int value = 0, exit = 0, minimum = 0;
798 // otp will contain the chain of the osd subtitle lines coming from the single vo_sub line.
799 otp = tmp_otp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
800 tmp_otp->ott = osl;
801 for (tmp_ott = tmp_otp->ott; exit == 0; ) {
802 do {
803 value += tmp_ott->osd_kerning + tmp_ott->osd_length;
804 tmp_ott = tmp_ott->next;
805 } while ((tmp_ott != NULL) && (value + tmp_ott->osd_kerning + tmp_ott->osd_length <= xlimit));
806 if (tmp_ott != NULL) {
807 struct osd_text_p *tmp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
809 tmp_otp->value = value;
810 tmp_otp->next = tmp;
811 tmp->prev = tmp_otp;
812 tmp_otp = tmp;
813 tmp_otp->ott = tmp_ott;
814 value = -2 * sub_font->charspace - sub_font->width[' '];
815 } else {
816 tmp_otp->value = value;
817 exit = 1;
822 #ifdef NEW_SPLITTING
823 // minimum holds the 'sum of the differences in length among the lines',
824 // a measure of the evenness of the lengths of the lines
825 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
826 pmt = tmp_otp->next;
827 while (pmt != NULL) {
828 minimum += abs(tmp_otp->value - pmt->value);
829 pmt = pmt->next;
833 if (otp->next != NULL) {
834 int mem1, mem2;
835 struct osd_text_p *mem, *hold;
837 exit = 0;
838 // until the last word of a line can be moved to the beginning of following line
839 // reducing the 'sum of the differences in length among the lines', it is done
840 while (exit == 0) {
841 hold = NULL;
842 exit = 1;
843 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
844 pmt = tmp_otp->next;
845 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
846 if (pmt->value + tmp->osd_length + pmt->ott->osd_kerning <= xlimit) {
847 mem1 = tmp_otp->value;
848 mem2 = pmt->value;
849 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
850 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
852 value = 0;
853 for (mem = otp; mem->next != NULL; mem = mem->next) {
854 pmt = mem->next;
855 while (pmt != NULL) {
856 value += abs(mem->value - pmt->value);
857 pmt = pmt->next;
860 if (value < minimum) {
861 minimum = value;
862 hold = tmp_otp;
863 exit = 0;
865 tmp_otp->value = mem1;
866 tmp_otp->next->value = mem2;
869 // merging
870 if (exit == 0) {
871 tmp_otp = hold;
872 pmt = tmp_otp->next;
873 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
874 mem1 = tmp_otp->value;
875 mem2 = pmt->value;
876 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
877 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
878 pmt->ott = tmp;
879 }//~merging
880 }//~while(exit == 0)
881 }//~if(otp->next!=NULL)
882 #endif
884 // adding otp (containing splitted lines) to otp chain
885 if (otp_sub == NULL) {
886 otp_sub = otp;
887 for (otp_sub_tmp = otp_sub; otp_sub_tmp->next != NULL; otp_sub_tmp = otp_sub_tmp->next);
888 } else {
889 //updating ott chain
890 tmp = otp_sub->ott;
891 while (tmp->next != NULL) tmp = tmp->next;
892 tmp->next = otp->ott;
893 otp->ott->prev = tmp;
894 //attaching new subtitle line at the end
895 otp_sub_tmp->next = otp;
896 otp->prev = otp_sub_tmp;
898 otp_sub_tmp = otp_sub_tmp->next;
899 while (otp_sub_tmp->next != NULL);
901 }//~ if(osl != NULL)
902 } // while
904 // write lines into utbl
905 xtblc = 0;
906 utblc = 0;
907 obj->y = dys;
908 obj->params.subtitle.lines = 0;
909 for (tmp_otp = otp_sub; tmp_otp != NULL; tmp_otp = tmp_otp->next) {
911 if ((obj->params.subtitle.lines++) >= MAX_UCSLINES)
912 break;
914 if (h > obj->y) { // out of the screen so end parsing
915 obj->y -= lasth - sub_font->height; // correct the y position
916 break;
918 xsize = tmp_otp->value;
919 obj->params.subtitle.xtbl[xtblc++] = (dxs - xsize) / 2;
920 if (xmin > (dxs - xsize) / 2)
921 xmin = (dxs - xsize) / 2;
922 if (xmax < (dxs + xsize) / 2)
923 xmax = (dxs + xsize) / 2;
925 tmp = (tmp_otp->next == NULL) ? NULL : tmp_otp->next->ott;
926 for (tmp_ott = tmp_otp->ott; tmp_ott != tmp; tmp_ott = tmp_ott->next) {
927 for (counter = 0; counter < tmp_ott->text_length; ++counter) {
928 if (utblc > MAX_UCS) {
929 break;
931 c = tmp_ott->text[counter];
932 render_one_glyph(sub_font, c);
933 obj->params.subtitle.utbl[utblc++] = c;
934 k++;
936 obj->params.subtitle.utbl[utblc++] = ' ';
938 obj->params.subtitle.utbl[utblc - 1] = 0;
939 obj->y -= sub_font->height;
941 if(obj->params.subtitle.lines)
942 obj->y = dys - ((obj->params.subtitle.lines - 1) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h);
944 // free memory
945 if (otp_sub != NULL) {
946 for (tmp = otp_sub->ott; tmp->next != NULL; free(tmp->prev)) {
947 free(tmp->text);
948 tmp = tmp->next;
950 free(tmp->text);
951 free(tmp);
953 for(pmt = otp_sub; pmt->next != NULL; free(pmt->prev)) {
954 pmt = pmt->next;
956 free(pmt);
960 /// vertical alignment
961 h = dys - obj->y;
962 if (sub_alignment == 2)
963 obj->y = dys * sub_pos / 100 - h;
964 else if (sub_alignment == 1)
965 obj->y = dys * sub_pos / 100 - h / 2;
966 else
967 obj->y = dys * sub_pos / 100;
969 if (obj->y < 0)
970 obj->y = 0;
971 if (obj->y > dys - h)
972 obj->y = dys - h;
974 obj->bbox.y2 = obj->y + h;
976 // calculate bbox:
977 if (sub_justify) xmin = 10;
978 obj->bbox.x1=xmin;
979 obj->bbox.x2=xmax;
980 obj->bbox.y1=obj->y;
981 // obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height;
982 obj->flags|=OSDFLAG_BBOX;
984 alloc_buf(obj);
986 y = obj->y;
988 obj->alignment = 0;
989 switch(vo_sub->alignment) {
990 case SUB_ALIGNMENT_BOTTOMLEFT:
991 case SUB_ALIGNMENT_MIDDLELEFT:
992 case SUB_ALIGNMENT_TOPLEFT:
993 obj->alignment |= 0x1;
994 break;
995 case SUB_ALIGNMENT_BOTTOMRIGHT:
996 case SUB_ALIGNMENT_MIDDLERIGHT:
997 case SUB_ALIGNMENT_TOPRIGHT:
998 obj->alignment |= 0x2;
999 break;
1000 case SUB_ALIGNMENT_BOTTOMCENTER:
1001 case SUB_ALIGNMENT_MIDDLECENTER:
1002 case SUB_ALIGNMENT_TOPCENTER:
1003 default:
1004 obj->alignment |= 0x0;
1007 i=j=0;
1008 if ((l = obj->params.subtitle.lines)) {
1009 for(counter = dxs; i < l; ++i)
1010 if (obj->params.subtitle.xtbl[i] < counter) counter = obj->params.subtitle.xtbl[i];
1011 for (i = 0; i < l; ++i) {
1012 switch (obj->alignment&0x3) {
1013 case 1:
1014 // left
1015 x = counter;
1016 break;
1017 case 2:
1018 // right
1019 x = 2 * obj->params.subtitle.xtbl[i] - counter - ((obj->params.subtitle.xtbl[i] == counter) ? 0 : 1);
1020 break;
1021 default:
1022 //center
1023 x = obj->params.subtitle.xtbl[i];
1025 prevc = -1;
1026 while ((c=obj->params.subtitle.utbl[j++])){
1027 x += kerning(sub_font,prevc,c);
1028 if ((font=sub_font->font[c])>=0)
1029 draw_alpha_buf(obj,x,y,
1030 sub_font->width[c],
1031 sub_font->pic_a[font]->h+y<obj->dys ? sub_font->pic_a[font]->h : obj->dys-y,
1032 sub_font->pic_b[font]->bmp+sub_font->start[c],
1033 sub_font->pic_a[font]->bmp+sub_font->start[c],
1034 sub_font->pic_a[font]->w);
1035 x+=sub_font->width[c]+sub_font->charspace;
1036 prevc = c;
1038 y+=sub_font->height;
1044 inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys)
1046 unsigned int bbox[4];
1047 spudec_calc_bbox(vo_spudec, dxs, dys, bbox);
1048 obj->bbox.x1 = bbox[0];
1049 obj->bbox.x2 = bbox[1];
1050 obj->bbox.y1 = bbox[2];
1051 obj->bbox.y2 = bbox[3];
1052 obj->flags |= OSDFLAG_BBOX;
1055 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))
1057 spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha);
1060 void *vo_spudec=NULL;
1061 void *vo_vobsub=NULL;
1063 static int draw_alpha_init_flag=0;
1065 void vo_draw_alpha_init(void);
1067 mp_osd_obj_t* vo_osd_list=NULL;
1069 static mp_osd_obj_t* new_osd_obj(int type){
1070 mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t));
1071 memset(osd,0,sizeof(mp_osd_obj_t));
1072 osd->next=vo_osd_list;
1073 vo_osd_list=osd;
1074 osd->type=type;
1075 osd->alpha_buffer = NULL;
1076 osd->bitmap_buffer = NULL;
1077 osd->allocated = -1;
1078 return osd;
1081 void free_osd_list(void){
1082 mp_osd_obj_t* obj=vo_osd_list;
1083 while(obj){
1084 mp_osd_obj_t* next=obj->next;
1085 if (obj->alpha_buffer) free(obj->alpha_buffer);
1086 if (obj->bitmap_buffer) free(obj->bitmap_buffer);
1087 free(obj);
1088 obj=next;
1090 vo_osd_list=NULL;
1093 #define FONT_LOAD_DEFER 6
1095 int vo_update_osd_ext(int dxs,int dys, int left_border, int top_border,
1096 int right_border, int bottom_border, int orig_w, int orig_h){
1097 mp_osd_obj_t* obj=vo_osd_list;
1098 int chg=0;
1099 #ifdef CONFIG_FREETYPE
1100 static int defer_counter = 0, prev_dxs = 0, prev_dys = 0;
1101 #endif
1103 #ifdef CONFIG_FREETYPE
1104 // here is the right place to get screen dimensions
1105 if (((dxs != vo_image_width)
1106 && (subtitle_autoscale == 2 || subtitle_autoscale == 3))
1107 || ((dys != vo_image_height)
1108 && (subtitle_autoscale == 1 || subtitle_autoscale == 3)))
1110 // screen dimensions changed
1111 // wait a while to avoid useless reloading of the font
1112 if (dxs == prev_dxs || dys == prev_dys) {
1113 defer_counter++;
1114 } else {
1115 prev_dxs = dxs;
1116 prev_dys = dys;
1117 defer_counter = 0;
1119 if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1;
1122 if (force_load_font) {
1123 force_load_font = 0;
1124 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1125 if (sub_font_name)
1126 load_font_ft(dxs, dys, &sub_font, sub_font_name, text_font_scale_factor);
1127 else
1128 load_font_ft(dxs, dys, &sub_font, font_name, text_font_scale_factor);
1129 prev_dxs = dxs;
1130 prev_dys = dys;
1131 defer_counter = 0;
1132 } else {
1133 if (!vo_font)
1134 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1135 if (!sub_font) {
1136 if (sub_font_name)
1137 load_font_ft(dxs, dys, &sub_font, sub_font_name, text_font_scale_factor);
1138 else
1139 load_font_ft(dxs, dys, &sub_font, font_name, text_font_scale_factor);
1142 #endif
1144 while(obj){
1145 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){
1146 int vis=obj->flags&OSDFLAG_VISIBLE;
1147 obj->flags&=~OSDFLAG_BBOX;
1148 switch(obj->type){
1149 #ifdef CONFIG_DVDNAV
1150 case OSDTYPE_DVDNAV:
1151 vo_update_nav(obj,dxs,dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h);
1152 break;
1153 #endif
1154 case OSDTYPE_SUBTITLE:
1155 vo_update_text_sub(obj,dxs,dys);
1156 break;
1157 #ifdef CONFIG_TV_TELETEXT
1158 case OSDTYPE_TELETEXT:
1159 vo_update_text_teletext(obj,dxs,dys);
1160 break;
1161 #endif
1162 case OSDTYPE_PROGBAR:
1163 vo_update_text_progbar(obj,dxs,dys);
1164 break;
1165 case OSDTYPE_SPU:
1166 if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){
1167 vo_update_spudec_sub(obj, dxs, dys);
1168 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1170 else
1171 obj->flags&=~OSDFLAG_VISIBLE;
1172 break;
1173 case OSDTYPE_OSD:
1174 if(vo_font && vo_osd_text && vo_osd_text[0]){
1175 vo_update_text_osd(obj,dxs,dys); // update bbox
1176 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1177 } else
1178 obj->flags&=~OSDFLAG_VISIBLE;
1179 break;
1181 // check bbox:
1182 if(!(obj->flags&OSDFLAG_BBOX)){
1183 // we don't know, so assume the whole screen changed :(
1184 obj->bbox.x1=obj->bbox.y1=0;
1185 obj->bbox.x2=dxs;
1186 obj->bbox.y2=dys;
1187 obj->flags|=OSDFLAG_BBOX;
1188 } else {
1189 // check bbox, reduce it if it's out of bounds (corners):
1190 if(obj->bbox.x1<0) obj->bbox.x1=0;
1191 if(obj->bbox.y1<0) obj->bbox.y1=0;
1192 if(obj->bbox.x2>dxs) obj->bbox.x2=dxs;
1193 if(obj->bbox.y2>dys) obj->bbox.y2=dys;
1194 if(obj->flags&OSDFLAG_VISIBLE)
1195 // debug:
1196 mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n",
1197 obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1,
1198 obj->bbox.y2-obj->bbox.y1);
1200 // check if visibility changed:
1201 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED;
1202 // remove the cause of automatic update:
1203 obj->dxs=dxs; obj->dys=dys;
1204 obj->flags&=~OSDFLAG_FORCE_UPDATE;
1206 if(obj->flags&OSDFLAG_CHANGED){
1207 chg|=1<<obj->type;
1208 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);
1210 obj=obj->next;
1212 return chg;
1215 int vo_update_osd(int dxs, int dys) {
1216 return vo_update_osd_ext(dxs, dys, 0, 0, 0, 0, dxs, dys);
1219 void vo_init_osd(void){
1220 if(!draw_alpha_init_flag){
1221 draw_alpha_init_flag=1;
1222 vo_draw_alpha_init();
1224 if(vo_osd_list) free_osd_list();
1225 // temp hack, should be moved to mplayer/mencoder later
1226 new_osd_obj(OSDTYPE_OSD);
1227 new_osd_obj(OSDTYPE_SUBTITLE);
1228 new_osd_obj(OSDTYPE_PROGBAR);
1229 new_osd_obj(OSDTYPE_SPU);
1230 #ifdef CONFIG_DVDNAV
1231 new_osd_obj(OSDTYPE_DVDNAV);
1232 #endif
1233 #ifdef CONFIG_TV_TELETEXT
1234 new_osd_obj(OSDTYPE_TELETEXT);
1235 #endif
1236 #ifdef CONFIG_FREETYPE
1237 force_load_font = 1;
1238 #endif
1241 int vo_osd_changed_flag=0;
1243 void vo_remove_text(int dxs,int dys,void (*remove)(int x0,int y0, int w,int h)){
1244 mp_osd_obj_t* obj=vo_osd_list;
1245 vo_update_osd(dxs,dys);
1246 while(obj){
1247 if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) &&
1248 (obj->flags&OSDFLAG_OLD_BBOX)){
1249 int w=obj->old_bbox.x2-obj->old_bbox.x1;
1250 int h=obj->old_bbox.y2-obj->old_bbox.y1;
1251 if(w>0 && h>0){
1252 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1253 remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h);
1255 // obj->flags&=~OSDFLAG_OLD_BBOX;
1257 obj=obj->next;
1261 void vo_draw_text_ext(int dxs, int dys, int left_border, int top_border,
1262 int right_border, int bottom_border, int orig_w, int orig_h,
1263 void (*draw_alpha)(int x0, int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)) {
1264 mp_osd_obj_t* obj=vo_osd_list;
1265 vo_update_osd_ext(dxs, dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h);
1266 while(obj){
1267 if(obj->flags&OSDFLAG_VISIBLE){
1268 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1269 switch(obj->type){
1270 case OSDTYPE_SPU:
1271 vo_draw_spudec_sub(obj, draw_alpha); // FIXME
1272 break;
1273 #ifdef CONFIG_DVDNAV
1274 case OSDTYPE_DVDNAV:
1275 #endif
1276 #ifdef CONFIG_TV_TELETEXT
1277 case OSDTYPE_TELETEXT:
1278 #endif
1279 case OSDTYPE_OSD:
1280 case OSDTYPE_SUBTITLE:
1281 case OSDTYPE_PROGBAR:
1282 vo_draw_text_from_buffer(obj,draw_alpha);
1283 break;
1285 obj->old_bbox=obj->bbox;
1286 obj->flags|=OSDFLAG_OLD_BBOX;
1288 obj->flags&=~OSDFLAG_CHANGED;
1289 obj=obj->next;
1293 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)) {
1294 vo_draw_text_ext(dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha);
1297 static int vo_osd_changed_status = 0;
1299 int vo_osd_changed(int new_value)
1301 mp_osd_obj_t* obj=vo_osd_list;
1302 int ret = vo_osd_changed_status;
1303 vo_osd_changed_status = new_value;
1305 while(obj){
1306 if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
1307 obj=obj->next;
1310 return ret;
1313 // BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB
1314 // BBBBBBBBBBBB BBBBBBBBBBBBB
1315 // BBBBBBB
1317 // return TRUE if we have osd in the specified rectangular area:
1318 int vo_osd_check_range_update(int x1,int y1,int x2,int y2){
1319 mp_osd_obj_t* obj=vo_osd_list;
1320 while(obj){
1321 if(obj->flags&OSDFLAG_VISIBLE){
1322 if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) &&
1323 (obj->bbox.y1<=y2 && obj->bbox.y2>=y1) &&
1324 obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1
1325 ) return 1;
1327 obj=obj->next;
1329 return 0;