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