From 2634379912ea972dedc0d389049945716c90c0db Mon Sep 17 00:00:00 2001 From: dscho Date: Tue, 14 Aug 2001 10:24:32 +0000 Subject: [PATCH] comments & new example: pnmshow --- Makefile | 5 ++++- example.c | 1 + main.c | 2 +- pnmshow.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 pnmshow.c diff --git a/Makefile b/Makefile index 1969adc..07fcb11 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ OBJS=main.o rfbserver.o miregion.o auth.o sockets.o xalloc.o \ stats.o corre.o hextile.o rre.o translate.o cutpaste.o \ zlib.o tight.o -all: example storepasswd +all: example pnmshow storepasswd install_OSX: OSXvnc-server cp OSXvnc-server storepasswd ../OSXvnc/build/OSXvnc.app/Contents/MacOS @@ -41,6 +41,9 @@ libvncserver.a: $(OBJS) example: example.o libvncauth/libvncauth.a libvncserver.a $(CC) -o example example.o $(LIBS) $(PTHREAD_LIBS) +pnmshow: pnmshow.o libvncauth/libvncauth.a libvncserver.a + $(CC) -o pnmshow pnmshow.o $(LIBS) $(PTHREAD_LIBS) + OSXvnc-server: mac.o libvncauth/libvncauth.a libvncserver.a $(CC) -o OSXvnc-server mac.o $(LIBS) $(OSX_LIBS) diff --git a/example.c b/example.c index 22d1c04..2ef78d8 100644 --- a/example.c +++ b/example.c @@ -145,6 +145,7 @@ int main(int argc,char** argv) initBuffer(rfbScreen->frameBuffer); /* this is the blocking event loop, i.e. it never returns */ + /* 40000 are the microseconds, i.e. 0.04 seconds */ runEventLoop(rfbScreen,40000,FALSE); /* this is the non-blocking event loop; a background thread is started */ diff --git a/main.c b/main.c index 9736b0d..43cb0e0 100644 --- a/main.c +++ b/main.c @@ -276,7 +276,7 @@ processArguments(rfbScreenInfoPtr rfbScreen,int argc, char *argv[]) } else if (strcmp(argv[i], "-dontdisconnect") == 0) { rfbScreen->rfbDontDisconnect = TRUE; } else { - usage(); + /* usage(); we no longer exit for unknown arguments */ } } } diff --git a/pnmshow.c b/pnmshow.c new file mode 100644 index 0000000..0f29d90 --- /dev/null +++ b/pnmshow.c @@ -0,0 +1,67 @@ +#include +#include "rfb.h" +#define XK_MISCELLANY +#include "keysymdef.h" + +void HandleKey(Bool down,KeySym key,rfbClientPtr cl) +{ + if(down && (key==XK_Escape || key=='q' || key=='Q')) + rfbCloseClient(cl); +} + +int main(int argc,char** argv) +{ + FILE* in=stdin; + int i,width,height; + unsigned char buffer[1024]; + rfbScreenInfoPtr rfbScreen; + + 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)) { + printf("Not a ppm.\n"); + exit(2); + } + + /* skip comments */ + do { + fgets(buffer,1024,in); + } while(buffer[0]=='#'); + + /* get width & height */ + sscanf(buffer,"%d %d",&width,&height); + fprintf(stderr,"Got width %d and height %d (%s).\n",width,height,buffer); + fgets(buffer,1024,in); + + /* initialize data for vnc server */ + rfbScreen = rfbDefaultScreenInit(argc,argv,width,height,8,3,4); + if(argc>1) + rfbScreen->desktopName = argv[1]; + else + rfbScreen->desktopName = "Picture"; + rfbScreen->rfbAlwaysShared = TRUE; + rfbScreen->kbdAddEvent = HandleKey; + + /* allocate picture and read it */ + rfbScreen->frameBuffer = (char*)malloc(width*height*4); + fread(rfbScreen->frameBuffer,width*3,height,in); + + /* correct the format to 4 bytes instead of 3 */ + for(i=width*height-1;i>=0;i--) { + rfbScreen->frameBuffer[i*4+3]=rfbScreen->frameBuffer[i*3+2]; + rfbScreen->frameBuffer[i*4+2]=rfbScreen->frameBuffer[i*3+1]; + rfbScreen->frameBuffer[i*4+1]=rfbScreen->frameBuffer[i*3+0]; + } + + /* run event loop */ + runEventLoop(rfbScreen,40000,FALSE); + + return(0); +}