Mercurial > mplayer.hg
annotate libvo/sub.c @ 1690:09f9297d2ee6
-vo help fixed
author | arpi |
---|---|
date | Sat, 25 Aug 2001 19:11:24 +0000 |
parents | 48f589cf639b |
children | 38871427a131 |
rev | line source |
---|---|
218 | 1 |
2 #include "sub.h" | |
202 | 3 |
213 | 4 //static int vo_font_loaded=-1; |
5 font_desc_t* vo_font=NULL; | |
202 | 6 |
213 | 7 unsigned char* vo_osd_text="00:00:00"; |
803
b25a887b6054
sub splitting patch applied by Vlada V.Dubsky@sh.cvut.cz
arpi_esp
parents:
726
diff
changeset
|
8 int sub_unicode=0; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
9 int sub_utf8=0; |
213 | 10 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
11 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)){ |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
12 unsigned char *cp=vo_osd_text; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
13 int c; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
14 int font; |
213 | 15 int y=10; |
16 int x=20; | |
202 | 17 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
18 while (*cp){ |
1549 | 19 c=*cp++; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
20 if ((font=vo_font->font[c])>=0) |
213 | 21 draw_alpha(x,y, |
22 vo_font->width[c], | |
23 vo_font->pic_a[font]->h, | |
24 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
25 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
26 vo_font->pic_a[font]->w); | |
27 x+=vo_font->width[c]+vo_font->charspace; | |
28 } | |
218 | 29 |
30 } | |
31 | |
32 int vo_osd_progbar_type=-1; | |
33 int vo_osd_progbar_value=100; // 0..255 | |
34 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
35 inline static void vo_draw_text_progbar(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){ |
1602 | 36 unsigned char *s; |
37 unsigned char *sa; | |
38 int i,w,h,st; | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
39 int y=(dys-vo_font->height)/2; |
218 | 40 int c,font; |
1548
eee7951a23af
changes according to proper subfont bar positioning and char spaceing - sub.c
atlka
parents:
1524
diff
changeset
|
41 int delimw=vo_font->width[OSD_PB_START] |
1549 | 42 +vo_font->width[OSD_PB_END] |
43 +vo_font->charspace; | |
1548
eee7951a23af
changes according to proper subfont bar positioning and char spaceing - sub.c
atlka
parents:
1524
diff
changeset
|
44 int width=(2*dxs-3*delimw)/3; |
1549 | 45 int charw=vo_font->width[OSD_PB_0]+vo_font->charspace; |
1548
eee7951a23af
changes according to proper subfont bar positioning and char spaceing - sub.c
atlka
parents:
1524
diff
changeset
|
46 int elems=width/charw; |
1549 | 47 int x=(dxs-elems*charw-delimw)/2; |
218 | 48 int mark=(vo_osd_progbar_value*(elems+1))>>8; |
1548
eee7951a23af
changes according to proper subfont bar positioning and char spaceing - sub.c
atlka
parents:
1524
diff
changeset
|
49 |
218 | 50 // printf("osd.progbar width=%d xpos=%d\n",width,x); |
51 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
52 c=vo_osd_progbar_type; |
1569
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
53 if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0) { |
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
54 int xp=x-vo_font->width[c]-vo_font->spacewidth; |
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
55 draw_alpha((xp<0?0:xp),y, |
218 | 56 vo_font->width[c], |
57 vo_font->pic_a[font]->h, | |
58 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
59 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
60 vo_font->pic_a[font]->w); | |
1569
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
61 } |
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
62 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
63 c=OSD_PB_START; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
64 if ((font=vo_font->font[c])>=0) |
218 | 65 draw_alpha(x,y, |
66 vo_font->width[c], | |
67 vo_font->pic_a[font]->h, | |
68 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
69 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
70 vo_font->pic_a[font]->w); | |
1548
eee7951a23af
changes according to proper subfont bar positioning and char spaceing - sub.c
atlka
parents:
1524
diff
changeset
|
71 x+=vo_font->width[c]+vo_font->charspace; |
218 | 72 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
73 c=OSD_PB_0; |
1602 | 74 if ((font=vo_font->font[c])>=0){ |
75 w=vo_font->width[c]; | |
76 h=vo_font->pic_a[font]->h; | |
77 s=vo_font->pic_b[font]->bmp+vo_font->start[c]; | |
78 sa=vo_font->pic_a[font]->bmp+vo_font->start[c]; | |
79 st=vo_font->pic_a[font]->w; | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
80 for (i=mark;i--;){ |
1602 | 81 draw_alpha(x,y,w,h,s,sa,st); |
1548
eee7951a23af
changes according to proper subfont bar positioning and char spaceing - sub.c
atlka
parents:
1524
diff
changeset
|
82 x+=charw; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
83 } |
1602 | 84 } |
202 | 85 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
86 c=OSD_PB_1; |
1602 | 87 if ((font=vo_font->font[c])>=0){ |
88 w=vo_font->width[c]; | |
89 h=vo_font->pic_a[font]->h; | |
90 s =vo_font->pic_b[font]->bmp+vo_font->start[c]; | |
91 sa=vo_font->pic_a[font]->bmp+vo_font->start[c]; | |
92 st=vo_font->pic_a[font]->w; | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
93 for (i=elems-mark;i--;){ |
1602 | 94 draw_alpha(x,y,w,h,s,sa,st); |
1548
eee7951a23af
changes according to proper subfont bar positioning and char spaceing - sub.c
atlka
parents:
1524
diff
changeset
|
95 x+=charw; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
96 } |
1602 | 97 } |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
98 |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
99 c=OSD_PB_END; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
100 if ((font=vo_font->font[c])>=0) |
218 | 101 draw_alpha(x,y, |
102 vo_font->width[c], | |
103 vo_font->pic_a[font]->h, | |
104 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
105 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
106 vo_font->pic_a[font]->w); | |
1548
eee7951a23af
changes according to proper subfont bar positioning and char spaceing - sub.c
atlka
parents:
1524
diff
changeset
|
107 // x+=vo_font->width[c]+vo_font->charspace; |
803
b25a887b6054
sub splitting patch applied by Vlada V.Dubsky@sh.cvut.cz
arpi_esp
parents:
726
diff
changeset
|
108 |
218 | 109 |
110 // vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF; | |
111 | |
112 } | |
113 | |
254 | 114 subtitle* vo_sub=NULL; |
218 | 115 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
116 #define MAX_UCS 1600 |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
117 #define MAX_UCSLINES 16 |
218 | 118 |
1591 | 119 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
120 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)){ |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
121 static int utbl[MAX_UCS+1]; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
122 static int xtbl[MAX_UCSLINES]; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
123 static int lines; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
124 static subtitle *memsub=NULL; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
125 static int memy; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
126 static int memdxs; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
127 static int memdys; |
1591 | 128 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
129 unsigned char *t; |
1591 | 130 int c,i,j,l,x,y,font; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
131 int len; |
1591 | 132 int k,lastk; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
133 int lastStripPosition; |
1591 | 134 int xsize,lastxsize; |
135 int h,lasth; | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
136 |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
137 if ((memsub!=vo_sub)||(memdxs!=dxs)||(memdys!=dys)){ |
1591 | 138 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
139 memsub=vo_sub; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
140 memdxs=dxs; |
1591 | 141 memdys=memy=dys; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
142 |
1602 | 143 // too long lines divide into a smaller ones |
1591 | 144 i=k=lines=lasth=0; |
145 h=vo_font->height; | |
146 xsize=-vo_font->charspace; | |
147 lastStripPosition=-1; | |
148 l=vo_sub->lines; | |
149 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
150 while (l--){ |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
151 t=vo_sub->text[i++]; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
152 len=strlen(t)-1; |
803
b25a887b6054
sub splitting patch applied by Vlada V.Dubsky@sh.cvut.cz
arpi_esp
parents:
726
diff
changeset
|
153 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
154 for (j=0;j<=len;j++){ |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
155 if ((c=t[j])>=0x80){ |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
156 if (sub_unicode) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
157 c = (c<<8) + t[++j]; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
158 else |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
159 if (sub_utf8){ |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
160 if ((c & 0xe0) == 0xc0) /* 2 bytes U+00080..U+0007FF*/ |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
161 c = (c & 0x1f)<<6 | (t[++j] & 0x3f); |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
162 else if((c & 0xf0) == 0xe0)/* 3 bytes U+00800..U+00FFFF*/ |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
163 c = ((c & 0x0f)<<6 | |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
164 (t[++j] & 0x3f))<<6 | (t[++j] & 0x3f); |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
165 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
166 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
167 if (k==MAX_UCS){ |
1591 | 168 utbl[k]=l=0; break; |
169 } | |
170 utbl[k++]=c; | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
171 if (c==' '){ |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
172 lastk=k; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
173 lastStripPosition=j; |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
174 lastxsize=xsize; |
1591 | 175 } else if ((font=vo_font->font[c])>=0){ |
176 if (vo_font->pic_a[font]->h > h){ | |
177 h=vo_font->pic_a[font]->h; | |
178 } | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
179 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
180 xsize+=vo_font->width[c]+vo_font->charspace; |
1591 | 181 if (dxs<xsize){ |
182 if (lastStripPosition>0){ | |
183 j=lastStripPosition; | |
184 xsize=lastxsize; | |
185 k=lastk; | |
186 } else { | |
187 xsize -=vo_font->width[c]+vo_font->charspace; // go back | |
188 k--; // cut line here | |
189 while (t[j] && t[j]!=' ') j++; // jump to the nearest space | |
190 } | |
191 } else if (j<len) | |
192 continue; | |
193 if (h>memy){ // out of the screen so end parsing | |
1602 | 194 memy +=vo_font->height-lasth; // correct the y position |
1591 | 195 l=0; break; |
196 } | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
197 utbl[k++]=0; |
1591 | 198 xtbl[lines++]=(dxs-xsize)/2; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
199 if (lines==MAX_UCSLINES||k>MAX_UCS){ |
1591 | 200 l=0; break; |
1602 | 201 } else if(l || j<len){ // not the last line or not the last char |
1591 | 202 lastStripPosition=-1; |
203 xsize=-vo_font->charspace; | |
204 lasth=h; | |
205 h=vo_font->height; | |
206 } | |
207 memy -=h; // according to max of vo_font->pic_a[font]->h | |
208 } | |
1573
c394d04d6b30
changes according to max of vo_font->pic_a[font]->h for the last line of subs
atlka
parents:
1569
diff
changeset
|
209 } |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
210 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
211 |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
212 y = memy; |
202 | 213 |
1591 | 214 i=j=0; l=lines; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
215 while (l--){ |
1569
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
216 x= xtbl[i++]; |
1591 | 217 while ((c=utbl[j++])){ |
1569
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
218 if ((font=vo_font->font[c])>=0) |
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
219 draw_alpha(x,y, |
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
220 vo_font->width[c], |
1573
c394d04d6b30
changes according to max of vo_font->pic_a[font]->h for the last line of subs
atlka
parents:
1569
diff
changeset
|
221 vo_font->pic_a[font]->h, |
1569
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
222 vo_font->pic_b[font]->bmp+vo_font->start[c], |
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
223 vo_font->pic_a[font]->bmp+vo_font->start[c], |
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
224 vo_font->pic_a[font]->w); |
1591 | 225 x+=vo_font->width[c]+vo_font->charspace; |
1569
fcbfc99cf8e6
skip lines with negative y position if there is too many lines to display
atlka
parents:
1549
diff
changeset
|
226 } |
1591 | 227 y+=vo_font->height; |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1109
diff
changeset
|
228 } |
218 | 229 } |
230 | |
947
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
865
diff
changeset
|
231 static int draw_alpha_init_flag=0; |
218 | 232 |
1109 | 233 extern void vo_draw_alpha_init(); |
234 | |
218 | 235 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)){ |
236 | |
237 if(!vo_font) return; // no font | |
238 | |
947
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
865
diff
changeset
|
239 if(!draw_alpha_init_flag){ |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
865
diff
changeset
|
240 draw_alpha_init_flag=1; |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
865
diff
changeset
|
241 vo_draw_alpha_init(); |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
865
diff
changeset
|
242 } |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
865
diff
changeset
|
243 |
218 | 244 if(vo_osd_text){ |
245 vo_draw_text_osd(dxs,dys,draw_alpha); | |
246 } | |
247 | |
254 | 248 if(vo_sub){ |
218 | 249 vo_draw_text_sub(dxs,dys,draw_alpha); |
250 } | |
251 | |
252 if(vo_osd_progbar_type>=0){ | |
253 vo_draw_text_progbar(dxs,dys,draw_alpha); | |
254 } | |
213 | 255 |
202 | 256 } |