Go to the documentation of this file.00001
00005 #include <stdio.h>
00006 #include <rfb/rfb.h>
00007 #include <rfb/keysym.h>
00008
00009 #ifndef LIBVNCSERVER_ALLOW24BPP
00010 int main() {
00011 printf("I need the ALLOW24BPP LibVNCServer flag to work\n");
00012 exit(1);
00013 }
00014 #else
00015
00016 static void HandleKey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
00017 {
00018 if(down && (key==XK_Escape || key=='q' || key=='Q'))
00019 rfbCloseClient(cl);
00020 }
00021
00022 int main(int argc,char** argv)
00023 {
00024 FILE* in=stdin;
00025 int j,width,height,paddedWidth;
00026 char buffer[1024];
00027 rfbScreenInfoPtr rfbScreen;
00028
00029 if(argc>1) {
00030 in=fopen(argv[1],"rb");
00031 if(!in) {
00032 printf("Couldn't find file %s.\n",argv[1]);
00033 exit(1);
00034 }
00035 }
00036
00037 fgets(buffer,1024,in);
00038 if(strncmp(buffer,"P6",2)) {
00039 printf("Not a ppm.\n");
00040 exit(2);
00041 }
00042
00043
00044 do {
00045 fgets(buffer,1024,in);
00046 } while(buffer[0]=='#');
00047
00048
00049 sscanf(buffer,"%d %d",&width,&height);
00050 rfbLog("Got width %d and height %d.\n",width,height);
00051 fgets(buffer,1024,in);
00052
00053
00054 paddedWidth = width;
00055
00056
00057
00058 if(width&3)
00059 paddedWidth+=4-(width&3);
00060
00061
00062 rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3);
00063 if(!rfbScreen)
00064 return 0;
00065 if(argc>1)
00066 rfbScreen->desktopName = argv[1];
00067 else
00068 rfbScreen->desktopName = "Picture";
00069 rfbScreen->alwaysShared = TRUE;
00070 rfbScreen->kbdAddEvent = HandleKey;
00071
00072
00073 rfbScreen->httpDir = "../webclients";
00074
00075
00076 rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height);
00077 fread(rfbScreen->frameBuffer,width*3,height,in);
00078 fclose(in);
00079
00080
00081 if(width != paddedWidth) {
00082 int padCount = 3*(paddedWidth - width);
00083 for(j=height-1;j>=0;j--) {
00084 memmove(rfbScreen->frameBuffer+3*paddedWidth*j,
00085 rfbScreen->frameBuffer+3*width*j,
00086 3*width);
00087 memset(rfbScreen->frameBuffer+3*paddedWidth*(j+1)-padCount,
00088 0,padCount);
00089 }
00090 }
00091
00092
00093 rfbInitServer(rfbScreen);
00094
00095
00096 rfbRunEventLoop(rfbScreen,40000,FALSE);
00097
00098 return(0);
00099 }
00100 #endif