Mercurial > mplayer.hg
annotate TOOLS/mwallp/mwallp.c @ 16111:5683110fce0a
Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
compile everywhere since the gl/glx headers are such a mess...
author | reimar |
---|---|
date | Tue, 26 Jul 2005 18:28:51 +0000 |
parents | 95918d5066b6 |
children |
rev | line source |
---|---|
6457
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
1 // based on x11_common.c/vo_x11.c from libvo |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
2 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
3 #include <stdio.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
4 #include <stdlib.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
5 #include <inttypes.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
6 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
7 #include <string.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
8 #include <unistd.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
9 #include <sys/mman.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
10 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
11 #include <X11/Xmd.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
12 #include <X11/Xlib.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
13 #include <X11/Xutil.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
14 #include <X11/Xatom.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
15 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
16 #include "cpudetect.h" |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
17 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
18 char* mDisplayName=NULL; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
19 Display* mDisplay=NULL; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
20 Window mRootWin=None; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
21 int mScreen=0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
22 XImage * mXImage = NULL; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
23 GC vo_gc = NULL; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
24 Pixmap mPixmap=0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
25 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
26 int vo_depthonscreen=0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
27 int vo_screenwidth=0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
28 int vo_screenheight=0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
29 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
30 int verbose=0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
31 int namecnt=0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
32 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
33 int main(int argc,char* argv[]){ |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
34 unsigned int mask; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
35 int bpp,depth; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
36 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
37 mp_msg_init(); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
38 mp_msg_set_level(5); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
39 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
40 GetCpuCaps(&gCpuCaps); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
41 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
42 mDisplayName = XDisplayName(mDisplayName); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
43 mDisplay=XOpenDisplay(mDisplayName); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
44 if ( !mDisplay ) |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
45 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
46 printf("vo: couldn't open the X11 display (%s)!\n",mDisplayName ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
47 return 0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
48 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
49 mScreen=DefaultScreen( mDisplay ); // Screen ID. |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
50 mRootWin=RootWindow( mDisplay,mScreen );// Root window ID. |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
51 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
52 vo_screenwidth=DisplayWidth( mDisplay,mScreen ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
53 vo_screenheight=DisplayHeight( mDisplay,mScreen ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
54 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
55 // get color depth (from root window, or the best visual): |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
56 { XWindowAttributes attribs; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
57 XGetWindowAttributes(mDisplay, mRootWin, &attribs); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
58 depth=vo_depthonscreen=attribs.depth; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
59 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
60 mXImage=XGetImage( mDisplay,mRootWin,0,0,vo_screenwidth,vo_screenheight,AllPlanes,ZPixmap ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
61 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
62 bpp=mXImage->bits_per_pixel; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
63 if((vo_depthonscreen+7)/8 != (bpp+7)/8) vo_depthonscreen=bpp; // by A'rpi |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
64 mask=mXImage->red_mask|mXImage->green_mask|mXImage->blue_mask; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
65 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
66 if(((vo_depthonscreen+7)/8)==2){ |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
67 if(mask==0x7FFF) vo_depthonscreen=15; else |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
68 if(mask==0xFFFF) vo_depthonscreen=16; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
69 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
70 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
71 printf("X11 running at %d x %d, %d bpp \n",vo_screenwidth,vo_screenheight,vo_depthonscreen); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
72 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
73 mPixmap=XCreatePixmap(mDisplay,mRootWin,vo_screenwidth,vo_screenheight,depth); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
74 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
75 { XGCValues xgcv; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
76 vo_gc=XCreateGC( mDisplay,mRootWin,0L,&xgcv ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
77 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
78 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
79 if(argc<2){ printf("no filenames!\n");return;} |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
80 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
81 srand(time(NULL)); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
82 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
83 while(1){ |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
84 FILE *f; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
85 char* data; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
86 int len; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
87 int ret; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
88 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
89 namecnt=1+(long long)rand()*(argc-1)/RAND_MAX; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
90 //++namecnt; if(namecnt>=argc) namecnt=1; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
91 if(namecnt<1 || namecnt>=argc) continue; // ??? |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
92 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
93 f=fopen(argv[namecnt],"rb");if(!f) continue; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
94 fseek(f,0,SEEK_END); len=ftell(f); fseek(f,0,SEEK_SET); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
95 data=malloc(len); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
96 len=fread(data,1,len,f); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
97 fclose(f); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
98 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
99 ret=decode_jpeg(data,len,mXImage->data,vo_screenwidth,vo_screenheight, |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
100 ((vo_depthonscreen+7)/8)*vo_screenwidth,vo_depthonscreen); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
101 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
102 free(data); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
103 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
104 if(!ret) continue; // failed to load |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
105 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
106 XPutImage( mDisplay,mPixmap,vo_gc,mXImage, |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
107 0,0, 0,0, vo_screenwidth,vo_screenheight); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
108 XSetWindowBackgroundPixmap(mDisplay,mRootWin,mPixmap); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
109 XClearWindow(mDisplay,mRootWin); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
110 XSync(mDisplay, True); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
111 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
112 break; // DONE! |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
113 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
114 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
115 } |