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