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