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