Mercurial > mplayer.hg
comparison libvo/sub.c @ 5640:a0cee3bb7f78
osd: calculating bbox
author | arpi |
---|---|
date | Mon, 15 Apr 2002 20:51:34 +0000 |
parents | 86663f1b9b00 |
children | eb0cb6185e6c |
comparison
equal
deleted
inserted
replaced
5639:91d4b2745e9e | 5640:a0cee3bb7f78 |
---|---|
30 unsigned char* vo_osd_text=NULL; | 30 unsigned char* vo_osd_text=NULL; |
31 int sub_unicode=0; | 31 int sub_unicode=0; |
32 int sub_utf8=0; | 32 int sub_utf8=0; |
33 int sub_pos=100; | 33 int sub_pos=100; |
34 | 34 |
35 inline static void vo_draw_text_osd(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){ | 35 inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){ |
36 unsigned char *cp=vo_osd_text; | 36 unsigned char *cp=vo_osd_text; |
37 int c; | 37 int x=20; |
38 | |
39 obj->bbox.x1=obj->x=x; | |
40 obj->bbox.y1=obj->y=10; | |
41 | |
42 while (*cp){ | |
43 int c=*cp++; | |
44 x+=vo_font->width[c]+vo_font->charspace; | |
45 } | |
46 | |
47 obj->bbox.x2=x; | |
48 obj->bbox.y2=obj->bbox.y1+vo_font->height; | |
49 obj->flags|=OSDFLAG_BBOX; | |
50 | |
51 } | |
52 | |
53 inline static void vo_draw_text_osd(mp_osd_obj_t* obj,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){ | |
54 unsigned char *cp=vo_osd_text; | |
38 int font; | 55 int font; |
39 int y=10; | 56 int x=obj->x; |
40 int x=20; | |
41 | 57 |
42 while (*cp){ | 58 while (*cp){ |
43 c=*cp++; | 59 int c=*cp++; |
44 if ((font=vo_font->font[c])>=0) | 60 if ((font=vo_font->font[c])>=0) |
45 draw_alpha(x,y, | 61 draw_alpha(x,obj->y, |
46 vo_font->width[c], | 62 vo_font->width[c], |
47 vo_font->pic_a[font]->h, | 63 vo_font->pic_a[font]->h, |
48 vo_font->pic_b[font]->bmp+vo_font->start[c], | 64 vo_font->pic_b[font]->bmp+vo_font->start[c], |
49 vo_font->pic_a[font]->bmp+vo_font->start[c], | 65 vo_font->pic_a[font]->bmp+vo_font->start[c], |
50 vo_font->pic_a[font]->w); | 66 vo_font->pic_a[font]->w); |
51 x+=vo_font->width[c]+vo_font->charspace; | 67 x+=vo_font->width[c]+vo_font->charspace; |
52 } | 68 } |
53 | |
54 } | 69 } |
55 | 70 |
56 int vo_osd_progbar_type=-1; | 71 int vo_osd_progbar_type=-1; |
57 int vo_osd_progbar_value=100; // 0..256 | 72 int vo_osd_progbar_value=100; // 0..256 |
58 | 73 |
84 int x=(dxs-elems*charw-delimw)/2; | 99 int x=(dxs-elems*charw-delimw)/2; |
85 obj->bbox.x1=obj->x=x; | 100 obj->bbox.x1=obj->x=x; |
86 obj->bbox.y1=obj->y=y; | 101 obj->bbox.y1=obj->y=y; |
87 obj->bbox.x2=x+width+delimw; | 102 obj->bbox.x2=x+width+delimw; |
88 obj->bbox.y2=y+vo_font->height; | 103 obj->bbox.y2=y+vo_font->height; |
104 obj->flags|=OSDFLAG_BBOX; | |
89 obj->params.progbar.elems=elems; | 105 obj->params.progbar.elems=elems; |
90 } | 106 } |
91 | 107 |
92 } | 108 } |
93 | 109 |
184 int c,i,j,l,x,y,font; | 200 int c,i,j,l,x,y,font; |
185 int len; | 201 int len; |
186 int k,lastk; | 202 int k,lastk; |
187 int lastStripPosition; | 203 int lastStripPosition; |
188 int xsize,lastxsize; | 204 int xsize,lastxsize; |
205 int xmin=dxs,xmax=0; | |
189 int h,lasth; | 206 int h,lasth; |
190 | 207 |
191 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE; | 208 obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE; |
192 | 209 |
193 if(!vo_sub || !vo_font){ | 210 if(!vo_sub || !vo_font){ |
257 l=0; | 274 l=0; |
258 break; | 275 break; |
259 } | 276 } |
260 obj->params.subtitle.utbl[k++]=0; | 277 obj->params.subtitle.utbl[k++]=0; |
261 obj->params.subtitle.xtbl[obj->params.subtitle.lines++]=(dxs-xsize)/2; | 278 obj->params.subtitle.xtbl[obj->params.subtitle.lines++]=(dxs-xsize)/2; |
279 if(xmin>(dxs-xsize)/2) xmin=(dxs-xsize)/2; | |
280 if(xmax<(dxs+xsize)/2) xmax=(dxs+xsize)/2; | |
262 if (obj->params.subtitle.lines==MAX_UCSLINES||k>MAX_UCS){ | 281 if (obj->params.subtitle.lines==MAX_UCSLINES||k>MAX_UCS){ |
263 l=0; len=j; // end parsing | 282 l=0; len=j; // end parsing |
264 } else if(l || j<len){ // not the last line or not the last char | 283 } else if(l || j<len){ // not the last line or not the last char |
265 lastStripPosition=-1; | 284 lastStripPosition=-1; |
266 xsize=-vo_font->charspace; | 285 xsize=-vo_font->charspace; |
269 } | 288 } |
270 // printf("h: %d -> %d \n",vo_font->height,h); | 289 // printf("h: %d -> %d \n",vo_font->height,h); |
271 obj->y -=h; // according to max of vo_font->pic_a[font]->h | 290 obj->y -=h; // according to max of vo_font->pic_a[font]->h |
272 } | 291 } |
273 } | 292 } |
293 | |
294 if (obj->y >= (dys * sub_pos / 100)) obj->y = dys * sub_pos /100; | |
274 | 295 |
275 // TODO: calculate bbox | 296 // calculate bbox: |
276 | 297 obj->bbox.x1=xmin; |
298 obj->bbox.x2=xmax; | |
299 obj->bbox.y1=obj->y; | |
300 obj->bbox.y2=obj->y+obj->params.subtitle.lines*vo_font->height; | |
301 obj->flags|=OSDFLAG_BBOX; | |
302 | |
277 } | 303 } |
278 | 304 |
279 inline static void vo_draw_text_sub(mp_osd_obj_t* obj,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){ | 305 inline static void vo_draw_text_sub(mp_osd_obj_t* obj,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){ |
280 int y,i,j,c,x,l,font; | 306 int i,j,c,x,l,font; |
281 | 307 int y=obj->y; |
282 // FIXME (bbox): | |
283 if (obj->y < (obj->dys * sub_pos / 100)) { y = obj->y; } else { y = obj->dys * sub_pos /100;}; | |
284 | |
285 // printf("lines=%d y=%d\n",lines,y); | |
286 | 308 |
287 i=j=0; | 309 i=j=0; |
288 if ((l=obj->params.subtitle.lines)) for (;;) { | 310 if ((l=obj->params.subtitle.lines)) for (;;) { |
289 x=obj->params.subtitle.xtbl[i++]; | 311 x=obj->params.subtitle.xtbl[i++]; |
290 while ((c=obj->params.subtitle.utbl[j++])){ | 312 while ((c=obj->params.subtitle.utbl[j++])){ |
334 mp_osd_obj_t* obj=vo_osd_list; | 356 mp_osd_obj_t* obj=vo_osd_list; |
335 int chg=0; | 357 int chg=0; |
336 while(obj){ | 358 while(obj){ |
337 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){ | 359 if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){ |
338 int vis=obj->flags&OSDFLAG_VISIBLE; | 360 int vis=obj->flags&OSDFLAG_VISIBLE; |
361 obj->flags&=~OSDFLAG_BBOX; | |
339 switch(obj->type){ | 362 switch(obj->type){ |
340 case OSDTYPE_SUBTITLE: | 363 case OSDTYPE_SUBTITLE: |
341 vo_update_text_sub(obj,dxs,dys); | 364 vo_update_text_sub(obj,dxs,dys); |
342 break; | 365 break; |
343 case OSDTYPE_PROGBAR: | 366 case OSDTYPE_PROGBAR: |
354 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED; | 377 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED; |
355 else | 378 else |
356 obj->flags&=~OSDFLAG_VISIBLE; | 379 obj->flags&=~OSDFLAG_VISIBLE; |
357 break; | 380 break; |
358 case OSDTYPE_OSD: | 381 case OSDTYPE_OSD: |
359 if(vo_font && vo_osd_text && vo_osd_text[0]) | 382 if(vo_font && vo_osd_text && vo_osd_text[0]){ |
383 vo_update_text_osd(obj,dxs,dys); // update bbox | |
360 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED; | 384 obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED; |
361 else | 385 } else |
362 obj->flags&=~OSDFLAG_VISIBLE; | 386 obj->flags&=~OSDFLAG_VISIBLE; |
363 break; | 387 break; |
388 } | |
389 // check bbox: | |
390 if(!(obj->flags&OSDFLAG_BBOX)){ | |
391 // we don't know, so assume the whole screen changed :( | |
392 obj->bbox.x1=obj->bbox.y1=0; | |
393 obj->bbox.x2=dxs; | |
394 obj->bbox.y2=dys; | |
395 obj->flags|=OSDFLAG_BBOX; | |
396 } else if(obj->flags&OSDFLAG_VISIBLE){ | |
397 mp_msg(MSGT_OSD,MSGL_V,"OSD update: %d;%d %dx%d \n", | |
398 obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1, | |
399 obj->bbox.y2-obj->bbox.y1); | |
364 } | 400 } |
365 // check if visibility changed: | 401 // check if visibility changed: |
366 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED; | 402 if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED; |
367 // remove the cause of updating: | 403 // remove the cause of automatic update: |
368 obj->dxs=dxs; obj->dys=dys; | 404 obj->dxs=dxs; obj->dys=dys; |
369 obj->flags&=~OSDFLAG_FORCE_UPDATE; | 405 obj->flags&=~OSDFLAG_FORCE_UPDATE; |
370 } | 406 } |
371 if(obj->flags&OSDFLAG_CHANGED){ | 407 if(obj->flags&OSDFLAG_CHANGED){ |
372 chg|=1<<obj->type; | 408 chg|=1<<obj->type; |
404 break; | 440 break; |
405 case OSDTYPE_VOBSUB: | 441 case OSDTYPE_VOBSUB: |
406 vobsub_draw(vo_vobsub, dxs, dys, draw_alpha); // FIXME | 442 vobsub_draw(vo_vobsub, dxs, dys, draw_alpha); // FIXME |
407 break; | 443 break; |
408 case OSDTYPE_OSD: | 444 case OSDTYPE_OSD: |
409 vo_draw_text_osd(dxs,dys,draw_alpha); | 445 vo_draw_text_osd(obj,draw_alpha); |
410 break; | 446 break; |
411 case OSDTYPE_SUBTITLE: | 447 case OSDTYPE_SUBTITLE: |
412 vo_draw_text_sub(obj,draw_alpha); | 448 vo_draw_text_sub(obj,draw_alpha); |
413 break; | 449 break; |
414 case OSDTYPE_PROGBAR: | 450 case OSDTYPE_PROGBAR: |