11 if(down && (key==
XK_Escape || key==
'q' || key==
'Q'))
16int main(
int argc,
char** argv)
21 rfbScreenInfoPtr rfbScreen;
22 enum { BW, GRAY, TRUECOLOUR } picType=TRUECOLOUR;
23 int bytesPerPixel,bitsPerPixelInFile;
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)) {
36 bytesPerPixel=4; bitsPerPixelInFile=3*8;
37 }
else if(!strncmp(buffer,
"P5",2)) {
39 bytesPerPixel=1; bitsPerPixelInFile=1*8;
40 }
else if(!strncmp(buffer,
"P4",2)) {
42 bytesPerPixel=1; bitsPerPixelInFile=1;
44 printf(
"Not a ppm.\n");
50 fgets(buffer,1024,in);
51 }
while(buffer[0]==
'#');
55 printf(
"Failed to get width or height.\n");
60 fgets(buffer,1024,in);
67 paddedWidth+=4-(
width&3);
70 rfbScreen =
rfbGetScreen(&argc,argv,paddedWidth,
height,8,(bitsPerPixelInFile+7)/8,bytesPerPixel);
74 rfbScreen->desktopName = argv[1];
76 rfbScreen->desktopName =
"Picture";
77 rfbScreen->alwaysShared =
TRUE;
78 rfbScreen->kbdAddEvent = HandleKey;
81 rfbScreen->httpDir =
"../webclients";
84 if (bytesPerPixel!=0 && paddedWidth>SIZE_MAX/bytesPerPixel) {
87 if (
height!=0 && paddedWidth*bytesPerPixel>SIZE_MAX/
height) {
90 rfbScreen->frameBuffer = (
char*)malloc(paddedWidth*bytesPerPixel*
height);
91 if(!rfbScreen->frameBuffer)
93 fread(rfbScreen->frameBuffer,
width*bitsPerPixelInFile/8,
height,in);
96 if(picType!=TRUECOLOUR) {
97 rfbScreen->serverFormat.trueColour=
FALSE;
98 rfbScreen->colourMap.count=256;
99 rfbScreen->colourMap.is16=
FALSE;
100 rfbScreen->colourMap.data.bytes=malloc(256*3);
101 if(!rfbScreen->colourMap.data.bytes)
104 memset(rfbScreen->colourMap.data.bytes+3*i,i,3);
110 for(j=
height-1;j>=0;j--) {
111 for(i=
width-1;i>=0;i--)
113 rfbScreen->frameBuffer[(j*paddedWidth+i)*4+k]=
114 rfbScreen->frameBuffer[(j*
width+i)*3+k];
115 for(i=
width*4;i<paddedWidth*4;i++)
116 rfbScreen->frameBuffer[j*paddedWidth*4+i]=0;
124 for(i=
width-1;i>=0;i-=8) {
125 l=(
unsigned char)rfbScreen->frameBuffer[(j*
width+i)/8];
127 rfbScreen->frameBuffer[j*paddedWidth+i+7-k]=(l&(1<<k))?0:255;
void rfbInitServer(rfbScreenInfoPtr rfbScreen)
void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, rfbBool runInBackground)
void rfbCloseClient(rfbClientPtr cl)
rfbScreenInfoPtr rfbGetScreen(int *argc, char **argv, int width, int height, int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
int main(int argc, char **argv)