annotate libvo/font_load.c @ 2181:d90f8fc7ead6

fixed a sig4 bug an non mmx2 cpus (in case of more sig4 errors please send me a "disassemble $eip-16 $eip+16" from gdb)
author michael
date Sat, 13 Oct 2001 11:58:41 +0000
parents a49fd85fc431
children ddf897c38fb1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
1
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
2 #include <stdio.h>
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
3 #include <stdlib.h>
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
4 #include <string.h>
1446
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
5 #include <sys/types.h>
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
6 #include <sys/stat.h>
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
7 #include <unistd.h>
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
8
947
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
9 #include "config.h"
213
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
216
338b5664ea13 Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents: 215
diff changeset
12 char *get_path ( char * );
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];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
25 if(raw->c>256) return NULL; // too many colors!?
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
26 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
27 if(raw->c){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
28 raw->pal=malloc(raw->c*3);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
29 fread(raw->pal,3,raw->c,f);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
30 bpp=1;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
31 } else {
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
32 raw->pal=NULL;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
33 bpp=3;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
34 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
35 raw->bmp=malloc(raw->h*raw->w*bpp);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
36 fread(raw->bmp,raw->h*raw->w*bpp,1,f);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
37 fclose(f);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
38 return raw;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
39 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
40
728
138d38a5915a fixed extern
arpi_esp
parents: 727
diff changeset
41 extern int sub_unicode;
138d38a5915a fixed extern
arpi_esp
parents: 727
diff changeset
42
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
43 font_desc_t* read_font_desc(char* fname,float factor,int verbose){
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
44 unsigned char sor[1024];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
45 unsigned char sor2[1024];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
46 font_desc_t *desc;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
47 FILE *f;
1446
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
48 struct stat fstate;
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
49 char section[64];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
50 int i,j;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
51 int chardb=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
52 int fontdb=-1;
214
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
53 int version=0;
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
54
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
55 desc=malloc(sizeof(font_desc_t));if(!desc) return NULL;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
56 memset(desc,0,sizeof(font_desc_t));
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
57
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
58 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
59
1446
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
60 desc->fpath=get_path("font/");
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
61
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
62 if (stat(desc->fpath, &fstate)!=0) desc->fpath=DATADIR"/font";
a49fd85fc431 DATADIR/font/ patch by Adam Tla/lka atlka@pg.gda.pl
arpi
parents: 1359
diff changeset
63
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
64 // set up some defaults, and erase table
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
65 desc->charspace=2;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
66 desc->spacewidth=12;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
67 desc->height=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
68 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
69
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
70 section[0]=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
71
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
72 while(fgets(sor,1020,f)){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
73 unsigned char* p[8];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
74 int pdb=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
75 unsigned char *s=sor;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
76 unsigned char *d=sor2;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
77 int ec=' ';
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
78 int id=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
79 sor[1020]=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
80 p[0]=d;++pdb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
81 while(1){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
82 int c=*s++;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
83 if(c==0 || c==13 || c==10) break;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
84 if(!id){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
85 if(c==39 || c==34){ id=c;continue;} // idezojel
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
86 if(c==';' || c=='#') break;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
87 if(c==9) c=' ';
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
88 if(c==' '){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
89 if(ec==' ') continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
90 *d=0; ++d;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
91 p[pdb]=d;++pdb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
92 if(pdb>=8) break;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
93 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
94 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
95 } else {
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
96 if(id==c){ id=0;continue;} // idezojel
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
97
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
98 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
99 *d=c;d++;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
100 ec=c;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
101 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
102 if(d==sor2) continue; // skip empty lines
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
103 *d=0;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
104
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
105 // printf("params=%d sor=%s\n",pdb,sor);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
106 // for(i=0;i<pdb;i++) printf(" param %d = '%s'\n",i,p[i]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
107
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
108 if(pdb==1 && p[0][0]=='['){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
109 int len=strlen(p[0]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
110 if(len && len<63 && p[0][len-1]==']'){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
111 strcpy(section,p[0]);
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
112 if(verbose) printf("font: Reading section: %s\n",section);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
113 if(strcmp(section,"[files]")==0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
114 ++fontdb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
115 if(fontdb>=16){ printf("font: Too many bitmaps defined!\n");return NULL;}
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
116 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
117 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
118 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
119 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
120
1353
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
121 if(strcmp(section,"[fpath]")==0){
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
122 if(pdb==1){
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
123 desc->fpath=strdup(p[0]);
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
124 continue;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
125 }
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
126 } else
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
127
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
128 if(strcmp(section,"[files]")==0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
129 if(pdb==2 && strcmp(p[0],"alpha")==0){
1353
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
130 char *cp;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
131 if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) return NULL;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
132
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
133 snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s/%s",
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
134 desc->fpath,p[1]);
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
135 if(!((desc->pic_a[fontdb]=load_raw(cp,verbose)))){
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
136 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
137 free(cp);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
138 return NULL;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
139 }
216
338b5664ea13 Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents: 215
diff changeset
140 free(cp);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
141 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
142 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
143 if(pdb==2 && strcmp(p[0],"bitmap")==0){
1353
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
144 char *cp;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
145 if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) return NULL;
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
146
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
147 snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s/%s",
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
148 desc->fpath,p[1]);
c3e3b0ae4d06 Applied DATADIR patch by Vladimir Kushnir
arpi
parents: 947
diff changeset
149 if(!((desc->pic_b[fontdb]=load_raw(cp,verbose)))){
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
150 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
151 free(cp);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
152 return NULL;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
153 }
216
338b5664ea13 Search font files in ~/.mplayer/font/ instead of current dir
lgb
parents: 215
diff changeset
154 free(cp);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
155 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
156 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
157 } else
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
158
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
159 if(strcmp(section,"[info]")==0){
214
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
160 if(pdb==2 && strcmp(p[0],"name")==0){
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
161 desc->name=strdup(p[1]);
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
162 continue;
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
163 }
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
164 if(pdb==2 && strcmp(p[0],"descversion")==0){
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
165 version=atoi(p[1]);
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
166 continue;
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
167 }
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
168 if(pdb==2 && strcmp(p[0],"spacewidth")==0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
169 desc->spacewidth=atoi(p[1]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
170 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
171 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
172 if(pdb==2 && strcmp(p[0],"charspace")==0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
173 desc->charspace=atoi(p[1]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
174 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
175 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
176 if(pdb==2 && strcmp(p[0],"height")==0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
177 desc->height=atoi(p[1]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
178 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
179 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
180 } else
214
09d0f437b817 desc fileformat changes
arpi_esp
parents: 213
diff changeset
181
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
182 if(strcmp(section,"[characters]")==0){
219
bc5c75b7a401 hex charcode support
arpi_esp
parents: 217
diff changeset
183 if(pdb==3){
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
184 int chr=p[0][0];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
185 int start=atoi(p[1]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
186 int end=atoi(p[2]);
727
cc208ebcb9f6 Deals with unicode/nounicode.
atmosfear
parents: 706
diff changeset
187 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
188 else if(strlen(p[0])!=1) chr=strtol(p[0],NULL,0);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
189 if(end<start) {
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
190 printf("error in font desc: end<start for char '%c'\n",chr);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
191 } else {
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
192 desc->start[chr]=start;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
193 desc->width[chr]=end-start+1;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
194 desc->font[chr]=fontdb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
195 // 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
196 ++chardb;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
197 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
198 continue;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
199 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
200 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
201 printf("Syntax error in font desc: %s\n",sor);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
202
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
203 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
204 fclose(f);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
205
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
206 //printf("font: pos of U = %d\n",desc->start[218]);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
207
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
208 for(i=0;i<=fontdb;i++){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
209 if(!desc->pic_a[i] || !desc->pic_b[i]){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
210 printf("font: Missing bitmap(s) for sub-font #%d\n",i);
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
211 return NULL;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
212 }
249
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
213 //if(factor!=1.0f)
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
214 {
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
215 // re-sample alpha
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
216 int f=factor*256.0f;
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
217 int size=desc->pic_a[i]->w*desc->pic_a[i]->h;
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
218 int j;
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
219 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
220 for(j=0;j<size;j++){
947
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
221 int x=desc->pic_a[i]->bmp[j]; // alpha
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
222 int y=desc->pic_b[i]->bmp[j]; // bitmap
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
223
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
224 #ifdef FAST_OSD
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
225 x=(x<(255-f))?0:1;
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
226 #else
249
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
227
250
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
228 x=255-((x*f)>>8); // scale
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
229 //if(x<0) x=0; else if(x>255) x=255;
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
230 //x^=255; // invert
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
231
249
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
232 if(x+y>255) x=255-y; // to avoid overflows
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
233
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
234 //x=0;
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
235 //x=((x*f*(255-y))>>16);
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
236 //x=((x*f*(255-y))>>16)+y;
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
237 //x=(x*f)>>8;if(x<y) x=y;
250
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
238
249
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
239 if(x<1) x=1; else
2dadc379a934 OSD/SUB image quality & speed improvement
arpi_esp
parents: 219
diff changeset
240 if(x>=252) x=0;
947
76fd9463b9d3 FAST_OSD option to disable font outline antialiasing
arpi_esp
parents: 728
diff changeset
241 #endif
250
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
242
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
243 desc->pic_a[i]->bmp[j]=x;
250
d4f711fde94b optimized alpha resampling
arpi_esp
parents: 249
diff changeset
244 // desc->pic_b[i]->bmp[j]=0; // hack
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
245 }
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
246 if(verbose) printf("DONE!\n");
215
09d565842a33 font alpha resampling, see -ffactor
arpi_esp
parents: 214
diff changeset
247 }
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
248 if(!desc->height) desc->height=desc->pic_a[i]->h;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
249 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
250
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
251 j='_';if(desc->font[j]<0) j='?';
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
252 for(i=0;i<512;i++)
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
253 if(desc->font[i]<0){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
254 desc->start[i]=desc->start[j];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
255 desc->width[i]=desc->width[j];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
256 desc->font[i]=desc->font[j];
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
257 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
258 desc->font[' ']=-1;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
259 desc->width[' ']=desc->spacewidth;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
260
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 339
diff changeset
261 printf("Font %s loaded successfully! (%d chars)\n",fname,chardb);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
262
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
263 return desc;
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
264 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
265
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
266 #if 0
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
267 int main(){
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
268
339
e7e89cd4169f printf's only if verbose>1
arpi_esp
parents: 250
diff changeset
269 read_font_desc("high_arpi.desc",1);
213
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
270
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
271 }
6ec8f6ab6cb1 subtitle+OSD font support
arpi_esp
parents:
diff changeset
272 #endif