Mercurial > mplayer.hg
annotate libvo/font_load.c @ 3041:6b31e121f36a
Changed the some functions prototypes for the network streaming.
author | bertrand |
---|---|
date | Tue, 20 Nov 2001 22:17:16 +0000 |
parents | a6c5a537f30a |
children | 48e91dc9534b |
rev | line source |
---|---|
213 | 1 |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include <string.h> | |
1446 | 5 #include <sys/types.h> |
6 #include <sys/stat.h> | |
7 #include <unistd.h> | |
213 | 8 |
947
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
9 #include "config.h" |
213 | 10 #include "font_load.h" |
11 | |
2476 | 12 extern char *get_path ( char * ); |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
13 |
339 | 14 raw_file* load_raw(char *name,int verbose){ |
213 | 15 int bpp; |
16 raw_file* raw=malloc(sizeof(raw_file)); | |
17 unsigned char head[32]; | |
18 FILE *f=fopen(name,"rb"); | |
19 if(!f) return NULL; // can't open | |
20 if(fread(head,32,1,f)<1) return NULL; // too small | |
21 if(memcmp(head,"mhwanh",6)) return NULL; // not raw file | |
22 raw->w=head[8]*256+head[9]; | |
23 raw->h=head[10]*256+head[11]; | |
24 raw->c=head[12]*256+head[13]; | |
25 if(raw->c>256) return NULL; // too many colors!? | |
339 | 26 if(verbose) printf("RAW: %s %d x %d, %d colors\n",name,raw->w,raw->h,raw->c); |
213 | 27 if(raw->c){ |
28 raw->pal=malloc(raw->c*3); | |
29 fread(raw->pal,3,raw->c,f); | |
30 bpp=1; | |
31 } else { | |
32 raw->pal=NULL; | |
33 bpp=3; | |
34 } | |
35 raw->bmp=malloc(raw->h*raw->w*bpp); | |
36 fread(raw->bmp,raw->h*raw->w*bpp,1,f); | |
37 fclose(f); | |
38 return raw; | |
39 } | |
40 | |
728 | 41 extern int sub_unicode; |
42 | |
339 | 43 font_desc_t* read_font_desc(char* fname,float factor,int verbose){ |
213 | 44 unsigned char sor[1024]; |
45 unsigned char sor2[1024]; | |
46 font_desc_t *desc; | |
47 FILE *f; | |
2222
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
48 char *dn; |
1446 | 49 struct stat fstate; |
213 | 50 char section[64]; |
51 int i,j; | |
52 int chardb=0; | |
53 int fontdb=-1; | |
214 | 54 int version=0; |
213 | 55 |
56 desc=malloc(sizeof(font_desc_t));if(!desc) return NULL; | |
57 memset(desc,0,sizeof(font_desc_t)); | |
58 | |
59 f=fopen(fname,"rt");if(!f){ printf("font: can't open file: %s\n",fname); return NULL;} | |
60 | |
2222
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
61 i = strlen (fname) - 9; |
2223 | 62 if ((dn = malloc(i+1))){ |
2222
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
63 strncpy (dn, fname, i); |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
64 dn[i]='\0'; |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
65 } |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
66 |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
67 desc->fpath = dn; // search in the same dir as fonts.desc |
1446 | 68 |
2222
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
69 // desc->fpath=get_path("font/"); |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
70 // if (stat(desc->fpath, &fstate)!=0) desc->fpath=DATADIR"/font"; |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
71 |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
72 |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
73 |
1446 | 74 |
213 | 75 // set up some defaults, and erase table |
76 desc->charspace=2; | |
77 desc->spacewidth=12; | |
78 desc->height=0; | |
79 for(i=0;i<512;i++) desc->start[i]=desc->width[i]=desc->font[i]=-1; | |
80 | |
81 section[0]=0; | |
82 | |
83 while(fgets(sor,1020,f)){ | |
84 unsigned char* p[8]; | |
85 int pdb=0; | |
86 unsigned char *s=sor; | |
87 unsigned char *d=sor2; | |
88 int ec=' '; | |
89 int id=0; | |
90 sor[1020]=0; | |
91 p[0]=d;++pdb; | |
92 while(1){ | |
93 int c=*s++; | |
94 if(c==0 || c==13 || c==10) break; | |
95 if(!id){ | |
96 if(c==39 || c==34){ id=c;continue;} // idezojel | |
97 if(c==';' || c=='#') break; | |
98 if(c==9) c=' '; | |
99 if(c==' '){ | |
100 if(ec==' ') continue; | |
101 *d=0; ++d; | |
102 p[pdb]=d;++pdb; | |
103 if(pdb>=8) break; | |
104 continue; | |
105 } | |
106 } else { | |
107 if(id==c){ id=0;continue;} // idezojel | |
108 | |
109 } | |
110 *d=c;d++; | |
111 ec=c; | |
112 } | |
113 if(d==sor2) continue; // skip empty lines | |
114 *d=0; | |
115 | |
116 // printf("params=%d sor=%s\n",pdb,sor); | |
117 // for(i=0;i<pdb;i++) printf(" param %d = '%s'\n",i,p[i]); | |
118 | |
119 if(pdb==1 && p[0][0]=='['){ | |
120 int len=strlen(p[0]); | |
121 if(len && len<63 && p[0][len-1]==']'){ | |
122 strcpy(section,p[0]); | |
339 | 123 if(verbose) printf("font: Reading section: %s\n",section); |
213 | 124 if(strcmp(section,"[files]")==0){ |
125 ++fontdb; | |
126 if(fontdb>=16){ printf("font: Too many bitmaps defined!\n");return NULL;} | |
127 } | |
128 continue; | |
129 } | |
130 } | |
131 | |
1353 | 132 if(strcmp(section,"[fpath]")==0){ |
133 if(pdb==1){ | |
2222
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
134 if (desc->fpath) |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
135 free (desc->fpath); // release previously allocated memory |
1353 | 136 desc->fpath=strdup(p[0]); |
137 continue; | |
138 } | |
139 } else | |
140 | |
213 | 141 if(strcmp(section,"[files]")==0){ |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
142 char *default_dir=DATADIR"/font"; |
213 | 143 if(pdb==2 && strcmp(p[0],"alpha")==0){ |
1353 | 144 char *cp; |
145 if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) return NULL; | |
146 | |
147 snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s/%s", | |
148 desc->fpath,p[1]); | |
149 if(!((desc->pic_a[fontdb]=load_raw(cp,verbose)))){ | |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
150 free(cp); |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
151 if (!(cp=malloc(strlen(default_dir)+strlen(p[1])+2))) |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
152 return NULL; |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
153 snprintf(cp,strlen(default_dir)+strlen(p[1])+2,"%s/%s", |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
154 default_dir,p[1]); |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
155 if (!((desc->pic_a[fontdb]=load_raw(cp,verbose)))){ |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
156 printf("Can't load font bitmap: %s\n",p[1]); |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
157 free(cp); |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
158 return NULL; |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
159 } |
213 | 160 } |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
161 free(cp); |
213 | 162 continue; |
163 } | |
164 if(pdb==2 && strcmp(p[0],"bitmap")==0){ | |
1353 | 165 char *cp; |
166 if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) return NULL; | |
167 | |
168 snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s/%s", | |
169 desc->fpath,p[1]); | |
170 if(!((desc->pic_b[fontdb]=load_raw(cp,verbose)))){ | |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
171 free(cp); |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
172 if (!(cp=malloc(strlen(default_dir)+strlen(p[1])+2))) |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
173 return NULL; |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
174 snprintf(cp,strlen(default_dir)+strlen(p[1])+2,"%s/%s", |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
175 default_dir,p[1]); |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
176 if (!((desc->pic_b[fontdb]=load_raw(cp,verbose)))){ |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
177 printf("Can't load font bitmap: %s\n",p[1]); |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
178 free(cp); |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
179 return NULL; |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
180 } |
213 | 181 } |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
182 free(cp); |
213 | 183 continue; |
184 } | |
185 } else | |
186 | |
187 if(strcmp(section,"[info]")==0){ | |
214 | 188 if(pdb==2 && strcmp(p[0],"name")==0){ |
189 desc->name=strdup(p[1]); | |
190 continue; | |
191 } | |
192 if(pdb==2 && strcmp(p[0],"descversion")==0){ | |
193 version=atoi(p[1]); | |
194 continue; | |
195 } | |
213 | 196 if(pdb==2 && strcmp(p[0],"spacewidth")==0){ |
197 desc->spacewidth=atoi(p[1]); | |
198 continue; | |
199 } | |
200 if(pdb==2 && strcmp(p[0],"charspace")==0){ | |
201 desc->charspace=atoi(p[1]); | |
202 continue; | |
203 } | |
204 if(pdb==2 && strcmp(p[0],"height")==0){ | |
205 desc->height=atoi(p[1]); | |
206 continue; | |
207 } | |
208 } else | |
214 | 209 |
213 | 210 if(strcmp(section,"[characters]")==0){ |
219 | 211 if(pdb==3){ |
213 | 212 int chr=p[0][0]; |
213 int start=atoi(p[1]); | |
214 int end=atoi(p[2]); | |
727 | 215 if(sub_unicode && (chr>=0x80)) chr=(chr<<8)+p[0][1]; |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
340
diff
changeset
|
216 else if(strlen(p[0])!=1) chr=strtol(p[0],NULL,0); |
213 | 217 if(end<start) { |
218 printf("error in font desc: end<start for char '%c'\n",chr); | |
219 } else { | |
220 desc->start[chr]=start; | |
221 desc->width[chr]=end-start+1; | |
222 desc->font[chr]=fontdb; | |
223 // printf("char %d '%c' start=%d width=%d\n",chr,chr,desc->start[chr],desc->width[chr]); | |
224 ++chardb; | |
225 } | |
226 continue; | |
227 } | |
228 } | |
229 printf("Syntax error in font desc: %s\n",sor); | |
230 | |
231 } | |
232 fclose(f); | |
233 | |
234 //printf("font: pos of U = %d\n",desc->start[218]); | |
235 | |
236 for(i=0;i<=fontdb;i++){ | |
237 if(!desc->pic_a[i] || !desc->pic_b[i]){ | |
238 printf("font: Missing bitmap(s) for sub-font #%d\n",i); | |
239 return NULL; | |
240 } | |
249 | 241 //if(factor!=1.0f) |
242 { | |
215 | 243 // re-sample alpha |
244 int f=factor*256.0f; | |
245 int size=desc->pic_a[i]->w*desc->pic_a[i]->h; | |
246 int j; | |
339 | 247 if(verbose) printf("font: resampling alpha by factor %5.3f (%d) ",factor,f);fflush(stdout); |
215 | 248 for(j=0;j<size;j++){ |
947
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
249 int x=desc->pic_a[i]->bmp[j]; // alpha |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
250 int y=desc->pic_b[i]->bmp[j]; // bitmap |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
251 |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
252 #ifdef FAST_OSD |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
253 x=(x<(255-f))?0:1; |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
254 #else |
249 | 255 |
250 | 256 x=255-((x*f)>>8); // scale |
257 //if(x<0) x=0; else if(x>255) x=255; | |
258 //x^=255; // invert | |
259 | |
249 | 260 if(x+y>255) x=255-y; // to avoid overflows |
261 | |
262 //x=0; | |
263 //x=((x*f*(255-y))>>16); | |
264 //x=((x*f*(255-y))>>16)+y; | |
215 | 265 //x=(x*f)>>8;if(x<y) x=y; |
250 | 266 |
249 | 267 if(x<1) x=1; else |
268 if(x>=252) x=0; | |
947
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
269 #endif |
250 | 270 |
215 | 271 desc->pic_a[i]->bmp[j]=x; |
250 | 272 // desc->pic_b[i]->bmp[j]=0; // hack |
215 | 273 } |
339 | 274 if(verbose) printf("DONE!\n"); |
215 | 275 } |
213 | 276 if(!desc->height) desc->height=desc->pic_a[i]->h; |
277 } | |
278 | |
279 j='_';if(desc->font[j]<0) j='?'; | |
280 for(i=0;i<512;i++) | |
281 if(desc->font[i]<0){ | |
282 desc->start[i]=desc->start[j]; | |
283 desc->width[i]=desc->width[j]; | |
284 desc->font[i]=desc->font[j]; | |
285 } | |
286 desc->font[' ']=-1; | |
287 desc->width[' ']=desc->spacewidth; | |
288 | |
340 | 289 printf("Font %s loaded successfully! (%d chars)\n",fname,chardb); |
213 | 290 |
291 return desc; | |
292 } | |
293 | |
294 #if 0 | |
295 int main(){ | |
296 | |
339 | 297 read_font_desc("high_arpi.desc",1); |
213 | 298 |
299 } | |
300 #endif |