comparison TOOLS/mwallp/mwallp.c @ 6457:95918d5066b6

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