cleanup: shut up more warnings
[mplayer/greg.git] / sub / sub.c
blob880793373cae2190d65113a491e4322600ec121a
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 "libvo/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 * const sub_osd_names[]={
68 _("Seekbar"),
69 _("Play"),
70 _("Pause"),
71 _("Stop"),
72 _("Rewind"),
73 _("Forward"),
74 _("Clock"),
75 _("Contrast"),
76 _("Saturation"),
77 _("Volume"),
78 _("Brightness"),
79 _("Hue"),
80 _("Balance")
82 char * const sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", "", "" };
84 //static int vo_font_loaded=-1;
85 font_desc_t* vo_font=NULL;
87 void* vo_osd_teletext_page=NULL;
88 int vo_osd_teletext_half = 0;
89 int vo_osd_teletext_mode=0;
90 int vo_osd_teletext_format=0;
91 int vo_osd_teletext_scale=0;
92 int sub_unicode=0;
93 int sub_utf8=0;
94 int sub_pos=100;
95 int sub_width_p=100;
96 int sub_alignment=2; /* 0=top, 1=center, 2=bottom */
97 int sub_visibility=1;
98 int sub_bg_color=0; /* subtitles background color */
99 int sub_bg_alpha=0;
100 int sub_justify=0;
101 #ifdef CONFIG_DVDNAV
102 static nav_highlight_t nav_hl;
103 #endif
105 // return the real height of a char:
106 static inline int get_height(int c,int h){
107 int font;
108 if ((font=vo_font->font[c])>=0)
109 if(h<vo_font->pic_a[font]->h) h=vo_font->pic_a[font]->h;
110 return h;
113 // renders char to a big per-object buffer where alpha and bitmap are separated
114 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)
116 int dststride = obj->stride;
117 int dstskip = obj->stride-w;
118 int srcskip = stride-w;
119 int i, j;
120 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
121 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
122 unsigned char *bs = src;
123 unsigned char *as = srca;
125 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) {
126 fprintf(stderr, "osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n",
127 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2,
128 x0, x0+w, y0, y0+h);
129 return;
132 for (i = 0; i < h; i++) {
133 for (j = 0; j < w; j++, b++, a++, bs++, as++) {
134 if (*b < *bs) *b = *bs;
135 if (*as) {
136 if (*a == 0 || *a > *as) *a = *as;
139 b+= dstskip;
140 a+= dstskip;
141 bs+= srcskip;
142 as+= srcskip;
146 // allocates/enlarges the alpha/bitmap buffer
147 static void alloc_buf(mp_osd_obj_t* obj)
149 int len;
150 if (obj->bbox.x2 < obj->bbox.x1) obj->bbox.x2 = obj->bbox.x1;
151 if (obj->bbox.y2 < obj->bbox.y1) obj->bbox.y2 = obj->bbox.y1;
152 obj->stride = ((obj->bbox.x2-obj->bbox.x1)+7)&(~7);
153 len = obj->stride*(obj->bbox.y2-obj->bbox.y1);
154 if (obj->allocated<len) {
155 obj->allocated = len;
156 free(obj->bitmap_buffer);
157 free(obj->alpha_buffer);
158 obj->bitmap_buffer = memalign(16, len);
159 obj->alpha_buffer = memalign(16, len);
161 memset(obj->bitmap_buffer, sub_bg_color, len);
162 memset(obj->alpha_buffer, sub_bg_alpha, len);
165 // renders the buffer
166 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)
168 if (obj->allocated > 0) {
169 draw_alpha(ctx,
170 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(struct osd_state *osd, mp_osd_obj_t* obj,
194 int dxs, int dys)
196 const char *cp = osd->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 = osd->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 // renders char to a big per-object buffer where alpha and bitmap are separated
278 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)
280 int dststride = obj->stride;
281 int dstskip = obj->stride-w;
282 int srcskip = stride-w;
283 int i, j;
284 unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
285 unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
286 unsigned char *bs = src;
287 if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) {
288 mp_msg(MSGT_OSD,MSGL_ERR,"tt osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n",
289 obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2,
290 x0, x0+w, y0, y0+h);
291 return;
293 for (i = 0; i < h; i++) {
294 for (j = 0; j < w; j++, b++, a++, bs++) {
295 *b=(fg-bg)*(*bs)/255+bg;
296 *a=alpha;
298 b+= dstskip;
299 a+= dstskip;
300 bs+= srcskip;
303 inline static void vo_update_text_teletext(mp_osd_obj_t *obj, int dxs, int dys)
305 int h=0,w=0,i,j,font,flashon;
306 int wm,hm;
307 int color;
308 int x,y,x0,y0;
309 int cols,rows;
310 int wm12;
311 int hm13;
312 int hm23;
313 int start_row,max_rows;
314 int b,ax[6],ay[6],aw[6],ah[6];
315 tt_char tc;
316 tt_char* tdp=vo_osd_teletext_page;
317 static const uint8_t colors[8]={1,85,150,226,70,105,179,254};
318 unsigned char* buf[9];
320 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
321 if (!tdp || !vo_osd_teletext_mode) {
322 obj->flags&=~OSDFLAG_VISIBLE;
323 return;
325 flashon=(GetTimer()/1000000)%2;
326 switch(vo_osd_teletext_half){
327 case TT_ZOOM_TOP_HALF:
328 start_row=0;
329 max_rows=VBI_ROWS/2;
330 break;
331 case TT_ZOOM_BOTTOM_HALF:
332 start_row=VBI_ROWS/2;
333 max_rows=VBI_ROWS/2;
334 break;
335 default:
336 start_row=0;
337 max_rows=VBI_ROWS;
338 break;
340 wm=0;
341 for(i=start_row;i<max_rows;i++){
342 for(j=0;j<VBI_COLUMNS;j++){
343 tc=tdp[i*VBI_COLUMNS+j];
344 if(!tc.ctl && !tc.gfx)
346 render_one_glyph(vo_font, tc.unicode);
347 if (wm<vo_font->width[tc.unicode])
348 wm=vo_font->width[tc.unicode];
353 hm=vo_font->height+1;
354 wm=dxs*hm*max_rows/(dys*VBI_COLUMNS);
356 #ifdef CONFIG_FREETYPE
357 //very simple teletext font auto scaling
358 if(!vo_osd_teletext_scale && hm*(max_rows+1)>dys){
359 osd_font_scale_factor*=1.0*(dys)/((max_rows+1)*hm);
360 force_load_font=1;
361 vo_osd_teletext_scale=osd_font_scale_factor;
362 obj->flags&=~OSDFLAG_VISIBLE;
363 return;
365 #endif
367 cols=dxs/wm;
368 rows=dys/hm;
370 if(cols>VBI_COLUMNS)
371 cols=VBI_COLUMNS;
372 if(rows>max_rows)
373 rows=max_rows;
374 w=cols*wm-vo_font->charspace;
375 h=rows*hm-vo_font->charspace;
377 if(w<dxs)
378 x0=(dxs-w)/2;
379 else
380 x0=0;
381 if(h<dys)
382 y0=(dys-h)/2;
383 else
384 y0=0;
386 wm12=wm>>1;
387 hm13=(hm+1)/3;
388 hm23=hm13<<1;
390 for(i=0;i<6;i+=2){
391 ax[i+0]=0;
392 aw[i+0]=wm12;
394 ax[i+1]=wm12;
395 aw[i+1]=wm-wm12;
398 for(i=0;i<2;i++){
399 ay[i+0]=0;
400 ah[i+0]=hm13;
402 ay[i+2]=hm13;
403 ah[i+2]=hm-hm23;
405 ay[i+4]=hm-hm13;
406 ah[i+4]=hm13;
409 obj->x = 0;
410 obj->y = 0;
411 obj->bbox.x1 = x0;
412 obj->bbox.y1 = y0;
413 obj->bbox.x2 = x0+w;
414 obj->bbox.y2 = y0+h;
415 obj->flags |= OSDFLAG_BBOX;
416 alloc_buf(obj);
418 for(i=0;i<9;i++)
419 buf[i]=malloc(wm*hm);
421 //alpha
422 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_OPAQUE_INV)
423 color=1;
424 else
425 color=200;
426 memset(buf[8],color,wm*hm);
427 //colors
428 if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_TRANSPARENT){
429 for(i=0;i<8;i++){
430 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[i]/255),wm*hm);
432 }else{
433 for(i=0;i<8;i++)
434 memset(buf[i],(unsigned char)(1.0*(255-color)*colors[7-i]/255),wm*hm);
437 y=y0;
438 for(i=0;i<rows;i++){
439 x=x0;
440 for(j=0;j<cols;j++){
441 tc=tdp[(i+start_row)*VBI_COLUMNS+j];
442 if (tc.hidden) { x+=wm; continue;}
443 if(!tc.gfx || (tc.flh && !flashon)){
444 /* Rendering one text character */
445 draw_alpha_buf(obj,x,y,wm,hm,buf[tc.bg],buf[8],wm);
446 if(tc.unicode!=0x20 && tc.unicode!=0x00 && !tc.ctl &&
447 (!tc.flh || flashon) &&
448 (font=vo_font->font[tc.unicode])>=0 && y+hm<dys){
449 tt_draw_alpha_buf(obj,x,y,vo_font->width[tc.unicode],vo_font->height,
450 vo_font->pic_b[font]->bmp+vo_font->start[tc.unicode]-vo_font->charspace*vo_font->pic_a[font]->w,
451 vo_font->pic_b[font]->w,
452 buf[tc.fg][0],buf[tc.bg][0],buf[8][0]);
454 }else{
456 Rendering one graphics character
457 TODO: support for separated graphics symbols (where six rectangles does not touch each other)
459 +--+ +--+ 87654321
460 |01| |12| --------
461 |10| <= |34| <= 00100110 <= 0x26
462 |01| |56|
463 +--+ +--+
465 (0:wm/2) (wm/2:wm-wm/2)
467 ********** *********** (0:hm/3)
468 *** **** **** ****
469 *** 1 **** **** 2 ****
470 *** **** **** ****
471 ********** ***********
472 ********** ***********
474 ********** *********** (hm/3:hm-2*hm/3)
475 ********** ***********
476 *** **** **** ****
477 *** 3 **** **** 4 ****
478 *** **** **** ****
479 ********** ***********
480 ********** ***********
481 ********** ***********
483 ********** *********** (hm-hm/3:hm/3)
484 *** **** **** ****
485 *** 5 **** **** 6 ****
486 *** **** **** ****
487 ********** ***********
488 ********** ***********
491 if(tc.gfx>1){ //separated gfx
492 for(b=0;b<6;b++){
493 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
494 draw_alpha_buf(obj,x+ax[b]+1,y+ay[b]+1,aw[b]-2,ah[b]-2,buf[color],buf[8],wm);
496 //separated gfx (background borders)
497 //vertical
498 draw_alpha_buf(obj,x ,y,1,hm,buf[tc.bg],buf[8],wm);
499 draw_alpha_buf(obj,x+ax[1]-1,y,2,hm,buf[tc.bg],buf[8],wm);
500 draw_alpha_buf(obj,x+ax[1]+aw[1]-1,y,wm-ax[1]-aw[1]+1,hm,buf[tc.bg],buf[8],wm);
501 //horizontal
502 draw_alpha_buf(obj,x,y ,wm,1,buf[tc.bg],buf[8],wm);
503 draw_alpha_buf(obj,x,y+ay[0]+ah[0]-1,wm,2,buf[tc.bg],buf[8],wm);
504 draw_alpha_buf(obj,x,y+ay[2]+ah[2]-1,wm,2,buf[tc.bg],buf[8],wm);
505 draw_alpha_buf(obj,x,y+ay[4]+ah[4]-1,wm,hm-ay[4]-ah[4]+1,buf[tc.bg],buf[8],wm);
506 }else{
507 for(b=0;b<6;b++){
508 color=(tc.unicode>>b)&1?tc.fg:tc.bg;
509 draw_alpha_buf(obj,x+ax[b],y+ay[b],aw[b],ah[b],buf[color],buf[8],wm);
513 x+=wm;
515 y+=hm;
517 for(i=0;i<9;i++)
518 free(buf[i]);
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(struct osd_state *osd, 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 xsize;
677 int xmin=dxs,xmax=0;
678 int h,lasth;
679 int xtblc, utblc;
680 struct font_desc *sub_font = osd->sub_font;
682 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
684 if(!vo_sub || !osd->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 l=vo_sub->lines;
698 struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp;
699 struct osd_text_p *otp_sub = NULL, *otp_sub_tmp = NULL, // these are used to store the whole sub text osd
700 *otp, *tmp_otp, *pmt; // these are used to manage sub text osd coming from a single sub line
701 int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
703 while (l) {
704 xsize = -sub_font->charspace;
705 l--;
706 t=vo_sub->text[i++];
707 char_position = 0;
708 char_seq = calloc(strlen(t), sizeof(int));
710 prevc = -1;
712 otp = NULL;
713 osl = NULL;
714 x = 1;
716 // reading the subtitle words from vo_sub->text[]
717 while (*t) {
718 if (sub_utf8)
719 c = utf8_get_char((const char **)&t);
720 else if ((c = *t++) >= 0x80 && sub_unicode)
721 c = (c<<8) + *t++;
722 if (k==MAX_UCS){
723 t += strlen(t); // end here
724 mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n");
726 if (!c) c++; // avoid UCS 0
727 render_one_glyph(sub_font, c);
729 if (c == ' ') {
730 struct osd_text_t *tmp_ott = calloc(1, sizeof(struct osd_text_t));
732 if (osl == NULL) {
733 osl = cp_ott = tmp_ott;
734 } else {
735 tmp_ott->prev = cp_ott;
736 cp_ott->next = tmp_ott;
737 tmp_ott->osd_kerning =
738 sub_font->charspace + sub_font->width[' '];
739 cp_ott = tmp_ott;
741 tmp_ott->osd_length = xsize;
742 tmp_ott->text_length = char_position;
743 tmp_ott->text = malloc(char_position * sizeof(int));
744 for (counter = 0; counter < char_position; ++counter)
745 tmp_ott->text[counter] = char_seq[counter];
746 char_position = 0;
747 xsize = 0;
748 prevc = c;
749 } else {
750 int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_font, prevc, c);
752 if (xsize + delta_xsize <= dxs) {
753 if (!x) x = 1;
754 prevc = c;
755 char_seq[char_position++] = c;
756 xsize += delta_xsize;
757 if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) {
758 if (sub_font->pic_a[font]->h > h) {
759 h = sub_font->pic_a[font]->h;
762 } else {
763 if (x) {
764 mp_msg(MSGT_OSD, MSGL_WARN, "\nSubtitle word '%s' too long!\n", t);
765 x = 0;
769 }// for len (all words from subtitle line read)
771 // osl holds an ordered (as they appear in the lines) chain of the subtitle words
773 struct osd_text_t *tmp_ott = calloc(1, sizeof(struct osd_text_t));
775 if (osl == NULL) {
776 osl = cp_ott = tmp_ott;
777 } else {
778 tmp_ott->prev = cp_ott;
779 cp_ott->next = tmp_ott;
780 tmp_ott->osd_kerning =
781 sub_font->charspace + sub_font->width[' '];
782 cp_ott = tmp_ott;
784 tmp_ott->osd_length = xsize;
785 tmp_ott->text_length = char_position;
786 tmp_ott->text = malloc(char_position * sizeof(int));
787 for (counter = 0; counter < char_position; ++counter)
788 tmp_ott->text[counter] = char_seq[counter];
789 char_position = 0;
790 xsize = -sub_font->charspace;
792 free(char_seq);
794 if (osl != NULL) {
795 int value = 0, exit = 0, minimum = 0;
797 // otp will contain the chain of the osd subtitle lines coming from the single vo_sub line.
798 otp = tmp_otp = calloc(1, sizeof(struct osd_text_p));
799 tmp_otp->ott = osl;
800 for (tmp_ott = tmp_otp->ott; exit == 0; ) {
801 do {
802 value += tmp_ott->osd_kerning + tmp_ott->osd_length;
803 tmp_ott = tmp_ott->next;
804 } while ((tmp_ott != NULL) && (value + tmp_ott->osd_kerning + tmp_ott->osd_length <= xlimit));
805 if (tmp_ott != NULL) {
806 struct osd_text_p *tmp = calloc(1, sizeof(struct osd_text_p));
808 tmp_otp->value = value;
809 tmp_otp->next = tmp;
810 tmp->prev = tmp_otp;
811 tmp_otp = tmp;
812 tmp_otp->ott = tmp_ott;
813 value = -2 * sub_font->charspace - sub_font->width[' '];
814 } else {
815 tmp_otp->value = value;
816 exit = 1;
821 #ifdef NEW_SPLITTING
822 // minimum holds the 'sum of the differences in length among the lines',
823 // a measure of the evenness of the lengths of the lines
824 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
825 pmt = tmp_otp->next;
826 while (pmt != NULL) {
827 minimum += abs(tmp_otp->value - pmt->value);
828 pmt = pmt->next;
832 if (otp->next != NULL) {
833 int mem1, mem2;
834 struct osd_text_p *mem, *hold;
836 exit = 0;
837 // until the last word of a line can be moved to the beginning of following line
838 // reducing the 'sum of the differences in length among the lines', it is done
839 while (exit == 0) {
840 hold = NULL;
841 exit = 1;
842 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
843 pmt = tmp_otp->next;
844 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
845 if (pmt->value + tmp->osd_length + pmt->ott->osd_kerning <= xlimit) {
846 mem1 = tmp_otp->value;
847 mem2 = pmt->value;
848 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
849 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
851 value = 0;
852 for (mem = otp; mem->next != NULL; mem = mem->next) {
853 pmt = mem->next;
854 while (pmt != NULL) {
855 value += abs(mem->value - pmt->value);
856 pmt = pmt->next;
859 if (value < minimum) {
860 minimum = value;
861 hold = tmp_otp;
862 exit = 0;
864 tmp_otp->value = mem1;
865 tmp_otp->next->value = mem2;
868 // merging
869 if (exit == 0) {
870 tmp_otp = hold;
871 pmt = tmp_otp->next;
872 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
873 mem1 = tmp_otp->value;
874 mem2 = pmt->value;
875 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
876 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
877 pmt->ott = tmp;
878 }//~merging
879 }//~while(exit == 0)
880 }//~if(otp->next!=NULL)
881 #endif
883 // adding otp (containing splitted lines) to otp chain
884 if (otp_sub == NULL) {
885 otp_sub = otp;
886 for (otp_sub_tmp = otp_sub; otp_sub_tmp->next != NULL; otp_sub_tmp = otp_sub_tmp->next);
887 } else {
888 //updating ott chain
889 tmp = otp_sub->ott;
890 while (tmp->next != NULL) tmp = tmp->next;
891 tmp->next = otp->ott;
892 otp->ott->prev = tmp;
893 //attaching new subtitle line at the end
894 otp_sub_tmp->next = otp;
895 otp->prev = otp_sub_tmp;
897 otp_sub_tmp = otp_sub_tmp->next;
898 while (otp_sub_tmp->next != NULL);
900 }//~ if(osl != NULL)
901 } // while
903 // write lines into utbl
904 xtblc = 0;
905 utblc = 0;
906 obj->y = dys;
907 obj->params.subtitle.lines = 0;
908 for (tmp_otp = otp_sub; tmp_otp != NULL; tmp_otp = tmp_otp->next) {
910 if ((obj->params.subtitle.lines++) >= MAX_UCSLINES)
911 break;
913 if (h > obj->y) { // out of the screen so end parsing
914 obj->y -= lasth - sub_font->height; // correct the y position
915 break;
917 xsize = tmp_otp->value;
918 obj->params.subtitle.xtbl[xtblc++] = (dxs - xsize) / 2;
919 if (xmin > (dxs - xsize) / 2)
920 xmin = (dxs - xsize) / 2;
921 if (xmax < (dxs + xsize) / 2)
922 xmax = (dxs + xsize) / 2;
924 tmp = (tmp_otp->next == NULL) ? NULL : tmp_otp->next->ott;
925 for (tmp_ott = tmp_otp->ott; tmp_ott != tmp; tmp_ott = tmp_ott->next) {
926 for (counter = 0; counter < tmp_ott->text_length; ++counter) {
927 if (utblc > MAX_UCS) {
928 break;
930 c = tmp_ott->text[counter];
931 render_one_glyph(sub_font, c);
932 obj->params.subtitle.utbl[utblc++] = c;
933 k++;
935 obj->params.subtitle.utbl[utblc++] = ' ';
937 obj->params.subtitle.utbl[utblc - 1] = 0;
938 obj->y -= sub_font->height;
940 if(obj->params.subtitle.lines)
941 obj->y = dys - ((obj->params.subtitle.lines - 1) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h);
943 // free memory
944 if (otp_sub != NULL) {
945 for (tmp = otp_sub->ott; tmp->next != NULL; free(tmp->prev)) {
946 free(tmp->text);
947 tmp = tmp->next;
949 free(tmp->text);
950 free(tmp);
952 for(pmt = otp_sub; pmt->next != NULL; free(pmt->prev)) {
953 pmt = pmt->next;
955 free(pmt);
959 /// vertical alignment
960 h = dys - obj->y;
961 if (sub_alignment == 2)
962 obj->y = dys * sub_pos / 100 - h;
963 else if (sub_alignment == 1)
964 obj->y = dys * sub_pos / 100 - h / 2;
965 else
966 obj->y = dys * sub_pos / 100;
968 if (obj->y < 0)
969 obj->y = 0;
970 if (obj->y > dys - h)
971 obj->y = dys - h;
973 obj->bbox.y2 = obj->y + h;
975 // calculate bbox:
976 if (sub_justify) xmin = 10;
977 obj->bbox.x1=xmin;
978 obj->bbox.x2=xmax;
979 obj->bbox.y1=obj->y;
980 // obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height;
981 obj->flags|=OSDFLAG_BBOX;
983 alloc_buf(obj);
985 y = obj->y;
987 obj->alignment = 0;
988 switch(vo_sub->alignment) {
989 case SUB_ALIGNMENT_BOTTOMLEFT:
990 case SUB_ALIGNMENT_MIDDLELEFT:
991 case SUB_ALIGNMENT_TOPLEFT:
992 obj->alignment |= 0x1;
993 break;
994 case SUB_ALIGNMENT_BOTTOMRIGHT:
995 case SUB_ALIGNMENT_MIDDLERIGHT:
996 case SUB_ALIGNMENT_TOPRIGHT:
997 obj->alignment |= 0x2;
998 break;
999 case SUB_ALIGNMENT_BOTTOMCENTER:
1000 case SUB_ALIGNMENT_MIDDLECENTER:
1001 case SUB_ALIGNMENT_TOPCENTER:
1002 default:
1003 obj->alignment |= 0x0;
1006 i=j=0;
1007 if ((l = obj->params.subtitle.lines)) {
1008 for(counter = dxs; i < l; ++i)
1009 if (obj->params.subtitle.xtbl[i] < counter) counter = obj->params.subtitle.xtbl[i];
1010 for (i = 0; i < l; ++i) {
1011 switch (obj->alignment&0x3) {
1012 case 1:
1013 // left
1014 x = counter;
1015 break;
1016 case 2:
1017 // right
1018 x = 2 * obj->params.subtitle.xtbl[i] - counter - ((obj->params.subtitle.xtbl[i] == counter) ? 0 : 1);
1019 break;
1020 default:
1021 //center
1022 x = obj->params.subtitle.xtbl[i];
1024 prevc = -1;
1025 while ((c=obj->params.subtitle.utbl[j++])){
1026 x += kerning(sub_font,prevc,c);
1027 if ((font=sub_font->font[c])>=0)
1028 draw_alpha_buf(obj,x,y,
1029 sub_font->width[c],
1030 sub_font->pic_a[font]->h+y<obj->dys ? sub_font->pic_a[font]->h : obj->dys-y,
1031 sub_font->pic_b[font]->bmp+sub_font->start[c],
1032 sub_font->pic_a[font]->bmp+sub_font->start[c],
1033 sub_font->pic_a[font]->w);
1034 x+=sub_font->width[c]+sub_font->charspace;
1035 prevc = c;
1037 y+=sub_font->height;
1043 inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys)
1045 unsigned int bbox[4];
1046 spudec_calc_bbox(vo_spudec, dxs, dys, bbox);
1047 obj->bbox.x1 = bbox[0];
1048 obj->bbox.x2 = bbox[1];
1049 obj->bbox.y1 = bbox[2];
1050 obj->bbox.y2 = bbox[3];
1051 obj->flags |= OSDFLAG_BBOX;
1054 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)
1056 spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha, ctx);
1059 void *vo_spudec=NULL;
1060 void *vo_vobsub=NULL;
1062 static int draw_alpha_init_flag=0;
1064 void vo_draw_alpha_init(void);
1066 mp_osd_obj_t* vo_osd_list=NULL;
1068 static mp_osd_obj_t* new_osd_obj(int type){
1069 mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t));
1070 memset(osd,0,sizeof(mp_osd_obj_t));
1071 osd->next=vo_osd_list;
1072 vo_osd_list=osd;
1073 osd->type=type;
1074 osd->alpha_buffer = NULL;
1075 osd->bitmap_buffer = NULL;
1076 osd->allocated = -1;
1077 return osd;
1080 void osd_free(struct osd_state *osd)
1082 mp_osd_obj_t* obj=vo_osd_list;
1083 while(obj){
1084 mp_osd_obj_t* next=obj->next;
1085 free(obj->alpha_buffer);
1086 free(obj->bitmap_buffer);
1087 free(obj);
1088 obj=next;
1090 vo_osd_list=NULL;
1091 talloc_free(osd);
1094 #define FONT_LOAD_DEFER 6
1096 static int osd_update_ext(struct osd_state *osd, int dxs, int dys,
1097 int left_border, int top_border, int right_border,
1098 int bottom_border, int orig_w, int orig_h)
1100 mp_osd_obj_t* obj=vo_osd_list;
1101 int chg=0;
1102 #ifdef CONFIG_FREETYPE
1103 static int defer_counter = 0, prev_dxs = 0, prev_dys = 0;
1104 #endif
1106 #ifdef CONFIG_FREETYPE
1107 // here is the right place to get screen dimensions
1108 if (((dxs != vo_image_width)
1109 && (subtitle_autoscale == 2 || subtitle_autoscale == 3))
1110 || ((dys != vo_image_height)
1111 && (subtitle_autoscale == 1 || subtitle_autoscale == 3)))
1113 // screen dimensions changed
1114 // wait a while to avoid useless reloading of the font
1115 if (dxs == prev_dxs || dys == prev_dys) {
1116 defer_counter++;
1117 } else {
1118 prev_dxs = dxs;
1119 prev_dys = dys;
1120 defer_counter = 0;
1122 if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1;
1125 if (force_load_font) {
1126 force_load_font = 0;
1127 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1128 if (sub_font_name)
1129 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1130 else
1131 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1132 prev_dxs = dxs;
1133 prev_dys = dys;
1134 defer_counter = 0;
1135 } else {
1136 if (!vo_font)
1137 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1138 if (!osd->sub_font) {
1139 if (sub_font_name)
1140 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1141 else
1142 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1145 #endif
1147 while(obj){
1148 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){
1149 int vis=obj->flags&OSDFLAG_VISIBLE;
1150 obj->flags&=~OSDFLAG_BBOX;
1151 switch(obj->type){
1152 #ifdef CONFIG_DVDNAV
1153 case OSDTYPE_DVDNAV:
1154 vo_update_nav(obj,dxs,dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h);
1155 break;
1156 #endif
1157 case OSDTYPE_SUBTITLE:
1158 vo_update_text_sub(osd, obj,dxs,dys);
1159 break;
1160 case OSDTYPE_TELETEXT:
1161 vo_update_text_teletext(obj,dxs,dys);
1162 break;
1163 case OSDTYPE_PROGBAR:
1164 vo_update_text_progbar(obj,dxs,dys);
1165 break;
1166 case OSDTYPE_SPU:
1167 if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){
1168 vo_update_spudec_sub(obj, dxs, dys);
1169 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1171 else
1172 obj->flags&=~OSDFLAG_VISIBLE;
1173 break;
1174 case OSDTYPE_OSD:
1175 if(vo_font && osd->osd_text[0]){
1176 vo_update_text_osd(osd, obj, dxs, dys); // update bbox
1177 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1178 } else
1179 obj->flags&=~OSDFLAG_VISIBLE;
1180 break;
1182 // check bbox:
1183 if(!(obj->flags&OSDFLAG_BBOX)){
1184 // we don't know, so assume the whole screen changed :(
1185 obj->bbox.x1=obj->bbox.y1=0;
1186 obj->bbox.x2=dxs;
1187 obj->bbox.y2=dys;
1188 obj->flags|=OSDFLAG_BBOX;
1189 } else {
1190 // check bbox, reduce it if it's out of bounds (corners):
1191 if(obj->bbox.x1<0) obj->bbox.x1=0;
1192 if(obj->bbox.y1<0) obj->bbox.y1=0;
1193 if(obj->bbox.x2>dxs) obj->bbox.x2=dxs;
1194 if(obj->bbox.y2>dys) obj->bbox.y2=dys;
1195 if(obj->flags&OSDFLAG_VISIBLE)
1196 // debug:
1197 mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n",
1198 obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1,
1199 obj->bbox.y2-obj->bbox.y1);
1201 // check if visibility changed:
1202 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED;
1203 // remove the cause of automatic update:
1204 obj->dxs=dxs; obj->dys=dys;
1205 obj->flags&=~OSDFLAG_FORCE_UPDATE;
1207 if(obj->flags&OSDFLAG_CHANGED){
1208 chg|=1<<obj->type;
1209 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);
1211 obj=obj->next;
1213 return chg;
1216 int osd_update(struct osd_state *osd, int dxs, int dys)
1218 return osd_update_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys);
1221 struct osd_state *osd_create(void)
1223 struct osd_state *osd = talloc_zero(NULL, struct osd_state);
1224 *osd = (struct osd_state){
1226 if(!draw_alpha_init_flag){
1227 draw_alpha_init_flag=1;
1228 vo_draw_alpha_init();
1230 // temp hack, should be moved to mplayer later
1231 new_osd_obj(OSDTYPE_OSD);
1232 new_osd_obj(OSDTYPE_SUBTITLE);
1233 new_osd_obj(OSDTYPE_PROGBAR);
1234 new_osd_obj(OSDTYPE_SPU);
1235 #ifdef CONFIG_DVDNAV
1236 new_osd_obj(OSDTYPE_DVDNAV);
1237 #endif
1238 new_osd_obj(OSDTYPE_TELETEXT);
1239 #ifdef CONFIG_FREETYPE
1240 force_load_font = 1;
1241 #endif
1242 return osd;
1245 int vo_osd_changed_flag=0;
1247 void osd_remove_text(struct osd_state *osd, int dxs, int dys,
1248 void (*remove)(int x0, int y0, int w, int h))
1250 mp_osd_obj_t* obj=vo_osd_list;
1251 osd_update(osd, dxs, dys);
1252 while(obj){
1253 if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) &&
1254 (obj->flags&OSDFLAG_OLD_BBOX)){
1255 int w=obj->old_bbox.x2-obj->old_bbox.x1;
1256 int h=obj->old_bbox.y2-obj->old_bbox.y1;
1257 if(w>0 && h>0){
1258 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1259 remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h);
1261 // obj->flags&=~OSDFLAG_OLD_BBOX;
1263 obj=obj->next;
1267 void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys,
1268 int left_border, int top_border, int right_border,
1269 int bottom_border, int orig_w, int orig_h,
1270 void (*draw_alpha)(void *ctx, int x0, int y0, int w,
1271 int h, unsigned char* src,
1272 unsigned char *srca,
1273 int stride),
1274 void *ctx)
1276 mp_osd_obj_t* obj=vo_osd_list;
1277 osd_update_ext(osd, dxs, dys, left_border, top_border, right_border,
1278 bottom_border, orig_w, orig_h);
1279 while(obj){
1280 if(obj->flags&OSDFLAG_VISIBLE){
1281 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1282 switch(obj->type){
1283 case OSDTYPE_SPU:
1284 vo_draw_spudec_sub(obj, draw_alpha, ctx); // FIXME
1285 break;
1286 #ifdef CONFIG_DVDNAV
1287 case OSDTYPE_DVDNAV:
1288 #endif
1289 case OSDTYPE_TELETEXT:
1290 case OSDTYPE_OSD:
1291 case OSDTYPE_SUBTITLE:
1292 case OSDTYPE_PROGBAR:
1293 vo_draw_text_from_buffer(obj, draw_alpha, ctx);
1294 break;
1296 obj->old_bbox=obj->bbox;
1297 obj->flags|=OSDFLAG_OLD_BBOX;
1299 obj->flags&=~OSDFLAG_CHANGED;
1300 obj=obj->next;
1304 void osd_draw_text(struct osd_state *osd, int dxs, int dys,
1305 void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h,
1306 unsigned char* src, unsigned char *srca,
1307 int stride),
1308 void *ctx)
1310 osd_draw_text_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha, ctx);
1313 static int vo_osd_changed_status = 0;
1315 int vo_osd_changed(int new_value)
1317 mp_osd_obj_t* obj=vo_osd_list;
1318 int ret = vo_osd_changed_status;
1319 vo_osd_changed_status = new_value;
1321 while(obj){
1322 if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
1323 obj=obj->next;
1326 return ret;
1329 // BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB
1330 // BBBBBBBBBBBB BBBBBBBBBBBBB
1331 // BBBBBBB
1333 // return TRUE if we have osd in the specified rectangular area:
1334 int vo_osd_check_range_update(int x1,int y1,int x2,int y2){
1335 mp_osd_obj_t* obj=vo_osd_list;
1336 while(obj){
1337 if(obj->flags&OSDFLAG_VISIBLE){
1338 if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) &&
1339 (obj->bbox.y1<=y2 && obj->bbox.y2>=y1) &&
1340 obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1
1341 ) return 1;
1343 obj=obj->next;
1345 return 0;