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