2001-03-24 04:36:17 +00:00
|
|
|
|
2002-04-06 19:09:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-14 21:28:18 +00:00
|
|
|
#include <string.h>
|
2002-04-06 19:09:06 +00:00
|
|
|
|
2002-01-11 16:06:45 +00:00
|
|
|
#include "config.h"
|
2002-04-15 19:17:12 +00:00
|
|
|
#include "mp_msg.h"
|
2002-01-11 16:06:45 +00:00
|
|
|
#include "video_out.h"
|
2002-03-24 00:32:13 +00:00
|
|
|
#include "font_load.h"
|
2001-03-27 00:32:24 +00:00
|
|
|
#include "sub.h"
|
2002-08-14 21:28:18 +00:00
|
|
|
#include "../spudec.h"
|
2001-03-27 00:32:24 +00:00
|
|
|
|
2001-10-27 14:30:43 +00:00
|
|
|
char * __sub_osd_names[]={
|
|
|
|
"Seekbar",
|
|
|
|
"Play",
|
|
|
|
"Pause",
|
|
|
|
"Stop",
|
|
|
|
"Rewind",
|
|
|
|
"Forward",
|
|
|
|
"Clock",
|
|
|
|
"Contrast",
|
|
|
|
"Saturation",
|
|
|
|
"Volume",
|
|
|
|
"Brightness",
|
|
|
|
"Hue"
|
|
|
|
};
|
|
|
|
char * __sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", ""};
|
|
|
|
|
2001-03-25 04:28:40 +00:00
|
|
|
//static int vo_font_loaded=-1;
|
|
|
|
font_desc_t* vo_font=NULL;
|
2001-03-24 04:36:17 +00:00
|
|
|
|
2001-09-27 17:40:43 +00:00
|
|
|
unsigned char* vo_osd_text=NULL;
|
2001-05-14 22:08:12 +00:00
|
|
|
int sub_unicode=0;
|
2001-08-13 11:08:18 +00:00
|
|
|
int sub_utf8=0;
|
2002-02-20 22:43:34 +00:00
|
|
|
int sub_pos=100;
|
2002-10-06 17:40:51 +00:00
|
|
|
int sub_visibility=1;
|
2001-03-24 04:36:17 +00:00
|
|
|
|
2002-04-17 20:46:12 +00:00
|
|
|
// return the real height of a char:
|
|
|
|
static inline int get_height(int c,int h){
|
|
|
|
int font;
|
|
|
|
if ((font=vo_font->font[c])>=0)
|
|
|
|
if(h<vo_font->pic_a[font]->h) h=vo_font->pic_a[font]->h;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2002-08-28 20:45:42 +00:00
|
|
|
// renders char to a big per-object buffer where alpha and bitmap are separated
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int dststride = obj->stride;
|
|
|
|
int dstskip = obj->stride-w;
|
|
|
|
int srcskip = stride-w;
|
|
|
|
int i, j;
|
|
|
|
unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
|
|
|
|
unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1);
|
|
|
|
unsigned char *bs = src;
|
|
|
|
unsigned char *as = srca;
|
|
|
|
|
|
|
|
if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) {
|
|
|
|
fprintf(stderr, "osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n",
|
|
|
|
obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2,
|
|
|
|
x0, x0+w, y0, y0+h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < h; i++) {
|
|
|
|
for (j = 0; j < w; j++, b++, a++, bs++, as++) {
|
|
|
|
if (*b < *bs) *b = *bs;
|
|
|
|
if (*as) {
|
|
|
|
if (*a == 0 || *a > *as) *a = *as;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b+= dstskip;
|
|
|
|
a+= dstskip;
|
|
|
|
bs+= srcskip;
|
|
|
|
as+= srcskip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocates/enlarges the alpha/bitmap buffer
|
|
|
|
static void alloc_buf(mp_osd_obj_t* obj)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
if (obj->bbox.x2 < obj->bbox.x1) obj->bbox.x2 = obj->bbox.x1;
|
|
|
|
if (obj->bbox.y2 < obj->bbox.y1) obj->bbox.y2 = obj->bbox.y1;
|
|
|
|
obj->stride = ((obj->bbox.x2-obj->bbox.x1)+7)&(~7);
|
|
|
|
len = obj->stride*(obj->bbox.y2-obj->bbox.y1);
|
|
|
|
if (obj->allocated<len) {
|
|
|
|
obj->allocated = len;
|
|
|
|
free(obj->bitmap_buffer);
|
|
|
|
free(obj->alpha_buffer);
|
|
|
|
obj->bitmap_buffer = (unsigned char *)memalign(16, len);
|
|
|
|
obj->alpha_buffer = (unsigned char *)memalign(16, len);
|
|
|
|
}
|
|
|
|
memset(obj->bitmap_buffer, 0, len);
|
|
|
|
memset(obj->alpha_buffer, 0, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
// renders the buffer
|
|
|
|
inline static void vo_draw_text_from_buffer(mp_osd_obj_t* obj,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
|
|
|
|
if (obj->allocated > 0) {
|
|
|
|
draw_alpha(obj->bbox.x1,obj->bbox.y1,
|
|
|
|
obj->bbox.x2-obj->bbox.x1,
|
|
|
|
obj->bbox.y2-obj->bbox.y1,
|
|
|
|
obj->bitmap_buffer,
|
|
|
|
obj->alpha_buffer,
|
|
|
|
obj->stride);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-15 20:51:34 +00:00
|
|
|
inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){
|
|
|
|
unsigned char *cp=vo_osd_text;
|
|
|
|
int x=20;
|
2002-04-17 20:46:12 +00:00
|
|
|
int h=0;
|
2002-08-28 20:45:42 +00:00
|
|
|
int font;
|
2002-04-15 20:51:34 +00:00
|
|
|
|
|
|
|
obj->bbox.x1=obj->x=x;
|
|
|
|
obj->bbox.y1=obj->y=10;
|
|
|
|
|
|
|
|
while (*cp){
|
|
|
|
int c=*cp++;
|
2002-08-28 20:45:42 +00:00
|
|
|
render_one_glyph(vo_font, c);
|
|
|
|
x+=vo_font->width[c]+vo_font->charspace;
|
2002-04-17 20:46:12 +00:00
|
|
|
h=get_height(c,h);
|
2002-04-15 20:51:34 +00:00
|
|
|
}
|
|
|
|
|
2002-04-17 20:46:12 +00:00
|
|
|
obj->bbox.x2=x-vo_font->charspace;
|
|
|
|
obj->bbox.y2=obj->bbox.y1+h;
|
2002-04-15 20:51:34 +00:00
|
|
|
obj->flags|=OSDFLAG_BBOX;
|
|
|
|
|
2002-08-28 20:45:42 +00:00
|
|
|
alloc_buf(obj);
|
2001-03-25 04:28:40 +00:00
|
|
|
|
2002-08-28 20:45:42 +00:00
|
|
|
cp=vo_osd_text;
|
|
|
|
x = obj->x;
|
2001-08-13 11:08:18 +00:00
|
|
|
while (*cp){
|
2002-04-15 20:51:34 +00:00
|
|
|
int c=*cp++;
|
2001-08-13 11:08:18 +00:00
|
|
|
if ((font=vo_font->font[c])>=0)
|
2002-08-28 20:45:42 +00:00
|
|
|
draw_alpha_buf(obj,x,obj->y,
|
|
|
|
vo_font->width[c],
|
|
|
|
vo_font->pic_a[font]->h,
|
|
|
|
vo_font->pic_b[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->w);
|
2001-03-25 04:28:40 +00:00
|
|
|
x+=vo_font->width[c]+vo_font->charspace;
|
|
|
|
}
|
2001-03-27 00:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int vo_osd_progbar_type=-1;
|
2001-08-28 12:43:41 +00:00
|
|
|
int vo_osd_progbar_value=100; // 0..256
|
|
|
|
|
|
|
|
// if we have n=256 bars then OSD progbar looks like below
|
|
|
|
//
|
2001-09-10 13:23:27 +00:00
|
|
|
// 0 1 2 3 ... 256 <= vo_osd_progbar_value
|
|
|
|
// | | | | |
|
2001-08-28 12:43:41 +00:00
|
|
|
// [ === === === ... === ]
|
|
|
|
//
|
|
|
|
// the above schema is rescalled to n=elems bars
|
2001-03-27 00:32:24 +00:00
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
inline static void vo_update_text_progbar(mp_osd_obj_t* obj,int dxs,int dys){
|
|
|
|
|
|
|
|
obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
|
|
|
|
|
|
|
|
if(vo_osd_progbar_type<0 || !vo_font){
|
|
|
|
obj->flags&=~OSDFLAG_VISIBLE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-28 20:45:42 +00:00
|
|
|
render_one_glyph(vo_font, OSD_PB_START);
|
|
|
|
render_one_glyph(vo_font, OSD_PB_END);
|
|
|
|
render_one_glyph(vo_font, OSD_PB_0);
|
|
|
|
render_one_glyph(vo_font, OSD_PB_1);
|
|
|
|
render_one_glyph(vo_font, vo_osd_progbar_type);
|
|
|
|
|
|
|
|
// calculate bbox corners:
|
2002-04-17 20:46:12 +00:00
|
|
|
{ int h=0;
|
2001-08-13 11:08:18 +00:00
|
|
|
int y=(dys-vo_font->height)/2;
|
2001-08-16 09:25:32 +00:00
|
|
|
int delimw=vo_font->width[OSD_PB_START]
|
2001-08-16 11:36:13 +00:00
|
|
|
+vo_font->width[OSD_PB_END]
|
|
|
|
+vo_font->charspace;
|
2001-08-16 09:25:32 +00:00
|
|
|
int width=(2*dxs-3*delimw)/3;
|
2001-08-16 11:36:13 +00:00
|
|
|
int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
|
2001-08-16 09:25:32 +00:00
|
|
|
int elems=width/charw;
|
2001-08-16 11:36:13 +00:00
|
|
|
int x=(dxs-elems*charw-delimw)/2;
|
2002-08-28 20:45:42 +00:00
|
|
|
int delta = 0;
|
|
|
|
if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
|
|
|
|
delta = vo_font->width[vo_osd_progbar_type]+vo_font->spacewidth;
|
|
|
|
delta = (x-delta > 0) ? delta : x;
|
|
|
|
}
|
2002-04-17 20:46:12 +00:00
|
|
|
h=get_height(OSD_PB_START,h);
|
|
|
|
h=get_height(OSD_PB_END,h);
|
|
|
|
h=get_height(OSD_PB_0,h);
|
|
|
|
h=get_height(OSD_PB_1,h);
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->bbox.x1=obj->x=x;
|
|
|
|
obj->bbox.y1=obj->y=y;
|
|
|
|
obj->bbox.x2=x+width+delimw;
|
2002-04-17 20:46:12 +00:00
|
|
|
obj->bbox.y2=y+h; //vo_font->height;
|
2002-04-15 20:51:34 +00:00
|
|
|
obj->flags|=OSDFLAG_BBOX;
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->params.progbar.elems=elems;
|
2002-08-28 20:45:42 +00:00
|
|
|
obj->bbox.x1-=delta; // space for an icon
|
2002-04-15 19:17:12 +00:00
|
|
|
}
|
|
|
|
|
2002-08-28 20:45:42 +00:00
|
|
|
alloc_buf(obj);
|
|
|
|
|
|
|
|
// render it:
|
|
|
|
{ unsigned char *s;
|
2002-04-15 19:17:12 +00:00
|
|
|
unsigned char *sa;
|
|
|
|
int i,w,h,st,mark;
|
|
|
|
int x=obj->x;
|
|
|
|
int y=obj->y;
|
|
|
|
int c,font;
|
|
|
|
int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
|
|
|
|
int elems=obj->params.progbar.elems;
|
2001-08-16 09:25:32 +00:00
|
|
|
|
2001-08-28 12:43:41 +00:00
|
|
|
if (vo_osd_progbar_value<=0)
|
|
|
|
mark=0;
|
2001-09-10 13:23:27 +00:00
|
|
|
else {
|
|
|
|
int ev=vo_osd_progbar_value*elems;
|
|
|
|
mark=ev>>8;
|
|
|
|
if (ev & 0xFF) mark++;
|
|
|
|
if (mark>elems) mark=elems;
|
|
|
|
}
|
|
|
|
|
2001-08-28 14:22:37 +00:00
|
|
|
|
2001-03-27 00:32:24 +00:00
|
|
|
// printf("osd.progbar width=%d xpos=%d\n",width,x);
|
|
|
|
|
2001-08-13 11:08:18 +00:00
|
|
|
c=vo_osd_progbar_type;
|
2001-08-17 08:47:58 +00:00
|
|
|
if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0) {
|
|
|
|
int xp=x-vo_font->width[c]-vo_font->spacewidth;
|
2002-08-28 20:45:42 +00:00
|
|
|
draw_alpha_buf(obj,(xp<0?0:xp),y,
|
2001-03-27 00:32:24 +00:00
|
|
|
vo_font->width[c],
|
|
|
|
vo_font->pic_a[font]->h,
|
|
|
|
vo_font->pic_b[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->w);
|
2001-08-17 08:47:58 +00:00
|
|
|
}
|
|
|
|
|
2001-08-13 11:08:18 +00:00
|
|
|
c=OSD_PB_START;
|
|
|
|
if ((font=vo_font->font[c])>=0)
|
2002-08-28 20:45:42 +00:00
|
|
|
draw_alpha_buf(obj,x,y,
|
2001-03-27 00:32:24 +00:00
|
|
|
vo_font->width[c],
|
|
|
|
vo_font->pic_a[font]->h,
|
|
|
|
vo_font->pic_b[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->w);
|
2001-08-16 09:25:32 +00:00
|
|
|
x+=vo_font->width[c]+vo_font->charspace;
|
2001-03-27 00:32:24 +00:00
|
|
|
|
2001-08-13 11:08:18 +00:00
|
|
|
c=OSD_PB_0;
|
2001-08-21 11:28:50 +00:00
|
|
|
if ((font=vo_font->font[c])>=0){
|
|
|
|
w=vo_font->width[c];
|
|
|
|
h=vo_font->pic_a[font]->h;
|
|
|
|
s=vo_font->pic_b[font]->bmp+vo_font->start[c];
|
|
|
|
sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
|
|
|
|
st=vo_font->pic_a[font]->w;
|
2001-10-15 06:14:55 +00:00
|
|
|
if ((i=mark)) do {
|
2002-08-28 20:45:42 +00:00
|
|
|
draw_alpha_buf(obj,x,y,w,h,s,sa,st);
|
2001-08-16 09:25:32 +00:00
|
|
|
x+=charw;
|
2001-10-15 06:14:55 +00:00
|
|
|
} while(--i);
|
2001-08-21 11:28:50 +00:00
|
|
|
}
|
2001-08-13 11:08:18 +00:00
|
|
|
|
|
|
|
c=OSD_PB_1;
|
2001-08-21 11:28:50 +00:00
|
|
|
if ((font=vo_font->font[c])>=0){
|
|
|
|
w=vo_font->width[c];
|
|
|
|
h=vo_font->pic_a[font]->h;
|
|
|
|
s =vo_font->pic_b[font]->bmp+vo_font->start[c];
|
|
|
|
sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
|
|
|
|
st=vo_font->pic_a[font]->w;
|
2001-10-15 06:14:55 +00:00
|
|
|
if ((i=elems-mark)) do {
|
2002-08-28 20:45:42 +00:00
|
|
|
draw_alpha_buf(obj,x,y,w,h,s,sa,st);
|
2001-08-16 09:25:32 +00:00
|
|
|
x+=charw;
|
2001-10-15 06:14:55 +00:00
|
|
|
} while(--i);
|
2001-08-21 11:28:50 +00:00
|
|
|
}
|
2001-08-13 11:08:18 +00:00
|
|
|
|
|
|
|
c=OSD_PB_END;
|
|
|
|
if ((font=vo_font->font[c])>=0)
|
2002-08-28 20:45:42 +00:00
|
|
|
draw_alpha_buf(obj,x,y,
|
2001-03-27 00:32:24 +00:00
|
|
|
vo_font->width[c],
|
|
|
|
vo_font->pic_a[font]->h,
|
|
|
|
vo_font->pic_b[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->w);
|
2001-08-16 09:25:32 +00:00
|
|
|
// x+=vo_font->width[c]+vo_font->charspace;
|
2001-05-14 22:08:12 +00:00
|
|
|
|
2002-08-28 20:45:42 +00:00
|
|
|
}
|
2001-03-27 00:32:24 +00:00
|
|
|
// vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-03-30 03:01:50 +00:00
|
|
|
subtitle* vo_sub=NULL;
|
2001-03-27 00:32:24 +00:00
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
// vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride))
|
2001-08-20 09:14:28 +00:00
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
inline static void vo_update_text_sub(mp_osd_obj_t* obj,int dxs,int dys){
|
2001-08-13 11:08:18 +00:00
|
|
|
unsigned char *t;
|
2002-08-28 20:45:42 +00:00
|
|
|
int c,i,j,l,x,y,font,prevc;
|
2001-08-13 11:08:18 +00:00
|
|
|
int len;
|
2001-08-20 09:14:28 +00:00
|
|
|
int k,lastk;
|
2001-08-13 11:08:18 +00:00
|
|
|
int lastStripPosition;
|
2001-08-20 09:14:28 +00:00
|
|
|
int xsize,lastxsize;
|
2002-04-15 20:51:34 +00:00
|
|
|
int xmin=dxs,xmax=0;
|
2001-08-20 09:14:28 +00:00
|
|
|
int h,lasth;
|
2001-08-13 11:08:18 +00:00
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
|
2002-10-06 17:40:51 +00:00
|
|
|
|
|
|
|
if(!vo_sub || !vo_font || !sub_visibility){
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->flags&=~OSDFLAG_VISIBLE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-17 20:46:12 +00:00
|
|
|
obj->bbox.y2=obj->y=dys;
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->params.subtitle.lines=0;
|
|
|
|
|
2001-08-21 11:28:50 +00:00
|
|
|
// too long lines divide into a smaller ones
|
2002-04-15 19:17:12 +00:00
|
|
|
i=k=lasth=0;
|
2001-08-20 09:14:28 +00:00
|
|
|
h=vo_font->height;
|
|
|
|
xsize=-vo_font->charspace;
|
|
|
|
lastStripPosition=-1;
|
|
|
|
l=vo_sub->lines;
|
|
|
|
|
2001-10-15 06:14:55 +00:00
|
|
|
while (l) {
|
|
|
|
l--;
|
2001-08-13 11:08:18 +00:00
|
|
|
t=vo_sub->text[i++];
|
|
|
|
len=strlen(t)-1;
|
2001-09-01 17:56:31 +00:00
|
|
|
|
2001-09-04 15:21:00 +00:00
|
|
|
// printf("sub(%d) '%s'\n",len,t);
|
2001-09-01 17:56:31 +00:00
|
|
|
// if(len<0) memy -=h; // according to max of vo_font->pic_a[font]->h
|
|
|
|
// else
|
2002-08-28 20:45:42 +00:00
|
|
|
|
|
|
|
prevc = -1;
|
|
|
|
|
2001-08-13 11:08:18 +00:00
|
|
|
for (j=0;j<=len;j++){
|
|
|
|
if ((c=t[j])>=0x80){
|
2001-10-12 13:24:07 +00:00
|
|
|
if (sub_utf8){
|
|
|
|
if ((c & 0xe0) == 0xc0) /* 2 bytes U+00080..U+0007FF*/
|
|
|
|
c = (c & 0x1f)<<6 | (t[++j] & 0x3f);
|
|
|
|
else if((c & 0xf0) == 0xe0)/* 3 bytes U+00800..U+00FFFF*/
|
|
|
|
c = ((c & 0x0f)<<6 |
|
|
|
|
(t[++j] & 0x3f))<<6 | (t[++j] & 0x3f);
|
|
|
|
} else if (sub_unicode)
|
|
|
|
c = (c<<8) + t[++j];
|
2001-08-13 11:08:18 +00:00
|
|
|
}
|
|
|
|
if (k==MAX_UCS){
|
2001-10-15 06:14:55 +00:00
|
|
|
len=j; // end here
|
2002-04-15 19:17:12 +00:00
|
|
|
mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n");
|
2001-08-20 09:14:28 +00:00
|
|
|
}
|
2001-10-15 06:14:55 +00:00
|
|
|
if (!c) c++; // avoid UCS 0
|
2002-08-28 20:45:42 +00:00
|
|
|
render_one_glyph(vo_font, c);
|
2001-08-13 11:08:18 +00:00
|
|
|
if (c==' '){
|
|
|
|
lastk=k;
|
|
|
|
lastStripPosition=j;
|
|
|
|
lastxsize=xsize;
|
2001-10-15 06:14:55 +00:00
|
|
|
} else if ((font=vo_font->font[c])>=0){
|
2001-08-20 09:14:28 +00:00
|
|
|
if (vo_font->pic_a[font]->h > h){
|
|
|
|
h=vo_font->pic_a[font]->h;
|
|
|
|
}
|
2001-08-13 11:08:18 +00:00
|
|
|
}
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->params.subtitle.utbl[k++]=c;
|
2002-08-28 20:45:42 +00:00
|
|
|
xsize+=vo_font->width[c]+vo_font->charspace+kerning(vo_font,prevc,c);
|
2001-08-20 09:14:28 +00:00
|
|
|
if (dxs<xsize){
|
2002-08-28 20:45:42 +00:00
|
|
|
prevc = -1;
|
2001-08-20 09:14:28 +00:00
|
|
|
if (lastStripPosition>0){
|
|
|
|
j=lastStripPosition;
|
|
|
|
xsize=lastxsize;
|
|
|
|
k=lastk;
|
|
|
|
} else {
|
2002-08-28 20:45:42 +00:00
|
|
|
xsize -=vo_font->width[c]+vo_font->charspace+kerning(vo_font,prevc,c);; // go back
|
2001-08-20 09:14:28 +00:00
|
|
|
k--; // cut line here
|
|
|
|
while (t[j] && t[j]!=' ') j++; // jump to the nearest space
|
|
|
|
}
|
2002-08-28 20:45:42 +00:00
|
|
|
} else if (j<len) {
|
|
|
|
prevc = c;
|
|
|
|
continue;
|
|
|
|
}
|
2002-04-15 19:17:12 +00:00
|
|
|
if (h>obj->y){ // out of the screen so end parsing
|
|
|
|
obj->y -= lasth - vo_font->height; // correct the y position
|
2001-10-15 06:14:55 +00:00
|
|
|
l=0;
|
|
|
|
break;
|
2001-08-20 09:14:28 +00:00
|
|
|
}
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->params.subtitle.utbl[k++]=0;
|
|
|
|
obj->params.subtitle.xtbl[obj->params.subtitle.lines++]=(dxs-xsize)/2;
|
2002-04-15 20:51:34 +00:00
|
|
|
if(xmin>(dxs-xsize)/2) xmin=(dxs-xsize)/2;
|
|
|
|
if(xmax<(dxs+xsize)/2) xmax=(dxs+xsize)/2;
|
2002-04-15 19:17:12 +00:00
|
|
|
if (obj->params.subtitle.lines==MAX_UCSLINES||k>MAX_UCS){
|
2001-10-15 06:14:55 +00:00
|
|
|
l=0; len=j; // end parsing
|
2001-08-21 11:28:50 +00:00
|
|
|
} else if(l || j<len){ // not the last line or not the last char
|
2001-08-20 09:14:28 +00:00
|
|
|
lastStripPosition=-1;
|
|
|
|
xsize=-vo_font->charspace;
|
|
|
|
lasth=h;
|
|
|
|
h=vo_font->height;
|
|
|
|
}
|
2001-10-12 13:24:07 +00:00
|
|
|
// printf("h: %d -> %d \n",vo_font->height,h);
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->y -=h; // according to max of vo_font->pic_a[font]->h
|
2002-08-28 20:45:42 +00:00
|
|
|
prevc = -1;
|
2001-08-20 09:14:28 +00:00
|
|
|
}
|
2001-08-17 11:14:57 +00:00
|
|
|
}
|
2002-04-15 20:51:34 +00:00
|
|
|
|
2002-04-17 20:46:12 +00:00
|
|
|
if (obj->y >= (dys * sub_pos / 100)){
|
|
|
|
int old=obj->y;
|
|
|
|
obj->y = dys * sub_pos /100;
|
|
|
|
obj->bbox.y2-=old-obj->y;
|
|
|
|
}
|
|
|
|
|
2002-04-15 20:51:34 +00:00
|
|
|
// calculate bbox:
|
|
|
|
obj->bbox.x1=xmin;
|
|
|
|
obj->bbox.x2=xmax;
|
|
|
|
obj->bbox.y1=obj->y;
|
2002-04-17 20:46:12 +00:00
|
|
|
// obj->bbox.y2=obj->y+obj->params.subtitle.lines*vo_font->height;
|
2002-04-15 20:51:34 +00:00
|
|
|
obj->flags|=OSDFLAG_BBOX;
|
2002-08-28 20:45:42 +00:00
|
|
|
|
|
|
|
alloc_buf(obj);
|
|
|
|
|
|
|
|
y = obj->y;
|
|
|
|
|
|
|
|
i=j=0;
|
|
|
|
if ((l=obj->params.subtitle.lines)) for (;;) {
|
|
|
|
x=obj->params.subtitle.xtbl[i++];
|
|
|
|
prevc = -1;
|
|
|
|
while ((c=obj->params.subtitle.utbl[j++])){
|
|
|
|
x += kerning(vo_font,prevc,c);
|
|
|
|
if ((font=vo_font->font[c])>=0)
|
|
|
|
draw_alpha_buf(obj,x,y,
|
|
|
|
vo_font->width[c],
|
|
|
|
vo_font->pic_a[font]->h+y<obj->dys ? vo_font->pic_a[font]->h : obj->dys-y,
|
|
|
|
vo_font->pic_b[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->bmp+vo_font->start[c],
|
|
|
|
vo_font->pic_a[font]->w);
|
|
|
|
x+=vo_font->width[c]+vo_font->charspace;
|
|
|
|
prevc = c;
|
|
|
|
}
|
|
|
|
if (!--l) break;
|
|
|
|
y+=vo_font->height;
|
|
|
|
}
|
2002-04-15 20:51:34 +00:00
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
}
|
|
|
|
|
2002-05-25 17:40:40 +00:00
|
|
|
inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys)
|
|
|
|
{
|
|
|
|
unsigned int bbox[4];
|
|
|
|
int i;
|
|
|
|
spudec_calc_bbox(vo_spudec, dxs, dys, bbox);
|
|
|
|
obj->bbox.x1 = bbox[0];
|
|
|
|
obj->bbox.x2 = bbox[1];
|
|
|
|
obj->bbox.y1 = bbox[2];
|
|
|
|
obj->bbox.y2 = bbox[3];
|
|
|
|
obj->flags |= OSDFLAG_BBOX;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void vo_draw_spudec_sub(mp_osd_obj_t* obj, void (*draw_alpha)(int x0, int y0, int w, int h, unsigned char* src, unsigned char* srca, int stride))
|
|
|
|
{
|
|
|
|
spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha);
|
|
|
|
}
|
2001-03-24 04:36:17 +00:00
|
|
|
|
2001-11-20 18:36:50 +00:00
|
|
|
void *vo_spudec=NULL;
|
2002-01-10 17:21:00 +00:00
|
|
|
void *vo_vobsub=NULL;
|
2001-11-20 18:36:50 +00:00
|
|
|
|
2001-06-02 16:02:38 +00:00
|
|
|
static int draw_alpha_init_flag=0;
|
2001-03-25 04:28:40 +00:00
|
|
|
|
2001-06-12 14:03:18 +00:00
|
|
|
extern void vo_draw_alpha_init();
|
|
|
|
|
2002-08-22 13:58:38 +00:00
|
|
|
mp_osd_obj_t* vo_osd_list=NULL;
|
2001-03-27 00:32:24 +00:00
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
mp_osd_obj_t* new_osd_obj(int type){
|
|
|
|
mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t));
|
|
|
|
memset(osd,0,sizeof(mp_osd_obj_t));
|
|
|
|
osd->next=vo_osd_list;
|
|
|
|
vo_osd_list=osd;
|
|
|
|
osd->type=type;
|
2002-08-28 20:45:42 +00:00
|
|
|
osd->alpha_buffer = NULL;
|
|
|
|
osd->bitmap_buffer = NULL;
|
|
|
|
osd->allocated = -1;
|
2002-04-15 19:17:12 +00:00
|
|
|
return osd;
|
|
|
|
}
|
2002-01-10 17:21:00 +00:00
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
void free_osd_list(){
|
|
|
|
mp_osd_obj_t* obj=vo_osd_list;
|
|
|
|
while(obj){
|
|
|
|
mp_osd_obj_t* next=obj->next;
|
2002-08-28 20:45:42 +00:00
|
|
|
if (obj->alpha_buffer) free(obj->alpha_buffer);
|
|
|
|
if (obj->bitmap_buffer) free(obj->bitmap_buffer);
|
2002-04-15 19:17:12 +00:00
|
|
|
free(obj);
|
|
|
|
obj=next;
|
2002-01-10 17:21:00 +00:00
|
|
|
}
|
2002-04-15 19:17:12 +00:00
|
|
|
vo_osd_list=NULL;
|
|
|
|
}
|
2002-01-10 17:21:00 +00:00
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
int vo_update_osd(int dxs,int dys){
|
|
|
|
mp_osd_obj_t* obj=vo_osd_list;
|
|
|
|
int chg=0;
|
2002-08-28 20:45:42 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_FREETYPE
|
|
|
|
// here is the right place to get screen dimensions
|
|
|
|
if (force_load_font) {
|
|
|
|
force_load_font = 0;
|
|
|
|
load_font(dxs, dys);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
while(obj){
|
|
|
|
if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){
|
|
|
|
int vis=obj->flags&OSDFLAG_VISIBLE;
|
2002-04-15 20:51:34 +00:00
|
|
|
obj->flags&=~OSDFLAG_BBOX;
|
2002-04-15 19:17:12 +00:00
|
|
|
switch(obj->type){
|
|
|
|
case OSDTYPE_SUBTITLE:
|
|
|
|
vo_update_text_sub(obj,dxs,dys);
|
|
|
|
break;
|
|
|
|
case OSDTYPE_PROGBAR:
|
|
|
|
vo_update_text_progbar(obj,dxs,dys);
|
|
|
|
break;
|
|
|
|
case OSDTYPE_SPU:
|
2002-10-06 17:40:51 +00:00
|
|
|
if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){
|
2002-05-25 17:40:40 +00:00
|
|
|
vo_update_spudec_sub(obj, dxs, dys);
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
|
2002-05-25 17:40:40 +00:00
|
|
|
}
|
2002-04-15 19:17:12 +00:00
|
|
|
else
|
|
|
|
obj->flags&=~OSDFLAG_VISIBLE;
|
|
|
|
break;
|
|
|
|
case OSDTYPE_OSD:
|
2002-04-15 20:51:34 +00:00
|
|
|
if(vo_font && vo_osd_text && vo_osd_text[0]){
|
|
|
|
vo_update_text_osd(obj,dxs,dys); // update bbox
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
|
2002-04-15 20:51:34 +00:00
|
|
|
} else
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->flags&=~OSDFLAG_VISIBLE;
|
|
|
|
break;
|
|
|
|
}
|
2002-04-15 20:51:34 +00:00
|
|
|
// check bbox:
|
|
|
|
if(!(obj->flags&OSDFLAG_BBOX)){
|
|
|
|
// we don't know, so assume the whole screen changed :(
|
|
|
|
obj->bbox.x1=obj->bbox.y1=0;
|
|
|
|
obj->bbox.x2=dxs;
|
|
|
|
obj->bbox.y2=dys;
|
|
|
|
obj->flags|=OSDFLAG_BBOX;
|
2002-04-17 20:46:12 +00:00
|
|
|
} else {
|
|
|
|
// check bbox, reduce it if it's out of bounds (corners):
|
|
|
|
if(obj->bbox.x1<0) obj->bbox.x1=0;
|
|
|
|
if(obj->bbox.y1<0) obj->bbox.y1=0;
|
|
|
|
if(obj->bbox.x2>dxs) obj->bbox.x2=dxs;
|
|
|
|
if(obj->bbox.y2>dys) obj->bbox.y2=dys;
|
|
|
|
if(obj->flags&OSDFLAG_VISIBLE)
|
|
|
|
// debug:
|
|
|
|
mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n",
|
2002-04-15 20:51:34 +00:00
|
|
|
obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1,
|
|
|
|
obj->bbox.y2-obj->bbox.y1);
|
|
|
|
}
|
2002-04-15 19:17:12 +00:00
|
|
|
// check if visibility changed:
|
|
|
|
if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED;
|
2002-04-15 20:51:34 +00:00
|
|
|
// remove the cause of automatic update:
|
2002-04-15 19:17:12 +00:00
|
|
|
obj->dxs=dxs; obj->dys=dys;
|
|
|
|
obj->flags&=~OSDFLAG_FORCE_UPDATE;
|
|
|
|
}
|
|
|
|
if(obj->flags&OSDFLAG_CHANGED){
|
|
|
|
chg|=1<<obj->type;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
obj=obj->next;
|
|
|
|
}
|
|
|
|
return chg;
|
|
|
|
}
|
2001-03-27 00:32:24 +00:00
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
void vo_init_osd(){
|
2001-06-02 16:02:38 +00:00
|
|
|
if(!draw_alpha_init_flag){
|
|
|
|
draw_alpha_init_flag=1;
|
|
|
|
vo_draw_alpha_init();
|
|
|
|
}
|
2002-05-17 23:47:27 +00:00
|
|
|
if(vo_osd_list) free_osd_list();
|
2002-04-15 19:17:12 +00:00
|
|
|
// temp hack, should be moved to mplayer/mencoder later
|
|
|
|
new_osd_obj(OSDTYPE_OSD);
|
|
|
|
new_osd_obj(OSDTYPE_SUBTITLE);
|
|
|
|
new_osd_obj(OSDTYPE_PROGBAR);
|
|
|
|
new_osd_obj(OSDTYPE_SPU);
|
2002-08-28 20:45:42 +00:00
|
|
|
#ifdef HAVE_FREETYPE
|
|
|
|
force_load_font = 1;
|
|
|
|
#endif
|
2002-04-15 19:17:12 +00:00
|
|
|
}
|
2001-06-02 16:02:38 +00:00
|
|
|
|
2002-04-15 22:08:50 +00:00
|
|
|
int vo_osd_changed_flag=0;
|
2002-04-15 19:17:12 +00:00
|
|
|
|
2002-04-15 22:08:50 +00:00
|
|
|
void vo_remove_text(int dxs,int dys,void (*remove)(int x0,int y0, int w,int h)){
|
|
|
|
mp_osd_obj_t* obj=vo_osd_list;
|
2002-04-15 19:17:12 +00:00
|
|
|
vo_update_osd(dxs,dys);
|
2002-04-15 22:08:50 +00:00
|
|
|
while(obj){
|
|
|
|
if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) &&
|
|
|
|
(obj->flags&OSDFLAG_OLD_BBOX)){
|
|
|
|
int w=obj->old_bbox.x2-obj->old_bbox.x1;
|
|
|
|
int h=obj->old_bbox.y2-obj->old_bbox.y1;
|
|
|
|
if(w>0 && h>0){
|
|
|
|
vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
|
|
|
|
remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h);
|
|
|
|
}
|
|
|
|
// obj->flags&=~OSDFLAG_OLD_BBOX;
|
|
|
|
}
|
2002-04-16 00:35:01 +00:00
|
|
|
obj=obj->next;
|
2002-04-15 22:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-15 19:17:12 +00:00
|
|
|
|
2002-04-15 22:08:50 +00:00
|
|
|
void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
|
|
|
|
mp_osd_obj_t* obj=vo_osd_list;
|
|
|
|
vo_update_osd(dxs,dys);
|
2002-04-15 19:17:12 +00:00
|
|
|
while(obj){
|
2002-04-15 22:08:50 +00:00
|
|
|
if(obj->flags&OSDFLAG_VISIBLE){
|
|
|
|
vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
|
2002-04-15 19:17:12 +00:00
|
|
|
switch(obj->type){
|
|
|
|
case OSDTYPE_SPU:
|
2002-05-25 17:40:40 +00:00
|
|
|
vo_draw_spudec_sub(obj, draw_alpha); // FIXME
|
2002-04-15 19:17:12 +00:00
|
|
|
break;
|
|
|
|
case OSDTYPE_OSD:
|
|
|
|
case OSDTYPE_SUBTITLE:
|
|
|
|
case OSDTYPE_PROGBAR:
|
2002-08-28 20:45:42 +00:00
|
|
|
vo_draw_text_from_buffer(obj,draw_alpha);
|
2002-04-15 19:17:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
obj->old_bbox=obj->bbox;
|
2002-04-15 22:08:50 +00:00
|
|
|
obj->flags|=OSDFLAG_OLD_BBOX;
|
|
|
|
}
|
|
|
|
obj->flags&=~OSDFLAG_CHANGED;
|
|
|
|
obj=obj->next;
|
2001-03-27 00:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-15 19:17:12 +00:00
|
|
|
|
2002-02-22 15:25:11 +00:00
|
|
|
static int vo_osd_changed_status = 0;
|
|
|
|
|
|
|
|
int vo_osd_changed(int new_value)
|
|
|
|
{
|
2002-04-15 19:17:12 +00:00
|
|
|
mp_osd_obj_t* obj=vo_osd_list;
|
2002-02-22 15:25:11 +00:00
|
|
|
int ret = vo_osd_changed_status;
|
|
|
|
vo_osd_changed_status = new_value;
|
2002-04-15 19:17:12 +00:00
|
|
|
|
|
|
|
while(obj){
|
|
|
|
if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE;
|
|
|
|
obj=obj->next;
|
|
|
|
}
|
|
|
|
|
2002-02-22 15:25:11 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2002-04-15 19:17:12 +00:00
|
|
|
|
2002-04-16 00:35:01 +00:00
|
|
|
// BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB
|
|
|
|
// BBBBBBBBBBBB BBBBBBBBBBBBB
|
|
|
|
// BBBBBBB
|
|
|
|
|
|
|
|
// return TRUE if we have osd in the specified rectangular area:
|
|
|
|
int vo_osd_check_range_update(int x1,int y1,int x2,int y2){
|
|
|
|
mp_osd_obj_t* obj=vo_osd_list;
|
|
|
|
while(obj){
|
|
|
|
if(obj->flags&OSDFLAG_VISIBLE){
|
|
|
|
if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) &&
|
|
|
|
(obj->bbox.y1<=y2 && obj->bbox.y2>=y1) ) return 1;
|
|
|
|
}
|
|
|
|
obj=obj->next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|