comparison libvo/sub.c @ 1501:d40f2b686846

changes according to -utf8 option, draw_osd() function added
author atlka
date Mon, 13 Aug 2001 11:08:18 +0000
parents a013b2124f05
children ccb1f3ddb29a
comparison
equal deleted inserted replaced
1500:526047bdda07 1501:d40f2b686846
4 //static int vo_font_loaded=-1; 4 //static int vo_font_loaded=-1;
5 font_desc_t* vo_font=NULL; 5 font_desc_t* vo_font=NULL;
6 6
7 unsigned char* vo_osd_text="00:00:00"; 7 unsigned char* vo_osd_text="00:00:00";
8 int sub_unicode=0; 8 int sub_unicode=0;
9 9 int sub_utf8=0;
10 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)){ 10
11 int len=strlen(vo_osd_text); 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)){
12 int j; 12 unsigned char *cp=vo_osd_text;
13 int c;
14 int font;
13 int y=10; 15 int y=10;
14 int x=20; 16 int x=20;
15 17
16 for(j=0;j<len;j++){ 18 while (*cp){
17 int c=vo_osd_text[j]; 19 c=*cp;
18 int font=vo_font->font[c]; 20 cp++;
19 if(font>=0) 21 if ((font=vo_font->font[c])>=0)
20 draw_alpha(x,y, 22 draw_alpha(x,y,
21 vo_font->width[c], 23 vo_font->width[c],
22 vo_font->pic_a[font]->h, 24 vo_font->pic_a[font]->h,
23 vo_font->pic_b[font]->bmp+vo_font->start[c], 25 vo_font->pic_b[font]->bmp+vo_font->start[c],
24 vo_font->pic_a[font]->bmp+vo_font->start[c], 26 vo_font->pic_a[font]->bmp+vo_font->start[c],
29 } 31 }
30 32
31 int vo_osd_progbar_type=-1; 33 int vo_osd_progbar_type=-1;
32 int vo_osd_progbar_value=100; // 0..255 34 int vo_osd_progbar_value=100; // 0..255
33 35
34 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)){ 36 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)){
35 int i; 37 int i;
36 int y=dys/2; 38 int y=(dys-vo_font->height)/2;
37 int x; 39 int x;
38 int c,font; 40 int c,font;
39 int width=(dxs*2/3-vo_font->width[0x10]-vo_font->width[0x12]); 41 int width=(dxs*2/3-vo_font->width[0x10]-vo_font->width[0x12]);
40 int elems=width/vo_font->width[0x11]; 42 int elems=width/vo_font->width[0x11];
41 int mark=(vo_osd_progbar_value*(elems+1))>>8; 43 int mark=(vo_osd_progbar_value*(elems+1))>>8;
42 x=(dxs-width)/2; 44 x=(dxs-width)/2;
43 // printf("osd.progbar width=%d xpos=%d\n",width,x); 45 // printf("osd.progbar width=%d xpos=%d\n",width,x);
44 46
45 c=vo_osd_progbar_type;font=vo_font->font[c]; 47 c=vo_osd_progbar_type;
46 if(vo_osd_progbar_type>0 && font>=0) 48 if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0)
47 draw_alpha(x-vo_font->width[c]-vo_font->spacewidth,y, 49 draw_alpha(x-vo_font->width[c]-vo_font->spacewidth,y,
48 vo_font->width[c], 50 vo_font->width[c],
49 vo_font->pic_a[font]->h, 51 vo_font->pic_a[font]->h,
50 vo_font->pic_b[font]->bmp+vo_font->start[c], 52 vo_font->pic_b[font]->bmp+vo_font->start[c],
51 vo_font->pic_a[font]->bmp+vo_font->start[c], 53 vo_font->pic_a[font]->bmp+vo_font->start[c],
52 vo_font->pic_a[font]->w); 54 vo_font->pic_a[font]->w);
53 55
54 c=OSD_PB_START;font=vo_font->font[c]; 56 c=OSD_PB_START;
55 if(font>=0) 57 if ((font=vo_font->font[c])>=0)
56 draw_alpha(x,y, 58 draw_alpha(x,y,
57 vo_font->width[c], 59 vo_font->width[c],
58 vo_font->pic_a[font]->h, 60 vo_font->pic_a[font]->h,
59 vo_font->pic_b[font]->bmp+vo_font->start[c], 61 vo_font->pic_b[font]->bmp+vo_font->start[c],
60 vo_font->pic_a[font]->bmp+vo_font->start[c], 62 vo_font->pic_a[font]->bmp+vo_font->start[c],
61 vo_font->pic_a[font]->w); 63 vo_font->pic_a[font]->w);
62 x+=vo_font->width[c]; 64 x+=vo_font->width[c];
63 65
64 for(i=0;i<elems;i++){ 66 c=OSD_PB_0;
65 c=(i<mark)?OSD_PB_0:OSD_PB_1;font=vo_font->font[c]; 67 if ((font=vo_font->font[c])>=0)
66 if(font>=0) 68 for (i=mark;i--;){
69 draw_alpha(x,y,
70 vo_font->width[c],
71 vo_font->pic_a[font]->h,
72 vo_font->pic_b[font]->bmp+vo_font->start[c],
73 vo_font->pic_a[font]->bmp+vo_font->start[c],
74 vo_font->pic_a[font]->w);
75 x+=vo_font->width[c];
76 }
77
78 c=OSD_PB_1;
79 if ((font=vo_font->font[c])>=0)
80 for (i=elems-mark;i--;){
81 draw_alpha(x,y,
82 vo_font->width[c],
83 vo_font->pic_a[font]->h,
84 vo_font->pic_b[font]->bmp+vo_font->start[c],
85 vo_font->pic_a[font]->bmp+vo_font->start[c],
86 vo_font->pic_a[font]->w);
87 x+=vo_font->width[c];
88 }
89
90 c=OSD_PB_END;
91 if ((font=vo_font->font[c])>=0)
67 draw_alpha(x,y, 92 draw_alpha(x,y,
68 vo_font->width[c], 93 vo_font->width[c],
69 vo_font->pic_a[font]->h, 94 vo_font->pic_a[font]->h,
70 vo_font->pic_b[font]->bmp+vo_font->start[c], 95 vo_font->pic_b[font]->bmp+vo_font->start[c],
71 vo_font->pic_a[font]->bmp+vo_font->start[c], 96 vo_font->pic_a[font]->bmp+vo_font->start[c],
72 vo_font->pic_a[font]->w); 97 vo_font->pic_a[font]->w);
73 x+=vo_font->width[c];
74 }
75
76 c=OSD_PB_END;font=vo_font->font[c];
77 if(font>=0)
78 draw_alpha(x,y,
79 vo_font->width[c],
80 vo_font->pic_a[font]->h,
81 vo_font->pic_b[font]->bmp+vo_font->start[c],
82 vo_font->pic_a[font]->bmp+vo_font->start[c],
83 vo_font->pic_a[font]->w);
84 // x+=vo_font->width[c]; 98 // x+=vo_font->width[c];
85 99
86 100
87 // vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF; 101 // vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF;
88 102
89 } 103 }
90 104
91 subtitle* vo_sub=NULL; 105 subtitle* vo_sub=NULL;
92 106
93 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)){ 107 #define MAX_UCS 1600
94 int i; 108 #define MAX_UCSLINES 16
95 int y; 109
96 y=dys-(1+vo_sub->lines-1)*vo_font->height-10; 110 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)){
97 111 static int utbl[MAX_UCS+1];
98 // too long lines divide into smaller ones 112 static int xtbl[MAX_UCSLINES];
99 for(i=0;i<vo_sub->lines;i++){ 113 static int lines;
100 unsigned char* text=vo_sub->text[i]; 114 static subtitle *memsub=NULL;
101 int len=strlen(text); 115 static int memy;
102 int j; 116 static int memdxs;
103 int xsize=-vo_font->charspace; 117 static int memdys;
104 int lastStripPosition=-1; 118 unsigned char *t;
105 int previousStrip=0; 119 int i;
106 int lastxsize=0; 120 int j;
107 121 int k;
108 for(j=0;j<len;j++){ 122 int l;
109 int c=text[j]; 123 int x;
110 int w; 124 int y;
111 if (sub_unicode && (c>=0x80)) c=(c<<8)+text[++j]; 125
112 w = vo_font->width[c]; 126 int c;
113 if (text[j]==' ' && dxs>xsize) 127 int len;
114 { 128 int line;
115 lastStripPosition=j; 129 int font;
116 lastxsize=xsize; 130 int lastStripPosition;
117 } 131 int xsize;
118 xsize+=w+vo_font->charspace; 132 int lastxsize;
119 if (dxs<xsize && lastStripPosition>0) 133 int lastk;
120 { 134
121 xsize=lastxsize; 135 if ((memsub!=vo_sub)||(memdxs!=dxs)||(memdys!=dys)){
122 j=lastStripPosition; 136 memsub=vo_sub;
123 y-=vo_font->height; 137 memdxs=dxs;
124 previousStrip=lastStripPosition; 138 memdys=dys;
125 xsize=-vo_font->charspace; 139
126 } 140 memy=dys-vo_font->height/4;
127 } 141
128 } 142 // too long lines divide into smaller ones
129 143 i=k=lines=0; l=vo_sub->lines;
130 144 while (l--){
131 for(i=0;i<vo_sub->lines;i++){ 145 t=vo_sub->text[i++];
132 unsigned char* text=vo_sub->text[i];// "Hello World! HÛDEJÓ!"; 146 len=strlen(t)-1;
133 int len=strlen(text); 147 xsize=lastxsize=-vo_font->charspace;
134 int j,k; 148 lastStripPosition=-1;
135 int xsize=-vo_font->charspace; 149
136 int x=0; 150 for (j=0;j<=len;j++){
137 151 if ((c=t[j])>=0x80){
138 int lastStripPosition=-1; 152 if (sub_unicode)
139 int previousStrip=0; 153 c = (c<<8) + t[++j];
140 int lastxsize=xsize; 154 else
141 155 if (sub_utf8){
142 for(j=0;j<len;j++){ 156 if ((c & 0xe0) == 0xc0) /* 2 bytes U+00080..U+0007FF*/
143 int c=text[j]; 157 c = (c & 0x1f)<<6 | (t[++j] & 0x3f);
144 int w; 158 else if((c & 0xf0) == 0xe0)/* 3 bytes U+00800..U+00FFFF*/
145 if (sub_unicode && (c>=0x80)) c=(c<<8)+text[++j]; 159 c = ((c & 0x0f)<<6 |
146 w = vo_font->width[c]; 160 (t[++j] & 0x3f))<<6 | (t[++j] & 0x3f);
147 if (c==' ' && dxs>xsize) 161 }
148 { 162 }
149 lastStripPosition=j; 163 if (k==MAX_UCS){
150 lastxsize=xsize; 164 utbl[k]=l=0;
165 break;
166 } else
167 utbl[k++]=c;
168 if (c==' '){
169 lastk=k;
170 lastStripPosition=j;
171 lastxsize=xsize;
172 }
173 xsize+=vo_font->width[c]+vo_font->charspace;
174 if (dxs<xsize && lastStripPosition>0){
175 j=lastStripPosition;
176 k=lastk;
177 } else if (j==len){
178 lastxsize=xsize;
179 } else
180 continue;
181 utbl[k++]=0;
182 xtbl[lines++]=(dxs-lastxsize)/2;
183 if (lines==MAX_UCSLINES||k>MAX_UCS){
184 l=0;
185 break;
186 }
187 memy-=vo_font->height;
188 xsize=lastxsize=-vo_font->charspace;
151 } 189 }
152 xsize+=w+vo_font->charspace; 190 xsize+=w+vo_font->charspace;
153 if ((dxs<xsize && lastStripPosition>0) || j==len-1) 191 if ((dxs<xsize && lastStripPosition>0) || j==len-1)
154 { 192 {
155 if (j==len-1) lastStripPosition=len; 193 if (j==len-1) lastStripPosition=len;
177 y+=vo_font->height; 215 y+=vo_font->height;
178 previousStrip=lastStripPosition; 216 previousStrip=lastStripPosition;
179 xsize=lastxsize=-vo_font->charspace; 217 xsize=lastxsize=-vo_font->charspace;
180 } 218 }
181 } 219 }
182 } 220 }
183 221
222 y = memy;
223
224 k=i=0; l=lines;
225 while (l--){
226 x = xtbl[i++];
227 while (utbl[k]){
228 c=utbl[k];
229 k++;
230 if (x>=0 && x+vo_font->width[c]<=dxs)
231 if ((font=vo_font->font[c])>=0)
232 draw_alpha(x,y,
233 vo_font->width[c],
234 vo_font->pic_a[font]->h,
235 vo_font->pic_b[font]->bmp+vo_font->start[c],
236 vo_font->pic_a[font]->bmp+vo_font->start[c],
237 vo_font->pic_a[font]->w);
238 x+=vo_font->width[c]+vo_font->charspace;
239 }
240 y+=vo_font->height;
241 }
184 } 242 }
185 243
186 static int draw_alpha_init_flag=0; 244 static int draw_alpha_init_flag=0;
187 245
188 extern void vo_draw_alpha_init(); 246 extern void vo_draw_alpha_init();