mirror of https://github.com/mpv-player/mpv
draw speedups, cut text if too many lines
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1592 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
81f87d5fbf
commit
b160e4d958
107
libvo/sub.c
107
libvo/sub.c
|
@ -112,6 +112,7 @@ subtitle* vo_sub=NULL;
|
||||||
#define MAX_UCS 1600
|
#define MAX_UCS 1600
|
||||||
#define MAX_UCSLINES 16
|
#define MAX_UCSLINES 16
|
||||||
|
|
||||||
|
|
||||||
inline static void 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)){
|
inline static void 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)){
|
||||||
static int utbl[MAX_UCS+1];
|
static int utbl[MAX_UCS+1];
|
||||||
static int xtbl[MAX_UCSLINES];
|
static int xtbl[MAX_UCSLINES];
|
||||||
|
@ -120,37 +121,31 @@ inline static void vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,in
|
||||||
static int memy;
|
static int memy;
|
||||||
static int memdxs;
|
static int memdxs;
|
||||||
static int memdys;
|
static int memdys;
|
||||||
|
|
||||||
unsigned char *t;
|
unsigned char *t;
|
||||||
int i;
|
int c,i,j,l,x,y,font;
|
||||||
int j;
|
|
||||||
int k;
|
|
||||||
int l;
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
|
|
||||||
int c;
|
|
||||||
int len;
|
int len;
|
||||||
int line;
|
int k,lastk;
|
||||||
int font;
|
|
||||||
int lastStripPosition;
|
int lastStripPosition;
|
||||||
int xsize;
|
int xsize,lastxsize;
|
||||||
int lastxsize;
|
int h,lasth;
|
||||||
int lastk;
|
|
||||||
|
|
||||||
if ((memsub!=vo_sub)||(memdxs!=dxs)||(memdys!=dys)){
|
if ((memsub!=vo_sub)||(memdxs!=dxs)||(memdys!=dys)){
|
||||||
|
|
||||||
memsub=vo_sub;
|
memsub=vo_sub;
|
||||||
memdxs=dxs;
|
memdxs=dxs;
|
||||||
memdys=dys;
|
memdys=memy=dys;
|
||||||
|
|
||||||
memy=dys;
|
|
||||||
|
|
||||||
// too long lines divide into smaller ones
|
// too long lines divide into smaller ones
|
||||||
i=k=lines=y=0; l=vo_sub->lines;
|
i=k=lines=lasth=0;
|
||||||
|
h=vo_font->height;
|
||||||
|
xsize=-vo_font->charspace;
|
||||||
|
lastStripPosition=-1;
|
||||||
|
l=vo_sub->lines;
|
||||||
|
|
||||||
while (l--){
|
while (l--){
|
||||||
t=vo_sub->text[i++];
|
t=vo_sub->text[i++];
|
||||||
len=strlen(t)-1;
|
len=strlen(t)-1;
|
||||||
xsize=lastxsize=-vo_font->charspace;
|
|
||||||
lastStripPosition=-1;
|
|
||||||
|
|
||||||
for (j=0;j<=len;j++){
|
for (j=0;j<=len;j++){
|
||||||
if ((c=t[j])>=0x80){
|
if ((c=t[j])>=0x80){
|
||||||
|
@ -166,50 +161,56 @@ inline static void vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (k==MAX_UCS){
|
if (k==MAX_UCS){
|
||||||
utbl[k]=l=0;
|
utbl[k]=l=0; break;
|
||||||
break;
|
}
|
||||||
} else
|
utbl[k++]=c;
|
||||||
utbl[k++]=c;
|
|
||||||
if (c==' '){
|
if (c==' '){
|
||||||
lastk=k;
|
lastk=k;
|
||||||
lastStripPosition=j;
|
lastStripPosition=j;
|
||||||
lastxsize=xsize;
|
lastxsize=xsize;
|
||||||
} else if (!l && ((font=vo_font->font[c])>=0)){
|
} else if ((font=vo_font->font[c])>=0){
|
||||||
if (vo_font->pic_a[font]->h > y)
|
if (vo_font->pic_a[font]->h > h){
|
||||||
y=vo_font->pic_a[font]->h;
|
h=vo_font->pic_a[font]->h;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
xsize+=vo_font->width[c]+vo_font->charspace;
|
xsize+=vo_font->width[c]+vo_font->charspace;
|
||||||
if (dxs<xsize && lastStripPosition>0){
|
if (dxs<xsize){
|
||||||
j=lastStripPosition;
|
if (lastStripPosition>0){
|
||||||
k=lastk;
|
j=lastStripPosition;
|
||||||
y=vo_font->height;
|
xsize=lastxsize;
|
||||||
} else if (j==len){
|
k=lastk;
|
||||||
lastxsize=xsize;
|
} else {
|
||||||
} else
|
xsize -=vo_font->width[c]+vo_font->charspace; // go back
|
||||||
continue;
|
k--; // cut line here
|
||||||
|
while (t[j] && t[j]!=' ') j++; // jump to the nearest space
|
||||||
|
}
|
||||||
|
} else if (j<len)
|
||||||
|
continue;
|
||||||
|
if (h>memy){ // out of the screen so end parsing
|
||||||
|
memy +=vo_font->height-lasth; // correct y position
|
||||||
|
l=0; break;
|
||||||
|
}
|
||||||
utbl[k++]=0;
|
utbl[k++]=0;
|
||||||
xtbl[lines++]=(dxs-lastxsize)/2;
|
xtbl[lines++]=(dxs-xsize)/2;
|
||||||
if (lines==MAX_UCSLINES||k>MAX_UCS){
|
if (lines==MAX_UCSLINES||k>MAX_UCS){
|
||||||
l=0;
|
l=0; break;
|
||||||
break;
|
} else if(l || j<len){ // not last line or not last char
|
||||||
} else if(l || j<len){ // not last line or there is no eol
|
lastStripPosition=-1;
|
||||||
y=0;
|
xsize=-vo_font->charspace;
|
||||||
xsize=lastxsize=-vo_font->charspace;
|
lasth=h;
|
||||||
memy -=vo_font->height;
|
h=vo_font->height;
|
||||||
} else
|
}
|
||||||
memy-=y; // according to max of vo_font->pic_a[font]->h
|
memy -=h; // according to max of vo_font->pic_a[font]->h
|
||||||
} // in last line
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
y = memy;
|
y = memy;
|
||||||
|
|
||||||
k=i=0; l=lines;
|
i=j=0; l=lines;
|
||||||
while (l--){
|
while (l--){
|
||||||
if (y>=0){
|
|
||||||
x= xtbl[i++];
|
x= xtbl[i++];
|
||||||
while ((c=utbl[k++])){
|
while ((c=utbl[j++])){
|
||||||
if (x>=0 && x+vo_font->width[c]<=dxs)
|
|
||||||
if ((font=vo_font->font[c])>=0)
|
if ((font=vo_font->font[c])>=0)
|
||||||
draw_alpha(x,y,
|
draw_alpha(x,y,
|
||||||
vo_font->width[c],
|
vo_font->width[c],
|
||||||
|
@ -217,18 +218,12 @@ inline static void vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,in
|
||||||
vo_font->pic_b[font]->bmp+vo_font->start[c],
|
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]->bmp+vo_font->start[c],
|
||||||
vo_font->pic_a[font]->w);
|
vo_font->pic_a[font]->w);
|
||||||
x+=vo_font->width[c]+vo_font->charspace;
|
x+=vo_font->width[c]+vo_font->charspace;
|
||||||
}
|
}
|
||||||
} else {
|
y+=vo_font->height;
|
||||||
while (utbl[k++]) ; // skip lines with negative y value
|
|
||||||
i++; // seldom case but who knows ;-)
|
|
||||||
}
|
|
||||||
y+=vo_font->height;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int draw_alpha_init_flag=0;
|
static int draw_alpha_init_flag=0;
|
||||||
|
|
||||||
extern void vo_draw_alpha_init();
|
extern void vo_draw_alpha_init();
|
||||||
|
|
Loading…
Reference in New Issue