Merge svn changes up to r30448
[mplayer/glamo.git] / libvo / sub.c
blob3187f935eab639f9cc06d6bae0243daddf6dda9f
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 "talloc.h"
36 #include "mplayer.h"
37 #include "mp_msg.h"
38 #include "help_mp.h"
39 #include "video_out.h"
40 #include "font_load.h"
41 #include "sub.h"
42 #include "spudec.h"
43 #include "libavutil/common.h"
45 #define NEW_SPLITTING
48 // Structures needed for the new splitting algorithm.
49 // osd_text_t contains the single subtitle word.
50 // osd_text_p is used to mark the lines of subtitles
51 struct osd_text_t {
52 int osd_kerning, //kerning with the previous word
53 osd_length, //orizontal length inside the bbox
54 text_length, //number of characters
55 *text; //characters
56 struct osd_text_t *prev,
57 *next;
60 struct osd_text_p {
61 int value;
62 struct osd_text_t *ott;
63 struct osd_text_p *prev,
64 *next;
66 //^
68 char * const sub_osd_names[]={
69 _("Seekbar"),
70 _("Play"),
71 _("Pause"),
72 _("Stop"),
73 _("Rewind"),
74 _("Forward"),
75 _("Clock"),
76 _("Contrast"),
77 _("Saturation"),
78 _("Volume"),
79 _("Brightness"),
80 _("Hue"),
81 _("Balance")
83 char * const sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", "", "" };
85 //static int vo_font_loaded=-1;
86 font_desc_t* vo_font=NULL;
88 void* vo_osd_teletext_page=NULL;
89 int vo_osd_teletext_half = 0;
90 int vo_osd_teletext_mode=0;
91 int vo_osd_teletext_format=0;
92 int vo_osd_teletext_scale=0;
93 int sub_unicode=0;
94 int sub_utf8=0;
95 int sub_pos=100;
96 int sub_width_p=100;
97 int sub_alignment=2; /* 0=top, 1=center, 2=bottom */
98 int sub_visibility=1;
99 int sub_bg_color=0; /* subtitles background color */
100 int sub_bg_alpha=0;
101 int sub_justify=0;
102 #ifdef CONFIG_DVDNAV
103 static nav_highlight_t nav_hl;
104 #endif
106 // return the real height of a char:
107 static inline int get_height(int c,int h){
108 int font;
109 if ((font=vo_font->font[c])>=0)
110 if(h<vo_font->pic_a[font]->h) h=vo_font->pic_a[font]->h;
111 return h;
114 // renders char to a big per-object buffer where alpha and bitmap are separated
115 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)
117 int dststride = obj->stride;
118 int dstskip = obj->stride-w;
119 int srcskip = stride-w;
120 int i, j;
121 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
122 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
123 unsigned char *bs = src;
124 unsigned char *as = srca;
126 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) {
127 fprintf(stderr, "osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n",
128 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2,
129 x0, x0+w, y0, y0+h);
130 return;
133 for (i = 0; i < h; i++) {
134 for (j = 0; j < w; j++, b++, a++, bs++, as++) {
135 if (*b < *bs) *b = *bs;
136 if (*as) {
137 if (*a == 0 || *a > *as) *a = *as;
140 b+= dstskip;
141 a+= dstskip;
142 bs+= srcskip;
143 as+= srcskip;
147 // allocates/enlarges the alpha/bitmap buffer
148 static void alloc_buf(mp_osd_obj_t* obj)
150 int len;
151 if (obj->bbox.x2 < obj->bbox.x1) obj->bbox.x2 = obj->bbox.x1;
152 if (obj->bbox.y2 < obj->bbox.y1) obj->bbox.y2 = obj->bbox.y1;
153 obj->stride = ((obj->bbox.x2-obj->bbox.x1)+7)&(~7);
154 len = obj->stride*(obj->bbox.y2-obj->bbox.y1);
155 if (obj->allocated<len) {
156 obj->allocated = len;
157 free(obj->bitmap_buffer);
158 free(obj->alpha_buffer);
159 obj->bitmap_buffer = (unsigned char *)memalign(16, len);
160 obj->alpha_buffer = (unsigned char *)memalign(16, len);
162 memset(obj->bitmap_buffer, sub_bg_color, len);
163 memset(obj->alpha_buffer, sub_bg_alpha, len);
166 // renders the buffer
167 inline static void vo_draw_text_from_buffer(mp_osd_obj_t* obj,void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx)
169 if (obj->allocated > 0) {
170 draw_alpha(ctx,
171 obj->bbox.x1,obj->bbox.y1,
172 obj->bbox.x2-obj->bbox.x1,
173 obj->bbox.y2-obj->bbox.y1,
174 obj->bitmap_buffer,
175 obj->alpha_buffer,
176 obj->stride);
180 unsigned utf8_get_char(const char **str) {
181 const uint8_t *strp = (const uint8_t *)*str;
182 unsigned c;
183 GET_UTF8(c, *strp++, goto no_utf8;);
184 *str = (const char *)strp;
185 return c;
187 no_utf8:
188 strp = (const uint8_t *)*str;
189 c = *strp++;
190 *str = (const char *)strp;
191 return c;
194 inline static void vo_update_text_osd(struct osd_state *osd, mp_osd_obj_t* obj,
195 int dxs, int dys)
197 const char *cp = osd->osd_text;
198 int x=20;
199 int h=0;
200 int font;
202 obj->bbox.x1=obj->x=x;
203 obj->bbox.y1=obj->y=10;
205 while (*cp){
206 uint16_t c=utf8_get_char(&cp);
207 render_one_glyph(vo_font, c);
208 x+=vo_font->width[c]+vo_font->charspace;
209 h=get_height(c,h);
212 obj->bbox.x2=x-vo_font->charspace;
213 obj->bbox.y2=obj->bbox.y1+h;
214 obj->flags|=OSDFLAG_BBOX;
216 alloc_buf(obj);
218 cp = osd->osd_text;
219 x = obj->x;
220 while (*cp){
221 uint16_t c=utf8_get_char(&cp);
222 if ((font=vo_font->font[c])>=0)
223 draw_alpha_buf(obj,x,obj->y,
224 vo_font->width[c],
225 vo_font->pic_a[font]->h,
226 vo_font->pic_b[font]->bmp+vo_font->start[c],
227 vo_font->pic_a[font]->bmp+vo_font->start[c],
228 vo_font->pic_a[font]->w);
229 x+=vo_font->width[c]+vo_font->charspace;
233 #ifdef CONFIG_DVDNAV
234 void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey) {
235 nav_hl.sx = sx;
236 nav_hl.sy = sy;
237 nav_hl.ex = ex;
238 nav_hl.ey = ey;
241 inline static void vo_update_nav (mp_osd_obj_t *obj, int dxs, int dys, int left_border, int top_border,
242 int right_border, int bottom_border, int orig_w, int orig_h) {
243 int len;
244 int sx = nav_hl.sx, sy = nav_hl.sy;
245 int ex = nav_hl.ex, ey = nav_hl.ey;
246 int scaled_w = dxs - left_border - right_border;
247 int scaled_h = dys - top_border - bottom_border;
248 if (scaled_w != orig_w) {
249 sx = sx * scaled_w / orig_w;
250 ex = ex * scaled_w / orig_w;
252 if (scaled_h != orig_h) {
253 sy = sy * scaled_h / orig_h;
254 ey = ey * scaled_h / orig_h;
256 sx += left_border; ex += left_border;
257 sy += top_border; ey += top_border;
258 sx = FFMIN(FFMAX(sx, 0), dxs);
259 ex = FFMIN(FFMAX(ex, 0), dxs);
260 sy = FFMIN(FFMAX(sy, 0), dys);
261 ey = FFMIN(FFMAX(ey, 0), dys);
263 obj->bbox.x1 = obj->x = sx;
264 obj->bbox.y1 = obj->y = sy;
265 obj->bbox.x2 = ex;
266 obj->bbox.y2 = ey;
268 alloc_buf (obj);
269 len = obj->stride * (obj->bbox.y2 - obj->bbox.y1);
270 memset (obj->bitmap_buffer, OSD_NAV_BOX_ALPHA, len);
271 memset (obj->alpha_buffer, OSD_NAV_BOX_ALPHA, len);
272 obj->flags |= OSDFLAG_BBOX | OSDFLAG_CHANGED;
273 if (obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1)
274 obj->flags |= OSDFLAG_VISIBLE;
276 #endif
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 static const uint8_t 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 #ifdef CONFIG_FREETYPE
358 //very simple teletext font auto scaling
359 if(!vo_osd_teletext_scale && hm*(max_rows+1)>dys){
360 osd_font_scale_factor*=1.0*(dys)/((max_rows+1)*hm);
361 force_load_font=1;
362 vo_osd_teletext_scale=osd_font_scale_factor;
363 obj->flags&=~OSDFLAG_VISIBLE;
364 return;
366 #endif
368 cols=dxs/wm;
369 rows=dys/hm;
371 if(cols>VBI_COLUMNS)
372 cols=VBI_COLUMNS;
373 if(rows>max_rows)
374 rows=max_rows;
375 w=cols*wm-vo_font->charspace;
376 h=rows*hm-vo_font->charspace;
378 if(w<dxs)
379 x0=(dxs-w)/2;
380 else
381 x0=0;
382 if(h<dys)
383 y0=(dys-h)/2;
384 else
385 y0=0;
387 wm12=wm>>1;
388 hm13=(hm+1)/3;
389 hm23=hm13<<1;
391 for(i=0;i<6;i+=2){
392 ax[i+0]=0;
393 aw[i+0]=wm12;
395 ax[i+1]=wm12;
396 aw[i+1]=wm-wm12;
399 for(i=0;i<2;i++){
400 ay[i+0]=0;
401 ah[i+0]=hm13;
403 ay[i+2]=hm13;
404 ah[i+2]=hm-hm23;
406 ay[i+4]=hm-hm13;
407 ah[i+4]=hm13;
410 obj->x = 0;
411 obj->y = 0;
412 obj->bbox.x1 = x0;
413 obj->bbox.y1 = y0;
414 obj->bbox.x2 = x0+w;
415 obj->bbox.y2 = y0+h;
416 obj->flags |= OSDFLAG_BBOX;
417 alloc_buf(obj);
419 for(i=0;i<9;i++)
420 buf[i]=malloc(wm*hm);
422 //alpha
423 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_OPAQUE_INV)
424 color=1;
425 else
426 color=200;
427 memset(buf[8],color,wm*hm);
428 //colors
429 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_TRANSPARENT){
430 for(i=0;i<8;i++){
431 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[i]/255),wm*hm);
433 }else{
434 for(i=0;i<8;i++)
435 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[7-i]/255),wm*hm);
438 y=y0;
439 for(i=0;i<rows;i++){
440 x=x0;
441 for(j=0;j<cols;j++){
442 tc=tdp[(i+start_row)*VBI_COLUMNS+j];
443 if (tc.hidden) { x+=wm; continue;}
444 if(!tc.gfx || (tc.flh && !flashon)){
445 /* Rendering one text character */
446 draw_alpha_buf(obj,x,y,wm,hm,buf[tc.bg],buf[8],wm);
447 if(tc.unicode!=0x20 && tc.unicode!=0x00 && !tc.ctl &&
448 (!tc.flh || flashon) &&
449 (font=vo_font->font[tc.unicode])>=0 && y+hm<dys){
450 tt_draw_alpha_buf(obj,x,y,vo_font->width[tc.unicode],vo_font->height,
451 vo_font->pic_b[font]->bmp+vo_font->start[tc.unicode]-vo_font->charspace*vo_font->pic_a[font]->w,
452 vo_font->pic_b[font]->w,
453 buf[tc.fg][0],buf[tc.bg][0],buf[8][0]);
455 }else{
457 Rendering one graphics character
458 TODO: support for separated graphics symbols (where six rectangles does not touch each other)
460 +--+ +--+ 87654321
461 |01| |12| --------
462 |10| <= |34| <= 00100110 <= 0x26
463 |01| |56|
464 +--+ +--+
466 (0:wm/2) (wm/2:wm-wm/2)
468 ********** *********** (0:hm/3)
469 *** **** **** ****
470 *** 1 **** **** 2 ****
471 *** **** **** ****
472 ********** ***********
473 ********** ***********
475 ********** *********** (hm/3:hm-2*hm/3)
476 ********** ***********
477 *** **** **** ****
478 *** 3 **** **** 4 ****
479 *** **** **** ****
480 ********** ***********
481 ********** ***********
482 ********** ***********
484 ********** *********** (hm-hm/3:hm/3)
485 *** **** **** ****
486 *** 5 **** **** 6 ****
487 *** **** **** ****
488 ********** ***********
489 ********** ***********
492 if(tc.gfx>1){ //separated gfx
493 for(b=0;b<6;b++){
494 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
495 draw_alpha_buf(obj,x+ax[b]+1,y+ay[b]+1,aw[b]-2,ah[b]-2,buf[color],buf[8],wm);
497 //separated gfx (background borders)
498 //vertical
499 draw_alpha_buf(obj,x ,y,1,hm,buf[tc.bg],buf[8],wm);
500 draw_alpha_buf(obj,x+ax[1]-1,y,2,hm,buf[tc.bg],buf[8],wm);
501 draw_alpha_buf(obj,x+ax[1]+aw[1]-1,y,wm-ax[1]-aw[1]+1,hm,buf[tc.bg],buf[8],wm);
502 //horizontal
503 draw_alpha_buf(obj,x,y ,wm,1,buf[tc.bg],buf[8],wm);
504 draw_alpha_buf(obj,x,y+ay[0]+ah[0]-1,wm,2,buf[tc.bg],buf[8],wm);
505 draw_alpha_buf(obj,x,y+ay[2]+ah[2]-1,wm,2,buf[tc.bg],buf[8],wm);
506 draw_alpha_buf(obj,x,y+ay[4]+ah[4]-1,wm,hm-ay[4]-ah[4]+1,buf[tc.bg],buf[8],wm);
507 }else{
508 for(b=0;b<6;b++){
509 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
510 draw_alpha_buf(obj,x+ax[b],y+ay[b],aw[b],ah[b],buf[color],buf[8],wm);
514 x+=wm;
516 y+=hm;
518 for(i=0;i<9;i++)
519 free(buf[i]);
522 int vo_osd_progbar_type=-1;
523 int vo_osd_progbar_value=100; // 0..256
525 // if we have n=256 bars then OSD progbar looks like below
527 // 0 1 2 3 ... 256 <= vo_osd_progbar_value
528 // | | | | |
529 // [ === === === ... === ]
531 // the above schema is rescalled to n=elems bars
533 inline static void vo_update_text_progbar(mp_osd_obj_t* obj,int dxs,int dys){
535 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
537 if(vo_osd_progbar_type<0 || !vo_font){
538 obj->flags&=~OSDFLAG_VISIBLE;
539 return;
542 render_one_glyph(vo_font, OSD_PB_START);
543 render_one_glyph(vo_font, OSD_PB_END);
544 render_one_glyph(vo_font, OSD_PB_0);
545 render_one_glyph(vo_font, OSD_PB_1);
546 render_one_glyph(vo_font, vo_osd_progbar_type);
548 // calculate bbox corners:
549 { int h=0;
550 int y=(dys-vo_font->height)/2;
551 int delimw=vo_font->width[OSD_PB_START]
552 +vo_font->width[OSD_PB_END]
553 +vo_font->charspace;
554 int width=(2*dxs-3*delimw)/3;
555 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
556 int elems=width/charw;
557 int x=(dxs-elems*charw-delimw)/2;
558 int delta = 0;
559 h=get_height(OSD_PB_START,h);
560 h=get_height(OSD_PB_END,h);
561 h=get_height(OSD_PB_0,h);
562 h=get_height(OSD_PB_1,h);
563 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
564 delta = vo_font->width[vo_osd_progbar_type]+vo_font->spacewidth;
565 delta = (x-delta > 0) ? delta : x;
566 h=get_height(vo_osd_progbar_type,h);
568 obj->bbox.x1=obj->x=x;
569 obj->bbox.y1=obj->y=y;
570 obj->bbox.x2=x+width+delimw;
571 obj->bbox.y2=y+h; //vo_font->height;
572 obj->flags|=OSDFLAG_BBOX;
573 obj->params.progbar.elems=elems;
574 obj->bbox.x1-=delta; // space for an icon
577 alloc_buf(obj);
580 int minw = vo_font->width[OSD_PB_START]+vo_font->width[OSD_PB_END]+vo_font->width[OSD_PB_0];
581 if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
582 minw += vo_font->width[vo_osd_progbar_type]+vo_font->charspace+vo_font->spacewidth;
584 if (obj->bbox.x2 - obj->bbox.x1 < minw) return; // space too small, don't render anything
587 // render it:
588 { unsigned char *s;
589 unsigned char *sa;
590 int i,w,h,st,mark;
591 int x=obj->x;
592 int y=obj->y;
593 int c,font;
594 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
595 int elems=obj->params.progbar.elems;
597 if (vo_osd_progbar_value<=0)
598 mark=0;
599 else {
600 int ev=vo_osd_progbar_value*elems;
601 mark=ev>>8;
602 if (ev & 0xFF) mark++;
603 if (mark>elems) mark=elems;
607 // printf("osd.progbar width=%d xpos=%d\n",width,x);
609 c=vo_osd_progbar_type;
610 if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0) {
611 int xp=x-vo_font->width[c]-vo_font->spacewidth;
612 draw_alpha_buf(obj,(xp<0?0:xp),y,
613 vo_font->width[c],
614 vo_font->pic_a[font]->h,
615 vo_font->pic_b[font]->bmp+vo_font->start[c],
616 vo_font->pic_a[font]->bmp+vo_font->start[c],
617 vo_font->pic_a[font]->w);
620 c=OSD_PB_START;
621 if ((font=vo_font->font[c])>=0)
622 draw_alpha_buf(obj,x,y,
623 vo_font->width[c],
624 vo_font->pic_a[font]->h,
625 vo_font->pic_b[font]->bmp+vo_font->start[c],
626 vo_font->pic_a[font]->bmp+vo_font->start[c],
627 vo_font->pic_a[font]->w);
628 x+=vo_font->width[c]+vo_font->charspace;
630 c=OSD_PB_0;
631 if ((font=vo_font->font[c])>=0){
632 w=vo_font->width[c];
633 h=vo_font->pic_a[font]->h;
634 s=vo_font->pic_b[font]->bmp+vo_font->start[c];
635 sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
636 st=vo_font->pic_a[font]->w;
637 if ((i=mark)) do {
638 draw_alpha_buf(obj,x,y,w,h,s,sa,st);
639 x+=charw;
640 } while(--i);
643 c=OSD_PB_1;
644 if ((font=vo_font->font[c])>=0){
645 w=vo_font->width[c];
646 h=vo_font->pic_a[font]->h;
647 s =vo_font->pic_b[font]->bmp+vo_font->start[c];
648 sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
649 st=vo_font->pic_a[font]->w;
650 if ((i=elems-mark)) do {
651 draw_alpha_buf(obj,x,y,w,h,s,sa,st);
652 x+=charw;
653 } while(--i);
656 c=OSD_PB_END;
657 if ((font=vo_font->font[c])>=0)
658 draw_alpha_buf(obj,x,y,
659 vo_font->width[c],
660 vo_font->pic_a[font]->h,
661 vo_font->pic_b[font]->bmp+vo_font->start[c],
662 vo_font->pic_a[font]->bmp+vo_font->start[c],
663 vo_font->pic_a[font]->w);
664 // x+=vo_font->width[c]+vo_font->charspace;
667 // vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF;
671 subtitle* vo_sub=NULL;
673 inline static void vo_update_text_sub(struct osd_state *osd, mp_osd_obj_t* obj,int dxs,int dys){
674 unsigned char *t;
675 int c,i,j,l,x,y,font,prevc,counter;
676 int k;
677 int lastStripPosition;
678 int xsize;
679 int xmin=dxs,xmax=0;
680 int h,lasth;
681 int xtblc, utblc;
682 struct font_desc *sub_font = osd->sub_font;
684 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
686 if(!vo_sub || !osd->sub_font || !sub_visibility || (sub_font->font[40]<0)){
687 obj->flags&=~OSDFLAG_VISIBLE;
688 return;
691 obj->bbox.y2=obj->y=dys;
692 obj->params.subtitle.lines=0;
694 // too long lines divide into a smaller ones
695 i=k=lasth=0;
696 h=sub_font->height;
697 lastStripPosition=-1;
698 l=vo_sub->lines;
701 struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp;
702 struct osd_text_p *otp_sub = NULL, *otp_sub_tmp, // these are used to store the whole sub text osd
703 *otp, *tmp_otp, *pmt; // these are used to manage sub text osd coming from a single sub line
704 int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
706 while (l) {
707 xsize = -sub_font->charspace;
708 l--;
709 t=vo_sub->text[i++];
710 char_position = 0;
711 char_seq = calloc(strlen(t), sizeof(int));
713 prevc = -1;
715 otp = NULL;
716 osl = NULL;
717 x = 1;
719 // reading the subtitle words from vo_sub->text[]
720 while (*t) {
721 if (sub_utf8)
722 c = utf8_get_char(&t);
723 else if ((c = *t++) >= 0x80 && sub_unicode)
724 c = (c<<8) + *t++;
725 if (k==MAX_UCS){
726 t += strlen(t); // end here
727 mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n");
729 if (!c) c++; // avoid UCS 0
730 render_one_glyph(sub_font, c);
732 if (c == ' ') {
733 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
735 if (osl == NULL) {
736 osl = cp_ott = tmp_ott;
737 } else {
738 tmp_ott->prev = cp_ott;
739 cp_ott->next = tmp_ott;
740 tmp_ott->osd_kerning =
741 sub_font->charspace + sub_font->width[' '];
742 cp_ott = tmp_ott;
744 tmp_ott->osd_length = xsize;
745 tmp_ott->text_length = char_position;
746 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
747 for (counter = 0; counter < char_position; ++counter)
748 tmp_ott->text[counter] = char_seq[counter];
749 char_position = 0;
750 xsize = 0;
751 prevc = c;
752 } else {
753 int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_font, prevc, c);
755 if (xsize + delta_xsize <= dxs) {
756 if (!x) x = 1;
757 prevc = c;
758 char_seq[char_position++] = c;
759 xsize += delta_xsize;
760 if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) {
761 if (sub_font->pic_a[font]->h > h) {
762 h = sub_font->pic_a[font]->h;
765 } else {
766 if (x) {
767 mp_msg(MSGT_OSD, MSGL_WARN, "\nSubtitle word '%s' too long!\n", t);
768 x = 0;
772 }// for len (all words from subtitle line read)
774 // osl holds an ordered (as they appear in the lines) chain of the subtitle words
776 struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
778 if (osl == NULL) {
779 osl = cp_ott = tmp_ott;
780 } else {
781 tmp_ott->prev = cp_ott;
782 cp_ott->next = tmp_ott;
783 tmp_ott->osd_kerning =
784 sub_font->charspace + sub_font->width[' '];
785 cp_ott = tmp_ott;
787 tmp_ott->osd_length = xsize;
788 tmp_ott->text_length = char_position;
789 tmp_ott->text = (int *) malloc(char_position * sizeof(int));
790 for (counter = 0; counter < char_position; ++counter)
791 tmp_ott->text[counter] = char_seq[counter];
792 char_position = 0;
793 xsize = -sub_font->charspace;
795 free(char_seq);
797 if (osl != NULL) {
798 int value = 0, exit = 0, minimum = 0;
800 // otp will contain the chain of the osd subtitle lines coming from the single vo_sub line.
801 otp = tmp_otp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
802 tmp_otp->ott = osl;
803 for (tmp_ott = tmp_otp->ott; exit == 0; ) {
804 do {
805 value += tmp_ott->osd_kerning + tmp_ott->osd_length;
806 tmp_ott = tmp_ott->next;
807 } while ((tmp_ott != NULL) && (value + tmp_ott->osd_kerning + tmp_ott->osd_length <= xlimit));
808 if (tmp_ott != NULL) {
809 struct osd_text_p *tmp = (struct osd_text_p *) calloc(1, sizeof(struct osd_text_p));
811 tmp_otp->value = value;
812 tmp_otp->next = tmp;
813 tmp->prev = tmp_otp;
814 tmp_otp = tmp;
815 tmp_otp->ott = tmp_ott;
816 value = -2 * sub_font->charspace - sub_font->width[' '];
817 } else {
818 tmp_otp->value = value;
819 exit = 1;
824 #ifdef NEW_SPLITTING
825 // minimum holds the 'sum of the differences in length among the lines',
826 // a measure of the evenness of the lengths of the lines
827 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
828 pmt = tmp_otp->next;
829 while (pmt != NULL) {
830 minimum += abs(tmp_otp->value - pmt->value);
831 pmt = pmt->next;
835 if (otp->next != NULL) {
836 int mem1, mem2;
837 struct osd_text_p *mem, *hold;
839 exit = 0;
840 // until the last word of a line can be moved to the beginning of following line
841 // reducing the 'sum of the differences in length among the lines', it is done
842 while (exit == 0) {
843 hold = NULL;
844 exit = 1;
845 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
846 pmt = tmp_otp->next;
847 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
848 if (pmt->value + tmp->osd_length + pmt->ott->osd_kerning <= xlimit) {
849 mem1 = tmp_otp->value;
850 mem2 = pmt->value;
851 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
852 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
854 value = 0;
855 for (mem = otp; mem->next != NULL; mem = mem->next) {
856 pmt = mem->next;
857 while (pmt != NULL) {
858 value += abs(mem->value - pmt->value);
859 pmt = pmt->next;
862 if (value < minimum) {
863 minimum = value;
864 hold = tmp_otp;
865 exit = 0;
867 tmp_otp->value = mem1;
868 tmp_otp->next->value = mem2;
871 // merging
872 if (exit == 0) {
873 tmp_otp = hold;
874 pmt = tmp_otp->next;
875 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
876 mem1 = tmp_otp->value;
877 mem2 = pmt->value;
878 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
879 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
880 pmt->ott = tmp;
881 }//~merging
882 }//~while(exit == 0)
883 }//~if(otp->next!=NULL)
884 #endif
886 // adding otp (containing splitted lines) to otp chain
887 if (otp_sub == NULL) {
888 otp_sub = otp;
889 for (otp_sub_tmp = otp_sub; otp_sub_tmp->next != NULL; otp_sub_tmp = otp_sub_tmp->next);
890 } else {
891 //updating ott chain
892 tmp = otp_sub->ott;
893 while (tmp->next != NULL) tmp = tmp->next;
894 tmp->next = otp->ott;
895 otp->ott->prev = tmp;
896 //attaching new subtitle line at the end
897 otp_sub_tmp->next = otp;
898 otp->prev = otp_sub_tmp;
900 otp_sub_tmp = otp_sub_tmp->next;
901 while (otp_sub_tmp->next != NULL);
903 }//~ if(osl != NULL)
904 } // while
906 // write lines into utbl
907 xtblc = 0;
908 utblc = 0;
909 obj->y = dys;
910 obj->params.subtitle.lines = 0;
911 for (tmp_otp = otp_sub; tmp_otp != NULL; tmp_otp = tmp_otp->next) {
913 if ((obj->params.subtitle.lines++) >= MAX_UCSLINES)
914 break;
916 if (h > obj->y) { // out of the screen so end parsing
917 obj->y -= lasth - sub_font->height; // correct the y position
918 break;
920 xsize = tmp_otp->value;
921 obj->params.subtitle.xtbl[xtblc++] = (dxs - xsize) / 2;
922 if (xmin > (dxs - xsize) / 2)
923 xmin = (dxs - xsize) / 2;
924 if (xmax < (dxs + xsize) / 2)
925 xmax = (dxs + xsize) / 2;
927 tmp = (tmp_otp->next == NULL) ? NULL : tmp_otp->next->ott;
928 for (tmp_ott = tmp_otp->ott; tmp_ott != tmp; tmp_ott = tmp_ott->next) {
929 for (counter = 0; counter < tmp_ott->text_length; ++counter) {
930 if (utblc > MAX_UCS) {
931 break;
933 c = tmp_ott->text[counter];
934 render_one_glyph(sub_font, c);
935 obj->params.subtitle.utbl[utblc++] = c;
936 k++;
938 obj->params.subtitle.utbl[utblc++] = ' ';
940 obj->params.subtitle.utbl[utblc - 1] = 0;
941 obj->y -= sub_font->height;
943 if(obj->params.subtitle.lines)
944 obj->y = dys - ((obj->params.subtitle.lines - 1) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h);
946 // free memory
947 if (otp_sub != NULL) {
948 for (tmp = otp_sub->ott; tmp->next != NULL; free(tmp->prev)) {
949 free(tmp->text);
950 tmp = tmp->next;
952 free(tmp->text);
953 free(tmp);
955 for(pmt = otp_sub; pmt->next != NULL; free(pmt->prev)) {
956 pmt = pmt->next;
958 free(pmt);
962 /// vertical alignment
963 h = dys - obj->y;
964 if (sub_alignment == 2)
965 obj->y = dys * sub_pos / 100 - h;
966 else if (sub_alignment == 1)
967 obj->y = dys * sub_pos / 100 - h / 2;
968 else
969 obj->y = dys * sub_pos / 100;
971 if (obj->y < 0)
972 obj->y = 0;
973 if (obj->y > dys - h)
974 obj->y = dys - h;
976 obj->bbox.y2 = obj->y + h;
978 // calculate bbox:
979 if (sub_justify) xmin = 10;
980 obj->bbox.x1=xmin;
981 obj->bbox.x2=xmax;
982 obj->bbox.y1=obj->y;
983 // obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height;
984 obj->flags|=OSDFLAG_BBOX;
986 alloc_buf(obj);
988 y = obj->y;
990 obj->alignment = 0;
991 switch(vo_sub->alignment) {
992 case SUB_ALIGNMENT_BOTTOMLEFT:
993 case SUB_ALIGNMENT_MIDDLELEFT:
994 case SUB_ALIGNMENT_TOPLEFT:
995 obj->alignment |= 0x1;
996 break;
997 case SUB_ALIGNMENT_BOTTOMRIGHT:
998 case SUB_ALIGNMENT_MIDDLERIGHT:
999 case SUB_ALIGNMENT_TOPRIGHT:
1000 obj->alignment |= 0x2;
1001 break;
1002 case SUB_ALIGNMENT_BOTTOMCENTER:
1003 case SUB_ALIGNMENT_MIDDLECENTER:
1004 case SUB_ALIGNMENT_TOPCENTER:
1005 default:
1006 obj->alignment |= 0x0;
1009 i=j=0;
1010 if ((l = obj->params.subtitle.lines)) {
1011 for(counter = dxs; i < l; ++i)
1012 if (obj->params.subtitle.xtbl[i] < counter) counter = obj->params.subtitle.xtbl[i];
1013 for (i = 0; i < l; ++i) {
1014 switch (obj->alignment&0x3) {
1015 case 1:
1016 // left
1017 x = counter;
1018 break;
1019 case 2:
1020 // right
1021 x = 2 * obj->params.subtitle.xtbl[i] - counter - ((obj->params.subtitle.xtbl[i] == counter) ? 0 : 1);
1022 break;
1023 default:
1024 //center
1025 x = obj->params.subtitle.xtbl[i];
1027 prevc = -1;
1028 while ((c=obj->params.subtitle.utbl[j++])){
1029 x += kerning(sub_font,prevc,c);
1030 if ((font=sub_font->font[c])>=0)
1031 draw_alpha_buf(obj,x,y,
1032 sub_font->width[c],
1033 sub_font->pic_a[font]->h+y<obj->dys ? sub_font->pic_a[font]->h : obj->dys-y,
1034 sub_font->pic_b[font]->bmp+sub_font->start[c],
1035 sub_font->pic_a[font]->bmp+sub_font->start[c],
1036 sub_font->pic_a[font]->w);
1037 x+=sub_font->width[c]+sub_font->charspace;
1038 prevc = c;
1040 y+=sub_font->height;
1046 inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys)
1048 unsigned int bbox[4];
1049 spudec_calc_bbox(vo_spudec, dxs, dys, bbox);
1050 obj->bbox.x1 = bbox[0];
1051 obj->bbox.x2 = bbox[1];
1052 obj->bbox.y1 = bbox[2];
1053 obj->bbox.y2 = bbox[3];
1054 obj->flags |= OSDFLAG_BBOX;
1057 inline static void vo_draw_spudec_sub(mp_osd_obj_t* obj, void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h, unsigned char* src, unsigned char* srca, int stride), void *ctx)
1059 spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha, ctx);
1062 void *vo_spudec=NULL;
1063 void *vo_vobsub=NULL;
1065 static int draw_alpha_init_flag=0;
1067 void vo_draw_alpha_init(void);
1069 mp_osd_obj_t* vo_osd_list=NULL;
1071 static mp_osd_obj_t* new_osd_obj(int type){
1072 mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t));
1073 memset(osd,0,sizeof(mp_osd_obj_t));
1074 osd->next=vo_osd_list;
1075 vo_osd_list=osd;
1076 osd->type=type;
1077 osd->alpha_buffer = NULL;
1078 osd->bitmap_buffer = NULL;
1079 osd->allocated = -1;
1080 return osd;
1083 void osd_free(struct osd_state *osd)
1085 mp_osd_obj_t* obj=vo_osd_list;
1086 while(obj){
1087 mp_osd_obj_t* next=obj->next;
1088 if (obj->alpha_buffer) free(obj->alpha_buffer);
1089 if (obj->bitmap_buffer) free(obj->bitmap_buffer);
1090 free(obj);
1091 obj=next;
1093 vo_osd_list=NULL;
1094 talloc_free(osd);
1097 #define FONT_LOAD_DEFER 6
1099 int osd_update_ext(struct osd_state *osd, int dxs, int dys, int left_border,
1100 int top_border, int right_border, int bottom_border,
1101 int orig_w, int orig_h)
1103 mp_osd_obj_t* obj=vo_osd_list;
1104 int chg=0;
1105 #ifdef CONFIG_FREETYPE
1106 static int defer_counter = 0, prev_dxs = 0, prev_dys = 0;
1107 #endif
1109 #ifdef CONFIG_FREETYPE
1110 // here is the right place to get screen dimensions
1111 if (((dxs != vo_image_width)
1112 && (subtitle_autoscale == 2 || subtitle_autoscale == 3))
1113 || ((dys != vo_image_height)
1114 && (subtitle_autoscale == 1 || subtitle_autoscale == 3)))
1116 // screen dimensions changed
1117 // wait a while to avoid useless reloading of the font
1118 if (dxs == prev_dxs || dys == prev_dys) {
1119 defer_counter++;
1120 } else {
1121 prev_dxs = dxs;
1122 prev_dys = dys;
1123 defer_counter = 0;
1125 if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1;
1128 if (force_load_font) {
1129 force_load_font = 0;
1130 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1131 if (sub_font_name)
1132 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1133 else
1134 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1135 prev_dxs = dxs;
1136 prev_dys = dys;
1137 defer_counter = 0;
1138 } else {
1139 if (!vo_font)
1140 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1141 if (!osd->sub_font) {
1142 if (sub_font_name)
1143 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1144 else
1145 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1148 #endif
1150 while(obj){
1151 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){
1152 int vis=obj->flags&OSDFLAG_VISIBLE;
1153 obj->flags&=~OSDFLAG_BBOX;
1154 switch(obj->type){
1155 #ifdef CONFIG_DVDNAV
1156 case OSDTYPE_DVDNAV:
1157 vo_update_nav(obj,dxs,dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h);
1158 break;
1159 #endif
1160 case OSDTYPE_SUBTITLE:
1161 vo_update_text_sub(osd, obj,dxs,dys);
1162 break;
1163 case OSDTYPE_TELETEXT:
1164 vo_update_text_teletext(obj,dxs,dys);
1165 break;
1166 case OSDTYPE_PROGBAR:
1167 vo_update_text_progbar(obj,dxs,dys);
1168 break;
1169 case OSDTYPE_SPU:
1170 if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){
1171 vo_update_spudec_sub(obj, dxs, dys);
1172 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1174 else
1175 obj->flags&=~OSDFLAG_VISIBLE;
1176 break;
1177 case OSDTYPE_OSD:
1178 if(vo_font && osd->osd_text[0]){
1179 vo_update_text_osd(osd, obj, dxs, dys); // update bbox
1180 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1181 } else
1182 obj->flags&=~OSDFLAG_VISIBLE;
1183 break;
1185 // check bbox:
1186 if(!(obj->flags&OSDFLAG_BBOX)){
1187 // we don't know, so assume the whole screen changed :(
1188 obj->bbox.x1=obj->bbox.y1=0;
1189 obj->bbox.x2=dxs;
1190 obj->bbox.y2=dys;
1191 obj->flags|=OSDFLAG_BBOX;
1192 } else {
1193 // check bbox, reduce it if it's out of bounds (corners):
1194 if(obj->bbox.x1<0) obj->bbox.x1=0;
1195 if(obj->bbox.y1<0) obj->bbox.y1=0;
1196 if(obj->bbox.x2>dxs) obj->bbox.x2=dxs;
1197 if(obj->bbox.y2>dys) obj->bbox.y2=dys;
1198 if(obj->flags&OSDFLAG_VISIBLE)
1199 // debug:
1200 mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n",
1201 obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1,
1202 obj->bbox.y2-obj->bbox.y1);
1204 // check if visibility changed:
1205 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED;
1206 // remove the cause of automatic update:
1207 obj->dxs=dxs; obj->dys=dys;
1208 obj->flags&=~OSDFLAG_FORCE_UPDATE;
1210 if(obj->flags&OSDFLAG_CHANGED){
1211 chg|=1<<obj->type;
1212 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);
1214 obj=obj->next;
1216 return chg;
1219 int osd_update(struct osd_state *osd, int dxs, int dys)
1221 return osd_update_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys);
1224 struct osd_state *osd_create(void)
1226 struct osd_state *osd = talloc_zero(NULL, struct osd_state);
1227 *osd = (struct osd_state){
1229 if(!draw_alpha_init_flag){
1230 draw_alpha_init_flag=1;
1231 vo_draw_alpha_init();
1233 // temp hack, should be moved to mplayer/mencoder later
1234 new_osd_obj(OSDTYPE_OSD);
1235 new_osd_obj(OSDTYPE_SUBTITLE);
1236 new_osd_obj(OSDTYPE_PROGBAR);
1237 new_osd_obj(OSDTYPE_SPU);
1238 #ifdef CONFIG_DVDNAV
1239 new_osd_obj(OSDTYPE_DVDNAV);
1240 #endif
1241 new_osd_obj(OSDTYPE_TELETEXT);
1242 #ifdef CONFIG_FREETYPE
1243 force_load_font = 1;
1244 #endif
1245 return osd;
1248 int vo_osd_changed_flag=0;
1250 void osd_remove_text(struct osd_state *osd, int dxs, int dys,
1251 void (*remove)(int x0, int y0, int w, int h))
1253 mp_osd_obj_t* obj=vo_osd_list;
1254 osd_update(osd, dxs, dys);
1255 while(obj){
1256 if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) &&
1257 (obj->flags&OSDFLAG_OLD_BBOX)){
1258 int w=obj->old_bbox.x2-obj->old_bbox.x1;
1259 int h=obj->old_bbox.y2-obj->old_bbox.y1;
1260 if(w>0 && h>0){
1261 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1262 remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h);
1264 // obj->flags&=~OSDFLAG_OLD_BBOX;
1266 obj=obj->next;
1270 void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys,
1271 int left_border, int top_border, int right_border,
1272 int bottom_border, int orig_w, int orig_h,
1273 void (*draw_alpha)(void *ctx, int x0, int y0, int w,
1274 int h, unsigned char* src,
1275 unsigned char *srca,
1276 int stride),
1277 void *ctx)
1279 mp_osd_obj_t* obj=vo_osd_list;
1280 osd_update_ext(osd, dxs, dys, left_border, top_border, right_border,
1281 bottom_border, orig_w, orig_h);
1282 while(obj){
1283 if(obj->flags&OSDFLAG_VISIBLE){
1284 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1285 switch(obj->type){
1286 case OSDTYPE_SPU:
1287 vo_draw_spudec_sub(obj, draw_alpha, ctx); // FIXME
1288 break;
1289 #ifdef CONFIG_DVDNAV
1290 case OSDTYPE_DVDNAV:
1291 #endif
1292 case OSDTYPE_TELETEXT:
1293 case OSDTYPE_OSD:
1294 case OSDTYPE_SUBTITLE:
1295 case OSDTYPE_PROGBAR:
1296 vo_draw_text_from_buffer(obj, draw_alpha, ctx);
1297 break;
1299 obj->old_bbox=obj->bbox;
1300 obj->flags|=OSDFLAG_OLD_BBOX;
1302 obj->flags&=~OSDFLAG_CHANGED;
1303 obj=obj->next;
1307 void osd_draw_text(struct osd_state *osd, int dxs, int dys,
1308 void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h,
1309 unsigned char* src, unsigned char *srca,
1310 int stride),
1311 void *ctx)
1313 osd_draw_text_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha, ctx);
1316 static int vo_osd_changed_status = 0;
1318 int vo_osd_changed(int new_value)
1320 mp_osd_obj_t* obj=vo_osd_list;
1321 int ret = vo_osd_changed_status;
1322 vo_osd_changed_status = new_value;
1324 while(obj){
1325 if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
1326 obj=obj->next;
1329 return ret;
1332 // BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB
1333 // BBBBBBBBBBBB BBBBBBBBBBBBB
1334 // BBBBBBB
1336 // return TRUE if we have osd in the specified rectangular area:
1337 int vo_osd_check_range_update(int x1,int y1,int x2,int y2){
1338 mp_osd_obj_t* obj=vo_osd_list;
1339 while(obj){
1340 if(obj->flags&OSDFLAG_VISIBLE){
1341 if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) &&
1342 (obj->bbox.y1<=y2 && obj->bbox.y2>=y1) &&
1343 obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1
1344 ) return 1;
1346 obj=obj->next;
1348 return 0;