5 void HandleKey(Bool down
,KeySym key
,rfbClientPtr cl
)
7 if(down
&& (key
==XK_Escape
|| key
=='q' || key
=='Q'))
11 int main(int argc
,char** argv
)
14 int i
,j
,k
,width
,height
,paddedWidth
;
15 unsigned char buffer
[1024];
16 rfbScreenInfoPtr rfbScreen
;
19 in
=fopen(argv
[1],"rb");
21 printf("Couldn't find file %s.\n",argv
[1]);
26 fgets(buffer
,1024,in
);
27 if(strncmp(buffer
,"P6",2)) {
28 printf("Not a ppm.\n");
34 fgets(buffer
,1024,in
);
35 } while(buffer
[0]=='#');
37 /* get width & height */
38 sscanf(buffer
,"%d %d",&width
,&height
);
39 fprintf(stderr
,"Got width %d and height %d.\n",width
,height
);
40 fgets(buffer
,1024,in
);
42 /* vncviewers have problems with widths which are no multiple of 4. */
45 paddedWidth
+=4-(width
&3);
47 /* initialize data for vnc server */
48 rfbScreen
= rfbGetScreen(&argc
,argv
,paddedWidth
,height
,8,3,4);
50 rfbScreen
->desktopName
= argv
[1];
52 rfbScreen
->desktopName
= "Picture";
53 rfbScreen
->rfbAlwaysShared
= TRUE
;
54 rfbScreen
->kbdAddEvent
= HandleKey
;
57 rfbScreen
->httpDir
= "./classes";
59 /* allocate picture and read it */
60 rfbScreen
->frameBuffer
= (char*)malloc(paddedWidth
*4*height
);
61 fread(rfbScreen
->frameBuffer
,width
*3,height
,in
);
64 /* correct the format to 4 bytes instead of 3 (and pad to paddedWidth) */
65 for(j
=height
-1;j
>=0;j
--) {
66 for(i
=width
-1;i
>=0;i
--)
68 rfbScreen
->frameBuffer
[(j
*paddedWidth
+i
)*4+k
]=
69 rfbScreen
->frameBuffer
[(j
*width
+i
)*3+k
];
70 for(i
=width
*4;i
<paddedWidth
*4;i
++)
71 rfbScreen
->frameBuffer
[j
*paddedWidth
*4+i
]=0;
74 /* initialize server */
75 rfbInitServer(rfbScreen
);
78 rfbRunEventLoop(rfbScreen
,40000,FALSE
);