#include <stdio.h>
#ifndef HAVE_HANDLEKEY
{
if(down && (key==
XK_Escape || key==
'q' || key==
'Q'))
}
#endif
int main(
int argc,
char** argv)
{
FILE* in=stdin;
char buffer[1024];
rfbScreenInfoPtr rfbScreen;
enum { BW, GRAY, TRUECOLOUR } picType=TRUECOLOUR;
int bytesPerPixel,bitsPerPixelInFile;
if(argc>1) {
in=fopen(argv[1],"rb");
if(!in) {
printf("Couldn't find file %s.\n",argv[1]);
exit(1);
}
}
fgets(buffer,1024,in);
if(!strncmp(buffer,"P6",2)) {
picType=TRUECOLOUR;
bytesPerPixel=4; bitsPerPixelInFile=3*8;
} else if(!strncmp(buffer,"P5",2)) {
picType=GRAY;
bytesPerPixel=1; bitsPerPixelInFile=1*8;
} else if(!strncmp(buffer,"P4",2)) {
picType=BW;
bytesPerPixel=1; bitsPerPixelInFile=1;
} else {
printf("Not a ppm.\n");
exit(2);
}
do {
fgets(buffer,1024,in);
} while(buffer[0]=='#');
if(picType!=BW)
fgets(buffer,1024,in);
else
paddedWidth+=4-(
width&3);
rfbScreen =
rfbGetScreen(&argc,argv,paddedWidth,
height,8,(bitsPerPixelInFile+7)/8,bytesPerPixel);
if(!rfbScreen)
return 1;
if(argc>1)
rfbScreen->desktopName = argv[1];
else
rfbScreen->desktopName = "Picture";
rfbScreen->alwaysShared =
TRUE;
rfbScreen->kbdAddEvent = HandleKey;
rfbScreen->httpDir = "../webclients";
rfbScreen->frameBuffer = (
char*)malloc(paddedWidth*bytesPerPixel*
height);
if(!rfbScreen->frameBuffer)
exit(1);
fread(rfbScreen->frameBuffer,
width*bitsPerPixelInFile/8,
height,in);
fclose(in);
if(picType!=TRUECOLOUR) {
rfbScreen->serverFormat.trueColour=
FALSE;
rfbScreen->colourMap.count=256;
rfbScreen->colourMap.is16=
FALSE;
rfbScreen->colourMap.data.bytes=malloc(256*3);
if(!rfbScreen->colourMap.data.bytes)
exit(1);
for(i=0;i<256;i++)
memset(rfbScreen->colourMap.data.bytes+3*i,i,3);
}
switch(picType) {
case TRUECOLOUR:
for(k=2;k>=0;k--)
rfbScreen->frameBuffer[(j*paddedWidth+i)*4+k]=
rfbScreen->frameBuffer[(j*
width+i)*3+k];
for(i=
width*4;i<paddedWidth*4;i++)
rfbScreen->frameBuffer[j*paddedWidth*4+i]=0;
}
break;
case GRAY:
break;
case BW:
for(i=
width-1;i>=0;i-=8) {
l=(
unsigned char)rfbScreen->frameBuffer[(j*
width+i)/8];
for(k=7;k>=0;k--)
rfbScreen->frameBuffer[j*paddedWidth+i+7-k]=(l&(1<<k))?0:255;
}
break;
}
return(0);
}
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)