VP6F has to be flipped for binary decoder.
[mplayer/glamo.git] / libvo / sub.c
blobd0abbf30cc35416956adb739c9ba93327fc771c2
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 "libmpcodecs/dec_teletext.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 void* vo_osd_teletext_page=NULL;
90 int vo_osd_teletext_half = 0;
91 int vo_osd_teletext_mode=0;
92 int vo_osd_teletext_format=0;
93 int vo_osd_teletext_scale=0;
94 int sub_unicode=0;
95 int sub_utf8=0;
96 int sub_pos=100;
97 int sub_width_p=100;
98 int sub_alignment=2; /* 0=top, 1=center, 2=bottom */
99 int sub_visibility=1;
100 int sub_bg_color=0; /* subtitles background color */
101 int sub_bg_alpha=0;
102 int sub_justify=0;
103 #ifdef CONFIG_DVDNAV
104 static nav_highlight_t nav_hl;
105 #endif
107 // return the real height of a char:
108 static inline int get_height(int c,int h){
109 int font;
110 if ((font=vo_font->font[c])>=0)
111 if(h<vo_font->pic_a[font]->h) h=vo_font->pic_a[font]->h;
112 return h;
115 // renders char to a big per-object buffer where alpha and bitmap are separated
116 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)
118 int dststride = obj->stride;
119 int dstskip = obj->stride-w;
120 int srcskip = stride-w;
121 int i, j;
122 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
123 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
124 unsigned char *bs = src;
125 unsigned char *as = srca;
127 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) {
128 fprintf(stderr, "osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n",
129 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2,
130 x0, x0+w, y0, y0+h);
131 return;
134 for (i = 0; i < h; i++) {
135 for (j = 0; j < w; j++, b++, a++, bs++, as++) {
136 if (*b < *bs) *b = *bs;
137 if (*as) {
138 if (*a == 0 || *a > *as) *a = *as;
141 b+= dstskip;
142 a+= dstskip;
143 bs+= srcskip;
144 as+= srcskip;
148 // allocates/enlarges the alpha/bitmap buffer
149 static void alloc_buf(mp_osd_obj_t* obj)
151 int len;
152 if (obj->bbox.x2 < obj->bbox.x1) obj->bbox.x2 = obj->bbox.x1;
153 if (obj->bbox.y2 < obj->bbox.y1) obj->bbox.y2 = obj->bbox.y1;
154 obj->stride = ((obj->bbox.x2-obj->bbox.x1)+7)&(~7);
155 len = obj->stride*(obj->bbox.y2-obj->bbox.y1);
156 if (obj->allocated<len) {
157 obj->allocated = len;
158 free(obj->bitmap_buffer);
159 free(obj->alpha_buffer);
160 obj->bitmap_buffer = (unsigned char *)memalign(16, len);
161 obj->alpha_buffer = (unsigned char *)memalign(16, len);
163 memset(obj->bitmap_buffer, sub_bg_color, len);
164 memset(obj->alpha_buffer, sub_bg_alpha, len);
167 // renders the buffer
168 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)){
169 if (obj->allocated > 0) {
170 draw_alpha(obj->bbox.x1,obj->bbox.y1,
171 obj->bbox.x2-obj->bbox.x1,
172 obj->bbox.y2-obj->bbox.y1,
173 obj->bitmap_buffer,
174 obj->alpha_buffer,
175 obj->stride);
179 unsigned utf8_get_char(const char **str) {
180 const uint8_t *strp = (const uint8_t *)*str;
181 unsigned c;
182 GET_UTF8(c, *strp++, goto no_utf8;);
183 *str = (const char *)strp;
184 return c;
186 no_utf8:
187 strp = (const uint8_t *)*str;
188 c = *strp++;
189 *str = (const char *)strp;
190 return c;
193 inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){
194 const char *cp=vo_osd_text;
195 int x=20;
196 int h=0;
197 int font;
199 obj->bbox.x1=obj->x=x;
200 obj->bbox.y1=obj->y=10;
202 while (*cp){
203 uint16_t c=utf8_get_char(&cp);
204 render_one_glyph(vo_font, c);
205 x+=vo_font->width[c]+vo_font->charspace;
206 h=get_height(c,h);
209 obj->bbox.x2=x-vo_font->charspace;
210 obj->bbox.y2=obj->bbox.y1+h;
211 obj->flags|=OSDFLAG_BBOX;
213 alloc_buf(obj);
215 cp=vo_osd_text;
216 x = obj->x;
217 while (*cp){
218 uint16_t c=utf8_get_char(&cp);
219 if ((font=vo_font->font[c])>=0)
220 draw_alpha_buf(obj,x,obj->y,
221 vo_font->width[c],
222 vo_font->pic_a[font]->h,
223 vo_font->pic_b[font]->bmp+vo_font->start[c],
224 vo_font->pic_a[font]->bmp+vo_font->start[c],
225 vo_font->pic_a[font]->w);
226 x+=vo_font->width[c]+vo_font->charspace;
230 #ifdef CONFIG_DVDNAV
231 void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey) {
232 nav_hl.sx = sx;
233 nav_hl.sy = sy;
234 nav_hl.ex = ex;
235 nav_hl.ey = ey;
238 inline static void vo_update_nav (mp_osd_obj_t *obj, int dxs, int dys, int left_border, int top_border,
239 int right_border, int bottom_border, int orig_w, int orig_h) {
240 int len;
241 int sx = nav_hl.sx, sy = nav_hl.sy;
242 int ex = nav_hl.ex, ey = nav_hl.ey;
243 int scaled_w = dxs - left_border - right_border;
244 int scaled_h = dys - top_border - bottom_border;
245 if (scaled_w != orig_w) {
246 sx = sx * scaled_w / orig_w;
247 ex = ex * scaled_w / orig_w;
249 if (scaled_h != orig_h) {
250 sy = sy * scaled_h / orig_h;
251 ey = ey * scaled_h / orig_h;
253 sx += left_border; ex += left_border;
254 sy += top_border; ey += top_border;
255 sx = FFMIN(FFMAX(sx, 0), dxs);
256 ex = FFMIN(FFMAX(ex, 0), dxs);
257 sy = FFMIN(FFMAX(sy, 0), dys);
258 ey = FFMIN(FFMAX(ey, 0), dys);
260 obj->bbox.x1 = obj->x = sx;
261 obj->bbox.y1 = obj->y = sy;
262 obj->bbox.x2 = ex;
263 obj->bbox.y2 = ey;
265 alloc_buf (obj);
266 len = obj->stride * (obj->bbox.y2 - obj->bbox.y1);
267 memset (obj->bitmap_buffer, OSD_NAV_BOX_ALPHA, len);
268 memset (obj->alpha_buffer, OSD_NAV_BOX_ALPHA, len);
269 obj->flags |= OSDFLAG_BBOX | OSDFLAG_CHANGED;
270 if (obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1)
271 obj->flags |= OSDFLAG_VISIBLE;
273 #endif
275 // renders char to a big per-object buffer where alpha and bitmap are separated
276 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)
278 int dststride = obj->stride;
279 int dstskip = obj->stride-w;
280 int srcskip = stride-w;
281 int i, j;
282 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
283 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
284 unsigned char *bs = src;
285 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) {
286 mp_msg(MSGT_OSD,MSGL_ERR,"tt osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n",
287 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2,
288 x0, x0+w, y0, y0+h);
289 return;
291 for (i = 0; i < h; i++) {
292 for (j = 0; j < w; j++, b++, a++, bs++) {
293 *b=(fg-bg)*(*bs)/255+bg;
294 *a=alpha;
296 b+= dstskip;
297 a+= dstskip;
298 bs+= srcskip;
301 inline static void vo_update_text_teletext(mp_osd_obj_t *obj, int dxs, int dys)
303 int h=0,w=0,i,j,font,flashon;
304 int wm,hm;
305 int color;
306 int x,y,x0,y0;
307 int cols,rows;
308 int wm12;
309 int hm13;
310 int hm23;
311 int start_row,max_rows;
312 int b,ax[6],ay[6],aw[6],ah[6];
313 tt_char tc;
314 tt_char* tdp=vo_osd_teletext_page;
315 static const uint8_t colors[8]={1,85,150,226,70,105,179,254};
316 unsigned char* buf[9];
318 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
319 if (!tdp || !vo_osd_teletext_mode) {
320 obj->flags&=~OSDFLAG_VISIBLE;
321 return;
323 flashon=(GetTimer()/1000000)%2;
324 switch(vo_osd_teletext_half){
325 case TT_ZOOM_TOP_HALF:
326 start_row=0;
327 max_rows=VBI_ROWS/2;
328 break;
329 case TT_ZOOM_BOTTOM_HALF:
330 start_row=VBI_ROWS/2;
331 max_rows=VBI_ROWS/2;
332 break;
333 default:
334 start_row=0;
335 max_rows=VBI_ROWS;
336 break;
338 wm=0;
339 for(i=start_row;i<max_rows;i++){
340 for(j=0;j<VBI_COLUMNS;j++){
341 tc=tdp[i*VBI_COLUMNS+j];
342 if(!tc.ctl && !tc.gfx)
344 render_one_glyph(vo_font, tc.unicode);
345 if (wm<vo_font->width[tc.unicode])
346 wm=vo_font->width[tc.unicode];
351 hm=vo_font->height+1;
352 wm=dxs*hm*max_rows/(dys*VBI_COLUMNS);
354 #ifdef CONFIG_FREETYPE
355 //very simple teletext font auto scaling
356 if(!vo_osd_teletext_scale && hm*(max_rows+1)>dys){
357 osd_font_scale_factor*=1.0*(dys)/((max_rows+1)*hm);
358 force_load_font=1;
359 vo_osd_teletext_scale=osd_font_scale_factor;
360 obj->flags&=~OSDFLAG_VISIBLE;
361 return;
363 #endif
365 cols=dxs/wm;
366 rows=dys/hm;
368 if(cols>VBI_COLUMNS)
369 cols=VBI_COLUMNS;
370 if(rows>max_rows)
371 rows=max_rows;
372 w=cols*wm-vo_font->charspace;
373 h=rows*hm-vo_font->charspace;
375 if(w<dxs)
376 x0=(dxs-w)/2;
377 else
378 x0=0;
379 if(h<dys)
380 y0=(dys-h)/2;
381 else
382 y0=0;
384 wm12=wm>>1;
385 hm13=(hm+1)/3;
386 hm23=hm13<<1;
388 for(i=0;i<6;i+=2){
389 ax[i+0]=0;
390 aw[i+0]=wm12;
392 ax[i+1]=wm12;
393 aw[i+1]=wm-wm12;
396 for(i=0;i<2;i++){
397 ay[i+0]=0;
398 ah[i+0]=hm13;
400 ay[i+2]=hm13;
401 ah[i+2]=hm-hm23;
403 ay[i+4]=hm-hm13;
404 ah[i+4]=hm13;
407 obj->x = 0;
408 obj->y = 0;
409 obj->bbox.x1 = x0;
410 obj->bbox.y1 = y0;
411 obj->bbox.x2 = x0+w;
412 obj->bbox.y2 = y0+h;
413 obj->flags |= OSDFLAG_BBOX;
414 alloc_buf(obj);
416 for(i=0;i<9;i++)
417 buf[i]=malloc(wm*hm);
419 //alpha
420 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_OPAQUE_INV)
421 color=1;
422 else
423 color=200;
424 memset(buf[8],color,wm*hm);
425 //colors
426 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_TRANSPARENT){
427 for(i=0;i<8;i++){
428 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[i]/255),wm*hm);
430 }else{
431 for(i=0;i<8;i++)
432 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[7-i]/255),wm*hm);
435 y=y0;
436 for(i=0;i<rows;i++){
437 x=x0;
438 for(j=0;j<cols;j++){
439 tc=tdp[(i+start_row)*VBI_COLUMNS+j];
440 if (tc.hidden) { x+=wm; continue;}
441 if(!tc.gfx || (tc.flh && !flashon)){
442 /* Rendering one text character */
443 draw_alpha_buf(obj,x,y,wm,hm,buf[tc.bg],buf[8],wm);
444 if(tc.unicode!=0x20 && tc.unicode!=0x00 && !tc.ctl &&
445 (!tc.flh || flashon) &&
446 (font=vo_font->font[tc.unicode])>=0 && y+hm<dys){
447 tt_draw_alpha_buf(obj,x,y,vo_font->width[tc.unicode],vo_font->height,
448 vo_font->pic_b[font]->bmp+vo_font->start[tc.unicode]-vo_font->charspace*vo_font->pic_a[font]->w,
449 vo_font->pic_b[font]->w,
450 buf[tc.fg][0],buf[tc.bg][0],buf[8][0]);
452 }else{
454 Rendering one graphics character
455 TODO: support for separated graphics symbols (where six rectangles does not touch each other)
457 +--+ +--+ 87654321
458 |01| |12| --------
459 |10| <= |34| <= 00100110 <= 0x26
460 |01| |56|
461 +--+ +--+
463 (0:wm/2) (wm/2:wm-wm/2)
465 ********** *********** (0:hm/3)
466 *** **** **** ****
467 *** 1 **** **** 2 ****
468 *** **** **** ****
469 ********** ***********
470 ********** ***********
472 ********** *********** (hm/3:hm-2*hm/3)
473 ********** ***********
474 *** **** **** ****
475 *** 3 **** **** 4 ****
476 *** **** **** ****
477 ********** ***********
478 ********** ***********
479 ********** ***********
481 ********** *********** (hm-hm/3:hm/3)
482 *** **** **** ****
483 *** 5 **** **** 6 ****
484 *** **** **** ****
485 ********** ***********
486 ********** ***********
489 if(tc.gfx>1){ //separated gfx
490 for(b=0;b<6;b++){
491 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
492 draw_alpha_buf(obj,x+ax[b]+1,y+ay[b]+1,aw[b]-2,ah[b]-2,buf[color],buf[8],wm);
494 //separated gfx (background borders)
495 //vertical
496 draw_alpha_buf(obj,x ,y,1,hm,buf[tc.bg],buf[8],wm);
497 draw_alpha_buf(obj,x+ax[1]-1,y,2,hm,buf[tc.bg],buf[8],wm);
498 draw_alpha_buf(obj,x+ax[1]+aw[1]-1,y,wm-ax[1]-aw[1]+1,hm,buf[tc.bg],buf[8],wm);
499 //horizontal
500 draw_alpha_buf(obj,x,y ,wm,1,buf[tc.bg],buf[8],wm);
501 draw_alpha_buf(obj,x,y+ay[0]+ah[0]-1,wm,2,buf[tc.bg],buf[8],wm);
502 draw_alpha_buf(obj,x,y+ay[2]+ah[2]-1,wm,2,buf[tc.bg],buf[8],wm);
503 draw_alpha_buf(obj,x,y+ay[4]+ah[4]-1,wm,hm-ay[4]-ah[4]+1,buf[tc.bg],buf[8],wm);
504 }else{
505 for(b=0;b<6;b++){
506 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
507 draw_alpha_buf(obj,x+ax[b],y+ay[b],aw[b],ah[b],buf[color],buf[8],wm);
511 x+=wm;
513 y+=hm;
515 for(i=0;i<9;i++)
516 free(buf[i]);
519 int vo_osd_progbar_type=-1;
520 int vo_osd_progbar_value=100; // 0..256
522 // if we have n=256 bars then OSD progbar looks like below
524 // 0 1 2 3 ... 256 <= vo_osd_progbar_value
525 // | | | | |
526 // [ === === === ... === ]
528 // the above schema is rescalled to n=elems bars
530 inline static void vo_update_text_progbar(mp_osd_obj_t* obj,int dxs,int dys){
532 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
534 if(vo_osd_progbar_type<0 || !vo_font){
535 obj->flags&=~OSDFLAG_VISIBLE;
536 return;
539 render_one_glyph(vo_font, OSD_PB_START);
540 render_one_glyph(vo_font, OSD_PB_END);
541 render_one_glyph(vo_font, OSD_PB_0);
542 render_one_glyph(vo_font, OSD_PB_1);
543 render_one_glyph(vo_font, vo_osd_progbar_type);
545 // calculate bbox corners:
546 { int h=0;
547 int y=(dys-vo_font->height)/2;
548 int delimw=vo_font->width[OSD_PB_START]
549 +vo_font->width[OSD_PB_END]
550 +vo_font->charspace;
551 int width=(2*dxs-3*delimw)/3;
552 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
553 int elems=width/charw;
554 int x=(dxs-elems*charw-delimw)/2;
555 int delta = 0;
556 h=get_height(OSD_PB_START,h);
557 h=get_height(OSD_PB_END,h);
558 h=get_height(OSD_PB_0,h);
559 h=get_height(OSD_PB_1,h);
560 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
561 delta = vo_font->width[vo_osd_progbar_type]+vo_font->spacewidth;
562 delta = (x-delta > 0) ? delta : x;
563 h=get_height(vo_osd_progbar_type,h);
565 obj->bbox.x1=obj->x=x;
566 obj->bbox.y1=obj->y=y;
567 obj->bbox.x2=x+width+delimw;
568 obj->bbox.y2=y+h; //vo_font->height;
569 obj->flags|=OSDFLAG_BBOX;
570 obj->params.progbar.elems=elems;
571 obj->bbox.x1-=delta; // space for an icon
574 alloc_buf(obj);
577 int minw = vo_font->width[OSD_PB_START]+vo_font->width[OSD_PB_END]+vo_font->width[OSD_PB_0];
578 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
579 minw += vo_font->width[vo_osd_progbar_type]+vo_font->charspace+vo_font->spacewidth;
581 if (obj->bbox.x2 - obj->bbox.x1 < minw) return; // space too small, don't render anything
584 // render it:
585 { unsigned char *s;
586 unsigned char *sa;
587 int i,w,h,st,mark;
588 int x=obj->x;
589 int y=obj->y;
590 int c,font;
591 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
592 int elems=obj->params.progbar.elems;
594 if (vo_osd_progbar_value<=0)
595 mark=0;
596 else {
597 int ev=vo_osd_progbar_value*elems;
598 mark=ev>>8;
599 if (ev & 0xFF) mark++;
600 if (mark>elems) mark=elems;
604 // printf("osd.progbar width=%d xpos=%d\n",width,x);
606 c=vo_osd_progbar_type;
607 if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0) {
608 int xp=x-vo_font->width[c]-vo_font->spacewidth;
609 draw_alpha_buf(obj,(xp<0?0:xp),y,
610 vo_font->width[c],
611 vo_font->pic_a[font]->h,
612 vo_font->pic_b[font]->bmp+vo_font->start[c],
613 vo_font->pic_a[font]->bmp+vo_font->start[c],
614 vo_font->pic_a[font]->w);
617 c=OSD_PB_START;
618 if ((font=vo_font->font[c])>=0)
619 draw_alpha_buf(obj,x,y,
620 vo_font->width[c],
621 vo_font->pic_a[font]->h,
622 vo_font->pic_b[font]->bmp+vo_font->start[c],
623 vo_font->pic_a[font]->bmp+vo_font->start[c],
624 vo_font->pic_a[font]->w);
625 x+=vo_font->width[c]+vo_font->charspace;
627 c=OSD_PB_0;
628 if ((font=vo_font->font[c])>=0){
629 w=vo_font->width[c];
630 h=vo_font->pic_a[font]->h;
631 s=vo_font->pic_b[font]->bmp+vo_font->start[c];
632 sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
633 st=vo_font->pic_a[font]->w;
634 if ((i=mark)) do {
635 draw_alpha_buf(obj,x,y,w,h,s,sa,st);
636 x+=charw;
637 } while(--i);
640 c=OSD_PB_1;
641 if ((font=vo_font->font[c])>=0){
642 w=vo_font->width[c];
643 h=vo_font->pic_a[font]->h;
644 s =vo_font->pic_b[font]->bmp+vo_font->start[c];
645 sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
646 st=vo_font->pic_a[font]->w;
647 if ((i=elems-mark)) do {
648 draw_alpha_buf(obj,x,y,w,h,s,sa,st);
649 x+=charw;
650 } while(--i);
653 c=OSD_PB_END;
654 if ((font=vo_font->font[c])>=0)
655 draw_alpha_buf(obj,x,y,
656 vo_font->width[c],
657 vo_font->pic_a[font]->h,
658 vo_font->pic_b[font]->bmp+vo_font->start[c],
659 vo_font->pic_a[font]->bmp+vo_font->start[c],
660 vo_font->pic_a[font]->w);
661 // x+=vo_font->width[c]+vo_font->charspace;
664 // vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF;
668 subtitle* vo_sub=NULL;
670 inline static void vo_update_text_sub(mp_osd_obj_t* obj,int dxs,int dys){
671 unsigned char *t;
672 int c,i,j,l,x,y,font,prevc,counter;
673 int k;
674 int lastStripPosition;
675 int xsize;
676 int xmin=dxs,xmax=0;
677 int h,lasth;
678 int xtblc, utblc;
680 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
682 if(!vo_sub || !sub_font || !sub_visibility || (sub_font->font[40]<0)){
683 obj->flags&=~OSDFLAG_VISIBLE;
684 return;
687 obj->bbox.y2=obj->y=dys;
688 obj->params.subtitle.lines=0;
690 // too long lines divide into a smaller ones
691 i=k=lasth=0;
692 h=sub_font->height;
693 lastStripPosition=-1;
694 l=vo_sub->lines;
697 struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp;
698 struct osd_text_p *otp_sub = NULL, *otp_sub_tmp, // these are used to store the whole sub text osd
699 *otp, *tmp_otp, *pmt; // these are used to manage sub text osd coming from a single sub line
700 int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
702 while (l) {
703 xsize = -sub_font->charspace;
704 l--;
705 t=vo_sub->text[i++];
706 char_position = 0;
707 char_seq = calloc(strlen(t), sizeof(int));
709 prevc = -1;
711 otp = NULL;
712 osl = NULL;
713 x = 1;
715 // reading the subtitle words from vo_sub->text[]
716 while (*t) {
717 if (sub_utf8)
718 c = utf8_get_char(&t);
719 else if ((c = *t++) >= 0x80 && sub_unicode)
720 c = (c<<8) + *t++;
721 if (k==MAX_UCS){
722 t += strlen(t); // end here
723 mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n");
725 if (!c) c++; // avoid UCS 0
726 render_one_glyph(sub_font, c);
728 if (c == ' ') {
729 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
731 if (osl == NULL) {
732 osl = cp_ott = tmp_ott;
733 } else {
734 tmp_ott->prev = cp_ott;
735 cp_ott->next = tmp_ott;
736 tmp_ott->osd_kerning =
737 sub_font->charspace + sub_font->width[' '];
738 cp_ott = tmp_ott;
740 tmp_ott->osd_length = xsize;
741 tmp_ott->text_length = char_position;
742 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
743 for (counter = 0; counter < char_position; ++counter)
744 tmp_ott->text[counter] = char_seq[counter];
745 char_position = 0;
746 xsize = 0;
747 prevc = c;
748 } else {
749 int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_font, prevc, c);
751 if (xsize + delta_xsize <= dxs) {
752 if (!x) x = 1;
753 prevc = c;
754 char_seq[char_position++] = c;
755 xsize += delta_xsize;
756 if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) {
757 if (sub_font->pic_a[font]->h > h) {
758 h = sub_font->pic_a[font]->h;
761 } else {
762 if (x) {
763 mp_msg(MSGT_OSD, MSGL_WARN, "\nSubtitle word '%s' too long!\n", t);
764 x = 0;
768 }// for len (all words from subtitle line read)
770 // osl holds an ordered (as they appear in the lines) chain of the subtitle words
772 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
774 if (osl == NULL) {
775 osl = cp_ott = tmp_ott;
776 } else {
777 tmp_ott->prev = cp_ott;
778 cp_ott->next = tmp_ott;
779 tmp_ott->osd_kerning =
780 sub_font->charspace + sub_font->width[' '];
781 cp_ott = tmp_ott;
783 tmp_ott->osd_length = xsize;
784 tmp_ott->text_length = char_position;
785 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
786 for (counter = 0; counter < char_position; ++counter)
787 tmp_ott->text[counter] = char_seq[counter];
788 char_position = 0;
789 xsize = -sub_font->charspace;
791 free(char_seq);
793 if (osl != NULL) {
794 int value = 0, exit = 0, minimum = 0;
796 // otp will contain the chain of the osd subtitle lines coming from the single vo_sub line.
797 otp = tmp_otp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
798 tmp_otp->ott = osl;
799 for (tmp_ott = tmp_otp->ott; exit == 0; ) {
800 do {
801 value += tmp_ott->osd_kerning + tmp_ott->osd_length;
802 tmp_ott = tmp_ott->next;
803 } while ((tmp_ott != NULL) && (value + tmp_ott->osd_kerning + tmp_ott->osd_length <= xlimit));
804 if (tmp_ott != NULL) {
805 struct osd_text_p *tmp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
807 tmp_otp->value = value;
808 tmp_otp->next = tmp;
809 tmp->prev = tmp_otp;
810 tmp_otp = tmp;
811 tmp_otp->ott = tmp_ott;
812 value = -2 * sub_font->charspace - sub_font->width[' '];
813 } else {
814 tmp_otp->value = value;
815 exit = 1;
820 #ifdef NEW_SPLITTING
821 // minimum holds the 'sum of the differences in length among the lines',
822 // a measure of the evenness of the lengths of the lines
823 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
824 pmt = tmp_otp->next;
825 while (pmt != NULL) {
826 minimum += abs(tmp_otp->value - pmt->value);
827 pmt = pmt->next;
831 if (otp->next != NULL) {
832 int mem1, mem2;
833 struct osd_text_p *mem, *hold;
835 exit = 0;
836 // until the last word of a line can be moved to the beginning of following line
837 // reducing the 'sum of the differences in length among the lines', it is done
838 while (exit == 0) {
839 hold = NULL;
840 exit = 1;
841 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
842 pmt = tmp_otp->next;
843 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
844 if (pmt->value + tmp->osd_length + pmt->ott->osd_kerning <= xlimit) {
845 mem1 = tmp_otp->value;
846 mem2 = pmt->value;
847 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
848 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
850 value = 0;
851 for (mem = otp; mem->next != NULL; mem = mem->next) {
852 pmt = mem->next;
853 while (pmt != NULL) {
854 value += abs(mem->value - pmt->value);
855 pmt = pmt->next;
858 if (value < minimum) {
859 minimum = value;
860 hold = tmp_otp;
861 exit = 0;
863 tmp_otp->value = mem1;
864 tmp_otp->next->value = mem2;
867 // merging
868 if (exit == 0) {
869 tmp_otp = hold;
870 pmt = tmp_otp->next;
871 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
872 mem1 = tmp_otp->value;
873 mem2 = pmt->value;
874 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
875 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
876 pmt->ott = tmp;
877 }//~merging
878 }//~while(exit == 0)
879 }//~if(otp->next!=NULL)
880 #endif
882 // adding otp (containing splitted lines) to otp chain
883 if (otp_sub == NULL) {
884 otp_sub = otp;
885 for (otp_sub_tmp = otp_sub; otp_sub_tmp->next != NULL; otp_sub_tmp = otp_sub_tmp->next);
886 } else {
887 //updating ott chain
888 tmp = otp_sub->ott;
889 while (tmp->next != NULL) tmp = tmp->next;
890 tmp->next = otp->ott;
891 otp->ott->prev = tmp;
892 //attaching new subtitle line at the end
893 otp_sub_tmp->next = otp;
894 otp->prev = otp_sub_tmp;
896 otp_sub_tmp = otp_sub_tmp->next;
897 while (otp_sub_tmp->next != NULL);
899 }//~ if(osl != NULL)
900 } // while
902 // write lines into utbl
903 xtblc = 0;
904 utblc = 0;
905 obj->y = dys;
906 obj->params.subtitle.lines = 0;
907 for (tmp_otp = otp_sub; tmp_otp != NULL; tmp_otp = tmp_otp->next) {
909 if ((obj->params.subtitle.lines++) >= MAX_UCSLINES)
910 break;
912 if (h > obj->y) { // out of the screen so end parsing
913 obj->y -= lasth - sub_font->height; // correct the y position
914 break;
916 xsize = tmp_otp->value;
917 obj->params.subtitle.xtbl[xtblc++] = (dxs - xsize) / 2;
918 if (xmin > (dxs - xsize) / 2)
919 xmin = (dxs - xsize) / 2;
920 if (xmax < (dxs + xsize) / 2)
921 xmax = (dxs + xsize) / 2;
923 tmp = (tmp_otp->next == NULL) ? NULL : tmp_otp->next->ott;
924 for (tmp_ott = tmp_otp->ott; tmp_ott != tmp; tmp_ott = tmp_ott->next) {
925 for (counter = 0; counter < tmp_ott->text_length; ++counter) {
926 if (utblc > MAX_UCS) {
927 break;
929 c = tmp_ott->text[counter];
930 render_one_glyph(sub_font, c);
931 obj->params.subtitle.utbl[utblc++] = c;
932 k++;
934 obj->params.subtitle.utbl[utblc++] = ' ';
936 obj->params.subtitle.utbl[utblc - 1] = 0;
937 obj->y -= sub_font->height;
939 if(obj->params.subtitle.lines)
940 obj->y = dys - ((obj->params.subtitle.lines - 1) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h);
942 // free memory
943 if (otp_sub != NULL) {
944 for (tmp = otp_sub->ott; tmp->next != NULL; free(tmp->prev)) {
945 free(tmp->text);
946 tmp = tmp->next;
948 free(tmp->text);
949 free(tmp);
951 for(pmt = otp_sub; pmt->next != NULL; free(pmt->prev)) {
952 pmt = pmt->next;
954 free(pmt);
958 /// vertical alignment
959 h = dys - obj->y;
960 if (sub_alignment == 2)
961 obj->y = dys * sub_pos / 100 - h;
962 else if (sub_alignment == 1)
963 obj->y = dys * sub_pos / 100 - h / 2;
964 else
965 obj->y = dys * sub_pos / 100;
967 if (obj->y < 0)
968 obj->y = 0;
969 if (obj->y > dys - h)
970 obj->y = dys - h;
972 obj->bbox.y2 = obj->y + h;
974 // calculate bbox:
975 if (sub_justify) xmin = 10;
976 obj->bbox.x1=xmin;
977 obj->bbox.x2=xmax;
978 obj->bbox.y1=obj->y;
979 // obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height;
980 obj->flags|=OSDFLAG_BBOX;
982 alloc_buf(obj);
984 y = obj->y;
986 obj->alignment = 0;
987 switch(vo_sub->alignment) {
988 case SUB_ALIGNMENT_BOTTOMLEFT:
989 case SUB_ALIGNMENT_MIDDLELEFT:
990 case SUB_ALIGNMENT_TOPLEFT:
991 obj->alignment |= 0x1;
992 break;
993 case SUB_ALIGNMENT_BOTTOMRIGHT:
994 case SUB_ALIGNMENT_MIDDLERIGHT:
995 case SUB_ALIGNMENT_TOPRIGHT:
996 obj->alignment |= 0x2;
997 break;
998 case SUB_ALIGNMENT_BOTTOMCENTER:
999 case SUB_ALIGNMENT_MIDDLECENTER:
1000 case SUB_ALIGNMENT_TOPCENTER:
1001 default:
1002 obj->alignment |= 0x0;
1005 i=j=0;
1006 if ((l = obj->params.subtitle.lines)) {
1007 for(counter = dxs; i < l; ++i)
1008 if (obj->params.subtitle.xtbl[i] < counter) counter = obj->params.subtitle.xtbl[i];
1009 for (i = 0; i < l; ++i) {
1010 switch (obj->alignment&0x3) {
1011 case 1:
1012 // left
1013 x = counter;
1014 break;
1015 case 2:
1016 // right
1017 x = 2 * obj->params.subtitle.xtbl[i] - counter - ((obj->params.subtitle.xtbl[i] == counter) ? 0 : 1);
1018 break;
1019 default:
1020 //center
1021 x = obj->params.subtitle.xtbl[i];
1023 prevc = -1;
1024 while ((c=obj->params.subtitle.utbl[j++])){
1025 x += kerning(sub_font,prevc,c);
1026 if ((font=sub_font->font[c])>=0)
1027 draw_alpha_buf(obj,x,y,
1028 sub_font->width[c],
1029 sub_font->pic_a[font]->h+y<obj->dys ? sub_font->pic_a[font]->h : obj->dys-y,
1030 sub_font->pic_b[font]->bmp+sub_font->start[c],
1031 sub_font->pic_a[font]->bmp+sub_font->start[c],
1032 sub_font->pic_a[font]->w);
1033 x+=sub_font->width[c]+sub_font->charspace;
1034 prevc = c;
1036 y+=sub_font->height;
1042 inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys)
1044 unsigned int bbox[4];
1045 spudec_calc_bbox(vo_spudec, dxs, dys, bbox);
1046 obj->bbox.x1 = bbox[0];
1047 obj->bbox.x2 = bbox[1];
1048 obj->bbox.y1 = bbox[2];
1049 obj->bbox.y2 = bbox[3];
1050 obj->flags |= OSDFLAG_BBOX;
1053 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))
1055 spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha);
1058 void *vo_spudec=NULL;
1059 void *vo_vobsub=NULL;
1061 static int draw_alpha_init_flag=0;
1063 void vo_draw_alpha_init(void);
1065 mp_osd_obj_t* vo_osd_list=NULL;
1067 static mp_osd_obj_t* new_osd_obj(int type){
1068 mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t));
1069 memset(osd,0,sizeof(mp_osd_obj_t));
1070 osd->next=vo_osd_list;
1071 vo_osd_list=osd;
1072 osd->type=type;
1073 osd->alpha_buffer = NULL;
1074 osd->bitmap_buffer = NULL;
1075 osd->allocated = -1;
1076 return osd;
1079 void free_osd_list(void){
1080 mp_osd_obj_t* obj=vo_osd_list;
1081 while(obj){
1082 mp_osd_obj_t* next=obj->next;
1083 if (obj->alpha_buffer) free(obj->alpha_buffer);
1084 if (obj->bitmap_buffer) free(obj->bitmap_buffer);
1085 free(obj);
1086 obj=next;
1088 vo_osd_list=NULL;
1091 #define FONT_LOAD_DEFER 6
1093 int vo_update_osd_ext(int dxs,int dys, int left_border, int top_border,
1094 int right_border, int bottom_border, int orig_w, int orig_h){
1095 mp_osd_obj_t* obj=vo_osd_list;
1096 int chg=0;
1097 #ifdef CONFIG_FREETYPE
1098 static int defer_counter = 0, prev_dxs = 0, prev_dys = 0;
1099 #endif
1101 #ifdef CONFIG_FREETYPE
1102 // here is the right place to get screen dimensions
1103 if (((dxs != vo_image_width)
1104 && (subtitle_autoscale == 2 || subtitle_autoscale == 3))
1105 || ((dys != vo_image_height)
1106 && (subtitle_autoscale == 1 || subtitle_autoscale == 3)))
1108 // screen dimensions changed
1109 // wait a while to avoid useless reloading of the font
1110 if (dxs == prev_dxs || dys == prev_dys) {
1111 defer_counter++;
1112 } else {
1113 prev_dxs = dxs;
1114 prev_dys = dys;
1115 defer_counter = 0;
1117 if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1;
1120 if (force_load_font) {
1121 force_load_font = 0;
1122 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1123 if (sub_font_name)
1124 load_font_ft(dxs, dys, &sub_font, sub_font_name, text_font_scale_factor);
1125 else
1126 load_font_ft(dxs, dys, &sub_font, font_name, text_font_scale_factor);
1127 prev_dxs = dxs;
1128 prev_dys = dys;
1129 defer_counter = 0;
1130 } else {
1131 if (!vo_font)
1132 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1133 if (!sub_font) {
1134 if (sub_font_name)
1135 load_font_ft(dxs, dys, &sub_font, sub_font_name, text_font_scale_factor);
1136 else
1137 load_font_ft(dxs, dys, &sub_font, font_name, text_font_scale_factor);
1140 #endif
1142 while(obj){
1143 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){
1144 int vis=obj->flags&OSDFLAG_VISIBLE;
1145 obj->flags&=~OSDFLAG_BBOX;
1146 switch(obj->type){
1147 #ifdef CONFIG_DVDNAV
1148 case OSDTYPE_DVDNAV:
1149 vo_update_nav(obj,dxs,dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h);
1150 break;
1151 #endif
1152 case OSDTYPE_SUBTITLE:
1153 vo_update_text_sub(obj,dxs,dys);
1154 break;
1155 case OSDTYPE_TELETEXT:
1156 vo_update_text_teletext(obj,dxs,dys);
1157 break;
1158 case OSDTYPE_PROGBAR:
1159 vo_update_text_progbar(obj,dxs,dys);
1160 break;
1161 case OSDTYPE_SPU:
1162 if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){
1163 vo_update_spudec_sub(obj, dxs, dys);
1164 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1166 else
1167 obj->flags&=~OSDFLAG_VISIBLE;
1168 break;
1169 case OSDTYPE_OSD:
1170 if(vo_font && vo_osd_text && vo_osd_text[0]){
1171 vo_update_text_osd(obj,dxs,dys); // update bbox
1172 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1173 } else
1174 obj->flags&=~OSDFLAG_VISIBLE;
1175 break;
1177 // check bbox:
1178 if(!(obj->flags&OSDFLAG_BBOX)){
1179 // we don't know, so assume the whole screen changed :(
1180 obj->bbox.x1=obj->bbox.y1=0;
1181 obj->bbox.x2=dxs;
1182 obj->bbox.y2=dys;
1183 obj->flags|=OSDFLAG_BBOX;
1184 } else {
1185 // check bbox, reduce it if it's out of bounds (corners):
1186 if(obj->bbox.x1<0) obj->bbox.x1=0;
1187 if(obj->bbox.y1<0) obj->bbox.y1=0;
1188 if(obj->bbox.x2>dxs) obj->bbox.x2=dxs;
1189 if(obj->bbox.y2>dys) obj->bbox.y2=dys;
1190 if(obj->flags&OSDFLAG_VISIBLE)
1191 // debug:
1192 mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n",
1193 obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1,
1194 obj->bbox.y2-obj->bbox.y1);
1196 // check if visibility changed:
1197 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED;
1198 // remove the cause of automatic update:
1199 obj->dxs=dxs; obj->dys=dys;
1200 obj->flags&=~OSDFLAG_FORCE_UPDATE;
1202 if(obj->flags&OSDFLAG_CHANGED){
1203 chg|=1<<obj->type;
1204 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);
1206 obj=obj->next;
1208 return chg;
1211 int vo_update_osd(int dxs, int dys) {
1212 return vo_update_osd_ext(dxs, dys, 0, 0, 0, 0, dxs, dys);
1215 void vo_init_osd(void){
1216 if(!draw_alpha_init_flag){
1217 draw_alpha_init_flag=1;
1218 vo_draw_alpha_init();
1220 if(vo_osd_list) free_osd_list();
1221 // temp hack, should be moved to mplayer/mencoder later
1222 new_osd_obj(OSDTYPE_OSD);
1223 new_osd_obj(OSDTYPE_SUBTITLE);
1224 new_osd_obj(OSDTYPE_PROGBAR);
1225 new_osd_obj(OSDTYPE_SPU);
1226 #ifdef CONFIG_DVDNAV
1227 new_osd_obj(OSDTYPE_DVDNAV);
1228 #endif
1229 new_osd_obj(OSDTYPE_TELETEXT);
1230 #ifdef CONFIG_FREETYPE
1231 force_load_font = 1;
1232 #endif
1235 int vo_osd_changed_flag=0;
1237 void vo_remove_text(int dxs,int dys,void (*remove)(int x0,int y0, int w,int h)){
1238 mp_osd_obj_t* obj=vo_osd_list;
1239 vo_update_osd(dxs,dys);
1240 while(obj){
1241 if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) &&
1242 (obj->flags&OSDFLAG_OLD_BBOX)){
1243 int w=obj->old_bbox.x2-obj->old_bbox.x1;
1244 int h=obj->old_bbox.y2-obj->old_bbox.y1;
1245 if(w>0 && h>0){
1246 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1247 remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h);
1249 // obj->flags&=~OSDFLAG_OLD_BBOX;
1251 obj=obj->next;
1255 void vo_draw_text_ext(int dxs, int dys, int left_border, int top_border,
1256 int right_border, int bottom_border, int orig_w, int orig_h,
1257 void (*draw_alpha)(int x0, int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)) {
1258 mp_osd_obj_t* obj=vo_osd_list;
1259 vo_update_osd_ext(dxs, dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h);
1260 while(obj){
1261 if(obj->flags&OSDFLAG_VISIBLE){
1262 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1263 switch(obj->type){
1264 case OSDTYPE_SPU:
1265 vo_draw_spudec_sub(obj, draw_alpha); // FIXME
1266 break;
1267 #ifdef CONFIG_DVDNAV
1268 case OSDTYPE_DVDNAV:
1269 #endif
1270 case OSDTYPE_TELETEXT:
1271 case OSDTYPE_OSD:
1272 case OSDTYPE_SUBTITLE:
1273 case OSDTYPE_PROGBAR:
1274 vo_draw_text_from_buffer(obj,draw_alpha);
1275 break;
1277 obj->old_bbox=obj->bbox;
1278 obj->flags|=OSDFLAG_OLD_BBOX;
1280 obj->flags&=~OSDFLAG_CHANGED;
1281 obj=obj->next;
1285 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)) {
1286 vo_draw_text_ext(dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha);
1289 static int vo_osd_changed_status = 0;
1291 int vo_osd_changed(int new_value)
1293 mp_osd_obj_t* obj=vo_osd_list;
1294 int ret = vo_osd_changed_status;
1295 vo_osd_changed_status = new_value;
1297 while(obj){
1298 if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
1299 obj=obj->next;
1302 return ret;
1305 // BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB
1306 // BBBBBBBBBBBB BBBBBBBBBBBBB
1307 // BBBBBBB
1309 // return TRUE if we have osd in the specified rectangular area:
1310 int vo_osd_check_range_update(int x1,int y1,int x2,int y2){
1311 mp_osd_obj_t* obj=vo_osd_list;
1312 while(obj){
1313 if(obj->flags&OSDFLAG_VISIBLE){
1314 if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) &&
1315 (obj->bbox.y1<=y2 && obj->bbox.y2>=y1) &&
1316 obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1
1317 ) return 1;
1319 obj=obj->next;
1321 return 0;