Mercurial > mplayer.hg
annotate gui/mplayer/common.c @ 23584:a01f8876ea2c
adding Blackfin swscale_bfin infrastructure, and the first swscale routine uyvy to yv12 video resampler
author | mhoffman |
---|---|
date | Fri, 22 Jun 2007 12:45:18 +0000 |
parents | 8b61dc798f48 |
children | 9fb716ab06a3 |
rev | line source |
---|---|
23077 | 1 |
2 // main window | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <inttypes.h> | |
7 #include <sys/stat.h> | |
8 #include <unistd.h> | |
23305
22d3d12c6dfb
Include string.h for memcpy, fastmemcpy.h alone is not enough.
reimar
parents:
23154
diff
changeset
|
9 #include <string.h> |
23077 | 10 |
11 #include "app.h" | |
12 #include "skin/font.h" | |
13 #include "skin/skin.h" | |
14 #include "wm/ws.h" | |
15 | |
16 #include "../config.h" | |
17 #include "../help_mp.h" | |
18 #include "../libvo/x11_common.h" | |
19 | |
20 #include "../stream/stream.h" | |
21 #include "../mixer.h" | |
22 #include "../libvo/sub.h" | |
23 | |
24 #include "../libmpdemux/demuxer.h" | |
25 #include "../libmpdemux/stheader.h" | |
26 #include "../codec-cfg.h" | |
23154
e564b9cd7290
Fix several implicit declarations of functions warnings.
diego
parents:
23077
diff
changeset
|
27 #include "../access_mpcontext.h" |
23077 | 28 |
29 | |
30 #include "play.h" | |
31 #include "widgets.h" | |
32 | |
33 extern unsigned int GetTimerMS( void ); | |
34 | |
35 inline void TranslateFilename( int c,char * tmp,size_t tmplen ) | |
36 { | |
37 int i; | |
38 char * p; | |
39 | |
40 switch ( guiIntfStruct.StreamType ) | |
41 { | |
42 case STREAMTYPE_STREAM: | |
43 strlcpy(tmp, guiIntfStruct.Filename, tmplen); | |
44 break; | |
45 case STREAMTYPE_FILE: | |
46 if ( ( guiIntfStruct.Filename )&&( guiIntfStruct.Filename[0] ) ) | |
47 { | |
48 if ( (p = strrchr(guiIntfStruct.Filename, '/')) ) | |
49 strlcpy(tmp, p + 1, tmplen); | |
50 else | |
51 strlcpy(tmp, guiIntfStruct.Filename, tmplen); | |
52 if ( tmp[strlen( tmp ) - 4] == '.' ) tmp[strlen( tmp ) - 4]=0; | |
53 if ( tmp[strlen( tmp ) - 5] == '.' ) tmp[strlen( tmp ) - 5]=0; | |
54 } else strlcpy( tmp,MSGTR_NoFileLoaded,tmplen ); | |
55 break; | |
56 #ifdef USE_DVDREAD | |
57 case STREAMTYPE_DVD: | |
58 if ( guiIntfStruct.DVD.current_chapter ) snprintf(tmp,tmplen,MSGTR_Chapter,guiIntfStruct.DVD.current_chapter ); | |
59 else strlcat( tmp,MSGTR_NoChapter,tmplen ); | |
60 break; | |
61 #endif | |
62 #ifdef HAVE_VCD | |
63 case STREAMTYPE_VCD: | |
64 snprintf( tmp,tmplen,MSGTR_VCDTrack,guiIntfStruct.Track ); | |
65 break; | |
66 #endif | |
67 default: strlcpy( tmp,MSGTR_NoMediaOpened,tmplen ); | |
68 } | |
69 if ( c ) | |
70 { | |
71 for ( i=0;i < (int)strlen( tmp );i++ ) | |
72 { | |
73 int t=0; | |
74 if ( c == 1 ) { if ( ( tmp[i] >= 'A' )&&( tmp[i] <= 'Z' ) ) t=32; } | |
75 if ( c == 2 ) { if ( ( tmp[i] >= 'a' )&&( tmp[i] <= 'z' ) ) t=-32; } | |
76 tmp[i]=(char)( tmp[i] + t ); | |
77 } | |
78 } | |
79 } | |
80 | |
81 /* Unsafe! Pass only null-terminated strings as (char *)str. */ | |
82 char * Translate( char * str ) | |
83 { | |
84 mixer_t *mixer = mpctx_get_mixer(guiIntfStruct.mpcontext); | |
85 static char trbuf[512]; | |
86 char tmp[512]; | |
87 int i,c; | |
88 int t; | |
89 int strsize = 0; | |
90 memset( trbuf,0,512 ); | |
91 memset( tmp,0,128 ); | |
92 strsize = strlen(str); | |
93 for ( c=0,i=0;i < strsize;i++ ) | |
94 { | |
95 if ( str[i] != '$' ) { trbuf[c++]=str[i]; trbuf[c]=0; } | |
96 else | |
97 { | |
98 switch ( str[++i] ) | |
99 { | |
100 case 't': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.Track ); | |
101 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
102 case 'o': TranslateFilename( 0,tmp,sizeof( tmp ) ); | |
103 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
104 case 'f': TranslateFilename( 1,tmp,sizeof( tmp ) ); | |
105 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
106 case 'F': TranslateFilename( 2,tmp,sizeof( tmp ) ); | |
107 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
108 case '6': t=guiIntfStruct.LengthInSec; goto calclengthhhmmss; | |
109 case '1': t=guiIntfStruct.TimeSec; | |
110 calclengthhhmmss: | |
111 snprintf( tmp,sizeof( tmp ),"%02d:%02d:%02d",t/3600,t/60%60,t%60 ); | |
112 strlcat( trbuf,tmp,sizeof( trbuf ) ); | |
113 break; | |
114 case '7': t=guiIntfStruct.LengthInSec; goto calclengthmmmmss; | |
115 case '2': t=guiIntfStruct.TimeSec; | |
116 calclengthmmmmss: | |
117 snprintf( tmp,sizeof( tmp ),"%04d:%02d",t/60,t%60 ); | |
118 strlcat( trbuf,tmp,sizeof( trbuf ) ); | |
119 break; | |
120 case '3': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec / 3600 ); | |
121 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
122 case '4': snprintf( tmp,sizeof( tmp ),"%02d",( ( guiIntfStruct.TimeSec / 60 ) % 60 ) ); | |
123 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
124 case '5': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec % 60 ); | |
125 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
126 case '8': snprintf( tmp,sizeof( tmp ),"%01d:%02d:%02d",guiIntfStruct.TimeSec / 3600,( guiIntfStruct.TimeSec / 60 ) % 60,guiIntfStruct.TimeSec % 60 ); strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
127 case 'v': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Volume ); | |
128 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
129 case 'V': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Volume ); | |
130 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
131 case 'b': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Balance ); | |
132 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
133 case 'B': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Balance ); | |
134 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
135 case 'd': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.FrameDrop ); | |
136 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
137 case 'x': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieWidth ); | |
138 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
139 case 'y': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieHeight ); | |
140 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
141 case 'C': snprintf( tmp,sizeof( tmp ),"%s", guiIntfStruct.sh_video? ((sh_video_t *)guiIntfStruct.sh_video)->codec->name : ""); | |
142 strlcat( trbuf,tmp,sizeof( trbuf ) ); break; | |
143 case 's': if ( guiIntfStruct.Playing == 0 ) strlcat( trbuf,"s",sizeof( trbuf ) ); break; | |
144 case 'l': if ( guiIntfStruct.Playing == 1 ) strlcat( trbuf,"p",sizeof( trbuf ) ); break; | |
145 case 'e': if ( guiIntfStruct.Playing == 2 ) strlcat( trbuf,"e",sizeof( trbuf ) ); break; | |
146 case 'a': | |
147 if ( mixer->muted ) { strlcat( trbuf,"n",sizeof( trbuf ) ); break; } | |
148 switch ( guiIntfStruct.AudioType ) | |
149 { | |
150 case 0: strlcat( trbuf,"n",sizeof( trbuf ) ); break; | |
151 case 1: strlcat( trbuf,"m",sizeof( trbuf ) ); break; | |
152 case 2: strlcat( trbuf,"t",sizeof( trbuf ) ); break; | |
153 } | |
154 break; | |
155 case 'T': | |
156 switch ( guiIntfStruct.StreamType ) | |
157 { | |
158 case STREAMTYPE_FILE: strlcat( trbuf,"f",sizeof( trbuf ) ); break; | |
159 #ifdef HAVE_VCD | |
160 case STREAMTYPE_VCD: strlcat( trbuf,"v",sizeof( trbuf ) ); break; | |
161 #endif | |
162 case STREAMTYPE_STREAM: strlcat( trbuf,"u",sizeof( trbuf ) ); break; | |
163 #ifdef USE_DVDREAD | |
164 case STREAMTYPE_DVD: strlcat( trbuf,"d",sizeof( trbuf ) ); break; | |
165 #endif | |
166 default: strlcat( trbuf," ",sizeof( trbuf ) ); break; | |
167 } | |
168 break; | |
169 case '$': strlcat( trbuf,"$",sizeof( trbuf ) ); break; | |
170 default: continue; | |
171 } | |
172 c=strlen( trbuf ); | |
173 } | |
174 } | |
175 return trbuf; | |
176 } | |
177 | |
178 static char * image_buffer = NULL; | |
179 static int image_width = 0; | |
180 | |
181 void PutImage( txSample * bf,int x,int y,int max,int ofs ) | |
182 { | |
183 int i=0,ix,iy; | |
184 uint32_t * buf = NULL; | |
185 uint32_t * drw = NULL; | |
186 register uint32_t tmp; | |
187 register uint32_t yc; | |
188 | |
189 if ( ( !bf )||( bf->Image == NULL ) ) return; | |
190 | |
191 i=( bf->Width * ( bf->Height / max ) ) * ofs; | |
192 buf=(uint32_t *)image_buffer; | |
193 drw=(uint32_t *)bf->Image; | |
194 | |
195 #if 1 | |
196 for ( iy=y;iy < (int)(y+bf->Height / max);iy++ ) | |
197 for ( ix=x;ix < (int)(x+bf->Width);ix++ ) | |
198 { | |
199 tmp=drw[i++]; | |
200 if ( tmp != 0x00ff00ff ) buf[iy * image_width + ix]=tmp; | |
201 } | |
202 #else | |
203 yc=y * image_width; | |
204 for ( iy=y;iy < (int)(y+bf->Height / max);iy++ ) | |
205 { | |
206 for ( ix=x;ix < (int)(x+bf->Width);ix++ ) | |
207 { | |
208 tmp=drw[i++]; | |
209 if ( tmp != 0x00ff00ff ) buf[yc + ix]=tmp; | |
210 } | |
211 yc+=image_width; | |
212 } | |
213 #endif | |
214 } | |
215 | |
216 void SimplePotmeterPutImage( txSample * bf,int x,int y,float frac ) | |
217 { | |
218 int i=0,w,r,ix,iy; | |
219 uint32_t * buf = NULL; | |
220 uint32_t * drw = NULL; | |
221 register uint32_t tmp; | |
222 | |
223 if ( ( !bf )||( bf->Image == NULL ) ) return; | |
224 | |
225 buf=(uint32_t *)image_buffer; | |
226 drw=(uint32_t *)bf->Image; | |
227 w=bf->Width*frac; | |
228 r=bf->Width-w; | |
229 for ( iy=y;iy < (int)(y+bf->Height);iy++ ) | |
230 { | |
231 for ( ix=x;ix < (int)(x+w);ix++ ) | |
232 { | |
233 tmp=drw[i++]; | |
234 if ( tmp != 0x00ff00ff ) buf[iy * image_width + ix]=tmp; | |
235 } | |
236 i+=r; | |
237 } | |
238 } | |
239 | |
240 void Render( wsTWindow * window,wItem * Items,int nrItems,char * db,int size ) | |
241 { | |
242 wItem * item; | |
243 txSample * image = NULL; | |
244 int i; | |
245 | |
246 image_buffer=db; | |
247 image_width=window->Width; | |
248 | |
249 for( i=0;i < nrItems + 1;i++ ) | |
250 { | |
251 item=&Items[i]; | |
252 switch( item->type ) | |
253 { | |
254 case itButton: | |
255 PutImage( &item->Bitmap,item->x,item->y,3,item->pressed ); | |
256 break; | |
257 case itPotmeter: | |
258 if (item->phases == 1)SimplePotmeterPutImage( &item->Bitmap,item->x,item->y, item->value / 100.0f ); | |
259 else PutImage( &item->Bitmap,item->x,item->y,item->phases,( item->phases - 1 ) * ( item->value / 100.0f ) ); | |
260 break; | |
261 case itHPotmeter: | |
262 if (item->phases == 1)SimplePotmeterPutImage( &item->Bitmap,item->x,item->y, item->value / 100.0f ); | |
263 else PutImage( &item->Bitmap,item->x,item->y,item->phases,( item->phases - 1 ) * ( item->value / 100.0f ) ); | |
264 PutImage( &item->Mask,item->x + (int)( ( item->width - item->psx ) * item->value / 100.0f ),item->y,3,item->pressed ); | |
265 break; | |
266 case itVPotmeter: | |
267 PutImage( &item->Bitmap, | |
268 item->x,item->y, | |
269 item->phases, | |
270 item->phases * ( 1. - item->value / 100.0f ) ); | |
271 PutImage( &item->Mask, | |
272 item->x,item->y + (int)( ( item->height - item->psy ) * ( 1. - item->value / 100.0f ) ), | |
273 3,item->pressed ); | |
274 break; | |
275 case itSLabel: | |
276 image=fntRender( item,0,"%s",item->label ); | |
277 if ( image ) PutImage( image,item->x,item->y,1,0 ); | |
278 case itDLabel: | |
279 { | |
280 char * t = Translate( item->label ); | |
281 int l = fntTextWidth( item->fontid,t ); | |
282 l=(l?l:item->width); | |
283 image=fntRender( item,l-(GetTimerMS() / 20)%l,"%s",t ); | |
284 } | |
285 if ( image ) PutImage( image,item->x,item->y,1,0 ); | |
286 break; | |
287 } | |
288 } | |
289 wsConvert( window,db,size ); | |
290 } |