Mercurial > mplayer.hg
annotate libvo/font_load.c @ 2181:d90f8fc7ead6
fixed a sig4 bug an non mmx2 cpus (in case of more sig4 errors please send me a "disassemble $eip-16 $eip+16" from gdb)
author | michael |
---|---|
date | Sat, 13 Oct 2001 11:58:41 +0000 |
parents | a49fd85fc431 |
children | ddf897c38fb1 |
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 | |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
12 char *get_path ( char * ); |
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; | |
1446 | 48 struct stat fstate; |
213 | 49 char section[64]; |
50 int i,j; | |
51 int chardb=0; | |
52 int fontdb=-1; | |
214 | 53 int version=0; |
213 | 54 |
55 desc=malloc(sizeof(font_desc_t));if(!desc) return NULL; | |
56 memset(desc,0,sizeof(font_desc_t)); | |
57 | |
58 f=fopen(fname,"rt");if(!f){ printf("font: can't open file: %s\n",fname); return NULL;} | |
59 | |
1446 | 60 desc->fpath=get_path("font/"); |
61 | |
62 if (stat(desc->fpath, &fstate)!=0) desc->fpath=DATADIR"/font"; | |
63 | |
213 | 64 // set up some defaults, and erase table |
65 desc->charspace=2; | |
66 desc->spacewidth=12; | |
67 desc->height=0; | |
68 for(i=0;i<512;i++) desc->start[i]=desc->width[i]=desc->font[i]=-1; | |
69 | |
70 section[0]=0; | |
71 | |
72 while(fgets(sor,1020,f)){ | |
73 unsigned char* p[8]; | |
74 int pdb=0; | |
75 unsigned char *s=sor; | |
76 unsigned char *d=sor2; | |
77 int ec=' '; | |
78 int id=0; | |
79 sor[1020]=0; | |
80 p[0]=d;++pdb; | |
81 while(1){ | |
82 int c=*s++; | |
83 if(c==0 || c==13 || c==10) break; | |
84 if(!id){ | |
85 if(c==39 || c==34){ id=c;continue;} // idezojel | |
86 if(c==';' || c=='#') break; | |
87 if(c==9) c=' '; | |
88 if(c==' '){ | |
89 if(ec==' ') continue; | |
90 *d=0; ++d; | |
91 p[pdb]=d;++pdb; | |
92 if(pdb>=8) break; | |
93 continue; | |
94 } | |
95 } else { | |
96 if(id==c){ id=0;continue;} // idezojel | |
97 | |
98 } | |
99 *d=c;d++; | |
100 ec=c; | |
101 } | |
102 if(d==sor2) continue; // skip empty lines | |
103 *d=0; | |
104 | |
105 // printf("params=%d sor=%s\n",pdb,sor); | |
106 // for(i=0;i<pdb;i++) printf(" param %d = '%s'\n",i,p[i]); | |
107 | |
108 if(pdb==1 && p[0][0]=='['){ | |
109 int len=strlen(p[0]); | |
110 if(len && len<63 && p[0][len-1]==']'){ | |
111 strcpy(section,p[0]); | |
339 | 112 if(verbose) printf("font: Reading section: %s\n",section); |
213 | 113 if(strcmp(section,"[files]")==0){ |
114 ++fontdb; | |
115 if(fontdb>=16){ printf("font: Too many bitmaps defined!\n");return NULL;} | |
116 } | |
117 continue; | |
118 } | |
119 } | |
120 | |
1353 | 121 if(strcmp(section,"[fpath]")==0){ |
122 if(pdb==1){ | |
123 desc->fpath=strdup(p[0]); | |
124 continue; | |
125 } | |
126 } else | |
127 | |
213 | 128 if(strcmp(section,"[files]")==0){ |
129 if(pdb==2 && strcmp(p[0],"alpha")==0){ | |
1353 | 130 char *cp; |
131 if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) return NULL; | |
132 | |
133 snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s/%s", | |
134 desc->fpath,p[1]); | |
135 if(!((desc->pic_a[fontdb]=load_raw(cp,verbose)))){ | |
213 | 136 printf("Can't load font bitmap: %s\n",p[1]); |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
137 free(cp); |
213 | 138 return NULL; |
139 } | |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
140 free(cp); |
213 | 141 continue; |
142 } | |
143 if(pdb==2 && strcmp(p[0],"bitmap")==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_b[fontdb]=load_raw(cp,verbose)))){ | |
213 | 150 printf("Can't load font bitmap: %s\n",p[1]); |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
151 free(cp); |
213 | 152 return NULL; |
153 } | |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
154 free(cp); |
213 | 155 continue; |
156 } | |
157 } else | |
158 | |
159 if(strcmp(section,"[info]")==0){ | |
214 | 160 if(pdb==2 && strcmp(p[0],"name")==0){ |
161 desc->name=strdup(p[1]); | |
162 continue; | |
163 } | |
164 if(pdb==2 && strcmp(p[0],"descversion")==0){ | |
165 version=atoi(p[1]); | |
166 continue; | |
167 } | |
213 | 168 if(pdb==2 && strcmp(p[0],"spacewidth")==0){ |
169 desc->spacewidth=atoi(p[1]); | |
170 continue; | |
171 } | |
172 if(pdb==2 && strcmp(p[0],"charspace")==0){ | |
173 desc->charspace=atoi(p[1]); | |
174 continue; | |
175 } | |
176 if(pdb==2 && strcmp(p[0],"height")==0){ | |
177 desc->height=atoi(p[1]); | |
178 continue; | |
179 } | |
180 } else | |
214 | 181 |
213 | 182 if(strcmp(section,"[characters]")==0){ |
219 | 183 if(pdb==3){ |
213 | 184 int chr=p[0][0]; |
185 int start=atoi(p[1]); | |
186 int end=atoi(p[2]); | |
727 | 187 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
|
188 else if(strlen(p[0])!=1) chr=strtol(p[0],NULL,0); |
213 | 189 if(end<start) { |
190 printf("error in font desc: end<start for char '%c'\n",chr); | |
191 } else { | |
192 desc->start[chr]=start; | |
193 desc->width[chr]=end-start+1; | |
194 desc->font[chr]=fontdb; | |
195 // printf("char %d '%c' start=%d width=%d\n",chr,chr,desc->start[chr],desc->width[chr]); | |
196 ++chardb; | |
197 } | |
198 continue; | |
199 } | |
200 } | |
201 printf("Syntax error in font desc: %s\n",sor); | |
202 | |
203 } | |
204 fclose(f); | |
205 | |
206 //printf("font: pos of U = %d\n",desc->start[218]); | |
207 | |
208 for(i=0;i<=fontdb;i++){ | |
209 if(!desc->pic_a[i] || !desc->pic_b[i]){ | |
210 printf("font: Missing bitmap(s) for sub-font #%d\n",i); | |
211 return NULL; | |
212 } | |
249 | 213 //if(factor!=1.0f) |
214 { | |
215 | 215 // re-sample alpha |
216 int f=factor*256.0f; | |
217 int size=desc->pic_a[i]->w*desc->pic_a[i]->h; | |
218 int j; | |
339 | 219 if(verbose) printf("font: resampling alpha by factor %5.3f (%d) ",factor,f);fflush(stdout); |
215 | 220 for(j=0;j<size;j++){ |
947
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
221 int x=desc->pic_a[i]->bmp[j]; // alpha |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
222 int y=desc->pic_b[i]->bmp[j]; // bitmap |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
223 |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
224 #ifdef FAST_OSD |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
225 x=(x<(255-f))?0:1; |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
226 #else |
249 | 227 |
250 | 228 x=255-((x*f)>>8); // scale |
229 //if(x<0) x=0; else if(x>255) x=255; | |
230 //x^=255; // invert | |
231 | |
249 | 232 if(x+y>255) x=255-y; // to avoid overflows |
233 | |
234 //x=0; | |
235 //x=((x*f*(255-y))>>16); | |
236 //x=((x*f*(255-y))>>16)+y; | |
215 | 237 //x=(x*f)>>8;if(x<y) x=y; |
250 | 238 |
249 | 239 if(x<1) x=1; else |
240 if(x>=252) x=0; | |
947
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
241 #endif |
250 | 242 |
215 | 243 desc->pic_a[i]->bmp[j]=x; |
250 | 244 // desc->pic_b[i]->bmp[j]=0; // hack |
215 | 245 } |
339 | 246 if(verbose) printf("DONE!\n"); |
215 | 247 } |
213 | 248 if(!desc->height) desc->height=desc->pic_a[i]->h; |
249 } | |
250 | |
251 j='_';if(desc->font[j]<0) j='?'; | |
252 for(i=0;i<512;i++) | |
253 if(desc->font[i]<0){ | |
254 desc->start[i]=desc->start[j]; | |
255 desc->width[i]=desc->width[j]; | |
256 desc->font[i]=desc->font[j]; | |
257 } | |
258 desc->font[' ']=-1; | |
259 desc->width[' ']=desc->spacewidth; | |
260 | |
340 | 261 printf("Font %s loaded successfully! (%d chars)\n",fname,chardb); |
213 | 262 |
263 return desc; | |
264 } | |
265 | |
266 #if 0 | |
267 int main(){ | |
268 | |
339 | 269 read_font_desc("high_arpi.desc",1); |
213 | 270 |
271 } | |
272 #endif |