Mercurial > mplayer.hg
annotate libvo/vo_x11.c @ 289:dbe4a779b891
vga<->vgagl swapped
author | arpi_esp |
---|---|
date | Thu, 05 Apr 2001 20:03:26 +0000 |
parents | 2dadc379a934 |
children | 828ec81e0d64 |
rev | line source |
---|---|
1 | 1 #define DISP |
2 | |
3 /* | |
4 * video_out_x11.c,X11 interface | |
5 * | |
6 * | |
7 * Copyright ( C ) 1996,MPEG Software Simulation Group. All Rights Reserved. | |
8 * | |
9 * Hacked into mpeg2dec by | |
10 * | |
11 * Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | |
12 * | |
13 * 15 & 16 bpp support added by Franck Sicard <Franck.Sicard@solsoft.fr> | |
14 * | |
15 */ | |
16 | |
17 #include <stdio.h> | |
18 #include <stdlib.h> | |
19 #include <string.h> | |
20 #include <signal.h> | |
21 | |
22 #include "config.h" | |
23 #include "video_out.h" | |
24 #include "video_out_internal.h" | |
25 | |
26 LIBVO_EXTERN( x11 ) | |
27 | |
28 #include <X11/Xlib.h> | |
29 #include <X11/Xutil.h> | |
30 #include <X11/extensions/XShm.h> | |
206
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
31 #ifdef HAVE_XF86VM |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
32 #include <X11/extensions/xf86vmode.h> |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
33 #endif |
1 | 34 #include <errno.h> |
35 #include "yuv2rgb.h" | |
36 | |
31 | 37 #include "x11_common.h" |
38 | |
1 | 39 static vo_info_t vo_info = |
40 { | |
41 "X11 ( XImage/Shm )", | |
42 "x11", | |
43 "Aaron Holtzman <aholtzma@ess.engr.uvic.ca>", | |
44 "" | |
45 }; | |
46 | |
47 /* private prototypes */ | |
48 static void Display_Image ( XImage * myximage,unsigned char *ImageData ); | |
49 | |
50 /* since it doesn't seem to be defined on some platforms */ | |
51 int XShmGetEventBase( Display* ); | |
52 | |
53 /* local data */ | |
54 static unsigned char *ImageData; | |
55 | |
206
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
56 #ifdef HAVE_XF86VM |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
57 XF86VidModeModeInfo **vidmodes=NULL; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
58 #endif |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
59 |
1 | 60 /* X11 related variables */ |
61 static Display *mDisplay; | |
62 static Window mywindow; | |
63 static GC mygc; | |
64 static XImage *myximage; | |
65 static int depth,bpp,mode; | |
66 static XWindowAttributes attribs; | |
67 static int X_already_started=0; | |
68 | |
31 | 69 //static int vo_dwidth,vo_dheight; |
1 | 70 |
71 #define SH_MEM | |
72 | |
73 #ifdef SH_MEM | |
74 | |
75 #include <sys/ipc.h> | |
76 #include <sys/shm.h> | |
77 #include <X11/extensions/XShm.h> | |
78 | |
79 //static int HandleXError _ANSI_ARGS_( ( Display * dpy,XErrorEvent * event ) ); | |
80 static void InstallXErrorHandler ( void ); | |
81 static void DeInstallXErrorHandler ( void ); | |
82 | |
83 static int Shmem_Flag; | |
84 static int Quiet_Flag; | |
85 static XShmSegmentInfo Shminfo[1]; | |
86 static int gXErrorFlag; | |
87 static int CompletionType=-1; | |
88 | |
89 static void InstallXErrorHandler() | |
90 { | |
91 //XSetErrorHandler( HandleXError ); | |
92 XFlush( mDisplay ); | |
93 } | |
94 | |
95 static void DeInstallXErrorHandler() | |
96 { | |
97 XSetErrorHandler( NULL ); | |
98 XFlush( mDisplay ); | |
99 } | |
100 | |
101 #endif | |
102 | |
103 static uint32_t image_width; | |
104 static uint32_t image_height; | |
105 static uint32_t image_format; | |
106 | |
31 | 107 static void check_events(){ |
108 int e=vo_x11_check_events(mDisplay); | |
1 | 109 } |
110 | |
111 static uint32_t init( uint32_t width,uint32_t height,uint32_t d_width,uint32_t d_height,uint32_t fullscreen,char *title,uint32_t format ) | |
112 { | |
113 int screen; | |
114 unsigned int fg,bg; | |
115 char *hello=( title == NULL ) ? "X11 render" : title; | |
116 char *name=":0.0"; | |
117 XSizeHints hint; | |
118 XVisualInfo vinfo; | |
119 XEvent xev; | |
120 XGCValues xgcv; | |
121 Colormap theCmap; | |
122 XSetWindowAttributes xswa; | |
123 unsigned long xswamask; | |
124 | |
125 image_height=height; | |
126 image_width=width; | |
127 image_format=format; | |
128 | |
129 if ( X_already_started ) return -1; | |
130 if( !vo_init() ) return 0; // Can't open X11 | |
131 | |
132 if( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" ); | |
133 | |
134 mDisplay=XOpenDisplay( name ); | |
135 | |
136 if ( mDisplay == NULL ) | |
137 { | |
138 fprintf( stderr,"Can not open display\n" ); | |
139 return -1; | |
140 } | |
141 | |
142 screen=DefaultScreen( mDisplay ); | |
143 | |
144 hint.x=0; | |
145 hint.y=0; | |
146 hint.width=image_width; | |
147 hint.height=image_height; | |
206
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
148 |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
149 #ifdef HAVE_XF86VM |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
150 if (fullscreen) { |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
151 unsigned int modeline_width, modeline_height, vm_event, vm_error; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
152 unsigned int vm_ver, vm_rev; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
153 int i,j,k,have_vm=0,X,Y; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
154 |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
155 int modecount; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
156 |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
157 if (XF86VidModeQueryExtension(mDisplay, &vm_event, &vm_error)) { |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
158 XF86VidModeQueryVersion(mDisplay, &vm_ver, &vm_rev); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
159 printf("XF86VidMode Extension v%i.%i\n", vm_ver, vm_rev); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
160 have_vm=1; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
161 } else |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
162 printf("XF86VidMode Extenstion not available.\n"); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
163 |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
164 if (have_vm) { |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
165 if (vidmodes==NULL) |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
166 XF86VidModeGetAllModeLines(mDisplay,screen,&modecount,&vidmodes); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
167 j=0; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
168 modeline_width=vidmodes[0]->hdisplay; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
169 modeline_height=vidmodes[0]->vdisplay; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
170 if ((d_width==0) && (d_height==0)) |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
171 { X=image_width; Y=image_height; } |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
172 else |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
173 { X=d_width; Y=d_height; } |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
174 |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
175 for (i=1; i<modecount; i++) |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
176 if ((vidmodes[i]->hdisplay >= X) && (vidmodes[i]->vdisplay >= Y)) |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
177 if ( (vidmodes[i]->hdisplay < modeline_width ) && (vidmodes[i]->vdisplay < modeline_height) ) |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
178 { |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
179 modeline_width=vidmodes[i]->hdisplay; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
180 modeline_height=vidmodes[i]->vdisplay; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
181 j=i; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
182 } |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
183 |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
184 printf("XF86VM: Selected video mode %dx%d for image size %dx%d.\n",modeline_width, modeline_height, image_width, image_height); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
185 XF86VidModeLockModeSwitch(mDisplay,screen,0); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
186 XF86VidModeSwitchToMode(mDisplay,screen,vidmodes[j]); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
187 XF86VidModeSwitchToMode(mDisplay,screen,vidmodes[j]); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
188 X=(vo_screenwidth-modeline_width)/2; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
189 Y=(vo_screenheight-modeline_height)/2; |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
190 XF86VidModeSetViewPort(mDisplay,screen,X,Y); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
191 } |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
192 } |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
193 #endif |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
194 |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
195 |
1 | 196 if ( fullscreen ) |
197 { | |
198 hint.width=vo_screenwidth; | |
199 hint.height=vo_screenheight; | |
200 } | |
31 | 201 vo_dwidth=hint.width; |
202 vo_dheight=hint.height; | |
1 | 203 hint.flags=PPosition | PSize; |
204 | |
205 bg=WhitePixel( mDisplay,screen ); | |
206 fg=BlackPixel( mDisplay,screen ); | |
207 | |
208 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs ); | |
209 depth=attribs.depth; | |
210 | |
211 if ( depth != 15 && depth != 16 && depth != 24 && depth != 32 ) depth=24; | |
212 XMatchVisualInfo( mDisplay,screen,depth,TrueColor,&vinfo ); | |
213 | |
214 theCmap =XCreateColormap( mDisplay,RootWindow( mDisplay,screen ), | |
215 vinfo.visual,AllocNone ); | |
216 | |
217 xswa.background_pixel=0; | |
218 xswa.border_pixel=1; | |
219 xswa.colormap=theCmap; | |
220 xswamask=CWBackPixel | CWBorderPixel |CWColormap; | |
221 | |
222 mywindow=XCreateWindow( mDisplay,RootWindow( mDisplay,screen ), | |
223 hint.x,hint.y, | |
224 hint.width,hint.height, | |
225 xswa.border_pixel,depth,CopyFromParent,vinfo.visual,xswamask,&xswa ); | |
226 | |
31 | 227 if ( fullscreen ) vo_x11_decoration( mDisplay,mywindow,0 ); |
1 | 228 XSelectInput( mDisplay,mywindow,StructureNotifyMask ); |
229 XSetStandardProperties( mDisplay,mywindow,hello,hello,None,NULL,0,&hint ); | |
230 XMapWindow( mDisplay,mywindow ); | |
231 do { XNextEvent( mDisplay,&xev ); } while ( xev.type != MapNotify || xev.xmap.event != mywindow ); | |
232 | |
233 XSelectInput( mDisplay,mywindow,NoEventMask ); | |
234 | |
235 XFlush( mDisplay ); | |
236 XSync( mDisplay,False ); | |
237 | |
238 mygc=XCreateGC( mDisplay,mywindow,0L,&xgcv ); | |
239 | |
240 #ifdef SH_MEM | |
241 if ( XShmQueryExtension( mDisplay ) ) Shmem_Flag=1; | |
242 else | |
243 { | |
244 Shmem_Flag=0; | |
245 if ( !Quiet_Flag ) fprintf( stderr,"Shared memory not supported\nReverting to normal Xlib\n" ); | |
246 } | |
247 if ( Shmem_Flag ) CompletionType=XShmGetEventBase( mDisplay ) + ShmCompletion; | |
248 | |
249 InstallXErrorHandler(); | |
250 | |
251 if ( Shmem_Flag ) | |
252 { | |
253 myximage=XShmCreateImage( mDisplay,vinfo.visual,depth,ZPixmap,NULL,&Shminfo[0],width,image_height ); | |
254 if ( myximage == NULL ) | |
255 { | |
256 if ( myximage != NULL ) XDestroyImage( myximage ); | |
257 if ( !Quiet_Flag ) fprintf( stderr,"Shared memory error,disabling ( Ximage error )\n" ); | |
258 goto shmemerror; | |
259 } | |
260 Shminfo[0].shmid=shmget( IPC_PRIVATE, | |
261 myximage->bytes_per_line * myximage->height , | |
262 IPC_CREAT | 0777 ); | |
263 if ( Shminfo[0].shmid < 0 ) | |
264 { | |
265 XDestroyImage( myximage ); | |
266 if ( !Quiet_Flag ) | |
267 { | |
268 printf( "%s\n",strerror( errno ) ); | |
269 perror( strerror( errno ) ); | |
270 fprintf( stderr,"Shared memory error,disabling ( seg id error )\n" ); | |
271 } | |
272 goto shmemerror; | |
273 } | |
274 Shminfo[0].shmaddr=( char * ) shmat( Shminfo[0].shmid,0,0 ); | |
275 | |
276 if ( Shminfo[0].shmaddr == ( ( char * ) -1 ) ) | |
277 { | |
278 XDestroyImage( myximage ); | |
279 if ( Shminfo[0].shmaddr != ( ( char * ) -1 ) ) shmdt( Shminfo[0].shmaddr ); | |
280 if ( !Quiet_Flag ) fprintf( stderr,"Shared memory error,disabling ( address error )\n" ); | |
281 goto shmemerror; | |
282 } | |
283 myximage->data=Shminfo[0].shmaddr; | |
284 ImageData=( unsigned char * ) myximage->data; | |
285 Shminfo[0].readOnly=False; | |
286 XShmAttach( mDisplay,&Shminfo[0] ); | |
287 | |
288 XSync( mDisplay,False ); | |
289 | |
290 if ( gXErrorFlag ) | |
291 { | |
292 XDestroyImage( myximage ); | |
293 shmdt( Shminfo[0].shmaddr ); | |
294 if ( !Quiet_Flag ) fprintf( stderr,"Shared memory error,disabling.\n" ); | |
295 gXErrorFlag=0; | |
296 goto shmemerror; | |
297 } | |
298 else | |
299 shmctl( Shminfo[0].shmid,IPC_RMID,0 ); | |
300 | |
301 if ( !Quiet_Flag ) fprintf( stderr,"Sharing memory.\n" ); | |
302 } | |
303 else | |
304 { | |
305 shmemerror: | |
306 Shmem_Flag=0; | |
307 #endif | |
308 myximage=XGetImage( mDisplay,mywindow,0,0, | |
309 width,image_height,AllPlanes,ZPixmap ); | |
310 ImageData=myximage->data; | |
311 #ifdef SH_MEM | |
312 } | |
313 | |
314 DeInstallXErrorHandler(); | |
315 #endif | |
316 | |
317 bpp=myximage->bits_per_pixel; | |
318 | |
319 fprintf( stderr,"X11 color mask: R:%X G:%X B:%X\n",myximage->red_mask,myximage->green_mask,myximage->blue_mask ); | |
320 | |
321 // If we have blue in the lowest bit then obviously RGB | |
322 mode=( ( myximage->blue_mask & 0x01 ) != 0 ) ? MODE_RGB : MODE_BGR; | |
323 #ifdef WORDS_BIGENDIAN | |
324 if ( myximage->byte_order != MSBFirst ) | |
325 #else | |
326 if ( myximage->byte_order != LSBFirst ) | |
327 #endif | |
328 { | |
329 fprintf( stderr,"No support fon non-native XImage byte order!\n" ); | |
330 return -1; | |
331 } | |
332 | |
333 if( format==IMGFMT_YV12 ) yuv2rgb_init( ( depth == 24 ) ? bpp : depth,mode ); | |
334 | |
335 XSelectInput( mDisplay,mywindow,StructureNotifyMask | KeyPressMask ); | |
336 X_already_started++; | |
337 | |
338 // vo_initthread( mThread ); | |
339 | |
340 return 0; | |
341 } | |
342 | |
343 static const vo_info_t* get_info( void ) | |
344 { return &vo_info; } | |
345 | |
346 static void Terminate_Display_Process( void ) | |
347 { | |
348 getchar(); /* wait for enter to remove window */ | |
349 #ifdef SH_MEM | |
350 if ( Shmem_Flag ) | |
351 { | |
352 XShmDetach( mDisplay,&Shminfo[0] ); | |
353 XDestroyImage( myximage ); | |
354 shmdt( Shminfo[0].shmaddr ); | |
355 } | |
356 #endif | |
357 XDestroyWindow( mDisplay,mywindow ); | |
358 XCloseDisplay( mDisplay ); | |
359 X_already_started=0; | |
360 } | |
361 | |
362 static void Display_Image( XImage *myximage,uint8_t *ImageData ) | |
363 { | |
364 #ifdef DISP | |
365 #ifdef SH_MEM | |
366 if ( Shmem_Flag ) | |
367 { | |
368 XShmPutImage( mDisplay,mywindow,mygc,myximage, | |
369 0,0, | |
31 | 370 ( vo_dwidth - myximage->width ) / 2,( vo_dheight - myximage->height ) / 2, |
1 | 371 myximage->width,myximage->height,True ); |
372 XFlush( mDisplay ); | |
373 } | |
374 else | |
375 #endif | |
376 { | |
377 XPutImage( mDisplay,mywindow,mygc,myximage, | |
378 0,0, | |
31 | 379 ( vo_dwidth - myximage->width ) / 2,( vo_dheight - myximage->height ) / 2, |
1 | 380 myximage->width,myximage->height ); |
381 XFlush( mDisplay ); | |
382 } | |
383 #endif | |
384 } | |
385 | |
202 | 386 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
387 int dbpp=( bpp+7 )/8; | |
388 int x,y; | |
389 | |
390 for(y=0;y<h;y++){ | |
391 uint8_t *dst = ImageData+ dbpp*((y+y0)*image_width+x0); | |
392 for(x=0;x<w;x++){ | |
393 // dst[x]=(dst[x]*srca[x]+src[x]*(srca[x]^255))>>8; | |
394 if(srca[x]){ | |
249 | 395 dst[0]=((dst[0]*srca[x])>>8)+src[x]; |
396 dst[1]=((dst[1]*srca[x])>>8)+src[x]; | |
397 dst[2]=((dst[2]*srca[x])>>8)+src[x]; | |
398 //dst[0]=(dst[0]*(srca[x]^255)+src[x]*(srca[x]))>>8; | |
399 //dst[1]=(dst[1]*(srca[x]^255)+src[x]*(srca[x]))>>8; | |
400 //dst[2]=(dst[2]*(srca[x]^255)+src[x]*(srca[x]))>>8; | |
202 | 401 } |
402 dst+=dbpp; | |
403 } | |
404 src+=stride; | |
405 srca+=stride; | |
406 } | |
407 | |
408 } | |
409 | |
410 | |
31 | 411 static void flip_page( void ){ |
213 | 412 vo_draw_text(image_width,image_height,draw_alpha); |
31 | 413 check_events(); |
414 Display_Image( myximage,ImageData ); | |
415 } | |
1 | 416 |
417 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
418 { | |
419 uint8_t *dst; | |
420 | |
421 dst=ImageData + ( image_width * y + x ) * ( bpp/8 ); | |
422 yuv2rgb( dst,src[0],src[1],src[2],w,h,image_width*( bpp/8 ),stride[0],stride[1] ); | |
423 return 0; | |
424 } | |
425 | |
426 void rgb15to16_mmx( char* s0,char* d0,int count ); | |
427 | |
428 #if 1 | |
429 static uint32_t draw_frame( uint8_t *src[] ) | |
430 { | |
431 if( image_format==IMGFMT_YV12 ) | |
432 { | |
433 yuv2rgb( ImageData,src[0],src[1],src[2],image_width,image_height,image_width*( bpp/8 ),image_width,image_width/2 ); | |
434 } | |
435 else | |
436 { | |
437 int sbpp=( ( image_format&0xFF )+7 )/8; | |
438 int dbpp=( bpp+7 )/8; | |
439 char *d=ImageData; | |
440 char *s=src[0]; | |
441 //printf( "sbpp=%d dbpp=%d depth=%d bpp=%d\n",sbpp,dbpp,depth,bpp ); | |
442 #if 0 | |
443 // flipped BGR | |
444 int i; | |
445 //printf( "Rendering flipped BGR frame bpp=%d src=%d dst=%d\n",bpp,sbpp,dbpp ); | |
446 s+=sbpp*image_width*image_height; | |
447 for( i=0;i<image_height;i++ ) | |
448 { | |
449 s-=sbpp*image_width; | |
450 if( sbpp==dbpp ) memcpy( d,s,sbpp*image_width ); | |
451 else | |
452 { | |
453 char *s2=s; | |
454 char *d2=d; | |
455 char *e=s2+sbpp*image_width; | |
456 while( s2<e ) | |
457 { | |
458 d2[0]=s2[0]; | |
459 d2[1]=s2[1]; | |
460 d2[2]=s2[2]; | |
461 s2+=sbpp;d2+=dbpp; | |
462 } | |
463 } | |
464 d+=dbpp*image_width; | |
465 } | |
466 #else | |
467 // memcpy( ImageData,src[0],image_width*image_height*bpp ); | |
468 if( sbpp==dbpp ) | |
469 { | |
470 //Display_Image( myximage,s );return 0; | |
471 #if 1 | |
472 if( depth==16 && image_format==( IMGFMT_BGR|15 ) ){ | |
473 // do 15bpp->16bpp | |
474 #ifdef HAVE_MMX | |
475 rgb15to16_mmx( s,d,2*image_width*image_height ); | |
476 #else | |
477 unsigned short *s1=( unsigned short * )s; | |
478 unsigned short *d1=( unsigned short * )d; | |
479 unsigned short *e=s1+image_width*image_height; | |
480 while( s1<e ) | |
481 { | |
482 register int x=*( s1++ ); | |
483 // rrrrrggggggbbbbb | |
484 // 0rrrrrgggggbbbbb | |
485 // 0111 1111 1110 0000=0x7FE0 | |
486 // 00000000000001 1111=0x001F | |
487 *( d1++ )=( x&0x001F )|( ( x&0x7FE0 )<<1 ); | |
488 } | |
489 #endif | |
490 } | |
491 else | |
492 #endif | |
493 { memcpy( d,s,sbpp*image_width*image_height ); } | |
494 } | |
495 else | |
496 { | |
497 char *e=s+sbpp*image_width*image_height; | |
498 //printf( "libvo: using C 24->32bpp conversion\n" ); | |
499 while( s<e ) | |
500 { | |
501 d[0]=s[0]; | |
502 d[1]=s[1]; | |
503 d[2]=s[2]; | |
504 s+=sbpp;d+=dbpp; | |
505 } | |
506 } | |
507 #endif | |
508 } | |
509 //Display_Image( myximage,ImageData ); | |
510 return 0; | |
511 } | |
512 #endif | |
513 | |
514 static uint32_t query_format( uint32_t format ) | |
515 { | |
516 if( !vo_init() ) return 0; // Can't open X11 | |
517 if( ( format&IMGFMT_BGR_MASK )==IMGFMT_BGR && ( format&0xFF )==vo_depthonscreen ) return 1; | |
518 switch( format ) | |
519 { | |
520 case IMGFMT_YV12: return 1; | |
521 } | |
522 return 0; | |
523 } | |
524 | |
525 | |
526 static void | |
527 uninit(void) | |
528 { | |
206
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
529 #ifdef HAVE_XF86VM |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
530 if (vidmodes!=NULL) |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
531 { |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
532 int screen; screen=DefaultScreen( mDisplay ); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
533 XF86VidModeSwitchToMode(mDisplay,screen,vidmodes[0]); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
534 XF86VidModeSwitchToMode(mDisplay,screen,vidmodes[0]); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
535 free(vidmodes); |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
536 } |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
537 #endif |
82b5ae8ceaf4
adds XF86VidMode support to vo_x11.c to do "pseudo-scaling"
mgraffam
parents:
202
diff
changeset
|
538 |
1 | 539 printf("vo: uninit!\n"); |
540 } | |
541 | |
542 | |
543 |