annotate libvo/font_load.c @ 580:dd0a2985304f

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