3 #include <rfb/keysym.h>
5 #ifndef LIBVNCSERVER_ALLOW24BPP
7 printf("I need the ALLOW24BPP LibVNCServer flag to work\n");
12 static void HandleKey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
14 if(down && (key==XK_Escape || key=='q' || key=='Q'))
18 int main(int argc,char** argv)
21 int j,width,height,paddedWidth;
23 rfbScreenInfoPtr rfbScreen;
26 in=fopen(argv[1],"rb");
28 printf("Couldn't find file %s.\n",argv[1]);
33 fgets(buffer,1024,in);
34 if(strncmp(buffer,"P6",2)) {
35 printf("Not a ppm.\n");
41 fgets(buffer,1024,in);
42 } while(buffer[0]=='#');
44 /* get width & height */
45 sscanf(buffer,"%d %d",&width,&height);
46 rfbLog("Got width %d and height %d.\n",width,height);
47 fgets(buffer,1024,in);
49 /* vncviewers have problems with widths which are no multiple of 4. */
52 /* if your vncviewer doesn't have problems with a width
53 which is not a multiple of 4, you can comment this. */
55 paddedWidth+=4-(width&3);
57 /* initialize data for vnc server */
58 rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3);
60 rfbScreen->desktopName = argv[1];
62 rfbScreen->desktopName = "Picture";
63 rfbScreen->alwaysShared = TRUE;
64 rfbScreen->kbdAddEvent = HandleKey;
67 rfbScreen->httpDir = "../classes";
69 /* allocate picture and read it */
70 rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height);
71 fread(rfbScreen->frameBuffer,width*3,height,in);
74 /* pad to paddedWidth */
75 if(width != paddedWidth) {
76 int padCount = 3*(paddedWidth - width);
77 for(j=height-1;j>=0;j--) {
78 memmove(rfbScreen->frameBuffer+3*paddedWidth*j,
79 rfbScreen->frameBuffer+3*width*j,
81 memset(rfbScreen->frameBuffer+3*paddedWidth*(j+1)-padCount,
86 /* initialize server */
87 rfbInitServer(rfbScreen);
90 rfbRunEventLoop(rfbScreen,40000,FALSE);