Mercurial > mplayer.hg
annotate libvo/font_load.c @ 28953:1e56ea9937ce
Consistently use ff_ prefixes for internal symbols.
author | diego |
---|---|
date | Wed, 18 Mar 2009 08:06:08 +0000 |
parents | 7681eab10aea |
children | 0f1b5b68af32 |
rev | line source |
---|---|
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
1 /* |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
2 * This file is part of MPlayer. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
3 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
7 * (at your option) any later version. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
8 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
12 * GNU General Public License for more details. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
13 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
17 */ |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28200
diff
changeset
|
18 |
7122
0dc9cb756b68
freetype 2.0/2.1+ support - disabled by default until bugs fixed
arpi
parents:
5928
diff
changeset
|
19 #include "config.h" |
0dc9cb756b68
freetype 2.0/2.1+ support - disabled by default until bugs fixed
arpi
parents:
5928
diff
changeset
|
20 |
213 | 21 #include <stdio.h> |
22 #include <stdlib.h> | |
23 #include <string.h> | |
1446 | 24 #include <sys/types.h> |
25 #include <sys/stat.h> | |
26 #include <unistd.h> | |
213 | 27 |
28 #include "font_load.h" | |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
29 #include "mp_msg.h" |
213 | 30 |
339 | 31 raw_file* load_raw(char *name,int verbose){ |
213 | 32 int bpp; |
33 raw_file* raw=malloc(sizeof(raw_file)); | |
34 unsigned char head[32]; | |
35 FILE *f=fopen(name,"rb"); | |
17791 | 36 if(!f) goto err_out; // can't open |
37 if(fread(head,32,1,f)<1) goto err_out; // too small | |
38 if(memcmp(head,"mhwanh",6)) goto err_out; // not raw file | |
213 | 39 raw->w=head[8]*256+head[9]; |
40 raw->h=head[10]*256+head[11]; | |
41 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
|
42 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
|
43 raw->w = ((head[28]*0x100 + head[29])*0x100 + head[30])*0x100 + head[31]; |
17791 | 44 if(raw->c>256) goto err_out; // too many colors!? |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
45 mp_msg(MSGT_OSD, MSGL_DBG2, "RAW: %s %d x %d, %d colors\n",name,raw->w,raw->h,raw->c); |
213 | 46 if(raw->c){ |
47 raw->pal=malloc(raw->c*3); | |
48 fread(raw->pal,3,raw->c,f); | |
49 bpp=1; | |
50 } else { | |
51 raw->pal=NULL; | |
52 bpp=3; | |
53 } | |
54 raw->bmp=malloc(raw->h*raw->w*bpp); | |
55 fread(raw->bmp,raw->h*raw->w*bpp,1,f); | |
56 fclose(f); | |
57 return raw; | |
17791 | 58 |
59 err_out: | |
60 if (f) | |
61 fclose(f); | |
62 free(raw); | |
63 return NULL; | |
213 | 64 } |
65 | |
728 | 66 extern int sub_unicode; |
67 | |
18980
ed69754aa58d
Marks several string parameters as const when they are not modified in the function, Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
17791
diff
changeset
|
68 font_desc_t* read_font_desc(const char* fname,float factor,int verbose){ |
213 | 69 unsigned char sor[1024]; |
70 unsigned char sor2[1024]; | |
71 font_desc_t *desc; | |
17766
b8be9bedc108
initialize f to NULL, needed if desc=malloc... fails
reimar
parents:
14065
diff
changeset
|
72 FILE *f = NULL; |
2222
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
73 char *dn; |
24245 | 74 //struct stat fstate; |
213 | 75 char section[64]; |
76 int i,j; | |
77 int chardb=0; | |
78 int fontdb=-1; | |
214 | 79 int version=0; |
8635
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
80 int first=1; |
213 | 81 |
13641 | 82 desc=malloc(sizeof(font_desc_t));if(!desc) goto fail_out; |
213 | 83 memset(desc,0,sizeof(font_desc_t)); |
84 | |
14065 | 85 f=fopen(fname,"rt");if(!f){ mp_msg(MSGT_OSD, MSGL_V, "font: can't open file: %s\n",fname); goto fail_out;} |
213 | 86 |
2222
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
87 i = strlen (fname) - 9; |
2223 | 88 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
|
89 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
|
90 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
|
91 } |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
92 |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
93 desc->fpath = dn; // search in the same dir as fonts.desc |
1446 | 94 |
2222
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
95 // 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
|
96 // 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
|
97 |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
98 |
ddf897c38fb1
read font files from the same dir as font.desc or as specified in font.desc
atlka
parents:
1446
diff
changeset
|
99 |
1446 | 100 |
213 | 101 // set up some defaults, and erase table |
102 desc->charspace=2; | |
103 desc->spacewidth=12; | |
104 desc->height=0; | |
12609
4be019266884
array initialization fix by SungKwanKang <ksquarekr at yahoo.com>
faust3
parents:
10272
diff
changeset
|
105 for(i=0;i<65536;i++) desc->start[i]=desc->width[i]=desc->font[i]=-1; |
213 | 106 |
107 section[0]=0; | |
108 | |
109 while(fgets(sor,1020,f)){ | |
110 unsigned char* p[8]; | |
111 int pdb=0; | |
112 unsigned char *s=sor; | |
113 unsigned char *d=sor2; | |
114 int ec=' '; | |
115 int id=0; | |
116 sor[1020]=0; | |
8635
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
117 |
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
118 /* skip files that look like: TTF (0x00, 0x01), PFM (0x00, 0x01), PFB |
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
119 * (0x80, 0x01), PCF (0x01, 0x66), fon ("MZ"), gzipped (0x1f, 0x8b) */ |
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
120 |
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
121 if (first) { |
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
122 if (!sor[0] || sor[1] == 1 || (sor[0] == 'M' && sor[1] == 'Z') || (sor[0] == 0x1f && sor[1] == 0x8b) || (sor[0] == 1 && sor[1] == 0x66)) { |
19551 | 123 mp_msg(MSGT_OSD, MSGL_ERR, "%s doesn't look like a bitmap font description, ignoring.\n", fname); |
13641 | 124 goto fail_out; |
8635
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
125 } |
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
126 first = 0; |
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
127 } |
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
7122
diff
changeset
|
128 |
213 | 129 p[0]=d;++pdb; |
130 while(1){ | |
131 int c=*s++; | |
132 if(c==0 || c==13 || c==10) break; | |
133 if(!id){ | |
134 if(c==39 || c==34){ id=c;continue;} // idezojel | |
135 if(c==';' || c=='#') break; | |
136 if(c==9) c=' '; | |
137 if(c==' '){ | |
138 if(ec==' ') continue; | |
139 *d=0; ++d; | |
140 p[pdb]=d;++pdb; | |
141 if(pdb>=8) break; | |
142 continue; | |
143 } | |
144 } else { | |
145 if(id==c){ id=0;continue;} // idezojel | |
146 | |
147 } | |
148 *d=c;d++; | |
149 ec=c; | |
150 } | |
151 if(d==sor2) continue; // skip empty lines | |
152 *d=0; | |
153 | |
154 // printf("params=%d sor=%s\n",pdb,sor); | |
155 // for(i=0;i<pdb;i++) printf(" param %d = '%s'\n",i,p[i]); | |
156 | |
157 if(pdb==1 && p[0][0]=='['){ | |
158 int len=strlen(p[0]); | |
159 if(len && len<63 && p[0][len-1]==']'){ | |
160 strcpy(section,p[0]); | |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
161 mp_msg(MSGT_OSD, MSGL_DBG2, "font: Reading section: %s\n",section); |
213 | 162 if(strcmp(section,"[files]")==0){ |
163 ++fontdb; | |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
164 if(fontdb>=16){ mp_msg(MSGT_OSD, MSGL_ERR, "font: Too many bitmaps defined.\n");goto fail_out;} |
213 | 165 } |
166 continue; | |
167 } | |
168 } | |
169 | |
1353 | 170 if(strcmp(section,"[fpath]")==0){ |
171 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
|
172 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
|
173 free (desc->fpath); // release previously allocated memory |
1353 | 174 desc->fpath=strdup(p[0]); |
175 continue; | |
176 } | |
177 } else | |
178 | |
25335 | 179 #ifdef __AMIGAOS4__ |
19386
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
180 #define FONT_PATH_SEP "" |
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
181 #else |
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
182 //! path seperator for font paths, may not be more than one character |
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
183 #define FONT_PATH_SEP "/" |
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
184 #endif |
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
185 |
213 | 186 if(strcmp(section,"[files]")==0){ |
19386
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
187 char *default_dir=MPLAYER_DATADIR FONT_PATH_SEP "font"; |
213 | 188 if(pdb==2 && strcmp(p[0],"alpha")==0){ |
1353 | 189 char *cp; |
13641 | 190 if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) goto fail_out; |
1353 | 191 |
19386
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
192 snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s" FONT_PATH_SEP "%s", |
1353 | 193 desc->fpath,p[1]); |
194 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
|
195 free(cp); |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
196 if (!(cp=malloc(strlen(default_dir)+strlen(p[1])+2))) |
13641 | 197 goto fail_out; |
19386
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
198 snprintf(cp,strlen(default_dir)+strlen(p[1])+2,"%s" FONT_PATH_SEP "%s", |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
199 default_dir,p[1]); |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
200 if (!((desc->pic_a[fontdb]=load_raw(cp,verbose)))){ |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
201 mp_msg(MSGT_OSD, MSGL_ERR, "Can't load font bitmap: %s\n",p[1]); |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
202 free(cp); |
13641 | 203 goto fail_out; |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
204 } |
213 | 205 } |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
206 free(cp); |
213 | 207 continue; |
208 } | |
209 if(pdb==2 && strcmp(p[0],"bitmap")==0){ | |
1353 | 210 char *cp; |
13641 | 211 if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) goto fail_out; |
1353 | 212 |
19386
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
213 snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s" FONT_PATH_SEP "%s", |
1353 | 214 desc->fpath,p[1]); |
215 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
|
216 free(cp); |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
217 if (!(cp=malloc(strlen(default_dir)+strlen(p[1])+2))) |
13641 | 218 goto fail_out; |
19386
01853e915882
Make path separator for font path a define and set it to a better value for AMIGAOS
reimar
parents:
18980
diff
changeset
|
219 snprintf(cp,strlen(default_dir)+strlen(p[1])+2,"%s" FONT_PATH_SEP "%s", |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
220 default_dir,p[1]); |
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
221 if (!((desc->pic_b[fontdb]=load_raw(cp,verbose)))){ |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
222 mp_msg(MSGT_OSD, MSGL_ERR, "Can't load font bitmap: %s\n",p[1]); |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
223 free(cp); |
13641 | 224 goto fail_out; |
2238
be4160d7db48
if not found using fpath try to load font bitmaps from default dir
atlka
parents:
2223
diff
changeset
|
225 } |
213 | 226 } |
216
338b5664ea13
Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents:
215
diff
changeset
|
227 free(cp); |
213 | 228 continue; |
229 } | |
230 } else | |
231 | |
232 if(strcmp(section,"[info]")==0){ | |
214 | 233 if(pdb==2 && strcmp(p[0],"name")==0){ |
234 desc->name=strdup(p[1]); | |
235 continue; | |
236 } | |
237 if(pdb==2 && strcmp(p[0],"descversion")==0){ | |
238 version=atoi(p[1]); | |
239 continue; | |
240 } | |
213 | 241 if(pdb==2 && strcmp(p[0],"spacewidth")==0){ |
242 desc->spacewidth=atoi(p[1]); | |
243 continue; | |
244 } | |
245 if(pdb==2 && strcmp(p[0],"charspace")==0){ | |
246 desc->charspace=atoi(p[1]); | |
247 continue; | |
248 } | |
249 if(pdb==2 && strcmp(p[0],"height")==0){ | |
250 desc->height=atoi(p[1]); | |
251 continue; | |
252 } | |
253 } else | |
214 | 254 |
213 | 255 if(strcmp(section,"[characters]")==0){ |
219 | 256 if(pdb==3){ |
213 | 257 int chr=p[0][0]; |
258 int start=atoi(p[1]); | |
259 int end=atoi(p[2]); | |
727 | 260 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
|
261 else if(strlen(p[0])!=1) chr=strtol(p[0],NULL,0); |
213 | 262 if(end<start) { |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
263 mp_msg(MSGT_OSD, MSGL_WARN, "error in font desc: end<start for char '%c'\n",chr); |
213 | 264 } else { |
265 desc->start[chr]=start; | |
266 desc->width[chr]=end-start+1; | |
267 desc->font[chr]=fontdb; | |
268 // printf("char %d '%c' start=%d width=%d\n",chr,chr,desc->start[chr],desc->width[chr]); | |
269 ++chardb; | |
270 } | |
271 continue; | |
272 } | |
273 } | |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
274 mp_msg(MSGT_OSD, MSGL_ERR, "Syntax error in font desc: %s",sor); |
13641 | 275 goto fail_out; |
213 | 276 |
277 } | |
278 fclose(f); | |
13641 | 279 f = NULL; |
213 | 280 |
12793
a9429d90157a
avoid using corrupted font descriptions patch by Daniel von Dincklage <danielvd+mpl@cs.colorado.edu>
faust3
parents:
12609
diff
changeset
|
281 if (first == 1) { |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
282 mp_msg(MSGT_OSD, MSGL_ERR, "%s is empty or a directory, ignoring.\n", fname); |
13641 | 283 goto fail_out; |
12793
a9429d90157a
avoid using corrupted font descriptions patch by Daniel von Dincklage <danielvd+mpl@cs.colorado.edu>
faust3
parents:
12609
diff
changeset
|
284 } |
a9429d90157a
avoid using corrupted font descriptions patch by Daniel von Dincklage <danielvd+mpl@cs.colorado.edu>
faust3
parents:
12609
diff
changeset
|
285 |
213 | 286 //printf("font: pos of U = %d\n",desc->start[218]); |
287 | |
288 for(i=0;i<=fontdb;i++){ | |
289 if(!desc->pic_a[i] || !desc->pic_b[i]){ | |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
290 mp_msg(MSGT_OSD, MSGL_ERR, "font: Missing bitmap(s) for sub-font #%d\n",i); |
13641 | 291 goto fail_out; |
213 | 292 } |
249 | 293 //if(factor!=1.0f) |
294 { | |
215 | 295 // re-sample alpha |
296 int f=factor*256.0f; | |
297 int size=desc->pic_a[i]->w*desc->pic_a[i]->h; | |
298 int j; | |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
299 mp_msg(MSGT_OSD, MSGL_DBG2, "font: resampling alpha by factor %5.3f (%d) ",factor,f);fflush(stdout); |
215 | 300 for(j=0;j<size;j++){ |
947
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
301 int x=desc->pic_a[i]->bmp[j]; // alpha |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
302 int y=desc->pic_b[i]->bmp[j]; // bitmap |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
303 |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
304 #ifdef FAST_OSD |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
305 x=(x<(255-f))?0:1; |
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
306 #else |
249 | 307 |
250 | 308 x=255-((x*f)>>8); // scale |
309 //if(x<0) x=0; else if(x>255) x=255; | |
310 //x^=255; // invert | |
311 | |
249 | 312 if(x+y>255) x=255-y; // to avoid overflows |
313 | |
314 //x=0; | |
315 //x=((x*f*(255-y))>>16); | |
316 //x=((x*f*(255-y))>>16)+y; | |
215 | 317 //x=(x*f)>>8;if(x<y) x=y; |
250 | 318 |
249 | 319 if(x<1) x=1; else |
320 if(x>=252) x=0; | |
947
76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
arpi_esp
parents:
728
diff
changeset
|
321 #endif |
250 | 322 |
215 | 323 desc->pic_a[i]->bmp[j]=x; |
250 | 324 // desc->pic_b[i]->bmp[j]=0; // hack |
215 | 325 } |
13897
41a4fc8421e9
Converted printf calls to mp_msg, reduced verbosity.
diego
parents:
13641
diff
changeset
|
326 mp_msg(MSGT_OSD, MSGL_DBG2, "DONE!\n"); |
215 | 327 } |
213 | 328 if(!desc->height) desc->height=desc->pic_a[i]->h; |
329 } | |
330 | |
331 j='_';if(desc->font[j]<0) j='?'; | |
12609
4be019266884
array initialization fix by SungKwanKang <ksquarekr at yahoo.com>
faust3
parents:
10272
diff
changeset
|
332 for(i=0;i<65536;i++) |
213 | 333 if(desc->font[i]<0){ |
334 desc->start[i]=desc->start[j]; | |
335 desc->width[i]=desc->width[j]; | |
336 desc->font[i]=desc->font[j]; | |
337 } | |
338 desc->font[' ']=-1; | |
339 desc->width[' ']=desc->spacewidth; | |
340 | |
19551 | 341 mp_msg(MSGT_OSD, MSGL_V, "Bitmap font %s loaded successfully! (%d chars)\n",fname,chardb); |
213 | 342 |
343 return desc; | |
13641 | 344 |
345 fail_out: | |
346 if (f) | |
347 fclose(f); | |
348 if (desc->fpath) | |
349 free(desc->fpath); | |
350 if (desc->name) | |
351 free(desc->name); | |
352 if (desc) | |
353 free(desc); | |
354 return NULL; | |
213 | 355 } |
28200
56868e6fb340
Conditionally define render_one_glyph and kerning dummy functions in
diego
parents:
28199
diff
changeset
|
356 |
56868e6fb340
Conditionally define render_one_glyph and kerning dummy functions in
diego
parents:
28199
diff
changeset
|
357 #ifndef CONFIG_FREETYPE |
56868e6fb340
Conditionally define render_one_glyph and kerning dummy functions in
diego
parents:
28199
diff
changeset
|
358 void render_one_glyph(font_desc_t *desc, int c) {} |
56868e6fb340
Conditionally define render_one_glyph and kerning dummy functions in
diego
parents:
28199
diff
changeset
|
359 int kerning(font_desc_t *desc, int prevc, int c) { return 0; } |
56868e6fb340
Conditionally define render_one_glyph and kerning dummy functions in
diego
parents:
28199
diff
changeset
|
360 #endif |