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