annotate libvo/font_load.c @ 11511:6e580b901205

original config: > ao_data.bps=channels*rate; > if(format != AFMT_U8 && format != AFMT_S8) > ao_data.bps*=2; fallback config, before patch: > ao_data.bps=ao_data.channels * ao_data.samplerate; since we forced the format to S16_LE in fallback, we should double bps to be consistent with an original config of the same settings.
author joey
date Sun, 23 Nov 2003 17:04:19 +0000
parents 7b0bc557987b
children 4be019266884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7122
0dc9cb756b68 freetype 2.0/2.1+ support - disabled by default until bugs fixed
arpi
parents: 5928
diff changeset
1 #include "config.h"
0dc9cb756b68 freetype 2.0/2.1+ support - disabled by default until bugs fixed
arpi
parents: 5928
diff changeset
2
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
3 #include <stdio.h>
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
4 #include <stdlib.h>
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
5 #include <string.h>
1446
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
6 #include <sys/types.h>
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
7 #include <sys/stat.h>
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
8 #include <unistd.h>
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
9
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
10 #include "font_load.h"
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
11
2476
a6c5a537f30a a few warning fixes (missing #include's)
pl
parents: 2238
diff changeset
12 extern char *get_path ( char * );
216
338b5664ea13 Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents: 215
diff changeset
13
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
14 raw_file* load_raw(char *name,int verbose){
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
15 int bpp;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
16 raw_file* raw=malloc(sizeof(raw_file));
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
17 unsigned char head[32];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
18 FILE *f=fopen(name,"rb");
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
19 if(!f) return NULL; // can't open
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
20 if(fread(head,32,1,f)<1) return NULL; // too small
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
21 if(memcmp(head,"mhwanh",6)) return NULL; // not raw file
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
22 raw->w=head[8]*256+head[9];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
23 raw->h=head[10]*256+head[11];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
24 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
25 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
26 raw->w = ((head[28]*0x100 + head[29])*0x100 + head[30])*0x100 + head[31];
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
27 if(raw->c>256) return NULL; // too many colors!?
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
28 if(verbose) printf("RAW: %s %d x %d, %d colors\n",name,raw->w,raw->h,raw->c);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
29 if(raw->c){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
30 raw->pal=malloc(raw->c*3);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
31 fread(raw->pal,3,raw->c,f);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
32 bpp=1;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
33 } else {
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
34 raw->pal=NULL;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
35 bpp=3;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
36 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
37 raw->bmp=malloc(raw->h*raw->w*bpp);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
38 fread(raw->bmp,raw->h*raw->w*bpp,1,f);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
39 fclose(f);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
40 return raw;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
41 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
42
728
138d38a5915a fixed extern
arpi_esp
parents: 727
diff changeset
43 extern int sub_unicode;
138d38a5915a fixed extern
arpi_esp
parents: 727
diff changeset
44
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
45 font_desc_t* read_font_desc(char* fname,float factor,int verbose){
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
46 unsigned char sor[1024];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
47 unsigned char sor2[1024];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
48 font_desc_t *desc;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
49 FILE *f;
2222
ddf897c38fb1 read font files from the same dir as font.desc or as specified in font.desc
atlka
parents: 1446
diff changeset
50 char *dn;
1446
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
51 struct stat fstate;
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
52 char section[64];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
53 int i,j;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
54 int chardb=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
55 int fontdb=-1;
214
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
56 int version=0;
8635
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
57 int first=1;
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
58
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
59 desc=malloc(sizeof(font_desc_t));if(!desc) return NULL;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
60 memset(desc,0,sizeof(font_desc_t));
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
61
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
62 f=fopen(fname,"rt");if(!f){ printf("font: can't open file: %s\n",fname); return NULL;}
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
63
2222
ddf897c38fb1 read font files from the same dir as font.desc or as specified in font.desc
atlka
parents: 1446
diff changeset
64 i = strlen (fname) - 9;
2223
560267b2ede8 cosmetic changes
atlka
parents: 2222
diff changeset
65 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
66 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
67 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
68 }
ddf897c38fb1 read font files from the same dir as font.desc or as specified in font.desc
atlka
parents: 1446
diff changeset
69
ddf897c38fb1 read font files from the same dir as font.desc or as specified in font.desc
atlka
parents: 1446
diff changeset
70 desc->fpath = dn; // search in the same dir as fonts.desc
1446
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
71
2222
ddf897c38fb1 read font files from the same dir as font.desc or as specified in font.desc
atlka
parents: 1446
diff changeset
72 // 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
73 // 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
74
ddf897c38fb1 read font files from the same dir as font.desc or as specified in font.desc
atlka
parents: 1446
diff changeset
75
ddf897c38fb1 read font files from the same dir as font.desc or as specified in font.desc
atlka
parents: 1446
diff changeset
76
1446
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
77
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
78 // set up some defaults, and erase table
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
79 desc->charspace=2;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
80 desc->spacewidth=12;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
81 desc->height=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
82 for(i=0;i<512;i++) desc->start[i]=desc->width[i]=desc->font[i]=-1;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
83
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
84 section[0]=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
85
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
86 while(fgets(sor,1020,f)){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
87 unsigned char* p[8];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
88 int pdb=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
89 unsigned char *s=sor;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
90 unsigned char *d=sor2;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
91 int ec=' ';
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
92 int id=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
93 sor[1020]=0;
8635
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
94
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
95 /* 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
96 * (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
97
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
98 if (first) {
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
99 if (!sor[0] || sor[1] == 1 || (sor[0] == 'M' && sor[1] == 'Z') || (sor[0] == 0x1f && sor[1] == 0x8b) || (sor[0] == 1 && sor[1] == 0x66)) {
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
100 printf("%s doesn't look like a font description, ignoring\n", fname);
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
101 fclose(f);
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
102 free(desc);
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
103 free(dn);
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
104 return NULL;
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
105 }
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
106 first = 0;
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
107 }
81dbd28ef7c0 these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents: 7122
diff changeset
108
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
109 p[0]=d;++pdb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
110 while(1){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
111 int c=*s++;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
112 if(c==0 || c==13 || c==10) break;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
113 if(!id){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
114 if(c==39 || c==34){ id=c;continue;} // idezojel
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
115 if(c==';' || c=='#') break;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
116 if(c==9) c=' ';
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
117 if(c==' '){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
118 if(ec==' ') continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
119 *d=0; ++d;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
120 p[pdb]=d;++pdb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
121 if(pdb>=8) break;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
122 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
123 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
124 } else {
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
125 if(id==c){ id=0;continue;} // idezojel
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
126
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
127 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
128 *d=c;d++;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
129 ec=c;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
130 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
131 if(d==sor2) continue; // skip empty lines
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
132 *d=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
133
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
134 // printf("params=%d sor=%s\n",pdb,sor);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
135 // for(i=0;i<pdb;i++) printf(" param %d = '%s'\n",i,p[i]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
136
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
137 if(pdb==1 && p[0][0]=='['){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
138 int len=strlen(p[0]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
139 if(len && len<63 && p[0][len-1]==']'){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
140 strcpy(section,p[0]);
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
141 if(verbose) printf("font: Reading section: %s\n",section);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
142 if(strcmp(section,"[files]")==0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
143 ++fontdb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
144 if(fontdb>=16){ printf("font: Too many bitmaps defined!\n");return NULL;}
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
145 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
146 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
147 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
148 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
149
1353
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
150 if(strcmp(section,"[fpath]")==0){
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
151 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
152 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
153 free (desc->fpath); // release previously allocated memory
1353
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
154 desc->fpath=strdup(p[0]);
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
155 continue;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
156 }
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
157 } else
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
158
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
159 if(strcmp(section,"[files]")==0){
10272
7b0bc557987b renames: DATADIR->MPLAYER_DATADIR, CONFDIR->MPLAYER_CONFDIR, LIBDIR->MPLAYER_LIBDIR
arpi
parents: 8635
diff changeset
160 char *default_dir=MPLAYER_DATADIR "/font";
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
161 if(pdb==2 && strcmp(p[0],"alpha")==0){
1353
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
162 char *cp;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
163 if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) return NULL;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
164
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
165 snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s/%s",
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
166 desc->fpath,p[1]);
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
167 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
168 free(cp);
2238
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
169 if (!(cp=malloc(strlen(default_dir)+strlen(p[1])+2)))
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
170 return NULL;
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
171 snprintf(cp,strlen(default_dir)+strlen(p[1])+2,"%s/%s",
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
172 default_dir,p[1]);
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
173 if (!((desc->pic_a[fontdb]=load_raw(cp,verbose)))){
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
174 printf("Can't load font bitmap: %s\n",p[1]);
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
175 free(cp);
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
176 return NULL;
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
177 }
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
178 }
216
338b5664ea13 Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents: 215
diff changeset
179 free(cp);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
180 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
181 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
182 if(pdb==2 && strcmp(p[0],"bitmap")==0){
1353
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
183 char *cp;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
184 if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) return NULL;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
185
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
186 snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s/%s",
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
187 desc->fpath,p[1]);
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
188 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
189 free(cp);
2238
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
190 if (!(cp=malloc(strlen(default_dir)+strlen(p[1])+2)))
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
191 return NULL;
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
192 snprintf(cp,strlen(default_dir)+strlen(p[1])+2,"%s/%s",
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
193 default_dir,p[1]);
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
194 if (!((desc->pic_b[fontdb]=load_raw(cp,verbose)))){
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
195 printf("Can't load font bitmap: %s\n",p[1]);
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
196 free(cp);
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
197 return NULL;
be4160d7db48 if not found using fpath try to load font bitmaps from default dir
atlka
parents: 2223
diff changeset
198 }
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
199 }
216
338b5664ea13 Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents: 215
diff changeset
200 free(cp);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
201 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
202 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
203 } else
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
204
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
205 if(strcmp(section,"[info]")==0){
214
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
206 if(pdb==2 && strcmp(p[0],"name")==0){
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
207 desc->name=strdup(p[1]);
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
208 continue;
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
209 }
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
210 if(pdb==2 && strcmp(p[0],"descversion")==0){
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
211 version=atoi(p[1]);
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
212 continue;
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
213 }
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
214 if(pdb==2 && strcmp(p[0],"spacewidth")==0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
215 desc->spacewidth=atoi(p[1]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
216 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
217 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
218 if(pdb==2 && strcmp(p[0],"charspace")==0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
219 desc->charspace=atoi(p[1]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
220 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
221 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
222 if(pdb==2 && strcmp(p[0],"height")==0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
223 desc->height=atoi(p[1]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
224 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
225 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
226 } else
214
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
227
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
228 if(strcmp(section,"[characters]")==0){
219
bc5c75b7a401 hex charcode support
arpi_esp
parents: 217
diff changeset
229 if(pdb==3){
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
230 int chr=p[0][0];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
231 int start=atoi(p[1]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
232 int end=atoi(p[2]);
727
cc208ebcb9f6 Deals with unicode/nounicode.
atmosfear
parents: 706
diff changeset
233 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
234 else if(strlen(p[0])!=1) chr=strtol(p[0],NULL,0);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
235 if(end<start) {
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
236 printf("error in font desc: end<start for char '%c'\n",chr);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
237 } else {
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
238 desc->start[chr]=start;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
239 desc->width[chr]=end-start+1;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
240 desc->font[chr]=fontdb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
241 // printf("char %d '%c' start=%d width=%d\n",chr,chr,desc->start[chr],desc->width[chr]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
242 ++chardb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
243 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
244 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
245 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
246 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
247 printf("Syntax error in font desc: %s\n",sor);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
248
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
249 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
250 fclose(f);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
251
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
252 //printf("font: pos of U = %d\n",desc->start[218]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
253
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
254 for(i=0;i<=fontdb;i++){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
255 if(!desc->pic_a[i] || !desc->pic_b[i]){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
256 printf("font: Missing bitmap(s) for sub-font #%d\n",i);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
257 return NULL;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
258 }
249
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
259 //if(factor!=1.0f)
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
260 {
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
261 // re-sample alpha
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
262 int f=factor*256.0f;
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
263 int size=desc->pic_a[i]->w*desc->pic_a[i]->h;
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
264 int j;
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
265 if(verbose) printf("font: resampling alpha by factor %5.3f (%d) ",factor,f);fflush(stdout);
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
266 for(j=0;j<size;j++){
947
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
267 int x=desc->pic_a[i]->bmp[j]; // alpha
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
268 int y=desc->pic_b[i]->bmp[j]; // bitmap
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
269
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
270 #ifdef FAST_OSD
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
271 x=(x<(255-f))?0:1;
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
272 #else
249
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
273
250
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
274 x=255-((x*f)>>8); // scale
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
275 //if(x<0) x=0; else if(x>255) x=255;
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
276 //x^=255; // invert
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
277
249
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
278 if(x+y>255) x=255-y; // to avoid overflows
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
279
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
280 //x=0;
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
281 //x=((x*f*(255-y))>>16);
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
282 //x=((x*f*(255-y))>>16)+y;
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
283 //x=(x*f)>>8;if(x<y) x=y;
250
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
284
249
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
285 if(x<1) x=1; else
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
286 if(x>=252) x=0;
947
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
287 #endif
250
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
288
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
289 desc->pic_a[i]->bmp[j]=x;
250
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
290 // desc->pic_b[i]->bmp[j]=0; // hack
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
291 }
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
292 if(verbose) printf("DONE!\n");
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
293 }
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
294 if(!desc->height) desc->height=desc->pic_a[i]->h;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
295 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
296
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
297 j='_';if(desc->font[j]<0) j='?';
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
298 for(i=0;i<512;i++)
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
299 if(desc->font[i]<0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
300 desc->start[i]=desc->start[j];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
301 desc->width[i]=desc->width[j];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
302 desc->font[i]=desc->font[j];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
303 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
304 desc->font[' ']=-1;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
305 desc->width[' ']=desc->spacewidth;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
306
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 339
diff changeset
307 printf("Font %s loaded successfully! (%d chars)\n",fname,chardb);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
308
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
309 return desc;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
310 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
311
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
312 #if 0
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
313 int main(){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
314
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
315 read_font_desc("high_arpi.desc",1);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
316
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
317 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
318 #endif
7122
0dc9cb756b68 freetype 2.0/2.1+ support - disabled by default until bugs fixed
arpi
parents: 5928
diff changeset
319