rpm: Remove MEncoder from rpm packaging
[mplayer/glamo.git] / libvo / sub.c
blob2c0f29d485c3c8315ccb59aa867886e50a9c1e56
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 "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 = (unsigned char *)memalign(16, len);
159 obj->alpha_buffer = (unsigned char *)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 lastStripPosition;
677 int xsize;
678 int xmin=dxs,xmax=0;
679 int h,lasth;
680 int xtblc, utblc;
681 struct font_desc *sub_font = osd->sub_font;
683 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
685 if(!vo_sub || !osd->sub_font || !sub_visibility || (sub_font->font[40]<0)){
686 obj->flags&=~OSDFLAG_VISIBLE;
687 return;
690 obj->bbox.y2=obj->y=dys;
691 obj->params.subtitle.lines=0;
693 // too long lines divide into a smaller ones
694 i=k=lasth=0;
695 h=sub_font->height;
696 lastStripPosition=-1;
697 l=vo_sub->lines;
700 struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp;
701 struct osd_text_p *otp_sub = NULL, *otp_sub_tmp, // these are used to store the whole sub text osd
702 *otp, *tmp_otp, *pmt; // these are used to manage sub text osd coming from a single sub line
703 int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
705 while (l) {
706 xsize = -sub_font->charspace;
707 l--;
708 t=vo_sub->text[i++];
709 char_position = 0;
710 char_seq = calloc(strlen(t), sizeof(int));
712 prevc = -1;
714 otp = NULL;
715 osl = NULL;
716 x = 1;
718 // reading the subtitle words from vo_sub->text[]
719 while (*t) {
720 if (sub_utf8)
721 c = utf8_get_char(&t);
722 else if ((c = *t++) >= 0x80 && sub_unicode)
723 c = (c<<8) + *t++;
724 if (k==MAX_UCS){
725 t += strlen(t); // end here
726 mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n");
728 if (!c) c++; // avoid UCS 0
729 render_one_glyph(sub_font, c);
731 if (c == ' ') {
732 struct osd_text_t *tmp_ott = calloc(1, sizeof(struct osd_text_t));
734 if (osl == NULL) {
735 osl = cp_ott = tmp_ott;
736 } else {
737 tmp_ott->prev = cp_ott;
738 cp_ott->next = tmp_ott;
739 tmp_ott->osd_kerning =
740 sub_font->charspace + sub_font->width[' '];
741 cp_ott = tmp_ott;
743 tmp_ott->osd_length = xsize;
744 tmp_ott->text_length = char_position;
745 tmp_ott->text = malloc(char_position * sizeof(int));
746 for (counter = 0; counter < char_position; ++counter)
747 tmp_ott->text[counter] = char_seq[counter];
748 char_position = 0;
749 xsize = 0;
750 prevc = c;
751 } else {
752 int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_font, prevc, c);
754 if (xsize + delta_xsize <= dxs) {
755 if (!x) x = 1;
756 prevc = c;
757 char_seq[char_position++] = c;
758 xsize += delta_xsize;
759 if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) {
760 if (sub_font->pic_a[font]->h > h) {
761 h = sub_font->pic_a[font]->h;
764 } else {
765 if (x) {
766 mp_msg(MSGT_OSD, MSGL_WARN, "\nSubtitle word '%s' too long!\n", t);
767 x = 0;
771 }// for len (all words from subtitle line read)
773 // osl holds an ordered (as they appear in the lines) chain of the subtitle words
775 struct osd_text_t *tmp_ott = calloc(1, sizeof(struct osd_text_t));
777 if (osl == NULL) {
778 osl = cp_ott = tmp_ott;
779 } else {
780 tmp_ott->prev = cp_ott;
781 cp_ott->next = tmp_ott;
782 tmp_ott->osd_kerning =
783 sub_font->charspace + sub_font->width[' '];
784 cp_ott = tmp_ott;
786 tmp_ott->osd_length = xsize;
787 tmp_ott->text_length = char_position;
788 tmp_ott->text = malloc(char_position * sizeof(int));
789 for (counter = 0; counter < char_position; ++counter)
790 tmp_ott->text[counter] = char_seq[counter];
791 char_position = 0;
792 xsize = -sub_font->charspace;
794 free(char_seq);
796 if (osl != NULL) {
797 int value = 0, exit = 0, minimum = 0;
799 // otp will contain the chain of the osd subtitle lines coming from the single vo_sub line.
800 otp = tmp_otp = calloc(1, sizeof(struct osd_text_p));
801 tmp_otp->ott = osl;
802 for (tmp_ott = tmp_otp->ott; exit == 0; ) {
803 do {
804 value += tmp_ott->osd_kerning + tmp_ott->osd_length;
805 tmp_ott = tmp_ott->next;
806 } while ((tmp_ott != NULL) && (value + tmp_ott->osd_kerning + tmp_ott->osd_length <= xlimit));
807 if (tmp_ott != NULL) {
808 struct osd_text_p *tmp = calloc(1, sizeof(struct osd_text_p));
810 tmp_otp->value = value;
811 tmp_otp->next = tmp;
812 tmp->prev = tmp_otp;
813 tmp_otp = tmp;
814 tmp_otp->ott = tmp_ott;
815 value = -2 * sub_font->charspace - sub_font->width[' '];
816 } else {
817 tmp_otp->value = value;
818 exit = 1;
823 #ifdef NEW_SPLITTING
824 // minimum holds the 'sum of the differences in length among the lines',
825 // a measure of the evenness of the lengths of the lines
826 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
827 pmt = tmp_otp->next;
828 while (pmt != NULL) {
829 minimum += abs(tmp_otp->value - pmt->value);
830 pmt = pmt->next;
834 if (otp->next != NULL) {
835 int mem1, mem2;
836 struct osd_text_p *mem, *hold;
838 exit = 0;
839 // until the last word of a line can be moved to the beginning of following line
840 // reducing the 'sum of the differences in length among the lines', it is done
841 while (exit == 0) {
842 hold = NULL;
843 exit = 1;
844 for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) {
845 pmt = tmp_otp->next;
846 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
847 if (pmt->value + tmp->osd_length + pmt->ott->osd_kerning <= xlimit) {
848 mem1 = tmp_otp->value;
849 mem2 = pmt->value;
850 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
851 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
853 value = 0;
854 for (mem = otp; mem->next != NULL; mem = mem->next) {
855 pmt = mem->next;
856 while (pmt != NULL) {
857 value += abs(mem->value - pmt->value);
858 pmt = pmt->next;
861 if (value < minimum) {
862 minimum = value;
863 hold = tmp_otp;
864 exit = 0;
866 tmp_otp->value = mem1;
867 tmp_otp->next->value = mem2;
870 // merging
871 if (exit == 0) {
872 tmp_otp = hold;
873 pmt = tmp_otp->next;
874 for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next);
875 mem1 = tmp_otp->value;
876 mem2 = pmt->value;
877 tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning;
878 pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning;
879 pmt->ott = tmp;
880 }//~merging
881 }//~while(exit == 0)
882 }//~if(otp->next!=NULL)
883 #endif
885 // adding otp (containing splitted lines) to otp chain
886 if (otp_sub == NULL) {
887 otp_sub = otp;
888 for (otp_sub_tmp = otp_sub; otp_sub_tmp->next != NULL; otp_sub_tmp = otp_sub_tmp->next);
889 } else {
890 //updating ott chain
891 tmp = otp_sub->ott;
892 while (tmp->next != NULL) tmp = tmp->next;
893 tmp->next = otp->ott;
894 otp->ott->prev = tmp;
895 //attaching new subtitle line at the end
896 otp_sub_tmp->next = otp;
897 otp->prev = otp_sub_tmp;
899 otp_sub_tmp = otp_sub_tmp->next;
900 while (otp_sub_tmp->next != NULL);
902 }//~ if(osl != NULL)
903 } // while
905 // write lines into utbl
906 xtblc = 0;
907 utblc = 0;
908 obj->y = dys;
909 obj->params.subtitle.lines = 0;
910 for (tmp_otp = otp_sub; tmp_otp != NULL; tmp_otp = tmp_otp->next) {
912 if ((obj->params.subtitle.lines++) >= MAX_UCSLINES)
913 break;
915 if (h > obj->y) { // out of the screen so end parsing
916 obj->y -= lasth - sub_font->height; // correct the y position
917 break;
919 xsize = tmp_otp->value;
920 obj->params.subtitle.xtbl[xtblc++] = (dxs - xsize) / 2;
921 if (xmin > (dxs - xsize) / 2)
922 xmin = (dxs - xsize) / 2;
923 if (xmax < (dxs + xsize) / 2)
924 xmax = (dxs + xsize) / 2;
926 tmp = (tmp_otp->next == NULL) ? NULL : tmp_otp->next->ott;
927 for (tmp_ott = tmp_otp->ott; tmp_ott != tmp; tmp_ott = tmp_ott->next) {
928 for (counter = 0; counter < tmp_ott->text_length; ++counter) {
929 if (utblc > MAX_UCS) {
930 break;
932 c = tmp_ott->text[counter];
933 render_one_glyph(sub_font, c);
934 obj->params.subtitle.utbl[utblc++] = c;
935 k++;
937 obj->params.subtitle.utbl[utblc++] = ' ';
939 obj->params.subtitle.utbl[utblc - 1] = 0;
940 obj->y -= sub_font->height;
942 if(obj->params.subtitle.lines)
943 obj->y = dys - ((obj->params.subtitle.lines - 1) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h);
945 // free memory
946 if (otp_sub != NULL) {
947 for (tmp = otp_sub->ott; tmp->next != NULL; free(tmp->prev)) {
948 free(tmp->text);
949 tmp = tmp->next;
951 free(tmp->text);
952 free(tmp);
954 for(pmt = otp_sub; pmt->next != NULL; free(pmt->prev)) {
955 pmt = pmt->next;
957 free(pmt);
961 /// vertical alignment
962 h = dys - obj->y;
963 if (sub_alignment == 2)
964 obj->y = dys * sub_pos / 100 - h;
965 else if (sub_alignment == 1)
966 obj->y = dys * sub_pos / 100 - h / 2;
967 else
968 obj->y = dys * sub_pos / 100;
970 if (obj->y < 0)
971 obj->y = 0;
972 if (obj->y > dys - h)
973 obj->y = dys - h;
975 obj->bbox.y2 = obj->y + h;
977 // calculate bbox:
978 if (sub_justify) xmin = 10;
979 obj->bbox.x1=xmin;
980 obj->bbox.x2=xmax;
981 obj->bbox.y1=obj->y;
982 // obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height;
983 obj->flags|=OSDFLAG_BBOX;
985 alloc_buf(obj);
987 y = obj->y;
989 obj->alignment = 0;
990 switch(vo_sub->alignment) {
991 case SUB_ALIGNMENT_BOTTOMLEFT:
992 case SUB_ALIGNMENT_MIDDLELEFT:
993 case SUB_ALIGNMENT_TOPLEFT:
994 obj->alignment |= 0x1;
995 break;
996 case SUB_ALIGNMENT_BOTTOMRIGHT:
997 case SUB_ALIGNMENT_MIDDLERIGHT:
998 case SUB_ALIGNMENT_TOPRIGHT:
999 obj->alignment |= 0x2;
1000 break;
1001 case SUB_ALIGNMENT_BOTTOMCENTER:
1002 case SUB_ALIGNMENT_MIDDLECENTER:
1003 case SUB_ALIGNMENT_TOPCENTER:
1004 default:
1005 obj->alignment |= 0x0;
1008 i=j=0;
1009 if ((l = obj->params.subtitle.lines)) {
1010 for(counter = dxs; i < l; ++i)
1011 if (obj->params.subtitle.xtbl[i] < counter) counter = obj->params.subtitle.xtbl[i];
1012 for (i = 0; i < l; ++i) {
1013 switch (obj->alignment&0x3) {
1014 case 1:
1015 // left
1016 x = counter;
1017 break;
1018 case 2:
1019 // right
1020 x = 2 * obj->params.subtitle.xtbl[i] - counter - ((obj->params.subtitle.xtbl[i] == counter) ? 0 : 1);
1021 break;
1022 default:
1023 //center
1024 x = obj->params.subtitle.xtbl[i];
1026 prevc = -1;
1027 while ((c=obj->params.subtitle.utbl[j++])){
1028 x += kerning(sub_font,prevc,c);
1029 if ((font=sub_font->font[c])>=0)
1030 draw_alpha_buf(obj,x,y,
1031 sub_font->width[c],
1032 sub_font->pic_a[font]->h+y<obj->dys ? sub_font->pic_a[font]->h : obj->dys-y,
1033 sub_font->pic_b[font]->bmp+sub_font->start[c],
1034 sub_font->pic_a[font]->bmp+sub_font->start[c],
1035 sub_font->pic_a[font]->w);
1036 x+=sub_font->width[c]+sub_font->charspace;
1037 prevc = c;
1039 y+=sub_font->height;
1045 inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys)
1047 unsigned int bbox[4];
1048 spudec_calc_bbox(vo_spudec, dxs, dys, bbox);
1049 obj->bbox.x1 = bbox[0];
1050 obj->bbox.x2 = bbox[1];
1051 obj->bbox.y1 = bbox[2];
1052 obj->bbox.y2 = bbox[3];
1053 obj->flags |= OSDFLAG_BBOX;
1056 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)
1058 spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha, ctx);
1061 void *vo_spudec=NULL;
1062 void *vo_vobsub=NULL;
1064 static int draw_alpha_init_flag=0;
1066 void vo_draw_alpha_init(void);
1068 mp_osd_obj_t* vo_osd_list=NULL;
1070 static mp_osd_obj_t* new_osd_obj(int type){
1071 mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t));
1072 memset(osd,0,sizeof(mp_osd_obj_t));
1073 osd->next=vo_osd_list;
1074 vo_osd_list=osd;
1075 osd->type=type;
1076 osd->alpha_buffer = NULL;
1077 osd->bitmap_buffer = NULL;
1078 osd->allocated = -1;
1079 return osd;
1082 void osd_free(struct osd_state *osd)
1084 mp_osd_obj_t* obj=vo_osd_list;
1085 while(obj){
1086 mp_osd_obj_t* next=obj->next;
1087 free(obj->alpha_buffer);
1088 free(obj->bitmap_buffer);
1089 free(obj);
1090 obj=next;
1092 vo_osd_list=NULL;
1093 talloc_free(osd);
1096 #define FONT_LOAD_DEFER 6
1098 static int osd_update_ext(struct osd_state *osd, int dxs, int dys,
1099 int left_border, int top_border, int right_border,
1100 int bottom_border, int orig_w, int orig_h)
1102 mp_osd_obj_t* obj=vo_osd_list;
1103 int chg=0;
1104 #ifdef CONFIG_FREETYPE
1105 static int defer_counter = 0, prev_dxs = 0, prev_dys = 0;
1106 #endif
1108 #ifdef CONFIG_FREETYPE
1109 // here is the right place to get screen dimensions
1110 if (((dxs != vo_image_width)
1111 && (subtitle_autoscale == 2 || subtitle_autoscale == 3))
1112 || ((dys != vo_image_height)
1113 && (subtitle_autoscale == 1 || subtitle_autoscale == 3)))
1115 // screen dimensions changed
1116 // wait a while to avoid useless reloading of the font
1117 if (dxs == prev_dxs || dys == prev_dys) {
1118 defer_counter++;
1119 } else {
1120 prev_dxs = dxs;
1121 prev_dys = dys;
1122 defer_counter = 0;
1124 if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1;
1127 if (force_load_font) {
1128 force_load_font = 0;
1129 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1130 if (sub_font_name)
1131 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1132 else
1133 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1134 prev_dxs = dxs;
1135 prev_dys = dys;
1136 defer_counter = 0;
1137 } else {
1138 if (!vo_font)
1139 load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor);
1140 if (!osd->sub_font) {
1141 if (sub_font_name)
1142 load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor);
1143 else
1144 load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor);
1147 #endif
1149 while(obj){
1150 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){
1151 int vis=obj->flags&OSDFLAG_VISIBLE;
1152 obj->flags&=~OSDFLAG_BBOX;
1153 switch(obj->type){
1154 #ifdef CONFIG_DVDNAV
1155 case OSDTYPE_DVDNAV:
1156 vo_update_nav(obj,dxs,dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h);
1157 break;
1158 #endif
1159 case OSDTYPE_SUBTITLE:
1160 vo_update_text_sub(osd, obj,dxs,dys);
1161 break;
1162 case OSDTYPE_TELETEXT:
1163 vo_update_text_teletext(obj,dxs,dys);
1164 break;
1165 case OSDTYPE_PROGBAR:
1166 vo_update_text_progbar(obj,dxs,dys);
1167 break;
1168 case OSDTYPE_SPU:
1169 if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){
1170 vo_update_spudec_sub(obj, dxs, dys);
1171 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1173 else
1174 obj->flags&=~OSDFLAG_VISIBLE;
1175 break;
1176 case OSDTYPE_OSD:
1177 if(vo_font && osd->osd_text[0]){
1178 vo_update_text_osd(osd, obj, dxs, dys); // update bbox
1179 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
1180 } else
1181 obj->flags&=~OSDFLAG_VISIBLE;
1182 break;
1184 // check bbox:
1185 if(!(obj->flags&OSDFLAG_BBOX)){
1186 // we don't know, so assume the whole screen changed :(
1187 obj->bbox.x1=obj->bbox.y1=0;
1188 obj->bbox.x2=dxs;
1189 obj->bbox.y2=dys;
1190 obj->flags|=OSDFLAG_BBOX;
1191 } else {
1192 // check bbox, reduce it if it's out of bounds (corners):
1193 if(obj->bbox.x1<0) obj->bbox.x1=0;
1194 if(obj->bbox.y1<0) obj->bbox.y1=0;
1195 if(obj->bbox.x2>dxs) obj->bbox.x2=dxs;
1196 if(obj->bbox.y2>dys) obj->bbox.y2=dys;
1197 if(obj->flags&OSDFLAG_VISIBLE)
1198 // debug:
1199 mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n",
1200 obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1,
1201 obj->bbox.y2-obj->bbox.y1);
1203 // check if visibility changed:
1204 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED;
1205 // remove the cause of automatic update:
1206 obj->dxs=dxs; obj->dys=dys;
1207 obj->flags&=~OSDFLAG_FORCE_UPDATE;
1209 if(obj->flags&OSDFLAG_CHANGED){
1210 chg|=1<<obj->type;
1211 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);
1213 obj=obj->next;
1215 return chg;
1218 int osd_update(struct osd_state *osd, int dxs, int dys)
1220 return osd_update_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys);
1223 struct osd_state *osd_create(void)
1225 struct osd_state *osd = talloc_zero(NULL, struct osd_state);
1226 *osd = (struct osd_state){
1228 if(!draw_alpha_init_flag){
1229 draw_alpha_init_flag=1;
1230 vo_draw_alpha_init();
1232 // temp hack, should be moved to mplayer/mencoder later
1233 new_osd_obj(OSDTYPE_OSD);
1234 new_osd_obj(OSDTYPE_SUBTITLE);
1235 new_osd_obj(OSDTYPE_PROGBAR);
1236 new_osd_obj(OSDTYPE_SPU);
1237 #ifdef CONFIG_DVDNAV
1238 new_osd_obj(OSDTYPE_DVDNAV);
1239 #endif
1240 new_osd_obj(OSDTYPE_TELETEXT);
1241 #ifdef CONFIG_FREETYPE
1242 force_load_font = 1;
1243 #endif
1244 return osd;
1247 int vo_osd_changed_flag=0;
1249 void osd_remove_text(struct osd_state *osd, int dxs, int dys,
1250 void (*remove)(int x0, int y0, int w, int h))
1252 mp_osd_obj_t* obj=vo_osd_list;
1253 osd_update(osd, dxs, dys);
1254 while(obj){
1255 if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) &&
1256 (obj->flags&OSDFLAG_OLD_BBOX)){
1257 int w=obj->old_bbox.x2-obj->old_bbox.x1;
1258 int h=obj->old_bbox.y2-obj->old_bbox.y1;
1259 if(w>0 && h>0){
1260 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1261 remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h);
1263 // obj->flags&=~OSDFLAG_OLD_BBOX;
1265 obj=obj->next;
1269 void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys,
1270 int left_border, int top_border, int right_border,
1271 int bottom_border, int orig_w, int orig_h,
1272 void (*draw_alpha)(void *ctx, int x0, int y0, int w,
1273 int h, unsigned char* src,
1274 unsigned char *srca,
1275 int stride),
1276 void *ctx)
1278 mp_osd_obj_t* obj=vo_osd_list;
1279 osd_update_ext(osd, dxs, dys, left_border, top_border, right_border,
1280 bottom_border, orig_w, orig_h);
1281 while(obj){
1282 if(obj->flags&OSDFLAG_VISIBLE){
1283 vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
1284 switch(obj->type){
1285 case OSDTYPE_SPU:
1286 vo_draw_spudec_sub(obj, draw_alpha, ctx); // FIXME
1287 break;
1288 #ifdef CONFIG_DVDNAV
1289 case OSDTYPE_DVDNAV:
1290 #endif
1291 case OSDTYPE_TELETEXT:
1292 case OSDTYPE_OSD:
1293 case OSDTYPE_SUBTITLE:
1294 case OSDTYPE_PROGBAR:
1295 vo_draw_text_from_buffer(obj, draw_alpha, ctx);
1296 break;
1298 obj->old_bbox=obj->bbox;
1299 obj->flags|=OSDFLAG_OLD_BBOX;
1301 obj->flags&=~OSDFLAG_CHANGED;
1302 obj=obj->next;
1306 void osd_draw_text(struct osd_state *osd, int dxs, int dys,
1307 void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h,
1308 unsigned char* src, unsigned char *srca,
1309 int stride),
1310 void *ctx)
1312 osd_draw_text_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha, ctx);
1315 static int vo_osd_changed_status = 0;
1317 int vo_osd_changed(int new_value)
1319 mp_osd_obj_t* obj=vo_osd_list;
1320 int ret = vo_osd_changed_status;
1321 vo_osd_changed_status = new_value;
1323 while(obj){
1324 if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
1325 obj=obj->next;
1328 return ret;
1331 // BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB
1332 // BBBBBBBBBBBB BBBBBBBBBBBBB
1333 // BBBBBBB
1335 // return TRUE if we have osd in the specified rectangular area:
1336 int vo_osd_check_range_update(int x1,int y1,int x2,int y2){
1337 mp_osd_obj_t* obj=vo_osd_list;
1338 while(obj){
1339 if(obj->flags&OSDFLAG_VISIBLE){
1340 if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) &&
1341 (obj->bbox.y1<=y2 && obj->bbox.y2>=y1) &&
1342 obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1
1343 ) return 1;
1345 obj=obj->next;
1347 return 0;